Skip to content

Commit

Permalink
Add configurable mouse sensitivity
Browse files Browse the repository at this point in the history
The `--mouse-sensitivity`/`-s` command line option allows the user to
set the value `g_mouseSensitivity` which is used to scale the mouse
movement in `wlserver_mousemotion`.
  • Loading branch information
dexgs authored and Joshua-Ashton committed Jan 20, 2024
1 parent 425eb07 commit 8783464
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const struct option *gamescope_options = (struct option[]){
{ "rt", no_argument, nullptr, 0 },
{ "prefer-vk-device", required_argument, 0 },
{ "expose-wayland", no_argument, 0 },
{ "mouse-sensitivity", required_argument, nullptr, 's' },

{ "headless", no_argument, 0 },

Expand Down Expand Up @@ -159,6 +160,7 @@ const char usage[] =
" nis => NVIDIA Image Scaling v1.0.3\n"
" --sharpness, --fsr-sharpness upscaler sharpness from 0 (max) to 20 (min)\n"
" --expose-wayland support wayland clients using xdg-shell\n"
" -s, --mouse-sensitivity multiply mouse movement by given decimal number\n"
" --headless use headless backend (no window, no DRM output)\n"
" --cursor path to default cursor image\n"
" -R, --ready-fd notify FD when ready\n"
Expand Down Expand Up @@ -267,6 +269,8 @@ bool g_bHeadless = false;

bool g_bGrabbed = false;

float g_mouseSensitivity = 1.0;

GamescopeUpscaleFilter g_upscaleFilter = GamescopeUpscaleFilter::LINEAR;
GamescopeUpscaleScaler g_upscaleScaler = GamescopeUpscaleScaler::AUTO;

Expand Down Expand Up @@ -596,6 +600,9 @@ int main(int argc, char **argv)
case 'g':
g_bGrabbed = true;
break;
case 's':
g_mouseSensitivity = atof( optarg );
break;
case 0: // long options without a short option
opt_name = gamescope_options[opt_index].name;
if (strcmp(opt_name, "help") == 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern bool g_bFullscreen;

extern bool g_bGrabbed;

extern float g_mouseSensitivity;

enum class GamescopeUpscaleFilter : uint32_t
{
LINEAR = 0,
Expand Down
13 changes: 4 additions & 9 deletions src/wlserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ static void wlserver_perform_rel_pointer_motion(double unaccel_dx, double unacce
auto server = steamcompmgr_get_focused_server();
if ( server != NULL )
{
unaccel_dx *= g_mouseSensitivity;
unaccel_dy *= g_mouseSensitivity;

server->ctx->accum_x += unaccel_dx;
server->ctx->accum_y += unaccel_dy;

Expand Down Expand Up @@ -1861,15 +1864,7 @@ void wlserver_mousefocus( struct wlr_surface *wlrsurface, int x /* = 0 */, int y

void wlserver_mousemotion( int x, int y, uint32_t time )
{
assert( wlserver_is_lock_held() );

// TODO: Pick the xwayland_server with active focus
auto server = steamcompmgr_get_focused_server();
if ( server != NULL )
{
XTestFakeRelativeMotionEvent( server->get_xdisplay(), x, y, CurrentTime );
XFlush( server->get_xdisplay() );
}
wlserver_perform_rel_pointer_motion( x, y );
}

void wlserver_mousewarp( int x, int y, uint32_t time )
Expand Down

0 comments on commit 8783464

Please sign in to comment.