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