Following patch adds the ability to switch between displays from a
keybinding
and does not break any old functionality nor default settings.
diff --unified --recursive x2x-1.27.orig/x2x.1 x2x-1.27/x2x.1
--- x2x-1.27.orig/x2x.1 Mon Jan 29 19:08:40 2001
+++ x2x-1.27/x2x.1 Mon Jan 29 19:06:01 2001
@@ -156,6 +156,9 @@
.TP
.B \-label \fIlabel\fP
Override the title of the control window (useful when running over ssh).
+.TP
+.B \-grabkey \fkeysym\fP \fmodifiermask\fP
+Grab a keysym to use for switching between displays.
.IP
.SH AUTHOR
David Chaiken
diff --unified --recursive x2x-1.27.orig/x2x.c x2x-1.27/x2x.c
--- x2x-1.27.orig/x2x.c Mon Jan 29 19:08:40 2001
+++ x2x-1.27/x2x.c Mon Jan 29 19:08:01 2001
@@ -237,6 +237,9 @@
static Bool doBtnBlock = False;
static int nButtons = 0;
static KeySym buttonmap[N_BUTTONS + 1][MAX_BUTTONMAPEVENTS + 1];
+static int doGrabKey = 0;
+static KeySym grabkeysym;
+static unsigned int grabmod = 0;
/**********
* main
@@ -268,6 +271,12 @@
sleep(10);
} /* END while fromDpy */
+ if (doGrabKey)
+ {
+ XGrabKey(fromDpy,XKeysymToKeycode(fromDpy,grabkeysym),grabmod,
+ DefaultRootWindow(fromDpy),True,GrabModeAsync,GrabModeAsync);
+ }
+
/* toDpy is always the first shadow */
pShadow = (PSHADOW)malloc(sizeof(SHADOW));
pShadow->name = toDpyName;
@@ -496,6 +505,15 @@
triggerw = atoi(argv[arg]);
} else if (!strcasecmp(argv[arg], "-copyright")) {
printf(lawyerese);
+ } else if (!strcasecmp(argv[arg], "-grabkey")) {
+ if (++arg >= argc) Usage();
+ if ((grabkeysym = XStringToKeysym(argv[arg])) == NoSymbol)
+ printf("x2x: warning: can't translate %s\n", argv[arg]);
+ else {
+ if (++arg >= argc) Usage();
+ doGrabKey = 1;
+ grabmod = atoi(argv[arg]);
+ }
} else {
Usage();
} /* END if... */
@@ -525,6 +543,7 @@
printf(" -sticky <sticky key>\n");
printf(" -label <LABEL>\n");
printf(" -buttonmap <button#> \"<keysym> ...\"\n");
+ printf(" -grabkey <keysym> <modifiermask>\n");
exit(4);
} /* END Usage */
@@ -997,6 +1016,11 @@
XSAVECONTEXT(toDpy, propWin, SelectionClear,
ProcessSelectionClear);
} /* END if doSel */
+ if (doGrabKey) {
+ XSAVECONTEXT(fromDpy, None, KeyPress, ProcessKeyEvent);
+ XSAVECONTEXT(fromDpy, None, KeyRelease, ProcessKeyEvent);
+ }
+
} /* END RegisterEventHandlers */
static Bool ProcessEvent(dpy, pDpyInfo)
@@ -1010,6 +1034,7 @@
#define XFINDCONTEXT(A, B, C, D) XFindContext(A, B, C, (XPointer *)(D))
XNextEvent(dpy, &ev);
+
handler = 0;
if ((!XFINDCONTEXT(dpy, pEv->window, pEv->type, &handler)) ||
(!XFINDCONTEXT(dpy, None, pEv->type, &handler))) {
@@ -1240,7 +1265,7 @@
#endif
break;
} /* END switch button */
- if (state) { /* then more than one button pressed */
+ if (state && !doGrabKey) { /* then more than one button pressed */
#ifdef DEBUG
printf("awaiting button release before disconnecting\n");
#endif
@@ -1335,6 +1360,19 @@
for (pSticky = stickies; pSticky; pSticky = pSticky->pNext)
if (keysym == pSticky->keysym)
break;
+
+ if (doGrabKey && XKeycodeToKeysym(dpy,pEv->keycode,0) == grabkeysym
+ && pEv->state == grabmod) {
+ if (pEv->type == KeyRelease) {
+ if (pDpyInfo->mode == X2X_DISCONNECTED) {
+ DoConnect(pDpyInfo);
+ } else if (pDpyInfo->mode == X2X_CONNECTED) {
+ DoDisconnect(pDpyInfo);
+ }
+ }
+
+ return False;
+ }
if (pSticky) {
for (pShadow = shadows; pShadow; pShadow = pShadow->pNext) {