From 9e8d9791c7f9b7d1183110da370772a8b2c1b6f4 Mon Sep 17 00:00:00 2001 From: DDoSolitary Date: Tue, 21 Jan 2025 01:53:29 +0800 Subject: [PATCH] xwayland: support sending clipboard change notification on focus (#9111) --- src/xwayland/XWM.cpp | 13 ++++++++++++- src/xwayland/XWM.hpp | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/xwayland/XWM.cpp b/src/xwayland/XWM.cpp index ae8e0ccc..3486b286 100644 --- a/src/xwayland/XWM.cpp +++ b/src/xwayland/XWM.cpp @@ -1144,7 +1144,8 @@ void CXWM::initSelection() { XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY | XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE; xcb_xfixes_select_selection_input(connection, clipboard.window, HYPRATOMS["CLIPBOARD"], mask2); - clipboard.listeners.setSelection = g_pSeatManager->events.setSelection.registerListener([this](std::any d) { clipboard.onSelection(); }); + clipboard.listeners.setSelection = g_pSeatManager->events.setSelection.registerListener([this](std::any d) { clipboard.onSelection(); }); + clipboard.listeners.keyboardFocusChange = g_pSeatManager->events.keyboardFocusChange.registerListener([this](std::any d) { clipboard.onKeyboardFocus(); }); dndSelection.window = xcb_generate_id(connection); xcb_create_window(connection, XCB_COPY_FROM_PARENT, dndSelection.window, screen->root, 0, 0, 8192, 8192, 0, XCB_WINDOW_CLASS_INPUT_ONLY, screen->root_visual, XCB_CW_EVENT_MASK, @@ -1287,6 +1288,16 @@ void SXSelection::onSelection() { if (g_pSeatManager->selection.currentSelection) { xcb_set_selection_owner(g_pXWayland->pWM->connection, g_pXWayland->pWM->clipboard.window, HYPRATOMS["CLIPBOARD"], XCB_TIME_CURRENT_TIME); xcb_flush(g_pXWayland->pWM->connection); + g_pXWayland->pWM->clipboard.notifyOnFocus = true; + } +} + +void SXSelection::onKeyboardFocus() { + if (!g_pSeatManager->state.keyboardFocusResource || g_pSeatManager->state.keyboardFocusResource->client() != g_pXWayland->pServer->xwaylandClient) + return; + if (g_pXWayland->pWM->clipboard.notifyOnFocus) { + onSelection(); + g_pXWayland->pWM->clipboard.notifyOnFocus = false; } } diff --git a/src/xwayland/XWM.hpp b/src/xwayland/XWM.hpp index bc5aa47b..0455c761 100644 --- a/src/xwayland/XWM.hpp +++ b/src/xwayland/XWM.hpp @@ -44,13 +44,16 @@ struct SXSelection { xcb_window_t owner = 0; xcb_timestamp_t timestamp = 0; SP dataSource; + bool notifyOnFocus = false; void onSelection(); + void onKeyboardFocus(); bool sendData(xcb_selection_request_event_t* e, std::string mime); int onRead(int fd, uint32_t mask); struct { CHyprSignalListener setSelection; + CHyprSignalListener keyboardFocusChange; } listeners; std::unique_ptr transfer;