aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2017-03-05 23:51:24 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2019-08-27 14:10:16 +0200
commit58183b7ceacb774b018bd61e6ad6c127662c7fcb (patch)
treec363adf91d180fcd3364f14495034bd9a03b1246 /nx-X11/programs/Xserver
parentdaa50fd80ed5f777754a51c0e2b4869ba083a337 (diff)
downloadnx-libs-58183b7ceacb774b018bd61e6ad6c127662c7fcb.tar.gz
nx-libs-58183b7ceacb774b018bd61e6ad6c127662c7fcb.tar.bz2
nx-libs-58183b7ceacb774b018bd61e6ad6c127662c7fcb.zip
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.
Diffstat (limited to 'nx-X11/programs/Xserver')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Events.c84
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Events.h3
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Keystroke.c9
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Keystroke.h2
4 files changed, 93 insertions, 5 deletions
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 */