mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-02 03:01:04 +02:00
fix: popup placement issues
This commit is contained in:
parent
8518262053
commit
8576ac5c44
7 changed files with 54 additions and 66 deletions
|
@ -2,7 +2,6 @@ mod popup;
|
|||
|
||||
use self::popup::Popup;
|
||||
use crate::modules::{Module, ModuleInfo};
|
||||
use crate::popup::PopupAlignment;
|
||||
use chrono::Local;
|
||||
use glib::Continue;
|
||||
use gtk::prelude::*;
|
||||
|
@ -33,6 +32,7 @@ impl Module<Button> for ClockModule {
|
|||
let popup = Popup::new(
|
||||
"popup-clock",
|
||||
info.app,
|
||||
info.monitor,
|
||||
Orientation::Vertical,
|
||||
info.bar_position,
|
||||
);
|
||||
|
@ -41,14 +41,7 @@ impl Module<Button> for ClockModule {
|
|||
button.show_all();
|
||||
|
||||
button.connect_clicked(move |button| {
|
||||
let button_w = button.allocation().width();
|
||||
|
||||
let (button_x, _) = button
|
||||
.translate_coordinates(&button.toplevel().unwrap(), 0, 0)
|
||||
.unwrap();
|
||||
|
||||
popup.show();
|
||||
popup.set_pos(f64::from(button_x + button_w), PopupAlignment::Right);
|
||||
popup.show(button);
|
||||
});
|
||||
|
||||
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::collection::Collection;
|
|||
use crate::icon::{find_desktop_file, get_icon};
|
||||
use crate::modules::launcher::popup::Popup;
|
||||
use crate::modules::launcher::FocusEvent;
|
||||
use crate::popup::PopupAlignment;
|
||||
use crate::sway::SwayNode;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{Button, IconTheme, Image};
|
||||
|
@ -175,19 +174,8 @@ impl LauncherItem {
|
|||
button.connect_enter_notify_event(move |button, _| {
|
||||
let windows = windows.lock().unwrap();
|
||||
if windows.len() > 1 {
|
||||
let button_w = button.allocation().width();
|
||||
|
||||
let (button_x, _) = button
|
||||
.translate_coordinates(&button.toplevel().unwrap(), 0, 0)
|
||||
.unwrap();
|
||||
|
||||
let button_center = f64::from(button_x) + f64::from(button_w) / 2.0;
|
||||
|
||||
popup.set_windows(windows.as_slice(), &tx_hover);
|
||||
popup.show();
|
||||
|
||||
// TODO: Pass through module location
|
||||
popup.set_pos(button_center, PopupAlignment::Center);
|
||||
popup.show(button);
|
||||
}
|
||||
|
||||
Inhibit(false)
|
||||
|
|
|
@ -194,6 +194,7 @@ impl Module<gtk::Box> for LauncherModule {
|
|||
let popup = Popup::new(
|
||||
"popup-launcher",
|
||||
info.app,
|
||||
info.monitor,
|
||||
Orientation::Vertical,
|
||||
info.bar_position,
|
||||
);
|
||||
|
|
|
@ -17,6 +17,7 @@ use crate::config::BarPosition;
|
|||
/// Shamelessly stolen from here:
|
||||
/// <https://github.com/zeroeightysix/rustbar/blob/master/src/modules/module.rs>
|
||||
use glib::IsA;
|
||||
use gtk::gdk::Monitor;
|
||||
use gtk::{Application, Widget};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_json::Value;
|
||||
|
@ -32,6 +33,7 @@ pub struct ModuleInfo<'a> {
|
|||
pub app: &'a Application,
|
||||
pub location: ModuleLocation,
|
||||
pub bar_position: &'a BarPosition,
|
||||
pub monitor: &'a Monitor,
|
||||
pub output_name: &'a str,
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ use self::popup::Popup;
|
|||
use crate::modules::mpd::client::{get_connection, get_duration, get_elapsed};
|
||||
use crate::modules::mpd::popup::{MpdPopup, PopupEvent};
|
||||
use crate::modules::{Module, ModuleInfo};
|
||||
use crate::popup::PopupAlignment;
|
||||
use dirs::home_dir;
|
||||
use glib::Continue;
|
||||
use gtk::prelude::*;
|
||||
|
@ -80,7 +79,7 @@ fn get_tokens(re: &Regex, format_string: &str) -> Vec<String> {
|
|||
}
|
||||
|
||||
enum Event {
|
||||
Open(f64),
|
||||
Open,
|
||||
Update(Box<Option<(Song, Status, String)>>),
|
||||
}
|
||||
|
||||
|
@ -96,6 +95,7 @@ impl Module<Button> for MpdModule {
|
|||
let popup = Popup::new(
|
||||
"popup-mpd",
|
||||
info.app,
|
||||
info.monitor,
|
||||
Orientation::Horizontal,
|
||||
info.bar_position,
|
||||
);
|
||||
|
@ -106,16 +106,8 @@ impl Module<Button> for MpdModule {
|
|||
|
||||
let music_dir = self.music_dir.clone();
|
||||
|
||||
button.connect_clicked(move |button| {
|
||||
let button_w = button.allocation().width();
|
||||
|
||||
let (button_x, _) = button
|
||||
.translate_coordinates(&button.toplevel().unwrap(), 0, 0)
|
||||
.unwrap();
|
||||
|
||||
click_tx
|
||||
.send(Event::Open(f64::from(button_x + button_w)))
|
||||
.unwrap();
|
||||
button.connect_clicked(move |_| {
|
||||
click_tx.send(Event::Open).unwrap();
|
||||
});
|
||||
|
||||
let host = self.host.clone();
|
||||
|
@ -167,9 +159,8 @@ impl Module<Button> for MpdModule {
|
|||
|
||||
rx.attach(None, move |event| {
|
||||
match event {
|
||||
Event::Open(pos) => {
|
||||
mpd_popup.popup.show();
|
||||
mpd_popup.popup.set_pos(pos, PopupAlignment::Right);
|
||||
Event::Open => {
|
||||
mpd_popup.popup.show(&button);
|
||||
}
|
||||
Event::Update(mut msg) => {
|
||||
if let Some((song, status, string)) = msg.take() {
|
||||
|
@ -220,7 +211,7 @@ impl MpdModule {
|
|||
PlayState::Playing => self.icon_play.as_ref(),
|
||||
PlayState::Paused => self.icon_pause.as_ref(),
|
||||
};
|
||||
icon.map(|i| i.as_str())
|
||||
icon.map(String::as_str)
|
||||
}
|
||||
"title" => song.title(),
|
||||
"album" => try_get_first_tag(song.tags.get(&Tag::Album)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue