From 5ff9125db3a7f8f545cbfb5f7bf452c8b0db4d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 29 Jun 2021 00:23:46 +0200 Subject: Raise window on next/prev key release --- src/event.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/event.c b/src/event.c index f88e2a5..8850665 100644 --- a/src/event.c +++ b/src/event.c @@ -30,6 +30,9 @@ #define MIN_TIME_DELTA 50 +/** Whether a window switch is active. */ +int switching = 0; + static void Signal(); static void DispatchBorderButtonEvent(const XButtonEvent *event, ClientNode *np); @@ -44,6 +47,7 @@ static void HandleMapRequest(const XMapEvent *event); static void HandleUnmapNotify(const XUnmapEvent *event); static void HandleButtonEvent(const XButtonEvent *event); static void HandleKeyPress(const XKeyEvent *event); +static void HandleKeyRelease(const XKeyEvent *event); static void HandleEnterNotify(const XCrossingEvent *event); static void HandleLeaveNotify(const XCrossingEvent *event); static void HandleMotionNotify(const XMotionEvent *event); @@ -207,6 +211,9 @@ void ProcessEvent(XEvent *event) { case KeyPress: HandleKeyPress(&event->xkey); break; + case KeyRelease: + HandleKeyRelease(&event->xkey); + break; case EnterNotify: HandleEnterNotify(&event->xcrossing); break; @@ -219,7 +226,6 @@ void ProcessEvent(XEvent *event) { break; case DestroyNotify: case Expose: - case KeyRelease: case ConfigureNotify: break; default: @@ -343,6 +349,12 @@ void HandleKeyPress(const XKeyEvent *event) { np = GetActiveClient(); +#define SWITCH() do { \ + switching = 1; \ + JXGrabKeyboard(display, rootWindow, False, \ + GrabModeAsync, GrabModeAsync, CurrentTime); \ + } while (0) + switch(key & 0xFF) { case KEY_EXEC: RunKeyCommand(event); @@ -362,15 +374,19 @@ void HandleKeyPress(const XKeyEvent *event) { break; case KEY_NEXT: FocusNext(); + SWITCH(); break; case KEY_NEXT_STACKED: FocusNextStackedCircular(); + SWITCH(); break; case KEY_PREV: FocusPrevious(); + SWITCH(); break; case KEY_PREV_STACKED: FocusPreviousStackedCircular(); + SWITCH(); break; case KEY_RAISE: if(np) { @@ -432,6 +448,30 @@ void HandleKeyPress(const XKeyEvent *event) { } +/**************************************************************************** + ****************************************************************************/ +void HandleKeyRelease(const XKeyEvent *event) { + ClientNode *np; + KeyType key; + + key = GetKey(event); + + switch(key & 0xFF) { + case KEY_NEXT: + case KEY_PREV: + case KEY_NEXT_STACKED: + case KEY_PREV_STACKED: + break; + default: + if(switching) { + switching = 0; + np = GetActiveClient(); + if (np) RaiseClient(np); + JXUngrabKeyboard(display, CurrentTime); + } + } +} + /**************************************************************************** ****************************************************************************/ void HandleConfigureRequest(const XConfigureRequestEvent *event) { -- cgit v1.2.3