From b18e6cff5afc6b0db16e11bec182f9f72884c6a3 Mon Sep 17 00:00:00 2001 From: Andriy Voskoboinyk Date: Thu, 4 Sep 2014 01:31:59 +0300 Subject: [PATCH 1/2] move duplicate code into separate function --- src/notify.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/notify.c b/src/notify.c index 54f2e70..81e783d 100644 --- a/src/notify.c +++ b/src/notify.c @@ -119,6 +119,12 @@ long unsigned int get_focused_window_id() #endif /* _X11 */ } +static _Bool notifications_are_disabled(const uint64_t flags) +{ + return ( (flags & NT_RESTOL && Control.cooldown > time(NULL)) || + (flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ); +} + static void control_lock() { #if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY) @@ -449,8 +455,7 @@ int sound_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_in else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } - if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || - ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) )) + if (notifications_are_disabled(flags)) return -1; int id = -1; @@ -493,8 +498,7 @@ int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id) else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } - if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || - ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) )) + if (notifications_are_disabled(flags)) return -1; if (id < 0 || id >= ACTIVE_NOTIFS_MAX) return -1; @@ -532,8 +536,7 @@ int sound_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id) int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indicator, char* title, const char* format, ...) { - if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || - ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) )) + if (notifications_are_disabled(flags)) return -1; #ifdef _BOX_NOTIFY @@ -585,8 +588,7 @@ int box_notify(ToxWindow* self, Notification notif, uint64_t flags, int* id_indi int box_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id, const char* format, ...) { - if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || - ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) )) + if (notifications_are_disabled(flags)) return -1; #ifdef _BOX_NOTIFY @@ -642,8 +644,7 @@ int box_silent_notify(ToxWindow* self, uint64_t flags, int* id_indicator, const else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } - if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || - ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) )) + if (notifications_are_disabled(flags)) return -1; #ifdef _BOX_NOTIFY @@ -698,8 +699,7 @@ int box_silent_notify2(ToxWindow* self, uint64_t flags, int id, const char* form else if ( (flags & NT_WNDALERT_2) && (!self->alert || self->alert > WINDOW_ALERT_1) ) self->alert = WINDOW_ALERT_2; } - if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) || - ((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) )) + if (notifications_are_disabled(flags)) return -1; #ifdef _BOX_NOTIFY From a9b0028a154b81de68727d06f58951cac5f1c82b Mon Sep 17 00:00:00 2001 From: Andriy Voskoboinyk Date: Thu, 4 Sep 2014 01:38:08 +0300 Subject: [PATCH 2/2] move some code inside _X11 ifdef --- src/notify.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/notify.c b/src/notify.c index 81e783d..af55562 100644 --- a/src/notify.c +++ b/src/notify.c @@ -67,9 +67,9 @@ extern struct user_settings *user_settings_; struct _Control { time_t cooldown; time_t notif_timeout; - unsigned long this_window; #ifdef _X11 Display *display; + unsigned long this_window; #endif /* _X11 */ #if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY) @@ -105,24 +105,26 @@ struct _ActiveNotifications { /**********************************************************************************/ /**********************************************************************************/ +#ifdef _X11 long unsigned int get_focused_window_id() { -#ifdef _X11 if (!Control.display) return 0; Window focus; int revert; XGetInputFocus(Control.display, &focus, &revert); return focus; -#else - return 0; -#endif /* _X11 */ } +#endif /* _X11 */ static _Bool notifications_are_disabled(const uint64_t flags) { return ( (flags & NT_RESTOL && Control.cooldown > time(NULL)) || +#ifdef _X11 (flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ); +#else + 0 ); +#endif } static void control_lock() @@ -323,8 +325,6 @@ int init_notify(int login_cooldown, int notification_timeout) #ifdef _X11 Control.display = XOpenDisplay(NULL); Control.this_window = get_focused_window_id(); -#else - Control.this_window = 1; #endif /* _X11 */