mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 15:53:26 +01:00
commit
0ef888eea3
36
src/notify.c
36
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,18 +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 */
|
||||
|
||||
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()
|
||||
@ -317,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 */
|
||||
|
||||
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user