Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast access (hotkey) to grab_keyboard() #2

Open
michaeltraxler opened this issue Jul 2, 2014 · 22 comments · May be fixed by #1375
Open

fast access (hotkey) to grab_keyboard() #2

michaeltraxler opened this issue Jul 2, 2014 · 22 comments · May be fixed by #1375
Labels
enhancement New feature or request

Comments

@michaeltraxler
Copy link

michaeltraxler commented Jul 2, 2014

From the mail to [email protected] from the 02.11.2013

Dear Tigervnc-developers,

I would like to know if it would be possible to integrate the functionality
provided by the attached patch (I know it is a hack, so it would need to be
done correctly) to a future stock tigervnc-release.

It assigns the grab_keyboard() function directly on the key "CONTROL_R" or
"META_L" for fast access (as also implemented in remmina).
This function is so much needed for me and my colleagues that I can not
imagine that it is not useful for others.
If you use a window manager like awesome then you need it....

Thanks a lot,

Michael

As I don't know how to attach a file to the comment, I paste the patch as an example I did here:

--- tigervnc-1.3.0/vncviewer/DesktopWindow.cxx  2013-07-01 14:42:06.000000000 +0200
+++ ../tigervnc-1.3.0/vncviewer/DesktopWindow.cxx   2013-11-02 04:51:44.447096532 +0100
@@ -59,6 +59,9 @@ DesktopWindow::DesktopWindow(int w, int
   : Fl_Window(w, h), cc(cc_), firstUpdate(true),
     delayedFullscreen(false), delayedDesktopSize(false)
 {
+  
+  grab_keyboard_state = 0;
+
   scroll = new Fl_Scroll(0, 0, w, h);
   scroll->color(FL_BLACK);

@@ -449,8 +452,10 @@ int DesktopWindow::fltkHandle(int event,
       //        a) Fl::grab(0) on X11 will release the keyboard grab for us.
       //        b) Gaining focus on the system level causes FLTK to switch
       //           window level on OS X.
-      if (dw->fullscreen_active())
+      if (dw->fullscreen_active()) {
         dw->grabKeyboard();
+   dw->grab_keyboard_state = 1;
+      }
       break;

     case FL_UNFOCUS:
@@ -458,6 +463,7 @@ int DesktopWindow::fltkHandle(int event,
       //        focus as it is very tied to this specific window on some
       //        platforms and we want to be able to open subwindows.
       dw->ungrabKeyboard();
+      dw->grab_keyboard_state = 0;
       break;
     }
   }
--- tigervnc-1.3.0/vncviewer/DesktopWindow.h    2013-07-01 14:42:05.000000000 +0200
+++ ../tigervnc-1.3.0/vncviewer/DesktopWindow.h 2013-11-02 04:53:30.975097085 +0100
@@ -81,12 +81,15 @@ public:

   void fullscreen_on();

-private:
-  static int fltkHandle(int event, Fl_Window *win);
+  int grab_keyboard_state;

   void grabKeyboard();
   void ungrabKeyboard();

+private:
+  static int fltkHandle(int event, Fl_Window *win);
+
+
   static void handleGrab(void *data);

   void maximizeWindow();
@@ -113,6 +116,9 @@ private:
   bool firstUpdate;
   bool delayedFullscreen;
   bool delayedDesktopSize;
+
+
+
 };

 #endif
--- tigervnc-1.3.0/vncviewer/Viewport.cxx   2013-07-01 14:42:05.000000000 +0200
+++ ../tigervnc-1.3.0/vncviewer/Viewport.cxx    2013-11-02 04:56:05.376802328 +0100
@@ -356,6 +356,8 @@ int Viewport::handle(int event)
   int buttonMask, wheelMask;
   DownMap::const_iterator iter;

+  DesktopWindow *dw = dynamic_cast<DesktopWindow*>(window());
+
   switch (event) {
   case FL_PASTE:
     buffer = new char[Fl::event_length() + 1];
@@ -434,9 +436,27 @@ int Viewport::handle(int event)
     while (!downKeySym.empty())
       handleKeyEvent(downKeySym.begin()->first, downKeySym.begin()->first,
                      "", false);
+    dw->ungrabKeyboard();
+    dw->fullscreen_off();
+
     return 1;

   case FL_KEYDOWN:
+    // Code to use Control_R as a grabKeyboard shortcut, as in remmina
+    if (menuKeyCode && (Fl::event_key() == (hostKeyMetaL ? FL_Meta_L : FL_Control_R)  ) ) {
+      if(dw->grab_keyboard_state == 0) {
+   dw->grab_keyboard_state = 1;
+   dw->grabKeyboard();
+      } 
+      else  {
+   dw->grab_keyboard_state = 0;
+   dw->fullscreen_off();
+   dw->ungrabKeyboard();
+      }
+      //window()->fullscreen_off();
+      vlog.debug("keyboard_grab key (ctrl-right) hit, keyboard grab state: %d\n", dw->grab_keyboard_state);
+    }
+    
     if (menuKeyCode && (Fl::event_key() == menuKeyCode)) {
       popupContextMenu();
       return 1;
--- tigervnc-1.3.0/vncviewer/parameters.cxx 2013-07-01 16:00:00.000000000 +0200
+++ ../tigervnc-1.3.0/vncviewer/parameters.cxx  2013-11-02 04:57:22.692802730 +0100
@@ -127,6 +127,10 @@ BoolParameter sendPrimary("SendPrimary",
                           "Send the primary selection and cut buffer to the "
                           "server as well as the clipboard selection",
                           true);
+BoolParameter hostKeyMetaL("HostKeyMetaL",
+              "Use the MetaL (Windows-Key) instead of "
+              "Control_R as the host key (grabKeyboard shortcut)",
+              false);

 StringParameter menuKey("MenuKey", "The key which brings up the popup menu",
                         "F8");
@@ -171,6 +175,7 @@ VoidParameter* parameterArray[] = {
   &acceptClipboard,
   &sendClipboard,
   &sendPrimary,
+  &hostKeyMetaL,
   &menuKey,
   &fullscreenSystemKeys
 };
--- tigervnc-1.3.0/vncviewer/parameters.h   2013-07-01 14:42:06.000000000 +0200
+++ ../tigervnc-1.3.0/vncviewer/parameters.h    2013-11-02 04:57:48.371802864 +0100
@@ -58,6 +58,8 @@ extern rfb::BoolParameter acceptClipboar
 extern rfb::BoolParameter sendClipboard;
 extern rfb::BoolParameter sendPrimary;

+extern rfb::BoolParameter hostKeyMetaL;
+
 extern rfb::StringParameter menuKey;

 extern rfb::BoolParameter fullscreenSystemKeys;


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@CendioOssman
Copy link
Member

Definitely interesting. Someone just needs to do the cleanup and integration. :)

Should probably alse be similar to MenuKey so that we can easily extend it in the future.

@twaugh
Copy link
Contributor

twaugh commented Apr 8, 2015

The way that virt-manager and gnome-boxes deals with this issue is pretty good: the mouse is free to move in and out of the window, but when the mouse cursor is inside the window the keyboard is grabbed. Not sure of the details.

@michaeltraxler
Copy link
Author

Just to help someone who urgently need this feature and as we are now on gitub, I made a fork
https://github.com/michaeltraxler/tigervnc-1
which implements the feature.
Strangely (because I don't understand enough about FLTK), I had to a change the patch a bit. The observation is, that after grabKeyboard() and without movement of the mouse (I tend not to use the mouse), the ungrabKeyboard() did not work. The only workaround I found was to add to the ungrabKeyboard() a hide() and show(). Then the ungabKeyboard has an effect. Maybe correlated to my window manager awesome...

@specing
Copy link

specing commented Sep 18, 2015

haven't had such an issue (or did not notice it)

Any ETA on upstreaming?

@specing
Copy link

specing commented Apr 16, 2017

What is the current state of this? The patch above fails to apply to tigervnc 1.7.1.

@CendioOssman
Copy link
Member

No one seems to be working on this right now. But it is on my (rather long) todo list. I was thinking of doing something like VMware and just use modifiers.

@michaeltraxler
Copy link
Author

Hi, as I'm "dependent" (I don't understand why not everyone needs this :-) ) on such a feature, I do the patching from time to time by hand, which is not nice and not professional, as I don't know details about the code and just hack the feature in I need...

@specing
Copy link

specing commented Jul 1, 2017

bump

@specing
Copy link

specing commented Jul 2, 2017

New patch for making 1.8.0 build (untested):

--- tigervnc-1.8.0/vncviewer/DesktopWindow.cxx	2017-05-16 15:53:28.000000000 +0200
+++ tigervnc-1.8.0/vncviewer/DesktopWindow.cxx	2017-07-01 23:03:10.872684824 +0200
@@ -70,6 +70,7 @@
 {
   Fl_Group* group;
 
+  grab_keyboard_state = 0;
   // Dummy group to prevent FLTK from moving our widgets around
   group = new Fl_Group(0, 0, w, h);
   group->resizable(NULL);
@@ -668,8 +669,10 @@
       //        a) Fl::grab(0) on X11 will release the keyboard grab for us.
       //        b) Gaining focus on the system level causes FLTK to switch
       //           window level on OS X.
-      if (dw->fullscreen_active())
+      if (dw->fullscreen_active()) {
         dw->grabKeyboard();
+        dw->grab_keyboard_state = 1;
+      }
       break;
 
     case FL_UNFOCUS:
@@ -677,6 +680,7 @@
       //        focus as it is very tied to this specific window on some
       //        platforms and we want to be able to open subwindows.
       dw->ungrabKeyboard();
+      dw->grab_keyboard_state = 0;
       break;
     }
   }
--- tigervnc-1.8.0/vncviewer/DesktopWindow.h	2017-05-16 15:53:28.000000000 +0200
+++ tigervnc-1.8.0/vncviewer/DesktopWindow.h	2017-07-01 23:03:10.872684824 +0200
@@ -73,6 +73,9 @@
   int handle(int event);
 
   void fullscreen_on();
+  int grab_keyboard_state;
+  void grabKeyboard();
+  void ungrabKeyboard();
 
 private:
   static void menuOverlay(void *data);
@@ -82,9 +85,6 @@
 
   static int fltkHandle(int event, Fl_Window *win);
 
-  void grabKeyboard();
-  void ungrabKeyboard();
-
   static void handleGrab(void *data);
 
   void maximizeWindow();
--- tigervnc-1.8.0/vncviewer/Viewport.cxx	2017-05-16 15:53:28.000000000 +0200
+++ tigervnc-1.8.0/vncviewer/Viewport.cxx	2017-07-01 23:03:10.872684824 +0200
@@ -266,6 +266,8 @@
   int buttonMask, wheelMask;
   DownMap::const_iterator iter;
 
+  DesktopWindow *dw = dynamic_cast<DesktopWindow*>(window());
+
   switch (event) {
   case FL_PASTE:
     buffer = new char[Fl::event_length() + 1];
@@ -340,10 +342,25 @@
     // sense (e.g. Alt+Tab where we only see the Alt press)
     while (!downKeySym.empty())
       handleKeyRelease(downKeySym.begin()->first);
+    dw->ungrabKeyboard();
+    dw->fullscreen_off();
     Fl::enable_im();
     return 1;
 
   case FL_KEYDOWN:
+    // Code to use Control_R as a grabKeyboard shortcut, as in remmina
+    if (menuKeyCode && (Fl::event_key() == (hostKeyMetaL ? FL_Meta_L : FL_Control_R)  ) ) {
+      if(dw->grab_keyboard_state == 0) {
+        dw->grab_keyboard_state = 1;
+        dw->grabKeyboard();
+      } else {
+        dw->grab_keyboard_state = 0;
+        dw->fullscreen_off();
+        dw->ungrabKeyboard();
+      }
+      //window()->fullscreen_off();
+      vlog.debug("keyboard_grab key (ctrl-right) hit, keyboard grab state: %d\n", dw->grab_keyboard_state);
+    }
   case FL_KEYUP:
     // Just ignore these as keys were handled in the event handler
     return 1;
--- tigervnc-1.8.0/vncviewer/parameters.cxx	2017-05-16 15:53:28.000000000 +0200
+++ tigervnc-1.8.0/vncviewer/parameters.cxx	2017-07-01 23:03:10.872684824 +0200
@@ -132,6 +132,10 @@
                           true);
 #endif
 
+BoolParameter hostKeyMetaL("HostKeyMetaL",
+              "Use the MetaL (Windows-Key) instead of "
+              "Control_R as the host key (grabKeyboard shortcut)",
+              false);
 StringParameter menuKey("MenuKey", "The key which brings up the popup menu",
                         "F8");
 
@@ -173,6 +177,7 @@
 #if !defined(WIN32) && !defined(__APPLE__)
   &sendPrimary,
 #endif
+  &hostKeyMetaL,
   &menuKey,
   &fullscreenSystemKeys
 };
--- tigervnc-1.8.0/vncviewer/parameters.h   2013-07-01 14:42:06.000000000 +0200
+++ tigervnc-1.8.0/vncviewer/parameters.h    2013-11-02 04:57:48.371802864 +0100
@@ -58,6 +58,8 @@ extern rfb::BoolParameter acceptClipboar
 extern rfb::BoolParameter sendClipboard;
 extern rfb::BoolParameter sendPrimary;

+extern rfb::BoolParameter hostKeyMetaL;
+
 extern rfb::StringParameter menuKey;

 extern rfb::BoolParameter fullscreenSystemKeys;

@michaeltraxler
Copy link
Author

The patch doesn't work as given above.
But I added a new version of the patch to my fork, so you can find it here:
https://github.com/michaeltraxler/tigervnc-1/tree/1.8-branch-grab

@specing
Copy link

specing commented Jul 8, 2017

Ah thanks

@piyushgarg
Copy link

I am also watching this enhancement, I am running the tiger vnc client on a second monitor which is occupying the whole screen, however I am not able to manually activate the "Grab Keyboard" as this is something which only works in "Full Screen" mode, irrespective the viewer actually occupying the whole screen.
As Michael has mentioned some META key combination Ctrl_R+G would be fine.

@CendioOssman
Copy link
Member

Any reason you are not using full screen mode for that single monitor? It should work the way you want in that case.

@piyushgarg
Copy link

piyushgarg commented Nov 10, 2017

Using "Full Screen" mode with F8 Menu obstructs mouse inputs to first monitor.

@CendioOssman
Copy link
Member

Ah. That issue has been fixed, but I guess it was after the latest release.

@michaeltraxler
Copy link
Author

michaeltraxler commented Nov 10, 2017

Or you just add this small feature which helps sooo much :-)
The fullscreen option is not always a way to go, e.g. if you have several vncviewer open with different screen resolutions and only have on screen and want to move between them permanently.
Don't get me wrong, I don't want to complain! I'm so grateful for your great software and my workday without it would be unthinkable!

@rahuls1071
Copy link

Having a feature to traverse between windows in VNC session in windowed mode will be very helpful.
Also feature to toggle between traverse in windows vs traverse in VNC session is also required.

@specing
Copy link

specing commented Jan 12, 2019

5 years later I am feeling a bit tired of patching every version (it does not apply, again).

@hopeseekr
Copy link

It's so stupid that this has been delayed so long when there are pull requests to fix it.

Shame on the devs!

@michaeltraxler
Copy link
Author

michaeltraxler commented May 24, 2019

Here the latest patch for v1.9.80

delme.txt

Feels even more a hack than before, but works like a charm...

Would be nice to have this in the main branch... I'm still puzzled, that this feature is not wanted by many others.

@specing
Copy link

specing commented Jun 6, 2019

Wow, that patch is short!

Thanks, I was getting tired of tigervnc upgrades failing for 6 months now.

gschwind added a commit to gschwind/tigervnc that referenced this issue Aug 30, 2019
gschwind added a commit to gschwind/tigervnc that referenced this issue Aug 30, 2019
gschwind added a commit to gschwind/tigervnc that referenced this issue Aug 31, 2019
gschwind added a commit to gschwind/tigervnc that referenced this issue Sep 5, 2019
gschwind added a commit to gschwind/tigervnc that referenced this issue Sep 5, 2019
@ichensky
Copy link

Created docker file, that builds debian deb package of tigervnc-viewer https://github.com/ichensky/tigervnc_docker with patch provided above, for father installation via dpkg -i.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants