From 58183b7ceacb774b018bd61e6ad6c127662c7fcb Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 5 Mar 2017 23:51:24 +0100 Subject: nxagent: Add autograb mode. You can now toggle between autograb mode by pressing CTRL-ALT-G (default, can be adjusted in keystrokes.cfg). Fixes ArcticaProject/nx-libs#384. --- doc/nxagent/README.keystrokes | 3 + etc/keystrokes.cfg | 1 + nx-X11/programs/Xserver/hw/nxagent/Events.c | 84 +++++++++++++++++++++++++- nx-X11/programs/Xserver/hw/nxagent/Events.h | 3 +- nx-X11/programs/Xserver/hw/nxagent/Keystroke.c | 9 ++- nx-X11/programs/Xserver/hw/nxagent/Keystroke.h | 2 + 6 files changed, 97 insertions(+), 5 deletions(-) diff --git a/doc/nxagent/README.keystrokes b/doc/nxagent/README.keystrokes index 750a460eb..b76e9fd62 100644 --- a/doc/nxagent/README.keystrokes +++ b/doc/nxagent/README.keystrokes @@ -126,6 +126,9 @@ reread_keystrokes Forces nxagent to re-read the keystroke configuration. Useful to add/change keystrokes to a running session. +autograb + Toggles autograb mode + force_synchronization Forces immediate drawing of elements to be synchronized which can fix some visual bugs. diff --git a/etc/keystrokes.cfg b/etc/keystrokes.cfg index 856369839..27acf8e84 100644 --- a/etc/keystrokes.cfg +++ b/etc/keystrokes.cfg @@ -24,4 +24,5 @@ + diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 553eaccd6..95a00afbf 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -674,6 +674,40 @@ static void nxagentSwitchDeferMode(void) } } +static Bool autograb = False; + +static void nxagentEnableAutoGrab(void) +{ +#ifdef DEBUG + fprintf(stderr, "enabling autograb\n"); +#endif + + nxagentGrabPointerAndKeyboard(NULL); + autograb = True; +} + +static void nxagentDisableAutoGrab(void) +{ +#ifdef DEBUG + fprintf(stderr, "disabling autograb\n"); +#endif + + nxagentUngrabPointerAndKeyboard(NULL); + autograb = False; +} + +static void nxagentToggleAutoGrab(void) +{ + /* autograb only works in windowed mode */ + if (nxagentOption(Rootless) || nxagentOption(Fullscreen)) + return; + + if (!autograb) + nxagentEnableAutoGrab(); + else + nxagentDisableAutoGrab(); +} + static Bool nxagentExposurePredicate(Display *display, XEvent *event, XPointer window) { /* @@ -1060,6 +1094,12 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate) break; } + case doAutoGrab: + { + nxagentToggleAutoGrab(); + + break; + } default: { FatalError("nxagentDispatchEvent: handleKeyPress returned unknown value\n"); @@ -1519,6 +1559,17 @@ FIXME: Don't enqueue the KeyRelease event if the key was } } + /* FIXME: only when in windowed mode! */ + if (autograb) + { + if (X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode == NotifyNormal) + { + #ifdef DEBUG + fprintf(stderr, "%s: (FocusIn): grabbing\n", __func__); + #endif + nxagentGrabPointerAndKeyboard(NULL); + } + } break; } case FocusOut: @@ -1597,6 +1648,19 @@ FIXME: Don't enqueue the KeyRelease event if the key was #endif /* NXAGENT_FIXKEYS */ + if (autograb) + { + XlibWindow w; + int revert_to; + XGetInputFocus(nxagentDisplay, &w, &revert_to); + if (w != nxagentDefaultWindows[0] && X.xfocus.mode == NotifyWhileGrabbed) + { + #ifdef DEBUG + fprintf(stderr, "%s: (FocusOut): ungrabbing\n", __func__); + #endif + nxagentUngrabPointerAndKeyboard(NULL); + } + } break; } case KeymapNotify: @@ -3827,13 +3891,26 @@ void nxagentGrabPointerAndKeyboard(XEvent *X) fprintf(stderr, "nxagentGrabPointerAndKeyboard: Going to grab the keyboard in context [B1].\n"); #endif - result = XGrabKeyboard(nxagentDisplay, nxagentFullscreenWindow, - True, GrabModeAsync, GrabModeAsync, now); + if (nxagentFullscreenWindow) + result = XGrabKeyboard(nxagentDisplay, nxagentFullscreenWindow, + True, GrabModeAsync, GrabModeAsync, now); + else + result = XGrabKeyboard(nxagentDisplay, RootWindow(nxagentDisplay, DefaultScreen(nxagentDisplay)), + True, GrabModeAsync, GrabModeAsync, now); if (result != GrabSuccess) { + #ifdef DEBUG + fprintf(stderr, "%s: keyboard grab failed.\n", __func__); + #endif return; } + #ifdef DEBUG + else + { + fprintf(stderr, "%s: keyboard grab successful.\n", __func__); + } + #endif /* * The smart scheduler could be stopped while @@ -3851,7 +3928,8 @@ void nxagentGrabPointerAndKeyboard(XEvent *X) resource = nxagentWaitForResource(NXGetCollectGrabPointerResource, nxagentCollectGrabPointerPredicate); - NXCollectGrabPointer(nxagentDisplay, resource, + if (nxagentFullscreenWindow) + NXCollectGrabPointer(nxagentDisplay, resource, nxagentFullscreenWindow, True, NXAGENT_POINTER_EVENT_MASK, GrabModeAsync, GrabModeAsync, None, None, now); diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.h b/nx-X11/programs/Xserver/hw/nxagent/Events.h index 8bc798945..85f585e1f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.h @@ -50,7 +50,8 @@ enum HandleEventResult doViewportRight, doViewportDown, doSwitchResizeMode, - doSwitchDeferMode + doSwitchDeferMode, + doAutoGrab, }; extern CARD32 nxagentLastEventTime; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c index fe7e10d82..fb2979a1f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.c @@ -99,6 +99,9 @@ char * nxagentSpecialKeystrokeNames[] = { "viewport_scroll_down", "reread_keystrokes", + + "autograb", + NULL, }; @@ -138,6 +141,7 @@ struct nxagentSpecialKeystrokeMap default_map[] = { {KEYSTROKE_VIEWPORT_SCROLL_DOWN, ControlMask, True, XK_Down}, {KEYSTROKE_VIEWPORT_SCROLL_DOWN, ControlMask, True, XK_KP_Down}, {KEYSTROKE_REREAD_KEYSTROKES, ControlMask, True, XK_k}, + {KEYSTROKE_AUTOGRAB, ControlMask, True, XK_g}, {KEYSTROKE_END_MARKER, 0, False, NoSymbol}, }; struct nxagentSpecialKeystrokeMap *map = default_map; @@ -467,7 +471,7 @@ static enum nxagentSpecialKeystroke find_keystroke(XKeyEvent *X) #endif for (struct nxagentSpecialKeystrokeMap *cur = map; cur->stroke != KEYSTROKE_END_MARKER; cur++) { #ifdef DEBUG - fprintf(stderr, "%s: checking keysym '%c' (%d)\n", __func__, cur->keysym, cur->keysym); + fprintf(stderr,"%s: keysym %d stroke %d, type %d\n", __func__, cur->keysym, cur->stroke, X->type); #endif if (cur->keysym == keysym && modifier_matches(cur->modifierMask, cur->modifierAltMeta, X->state)) { #ifdef DEBUG @@ -627,6 +631,9 @@ Bool nxagentCheckSpecialKeystroke(XKeyEvent *X, enum HandleEventResult *result) if (X->type == KeyRelease) nxagentInitKeystrokes(True); break; + case KEYSTROKE_AUTOGRAB: + *result = doAutoGrab; + break; case KEYSTROKE_NOTHING: /* do nothing. difference to KEYSTROKE_IGNORE is the return value */ case KEYSTROKE_END_MARKER: /* just to make gcc STFU */ case KEYSTROKE_MAX: diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h index 13a83d0fe..9d7c4c4d5 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Keystroke.h @@ -73,6 +73,8 @@ enum nxagentSpecialKeystroke { KEYSTROKE_REREAD_KEYSTROKES, + KEYSTROKE_AUTOGRAB, + KEYSTROKE_NOTHING, /* insert more here and in the string translation */ -- cgit v1.2.3 From 8bf3429bc9f7aed5b85cf8c0dd71ae678bce544e Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 16 Mar 2017 13:00:48 +0100 Subject: nxagent: Make autograb an nxagentOption. --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 12 +++++------- nx-X11/programs/Xserver/hw/nxagent/Options.c | 2 ++ nx-X11/programs/Xserver/hw/nxagent/Options.h | 7 +++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 95a00afbf..8bc06e0ae 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -674,8 +674,6 @@ static void nxagentSwitchDeferMode(void) } } -static Bool autograb = False; - static void nxagentEnableAutoGrab(void) { #ifdef DEBUG @@ -683,7 +681,7 @@ static void nxagentEnableAutoGrab(void) #endif nxagentGrabPointerAndKeyboard(NULL); - autograb = True; + nxagentChangeOption(AutoGrab, True); } static void nxagentDisableAutoGrab(void) @@ -693,7 +691,7 @@ static void nxagentDisableAutoGrab(void) #endif nxagentUngrabPointerAndKeyboard(NULL); - autograb = False; + nxagentChangeOption(AutoGrab, False); } static void nxagentToggleAutoGrab(void) @@ -702,7 +700,7 @@ static void nxagentToggleAutoGrab(void) if (nxagentOption(Rootless) || nxagentOption(Fullscreen)) return; - if (!autograb) + if (!nxagentOption(AutoGrab)) nxagentEnableAutoGrab(); else nxagentDisableAutoGrab(); @@ -1560,7 +1558,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was } /* FIXME: only when in windowed mode! */ - if (autograb) + if (nxagentOption(AutoGrab)) { if (X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode == NotifyNormal) { @@ -1648,7 +1646,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was #endif /* NXAGENT_FIXKEYS */ - if (autograb) + if (nxagentOption(AutoGrab)) { XlibWindow w; int revert_to; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Options.c b/nx-X11/programs/Xserver/hw/nxagent/Options.c index c06967c76..10e006a23 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Options.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Options.c @@ -172,6 +172,8 @@ void nxagentInitOptions(void) nxagentOptions.ReconnectTolerance = DEFAULT_TOLERANCE; nxagentOptions.KeycodeConversion = DEFAULT_KEYCODE_CONVERSION; + + nxagentOptions.AutoGrab = False; } /* diff --git a/nx-X11/programs/Xserver/hw/nxagent/Options.h b/nx-X11/programs/Xserver/hw/nxagent/Options.h index b5394ee01..88bb60e8f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Options.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Options.h @@ -450,6 +450,13 @@ typedef struct _AgentOptions * Convert evdev keycodes to pc105. */ KeycodeConversionMode KeycodeConversion; + + /* + * True if agent should grab the input in windowed mode whenever the + * agent window gets the focus + */ + int AutoGrab; /* Should be Bool but I do not want to include Xlib.h here */ + } AgentOptionsRec; typedef AgentOptionsRec *AgentOptionsPtr; -- cgit v1.2.3 From 4eaedd002e8628bb6738d2b3994628b1fef3837a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 16 Mar 2017 13:12:01 +0100 Subject: Args.c: Add command line option -autograb. --- nx-X11/programs/Xserver/hw/nxagent/Args.c | 9 +++++++++ nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 | 3 +++ 2 files changed, 12 insertions(+) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index 1d8beca3d..cbdb2fd9d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -1039,6 +1039,14 @@ int ddxProcessArgument(int argc, char *argv[], int i) return 0; } + if (!strcmp(argv[i], "-autograb")) + { + nxagentChangeOption(AutoGrab, True); + + return 1; + } + + /* * Disable Xinerama (i.e. fake it in Screen.c) if somehow Xinerama support * has been disabled on the cmdline. @@ -2195,6 +2203,7 @@ void ddxUseMsg(void) ErrorF("-noignore don't ignore pointer and keyboard configuration changes mandated by clients\n"); ErrorF("-nokbreset don't reset keyboard device if the session is resumed\n"); ErrorF("-noxkblock always allow applications to change layout through XKEYBOARD\n"); + ErrorF("-autograb enable autograb\n"); ErrorF("-tile WxH size of image tiles (minimum allowed: 32x32)\n"); ErrorF("-keystrokefile file file with keyboard shortcut definitions\n"); ErrorF("-verbose print more warning and error messages\n"); diff --git a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 index 34ac7d7d0..860efd6ac 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 +++ b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 @@ -457,6 +457,9 @@ The nx-X11 system adds the following command line arguments: .B \-forcenx force use of NX protocol messages assuming communication through \fBnxproxy\fR .TP 8 +.B \-autograb +enable autograb mode on \fBnxagent\fR startup. The autograb feature can be toggled via nxagent keystrokes +.TP 8 .B \-nxrealwindowprop set property NX_REAL_WINDOW for each X11 client inside \fBnxagent\fR, providing the window XID of the corresponding window object on the X -- cgit v1.2.3 From ebfd8742cb043f718704622b0b8495affe98a708 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 20 Apr 2017 14:19:27 +0200 Subject: Args.c: make autograb available via options file, too. --- nx-X11/programs/Xserver/hw/nxagent/Args.c | 13 +++++++++++++ nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index cbdb2fd9d..2d998980c 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -1547,6 +1547,19 @@ static void nxagentParseSingleOption(char *name, char *value) return; } + else if (!strcmp(name, "autograb")) + { + if (!strcmp(value, "0")) + { + nxagentChangeOption(AutoGrab, False); + } + else + { + nxagentChangeOption(AutoGrab, True); + } + + return; + } else { #ifdef DEBUG diff --git a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 index 860efd6ac..fbf01f8ea 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 +++ b/nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 @@ -756,6 +756,10 @@ format must be included in both. This is potentially unsafe. means that all of these checks are essentially deactivated. This is a very bad idea. .RE +.TP 8 +.B autograb= +enable or disable autograb (default: disabled) +.RE If you want to use \fBnxagent\fR as a replacement for Xnest or Xephyr you can pass options like this: -- cgit v1.2.3 From 6dcdc578f450c71933d7f7c40383358f73e45358 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 18 May 2017 15:08:29 +0200 Subject: Events.c: improve debugging output for FocusIn/Out --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 60 +++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 8bc06e0ae..c9f5324a0 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -292,6 +292,36 @@ void ProcessInputEvents(void) mieqProcessInputEvents(); } +#ifdef DEBUG +char * nxagentGetNotifyMode(int mode) +{ + switch (mode) + { + case NotifyNormal: + { + return "NotifyNormal"; + break; + } + case NotifyGrab: + { + return "NotifyGrab"; + break; + } + case NotifyUngrab: + { + return "NotifyUngrab"; + break; + } + case NotifyWhileGrabbed: + { + return "NotifyWhileGrabbed"; + break; + } + } + return "Unknown"; +} +#endif + #ifdef DEBUG_TREE /* @@ -1530,8 +1560,18 @@ FIXME: Don't enqueue the KeyRelease event if the key was { WindowPtr pWin; - #ifdef TEST - fprintf(stderr, "nxagentDispatchEvents: Going to handle new FocusIn event.\n"); + #ifdef DEBUG + fprintf(stderr, "%s: Going to handle new FocusIn event [0x%x] mode: [%s]\n", __func__, X.xfocus.window, nxagentGetNotifyMode(X.xfocus.mode)); + { + XlibWindow w; + int revert_to; + XGetInputFocus(nxagentDisplay, &w, &revert_to); + fprintf(stderr, "%s: (FocusIn): Event win [0x%x] Focus owner [0x%x] nxagentDefaultWindows[0] [0x%x]\n", __func__, X.xfocus.window, w, nxagentDefaultWindows[0]); + } + #else + #ifdef TEST + fprintf(stderr, "%s: Going to handle new FocusIn event\n", __func__); + #endif #endif /* @@ -1567,13 +1607,25 @@ FIXME: Don't enqueue the KeyRelease event if the key was #endif nxagentGrabPointerAndKeyboard(NULL); } + /* else + { + #ifdef DEBUG + fprintf(stderr, "%s: (FocusIn): ungrabbing\n", __func__); + #endif + nxagentUngrabPointerAndKeyboard(NULL); + } + */ } break; } case FocusOut: { - #ifdef TEST - fprintf(stderr, "nxagentDispatchEvents: Going to handle new FocusOut event.\n"); + #ifdef DEBUG + fprintf(stderr, "%s: Going to handle new FocusOut event [0x%x] mode: [%s]\n", __func__, X.xfocus.window, nxagentGetNotifyMode(X.xfocus.mode)); + #else + #ifdef TEST + fprintf(stderr, "%s: Going to handle new FocusOut event.\n", __func__); + #endif #endif if (X.xfocus.detail != NotifyInferior) -- cgit v1.2.3 From a4d7a04c45ceac0c33ddd7e32495db07906bdba0 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 18 May 2017 15:09:29 +0200 Subject: Events.c: do not ungrab keyboard on LeaveNotify when in autograb mode --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index c9f5324a0..76a324fdb 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -1846,11 +1846,14 @@ FIXME: Don't enqueue the KeyRelease event if the key was nxagentLastEnteredWindow = NULL; } - if (X.xcrossing.window == nxagentDefaultWindows[0] && - X.xcrossing.detail != NotifyInferior && - X.xcrossing.mode == NotifyNormal) + if (!nxagentOption(AutoGrab)) { - nxagentUngrabPointerAndKeyboard(&X); + if (X.xcrossing.window == nxagentDefaultWindows[0] && + X.xcrossing.detail != NotifyInferior && + X.xcrossing.mode == NotifyNormal) + { + nxagentUngrabPointerAndKeyboard(&X); + } } if (X.xcrossing.detail != NotifyInferior) -- cgit v1.2.3 From 03aa5d7430817fe74499102dbc05cfd4d533c068 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 25 May 2017 23:20:50 +0200 Subject: Events.c: Autograb only for windowed modes This also make re-autograbbing after switch back from AllScreens work. --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 76a324fdb..d62bb6866 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -1597,8 +1597,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was } } - /* FIXME: only when in windowed mode! */ - if (nxagentOption(AutoGrab)) + if (nxagentOption(AutoGrab) && !(nxagentOption(AllScreens) || nxagentOption(Fullscreen) || nxagentOption(Rootless))) { if (X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode == NotifyNormal) { -- cgit v1.2.3 From 14d8e0a2a69f2468a49fcb53c4ba7e12cea10b1d Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 24 Jul 2017 14:48:29 +0200 Subject: Dialog.c: Add NXTransDialog() call for autograb toggling. --- nx-X11/programs/Xserver/hw/nxagent/Dialog.c | 50 +++++++++++++++++++++++++++++ nx-X11/programs/Xserver/hw/nxagent/Dialog.h | 30 +++++++++++++++++ nx-X11/programs/Xserver/hw/nxagent/Events.c | 2 ++ 3 files changed, 82 insertions(+) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c index 753b9d708..0dcdda5a4 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Dialog.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Dialog.c @@ -63,6 +63,8 @@ int nxagentEnableRandRModeDialogPid = 0; int nxagentDisableRandRModeDialogPid = 0; int nxagentEnableDeferModePid = 0; int nxagentDisableDeferModePid = 0; +int nxagentEnableAutograbModePid = 0; +int nxagentDisableAutograbModePid = 0; static int nxagentFailedReconnectionDialogPid = 0; @@ -158,6 +160,24 @@ void nxagentResetDialog(int pid) nxagentDisableDeferModePid = 0; } + else if (pid == nxagentEnableAutograbModePid) + { + #ifdef TEST + fprintf(stderr, "nxagentResetDialog: Resetting enable autograb mode dialog pid [%d].\n", + nxagentEnableAutograbModePid); + #endif + + nxagentEnableAutograbModePid = 0; + } + else if (pid == nxagentDisableAutograbModePid) + { + #ifdef TEST + fprintf(stderr, "nxagentResetDialog: Resetting disable autograb mode dialog pid [%d].\n", + nxagentDisableAutograbModePid); + #endif + + nxagentDisableAutograbModePid = 0; + } } void nxagentLaunchDialog(DialogType dialogType) @@ -263,6 +283,24 @@ void nxagentLaunchDialog(DialogType dialogType) break; } + case DIALOG_ENABLE_AUTOGRAB_MODE: + { + message = DIALOG_ENABLE_AUTOGRAB_MODE_MESSAGE; + type = DIALOG_ENABLE_AUTOGRAB_MODE_TYPE; + local = DIALOG_ENABLE_AUTOGRAB_MODE_LOCAL; + pid = &nxagentEnableAutograbModePid; + + break; + } + case DIALOG_DISABLE_AUTOGRAB_MODE: + { + message = DIALOG_DISABLE_AUTOGRAB_MODE_MESSAGE; + type = DIALOG_DISABLE_AUTOGRAB_MODE_TYPE; + local = DIALOG_DISABLE_AUTOGRAB_MODE_LOCAL; + pid = &nxagentDisableAutograbModePid; + + break; + } default: { #ifdef WARNING @@ -496,6 +534,18 @@ void nxagentTerminateDialog(DialogType type) break; } + case DIALOG_ENABLE_AUTOGRAB_MODE: + { + pid = nxagentEnableAutograbModePid; + + break; + } + case DIALOG_DISABLE_AUTOGRAB_MODE: + { + pid = nxagentDisableAutograbModePid; + + break; + } default: { #ifdef WARNING diff --git a/nx-X11/programs/Xserver/hw/nxagent/Dialog.h b/nx-X11/programs/Xserver/hw/nxagent/Dialog.h index ffcdf48f2..42bba290d 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Dialog.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Dialog.h @@ -41,6 +41,8 @@ typedef enum DIALOG_FAILED_RECONNECTION, DIALOG_ENABLE_DEFER_MODE, DIALOG_DISABLE_DEFER_MODE, + DIALOG_ENABLE_AUTOGRAB_MODE, + DIALOG_DISABLE_AUTOGRAB_MODE, DIALOG_LAST_TAG } DialogType; @@ -54,6 +56,8 @@ extern int nxagentEnableRandRModeDialogPid; extern int nxagentDisableRandRModeDialogPid; extern int nxagentEnableDeferModePid; extern int nxagentDisableDeferModePid; +extern int nxagentEnableAutograbModePid; +extern int nxagentDisableAutograbModePid; #define NXAGENTFAILEDRECONNECTIONMESSAGELENGTH 256 extern char nxagentFailedReconnectionMessage[NXAGENTFAILEDRECONNECTIONMESSAGELENGTH]; @@ -87,6 +91,8 @@ extern void nxagentTerminateDialogs(void); (type) == DIALOG_FAILED_RECONNECTION ? "DIALOG_FAILED_RECONNECTION" : \ (type) == DIALOG_ENABLE_DEFER_MODE ? "DIALOG_ENABLE_DEFER_MODE" : \ (type) == DIALOG_DISABLE_DEFER_MODE ? "DIALOG_DISABLE_DEFER_MODE" : \ + (type) == DIALOG_ENABLE_AUTOGRAB_MODE ? "DIALOG_ENABLE_AUTGRAB_MODE" : \ + (type) == DIALOG_DISABLE_AUTOGRAB_MODE ? "DIALOG_DISABLE_AUTOGRAB_MODE" : \ "UNKNOWN_DIALOG") /* @@ -214,5 +220,29 @@ Ctrl+Alt+E to enable it again.\ #define DIALOG_DISABLE_DEFER_MODE_LOCAL 0 + +#define DIALOG_ENABLE_AUTOGRAB_MODE_MESSAGE \ +\ +"\ +Keyboard auto-grabbing mode is now enabled. You can press\n\ +Ctrl+Alt+G again to disable auto-grabbing.\ +" + +#define DIALOG_ENABLE_AUTOGRAB_MODE_TYPE "ok" + +#define DIALOG_ENABLE_AUTOGRAB_MODE_LOCAL 0 + + +#define DIALOG_DISABLE_AUTOGRAB_MODE_MESSAGE \ +\ +"\ +Keyboard auto-grabbing mode is now disabled. You can press\n\ +Ctrl+Alt+G again to re-enable auto-grabbing.\ +" + +#define DIALOG_DISABLE_AUTOGRAB_MODE_TYPE "ok" + +#define DIALOG_DISABLE_AUTOGRAB_MODE_LOCAL 0 + #endif /* __Dialog_H__ */ diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index d62bb6866..020278841 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -712,6 +712,7 @@ static void nxagentEnableAutoGrab(void) nxagentGrabPointerAndKeyboard(NULL); nxagentChangeOption(AutoGrab, True); + nxagentLaunchDialog(DIALOG_ENABLE_AUTOGRAB_MODE); } static void nxagentDisableAutoGrab(void) @@ -722,6 +723,7 @@ static void nxagentDisableAutoGrab(void) nxagentUngrabPointerAndKeyboard(NULL); nxagentChangeOption(AutoGrab, False); + nxagentLaunchDialog(DIALOG_DISABLE_AUTOGRAB_MODE); } static void nxagentToggleAutoGrab(void) -- cgit v1.2.3 From 063813d35549a52358b0df8e5ede4e105f2e4d96 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 27 Jun 2019 23:43:44 +0200 Subject: Make AutoGrab work in more situations Especially switchin to/from fullscreen with active AutoGrab was problematic. Works much smoother now. --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 2 +- nx-X11/programs/Xserver/hw/nxagent/Window.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index 020278841..f3e7880c8 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -1699,7 +1699,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was #endif /* NXAGENT_FIXKEYS */ - if (nxagentOption(AutoGrab)) + if (nxagentOption(AutoGrab) && !nxagentFullscreenWindow) { XlibWindow w; int revert_to; diff --git a/nx-X11/programs/Xserver/hw/nxagent/Window.c b/nx-X11/programs/Xserver/hw/nxagent/Window.c index 59b33b6be..80e9bef3b 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Window.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Window.c @@ -754,7 +754,12 @@ void nxagentSwitchFullscreen(ScreenPtr pScreen, Bool switchOn) else { nxagentFullscreenWindow = None; - nxagentUngrabPointerAndKeyboard(NULL); + + /* if we had AutoGrab before entering fullscreen reactivate it now */ + if (nxagentOption(AutoGrab)) + nxagentGrabPointerAndKeyboard(NULL); + else + nxagentUngrabPointerAndKeyboard(NULL); } } @@ -1005,6 +1010,10 @@ void nxagentSwitchAllScreens(ScreenPtr pScreen, Bool switchOn) XMoveResizeWindow(nxagentDisplay, nxagentInputWindows[0], 0, 0, nxagentOption(Width), nxagentOption(Height)); + /* if we had AutoGrab before entering fullscreen reactivate it now */ + if (nxagentOption(AutoGrab)) + nxagentGrabPointerAndKeyboard(NULL); + nxagentSetPrintGeometry(pScreen -> myNum); } -- cgit v1.2.3 From 6181aa9113cc1e852d405ef85c184e32e7fad6c4 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 14 Aug 2019 20:59:49 +0200 Subject: Events.c: introduce separate debug level for autograb debugging only We should do something similar for all subsystems over time... --- nx-X11/programs/Xserver/hw/nxagent/Events.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Events.c b/nx-X11/programs/Xserver/hw/nxagent/Events.c index f3e7880c8..4a6a05482 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Events.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Events.c @@ -115,6 +115,15 @@ #undef TEST #undef DEBUG +/* debug individual subsystems */ +#undef DEBUG_AUTOGRAB + +/* aktivate subsystems if generic DEBUG is activated */ +#ifdef DEBUG +#ifndef DEBUG_AUTOGRAB +#define DEBUG_AUTOGRAB +#endif +#endif /* * Log begin and end of the important handlers. */ @@ -706,9 +715,9 @@ static void nxagentSwitchDeferMode(void) static void nxagentEnableAutoGrab(void) { -#ifdef DEBUG + #ifdef DEBUG_AUTOGRAB fprintf(stderr, "enabling autograb\n"); -#endif + #endif nxagentGrabPointerAndKeyboard(NULL); nxagentChangeOption(AutoGrab, True); @@ -717,9 +726,9 @@ static void nxagentEnableAutoGrab(void) static void nxagentDisableAutoGrab(void) { -#ifdef DEBUG + #ifdef DEBUG_AUTOGRAB fprintf(stderr, "disabling autograb\n"); -#endif + #endif nxagentUngrabPointerAndKeyboard(NULL); nxagentChangeOption(AutoGrab, False); @@ -1603,14 +1612,14 @@ FIXME: Don't enqueue the KeyRelease event if the key was { if (X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode == NotifyNormal) { - #ifdef DEBUG + #if defined(DEBUG) || defined(DEBUG_AUTOGRAB) fprintf(stderr, "%s: (FocusIn): grabbing\n", __func__); #endif nxagentGrabPointerAndKeyboard(NULL); } /* else { - #ifdef DEBUG + #if defined(DEBUG) || defined(DEBUG_AUTOGRAB) fprintf(stderr, "%s: (FocusIn): ungrabbing\n", __func__); #endif nxagentUngrabPointerAndKeyboard(NULL); @@ -1706,7 +1715,7 @@ FIXME: Don't enqueue the KeyRelease event if the key was XGetInputFocus(nxagentDisplay, &w, &revert_to); if (w != nxagentDefaultWindows[0] && X.xfocus.mode == NotifyWhileGrabbed) { - #ifdef DEBUG + #if defined(DEBUG) || defined(DEBUG_AUTOGRAB) fprintf(stderr, "%s: (FocusOut): ungrabbing\n", __func__); #endif nxagentUngrabPointerAndKeyboard(NULL); -- cgit v1.2.3