From 88009800110073d339d41ca738da44e051531db0 Mon Sep 17 00:00:00 2001 From: snakedye <49378990+snakedye@users.noreply.github.com> Date: Sun, 23 May 2021 16:30:36 -0400 Subject: [PATCH] Fix for #175. (#180) * widgets on non existing output do not spawn * fix no-x11-wayland build Co-authored-by: Bryan Ndjeutcha --- src/app.rs | 60 ++++++++++++++++++++++-------------------- src/display_backend.rs | 18 +++++++------ 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/app.rs b/src/app.rs index aa865d4..ebeff2a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -308,41 +308,43 @@ fn initialize_window( ) -> Result { let actual_window_rect = window_def.geometry.get_window_rectangle(monitor_geometry); - let window = display_backend::initialize_window(&window_def, monitor_geometry); + if let Some(window) = display_backend::initialize_window(&window_def, monitor_geometry) { + window.set_title(&format!("Eww - {}", window_def.name)); + let wm_class_name = format!("eww-{}", window_def.name); + window.set_wmclass(&wm_class_name, &wm_class_name); + window.set_position(gtk::WindowPosition::Center); + window.set_size_request(actual_window_rect.width, actual_window_rect.height); + window.set_default_size(actual_window_rect.width, actual_window_rect.height); + window.set_decorated(false); + // run on_screen_changed to set the visual correctly initially. + on_screen_changed(&window, None); + window.connect_screen_changed(on_screen_changed); - window.set_title(&format!("Eww - {}", window_def.name)); - let wm_class_name = format!("eww-{}", window_def.name); - window.set_wmclass(&wm_class_name, &wm_class_name); - window.set_position(gtk::WindowPosition::Center); - window.set_size_request(actual_window_rect.width, actual_window_rect.height); - window.set_default_size(actual_window_rect.width, actual_window_rect.height); - window.set_decorated(false); - // run on_screen_changed to set the visual correctly initially. - on_screen_changed(&window, None); - window.connect_screen_changed(on_screen_changed); + window.add(&root_widget); - window.add(&root_widget); + window.show_all(); - window.show_all(); + apply_window_position(window_def.clone(), monitor_geometry, &window)?; + let gdk_window = window.get_window().context("couldn't get gdk window from gtk window")?; + gdk_window.set_override_redirect(!window_def.focusable); - apply_window_position(window_def.clone(), monitor_geometry, &window)?; - let gdk_window = window.get_window().context("couldn't get gdk window from gtk window")?; - gdk_window.set_override_redirect(!window_def.focusable); + #[cfg(feature = "x11")] + display_backend::reserve_space_for(&window, monitor_geometry, window_def.struts)?; - #[cfg(feature = "x11")] - display_backend::reserve_space_for(&window, monitor_geometry, window_def.struts)?; + // this should only be required on x11, as waylands layershell should manage the margins properly anways. + #[cfg(feature = "x11")] + window.connect_configure_event({ + let window_def = window_def.clone(); + move |window, _evt| { + let _ = apply_window_position(window_def.clone(), monitor_geometry, &window); + false + } + }); + Ok(EwwWindow { name: window_def.name.clone(), definition: window_def, gtk_window: window }) + } else { + Err(anyhow!("monitor {} is unavailable", window_def.screen_number.unwrap())) + } - // this should only be required on x11, as waylands layershell should manage the margins properly anways. - #[cfg(feature = "x11")] - window.connect_configure_event({ - let window_def = window_def.clone(); - move |window, _evt| { - let _ = apply_window_position(window_def.clone(), monitor_geometry, &window); - false - } - }); - - Ok(EwwWindow { name: window_def.name.clone(), definition: window_def, gtk_window: window }) } /// Apply the provided window-positioning rules to the window. diff --git a/src/display_backend.rs b/src/display_backend.rs index d8d431d..7e0c9de 100644 --- a/src/display_backend.rs +++ b/src/display_backend.rs @@ -6,7 +6,7 @@ mod platform { use anyhow::*; use gtk::{self, prelude::*}; - pub fn initialize_window(window_def: &EwwWindowDefinition, _monitor: gdk::Rectangle) -> gtk::Window { + pub fn initialize_window(window_def: &EwwWindowDefinition, _monitor: gdk::Rectangle) -> Option { let window = if window_def.focusable { gtk::Window::new(gtk::WindowType::Toplevel) } else { @@ -21,7 +21,7 @@ mod platform { } else { window.set_keep_below(true); } - window + Some(window) } pub fn reserve_space_for(_window: >k::Window, _monitor: gdk::Rectangle, _strut_def: StrutDefinition) -> Result<()> { @@ -36,7 +36,7 @@ mod platform { use gdk; use gtk::prelude::*; - pub fn initialize_window(window_def: &EwwWindowDefinition, monitor: gdk::Rectangle) -> gtk::Window { + pub fn initialize_window(window_def: &EwwWindowDefinition, monitor: gdk::Rectangle) -> Option { let window = gtk::Window::new(gtk::WindowType::Toplevel); // Initialising a layer shell surface gtk_layer_shell::init_for_window(&window); @@ -45,9 +45,11 @@ mod platform { Some(index) => { if let Some(monitor) = gdk::Display::get_default().expect("could not get default display").get_monitor(index) { gtk_layer_shell::set_monitor(&window, &monitor); - }; + } else { + return None + } } - None => {} + None => {}, }; window.set_resizable(true); @@ -100,7 +102,7 @@ mod platform { if window_def.exclusive { gtk_layer_shell::auto_exclusive_zone_enable(&window); } - window + Some(window) } } @@ -119,7 +121,7 @@ mod platform { rust_connection::{DefaultStream, RustConnection}, }; - pub fn initialize_window(window_def: &EwwWindowDefinition, _monitor: gdk::Rectangle) -> gtk::Window { + pub fn initialize_window(window_def: &EwwWindowDefinition, _monitor: gdk::Rectangle) -> Option { let window = if window_def.focusable { gtk::Window::new(gtk::WindowType::Toplevel) } else { @@ -134,7 +136,7 @@ mod platform { } else { window.set_keep_below(true); } - window + Some(window) } pub fn reserve_space_for(window: >k::Window, monitor: gdk::Rectangle, strut_def: StrutDefinition) -> Result<()> {