Skip to content

Monitor hotplug - #12

Merged
DNAPrototypeX merged 3 commits into
mainfrom
monitor-hotplug
Sep 9, 2026
Merged

DNAPrototypeX merged 3 commits into
mainfrom
monitor-hotplug

Conversation

@DNAPrototypeX

Copy link
Copy Markdown
Owner

Fix the locker and greeter crashing if a monitor is unplugged while the screen is locked.

DNAPrototypeX and others added 2 commits September 8, 2026 16:29
PSLDM built one pane for each monitor at the start and never looked
again. A monitor that arrived during the lock or during the greeter
showed no pane, and a monitor that went away left a dead pane behind.
A laptop lid that closed the last screen ended the program.

Surfaces now watches the monitor list of the display. A monitor that
arrives gets a pane, and a monitor that leaves loses it. The count can
fall to zero, and both programs stay in memory until a monitor comes
back. The locker keeps the lock during that time, so a closed lid never
opens the session.

- Surfaces holds the panes in a RefCell and keeps the monitor of each
  one, so the set can change while the program runs.
- The lock host builds its surfaces from the `monitor` signal of
  gtk4-session-lock, the only safe moment to make a lock surface. That
  signal needs the v1_2 feature and gtk4-layer-shell 1.2 or later.
- The layer-shell host reads the monitor list of the display, and it now
  holds the application open, as the lock host already did.
- Surfaces::on_new_pane gives every pane its handlers and its first
  frame, both the first panes and the panes that arrive later.
- The greeter keeps the user and the session in one place, so a screen
  that goes away takes no choice with it.
- A new pane no longer takes the keyboard from the screen that the user
  types on.
- The greeter compositor gives an unknown monitor the mode that the
  monitor prefers, with the position and the scale that Hyprland picks.
  /etc/psldm/monitors.lua still wins for a monitor that it names.

Tested in a nested Hyprland instance with `hyprctl output create
headless` and `hyprctl output remove`: the greeter and the locker both
add and drop panes, and both survive a monitor count of zero.

Closes #11

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRi2nLG1kntocGApdMopMd
psldm-lock stopped with a segmentation fault when a monitor left while
the screen was locked.

GDK removes a monitor in two steps. It takes the monitor out of the
list first, then it invalidates the monitor:

    g_list_store_remove (self->monitors, i);
    gdk_monitor_invalidate (GDK_MONITOR (monitor));

Step one brought the program to Surfaces::drop_gone_monitors, which
dropped the pane and the window of that monitor. gtk4-session-lock
keeps no reference of its own to that window, so this program held the
only one, and the drop freed the window. Step two then called the
handler of the library on the free memory:

    static void gtk_lock_surface_unmap_window(struct gtk_lock_surface_t* self) {
        GtkWindow* window = self->gtk_window;
        ...
        g_signal_handlers_disconnect_by_data(window, self);

The core dump shows the fault inside libgtk-4, under a Wayland
callback, at `mov 0x8(%rbx),%rdi`.

drop_gone_monitors now takes the panes out of the list and gives them
up in an idle callback. The list is correct at once, and the memory
stays until the Wayland event ends, so the library reads a window that
is still there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E5ag7LJrDqAWveeef6twDr
@DNAPrototypeX DNAPrototypeX self-assigned this Sep 9, 2026
@DNAPrototypeX DNAPrototypeX added the bug Something isn't working label Sep 9, 2026
@DNAPrototypeX DNAPrototypeX linked an issue Sep 9, 2026 that may be closed by this pull request
Comment thread README.md
The three paragraphs said what the code and the Hyprland files already
say. The install section covers /etc/psldm/monitors.lua, and the greeter
configuration carries the rest in its comments.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TWyxdWoZGKfm1XWRvvem1L
@DNAPrototypeX
DNAPrototypeX merged commit e8eb15d into main Sep 9, 2026
1 check passed
@DNAPrototypeX
DNAPrototypeX deleted the monitor-hotplug branch September 9, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does not open on newly connected monitors while locked.

1 participant