diff --git a/src/bar.rs b/src/bar.rs index e72889f..688ba43 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -175,8 +175,8 @@ fn add_modules( let popup = popup.read().expect("Failed to get read lock on popup"); popup.hide(); - popup.show(x, w); popup.show_content($id); + popup.show(x, w); } ModuleUpdateEvent::ClosePopup => { debug!("Closing popup for {} [#{}]", $name, $id); diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index 5070bb8..906f638 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -416,7 +416,15 @@ impl Module for LauncherModule { controller_tx: Sender, rx: glib::Receiver, ) -> Option { - let container = gtk::Box::new(Orientation::Vertical, 0); + const MAX_WIDTH: i32 = 250; + + let container = gtk::Box::builder() + .orientation(Orientation::Vertical) + .build(); + + let placeholder = Button::with_label("PLACEHOLDER"); + placeholder.set_width_request(MAX_WIDTH); + container.add(&placeholder); let mut buttons = Collection::>::new(); @@ -432,9 +440,8 @@ impl Module for LauncherModule { .into_iter() .map(|win| { let button = Button::builder() - .label(&win.name) + .label(&clamp(&win.name)) .height_request(40) - .width_request(100) .build(); { @@ -458,9 +465,8 @@ impl Module for LauncherModule { LauncherUpdate::AddWindow(app_id, win) => { if let Some(buttons) = buttons.get_mut(&app_id) { let button = Button::builder() - .label(&win.name) .height_request(40) - .width_request(100) + .label(&clamp(&win.name)) .build(); { @@ -503,6 +509,7 @@ impl Module for LauncherModule { } container.show_all(); + container.set_width_request(MAX_WIDTH); } } _ => {} @@ -515,3 +522,18 @@ impl Module for LauncherModule { Some(container) } } + +/// Clamps a string at 24 characters. +/// +/// This is a hacky number derived from +/// "what fits inside the 250px popup" +/// and probably won't hold up with wide fonts. +fn clamp(str: &str) -> String { + const MAX_CHARS: usize = 24; + + if str.len() > MAX_CHARS { + str.chars().take(MAX_CHARS - 3).collect::() + "..." + } else { + str.to_string() + } +} diff --git a/src/popup.rs b/src/popup.rs index 7cf9b28..c072b4a 100644 --- a/src/popup.rs +++ b/src/popup.rs @@ -111,7 +111,7 @@ impl Popup { /// Sets the popover's X position relative to the left border of the screen fn set_pos(&self, button_x: i32, button_width: i32) { let screen_width = self.monitor.workarea().width(); - let popup_width = self.window.allocated_width(); + let (popup_width, _popup_height) = self.window.size(); let widget_center = f64::from(button_x) + f64::from(button_width) / 2.0;