Skip to content

Auto-remove desktops that contain only pinned (on-all-desktops) windows - #48

Open
mpollock wants to merge 1 commit into
rxappdev:mainfrom
mpollock:pin-aware-autoremove
Open

Auto-remove desktops that contain only pinned (on-all-desktops) windows#48
mpollock wants to merge 1 commit into
rxappdev:mainfrom
mpollock:pin-aware-autoremove

Conversation

@mpollock

Copy link
Copy Markdown

Problem

With Auto-remove empty virtual desktops enabled, removeEmptyVirtualDesktops() returns early the moment it encounters any window with onAllDesktops set:

if (window.onAllDesktops) {
    // A window occupies all windows - do not remove anything
    return;
}

If you keep even one "pin to all desktops" window around (common with multi-monitor setups, media players, chat, per-monitor-virtual-desktop scripts, etc.), the feature is effectively disabled — every desktop looks occupied, so nothing is ever removed.

Repro

  1. Enable Auto-remove empty virtual desktops.
  2. Pin any window to all desktops.
  3. Create a second virtual desktop, put a normal window on it, then close/move that window.
  4. The now-empty desktop is not removed.

Change

Skip on-all-desktops windows (continue) instead of aborting the whole sweep. A window that is on every desktop cannot be the thing that makes a particular desktop non-empty, so a desktop whose only remaining windows are pinned is now correctly removed. The first desktop is still never removed.

No change for users who don't use pinned windows, and none when the setting is off.

Also included (happy to split out if you'd rather)

  • Workspace.onWindowRemoved backstop — the per-window closed handler wired in addWindow() only covers windows that passed isValidWindow() at add time; this workspace-level signal fires for every removal. removeEmptyVirtualDesktops() already short-circuits on the config flag, so it's a cheap no-op when disabled.
  • Off-by-one in the removal loop — it started at virtualDesktopWindowCount.length, so virtualDesktopWindowCount[length] was undefined on the first iteration (harmless, but === 0 was never true there anyway).

Testing

Bazzite / KDE Plasma 6.7.4, Wayland. With the patch: empty desktops are removed as soon as their last non-pinned window is closed or moved away, whether or not pinned windows are present; desktop 1 is preserved; no change observed with the setting disabled.

removeEmptyVirtualDesktops() bailed out entirely (`return`) the moment it
saw any window with onAllDesktops set. With one or more "pin to all
desktops" windows present, that disabled the feature completely: every
desktop looked occupied.

Skip on-all-desktops windows instead (`continue`). A window that is on
every desktop cannot be what makes a particular desktop non-empty, so a
desktop whose only remaining windows are pinned is now correctly removed.

Also:
- add a Workspace.onWindowRemoved backstop so the sweep runs on every
  window removal, not only windows registered through addWindow().
- fix the trailing-index off-by-one in the removal loop (started at
  length, so counts[length] was always undefined on the first pass).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018DjxQ7ZqJwqb3ohScJYUwC
@mpollock

Copy link
Copy Markdown
Author

Unsure if this is desired behavior for others, but I find it helpful. Perhaps it can be a part of settings?

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.

1 participant