From 7f2db65c00b3805b13e983a6bea1aa37f93d16e3 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 23 Sep 2022 20:44:51 +0000 Subject: [PATCH] steamcompmgr: Add GAMESCOPE_CURSOR_VISIBLE_FEEDBACK --- src/steamcompmgr.cpp | 29 ++++++++++++++++++++++++++++- src/steamcompmgr.hpp | 6 +++++- src/xwayland_ctx.hpp | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index a058162..c310ace 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -900,6 +900,7 @@ MouseCursor::MouseCursor(xwayland_ctx_t *ctx) { m_lastX = g_nNestedWidth / 2; m_lastY = g_nNestedHeight / 2; + updateCursorFeedback( true ); } void MouseCursor::queryPositions(int &rootX, int &rootY, int &winX, int &winY) @@ -973,6 +974,8 @@ void MouseCursor::checkSuspension() nudge_steamcompmgr(); } } + + updateCursorFeedback(); } void MouseCursor::warp(int x, int y) @@ -1162,6 +1165,7 @@ void MouseCursor::move(int x, int y) XWarpPointer(m_ctx->dpy, None, x11_win(m_ctx->focus.inputFocusWindow), 0, 0, 0, 0, m_lastX, m_lastY); } m_hideForMovement = false; + updateCursorFeedback(); } void MouseCursor::updatePosition() @@ -1235,8 +1239,10 @@ bool MouseCursor::getTexture() } m_dirty = false; + updateCursorFeedback(); if (m_imageEmpty) { + return false; } @@ -1257,7 +1263,7 @@ bool MouseCursor::getTexture() void MouseCursor::paint(win *window, win *fit, struct FrameInfo_t *frameInfo) { - if (m_hideForMovement || m_imageEmpty) { + if ( m_hideForMovement || m_imageEmpty ) { return; } @@ -1334,6 +1340,25 @@ void MouseCursor::paint(win *window, win *fit, struct FrameInfo_t *frameInfo) layer->blackBorder = false; } +void MouseCursor::updateCursorFeedback( bool bForce ) +{ + // Can't resolve this until cursor is un-dirtied. + if ( m_dirty && !bForce ) + return; + + bool bVisible = !isHidden(); + + if ( m_bCursorVisibleFeedback == bVisible && !bForce ) + return; + + uint32_t value = bVisible ? 1 : 0; + + XChangeProperty(m_ctx->dpy, m_ctx->root, m_ctx->atoms.gamescopeCursorVisibleFeedback, XA_CARDINAL, 32, PropModeReplace, + (unsigned char *)&value, 1 ); + + m_bCursorVisibleFeedback = bVisible; +} + struct BaseLayerInfo_t { float scale[2]; @@ -5158,6 +5183,8 @@ void init_xwayland_ctx(gamescope_xwayland_server_t *xwayland_server) ctx->atoms.gamescopeDisplayIsExternal = XInternAtom( ctx->dpy, "GAMESCOPE_DISPLAY_IS_EXTERNAL", false ); ctx->atoms.gamescopeDisplayModeListExternal = XInternAtom( ctx->dpy, "GAMESCOPE_DISPLAY_MODE_LIST_EXTERNAL", false ); + ctx->atoms.gamescopeCursorVisibleFeedback = XInternAtom( ctx->dpy, "GAMESCOPE_CURSOR_VISIBLE_FEEDBACK", false ); + ctx->atoms.wineHwndStyle = XInternAtom( ctx->dpy, "_WINE_HWND_STYLE", false ); ctx->atoms.wineHwndStyleEx = XInternAtom( ctx->dpy, "_WINE_HWND_EXSTYLE", false ); diff --git a/src/steamcompmgr.hpp b/src/steamcompmgr.hpp index 6162738..5d11fed 100644 --- a/src/steamcompmgr.hpp +++ b/src/steamcompmgr.hpp @@ -58,7 +58,7 @@ public: void hide() { m_lastMovedTime = 0; checkSuspension(); } - bool isHidden() { return m_hideForMovement; } + bool isHidden() { return m_hideForMovement || m_imageEmpty; } void forcePosition(int x, int y) { @@ -77,6 +77,8 @@ private: bool getTexture(); + void updateCursorFeedback( bool bForce = false ); + int m_x = 0, m_y = 0; int m_hotspotX = 0, m_hotspotY = 0; @@ -93,6 +95,8 @@ private: int m_lastX = 0; int m_lastY = 0; + + bool m_bCursorVisibleFeedback = false; }; extern std::vector< wlr_surface * > wayland_surfaces_deleted; diff --git a/src/xwayland_ctx.hpp b/src/xwayland_ctx.hpp index fb95e18..a01e982 100644 --- a/src/xwayland_ctx.hpp +++ b/src/xwayland_ctx.hpp @@ -153,6 +153,8 @@ struct xwayland_ctx_t Atom gamescopeDisplayIsExternal; Atom gamescopeDisplayModeListExternal; + Atom gamescopeCursorVisibleFeedback; + Atom wineHwndStyle; Atom wineHwndStyleEx; } atoms;