diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/astal/io/process.vala | 13 | ||||
-rw-r--r-- | lib/astal/io/variable.vala | 2 | ||||
-rw-r--r-- | lib/tray/meson.build | 48 | ||||
-rw-r--r-- | lib/tray/trayItem.vala | 219 |
4 files changed, 134 insertions, 148 deletions
diff --git a/lib/astal/io/process.vala b/lib/astal/io/process.vala index cfd05b9..4b77aee 100644 --- a/lib/astal/io/process.vala +++ b/lib/astal/io/process.vala @@ -76,7 +76,7 @@ public class AstalIO.Process : Object { * * The first element of the vector is executed with the remaining elements as the argument list. */ - public Process.subprocessv(string[] cmd) throws Error { + public Process(string[] cmd) throws Error { Object(argv: cmd); process = new Subprocess.newv(cmd, SubprocessFlags.STDIN_PIPE | @@ -91,13 +91,22 @@ public class AstalIO.Process : Object { } /** + * Start a new subprocess with the given command. + * + * The first element of the vector is executed with the remaining elements as the argument list. + */ + public static Process subprocessv(string[] cmd) throws Error { + return new Process(cmd); + } + + /** * Start a new subprocess with the given command * which is parsed using [[email protected]_parse_argv]. */ public static Process subprocess(string cmd) throws Error { string[] argv; Shell.parse_argv(cmd, out argv); - return new Process.subprocessv(argv); + return Process.subprocessv(argv); } /** diff --git a/lib/astal/io/variable.vala b/lib/astal/io/variable.vala index 312a27a..e4105f8 100644 --- a/lib/astal/io/variable.vala +++ b/lib/astal/io/variable.vala @@ -172,7 +172,7 @@ public class AstalIO.Variable : VariableBase { return_if_fail(watch_proc == null); return_if_fail(watch_exec != null); - watch_proc = new Process.subprocessv(watch_exec); + watch_proc = Process.subprocessv(watch_exec); watch_proc.stdout.connect((str) => set_closure(str, watch_transform)); watch_proc.stderr.connect((str) => this.error(str)); } diff --git a/lib/tray/meson.build b/lib/tray/meson.build index fbf2f98..139cfb1 100644 --- a/lib/tray/meson.build +++ b/lib/tray/meson.build @@ -39,29 +39,9 @@ deps = [ dependency('gio-2.0'), dependency('json-glib-1.0'), dependency('gdk-pixbuf-2.0'), - dependency('gtk+-3.0'), + dependency('appmenu-glib-translator') ] -dbusmenu_cflags = run_command( - find_program('pkg-config', required: true), - '--cflags', 'dbusmenu-gtk3-0.4', - 'gobject-introspection-1.0', - 'gobject-2.0', - 'glib-2.0', - capture: true, - check: true, -).stdout().strip() - -dbusmenu_libs = run_command( - find_program('pkg-config', required: true), - '--libs', 'dbusmenu-gtk3-0.4', - 'gobject-introspection-1.0', - 'gobject-2.0', - 'glib-2.0', - capture: true, - check: true, -).stdout().strip() - sources = [config] + files('tray.vala', 'watcher.vala', 'trayItem.vala') if get_option('lib') @@ -71,15 +51,13 @@ if get_option('lib') dependencies: deps, vala_header: meson.project_name() + '.h', vala_vapi: meson.project_name() + '-' + api_version + '.vapi', - vala_args: ['--vapi-comments', '--pkg', 'DbusmenuGtk3-0.4', '--pkg', 'Dbusmenu-0.4'], + vala_args: ['--vapi-comments'], version: meson.project_version(), - c_args: dbusmenu_cflags.split(' '), - link_args: dbusmenu_libs.split(' '), install: true, install_dir: [true, true, true] ) - pkgs = ['--pkg', 'DbusmenuGtk3-0.4', '--pkg', 'Dbusmenu-0.4'] + pkgs = [] foreach dep : deps pkgs += ['--pkg=' + dep.name()] endforeach @@ -120,31 +98,13 @@ if get_option('lib') requires: deps, install_dir: get_option('libdir') / 'pkgconfig', ) - # - # custom_target( - # typelib, - # command: [ - # find_program('g-ir-compiler'), - # '--output', '@OUTPUT@', - # '--shared-library', get_option('prefix') / get_option('libdir') / '@PLAINNAME@', - # meson.current_build_dir() / gir, - # ], - # input: lib, - # output: typelib, - # depends: lib, - # install: true, - # install_dir: get_option('libdir') / 'girepository-1.0', - # ) -endif + endif if get_option('cli') executable( meson.project_name(), ['cli.vala', sources], dependencies: deps, - vala_args: ['--pkg', 'DbusmenuGtk3-0.4', '--pkg', 'Dbusmenu-0.4'], - c_args: dbusmenu_cflags.split(' '), - link_args: dbusmenu_libs.split(' '), install: true, ) endif diff --git a/lib/tray/trayItem.vala b/lib/tray/trayItem.vala index db0e6d4..991abce 100644 --- a/lib/tray/trayItem.vala +++ b/lib/tray/trayItem.vala @@ -1,5 +1,3 @@ -using DbusmenuGtk; - namespace AstalTray { public struct Pixmap { int width; @@ -88,21 +86,20 @@ public class TrayItem : Object { private IItem proxy; private List<ulong> 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 { @@ -120,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 [[email protected]]. */ public bool is_menu { get { return proxy.ItemIsMenu ;} } - - /** - * the icon theme path, where to look for the [[email protected]:icon-name]. - * - * It is recommended to use the [[email protected]:gicon] property, + + /** + * The icon theme path, where to look for the [[email protected]:icon-name]. + * It is recommended to use the [[email protected]: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 [[email protected]:icon-theme-path] - * if set or in the currently used icon theme otherwise. - * - * It is recommended to use the [[email protected]:gicon] property, + + /** + * The name of the icon. This should be looked up in the [[email protected]:icon-theme-path] + * if set or in the currently used icon theme otherwise. + * It is recommended to use the [[email protected]:gicon] property, * which does the icon lookups for you. */ public string icon_name { @@ -149,26 +144,41 @@ public class TrayItem : Object { : proxy.IconName; } } - - /** - * a pixbuf containing the icon. - * - * It is recommended to use the [[email protected]:gicon] property, + + /** + * A pixbuf containing the icon. + * It is recommended to use the [[email protected]: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 [[email protected]:icon-name], + * This property unifies the [[email protected]:icon-name], * [[email protected]:icon-theme-path] and [[email protected]: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; + } + } + + 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(); @@ -183,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)); @@ -196,9 +207,16 @@ public class TrayItem : Object { SignalHandler.disconnect(proxy, id); } }); - - update_gicon(); + 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); @@ -206,28 +224,33 @@ public class TrayItem : Object { } private void _notify() { - string[] props = { "category", "id", "title", "status", "is-menu", "tooltip-markup", "icon-name", "icon-pixbuf" }; - - foreach (string prop in props) + string[] props = { + "category", + "id", + "title", + "status", + "is-menu", + "tooltip-markup", + "icon-name", + "icon-pixbuf" + }; + + foreach (string prop in props) { notify_property(prop); + } changed(); } 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())); + 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) + )); } else { gicon = new GLib.ThemedIcon(icon_name); } @@ -274,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) { @@ -312,58 +337,44 @@ public class TrayItem : Object { } } - /** - * creates a new Gtk Menu for this item. - */ - public Gtk.Menu? create_menu() { - if (proxy.Menu == 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; + } - 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 - : proxy.IconPixmap; - - - string icon_name = proxy.Status == Status.NEEDS_ATTENTION - ? proxy.AttentionIconName - : proxy.IconName; - - Gdk.Pixbuf pixbuf = null; - - if (icon_name != null && proxy.IconThemePath != null) - pixbuf = load_from_theme(icon_name, proxy.IconThemePath); + try { + Dir dir = Dir.open(theme_path, 0); + string? name = null; - if (pixbuf == null) - pixbuf = pixmap_to_pixbuf(pixmaps); + while ((name = dir.read_name ()) != null) { + var path = Path.build_filename(theme_path, name); - return pixbuf; - } + if (FileUtils.test(path, FileTest.IS_DIR)) { + string? icon = find_icon_in_theme(icon_name, path); + if (icon != null) return icon; + else continue; + } - private Gdk.Pixbuf? load_from_theme(string icon_name, string theme_path) { - if (theme_path == "" || theme_path == null) - return null; + int dot_index = name.last_index_of("."); + if (dot_index != -1) { + name = name.substring(0, dot_index); + } - if (icon_name == "" || icon_name == null) + if (name == icon_name) return path; + } + } catch (FileError err) { return 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(); + private Gdk.Pixbuf? _get_icon_pixbuf() { + Pixmap[] pixmaps = proxy.Status == Status.NEEDS_ATTENTION + ? proxy.AttentionIconPixmap + : proxy.IconPixmap; - return null; + return pixmap_to_pixbuf(pixmaps); } private Gdk.Pixbuf? pixmap_to_pixbuf(Pixmap[] pixmaps) { @@ -371,6 +382,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) { |