1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2016-04-18 00:37:49 +01:00
commit ae14d46739
4 changed files with 52 additions and 30 deletions

View File

@ -5546,9 +5546,9 @@ cmd_tray(ProfWin *window, const char *const command, gchar **args)
gboolean new = prefs_get_boolean(PREF_TRAY); gboolean new = prefs_get_boolean(PREF_TRAY);
if (old != new) { if (old != new) {
if (new) { if (new) {
create_tray(); tray_enable();
} else { } else {
destroy_tray(); tray_disable();
} }
} }
return TRUE; return TRUE;

View File

@ -38,7 +38,6 @@
#endif #endif
#ifdef HAVE_GTK #ifdef HAVE_GTK
#include <gtk/gtk.h>
#include "tray.h" #include "tray.h"
#endif #endif
#include <locale.h> #include <locale.h>
@ -96,21 +95,10 @@ char *saved_status;
static gboolean cont = TRUE; static gboolean cont = TRUE;
static gboolean force_quit = FALSE; static gboolean force_quit = FALSE;
#ifdef HAVE_GTK
static gboolean gtk_ready = FALSE;
#endif
void void
prof_run(char *log_level, char *account_name) prof_run(char *log_level, char *account_name)
{ {
#ifdef HAVE_GTK
gtk_ready = gtk_init_check(0, NULL);
log_debug("Env is GTK-ready: %s", gtk_ready ? "true" : "false");
if (gtk_ready) {
gtk_init(0, NULL);
gtk_main_iteration_do(FALSE);
}
#endif
_init(log_level); _init(log_level);
plugins_on_start(); plugins_on_start();
_connect_default(account_name); _connect_default(account_name);
@ -146,9 +134,7 @@ prof_run(char *log_level, char *account_name)
iq_autoping_check(); iq_autoping_check();
ui_update(); ui_update();
#ifdef HAVE_GTK #ifdef HAVE_GTK
if (gtk_ready) { tray_update();
gtk_main_iteration_do(FALSE);
}
#endif #endif
} }
} }
@ -373,10 +359,7 @@ _init(char *log_level)
atexit(_shutdown); atexit(_shutdown);
plugins_init(); plugins_init();
#ifdef HAVE_GTK #ifdef HAVE_GTK
if (gtk_ready && prefs_get_boolean(PREF_TRAY)) { tray_init();
log_debug("Building GTK icon");
create_tray();
}
#endif #endif
inp_nonblocking(TRUE); inp_nonblocking(TRUE);
} }
@ -397,9 +380,7 @@ _shutdown(void)
cl_ev_disconnect(); cl_ev_disconnect();
} }
#ifdef HAVE_GTK #ifdef HAVE_GTK
if (gtk_ready && prefs_get_boolean(PREF_TRAY)) { tray_shutdown();
destroy_tray();
}
#endif #endif
jabber_shutdown(); jabber_shutdown();
plugins_on_shutdown(); plugins_on_shutdown();

View File

@ -42,7 +42,9 @@
#include "tray.h" #include "tray.h"
#include "window_list.h" #include "window_list.h"
#include "log.h" #include "log.h"
#include "config/preferences.h"
static gboolean gtk_ready = FALSE;
static GtkStatusIcon *prof_tray = NULL; static GtkStatusIcon *prof_tray = NULL;
static GString *icon_filename = NULL; static GString *icon_filename = NULL;
static GString *icon_msg_filename = NULL; static GString *icon_msg_filename = NULL;
@ -141,16 +143,53 @@ _tray_change_icon(gpointer data)
/* {{{ Public */ /* {{{ Public */
void void
create_tray(void) tray_init(void)
{ {
_get_icons(); _get_icons();
gtk_ready = gtk_init_check(0, NULL);
log_debug("Env is GTK-ready: %s", gtk_ready ? "true" : "false");
if (!gtk_ready) {
return;
}
gtk_init(0, NULL);
if (prefs_get_boolean(PREF_TRAY)) {
log_debug("Building GTK icon");
tray_enable();
}
gtk_main_iteration_do(FALSE);
}
void
tray_update(void)
{
if (gtk_ready) {
gtk_main_iteration_do(FALSE);
}
}
void
tray_shutdown(void)
{
if (gtk_ready && prefs_get_boolean(PREF_TRAY)) {
tray_disable();
}
g_string_free(icon_filename, TRUE);
g_string_free(icon_msg_filename, TRUE);
}
void
tray_enable(void)
{
prof_tray = gtk_status_icon_new_from_file(icon_filename->str); prof_tray = gtk_status_icon_new_from_file(icon_filename->str);
shutting_down = FALSE; shutting_down = FALSE;
_tray_change_icon(NULL);
timer = g_timeout_add(5000, _tray_change_icon, NULL); timer = g_timeout_add(5000, _tray_change_icon, NULL);
} }
void void
destroy_tray(void) tray_disable(void)
{ {
shutting_down = TRUE; shutting_down = TRUE;
g_source_remove(timer); g_source_remove(timer);
@ -158,8 +197,6 @@ destroy_tray(void)
g_clear_object(&prof_tray); g_clear_object(&prof_tray);
prof_tray = NULL; prof_tray = NULL;
} }
g_string_free(icon_filename, TRUE);
g_string_free(icon_msg_filename, TRUE);
} }
/* }}} */ /* }}} */

View File

@ -35,16 +35,20 @@
#ifndef PROFANITY_TRAY_H #ifndef PROFANITY_TRAY_H
#define PROFANITY_TRAY_H #define PROFANITY_TRAY_H
void tray_init(void);
void tray_update(void);
void tray_shutdown(void);
/* /*
* Create tray icon * Create tray icon
* *
* This will initialize the timer that will be called in order to change the icons * This will initialize the timer that will be called in order to change the icons
* and will search the icons in the defaults paths * and will search the icons in the defaults paths
*/ */
void create_tray(void); void tray_enable(void);
/* /*
* Destroy tray icon * Destroy tray icon
*/ */
void destroy_tray(void); void tray_disable(void);
#endif #endif