From d5710d80e0d4b526d79440ef65d329e9898573d0 Mon Sep 17 00:00:00 2001 From: mannol Date: Mon, 28 Jul 2014 01:35:40 +0200 Subject: [PATCH] Upstream adaption --- src/audio_call.c | 3 +- src/notify.c | 106 ++++++++++++++++++++++++++++++++++++++++------- src/notify.h | 3 +- src/toxic.c | 4 +- 4 files changed, 94 insertions(+), 22 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index 65745fc..aa57f9a 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -107,7 +107,6 @@ ToxAv *init_audio(ToxWindow *self, Tox *tox) { ASettins.cs = av_DefaultSettings; ASettins.cs.max_video_height = ASettins.cs.max_video_width = 0; - ASettins.cs.audio_channels = 1; ASettins.errors = ae_None; @@ -186,7 +185,7 @@ int start_transmission(ToxWindow *self) if ( !ASettins.av || self->call_idx == -1 ) return -1; /* Don't provide support for video */ - if ( 0 != toxav_prepare_transmission(ASettins.av, self->call_idx, av_jbufdc, av_VADd, 0) ) { + if ( 0 != toxav_prepare_transmission(ASettins.av, self->call_idx, av_jbufdc * 2, av_VADd, 0) ) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Could not prepare transmission"); } diff --git a/src/notify.c b/src/notify.c index 1a47ff9..6872d0b 100644 --- a/src/notify.c +++ b/src/notify.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #ifdef _AUDIO @@ -87,6 +88,10 @@ struct _ActiveNotifications { #ifdef _BOX_NOTIFY NotifyNotification* box; + char messages[128][128]; + char title[24]; + size_t size; + time_t timeout; #endif } actives[ACTIVE_NOTIFS_MAX] = {{0}}; /**********************************************************************************/ @@ -126,6 +131,13 @@ void graceful_clear() while (1) { for (i = 0; i < ACTIVE_NOTIFS_MAX; i ++) { if (actives[i].active) { + #ifdef _BOX_NOTIFY + if (actives[i].box) { + notify_notification_close(actives[i].box, NULL); + memset(&actives[i], 0, sizeof(struct _ActiveNotifications)); + } + #endif + if ( actives[i].looping ) { stop_sound(i); } else { @@ -166,7 +178,22 @@ void* do_playing(void* _p) alDeleteBuffers(1,&actives[i].buffer); memset(&actives[i], 0, sizeof(struct _ActiveNotifications)); } + } + #ifdef _BOX_NOTIFY + else if (actives[i].box && !actives[i].looping && + time(NULL) >= actives[i].timeout && !is_playing(actives[i].source)) + { + alSourceStop(actives[i].source); + alDeleteSources(1, &actives[i].source); + alDeleteBuffers(1,&actives[i].buffer); + memset(&actives[i], 0, sizeof(struct _ActiveNotifications)); + + GError* ignore; + notify_notification_close(actives[i].box, &ignore); + memset(&actives[i], 0, sizeof(struct _ActiveNotifications)); + assert(0); } + #endif } pthread_mutex_unlock(Control.poll_mutex); usleep(10000); @@ -363,8 +390,9 @@ int box_notify(ToxWindow* self, Notification notif, uint64_t flags, char* title, #ifdef _BOX_NOTIFY int id = notify(self, notif, flags); - if (id == -1) { /* Could not play */ - pthread_mutex_lock(Control.poll_mutex); + pthread_mutex_lock(Control.poll_mutex); + + if (id == -1 && !(flags & NT_NOFOCUS && Control.this_window == get_focused_window_id())) { /* Could not play */ for (id = 0; id < ACTIVE_NOTIFS_MAX && actives[id].active; id ++); if ( id == ACTIVE_NOTIFS_MAX ) { @@ -372,33 +400,79 @@ int box_notify(ToxWindow* self, Notification notif, uint64_t flags, char* title, return -1; /* Full */ } - pthread_mutex_unlock(Control.poll_mutex); + actives[id].active = 1; } - - char title_compact [24] = {'\0'}; - strncpy(title_compact, title, 24); - if (strlen(title) > 23) strcpy(title_compact + 20, "..."); + + strncpy(actives[id].title, title, 24); + if (strlen(title) > 23) strcpy(actives[id].title + 20, "..."); - char msg_compact [128] = {'\0'}; - va_list __ARGS__; - va_start (__ARGS__, format); - snprintf (msg_compact, 127, format, __ARGS__); + va_list __ARGS__; va_start (__ARGS__, format); + snprintf (actives[id].messages[0], 127, format, __ARGS__); va_end (__ARGS__); - if (strlen(msg_compact) > 124) strcpy(msg_compact + 124, "..."); + if (strlen(actives[id].messages[0]) > 124) + strcpy(actives[id].messages[0] + 124, "..."); + + actives[id].box = notify_notification_new(actives[id].title, actives[id].messages[0], NULL); + actives[id].size ++; + actives[id].timeout = time(NULL) + Control.notif_timeout; - actives[id].active = 1; - actives[id].box = notify_notification_new(title_compact, msg_compact, NULL); notify_notification_set_timeout(actives[id].box, Control.notif_timeout); notify_notification_show(actives[id].box, NULL); + pthread_mutex_unlock(Control.poll_mutex); return id; #else return notify(self, notif, flags); #endif } -int box_notify_append(int id, char* format, ...) +int box_notify_append(ToxWindow* self, Notification notif, uint64_t flags, int id, char* format, ...) { - return 0; +#ifdef _BOX_NOTIFY + if (id < 0 || id >= ACTIVE_NOTIFS_MAX || !actives[id].box || actives[id].size >= 128 ) return -1; + + /* Consider colored notify as primary */ + if (self && self->alert == WINDOW_ALERT_NONE) { + if (flags & NT_WNDALERT_0) self->alert = WINDOW_ALERT_0; + else if (flags & NT_WNDALERT_1) self->alert = WINDOW_ALERT_1; + else if (flags & NT_WNDALERT_2) self->alert = WINDOW_ALERT_2; + } + if (flags & NT_NOFOCUS && Control.this_window == get_focused_window_id()) + return -1; + + pthread_mutex_lock(Control.poll_mutex); + + /* Play the sound again */ + alSourcePlay(actives[id].source); + + va_list __ARGS__; va_start (__ARGS__, format); + snprintf (actives[id].messages[actives[id].size], 127, format, __ARGS__); + va_end (__ARGS__); + + if (strlen(actives[id].messages[actives[id].size]) > 124) + strcpy(actives[id].messages[actives[id].size] + 124, "..."); + + actives[id].size ++; + actives[id].timeout = time(NULL) + Control.notif_timeout; + + char formated[128 * 129] = {'\0'}; + + int i = 0; + for (; i