mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-09-15 19:26:58 +02:00
refactor(tray): complete client rewrite
This commit is contained in:
parent
c7b6ee8bc0
commit
004ea76da5
9 changed files with 193 additions and 246 deletions
|
@ -1,4 +1,5 @@
|
|||
use crate::image::ImageProvider;
|
||||
use crate::modules::tray::interface::TrayMenu;
|
||||
use color_eyre::{Report, Result};
|
||||
use glib::ffi::g_strfreev;
|
||||
use glib::translate::ToGlibPtr;
|
||||
|
@ -10,7 +11,6 @@ use std::collections::HashSet;
|
|||
use std::ffi::CStr;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
use std::ptr;
|
||||
use system_tray::message::tray::StatusNotifierItem;
|
||||
|
||||
/// Gets the GTK icon theme search paths by calling the FFI function.
|
||||
/// Conveniently returns the result as a `HashSet`.
|
||||
|
@ -38,17 +38,23 @@ fn get_icon_theme_search_paths(icon_theme: &IconTheme) -> HashSet<String> {
|
|||
paths
|
||||
}
|
||||
|
||||
pub fn get_image(item: &StatusNotifierItem, icon_theme: &IconTheme, size: u32) -> Result<Image> {
|
||||
get_image_from_icon_name(item, icon_theme, size).or_else(|_| get_image_from_pixmap(item, size))
|
||||
pub fn get_image(
|
||||
item: &TrayMenu,
|
||||
icon_theme: &IconTheme,
|
||||
size: u32,
|
||||
prefer_icons: bool,
|
||||
) -> Result<Image> {
|
||||
if !prefer_icons && item.icon_pixmap.is_some() {
|
||||
get_image_from_pixmap(item, size)
|
||||
} else {
|
||||
get_image_from_icon_name(item, icon_theme, size)
|
||||
.or_else(|_| get_image_from_pixmap(item, size))
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to get a GTK `Image` component
|
||||
/// for the status notifier item's icon.
|
||||
fn get_image_from_icon_name(
|
||||
item: &StatusNotifierItem,
|
||||
icon_theme: &IconTheme,
|
||||
size: u32,
|
||||
) -> Result<Image> {
|
||||
fn get_image_from_icon_name(item: &TrayMenu, icon_theme: &IconTheme, size: u32) -> Result<Image> {
|
||||
if let Some(path) = item.icon_theme_path.as_ref() {
|
||||
if !path.is_empty() && !get_icon_theme_search_paths(icon_theme).contains(path) {
|
||||
icon_theme.append_search_path(path);
|
||||
|
@ -59,18 +65,21 @@ fn get_image_from_icon_name(
|
|||
icon_theme.lookup_icon(icon_name, size as i32, IconLookupFlags::empty())
|
||||
});
|
||||
|
||||
let pixbuf = icon_info.unwrap().load_icon()?;
|
||||
|
||||
let image = Image::new();
|
||||
ImageProvider::create_and_load_surface(&pixbuf, &image)?;
|
||||
Ok(image)
|
||||
if let Some(icon_info) = icon_info {
|
||||
let pixbuf = icon_info.load_icon()?;
|
||||
let image = Image::new();
|
||||
ImageProvider::create_and_load_surface(&pixbuf, &image)?;
|
||||
Ok(image)
|
||||
} else {
|
||||
Err(Report::msg("could not find icon"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to get an image from the item pixmap.
|
||||
///
|
||||
/// The pixmap is supplied in ARGB32 format,
|
||||
/// which has 8 bits per sample and a bit stride of `4*width`.
|
||||
fn get_image_from_pixmap(item: &StatusNotifierItem, size: u32) -> Result<Image> {
|
||||
fn get_image_from_pixmap(item: &TrayMenu, size: u32) -> Result<Image> {
|
||||
const BITS_PER_SAMPLE: i32 = 8;
|
||||
|
||||
let pixmap = item
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue