Skip to content

Commit 4f7cf90

Browse files
committed
Add support for "action-icons" capability
1 parent 090cc4b commit 4f7cf90

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

data/application.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ window,
6060
margin-top: 12px;
6161
}
6262

63-
.notification .buttonbox button {
63+
.notification .buttonbox.text-buttons button {
6464
min-width: 65px;
6565
}
6666

src/Bubble.vala

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,27 @@ public class Notifications.Bubble : AbstractBubble {
145145
};
146146
action_area.add_css_class ("buttonbox");
147147

148-
foreach (var button in notification.buttons) {
149-
action_area.append (new Gtk.Button.with_label (button.label) {
150-
action_name = button.action_name
151-
});
148+
if (!notification.action_icons) {
149+
action_area.add_css_class ("text-buttons");
150+
}
151+
152+
foreach (var action in notification.buttons) {
153+
var button = new Gtk.Button () {
154+
action_name = action.action_name
155+
};
156+
157+
if (notification.action_icons) {
158+
var action_name_split = action.action_name.split (".");
159+
160+
button.child = new Gtk.Image.from_icon_name (action_name_split[action_name_split.length - 1]) {
161+
icon_size = LARGE
162+
};
163+
button.add_css_class (Granite.CssClass.CIRCULAR);
164+
} else {
165+
button.child = new Gtk.Label (action.label);
166+
}
167+
168+
action_area.append (button);
152169
}
153170

154171
attach (action_area, 0, 2, 2);

src/DBus.vala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class Notifications.Server : Object {
7171

7272
public string [] get_capabilities () throws DBusError, IOError {
7373
return {
74+
"action-icons",
7475
"actions",
7576
"body",
7677
"body-markup",
@@ -120,8 +121,13 @@ public class Notifications.Server : Object {
120121
if (hints.contains (X_CANONICAL_PRIVATE_SYNCHRONOUS)) {
121122
send_confirmation (app_icon, hints);
122123
} else {
123-
var notification = new Notification (app_name, app_icon, summary, body, hints);
124-
notification.buttons = new GenericArray<Notification.Button?> (actions.length / 2);
124+
var notification = new Notification (app_name, app_icon, summary, body, hints) {
125+
buttons = new GenericArray<Notification.Button?> (actions.length / 2)
126+
};
127+
128+
if ("action-icons" in hints && hints["action-icons"].is_of_type (VariantType.BOOLEAN)) {
129+
notification.action_icons = hints["action-icons"].get_boolean ();
130+
}
125131

126132
// validate actions
127133
for (var i = 0; i < actions.length; i += 2) {

src/Notification.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Notifications.Notification : GLib.Object {
3838
public Variant default_action_target { get; set; }
3939

4040
public GenericArray<Button?> buttons { get; set; }
41+
public bool action_icons { get; set; default = false; }
4142

4243
private static Regex entity_regex;
4344
private static Regex tag_regex;

0 commit comments

Comments
 (0)