From 29f45957502efac71a7482a9bc60a8a4e200cacf Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 29 Apr 2023 17:06:02 +0200 Subject: [PATCH] mouse left & right click --- Makefile | 2 +- bindings/action_manifest.json | 12 ++++++++++++ src/app.cpp | 10 ++++++++++ src/app.h | 3 +++ src/controller.cpp | 10 ++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 45b2cd1..18db0c1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION=v0.1.0 # CC := g++ CC := clang++ -LFLAGS := -lX11 -lXrandr -lglfw -lGL +LFLAGS := -lX11 -lXrandr -lXtst -lglfw -lGL LIBS := openvr/libopenvr_api.so SRC := src/*.cpp OUT := ./sinpin_vr diff --git a/bindings/action_manifest.json b/bindings/action_manifest.json index 96383cd..4870f9f 100644 --- a/bindings/action_manifest.json +++ b/bindings/action_manifest.json @@ -31,6 +31,16 @@ "requirement": "suggested", "type": "boolean" }, + { + "name": "/actions/main/in/mouse_left", + "requirement": "suggested", + "type": "boolean" + }, + { + "name": "/actions/main/in/mouse_right", + "requirement": "suggested", + "type": "boolean" + }, { "name": "/actions/main/in/distance", "requirement": "suggested", @@ -52,6 +62,8 @@ "/actions/main/in/grab": "grab panel", "/actions/main/in/activate_cursor": "activate cursor", "/actions/main/in/distance": "move away", + "/actions/main/in/mouse_left": "mouse left", + "/actions/main/in/mouse_right": "mouse right", "/actions/main/in/reset": "reset positions" } ] diff --git a/src/app.cpp b/src/app.cpp index cb20377..718d702 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -2,6 +2,7 @@ #include "controller.h" #include "util.h" #include +#include #include #include #include @@ -64,6 +65,10 @@ App::App() assert(action_err == 0); action_err = vr_input->GetActionHandle("/actions/main/in/distance", &_input_handles.distance); assert(action_err == 0); + action_err = vr_input->GetActionHandle("/actions/main/in/mouse_left", &_input_handles.mouse_left); + assert(action_err == 0); + action_err = vr_input->GetActionHandle("/actions/main/in/mouse_right", &_input_handles.mouse_right); + assert(action_err == 0); action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.set); assert(action_err == 0); } @@ -292,3 +297,8 @@ void App::SetCursor(int x, int y) // I don't know what the return value of XWarpPointer means, it seems to be 1 on success. XWarpPointer(_xdisplay, _root_window, _root_window, 0, 0, _root_width, _root_height, x, y); } + +void App::SendMouseInput(unsigned int button, bool state) +{ + XTestFakeButtonEvent(_xdisplay, button, state, 0); +} diff --git a/src/app.h b/src/app.h index 6b48ce4..c1ea145 100644 --- a/src/app.h +++ b/src/app.h @@ -23,6 +23,8 @@ struct InputHandles vr::VRActionHandle_t distance; vr::VRActionHandle_t grab; vr::VRActionHandle_t activate_cursor; + vr::VRActionHandle_t mouse_left; + vr::VRActionHandle_t mouse_right; vr::VRActionHandle_t edit_mode; vr::VRActionHandle_t reset; }; @@ -43,6 +45,7 @@ class App Ray IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len); void SetCursor(int x, int y); + void SendMouseInput(unsigned int button, bool state); Display *_xdisplay; Window _root_window; diff --git a/src/controller.cpp b/src/controller.cpp index 2103295..fb1774e 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -135,6 +135,16 @@ void Controller::Update() pos *= _last_ray.hit_panel->Width(); _last_ray.hit_panel->SetCursor(pos.x, pos.y); } + auto mouse_left = _app->GetInputDigital(_app->_input_handles.mouse_left, _input_handle); + if (mouse_left.bChanged) + { + _app->SendMouseInput(1, mouse_left.bState); + } + auto mouse_right = _app->GetInputDigital(_app->_input_handles.mouse_right, _input_handle); + if (mouse_right.bChanged) + { + _app->SendMouseInput(3, mouse_right.bState); + } } } }