Skip to content

Commit 4b32ee4

Browse files
committed
Refactor InputLock
1 parent 4b8c7b5 commit 4b32ee4

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

doc/nxagent/README.keystrokes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ reread_keystrokes
105105
session.
106106
autograb
107107
enable/disable autograb mode
108-
lockinput
108+
inputlock
109109
lock/unlock pointer within nxagent window
110110

111111
Only in builds with certain debugging options enabled, ignored otherwise:

etc/keystrokes.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
<keystroke action="viewport_move_down" Control="1" AltMeta="1" key="Down" />
1919
<keystroke action="reread_keystrokes" Control="1" AltMeta="1" key="k" />
2020
<keystroke action="autograb" Control="1" AltMeta="1" key="g" />
21-
<keystroke action="lockinput" Control="1" AltMeta="1" key="c" />
21+
<keystroke action="inputlock" Control="1" AltMeta="1" key="c" />
2222
</keystrokes>

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

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -770,35 +770,41 @@ static void nxagentToggleAutoGrab(void)
770770
}
771771
}
772772

773-
/* TODO: drop inputlock when switching to Fullscreen */
774-
static void nxagentLockInput(void)
773+
static void nxagentEnableInputlock(void)
775774
{
776-
#ifdef DEBUG
777-
if (inputlock)
778-
fprintf(stderr, "releasing inputlock\n");
779-
else
780-
fprintf(stderr, "activating inputlock\n");
781-
#endif
775+
#ifdef DEBUG
776+
fprintf(stderr, "activating inputlock\n");
777+
#endif
778+
setWinNameSuffix("input locked");
779+
XGrabPointer(nxagentDisplay,nxagentDefaultWindows[0], True,
780+
ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask,
781+
GrabModeAsync, GrabModeAsync, nxagentDefaultWindows[0], None, CurrentTime);
782+
inputlock = True;
783+
}
784+
785+
static void nxagentDisableInputlock(void)
786+
{
787+
#ifdef DEBUG
788+
fprintf(stderr, "deactivating inputlock\n");
789+
#endif
790+
nxagentUngrabPointerAndKeyboard(NULL);
791+
XTextProperty name = {
792+
.value = (unsigned char *)nxagentWindowName,
793+
.encoding = XA_STRING,
794+
.format = 8,
795+
.nitems = strlen((char *) name.value)
796+
};
797+
setWinNameSuffix(NULL);
798+
inputlock = False;
799+
}
782800

801+
/* TODO: drop inputlock when switching to Fullscreen */
802+
static void nxagentToggleInputLock(void)
803+
{
783804
if (!inputlock)
784-
{
785-
setWinNameSuffix("input locked");
786-
XGrabPointer(nxagentDisplay,nxagentDefaultWindows[0], True,
787-
ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask,
788-
GrabModeAsync, GrabModeAsync, nxagentDefaultWindows[0], None, CurrentTime);
789-
}
805+
nxagentEnableInputlock();
790806
else
791-
{
792-
nxagentUngrabPointerAndKeyboard(NULL);
793-
XTextProperty name = {
794-
.value = (unsigned char *)nxagentWindowName,
795-
.encoding = XA_STRING,
796-
.format = 8,
797-
.nitems = strlen((char *) name.value)
798-
};
799-
setWinNameSuffix(NULL);
800-
}
801-
inputlock = !inputlock;
807+
nxagentDisableInputlock();
802808
}
803809

804810
static Bool nxagentExposurePredicate(Display *display, XEvent *event, XPointer window)
@@ -1200,9 +1206,9 @@ void nxagentDispatchEvents(PredicateFuncPtr predicate)
12001206

12011207
break;
12021208
}
1203-
case doLockInput:
1209+
case doInputLock:
12041210
{
1205-
nxagentLockInput();
1211+
nxagentToggleInputLock();
12061212

12071213
break;
12081214
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum HandleEventResult
5353
doSwitchResizeMode,
5454
doSwitchDeferMode,
5555
doAutoGrab,
56-
doLockInput
56+
doInputLock
5757
};
5858

5959
extern CARD32 nxagentLastEventTime;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ char * nxagentSpecialKeystrokeNames[] = {
9393
"reread_keystrokes",
9494

9595
"autograb",
96-
"lockinput",
96+
"inputlock",
9797

9898
NULL,
9999
};
@@ -131,7 +131,7 @@ struct nxagentSpecialKeystrokeMap default_map[] = {
131131
{KEYSTROKE_VIEWPORT_MOVE_DOWN, ControlMask | ShiftMask, True, XK_KP_Down},
132132
{KEYSTROKE_REREAD_KEYSTROKES, ControlMask, True, XK_k},
133133
{KEYSTROKE_AUTOGRAB, ControlMask, True, XK_g},
134-
{KEYSTROKE_LOCKINPUT, ControlMask, True, XK_c},
134+
{KEYSTROKE_INPUTLOCK, ControlMask, True, XK_c},
135135
{KEYSTROKE_END_MARKER, 0, False, NoSymbol},
136136
};
137137
struct nxagentSpecialKeystrokeMap *map = default_map;
@@ -597,8 +597,8 @@ Bool nxagentCheckSpecialKeystroke(XKeyEvent *X, enum HandleEventResult *result)
597597
case KEYSTROKE_AUTOGRAB:
598598
*result = doAutoGrab;
599599
break;
600-
case KEYSTROKE_LOCKINPUT:
601-
*result = doLockInput;
600+
case KEYSTROKE_INPUTLOCK:
601+
*result = doInputLock;
602602
break;
603603
case KEYSTROKE_NOTHING: /* do nothing. difference to KEYSTROKE_IGNORE is the return value */
604604
case KEYSTROKE_END_MARKER: /* just to make gcc STFU */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum nxagentSpecialKeystroke {
6767
KEYSTROKE_REREAD_KEYSTROKES = 21,
6868

6969
KEYSTROKE_AUTOGRAB = 22,
70-
KEYSTROKE_LOCKINPUT = 23,
70+
KEYSTROKE_INPUTLOCK = 23,
7171

7272
KEYSTROKE_NOTHING = 24,
7373

0 commit comments

Comments
 (0)