summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-12-19 23:42:33 +0100
committerAylur <[email protected]>2024-12-19 23:42:33 +0100
commitc5664e2941b33609de0743a8475a40b24522a3dc (patch)
tree604bdece8e3fe3bd2a286ab1e8ef07dd8d90c37c /lib
parent61637d6333bd812021763039ceea61e7f7d29dbf (diff)
update examples, fix styling
Diffstat (limited to 'lib')
-rw-r--r--lib/tray/trayItem.vala185
1 files changed, 98 insertions, 87 deletions
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<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 {
@@ -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 [[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 {
@@ -148,40 +144,39 @@ 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;
- }
+ 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];
};