mouse left & right click

This commit is contained in:
Crispy 2023-04-29 17:06:02 +02:00
parent d204387e19
commit 29f4595750
5 changed files with 36 additions and 1 deletions

View file

@ -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

View file

@ -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"
}
]

View file

@ -2,6 +2,7 @@
#include "controller.h"
#include "util.h"
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/Xrandr.h>
#include <cassert>
#include <glm/matrix.hpp>
@ -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);
}

View file

@ -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;

View file

@ -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);
}
}
}
}