1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-02 03:01:04 +02:00

fix(popup): often opening in wrong place

Fixes #16.
This commit is contained in:
Jake Stanger 2022-10-14 23:48:28 +01:00
parent 9e31107251
commit 5523e9af46
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
3 changed files with 29 additions and 7 deletions

View file

@ -416,7 +416,15 @@ impl Module<gtk::Box> for LauncherModule {
controller_tx: Sender<Self::ReceiveMessage>,
rx: glib::Receiver<Self::SendMessage>,
) -> 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();
@ -432,9 +440,8 @@ impl Module<gtk::Box> 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<gtk::Box> 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<gtk::Box> for LauncherModule {
}
container.show_all();
container.set_width_request(MAX_WIDTH);
}
}
_ => {}
@ -515,3 +522,18 @@ impl Module<gtk::Box> 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::<String>() + "..."
} else {
str.to_string()
}
}