From 48124315356b105cd835dc3d76458fe07a132dc2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 29 Aug 2020 21:10:30 +0200 Subject: Add alt+f1 global hotkey to reset window rotation (keyboard mapping update not tested) --- src/main.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 62450ee..c646e82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -582,6 +583,24 @@ static int xerror(Display *dpy, XErrorEvent *ee) { return 0; /* may call exit */ /* TODO: xerrorxlib(dpy, ee); */ } +static void grabkeys(Display *display) { + unsigned int numlockmask = 0; + KeyCode numlock_keycode = XKeysymToKeycode(display, XK_Num_Lock); + XModifierKeymap *modmap = XGetModifierMapping(display); + for(int i = 0; i < 8; ++i) { + for(int j = 0; j < modmap->max_keypermod; ++j) { + if(modmap->modifiermap[i * modmap->max_keypermod + j] == numlock_keycode) + numlockmask = (1 << i); + } + } + XFreeModifiermap(modmap); + + Window root_window = DefaultRootWindow(display); + unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; + for(int i = 0; i < 4; ++i) + XGrabKey(display, XKeysymToKeycode(display, XK_F1), Mod1Mask|modifiers[i], root_window, False, GrabModeAsync, GrabModeAsync); +} + //----------------------------------------------------------------------------- // Purpose: @@ -607,7 +626,10 @@ bool CMainApplication::BInit() window_resize_time = SDL_GetTicks(); window_resized = false; - XSelectInput(x_display, src_window_id, StructureNotifyMask); + grabkeys(x_display); + XSelectInput(x_display, src_window_id, StructureNotifyMask|KeyPressMask|KeyReleaseMask); + Bool sup = False; + XkbSetDetectableAutoRepeat(x_display, True, &sup); if(!XFixesQueryExtension(x_display, &x_fixes_event_base, &x_fixes_error_base)) { fprintf(stderr, "Your x11 server is missing the xfixes extension\n"); @@ -963,6 +985,19 @@ bool CMainApplication::HandleInput() } } + if (XCheckTypedEvent(x_display, KeyPress, &xev) && XKeycodeToKeysym(x_display, xev.xkey.keycode, 0) == XK_F1 && (xev.xkey.state & Mod1Mask)) { + m_bResetRotation = true; + } + + if(XCheckTypedEvent(x_display, MappingNotify, &xev)) { + XMappingEvent *mapping_ev = &xev.xmapping; + XRefreshKeyboardMapping(mapping_ev); + if(mapping_ev->request == MappingKeyboard) { + fprintf(stderr, "Update keyboard mapping!\n"); + grabkeys(x_display); + } + } + if(!cursor_image_set) { cursor_image_set = true; SetCursorFromX11CursorImage(XFixesGetCursorImage(x_display)); -- cgit v1.2.3