Skip to content

Commit

Permalink
Allow notification timeout to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
konsolebox committed Jul 10, 2024
1 parent 5ba3131 commit 2d31a36
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/common/cfgfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ const struct prefs vars[] =
{"gui_lagometer", P_OFFINT (hex_gui_lagometer), TYPE_INT},
{"gui_lang", P_OFFINT (hex_gui_lang), TYPE_INT},
{"gui_mode_buttons", P_OFFINT (hex_gui_mode_buttons), TYPE_BOOL},
{"gui_notification_timeout", P_OFFINT (hex_gui_notification_timeout), TYPE_INT},
{"gui_pane_divider_position", P_OFFINT (hex_gui_pane_divider_position), TYPE_INT},
{"gui_pane_left_size", P_OFFINT (hex_gui_pane_left_size), TYPE_INT},
{"gui_pane_right_size", P_OFFINT (hex_gui_pane_right_size), TYPE_INT},
Expand Down Expand Up @@ -826,6 +827,7 @@ load_default_config(void)
prefs.hex_gui_dialog_width = 500;
prefs.hex_gui_lagometer = 1;
prefs.hex_gui_lang = get_default_language();
prefs.hex_gui_notification_timeout = 0;
prefs.hex_gui_pane_left_size = 128; /* with treeview icons we need a bit bigger space */
prefs.hex_gui_pane_right_size = 100;
prefs.hex_gui_pane_right_size_min = 80;
Expand Down
1 change: 1 addition & 0 deletions src/common/hexchat.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ struct hexchatprefs
int hex_gui_dialog_width;
int hex_gui_lagometer;
int hex_gui_lang;
int hex_gui_notification_timeout;
int hex_gui_pane_divider_position;
int hex_gui_pane_left_size;
int hex_gui_pane_right_size;
Expand Down
2 changes: 1 addition & 1 deletion src/fe-gtk/notifications/notification-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define HEXCHAT_PLUGIN_NOTIFICATION_BACKEND_H

int notification_backend_supported (void);
void notification_backend_show (const char *title, const char *text);
void notification_backend_show (const char *title, const char *text, int notification_timeout);
int notification_backend_init (const char **error);
void notification_backend_deinit (void);

Expand Down
2 changes: 1 addition & 1 deletion src/fe-gtk/notifications/notification-dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

void
notification_backend_show (const char *title, const char *text)
notification_backend_show (const char *title, const char *text, int notification_timeout)
{
}

Expand Down
6 changes: 4 additions & 2 deletions src/fe-gtk/notifications/notification-freedesktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ on_notify_ready (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
}

void
notification_backend_show (const char *title, const char *text)
notification_backend_show (const char *title, const char *text, int notification_timeout)
{
GVariantBuilder params;

Expand All @@ -69,7 +69,9 @@ notification_backend_show (const char *title, const char *text)
g_variant_builder_close (&params);
g_variant_builder_close (&params);

g_variant_builder_add (&params, "i", -1); /* Expiration */
/* Expiration */
g_variant_builder_add (&params, "i",
notification_timeout > 0 ? notification_timeout : -1);

g_dbus_proxy_call (fdo_notifications,
"Notify",
Expand Down
2 changes: 1 addition & 1 deletion src/fe-gtk/notifications/notification-osx.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <gtkosxapplication.h>

void
notification_backend_show (const char *title, const char *text)
notification_backend_show (const char *title, const char *text, int notification_timeout)
{
NSString *str_title = [[NSString alloc] initWithUTF8String:title];
NSString *str_text = [[NSString alloc] initWithUTF8String:text];
Expand Down
2 changes: 1 addition & 1 deletion src/fe-gtk/notifications/notification-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void (*winrt_notification_backend_deinit) (void) = NULL;
int (*winrt_notification_backend_supported) (void) = NULL;

void
notification_backend_show (const char *title, const char *text)
notification_backend_show (const char *title, const char *text, int notification_timeout)
{
if (winrt_notification_backend_show == NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion src/fe-gtk/notifications/notification-winrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ narrow(const std::wstring & to_narrow)
extern "C"
{
__declspec (dllexport) void
notification_backend_show (const char *title, const char *text)
notification_backend_show (const char *title, const char *text, int notification_timeout)
{
try
{
Expand Down
8 changes: 6 additions & 2 deletions src/fe-gtk/plugin-notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ static void
show_notification (const char *title, const char *text)
{
char *stripped_title, *stripped_text;
int notification_timeout;

/* Strip all colors */
stripped_title = hexchat_strip (ph, title, -1, 7);
stripped_text = hexchat_strip (ph, text, -1, 7);

notification_backend_show (stripped_title, stripped_text);

if (hexchat_get_prefs (ph, "gui_notification_timeout", NULL, &notification_timeout) != 3)
notification_timeout = 0;

notification_backend_show (stripped_title, stripped_text, notification_timeout);

hexchat_free (ph, stripped_title);
hexchat_free (ph, stripped_text);
Expand Down
4 changes: 4 additions & 0 deletions src/fe-gtk/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ static const setting alert_settings[] =
{ST_TOGGLE, N_("Close to tray"), P_OFFINTNL(hex_gui_tray_close), 0, 0, 0},
{ST_TOGGLE, N_("Automatically mark away/back"), P_OFFINTNL(hex_gui_tray_away), N_("Automatically change status when hiding to tray."), 0, 0},
{ST_TOGGLE, N_("Only show notifications when hidden or iconified"), P_OFFINTNL(hex_gui_tray_quiet), 0, 0, 0},
#ifndef WIN32 // Based on meson.build:46
{ST_NUMBER, N_("Notification timeout:"), P_OFFINTNL(hex_gui_notification_timeout), 0,
(const char **)N_("0 = backend default"), 1000},
#endif

{ST_HEADER, N_("Highlighted Messages"),0,0,0},
{ST_LABEL, N_("Highlighted messages are ones where your nickname is mentioned, but also:"), 0, 0, 0, 1},
Expand Down

0 comments on commit 2d31a36

Please sign in to comment.