1 /* Notification plugin for Claws Mail
2 * Copyright (C) 2005-2009 Holger Berndt and the Claws Mail Team.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # include "claws-features.h"
23 #ifdef NOTIFICATION_HOTKEYS
25 #include "notification_hotkeys.h"
26 #include "notification_prefs.h"
27 #include "notification_core.h"
29 #include "gtkhotkey.h"
31 #define HOTKEYS_APP_ID "claws-mail"
32 #define HOTKEY_KEY_ID_TOGGLED "toggle-mainwindow"
34 static GtkHotkeyInfo
*hotkey_toggle_mainwindow
= NULL
;
36 static void hotkey_toggle_mainwindow_activated(GtkHotkeyInfo
*hotkey
, guint event_time
, gpointer data
)
38 g_return_if_fail(GTK_HOTKEY_IS_INFO(hotkey
));
39 debug_print("Notification plugin: Toggled hide/show window due to hotkey %s activation\n", gtk_hotkey_info_get_signature(hotkey
));
40 notification_toggle_hide_show_window();
43 static void unbind_toggle_mainwindow()
46 GtkHotkeyRegistry
*registry
;
48 /* clean up old hotkey */
49 if(hotkey_toggle_mainwindow
) {
50 if(gtk_hotkey_info_is_bound(hotkey_toggle_mainwindow
)) {
52 gtk_hotkey_info_unbind(hotkey_toggle_mainwindow
, &error
);
54 debug_print("Notification plugin: Failed to unbind toggle hotkey\n");
59 g_object_unref(hotkey_toggle_mainwindow
);
60 hotkey_toggle_mainwindow
= NULL
;
62 registry
= gtk_hotkey_registry_get_default();
63 if(gtk_hotkey_registry_has_hotkey(registry
, HOTKEYS_APP_ID
, HOTKEY_KEY_ID_TOGGLED
)) {
65 gtk_hotkey_registry_delete_hotkey(registry
, HOTKEYS_APP_ID
, HOTKEY_KEY_ID_TOGGLED
, &error
);
67 debug_print("Notification plugin: Failed to unregister toggle hotkey: %s\n", error
->message
);
74 static void update_hotkey_binding_toggle_mainwindow()
78 /* don't do anything if no signature is given */
79 if(!notify_config
.hotkeys_toggle_mainwindow
|| !strcmp(notify_config
.hotkeys_toggle_mainwindow
, ""))
82 unbind_toggle_mainwindow();
84 /* (re)create hotkey info */
85 hotkey_toggle_mainwindow
= gtk_hotkey_info_new(HOTKEYS_APP_ID
, HOTKEY_KEY_ID_TOGGLED
, notify_config
.hotkeys_toggle_mainwindow
, NULL
);
86 if(!hotkey_toggle_mainwindow
) {
87 debug_print("Notification plugin: Failed to create toggle hotkey for '%s'\n", notify_config
.hotkeys_toggle_mainwindow
);
91 /* try to register hotkey */
93 gtk_hotkey_info_bind(hotkey_toggle_mainwindow
, &error
);
95 debug_print("Notification plugin: Failed to bind toggle hotkey to '%s': %s\n", notify_config
.hotkeys_toggle_mainwindow
, error
->message
);
100 g_signal_connect(hotkey_toggle_mainwindow
, "activated", G_CALLBACK(hotkey_toggle_mainwindow_activated
), NULL
);
103 void notification_hotkeys_update_bindings()
105 debug_print("Notification plugin: Updating keybindings..\n");
106 if(notify_config
.hotkeys_enabled
) {
107 update_hotkey_binding_toggle_mainwindow();
110 notification_hotkeys_unbind_all();
113 void notification_hotkeys_unbind_all()
115 debug_print("Notification plugin: Unbinding all keybindings..\n");
116 unbind_toggle_mainwindow();
119 #endif /* NOTIFICATION_HOTKEYS */