mirror of
https://github.com/ErikReider/SwayNotificationCenter.git
synced 2024-08-16 11:20:25 +03:00
Vala-lint fixes + linting Github Action (#118)
* Updated code to follow vala-lint style * Added GitHub Linting Action
This commit is contained in:
parent
b7c943617c
commit
8eb56a195b
25
.github/workflows/linting.yml
vendored
Normal file
25
.github/workflows/linting.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# This is a basic workflow to help you get started with Actions
|
||||
|
||||
name: Linting
|
||||
|
||||
# Controls when the workflow will run
|
||||
on:
|
||||
# Triggers the workflow on push or pull request events but only for the main branch
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: elementary/actions/vala-lint@master
|
||||
with:
|
||||
dir: src/
|
||||
conf: .vala-lint.conf
|
||||
fail: true
|
@ -355,7 +355,7 @@ sp_before_byref_func = force # ignore/add/remove/force
|
||||
sp_after_type = force # ignore/add/remove/force
|
||||
|
||||
# Add or remove space before the paren in the D constructs 'template Foo(' and 'class Foo('.
|
||||
sp_before_template_paren = ignore # ignore/add/remove/force
|
||||
sp_before_template_paren = force # ignore/add/remove/force
|
||||
|
||||
# Add or remove space in 'template <' vs 'template<'.
|
||||
# If set to ignore, sp_before_angle is used.
|
||||
@ -371,7 +371,7 @@ sp_inside_angle = remove # ignore/add/remove/force
|
||||
sp_after_angle = remove # ignore/add/remove/force
|
||||
|
||||
# Add or remove space between '<>' and '(' as found in 'new List<byte>();'
|
||||
sp_angle_paren = remove # ignore/add/remove/force
|
||||
sp_angle_paren = force # ignore/add/remove/force
|
||||
|
||||
# Add or remove space between '<>' and a word as in 'List<byte> m;'
|
||||
sp_angle_word = force # ignore/add/remove/force
|
||||
|
27
.vala-lint.conf
Normal file
27
.vala-lint.conf
Normal file
@ -0,0 +1,27 @@
|
||||
[Checks]
|
||||
block-opening-brace-space-before=error
|
||||
double-semicolon=error
|
||||
double-spaces=error
|
||||
ellipsis=off
|
||||
line-length=warn
|
||||
naming-convention=error
|
||||
no-space=error
|
||||
note=warn
|
||||
space-before-paren=error
|
||||
use-of-tabs=error
|
||||
trailing-newlines=error
|
||||
trailing-whitespace=error
|
||||
unnecessary-string-template=error
|
||||
|
||||
[Disabler]
|
||||
disable-by-inline-comments=true
|
||||
|
||||
[line-length]
|
||||
max-line-length=120
|
||||
ignore-comments=true
|
||||
|
||||
[naming-convention]
|
||||
exceptions=UUID,
|
||||
|
||||
[note]
|
||||
keywords=TODO,FIXME,
|
@ -1,17 +1,17 @@
|
||||
namespace SwayNotificationCenter {
|
||||
[DBus (name = "org.erikreider.swaync.cc")]
|
||||
public class CcDaemon : Object {
|
||||
public ControlCenter controlCenter;
|
||||
public NotiDaemon notiDaemon;
|
||||
public ControlCenter control_center;
|
||||
public NotiDaemon noti_daemon;
|
||||
|
||||
public CcDaemon (NotiDaemon notiDaemon) {
|
||||
this.notiDaemon = notiDaemon;
|
||||
this.controlCenter = new ControlCenter (this);
|
||||
public CcDaemon (NotiDaemon noti_daemon) {
|
||||
this.noti_daemon = noti_daemon;
|
||||
this.control_center = new ControlCenter (this);
|
||||
|
||||
notiDaemon.on_dnd_toggle.connect ((dnd) => {
|
||||
this.controlCenter.set_switch_dnd_state (dnd);
|
||||
noti_daemon.on_dnd_toggle.connect ((dnd) => {
|
||||
this.control_center.set_switch_dnd_state (dnd);
|
||||
try {
|
||||
subscribe (controlCenter.notification_count (),
|
||||
subscribe (control_center.notification_count (),
|
||||
dnd,
|
||||
get_visibility ());
|
||||
} catch (Error e) {
|
||||
@ -38,7 +38,7 @@ namespace SwayNotificationCenter {
|
||||
/** Reloads the CSS file */
|
||||
public bool reload_css () throws Error {
|
||||
bool result = Functions.load_css (style_path);
|
||||
if (result) controlCenter.reload_notifications_style ();
|
||||
if (result) control_center.reload_notifications_style ();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -67,32 +67,32 @@ namespace SwayNotificationCenter {
|
||||
|
||||
/** Gets the controlcenter visibility */
|
||||
public bool get_visibility () throws DBusError, IOError {
|
||||
return controlCenter.get_visibility ();
|
||||
return control_center.get_visibility ();
|
||||
}
|
||||
|
||||
/** Closes latest popup notification */
|
||||
public void hide_latest_notifications (bool close)
|
||||
throws DBusError, IOError {
|
||||
notiDaemon.hide_latest_notification (close);
|
||||
noti_daemon.hide_latest_notification (close);
|
||||
}
|
||||
|
||||
/** Closes all popup and controlcenter notifications */
|
||||
public void close_all_notifications () throws DBusError, IOError {
|
||||
notiDaemon.close_all_notifications ();
|
||||
noti_daemon.close_all_notifications ();
|
||||
}
|
||||
|
||||
/** Gets the current controlcenter notification count */
|
||||
public uint notification_count () throws DBusError, IOError {
|
||||
return controlCenter.notification_count ();
|
||||
return control_center.notification_count ();
|
||||
}
|
||||
|
||||
/** Toggles the visibility of the controlcenter */
|
||||
public void toggle_visibility () throws DBusError, IOError {
|
||||
if (controlCenter.toggle_visibility ()) {
|
||||
notiDaemon.set_noti_window_visibility (false);
|
||||
if (control_center.toggle_visibility ()) {
|
||||
noti_daemon.set_noti_window_visibility (false);
|
||||
}
|
||||
try {
|
||||
subscribe (controlCenter.notification_count (),
|
||||
subscribe (control_center.notification_count (),
|
||||
get_dnd (),
|
||||
get_visibility ());
|
||||
} catch (Error e) {
|
||||
@ -102,10 +102,10 @@ namespace SwayNotificationCenter {
|
||||
|
||||
/** Sets the visibility of the controlcenter */
|
||||
public void set_visibility (bool visibility) throws DBusError, IOError {
|
||||
controlCenter.set_visibility (visibility);
|
||||
if (visibility) notiDaemon.set_noti_window_visibility (false);
|
||||
control_center.set_visibility (visibility);
|
||||
if (visibility) noti_daemon.set_noti_window_visibility (false);
|
||||
try {
|
||||
subscribe (controlCenter.notification_count (),
|
||||
subscribe (control_center.notification_count (),
|
||||
get_dnd (),
|
||||
visibility);
|
||||
} catch (Error e) {
|
||||
@ -115,28 +115,28 @@ namespace SwayNotificationCenter {
|
||||
|
||||
/** Toggles the current Do Not Disturb state */
|
||||
public bool toggle_dnd () throws DBusError, IOError {
|
||||
return notiDaemon.toggle_dnd ();
|
||||
return noti_daemon.toggle_dnd ();
|
||||
}
|
||||
|
||||
/** Sets the current Do Not Disturb state */
|
||||
public void set_dnd (bool state) throws DBusError, IOError {
|
||||
notiDaemon.set_dnd (state);
|
||||
noti_daemon.set_dnd (state);
|
||||
}
|
||||
|
||||
/** Gets the current Do Not Disturb state */
|
||||
public bool get_dnd () throws DBusError, IOError {
|
||||
return notiDaemon.get_dnd ();
|
||||
return noti_daemon.get_dnd ();
|
||||
}
|
||||
|
||||
/** Adds a new notification */
|
||||
public void add_notification (NotifyParams param)
|
||||
throws DBusError, IOError {
|
||||
controlCenter.add_notification (param, notiDaemon);
|
||||
control_center.add_notification (param, noti_daemon);
|
||||
}
|
||||
|
||||
/** Closes a specific notification with the `id` */
|
||||
public void close_notification (uint32 id) throws DBusError, IOError {
|
||||
controlCenter.close_notification (id);
|
||||
control_center.close_notification (id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,26 +27,27 @@ interface CcDaemon : GLib.Object {
|
||||
private CcDaemon cc_daemon = null;
|
||||
|
||||
private void print_help (string[] args) {
|
||||
print (@"Usage:\n");
|
||||
print (@"\t $(args[0]) <OPTION>\n");
|
||||
print (@"Help:\n");
|
||||
print (@"\t -h, \t --help \t\t Show help options\n");
|
||||
print (@"\t -v, \t --version \t\t Prints version\n");
|
||||
print (@"Options:\n");
|
||||
print (@"\t -R, \t --reload-config \t Reload the config file\n");
|
||||
print (@"\t -rs, \t --reload-css \t\t Reload the css file. Location change requires restart\n");
|
||||
print (@"\t -t, \t --toggle-panel \t Toggle the notificaion panel\n");
|
||||
print (@"\t -op, \t --open-panel \t\t Opens the notificaion panel\n");
|
||||
print (@"\t -cp, \t --close-panel \t\t Closes the notificaion panel\n");
|
||||
print (@"\t -d, \t --toggle-dnd \t\t Toggle and print the current dnd state\n");
|
||||
print (@"\t -D, \t --get-dnd \t\t Print the current dnd state\n");
|
||||
print (@"\t -c, \t --count \t\t Print the current notificaion count\n");
|
||||
print (@"\t \t --hide-latest \t\t Hides latest notification. Still shown in Control Center\n");
|
||||
print (@"\t \t --close-latest \t Closes latest notification\n");
|
||||
print (@"\t -C, \t --close-all \t\t Closes all notifications\n");
|
||||
print (@"\t -sw, \t --skip-wait \t\t Doesn't wait when swaync hasn't been started\n");
|
||||
print (@"\t -s, \t --subscribe \t\t Subscribe to notificaion add and close events\n");
|
||||
print (@"\t -swb, \t --subscribe-waybar \t Subscribe to notificaion add and close events with waybar support. Read README for example\n");
|
||||
print ("Usage:\n");
|
||||
print ("\t %s <OPTION>\n".printf (args[0]));
|
||||
print ("Help:\n");
|
||||
print ("\t -h, \t --help \t\t Show help options\n");
|
||||
print ("\t -v, \t --version \t\t Prints version\n");
|
||||
print ("Options:\n");
|
||||
print ("\t -R, \t --reload-config \t Reload the config file\n");
|
||||
print ("\t -rs, \t --reload-css \t\t Reload the css file. Location change requires restart\n");
|
||||
print ("\t -t, \t --toggle-panel \t Toggle the notificaion panel\n");
|
||||
print ("\t -op, \t --open-panel \t\t Opens the notificaion panel\n");
|
||||
print ("\t -cp, \t --close-panel \t\t Closes the notificaion panel\n");
|
||||
print ("\t -d, \t --toggle-dnd \t\t Toggle and print the current dnd state\n");
|
||||
print ("\t -D, \t --get-dnd \t\t Print the current dnd state\n");
|
||||
print ("\t -c, \t --count \t\t Print the current notificaion count\n");
|
||||
print ("\t \t --hide-latest \t\t Hides latest notification. Still shown in Control Center\n");
|
||||
print ("\t \t --close-latest \t Closes latest notification\n");
|
||||
print ("\t -C, \t --close-all \t\t Closes all notifications\n");
|
||||
print ("\t -sw, \t --skip-wait \t\t Doesn't wait when swaync hasn't been started\n");
|
||||
print ("\t -s, \t --subscribe \t\t Subscribe to notificaion add and close events\n");
|
||||
print ("\t -swb, \t --subscribe-waybar \t Subscribe to notificaion add and close events "
|
||||
+ "with waybar support. Read README for example\n");
|
||||
}
|
||||
|
||||
private void on_subscribe (uint count, bool dnd, bool cc_open) {
|
||||
@ -107,7 +108,7 @@ public int command_line (string[] args) {
|
||||
break;
|
||||
case "--version":
|
||||
case "-v":
|
||||
stdout.printf ("%s\n", Constants.version);
|
||||
stdout.printf ("%s\n", Constants.VERSION);
|
||||
break;
|
||||
case "--reload-config":
|
||||
case "-R":
|
||||
|
@ -271,55 +271,55 @@ namespace SwayNotificationCenter {
|
||||
/* Properties */
|
||||
|
||||
/** The notifications and controlcenters horizontal alignment */
|
||||
public PositionX positionX { get; set; default = PositionX.RIGHT; }
|
||||
public PositionX position_x { get; set; default = PositionX.RIGHT; }
|
||||
/** The notifications and controlcenters vertical alignment */
|
||||
public PositionY positionY { get; set; default = PositionY.TOP; }
|
||||
public PositionY position_y { get; set; default = PositionY.TOP; }
|
||||
|
||||
/** The timeout for notifications with NORMAL priority */
|
||||
private const int _timeout_def = 10;
|
||||
private int _timeout = _timeout_def;
|
||||
private const int TIMEOUT_DEFAULT = 10;
|
||||
private int _timeout = TIMEOUT_DEFAULT;
|
||||
public int timeout {
|
||||
get {
|
||||
return _timeout;
|
||||
}
|
||||
set {
|
||||
_timeout = value < 1 ? _timeout_def : value;
|
||||
_timeout = value < 1 ? TIMEOUT_DEFAULT : value;
|
||||
}
|
||||
}
|
||||
|
||||
/** The timeout for notifications with LOW priority */
|
||||
private const int _timeout_low_def = 5;
|
||||
private int _timeout_low = _timeout_low_def;
|
||||
private const int TIMEOUT_LOW_DEFAULT = 5;
|
||||
private int _timeout_low = TIMEOUT_LOW_DEFAULT;
|
||||
public int timeout_low {
|
||||
get {
|
||||
return _timeout_low;
|
||||
}
|
||||
set {
|
||||
_timeout_low = value < 1 ? _timeout_low_def : value;
|
||||
_timeout_low = value < 1 ? TIMEOUT_LOW_DEFAULT : value;
|
||||
}
|
||||
}
|
||||
|
||||
/** The transition time for all animations */
|
||||
private const int _transition_time_def = 200;
|
||||
private int _transition_time = _transition_time_def;
|
||||
private const int TRANSITION_TIME_DEFAULT = 200;
|
||||
private int _transition_time = TRANSITION_TIME_DEFAULT;
|
||||
public int transition_time {
|
||||
get {
|
||||
return _transition_time;
|
||||
}
|
||||
set {
|
||||
_transition_time = value < 0 ? _transition_time_def : value;
|
||||
_transition_time = value < 0 ? TRANSITION_TIME_DEFAULT : value;
|
||||
}
|
||||
}
|
||||
|
||||
/** The timeout for notifications with CRITICAL priority */
|
||||
private const int _timeout_critical_def = 0;
|
||||
private int _timeout_critical = _timeout_critical_def;
|
||||
private const int TIMEOUT_CRITICAL_DEFAULT = 0;
|
||||
private int _timeout_critical = TIMEOUT_CRITICAL_DEFAULT;
|
||||
public int timeout_critical {
|
||||
get {
|
||||
return _timeout_critical;
|
||||
}
|
||||
set {
|
||||
_timeout_critical = value < 0 ? _timeout_critical_def : value;
|
||||
_timeout_critical = value < 0 ? TIMEOUT_CRITICAL_DEFAULT : value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,14 +392,14 @@ namespace SwayNotificationCenter {
|
||||
public HashTable<string, Category> categories_settings {
|
||||
get;
|
||||
set;
|
||||
default = new HashTable<string, Category>(str_hash, str_equal);
|
||||
default = new HashTable<string, Category> (str_hash, str_equal);
|
||||
}
|
||||
|
||||
/** Notification Status */
|
||||
public HashTable<string, NotificationVisibility> notification_visibility {
|
||||
get;
|
||||
set;
|
||||
default = new HashTable<string, NotificationVisibility>(str_hash, str_equal);
|
||||
default = new HashTable<string, NotificationVisibility> (str_hash, str_equal);
|
||||
}
|
||||
|
||||
#if WANT_SCRIPTING
|
||||
@ -407,7 +407,7 @@ namespace SwayNotificationCenter {
|
||||
public HashTable<string, Script> scripts {
|
||||
get;
|
||||
set;
|
||||
default = new HashTable<string, Script>(str_hash, str_equal);
|
||||
default = new HashTable<string, Script> (str_hash, str_equal);
|
||||
}
|
||||
/** Show notification if script fails */
|
||||
public bool script_fail_notify { get; set; default = true; }
|
||||
@ -420,28 +420,30 @@ namespace SwayNotificationCenter {
|
||||
* Notification center's height, in pixels.
|
||||
* Set `fit_to_screen` to true to ignore the height setting.
|
||||
*/
|
||||
private const int control_center_minimum_height = 300;
|
||||
private int _control_center_height = control_center_minimum_height;
|
||||
private const int CONTROL_CENTER_MINIMUM_HEIGHT = 300;
|
||||
private int _control_center_height = CONTROL_CENTER_MINIMUM_HEIGHT;
|
||||
public int control_center_height {
|
||||
get {
|
||||
return _control_center_height;
|
||||
}
|
||||
set {
|
||||
_control_center_height = value > control_center_minimum_height ? value : control_center_minimum_height;
|
||||
_control_center_height = value > CONTROL_CENTER_MINIMUM_HEIGHT
|
||||
? value : CONTROL_CENTER_MINIMUM_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification center's width, in pixels.
|
||||
*/
|
||||
private const int control_center_minimum_width = 300;
|
||||
private int _control_center_width = control_center_minimum_width;
|
||||
private const int CONTROL_CENTER_MINIMUM_WIDTH = 300;
|
||||
private int _control_center_width = CONTROL_CENTER_MINIMUM_WIDTH;
|
||||
public int control_center_width {
|
||||
get {
|
||||
return _control_center_width;
|
||||
}
|
||||
set {
|
||||
_control_center_width = value > control_center_minimum_width ? value : control_center_minimum_width;
|
||||
_control_center_width = value > CONTROL_CENTER_MINIMUM_WIDTH
|
||||
? value : CONTROL_CENTER_MINIMUM_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,7 +462,7 @@ namespace SwayNotificationCenter {
|
||||
case "categories-settings" :
|
||||
bool status;
|
||||
HashTable<string, Category> result =
|
||||
extract_hashtable<Category>(
|
||||
extract_hashtable<Category> (
|
||||
property_name,
|
||||
property_node,
|
||||
out status);
|
||||
@ -469,7 +471,7 @@ namespace SwayNotificationCenter {
|
||||
case "notification-visibility":
|
||||
bool status;
|
||||
HashTable<string, NotificationVisibility> result =
|
||||
extract_hashtable<NotificationVisibility>(
|
||||
extract_hashtable<NotificationVisibility> (
|
||||
property_name,
|
||||
property_node,
|
||||
out status);
|
||||
@ -479,7 +481,7 @@ namespace SwayNotificationCenter {
|
||||
case "scripts":
|
||||
bool status;
|
||||
HashTable<string, Script> result =
|
||||
extract_hashtable<Script>(
|
||||
extract_hashtable<Script> (
|
||||
property_name,
|
||||
property_node,
|
||||
out status);
|
||||
@ -513,21 +515,21 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
// All other properties that can't be serialized
|
||||
switch (property_name) {
|
||||
case "categories-settings":
|
||||
case "categories-settings" :
|
||||
node = new Json.Node (Json.NodeType.OBJECT);
|
||||
var table = (HashTable<string, Category>) value.get_boxed ();
|
||||
node.set_object (serialize_hashtable<Category>(table));
|
||||
node.set_object (serialize_hashtable<Category> (table));
|
||||
break;
|
||||
case "notification-visibility":
|
||||
node = new Json.Node (Json.NodeType.OBJECT);
|
||||
var table = (HashTable<string, NotificationVisibility>) value.get_boxed ();
|
||||
node.set_object (serialize_hashtable<NotificationVisibility>(table));
|
||||
node.set_object (serialize_hashtable<NotificationVisibility> (table));
|
||||
break;
|
||||
#if WANT_SCRIPTING
|
||||
case "scripts":
|
||||
node = new Json.Node (Json.NodeType.OBJECT);
|
||||
var table = (HashTable<string, Script>) value.get_boxed ();
|
||||
node.set_object (serialize_hashtable<Script>(table));
|
||||
node.set_object (serialize_hashtable<Script> (table));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -552,11 +554,11 @@ namespace SwayNotificationCenter {
|
||||
* - int64
|
||||
* - GLib.Object
|
||||
*/
|
||||
private HashTable<string, T> extract_hashtable<T>(string property_name,
|
||||
Json.Node node,
|
||||
out bool status) {
|
||||
private HashTable<string, T> extract_hashtable<T> (string property_name,
|
||||
Json.Node node,
|
||||
out bool status) {
|
||||
status = false;
|
||||
var tmp_table = new HashTable<string, T>(str_hash, str_equal);
|
||||
var tmp_table = new HashTable<string, T> (str_hash, str_equal);
|
||||
|
||||
if (node.get_node_type () != Json.NodeType.OBJECT) {
|
||||
stderr.printf ("Node %s is not a json object!...\n",
|
||||
@ -637,7 +639,7 @@ namespace SwayNotificationCenter {
|
||||
return tmp_table;
|
||||
}
|
||||
|
||||
private Json.Object serialize_hashtable<T>(HashTable<string, T> table) {
|
||||
private Json.Object serialize_hashtable<T> (HashTable<string, T> table) {
|
||||
var json_object = new Json.Object ();
|
||||
|
||||
if (table == null) return json_object;
|
||||
@ -684,11 +686,11 @@ namespace SwayNotificationCenter {
|
||||
* - int64
|
||||
* - GLib.Object
|
||||
*/
|
||||
private GenericArray<T> extract_array<T>(string property_name,
|
||||
Json.Node node,
|
||||
out bool status) {
|
||||
private GenericArray<T> extract_array<T> (string property_name,
|
||||
Json.Node node,
|
||||
out bool status) {
|
||||
status = false;
|
||||
GenericArray<T> tmp_array = new GenericArray<T>();
|
||||
GenericArray<T> tmp_array = new GenericArray<T> ();
|
||||
|
||||
if (node.get_node_type () != Json.NodeType.ARRAY) {
|
||||
stderr.printf ("Node %s is not a json array!...\n",
|
||||
@ -739,7 +741,7 @@ namespace SwayNotificationCenter {
|
||||
return tmp_array;
|
||||
}
|
||||
|
||||
private Json.Array serialize_array<T>(GenericArray<T> array) {
|
||||
private Json.Array serialize_array<T> (GenericArray<T> array) {
|
||||
var json_array = new Json.Array ();
|
||||
|
||||
if (array == null) return json_array;
|
||||
|
@ -1,4 +1,4 @@
|
||||
public class Constants {
|
||||
public const string version = @VERSION@;
|
||||
public const string versionNum = @VERSION_NUM@;
|
||||
public const string VERSION = @VERSION@;
|
||||
public const string VERSIONNUM = @VERSION_NUM@;
|
||||
}
|
||||
|
@ -162,24 +162,24 @@ namespace SwayNotificationCenter {
|
||||
ConfigModel.instance.control_center_margin_left);
|
||||
|
||||
// Anchor to north/south edges as needed
|
||||
bool anchorTop = ConfigModel.instance.positionY == PositionY.TOP;
|
||||
bool anchor_top = ConfigModel.instance.position_y == PositionY.TOP;
|
||||
GtkLayerShell.set_anchor (this,
|
||||
GtkLayerShell.Edge.TOP,
|
||||
ConfigModel.instance.fit_to_screen || anchorTop);
|
||||
ConfigModel.instance.fit_to_screen || anchor_top);
|
||||
GtkLayerShell.set_anchor (this,
|
||||
GtkLayerShell.Edge.BOTTOM,
|
||||
ConfigModel.instance.fit_to_screen || !anchorTop);
|
||||
ConfigModel.instance.fit_to_screen || !anchor_top);
|
||||
|
||||
bool anchorLeft = ConfigModel.instance.positionX == PositionX.LEFT;
|
||||
bool anchorRight = ConfigModel.instance.positionX == PositionX.RIGHT;
|
||||
bool anchor_left = ConfigModel.instance.position_x == PositionX.LEFT;
|
||||
bool anchor_right = ConfigModel.instance.position_x == PositionX.RIGHT;
|
||||
GtkLayerShell.set_anchor (this,
|
||||
GtkLayerShell.Edge.RIGHT,
|
||||
anchorRight);
|
||||
anchor_right);
|
||||
GtkLayerShell.set_anchor (this,
|
||||
GtkLayerShell.Edge.LEFT,
|
||||
anchorLeft);
|
||||
anchor_left);
|
||||
|
||||
switch (ConfigModel.instance.positionY) {
|
||||
switch (ConfigModel.instance.position_y) {
|
||||
case PositionY.BOTTOM:
|
||||
list_reverse = true;
|
||||
list_align = Gtk.Align.END;
|
||||
@ -206,9 +206,9 @@ namespace SwayNotificationCenter {
|
||||
});
|
||||
|
||||
// Always set the size request in all events.
|
||||
int configuredWidth = ConfigModel.instance.control_center_width;
|
||||
int configuredHeight = ConfigModel.instance.control_center_height;
|
||||
this.set_size_request (configuredWidth, configuredHeight);
|
||||
int configured_width = ConfigModel.instance.control_center_width;
|
||||
int configured_height = ConfigModel.instance.control_center_height;
|
||||
this.set_size_request (configured_width, configured_height);
|
||||
}
|
||||
|
||||
private void size_alloc () {
|
||||
@ -221,12 +221,11 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
private void scroll_to_start (bool reverse) {
|
||||
const bool horizontal_scroll = false;
|
||||
Gtk.ScrollType scroll_type = Gtk.ScrollType.START;
|
||||
if (reverse) {
|
||||
scroll_type = Gtk.ScrollType.END;
|
||||
}
|
||||
scrolled_window.scroll_child (scroll_type, horizontal_scroll);
|
||||
scrolled_window.scroll_child (scroll_type, false);
|
||||
}
|
||||
|
||||
public uint notification_count () {
|
||||
@ -321,8 +320,8 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
public void add_notification (NotifyParams param,
|
||||
NotiDaemon notiDaemon) {
|
||||
var noti = new Notification (param, notiDaemon);
|
||||
NotiDaemon noti_daemon) {
|
||||
var noti = new Notification (param, noti_daemon);
|
||||
noti.grab_focus.connect ((w) => {
|
||||
uint i = list_box.get_children ().index (w);
|
||||
if (list_position != uint.MAX && list_position != i) {
|
||||
|
@ -32,7 +32,7 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void set_image_data (Image_Data data, Gtk.Image img) {
|
||||
public static void set_image_data (ImageData data, Gtk.Image img) {
|
||||
// Rebuild and scale the image
|
||||
var pixbuf = new Gdk.Pixbuf.with_unowned_data (data.data,
|
||||
Gdk.Colorspace.RGB,
|
||||
|
@ -1,5 +1,5 @@
|
||||
namespace SwayNotificationCenter {
|
||||
static NotiDaemon notiDaemon;
|
||||
static NotiDaemon noti_daemon;
|
||||
static string ? style_path;
|
||||
static string ? config_path;
|
||||
|
||||
@ -21,7 +21,7 @@ namespace SwayNotificationCenter {
|
||||
break;
|
||||
case "-v":
|
||||
case "--version":
|
||||
stdout.printf ("%s\n", Constants.version);
|
||||
stdout.printf ("%s\n", Constants.VERSION);
|
||||
return;
|
||||
case "-h":
|
||||
case "--help":
|
||||
@ -48,7 +48,7 @@ namespace SwayNotificationCenter {
|
||||
|
||||
ConfigModel.init (config_path);
|
||||
|
||||
notiDaemon = new NotiDaemon ();
|
||||
noti_daemon = new NotiDaemon ();
|
||||
|
||||
Gtk.main ();
|
||||
}
|
||||
@ -56,7 +56,7 @@ namespace SwayNotificationCenter {
|
||||
void on_noti_bus_aquired (DBusConnection conn) {
|
||||
try {
|
||||
conn.register_object (
|
||||
"/org/freedesktop/Notifications", notiDaemon);
|
||||
"/org/freedesktop/Notifications", noti_daemon);
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("Could not register notification service\n");
|
||||
Process.exit (1);
|
||||
@ -64,13 +64,13 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
private void print_help (string[] args) {
|
||||
print (@"Usage:\n");
|
||||
print (@"\t $(args[0]) <OPTION>\n");
|
||||
print (@"Help:\n");
|
||||
print (@"\t -h, --help \t\t Show help options\n");
|
||||
print (@"\t -v, --version \t\t Prints version\n");
|
||||
print (@"Options:\n");
|
||||
print (@"\t -s, --style \t\t Use a custom Stylesheet file\n");
|
||||
print (@"\t -c, --config \t\t Use a custom config file\n");
|
||||
print ("Usage:\n");
|
||||
print ("\t %s <OPTION>\n".printf (args[0]));
|
||||
print ("Help:\n");
|
||||
print ("\t -h, --help \t\t Show help options\n");
|
||||
print ("\t -v, --version \t\t Prints version\n");
|
||||
print ("Options:\n");
|
||||
print ("\t -s, --style \t\t Use a custom Stylesheet file\n");
|
||||
print ("\t -c, --config \t\t Use a custom config file\n");
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ namespace SwayNotificationCenter {
|
||||
private uint32 noti_id = 0;
|
||||
private bool dnd = false;
|
||||
private HashTable<string, uint32> synchronous_ids =
|
||||
new HashTable<string, uint32>(str_hash, str_equal);
|
||||
new HashTable<string, uint32> (str_hash, str_equal);
|
||||
|
||||
public CcDaemon ccDaemon;
|
||||
public NotiWindow notiWindow;
|
||||
public CcDaemon cc_daemon;
|
||||
public NotiWindow noti_window;
|
||||
|
||||
public NotiDaemon () {
|
||||
this.ccDaemon = new CcDaemon (this);
|
||||
this.cc_daemon = new CcDaemon (this);
|
||||
Bus.own_name (BusType.SESSION, "org.erikreider.swaync.cc",
|
||||
BusNameOwnerFlags.NONE,
|
||||
on_cc_bus_aquired,
|
||||
@ -21,12 +21,12 @@ namespace SwayNotificationCenter {
|
||||
Process.exit (1);
|
||||
});
|
||||
|
||||
this.notiWindow = new NotiWindow ();
|
||||
this.noti_window = new NotiWindow ();
|
||||
}
|
||||
|
||||
private void on_cc_bus_aquired (DBusConnection conn) {
|
||||
try {
|
||||
conn.register_object ("/org/erikreider/swaync/cc", ccDaemon);
|
||||
conn.register_object ("/org/erikreider/swaync/cc", cc_daemon);
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("Could not register CC service\n");
|
||||
Process.exit (1);
|
||||
@ -39,7 +39,7 @@ namespace SwayNotificationCenter {
|
||||
*/
|
||||
public void set_noti_window_visibility (bool value)
|
||||
throws DBusError, IOError {
|
||||
notiWindow.change_visibility (value);
|
||||
noti_window.change_visibility (value);
|
||||
}
|
||||
|
||||
/** Toggles the current Do Not Disturb state */
|
||||
@ -65,23 +65,23 @@ namespace SwayNotificationCenter {
|
||||
/** Method to close notification and send DISMISSED signal */
|
||||
public void manually_close_notification (uint32 id, bool timeout)
|
||||
throws DBusError, IOError {
|
||||
notiWindow.close_notification (id);
|
||||
noti_window.close_notification (id);
|
||||
if (!timeout) {
|
||||
ccDaemon.controlCenter.close_notification (id);
|
||||
cc_daemon.control_center.close_notification (id);
|
||||
NotificationClosed (id, ClosedReasons.DISMISSED);
|
||||
}
|
||||
}
|
||||
|
||||
/** Closes all popup and controlcenter notifications */
|
||||
public void close_all_notifications () throws DBusError, IOError {
|
||||
notiWindow.close_all_notifications ();
|
||||
ccDaemon.controlCenter.close_all_notifications ();
|
||||
noti_window.close_all_notifications ();
|
||||
cc_daemon.control_center.close_all_notifications ();
|
||||
}
|
||||
|
||||
/** Closes latest popup notification */
|
||||
public void hide_latest_notification (bool close)
|
||||
throws DBusError, IOError {
|
||||
uint32 ? id = notiWindow.get_latest_notification ();
|
||||
uint32 ? id = noti_window.get_latest_notification ();
|
||||
if (id == null) return;
|
||||
manually_close_notification (id, !close);
|
||||
}
|
||||
@ -100,7 +100,8 @@ namespace SwayNotificationCenter {
|
||||
* not contain spaces. They are limited to alpha-numeric characters
|
||||
* and dashes ("-").
|
||||
*/
|
||||
public string[] GetCapabilities () throws DBusError, IOError {
|
||||
[DBus (name = "GetCapabilities")]
|
||||
public string[] get_capabilities () throws DBusError, IOError {
|
||||
return {
|
||||
"actions",
|
||||
"body",
|
||||
@ -126,7 +127,8 @@ namespace SwayNotificationCenter {
|
||||
* If replaces_id is not 0, the returned value is the same value
|
||||
* as replaces_id.
|
||||
*/
|
||||
public uint32 Notify (string app_name,
|
||||
[DBus (name = "Notify")]
|
||||
public new uint32 notify (string app_name,
|
||||
uint32 replaces_id,
|
||||
string app_icon,
|
||||
string summary,
|
||||
@ -163,8 +165,8 @@ namespace SwayNotificationCenter {
|
||||
// Replace notification logic
|
||||
if (id == replaces_id) {
|
||||
param.replaces = true;
|
||||
notiWindow.close_notification (id);
|
||||
ccDaemon.controlCenter.close_notification (id, true);
|
||||
noti_window.close_notification (id);
|
||||
cc_daemon.control_center.close_notification (id, true);
|
||||
} else if (param.synchronous != null
|
||||
&& param.synchronous.length > 0) {
|
||||
// Tries replacing without replaces_id instead
|
||||
@ -174,23 +176,23 @@ namespace SwayNotificationCenter {
|
||||
param.synchronous, null, out r_id)) {
|
||||
param.replaces = true;
|
||||
// Close the notification
|
||||
notiWindow.close_notification (r_id);
|
||||
ccDaemon.controlCenter.close_notification (r_id, true);
|
||||
noti_window.close_notification (r_id);
|
||||
cc_daemon.control_center.close_notification (r_id, true);
|
||||
}
|
||||
synchronous_ids.set (param.synchronous, id);
|
||||
}
|
||||
|
||||
// Only show popup notification if it is ENABLED
|
||||
if (state == NotificationStatusEnum.ENABLED
|
||||
&& !ccDaemon.controlCenter.get_visibility ()) {
|
||||
&& !cc_daemon.control_center.get_visibility ()) {
|
||||
if (param.urgency == UrgencyLevels.CRITICAL ||
|
||||
(!dnd && param.urgency != UrgencyLevels.CRITICAL)) {
|
||||
notiWindow.add_notification (param, this);
|
||||
noti_window.add_notification (param, this);
|
||||
}
|
||||
}
|
||||
// Only add notification to CC if it isn't IGNORED
|
||||
if (state != NotificationStatusEnum.IGNORED) {
|
||||
ccDaemon.controlCenter.add_notification (param, this);
|
||||
cc_daemon.control_center.add_notification (param, this);
|
||||
}
|
||||
|
||||
#if WANT_SCRIPTING
|
||||
@ -217,7 +219,7 @@ namespace SwayNotificationCenter {
|
||||
} else {
|
||||
// Send notification with error message
|
||||
try {
|
||||
var _hints = new HashTable<string, Variant>(
|
||||
var _hints = new HashTable<string, Variant> (
|
||||
str_hash,
|
||||
str_equal);
|
||||
// Disable scripts for this notification
|
||||
@ -227,7 +229,7 @@ namespace SwayNotificationCenter {
|
||||
|
||||
string _summary = @"Failed to run script: $key";
|
||||
string _body = "<b>Output:</b> " + error_msg;
|
||||
this.Notify ("SwayNotificationCenter",
|
||||
this.notify ("SwayNotificationCenter",
|
||||
0,
|
||||
"dialog-error",
|
||||
_summary,
|
||||
@ -259,9 +261,10 @@ namespace SwayNotificationCenter {
|
||||
* If the notification no longer exists, an empty D-BUS Error message
|
||||
* is sent back.
|
||||
*/
|
||||
public void CloseNotification (uint32 id) throws DBusError, IOError {
|
||||
notiWindow.close_notification (id);
|
||||
ccDaemon.controlCenter.close_notification (id);
|
||||
[DBus (name = "CloseNotification")]
|
||||
public void close_notification (uint32 id) throws DBusError, IOError {
|
||||
noti_window.close_notification (id);
|
||||
cc_daemon.control_center.close_notification (id);
|
||||
NotificationClosed (id, ClosedReasons.CLOSED_BY_CLOSENOTIFICATION);
|
||||
}
|
||||
|
||||
@ -269,14 +272,15 @@ namespace SwayNotificationCenter {
|
||||
* This message returns the information on the server. Specifically, the
|
||||
* server name, vendor, and version number.
|
||||
*/
|
||||
public void GetServerInformation (out string name,
|
||||
[DBus (name = "GetServerInformation")]
|
||||
public void get_server_information (out string name,
|
||||
out string vendor,
|
||||
out string version,
|
||||
out string spec_version)
|
||||
throws DBusError, IOError {
|
||||
name = "SwayNotificationCenter";
|
||||
vendor = "ErikReider";
|
||||
version = Constants.versionNum;
|
||||
version = Constants.VERSIONNUM;
|
||||
spec_version = "1.2";
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Image_Data {
|
||||
public struct ImageData {
|
||||
int width;
|
||||
int height;
|
||||
int rowstride;
|
||||
@ -77,8 +77,8 @@ namespace SwayNotificationCenter {
|
||||
|
||||
// Hints
|
||||
public bool action_icons { get; set; }
|
||||
public Image_Data image_data { get; set; }
|
||||
public Image_Data icon_data { get; set; }
|
||||
public ImageData image_data { get; set; }
|
||||
public ImageData icon_data { get; set; }
|
||||
public string image_path { get; set; }
|
||||
public string desktop_entry { get; set; }
|
||||
public string category { get; set; }
|
||||
@ -184,7 +184,7 @@ namespace SwayNotificationCenter {
|
||||
case "image_data":
|
||||
case "icon_data":
|
||||
if (image_data.is_initialized) break;
|
||||
var img_d = Image_Data ();
|
||||
var img_d = ImageData ();
|
||||
// Read each value
|
||||
// https://specifications.freedesktop.org/notification-spec/latest/ar01s05.html
|
||||
img_d.width = hint_value.get_child_value (0).get_int32 ();
|
||||
@ -234,7 +234,7 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
public string to_string () {
|
||||
var params = new HashTable<string, string ? >(str_hash, str_equal);
|
||||
var params = new HashTable<string, string ? > (str_hash, str_equal);
|
||||
|
||||
params.set ("applied_id", applied_id.to_string ());
|
||||
params.set ("app_name", app_name);
|
||||
|
@ -20,8 +20,8 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
public void add_notification (NotifyParams param,
|
||||
NotiDaemon notiDaemon) {
|
||||
notificationWindow.add_notification (param, notiDaemon);
|
||||
NotiDaemon noti_daemon) {
|
||||
notificationWindow.add_notification (param, noti_daemon);
|
||||
}
|
||||
|
||||
public void close_notification (uint32 id) {
|
||||
@ -65,7 +65,7 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
private void set_anchor () {
|
||||
switch (ConfigModel.instance.positionX) {
|
||||
switch (ConfigModel.instance.position_x) {
|
||||
case PositionX.LEFT:
|
||||
GtkLayerShell.set_anchor (
|
||||
this, GtkLayerShell.Edge.RIGHT, false);
|
||||
@ -85,7 +85,7 @@ namespace SwayNotificationCenter {
|
||||
this, GtkLayerShell.Edge.RIGHT, true);
|
||||
break;
|
||||
}
|
||||
switch (ConfigModel.instance.positionY) {
|
||||
switch (ConfigModel.instance.position_y) {
|
||||
case PositionY.BOTTOM:
|
||||
GtkLayerShell.set_anchor (
|
||||
this, GtkLayerShell.Edge.TOP, false);
|
||||
@ -148,9 +148,9 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
public void add_notification (NotifyParams param,
|
||||
NotiDaemon notiDaemon) {
|
||||
NotiDaemon noti_daemon) {
|
||||
var noti = new Notification.timed (param,
|
||||
notiDaemon,
|
||||
noti_daemon,
|
||||
ConfigModel.instance.timeout,
|
||||
ConfigModel.instance.timeout_low,
|
||||
ConfigModel.instance.timeout_critical);
|
||||
|
@ -43,7 +43,7 @@ namespace SwayNotificationCenter {
|
||||
|
||||
public bool is_timed = false;
|
||||
public NotifyParams param;
|
||||
private NotiDaemon notiDaemon;
|
||||
private NotiDaemon noti_daemon;
|
||||
private uint timeout_delay;
|
||||
private uint timeout_low_delay;
|
||||
private int transition_time;
|
||||
@ -66,14 +66,14 @@ namespace SwayNotificationCenter {
|
||||
}
|
||||
|
||||
public Notification (NotifyParams param,
|
||||
NotiDaemon notiDaemon) {
|
||||
build_noti (param, notiDaemon);
|
||||
NotiDaemon noti_daemon) {
|
||||
build_noti (param, noti_daemon);
|
||||
this.body.set_lines (10);
|
||||
}
|
||||
|
||||
// Called to show a temp notification
|
||||
public Notification.timed (NotifyParams param,
|
||||
NotiDaemon notiDaemon,
|
||||
NotiDaemon noti_daemon,
|
||||
uint timeout,
|
||||
uint timeout_low,
|
||||
uint timeout_critical) {
|
||||
@ -81,14 +81,14 @@ namespace SwayNotificationCenter {
|
||||
this.timeout_delay = timeout;
|
||||
this.timeout_low_delay = timeout_low;
|
||||
this.timeout_critical_delay = timeout_critical;
|
||||
build_noti (param, notiDaemon);
|
||||
build_noti (param, noti_daemon);
|
||||
add_noti_timeout ();
|
||||
}
|
||||
|
||||
private void build_noti (NotifyParams param, NotiDaemon notiDaemon) {
|
||||
private void build_noti (NotifyParams param, NotiDaemon noti_daemon) {
|
||||
this.transition_time = ConfigModel.instance.transition_time;
|
||||
|
||||
this.notiDaemon = notiDaemon;
|
||||
this.noti_daemon = noti_daemon;
|
||||
this.param = param;
|
||||
|
||||
this.summary.set_text (param.summary ?? param.app_name);
|
||||
@ -123,7 +123,7 @@ namespace SwayNotificationCenter {
|
||||
|
||||
this.carousel.set_animation_duration (this.transition_time);
|
||||
// Changes the swipte direction depending on the notifications X position
|
||||
switch (ConfigModel.instance.positionX) {
|
||||
switch (ConfigModel.instance.position_x) {
|
||||
case PositionX.LEFT:
|
||||
this.carousel.reorder (event_box, 0);
|
||||
this.carousel_empty_widget_index = 1;
|
||||
@ -138,7 +138,7 @@ namespace SwayNotificationCenter {
|
||||
if (i != this.carousel_empty_widget_index) return;
|
||||
remove_noti_timeout ();
|
||||
try {
|
||||
notiDaemon.manually_close_notification (
|
||||
noti_daemon.manually_close_notification (
|
||||
param.applied_id, false);
|
||||
} catch (Error e) {
|
||||
print ("Error: %s\n", e.message);
|
||||
@ -272,10 +272,10 @@ namespace SwayNotificationCenter {
|
||||
|
||||
private void action_clicked (Action action, bool is_default = false) {
|
||||
if (action._identifier != null && action._identifier != "") {
|
||||
notiDaemon.ActionInvoked (param.applied_id, action._identifier);
|
||||
noti_daemon.ActionInvoked (param.applied_id, action._identifier);
|
||||
if (ConfigModel.instance.hide_on_action) {
|
||||
try {
|
||||
this.notiDaemon.ccDaemon.set_visibility (false);
|
||||
this.noti_daemon.cc_daemon.set_visibility (false);
|
||||
} catch (Error e) {
|
||||
print ("Error: %s\n", e.message);
|
||||
}
|
||||
@ -307,12 +307,12 @@ namespace SwayNotificationCenter {
|
||||
alt_actions_box.set_homogeneous (true);
|
||||
alt_actions_box.set_layout (Gtk.ButtonBoxStyle.EXPAND);
|
||||
foreach (var action in param.actions) {
|
||||
var actionButton = new Gtk.Button.with_label (action._name);
|
||||
actionButton.clicked.connect (() => action_clicked (action));
|
||||
actionButton
|
||||
var action_button = new Gtk.Button.with_label (action._name);
|
||||
action_button.clicked.connect (() => action_clicked (action));
|
||||
action_button
|
||||
.get_style_context ().add_class ("notification-action");
|
||||
actionButton.set_can_focus (false);
|
||||
alt_actions_box.add (actionButton);
|
||||
action_button.set_can_focus (false);
|
||||
alt_actions_box.add (action_button);
|
||||
}
|
||||
viewport.add (alt_actions_box);
|
||||
scroll.add (viewport);
|
||||
@ -361,7 +361,7 @@ namespace SwayNotificationCenter {
|
||||
this.revealer.set_reveal_child (false);
|
||||
Timeout.add (this.transition_time, () => {
|
||||
try {
|
||||
notiDaemon.manually_close_notification (param.applied_id,
|
||||
noti_daemon.manually_close_notification (param.applied_id,
|
||||
is_timeout);
|
||||
} catch (Error e) {
|
||||
print ("Error: %s\n", e.message);
|
||||
|
Loading…
Reference in New Issue
Block a user