mirror of
https://github.com/ErikReider/SwayNotificationCenter.git
synced 2024-08-17 03:40:38 +03:00
Notification.vala now follows vala coding style
This commit is contained in:
parent
312a69dd69
commit
8c2df6b2bc
@ -956,7 +956,7 @@ align_oc_decl_colon = false # false/true
|
|||||||
#
|
#
|
||||||
|
|
||||||
# Whether to collapse empty blocks between '{' and '}'
|
# Whether to collapse empty blocks between '{' and '}'
|
||||||
nl_collapse_empty_body = false # false/true
|
nl_collapse_empty_body = true # false/true
|
||||||
|
|
||||||
# Don't split one-line braced assignments - 'foo_t f = { 1, 2 };'
|
# Don't split one-line braced assignments - 'foo_t f = { 1, 2 };'
|
||||||
nl_assign_leave_one_liners = true # false/true
|
nl_assign_leave_one_liners = true # false/true
|
||||||
|
@ -321,7 +321,7 @@ namespace SwayNotificationCenter {
|
|||||||
|
|
||||||
public void add_notification (NotifyParams param,
|
public void add_notification (NotifyParams param,
|
||||||
NotiDaemon noti_daemon) {
|
NotiDaemon noti_daemon) {
|
||||||
var noti = new Notification (param, noti_daemon);
|
var noti = new Notification.regular (param, noti_daemon);
|
||||||
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);
|
||||||
if (list_position != uint.MAX && list_position != i) {
|
if (list_position != uint.MAX && list_position != i) {
|
||||||
|
@ -41,14 +41,18 @@ namespace SwayNotificationCenter {
|
|||||||
|
|
||||||
private uint timeout_id = 0;
|
private uint timeout_id = 0;
|
||||||
|
|
||||||
private int number_of_body_lines = 10;
|
public bool is_timed { get; construct; default = false; }
|
||||||
public bool is_timed = false;
|
|
||||||
public NotifyParams param;
|
public NotifyParams param { get; construct; }
|
||||||
private NotiDaemon noti_daemon;
|
public NotiDaemon noti_daemon { get; construct; }
|
||||||
private uint timeout_delay;
|
|
||||||
private uint timeout_low_delay;
|
public uint timeout_delay { get; construct; }
|
||||||
private int transition_time;
|
public uint timeout_low_delay { get; construct; }
|
||||||
private uint timeout_critical_delay;
|
public uint timeout_critical_delay { get; construct; }
|
||||||
|
|
||||||
|
public int transition_time { get; construct; }
|
||||||
|
|
||||||
|
public int number_of_body_lines { get; construct; default = 10; }
|
||||||
|
|
||||||
private int carousel_empty_widget_index = 0;
|
private int carousel_empty_widget_index = 0;
|
||||||
|
|
||||||
@ -56,37 +60,46 @@ namespace SwayNotificationCenter {
|
|||||||
private static Regex tag_replace_regex;
|
private static Regex tag_replace_regex;
|
||||||
private const string[] TAGS = { "b", "u", "i" };
|
private const string[] TAGS = { "b", "u", "i" };
|
||||||
|
|
||||||
construct {
|
private Notification () {}
|
||||||
try {
|
|
||||||
string joined_tags = string.joinv ("|", TAGS);
|
/** Show a non-timed notification */
|
||||||
tag_regex = new Regex (@"</?($joined_tags)>");
|
public Notification.regular (NotifyParams param,
|
||||||
tag_replace_regex = new Regex ("</?|>");
|
NotiDaemon noti_daemon) {
|
||||||
} catch (Error e) {
|
Object (noti_daemon: noti_daemon, param: param);
|
||||||
stderr.printf ("Invalid regex: %s", e.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Notification (NotifyParams param,
|
/** Show a timed notification */
|
||||||
NotiDaemon noti_daemon) {
|
|
||||||
build_noti (param, noti_daemon);
|
|
||||||
this.body.set_lines (10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called to show a temp notification
|
|
||||||
public Notification.timed (NotifyParams param,
|
public Notification.timed (NotifyParams param,
|
||||||
NotiDaemon noti_daemon,
|
NotiDaemon noti_daemon,
|
||||||
uint timeout,
|
uint timeout,
|
||||||
uint timeout_low,
|
uint timeout_low,
|
||||||
uint timeout_critical) {
|
uint timeout_critical) {
|
||||||
this.is_timed = true;
|
Object (noti_daemon: noti_daemon,
|
||||||
this.timeout_delay = timeout;
|
param: param,
|
||||||
this.timeout_low_delay = timeout_low;
|
is_timed: true,
|
||||||
this.timeout_critical_delay = timeout_critical;
|
timeout_delay: timeout,
|
||||||
this.number_of_body_lines = 5;
|
timeout_low_delay: timeout_low,
|
||||||
|
timeout_critical_delay: timeout_critical,
|
||||||
|
number_of_body_lines: 5
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
build_noti (param, noti_daemon);
|
construct {
|
||||||
add_noti_timeout ();
|
try {
|
||||||
this.size_allocate.connect (on_size_allocation);
|
string joined_tags = string.joinv ("|", TAGS);
|
||||||
|
tag_regex = new Regex ("</?(%s)>".printf (joined_tags));
|
||||||
|
tag_replace_regex = new Regex ("</?|>");
|
||||||
|
} catch (Error e) {
|
||||||
|
stderr.printf ("Invalid regex: %s", e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.transition_time = ConfigModel.instance.transition_time;
|
||||||
|
build_noti ();
|
||||||
|
|
||||||
|
if (is_timed) {
|
||||||
|
add_notification_timeout ();
|
||||||
|
this.size_allocate.connect (on_size_allocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_size_allocation (Gtk.Allocation _ignored) {
|
private void on_size_allocation (Gtk.Allocation _ignored) {
|
||||||
@ -99,12 +112,7 @@ namespace SwayNotificationCenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build_noti (NotifyParams param, NotiDaemon noti_daemon) {
|
private void build_noti () {
|
||||||
this.transition_time = ConfigModel.instance.transition_time;
|
|
||||||
|
|
||||||
this.noti_daemon = noti_daemon;
|
|
||||||
this.param = param;
|
|
||||||
|
|
||||||
this.body.set_line_wrap (true);
|
this.body.set_line_wrap (true);
|
||||||
this.body.set_line_wrap_mode (Pango.WrapMode.WORD_CHAR);
|
this.body.set_line_wrap_mode (Pango.WrapMode.WORD_CHAR);
|
||||||
this.body.set_ellipsize (Pango.EllipsizeMode.END);
|
this.body.set_ellipsize (Pango.EllipsizeMode.END);
|
||||||
@ -135,7 +143,7 @@ namespace SwayNotificationCenter {
|
|||||||
this.event_box.leave_notify_event.connect ((event) => {
|
this.event_box.leave_notify_event.connect ((event) => {
|
||||||
if (event.detail == Gdk.NotifyType.INFERIOR) return true;
|
if (event.detail == Gdk.NotifyType.INFERIOR) return true;
|
||||||
close_revealer.set_reveal_child (false);
|
close_revealer.set_reveal_child (false);
|
||||||
add_noti_timeout ();
|
add_notification_timeout ();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -384,7 +392,7 @@ namespace SwayNotificationCenter {
|
|||||||
Timeout.add (this.transition_time, () => {
|
Timeout.add (this.transition_time, () => {
|
||||||
try {
|
try {
|
||||||
noti_daemon.manually_close_notification (param.applied_id,
|
noti_daemon.manually_close_notification (param.applied_id,
|
||||||
is_timeout);
|
is_timeout);
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
print ("Error: %s\n", e.message);
|
print ("Error: %s\n", e.message);
|
||||||
this.destroy ();
|
this.destroy ();
|
||||||
@ -425,7 +433,8 @@ namespace SwayNotificationCenter {
|
|||||||
if (param.desktop_entry != null) {
|
if (param.desktop_entry != null) {
|
||||||
string entry = param.desktop_entry;
|
string entry = param.desktop_entry;
|
||||||
entry = entry.replace (".desktop", "");
|
entry = entry.replace (".desktop", "");
|
||||||
var entry_info = new DesktopAppInfo (@"$entry.desktop");
|
var entry_info = new DesktopAppInfo (
|
||||||
|
"%s.desktop".printf (entry));
|
||||||
icon = entry_info.get_icon ();
|
icon = entry_info.get_icon ();
|
||||||
}
|
}
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
@ -439,7 +448,7 @@ namespace SwayNotificationCenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add_noti_timeout () {
|
public void add_notification_timeout () {
|
||||||
if (!this.is_timed) return;
|
if (!this.is_timed) return;
|
||||||
|
|
||||||
// Removes the previous timeout
|
// Removes the previous timeout
|
||||||
|
Loading…
Reference in New Issue
Block a user