| 204 | } |
| 205 | |
| 206 | void waybar::Client::bindInterfaces() { |
| 207 | registry = wl_display_get_registry(wl_display); |
| 208 | static const struct wl_registry_listener registry_listener = { |
| 209 | .global = handleGlobal, |
| 210 | .global_remove = handleGlobalRemove, |
| 211 | }; |
| 212 | wl_registry_add_listener(registry, ®istry_listener, this); |
| 213 | wl_display_roundtrip(wl_display); |
| 214 | |
| 215 | if (gtk_layer_is_supported() == 0) { |
| 216 | throw std::runtime_error("The Wayland compositor does not support wlr-layer-shell protocol"); |
| 217 | } |
| 218 | |
| 219 | if (xdg_output_manager == nullptr) { |
| 220 | throw std::runtime_error("Failed to acquire required resources."); |
| 221 | } |
| 222 | |
| 223 | // Disconnect previous signal handlers to prevent duplicate handlers on reload |
| 224 | monitor_added_connection_.disconnect(); |
| 225 | monitor_removed_connection_.disconnect(); |
| 226 | |
| 227 | // Clear stale outputs from previous run |
| 228 | outputs_.clear(); |
| 229 | |
| 230 | // add existing outputs and subscribe to updates |
| 231 | for (auto i = 0; i < gdk_display->get_n_monitors(); ++i) { |
| 232 | auto monitor = gdk_display->get_monitor(i); |
| 233 | handleMonitorAdded(monitor); |
| 234 | } |
| 235 | monitor_added_connection_ = gdk_display->signal_monitor_added().connect( |
| 236 | sigc::mem_fun(*this, &Client::handleMonitorAdded)); |
| 237 | monitor_removed_connection_ = gdk_display->signal_monitor_removed().connect( |
| 238 | sigc::mem_fun(*this, &Client::handleMonitorRemoved)); |
| 239 | } |
| 240 | |
| 241 | int waybar::Client::main(int argc, char* argv[]) { |
| 242 | bool show_help = false; |