From 1ee73ec62968c4a2cd8c88e7977aabcc9448860a Mon Sep 17 00:00:00 2001 From: kotontrion Date: Thu, 7 Nov 2024 11:40:04 +0100 Subject: tray: use appmenu-glib-translator for menus --- lib/tray/trayItem.vala | 84 ++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 36 deletions(-) (limited to 'lib/tray/trayItem.vala') diff --git a/lib/tray/trayItem.vala b/lib/tray/trayItem.vala index db0e6d4..57f7a23 100644 --- a/lib/tray/trayItem.vala +++ b/lib/tray/trayItem.vala @@ -1,4 +1,3 @@ -using DbusmenuGtk; namespace AstalTray { public struct Pixmap { @@ -169,6 +168,22 @@ public class TrayItem : Object { /** the id of the item used to uniquely identify the TrayItems by this lib.*/ public string item_id { get; private set; } + private DBusMenu.Importer menu_importer; + + public MenuModel menu_model { + owned get { + if (menu_importer == null) return null; + return menu_importer.model; + } + } + + public ActionGroup action_group { + owned get { + if (menu_importer == null) return null; + return menu_importer.action_group; + } + } + public signal void changed(); public signal void ready(); @@ -197,6 +212,14 @@ public class TrayItem : Object { } }); + if(proxy.Menu != null) { + this.menu_importer = new DBusMenu.Importer(proxy.get_name_owner(), proxy.Menu); + this.menu_importer.notify["model"].connect(() => { + notify_property("menu-model"); + notify_property("action-group"); + }); + } + update_gicon(); ready(); @@ -217,17 +240,18 @@ public class TrayItem : Object { private void update_gicon() { if(icon_name != null && icon_name != "") { if(icon_theme_path != null && icon_theme_path != "") { - - Gtk.IconTheme icon_theme = new Gtk.IconTheme(); - string[] paths = {icon_theme_path}; - icon_theme.set_search_path(paths); - - int size = icon_theme.get_icon_sizes(icon_name)[0]; - Gtk.IconInfo icon_info = icon_theme.lookup_icon( - icon_name, size, Gtk.IconLookupFlags.FORCE_SIZE); - - if (icon_info != null) - gicon = new GLib.FileIcon(GLib.File.new_for_path(icon_info.get_filename())); + //TODO: icon loopkup + + // Gtk.IconTheme icon_theme = new Gtk.IconTheme(); + // string[] paths = {icon_theme_path}; + // icon_theme.set_search_path(paths); + // + // int size = icon_theme.get_icon_sizes(icon_name)[0]; + // Gtk.IconInfo icon_info = icon_theme.lookup_icon( + // icon_name, size, Gtk.IconLookupFlags.FORCE_SIZE); + // + // if (icon_info != null) + // gicon = new GLib.FileIcon(GLib.File.new_for_path(icon_info.get_filename())); } else { gicon = new GLib.ThemedIcon(icon_name); } @@ -312,18 +336,6 @@ public class TrayItem : Object { } } - /** - * creates a new Gtk Menu for this item. - */ - public Gtk.Menu? create_menu() { - if (proxy.Menu == null) - return null; - - return new DbusmenuGtk.Menu( - proxy.get_name_owner(), - proxy.Menu); - } - private Gdk.Pixbuf? _get_icon_pixbuf() { Pixmap[] pixmaps = proxy.Status == Status.NEEDS_ATTENTION ? proxy.AttentionIconPixmap @@ -351,18 +363,18 @@ public class TrayItem : Object { if (icon_name == "" || icon_name == null) return null; - - Gtk.IconTheme icon_theme = new Gtk.IconTheme(); - string[] paths = {theme_path}; - icon_theme.set_search_path(paths); - - int size = icon_theme.get_icon_sizes(icon_name)[0]; - Gtk.IconInfo icon_info = icon_theme.lookup_icon( - icon_name, size, Gtk.IconLookupFlags.FORCE_SIZE); - - if (icon_info != null) - return icon_info.load_icon(); - + // + // Gtk.IconTheme icon_theme = new Gtk.IconTheme(); + // string[] paths = {theme_path}; + // icon_theme.set_search_path(paths); + // + // int size = icon_theme.get_icon_sizes(icon_name)[0]; + // Gtk.IconInfo icon_info = icon_theme.lookup_icon( + // icon_name, size, Gtk.IconLookupFlags.FORCE_SIZE); + // + // if (icon_info != null) + // return icon_info.load_icon(); + // return null; } -- cgit v1.2.3 From 07bcaf9c26a28ac6afbbab73bb7660c0b32efc30 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Fri, 8 Nov 2024 10:15:13 +0100 Subject: tray: icon lookup --- lib/tray/trayItem.vala | 79 ++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 47 deletions(-) (limited to 'lib/tray/trayItem.vala') diff --git a/lib/tray/trayItem.vala b/lib/tray/trayItem.vala index 57f7a23..be221bf 100644 --- a/lib/tray/trayItem.vala +++ b/lib/tray/trayItem.vala @@ -239,19 +239,9 @@ public class TrayItem : Object { private void update_gicon() { if(icon_name != null && icon_name != "") { - if(icon_theme_path != null && icon_theme_path != "") { - //TODO: icon loopkup - - // Gtk.IconTheme icon_theme = new Gtk.IconTheme(); - // string[] paths = {icon_theme_path}; - // icon_theme.set_search_path(paths); - // - // int size = icon_theme.get_icon_sizes(icon_name)[0]; - // Gtk.IconInfo icon_info = icon_theme.lookup_icon( - // icon_name, size, Gtk.IconLookupFlags.FORCE_SIZE); - // - // if (icon_info != null) - // gicon = new GLib.FileIcon(GLib.File.new_for_path(icon_info.get_filename())); + if(icon_theme_path != null && icon_theme_path != "") { + gicon = new GLib.FileIcon(GLib.File.new_for_path( + find_icon_in_theme(icon_name, icon_theme_path))); } else { gicon = new GLib.ThemedIcon(icon_name); } @@ -336,46 +326,41 @@ public class TrayItem : Object { } } - private Gdk.Pixbuf? _get_icon_pixbuf() { - Pixmap[] pixmaps = proxy.Status == Status.NEEDS_ATTENTION - ? proxy.AttentionIconPixmap - : proxy.IconPixmap; - - - string icon_name = proxy.Status == Status.NEEDS_ATTENTION - ? proxy.AttentionIconName - : proxy.IconName; - - Gdk.Pixbuf pixbuf = null; + private string? find_icon_in_theme(string icon_name, string theme_path){ + if(icon_name == null || theme_path == null || icon_name == "" || theme_path == "") return null; + + try { + Dir dir = Dir.open (theme_path, 0); + string? name = null; + + while ((name = dir.read_name ()) != null) { + string path = Path.build_filename (theme_path, name); + + if (FileUtils.test (path, FileTest.IS_DIR)) { + string? icon = find_icon_in_theme(icon_name, path); + if(icon != null) return icon; + else continue; + } - if (icon_name != null && proxy.IconThemePath != null) - pixbuf = load_from_theme(icon_name, proxy.IconThemePath); + int dot_index = name.last_index_of("."); + if (dot_index != -1) + name = name.substring(0, dot_index); + if (name == icon_name) return path; - if (pixbuf == null) - pixbuf = pixmap_to_pixbuf(pixmaps); + } + } catch (FileError err) { + return null; + } + return null; - return pixbuf; } - private Gdk.Pixbuf? load_from_theme(string icon_name, string theme_path) { - if (theme_path == "" || theme_path == null) - return null; + private Gdk.Pixbuf? _get_icon_pixbuf() { + Pixmap[] pixmaps = proxy.Status == Status.NEEDS_ATTENTION + ? proxy.AttentionIconPixmap + : proxy.IconPixmap; - if (icon_name == "" || icon_name == null) - return null; - // - // Gtk.IconTheme icon_theme = new Gtk.IconTheme(); - // string[] paths = {theme_path}; - // icon_theme.set_search_path(paths); - // - // int size = icon_theme.get_icon_sizes(icon_name)[0]; - // Gtk.IconInfo icon_info = icon_theme.lookup_icon( - // icon_name, size, Gtk.IconLookupFlags.FORCE_SIZE); - // - // if (icon_info != null) - // return icon_info.load_icon(); - // - return null; + return pixmap_to_pixbuf(pixmaps); } private Gdk.Pixbuf? pixmap_to_pixbuf(Pixmap[] pixmaps) { -- cgit v1.2.3 From 361fe5d1937bf2220e7e35a7e26fbd2a6b0a2d83 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Tue, 26 Nov 2024 09:44:39 +0100 Subject: tray: workaround for icon name as path --- lib/tray/trayItem.vala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/tray/trayItem.vala') diff --git a/lib/tray/trayItem.vala b/lib/tray/trayItem.vala index be221bf..d1de0c3 100644 --- a/lib/tray/trayItem.vala +++ b/lib/tray/trayItem.vala @@ -239,7 +239,10 @@ public class TrayItem : Object { private void update_gicon() { if(icon_name != null && icon_name != "") { - if(icon_theme_path != null && icon_theme_path != "") { + if(GLib.FileUtils.test(icon_name, GLib.FileTest.EXISTS)) { + gicon = new GLib.FileIcon(GLib.File.new_for_path(icon_name)); + } + else if(icon_theme_path != null && icon_theme_path != "") { gicon = new GLib.FileIcon(GLib.File.new_for_path( find_icon_in_theme(icon_name, icon_theme_path))); } else { -- cgit v1.2.3 From 64150c7739049e3cc9b6b931eba58a635cbc24df Mon Sep 17 00:00:00 2001 From: kotontrion Date: Tue, 10 Dec 2024 16:09:18 +0100 Subject: tray: use highest res pixmap available --- lib/tray/trayItem.vala | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/tray/trayItem.vala') diff --git a/lib/tray/trayItem.vala b/lib/tray/trayItem.vala index d1de0c3..14a2ba7 100644 --- a/lib/tray/trayItem.vala +++ b/lib/tray/trayItem.vala @@ -371,6 +371,12 @@ public class TrayItem : Object { return null; Pixmap pixmap = pixmaps[0]; + + for(int i = 0; i < pixmaps.length; i++){ + if(pixmap.width < pixmaps[i].width) + pixmap = pixmaps[i]; + }; + uint8[] image_data = pixmap.bytes.copy(); for (int i = 0; i < pixmap.width * pixmap.height * 4; i += 4) { -- cgit v1.2.3 From c5664e2941b33609de0743a8475a40b24522a3dc Mon Sep 17 00:00:00 2001 From: Aylur Date: Thu, 19 Dec 2024 23:42:33 +0100 Subject: update examples, fix styling --- lib/tray/trayItem.vala | 185 ++++++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 87 deletions(-) (limited to 'lib/tray/trayItem.vala') diff --git a/lib/tray/trayItem.vala b/lib/tray/trayItem.vala index 14a2ba7..991abce 100644 --- a/lib/tray/trayItem.vala +++ b/lib/tray/trayItem.vala @@ -1,4 +1,3 @@ - namespace AstalTray { public struct Pixmap { int width; @@ -87,21 +86,20 @@ public class TrayItem : Object { private IItem proxy; private List connection_ids; - /** The Title of the TrayItem */ public string title { owned get { return proxy.Title; } } - + /** The category this item belongs to */ public Category category { get { return proxy.Category; } } - - /** the current status of this item */ + + /** The current status of this item */ public Status status { get { return proxy.Status; } } - - /** the tooltip of this item */ + + /** The tooltip of this item */ public Tooltip? tooltip { owned get { return proxy.ToolTip; } } - - /** - * a markup representation of the tooltip. This is basically equvivalent + + /** + * A markup representation of the tooltip. This is basically equvivalent * to `tooltip.title \n tooltip.description` */ public string tooltip_markup { @@ -119,26 +117,24 @@ public class TrayItem : Object { /** the id of the item. This id is specified by the tray app.*/ public string id { owned get { return proxy.Id ;} } - - /** - * If set, this only supports the menu, so showing the menu should be prefered + + /** + * If set, this only supports the menu, so showing the menu should be prefered * over calling [method@AstalTray.TrayItem.activate]. */ public bool is_menu { get { return proxy.ItemIsMenu ;} } - - /** - * the icon theme path, where to look for the [property@AstalTray.TrayItem:icon-name]. - * - * It is recommended to use the [property@AstalTray.TrayItem:gicon] property, + + /** + * The icon theme path, where to look for the [property@AstalTray.TrayItem:icon-name]. + * It is recommended to use the [property@AstalTray.TrayItem:gicon] property, * which does the icon lookups for you. */ public string icon_theme_path { owned get { return proxy.IconThemePath ;} } - - /** - * the name of the icon. This should be looked up in the [property@AstalTray.TrayItem:icon-theme-path] - * if set or in the currently used icon theme otherwise. - * - * It is recommended to use the [property@AstalTray.TrayItem:gicon] property, + + /** + * The name of the icon. This should be looked up in the [property@AstalTray.TrayItem:icon-theme-path] + * if set or in the currently used icon theme otherwise. + * It is recommended to use the [property@AstalTray.TrayItem:gicon] property, * which does the icon lookups for you. */ public string icon_name { @@ -148,40 +144,39 @@ public class TrayItem : Object { : proxy.IconName; } } - - /** - * a pixbuf containing the icon. - * - * It is recommended to use the [property@AstalTray.TrayItem:gicon] property, + + /** + * A pixbuf containing the icon. + * It is recommended to use the [property@AstalTray.TrayItem:gicon] property, * which does the icon lookups for you. */ public Gdk.Pixbuf icon_pixbuf { owned get { return _get_icon_pixbuf(); } } /** - * contains the items icon. This property is intended to be used with the gicon property + * Contains the items icon. This property is intended to be used with the gicon property * of the Icon widget and the recommended way to display the icon. - * This property unifies the [property@AstalTray.TrayItem:icon-name], + * This property unifies the [property@AstalTray.TrayItem:icon-name], * [property@AstalTray.TrayItem:icon-theme-path] and [property@AstalTray.TrayItem:icon-pixbuf] properties. */ public GLib.Icon gicon { get; private set; } - - /** the id of the item used to uniquely identify the TrayItems by this lib.*/ + + /** The id of the item used to uniquely identify the TrayItems by this lib.*/ public string item_id { get; private set; } private DBusMenu.Importer menu_importer; - + public MenuModel menu_model { - owned get { - if (menu_importer == null) return null; - return menu_importer.model; - } + owned get { + if (menu_importer == null) return null; + return menu_importer.model; + } } public ActionGroup action_group { - owned get { - if (menu_importer == null) return null; - return menu_importer.action_group; - } + owned get { + if (menu_importer == null) return null; + return menu_importer.action_group; + } } public signal void changed(); @@ -198,7 +193,8 @@ public class TrayItem : Object { proxy = yield Bus.get_proxy( BusType.SESSION, service, - path); + path + ); connection_ids.append(proxy.NewStatus.connect(refresh_all_properties)); connection_ids.append(proxy.NewToolTip.connect(refresh_all_properties)); @@ -211,17 +207,16 @@ public class TrayItem : Object { SignalHandler.disconnect(proxy, id); } }); - - if(proxy.Menu != null) { - this.menu_importer = new DBusMenu.Importer(proxy.get_name_owner(), proxy.Menu); - this.menu_importer.notify["model"].connect(() => { - notify_property("menu-model"); - notify_property("action-group"); - }); + + if (proxy.Menu != null) { + this.menu_importer = new DBusMenu.Importer(proxy.get_name_owner(), proxy.Menu); + this.menu_importer.notify["model"].connect(() => { + notify_property("menu-model"); + notify_property("action-group"); + }); } update_gicon(); - ready(); } catch (Error err) { critical(err.message); @@ -229,22 +224,33 @@ public class TrayItem : Object { } private void _notify() { - string[] props = { "category", "id", "title", "status", "is-menu", "tooltip-markup", "icon-name", "icon-pixbuf" }; + string[] props = { + "category", + "id", + "title", + "status", + "is-menu", + "tooltip-markup", + "icon-name", + "icon-pixbuf" + }; - foreach (string prop in props) + foreach (string prop in props) { notify_property(prop); + } changed(); } private void update_gicon() { - if(icon_name != null && icon_name != "") { - if(GLib.FileUtils.test(icon_name, GLib.FileTest.EXISTS)) { + if (icon_name != null && icon_name != "") { + if (GLib.FileUtils.test(icon_name, GLib.FileTest.EXISTS)) { gicon = new GLib.FileIcon(GLib.File.new_for_path(icon_name)); } else if(icon_theme_path != null && icon_theme_path != "") { gicon = new GLib.FileIcon(GLib.File.new_for_path( - find_icon_in_theme(icon_name, icon_theme_path))); + find_icon_in_theme(icon_name, icon_theme_path) + )); } else { gicon = new GLib.ThemedIcon(icon_name); } @@ -291,33 +297,35 @@ public class TrayItem : Object { } ); } - + /** - * send an activate request to the tray app. + * Send an activate request to the tray app. */ public void activate(int x, int y) { try { proxy.Activate(x, y); } catch (Error e) { - if(e.domain != DBusError.quark() || e.code != DBusError.UNKNOWN_METHOD) + if (e.domain != DBusError.quark() || e.code != DBusError.UNKNOWN_METHOD) { warning(e.message); + } } } /** - * send a secondary activate request to the tray app. + * Send a secondary activate request to the tray app. */ public void secondary_activate(int x, int y) { try { proxy.SecondaryActivate(x, y); } catch (Error e) { - if(e.domain != DBusError.quark() || e.code != DBusError.UNKNOWN_METHOD) + if (e.domain != DBusError.quark() || e.code != DBusError.UNKNOWN_METHOD) { warning(e.message); + } } } /** - * send a scroll request to the tray app. + * Send a scroll request to the tray app. * valid values for the orientation are "horizontal" and "vertical". */ public void scroll(int delta, string orientation) { @@ -330,31 +338,34 @@ public class TrayItem : Object { } private string? find_icon_in_theme(string icon_name, string theme_path){ - if(icon_name == null || theme_path == null || icon_name == "" || theme_path == "") return null; - - try { - Dir dir = Dir.open (theme_path, 0); - string? name = null; - - while ((name = dir.read_name ()) != null) { - string path = Path.build_filename (theme_path, name); - - if (FileUtils.test (path, FileTest.IS_DIR)) { - string? icon = find_icon_in_theme(icon_name, path); - if(icon != null) return icon; - else continue; - } + if (icon_name == null || theme_path == null || icon_name == "" || theme_path == "") { + return null; + } - int dot_index = name.last_index_of("."); - if (dot_index != -1) - name = name.substring(0, dot_index); - if (name == icon_name) return path; + try { + Dir dir = Dir.open(theme_path, 0); + string? name = null; + + while ((name = dir.read_name ()) != null) { + var path = Path.build_filename(theme_path, name); + + if (FileUtils.test(path, FileTest.IS_DIR)) { + string? icon = find_icon_in_theme(icon_name, path); + if (icon != null) return icon; + else continue; + } + + int dot_index = name.last_index_of("."); + if (dot_index != -1) { + name = name.substring(0, dot_index); + } - } - } catch (FileError err) { - return null; - } - return null; + if (name == icon_name) return path; + } + } catch (FileError err) { + return null; + } + return null; } @@ -371,8 +382,8 @@ public class TrayItem : Object { return null; Pixmap pixmap = pixmaps[0]; - - for(int i = 0; i < pixmaps.length; i++){ + + for (int i = 0; i < pixmaps.length; i++){ if(pixmap.width < pixmaps[i].width) pixmap = pixmaps[i]; }; -- cgit v1.2.3