aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWebFreak001 <gh@webfreak.org>2020-06-12 23:01:30 +0200
committerdec05eba <dec05eba@protonmail.com>2020-06-13 07:21:25 +0200
commitaf94cbca3243c21fe03d7895da439532ce4bc24e (patch)
tree943ddb92bb7b8964776d98cf1e4744a13ba5fa17 /src
parent6bde0531a61212a075490d2701d44ede7b35211b (diff)
add ability to reset rotation via signal + gamepad
The gamepad change isn't the best as it requires the window to be focused, but it allows to use a wireless gamepad to reset the rotation and position like using the w key on the keyboard. I currently hardcoded the reset button to 6 on a joystick, which was equal to the select button on my steam controller using sc-controller simulating an xbox controller. Maybe the controller update isn't quite fit to stay and should use the VR controllers instead & work without focus. The more interesting part of this patch is adding signal handling of SIGUSR1 or SIGUSR2 to do the same thing. This allows to simply run a command like `killall -USR1 vr-video-player` to reset the rotation and position even without window focus. This is especially useful for example for adding a custom command action to KDE connect so you can reset the VR view from your phone without needing to have any special software. However I believe even this signal handling should eventually be replaced with some more advanced API like dbus or a unix socket to also allow for more advanced features like changing tracked windows on the fly.
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index dddee0e..e2627e0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -53,6 +53,7 @@ extern "C" {
#include <vector>
#include <unistd.h>
+#include <signal.h>
#include <libgen.h>
#ifndef _countof
@@ -107,6 +108,7 @@ public:
void ProcessVREvent( const vr::VREvent_t & event );
void RenderFrame();
+ void ResetRotation();
void SetupScene();
void AddCubeToScene( const glm::mat4 &mat, std::vector<float> &vertdata );
void AddCubeVertex( float fl0, float fl1, float fl2, float fl3, float fl4, std::vector<float> &vertdata );
@@ -543,7 +545,7 @@ bool CMainApplication::BInit()
XSelectInput(x_display, src_window_id, StructureNotifyMask);
- if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 )
+ if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ) < 0 )
{
printf("%s - SDL could not initialize! SDL Error: %s\n", __FUNCTION__, SDL_GetError());
return false;
@@ -978,6 +980,11 @@ void CMainApplication::RunMainLoop()
SDL_StartTextInput();
SDL_ShowCursor( SDL_DISABLE );
+ SDL_Joystick *controller = SDL_JoystickOpen(0);
+ if (!controller)
+ fprintf(stderr, "Could not open gamecontroller: %s\n", SDL_GetError());
+
+
while ( !bQuit )
{
bQuit = HandleInput();
@@ -985,6 +992,9 @@ void CMainApplication::RunMainLoop()
RenderFrame();
}
+ if (controller)
+ SDL_JoystickClose(controller);
+
SDL_StopTextInput();
}
@@ -1069,6 +1079,14 @@ void CMainApplication::RenderFrame()
UpdateHMDMatrixPose();
}
+//-----------------------------------------------------------------------------
+// Purpose: resets rotation & position of the screen
+//-----------------------------------------------------------------------------
+void CMainApplication::ResetRotation()
+{
+ m_bResetRotation = true;
+}
+
//-----------------------------------------------------------------------------
// Purpose: Compiles a GL shader program and returns the handle. Returns 0 if
@@ -2200,13 +2218,23 @@ void CGLRenderModel::Draw()
glBindVertexArray( 0 );
}
+CMainApplication *pMainApplication;
+
+void reset_position(int signum)
+{
+ printf("ok\n");
+ pMainApplication->ResetRotation();
+}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
- CMainApplication *pMainApplication = new CMainApplication( argc, argv );
+ pMainApplication = new CMainApplication( argc, argv );
+
+ signal(SIGUSR1, reset_position);
+ signal(SIGUSR2, reset_position);
if (!pMainApplication->BInit())
{