aboutsummaryrefslogtreecommitdiff
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
parentc46c62b33961f9922f7f1eb2c1cb43f253f4571d (diff)
Add alt+f1 global hotkey to reset window rotation (keyboard mapping update not tested)
-rw-r--r--.gitignore1
-rw-r--r--README.md10
-rw-r--r--src/main.cpp37
3 files changed, 43 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index dbb08f9..1f413f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ tests/compile_commands.json
vr-video-player
window_texture.o
main.o
+.clangd/
diff --git a/README.md b/README.md
index 8af999a..9bc6c8e 100644
--- a/README.md
+++ b/README.md
@@ -35,10 +35,12 @@ if you want to watch a regular non-stereoscopic video, then run:
```
and click on your video player.
-The video might not be in front of you, so to move the video in front of you, you can pull the trigger on the vr controller or press the "W" key while the vr-video-player is focused or press the select/back button on an xbox controller while the application is focused. You can also send the SIGUSR1 signal to the application, using the following command:
-```
-killall -USR1 vr-video-player`
-```
+The video might not be in front of you, so to move the video in front of you, you can do any of the following:
+* Pull the trigger on the vr controller
+* Press "Alt + F1"
+* Press the "W" key while the vr-video-player is focused
+* Press the select/back button on an xbox controller while the application is focused
+* Send a SIGUSR1 signal to the application, using the following command: `killall -USR1 vr-video-player`
You can zoom the view with the Q and E keys when the vr-video-player is focused.
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));