diff options
author | Aylur <[email protected]> | 2024-06-28 17:07:18 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-28 17:07:18 +0200 |
commit | 9a484bdee02904034449961612fd5b2cdbe6a337 (patch) | |
tree | 7be3b0a66894a980e6e9ddef5ef2e8782a2fe964 /src/watcher.vala | |
parent | 2c701b970e7b2b208d8d12d3ea34078236d3f62e (diff) |
add flake, format, small fixes (#1)
* add flake, format, small fixes
* moved the mainloop in cli.vala to the scope of deamonize
* made versions public in config.vala
* added notify_property("items") calls in tray.vala, this makes it work
with the bind API in gjs
* added flake.nix
NOTE for nix: The dbusmenu workaround in meson seems to break typelib
linking on nix which I could not find a solution for. A simple
workaround is to simply put the dependencies of dbusmenu-gtk in
buildInputs, which is fine, but I'm sure this will cause confusion since
no other libs require additional packages in buildInputs
* fix(cli): item changed event
* move header to includedir/astal
Diffstat (limited to 'src/watcher.vala')
-rw-r--r-- | src/watcher.vala | 92 |
1 files changed, 42 insertions, 50 deletions
diff --git a/src/watcher.vala b/src/watcher.vala index cf06c7d..974cd02 100644 --- a/src/watcher.vala +++ b/src/watcher.vala @@ -1,67 +1,59 @@ namespace AstalTray { +[DBus (name="org.kde.StatusNotifierWatcher")] +internal class StatusNotifierWatcher : Object { + private HashTable<string, string> _items = + new HashTable<string, string>(str_hash, str_equal); - [DBus (name="org.kde.StatusNotifierWatcher")] - internal class StatusNotifierWatcher : Object { + public string[] RegisteredStatusNotifierItems { owned get { return _items.get_values_as_ptr_array().data; } } + public bool IsStatusNotifierHostRegistered { get; default = true; } + public int ProtocolVersion { get; default = 0; } - private HashTable<string, string> _items; + public signal void StatusNotifierItemRegistered(string service); + public signal void StatusNotifierItemUnregistered(string service); + public signal void StatusNotifierHostRegistered(); + public signal void StatusNotifierHostUnregistered(); - public string[] RegisteredStatusNotifierItems { owned get { return _items.get_values_as_ptr_array().data; } } - public bool IsStatusNotifierHostRegistered { get; default = true; } - public int ProtocolVersion { get; default = 0; } - - public signal void StatusNotifierItemRegistered(string service); - public signal void StatusNotifierItemUnregistered(string service); - public signal void StatusNotifierHostRegistered(); - public signal void StatusNotifierHostUnregistered(); - - construct { - _items = new HashTable<string, string>(GLib.str_hash, GLib.str_equal); - } - - public void RegisterStatusNotifierItem(string service, BusName sender) throws DBusError, IOError { + public void RegisterStatusNotifierItem(string service, BusName sender) throws DBusError, IOError { string busName; string path; - if(service[0] == '/') { - path = service; - busName = sender; - } - else { - busName = service; - path = "/StatusNotifierItem"; + if (service[0] == '/') { + path = service; + busName = sender; + } else { + busName = service; + path = "/StatusNotifierItem"; } Bus.get_sync(BusType.SESSION).signal_subscribe( - null, - "org.freedesktop.DBus", - "NameOwnerChanged", - null, - null, - DBusSignalFlags.NONE, - (connection, sender_name, path, interface_name, signal_name, parameters) => { - string name = null; - string new_owner = null; - string old_owner = null; - parameters.get("(sss)", &name, &old_owner, &new_owner); - if(new_owner == "" && _items.contains(old_owner)){ - string full_path = _items.take(old_owner); - StatusNotifierItemUnregistered(full_path); + null, + "org.freedesktop.DBus", + "NameOwnerChanged", + null, + null, + DBusSignalFlags.NONE, + (connection, sender_name, path, interface_name, signal_name, parameters) => { + string name = null; + string new_owner = null; + string old_owner = null; + parameters.get("(sss)", &name, &old_owner, &new_owner); + if (new_owner == "" && _items.contains(old_owner)) { + string full_path = _items.take(old_owner); + StatusNotifierItemUnregistered(full_path); + } } - } ); _items.set(busName, busName+path); - StatusNotifierItemRegistered(busName+path); - } + } - public void RegisterStatusNotifierHost(string service) throws DBusError, IOError { - /* - NOTE: - usually the watcher should keep track of registered host - but some tray applications do net register their trayitem properly - when hosts register/deregister. This is fixed by setting isHostRegistered - always to true, this also make host handling logic unneccessary. - */ - } + public void RegisterStatusNotifierHost(string service) throws DBusError, IOError { + /* NOTE: + usually the watcher should keep track of registered host + but some tray applications do net register their trayitem properly + when hosts register/deregister. This is fixed by setting isHostRegistered + always to true, this also make host handling logic unneccessary. + */ } } +} |