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

steamcompmgr: Add an option to disable automatic relative mouse #1098

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ meson install -C build/ --skip-subprojects
* **Super + O** : Decrease FSR sharpness by 1
* **Super + S** : Take screenshot (currently goes to `/tmp/gamescope_$DATE.png`)
* **Super + G** : Toggle keyboard grab
* **Super + M** : Toggle mouse grab

## Examples

Expand Down
11 changes: 8 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const struct option *gamescope_options = (struct option[]){
{ "fullscreen", no_argument, nullptr, 'f' },
{ "grab", no_argument, nullptr, 'g' },
{ "force-grab-cursor", no_argument, nullptr, 0 },
{ "never-grab-cursor", no_argument, nullptr, 0 },

// embedded mode options
{ "disable-layers", no_argument, nullptr, 0 },
Expand Down Expand Up @@ -190,6 +191,7 @@ const char usage[] =
" -f, --fullscreen make the window fullscreen\n"
" -g, --grab grab the keyboard\n"
" --force-grab-cursor always use relative mouse mode instead of flipping dependent on cursor visibility.\n"
" --never-grab-cursor never use relative mouse mode instead of flipping dependent on cursor visibility.\n"
"\n"
"Embedded mode options:\n"
" -O, --prefer-output list of connectors in order of preference\n"
Expand Down Expand Up @@ -247,6 +249,7 @@ const char usage[] =
" Super + O decrease FSR sharpness by 1\n"
" Super + S take a screenshot\n"
" Super + G toggle keyboard grab\n"
" Super + M toggle mouse grab\n"
"";

std::atomic< bool > g_bRun{true};
Expand All @@ -262,7 +265,7 @@ int g_nOutputRefresh = 0;
bool g_bOutputHDREnabled = false;

bool g_bFullscreen = false;
bool g_bForceRelativeMouse = false;
ForceRelativeMouseMode g_forceRelativeMouse = ForceRelativeMouseMode::OFF;

bool g_bIsNested = false;
bool g_bHeadless = false;
Expand Down Expand Up @@ -640,7 +643,9 @@ int main(int argc, char **argv)
} else if (strcmp(opt_name, "immediate-flips") == 0) {
g_nAsyncFlipsEnabled = 1;
} else if (strcmp(opt_name, "force-grab-cursor") == 0) {
g_bForceRelativeMouse = true;
g_forceRelativeMouse = ForceRelativeMouseMode::FORCE_ON;
} else if (strcmp(opt_name, "never-grab-cursor") == 0) {
g_forceRelativeMouse = ForceRelativeMouseMode::FORCE_OFF;
} else if (strcmp(opt_name, "adaptive-sync") == 0) {
s_bInitialWantsVRREnabled = true;
} else if (strcmp(opt_name, "expose-wayland") == 0) {
Expand Down Expand Up @@ -767,7 +772,7 @@ int main(int argc, char **argv)

if ( !BIsNested() )
{
g_bForceRelativeMouse = false;
g_forceRelativeMouse = ForceRelativeMouseMode::OFF;
}

#if HAVE_OPENVR
Expand Down
7 changes: 7 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ enum class GamescopeUpscaleScaler : uint32_t
STRETCH,
};

enum class ForceRelativeMouseMode : uint32_t
{
OFF,
FORCE_OFF,
FORCE_ON,
};

extern GamescopeUpscaleFilter g_upscaleFilter;
extern GamescopeUpscaleScaler g_upscaleScaler;
extern GamescopeUpscaleFilter g_wantedUpscaleFilter;
Expand Down
11 changes: 7 additions & 4 deletions src/sdlwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void updateOutputRefresh( void )
}
}

extern bool g_bForceRelativeMouse;
extern ForceRelativeMouseMode g_forceRelativeMouse;

static std::string gamescope_str = DEFAULT_TITLE;

Expand Down Expand Up @@ -163,7 +163,7 @@ void inputSDLThreadRun( void )
g_nOutputHeight = height;
}

if ( g_bForceRelativeMouse )
if ( g_forceRelativeMouse == ForceRelativeMouseMode::FORCE_ON )
{
SDL_SetRelativeMouseMode( SDL_TRUE );
bRelativeMouse = true;
Expand Down Expand Up @@ -265,6 +265,9 @@ void inputSDLThreadRun( void )
g_bFullscreen = !g_bFullscreen;
SDL_SetWindowFullscreen( g_SDLWindow, g_bFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0 );
break;
case KEY_M:
sdlwindow_grab( !SDL_GetRelativeMouseMode() );
break;
case KEY_N:
g_wantedUpscaleFilter = GamescopeUpscaleFilter::PIXEL;
break;
Expand Down Expand Up @@ -559,7 +562,7 @@ void sdlwindow_grab( bool bGrab )
if ( !BIsSDLSession() )
return;

if ( g_bForceRelativeMouse )
if ( g_forceRelativeMouse == ForceRelativeMouseMode::FORCE_ON )
return;

static bool s_bWasGrabbed = false;
Expand All @@ -580,7 +583,7 @@ void sdlwindow_cursor(std::shared_ptr<std::vector<uint32_t>> pixels, uint32_t wi
if ( !BIsSDLSession() )
return;

if ( g_bForceRelativeMouse )
if ( g_forceRelativeMouse == ForceRelativeMouseMode::FORCE_ON )
return;

{
Expand Down
8 changes: 4 additions & 4 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ constexpr const T& clamp( const T& x, const T& min, const T& max )
return x < min ? min : max < x ? max : x;
}

extern bool g_bForceRelativeMouse;
extern ForceRelativeMouseMode g_forceRelativeMouse;
bool bSteamCompMgrGrab = false;

CommitDoneList_t g_steamcompmgr_xdg_done_commits;
Expand Down Expand Up @@ -1887,7 +1887,7 @@ bool MouseCursor::getTexture()
m_texture = nullptr;

// Assume the cursor is fully translucent unless proven otherwise.
bool bNoCursor = true;
bool bNoCursor = g_forceRelativeMouse != ForceRelativeMouseMode::FORCE_OFF;

std::shared_ptr<std::vector<uint32_t>> cursorBuffer = nullptr;

Expand Down Expand Up @@ -1949,7 +1949,7 @@ bool MouseCursor::getTexture()

m_imageEmpty = bNoCursor;

if ( !g_bForceRelativeMouse )
if ( g_forceRelativeMouse == ForceRelativeMouseMode::OFF )
{
sdlwindow_grab( m_imageEmpty );
bSteamCompMgrGrab = BIsNested() && m_imageEmpty;
Expand Down Expand Up @@ -7768,7 +7768,7 @@ steamcompmgr_main(int argc, char **argv)
// Reset getopt() state
optind = 1;

bSteamCompMgrGrab = BIsNested() && g_bForceRelativeMouse;
bSteamCompMgrGrab = BIsNested() && g_forceRelativeMouse == ForceRelativeMouseMode::FORCE_ON;

int o;
int opt_index = -1;
Expand Down
Loading