[fix] fix blocking join() in Linux clipboard monitor thread during shutdown

This commit is contained in:
dijunkun
2026-03-20 15:02:34 +08:00
parent 262af263f2
commit f0f8f27f4c

View File

@@ -452,11 +452,17 @@ static void MonitorThreadFunc() {
LOG_INFO("Clipboard event monitoring started (Linux XFixes)");
XEvent event;
constexpr int kEventPollIntervalMs = 20;
while (g_monitoring.load()) {
XNextEvent(g_x11_display, &event);
if (event.type == event_base + XFixesSelectionNotify) {
HandleClipboardChange();
// Avoid blocking on XNextEvent so StopMonitoring() can stop quickly.
while (g_monitoring.load() && XPending(g_x11_display) > 0) {
XNextEvent(g_x11_display, &event);
if (event.type == event_base + XFixesSelectionNotify) {
HandleClipboardChange();
}
}
std::this_thread::sleep_for(
std::chrono::milliseconds(kEventPollIntervalMs));
}
XFixesSelectSelectionInput(g_x11_display, event_window, g_clipboard_atom, 0);