mirror of
https://github.com/JakeStanger/ironbar.git
synced 2024-11-22 05:34:35 +03:00
Merge pull request #782 from JakeStanger/fix/tray-fixes2
More tray fixes
This commit is contained in:
commit
bdf6b3b1b3
66
Cargo.lock
generated
66
Cargo.lock
generated
@ -17,12 +17,6 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "adler2"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.3"
|
||||
@ -285,7 +279,7 @@ dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"miniz_oxide 0.6.2",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
@ -567,15 +561,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.8"
|
||||
@ -904,15 +889,6 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
||||
|
||||
[[package]]
|
||||
name = "fdeflate"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07c6f4c64c1d33a3111c4466f7365ebdcc37c5bd1ea0d62aae2e3d722aacbedb"
|
||||
dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "field-offset"
|
||||
version = "0.3.5"
|
||||
@ -935,16 +911,6 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
@ -1733,7 +1699,6 @@ dependencies = [
|
||||
"mpris",
|
||||
"nix 0.29.0",
|
||||
"notify",
|
||||
"png",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"schemars",
|
||||
@ -1958,16 +1923,6 @@ dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "1.0.1"
|
||||
@ -2402,19 +2357,6 @@ version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.17.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"crc32fast",
|
||||
"fdeflate",
|
||||
"flate2",
|
||||
"miniz_oxide 0.8.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "polling"
|
||||
version = "2.7.0"
|
||||
@ -3046,12 +2988,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.8"
|
||||
|
@ -68,7 +68,7 @@ notifications = ["zbus"]
|
||||
|
||||
sys_info = ["sysinfo", "regex"]
|
||||
|
||||
tray = ["system-tray", "png"]
|
||||
tray = ["system-tray"]
|
||||
|
||||
upower = ["upower_dbus", "zbus", "futures-lite"]
|
||||
|
||||
@ -149,7 +149,6 @@ sysinfo = { version = "0.29.11", optional = true }
|
||||
|
||||
# tray
|
||||
system-tray = { version = "0.4.0", features = ["dbusmenu-gtk3"], optional = true }
|
||||
png = { version = "0.17.14", optional = true }
|
||||
|
||||
# upower
|
||||
upower_dbus = { version = "0.3.2", optional = true }
|
||||
|
@ -7,7 +7,6 @@ use gtk::ffi::gtk_icon_theme_get_search_path;
|
||||
use gtk::gdk_pixbuf::{Colorspace, InterpType, Pixbuf};
|
||||
use gtk::prelude::IconThemeExt;
|
||||
use gtk::{IconLookupFlags, IconTheme, Image};
|
||||
use png::ColorType;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
@ -126,36 +125,3 @@ fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result<Image> {
|
||||
ImageProvider::create_and_load_surface(&pixbuf, &image)?;
|
||||
Ok(image)
|
||||
}
|
||||
|
||||
pub struct PngData<'a>(pub &'a [u8]);
|
||||
impl TryFrom<PngData<'_>> for Image {
|
||||
type Error = Report;
|
||||
|
||||
fn try_from(value: PngData) -> std::result::Result<Self, Self::Error> {
|
||||
let data = value.0;
|
||||
|
||||
let decoder = png::Decoder::new(data);
|
||||
let mut reader = decoder.read_info()?;
|
||||
let mut buf = vec![0; reader.output_buffer_size()];
|
||||
|
||||
let info = reader.next_frame(&mut buf)?;
|
||||
let bytes = glib::Bytes::from(&buf[..info.buffer_size()]);
|
||||
|
||||
let has_alpha = matches!(info.color_type, ColorType::Rgba | ColorType::GrayscaleAlpha);
|
||||
let row_stride_multiplier = if has_alpha { 4 } else { 3 };
|
||||
|
||||
let pixbuf = Pixbuf::from_bytes(
|
||||
&bytes,
|
||||
Colorspace::Rgb,
|
||||
has_alpha,
|
||||
info.bit_depth as i32,
|
||||
info.width as i32,
|
||||
info.height as i32,
|
||||
(info.width * row_stride_multiplier) as i32,
|
||||
);
|
||||
|
||||
let image = Image::new();
|
||||
ImageProvider::create_and_load_surface(&pixbuf, &image)?;
|
||||
Ok(image)
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use system_tray::item::{IconPixmap, StatusNotifierItem, Tooltip};
|
||||
/// Main tray icon to show on the bar
|
||||
pub(crate) struct TrayMenu {
|
||||
pub event_box: EventBox,
|
||||
pub widget: MenuItem,
|
||||
widget: MenuItem,
|
||||
image_widget: Option<Image>,
|
||||
label_widget: Option<Label>,
|
||||
|
||||
@ -18,7 +18,7 @@ pub(crate) struct TrayMenu {
|
||||
}
|
||||
|
||||
impl TrayMenu {
|
||||
pub fn new(item: StatusNotifierItem) -> Self {
|
||||
pub fn new(address: &str, item: StatusNotifierItem) -> Self {
|
||||
let event_box = EventBox::new();
|
||||
|
||||
let widget = MenuItem::new();
|
||||
@ -27,7 +27,7 @@ impl TrayMenu {
|
||||
|
||||
event_box.show_all();
|
||||
|
||||
Self {
|
||||
let mut slf = Self {
|
||||
event_box,
|
||||
widget,
|
||||
image_widget: None,
|
||||
@ -36,7 +36,14 @@ impl TrayMenu {
|
||||
icon_name: item.icon_name,
|
||||
icon_theme_path: item.icon_theme_path,
|
||||
icon_pixmap: item.icon_pixmap,
|
||||
};
|
||||
|
||||
if let Some(menu) = item.menu {
|
||||
let menu = system_tray::gtk_menu::Menu::new(address, &menu);
|
||||
slf.set_menu_widget(menu);
|
||||
}
|
||||
|
||||
slf
|
||||
}
|
||||
|
||||
/// Updates the label text, and shows it in favour of the image.
|
||||
|
@ -150,7 +150,7 @@ fn on_update(
|
||||
Event::Add(address, item) => {
|
||||
debug!("Received new tray item at '{address}': {item:?}");
|
||||
|
||||
let mut menu_item = TrayMenu::new(*item);
|
||||
let mut menu_item = TrayMenu::new(&address, *item);
|
||||
container.pack_start(&menu_item.event_box, true, true, 0);
|
||||
|
||||
if let Ok(image) = icon::get_image(&menu_item, icon_theme, icon_size, prefer_icons) {
|
||||
@ -160,7 +160,7 @@ fn on_update(
|
||||
menu_item.set_label(&label);
|
||||
};
|
||||
|
||||
menu_item.widget.show();
|
||||
menu_item.event_box.show();
|
||||
menus.insert(address.into(), menu_item);
|
||||
}
|
||||
Event::Update(address, update) => {
|
||||
@ -210,7 +210,7 @@ fn on_update(
|
||||
debug!("Removing tray item at '{address}'");
|
||||
|
||||
if let Some(menu) = menus.get(address.as_str()) {
|
||||
container.remove(&menu.widget);
|
||||
container.remove(&menu.event_box);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user