Skip to content

X11: Reduce blocking XSync calls when showing main window - #3485

Merged
hluk merged 1 commit into
masterfrom
fix/x11-window-show-delay
Mar 20, 2026
Merged

hluk merged 1 commit into
masterfrom
fix/x11-window-show-delay

Conversation

@hluk

@hluk hluk commented Mar 19, 2026 •

Copy link
Copy Markdown
Owner

Remove or replace synchronous XSync round-trips that block the event loop when the X server/compositor is slow to respond after idle periods, causing multi-second delays when activating the main window via global shortcut.

Changes

  1. getCurrentWindow(): Remove XSync before XGetProperty.
    XGetProperty is already a synchronous round-trip; the preceding XSync served no purpose since the _NET_ACTIVE_WINDOW property is maintained by the window manager, not by CopyQ pending requests.

  2. moveToCurrentWorkspace(): On X11, replace hide/show cycle with _NET_WM_DESKTOP client message (standard EWMH). The old approach unmapped and remapped the window, forcing the compositor to destroy and recreate textures — expensive when the GPU is in a low-power state after idle. On non-X11 (Wayland), preserve the hide/show behavior needed for focus stealing via compositor re-initialization.

  3. raise(): Replace two XSync calls with a single XFlush. No caller depends on synchronous completion of the raise operation.

  4. moveToCurrentWorkspace(): Fix potential XGetWindowProperty memory leak — always call XFree when data is non-null, validate type/format before reinterpret_cast, and extract getCardinalProperty() helper to eliminate duplication.

Fixes #2877

Assisted-by: Claude (Anthropic)

@codecov

codecov Bot commented Mar 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.10256% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.68%. Comparing base (6c30e5c) to head (fb19a79).
⚠ïļ Report is 120 commits behind head on master.

Files with missing lines Patch % Lines
src/gui/geometry.cpp 63.15% 14 Missing ⚠ïļ

❌ Your patch status has failed because the patch coverage (64.10%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3485      +/-   ##
==========================================
- Coverage   80.77%   80.68%   -0.10%     
==========================================
  Files         245      245              
  Lines       30977    31011      +34     
==========================================
- Hits        25023    25021       -2     
- Misses       5954     5990      +36     

☔ View full report in Codecov by Harness.
ðŸ“Ē Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄ïļ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • ðŸ“Ķ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hluk
hluk force-pushed the fix/x11-window-show-delay branch from 6f43a41 to 09946a4 Compare March 19, 2026 12:08
@hluk
hluk requested a review from Copilot March 19, 2026 14:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets X11 responsiveness when activating/showing the main window by reducing synchronous X11 round-trips and avoiding costly hide/show remaps, addressing delays reported in #2877.

Changes:

  • Removed an unnecessary XSync() before _NET_ACTIVE_WINDOW property retrieval.
  • Reworked “move to current workspace” to use EWMH _NET_WM_DESKTOP on X11 (and kept hide-based behavior for non-X11/Wayland).
  • Replaced XSync() calls in X11 window raising with a single XFlush().

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/platform/x11/x11platformwindow.cpp Reduces blocking X11 sync calls in focus/raise and current-window detection.
src/gui/geometry.cpp Implements X11 workspace move via EWMH client message; keeps non-X11 hide behavior.
.github/actions/download-miniaudio/action.yml No functional change (formatting/whitespace only).

ðŸ’Ą Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/gui/geometry.cpp Outdated
Comment thread src/gui/geometry.cpp Outdated
Comment thread src/gui/geometry.cpp Outdated
Comment thread src/platform/x11/x11platformwindow.cpp
Remove or replace synchronous XSync round-trips that block the event loop
when the X server/compositor is slow to respond after idle periods, causing
multi-second delays when activating the main window via global shortcut.

Changes:

1. getCurrentWindow(): Remove XSync before XGetProperty.
   XGetProperty is already a synchronous round-trip; the preceding XSync
   served no purpose since the _NET_ACTIVE_WINDOW property is maintained
   by the window manager, not by CopyQ pending requests.

2. moveToCurrentWorkspace(): On X11, replace hide/show cycle with
   _NET_WM_DESKTOP client message (standard EWMH). The old approach
   unmapped and remapped the window, forcing the compositor to destroy
   and recreate textures — expensive when the GPU is in a low-power
   state after idle. On non-X11 (Wayland), preserve the hide/show
   behavior needed for focus stealing via compositor re-initialization.

3. raise(): Replace two XSync calls with a single XFlush. No caller
   depends on synchronous completion of the raise operation.

Fixes: #2877
Assisted-by: Claude (Anthropic)
@hluk
hluk force-pushed the fix/x11-window-show-delay branch from 09946a4 to fb19a79 Compare March 19, 2026 17:02
@hluk
hluk merged commit a814b1d into master Mar 20, 2026
11 of 14 checks passed
@hluk
hluk deleted the fix/x11-window-show-delay branch March 20, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The main window opens with a delay after a while

2 participants