Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable mouse sensitivity #915

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 @@ -154,6 +155,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 @@ -259,6 +261,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 @@ -582,6 +586,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
dexgs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,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 @@ -1674,15 +1677,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