Skip to content

Handle display connection loss gracefully instead of crashing#4811

Draft
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-waybar-crash-dosbox
Draft

Handle display connection loss gracefully instead of crashing#4811
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-waybar-crash-dosbox

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

Waybar crashes when the display connection breaks (e.g., when opening dosbox), showing "Error reading events from display: Broken pipe" before terminating. The GTK main loop doesn't recover from this condition.

Changes

Install GLib log handlers to intercept display errors (src/client.cpp)

  • Added gdkLogHandler that detects "Error reading events from display" and "Broken pipe" messages
  • Calls gtk_app->quit() for clean shutdown, falls back to std::exit(1) if GTK isn't initialized
  • Forwards other log messages to spdlog at appropriate levels
  • Installed after gtk_app creation to ensure availability:
    • Gdk/Gtk handlers use G_LOG_LEVEL_MASK
    • Default handler limited to G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL to avoid library interference

Resource cleanup (include/client.hpp, src/client.cpp)

  • Store handler IDs as member variables
  • Remove handlers in ~Client() destructor via g_log_remove_handler()
void gdkLogHandler(const gchar* log_domain, GLogLevelFlags log_level, 
                   const gchar* message, gpointer user_data) {
  if (message && (strstr(message, "Error reading events from display") != nullptr ||
                  strstr(message, "Broken pipe") != nullptr)) {
    spdlog::error("Display connection lost: {}. Exiting gracefully.", message);
    auto* client = waybar::Client::inst();
    if (client && client->gtk_app) {
      client->gtk_app->quit();
    } else {
      std::exit(1);
    }
    return;
  }
  // Forward other messages to spdlog...
}
Original prompt

This section details on the original issue you should resolve

<issue_title>waybar crashes when opening dosbox</issue_title>
<issue_description>```
[2025-07-28 11:46:56.606] [info] Using configuration file /home/killertofus/.config/waybar/config.jsonc
[2025-07-28 11:46:56.606] [info] Including resource file: ~/.config/waybar/modules.json
[2025-07-28 11:46:56.607] [info] Using CSS file /home/killertofus/.config/waybar/style.css
[2025-07-28 11:46:56.612] [warning] 'swap-icon-label' must be a bool.
[2025-07-28 11:46:56.613] [warning] No batteries.
[2025-07-28 11:46:56.641] [info] Bar configured (width: 1920, height: 32) for output: DVI-D-1

** (waybar:740594): WARNING **: 11:46:56.644: Status Notifier Item with bus name ':1.5' and object path '/org/ayatana/NotificationItem/nm_applet' is already registered

** (waybar:740594): WARNING **: 11:46:56.661: Status Notifier Item with bus name ':1.5' and object path '/org/ayatana/NotificationItem/nm_applet' is already registered

** (waybar:740594): WARNING **: 11:46:58.018: Status Notifier Item with bus name ':1.5' and object path '/org/ayatana/NotificationItem/nm_applet' is already registered

** (waybar:740594): WARNING **: 11:47:07.193: Status Notifier Item with bus name ':1.5' and object path '/org/ayatana/NotificationItem/nm_applet' is already registered
Gdk-Message: 11:47:25.323: Error reading events from display: Broken pipe


https://github.com/user-attachments/assets/687e98ea-2fc9-4de7-b526-7340d8943641


my config https://github.com/killertofus/awesome/tree/dw-arch/.config/waybar</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits February 4, 2026 09:36
…fully

Co-authored-by: Alexays <13947260+Alexays@users.noreply.github.com>
Co-authored-by: Alexays <13947260+Alexays@users.noreply.github.com>
… exit

Co-authored-by: Alexays <13947260+Alexays@users.noreply.github.com>
… documentation

Co-authored-by: Alexays <13947260+Alexays@users.noreply.github.com>
Co-authored-by: Alexays <13947260+Alexays@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix waybar crash issue when opening dosbox Handle display connection loss gracefully instead of crashing Feb 4, 2026
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.

waybar crashes when opening dosbox

2 participants