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

Merge branch 'master' into feat/networkmanager

This commit is contained in:
Reinout Meliesie 2024-04-30 00:11:17 +02:00
commit 30613754ad
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
14 changed files with 157 additions and 28 deletions

View file

@ -62,12 +62,16 @@ impl Module<gtk::Box> for FocusedModule {
let wl = context.client::<wayland::Client>();
spawn(async move {
let mut current = None;
let mut wlrx = wl.subscribe_toplevels();
let handles = wl.toplevel_info_all();
let focused = handles.into_iter().find(|info| info.focused);
if let Some(focused) = focused {
current = Some(focused.id);
try_send!(
tx,
ModuleUpdateEvent::Update(Some((focused.title.clone(), focused.app_id)))
@ -77,8 +81,12 @@ impl Module<gtk::Box> for FocusedModule {
while let Ok(event) = wlrx.recv().await {
match event {
ToplevelEvent::Update(info) => {
println!("{current:?} | {info:?}");
if info.focused {
debug!("Changing focus");
current = Some(info.id);
send_async!(
tx,
ModuleUpdateEvent::Update(Some((
@ -86,13 +94,16 @@ impl Module<gtk::Box> for FocusedModule {
info.app_id.clone()
)))
);
} else {
} else if info.id == current.unwrap_or_default() {
debug!("Clearing focus");
current = None;
send_async!(tx, ModuleUpdateEvent::Update(None));
}
}
ToplevelEvent::Remove(info) => {
if info.focused {
debug!("Clearing focus");
current = None;
send_async!(tx, ModuleUpdateEvent::Update(None));
}
}

View file

@ -33,6 +33,9 @@ pub struct LauncherModule {
#[serde(default = "default_icon_size")]
icon_size: i32,
#[serde(default = "crate::config::default_false")]
reversed: bool,
#[serde(flatten)]
pub common: Option<CommonConfig>,
}
@ -338,7 +341,12 @@ impl Module<gtk::Box> for LauncherModule {
&controller_tx,
);
container.add(&button.button);
if self.reversed {
container.pack_end(&button.button, false, false, 0);
} else {
container.add(&button.button);
}
buttons.insert(item.app_id, button);
}
}

View file

@ -79,6 +79,8 @@ fn get_image_from_icon_name(item: &TrayMenu, icon_theme: &IconTheme, size: u32)
///
/// The pixmap is supplied in ARGB32 format,
/// which has 8 bits per sample and a bit stride of `4*width`.
/// The Pixbuf expects RGBA32 format, so some channel shuffling
/// is required.
fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result<Image> {
const BITS_PER_SAMPLE: i32 = 8;
@ -88,8 +90,18 @@ fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result<Image> {
.and_then(|pixmap| pixmap.first())
.ok_or_else(|| Report::msg("Failed to get pixmap from tray icon"))?;
let bytes = glib::Bytes::from(&pixmap.pixels);
let mut pixels = pixmap.pixels.to_vec();
for i in (0..pixels.len()).step_by(4) {
let alpha = pixels[i];
pixels[i] = pixels[i + 1];
pixels[i + 1] = pixels[i + 2];
pixels[i + 2] = pixels[i + 3];
pixels[i + 3] = alpha;
}
let row_stride = pixmap.width * 4;
let bytes = glib::Bytes::from(&pixels);
let pixbuf = Pixbuf::from_bytes(
&bytes,