mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2025-05-13 19:45:33 +02:00
mouse left & right click
This commit is contained in:
parent
d204387e19
commit
29f4595750
5 changed files with 36 additions and 1 deletions
10
src/app.cpp
10
src/app.cpp
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue