All *.vala files now 80 chars wide

This commit is contained in:
Erik Reider
2021-10-13 23:03:50 +02:00
parent ababdd9807
commit 37ea6c61ae
8 changed files with 116 additions and 57 deletions

View File

@@ -92,7 +92,8 @@ public int command_line (string[] args) {
} }
void print_connection_error () { void print_connection_error () {
stderr.printf ("Could not connect to CC service. Will wait for connection...\n"); stderr.printf (
"Could not connect to CC service. Will wait for connection...\n");
} }
int try_connect (string[] args) { int try_connect (string[] args) {
@@ -115,11 +116,14 @@ int try_connect (string[] args) {
public int main (string[] args) { public int main (string[] args) {
if (try_connect (args) == 1) { if (try_connect (args) == 1) {
MainLoop loop = new MainLoop (); MainLoop loop = new MainLoop ();
Bus.watch_name (BusType.SESSION, Bus.watch_name (
"org.erikreider.swaync.cc", BusType.SESSION,
GLib.BusNameWatcherFlags.NONE, "org.erikreider.swaync.cc",
(conn, name, name_owner) => { if (try_connect (args) == 0) loop.quit (); }, GLib.BusNameWatcherFlags.NONE,
null); (conn, name, name_owner) => {
if (try_connect (args) == 0) loop.quit ();
},
null);
loop.run (); loop.run ();
} }
return 0; return 0;

View File

@@ -54,7 +54,8 @@ namespace SwayNotificatonCenter {
modify_cb (node); modify_cb (node);
ConfigModel model = Json.gobject_deserialize (typeof (ConfigModel), node) as ConfigModel; ConfigModel model = Json.gobject_deserialize (
typeof (ConfigModel), node) as ConfigModel;
if (model == null) { if (model == null) {
throw new Json.ParserError.UNKNOWN ("Json model is null!"); throw new Json.ParserError.UNKNOWN ("Json model is null!");
} }
@@ -180,9 +181,10 @@ namespace SwayNotificatonCenter {
try { try {
if (path == null) { if (path == null) {
// Use the default user accessable config // Use the default user accessable config
string dir_path = Path.build_path (Path.DIR_SEPARATOR.to_string (), string dir_path = Path.build_path (
GLib.Environment.get_user_config_dir (), Path.DIR_SEPARATOR.to_string (),
"swaync"); Environment.get_user_config_dir (),
"swaync");
path = Path.build_path (Path.DIR_SEPARATOR.to_string (), path = Path.build_path (Path.DIR_SEPARATOR.to_string (),
dir_path, "config.json"); dir_path, "config.json");
var dir = File.new_for_path (dir_path); var dir = File.new_for_path (dir_path);
@@ -191,18 +193,19 @@ namespace SwayNotificatonCenter {
} }
var file = File.new_for_path (path); var file = File.new_for_path (path);
if (!file.query_exists ()) { if (!file.query_exists ()) {
file.create (GLib.FileCreateFlags.NONE); file.create (FileCreateFlags.NONE);
} }
} }
var file = File.new_for_path (path); var file = File.new_for_path (path);
string data = ConfigModel.instance.json_serialized (); string data = ConfigModel.instance.json_serialized ();
return file.replace_contents (data.data, return file.replace_contents (
null, data.data,
false, null,
GLib.FileCreateFlags.REPLACE_DESTINATION, false,
null); FileCreateFlags.REPLACE_DESTINATION,
null);
} catch (Error e) { } catch (Error e) {
stderr.printf (e.message + "\n"); stderr.printf (e.message + "\n");
return false; return false;

View File

@@ -72,7 +72,8 @@ namespace SwayNotificatonCenter {
return dbusInit.notiDaemon.get_dnd (); return dbusInit.notiDaemon.get_dnd ();
} }
public void add_notification (NotifyParams param) throws DBusError, IOError { public void add_notification (NotifyParams param)
throws DBusError, IOError {
cc.add_notification (param, dbusInit.notiDaemon); cc.add_notification (param, dbusInit.notiDaemon);
} }
@@ -177,9 +178,12 @@ namespace SwayNotificatonCenter {
}); });
clear_all_button = new Gtk.Button.with_label ("Clear All"); clear_all_button = new Gtk.Button.with_label ("Clear All");
clear_all_button.get_style_context ().add_class ("control-center-clear-all"); clear_all_button.get_style_context ().add_class (
"control-center-clear-all");
clear_all_button.clicked.connect (close_all_notifications); clear_all_button.clicked.connect (close_all_notifications);
this.box.add (new TopAction ("Notifications", clear_all_button, true)); this.box.add (new TopAction ("Notifications",
clear_all_button,
true));
dnd_button = new Gtk.Switch (); dnd_button = new Gtk.Switch ();
dnd_button.get_style_context ().add_class ("control-center-dnd"); dnd_button.get_style_context ().add_class ("control-center-dnd");
@@ -199,7 +203,7 @@ namespace SwayNotificatonCenter {
// 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;
#if HAVE_LATEST_GTK_LAYER_SHELL #if HAVE_LATEST_GTK_LAYER_SHELL
GtkLayerShell.KeyboardMode 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);
@@ -212,24 +216,34 @@ namespace SwayNotificatonCenter {
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, true); GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, true);
switch (ConfigModel.instance.positionX) { switch (ConfigModel.instance.positionX) {
case PositionX.LEFT: case PositionX.LEFT:
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, false); GtkLayerShell.set_anchor (this,
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, true); GtkLayerShell.Edge.RIGHT,
false);
GtkLayerShell.set_anchor (this,
GtkLayerShell.Edge.LEFT,
true);
break; break;
default: default:
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, false); GtkLayerShell.set_anchor (this,
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true); GtkLayerShell.Edge.LEFT,
false);
GtkLayerShell.set_anchor (this,
GtkLayerShell.Edge.RIGHT,
true);
break; break;
} }
switch (ConfigModel.instance.positionY) { switch (ConfigModel.instance.positionY) {
case PositionY.BOTTOM: case PositionY.BOTTOM:
list_reverse = true; list_reverse = true;
list_align = Gtk.Align.END; list_align = Gtk.Align.END;
this.box.set_child_packing (scrolled_window, true, true, 0, Gtk.PackType.START); this.box.set_child_packing (
scrolled_window, true, true, 0, Gtk.PackType.START);
break; break;
case PositionY.TOP: case PositionY.TOP:
list_reverse = false; list_reverse = false;
list_align = Gtk.Align.START; list_align = Gtk.Align.START;
this.box.set_child_packing (scrolled_window, true, true, 0, Gtk.PackType.END); this.box.set_child_packing (
scrolled_window, true, true, 0, Gtk.PackType.END);
break; break;
} }
@@ -260,7 +274,8 @@ namespace SwayNotificatonCenter {
list_position = 0; list_position = 0;
if (reverse) { if (reverse) {
val = adj.get_upper (); val = adj.get_upper ();
list_position = list_reverse ? (list_box.get_children ().length () - 1) : 0; list_position = list_reverse ?
(list_box.get_children ().length () - 1) : 0;
if (list_position == uint.MAX) list_position = -1; if (list_position == uint.MAX) list_position = -1;
} }
adj.set_value (val); adj.set_value (val);
@@ -277,7 +292,8 @@ namespace SwayNotificatonCenter {
} }
try { try {
cc_daemon.subscribe (notification_count (), cc_daemon.get_dnd ()); cc_daemon.subscribe (
notification_count (), cc_daemon.get_dnd ());
} catch (Error e) { } catch (Error e) {
stderr.printf (e.message + "\n"); stderr.printf (e.message + "\n");
} }
@@ -303,7 +319,8 @@ namespace SwayNotificatonCenter {
// Reload the settings from config // Reload the settings from config
this.set_anchor (); this.set_anchor ();
// Focus the first notification // Focus the first notification
list_position = list_reverse ? (list_box.get_children ().length () - 1) : 0; list_position = list_reverse ?
(list_box.get_children ().length () - 1) : 0;
if (list_position == uint.MAX) list_position = 0; if (list_position == uint.MAX) list_position = 0;
list_box.grab_focus (); list_box.grab_focus ();
@@ -325,13 +342,15 @@ namespace SwayNotificatonCenter {
} }
} }
try { try {
cc_daemon.subscribe (notification_count (), cc_daemon.get_dnd ()); cc_daemon.subscribe (
notification_count (), cc_daemon.get_dnd ());
} catch (Error e) { } catch (Error e) {
stderr.printf (e.message + "\n"); stderr.printf (e.message + "\n");
} }
} }
public void add_notification (NotifyParams param, NotiDaemon notiDaemon) { public void add_notification (NotifyParams param,
NotiDaemon notiDaemon) {
var noti = new Notification (param, notiDaemon); var noti = new Notification (param, notiDaemon);
noti.grab_focus.connect ((w) => { noti.grab_focus.connect ((w) => {
uint i = list_box.get_children ().index (w); uint i = list_box.get_children ().index (w);
@@ -343,7 +362,8 @@ namespace SwayNotificatonCenter {
list_box.add (noti); list_box.add (noti);
scroll_to_start (list_reverse); scroll_to_start (list_reverse);
try { try {
cc_daemon.subscribe (notification_count (), cc_daemon.get_dnd ()); cc_daemon.subscribe (
notification_count (), cc_daemon.get_dnd ());
} catch (Error e) { } catch (Error e) {
stderr.printf (e.message + "\n"); stderr.printf (e.message + "\n");
} }

View File

@@ -5,7 +5,9 @@ namespace SwayNotificatonCenter {
[GtkChild] [GtkChild]
unowned Gtk.Label title; unowned Gtk.Label title;
public TopAction (string title_text, Gtk.Widget action, bool is_title = false) { public TopAction (string title_text,
Gtk.Widget action,
bool is_title = false) {
this.title.set_text (title_text); this.title.set_text (title_text);
var attr = new Pango.AttrList (); var attr = new Pango.AttrList ();
if (is_title) attr.insert (new Pango.AttrSize (16000)); if (is_title) attr.insert (new Pango.AttrSize (16000));

View File

@@ -1,6 +1,8 @@
namespace SwayNotificatonCenter { namespace SwayNotificatonCenter {
public class Functions { public class Functions {
public static void set_image_path (owned string path, Gtk.Image img, bool file_exists) { public static void set_image_path (owned string path,
Gtk.Image img,
bool file_exists) {
if (path.slice (0, 7) == "file://" || file_exists) { if (path.slice (0, 7) == "file://" || file_exists) {
try { try {
if (!file_exists) path = path.slice (7, path.length); if (!file_exists) path = path.slice (7, path.length);
@@ -17,10 +19,16 @@ namespace SwayNotificatonCenter {
public static void set_image_data (Image_Data data, Gtk.Image img) { public static void set_image_data (Image_Data data, Gtk.Image img) {
// Rebuild and scale the image // Rebuild and scale the image
var pixbuf = new Gdk.Pixbuf.with_unowned_data (data.data, Gdk.Colorspace.RGB, var pixbuf = new Gdk.Pixbuf.with_unowned_data (data.data,
data.has_alpha, data.bits_per_sample, Gdk.Colorspace.RGB,
data.width, data.height, data.rowstride, null); data.has_alpha,
var scaled_pixbuf = pixbuf.scale_simple (64, 64, Gdk.InterpType.BILINEAR); data.bits_per_sample,
data.width,
data.height,
data.rowstride,
null);
var scaled_pixbuf = pixbuf.scale_simple (64, 64,
Gdk.InterpType.BILINEAR);
img.set_from_pixbuf (scaled_pixbuf); img.set_from_pixbuf (scaled_pixbuf);
} }
@@ -44,7 +52,8 @@ namespace SwayNotificatonCenter {
} }
} }
if (path == "") { if (path == "") {
stderr.printf ("COULD NOT FIND CSS FILE! REINSTALL THE PACKAGE!\n"); stderr.printf (
"COULD NOT FIND CSS FILE! REINSTALL THE PACKAGE!\n");
Process.exit (1); Process.exit (1);
} }
return path; return path;
@@ -69,7 +78,8 @@ namespace SwayNotificatonCenter {
} }
} }
if (path == "") { if (path == "") {
stderr.printf ("COULD NOT FIND CONFIG FILE! REINSTALL THE PACKAGE!\n"); stderr.printf (
"COULD NOT FIND CONFIG FILE! REINSTALL THE PACKAGE!\n");
Process.exit (1); Process.exit (1);
} }
return path; return path;

View File

@@ -13,19 +13,24 @@ namespace SwayNotificatonCenter {
BusNameOwnerFlags.NONE, BusNameOwnerFlags.NONE,
on_noti_bus_aquired, on_noti_bus_aquired,
() => {}, () => {},
() => stderr.printf ("Could not aquire notification name. Please close any other notification daemon like mako or dunst\n")); () => stderr.printf (
"Could not aquire notification name. " +
"Please close any other notification daemon " +
"like mako or dunst\n"));
Bus.own_name (BusType.SESSION, "org.erikreider.swaync.cc", Bus.own_name (BusType.SESSION, "org.erikreider.swaync.cc",
BusNameOwnerFlags.NONE, BusNameOwnerFlags.NONE,
on_cc_bus_aquired, on_cc_bus_aquired,
() => {}, () => {},
() => stderr.printf ("Could not aquire control center name\n")); () => stderr.printf (
"Could not aquire control center name\n"));
} }
void on_noti_bus_aquired (DBusConnection conn) { void on_noti_bus_aquired (DBusConnection conn) {
try { try {
conn.register_object ("/org/freedesktop/Notifications", notiDaemon); conn.register_object (
"/org/freedesktop/Notifications", notiDaemon);
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("Could not register notification service\n"); stderr.printf ("Could not register notification service\n");
} }

View File

@@ -32,24 +32,32 @@ namespace SwayNotificatonCenter {
private void set_anchor () { private void set_anchor () {
switch (ConfigModel.instance.positionX) { switch (ConfigModel.instance.positionX) {
case PositionX.LEFT: case PositionX.LEFT:
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, false); GtkLayerShell.set_anchor (
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, true); this, GtkLayerShell.Edge.RIGHT, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.LEFT, true);
break; break;
default: default:
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.LEFT, false); GtkLayerShell.set_anchor (
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true); this, GtkLayerShell.Edge.LEFT, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.RIGHT, true);
break; break;
} }
switch (ConfigModel.instance.positionY) { switch (ConfigModel.instance.positionY) {
case PositionY.BOTTOM: case PositionY.BOTTOM:
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, false); GtkLayerShell.set_anchor (
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, true); this, GtkLayerShell.Edge.TOP, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.BOTTOM, true);
list_reverse = true; list_reverse = true;
break; break;
case PositionY.TOP: case PositionY.TOP:
list_reverse = false; list_reverse = false;
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.BOTTOM, false); GtkLayerShell.set_anchor (
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.TOP, true); this, GtkLayerShell.Edge.BOTTOM, false);
GtkLayerShell.set_anchor (
this, GtkLayerShell.Edge.TOP, true);
break; break;
} }
} }
@@ -101,7 +109,8 @@ namespace SwayNotificatonCenter {
} }
} }
public void add_notification (NotifyParams param, NotiDaemon notiDaemon) { public void add_notification (NotifyParams param,
NotiDaemon notiDaemon) {
var noti = new Notification.timed (param, var noti = new Notification.timed (param,
notiDaemon, notiDaemon,
ConfigModel.instance.timeout, ConfigModel.instance.timeout,

View File

@@ -166,7 +166,9 @@ namespace SwayNotificatonCenter {
} }
public void click_alt_action (uint index) { public void click_alt_action (uint index) {
if (param.actions.length == 0 || index >= param.actions.length) return; if (param.actions.length == 0 || index >= param.actions.length) {
return;
}
action_clicked (param.actions[index]); action_clicked (param.actions[index]);
} }
@@ -187,7 +189,8 @@ namespace SwayNotificatonCenter {
foreach (var action in param.actions) { foreach (var action in param.actions) {
var actionButton = new Gtk.Button.with_label (action._name); var actionButton = new Gtk.Button.with_label (action._name);
actionButton.clicked.connect (() => action_clicked (action)); actionButton.clicked.connect (() => action_clicked (action));
actionButton.get_style_context ().add_class ("notification-action"); actionButton
.get_style_context ().add_class ("notification-action");
actionButton.set_can_focus (false); actionButton.set_can_focus (false);
alt_actions_box.add (actionButton); alt_actions_box.add (actionButton);
} }
@@ -245,8 +248,10 @@ namespace SwayNotificatonCenter {
private void set_icon () { private void set_icon () {
img.set_pixel_size (48); img.set_pixel_size (48);
var img_path_exists = File.new_for_path (param.image_path ?? "").query_exists (); var img_path_exists = File.new_for_path (
var app_icon_exists = File.new_for_path (param.app_icon ?? "").query_exists (); param.image_path ?? "").query_exists ();
var app_icon_exists = File.new_for_path (
param.app_icon ?? "").query_exists ();
if (param.image_data.is_initialized) { if (param.image_data.is_initialized) {
Functions.set_image_data (param.image_data, img); Functions.set_image_data (param.image_data, img);
@@ -269,7 +274,8 @@ namespace SwayNotificatonCenter {
entry_same = (entry == ref_entry); entry_same = (entry == ref_entry);
} }
if (entry_same && app.get_name ().down () == param.app_name.down ()) { if (entry_same
&& app.get_name ().down () == param.app_name.down ()) {
icon = app.get_icon (); icon = app.get_icon ();
break; break;
} }