mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
parent
9e31107251
commit
5523e9af46
3 changed files with 29 additions and 7 deletions
|
@ -175,8 +175,8 @@ fn add_modules(
|
||||||
|
|
||||||
let popup = popup.read().expect("Failed to get read lock on popup");
|
let popup = popup.read().expect("Failed to get read lock on popup");
|
||||||
popup.hide();
|
popup.hide();
|
||||||
popup.show(x, w);
|
|
||||||
popup.show_content($id);
|
popup.show_content($id);
|
||||||
|
popup.show(x, w);
|
||||||
}
|
}
|
||||||
ModuleUpdateEvent::ClosePopup => {
|
ModuleUpdateEvent::ClosePopup => {
|
||||||
debug!("Closing popup for {} [#{}]", $name, $id);
|
debug!("Closing popup for {} [#{}]", $name, $id);
|
||||||
|
|
|
@ -416,7 +416,15 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
controller_tx: Sender<Self::ReceiveMessage>,
|
controller_tx: Sender<Self::ReceiveMessage>,
|
||||||
rx: glib::Receiver<Self::SendMessage>,
|
rx: glib::Receiver<Self::SendMessage>,
|
||||||
) -> Option<gtk::Box> {
|
) -> Option<gtk::Box> {
|
||||||
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::<String, Collection<usize, Button>>::new();
|
let mut buttons = Collection::<String, Collection<usize, Button>>::new();
|
||||||
|
|
||||||
|
@ -432,9 +440,8 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|win| {
|
.map(|win| {
|
||||||
let button = Button::builder()
|
let button = Button::builder()
|
||||||
.label(&win.name)
|
.label(&clamp(&win.name))
|
||||||
.height_request(40)
|
.height_request(40)
|
||||||
.width_request(100)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -458,9 +465,8 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
LauncherUpdate::AddWindow(app_id, win) => {
|
LauncherUpdate::AddWindow(app_id, win) => {
|
||||||
if let Some(buttons) = buttons.get_mut(&app_id) {
|
if let Some(buttons) = buttons.get_mut(&app_id) {
|
||||||
let button = Button::builder()
|
let button = Button::builder()
|
||||||
.label(&win.name)
|
|
||||||
.height_request(40)
|
.height_request(40)
|
||||||
.width_request(100)
|
.label(&clamp(&win.name))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -503,6 +509,7 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
container.show_all();
|
container.show_all();
|
||||||
|
container.set_width_request(MAX_WIDTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -515,3 +522,18 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
Some(container)
|
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::<String>() + "..."
|
||||||
|
} else {
|
||||||
|
str.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl Popup {
|
||||||
/// Sets the popover's X position relative to the left border of the screen
|
/// Sets the popover's X position relative to the left border of the screen
|
||||||
fn set_pos(&self, button_x: i32, button_width: i32) {
|
fn set_pos(&self, button_x: i32, button_width: i32) {
|
||||||
let screen_width = self.monitor.workarea().width();
|
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;
|
let widget_center = f64::from(button_x) + f64::from(button_width) / 2.0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue