Skip to content

Commit 08a4595

Browse files
committed
OpenVRBackend: Add closing window support
1 parent 81d6554 commit 08a4595

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/Backends/OpenVRBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extern bool g_bAllowDeferredBackend;
5555

5656
void MakeFocusDirty();
5757
void update_connector_display_info_wl(struct drm_t *drm);
58+
void close_virtual_connector_key(gamescope::VirtualConnectorKey_t eKey);
5859

5960
static LogScope openvr_log("openvr");
6061

@@ -1088,8 +1089,7 @@ namespace gamescope
10881089
}
10891090
else
10901091
{
1091-
// How do we quit a game?
1092-
// Do we?
1092+
close_virtual_connector_key( pConnector->GetVirtualConnectorKey() );
10931093
}
10941094
break;
10951095
}

src/steamcompmgr.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,15 @@ extern bool g_bForceRelativeMouse;
804804

805805
CommitDoneList_t g_steamcompmgr_xdg_done_commits;
806806

807+
808+
static std::mutex s_KeysToCloseMutex;
809+
static std::vector<gamescope::VirtualConnectorKey_t> s_KeysToClose;
810+
void close_virtual_connector_key(gamescope::VirtualConnectorKey_t eKey)
811+
{
812+
std::unique_lock lock{ s_KeysToCloseMutex };
813+
s_KeysToClose.push_back( eKey );
814+
}
815+
807816
struct ignore {
808817
struct ignore *next;
809818
unsigned long sequence;
@@ -7719,6 +7728,9 @@ void init_xwayland_ctx(uint32_t serverId, gamescope_xwayland_server_t *xwayland_
77197728
ctx->atoms.primarySelection = XInternAtom(ctx->dpy, "PRIMARY", false);
77207729
ctx->atoms.targets = XInternAtom(ctx->dpy, "TARGETS", false);
77217730

7731+
ctx->atoms.wm_protocols = XInternAtom(ctx->dpy, "WM_PROTOCOLS", false);
7732+
ctx->atoms.wm_delete_window = XInternAtom(ctx->dpy, "WM_DELETE_WINDOW", false);
7733+
77227734
ctx->root_width = DisplayWidth(ctx->dpy, ctx->scr);
77237735
ctx->root_height = DisplayHeight(ctx->dpy, ctx->scr);
77247736

@@ -8390,6 +8402,13 @@ steamcompmgr_main(int argc, char **argv)
83908402
}
83918403
#endif
83928404

8405+
std::vector<gamescope::VirtualConnectorKey_t> keysToClose;
8406+
{
8407+
std::unique_lock lock{ s_KeysToCloseMutex };
8408+
keysToClose = std::move( s_KeysToClose );
8409+
s_KeysToClose.clear();
8410+
}
8411+
83938412
// XXX: Need to look into why this doesn't work.
83948413
// if ( bDirtyFocuses )
83958414
{
@@ -8412,6 +8431,27 @@ steamcompmgr_main(int argc, char **argv)
84128431
}
84138432

84148433
gamescope::VirtualConnectorKey_t ulKey = pWindow->GetVirtualConnectorKey( eVirtualConnectorStrategy );
8434+
8435+
if ( gamescope::Algorithm::Contains( keysToClose, ulKey ) )
8436+
{
8437+
if ( pWindow->type == steamcompmgr_win_type_t::XWAYLAND )
8438+
{
8439+
XEvent event = {0};
8440+
event.xclient.type = ClientMessage;
8441+
event.xclient.window = pWindow->xwayland().id;
8442+
event.xclient.message_type = pWindow->xwayland().ctx->atoms.wm_protocols;
8443+
event.xclient.format = 32;
8444+
event.xclient.data.l[0] = pWindow->xwayland().ctx->atoms.wm_delete_window;
8445+
event.xclient.data.l[1] = CurrentTime;
8446+
8447+
XSendEvent(pWindow->xwayland().ctx->dpy, pWindow->xwayland().id, False, NoEventMask, &event);
8448+
}
8449+
else
8450+
{
8451+
xwm_log.errorf( "Closing Wayland windows not supported yet." );
8452+
}
8453+
}
8454+
84158455
if ( !gamescope::Algorithm::Contains( newKeys, ulKey ) )
84168456
newKeys.emplace_back( ulKey );
84178457
}

src/xwayland_ctx.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ struct xwayland_ctx_t final : public gamescope::IWaitable
251251
Atom clipboard;
252252
Atom primarySelection;
253253
Atom targets;
254+
255+
Atom wm_protocols;
256+
Atom wm_delete_window;
254257
} atoms;
255258

256259
bool HasQueuedEvents();

0 commit comments

Comments
 (0)