From 4cb1d73a8358f660056156b5632e8c41659eb6e0 Mon Sep 17 00:00:00 2001 From: Dominik Heidler Date: Sat, 16 Apr 2016 16:29:32 +0200 Subject: [PATCH] Make tray icon configurable using /tray cmd --- src/command/command.c | 15 +++++++++++++++ src/command/commands.c | 21 +++++++++++++++++++++ src/command/commands.h | 3 +++ src/config/preferences.c | 11 +++++++++++ src/config/preferences.h | 3 +++ src/profanity.c | 4 ++-- src/ui/console.c | 14 ++++++++++++++ src/ui/ui.h | 3 +++ 8 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 191415ae..e94d3406 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1253,6 +1253,21 @@ static struct cmd_t command_defs[] = CMD_NOEXAMPLES }, +#ifdef HAVE_GTK + { "/tray", + cmd_tray, parse_args, 1, 1, &cons_tray_setting, + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/tray on|off") + CMD_DESC( + "Display an icon in the tray that will indicate new messages.") + CMD_ARGS( + { "on|off", "Enable or disable tray icon." }) + CMD_NOEXAMPLES + }, +#endif + { "/intype", cmd_intype, parse_args, 1, 1, &cons_intype_setting, CMD_TAGS( diff --git a/src/command/commands.c b/src/command/commands.c index 8d32237b..b2795a43 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -77,6 +77,9 @@ #include "ui/ui.h" #include "window_list.h" #include "event/client_events.h" +#ifdef HAVE_GTK +#include "tray.h" +#endif static void _update_presence(const resource_presence_t presence, const char *const show, gchar **args); @@ -5525,6 +5528,24 @@ cmd_flash(ProfWin *window, const char *const command, gchar **args) return _cmd_set_boolean_preference(args[0], command, "Screen flash", PREF_FLASH); } +#ifdef HAVE_GTK +gboolean +cmd_tray(ProfWin *window, const char *const command, gchar **args) +{ + gboolean old = prefs_get_boolean(PREF_TRAY); + gboolean ret = _cmd_set_boolean_preference(args[0], command, "Tray icon", PREF_TRAY); + gboolean new = prefs_get_boolean(PREF_TRAY); + if (old != new) { + if (new) { + create_tray(); + } else { + destroy_tray(); + } + } + return ret; +} +#endif + gboolean cmd_intype(ProfWin *window, const char *const command, gchar **args) { diff --git a/src/command/commands.h b/src/command/commands.h index 3e1a4592..34c9cc49 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -89,6 +89,9 @@ gboolean cmd_lastactivity(ProfWin *window, const char *const command, gchar **ar gboolean cmd_disconnect(ProfWin *window, const char *const command, gchar **args); gboolean cmd_dnd(ProfWin *window, const char *const command, gchar **args); gboolean cmd_flash(ProfWin *window, const char *const command, gchar **args); +#ifdef HAVE_GTK +gboolean cmd_tray(ProfWin *window, const char *const command, gchar **args); +#endif gboolean cmd_gone(ProfWin *window, const char *const command, gchar **args); gboolean cmd_grlog(ProfWin *window, const char *const command, gchar **args); gboolean cmd_group(ProfWin *window, const char *const command, gchar **args); diff --git a/src/config/preferences.c b/src/config/preferences.c index 0ad95dc4..4f403888 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -47,6 +47,10 @@ #include "tools/autocomplete.h" #include "config/conflists.h" +#ifdef HAVE_GTK +#include "tray.h" +#endif + // preference groups refer to the sections in .profrc, for example [ui] #define PREF_GROUP_LOGGING "logging" #define PREF_GROUP_CHATSTATES "chatstates" @@ -1171,6 +1175,9 @@ _get_group(preference_t pref) case PREF_TITLEBAR_SHOW: case PREF_TITLEBAR_GOODBYE: case PREF_FLASH: +#ifdef HAVE_GTK + case PREF_TRAY: +#endif case PREF_INTYPE: case PREF_HISTORY: case PREF_OCCUPANTS: @@ -1289,6 +1296,10 @@ _get_key(preference_t pref) return "titlebar.goodbye"; case PREF_FLASH: return "flash"; +#ifdef HAVE_GTK + case PREF_TRAY: + return "tray"; +#endif case PREF_INTYPE: return "intype"; case PREF_HISTORY: diff --git a/src/config/preferences.h b/src/config/preferences.h index 287e56d3..eb749b16 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -52,6 +52,9 @@ typedef enum { PREF_TITLEBAR_SHOW, PREF_TITLEBAR_GOODBYE, PREF_FLASH, +#ifdef HAVE_GTK + PREF_TRAY, +#endif PREF_INTYPE, PREF_HISTORY, PREF_CARBONS, diff --git a/src/profanity.c b/src/profanity.c index 2595f5f7..4ca649cd 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -373,7 +373,7 @@ _init(char *log_level) atexit(_shutdown); plugins_init(); #ifdef HAVE_GTK - if (gtk_ready) { + if (gtk_ready && prefs_get_boolean(PREF_TRAY)) { log_debug("Building GTK icon"); create_tray(); } @@ -397,7 +397,7 @@ _shutdown(void) cl_ev_disconnect(); } #ifdef HAVE_GTK - if (gtk_ready) { + if (gtk_ready && prefs_get_boolean(PREF_TRAY)) { destroy_tray(); } #endif diff --git a/src/ui/console.c b/src/ui/console.c index c104e21b..73cfbfd1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1182,6 +1182,17 @@ cons_flash_setting(void) cons_show("Terminal flash (/flash) : OFF"); } +#ifdef HAVE_GTK +void +cons_tray_setting(void) +{ + if (prefs_get_boolean(PREF_TRAY)) + cons_show("Tray icon (/tray) : ON"); + else + cons_show("Tray icon (/tray) : OFF"); +} +#endif + void cons_splash_setting(void) { @@ -1497,6 +1508,9 @@ cons_show_ui_prefs(void) cons_theme_setting(); cons_beep_setting(); cons_flash_setting(); +#ifdef HAVE_GTK + cons_tray_setting(); +#endif cons_splash_setting(); cons_wrap_setting(); cons_winstidy_setting(); diff --git a/src/ui/ui.h b/src/ui/ui.h index 924ba33c..09215595 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -284,6 +284,9 @@ void cons_privileges_setting(void); void cons_beep_setting(void); void cons_console_setting(void); void cons_flash_setting(void); +#ifdef HAVE_GTK +void cons_tray_setting(void); +#endif void cons_splash_setting(void); void cons_encwarn_setting(void); void cons_tlsshow_setting(void);