diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-07-16 12:05:50 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-07-16 12:05:50 +0200 |
commit | 53f04c9833570cf3c15c3d24cf5bcbbb09f94066 (patch) | |
tree | 01175a3bbba267c812326cd7d4e774d30402ed71 | |
parent | 01f82bd7967a4487ff01fb255f222447edfaf7e8 (diff) |
Add global alt+q/e for zoom
-rw-r--r-- | README.md | 2 | ||||
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | src/main.cpp | 108 |
3 files changed, 68 insertions, 44 deletions
@@ -53,7 +53,7 @@ The video might not be in front of you, so to move the video in front of you, yo * 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. +You can zoom the view with alt + Q/E. You can launch vr-video-player without any arguments to show a list of all arguments. @@ -5,4 +5,4 @@ includes=$(pkg-config --cflags $dependencies) libs=$(pkg-config --libs $dependencies) gcc -c src/window_texture.c -O2 $includes g++ -c src/main.cpp -O2 $includes -g++ -o vr-video-player window_texture.o main.o -s $libs +g++ -o vr-video-player -O2 window_texture.o main.o -s $libs diff --git a/src/main.cpp b/src/main.cpp index dd6eb8c..5ed6335 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,6 +93,8 @@ public: void RunMainLoop(); bool HandleInput(); + void zoom_in(); + void zoom_out(); void ProcessVREvent( const vr::VREvent_t & event ); void RenderFrame(); @@ -254,6 +256,8 @@ private: // X compositor int window_height; Uint32 window_resize_time; bool window_resized = false; + + bool zoom_resize = false; int x_fixes_event_base; int x_fixes_error_base; @@ -629,11 +633,17 @@ static void grabkeys(Display *display) { } } XFreeModifiermap(modmap); + + const int num_keys = 3; + int keys[num_keys] = { XK_F1, XK_q, XK_e }; 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); + for(int i = 0; i < 4; ++i) { + for(int j = 0; j < num_keys; ++j) { + XGrabKey(display, XKeysymToKeycode(display, keys[j]), Mod1Mask|modifiers[i], root_window, False, GrabModeAsync, GrabModeAsync); + } + } } @@ -944,6 +954,38 @@ void CMainApplication::Shutdown() XCloseDisplay(x_display); } +void CMainApplication::zoom_in() { + if(projection_mode == ProjectionMode::SPHERE360) + zoom -= 1.0f; + else + zoom -= 0.01f; + zoom_resize = true; + + std::stringstream strstr; + if(follow_focused) + strstr << "/tmp/vr-video-player_focused"; + else + strstr << "/tmp/vr-video-player_" << src_window_id; + std::ofstream zoomstate(strstr.str()); + zoomstate << zoom; +} + +void CMainApplication::zoom_out() { + if(projection_mode == ProjectionMode::SPHERE360) + zoom += 1.0f; + else + zoom += 0.01f; + zoom_resize = true; + + std::stringstream strstr; + if(follow_focused) + strstr << "/tmp/vr-video-player_focused"; + else + strstr << "/tmp/vr-video-player_" << src_window_id; + std::ofstream zoomstate(strstr.str()); + zoomstate << zoom; +} + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- @@ -951,7 +993,7 @@ bool CMainApplication::HandleInput() { SDL_Event sdlEvent; bool bRet = false; - bool zoom_resize = false; + zoom_resize = false; while ( SDL_PollEvent( &sdlEvent ) != 0 ) { @@ -971,40 +1013,35 @@ bool CMainApplication::HandleInput() } if( sdlEvent.key.keysym.sym == SDLK_q ) { - if(projection_mode == ProjectionMode::SPHERE360) - zoom -= 1.0f; - else - zoom -= 0.01f; - zoom_resize = true; - - std::stringstream strstr; - if(follow_focused) - strstr << "/tmp/vr-video-player_focused"; - else - strstr << "/tmp/vr-video-player_" << src_window_id; - std::ofstream zoomstate(strstr.str()); - zoomstate << zoom; + zoom_in(); } if( sdlEvent.key.keysym.sym == SDLK_e ) { - if(projection_mode == ProjectionMode::SPHERE360) - zoom += 1.0f; - else - zoom += 0.01f; - zoom_resize = true; - - std::stringstream strstr; - if(follow_focused) - strstr << "/tmp/vr-video-player_focused"; - else - strstr << "/tmp/vr-video-player_" << src_window_id; - std::ofstream zoomstate(strstr.str()); - zoomstate << zoom; + zoom_out(); } } } XEvent xev; + + 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 (XCheckTypedEvent(x_display, KeyPress, &xev) && (xev.xkey.state & Mod1Mask)) { + int keysym = XKeycodeToKeysym(x_display, xev.xkey.keycode, 0); + if(keysym == XK_F1) + m_bResetRotation = true; + else if(keysym == XK_q) + zoom_in(); + else if(keysym == XK_e) + zoom_out(); + } if(follow_focused && ((XCheckTypedWindowEvent(x_display, DefaultRootWindow(x_display), PropertyNotify, &xev) && xev.xproperty.atom == net_active_window_atom) || !focused_window_set)) { focused_window_set = true; @@ -1036,19 +1073,6 @@ 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)); |