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/meson.build | 50 +++--------------------------- lib/tray/trayItem.vala | 84 ++++++++++++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 81 deletions(-) diff --git a/lib/tray/meson.build b/lib/tray/meson.build index fbb6672..cb7ab30 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, + 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..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(-) 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 ce64b076e6930dfc499d889ad992191a4fbb7b11 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Sat, 16 Nov 2024 11:48:43 +0100 Subject: gjs: add actionGroup property --- examples/js/simple-bar/widget/Bar.tsx | 17 ++++++----------- lang/gjs/src/gtk3/astalify.ts | 5 +++++ lang/gjs/src/gtk3/jsx-runtime.ts | 2 ++ lang/gjs/src/gtk3/widget.ts | 9 +++++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/js/simple-bar/widget/Bar.tsx b/examples/js/simple-bar/widget/Bar.tsx index efc065a..029aca1 100644 --- a/examples/js/simple-bar/widget/Bar.tsx +++ b/examples/js/simple-bar/widget/Bar.tsx @@ -13,19 +13,14 @@ function SysTray() { return {bind(tray, "items").as(items => items.map(item => { - if (item.iconThemePath) - App.add_icons(item.iconThemePath) - - const menu = item.create_menu() - - return + }))} } diff --git a/lang/gjs/src/gtk3/astalify.ts b/lang/gjs/src/gtk3/astalify.ts index b9621be..b9dd36f 100644 --- a/lang/gjs/src/gtk3/astalify.ts +++ b/lang/gjs/src/gtk3/astalify.ts @@ -69,6 +69,9 @@ export default function astalify< get noImplicitDestroy(): boolean { return this.__no_implicit_destroy } set noImplicitDestroy(value: boolean) { this.__no_implicit_destroy = value } + set actionGroup(actionGroup: ActionGroup) { this.insert_action_group(actionGroup.prefix, actionGroup.actionGroup) } + set_action_group(actionGroup: ActionGroup) { this.actionGroup = actionGroup } + _setChildren(children: Gtk.Widget[]) { children = children.flat(Infinity).map(ch => ch instanceof Gtk.Widget ? ch @@ -327,3 +330,5 @@ type Cursor = | "nwse-resize" | "zoom-in" | "zoom-out" + +type ActionGroup = { prefix: string, actionGroup: Gtk.ActionGroup } diff --git a/lang/gjs/src/gtk3/jsx-runtime.ts b/lang/gjs/src/gtk3/jsx-runtime.ts index 22dc424..10b3bcf 100644 --- a/lang/gjs/src/gtk3/jsx-runtime.ts +++ b/lang/gjs/src/gtk3/jsx-runtime.ts @@ -54,6 +54,7 @@ const ctors = { label: Widget.Label, levelbar: Widget.LevelBar, // TODO: listbox + menubutton: Widget.MenuButton, overlay: Widget.Overlay, revealer: Widget.Revealer, scrollable: Widget.Scrollable, @@ -82,6 +83,7 @@ declare global { label: Widget.LabelProps levelbar: Widget.LevelBarProps // TODO: listbox + menubutton: Widget.MenuButton, overlay: Widget.OverlayProps revealer: Widget.RevealerProps scrollable: Widget.ScrollableProps diff --git a/lang/gjs/src/gtk3/widget.ts b/lang/gjs/src/gtk3/widget.ts index b4e8497..b3c4a4d 100644 --- a/lang/gjs/src/gtk3/widget.ts +++ b/lang/gjs/src/gtk3/widget.ts @@ -102,6 +102,15 @@ export class LevelBar extends astalify(Astal.LevelBar) { // TODO: ListBox + +// MenuButton +export type MenuButtonProps = ConstructProps +export class MenuButton extends astalify(Gtk.MenuButton) { + static { GObject.registerClass({ GTypeName: "MenuButton" }, this) } + constructor(props?: MenuButtonProps, child?: BindableChild) { super({ child, ...props } as any) } +} + + // Overlay Object.defineProperty(Astal.Overlay.prototype, "overlays", { get() { return this.get_overlays() }, -- cgit v1.2.3 From 3c33226dc7c1636194491842c43dd3dd8945d3d0 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Sat, 16 Nov 2024 12:07:28 +0100 Subject: lua: add actionGroup property --- examples/lua/simple-bar/widget/Bar.lua | 26 +++++++++----------------- lang/lua/astal/gtk3/widget.lua | 7 +++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/examples/lua/simple-bar/widget/Bar.lua b/examples/lua/simple-bar/widget/Bar.lua index bf230bb..843e292 100644 --- a/examples/lua/simple-bar/widget/Bar.lua +++ b/examples/lua/simple-bar/widget/Bar.lua @@ -19,24 +19,16 @@ local function SysTray() return Widget.Box({ bind(tray, "items"):as(function(items) return map(items, function(item) - if item.icon_theme_path ~= nil then - App:add_icons(item.icon_theme_path) - end - - local menu = item:create_menu() - - return Widget.Button({ + return Widget.MenuButton({ tooltip_markup = bind(item, "tooltip_markup"), - on_destroy = function() - if menu ~= nil then - menu:destroy() - end - end, - on_click_release = function(self) - if menu ~= nil then - menu:popup_at_widget(self, Gdk.Gravity.SOUTH, Gdk.Gravity.NORTH, nil) - end - end, + use_popover = false, + menu_model = bind(item, "menu-model"), + action_group = bind(item, "action-group"):as(function(ag) + return { + prefix = "dbusmenu", + action_group = ag + } + end), Widget.Icon({ g_icon = bind(item, "gicon"), }), diff --git a/lang/lua/astal/gtk3/widget.lua b/lang/lua/astal/gtk3/widget.lua index beaad6c..3286c26 100644 --- a/lang/lua/astal/gtk3/widget.lua +++ b/lang/lua/astal/gtk3/widget.lua @@ -18,6 +18,7 @@ local Widget = { Label = astalify(Gtk.Label), LevelBar = astalify(Astal.LevelBar), -- TODO: ListBox + MenuButton = astalify(Gtk.MenuButton), Overlay = astalify(Astal.Overlay), Revealer = astalify(Gtk.Revealer), Scrollable = astalify(Astal.Scrollable), @@ -63,6 +64,12 @@ Gtk.Widget._attribute.click_through = { set = Astal.widget_set_click_through, } +Gtk.Widget._attribute.action_group = { + set = function (self, v) + self:insert_action_group(v.prefix, v.action_group) + end +} + local no_implicit_destroy = {} Gtk.Widget._attribute.no_implicit_destroy = { get = function(self) -- cgit v1.2.3 From e674e8f6e49e74edde795e012adbfe0fcfd8d729 Mon Sep 17 00:00:00 2001 From: kotontrion Date: Sat, 16 Nov 2024 12:30:21 +0100 Subject: examples(vala): update tray --- examples/vala/simple-bar/widget/Bar.vala | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/examples/vala/simple-bar/widget/Bar.vala b/examples/vala/simple-bar/widget/Bar.vala index 17db831..3893ec5 100644 --- a/examples/vala/simple-bar/widget/Bar.vala +++ b/examples/vala/simple-bar/widget/Bar.vala @@ -113,26 +113,22 @@ class SysTray : Gtk.Box { var item = tray.get_item(id); - if (item.icon_theme_path != null) - App.instance.add_icons(item.icon_theme_path); - - var menu = item.create_menu(); - var btn = new Astal.Button(); + var btn = new Gtk.MenuButton() { + use_popover = false + }; var icon = new Astal.Icon(); - btn.clicked.connect(() => { - if (menu != null) - menu.popup_at_widget(this, Gdk.Gravity.SOUTH, Gdk.Gravity.NORTH, null); - }); - - btn.destroy.connect(() => { - if (menu != null) - menu.destroy(); + item.bind_property("tooltip-markup", btn, "tooltip-markup", BindingFlags.SYNC_CREATE); + item.bind_property("gicon", icon, "g-icon", BindingFlags.SYNC_CREATE); + item.bind_property("menu-model", btn, "menu-model", BindingFlags.SYNC_CREATE); + btn.insert_action_group("dbusmenu", item.action_group); + item.notify["action-group"].connect(() => { + btn.insert_action_group("dbusmenu", item.action_group); }); - item.bind_property("tooltip-markup", btn, "tooltip-markup", BindingFlags.SYNC_CREATE); - item.bind_property("gicon", icon, "gicon", BindingFlags.SYNC_CREATE); + btn.add(icon); add(btn); + btn.show_all(); items.set(id, btn); } -- cgit v1.2.3 From 60e0dfc945616d739c1acdf93f9e2c55dc505638 Mon Sep 17 00:00:00 2001 From: Aylur Date: Sun, 24 Nov 2024 00:38:14 +0000 Subject: add: nix support --- flake.nix | 2 +- nix/appmenu-glib.nix | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 nix/appmenu-glib.nix diff --git a/flake.nix b/flake.nix index d7c5229..ac1c5e6 100644 --- a/flake.nix +++ b/flake.nix @@ -62,7 +62,7 @@ notifd = mkPkg "astal-notifd" ./lib/notifd [json-glib gdk-pixbuf]; powerprofiles = mkPkg "astal-power-profiles" ./lib/powerprofiles [json-glib]; river = mkPkg "astal-river" ./lib/river [json-glib]; - tray = mkPkg "astal-tray" ./lib/tray [gtk3 gdk-pixbuf libdbusmenu-gtk3 json-glib]; + tray = mkPkg "astal-tray" ./lib/tray [json-glib (pkgs.callPackage ./nix/appmenu-glib.nix {})]; wireplumber = mkPkg "astal-wireplumber" ./lib/wireplumber [wireplumber]; gjs = pkgs.stdenvNoCC.mkDerivation { diff --git a/nix/appmenu-glib.nix b/nix/appmenu-glib.nix new file mode 100644 index 0000000..873fb93 --- /dev/null +++ b/nix/appmenu-glib.nix @@ -0,0 +1,35 @@ +{ + stdenv, + fetchFromGitLab, + pkg-config, + meson, + ninja, + gobject-introspection, + vala, + glib, +}: let + vala-panel-appmenu = fetchFromGitLab { + owner = "vala-panel-project"; + repo = "vala-panel-appmenu"; + rev = "24.05"; + hash = "sha256-8GWauw7r3zKhvGF2TNOI8GDVctUFDhtG/Vy1cNUpsVo="; + }; +in + stdenv.mkDerivation { + pname = "appmenu-glib-translator"; + version = "24.05"; + + src = "${vala-panel-appmenu}/subprojects/appmenu-glib-translator"; + + buildInputs = [ + glib + ]; + + nativeBuildInputs = [ + gobject-introspection + meson + pkg-config + ninja + vala + ]; + } -- 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(-) 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(+) 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 c12fb05408c1cd1b1bca545fec636abda52f6755 Mon Sep 17 00:00:00 2001 From: Aylur Date: Sat, 14 Dec 2024 20:14:29 +0100 Subject: style: IO.Process constructor --- lib/astal/io/process.vala | 13 +++++++++++-- lib/astal/io/variable.vala | 2 +- 2 files changed, 12 insertions(+), 3 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 | @@ -90,6 +90,15 @@ public class AstalIO.Process : Object { read_stream(err_stream, false); } + /** + * 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 [func@GLib.shell_parse_argv]. @@ -97,7 +106,7 @@ public class AstalIO.Process : Object { 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)); } -- 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 --- examples/js/simple-bar/style.scss | 50 ++++++--- examples/js/simple-bar/widget/Bar.tsx | 13 +-- examples/lua/simple-bar/style.scss | 50 ++++++--- examples/lua/simple-bar/widget/Bar.lua | 16 +-- examples/py/simple-bar/app.py | 6 +- examples/py/simple-bar/style.scss | 50 ++++++--- examples/py/simple-bar/widget/Bar.py | 30 ++--- examples/vala/simple-bar/meson.build | 19 +--- examples/vala/simple-bar/style.scss | 50 ++++++--- examples/vala/simple-bar/widget/Bar.vala | 11 +- lang/gjs/src/gtk3/astalify.ts | 4 +- lang/lua/astal/gtk3/widget.lua | 2 +- lib/tray/trayItem.vala | 185 ++++++++++++++++--------------- 13 files changed, 264 insertions(+), 222 deletions(-) diff --git a/examples/js/simple-bar/style.scss b/examples/js/simple-bar/style.scss index 1dcf729..f5f771a 100644 --- a/examples/js/simple-bar/style.scss +++ b/examples/js/simple-bar/style.scss @@ -13,31 +13,45 @@ window.Bar { font-size: 1.1em; font-weight: bold; - button { - all: unset; - background-color: transparent; + label { + margin: 0 8px; + } + + .Workspaces { + button { + all: unset; + background-color: transparent; - &:hover label { - background-color: color.adjust($fg, $alpha: -0.84); - border-color: color.adjust($accent, $alpha: -0.8); + &:hover label { + background-color: color.adjust($fg, $alpha: -0.84); + border-color: color.adjust($accent, $alpha: -0.8); + } + + &:active label { + background-color: color.adjust($fg, $alpha: -0.8) + } } - &:active label { - background-color: color.adjust($fg, $alpha: -0.8) + label { + transition: 200ms; + padding: 0 8px; + margin: 2px; + border-radius: $radius; + border: 1pt solid transparent; } - } - label { - transition: 200ms; - padding: 0 8px; - margin: 2px; - border-radius: $radius; - border: 1pt solid transparent; + .focused label { + color: $accent; + border-color: $accent; + } } - .Workspaces .focused label { - color: $accent; - border-color: $accent; + .SysTray { + margin-right: 8px; + + button { + padding: 0 4px; + } } .FocusedClient { diff --git a/examples/js/simple-bar/widget/Bar.tsx b/examples/js/simple-bar/widget/Bar.tsx index f5e96cb..87cc20d 100644 --- a/examples/js/simple-bar/widget/Bar.tsx +++ b/examples/js/simple-bar/widget/Bar.tsx @@ -11,17 +11,16 @@ import Tray from "gi://AstalTray" function SysTray() { const tray = Tray.get_default() - return - {bind(tray, "items").as(items => items.map(item => { - - return + {bind(tray, "items").as(items => items.map(item => ( + { return { prefix: "dbusmenu", actionGroup: ag}})} - menuModel={bind(item, "menu-model")} > + actionGroup={bind(item, "action-group").as(ag => ["dbusmenu", ag])} + menuModel={bind(item, "menu-model")}> - }))} + ))} } diff --git a/examples/lua/simple-bar/style.scss b/examples/lua/simple-bar/style.scss index 1dcf729..f5f771a 100644 --- a/examples/lua/simple-bar/style.scss +++ b/examples/lua/simple-bar/style.scss @@ -13,31 +13,45 @@ window.Bar { font-size: 1.1em; font-weight: bold; - button { - all: unset; - background-color: transparent; + label { + margin: 0 8px; + } + + .Workspaces { + button { + all: unset; + background-color: transparent; - &:hover label { - background-color: color.adjust($fg, $alpha: -0.84); - border-color: color.adjust($accent, $alpha: -0.8); + &:hover label { + background-color: color.adjust($fg, $alpha: -0.84); + border-color: color.adjust($accent, $alpha: -0.8); + } + + &:active label { + background-color: color.adjust($fg, $alpha: -0.8) + } } - &:active label { - background-color: color.adjust($fg, $alpha: -0.8) + label { + transition: 200ms; + padding: 0 8px; + margin: 2px; + border-radius: $radius; + border: 1pt solid transparent; } - } - label { - transition: 200ms; - padding: 0 8px; - margin: 2px; - border-radius: $radius; - border: 1pt solid transparent; + .focused label { + color: $accent; + border-color: $accent; + } } - .Workspaces .focused label { - color: $accent; - border-color: $accent; + .SysTray { + margin-right: 8px; + + button { + padding: 0 4px; + } } .FocusedClient { diff --git a/examples/lua/simple-bar/widget/Bar.lua b/examples/lua/simple-bar/widget/Bar.lua index 843e292..e7bd4ff 100644 --- a/examples/lua/simple-bar/widget/Bar.lua +++ b/examples/lua/simple-bar/widget/Bar.lua @@ -1,8 +1,6 @@ local astal = require("astal") -local App = require("astal.gtk3.app") local Widget = require("astal.gtk3.widget") local Variable = astal.Variable -local Gdk = astal.require("Gdk", "3.0") local GLib = astal.require("GLib") local bind = astal.bind local Mpris = astal.require("AstalMpris") @@ -17,18 +15,16 @@ local function SysTray() local tray = Tray.get_default() return Widget.Box({ + class_name = "SysTray", bind(tray, "items"):as(function(items) return map(items, function(item) return Widget.MenuButton({ tooltip_markup = bind(item, "tooltip_markup"), - use_popover = false, + use_popover = false, menu_model = bind(item, "menu-model"), - action_group = bind(item, "action-group"):as(function(ag) - return { - prefix = "dbusmenu", - action_group = ag - } - end), + action_group = bind(item, "action-group"):as(function(ag) + return { "dbusmenu", ag } + end), Widget.Icon({ g_icon = bind(item, "gicon"), }), @@ -181,10 +177,10 @@ return function(gdkmonitor) }), Widget.Box({ halign = "END", + SysTray(), Wifi(), AudioSlider(), BatteryLevel(), - SysTray(), Time("%H:%M - %A %e."), }), }), diff --git a/examples/py/simple-bar/app.py b/examples/py/simple-bar/app.py index 17b6782..d95dc0e 100755 --- a/examples/py/simple-bar/app.py +++ b/examples/py/simple-bar/app.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import sys import versions +import subprocess from gi.repository import AstalIO, Astal, Gio from widget.Bar import Bar from pathlib import Path @@ -18,9 +19,8 @@ class App(Astal.Application): def do_activate(self) -> None: self.hold() - AstalIO.Process.execv(["sass", scss, css]) + subprocess.run(["sass", scss, css]) self.apply_css(css, True) - print("hello") for mon in self.get_monitors(): self.add_window(Bar(mon)) @@ -30,7 +30,7 @@ app = App(instance_name=instance_name) if __name__ == "__main__": try: - print(app.acquire_socket()) + app.acquire_socket() app.run(None) except Exception as e: print(AstalIO.send_message(instance_name, "".join(sys.argv[1:]))) diff --git a/examples/py/simple-bar/style.scss b/examples/py/simple-bar/style.scss index 1dcf729..f5f771a 100644 --- a/examples/py/simple-bar/style.scss +++ b/examples/py/simple-bar/style.scss @@ -13,31 +13,45 @@ window.Bar { font-size: 1.1em; font-weight: bold; - button { - all: unset; - background-color: transparent; + label { + margin: 0 8px; + } + + .Workspaces { + button { + all: unset; + background-color: transparent; - &:hover label { - background-color: color.adjust($fg, $alpha: -0.84); - border-color: color.adjust($accent, $alpha: -0.8); + &:hover label { + background-color: color.adjust($fg, $alpha: -0.84); + border-color: color.adjust($accent, $alpha: -0.8); + } + + &:active label { + background-color: color.adjust($fg, $alpha: -0.8) + } } - &:active label { - background-color: color.adjust($fg, $alpha: -0.8) + label { + transition: 200ms; + padding: 0 8px; + margin: 2px; + border-radius: $radius; + border: 1pt solid transparent; } - } - label { - transition: 200ms; - padding: 0 8px; - margin: 2px; - border-radius: $radius; - border: 1pt solid transparent; + .focused label { + color: $accent; + border-color: $accent; + } } - .Workspaces .focused label { - color: $accent; - border-color: $accent; + .SysTray { + margin-right: 8px; + + button { + padding: 0 4px; + } } .FocusedClient { diff --git a/examples/py/simple-bar/widget/Bar.py b/examples/py/simple-bar/widget/Bar.py index 3b09dce..ca02dd6 100644 --- a/examples/py/simple-bar/widget/Bar.py +++ b/examples/py/simple-bar/widget/Bar.py @@ -108,6 +108,7 @@ class Media(Gtk.Box): class SysTray(Gtk.Box): def __init__(self) -> None: super().__init__() + Astal.widget_set_class_names(self, ["SysTray"]) self.items = {} tray = Tray.get_default() tray.connect("item_added", self.add_item) @@ -118,33 +119,22 @@ class SysTray(Gtk.Box): return item = Tray.get_default().get_item(id) - theme = item.get_icon_theme_path() - - if theme is not None: - from app import app - - app.add_icons(theme) - - menu = item.create_menu() - btn = Astal.Button(visible=True) + btn = Gtk.MenuButton(use_popover=False, visible=True) icon = Astal.Icon(visible=True) - def on_clicked(btn): - if menu: - menu.popup_at_widget(btn, Gdk.Gravity.SOUTH, Gdk.Gravity.NORTH, None) + item.bind_property("tooltip-markup", btn, "tooltip-markup", SYNC) + item.bind_property("gicon", icon, "g-icon", SYNC) + item.bind_property("menu-model", btn, "menu-model", SYNC) + btn.insert_action_group("dbusmenu", item.get_action_group()) - def on_destroy(btn): - if menu: - menu.destroy() + def on_action_group(*args): + btn.insert_action_group("dbusmenu", item.get_action_group()) - btn.connect("clicked", on_clicked) - btn.connect("destroy", on_destroy) + item.connect("notify::action-group", on_action_group) - item.bind_property("tooltip-markup", btn, "tooltip-markup", SYNC) - item.bind_property("gicon", icon, "gicon", SYNC) + btn.add(icon) self.add(btn) self.items[id] = btn - self.show_all() def remove_item(self, _: Tray.Tray, id: str): if id in self.items: diff --git a/examples/vala/simple-bar/meson.build b/examples/vala/simple-bar/meson.build index 10f5dd2..5a0ef4c 100644 --- a/examples/vala/simple-bar/meson.build +++ b/examples/vala/simple-bar/meson.build @@ -21,22 +21,15 @@ pkgconfig_deps = [ # needed for GLib.Math deps = pkgconfig_deps + meson.get_compiler('c').find_library('m') -custom_target( - 'style.css', - command: [ - find_program('sass'), - meson.project_source_root() / 'style.scss', - '@OUTPUT@', - ], - output: 'style.css', - install: true, - install_dir: libdir, -) - main = configure_file( input: 'app.in.vala', output: 'app.vala', - configuration: {'STYLE': libdir / 'style.css'}, + configuration: { + 'STYLE': run_command( + find_program('sass'), + meson.project_source_root() / 'style.scss', + ).stdout(), + }, ) sources = files( diff --git a/examples/vala/simple-bar/style.scss b/examples/vala/simple-bar/style.scss index 1dcf729..f5f771a 100644 --- a/examples/vala/simple-bar/style.scss +++ b/examples/vala/simple-bar/style.scss @@ -13,31 +13,45 @@ window.Bar { font-size: 1.1em; font-weight: bold; - button { - all: unset; - background-color: transparent; + label { + margin: 0 8px; + } + + .Workspaces { + button { + all: unset; + background-color: transparent; - &:hover label { - background-color: color.adjust($fg, $alpha: -0.84); - border-color: color.adjust($accent, $alpha: -0.8); + &:hover label { + background-color: color.adjust($fg, $alpha: -0.84); + border-color: color.adjust($accent, $alpha: -0.8); + } + + &:active label { + background-color: color.adjust($fg, $alpha: -0.8) + } } - &:active label { - background-color: color.adjust($fg, $alpha: -0.8) + label { + transition: 200ms; + padding: 0 8px; + margin: 2px; + border-radius: $radius; + border: 1pt solid transparent; } - } - label { - transition: 200ms; - padding: 0 8px; - margin: 2px; - border-radius: $radius; - border: 1pt solid transparent; + .focused label { + color: $accent; + border-color: $accent; + } } - .Workspaces .focused label { - color: $accent; - border-color: $accent; + .SysTray { + margin-right: 8px; + + button { + padding: 0 4px; + } } .FocusedClient { diff --git a/examples/vala/simple-bar/widget/Bar.vala b/examples/vala/simple-bar/widget/Bar.vala index 3893ec5..ba9f06c 100644 --- a/examples/vala/simple-bar/widget/Bar.vala +++ b/examples/vala/simple-bar/widget/Bar.vala @@ -103,6 +103,7 @@ class SysTray : Gtk.Box { AstalTray.Tray tray = AstalTray.get_default(); public SysTray() { + Astal.widget_set_class_names(this, { "SysTray" }); tray.item_added.connect(add_item); tray.item_removed.connect(remove_item); } @@ -112,23 +113,19 @@ class SysTray : Gtk.Box { return; var item = tray.get_item(id); - - var btn = new Gtk.MenuButton() { - use_popover = false - }; - var icon = new Astal.Icon(); + var btn = new Gtk.MenuButton() { use_popover = false, visible = true }; + var icon = new Astal.Icon() { visible = true }; item.bind_property("tooltip-markup", btn, "tooltip-markup", BindingFlags.SYNC_CREATE); item.bind_property("gicon", icon, "g-icon", BindingFlags.SYNC_CREATE); item.bind_property("menu-model", btn, "menu-model", BindingFlags.SYNC_CREATE); btn.insert_action_group("dbusmenu", item.action_group); item.notify["action-group"].connect(() => { - btn.insert_action_group("dbusmenu", item.action_group); + btn.insert_action_group("dbusmenu", item.action_group); }); btn.add(icon); add(btn); - btn.show_all(); items.set(id, btn); } diff --git a/lang/gjs/src/gtk3/astalify.ts b/lang/gjs/src/gtk3/astalify.ts index b758976..18df132 100644 --- a/lang/gjs/src/gtk3/astalify.ts +++ b/lang/gjs/src/gtk3/astalify.ts @@ -69,7 +69,7 @@ export default function astalify< get noImplicitDestroy(): boolean { return this.__no_implicit_destroy } set noImplicitDestroy(value: boolean) { this.__no_implicit_destroy = value } - set actionGroup(actionGroup: ActionGroup) { this.insert_action_group(actionGroup.prefix, actionGroup.actionGroup) } + set actionGroup([prefix, group]: ActionGroup) { this.insert_action_group(prefix, group) } set_action_group(actionGroup: ActionGroup) { this.actionGroup = actionGroup } _setChildren(children: Gtk.Widget[]) { @@ -331,4 +331,4 @@ type Cursor = | "zoom-in" | "zoom-out" -type ActionGroup = { prefix: string, actionGroup: Gtk.ActionGroup } +type ActionGroup = [prefix: string, actionGroup: Gtk.ActionGroup] diff --git a/lang/lua/astal/gtk3/widget.lua b/lang/lua/astal/gtk3/widget.lua index adcb65f..654da29 100644 --- a/lang/lua/astal/gtk3/widget.lua +++ b/lang/lua/astal/gtk3/widget.lua @@ -67,7 +67,7 @@ Gtk.Widget._attribute.click_through = { Gtk.Widget._attribute.action_group = { set = function (self, v) - self:insert_action_group(v.prefix, v.action_group) + self:insert_action_group(v[1], v[2]) end } 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 From 0cf43e594f13e3de1f076028c13d10a25ef4a635 Mon Sep 17 00:00:00 2001 From: Cameron Smith <114649266+smathles@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:45:33 +1000 Subject: Fix typo in docs (#190) --- CONTRIBUTING.md | 2 +- docs/guide/getting-started/installation.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7b29bcf..8b4ea71 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ You can contribute by: - [Suggesting new features](https://github.com/Aylur/astal/issues/new?assignees=&labels=enhancement&projects=&template=feature_request.md&title=) - [Reporting bugs](https://github.com/Aylur/astal/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=) - Improving docs with additional contexts and examples - - adding more distros to sections about installations e.g [bulding from source](https://aylur.github.io/astal/guide/getting-started/installation#bulding-libastal-from-source) + - adding more distros to sections about installations e.g [building from source](https://aylur.github.io/astal/guide/getting-started/installation#building-from-source) - Adding more example projects to [examples](https://github.com/Aylur/astal/tree/main/examples) - Adding new language support/binding. For these open a PR for discussions. - Adding new libraries e.g support for more wayland compositors diff --git a/docs/guide/getting-started/installation.md b/docs/guide/getting-started/installation.md index e32b6a9..a942315 100644 --- a/docs/guide/getting-started/installation.md +++ b/docs/guide/getting-started/installation.md @@ -22,7 +22,7 @@ maintainer: [@Aylur](https://github.com/Aylur) Read more about it on the [nix page](./nix#astal) -## Bulding From Source +## Building From Source 1. Install the following dependencies -- cgit v1.2.3 From 23083cdec69853bc8e480807a5f93b03df340183 Mon Sep 17 00:00:00 2001 From: cold-leopard Date: Thu, 19 Dec 2024 16:56:58 -0600 Subject: Add aarch64 Compatability to Flake (#183) --- flake.nix | 69 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/flake.nix b/flake.nix index ac1c5e6..052a6f5 100644 --- a/flake.nix +++ b/flake.nix @@ -5,45 +5,48 @@ }: let inherit (builtins) replaceStrings readFile; readVer = file: replaceStrings ["\n"] [""] (readFile file); - - system = "x86_64-linux"; # TODO: other architectures - pkgs = nixpkgs.legacyPackages.${system}; - - mkPkg = name: src: inputs: - pkgs.stdenv.mkDerivation { - nativeBuildInputs = with pkgs; [ - wrapGAppsHook - gobject-introspection - meson - pkg-config - ninja - vala - wayland - wayland-scanner - python3 - ]; - propagatedBuildInputs = [pkgs.glib] ++ inputs; - pname = name; - version = readVer "${src}/version"; - src = src; - postUnpack = '' - cp --remove-destination ${./lib/gir.py} $sourceRoot/gir.py - ''; - outputs = ["out" "dev"]; - }; - in { - devShells.${system} = import ./nix/devshell.nix { - inherit self pkgs; + supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: (forSystem system f)); + forSystem = system: f: f rec { + inherit system; + pkgs = nixpkgs.legacyPackages.${system}; + mkPkg = name: src: inputs: + pkgs.stdenv.mkDerivation { + nativeBuildInputs = with pkgs; [ + wrapGAppsHook + gobject-introspection + meson + pkg-config + ninja + vala + wayland + wayland-scanner + python3 + ]; + propagatedBuildInputs = [pkgs.glib] ++ inputs; + pname = name; + version = readVer "${src}/version"; + src = src; + postUnpack = '' + cp --remove-destination ${./lib/gir.py} $sourceRoot/gir.py + ''; + outputs = ["out" "dev"]; + }; }; + in { - lib = { + devShells = forAllSystems({system, pkgs, ...}: import ./nix/devshell.nix { + inherit self pkgs; + }); + + lib = forAllSystems({system, pkgs, ...}: { mkLuaPackage = import ./nix/lua.nix { inherit pkgs; astal = self; }; - }; + }); - packages.${system} = with pkgs; { + packages = forAllSystems({system, pkgs, mkPkg, ...}: with pkgs;{ docs = import ./docs {inherit self pkgs;}; default = self.packages.${system}.io; @@ -76,7 +79,7 @@ self.packages.${system}.astal3 ]; }; - }; + }); }; inputs = { -- cgit v1.2.3 From d16c856074531b9fb867b8922be370bcfc749614 Mon Sep 17 00:00:00 2001 From: rRedLim <82714753+rRedLim@users.noreply.github.com> Date: Fri, 20 Dec 2024 02:21:09 +0300 Subject: chore: simple-bar filter special workspaces (#168) --- examples/js/simple-bar/widget/Bar.tsx | 1 + examples/lua/simple-bar/widget/Bar.lua | 24 +++++++++++++----------- examples/py/simple-bar/widget/Bar.py | 3 ++- examples/vala/simple-bar/widget/Bar.vala | 8 ++++++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/js/simple-bar/widget/Bar.tsx b/examples/js/simple-bar/widget/Bar.tsx index 87cc20d..54a14b0 100644 --- a/examples/js/simple-bar/widget/Bar.tsx +++ b/examples/js/simple-bar/widget/Bar.tsx @@ -89,6 +89,7 @@ function Workspaces() { return {bind(hypr, "workspaces").as(wss => wss + .filter(ws => !(ws.id >= -99 && ws.id <= -2)) // filter out special workspaces .sort((a, b) => a.id - b.id) .map(ws => (