Dear vnc users/developers,
I patched unix vnc 3.3.7 and 4.0 to have a switch to grab the keyboard
while the mouse is inside the desktop window.
For me, this increases the usability of vncviewer very much, as I can now
operate all the window manager keys on the remote machine, while at the
same time it is much more convenient to "get back" to the local machine
than e.g. if I run a separate X server with vncviewer in fullscreen mode
as the only client: I just need to move the mouse outside the window. As
there is a switch (for 4.0 also in the options dialog), it is easy to get
back to non-grabbing behaviour.
I did not yet notice any serious problems; for normal use it seems to work
fine. I did not test how it cooperates with fullscreen mode.
Kind regards,
Alexander
Below I put the two patches for version 3.3.7 ...
****************************************************************************************
diff -Naur vnc-3.3.7/vncviewer/argsresources.c
grabvnc/vnc-3.3.7/vncviewer/argsresources.c
--- vnc-3.3.7/vncviewer/argsresources.c 2004-07-23 23:30:17.000000000 +0200
+++ grabvnc/vnc-3.3.7/vncviewer/argsresources.c 2004-07-23 23:55:49.000000000 +0200
@@ -212,6 +212,9 @@
{"bumpScrollPixels", "BumpScrollPixels", XtRInt, sizeof(int),
XtOffsetOf(AppData, bumpScrollPixels), XtRImmediate, (XtPointer) 20},
+
+ {"grabKeyboard", "GrabKeyboard", XtRBool, sizeof(Bool),
+ XtOffsetOf(AppData, grabKeyboard), XtRImmediate, (XtPointer) False},
};
diff -Naur vnc-3.3.7/vncviewer/desktop.c grabvnc/vnc-3.3.7/vncviewer/desktop.c
--- vnc-3.3.7/vncviewer/desktop.c 2002-10-22 13:09:35.000000000 +0200
+++ grabvnc/vnc-3.3.7/vncviewer/desktop.c 2004-07-23 23:55:48.000000000 +0200
@@ -76,7 +76,7 @@
XtVaSetValues(desktop, XtNwidth, si.framebufferWidth,
XtNheight, si.framebufferHeight, NULL);
- XtAddEventHandler(desktop, LeaveWindowMask|ExposureMask,
+ XtAddEventHandler(desktop, EnterWindowMask|LeaveWindowMask|ExposureMask,
True, HandleBasicDesktopEvent, NULL);
for (i = 0; i < 256; i++)
@@ -170,7 +170,16 @@
ev->xexpose.width, ev->xexpose.height);
break;
+ case EnterNotify:
+ if (appData.grabKeyboard &&
+ XtGrabKeyboard(desktop, True, GrabModeAsync,
+ GrabModeAsync, CurrentTime) != GrabSuccess) {
+ fprintf(stderr, "XtGrabKeyboard() failed.\n");
+ }
+ break;
case LeaveNotify:
+ if (appData.grabKeyboard)
+ XtUngrabKeyboard(desktop, CurrentTime);
for (i = 0; i < 256; i++) {
if (modifierPressed[i]) {
SendKeyEvent(XKeycodeToKeysym(dpy, i, 0), False);
diff -Naur vnc-3.3.7/vncviewer/vncviewer.h grabvnc/vnc-3.3.7/vncviewer/vncviewer.h
--- vnc-3.3.7/vncviewer/vncviewer.h 2004-07-23 23:30:17.000000000 +0200
+++ grabvnc/vnc-3.3.7/vncviewer/vncviewer.h 2004-07-23 23:56:14.000000000 +0200
@@ -98,6 +98,7 @@
int bumpScrollTime;
int bumpScrollPixels;
+ Bool grabKeyboard;
} AppData;
extern AppData appData;
********************************************************************************
... and for 4.0:
********************************************************************************
diff -Naur vnc-4.0-unixsrc/vncviewer/CConn.cxx
grabvnc/vnc-4.0-unixsrc/vncviewer/CConn.cxx
--- vnc-4.0-unixsrc/vncviewer/CConn.cxx 2004-04-26 18:39:08.000000000 +0200
+++ grabvnc/vnc-4.0-unixsrc/vncviewer/CConn.cxx 2004-07-24 11:15:00.000000000 +0200
@@ -498,6 +498,7 @@
options.fullScreen.checked(fullScreen);
options.useLocalCursor.checked(useLocalCursor);
options.dotWhenNoCursor.checked(dotWhenNoCursor);
+ options.grabKeyboard.checked(grabKeyboard);
}
void CConn::getOptions() {
@@ -538,6 +539,7 @@
desktop->resetLocalCursor();
}
dotWhenNoCursor.setParam(options.dotWhenNoCursor.checked());
+ grabKeyboard.setParam(options.grabKeyboard.checked());
checkEncodings();
}
diff -Naur vnc-4.0-unixsrc/vncviewer/DesktopWindow.cxx
grabvnc/vnc-4.0-unixsrc/vncviewer/DesktopWindow.cxx
--- vnc-4.0-unixsrc/vncviewer/DesktopWindow.cxx 2004-04-30 12:24:35.000000000 +0200
+++ grabvnc/vnc-4.0-unixsrc/vncviewer/DesktopWindow.cxx 2004-07-24 11:05:53.000000000
+0200
@@ -417,6 +417,11 @@
break;
case EnterNotify:
+ if (grabKeyboard &&
+ XGrabKeyboard(dpy, win(), True, GrabModeAsync,
+ GrabModeAsync, CurrentTime) != GrabSuccess) {
+ fprintf(stderr, "XGrabKeyboard() failed.\n");
+ }
newSelection = 0;
if (sendPrimary && !selectionOwner(XA_PRIMARY)) {
XConvertSelection(dpy, XA_PRIMARY, xaTIMESTAMP, xaSELECTION_TIME,
@@ -428,6 +433,8 @@
break;
case LeaveNotify:
+ if( grabKeyboard )
+ XUngrabKeyboard(dpy, CurrentTime);
if (serverCutText_ && newServerCutText) {
newServerCutText = false;
vlog.debug("acquiring primary and clipboard selections");
diff -Naur vnc-4.0-unixsrc/vncviewer/OptionsDialog.h
grabvnc/vnc-4.0-unixsrc/vncviewer/OptionsDialog.h
--- vnc-4.0-unixsrc/vncviewer/OptionsDialog.h 2003-09-02 19:20:45.000000000 +0200
+++ grabvnc/vnc-4.0-unixsrc/vncviewer/OptionsDialog.h 2004-07-24 11:12:39.000000000
+0200
@@ -60,6 +60,7 @@
fullScreen(dpy, "Full-screen mode", this, false, this),
useLocalCursor(dpy, "Render cursor locally", this, false, this),
dotWhenNoCursor(dpy, "Show dot when no cursor", this, false, this),
+ grabKeyboard(dpy, "Grab keyboard when mouse in viewer", this, false, this),
okButton(dpy, "OK", this, this, 60),
cancelButton(dpy, "Cancel", this, this, 60)
{
@@ -103,6 +104,8 @@
y += useLocalCursor.height();
dotWhenNoCursor.move(xPad, y);
y += dotWhenNoCursor.height();
+ grabKeyboard.move(xPad, y);
+ y += grabKeyboard.height();
okButton.move(width() - xPad*12 - cancelButton.width() - okButton.width(),
height() - yPad*4 - okButton.height());
@@ -161,7 +164,7 @@
TXCheckbox fullColour, mediumColour, lowColour, veryLowColour;
TXCheckbox zrle, hextile, raw;
TXCheckbox viewOnly, acceptClipboard, sendClipboard, sendPrimary;
- TXCheckbox shared, fullScreen, useLocalCursor, dotWhenNoCursor;
+ TXCheckbox shared, fullScreen, useLocalCursor, dotWhenNoCursor, grabKeyboard;
TXButton okButton, cancelButton;
};
diff -Naur vnc-4.0-unixsrc/vncviewer/parameters.h
grabvnc/vnc-4.0-unixsrc/vncviewer/parameters.h
--- vnc-4.0-unixsrc/vncviewer/parameters.h 2003-09-16 12:04:18.000000000 +0200
+++ grabvnc/vnc-4.0-unixsrc/vncviewer/parameters.h 2004-07-24 11:02:07.000000000
+0200
@@ -36,6 +36,7 @@
extern rfb::BoolParameter sendClipboard;
extern rfb::BoolParameter sendPrimary;
extern rfb::BoolParameter fullScreen;
+extern rfb::BoolParameter grabKeyboard;
extern rfb::StringParameter geometry;
extern char aboutText[];
diff -Naur vnc-4.0-unixsrc/vncviewer/vncviewer.cxx
grabvnc/vnc-4.0-unixsrc/vncviewer/vncviewer.cxx
--- vnc-4.0-unixsrc/vncviewer/vncviewer.cxx 2004-06-11 16:45:00.000000000 +0200
+++ grabvnc/vnc-4.0-unixsrc/vncviewer/vncviewer.cxx 2004-07-24 11:08:43.000000000
+0200
@@ -92,6 +92,9 @@
false);
StringParameter geometry("geometry", "X geometry specification", "");
StringParameter displayname("display", "The X display", "");
+BoolParameter grabKeyboard("GrabKeyboard",
+ "Grab the keyboard while mouse is inside the "
+ "desktop window", false);
char aboutText[256];
char* programName;
********************************************************************************
_______________________________________________
VNC-List mailing list
[EMAIL PROTECTED]
To remove yourself from the list visit:
http://www.realvnc.com/mailman/listinfo/vnc-list