Skip to content

Commit 98d4176

Browse files
committed
Add inputlock
1 parent 03966df commit 98d4176

File tree

5 files changed

+188
-24
lines changed

5 files changed

+188
-24
lines changed

etc/keystrokes.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
<keystroke action="viewport_move_up" Control="1" AltMeta="1" key="Up" />
1717
<keystroke action="viewport_move_right" Control="1" AltMeta="1" key="Right" />
1818
<keystroke action="viewport_move_down" Control="1" AltMeta="1" key="Down" />
19+
<keystroke action="autograb" Control="1" AltMeta="1" key="g" />
20+
<keystroke action="lockinput" Control="1" AltMeta="1" key="x" />
1921
</keystrokes>

nx-X11/programs/Xserver/hw/nxagent/Events.c

Lines changed: 167 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,12 @@ static void nxagentSwitchDeferMode(void)
690690
}
691691
}
692692

693-
static autograb = False;
693+
static Bool autograb = False;
694+
static Bool focus = False;
694695

695-
static void nxagentGrab(void)
696+
static void nxagentAutoGrab(void)
696697
{
698+
fprintf(stderr, "autograb\n");
697699
if (!autograb)
698700
nxagentGrabPointerAndKeyboard(NULL);
699701
else
@@ -702,6 +704,19 @@ static void nxagentGrab(void)
702704
autograb = !autograb;
703705
}
704706

707+
static Bool inputlock = False;
708+
709+
static void nxagentLockInput(void)
710+
{
711+
fprintf(stderr, "inputlock\n");
712+
/* if (!inputlock)
713+
nxagentGrabPointerAndKeyboard(NULL);
714+
else
715+
nxagentUngrabPointerAndKeyboard(NULL);
716+
*/
717+
inputlock = !inputlock;
718+
}
719+
705720
static Bool nxagentExposurePredicate(Display *display, XEvent *event, XPointer window)
706721
{
707722
/*
@@ -1095,9 +1110,15 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
10951110

10961111
break;
10971112
}
1098-
case doGrab:
1113+
case doAutoGrab:
10991114
{
1100-
nxagentGrab();
1115+
nxagentAutoGrab();
1116+
1117+
break;
1118+
}
1119+
case doLockInput:
1120+
{
1121+
nxagentLockInput();
11011122

11021123
break;
11031124
}
@@ -1528,9 +1549,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was
15281549
{
15291550
WindowPtr pWin;
15301551

1531-
#ifdef TEST
1552+
#ifdef TEST
15321553
fprintf(stderr, "nxagentDispatchEvents: Going to handle new FocusIn event.\n");
1533-
#endif
1554+
#endif
15341555

15351556
/*
15361557
* Here we change the focus state in the agent.
@@ -1545,23 +1566,74 @@ FIXME: Don't enqueue the KeyRelease event if the key was
15451566
RevertToPointerRoot, GetTimeInMillis(), False);
15461567
}
15471568

1569+
1570+
switch (X.xfocus.mode)
1571+
{
1572+
case NotifyNormal: fprintf(stderr, "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyNormal\n"); break;
1573+
case NotifyWhileGrabbed: fprintf(stderr, "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyWhileGrabbed\n"); break;
1574+
case NotifyGrab: fprintf(stderr, "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyGrab\n"); break;
1575+
case NotifyUngrab: fprintf(stderr, "nxagentDispatchEvents(FocusIn): X.xfocus.mode NotifyUngrab\n"); break;
1576+
}
1577+
1578+
/* if (autograb)
1579+
fprintf(stderr, "nxagentDispatchEvents(FocusIn): autogab is on\n");
1580+
else
1581+
fprintf(stderr, "nxagentDispatchEvents(FocusIn): autogab is off\n");
1582+
*/
15481583
if (X.xfocus.detail != NotifyInferior)
15491584
{
15501585
pScreen = nxagentScreen(X.xfocus.window);
1551-
1586+
fprintf(stderr, "nxagentDispatchEvents(FocusIn): X.xfocus.window %d\n", (int)X.xfocus.window);
15521587
if (pScreen)
15531588
{
15541589
nxagentDirectInstallColormaps(pScreen);
15551590
}
1591+
/* if (X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode != NotifyNormal)*/
1592+
/* if (autograb && X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode == NotifyNormal)
1593+
{
1594+
fprintf(stderr, "nxagentDispatchEvents(FocusIn): grabbing\n");
1595+
nxagentGrabPointerAndKeyboard(NULL);
1596+
}*/
15561597
}
15571598

1599+
if (autograb)
1600+
{
1601+
if (X.xfocus.window == nxagentDefaultWindows[0] && X.xfocus.mode == NotifyNormal)
1602+
{
1603+
focus = True;
1604+
fprintf(stderr, "nxagentDispatchEvents(FocusIn): grabbing\n");
1605+
nxagentGrabPointerAndKeyboard(NULL);
1606+
{
1607+
#include <nx-X11/Xatom.h>
1608+
XTextProperty name = {
1609+
.value = (unsigned char *) "grabbed",
1610+
.encoding = XA_STRING,
1611+
.format = 8,
1612+
.nitems = strlen((char *) name.value)
1613+
};
1614+
XSetWMName(nxagentDisplay, nxagentDefaultWindows[0], &name);
1615+
}
1616+
XGrabPointer(nxagentDisplay,nxagentDefaultWindows[0], True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask |EnterWindowMask |
1617+
LeaveWindowMask,GrabModeAsync,GrabModeAsync, nxagentDefaultWindows[0], None, CurrentTime);
1618+
1619+
}
1620+
}
15581621
break;
15591622
}
15601623
case FocusOut:
15611624
{
1562-
#ifdef TEST
1625+
#ifdef TEST
15631626
fprintf(stderr, "nxagentDispatchEvents: Going to handle new FocusOut event.\n");
1564-
#endif
1627+
1628+
switch (X.xfocus.mode)
1629+
{
1630+
case NotifyNormal: fprintf(stderr, "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyNormal\n"); break;
1631+
case NotifyWhileGrabbed: fprintf(stderr, "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyWhileGrabbed\n"); break;
1632+
case NotifyGrab: fprintf(stderr, "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyGrab\n"); break;
1633+
case NotifyUngrab: fprintf(stderr, "nxagentDispatchEvents(FocusOut): X.xfocus.mode NotifyUngrab\n"); break;
1634+
}
1635+
#endif
1636+
15651637

15661638
if (X.xfocus.detail != NotifyInferior)
15671639
{
@@ -1572,7 +1644,8 @@ FIXME: Don't enqueue the KeyRelease event if the key was
15721644
nxagentDirectUninstallColormaps(pScreen);
15731645
}
15741646
}
1575-
1647+
/* nxagentUngrabPointerAndKeyboard(NULL);*/
1648+
15761649
#ifdef NXAGENT_FIXKEYS
15771650

15781651
{
@@ -1632,7 +1705,43 @@ FIXME: Don't enqueue the KeyRelease event if the key was
16321705
}
16331706

16341707
#endif /* NXAGENT_FIXKEYS */
1635-
1708+
1709+
if (autograb)
1710+
{
1711+
XlibWindow w;
1712+
int revert_to;
1713+
int ret;
1714+
fprintf(stderr, "FocusOut: getting input focus window ... ");
1715+
ret = XGetInputFocus(nxagentDisplay, &w, &revert_to); // see man
1716+
if(ret == BadValue){
1717+
fprintf(stderr,"FocusOut: BadValue\n");
1718+
} else if(ret == BadWindow){
1719+
fprintf(stderr,"FocusOut: BadWindow\n");
1720+
}else if(w == None){
1721+
fprintf(stderr, "FocusOut: no focus window\n");
1722+
}else{
1723+
fprintf(stderr, "FocusOut: success (window: %d)\n", (int)w);
1724+
/* fprintf(stderr, "DefaultRootWindow: %d\n" ,(int)DefaultRootWindow(nxagentDisplay));
1725+
fprintf(stderr, "DefaultWindows: %d\n" ,(int)nxagentDefaultWindows[0]);*/
1726+
}
1727+
1728+
1729+
if (w != nxagentDefaultWindows[0] && X.xfocus.mode == NotifyWhileGrabbed)
1730+
{
1731+
focus = False;
1732+
fprintf(stderr, "nxagentDispatchEvents(FocusOut): ungrabbing\n");
1733+
nxagentUngrabPointerAndKeyboard(NULL);
1734+
#include <nx-X11/Xatom.h>
1735+
XTextProperty name = {
1736+
.value = nxagentWindowName,
1737+
.encoding = XA_STRING,
1738+
.format = 8,
1739+
.nitems = strlen((char *) name.value)
1740+
};
1741+
XSetWMName(nxagentDisplay, nxagentDefaultWindows[0], &name);
1742+
1743+
}
1744+
}
16361745
break;
16371746
}
16381747
case KeymapNotify:
@@ -1714,9 +1823,43 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17141823
nxagentScreenTrap = 0;
17151824
}
17161825

1717-
if (autograb || (nxagentOption(Fullscreen) == 1 &&
1826+
{
1827+
XlibWindow w;
1828+
int revert_to;
1829+
int ret;
1830+
fprintf(stderr, "EnterNotify: getting input focus window ... ");
1831+
ret = XGetInputFocus(nxagentDisplay, &w, &revert_to); // see man
1832+
if(ret == BadValue){
1833+
fprintf(stderr,"EnterNotify: BadValue\n");
1834+
} else if(ret == BadWindow){
1835+
fprintf(stderr,"EnterNotify: BadWindow\n");
1836+
}else if(w == None){
1837+
fprintf(stderr, "EnterNotify: no focus window\n");
1838+
}else{
1839+
fprintf(stderr, "EnterNotify: success (window: %d)\n", (int)w);
1840+
/* fprintf(stderr, "DefaultRootWindow: %d\n" ,(int)DefaultRootWindow(nxagentDisplay));
1841+
fprintf(stderr, "DefaultWindows: %d\n" ,(int)nxagentDefaultWindows[0]);*/
1842+
}
1843+
}
1844+
/* if (autograb)
1845+
{
1846+
if (X.xcrossing.focus)
1847+
{
1848+
fprintf(stderr, "nxagentDispatchEvents(EnterNotify): xcrossing.focus is True\n");
1849+
fprintf(stderr, "nxagentDispatchEvents(EnterNotify): grabbing\n");
1850+
nxagentGrabPointerAndKeyboard(&X);
1851+
}
1852+
else
1853+
{
1854+
fprintf(stderr, "nxagentDispatchEvents(EnterNotify): xcrossing.focus is False\n");
1855+
}
1856+
}
1857+
*/
1858+
/* if (autograb || (nxagentOption(Fullscreen) == 1 &&*/
1859+
/*if (w == nxagentDefaultWindows[0] || (nxagentOption(Fullscreen) == 1 &&*/
1860+
if (nxagentOption(Fullscreen) == 1 &&
17181861
X.xcrossing.window == nxagentFullscreenWindow &&
1719-
X.xcrossing.detail != NotifyInferior))
1862+
X.xcrossing.detail != NotifyInferior)
17201863
{
17211864
fprintf(stderr, "nxagentDispatchEvents(EnterNotify): grabbing\n");
17221865
nxagentGrabPointerAndKeyboard(&X);
@@ -1769,10 +1912,10 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17691912
nxagentLastEnteredWindow = NULL;
17701913
}
17711914

1772-
if (X.xcrossing.window == nxagentDefaultWindows[0] &&
1915+
/* if (X.xcrossing.window == nxagentDefaultWindows[0] &&
17731916
X.xcrossing.detail != NotifyInferior &&
17741917
X.xcrossing.mode == NotifyNormal)
1775-
{
1918+
{*/
17761919
/* if (!autograb)
17771920
{
17781921
fprintf(stderr, "nxagentDispatchEvents: no autograb -> ungrabbing\n");
@@ -1781,9 +1924,9 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17811924
else
17821925
fprintf(stderr, "nxagentDispatchEvents: autograb -> no ungrabbing\n");
17831926
*/
1784-
fprintf(stderr, "nxagentDispatchEvents(LeaveNotify): ungrabbing\n");
1927+
/* fprintf(stderr, "nxagentDispatchEvents(LeaveNotify): ungrabbing\n");
17851928
nxagentUngrabPointerAndKeyboard(&X);
1786-
}
1929+
}*/
17871930

17881931
if (X.xcrossing.detail != NotifyInferior)
17891932
{
@@ -1795,6 +1938,13 @@ FIXME: Don't enqueue the KeyRelease event if the key was
17951938
}
17961939
}
17971940

1941+
1942+
/* if (!focus)
1943+
{
1944+
fprintf(stderr, "nxagentDispatchEvents(LeaveNotify): ungrabbing\n");
1945+
nxagentUngrabPointerAndKeyboard(&X);
1946+
}
1947+
*/
17981948
nxagentInputEvent = 1;
17991949

18001950
break;

nx-X11/programs/Xserver/hw/nxagent/Events.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ enum HandleEventResult
5252
doViewportDown,
5353
doSwitchResizeMode,
5454
doSwitchDeferMode,
55-
doGrab
55+
doAutoGrab,
56+
doLockInput
5657
};
5758

5859
extern CARD32 nxagentLastEventTime;

nx-X11/programs/Xserver/hw/nxagent/Keystroke.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ char * nxagentSpecialKeystrokeNames[] = {
9191
"viewport_move_right",
9292
"viewport_move_down",
9393

94-
"grab",
94+
"autograb",
95+
"lockinput",
96+
9597
NULL,
9698
};
9799

@@ -140,6 +142,8 @@ struct nxagentSpecialKeystrokeMap default_map[] = {
140142
{KEYSTROKE_END_MARKER, 0, False, NoSymbol},
141143
{KEYSTROKE_AUTOGRAB, ControlMask, True, XK_G},
142144
{KEYSTROKE_AUTOGRAB, ControlMask, True, XK_g},
145+
{KEYSTROKE_LOCKINPUT, ControlMask, True, XK_C},
146+
{KEYSTROKE_LOCKINPUT, ControlMask, True, XK_c},
143147
{KEYSTROKE_END_MARKER, 0, 0, 0},
144148
};
145149
struct nxagentSpecialKeystrokeMap *map = default_map;
@@ -410,6 +414,9 @@ static enum nxagentSpecialKeystroke find_keystroke(XKeyEvent *X)
410414
&keysyms_per_keycode_return);
411415

412416
while (cur->stroke != KEYSTROKE_END_MARKER) {
417+
#ifdef DEBUG
418+
fprintf(stderr,"%s: keysym %d stroke %d, type %d\n", __func__, cur->keysym, cur->stroke, X->type);
419+
#endif
413420
if (cur->keysym == keysym[0] && modifier_matches(cur->modifierMask, cur->modifierAltMeta, X->state)) {
414421
free(keysym);
415422
return cur->stroke;
@@ -572,8 +579,11 @@ Bool nxagentCheckSpecialKeystroke(XKeyEvent *X, enum HandleEventResult *result)
572579
*result = doViewportMoveDown;
573580
}
574581
break;
575-
case KEYSTROKE_GRAB:
576-
*result = doGrab;
582+
case KEYSTROKE_AUTOGRAB:
583+
*result = doAutoGrab;
584+
break;
585+
case KEYSTROKE_LOCKINPUT:
586+
*result = doLockInput;
577587
break;
578588
case KEYSTROKE_NOTHING: /* do nothing. difference to KEYSTROKE_IGNORE is the return value */
579589
case KEYSTROKE_END_MARKER: /* just to make gcc STFU */

nx-X11/programs/Xserver/hw/nxagent/Keystroke.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ enum nxagentSpecialKeystroke {
6464
KEYSTROKE_VIEWPORT_MOVE_RIGHT = 19,
6565
KEYSTROKE_VIEWPORT_MOVE_DOWN = 20,
6666

67-
KEYSTROKE_GRAB = 21,
67+
KEYSTROKE_AUTOGRAB = 21,
68+
KEYSTROKE_LOCKINPUT = 22,
6869

69-
KEYSTROKE_NOTHING = 22,
70+
KEYSTROKE_NOTHING = 23,
7071

7172
/* insert more here, increment KEYSTROKE_MAX accordingly.
7273
* then update string translation below */
7374

74-
KEYSTROKE_MAX=23,
75+
KEYSTROKE_MAX=24,
7576
};
7677

7778
struct nxagentSpecialKeystrokeMap {

0 commit comments

Comments
 (0)