mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 19:53:25 +01:00
commit
0ef888eea3
36
src/notify.c
36
src/notify.c
@ -67,9 +67,9 @@ extern struct user_settings *user_settings_;
|
|||||||
struct _Control {
|
struct _Control {
|
||||||
time_t cooldown;
|
time_t cooldown;
|
||||||
time_t notif_timeout;
|
time_t notif_timeout;
|
||||||
unsigned long this_window;
|
|
||||||
#ifdef _X11
|
#ifdef _X11
|
||||||
Display *display;
|
Display *display;
|
||||||
|
unsigned long this_window;
|
||||||
#endif /* _X11 */
|
#endif /* _X11 */
|
||||||
|
|
||||||
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
|
#if defined(_SOUND_NOTIFY) || defined(_BOX_NOTIFY)
|
||||||
@ -105,18 +105,26 @@ struct _ActiveNotifications {
|
|||||||
/**********************************************************************************/
|
/**********************************************************************************/
|
||||||
/**********************************************************************************/
|
/**********************************************************************************/
|
||||||
|
|
||||||
|
#ifdef _X11
|
||||||
long unsigned int get_focused_window_id()
|
long unsigned int get_focused_window_id()
|
||||||
{
|
{
|
||||||
#ifdef _X11
|
|
||||||
if (!Control.display) return 0;
|
if (!Control.display) return 0;
|
||||||
|
|
||||||
Window focus;
|
Window focus;
|
||||||
int revert;
|
int revert;
|
||||||
XGetInputFocus(Control.display, &focus, &revert);
|
XGetInputFocus(Control.display, &focus, &revert);
|
||||||
return focus;
|
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()
|
static void control_lock()
|
||||||
@ -317,8 +325,6 @@ int init_notify(int login_cooldown, int notification_timeout)
|
|||||||
#ifdef _X11
|
#ifdef _X11
|
||||||
Control.display = XOpenDisplay(NULL);
|
Control.display = XOpenDisplay(NULL);
|
||||||
Control.this_window = get_focused_window_id();
|
Control.this_window = get_focused_window_id();
|
||||||
#else
|
|
||||||
Control.this_window = 1;
|
|
||||||
#endif /* _X11 */
|
#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;
|
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)) ||
|
if (notifications_are_disabled(flags))
|
||||||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int id = -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;
|
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)) ||
|
if (notifications_are_disabled(flags))
|
||||||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (id < 0 || id >= ACTIVE_NOTIFS_MAX) 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, ...)
|
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)) ||
|
if (notifications_are_disabled(flags))
|
||||||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef _BOX_NOTIFY
|
#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, ...)
|
int box_notify2(ToxWindow* self, Notification notif, uint64_t flags, int id, const char* format, ...)
|
||||||
{
|
{
|
||||||
if ((flags & NT_RESTOL && Control.cooldown > time(NULL)) ||
|
if (notifications_are_disabled(flags))
|
||||||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef _BOX_NOTIFY
|
#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;
|
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)) ||
|
if (notifications_are_disabled(flags))
|
||||||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef _BOX_NOTIFY
|
#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;
|
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)) ||
|
if (notifications_are_disabled(flags))
|
||||||
((flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) ))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef _BOX_NOTIFY
|
#ifdef _BOX_NOTIFY
|
||||||
|
Loading…
Reference in New Issue
Block a user