aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-08-29 21:10:30 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-29 21:10:30 +0200
commit48124315356b105cd835dc3d76458fe07a132dc2 (patch)
tree450193f80110abebad8a37f03e0b026790849a2d /src
parentc46c62b33961f9922f7f1eb2c1cb43f253f4571d (diff)
Add alt+f1 global hotkey to reset window rotation (keyboard mapping update not tested)
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp37
1 files changed, 36 insertions, 1 deletions
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 <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
#include <X11/extensions/Xfixes.h>
#include <X11/Xproto.h>
#include <GL/glxproto.h>
@@ -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));