From 0040709c3080a3cb29e00c0da0bba973de091daa Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 7 Jan 2022 07:22:33 +0000 Subject: [PATCH] steamcompmgr: Provide feedback about focused display, mouse focus and keyboard focus --- src/steamcompmgr.cpp | 46 ++++++++++++++++++++++++++++++++++++-------- src/xwayland_ctx.hpp | 4 ++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index c0f4774..517b997 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -2168,17 +2168,20 @@ found: else global_focus.currentInputFocusWindow = global_focus.currentFocusWindow; + if (global_focus.currentInputFocusWindow) + global_focus.currentInputFocusMode = global_focus.currentInputFocusWindow->inputFocusMode; + + win *keyboardFocusWin = global_focus.currentInputFocusWindow; + if ( global_focus.currentInputFocusMode ) + { + keyboardFocusWin = global_focus.currentOverrideWindow + ? global_focus.currentOverrideWindow + : global_focus.currentFocusWindow; + } + if ( global_focus.currentInputFocusWindow != previous_focus.currentInputFocusWindow || global_focus.currentInputFocusMode != previous_focus.currentInputFocusMode ) { - win *keyboardFocusWin = global_focus.currentInputFocusWindow; - if ( global_focus.currentInputFocusWindow && global_focus.currentInputFocusWindow->inputFocusMode ) - { - keyboardFocusWin = global_focus.currentOverrideWindow - ? global_focus.currentOverrideWindow - : global_focus.currentFocusWindow; - } - if ( (global_focus.currentInputFocusWindow && global_focus.currentInputFocusWindow->surface.wlr != nullptr) || (keyboardFocusWin && keyboardFocusWin->surface.wlr != nullptr) ) { @@ -2211,11 +2214,25 @@ found: // Backchannel to Steam unsigned long focusedWindow = 0; unsigned long focusedAppId = 0; + const char *focused_display = root_ctx->xwayland_server->get_nested_display_name(); + const char *focused_keyboard_display = root_ctx->xwayland_server->get_nested_display_name(); + const char *focused_mouse_display = root_ctx->xwayland_server->get_nested_display_name(); if ( global_focus.currentFocusWindow ) { focusedWindow = global_focus.currentFocusWindow->id; focusedAppId = global_focus.currentInputFocusWindow->appID; + focused_display = global_focus.currentFocusWindow->ctx->xwayland_server->get_nested_display_name(); + } + + if ( global_focus.currentInputFocusWindow ) + { + focused_mouse_display = global_focus.currentInputFocusWindow->ctx->xwayland_server->get_nested_display_name(); + } + + if ( keyboardFocusWin ) + { + focused_keyboard_display = keyboardFocusWin->ctx->xwayland_server->get_nested_display_name(); } XChangeProperty( root_ctx->dpy, root_ctx->root, root_ctx->atoms.gamescopeFocusedAppAtom, XA_CARDINAL, 32, PropModeReplace, @@ -2224,6 +2241,15 @@ found: XChangeProperty( root_ctx->dpy, root_ctx->root, root_ctx->atoms.gamescopeFocusedWindowAtom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&focusedWindow, focusedWindow != 0 ? 1 : 0 ); + XChangeProperty( root_ctx->dpy, root_ctx->root, root_ctx->atoms.gamescopeFocusDisplay, XA_CARDINAL, 32, PropModeReplace, + (unsigned char *)focused_display, strlen(focused_display) + 1 ); + + XChangeProperty( root_ctx->dpy, root_ctx->root, root_ctx->atoms.gamescopeMouseFocusDisplay, XA_CARDINAL, 32, PropModeReplace, + (unsigned char *)focused_mouse_display, strlen(focused_mouse_display) + 1 ); + + XChangeProperty( root_ctx->dpy, root_ctx->root, root_ctx->atoms.gamescopeKeyboardFocusDisplay, XA_CARDINAL, 32, PropModeReplace, + (unsigned char *)focused_keyboard_display, strlen(focused_keyboard_display) + 1 ); + // Sort out fading. if (previous_focus.currentFocusWindow != global_focus.currentFocusWindow) { @@ -4107,6 +4133,10 @@ void init_xwayland_ctx(gamescope_xwayland_server_t *xwayland_server) ctx->atoms.gamescopeInputCounterAtom = XInternAtom(ctx->dpy, "GAMESCOPE_INPUT_COUNTER", false); ctx->atoms.gamescopeScreenShotAtom = XInternAtom( ctx->dpy, "GAMESCOPECTRL_REQUEST_SCREENSHOT", false ); + ctx->atoms.gamescopeFocusDisplay = XInternAtom(ctx->dpy, "GAMESCOPE_FOCUS_DISPLAY", false); + ctx->atoms.gamescopeMouseFocusDisplay = XInternAtom(ctx->dpy, "GAMESCOPE_MOUSE_FOCUS_DISPLAY", false); + ctx->atoms.gamescopeKeyboardFocusDisplay = XInternAtom( ctx->dpy, "GAMESCOPE_KEYBOARD_FOCUS_DISPLAY", false ); + ctx->root_width = DisplayWidth(ctx->dpy, ctx->scr); ctx->root_height = DisplayHeight(ctx->dpy, ctx->scr); diff --git a/src/xwayland_ctx.hpp b/src/xwayland_ctx.hpp index 7aab1e5..c4f5283 100644 --- a/src/xwayland_ctx.hpp +++ b/src/xwayland_ctx.hpp @@ -100,5 +100,9 @@ struct xwayland_ctx_t Atom gamescopeCtrlWindowAtom; Atom gamescopeInputCounterAtom; Atom gamescopeScreenShotAtom; + + Atom gamescopeFocusDisplay; + Atom gamescopeMouseFocusDisplay; + Atom gamescopeKeyboardFocusDisplay; } atoms; };