Unverified Commit 23fb96f3 authored by Erik Reider's avatar Erik Reider Committed by GitHub

Updated uncrustify config + formatted all vala files (#656)

* Updated uncrustify config * Added uncrustify GitHub Action * Formatted all vala files * Updated vala-lint config
parent 915bc8e9
root = true
# elementary defaults
[*]
charset = utf-8
end_of_line = lf
indent_size = tab
indent_style = space
insert_final_newline = true
max_line_length = 100
tab_width = 4
# Markup files
[{*.html,*.xml,*.xml.in,*.yml}]
tab_width = 2
...@@ -24,6 +24,27 @@ jobs: ...@@ -24,6 +24,27 @@ jobs:
conf: .vala-lint.conf conf: .vala-lint.conf
fail: true fail: true
uncrustify:
container: registry.fedoraproject.org/fedora-minimal:latest
runs-on: ubuntu-latest
steps:
- name: Install uncrustify
run: |
microdnf -y install --nodocs --setopt=install_weak_deps=0 \
@development-tools git \
uncrustify
- name: Check out sources
uses: actions/checkout@v3
with:
fetch-depth: 0
path: swaync
- name: Run uncrustify
run: |
cd swaync
uncrustify -c ./.uncrustify.cfg -l vala $(find . -name "*.vala" -type f) --check
rpmlint: rpmlint:
container: registry.fedoraproject.org/fedora-minimal:latest container: registry.fedoraproject.org/fedora-minimal:latest
runs-on: ubuntu-latest runs-on: ubuntu-latest
......
...@@ -17,7 +17,7 @@ unnecessary-string-template=error ...@@ -17,7 +17,7 @@ unnecessary-string-template=error
disable-by-inline-comments=true disable-by-inline-comments=true
[line-length] [line-length]
max-line-length=120 max-line-length=100
ignore-comments=true ignore-comments=true
[naming-convention] [naming-convention]
......
...@@ -60,17 +60,17 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -60,17 +60,17 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
// Scroll bottom animation // Scroll bottom animation
Adw.CallbackAnimationTarget scroll_btm_target; Adw.CallbackAnimationTarget scroll_btm_target;
Adw.TimedAnimation scroll_btm_anim; Adw.TimedAnimation scroll_btm_anim;
AnimationData ? scroll_btm_anim_data = null; AnimationData ?scroll_btm_anim_data = null;
// Scroll top animation // Scroll top animation
Adw.CallbackAnimationTarget scroll_top_target; Adw.CallbackAnimationTarget scroll_top_target;
Adw.TimedAnimation scroll_top_anim; Adw.TimedAnimation scroll_top_anim;
AnimationData ? scroll_top_anim_data = null; AnimationData ?scroll_top_anim_data = null;
// Adding an item to the top compensation // Adding an item to the top compensation
Adw.CallbackAnimationTarget scroll_comp_target; Adw.CallbackAnimationTarget scroll_comp_target;
Adw.TimedAnimation scroll_comp_anim; Adw.TimedAnimation scroll_comp_anim;
AnimationData ? scroll_comp_anim_data = null; AnimationData ?scroll_comp_anim_data = null;
// When true, the size_allocate method will scroll to the top/bottom // When true, the size_allocate method will scroll to the top/bottom
private bool set_initial_scroll_value = false; private bool set_initial_scroll_value = false;
...@@ -120,9 +120,9 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -120,9 +120,9 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
public AnimatedList () { public AnimatedList () {
Object ( Object (
css_name: "animatedlist", css_name : "animatedlist",
accessible_role: Gtk.AccessibleRole.LIST, accessible_role : Gtk.AccessibleRole.LIST,
transition_children: true, transition_children : true,
use_card_animation: true, use_card_animation: true,
direction: AnimatedListDirection.TOP_TO_BOTTOM, direction: AnimatedListDirection.TOP_TO_BOTTOM,
scroll_to_append: false scroll_to_append: false
...@@ -386,8 +386,8 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -386,8 +386,8 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
} }
Gsk.Transform transform = new Gsk.Transform () Gsk.Transform transform = new Gsk.Transform ()
.translate (Graphene.Point ().init (x, y)) .translate (Graphene.Point ().init (x, y))
.scale (scale, scale); .scale (scale, scale);
child.allocate (width, child_height, baseline, transform); child.allocate (width, child_height, baseline, transform);
child.set_opacity (opacity); child.set_opacity (opacity);
...@@ -539,7 +539,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -539,7 +539,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
* TOP_TO_BOTTOM: Bottom * TOP_TO_BOTTOM: Bottom
* BOTTOM_TO_TOP: Top * BOTTOM_TO_TOP: Top
*/ */
public async AnimatedListItem ? prepend (Gtk.Widget widget) { public async AnimatedListItem ?prepend (Gtk.Widget widget) {
if (widget == null || widget.parent != null) { if (widget == null || widget.parent != null) {
warn_if_reached (); warn_if_reached ();
return null; return null;
...@@ -563,6 +563,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -563,6 +563,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
} }
yield item.added (transition_children); yield item.added (transition_children);
return item; return item;
} }
...@@ -571,7 +572,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -571,7 +572,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
* TOP_TO_BOTTOM: Top * TOP_TO_BOTTOM: Top
* BOTTOM_TO_TOP: Bottom * BOTTOM_TO_TOP: Bottom
*/ */
public async AnimatedListItem ? append (Gtk.Widget widget) { public async AnimatedListItem ?append (Gtk.Widget widget) {
if (widget == null || widget.parent != null) { if (widget == null || widget.parent != null) {
warn_if_reached (); warn_if_reached ();
return null; return null;
...@@ -595,32 +596,33 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -595,32 +596,33 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
} else if (scroll_to_append) { } else if (scroll_to_append) {
// Scrolls to the item if enabled // Scrolls to the item if enabled
switch (direction) { switch (direction) {
case AnimatedListDirection.TOP_TO_BOTTOM: case AnimatedListDirection.TOP_TO_BOTTOM :
play_scroll_top_anim (item); play_scroll_top_anim (item);
break; break;
case AnimatedListDirection.BOTTOM_TO_TOP: case AnimatedListDirection.BOTTOM_TO_TOP :
play_scroll_bottom_anim (item); play_scroll_bottom_anim (item);
break; break;
} }
} }
yield item.added (transition_children); yield item.added (transition_children);
return item; return item;
} }
private AnimatedListItem ? try_get_ancestor (Gtk.Widget widget) { private AnimatedListItem ?try_get_ancestor (Gtk.Widget widget) {
AnimatedListItem item; AnimatedListItem item;
if (widget is AnimatedListItem) { if (widget is AnimatedListItem) {
item = widget as AnimatedListItem; item = widget as AnimatedListItem;
} else if (widget.parent is AnimatedListItem) { } else if (widget.parent is AnimatedListItem) {
item = widget.parent as AnimatedListItem; item = widget.parent as AnimatedListItem;
} else { } else {
unowned Gtk.Widget ? ancestor unowned Gtk.Widget ?ancestor
= widget.get_ancestor (typeof (AnimatedListItem)); = widget.get_ancestor (typeof (AnimatedListItem));
if (!(ancestor is AnimatedListItem)) { if (!(ancestor is AnimatedListItem)) {
warning ("Widget %p of type \"%s\" is not an ancestor of %s!", warning ("Widget %p of type \"%s\" is not an ancestor of %s!",
widget, widget.get_type ().name (), widget, widget.get_type ().name (),
typeof (AnimatedListItem).name ()); typeof (AnimatedListItem).name ());
return null; return null;
} }
item = ancestor as AnimatedListItem; item = ancestor as AnimatedListItem;
...@@ -639,7 +641,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -639,7 +641,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
return false; return false;
} }
AnimatedListItem ? item = try_get_ancestor (widget); AnimatedListItem ?item = try_get_ancestor (widget);
if (item == null) { if (item == null) {
return false; return false;
} }
...@@ -660,7 +662,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -660,7 +662,7 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
return false; return false;
} }
AnimatedListItem ? item = try_get_ancestor (widget); AnimatedListItem ?item = try_get_ancestor (widget);
if (item == null) { if (item == null) {
warn_if_reached (); warn_if_reached ();
return false; return false;
...@@ -688,13 +690,13 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -688,13 +690,13 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
scroll_to_source_id = Idle.add_once (() => { scroll_to_source_id = Idle.add_once (() => {
scroll_to_source_id = 0; scroll_to_source_id = 0;
unowned AnimatedListItem ? item = get_first_item (); unowned AnimatedListItem ?item = get_first_item ();
return_if_fail (item != null); return_if_fail (item != null);
switch (direction) { switch (direction) {
case AnimatedListDirection.TOP_TO_BOTTOM: case AnimatedListDirection.TOP_TO_BOTTOM :
play_scroll_top_anim (item); play_scroll_top_anim (item);
break; break;
case AnimatedListDirection.BOTTOM_TO_TOP: case AnimatedListDirection.BOTTOM_TO_TOP :
play_scroll_bottom_anim (item); play_scroll_bottom_anim (item);
break; break;
} }
...@@ -705,14 +707,14 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable { ...@@ -705,14 +707,14 @@ public class AnimatedList : Gtk.Widget, Gtk.Scrollable {
return children.is_empty (); return children.is_empty ();
} }
public unowned AnimatedListItem ? get_first_item () { public unowned AnimatedListItem ?get_first_item () {
if (children.is_empty ()) { if (children.is_empty ()) {
return null; return null;
} }
return children.first ().data; return children.first ().data;
} }
public unowned AnimatedListItem ? get_last_item () { public unowned AnimatedListItem ?get_last_item () {
if (children.is_empty ()) { if (children.is_empty ()) {
return null; return null;
} }
......
...@@ -32,13 +32,13 @@ public class AnimatedListItem : Gtk.Widget { ...@@ -32,13 +32,13 @@ public class AnimatedListItem : Gtk.Widget {
private Adw.TimedAnimation animation; private Adw.TimedAnimation animation;
private double animation_value = 1.0; private double animation_value = 1.0;
private ulong animation_done_cb_id = 0; private ulong animation_done_cb_id = 0;
private unowned SourceFunc ? removed_cb = null; private unowned SourceFunc ?removed_cb = null;
private unowned SourceFunc ? added_cb = null; private unowned SourceFunc ?added_cb = null;
public AnimatedListItem () { public AnimatedListItem () {
Object ( Object (
css_name: "animatedlistitem", css_name : "animatedlistitem",
accessible_role: Gtk.AccessibleRole.LIST_ITEM, accessible_role : Gtk.AccessibleRole.LIST_ITEM,
overflow: Gtk.Overflow.HIDDEN, overflow: Gtk.Overflow.HIDDEN,
animation_duration: DEFAULT_ANIMATION_DURATION, animation_duration: DEFAULT_ANIMATION_DURATION,
animation_easing: Adw.Easing.EASE_OUT_QUINT, animation_easing: Adw.Easing.EASE_OUT_QUINT,
...@@ -111,13 +111,13 @@ public class AnimatedListItem : Gtk.Widget { ...@@ -111,13 +111,13 @@ public class AnimatedListItem : Gtk.Widget {
case ChildAnimationType.SLIDE_FROM_RIGHT: case ChildAnimationType.SLIDE_FROM_RIGHT:
transform = transform.translate_3d ( transform = transform.translate_3d (
Graphene.Point3D () Graphene.Point3D ()
.init (child_width * (float) (1 - animation_value), 0, 0) .init (child_width * (float) (1 - animation_value), 0, 0)
); );
break; break;
case ChildAnimationType.SLIDE_FROM_LEFT: case ChildAnimationType.SLIDE_FROM_LEFT:
transform = transform.translate_3d ( transform = transform.translate_3d (
Graphene.Point3D () Graphene.Point3D ()
.init (-child_width * (float) (1 - animation_value), 0, 0) .init (-child_width * (float) (1 - animation_value), 0, 0)
); );
break; break;
case ChildAnimationType.NONE: case ChildAnimationType.NONE:
...@@ -184,6 +184,7 @@ public class AnimatedListItem : Gtk.Widget { ...@@ -184,6 +184,7 @@ public class AnimatedListItem : Gtk.Widget {
} }
delegate void animation_done (Adw.Animation animation); delegate void animation_done (Adw.Animation animation);
private void set_animation_done_cb (animation_done handler) { private void set_animation_done_cb (animation_done handler) {
remove_animation_done_cb (); remove_animation_done_cb ();
animation_done_cb_id = animation.done.connect (handler); animation_done_cb_id = animation.done.connect (handler);
......
...@@ -22,7 +22,9 @@ namespace SwayNotificationCenter { ...@@ -22,7 +22,9 @@ namespace SwayNotificationCenter {
}); });
blank_window_gesture.released.connect ((n_press, x, y) => { blank_window_gesture.released.connect ((n_press, x, y) => {
// Emit released // Emit released
if (!blank_window_down) return; if (!blank_window_down) {
return;
}
blank_window_down = false; blank_window_down = false;
if (blank_window_in) { if (blank_window_in) {
try { try {
...@@ -39,13 +41,15 @@ namespace SwayNotificationCenter { ...@@ -39,13 +41,15 @@ namespace SwayNotificationCenter {
}); });
blank_window_gesture.update.connect ((gesture, sequence) => { blank_window_gesture.update.connect ((gesture, sequence) => {
Gtk.GestureSingle gesture_single = (Gtk.GestureSingle) gesture; Gtk.GestureSingle gesture_single = (Gtk.GestureSingle) gesture;
if (sequence != gesture_single.get_current_sequence ()) return; if (sequence != gesture_single.get_current_sequence ()) {
return;
}
// Calculate if the clicked coords intersect other monitors // Calculate if the clicked coords intersect other monitors
double x, y; double x, y;
gesture.get_point (sequence, out x, out y); gesture.get_point (sequence, out x, out y);
Graphene.Point click_point = Graphene.Point () Graphene.Point click_point = Graphene.Point ()
.init ((float) x, (float) y); .init ((float) x, (float) y);
Graphene.Rect ? bounds = null; Graphene.Rect ?bounds = null;
this.compute_bounds (this, out bounds); this.compute_bounds (this, out bounds);
if (bounds != null && bounds.contains_point (click_point)) { if (bounds != null && bounds.contains_point (click_point)) {
blank_window_in = false; blank_window_in = false;
......
...@@ -7,7 +7,6 @@ public struct SwayncDaemonData { ...@@ -7,7 +7,6 @@ public struct SwayncDaemonData {
[DBus (name = "org.erikreider.swaync.cc")] [DBus (name = "org.erikreider.swaync.cc")]
interface CcDaemon : Object { interface CcDaemon : Object {
public abstract bool reload_css () throws Error; public abstract bool reload_css () throws Error;
public abstract void reload_config () throws Error; public abstract void reload_config () throws Error;
...@@ -73,11 +72,13 @@ private void print_help (string[] args) { ...@@ -73,11 +72,13 @@ private void print_help (string[] args) {
print (" -Ir, \t --inhibitor-remove [APP_ID] \t Remove an inhibitor\n"); print (" -Ir, \t --inhibitor-remove [APP_ID] \t Remove an inhibitor\n");
print (" -Ic, \t --inhibitors-clear \t\t Clears all inhibitors\n"); print (" -Ic, \t --inhibitors-clear \t\t Clears all inhibitors\n");
print (" -c, \t --count \t\t\t Print the current notification count\n"); print (" -c, \t --count \t\t\t Print the current notification count\n");
print (" \t --hide-latest \t\t\t Hides latest notification. Still shown in Control Center\n"); print (
" \t --hide-latest \t\t\t Hides latest notification. Still shown in Control Center\n");
print (" \t --hide-all \t\t\t Hides all notifications. Still shown in Control Center\n"); print (" \t --hide-all \t\t\t Hides all notifications. Still shown in Control Center\n");
print (" \t --close-latest \t\t Closes latest notification\n"); print (" \t --close-latest \t\t Closes latest notification\n");
print (" -C, \t --close-all \t\t\t Closes all notifications\n"); print (" -C, \t --close-all \t\t\t Closes all notifications\n");
print (" -a, \t --action [ACTION_INDEX]\t Invokes the action [ACTION_INDEX] of the latest notification\n"); print (" -a, \t --action [ACTION_INDEX]\t " +
"Invokes the action [ACTION_INDEX] of the latest notification\n");
print (" -sw, \t --skip-wait \t\t\t Doesn't wait when swaync hasn't been started\n"); print (" -sw, \t --skip-wait \t\t\t Doesn't wait when swaync hasn't been started\n");
print (" -s, \t --subscribe \t\t\t Subscribe to notification add and close events\n"); print (" -s, \t --subscribe \t\t\t Subscribe to notification add and close events\n");
print (" -swb, --subscribe-waybar \t\t Subscribe to notification add and close events " print (" -swb, --subscribe-waybar \t\t Subscribe to notification add and close events "
...@@ -91,7 +92,7 @@ private void print_help (string[] args) { ...@@ -91,7 +92,7 @@ private void print_help (string[] args) {
private void on_subscribe (uint count, bool dnd, bool cc_open, bool inhibited) { private void on_subscribe (uint count, bool dnd, bool cc_open, bool inhibited) {
stdout.printf ( stdout.printf (
"{ \"count\": %u, \"dnd\": %s, \"visible\": %s, \"inhibited\": %s }\n", "{ \"count\": %u, \"dnd\": %s, \"visible\": %s, \"inhibited\": %s }\n",
count, dnd.to_string (), cc_open.to_string (), inhibited.to_string ()); count, dnd.to_string (), cc_open.to_string (), inhibited.to_string ());
stdout.flush (); stdout.flush ();
} }
...@@ -106,8 +107,8 @@ private void print_subscribe () { ...@@ -106,8 +107,8 @@ private void print_subscribe () {
private void on_subscribe_waybar (uint count, bool dnd, bool cc_open, bool inhibited) { private void on_subscribe_waybar (uint count, bool dnd, bool cc_open, bool inhibited) {
string state = (dnd ? "dnd-" : "") string state = (dnd ? "dnd-" : "")
+ (inhibited ? "inhibited-" : "") + (inhibited ? "inhibited-" : "")
+ (count > 0 ? "notification" : "none"); + (count > 0 ? "notification" : "none");
string tooltip = ""; string tooltip = "";
if (count > 0) { if (count > 0) {
...@@ -317,7 +318,9 @@ public int command_line (ref string[] args, bool skip_wait) { ...@@ -317,7 +318,9 @@ public int command_line (ref string[] args, bool skip_wait) {
} }
} catch (Error e) { } catch (Error e) {
stderr.printf (e.message + "\n"); stderr.printf (e.message + "\n");
if (skip_wait) Process.exit (1); if (skip_wait) {
Process.exit (1);
}
return 1; return 1;
} }
...@@ -341,7 +344,7 @@ int try_connect (owned string[] args) { ...@@ -341,7 +344,7 @@ int try_connect (owned string[] args) {
bool one_arg = true; bool one_arg = true;
while (args.length > 0) { while (args.length > 0) {
if (args[0] == "--skip-wait" || args[0] == "-sw") { if (args[0] == "--skip-wait" || args[0] == "-sw") {
args = args[1:]; args = args[1 :];
continue; continue;
} }
if (!one_arg) { if (!one_arg) {
...@@ -366,14 +369,16 @@ int try_connect (owned string[] args) { ...@@ -366,14 +369,16 @@ int try_connect (owned string[] args) {
} }
public int main (string[] args) { public int main (string[] args) {
if (try_connect (args[1:]) == 1) { if (try_connect (args[1 :]) == 1) {
MainLoop loop = new MainLoop (); MainLoop loop = new MainLoop ();
Bus.watch_name ( Bus.watch_name (
BusType.SESSION, BusType.SESSION,
"org.erikreider.swaync.cc", "org.erikreider.swaync.cc",
BusNameWatcherFlags.NONE, BusNameWatcherFlags.NONE,
(conn, name, name_owner) => { (conn, name, name_owner) => {
if (try_connect (args[1:]) == 0) loop.quit (); if (try_connect (args[1 :]) == 0) {
loop.quit ();
}
}, },
null); null);
loop.run (); loop.run ();
......
...@@ -21,7 +21,7 @@ namespace SwayNotificationCenter { ...@@ -21,7 +21,7 @@ namespace SwayNotificationCenter {
private List<Widgets.BaseWidget> widgets; private List<Widgets.BaseWidget> widgets;
private const string[] DEFAULT_WIDGETS = { "title", "dnd", "notifications" }; private const string[] DEFAULT_WIDGETS = { "title", "dnd", "notifications" };
private string ? monitor_name = null; private string ?monitor_name = null;
public ControlCenter (SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public ControlCenter (SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
Object (css_name: "blankwindow"); Object (css_name: "blankwindow");
...@@ -74,15 +74,17 @@ namespace SwayNotificationCenter { ...@@ -74,15 +74,17 @@ namespace SwayNotificationCenter {
blank_window_gesture.pressed.connect ((n_press, x, y) => { blank_window_gesture.pressed.connect ((n_press, x, y) => {
// Calculate if the clicked coords intersect the ControlCenter // Calculate if the clicked coords intersect the ControlCenter
Graphene.Point click_point = Graphene.Point () Graphene.Point click_point = Graphene.Point ()
.init ((float) x, (float) y); .init ((float) x, (float) y);
Graphene.Rect ? bounds = null; Graphene.Rect ?bounds = null;
window.compute_bounds (this, out bounds); window.compute_bounds (this, out bounds);
blank_window_in = !(bounds != null && bounds.contains_point (click_point)); blank_window_in = !(bounds != null && bounds.contains_point (click_point));
blank_window_down = true; blank_window_down = true;
}); });
blank_window_gesture.released.connect ((n_press, x, y) => { blank_window_gesture.released.connect ((n_press, x, y) => {
// Emit released // Emit released
if (!blank_window_down) return; if (!blank_window_down) {
return;
}
blank_window_down = false; blank_window_down = false;
if (blank_window_in) { if (blank_window_in) {
try { try {
...@@ -99,13 +101,15 @@ namespace SwayNotificationCenter { ...@@ -99,13 +101,15 @@ namespace SwayNotificationCenter {
}); });
blank_window_gesture.update.connect ((gesture, sequence) => { blank_window_gesture.update.connect ((gesture, sequence) => {
Gtk.GestureSingle gesture_single = (Gtk.GestureSingle) gesture; Gtk.GestureSingle gesture_single = (Gtk.GestureSingle) gesture;
if (sequence != gesture_single.get_current_sequence ()) return; if (sequence != gesture_single.get_current_sequence ()) {
return;
}
// Calculate if the clicked coords intersect the ControlCenter // Calculate if the clicked coords intersect the ControlCenter
double x, y; double x, y;
gesture.get_point (sequence, out x, out y); gesture.get_point (sequence, out x, out y);
Graphene.Point click_point = Graphene.Point () Graphene.Point click_point = Graphene.Point ()
.init ((float) x, (float) y); .init ((float) x, (float) y);
Graphene.Rect ? bounds = null; Graphene.Rect ?bounds = null;
window.compute_bounds (this, out bounds); window.compute_bounds (this, out bounds);
if (bounds != null && bounds.contains_point (click_point)) { if (bounds != null && bounds.contains_point (click_point)) {
blank_window_in = false; blank_window_in = false;
...@@ -141,14 +145,14 @@ namespace SwayNotificationCenter { ...@@ -141,14 +145,14 @@ namespace SwayNotificationCenter {
private void key_released_event_cb (uint keyval, uint keycode, Gdk.ModifierType state) { private void key_released_event_cb (uint keyval, uint keycode, Gdk.ModifierType state) {
if (this.get_focus () is Gtk.Entry) { if (this.get_focus () is Gtk.Entry) {
switch (Gdk.keyval_name (keyval)) { switch (Gdk.keyval_name (keyval)) {
case "Escape": case "Escape" :
this.set_focus (null); this.set_focus (null);
return; return;
} }
return; return;
} }
switch (Gdk.keyval_name (keyval)) { switch (Gdk.keyval_name (keyval)) {
case "Escape": case "Escape" :
case "Caps_Lock": case "Caps_Lock":
this.set_visibility (false); this.set_visibility (false);
return; return;
...@@ -189,23 +193,27 @@ namespace SwayNotificationCenter { ...@@ -189,23 +193,27 @@ namespace SwayNotificationCenter {
}); });
string[] w = ConfigModel.instance.widgets.data; string[] w = ConfigModel.instance.widgets.data;
if (w.length == 0) w = DEFAULT_WIDGETS; if (w.length == 0) {
w = DEFAULT_WIDGETS;
}
// Add the notifications widget if not found in the list // Add the notifications widget if not found in the list
if (!("notifications" in w)) { if (!("notifications" in w)) {
warning ("Notification widget not included in \"widgets\" config. Using default bottom position"); warning ("Notification widget not included in \"widgets\" config. " +
"Using default bottom position");
w += "notifications"; w += "notifications";
} }
bool has_notifications = false; bool has_notifications = false;
foreach (string key in w) { foreach (string key in w) {
// Add the widget if it is valid // Add the widget if it is valid
bool is_notifications; bool is_notifications;
Widgets.BaseWidget ? widget = Widgets.get_widget_from_key ( Widgets.BaseWidget ?widget = Widgets.get_widget_from_key (
key, swaync_daemon, noti_daemon, out is_notifications); key, swaync_daemon, noti_daemon, out is_notifications);
if (is_notifications) { if (is_notifications) {
if (has_notifications) { if (has_notifications) {
warning ("Cannot have multiple \"notifications\" widgets! Skipping\"%s\"", key); warning ("Cannot have multiple \"notifications\" widgets! Skipping\"%s\"",
key);
continue; continue;
} }
has_notifications = true; has_notifications = true;
...@@ -231,9 +239,13 @@ namespace SwayNotificationCenter { ...@@ -231,9 +239,13 @@ namespace SwayNotificationCenter {
/** Resets the UI positions */ /** Resets the UI positions */
private void set_anchor () { private void set_anchor () {
PositionX pos_x = ConfigModel.instance.control_center_positionX; PositionX pos_x = ConfigModel.instance.control_center_positionX;
if (pos_x == PositionX.NONE) pos_x = ConfigModel.instance.positionX; if (pos_x == PositionX.NONE) {
pos_x = ConfigModel.instance.positionX;
}
PositionY pos_y = ConfigModel.instance.control_center_positionY; PositionY pos_y = ConfigModel.instance.control_center_positionY;
if (pos_y == PositionY.NONE) pos_y = ConfigModel.instance.positionY; if (pos_y == PositionY.NONE) {
pos_y = ConfigModel.instance.positionY;
}
if (swaync_daemon.use_layer_shell) { if (swaync_daemon.use_layer_shell) {
// Set the exlusive zone // Set the exlusive zone
...@@ -242,8 +254,8 @@ namespace SwayNotificationCenter { ...@@ -242,8 +254,8 @@ namespace SwayNotificationCenter {
// Grabs the keyboard input until closed // Grabs the keyboard input until closed
bool keyboard_shortcuts = ConfigModel.instance.keyboard_shortcuts; bool keyboard_shortcuts = ConfigModel.instance.keyboard_shortcuts;
var mode = keyboard_shortcuts ? var mode = keyboard_shortcuts ?
GtkLayerShell.KeyboardMode.EXCLUSIVE : GtkLayerShell.KeyboardMode.EXCLUSIVE :
GtkLayerShell.KeyboardMode.NONE; GtkLayerShell.KeyboardMode.NONE;
GtkLayerShell.set_keyboard_mode (this, mode); GtkLayerShell.set_keyboard_mode (this, mode);
// Set layer // Set layer
...@@ -260,7 +272,7 @@ namespace SwayNotificationCenter { ...@@ -260,7 +272,7 @@ namespace SwayNotificationCenter {
} else { } else {
// Fallback to conventional positioning // Fallback to conventional positioning
switch (pos_x) { switch (pos_x) {
case PositionX.LEFT: case PositionX.LEFT :
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, true); GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, false); GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, false);
break; break;
...@@ -337,7 +349,9 @@ namespace SwayNotificationCenter { ...@@ -337,7 +349,9 @@ namespace SwayNotificationCenter {
break; break;
} }
// Fit the ControlCenter to the monitor height // Fit the ControlCenter to the monitor height
if (ConfigModel.instance.fit_to_screen) align_y = Gtk.Align.FILL; if (ConfigModel.instance.fit_to_screen) {
align_y = Gtk.Align.FILL;
}
// Set the ControlCenter alignment // Set the ControlCenter alignment
window.set_halign (align_x); window.set_halign (align_x);
window.set_valign (align_y); window.set_valign (align_y);
...@@ -347,12 +361,12 @@ namespace SwayNotificationCenter { ...@@ -347,12 +361,12 @@ namespace SwayNotificationCenter {
ConfigModel.instance.control_center_height < 1 ConfigModel.instance.control_center_height < 1
|| ConfigModel.instance.fit_to_screen); || ConfigModel.instance.fit_to_screen);
window.set_size_request (ConfigModel.instance.control_center_width, window.set_size_request (ConfigModel.instance.control_center_width,
ConfigModel.instance.control_center_height); ConfigModel.instance.control_center_height);
box.set_size_request (ConfigModel.instance.control_center_width, box.set_size_request (ConfigModel.instance.control_center_width,
ConfigModel.instance.control_center_height); ConfigModel.instance.control_center_height);
// Set the preferred monitor // Set the preferred monitor
string ? monitor_name = ConfigModel.instance.control_center_preferred_output; string ?monitor_name = ConfigModel.instance.control_center_preferred_output;
if (this.monitor_name != null) { if (this.monitor_name != null) {
monitor_name = this.monitor_name; monitor_name = this.monitor_name;
} }
...@@ -391,7 +405,9 @@ namespace SwayNotificationCenter { ...@@ -391,7 +405,9 @@ namespace SwayNotificationCenter {
} }
public void set_visibility (bool visibility) { public void set_visibility (bool visibility) {
if (this.visible == visibility) return; if (this.visible == visibility) {
return;
}
if (visibility) { if (visibility) {
// Destroy the wl_surface to get a new "enter-monitor" signal // Destroy the wl_surface to get a new "enter-monitor" signal
((Gtk.Widget) this).unrealize (); ((Gtk.Widget) this).unrealize ();
...@@ -417,7 +433,7 @@ namespace SwayNotificationCenter { ...@@ -417,7 +433,7 @@ namespace SwayNotificationCenter {
return this.visible; return this.visible;
} }
public void set_monitor (Gdk.Monitor ? monitor) { public void set_monitor (Gdk.Monitor ?monitor) {
this.monitor_name = monitor == null ? null : monitor.connector; this.monitor_name = monitor == null ? null : monitor.connector;
GtkLayerShell.set_monitor (this, monitor); GtkLayerShell.set_monitor (this, monitor);
} }
......
...@@ -16,21 +16,22 @@ namespace SwayNotificationCenter.Widgets { ...@@ -16,21 +16,22 @@ namespace SwayNotificationCenter.Widgets {
public Backlight (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public Backlight (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon); base (suffix, swaync_daemon, noti_daemon);
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
string ? label = get_prop<string> (config, "label"); string ?label = get_prop<string> (config, "label");
label_widget.set_label (label ?? "Brightness"); label_widget.set_label (label ?? "Brightness");
string device = (get_prop<string> (config, "device") ?? "intel_backlight"); string device = (get_prop<string> (config, "device") ?? "intel_backlight");
string subsystem = (get_prop<string> (config, "subsystem") ?? "backlight"); string subsystem = (get_prop<string> (config, "subsystem") ?? "backlight");
int min = int.max (0, get_prop<int> (config, "min")); int min = int.max (0, get_prop<int> (config, "min"));
switch (subsystem) { switch (subsystem) {
default: default :
case "backlight": case "backlight":
if (subsystem != "backlight") if (subsystem != "backlight") {
info ("Invalid subsystem %s for device %s. " + info ("Invalid subsystem %s for device %s. " +
"Use 'backlight' or 'leds'. Using default: 'backlight'", "Use 'backlight' or 'leds'. Using default: 'backlight'",
subsystem, device); subsystem, device);
}
client = new BacklightUtil ("backlight", device); client = new BacklightUtil ("backlight", device);
slider.set_range (min, 100); slider.set_range (min, 100);
break; break;
......
namespace SwayNotificationCenter.Widgets { namespace SwayNotificationCenter.Widgets {
class BacklightUtil { class BacklightUtil {
[DBus (name = "org.freedesktop.login1.Session")] [DBus (name = "org.freedesktop.login1.Session")]
interface Login1 : Object { interface Login1 : Object {
public abstract async void set_brightness (string subsystem, public abstract async void set_brightness (string subsystem,
string name, uint32 brightness) throws GLib.Error; string name,
uint32 brightness) throws GLib.Error;
} }
string path_current; string path_current;
...@@ -45,7 +45,8 @@ namespace SwayNotificationCenter.Widgets { ...@@ -45,7 +45,8 @@ namespace SwayNotificationCenter.Widgets {
try { try {
// setup DBus for setting brightness // setup DBus for setting brightness
login1 = Bus.get_proxy_sync (BusType.SYSTEM, login1 = Bus.get_proxy_sync (BusType.SYSTEM,
"org.freedesktop.login1", "/org/freedesktop/login1/session/auto"); "org.freedesktop.login1",
"/org/freedesktop/login1/session/auto");
} catch (Error e) { } catch (Error e) {
critical ("Error %s\n", e.message); critical ("Error %s\n", e.message);
} }
...@@ -74,7 +75,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -74,7 +75,9 @@ namespace SwayNotificationCenter.Widgets {
} }
public void close () { public void close () {
if (monitor != null) monitor.cancel (); if (monitor != null) {
monitor.cancel ();
}
} }
public async void set_brightness (float percent) { public async void set_brightness (float percent) {
......
...@@ -19,12 +19,12 @@ namespace SwayNotificationCenter.Widgets { ...@@ -19,12 +19,12 @@ namespace SwayNotificationCenter.Widgets {
NORMAL; NORMAL;
public static ButtonType parse (string value) { public static ButtonType parse (string value) {
switch (value) { switch (value) {
case "toggle": case "toggle":
return ButtonType.TOGGLE; return ButtonType.TOGGLE;
default: default:
return ButtonType.NORMAL; return ButtonType.NORMAL;
} }
} }
} }
...@@ -37,14 +37,16 @@ namespace SwayNotificationCenter.Widgets { ...@@ -37,14 +37,16 @@ namespace SwayNotificationCenter.Widgets {
set_overflow (Gtk.Overflow.HIDDEN); set_overflow (Gtk.Overflow.HIDDEN);
add_css_class ("widget"); add_css_class ("widget");
add_css_class (css_class_name); add_css_class (css_class_name);
if (suffix.length > 0) add_css_class (suffix); if (suffix.length > 0) {
add_css_class (suffix);
}
} }
protected Json.Object ? get_config (Gtk.Widget widget) { protected Json.Object ?get_config (Gtk.Widget widget) {
unowned OrderedHashTable<Json.Object> config unowned OrderedHashTable<Json.Object> config
= ConfigModel.instance.widget_config; = ConfigModel.instance.widget_config;
string ? orig_key = null; string ?orig_key = null;
Json.Object ? props = null; Json.Object ?props = null;
bool result = config.lookup_extended (key, out orig_key, out props); bool result = config.lookup_extended (key, out orig_key, out props);
if (!result || orig_key == null || props == null) { if (!result || orig_key == null || props == null) {
warning ("%s: Config not found! Using default config...\n", key); warning ("%s: Config not found! Using default config...\n", key);
...@@ -53,9 +55,10 @@ namespace SwayNotificationCenter.Widgets { ...@@ -53,9 +55,10 @@ namespace SwayNotificationCenter.Widgets {
return props; return props;
} }
public virtual void on_cc_visibility_change (bool value) {} public virtual void on_cc_visibility_change (bool value) {
}
protected T ? get_prop<T> (Json.Object config, string value_key, out bool found = null) { protected T ?get_prop<T> (Json.Object config, string value_key, out bool found = null) {
found = false; found = false;
if (!config.has_member (value_key)) { if (!config.has_member (value_key)) {
debug ("%s: Config doesn't have key: %s!\n", key, value_key); debug ("%s: Config doesn't have key: %s!\n", key, value_key);
...@@ -67,7 +70,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -67,7 +70,9 @@ namespace SwayNotificationCenter.Widgets {
Type generic_base_type = Functions.get_base_type (typeof (T)); Type generic_base_type = Functions.get_base_type (typeof (T));
// Convert all INTs to INT64 // Convert all INTs to INT64
if (generic_base_type == Type.INT) generic_base_type = Type.INT64; if (generic_base_type == Type.INT) {
generic_base_type = Type.INT64;
}
if (!base_type.is_a (generic_base_type)) { if (!base_type.is_a (generic_base_type)) {
warning ("%s: Config type %s doesn't match: %s!\n", warning ("%s: Config type %s doesn't match: %s!\n",
...@@ -78,11 +83,11 @@ namespace SwayNotificationCenter.Widgets { ...@@ -78,11 +83,11 @@ namespace SwayNotificationCenter.Widgets {
} }
found = true; found = true;
switch (generic_base_type) { switch (generic_base_type) {
case Type.STRING: case Type.STRING :
return member.get_string (); return member.get_string ();
case Type.INT64: case Type.INT64 :
return (int) member.get_int (); return (int) member.get_int ();
case Type.BOOLEAN: case Type.BOOLEAN :
return member.get_boolean (); return member.get_boolean ();
default: default:
found = false; found = false;
...@@ -90,7 +95,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -90,7 +95,7 @@ namespace SwayNotificationCenter.Widgets {
} }
} }
protected Json.Array ? get_prop_array (Json.Object config, string value_key) { protected Json.Array ?get_prop_array (Json.Object config, string value_key) {
if (!config.has_member (value_key)) { if (!config.has_member (value_key)) {
debug ("%s: Config doesn't have key: %s!\n", key, value_key); debug ("%s: Config doesn't have key: %s!\n", key, value_key);
return null; return null;
...@@ -105,13 +110,20 @@ namespace SwayNotificationCenter.Widgets { ...@@ -105,13 +110,20 @@ namespace SwayNotificationCenter.Widgets {
protected Action[] parse_actions (Json.Array actions) { protected Action[] parse_actions (Json.Array actions) {
Action[] res = new Action[actions.get_length ()]; Action[] res = new Action[actions.get_length ()];
for (int i = 0; i < actions.get_length (); i++) { for (int i = 0; i < actions.get_length (); i++) {
string label = actions.get_object_element (i).get_string_member_with_default ("label", "label"); string label =
string command = actions.get_object_element (i).get_string_member_with_default ("command", ""); actions.get_object_element (i).get_string_member_with_default ("label",
string t = actions.get_object_element (i).get_string_member_with_default ("type", "normal"); "label");
string command =
actions.get_object_element (i).get_string_member_with_default ("command", "");
string t = actions.get_object_element (i).get_string_member_with_default ("type",
"normal");
ButtonType type = ButtonType.parse (t); ButtonType type = ButtonType.parse (t);
string update_command = string update_command =
actions.get_object_element (i).get_string_member_with_default ("update-command", ""); actions.get_object_element (i).get_string_member_with_default ("update-command",
bool active = actions.get_object_element (i).get_boolean_member_with_default ("active", false); "");
bool active =
actions.get_object_element (i).get_boolean_member_with_default ("active",
false);
res[i] = Action () { res[i] = Action () {
label = label, label = label,
command = command, command = command,
...@@ -123,7 +135,6 @@ namespace SwayNotificationCenter.Widgets { ...@@ -123,7 +135,6 @@ namespace SwayNotificationCenter.Widgets {
return res; return res;
} }
protected async void execute_command (string cmd, string[] env_additions = {}) { protected async void execute_command (string cmd, string[] env_additions = {}) {
string msg = ""; string msg = "";
yield Functions.execute_command (cmd, env_additions, out msg); yield Functions.execute_command (cmd, env_additions, out msg);
......
using GLib; using GLib;
namespace SwayNotificationCenter.Widgets { namespace SwayNotificationCenter.Widgets {
public class ButtonsGrid : BaseWidget { public class ButtonsGrid : BaseWidget {
public override string widget_name { public override string widget_name {
get { get {
...@@ -17,14 +16,18 @@ namespace SwayNotificationCenter.Widgets { ...@@ -17,14 +16,18 @@ namespace SwayNotificationCenter.Widgets {
public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon); base (suffix, swaync_daemon, noti_daemon);
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
Json.Array a = get_prop_array (config, "actions"); Json.Array a = get_prop_array (config, "actions");
if (a != null) actions = parse_actions (a); if (a != null) {
actions = parse_actions (a);
}
bool bpr_found = false; bool bpr_found = false;
int bpr = get_prop<int> (config, "buttons-per-row", out bpr_found); int bpr = get_prop<int> (config, "buttons-per-row", out bpr_found);
if (bpr_found) buttons_per_row = bpr; if (bpr_found) {
buttons_per_row = bpr;
}
} }
Gtk.FlowBox container = new Gtk.FlowBox (); Gtk.FlowBox container = new Gtk.FlowBox ();
...@@ -36,8 +39,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -36,8 +39,9 @@ namespace SwayNotificationCenter.Widgets {
// add action to container // add action to container
foreach (var act in actions) { foreach (var act in actions) {
switch (act.type) { switch (act.type) {
case ButtonType.TOGGLE: case ButtonType.TOGGLE :
ToggleButton tb = new ToggleButton (act.label, act.command, act.update_command, act.active); ToggleButton tb = new ToggleButton (act.label, act.command,
act.update_command, act.active);
container.insert (tb, -1); container.insert (tb, -1);
toggle_buttons.append (tb); toggle_buttons.append (tb);
break; break;
......
...@@ -15,11 +15,13 @@ namespace SwayNotificationCenter.Widgets { ...@@ -15,11 +15,13 @@ namespace SwayNotificationCenter.Widgets {
public Dnd (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public Dnd (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon); base (suffix, swaync_daemon, noti_daemon);
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
// Get title // Get title
string? title = get_prop<string> (config, "text"); string ?title = get_prop<string> (config, "text");
if (title != null) this.title = title; if (title != null) {
this.title = title;
}
} }
// Title // Title
......
namespace SwayNotificationCenter.Widgets { namespace SwayNotificationCenter.Widgets {
public static BaseWidget ? get_widget_from_key (owned string key, public static BaseWidget ?get_widget_from_key (owned string key,
SwayncDaemon swaync_daemon, SwayncDaemon swaync_daemon,
NotiDaemon noti_daemon, NotiDaemon noti_daemon,
out bool is_notifications) { out bool is_notifications) {
is_notifications = false; is_notifications = false;
string[] key_seperated = key.split ("#"); string[] key_seperated = key.split ("#");
string suffix = ""; string suffix = "";
if (key_seperated.length > 0) key = key_seperated[0]; if (key_seperated.length > 0) {
if (key_seperated.length > 1) suffix = key_seperated[1]; key = key_seperated[0];
}
if (key_seperated.length > 1) {
suffix = key_seperated[1];
}
BaseWidget widget; BaseWidget widget;
switch (key) { switch (key) {
case "notifications": case "notifications" :
is_notifications = true; is_notifications = true;
message ("Loading widget: widget-notifications"); message ("Loading widget: widget-notifications");
return null; return null;
......
...@@ -26,19 +26,25 @@ namespace SwayNotificationCenter.Widgets { ...@@ -26,19 +26,25 @@ namespace SwayNotificationCenter.Widgets {
title_widget.set_text ("%s %u".printf (title, length)); title_widget.set_text ("%s %u".printf (title, length));
}); });
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
// Get title // Get title
string ? title = get_prop<string> (config, "text"); string ?title = get_prop<string> (config, "text");
if (title != null) this.title = title; if (title != null) {
this.title = title;
}
// Get has clear-all-button // Get has clear-all-button
bool found_clear_all; bool found_clear_all;
bool ? has_clear_all_button = get_prop<bool> ( bool ?has_clear_all_button = get_prop<bool> (
config, "clear-all-button", out found_clear_all); config, "clear-all-button", out found_clear_all);
if (found_clear_all) this.has_clear_all_button = has_clear_all_button; if (found_clear_all) {
this.has_clear_all_button = has_clear_all_button;
}
// Get button text // Get button text
string ? button_text = get_prop<string> (config, "button-text"); string ?button_text = get_prop<string> (config, "button-text");
if (button_text != null) this.button_text = button_text; if (button_text != null) {
this.button_text = button_text;
}
} }
title_widget = new Gtk.Label (title); title_widget = new Gtk.Label (title);
......
...@@ -15,14 +15,18 @@ namespace SwayNotificationCenter.Widgets { ...@@ -15,14 +15,18 @@ namespace SwayNotificationCenter.Widgets {
public Label (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public Label (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon); base (suffix, swaync_daemon, noti_daemon);
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
// Get text // Get text
string? text = get_prop<string> (config, "text"); string ?text = get_prop<string> (config, "text");
if (text != null) this.text = text; if (text != null) {
this.text = text;
}
// Get max lines // Get max lines
int? max_lines = get_prop<int> (config, "max-lines"); int ?max_lines = get_prop<int> (config, "max-lines");
if (max_lines != null) this.max_lines = max_lines; if (max_lines != null) {
this.max_lines = max_lines;
}
} }
label_widget = new Gtk.Label (null); label_widget = new Gtk.Label (null);
......
...@@ -16,9 +16,9 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -16,9 +16,9 @@ namespace SwayNotificationCenter.Widgets.Mpris {
(i, c, inv) => properties_changed (i, c, inv)); (i, c, inv) => properties_changed (i, c, inv));
} }
public static MprisSource ? get_player (string bus_name) { public static MprisSource ?get_player (string bus_name) {
MprisMediaPlayer ? player; MprisMediaPlayer ?player;
DbusPropChange ? props; DbusPropChange ?props;
try { try {
player = Bus.get_proxy_sync (BusType.SESSION, bus_name, INTERFACE_PATH); player = Bus.get_proxy_sync (BusType.SESSION, bus_name, INTERFACE_PATH);
} catch (Error e) { } catch (Error e) {
...@@ -31,18 +31,20 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -31,18 +31,20 @@ namespace SwayNotificationCenter.Widgets.Mpris {
message (e.message); message (e.message);
return null; return null;
} }
if (player == null || props == null) return null; if (player == null || props == null) {
return null;
}
return new MprisSource (player, props); return new MprisSource (player, props);
} }
public Variant ? get_mpris_player_prop (string property_name) { public Variant ?get_mpris_player_prop (string property_name) {
try { try {
return props.get ("org.mpris.MediaPlayer2.Player", property_name); return props.get ("org.mpris.MediaPlayer2.Player", property_name);
} catch (Error e) {} } catch (Error e) {}
return null; return null;
} }
public Variant ? get_mpris_prop (string property_name) { public Variant ?get_mpris_prop (string property_name) {
try { try {
return props.get ("org.mpris.MediaPlayer2", property_name); return props.get ("org.mpris.MediaPlayer2", property_name);
} catch (Error e) {} } catch (Error e) {}
......
...@@ -23,7 +23,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -23,7 +23,7 @@ namespace SwayNotificationCenter.Widgets {
private IterListBoxController list_box_controller; private IterListBoxController list_box_controller;
private unowned NotificationGroup ? expanded_group = null; private unowned NotificationGroup ?expanded_group = null;
private uint scroll_timer_id = 0; private uint scroll_timer_id = 0;
private HashTable<uint32, unowned NotificationGroup> noti_groups_id = private HashTable<uint32, unowned NotificationGroup> noti_groups_id =
...@@ -59,12 +59,14 @@ namespace SwayNotificationCenter.Widgets { ...@@ -59,12 +59,14 @@ namespace SwayNotificationCenter.Widgets {
} }
public void reload_config () { public void reload_config () {
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
// Get vexpand // Get vexpand
bool found_vexpand; bool found_vexpand;
bool? vexpand = get_prop<bool> (config, "vexpand", out found_vexpand); bool ?vexpand = get_prop<bool> (config, "vexpand", out found_vexpand);
if (found_vexpand) this.vertical_expand = vexpand; if (found_vexpand) {
this.vertical_expand = vexpand;
}
} }
set_vexpand (this.vertical_expand); set_vexpand (this.vertical_expand);
...@@ -85,7 +87,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -85,7 +87,9 @@ namespace SwayNotificationCenter.Widgets {
public void close_all_notifications () { public void close_all_notifications () {
foreach (unowned Gtk.Widget w in list_box_controller.get_children ()) { foreach (unowned Gtk.Widget w in list_box_controller.get_children ()) {
NotificationGroup group = (NotificationGroup) w; NotificationGroup group = (NotificationGroup) w;
if (group != null) group.close_all_notifications (); if (group != null) {
group.close_all_notifications ();
}
} }
try { try {
...@@ -173,7 +177,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -173,7 +177,7 @@ namespace SwayNotificationCenter.Widgets {
NotificationType.CONTROL_CENTER); NotificationType.CONTROL_CENTER);
noti.set_time (); noti.set_time ();
NotificationGroup ? group = null; NotificationGroup ?group = null;
if (param.name_id.length > 0) { if (param.name_id.length > 0) {
noti_groups_name.lookup_extended (param.name_id, null, out group); noti_groups_name.lookup_extended (param.name_id, null, out group);
} }
...@@ -254,7 +258,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -254,7 +258,7 @@ namespace SwayNotificationCenter.Widgets {
} }
var group = (NotificationGroup) list_box.get_focus_child (); var group = (NotificationGroup) list_box.get_focus_child ();
switch (Gdk.keyval_name (keyval)) { switch (Gdk.keyval_name (keyval)) {
case "Return": case "Return" :
if (group != null) { if (group != null) {
var noti = group.get_latest_notification (); var noti = group.get_latest_notification ();
if (group.only_single_notification () && noti != null) { if (group.only_single_notification () && noti != null) {
...@@ -264,8 +268,8 @@ namespace SwayNotificationCenter.Widgets { ...@@ -264,8 +268,8 @@ namespace SwayNotificationCenter.Widgets {
group.on_expand_change (group.toggle_expanded ()); group.on_expand_change (group.toggle_expanded ());
} }
break; break;
case "Delete": case "Delete" :
case "BackSpace": case "BackSpace" :
if (group != null && !children.is_empty ()) { if (group != null && !children.is_empty ()) {
var noti = group.get_latest_notification (); var noti = group.get_latest_notification ();
if (group.only_single_notification () && noti != null) { if (group.only_single_notification () && noti != null) {
...@@ -335,9 +339,13 @@ namespace SwayNotificationCenter.Widgets { ...@@ -335,9 +339,13 @@ namespace SwayNotificationCenter.Widgets {
// Check time // Check time
var a_time = a_group.get_time (); var a_time = a_group.get_time ();
var b_time = b_group.get_time (); var b_time = b_group.get_time ();
if (a_time < 0 || b_time < 0) return 0; if (a_time < 0 || b_time < 0) {
return 0;
}
// Sort the list in reverse if needed // Sort the list in reverse if needed
if (a_time == b_time) return 0; if (a_time == b_time) {
return 0;
}
return a_time > b_time ? val : val * -1; return a_time > b_time ? val : val * -1;
} }
...@@ -372,7 +380,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -372,7 +380,7 @@ namespace SwayNotificationCenter.Widgets {
return; return;
} }
unowned Gtk.ListBoxRow ? widget = list_box.get_row_at_index (i); unowned Gtk.ListBoxRow ?widget = list_box.get_row_at_index (i);
if (widget == null) { if (widget == null) {
// Try getting the last widget // Try getting the last widget
if (list_reverse) { if (list_reverse) {
...@@ -389,7 +397,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -389,7 +397,7 @@ namespace SwayNotificationCenter.Widgets {
} }
} }
private void navigate_up (NotificationGroup ? focused_group, private void navigate_up (NotificationGroup ?focused_group,
bool fallback_other_dir = false) { bool fallback_other_dir = false) {
if (list_box_controller.length == 1) { if (list_box_controller.length == 1) {
focus_first_notification (); focus_first_notification ();
...@@ -408,7 +416,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -408,7 +416,7 @@ namespace SwayNotificationCenter.Widgets {
focused_group.move_focus (Gtk.DirectionType.TAB_BACKWARD); focused_group.move_focus (Gtk.DirectionType.TAB_BACKWARD);
} }
private void navigate_down (NotificationGroup ? focused_group, private void navigate_down (NotificationGroup ?focused_group,
bool fallback_other_dir = false) { bool fallback_other_dir = false) {
if (list_box_controller.length == 1) { if (list_box_controller.length == 1) {
focus_first_notification (); focus_first_notification ();
...@@ -429,13 +437,13 @@ namespace SwayNotificationCenter.Widgets { ...@@ -429,13 +437,13 @@ namespace SwayNotificationCenter.Widgets {
private void navigate_to_first_notification () { private void navigate_to_first_notification () {
int i = (list_reverse ? list_box_controller.length - 1 : 0) int i = (list_reverse ? list_box_controller.length - 1 : 0)
.clamp (0, list_box_controller.length); .clamp (0, list_box_controller.length);
navigate_list (i); navigate_list (i);
} }
private void navigate_to_last_notification () { private void navigate_to_last_notification () {
int i = (list_reverse ? 0 : list_box_controller.length - 1) int i = (list_reverse ? 0 : list_box_controller.length - 1)
.clamp (0, list_box_controller.length); .clamp (0, list_box_controller.length);
navigate_list (i); navigate_list (i);
} }
...@@ -444,7 +452,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -444,7 +452,9 @@ namespace SwayNotificationCenter.Widgets {
foreach (unowned Gtk.Widget w in list_box_controller.get_children ()) { foreach (unowned Gtk.Widget w in list_box_controller.get_children ()) {
var group = (NotificationGroup) w; var group = (NotificationGroup) w;
if (group != null) group.update (); if (group != null) {
group.update ();
}
} }
} }
} }
......
namespace SwayNotificationCenter.Widgets { namespace SwayNotificationCenter.Widgets {
class ToggleButton : Gtk.ToggleButton { class ToggleButton : Gtk.ToggleButton {
private string command; private string command;
private string update_command; private string update_command;
private ulong handler_id; private ulong handler_id;
...@@ -26,23 +25,26 @@ namespace SwayNotificationCenter.Widgets { ...@@ -26,23 +25,26 @@ namespace SwayNotificationCenter.Widgets {
} }
public async void on_update () { public async void on_update () {
if (update_command == "") return; if (update_command == "") {
return;
}
string msg = ""; string msg = "";
string[] env_additions = { "SWAYNC_TOGGLE_STATE=" + this.active.to_string () }; string[] env_additions = { "SWAYNC_TOGGLE_STATE=" + this.active.to_string () };
yield Functions.execute_command (this.update_command, env_additions, out msg); yield Functions.execute_command (this.update_command, env_additions, out msg);
try { try {
// remove trailing whitespaces // remove trailing whitespaces
Regex regex = new Regex ("\\s+$"); Regex regex = new Regex ("\\s+$");
string res = regex.replace (msg, msg.length, 0, ""); string res = regex.replace (msg, msg.length, 0, "");
GLib.SignalHandler.block (this, this.handler_id); GLib.SignalHandler.block (this, this.handler_id);
if (res.up () == "TRUE") { if (res.up () == "TRUE") {
this.active = true; this.active = true;
} else { } else {
this.active = false; this.active = false;
} }
GLib.SignalHandler.unblock (this, this.handler_id); GLib.SignalHandler.unblock (this, this.handler_id);
} catch (RegexError e) { } catch (RegexError e) {
stderr.printf ("RegexError: %s\n", e.message); stderr.printf ("RegexError: %s\n", e.message);
} }
} }
} }
......
...@@ -11,7 +11,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -11,7 +11,7 @@ namespace SwayNotificationCenter.Widgets {
private double min_limit; private double min_limit;
private double max_limit; private double max_limit;
private double ? last_set; private double ?last_set;
private bool cmd_ing = false; private bool cmd_ing = false;
private string cmd_setter; private string cmd_setter;
...@@ -20,29 +20,35 @@ namespace SwayNotificationCenter.Widgets { ...@@ -20,29 +20,35 @@ namespace SwayNotificationCenter.Widgets {
public Slider (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public Slider (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon); base (suffix, swaync_daemon, noti_daemon);
int ? round_digits = 0; int ?round_digits = 0;
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
string ? label = get_prop<string> (config, "label"); string ?label = get_prop<string> (config, "label");
label_widget.set_label (label ?? "Slider"); label_widget.set_label (label ?? "Slider");
cmd_setter = get_prop<string> (config, "cmd_setter") ?? ""; cmd_setter = get_prop<string> (config, "cmd_setter") ?? "";
cmd_getter = get_prop<string> (config, "cmd_getter") ?? ""; cmd_getter = get_prop<string> (config, "cmd_getter") ?? "";
int ? min = get_prop<int> (config, "min"); int ?min = get_prop<int> (config, "min");
int ? max = get_prop<int> (config, "max"); int ?max = get_prop<int> (config, "max");
int ? maxl = get_prop<int> (config, "max_limit"); int ?maxl = get_prop<int> (config, "max_limit");
int ? minl = get_prop<int> (config, "min_limit"); int ?minl = get_prop<int> (config, "min_limit");
round_digits = get_prop<int> (config, "value_scale"); round_digits = get_prop<int> (config, "value_scale");
if (min == null)min = 0; if (min == null) {
if (max == null)max = 100; min = 0;
if (round_digits == null)round_digits = 0; }
if (max == null) {
max = 100;
}
if (round_digits == null) {
round_digits = 0;
}
max_limit = maxl != null ? double.min (max, maxl) : max; max_limit = maxl != null ?double.min (max, maxl) : max;
min_limit = minl != null ? double.max (min, minl) : min; min_limit = minl != null ?double.max (min, minl) : min;
double scale = Math.pow (10, round_digits); double scale = Math.pow (10, round_digits);
...@@ -58,10 +64,12 @@ namespace SwayNotificationCenter.Widgets { ...@@ -58,10 +64,12 @@ namespace SwayNotificationCenter.Widgets {
slider.set_halign (Gtk.Align.FILL); slider.set_halign (Gtk.Align.FILL);
slider.value_changed.connect (() => { slider.value_changed.connect (() => {
double value = slider.get_value (); double value = slider.get_value ();
if (value > max_limit) if (value > max_limit) {
value = max_limit; value = max_limit;
if (value < min_limit) }
if (value < min_limit) {
value = min_limit; value = min_limit;
}
slider.set_value (value); slider.set_value (value);
slider.tooltip_text = value.to_string (); slider.tooltip_text = value.to_string ();
...@@ -87,8 +95,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -87,8 +95,9 @@ namespace SwayNotificationCenter.Widgets {
} }
public async void queue_set (double value) { public async void queue_set (double value) {
if (cmd_ing) if (cmd_ing) {
return; return;
}
cmd_ing = true; cmd_ing = true;
var cmd = expand_cmd (cmd_setter, "$value", value.to_string ()); var cmd = expand_cmd (cmd_setter, "$value", value.to_string ());
...@@ -118,8 +127,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -118,8 +127,9 @@ namespace SwayNotificationCenter.Widgets {
} }
public async void on_update () { public async void on_update () {
if (cmd_getter == "") if (cmd_getter == "") {
return; return;
}
string value_str = ""; string value_str = "";
yield queue_get (4, out value_str); yield queue_get (4, out value_str);
...@@ -132,8 +142,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -132,8 +142,9 @@ namespace SwayNotificationCenter.Widgets {
} }
public override void on_cc_visibility_change (bool value) { public override void on_cc_visibility_change (bool value) {
if (value) if (value) {
on_update.begin (); on_update.begin ();
}
} }
} }
} }
...@@ -17,19 +17,25 @@ namespace SwayNotificationCenter.Widgets { ...@@ -17,19 +17,25 @@ namespace SwayNotificationCenter.Widgets {
public Title (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public Title (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon); base (suffix, swaync_daemon, noti_daemon);
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
// Get title // Get title
string ? title = get_prop<string> (config, "text"); string ?title = get_prop<string> (config, "text");
if (title != null) this.title = title; if (title != null) {
this.title = title;
}
// Get has clear-all-button // Get has clear-all-button
bool found_clear_all; bool found_clear_all;
bool? has_clear_all_button = get_prop<bool> ( bool ?has_clear_all_button = get_prop<bool> (
config, "clear-all-button", out found_clear_all); config, "clear-all-button", out found_clear_all);
if (found_clear_all) this.has_clear_all_button = has_clear_all_button; if (found_clear_all) {
this.has_clear_all_button = has_clear_all_button;
}
// Get button text // Get button text
string? button_text = get_prop<string> (config, "button-text"); string ?button_text = get_prop<string> (config, "button-text");
if (button_text != null) this.button_text = button_text; if (button_text != null) {
this.button_text = button_text;
}
} }
title_widget = new Gtk.Label (title); title_widget = new Gtk.Label (title);
......
// From SwaySettings PulseAudio page: https://github.com/ErikReider/SwaySettings/blob/407c9e99dd3e50a0f09c64d94a9e6ff741488378/src/Pages/Pulse/PulseDevice.vala // From SwaySettings PulseAudio page: https://github.com/ErikReider/SwaySettings/blob/407c9e99dd3e50a0f09c64d94a9e6ff741488378/src/Pages/Pulse/PulseDevice.vala
using PulseAudio;
using Gee; using Gee;
using PulseAudio;
namespace SwayNotificationCenter.Widgets { namespace SwayNotificationCenter.Widgets {
public class PulseCardProfile : Object { public class PulseCardProfile : Object {
...@@ -10,7 +10,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -10,7 +10,7 @@ namespace SwayNotificationCenter.Widgets {
public uint32 priority; public uint32 priority;
int available; int available;
public PulseCardProfile (CardProfileInfo2 * profile) { public PulseCardProfile (CardProfileInfo2 *profile) {
this.name = profile->name; this.name = profile->name;
this.description = profile->description; this.description = profile->description;
this.n_sinks = profile->n_sinks; this.n_sinks = profile->n_sinks;
...@@ -28,7 +28,6 @@ namespace SwayNotificationCenter.Widgets { ...@@ -28,7 +28,6 @@ namespace SwayNotificationCenter.Widgets {
} }
public class PulseDevice : Object { public class PulseDevice : Object {
public bool removed { get; set; default = false; } public bool removed { get; set; default = false; }
public bool has_card { get; set; default = true; } public bool has_card { get; set; default = true; }
...@@ -61,7 +60,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -61,7 +60,7 @@ namespace SwayNotificationCenter.Widgets {
public string card_sink_port_name { get; set; } public string card_sink_port_name { get; set; }
/** The Sink name: `Name` */ /** The Sink name: `Name` */
public string ? device_name { get; set; } public string ?device_name { get; set; }
/** The Sink description: `Description` */ /** The Sink description: `Description` */
public string device_description { get; set; } public string device_description { get; set; }
/** If the Sink is muted: `Mute` */ /** If the Sink is muted: `Mute` */
...@@ -76,7 +75,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -76,7 +75,7 @@ namespace SwayNotificationCenter.Widgets {
/** Gets the name to be shown to the user: /** Gets the name to be shown to the user:
* "port_description - card_description" * "port_description - card_description"
*/ */
public string ? get_display_name () { public string ?get_display_name () {
if (card_name == null) { if (card_name == null) {
return device_description; return device_description;
} }
...@@ -126,7 +125,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -126,7 +125,7 @@ namespace SwayNotificationCenter.Widgets {
/** All port profiles */ /** All port profiles */
public string[] port_profiles { get; set; } public string[] port_profiles { get; set; }
public Array<PulseCardProfile> profiles { get; set; } public Array<PulseCardProfile> profiles { get; set; }
public PulseCardProfile ? active_profile { get; set; } public PulseCardProfile ?active_profile { get; set; }
construct { construct {
volume_operations = new LinkedList<Operation> (); volume_operations = new LinkedList<Operation> ();
......
// From SwaySettings PulseAudio page: https://github.com/ErikReider/SwaySettings/blob/2b05776bce2fd55933a7fbdec995f54849e39e7d/src/Pages/Pulse/PulseSinkInput.vala // From SwaySettings PulseAudio page: https://github.com/ErikReider/SwaySettings/blob/2b05776bce2fd55933a7fbdec995f54849e39e7d/src/Pages/Pulse/PulseSinkInput.vala
using PulseAudio;
using Gee; using Gee;
using PulseAudio;
namespace SwayNotificationCenter.Widgets { namespace SwayNotificationCenter.Widgets {
public class PulseSinkInput : Object { public class PulseSinkInput : Object {
...@@ -16,7 +16,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -16,7 +16,7 @@ namespace SwayNotificationCenter.Widgets {
/** The name of the application binary: `application.process.binary` */ /** The name of the application binary: `application.process.binary` */
public string application_binary; public string application_binary;
/** The application icon. Can be null: `application.icon_name` */ /** The application icon. Can be null: `application.icon_name` */
public string ? application_icon_name; public string ?application_icon_name;
/** The name of the media: `media.name` */ /** The name of the media: `media.name` */
public string media_name; public string media_name;
...@@ -34,7 +34,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -34,7 +34,7 @@ namespace SwayNotificationCenter.Widgets {
/** Gets the name to be shown to the user: /** Gets the name to be shown to the user:
* "application_name" * "application_name"
*/ */
public string ? get_display_name () { public string ?get_display_name () {
return name; return name;
} }
......
namespace SwayNotificationCenter.Widgets { namespace SwayNotificationCenter.Widgets {
public class SinkInputRow : Gtk.ListBoxRow { public class SinkInputRow : Gtk.ListBoxRow {
Gtk.Box container; Gtk.Box container;
Gtk.Image icon = new Gtk.Image (); Gtk.Image icon = new Gtk.Image ();
Gtk.Label label = new Gtk.Label (null); Gtk.Label label = new Gtk.Label (null);
......
...@@ -18,8 +18,8 @@ namespace SwayNotificationCenter.Widgets { ...@@ -18,8 +18,8 @@ namespace SwayNotificationCenter.Widgets {
Gtk.Label no_sink_inputs_label; Gtk.Label no_sink_inputs_label;
string empty_label = "No active sink input"; string empty_label = "No active sink input";
string ? expand_label = null; string ?expand_label = null;
string ? collapse_label = null; string ?collapse_label = null;
[Version (deprecated = true, replacement = "CSS root variable")] [Version (deprecated = true, replacement = "CSS root variable")]
int icon_size = -1; int icon_size = -1;
...@@ -27,7 +27,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -27,7 +27,7 @@ namespace SwayNotificationCenter.Widgets {
Gtk.RevealerTransitionType revealer_type = Gtk.RevealerTransitionType.SLIDE_DOWN; Gtk.RevealerTransitionType revealer_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
int revealer_duration = 250; int revealer_duration = 250;
private PulseDevice ? default_sink = null; private PulseDevice ?default_sink = null;
private PulseDaemon client = new PulseDaemon (); private PulseDaemon client = new PulseDaemon ();
private bool show_per_app; private bool show_per_app;
...@@ -50,42 +50,61 @@ namespace SwayNotificationCenter.Widgets { ...@@ -50,42 +50,61 @@ namespace SwayNotificationCenter.Widgets {
public Volume (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public Volume (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
base (suffix, swaync_daemon, noti_daemon); base (suffix, swaync_daemon, noti_daemon);
Json.Object ? config = get_config (this); Json.Object ?config = get_config (this);
if (config != null) { if (config != null) {
string ? label = get_prop<string> (config, "label"); string ?label = get_prop<string> (config, "label");
label_widget.set_label (label ?? "Volume"); label_widget.set_label (label ?? "Volume");
bool show_per_app_found; bool show_per_app_found;
bool ? show_per_app = get_prop<bool> (config, "show-per-app", out show_per_app_found); bool ?show_per_app = get_prop<bool> (config, "show-per-app",
if (show_per_app_found) this.show_per_app = show_per_app; out show_per_app_found);
if (show_per_app_found) {
this.show_per_app = show_per_app;
}
bool show_per_app_icon_found; bool show_per_app_icon_found;
bool ? show_per_app_icon = get_prop<bool> (config, "show-per-app-icon", out show_per_app_icon_found); bool ?show_per_app_icon = get_prop<bool> (config, "show-per-app-icon",
if (show_per_app_icon_found) this.show_per_app_icon = show_per_app_icon; out show_per_app_icon_found);
if (show_per_app_icon_found) {
this.show_per_app_icon = show_per_app_icon;
}
bool show_per_app_label_found; bool show_per_app_label_found;
bool ? show_per_app_label = get_prop<bool> (config, "show-per-app-label", out show_per_app_label_found); bool ?show_per_app_label = get_prop<bool> (config, "show-per-app-label",
if (show_per_app_label_found) this.show_per_app_label = show_per_app_label; out show_per_app_label_found);
if (show_per_app_label_found) {
this.show_per_app_label = show_per_app_label;
}
string ? el = get_prop<string> (config, "empty-list-label"); string ?el = get_prop<string> (config, "empty-list-label");
if (el != null) empty_label = el; if (el != null) {
empty_label = el;
}
string ? l1 = get_prop<string> (config, "expand-button-label"); string ?l1 = get_prop<string> (config, "expand-button-label");
if (l1 != null) expand_label = l1; if (l1 != null) {
string ? l2 = get_prop<string> (config, "collapse-button-label"); expand_label = l1;
if (l2 != null) collapse_label = l2; }
string ?l2 = get_prop<string> (config, "collapse-button-label");
if (l2 != null) {
collapse_label = l2;
}
int i = int.max (get_prop<int> (config, "icon-size"), 0); int i = int.max (get_prop<int> (config, "icon-size"), 0);
if (i != 0) icon_size = i; if (i != 0) {
icon_size = i;
}
revealer_duration = int.max (0, get_prop<int> (config, "animation-duration")); revealer_duration = int.max (0, get_prop<int> (config, "animation-duration"));
if (revealer_duration == 0) revealer_duration = 250; if (revealer_duration == 0) {
revealer_duration = 250;
}
string ? animation_type = get_prop<string> (config, "animation-type"); string ?animation_type = get_prop<string> (config, "animation-type");
if (animation_type != null) { if (animation_type != null) {
switch (animation_type) { switch (animation_type) {
default: default :
case "none": case "none" :
revealer_type = Gtk.RevealerTransitionType.NONE; revealer_type = Gtk.RevealerTransitionType.NONE;
break; break;
case "slide_up": case "slide_up":
......
...@@ -59,7 +59,8 @@ public class DismissibleWidget : Gtk.Widget, Adw.Swipeable { ...@@ -59,7 +59,8 @@ public class DismissibleWidget : Gtk.Widget, Adw.Swipeable {
swipe_tracker.end_swipe.connect (swipe_end_swipe_cb); swipe_tracker.end_swipe.connect (swipe_end_swipe_cb);
double[] snap_dir = get_snap_points (); double[] snap_dir = get_snap_points ();
Adw.PropertyAnimationTarget target = new Adw.PropertyAnimationTarget (this, "swipe-progress"); Adw.PropertyAnimationTarget target = new Adw.PropertyAnimationTarget (this,
"swipe-progress");
animation = new Adw.SpringAnimation (this, snap_dir[0], snap_dir[1], animation = new Adw.SpringAnimation (this, snap_dir[0], snap_dir[1],
new Adw.SpringParams (1, 0.5, 500), new Adw.SpringParams (1, 0.5, 500),
target); target);
...@@ -121,7 +122,7 @@ public class DismissibleWidget : Gtk.Widget, Adw.Swipeable { ...@@ -121,7 +122,7 @@ public class DismissibleWidget : Gtk.Widget, Adw.Swipeable {
} }
Gsk.Transform transform = new Gsk.Transform () Gsk.Transform transform = new Gsk.Transform ()
.translate (Graphene.Point ().init ((float) x, 0)); .translate (Graphene.Point ().init ((float) x, 0));
child.allocate (child_width, child_height, baseline, transform); child.allocate (child_width, child_height, baseline, transform);
} }
......
...@@ -38,7 +38,9 @@ namespace SwayNotificationCenter { ...@@ -38,7 +38,9 @@ namespace SwayNotificationCenter {
if (!is_theme_icon && (is_uri || file_exists)) { if (!is_theme_icon && (is_uri || file_exists)) {
// Try as a URI (file:// is the only URI schema supported right now) // Try as a URI (file:// is the only URI schema supported right now)
try { try {
if (is_uri) uri = uri.slice (URI_PREFIX.length, uri.length); if (is_uri) {
uri = uri.slice (URI_PREFIX.length, uri.length);
}
Gtk.Requisition natural_size; Gtk.Requisition natural_size;
img.get_preferred_size (null, out natural_size); img.get_preferred_size (null, out natural_size);
...@@ -70,13 +72,13 @@ namespace SwayNotificationCenter { ...@@ -70,13 +72,13 @@ namespace SwayNotificationCenter {
img.get_preferred_size (null, out natural_size); img.get_preferred_size (null, out natural_size);
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.with_unowned_data (data.data, Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.with_unowned_data (data.data,
Gdk.Colorspace.RGB, Gdk.Colorspace.RGB,
data.has_alpha, data.has_alpha,
data.bits_per_sample, data.bits_per_sample,
data.width, data.width,
data.height, data.height,
data.rowstride, data.rowstride,
null); null);
Gdk.Pixbuf scaled = pixbuf.scale_simple (natural_size.width, Gdk.Pixbuf scaled = pixbuf.scale_simple (natural_size.width,
natural_size.height, natural_size.height,
Gdk.InterpType.BILINEAR); Gdk.InterpType.BILINEAR);
...@@ -89,7 +91,7 @@ namespace SwayNotificationCenter { ...@@ -89,7 +91,7 @@ namespace SwayNotificationCenter {
* Without this, an empty user CSS file would result in widgets * Without this, an empty user CSS file would result in widgets
* with default GTK style properties * with default GTK style properties
*/ */
public static bool load_css (string ? style_path) { public static bool load_css (string ?style_path) {
int css_priority = ConfigModel.instance.cssPriority.get_priority (); int css_priority = ConfigModel.instance.cssPriority.get_priority ();
// Load packaged CSS as backup // Load packaged CSS as backup
...@@ -122,13 +124,13 @@ namespace SwayNotificationCenter { ...@@ -122,13 +124,13 @@ namespace SwayNotificationCenter {
return true; return true;
} }
public static string get_style_path (owned string ? custom_path, public static string get_style_path (owned string ?custom_path,
bool only_system = false) { bool only_system = false) {
string[] paths = {}; string[] paths = {};
if (custom_path != null && custom_path.length > 0) { if (custom_path != null && custom_path.length > 0) {
// Replaces the home directory relative path with a absolute path // Replaces the home directory relative path with a absolute path
if (custom_path.get (0) == '~') { if (custom_path.get (0) == '~') {
custom_path = Environment.get_home_dir () + custom_path[1:]; custom_path = Environment.get_home_dir () + custom_path[1 :];
} }
paths += custom_path; paths += custom_path;
} }
...@@ -163,12 +165,12 @@ namespace SwayNotificationCenter { ...@@ -163,12 +165,12 @@ namespace SwayNotificationCenter {
return path; return path;
} }
public static string get_config_path (owned string ? custom_path) { public static string get_config_path (owned string ?custom_path) {
string[] paths = {}; string[] paths = {};
if (custom_path != null && (custom_path = custom_path.strip ()).length > 0) { if (custom_path != null && (custom_path = custom_path.strip ()).length > 0) {
// Replaces the home directory relative path with a absolute path // Replaces the home directory relative path with a absolute path
if (custom_path.get (0) == '~') { if (custom_path.get (0) == '~') {
custom_path = Environment.get_home_dir () + custom_path[1:]; custom_path = Environment.get_home_dir () + custom_path[1 :];
} }
if (File.new_for_path (custom_path).query_exists ()) { if (File.new_for_path (custom_path).query_exists ()) {
...@@ -280,13 +282,16 @@ namespace SwayNotificationCenter { ...@@ -280,13 +282,16 @@ namespace SwayNotificationCenter {
public static string filter_string (string body, FilterFunc func) { public static string filter_string (string body, FilterFunc func) {
string result = ""; string result = "";
foreach (char char in (char[]) body.data) { foreach (char char in (char[]) body.data) {
if (!func (char)) continue; if (!func (char)) {
continue;
}
result += char.to_string (); result += char.to_string ();
} }
return result; return result;
} }
public static async bool execute_command (string cmd, string[] env_additions = {}, out string msg) { public static async bool execute_command (string cmd, string[] env_additions = {},
out string msg) {
msg = ""; msg = "";
try { try {
string[] spawn_env = Environ.get (); string[] spawn_env = Environ.get ();
...@@ -298,8 +303,9 @@ namespace SwayNotificationCenter { ...@@ -298,8 +303,9 @@ namespace SwayNotificationCenter {
string[] argvp; string[] argvp;
Shell.parse_argv ("/bin/sh -c \"%s\"".printf (cmd), out argvp); Shell.parse_argv ("/bin/sh -c \"%s\"".printf (cmd), out argvp);
if (argvp[0].has_prefix ("~")) if (argvp[0].has_prefix ("~")) {
argvp[0] = Environment.get_home_dir () + argvp[0].substring (1); argvp[0] = Environment.get_home_dir () + argvp[0].substring (1);
}
Pid child_pid; Pid child_pid;
int std_output; int std_output;
...@@ -364,7 +370,7 @@ namespace SwayNotificationCenter { ...@@ -364,7 +370,7 @@ namespace SwayNotificationCenter {
error ("Only supports Wayland!"); error ("Only supports Wayland!");
} }
public static Wl.Surface * get_wl_surface (Gdk.Surface surface) { public static Wl.Surface *get_wl_surface (Gdk.Surface surface) {
if (surface is Gdk.Wayland.Surface) { if (surface is Gdk.Wayland.Surface) {
return ((Gdk.Wayland.Surface) surface).get_wl_surface (); return ((Gdk.Wayland.Surface) surface).get_wl_surface ();
} }
...@@ -375,14 +381,16 @@ namespace SwayNotificationCenter { ...@@ -375,14 +381,16 @@ namespace SwayNotificationCenter {
return a * (1.0 - t) + b * t; return a * (1.0 - t) + b * t;
} }
public static unowned Gdk.Monitor ? try_get_monitor (string name) { public static unowned Gdk.Monitor ?try_get_monitor (string name) {
if (name == null || name.length == 0) { if (name == null || name.length == 0) {
return null; return null;
} }
for (int i = 0; i < monitors.get_n_items (); i++) { for (int i = 0; i < monitors.get_n_items (); i++) {
Object ? obj = monitors.get_item (i); Object ?obj = monitors.get_item (i);
if (obj == null || !(obj is Gdk.Monitor)) continue; if (obj == null || !(obj is Gdk.Monitor)) {
continue;
}
unowned Gdk.Monitor monitor = (Gdk.Monitor) obj; unowned Gdk.Monitor monitor = (Gdk.Monitor) obj;
if (monitor.connector == name) { if (monitor.connector == name) {
......
namespace SwayNotificationCenter { namespace SwayNotificationCenter {
static SwayncDaemon swaync_daemon; static SwayncDaemon swaync_daemon;
static unowned ListModel ? monitors = null; static unowned ListModel ?monitors = null;
static Swaync app; static Swaync app;
static Settings self_settings; static Settings self_settings;
// Args // Args
static string ? style_path; static string ?style_path;
static string ? config_path; static string ?config_path;
// Dev args // Dev args
static bool skip_packaged_css = false; static bool skip_packaged_css = false;
static string ? custom_packaged_css; static string ?custom_packaged_css;
public class Swaync : Gtk.Application { public class Swaync : Gtk.Application {
static bool activated = false; static bool activated = false;
public signal void config_reload (ConfigModel ? old_config, ConfigModel new_config); public signal void config_reload (ConfigModel ?old_config, ConfigModel new_config);
public Swaync () { public Swaync () {
Object ( Object (
application_id: "org.erikreider.swaync", application_id : "org.erikreider.swaync",
flags: ApplicationFlags.DEFAULT_FLAGS flags: ApplicationFlags.DEFAULT_FLAGS
); );
...@@ -43,7 +42,7 @@ namespace SwayNotificationCenter { ...@@ -43,7 +42,7 @@ namespace SwayNotificationCenter {
hold (); hold ();
unowned Gdk.Display ? display = Gdk.Display.get_default (); unowned Gdk.Display ?display = Gdk.Display.get_default ();
if (display == null) { if (display == null) {
error ("Could not get Display!"); error ("Could not get Display!");
} }
...@@ -77,7 +76,7 @@ namespace SwayNotificationCenter { ...@@ -77,7 +76,7 @@ namespace SwayNotificationCenter {
for (uint i = 1; i < args.length; i++) { for (uint i = 1; i < args.length; i++) {
string arg = args[i]; string arg = args[i];
switch (arg) { switch (arg) {
case "-s": case "-s" :
case "--style": case "--style":
style_path = args[++i]; style_path = args[++i];
break; break;
...@@ -138,9 +137,9 @@ namespace SwayNotificationCenter { ...@@ -138,9 +137,9 @@ namespace SwayNotificationCenter {
print ("\t -s, --style \t\t Use a custom Stylesheet file\n"); print ("\t -s, --style \t\t Use a custom Stylesheet file\n");
print ("\t -c, --config \t\t Use a custom config file\n"); print ("\t -c, --config \t\t Use a custom config file\n");
print ("\t --skip-system-css \t Skip trying to parse the packaged Stylesheet file." print ("\t --skip-system-css \t Skip trying to parse the packaged Stylesheet file."
+ " Useful for CSS debugging\n"); + " Useful for CSS debugging\n");
print ("\t --custom-system-css \t Pick a custom CSS file to use as the \"system\" CSS." print ("\t --custom-system-css \t Pick a custom CSS file to use as the \"system\" CSS."
+ " Useful for CSS debugging\n"); + " Useful for CSS debugging\n");
} }
} }
} }
...@@ -18,7 +18,9 @@ namespace SwayNotificationCenter { ...@@ -18,7 +18,9 @@ namespace SwayNotificationCenter {
this.notify["dnd"].connect (() => on_dnd_toggle (dnd)); this.notify["dnd"].connect (() => on_dnd_toggle (dnd));
on_dnd_toggle.connect ((dnd) => { on_dnd_toggle.connect ((dnd) => {
if (!dnd || NotificationWindow.is_null) return; if (!dnd || NotificationWindow.is_null) {
return;
}
NotificationWindow.instance.close_all_notifications ((noti) => { NotificationWindow.instance.close_all_notifications ((noti) => {
return noti.param.urgency != UrgencyLevels.CRITICAL; return noti.param.urgency != UrgencyLevels.CRITICAL;
}); });
...@@ -83,8 +85,10 @@ namespace SwayNotificationCenter { ...@@ -83,8 +85,10 @@ namespace SwayNotificationCenter {
/** Closes latest popup notification */ /** Closes latest popup notification */
public void hide_latest_notification (bool close) public void hide_latest_notification (bool close)
throws DBusError, IOError { throws DBusError, IOError {
uint32 ? id = NotificationWindow.instance.get_latest_notification (); uint32 ?id = NotificationWindow.instance.get_latest_notification ();
if (id == null) return; if (id == null) {
return;
}
manually_close_notification (id, !close); manually_close_notification (id, !close);
} }
...@@ -152,7 +156,9 @@ namespace SwayNotificationCenter { ...@@ -152,7 +156,9 @@ namespace SwayNotificationCenter {
HashTable<string, Variant> hints, HashTable<string, Variant> hints,
int expire_timeout) throws DBusError, IOError { int expire_timeout) throws DBusError, IOError {
uint32 id = replaces_id; uint32 id = replaces_id;
if (replaces_id == 0 || replaces_id > noti_id) id = ++noti_id; if (replaces_id == 0 || replaces_id > noti_id) {
id = ++noti_id;
}
var param = new NotifyParams ( var param = new NotifyParams (
id, id,
...@@ -171,7 +177,9 @@ namespace SwayNotificationCenter { ...@@ -171,7 +177,9 @@ namespace SwayNotificationCenter {
ConfigModel.instance.notification_visibility; ConfigModel.instance.notification_visibility;
foreach (string key in visibilities.get_keys ()) { foreach (string key in visibilities.get_keys ()) {
unowned NotificationVisibility vis = visibilities[key]; unowned NotificationVisibility vis = visibilities[key];
if (!vis.matches_notification (param)) continue; if (!vis.matches_notification (param)) {
continue;
}
state = vis.state; state = vis.state;
if (vis.override_urgency != UNSET) { if (vis.override_urgency != UNSET) {
debug ("override urgency to %s\n", vis.override_urgency.to_string ()); debug ("override urgency to %s\n", vis.override_urgency.to_string ());
...@@ -181,7 +189,7 @@ namespace SwayNotificationCenter { ...@@ -181,7 +189,7 @@ namespace SwayNotificationCenter {
} }
debug ("Notification (ID:%u, state: %s): %s\n", debug ("Notification (ID:%u, state: %s): %s\n",
param.applied_id, state.to_string (), param.to_string ()); param.applied_id, state.to_string (), param.to_string ());
// Get the notification id to replace // Get the notification id to replace
uint32 replace_notification = 0; uint32 replace_notification = 0;
...@@ -199,11 +207,12 @@ namespace SwayNotificationCenter { ...@@ -199,11 +207,12 @@ namespace SwayNotificationCenter {
synchronous_ids.set (param.synchronous, id); synchronous_ids.set (param.synchronous, id);
} }
string ? hide_notification_reason = null; string ?hide_notification_reason = null;
bool show_notification = state == NotificationStatusEnum.ENABLED bool show_notification = state == NotificationStatusEnum.ENABLED
|| state == NotificationStatusEnum.TRANSIENT; || state == NotificationStatusEnum.TRANSIENT;
if (!show_notification) { if (!show_notification) {
hide_notification_reason = "Notification status is not Enabled or Transient in Config"; hide_notification_reason =
"Notification status is not Enabled or Transient in Config";
} }
// Don't show the notification window if the control center is open // Don't show the notification window if the control center is open
...@@ -231,19 +240,19 @@ namespace SwayNotificationCenter { ...@@ -231,19 +240,19 @@ namespace SwayNotificationCenter {
NotificationWindow.instance.close_notification (replace_notification, false); NotificationWindow.instance.close_notification (replace_notification, false);
} else { } else {
debug ("Not displaying Notification: ID:%u, Reason: \"%s\"\n", debug ("Not displaying Notification: ID:%u, Reason: \"%s\"\n",
param.applied_id, hide_notification_reason); param.applied_id, hide_notification_reason);
} }
// Only add notification to CC if it isn't IGNORED and not transient/TRANSIENT // Only add notification to CC if it isn't IGNORED and not transient/TRANSIENT
if (state != NotificationStatusEnum.IGNORED if (state != NotificationStatusEnum.IGNORED
&& state != NotificationStatusEnum.TRANSIENT && state != NotificationStatusEnum.TRANSIENT
&& !param.transient) { && !param.transient) {
if (replace_notification > 0) { if (replace_notification > 0) {
debug ("Replacing CC Notification: ID:%u\n", param.applied_id); debug ("Replacing CC Notification: ID:%u\n", param.applied_id);
control_center.replace_notification (replace_notification, param); control_center.replace_notification (replace_notification, param);
} else { } else {
control_center.add_notification (param); control_center.add_notification (param);
} }
} else if (replace_notification > 0) { } else if (replace_notification > 0) {
// Remove the old notification due to it not being replaced // Remove the old notification due to it not being replaced
control_center.close_notification (replace_notification, false); control_center.close_notification (replace_notification, false);
...@@ -258,7 +267,9 @@ namespace SwayNotificationCenter { ...@@ -258,7 +267,9 @@ namespace SwayNotificationCenter {
} }
// Run the first script if notification meets requirements // Run the first script if notification meets requirements
OrderedHashTable<Script> scripts = ConfigModel.instance.scripts; OrderedHashTable<Script> scripts = ConfigModel.instance.scripts;
if (scripts.length == 0) return id; if (scripts.length == 0) {
return id;
}
this.run_scripts (param, ScriptRunOnType.RECEIVE); this.run_scripts (param, ScriptRunOnType.RECEIVE);
#endif #endif
debug ("\n"); debug ("\n");
...@@ -277,16 +288,24 @@ namespace SwayNotificationCenter { ...@@ -277,16 +288,24 @@ namespace SwayNotificationCenter {
} }
// Run the first script if notification meets requirements // Run the first script if notification meets requirements
OrderedHashTable<Script> scripts = ConfigModel.instance.scripts; OrderedHashTable<Script> scripts = ConfigModel.instance.scripts;
if (scripts.length == 0) return; if (scripts.length == 0) {
return;
}
foreach (string key in scripts.get_keys ()) { foreach (string key in scripts.get_keys ()) {
unowned Script script = scripts[key]; unowned Script script = scripts[key];
if (!script.matches_notification (param)) continue; if (!script.matches_notification (param)) {
if (script.run_on != run_on) continue; continue;
}
if (script.run_on != run_on) {
continue;
}
script.run_script.begin (param, (obj, res) => { script.run_script.begin (param, (obj, res) => {
// Gets the end status // Gets the end status
string error_msg; string error_msg;
if (script.run_script.end (res, out error_msg)) return; if (script.run_script.end (res, out error_msg)) {
return;
}
if (!ConfigModel.instance.script_fail_notify) { if (!ConfigModel.instance.script_fail_notify) {
stderr.printf ( stderr.printf (
......
...@@ -62,7 +62,9 @@ namespace SwayNotificationCenter { ...@@ -62,7 +62,9 @@ namespace SwayNotificationCenter {
} }
public string to_string () { public string to_string () {
if (identifier == null || text == null) return "None"; if (identifier == null || text == null) {
return "None";
}
return "Name: %s, Id: %s".printf (text, identifier); return "Name: %s, Id: %s".printf (text, identifier);
} }
} }
...@@ -72,7 +74,7 @@ namespace SwayNotificationCenter { ...@@ -72,7 +74,7 @@ namespace SwayNotificationCenter {
public string app_name { get; set; } public string app_name { get; set; }
public uint32 replaces_id { get; set; } public uint32 replaces_id { get; set; }
public string app_icon { get; set; } public string app_icon { get; set; }
public Action ? default_action { get; set; } public Action ?default_action { get; set; }
public string summary { get; set; } public string summary { get; set; }
public string body { get; set; } public string body { get; set; }
public HashTable<string, Variant> hints { get; set; } public HashTable<string, Variant> hints { get; set; }
...@@ -131,7 +133,7 @@ namespace SwayNotificationCenter { ...@@ -131,7 +133,7 @@ namespace SwayNotificationCenter {
* - x-canonical-private-synchronous * - x-canonical-private-synchronous
* - synchronous * - synchronous
*/ */
public string ? synchronous { get; set; } public string ?synchronous { get; set; }
/** Used for notification progress bar (0->100) */ /** Used for notification progress bar (0->100) */
public int value { public int value {
get { get {
...@@ -145,8 +147,8 @@ namespace SwayNotificationCenter { ...@@ -145,8 +147,8 @@ namespace SwayNotificationCenter {
public bool has_synch { public get; private set; } public bool has_synch { public get; private set; }
/** Inline-replies */ /** Inline-replies */
public Action ? inline_reply { get; set; } public Action ?inline_reply { get; set; }
public string ? inline_reply_placeholder { get; set; } public string ?inline_reply_placeholder { get; set; }
// Custom hints // Custom hints
/** Disables scripting for notification */ /** Disables scripting for notification */
...@@ -157,7 +159,7 @@ namespace SwayNotificationCenter { ...@@ -157,7 +159,7 @@ namespace SwayNotificationCenter {
public Array<Action> actions { get; set; } public Array<Action> actions { get; set; }
public DesktopAppInfo ? desktop_app_info = null; public DesktopAppInfo ?desktop_app_info = null;
public string name_id; public string name_id;
...@@ -211,7 +213,7 @@ namespace SwayNotificationCenter { ...@@ -211,7 +213,7 @@ namespace SwayNotificationCenter {
this.name_id = this.desktop_entry ?? this.app_name ?? ""; this.name_id = this.desktop_entry ?? this.app_name ?? "";
// Set display_name // Set display_name
string ? display_name = this.desktop_entry ?? this.app_name; string ?display_name = this.desktop_entry ?? this.app_name;
if (desktop_app_info != null) { if (desktop_app_info != null) {
display_name = desktop_app_info.get_display_name (); display_name = desktop_app_info.get_display_name ();
} }
...@@ -225,21 +227,21 @@ namespace SwayNotificationCenter { ...@@ -225,21 +227,21 @@ namespace SwayNotificationCenter {
foreach (var hint in hints.get_keys ()) { foreach (var hint in hints.get_keys ()) {
Variant hint_value = hints[hint]; Variant hint_value = hints[hint];
switch (hint) { switch (hint) {
case "SWAYNC_NO_SCRIPT": case "SWAYNC_NO_SCRIPT" :
if (hint_value.is_of_type (VariantType.INT32)) { if (hint_value.is_of_type (VariantType.INT32)) {
swaync_no_script = hint_value.get_int32 () == 1; swaync_no_script = hint_value.get_int32 () == 1;
} else if (hint_value.is_of_type (VariantType.BOOLEAN)) { } else if (hint_value.is_of_type (VariantType.BOOLEAN)) {
swaync_no_script = hint_value.get_boolean (); swaync_no_script = hint_value.get_boolean ();
} }
break; break;
case "SWAYNC_BYPASS_DND": case "SWAYNC_BYPASS_DND" :
if (hint_value.is_of_type (VariantType.INT32)) { if (hint_value.is_of_type (VariantType.INT32)) {
swaync_bypass_dnd = hint_value.get_int32 () == 1; swaync_bypass_dnd = hint_value.get_int32 () == 1;
} else if (hint_value.is_of_type (VariantType.BOOLEAN)) { } else if (hint_value.is_of_type (VariantType.BOOLEAN)) {
swaync_bypass_dnd = hint_value.get_boolean (); swaync_bypass_dnd = hint_value.get_boolean ();
} }
break; break;
case "value": case "value" :
if (hint_value.is_of_type (VariantType.INT32)) { if (hint_value.is_of_type (VariantType.INT32)) {
this.has_synch = true; this.has_synch = true;
value = hint_value.get_int32 (); value = hint_value.get_int32 ();
...@@ -262,7 +264,9 @@ namespace SwayNotificationCenter { ...@@ -262,7 +264,9 @@ namespace SwayNotificationCenter {
case "image-data": case "image-data":
case "image_data": case "image_data":
case "icon_data": case "icon_data":
if (image_data.is_initialized) break; if (image_data.is_initialized) {
break;
}
var img_d = ImageData (); var img_d = ImageData ();
// Read each value // Read each value
// https://specifications.freedesktop.org/notification-spec/latest/ar01s05.html // https://specifications.freedesktop.org/notification-spec/latest/ar01s05.html
...@@ -439,7 +443,7 @@ namespace SwayNotificationCenter { ...@@ -439,7 +443,7 @@ namespace SwayNotificationCenter {
string[] result = {}; string[] result = {};
foreach (var k in params.get_keys ()) { foreach (var k in params.get_keys ()) {
string ? v = params[k]; string ?v = params[k];
result += "%s:\t\t %s".printf (k, v); result += "%s:\t\t %s".printf (k, v);
} }
return "\n" + string.joinv ("\n", result); return "\n" + string.joinv ("\n", result);
......
...@@ -130,7 +130,9 @@ namespace SwayNotificationCenter { ...@@ -130,7 +130,9 @@ namespace SwayNotificationCenter {
}); });
gesture.released.connect ((gesture, _n_press, _x, _y) => { gesture.released.connect ((gesture, _n_press, _x, _y) => {
// Emit released // Emit released
if (!gesture_down) return; if (!gesture_down) {
return;
}
gesture_down = false; gesture_down = false;
if (gesture_in) { if (gesture_in) {
bool single_noti = only_single_notification (); bool single_noti = only_single_notification ();
...@@ -141,14 +143,16 @@ namespace SwayNotificationCenter { ...@@ -141,14 +143,16 @@ namespace SwayNotificationCenter {
group.set_sensitive (single_noti || group.is_expanded); group.set_sensitive (single_noti || group.is_expanded);
} }
Gdk.EventSequence ? sequence = gesture.get_current_sequence (); Gdk.EventSequence ?sequence = gesture.get_current_sequence ();
if (sequence == null) { if (sequence == null) {
gesture_in = false; gesture_in = false;
} }
}); });
gesture.update.connect ((gesture, sequence) => { gesture.update.connect ((gesture, sequence) => {
Gtk.GestureSingle gesture_single = (Gtk.GestureSingle) gesture; Gtk.GestureSingle gesture_single = (Gtk.GestureSingle) gesture;
if (sequence != gesture_single.get_current_sequence ()) return; if (sequence != gesture_single.get_current_sequence ()) {
return;
}
int width = get_width (); int width = get_width ();
int height = get_height (); int height = get_height ();
...@@ -189,12 +193,14 @@ namespace SwayNotificationCenter { ...@@ -189,12 +193,14 @@ namespace SwayNotificationCenter {
} }
private void set_icon () { private void set_icon () {
if (is_empty ()) return; if (is_empty ()) {
return;
}
unowned Notification first = (Notification) group.widgets.first ().data; unowned Notification first = (Notification) group.widgets.first ().data;
unowned NotifyParams param = first.param; unowned NotifyParams param = first.param;
// Get the app icon // Get the app icon
Icon ? icon = null; Icon ?icon = null;
if (param.desktop_app_info != null if (param.desktop_app_info != null
&& (icon = param.desktop_app_info.get_icon ()) != null) { && (icon = param.desktop_app_info.get_icon ()) != null) {
app_icon.set_from_gicon (icon); app_icon.set_from_gicon (icon);
...@@ -254,12 +260,14 @@ namespace SwayNotificationCenter { ...@@ -254,12 +260,14 @@ namespace SwayNotificationCenter {
return group.widgets.copy (); return group.widgets.copy ();
} }
public unowned Notification ? get_latest_notification () { public unowned Notification ?get_latest_notification () {
return (Notification ?) group.widgets.last ().data; return (Notification ?) group.widgets.last ().data;
} }
public int64 get_time () { public int64 get_time () {
if (group.widgets.is_empty ()) return -1; if (group.widgets.is_empty ()) {
return -1;
}
return ((Notification) group.widgets.last ().data).param.time; return ((Notification) group.widgets.last ().data).param.time;
} }
...@@ -290,7 +298,9 @@ namespace SwayNotificationCenter { ...@@ -290,7 +298,9 @@ namespace SwayNotificationCenter {
set_icon (); set_icon ();
foreach (unowned Gtk.Widget widget in group.widgets) { foreach (unowned Gtk.Widget widget in group.widgets) {
var noti = (Notification) widget; var noti = (Notification) widget;
if (noti != null) noti.set_time (); if (noti != null) {
noti.set_time ();
}
} }
} }
...@@ -341,7 +351,9 @@ namespace SwayNotificationCenter { ...@@ -341,7 +351,9 @@ namespace SwayNotificationCenter {
} }
public void set_expanded (bool value) { public void set_expanded (bool value) {
if (is_expanded == value) return; if (is_expanded == value) {
return;
}
is_expanded = value; is_expanded = value;
animate (is_expanded ? 1 : 0); animate (is_expanded ? 1 : 0);
...@@ -413,18 +425,20 @@ namespace SwayNotificationCenter { ...@@ -413,18 +425,20 @@ namespace SwayNotificationCenter {
// TODO: Always use natural as minimum? // TODO: Always use natural as minimum?
// Fixes large (tall) Notification body Pictures // Fixes large (tall) Notification body Pictures
minimum = (int) Functions.lerp (minimum, minimum = (int) Functions.lerp (minimum,
target_natural_height, target_natural_height,
animation_progress_inv); animation_progress_inv);
natural = (int) Functions.lerp (natural, natural = (int) Functions.lerp (natural,
target_natural_height, target_natural_height,
animation_progress_inv); animation_progress_inv);
} }
protected override void size_allocate (int alloc_width, int alloc_height, int baseline) { protected override void size_allocate (int alloc_width, int alloc_height, int baseline) {
base.size_allocate (alloc_width, alloc_height, baseline); base.size_allocate (alloc_width, alloc_height, baseline);
int length = (int) widgets.length (); int length = (int) widgets.length ();
if (length == 0) return; if (length == 0) {
return;
}
Gtk.Allocation allocation = get_alloc (this); Gtk.Allocation allocation = get_alloc (this);
allocation.width = alloc_width; allocation.width = alloc_width;
...@@ -437,7 +451,8 @@ namespace SwayNotificationCenter { ...@@ -437,7 +451,8 @@ namespace SwayNotificationCenter {
unowned Gtk.Widget last = widgets.last ().data; unowned Gtk.Widget last = widgets.last ().data;
int target_height = 0; int target_height = 0;
last.measure (Gtk.Orientation.VERTICAL, allocation.width, null, out target_height, null, null); last.measure (Gtk.Orientation.VERTICAL, allocation.width, null, out target_height, null,
null);
for (int i = length - 1; i >= 0; i--) { for (int i = length - 1; i >= 0; i--) {
unowned Gtk.Widget widget = widgets.nth_data (i); unowned Gtk.Widget widget = widgets.nth_data (i);
...@@ -523,8 +538,8 @@ namespace SwayNotificationCenter { ...@@ -523,8 +538,8 @@ namespace SwayNotificationCenter {
animation_progress + Math.pow (0.95, length - 1 - i), 1); animation_progress + Math.pow (0.95, length - 1 - i), 1);
// Moves the scaled notification to the center of X and bottom y // Moves the scaled notification to the center of X and bottom y
snapshot.translate (Graphene.Point ().init ( snapshot.translate (Graphene.Point ().init (
(float) ((widget_alloc.width - width * scale) * 0.5), (float) ((widget_alloc.width - width * scale) * 0.5),
(float) (widget_alloc.height * (1 - scale)))); (float) (widget_alloc.height * (1 - scale))));
snapshot.scale ((float) scale, (float) scale); snapshot.scale ((float) scale, (float) scale);
} }
...@@ -547,15 +562,15 @@ namespace SwayNotificationCenter { ...@@ -547,15 +562,15 @@ namespace SwayNotificationCenter {
// cr.push_group (); // cr.push_group ();
// widget.draw (cr); // widget.draw (cr);
// if (i + 1 != length) { // if (i + 1 != length) {
// // Draw Fade Gradient //// Draw Fade Gradient
// cr.save (); // cr.save ();
// cr.translate (0, lerped_y); // cr.translate (0, lerped_y);
// cr.scale (1, lerped_height * 0.5); // cr.scale (1, lerped_height * 0.5);
// cr.set_source (fade_gradient); // cr.set_source (fade_gradient);
// cr.rectangle (0, 0, width, lerped_height * 0.5); // cr.rectangle (0, 0, width, lerped_height * 0.5);
// cr.set_operator (Cairo.Operator.DEST_OUT); // cr.set_operator (Cairo.Operator.DEST_OUT);
// cr.fill (); // cr.fill ();
// cr.restore (); // cr.restore ();
// } // }
// cr.pop_group_to_source (); // cr.pop_group_to_source ();
// cr.paint (); // cr.paint ();
......
namespace SwayNotificationCenter { namespace SwayNotificationCenter {
[GtkTemplate (ui = "/org/erikreider/swaync/ui/notification_window.ui")] [GtkTemplate (ui = "/org/erikreider/swaync/ui/notification_window.ui")]
public class NotificationWindow : Gtk.ApplicationWindow { public class NotificationWindow : Gtk.ApplicationWindow {
private static NotificationWindow ? window = null; private static NotificationWindow ?window = null;
/** /**
* A NotificationWindow singleton due to a nasty notification * A NotificationWindow singleton due to a nasty notification
* enter_notify_event bug where GTK still thinks that the cursor is at * enter_notify_event bug where GTK still thinks that the cursor is at
...@@ -38,12 +38,12 @@ namespace SwayNotificationCenter { ...@@ -38,12 +38,12 @@ namespace SwayNotificationCenter {
Gee.HashSet<uint32> inline_reply_notifications = new Gee.HashSet<uint32> (); Gee.HashSet<uint32> inline_reply_notifications = new Gee.HashSet<uint32> ();
private static string ? monitor_name = null; private static string ?monitor_name = null;
private const int MAX_HEIGHT = 600; private const int MAX_HEIGHT = 600;
private NotificationWindow () { private NotificationWindow () {
Object (css_name: "notificationwindow"); Object (css_name : "notificationwindow");
if (swaync_daemon.use_layer_shell) { if (swaync_daemon.use_layer_shell) {
if (!GtkLayerShell.is_supported ()) { if (!GtkLayerShell.is_supported ()) {
stderr.printf ("GTKLAYERSHELL IS NOT SUPPORTED!\n"); stderr.printf ("GTKLAYERSHELL IS NOT SUPPORTED!\n");
...@@ -147,7 +147,7 @@ namespace SwayNotificationCenter { ...@@ -147,7 +147,7 @@ namespace SwayNotificationCenter {
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, true); GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, true);
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, true); GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, true);
switch (ConfigModel.instance.positionX) { switch (ConfigModel.instance.positionX) {
case PositionX.LEFT: case PositionX.LEFT :
GtkLayerShell.set_anchor ( GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.RIGHT, false); this, GtkLayerShell.Edge.RIGHT, false);
GtkLayerShell.set_anchor ( GtkLayerShell.set_anchor (
...@@ -190,7 +190,8 @@ namespace SwayNotificationCenter { ...@@ -190,7 +190,8 @@ namespace SwayNotificationCenter {
break; break;
default: default:
case PositionX.RIGHT: case PositionX.RIGHT:
list.animation_child_type = AnimatedListItem.ChildAnimationType.SLIDE_FROM_RIGHT; list.animation_child_type =
AnimatedListItem.ChildAnimationType.SLIDE_FROM_RIGHT;
break; break;
} }
switch (ConfigModel.instance.positionY) { switch (ConfigModel.instance.positionY) {
...@@ -205,7 +206,7 @@ namespace SwayNotificationCenter { ...@@ -205,7 +206,7 @@ namespace SwayNotificationCenter {
} }
// Set the preferred monitor // Set the preferred monitor
string ? monitor_name = ConfigModel.instance.notification_window_preferred_output; string ?monitor_name = ConfigModel.instance.notification_window_preferred_output;
if (NotificationWindow.monitor_name != null) { if (NotificationWindow.monitor_name != null) {
monitor_name = NotificationWindow.monitor_name; monitor_name = NotificationWindow.monitor_name;
} }
...@@ -224,9 +225,11 @@ namespace SwayNotificationCenter { ...@@ -224,9 +225,11 @@ namespace SwayNotificationCenter {
public delegate bool remove_iter_func (Notification notification); public delegate bool remove_iter_func (Notification notification);
/** Hides all notifications. Only invokes the close action when transient */ /** Hides all notifications. Only invokes the close action when transient */
public void close_all_notifications (remove_iter_func ? func = null) { public void close_all_notifications (remove_iter_func ?func = null) {
inline_reply_notifications.clear (); inline_reply_notifications.clear ();
if (!this.get_realized ()) return; if (!this.get_realized ()) {
return;
}
foreach (unowned AnimatedListItem item in list.children) { foreach (unowned AnimatedListItem item in list.children) {
if (item.destroying) { if (item.destroying) {
continue; continue;
...@@ -240,7 +243,7 @@ namespace SwayNotificationCenter { ...@@ -240,7 +243,7 @@ namespace SwayNotificationCenter {
close (); close ();
} }
private void remove_notification (Notification ? noti, private void remove_notification (Notification ?noti,
bool dismiss, bool dismiss,
bool transition) { bool transition) {
// Remove notification and its destruction timeout // Remove notification and its destruction timeout
...@@ -330,8 +333,8 @@ namespace SwayNotificationCenter { ...@@ -330,8 +333,8 @@ namespace SwayNotificationCenter {
add_notification (new_params); add_notification (new_params);
} }
public uint32 ? get_latest_notification () { public uint32 ?get_latest_notification () {
unowned AnimatedListItem ? item = list.get_first_item (); unowned AnimatedListItem ?item = list.get_first_item ();
if (item == null || !(item.child is Notification)) { if (item == null || !(item.child is Notification)) {
return null; return null;
} }
...@@ -341,7 +344,7 @@ namespace SwayNotificationCenter { ...@@ -341,7 +344,7 @@ namespace SwayNotificationCenter {
} }
public void latest_notification_action (uint32 action) { public void latest_notification_action (uint32 action) {
unowned AnimatedListItem ? item = list.get_first_item (); unowned AnimatedListItem ?item = list.get_first_item ();
if (item == null || !(item.child is Notification)) { if (item == null || !(item.child is Notification)) {
return; return;
} }
...@@ -351,7 +354,7 @@ namespace SwayNotificationCenter { ...@@ -351,7 +354,7 @@ namespace SwayNotificationCenter {
noti.close_notification (); noti.close_notification ();
} }
public void set_monitor (Gdk.Monitor ? monitor) { public void set_monitor (Gdk.Monitor ?monitor) {
NotificationWindow.monitor_name = monitor == null ? null : monitor.connector; NotificationWindow.monitor_name = monitor == null ? null : monitor.connector;
GtkLayerShell.set_monitor (this, monitor); GtkLayerShell.set_monitor (this, monitor);
} }
......
namespace SwayNotificationCenter { namespace SwayNotificationCenter {
/** A regular GLib HashTable but preserves the order of inserted keys and values */ /** A regular GLib HashTable but preserves the order of inserted keys and values */
public class OrderedHashTable<T> { public class OrderedHashTable<T> {
private HashTable<string, T> hash_table; private HashTable<string, T> hash_table;
private List<string> order; private List<string> order;
...@@ -31,7 +30,8 @@ namespace SwayNotificationCenter { ...@@ -31,7 +30,8 @@ namespace SwayNotificationCenter {
return order.copy (); return order.copy ();
} }
public bool lookup_extended (string lookup_key, out unowned string orig_key, out unowned T value) { public bool lookup_extended (string lookup_key, out unowned string orig_key,
out unowned T value) {
return hash_table.lookup_extended (lookup_key, out orig_key, out value); return hash_table.lookup_extended (lookup_key, out orig_key, out value);
} }
} }
......
...@@ -27,7 +27,8 @@ namespace SwayNotificationCenter { ...@@ -27,7 +27,8 @@ namespace SwayNotificationCenter {
public SwayncDaemon () { public SwayncDaemon () {
// Init noti_daemon // Init noti_daemon
this.use_layer_shell = ConfigModel.instance.layer_shell; this.use_layer_shell = ConfigModel.instance.layer_shell;
this.has_layer_on_demand = use_layer_shell && GtkLayerShell.get_protocol_version () >= 4; this.has_layer_on_demand = use_layer_shell &&
GtkLayerShell.get_protocol_version () >= 4;
this.noti_daemon = new NotiDaemon (this); this.noti_daemon = new NotiDaemon (this);
this.xdg_activation = new XdgActivationHelper (); this.xdg_activation = new XdgActivationHelper ();
Bus.own_name (BusType.SESSION, "org.freedesktop.Notifications", Bus.own_name (BusType.SESSION, "org.freedesktop.Notifications",
...@@ -45,9 +46,9 @@ namespace SwayNotificationCenter { ...@@ -45,9 +46,9 @@ namespace SwayNotificationCenter {
noti_daemon.on_dnd_toggle.connect ((dnd) => { noti_daemon.on_dnd_toggle.connect ((dnd) => {
try { try {
subscribe_v2 (noti_daemon.control_center.notification_count (), subscribe_v2 (noti_daemon.control_center.notification_count (),
dnd, dnd,
get_visibility (), get_visibility (),
inhibited); inhibited);
} catch (Error e) { } catch (Error e) {
stderr.printf (e.message + "\n"); stderr.printf (e.message + "\n");
} }
...@@ -56,9 +57,9 @@ namespace SwayNotificationCenter { ...@@ -56,9 +57,9 @@ namespace SwayNotificationCenter {
// Update on start // Update on start
try { try {
subscribe_v2 (notification_count (), subscribe_v2 (notification_count (),
get_dnd (), get_dnd (),
get_visibility (), get_visibility (),
inhibited); inhibited);
} catch (Error e) { } catch (Error e) {
stderr.printf (e.message + "\n"); stderr.printf (e.message + "\n");
} }
...@@ -105,7 +106,7 @@ namespace SwayNotificationCenter { ...@@ -105,7 +106,7 @@ namespace SwayNotificationCenter {
} }
[DBus (visible = false)] [DBus (visible = false)]
public void show_blank_windows (Gdk.Monitor ? ref_monitor) { public void show_blank_windows (Gdk.Monitor ?ref_monitor) {
if (!use_layer_shell || !ConfigModel.instance.layer_shell_cover_screen) { if (!use_layer_shell || !ConfigModel.instance.layer_shell_cover_screen) {
return; return;
} }
...@@ -118,7 +119,9 @@ namespace SwayNotificationCenter { ...@@ -118,7 +119,9 @@ namespace SwayNotificationCenter {
[DBus (visible = false)] [DBus (visible = false)]
public void hide_blank_windows () { public void hide_blank_windows () {
if (!use_layer_shell) return; if (!use_layer_shell) {
return;
}
foreach (unowned BlankWindow win in blank_windows.data) { foreach (unowned BlankWindow win in blank_windows.data) {
win.hide (); win.hide ();
} }
...@@ -175,7 +178,7 @@ namespace SwayNotificationCenter { ...@@ -175,7 +178,7 @@ namespace SwayNotificationCenter {
public void change_config_value (string name, public void change_config_value (string name,
Variant value, Variant value,
bool write_to_file = true, bool write_to_file = true,
string ? path = null) throws Error { string ?path = null) throws Error {
ConfigModel.instance.change_value (name, ConfigModel.instance.change_value (name,
value, value,
write_to_file, write_to_file,
...@@ -219,7 +222,9 @@ namespace SwayNotificationCenter { ...@@ -219,7 +222,9 @@ namespace SwayNotificationCenter {
/** Sets the visibility of the controlcenter */ /** Sets the visibility of the controlcenter */
public void set_visibility (bool visibility) throws DBusError, IOError { public void set_visibility (bool visibility) throws DBusError, IOError {
noti_daemon.control_center.set_visibility (visibility); noti_daemon.control_center.set_visibility (visibility);
if (visibility) noti_daemon.set_noti_window_visibility (false); if (visibility) {
noti_daemon.set_noti_window_visibility (false);
}
} }
/** Toggles the current Do Not Disturb state */ /** Toggles the current Do Not Disturb state */
...@@ -255,14 +260,16 @@ namespace SwayNotificationCenter { ...@@ -255,14 +260,16 @@ namespace SwayNotificationCenter {
* @return false if the `application_id` already exists, otherwise true. * @return false if the `application_id` already exists, otherwise true.
*/ */
public bool add_inhibitor (string application_id) throws DBusError, IOError { public bool add_inhibitor (string application_id) throws DBusError, IOError {
if (inhibitors.contains (application_id)) return false; if (inhibitors.contains (application_id)) {
return false;
}
inhibitors.add (application_id); inhibitors.add (application_id);
inhibited = inhibitors.length > 0; inhibited = inhibitors.length > 0;
inhibited_changed (inhibitors.length); inhibited_changed (inhibitors.length);
subscribe_v2 (noti_daemon.control_center.notification_count (), subscribe_v2 (noti_daemon.control_center.notification_count (),
noti_daemon.dnd, noti_daemon.dnd,
get_visibility (), get_visibility (),
inhibited); inhibited);
return true; return true;
} }
...@@ -273,13 +280,15 @@ namespace SwayNotificationCenter { ...@@ -273,13 +280,15 @@ namespace SwayNotificationCenter {
* @return false if the `application_id` doesn't exist, otherwise true * @return false if the `application_id` doesn't exist, otherwise true
*/ */
public bool remove_inhibitor (string application_id) throws DBusError, IOError { public bool remove_inhibitor (string application_id) throws DBusError, IOError {
if (!inhibitors.remove (application_id)) return false; if (!inhibitors.remove (application_id)) {
return false;
}
inhibited = inhibitors.length > 0; inhibited = inhibitors.length > 0;
inhibited_changed (inhibitors.length); inhibited_changed (inhibitors.length);
subscribe_v2 (noti_daemon.control_center.notification_count (), subscribe_v2 (noti_daemon.control_center.notification_count (),
noti_daemon.dnd, noti_daemon.dnd,
get_visibility (), get_visibility (),
inhibited); inhibited);
return true; return true;
} }
...@@ -295,19 +304,21 @@ namespace SwayNotificationCenter { ...@@ -295,19 +304,21 @@ namespace SwayNotificationCenter {
/** Clear all inhibitors */ /** Clear all inhibitors */
public bool clear_inhibitors () throws DBusError, IOError { public bool clear_inhibitors () throws DBusError, IOError {
if (inhibitors.length == 0) return false; if (inhibitors.length == 0) {
return false;
}
inhibitors.remove_all (); inhibitors.remove_all ();
inhibited = false; inhibited = false;
inhibited_changed (0); inhibited_changed (0);
subscribe_v2 (noti_daemon.control_center.notification_count (), subscribe_v2 (noti_daemon.control_center.notification_count (),
noti_daemon.dnd, noti_daemon.dnd,
get_visibility (), get_visibility (),
inhibited); inhibited);
return true; return true;
} }
public bool set_cc_monitor (string name) throws DBusError, IOError { public bool set_cc_monitor (string name) throws DBusError, IOError {
unowned Gdk.Monitor ? monitor = Functions.try_get_monitor (name); unowned Gdk.Monitor ?monitor = Functions.try_get_monitor (name);
if (monitor == null) { if (monitor == null) {
return false; return false;
} }
...@@ -317,7 +328,7 @@ namespace SwayNotificationCenter { ...@@ -317,7 +328,7 @@ namespace SwayNotificationCenter {
} }
public bool set_noti_window_monitor (string name) throws DBusError, IOError { public bool set_noti_window_monitor (string name) throws DBusError, IOError {
unowned Gdk.Monitor ? monitor = Functions.try_get_monitor (name); unowned Gdk.Monitor ?monitor = Functions.try_get_monitor (name);
if (monitor == null) { if (monitor == null) {
return false; return false;
} }
......
using XDG.Activation;
using SwayNotificationCenter; using SwayNotificationCenter;
using XDG.Activation;
public class XdgActivationHelper : Object { public class XdgActivationHelper : Object {
private static Wl.RegistryListener registry_listener = Wl.RegistryListener () { private static Wl.RegistryListener registry_listener = Wl.RegistryListener () {
global = registry_handle_global, global = registry_handle_global,
}; };
private Activation * xdg_activation = null; private Activation *xdg_activation = null;
public XdgActivationHelper () { public XdgActivationHelper () {
unowned Wl.Display wl_display = Functions.get_wl_display (); unowned Wl.Display wl_display = Functions.get_wl_display ();
...@@ -33,9 +33,9 @@ public class XdgActivationHelper : Object { ...@@ -33,9 +33,9 @@ public class XdgActivationHelper : Object {
} }
} }
private static void handle_done (void * data, Token activation_token, private static void handle_done (void *data, Token activation_token,
string token) { string token) {
Value * value = (Value *) data; Value *value = (Value *) data;
value->set_string (token.dup ()); value->set_string (token.dup ());
} }
...@@ -43,13 +43,13 @@ public class XdgActivationHelper : Object { ...@@ -43,13 +43,13 @@ public class XdgActivationHelper : Object {
handle_done, handle_done,
}; };
public string ? get_token (Gtk.Widget widget) { public string ?get_token (Gtk.Widget widget) {
if (xdg_activation == null) { if (xdg_activation == null) {
return null; return null;
} }
unowned Wl.Display wl_display = Functions.get_wl_display (); unowned Wl.Display wl_display = Functions.get_wl_display ();
unowned Gtk.Root ? root = widget.get_root (); unowned Gtk.Root ?root = widget.get_root ();
if (root == null) { if (root == null) {
warning ("GDK Window is null"); warning ("GDK Window is null");
return null; return null;
...@@ -59,7 +59,7 @@ public class XdgActivationHelper : Object { ...@@ -59,7 +59,7 @@ public class XdgActivationHelper : Object {
Value token_value = Value (typeof (string)); Value token_value = Value (typeof (string));
token_value.set_string (null); token_value.set_string (null);
Token * token = xdg_activation->get_activation_token (); Token *token = xdg_activation->get_activation_token ();
token->add_listener (TOKEN_LISTENER, &token_value); token->add_listener (TOKEN_LISTENER, &token_value);
token->set_surface (wl_surface); token->set_surface (wl_surface);
token->commit (); token->commit ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment