xwayland: support sending clipboard change notification on focus (#9111)

This commit is contained in:
DDoSolitary 2025-01-21 01:53:29 +08:00 committed by GitHub
parent 2d82a92324
commit 9e8d9791c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -44,13 +44,16 @@ struct SXSelection {
xcb_window_t owner = 0;
xcb_timestamp_t timestamp = 0;
SP<CXDataSource> 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<SXTransfer> transfer;