2013-02-20 [colin] 3.9.0cvs85

* configure.ac
		Rework plugin enabling logic. More clean!
	* src/plugins/fancy/fancy_viewer.c
	* src/plugins/fancy/fancy_viewer.h
	* src/plugins/spam_report/spam_report.c
		Make curl dependancy mandatory
	* src/plugins/notification/notification_plugin.c
		Fix build with every possible thing disabled
	* src/plugins/notification/Makefile.am
	* src/plugins/notification/gtkhotkey/.cvsignore
	* src/plugins/notification/gtkhotkey/Makefile.am
	* src/plugins/notification/gtkhotkey/gtk-hotkey-error.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-error.h
	* src/plugins/notification/gtkhotkey/gtk-hotkey-info.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-info.h
	* src/plugins/notification/gtkhotkey/gtk-hotkey-key-file-registry.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-key-file-registry.h
	* src/plugins/notification/gtkhotkey/gtk-hotkey-listener.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-listener.h
	* src/plugins/notification/gtkhotkey/gtk-hotkey-marshal.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-marshal.h
	* src/plugins/notification/gtkhotkey/gtk-hotkey-registry.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-registry.h
	* src/plugins/notification/gtkhotkey/gtk-hotkey-utils.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-utils.h
	* src/plugins/notification/gtkhotkey/gtk-hotkey-x11-listener.c
	* src/plugins/notification/gtkhotkey/gtk-hotkey-x11-listener.h
	* src/plugins/notification/gtkhotkey/gtkhotkey.h
	* src/plugins/notification/gtkhotkey/x11/eggaccelerators.c
	* src/plugins/notification/gtkhotkey/x11/eggaccelerators.h
	* src/plugins/notification/gtkhotkey/x11/tomboykeybinder.c
	* src/plugins/notification/gtkhotkey/x11/tomboykeybinder.h
		Re-add hotkey support
	* src/plugins/spam_report/Makefile.am
	* src/plugins/tnef_parse/Makefile.am
		Remove gettext.h
This commit is contained in:
Colin Leroy 2013-02-20 11:25:36 +00:00
parent fa12fb431e
commit a0e9ba8a56
33 changed files with 5004 additions and 575 deletions

View file

@ -1,3 +1,42 @@
2013-02-20 [colin] 3.9.0cvs85
* configure.ac
Rework plugin enabling logic. More clean!
* src/plugins/fancy/fancy_viewer.c
* src/plugins/fancy/fancy_viewer.h
* src/plugins/spam_report/spam_report.c
Make curl dependancy mandatory
* src/plugins/notification/notification_plugin.c
Fix build with every possible thing disabled
* src/plugins/notification/Makefile.am
* src/plugins/notification/gtkhotkey/.cvsignore
* src/plugins/notification/gtkhotkey/Makefile.am
* src/plugins/notification/gtkhotkey/gtk-hotkey-error.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-error.h
* src/plugins/notification/gtkhotkey/gtk-hotkey-info.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-info.h
* src/plugins/notification/gtkhotkey/gtk-hotkey-key-file-registry.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-key-file-registry.h
* src/plugins/notification/gtkhotkey/gtk-hotkey-listener.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-listener.h
* src/plugins/notification/gtkhotkey/gtk-hotkey-marshal.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-marshal.h
* src/plugins/notification/gtkhotkey/gtk-hotkey-registry.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-registry.h
* src/plugins/notification/gtkhotkey/gtk-hotkey-utils.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-utils.h
* src/plugins/notification/gtkhotkey/gtk-hotkey-x11-listener.c
* src/plugins/notification/gtkhotkey/gtk-hotkey-x11-listener.h
* src/plugins/notification/gtkhotkey/gtkhotkey.h
* src/plugins/notification/gtkhotkey/x11/eggaccelerators.c
* src/plugins/notification/gtkhotkey/x11/eggaccelerators.h
* src/plugins/notification/gtkhotkey/x11/tomboykeybinder.c
* src/plugins/notification/gtkhotkey/x11/tomboykeybinder.h
Re-add hotkey support
* src/plugins/spam_report/Makefile.am
* src/plugins/tnef_parse/Makefile.am
Remove gettext.h
2013-02-20 [colin] 3.9.0cvs84
* configure.ac

View file

@ -4582,3 +4582,4 @@
( cvs diff -u -r 1.1.2.7 -r 1.1.2.8 src/plugins/bogofilter/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/clamd/Makefile.am; cvs diff -u -r 1.3.2.4 -r 1.3.2.5 src/plugins/demo/Makefile.am; cvs diff -u -r 1.4.2.9 -r 1.4.2.10 src/plugins/dillo_viewer/Makefile.am; cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/plugins/fancy/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/fetchinfo/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/gdata/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/mailmbox/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/newmail/Makefile.am; cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/plugins/notification/Makefile.am; cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/plugins/pdf_viewer/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/perl/Makefile.am; cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/plugins/python/Makefile.am; cvs diff -u -r 1.5.2.10 -r 1.5.2.11 src/plugins/spamassassin/Makefile.am; cvs diff -u -r 1.4.2.14 -r 1.4.2.15 src/plugins/trayicon/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/vcalendar/libical/libical/Makefile.am; ) > 3.9.0cvs82.patchset
( cvs diff -u -r 1.654.2.4659 -r 1.654.2.4660 configure.ac; cvs diff -u -r 1.8.2.14 -r 1.8.2.15 src/plugins/Makefile.am; diff -u /dev/null src/plugins/spam_report/.cvsignore; diff -u /dev/null src/plugins/spam_report/Makefile.am; cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/spam_report/placeholder.txt; diff -u /dev/null src/plugins/spam_report/spam_report.c; diff -u /dev/null src/plugins/spam_report/spam_report_prefs.c; diff -u /dev/null src/plugins/spam_report/spam_report_prefs.h; diff -u /dev/null src/plugins/tnef_parse/.cvsignore; diff -u /dev/null src/plugins/tnef_parse/Makefile.am; diff -u /dev/null src/plugins/tnef_parse/claws.def; diff -u /dev/null src/plugins/tnef_parse/mapi.h; diff -u /dev/null src/plugins/tnef_parse/mapidefs.h; diff -u /dev/null src/plugins/tnef_parse/mapitags.h; cvs diff -u -r -1.1.2.1 -r -1.1.2.2 src/plugins/tnef_parse/placeholder.txt; diff -u /dev/null src/plugins/tnef_parse/plugin.def; diff -u /dev/null src/plugins/tnef_parse/tnef-errors.h; diff -u /dev/null src/plugins/tnef_parse/tnef-types.h; diff -u /dev/null src/plugins/tnef_parse/tnef_dump.c; diff -u /dev/null src/plugins/tnef_parse/tnef_dump.h; diff -u /dev/null src/plugins/tnef_parse/tnef_parse.c; diff -u /dev/null src/plugins/tnef_parse/version.rc; diff -u /dev/null src/plugins/tnef_parse/ytnef.c; diff -u /dev/null src/plugins/tnef_parse/ytnef.h; ) > 3.9.0cvs83.patchset
( cvs diff -u -r 1.654.2.4660 -r 1.654.2.4661 configure.ac; cvs diff -u -r 1.53.2.46 -r 1.53.2.47 po/POTFILES.in; cvs diff -u -r 1.8.2.15 -r 1.8.2.16 src/plugins/Makefile.am; cvs diff -u -r -1.1 -r -1.2 src/plugins/dillo_viewer/.cvsignore; cvs diff -u -r -1.4.2.10 -r -1.4.2.11 src/plugins/dillo_viewer/Makefile.am; cvs diff -u -r -1.2.4.2 -r -1.2.4.3 src/plugins/dillo_viewer/README; cvs diff -u -r -1.5.2.30 -r -1.5.2.31 src/plugins/dillo_viewer/dillo_prefs.c; cvs diff -u -r -1.2.4.11 -r -1.2.4.12 src/plugins/dillo_viewer/dillo_prefs.h; cvs diff -u -r -1.12.2.32 -r -1.12.2.33 src/plugins/dillo_viewer/dillo_viewer.c; cvs diff -u -r -1.1 -r -1.2 src/plugins/trayicon/.cvsignore; cvs diff -u -r -1.4.2.15 -r -1.4.2.16 src/plugins/trayicon/Makefile.am; cvs diff -u -r -1.1.4.1 -r -1.1.4.2 src/plugins/trayicon/README; cvs diff -u -r -1.14.2.83 -r -1.14.2.84 src/plugins/trayicon/trayicon.c; cvs diff -u -r -1.1.2.12 -r -1.1.2.13 src/plugins/trayicon/trayicon_prefs.c; cvs diff -u -r -1.1.2.7 -r -1.1.2.8 src/plugins/trayicon/trayicon_prefs.h; cvs diff -u -r -1.1.4.2 -r -1.1.4.3 src/plugins/trayicon/libeggtrayicon/.cvsignore; ) > 3.9.0cvs84.patchset
( cvs diff -u -r 1.654.2.4661 -r 1.654.2.4662 configure.ac; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/fancy/fancy_viewer.c; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/fancy/fancy_viewer.h; cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/plugins/notification/Makefile.am; cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/plugins/notification/notification_plugin.c; diff -u /dev/null src/plugins/notification/gtkhotkey/.cvsignore; diff -u /dev/null src/plugins/notification/gtkhotkey/Makefile.am; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-error.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-error.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-info.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-info.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-key-file-registry.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-key-file-registry.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-listener.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-listener.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-marshal.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-marshal.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-registry.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-registry.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-utils.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-utils.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-x11-listener.c; diff -u /dev/null src/plugins/notification/gtkhotkey/gtk-hotkey-x11-listener.h; diff -u /dev/null src/plugins/notification/gtkhotkey/gtkhotkey.h; diff -u /dev/null src/plugins/notification/gtkhotkey/x11/eggaccelerators.c; diff -u /dev/null src/plugins/notification/gtkhotkey/x11/eggaccelerators.h; diff -u /dev/null src/plugins/notification/gtkhotkey/x11/tomboykeybinder.c; diff -u /dev/null src/plugins/notification/gtkhotkey/x11/tomboykeybinder.h; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/spam_report/Makefile.am; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/spam_report/spam_report.c; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/plugins/tnef_parse/Makefile.am; ) > 3.9.0cvs85.patchset

File diff suppressed because it is too large Load diff

View file

@ -27,7 +27,7 @@
#include <fancy_prefs.h>
#include <alertpanel.h>
#if USE_PRINTUNIX
#if HAVE_GTKPRINTUNIX
#include <printing.h>
#if GTK_CHECK_VERSION(2,13,1)
#include <gtk/gtkunixprint.h>
@ -78,12 +78,10 @@ static void open_in_browser_cb(GtkWidget *widget, FancyViewer *viewer);
static WebKitNavigationResponse fancy_open_uri (FancyViewer *viewer, gboolean external);
static void fancy_create_popup_prefs_menu(FancyViewer *viewer);
static void fancy_show_notice(FancyViewer *viewer, const gchar *message);
#ifdef HAVE_LIBCURL
static size_t download_file_curl_write_cb(void *buffer, size_t size,
size_t nmemb, void *data);
static void *download_file_curl (void *data);
static void download_file_cb(GtkWidget *widget, FancyViewer *viewer);
#endif
#if !WEBKIT_CHECK_VERSION (1,5,1)
gchar* webkit_web_view_get_selected_text(WebKitWebView* web_view);
@ -181,7 +179,7 @@ static void fancy_show_mimepart(MimeViewer *_viewer, const gchar *infile,
viewer->loading = TRUE;
g_timeout_add(5, (GtkFunction)fancy_show_mimepart_prepare, viewer);
}
#if GTK_CHECK_VERSION(2,10,0) && USE_PRINTUNIX
#if GTK_CHECK_VERSION(2,10,0) && HAVE_GTKPRINTUNIX
static void
job_complete_cb (GtkPrintJob *print_job, FancyViewer *viewer, GError *error)
@ -737,7 +735,7 @@ static void open_in_browser_cb(GtkWidget *widget, FancyViewer *viewer)
debug_print("link: %s\n", viewer->cur_link);
open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
}
#ifdef HAVE_LIBCURL
static size_t download_file_curl_write_cb(void *buffer, size_t size,
size_t nmemb, void *data)
{
@ -805,7 +803,7 @@ static void download_file_cb(GtkWidget *widget, FancyViewer *viewer)
download_file_curl((void *)viewer);
#endif
}
#endif
static void open_image_cb(GtkWidget *widget, FancyViewer *viewer)
{
debug_print("Not Yet Implemented\n");
@ -871,7 +869,7 @@ static void viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer)
"Download Linked File" )) {
gtk_label_set_text(GTK_LABEL(menul), _("Download Link"));
#ifdef HAVE_LIBCURL
GtkImageMenuItem *m_dlink = GTK_IMAGE_MENU_ITEM(menuitem);
if (!fancy_prefs.block_extern_content) {
gtk_widget_set_sensitive(GTK_WIDGET(menul), TRUE);
@ -887,17 +885,13 @@ static void viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer)
g_signal_connect(G_OBJECT(m_dlink), "activate",
G_CALLBACK(download_file_cb),
(gpointer *) viewer);
#else
gtk_widget_set_sensitive(GTK_WIDGET(menul), FALSE);
#endif
}
if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
"Save Image As" )) {
gtk_label_set_text(GTK_LABEL(menul), _("Save Image As"));
#ifdef HAVE_LIBCURL
GtkImageMenuItem *m_simage = GTK_IMAGE_MENU_ITEM(menuitem);
if (!fancy_prefs.block_extern_content) {
gtk_widget_set_sensitive(GTK_WIDGET(menul), TRUE);
@ -912,9 +906,6 @@ static void viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer)
}
g_signal_connect(G_OBJECT(m_simage), "activate",
G_CALLBACK(download_file_cb), (gpointer *) viewer);
#else
gtk_widget_set_sensitive(GTK_WIDGET(menul), FALSE);
#endif
}
if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
@ -1013,7 +1004,7 @@ static MimeViewer *fancy_viewer_create(void)
viewer->mimeviewer.get_widget = fancy_get_widget;
viewer->mimeviewer.get_selection = fancy_get_selection;
viewer->mimeviewer.show_mimepart = fancy_show_mimepart;
#if GTK_CHECK_VERSION(2,10,0) && USE_PRINTUNIX
#if GTK_CHECK_VERSION(2,10,0) && HAVE_GTKPRINTUNIX
viewer->mimeviewer.print = fancy_print;
#endif
viewer->mimeviewer.clear_viewer = fancy_clear_viewer;

View file

@ -53,11 +53,9 @@
#include <pthread.h>
#endif
#ifdef HAVE_LIBCURL
#include <curl/curl.h>
#include <curl/curlver.h>
#include "filesel.h"
#endif
#ifdef HAVE_LIBSOUP_GNOME
#include <libsoup/soup-gnome.h>

View file

@ -1,12 +1,12 @@
#if BUILD_HOTKEYS
#hotkey_lib = libcmnpgtkhotkey.la
#hotkey_lib_path = $(top_builddir)/src/plugins/notification/gtkhotkey/libcmnpgtkhotkey.la
#else
if BUILD_HOTKEYS
hotkey_lib = libcmnpgtkhotkey.la
hotkey_lib_path = $(top_builddir)/src/plugins/notification/gtkhotkey/libcmnpgtkhotkey.la
else
hotkey_lib =
hotkey_lib_path =
#endif
endif
SUBDIRS=gtkhotkey
EXTRA_DIST = claws.def plugin.def version.rc
CFLAGS += "-Wall"

View file

@ -0,0 +1,7 @@
.deps
.libs
Makefile
Makefile.in
*.la
*.lo
*.o

View file

@ -0,0 +1,37 @@
noinst_LTLIBRARIES = libcmnpgtkhotkey.la
libcmnpgtkhotkey_la_SOURCES = \
gtk-hotkey-info.c \
gtk-hotkey-error.c \
gtk-hotkey-listener.c \
gtk-hotkey-marshal.c \
gtk-hotkey-x11-listener.c \
x11/tomboykeybinder.c \
x11/eggaccelerators.c \
gtk-hotkey-registry.c \
gtk-hotkey-key-file-registry.c \
gtk-hotkey-utils.c
cmnpgtkhotkeyincludedir = $(includedir)/claws-mail/plugins/@PACKAGE@/gtkhotkey
cmnpgtkhotkeyinclude_HEADERS = \
gtk-hotkey-error.h \
gtkhotkey.h \
gtk-hotkey-info.h \
gtk-hotkey-key-file-registry.h \
gtk-hotkey-listener.h \
gtk-hotkey-registry.h \
gtk-hotkey-x11-listener.h \
gtk-hotkey-marshal.h \
x11/tomboykeybinder.h \
x11/eggaccelerators.h \
gtk-hotkey-utils.h
libcmnpgtkhotkey_la_LIBADD = \
$(GTK_LIBS) \
$(CM_NP_HOTKEY_LIBS)
AM_CPPFLAGS = \
-DGTK_HOTKEY_COMPILATION \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(CM_NP_HOTKEY_CFLAGS)

View file

@ -0,0 +1,31 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gtk-hotkey-error.h"
GQuark
gtk_hotkey_listener_error_quark (void)
{
return g_quark_from_static_string ("gtk-hotkey-listener-error-quark");
}
GQuark
gtk_hotkey_registry_error_quark (void)
{
return g_quark_from_static_string ("gtk-hotkey-storage-error-quark");
}

View file

@ -0,0 +1,100 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __GTK_HOTKEY_ERROR_H__
#define __GTK_HOTKEY_ERROR_H__
#include <glib.h>
G_BEGIN_DECLS
/**
* GTK_HOTKEY_LISTENER_ERROR:
*
* Error domain for #GtkHotkeyListener.
*/
#define GTK_HOTKEY_LISTENER_ERROR gtk_hotkey_listener_error_quark()
GQuark gtk_hotkey_listener_error_quark (void);
/**
* GTK_HOTKEY_REGISTRY_ERROR:
*
* Error domain for #GtkHotkeyRegistry.
*/
#define GTK_HOTKEY_REGISTRY_ERROR gtk_hotkey_registry_error_quark()
GQuark gtk_hotkey_registry_error_quark (void);
/**
* GtkHotkeyListenerError:
* @GTK_HOTKEY_LISTENER_ERROR_BIND: An error occured when binding a hotkey with
* the listener
* @GTK_HOTKEY_LISTENER_ERROR_UNBIND: An error occured when unbinding a hotkey
* with the listener
*
* Error codes for #GError<!-- -->s related to #GtkHotkeyListener<!-- -->s
*/
typedef enum
{
GTK_HOTKEY_LISTENER_ERROR_BIND,
GTK_HOTKEY_LISTENER_ERROR_UNBIND,
} GtkHotkeyListenerError;
/**
* GtkHotkeyRegistryError:
* @GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_APP: The application which is the involved
* in the transaction has not registered
* any hotkeys
* @GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_KEY: The hotkey key-id (the identifier that
* identifies the hotkey among those
* belonging to an application) is not
* known.
* @GTK_HOTKEY_REGISTRY_ERROR_MALFORMED_MEDIUM: The medium from which to read
* or write is in an unrecoverable
* state. For example a file
* containing syntax errors
* @GTK_HOTKEY_REGISTRY_ERROR_IO: There was some problem with the actual io
* operation. Missing file permissions, disk full,
* etc.
* @GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN: Unexpected and uncharacterized error
* @GTK_HOTKEY_REGISTRY_ERROR_BAD_SIGNATURE: The hotkey signature is not valid.
* See #GtkHotkeyInfo:signature.
* @GTK_HOTKEY_REGISTRY_ERROR_MISSING_APP: A #GtkHotkeyInfo is referring an
* application via its #GtkHotkeyInfo:app-info
* property, but the application can not
* be found.
*
* Error codes for #GError<!-- -->s related to #GtkHotkeyRegistry<!-- -->s
*/
typedef enum
{
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_APP,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_KEY,
GTK_HOTKEY_REGISTRY_ERROR_MALFORMED_MEDIUM,
GTK_HOTKEY_REGISTRY_ERROR_IO,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN,
GTK_HOTKEY_REGISTRY_ERROR_BAD_SIGNATURE,
GTK_HOTKEY_REGISTRY_ERROR_MISSING_APP,
} GtkHotkeyRegistryError;
G_END_DECLS
#endif /* __GTK_HOTKEY_ERROR_H__ */

View file

@ -0,0 +1,658 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gtk-hotkey-info.h"
#include "gtk-hotkey-error.h"
#include "gtk-hotkey-listener.h"
struct _GtkHotkeyInfoPrivate {
gchar *app_id;
gchar *key_id;
GAppInfo *app_info;
gchar *signature;
gchar *description;
GtkHotkeyListener *listener;
};
#define GTK_HOTKEY_INFO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_HOTKEY_TYPE_INFO, GtkHotkeyInfoPrivate))
enum {
GTK_HOTKEY_INFO_DUMMY_PROPERTY,
GTK_HOTKEY_INFO_BOUND,
GTK_HOTKEY_INFO_APPLICATION_ID,
GTK_HOTKEY_INFO_KEY_ID,
GTK_HOTKEY_INFO_APP_INFO,
GTK_HOTKEY_INFO_SIGNATURE,
GTK_HOTKEY_INFO_DESCRIPTION,
};
enum {
ACTIVATED,
LAST_SIGNAL
};
guint info_signals[LAST_SIGNAL] = { 0 };
static gpointer gtk_hotkey_info_parent_class = NULL;
static void gtk_hotkey_info_finalize (GObject * obj);
/**
* SECTION:gtk-hotkey-info
* @short_description: Primary representation of a hotkey
* @see_also: #GtkHotkeyRegistry
*
* #GtkHotkeyInfo is the primary object around which the GtkHotkey library
* revolves.
*
* Hotkeys are stored and managed via a #GtkHotkeyRegistry, while the actual
* binding and listening for key-presses is done by a #GtkHotkeyListener.
**/
/**
* gtk_hotkey_info_bind:
* @self: The hotkey to bind
* @error: Place to return a #GError, or %NULL to ignore
*
* Register the hotkey with the system. The #GtkHotkeyInfo::activated signal
* will now be emitted when the user presses the keyboard combination
* matching the hotkey's signature.
*
* Returns: %TRUE on success, and %FALSE on error in which case @error
* is also set
**/
gboolean
gtk_hotkey_info_bind (GtkHotkeyInfo* self, GError **error)
{
gboolean result;
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (self), FALSE);
if (gtk_hotkey_info_is_bound(self)) {
g_set_error (error, GTK_HOTKEY_LISTENER_ERROR,
GTK_HOTKEY_LISTENER_ERROR_BIND,
"Can not bind hotkey '%s' with signature '%s'. "
"It is already bound",
gtk_hotkey_info_get_key_id(self),
gtk_hotkey_info_get_signature(self));
return FALSE;
}
if (!self->priv->listener)
self->priv->listener = gtk_hotkey_listener_get_default ();
g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(self->priv->listener), FALSE);
result = gtk_hotkey_listener_bind_hotkey (self->priv->listener, self, error);
if (!result) {
g_object_unref (self->priv->listener);
self->priv->listener = NULL;
}
if (result)
g_object_notify (G_OBJECT(self), "bound");
return result;
}
/**
* gtk_hotkey_info_unbind
* @self: The hotkey to unbind
* @error: Place to return a #GError, or %NULL to ignore
* @returns: %TRUE on success, and %FALSE on error in which case @error
* is also set
*
* Remove the hotkey binding from the system. The #GtkHotkeyInfo::activated
* signal will no longer be emitted when the hotkey is pressed.
*/
gboolean
gtk_hotkey_info_unbind (GtkHotkeyInfo* self, GError **error)
{
gboolean result;
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (self), FALSE);
if (!gtk_hotkey_info_is_bound(self)) {
g_set_error (error, GTK_HOTKEY_LISTENER_ERROR,
GTK_HOTKEY_LISTENER_ERROR_UNBIND,
"Can not unbind hotkey '%s' with signature '%s'."
"It is not bound",
gtk_hotkey_info_get_key_id(self),
gtk_hotkey_info_get_signature(self));
return FALSE;
}
g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(self->priv->listener), FALSE);
result = gtk_hotkey_listener_unbind_hotkey (self->priv->listener, self,
error);
g_object_unref (self->priv->listener);
self->priv->listener = NULL;
if (result)
g_object_notify (G_OBJECT(self), "bound");
return result;
}
/**
* gtk_hotkey_info_is_bound
* @self: The hotkey to inspect
* @returns: %TRUE if gtk_hotkey_info_bind() has been called and returned %TRUE
* on this hotkey
*
* Check whether the hotkey has been succesfully bound to a #GtkHotkeyListener.
*/
gboolean
gtk_hotkey_info_is_bound (GtkHotkeyInfo* self)
{
return (self->priv->listener != NULL);
}
/**
* gtk_hotkey_info_get_application_id
* @self:
*
* Get the unique system identifier for the hotkey. See
* #GtkHotkeyInfo:application-id for details.
*/
const gchar*
gtk_hotkey_info_get_application_id (GtkHotkeyInfo* self)
{
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (self), NULL);
return self->priv->app_id;
}
/**
* gtk_hotkey_info_get_key_id
* @self:
*
* Get the identifier the owning application use to identify this hotkey.
* See #GtkHotkeyInfo:key-id for details.
*/
const gchar*
gtk_hotkey_info_get_key_id (GtkHotkeyInfo* self)
{
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (self), NULL);
return self->priv->key_id;
}
/**
* gtk_hotkey_info_get_app_info
* @self:
*
* Not to be confused with the value of the #GtkHotkeyInfo:application-id
* property. The hotkey can be associated with an installed desktop application
* via a #GAppInfo. This is not mandatory and this method returns %NULL
* if no desktop application has been associated with this hotkey.
*
* See the #GtkHotkeyInfo:app-info property for details.
*/
GAppInfo*
gtk_hotkey_info_get_app_info (GtkHotkeyInfo* self)
{
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (self), NULL);
return self->priv->app_info;
}
/**
* gtk_hotkey_info_get_signature
* @self:
*
* Get the keyboard signature of the hotkey. This could for example be
* '&lt;Alt&gt;F3' or '&lt;Control&gt;&lt;Shift&gt;G'.
*/
const gchar*
gtk_hotkey_info_get_signature (GtkHotkeyInfo* self)
{
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (self), NULL);
return self->priv->signature;
}
/**
* gtk_hotkey_info_get_description
* @self:
* @returns: The description of the hotkey or %NULL if none is set
*
* Get the free form description of the hotkey. The description is not guaranteed
* to be set and may be %NULL.
*
* FIXME: Do we need to take i18n into account here?
*/
const gchar*
gtk_hotkey_info_get_description (GtkHotkeyInfo* self)
{
g_return_val_if_fail (GTK_HOTKEY_IS_INFO(self), NULL);
return self->priv->description;
}
/**
* gtk_hotkey_info_set_description
* @self:
*
* Set a description for the hotkey. See also gtk_hotkey_info_get_description().
*/
void
gtk_hotkey_info_set_description (GtkHotkeyInfo* self, const gchar *description)
{
g_return_if_fail (GTK_HOTKEY_IS_INFO(self));
g_object_set (self, "description", description, NULL);
}
/**
* gtk_hotkey_info_equals
* @hotkey1: The first hotkey to compare
* @hotkey2: Second hotkey to compare to
* @sloppy_equals: If %TRUE sloppy equality will be used. This ignores
* the #GtkHotkeyInfo:description and #GtkHotkeyInfo:app-info
* properties of the objects.
* @returns: %TRUE if all the properties of the hotkeys match. Two %NULL hotkeys
* are also considered equal.
*
* Compare two #GtkHotkeyInfo<!-- -->s to see if they are equal. This method
* allows an optional 'sloppy equality' which ignores #GtkHotkeyInfo:description
* and #GtkHotkeyInfo:app-info.
*/
gboolean
gtk_hotkey_info_equals (GtkHotkeyInfo *hotkey1,
GtkHotkeyInfo *hotkey2,
gboolean sloppy_equals)
{
if (hotkey1 == hotkey2) return TRUE;
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (hotkey1), FALSE);
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (hotkey2), FALSE);
if (!g_str_equal (gtk_hotkey_info_get_application_id (hotkey1),
gtk_hotkey_info_get_application_id (hotkey2)))
return FALSE;
if (!g_str_equal (gtk_hotkey_info_get_key_id (hotkey1),
gtk_hotkey_info_get_key_id (hotkey2)))
return FALSE;
if (!g_str_equal (gtk_hotkey_info_get_signature (hotkey1),
gtk_hotkey_info_get_signature (hotkey2)))
return FALSE;
/* For sloppy equality this is good enough */
if (sloppy_equals)
return TRUE;
const gchar *d1, *d2;
d1 = gtk_hotkey_info_get_description (hotkey1);
d2 = gtk_hotkey_info_get_description (hotkey2);
if (d1 != NULL && d2 != NULL) {
if (!g_str_equal (gtk_hotkey_info_get_description (hotkey1),
gtk_hotkey_info_get_description (hotkey2)))
return FALSE;
} else if (d1 != d2)
return FALSE;
/* The case d1 == d2 == NULL will pass through the above */
GAppInfo *app1, *app2;
app1 = gtk_hotkey_info_get_app_info (hotkey1);
app2 = gtk_hotkey_info_get_app_info (hotkey2);
if (app1 != NULL && app2 != NULL) {
if (!g_app_info_equal (app1, app2))
return FALSE;
} else if (app1 != app2)
return FALSE;
/* As above, if app1 == app2 == NULL we count equality */
return TRUE;
}
/**
* gtk_hotkey_info_activated
* @self: #GtkHotkeyInfo to emit the #GtkHotkeyInfo::activated signal
* @event_time: The system time the event happened on. This is useful for
* applications to pass through focus stealing prevention when
* mapping windows
*
* Emit the #GtkHotkeyInfo::activated signal on a hotkey. Mainly called
* by #GtkHotkeyListener implementations. This method should not normally be
* used by applications.
*/
void
gtk_hotkey_info_activated (GtkHotkeyInfo* self, guint event_time)
{
g_return_if_fail (GTK_HOTKEY_IS_INFO(self));
g_signal_emit (self, info_signals[ACTIVATED], 0, event_time);
}
/**
* gtk_hotkey_info_new:
* @app_id: Unique identifier the running application can choose for it self.
* May be a free form string, but a descriptive name is encouraged
* @key_id: A key the application uses to recognize the hotkey. May be a free
* form string, but a descriptive name is encouraged
* @signature: A key press signature parsable by gtk_accelerator_parse(). For
* examplpe '&lt;Alt&gt;F3' or '&lt;Control&gt;&lt;Shift&gt;G'.
* @app_info: An optional #GAppInfo to associate with the hotkey. Pass %NULL to
* ignore this
* @returns: A new #GtkHotkeyInfo or %NULL on error. Error conditions could for
* example be invalid an invalid @signature, or %NULL arguments.
*
* Create a new hotkey. To actually trigger the hotkey when the user enters
* the right keyboard combination call gtk_hotkey_info_bind(). To save and
* load your hotkey settings use the #GtkHotkeyRegistry provided by
* gtk_hotkey_registry_get_default().
**/
GtkHotkeyInfo*
gtk_hotkey_info_new (const gchar *app_id,
const gchar *key_id,
const gchar *signature,
GAppInfo *app_info)
{
GtkHotkeyInfo * self;
g_return_val_if_fail (app_id != NULL, NULL);
g_return_val_if_fail (key_id != NULL, NULL);
/* A NULL app_info is ok, but it better be a GAppInfo then */
if (app_info != NULL)
g_return_val_if_fail (G_IS_APP_INFO(app_info), NULL);
self = g_object_new (GTK_HOTKEY_TYPE_INFO, "application-id", app_id,
"key-id", key_id,
"signature", signature,
"app-info", app_info,
NULL);
return self;
}
static void
gtk_hotkey_info_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec)
{
GtkHotkeyInfo * self;
self = GTK_HOTKEY_INFO (object);
switch (property_id) {
case GTK_HOTKEY_INFO_BOUND:
g_value_set_boolean (value,
(self->priv->listener != NULL));
break;
case GTK_HOTKEY_INFO_APPLICATION_ID:
g_value_set_string (value,
gtk_hotkey_info_get_application_id (self));
break;
case GTK_HOTKEY_INFO_KEY_ID:
g_value_set_string (value,
gtk_hotkey_info_get_key_id (self));
break;
case GTK_HOTKEY_INFO_APP_INFO:
g_value_set_object (value,
gtk_hotkey_info_get_app_info (self));
break;
case GTK_HOTKEY_INFO_SIGNATURE:
g_value_set_string (value,
gtk_hotkey_info_get_signature (self));
break;
case GTK_HOTKEY_INFO_DESCRIPTION:
g_value_set_string (value,
gtk_hotkey_info_get_description (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_hotkey_info_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec)
{
GtkHotkeyInfo *self;
GtkHotkeyInfoPrivate *priv;
self = GTK_HOTKEY_INFO (object);
priv = self->priv;
switch (property_id) {
case GTK_HOTKEY_INFO_BOUND:
g_critical ("Writing to read only property 'bound'");
break;
case GTK_HOTKEY_INFO_APPLICATION_ID:
if (priv->app_id)
g_critical ("Overwriting construct only property 'application-id'");
priv->app_id = g_value_dup_string (value);
break;
case GTK_HOTKEY_INFO_KEY_ID:
if (priv->key_id)
g_critical ("Overwriting construct only property 'key-id'");
priv->key_id = g_value_dup_string (value);
break;
case GTK_HOTKEY_INFO_APP_INFO:
if (priv->app_info)
g_critical ("Overwriting construct only property 'app-info'");
priv->app_info = g_value_dup_object (value);
break;
case GTK_HOTKEY_INFO_SIGNATURE:
if (priv->signature)
g_critical ("Overwriting construct only property 'signature'");
priv->signature = g_value_dup_string (value);
break;
case GTK_HOTKEY_INFO_DESCRIPTION:
if (priv->description)
g_free(priv->description);
priv->description = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_hotkey_info_class_init (GtkHotkeyInfoClass * klass)
{
gtk_hotkey_info_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GtkHotkeyInfoPrivate));
G_OBJECT_CLASS (klass)->get_property = gtk_hotkey_info_get_property;
G_OBJECT_CLASS (klass)->set_property = gtk_hotkey_info_set_property;
G_OBJECT_CLASS (klass)->finalize = gtk_hotkey_info_finalize;
/**
* GtkHotkeyInfo:bound
*
* Property reflecting whether or not this hotkey has been bound to
* a #GtkHotkeyListener. If this property is %TRUE you will receive
* #GtkHotkeyInfo::activated signals when the hotkey is triggered
* by the user.
*/
g_object_class_install_property (G_OBJECT_CLASS (klass),
GTK_HOTKEY_INFO_BOUND,
g_param_spec_boolean ("bound",
"Is Bound",
"Whether or not the hotkey is bound to a GtkHotkeyListener",
FALSE,
G_PARAM_READABLE));
/**
* GtkHotkeyInfo:application-id
*
* A free form string chosen by the application using the hotkey, under
* which the application identifies itself.
*/
g_object_class_install_property (G_OBJECT_CLASS (klass),
GTK_HOTKEY_INFO_APPLICATION_ID,
g_param_spec_string ("application-id",
"Application Id",
"Globally unique application id",
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
/**
* GtkHotkeyInfo:key-id
*
* A free form string the application using the hotkey has attributed
* the hotkey so that it can be identified later on. Applications are
* encouraged to choose descriptive key ids.
*/
g_object_class_install_property (G_OBJECT_CLASS (klass),
GTK_HOTKEY_INFO_KEY_ID,
g_param_spec_string ("key-id",
"Hotkey Id",
"Globally unique identifier for the hotkey",
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
/**
* GtkHotkeyInfo:app-info
*
* A #GAppInfo associated with the key. This is mainly useful for external
* applications which can use the information provided by the #GAppInfo
* to display meaningful messages to the user. Like 'The keyboard
* combination &lt;Alt&gt;F3' is already assigned to the application
* "Deskbar Applet", please select another'.
*/
g_object_class_install_property (G_OBJECT_CLASS (klass),
GTK_HOTKEY_INFO_APP_INFO,
g_param_spec_object ("app-info",
"Application Information",
"Object holding metadata about "
"the hotkey's application",
G_TYPE_APP_INFO,
G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
/**
* GtkHotkeyInfo:signature
*
* The keyboard signature of the hotkey. This could for example by
* '&lt;Alt&gt;F3' or '&lt;Control&gt;&lt;Shift&gt;G'. The signature should be parsable by
* gtk_accelerator_parse().
*/
g_object_class_install_property (G_OBJECT_CLASS (klass),
GTK_HOTKEY_INFO_SIGNATURE,
g_param_spec_string ("signature",
"Signature",
"String defining the keyboard shortcut",
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
/**
* GtkHotkeyInfo:description
*
* An optional free form description of the hotkey.
*/
g_object_class_install_property (G_OBJECT_CLASS (klass),
GTK_HOTKEY_INFO_DESCRIPTION,
g_param_spec_string ("description",
"Description",
"Short description of what happens upon activation",
"",
G_PARAM_READABLE | G_PARAM_WRITABLE));
/**
* GtkHotkeyInfo::activated:
* @hotkey: a #GtkHotkeyInfo for the hotkey that was activated
* @event_time: Time for event triggering the keypress. This is mainly
* used to pass to window management functions to pass through
* focus stealing prevention
*
* Emitted when a hotkey has been activated.
*/
info_signals[ACTIVATED] = \
g_signal_new ("activated",
GTK_HOTKEY_TYPE_INFO,
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
}
static void
gtk_hotkey_info_init (GtkHotkeyInfo * self)
{
self->priv = GTK_HOTKEY_INFO_GET_PRIVATE (self);
self->priv->app_id = NULL;
self->priv->key_id = NULL;
self->priv->app_info = NULL;
}
static void
gtk_hotkey_info_finalize (GObject * obj)
{
GtkHotkeyInfo *self;
GtkHotkeyInfoPrivate *priv;
self = GTK_HOTKEY_INFO (obj);
priv = self->priv;
if (priv->app_id)
g_free (priv->app_id);
if (priv->key_id)
g_free (priv->key_id);
if (priv->app_info)
g_object_unref (priv->app_info);
if (priv->signature)
g_free (priv->signature);
if (priv->description)
g_free (priv->description);
if (GTK_HOTKEY_IS_LISTENER (priv->listener))
g_object_unref (priv->listener);
G_OBJECT_CLASS (gtk_hotkey_info_parent_class)->finalize (obj);
}
GType
gtk_hotkey_info_get_type (void)
{
static GType gtk_hotkey_info_type_id = 0;
if (G_UNLIKELY (gtk_hotkey_info_type_id == 0)) {
static const GTypeInfo g_define_type_info = {
sizeof (GtkHotkeyInfoClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gtk_hotkey_info_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GtkHotkeyInfo),
0,
(GInstanceInitFunc) gtk_hotkey_info_init
};
gtk_hotkey_info_type_id = g_type_register_static (G_TYPE_OBJECT,
"GtkHotkeyInfo",
&g_define_type_info,
0);
}
return gtk_hotkey_info_type_id;
}

View file

@ -0,0 +1,89 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __GTK_HOTKEY_INFO_H__
#define __GTK_HOTKEY_INFO_H__
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
G_BEGIN_DECLS
#define GTK_HOTKEY_TYPE_INFO (gtk_hotkey_info_get_type ())
#define GTK_HOTKEY_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_HOTKEY_TYPE_INFO, GtkHotkeyInfo))
#define GTK_HOTKEY_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_HOTKEY_TYPE_INFO, GtkHotkeyInfoClass))
#define GTK_HOTKEY_IS_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_HOTKEY_TYPE_INFO))
#define GTK_HOTKEY_IS_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_HOTKEY_TYPE_INFO))
#define GTK_HOTKEY_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_HOTKEY_TYPE_INFO, GtkHotkeyInfoClass))
typedef struct _GtkHotkeyInfo GtkHotkeyInfo;
typedef struct _GtkHotkeyInfoClass GtkHotkeyInfoClass;
typedef struct _GtkHotkeyInfoPrivate GtkHotkeyInfoPrivate;
struct _GtkHotkeyInfo {
GObject parent;
GtkHotkeyInfoPrivate * priv;
};
struct _GtkHotkeyInfoClass {
GObjectClass parent;
};
gboolean gtk_hotkey_info_bind (GtkHotkeyInfo* self, GError **error);
gboolean gtk_hotkey_info_unbind (GtkHotkeyInfo* self, GError **error);
gboolean gtk_hotkey_info_is_bound (GtkHotkeyInfo* self);
const gchar* gtk_hotkey_info_get_application_id (GtkHotkeyInfo* self);
const gchar* gtk_hotkey_info_get_key_id (GtkHotkeyInfo* self);
GAppInfo* gtk_hotkey_info_get_app_info (GtkHotkeyInfo* self);
const gchar* gtk_hotkey_info_get_application_id (GtkHotkeyInfo* self);
const gchar* gtk_hotkey_info_get_signature (GtkHotkeyInfo* self);
const gchar* gtk_hotkey_info_get_key_id (GtkHotkeyInfo* self);
const gchar* gtk_hotkey_info_get_description (GtkHotkeyInfo* self);
void gtk_hotkey_info_set_description (GtkHotkeyInfo* self, const gchar *description);
gboolean gtk_hotkey_info_equals (GtkHotkeyInfo *hotkey1, GtkHotkeyInfo *hotkey2, gboolean sloppy_equals);
void gtk_hotkey_info_activated (GtkHotkeyInfo* self, guint event_time);
GtkHotkeyInfo* gtk_hotkey_info_new (const gchar *app_id,
const gchar *key_id,
const gchar *signature,
GAppInfo *app_info);
GType gtk_hotkey_info_get_type (void);
G_END_DECLS
#endif

View file

@ -0,0 +1,720 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gtk-hotkey-key-file-registry.h"
#include "gtk-hotkey-utils.h"
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
enum {
GTK_HOTKEY_KEY_FILE_REGISTRY_DUMMY_PROPERTY
};
/* Beware - the lengths of these strings are hardcoded throughout
* this file (sorry) */
#define HOTKEY_HOME "~/.config/hotkeys"
#define HOTKEY_FILE_EXT ".hotkeys"
#define HOTKEY_GROUP "hotkey:"
static GtkHotkeyInfo* gtk_hotkey_key_file_registry_real_get_hotkey (GtkHotkeyRegistry *base,
const char *app_id,
const char *key_id,
GError **error);
static GList* gtk_hotkey_key_file_registry_real_get_application_hotkeys
(GtkHotkeyRegistry *base,
const char *app_id,
GError **error);
static GList* gtk_hotkey_key_file_registry_real_get_all_hotkeys
(GtkHotkeyRegistry *base);
static gboolean gtk_hotkey_key_file_registry_real_store_hotkey(GtkHotkeyRegistry *base,
GtkHotkeyInfo *info,
GError **error);
static gboolean gtk_hotkey_key_file_registry_real_delete_hotkey
(GtkHotkeyRegistry *base,
const gchar *app_id,
const gchar *key_id,
GError **error);
static gboolean gtk_hotkey_key_file_registry_real_has_hotkey (GtkHotkeyRegistry *base,
const gchar *app_id,
const gchar *key_id);
static GFile* get_hotkey_home (void);
static GFile* get_hotkey_file (const gchar *app_id);
static GKeyFile* get_hotkey_key_file (const gchar *app_id,
GError **error);
static GtkHotkeyInfo* get_hotkey_info_from_key_file (GKeyFile *keyfile,
const gchar *app_id,
const gchar *key_id,
GError **error);
static GList* get_all_hotkey_infos_from_key_file (GKeyFile *keyfile,
const gchar *app_id);
static gpointer gtk_hotkey_key_file_registry_parent_class = NULL;
static
GtkHotkeyInfo*
gtk_hotkey_key_file_registry_real_get_hotkey (GtkHotkeyRegistry *base,
const char *app_id,
const char *key_id,
GError **error)
{
GtkHotkeyKeyFileRegistry *self;
GKeyFile *keyfile = NULL;
GtkHotkeyInfo *info = NULL;
g_return_val_if_fail (GTK_HOTKEY_IS_KEY_FILE_REGISTRY(base), NULL);
g_return_val_if_fail (app_id != NULL, NULL);
g_return_val_if_fail (key_id != NULL, NULL);
self = GTK_HOTKEY_KEY_FILE_REGISTRY (base);
keyfile = get_hotkey_key_file (app_id, error);
if (keyfile == NULL)
goto clean_up;
info = get_hotkey_info_from_key_file (keyfile, app_id, key_id, error);
clean_up:
if (keyfile) g_key_file_free (keyfile);
return info;
}
static GList*
gtk_hotkey_key_file_registry_real_get_application_hotkeys (GtkHotkeyRegistry *base,
const char *app_id,
GError **error)
{
GtkHotkeyKeyFileRegistry *self;
GKeyFile *keyfile;
g_return_val_if_fail (app_id != NULL, NULL);
self = GTK_HOTKEY_KEY_FILE_REGISTRY (base);
keyfile = get_hotkey_key_file (app_id, error);
if (keyfile == NULL)
return NULL; /* error is set by get_hotkey_key_file() */
return get_all_hotkey_infos_from_key_file (keyfile, app_id);
}
static GList*
gtk_hotkey_key_file_registry_real_get_all_hotkeys (GtkHotkeyRegistry *base)
{
GtkHotkeyKeyFileRegistry *self;
GFile *home;
GFileEnumerator *dir;
GFileInfo *file_info;
GError *error;
GList *result = NULL;
self = GTK_HOTKEY_KEY_FILE_REGISTRY (base);
home = get_hotkey_home ();
error = NULL;
dir = g_file_enumerate_children (home, G_FILE_ATTRIBUTE_STANDARD_NAME,
0, NULL, &error);
if (error) {
gchar *path = g_file_get_path (home);
g_critical ("Failed to read hotkey home directory '%s': %s",
path, error->message);
g_free (path);
g_error_free (error);
return NULL;
}
error = NULL;
while ((file_info = g_file_enumerator_next_file (dir, NULL, &error)) != NULL) {
const gchar *filename;
GFile *file;
GString *app_id;
GList *app_hotkeys;
filename = g_file_info_get_name(file_info);
if (g_str_has_suffix (filename, HOTKEY_FILE_EXT)) {
file = g_file_get_child (home, filename);
/* Extract app_id from file name */
app_id = g_string_new (filename);
g_string_erase (app_id, app_id->len - 8, 8);
/* Load all hotkeys from the file, and append it to
* the total result */
app_hotkeys = gtk_hotkey_registry_get_application_hotkeys (base,
app_id->str,
&error);
if (error) {
g_warning ("Failed to read hotkeys for application '%s': %s",
app_id->str, error->message);
g_error_free (error);
error = NULL;
} else {
result = g_list_concat (result, app_hotkeys);
}
g_string_free (app_id, TRUE);
g_object_unref (file);
}
g_object_unref (file_info);
}
if (error) {
gchar *path = g_file_get_path (home);
g_warning ("Failed to read hotkey home directory '%s': %s",
path, error->message);
g_free (path);
g_error_free (error);
}
g_object_unref (dir);
g_object_unref (home);
return result;
}
static gboolean
gtk_hotkey_key_file_registry_real_store_hotkey (GtkHotkeyRegistry *base,
GtkHotkeyInfo *info,
GError **error)
{
GtkHotkeyKeyFileRegistry *self;
GKeyFile *keyfile;
GFile *file, *home;
GError *tmp_error;
gchar *file_path, *group;
self = GTK_HOTKEY_KEY_FILE_REGISTRY (base);
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (info), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
/* Make sure we have our root dir */
home = get_hotkey_home ();
if (!g_file_query_exists(home, NULL)) {
tmp_error = NULL;
if (!g_file_make_directory (home, NULL, &tmp_error)) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_IO,
"Failed to create hotkey configuration dir "
HOTKEY_HOME": %s", tmp_error->message);
g_error_free (tmp_error);
g_object_unref (home);
return FALSE;
}
}
/* Now load any old contents of the keyfile */
file = get_hotkey_file (gtk_hotkey_info_get_application_id (info));
file_path = g_file_get_path (file);
keyfile = g_key_file_new ();
tmp_error = NULL;
if (!g_key_file_load_from_file (keyfile, file_path, 0, &tmp_error)) {
if (tmp_error->code == G_KEY_FILE_ERROR_PARSE) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_MALFORMED_MEDIUM,
"The file %s is not in a valid key-file format: %s",
file_path, tmp_error->message);
goto clean_up;
}
/* Ignore other errors */
g_error_free (tmp_error);
}
/* Prepare keyfile data */
group = g_strconcat (HOTKEY_GROUP, gtk_hotkey_info_get_key_id (info), NULL);
g_key_file_set_string (keyfile, group, "Owner",
gtk_hotkey_info_get_application_id (info));
g_key_file_set_string (keyfile, group, "Signature",
gtk_hotkey_info_get_signature (info));
if (gtk_hotkey_info_get_description (info))
g_key_file_set_string (keyfile, group, "Description",
gtk_hotkey_info_get_description (info));
if (gtk_hotkey_info_get_app_info (info)) {
GAppInfo *ai = gtk_hotkey_info_get_app_info (info);
g_key_file_set_string (keyfile, group, "AppInfo",
g_app_info_get_id (ai));
}
gsize size;
gchar *contents;
tmp_error = NULL;
contents = g_key_file_to_data (keyfile, &size, &tmp_error);
if (tmp_error) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN,
"Failed to generate keyfile contents: %s",
tmp_error->message);
goto clean_up;
}
/* Write the actual data */
g_file_set_contents (file_path, contents, size, &tmp_error);
if (tmp_error) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_IO,
"Failed to write keyfile '%s': %s",
file_path, tmp_error->message);
goto clean_up;
}
clean_up:
if (tmp_error) g_error_free (tmp_error);
g_free (file_path);
if (group) g_free (group);
g_key_file_free (keyfile);
g_object_unref (file);
g_object_unref (home);
if (*error)
return FALSE;
self = GTK_HOTKEY_KEY_FILE_REGISTRY (base);
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (info), FALSE);
gtk_hotkey_registry_hotkey_stored (base, info);
return TRUE;
}
static gboolean
gtk_hotkey_key_file_registry_real_delete_hotkey (GtkHotkeyRegistry *base,
const gchar *app_id,
const gchar *key_id,
GError **error)
{
GtkHotkeyKeyFileRegistry *self;
GtkHotkeyInfo *info = NULL;
GFile *file;
GKeyFile *keyfile;
GError *tmp_error;
gboolean is_error = FALSE;
gchar *path, *group;
g_return_val_if_fail (app_id != NULL, FALSE);
g_return_val_if_fail (key_id != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
self = GTK_HOTKEY_KEY_FILE_REGISTRY (base);
group = NULL;
file = get_hotkey_file (app_id);
g_return_val_if_fail (G_IS_FILE(file), FALSE);
path = g_file_get_path (file);
keyfile = g_key_file_new ();
/* Load the old keyfile */
tmp_error = NULL;
g_key_file_load_from_file (keyfile, path, 0, &tmp_error);
if (tmp_error) {
if ((tmp_error->domain == G_FILE_ERROR &&
tmp_error->code == G_FILE_ERROR_NOENT) ||
(tmp_error->domain == G_KEY_FILE_ERROR &&
tmp_error->code == G_KEY_FILE_ERROR_NOT_FOUND))
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_APP,
"No such keyfile '%s'. Application '%s' has not "
"registered any hotkeys",
path, app_id);
else
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_IO,
"Failed to load keyfile '%s': %s",
app_id, tmp_error->message);
is_error = TRUE;
goto clean_up;
}
/* Get a ref to the GtkHotkeyInfo so that we can emit it with the
* hotkey-deleted signal */
tmp_error = NULL;
info = get_hotkey_info_from_key_file (keyfile, app_id, key_id, error);
if (info == NULL) {
is_error = TRUE;
goto clean_up;
}
/* Remove the group for key_id */
group = g_strconcat (HOTKEY_GROUP, key_id, NULL);
tmp_error = NULL;
g_key_file_remove_group (keyfile, group, &tmp_error);
if (tmp_error) {
if (tmp_error->domain == G_KEY_FILE_ERROR &&
tmp_error->code == G_KEY_FILE_ERROR_GROUP_NOT_FOUND)
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_APP,
"Application '%s' has not registered a hotkey with"
"id '%s'", app_id, key_id);
else
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN,
"Failed to delete hotkey '%s' from application %s: %s",
key_id, app_id, tmp_error->message);
is_error = TRUE;
goto clean_up;
}
/* Check if the keyfile is empty. If it is we delete it */
gsize count;
GStrv groups;
groups = g_key_file_get_groups (keyfile, &count);
g_strfreev (groups);
if (count == 0) {
tmp_error = NULL;
g_file_delete (file, NULL, &tmp_error);
if (tmp_error) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_IO,
"Failed to delete empty keyfile '%s': %s",
path, tmp_error->message);
is_error = TRUE;
}
/* File deleted, we should just clean up and exit */
goto clean_up;
}
/* Write new keyfile */
gsize size;
gchar *contents;
tmp_error = NULL;
contents = g_key_file_to_data (keyfile, &size, &tmp_error);
if (tmp_error) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN,
"Failed to generate keyfile contents: %s",
tmp_error->message);
is_error = TRUE;
goto clean_up;
}
tmp_error = NULL;
g_file_set_contents (path, contents, size, &tmp_error);
if (tmp_error) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_IO,
"Failed to write keyfile '%s': %s",
path, tmp_error->message);
is_error = TRUE;
goto clean_up;
}
clean_up:
if (tmp_error) g_error_free (tmp_error);
g_object_unref (file);
g_free (path);
if (group) g_free (group);
g_key_file_free (keyfile);
if (is_error)
return FALSE;
gtk_hotkey_registry_hotkey_deleted (base, info);
g_object_unref (info);
return TRUE;
}
static gboolean
gtk_hotkey_key_file_registry_real_has_hotkey (GtkHotkeyRegistry *base,
const gchar *app_id,
const gchar *key_id)
{
GtkHotkeyKeyFileRegistry *self;
GFile *file;
gboolean exists;
g_return_val_if_fail (app_id != NULL, FALSE);
g_return_val_if_fail (key_id != NULL, FALSE);
self = GTK_HOTKEY_KEY_FILE_REGISTRY (base);
file = get_hotkey_file (app_id);
g_return_val_if_fail (G_IS_FILE(file), FALSE);
if (g_file_query_exists (file, NULL))
exists = TRUE;
else
exists = FALSE;
g_object_unref (file);
return exists;
}
static void
gtk_hotkey_key_file_registry_class_init (GtkHotkeyKeyFileRegistryClass *klass)
{
gtk_hotkey_key_file_registry_parent_class = g_type_class_peek_parent (klass);
GTK_HOTKEY_REGISTRY_CLASS (klass)->get_hotkey = gtk_hotkey_key_file_registry_real_get_hotkey;
GTK_HOTKEY_REGISTRY_CLASS (klass)->get_application_hotkeys = gtk_hotkey_key_file_registry_real_get_application_hotkeys;
GTK_HOTKEY_REGISTRY_CLASS (klass)->get_all_hotkeys = gtk_hotkey_key_file_registry_real_get_all_hotkeys;
GTK_HOTKEY_REGISTRY_CLASS (klass)->store_hotkey = gtk_hotkey_key_file_registry_real_store_hotkey;
GTK_HOTKEY_REGISTRY_CLASS (klass)->delete_hotkey = gtk_hotkey_key_file_registry_real_delete_hotkey;
GTK_HOTKEY_REGISTRY_CLASS (klass)->has_hotkey = gtk_hotkey_key_file_registry_real_has_hotkey;
}
static void
gtk_hotkey_key_file_registry_init (GtkHotkeyKeyFileRegistry *self)
{
}
static void
gtk_hotkey_key_file_registry_finalize (GtkHotkeyKeyFileRegistry *self)
{
}
GType
gtk_hotkey_key_file_registry_get_type (void)
{
static GType gtk_hotkey_key_file_registry_type_id = 0;
if (G_UNLIKELY (gtk_hotkey_key_file_registry_type_id == 0)) {
static const GTypeInfo g_define_type_info = {
sizeof (GtkHotkeyKeyFileRegistryClass),
(GBaseInitFunc) gtk_hotkey_key_file_registry_init,
(GBaseFinalizeFunc) gtk_hotkey_key_file_registry_finalize,
(GClassInitFunc) gtk_hotkey_key_file_registry_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GtkHotkeyKeyFileRegistry),
0,
(GInstanceInitFunc) gtk_hotkey_key_file_registry_init
};
gtk_hotkey_key_file_registry_type_id = g_type_register_static (GTK_HOTKEY_TYPE_STORAGE, "GtkHotkeyKeyFileRegistry", &g_define_type_info, 0);
}
return gtk_hotkey_key_file_registry_type_id;
}
static GFile*
get_hotkey_home (void)
{
GFile *home;
home = g_file_parse_name (HOTKEY_HOME);
if (g_file_query_exists(home, NULL) &&
!gtk_hotkey_g_file_is_directory(home)) {
g_critical (HOTKEY_HOME" exists but is not a directory");
g_object_unref (home);
return NULL;
}
return home;
}
/* It is not guaranteed that the keyfile exists */
static GFile*
get_hotkey_file (const gchar *app_id)
{
GFile *home, *file;
gchar *filename;
g_return_val_if_fail (app_id != NULL, NULL);
home = get_hotkey_home();
g_return_val_if_fail (home != NULL, NULL);
filename = g_strconcat (app_id, HOTKEY_FILE_EXT, NULL);
file = g_file_get_child (home, filename);
g_object_unref (home);
g_free (filename);
return file;
}
static GKeyFile*
get_hotkey_key_file (const gchar *app_id, GError **error)
{
gchar *path;
GFile *file;
GKeyFile *keyfile = NULL;
GError *tmp_error;
g_return_val_if_fail (app_id != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = get_hotkey_file (app_id);
if (!g_file_query_exists (file, NULL)) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_APP,
"Application '%s' has not registered any hotkeys", app_id);
g_object_unref (file);
return NULL;
}
path = g_file_get_path (file);
keyfile = g_key_file_new ();
tmp_error = NULL;
g_key_file_load_from_file (keyfile, path, 0, &tmp_error);
if (tmp_error) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_IO,
"Failed to load keyfile '%s': %s", path, tmp_error->message);
goto clean_up;
}
clean_up:
g_free (path);
g_object_unref (file);
if (tmp_error) g_error_free (tmp_error);
if (*error) {
g_key_file_free (keyfile);
return NULL;
}
return keyfile;
}
static GtkHotkeyInfo*
get_hotkey_info_from_key_file (GKeyFile *keyfile,
const gchar *app_id,
const gchar *key_id,
GError **error)
{
GtkHotkeyInfo *info = NULL;
gchar *group, *description, *app_info_id, *signature;
GAppInfo *app_info = NULL;
g_return_val_if_fail (keyfile != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
g_return_val_if_fail (app_id != NULL, NULL);
g_return_val_if_fail (key_id != NULL, NULL);
group = g_strconcat (HOTKEY_GROUP, key_id, NULL);
description = g_key_file_get_string (keyfile, group, "Description", NULL);
app_info_id = g_key_file_get_string (keyfile, group, "AppInfo", NULL);
signature = g_key_file_get_string (keyfile, group, "Signature", NULL);
if (!g_key_file_has_group (keyfile, group)) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN_KEY,
"Keyfile has no group "HOTKEY_GROUP"%s", key_id);
goto clean_up;
}
if (!signature) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_BAD_SIGNATURE,
"No 'Signature' defined for hotkey '%s' for application '%s'",
key_id, app_id);
goto clean_up;
}
if (app_info_id) {
app_info = G_APP_INFO(g_desktop_app_info_new (app_info_id));
if (!G_IS_APP_INFO(app_info)) {
g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR,
GTK_HOTKEY_REGISTRY_ERROR_MISSING_APP,
"Keyfile refering to 'AppInfo = %s', but no application"
"by that id is registered on the system", app_info_id);
goto clean_up;
}
}
info = gtk_hotkey_info_new (app_id, key_id, signature, app_info);
if (description)
gtk_hotkey_info_set_description (info, description);
clean_up:
g_free (group);
if (signature) g_free (signature);
if (description) g_free (description);
if (app_info_id) g_free (app_info_id);
if (app_info) g_object_unref (app_info);
return info;
}
static GList*
get_all_hotkey_infos_from_key_file (GKeyFile *keyfile,
const gchar *app_id)
{
GList *hotkeys;
GtkHotkeyInfo *hotkey;
GStrv groups;
gsize count;
gchar *group;
GString *key_id;
GError *error;
g_return_val_if_fail (keyfile != NULL, NULL);
g_return_val_if_fail (app_id != NULL, NULL);
hotkeys = NULL;
groups = g_key_file_get_groups (keyfile, &count);
int i;
for (i = 0; i < count; i++) {
group = groups[i];
key_id = g_string_new (group);
/* Ignore non hotkey groups */
if (!g_str_has_prefix (key_id->str, HOTKEY_GROUP)) {
g_warning ("Hotkey file for %s contains non 'hotkey:' group '%s'",
app_id, group);
g_string_free (key_id, TRUE);
continue;
}
/* Strip 'hotkey:' prefix from key_id */
g_string_erase (key_id, 0, 7);
error = NULL;
hotkey = get_hotkey_info_from_key_file (keyfile, app_id, key_id->str, &error);
if (error) {
g_warning ("Failed to read hotkey '%s' for application '%s': %s",
key_id->str, app_id, error->message);
g_error_free (error);
g_string_free (key_id, TRUE);
continue;
}
hotkeys = g_list_prepend (hotkeys, hotkey);
g_string_free (key_id, TRUE);
}
g_strfreev (groups);
return hotkeys;
}

View file

@ -0,0 +1,59 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __GTK_HOTKEY_KEY_FILE_REGISTRY_H__
#define __GTK_HOTKEY_KEY_FILE_REGISTRY_H__
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "gtk-hotkey-registry.h"
#include "gtk-hotkey-info.h"
G_BEGIN_DECLS
#define GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY (gtk_hotkey_key_file_registry_get_type ())
#define GTK_HOTKEY_KEY_FILE_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY, GtkHotkeyKeyFileRegistry))
#define GTK_HOTKEY_KEY_FILE_REGISTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY, GtkHotkeyKeyFileRegistryClass))
#define GTK_HOTKEY_IS_KEY_FILE_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY))
#define GTK_HOTKEY_IS_KEY_FILE_REGISTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY))
#define GTK_HOTKEY_KEY_FILE_REGISTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY, GtkHotkeyKeyFileRegistryClass))
typedef struct _GtkHotkeyKeyFileRegistry GtkHotkeyKeyFileRegistry;
typedef struct _GtkHotkeyKeyFileRegistryClass GtkHotkeyKeyFileRegistryClass;
typedef struct _GtkHotkeyKeyFileRegistryPrivate GtkHotkeyKeyFileRegistryPrivate;
struct _GtkHotkeyKeyFileRegistry {
GtkHotkeyRegistry parent;
GtkHotkeyKeyFileRegistryPrivate * priv;
};
struct _GtkHotkeyKeyFileRegistryClass {
GtkHotkeyRegistryClass parent;
};
GType gtk_hotkey_key_file_registry_get_type (void);
G_END_DECLS
#endif

View file

@ -0,0 +1,218 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gtk-hotkey-listener.h"
#include "gtk-hotkey-x11-listener.h"
#include "gtk-hotkey-marshal.h"
/* FIXME: The default listener is hardcoded to x11, should be compilation target dependent */
enum {
ACTIVATED,
LAST_SIGNAL
};
enum {
GTK_HOTKEY_LISTENER_DUMMY_PROPERTY
};
guint listener_signals[LAST_SIGNAL] = { 0 };
static gpointer gtk_hotkey_listener_parent_class = NULL;
static GtkHotkeyListener *default_listener = NULL;
static GType default_listener_type = G_TYPE_INVALID;
/**
* SECTION:gtk-hotkey-listener
* @short_description: Abstract base class providing platform independent hotkey listening capabilities
* @see_also: #GtkHotkeyRegistry, #GtkHotkeyInfo
*
* #GtkHotkeyListener is an abstract base class for implementing platform
* specific hotkey listeners - ie objects able to register when the user enters
* a certain keyboard combination, regardless of which window has focus.
*
* Unless you have very special needs you should use the factory method
* gtk_hotkey_listener_get_default() to get a reference to a #GtkHotkeyListener
* matching your platform. Although most applications will not need.
*
* This class is part of the advanced API of GtkHotkey. Applications will not
* normally use a #GtkHotkeyListener directly, since gtk_hotkey_info_bind()
* will call into gtk_hotkey_listener_bind() on the default listener for you.
**/
/**
* gtk_hotkey_listener_get_default
* @returns: A new reference to the default hotkey listener for the platform
*
* Static factory method to get a reference to the default #GtkHotkeyListener
* for the current platform.
*
* FIXME: Currently hardcoded to X11
*/
GtkHotkeyListener*
gtk_hotkey_listener_get_default ()
{
/* FIXME: This method should be changedd to use the same approach as
* gtk_hotkey_registry_get_default() */
if (default_listener) {
g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(default_listener), NULL);
return g_object_ref (default_listener);
}
gtk_hotkey_listener_get_type (); /* This call makes sure the default type ise set */
g_debug ("Listener Type: %s", g_type_name (default_listener_type));
default_listener = g_object_new (default_listener_type, NULL);
g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(default_listener), NULL);
return g_object_ref (default_listener);
}
/**
* gtk_hotkey_listener_bind_hotkey
* @self: The hotkey listener on which to bind a hotkey
* @hotkey: The #GtkHotkeyInfo to bind. See #GtkHotkeyInfo:signature
* @error: #GError in which to store errors, or %NULL to ignore
* @returns: %TRUE if the binding succeeded, or %FALSE otherwise. In case of
* runtime errors @error will be set
*
* This method must be implemented by any child class of #GtkHotkeyListener.
*
* Start listening for keypresses matching the signature of @hotkey.
* This method is notmally accessed indirectly by calling gtk_hotkey_info_bind().
*/
gboolean
gtk_hotkey_listener_bind_hotkey (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
GError **error)
{
g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(self), FALSE);
return GTK_HOTKEY_LISTENER_GET_CLASS (self)->bind_hotkey (self, hotkey, error);
}
/**
* gtk_hotkey_listener_unbind_hotkey
* @self: The hotkey listener on which to bind a hotkey
* @hotkey: The #GtkHotkeyInfo to bind. See #GtkHotkeyInfo:signature
* @error: #GError in which to store errors, or %NULL to ignore
* @returns: %TRUE if the binding has been removed, or %FALSE otherwise.
* In case of runtime errors @error will be set
*
* This method must be implemented by any child class of #GtkHotkeyListener.
*
* Stop listening for keypresses matching the signature of @hotkey. This method
* is notmally accessed indirectly by calling gtk_hotkey_info_unbind().
*/
gboolean
gtk_hotkey_listener_unbind_hotkey (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
GError **error)
{
g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(self), FALSE);
return GTK_HOTKEY_LISTENER_GET_CLASS (self)->unbind_hotkey (self, hotkey, error);
}
/**
* gtk_hotkey_listener_activated
* @self: #GtkHotkeyListener to emit the #GtkHotkeyListener::activated signal
* @hotkey: The #GtkHotkeyInfo the event happened for
* @event_time: The system time the event happened on. This is useful for
* applications to pass through focus stealing prevention when
* mapping windows
*
* Emit the #GtkHotkeyInfo::activated signal on a hotkey listener.
*/
void
gtk_hotkey_listener_activated (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
guint event_time)
{
g_return_if_fail (GTK_HOTKEY_IS_LISTENER(self));
g_return_if_fail (GTK_HOTKEY_IS_INFO(hotkey));
g_signal_emit (self, listener_signals[ACTIVATED], 0, hotkey, event_time);
}
static void
gtk_hotkey_listener_class_init (GtkHotkeyListenerClass * klass)
{
gtk_hotkey_listener_parent_class = g_type_class_peek_parent (klass);
/**
* GtkHotkeyListener::activated
* @listener: The object that emitted the signal
* @hotkey: a #GtkHotkeyInfo for the hotkey that was activated
* @event_time: Time for event triggering the keypress. This is mainly
* used to pass to window management functions to pass through
* focus stealing prevention
*
* Emitted when a registered hotkey has been activated.
*/
listener_signals[ACTIVATED] = \
g_signal_new ("activated",
GTK_HOTKEY_TYPE_LISTENER,
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
gtk_hotkey_marshal_VOID__OBJECT_UINT,
G_TYPE_NONE, 2,
GTK_HOTKEY_TYPE_INFO,
G_TYPE_UINT);
}
static void
gtk_hotkey_listener_init (GtkHotkeyListener * self)
{
}
GType
gtk_hotkey_listener_get_type (void)
{
static GType gtk_hotkey_listener_type_id = 0;
if (G_UNLIKELY (gtk_hotkey_listener_type_id == 0)) {
static const GTypeInfo g_define_type_info = {
sizeof (GtkHotkeyListenerClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gtk_hotkey_listener_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GtkHotkeyListener),
0,
(GInstanceInitFunc) gtk_hotkey_listener_init
};
gtk_hotkey_listener_type_id = g_type_register_static (G_TYPE_OBJECT,
"GtkHotkeyListener",
&g_define_type_info,
G_TYPE_FLAG_ABSTRACT);
default_listener_type = gtk_hotkey_x11_listener_get_type ();
}
return gtk_hotkey_listener_type_id;
}

View file

@ -0,0 +1,77 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __GTK_HOTKEY_LISTENER_H__
#define __GTK_HOTKEY_LISTENER_H__
#include <glib.h>
#include <glib-object.h>
#include "gtk-hotkey-info.h"
G_BEGIN_DECLS
#define GTK_HOTKEY_TYPE_LISTENER (gtk_hotkey_listener_get_type ())
#define GTK_HOTKEY_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_HOTKEY_TYPE_LISTENER, GtkHotkeyListener))
#define GTK_HOTKEY_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_HOTKEY_TYPE_LISTENER, GtkHotkeyListenerClass))
#define GTK_HOTKEY_IS_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_HOTKEY_TYPE_LISTENER))
#define GTK_HOTKEY_IS_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_HOTKEY_TYPE_LISTENER))
#define GTK_HOTKEY_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_HOTKEY_TYPE_LISTENER, GtkHotkeyListenerClass))
typedef struct _GtkHotkeyListener GtkHotkeyListener;
typedef struct _GtkHotkeyListenerClass GtkHotkeyListenerClass;
typedef struct _GtkHotkeyListenerPrivate GtkHotkeyListenerPrivate;
struct _GtkHotkeyListener {
GObject parent;
GtkHotkeyListenerPrivate *priv;
};
struct _GtkHotkeyListenerClass {
GObjectClass parent;
gboolean (*bind_hotkey) (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
GError **error);
gboolean (*unbind_hotkey) (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
GError **error);
};
GtkHotkeyListener* gtk_hotkey_listener_get_default (void);
void gtk_hotkey_listener_activated (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
guint event_time);
gboolean gtk_hotkey_listener_bind_hotkey (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
GError **error);
gboolean gtk_hotkey_listener_unbind_hotkey (GtkHotkeyListener *self,
GtkHotkeyInfo *hotkey,
GError **error);
GType gtk_hotkey_listener_get_type (void);
G_END_DECLS
#endif /* __GTK_HOTKEY_LISTENER_H__ */

View file

@ -0,0 +1,86 @@
#include <glib-object.h>
#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
#define g_marshal_value_peek_char(v) g_value_get_char (v)
#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)
#define g_marshal_value_peek_int(v) g_value_get_int (v)
#define g_marshal_value_peek_uint(v) g_value_get_uint (v)
#define g_marshal_value_peek_long(v) g_value_get_long (v)
#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)
#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)
#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)
#define g_marshal_value_peek_enum(v) g_value_get_enum (v)
#define g_marshal_value_peek_flags(v) g_value_get_flags (v)
#define g_marshal_value_peek_float(v) g_value_get_float (v)
#define g_marshal_value_peek_double(v) g_value_get_double (v)
#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
#define g_marshal_value_peek_param(v) g_value_get_param (v)
#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)
#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)
#define g_marshal_value_peek_object(v) g_value_get_object (v)
#else /* !G_ENABLE_DEBUG */
/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
* Do not access GValues directly in your code. Instead, use the
* g_value_get_*() functions
*/
#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int
#define g_marshal_value_peek_char(v) (v)->data[0].v_int
#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint
#define g_marshal_value_peek_int(v) (v)->data[0].v_int
#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint
#define g_marshal_value_peek_long(v) (v)->data[0].v_long
#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64
#define g_marshal_value_peek_enum(v) (v)->data[0].v_long
#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong
#define g_marshal_value_peek_float(v) (v)->data[0].v_float
#define g_marshal_value_peek_double(v) (v)->data[0].v_double
#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer
#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
#endif /* !G_ENABLE_DEBUG */
/* VOID:OBJECT,UINT (src/marshal.list:2) */
void
gtk_hotkey_marshal_VOID__OBJECT_UINT (GClosure *closure,
GValue *return_value G_GNUC_UNUSED,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint G_GNUC_UNUSED,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__OBJECT_UINT) (gpointer data1,
gpointer arg_1,
guint arg_2,
gpointer data2);
register GMarshalFunc_VOID__OBJECT_UINT callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
g_return_if_fail (n_param_values == 3);
if (G_CCLOSURE_SWAP_DATA (closure))
{
data1 = closure->data;
data2 = g_value_peek_pointer (param_values + 0);
}
else
{
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
callback = (GMarshalFunc_VOID__OBJECT_UINT) (marshal_data ? marshal_data : cc->callback);
callback (data1,
g_marshal_value_peek_object (param_values + 1),
g_marshal_value_peek_uint (param_values + 2),
data2);
}

View file

@ -0,0 +1,24 @@
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __gtk_hotkey_marshal_MARSHAL_H__
#define __gtk_hotkey_marshal_MARSHAL_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* VOID:OBJECT,UINT (src/marshal.list:2) */
extern void gtk_hotkey_marshal_VOID__OBJECT_UINT (GClosure *closure,
GValue *return_value,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint,
gpointer marshal_data);
G_END_DECLS
#endif /* __gtk_hotkey_marshal_MARSHAL_H__ */

View file

@ -0,0 +1,341 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gtk-hotkey-registry.h"
#include "gtk-hotkey-key-file-registry.h"
enum {
GTK_HOTKEY_REGISTRY_DUMMY_PROPERTY
};
enum {
HOTKEY_STORED,
HOTKEY_DELETED,
LAST_SIGNAL
};
static gpointer gtk_hotkey_registry_parent_class = NULL;
static GType default_registry_type = G_TYPE_INVALID;
static GtkHotkeyRegistry
*default_registry = NULL;
#define DEFAULT_REGISTRY_TYPE GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY
guint storage_signals[LAST_SIGNAL] = { 0 };
/**
* SECTION:gtk-hotkey-registry
* @short_description: Abstract base class for services storing and loading hotkeys
* @see_also: #GtkHotkeyKeyFileRegistry
*
* #GtkHotkeyRegistry is an abstract base class for implementing a platform
* specific service for storing and loading hotkey configurations.
*
* The actual binding of the hotkey into the environment is done by a
* #GtkHotkeyListener. This class is only meant to do the management part of the
* hotkey handling.
*
* The reasong why applications should use a #GtkHotkeyRegistry and not just a
* flat text file with the hotkey signature is to make sure we don't overwrite
* or interfere with the hotkeys of other applications. And possibly providing
* a unified user interface for managing the hotkeys of all applications.
*
* To obtain a #GtkHotkeyRegistry matching your desktop environment use
* the factory method gtk_hotkey_registry_get_default().
*
**/
/**
* gtk_hotkey_registry_get_default
* @returns: A reference to a #GtkHotkeyRegistry matching your platform
*
* Currently the only implementation of this class is #GtkHotkeyKeyFileRegistry.
*/
GtkHotkeyRegistry*
gtk_hotkey_registry_get_default (void)
{
if (G_UNLIKELY(default_registry == NULL)) {
/* Set the default type of registry to create */
if (default_registry_type == G_TYPE_INVALID)
default_registry_type = DEFAULT_REGISTRY_TYPE;
default_registry = GTK_HOTKEY_REGISTRY (g_object_new (GTK_HOTKEY_TYPE_KEY_FILE_REGISTRY,
NULL));
g_return_val_if_fail (GTK_HOTKEY_IS_REGISTRY(default_registry), NULL);
/* We always keep a ref to the registry here */
}
return g_object_ref(default_registry);
}
/**
* gtk_hotkey_registry_get_hotkey
* @self: The registry to search in
* @app_id: The name under which the application has registered it self
* when it created the #GtkHotkeyInfo in the first place.
* @key_id: The id assignedd to the actual hotkey on the moment of its creation
* @error: Place to store a #GError in case of errors, or %NULL to ignore
* @returns: The #GtkHotkeyInfo for the requested parameters or %NULL is none
* where found. In the case %NULL is returned @error will be set
* accordingly. Free the hotkey with g_object_unref() when you are done
* using it.
*
* Look up a hotkey given its id and application id.
*/
GtkHotkeyInfo*
gtk_hotkey_registry_get_hotkey (GtkHotkeyRegistry *self,
const char *app_id,
const char *key_id,
GError **error)
{
g_return_val_if_fail (GTK_HOTKEY_IS_REGISTRY(self), NULL);
return GTK_HOTKEY_REGISTRY_GET_CLASS (self)->get_hotkey (self, app_id, key_id,
error);
}
/**
* gtk_hotkey_registry_get_application_hotkeys
* @self: The #GtkHotkeyRegistry to look hotkeys up in
* @app_id: Unique application id
* @error: Place to return a #GError or %NULL
* @returns: A list of #GtkHotkeyInfo objects. The list should be with freed with
* g_list_free() and the hotkey objects should be freed with
* g_object_unref().
*
* Look up all hotkeys registered by a given application.
*/
GList*
gtk_hotkey_registry_get_application_hotkeys (GtkHotkeyRegistry *self,
const char *app_id,
GError **error)
{
g_return_val_if_fail (GTK_HOTKEY_IS_REGISTRY(self), NULL);
return GTK_HOTKEY_REGISTRY_GET_CLASS (self)->get_application_hotkeys (self, app_id, error);
}
/**
* gtk_hotkey_registry_get_all_hotkeys
* @self: The #GtkHotkeyRegistry to look hotkeys up in
* @returns: A list of all valid #GtkHotkeyInfo<!-- -->s stored in the registry.
* The list should be with freed with g_list_free() and the hotkey
* objects should be freed with g_object_unref().
*
* Look up all hotkeys registered by a given application.
*/
GList*
gtk_hotkey_registry_get_all_hotkeys (GtkHotkeyRegistry *self)
{
g_return_val_if_fail (GTK_HOTKEY_IS_REGISTRY(self), NULL);
return GTK_HOTKEY_REGISTRY_GET_CLASS (self)->get_all_hotkeys (self);
}
/**
* gtk_hotkey_registry_store_hotkey
* @self: The #GtkHotkeyRegistry in which to store the hotkey
* @info: The #GtkHotkeyInfo to store
* @error: Place to return a #GError or %NULL to ignore
* @returns: %TRUE on success and %FALS otherwise. In case of errors @error
* will be set accordingly.
*
* Store a hotkey in the registry for later usage. In case of success the
* #GtkHotkeyRegistry::hotkey-stored signal will be emitted.
*/
gboolean
gtk_hotkey_registry_store_hotkey (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info,
GError **error)
{
g_return_val_if_fail (GTK_HOTKEY_IS_REGISTRY(self), FALSE);
return GTK_HOTKEY_REGISTRY_GET_CLASS (self)->store_hotkey (self, info, error);
}
/**
* gtk_hotkey_registry_delete_hotkey
* @self: The #GtkHotkeyRegistry from which to delete the hotkey
* @app_id: The value of the #GtkHotkeyInfo:application-id property of the stored
* hotkey
* @key_id: The value of the #GtkHotkeyInfo:key-id property of the stored hotkey
* @error: Place to return a #GError or %NULL to ignore
* @returns: %TRUE on success and %FALS otherwise. In case of errors @error
* will be set accordingly.
*
* Delete a hotkey from the registry. In case of success the
* #GtkHotkeyRegistry::hotkey-deleted signal will be emitted.
*/
gboolean
gtk_hotkey_registry_delete_hotkey (GtkHotkeyRegistry *self,
const gchar *app_id,
const gchar *key_id,
GError **error)
{
g_return_val_if_fail (GTK_HOTKEY_IS_REGISTRY(self), FALSE);
return GTK_HOTKEY_REGISTRY_GET_CLASS (self)->delete_hotkey (self, app_id,
key_id, error);
}
/**
* gtk_hotkey_registry_has_hotkey
* @self: The #GtkHotkeyRegistry to look hotkeys up in
* @app_id: The value of the #GtkHotkeyInfo:application-id property of the stored
* hotkey
* @key_id: The value of the #GtkHotkeyInfo:key-id property of the stored hotkey
* @returns: %TRUE if the registry has stored a hotkey with with application id
* @app_id and hotkey id @key_id.
*
* Look up all hotkeys registered by a given application.
*/
gboolean
gtk_hotkey_registry_has_hotkey (GtkHotkeyRegistry *self,
const gchar *app_id,
const gchar *key_id)
{
g_return_val_if_fail (GTK_HOTKEY_IS_REGISTRY(self), FALSE);
return GTK_HOTKEY_REGISTRY_GET_CLASS (self)->has_hotkey (self, app_id, key_id);
}
/**
* gtk_hotkey_registry_hotkey_stored
* @self: The #GtkHotkeyRegistry to emit the signal on
* @info: The #GtkHotkeyInfo that was stored
*
* Emit the #GtkHotkeyRegistry::hotkey-stored signal on @self. This method should
* only be used by child classes of #GtkHotkeyRegistry.
*/
void
gtk_hotkey_registry_hotkey_stored (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info)
{
g_return_if_fail (GTK_HOTKEY_IS_REGISTRY(self));
g_return_if_fail (GTK_HOTKEY_IS_INFO(info));
GTK_HOTKEY_REGISTRY_GET_CLASS (self)->hotkey_stored (self, info);
}
/**
* gtk_hotkey_registry_hotkey_deleted
* @self: The #GtkHotkeyRegistry to emit the signal on
* @info: The #GtkHotkeyInfo that was deleted
*
* Emit the #GtkHotkeyRegistry::hotkey-deleted signal on @self. This method should
* only be used by child classes of #GtkHotkeyRegistry.
*/
void
gtk_hotkey_registry_hotkey_deleted (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info)
{
g_return_if_fail (GTK_HOTKEY_IS_REGISTRY(self));
GTK_HOTKEY_REGISTRY_GET_CLASS (self)->hotkey_deleted (self, info);
}
static void
gtk_hotkey_registry_hotkey_stored_real (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info)
{
g_return_if_fail (GTK_HOTKEY_IS_INFO(info));
g_return_if_fail (GTK_HOTKEY_IS_REGISTRY(self));
g_signal_emit (self, storage_signals[HOTKEY_STORED], 0, info);
}
static void
gtk_hotkey_registry_hotkey_deleted_real (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info)
{
g_return_if_fail (GTK_HOTKEY_IS_INFO(info));
g_return_if_fail (GTK_HOTKEY_IS_REGISTRY(self));
g_signal_emit (self, storage_signals[HOTKEY_DELETED], 0, info);
}
static void
gtk_hotkey_registry_class_init (GtkHotkeyRegistryClass *klass)
{
gtk_hotkey_registry_parent_class = g_type_class_peek_parent (klass);
klass->hotkey_stored = gtk_hotkey_registry_hotkey_stored_real;
klass->hotkey_deleted = gtk_hotkey_registry_hotkey_deleted_real;
/**
* GtkHotkeyRegistry::hotkey-stored
* @hotkey:The hotkey that was stored
*
* Emitted when a hotkey has been stored in the registry
*/
storage_signals[HOTKEY_STORED] = \
g_signal_new ("hotkey_stored",
GTK_HOTKEY_TYPE_STORAGE,
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
/**
* GtkHotkeyRegistry::hotkey-deleted
* @hotkey:The hotkey that was deleted
*
* Emitted when a hotkey has been deleted from the registry
*/
storage_signals[HOTKEY_DELETED] = \
g_signal_new ("hotkey_deleted",
GTK_HOTKEY_TYPE_STORAGE,
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
}
static void
gtk_hotkey_registry_init (GtkHotkeyRegistry * self)
{
}
static void
gtk_hotkey_registry_finalize (GtkHotkeyRegistry * self)
{
}
GType
gtk_hotkey_registry_get_type (void)
{
static GType gtk_hotkey_registry_type_id = 0;
if (G_UNLIKELY (gtk_hotkey_registry_type_id == 0)) {
static const GTypeInfo g_define_type_info = {
sizeof (GtkHotkeyRegistryClass),
(GBaseInitFunc) gtk_hotkey_registry_init,
(GBaseFinalizeFunc) gtk_hotkey_registry_finalize,
(GClassInitFunc) gtk_hotkey_registry_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GtkHotkeyRegistry),
0,
(GInstanceInitFunc) gtk_hotkey_registry_init
};
gtk_hotkey_registry_type_id = g_type_register_static (G_TYPE_OBJECT, "GtkHotkeyRegistry", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
}
return gtk_hotkey_registry_type_id;
}

View file

@ -0,0 +1,114 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __GTK_HOTKEY_REGISTRY_H__
#define __GTK_HOTKEY_REGISTRY_H__
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "gtk-hotkey-info.h"
#include "gtk-hotkey-error.h"
G_BEGIN_DECLS
#define GTK_HOTKEY_TYPE_STORAGE (gtk_hotkey_registry_get_type ())
#define GTK_HOTKEY_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_HOTKEY_TYPE_STORAGE, GtkHotkeyRegistry))
#define GTK_HOTKEY_REGISTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_HOTKEY_TYPE_STORAGE, GtkHotkeyRegistryClass))
#define GTK_HOTKEY_IS_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_HOTKEY_TYPE_STORAGE))
#define GTK_HOTKEY_IS_REGISTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_HOTKEY_TYPE_STORAGE))
#define GTK_HOTKEY_REGISTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_HOTKEY_TYPE_STORAGE, GtkHotkeyRegistryClass))
typedef struct _GtkHotkeyRegistry GtkHotkeyRegistry;
typedef struct _GtkHotkeyRegistryClass GtkHotkeyRegistryClass;
typedef struct _GtkHotkeyRegistryPrivate GtkHotkeyRegistryPrivate;
struct _GtkHotkeyRegistry {
GObject parent;
GtkHotkeyRegistryPrivate * priv;
};
struct _GtkHotkeyRegistryClass {
GObjectClass parent;
GtkHotkeyInfo* (*get_hotkey) (GtkHotkeyRegistry *self,
const char *app_id,
const char *key_id,
GError **error);
GList* (*get_application_hotkeys) (GtkHotkeyRegistry *self,
const char *app_id,
GError **error);
GList* (*get_all_hotkeys) (GtkHotkeyRegistry *self);
gboolean (*store_hotkey) (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info,
GError **error);
gboolean (*delete_hotkey) (GtkHotkeyRegistry *self,
const gchar *app_id,
const gchar *key_id,
GError **error);
gboolean (*has_hotkey) (GtkHotkeyRegistry *self,
const gchar *app_id,
const gchar *key_id);
void (*hotkey_stored) (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info);
void (*hotkey_deleted) (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info);
};
GtkHotkeyRegistry* gtk_hotkey_registry_get_default (void);
GtkHotkeyInfo* gtk_hotkey_registry_get_hotkey (GtkHotkeyRegistry *self,
const char *app_id,
const char *key_id,
GError **error);
GList* gtk_hotkey_registry_get_application_hotkeys
(GtkHotkeyRegistry *self,
const char *app_id,
GError **error);
GList* gtk_hotkey_registry_get_all_hotkeys (GtkHotkeyRegistry *self);
gboolean gtk_hotkey_registry_store_hotkey (GtkHotkeyRegistry *self,
GtkHotkeyInfo *info,
GError **error);
gboolean gtk_hotkey_registry_delete_hotkey (GtkHotkeyRegistry *self,
const gchar *app_id,
const gchar *key_id,
GError **error);
gboolean gtk_hotkey_registry_has_hotkey (GtkHotkeyRegistry *self,
const gchar *app_id,
const gchar *key_id);
void gtk_hotkey_registry_hotkey_stored (GtkHotkeyRegistry *self,
GtkHotkeyInfo *hotkey);
void gtk_hotkey_registry_hotkey_deleted (GtkHotkeyRegistry *self,
GtkHotkeyInfo *hotkey);
GType gtk_hotkey_registry_get_type (void);
G_END_DECLS
#endif

View file

@ -0,0 +1,48 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gio/gio.h>
GFileType
gtk_hotkey_g_file_get_type (GFile *file)
{
GFileInfo *info;
GFileType type;
GError *error;
g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
if (!g_file_query_exists(file, NULL))
return G_FILE_TYPE_UNKNOWN;
g_return_val_if_fail (G_IS_FILE(file), G_FILE_TYPE_UNKNOWN);
error = NULL;
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
0, NULL, &error);
if (error) {
g_critical ("Failed to create GFileInfo: %s", error->message);
g_error_free (error);
return G_FILE_TYPE_UNKNOWN;
}
type = g_file_info_get_file_type (info);
g_object_unref (info);
return type;
}

View file

@ -0,0 +1,37 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __GTK_HOTKEY_UTILS_H__
#define __GTK_HOTKEY_UTILS_H__
#include <gio/gio.h>
G_BEGIN_DECLS
#define gtk_hotkey_g_file_is_directory(file) (gtk_hotkey_g_file_get_type(file) == G_FILE_TYPE_DIRECTORY)
#define gtk_hotkey_g_file_is_regular(file) (gtk_hotkey_g_file_get_type(file) == G_FILE_TYPE_REGULAR)
GFileType gtk_hotkey_g_file_get_type (GFile *file);
G_END_DECLS
#endif /* __GTK_HOTKEY_UTILS_H__ */

View file

@ -0,0 +1,243 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gtk-hotkey-error.h"
#include "gtk-hotkey-x11-listener.h"
#include "gtk-hotkey-listener.h"
#include "gtk-hotkey-info.h"
#include "x11/tomboykeybinder.h"
struct _GtkHotkeyX11ListenerPrivate {
GList *hotkeys;
};
enum {
GTK_HOTKEY_X11_LISTENER_DUMMY_PROPERTY
};
static gboolean gtk_hotkey_x11_listener_real_bind_hotkey (GtkHotkeyListener *base,
GtkHotkeyInfo *hotkey,
GError **error);
static gboolean gtk_hotkey_x11_listener_real_unbind_hotkey (GtkHotkeyListener *base,
GtkHotkeyInfo *hotkey,
GError **error);
static void hotkey_activated_cb (char *signature,
gpointer user_data);
static GtkHotkeyInfo*
find_hotkey_from_key_id (GtkHotkeyX11Listener *self,
const gchar *key_id);
static gpointer gtk_hotkey_x11_listener_parent_class = NULL;
/**
* SECTION:gtk-hotkey-x11-listener
* @short_description: Implementation of #GtkHotkeyListener for a standard X11
* environment
* @see_also: #GtkHotkeyRegistry, #GtkHotkeyInfo
*
* This implementation of a #GtkHotkeyListener should work in any X11
* environment.
**/
static gboolean
gtk_hotkey_x11_listener_real_bind_hotkey (GtkHotkeyListener *base,
GtkHotkeyInfo *hotkey,
GError **error)
{
GtkHotkeyX11Listener *self;
g_return_val_if_fail (GTK_HOTKEY_IS_X11_LISTENER(base), FALSE);
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (hotkey), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
self = GTK_HOTKEY_X11_LISTENER (base);
if (find_hotkey_from_key_id(self,
gtk_hotkey_info_get_key_id (hotkey))) {
g_warning ("Hotkey '%s' already registered. Ignoring register request.",
gtk_hotkey_info_get_key_id (hotkey));
return FALSE;
}
if (tomboy_keybinder_bind (gtk_hotkey_info_get_signature(hotkey),
hotkey_activated_cb,
self)) {
self->priv->hotkeys = g_list_prepend (self->priv->hotkeys, hotkey);
g_object_ref (hotkey);
return TRUE;
}
/* Bugger, we failed to bind */
g_set_error (error, GTK_HOTKEY_LISTENER_ERROR,
GTK_HOTKEY_LISTENER_ERROR_BIND,
"Failed to register hotkey '%s' with signature '%s'",
gtk_hotkey_info_get_key_id (hotkey),
gtk_hotkey_info_get_signature (hotkey));
return FALSE;
}
static gboolean
gtk_hotkey_x11_listener_real_unbind_hotkey (GtkHotkeyListener *base,
GtkHotkeyInfo *hotkey,
GError **error)
{
GtkHotkeyX11Listener *self;
GtkHotkeyInfo *saved_hk;
const gchar *signature;
g_return_val_if_fail (GTK_HOTKEY_IS_X11_LISTENER (base), FALSE);
g_return_val_if_fail (GTK_HOTKEY_IS_INFO (hotkey), FALSE);
self = GTK_HOTKEY_X11_LISTENER (base);
signature = gtk_hotkey_info_get_signature (hotkey);
saved_hk = find_hotkey_from_key_id (self, gtk_hotkey_info_get_key_id(hotkey));
if (!saved_hk) {
g_set_error (error, GTK_HOTKEY_LISTENER_ERROR,
GTK_HOTKEY_LISTENER_ERROR_UNBIND,
"Failed to unregister hotkey '%s' with signature '%s'. "
"No hotkey with that signature is known",
gtk_hotkey_info_get_key_id (hotkey),
signature);
return FALSE;
}
/* Remove actual keybinding */
tomboy_keybinder_unbind (signature, hotkey_activated_cb);
/* Clean up refs */
self->priv->hotkeys = g_list_remove (self->priv->hotkeys, saved_hk);
g_object_unref (saved_hk);
/* Clean up signal handler */
gulong handler = g_signal_handler_find (self,
G_SIGNAL_MATCH_DATA | G_SIGNAL_MATCH_FUNC,
0, 0, NULL, gtk_hotkey_info_activated,
hotkey);
if (handler == 0) {
g_warning ("Failed to disconnect signal handler for hotkey '%s'",
gtk_hotkey_info_get_key_id (hotkey));
} else {
g_signal_handler_disconnect (self, handler);
}
return TRUE;
}
static void
hotkey_activated_cb (char *signature,
gpointer user_data)
{
GtkHotkeyX11Listener *self;
GtkHotkeyInfo *hotkey;
GList *iter;
guint event_time;
g_return_if_fail (GTK_HOTKEY_IS_X11_LISTENER(user_data));
g_return_if_fail (signature != NULL);
self = GTK_HOTKEY_X11_LISTENER(user_data);
event_time = tomboy_keybinder_get_current_event_time ();
/* Trigger signals for hotkeys with matching signature */
for (iter = self->priv->hotkeys; iter; iter = iter->next) {
hotkey = GTK_HOTKEY_INFO (iter->data);
if (g_str_equal (signature, gtk_hotkey_info_get_signature (hotkey))) {
gtk_hotkey_listener_activated (GTK_HOTKEY_LISTENER(self),
hotkey, event_time);
gtk_hotkey_info_activated (hotkey, event_time);
}
}
}
static GtkHotkeyInfo*
find_hotkey_from_key_id (GtkHotkeyX11Listener *self,
const gchar *key_id)
{
GList *iter;
GtkHotkeyInfo *hotkey;
g_return_val_if_fail (GTK_HOTKEY_IS_X11_LISTENER(self), NULL);
g_return_val_if_fail (key_id != NULL, NULL);
for (iter = self->priv->hotkeys; iter; iter = iter->next) {
hotkey = GTK_HOTKEY_INFO (iter->data);
if (g_str_equal (gtk_hotkey_info_get_key_id(hotkey), key_id))
return hotkey;
}
return NULL;
}
static void
gtk_hotkey_x11_listener_class_init (GtkHotkeyX11ListenerClass * klass)
{
gtk_hotkey_x11_listener_parent_class = g_type_class_peek_parent (klass);
GTK_HOTKEY_LISTENER_CLASS (klass)->bind_hotkey =
gtk_hotkey_x11_listener_real_bind_hotkey;
GTK_HOTKEY_LISTENER_CLASS (klass)->unbind_hotkey =
gtk_hotkey_x11_listener_real_unbind_hotkey;
/* Initialize the tomboy keybinder */
tomboy_keybinder_init ();
}
static void
gtk_hotkey_x11_listener_init (GtkHotkeyX11Listener * self)
{
self->priv = g_new0 (GtkHotkeyX11ListenerPrivate, 1);
}
static void
gtk_hotkey_x11_listener_finalize (GtkHotkeyX11Listener * self)
{
g_free(self->priv);
}
GType
gtk_hotkey_x11_listener_get_type (void)
{
static GType gtk_hotkey_x11_listener_type_id = 0;
if (G_UNLIKELY (gtk_hotkey_x11_listener_type_id == 0)) {
static const GTypeInfo g_define_type_info = {
sizeof (GtkHotkeyX11ListenerClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) gtk_hotkey_x11_listener_finalize,
(GClassInitFunc) gtk_hotkey_x11_listener_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (GtkHotkeyX11Listener),
0,
(GInstanceInitFunc) gtk_hotkey_x11_listener_init
};
gtk_hotkey_x11_listener_type_id = g_type_register_static (GTK_HOTKEY_TYPE_LISTENER, "GtkHotkeyX11Listener", &g_define_type_info, 0);
}
return gtk_hotkey_x11_listener_type_id;
}

View file

@ -0,0 +1,57 @@
/*
* This file is part of GtkHotkey.
* Copyright Mikkel Kamstrup Erlandsen, March, 2008
*
* GtkHotkey is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GtkHotkey is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__GTK_HOTKEY_H__) && !defined (GTK_HOTKEY_COMPILATION)
#error "Only <gtkhotkey.h> can be included directly."
#endif
#ifndef __GTK_HOTKEY_X11_LISTENER_H__
#define __GTK_HOTKEY_X11_LISTENER_H__
#include <glib.h>
#include <glib-object.h>
#include "gtk-hotkey-listener.h"
#include "gtk-hotkey-info.h"
G_BEGIN_DECLS
#define GTK_HOTKEY_TYPE_X11_LISTENER (gtk_hotkey_x11_listener_get_type ())
#define GTK_HOTKEY_X11_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_HOTKEY_TYPE_X11_LISTENER, GtkHotkeyX11Listener))
#define GTK_HOTKEY_X11_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_HOTKEY_TYPE_X11_LISTENER, GtkHotkeyX11ListenerClass))
#define GTK_HOTKEY_IS_X11_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_HOTKEY_TYPE_X11_LISTENER))
#define GTK_HOTKEY_IS_X11_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_HOTKEY_TYPE_X11_LISTENER))
#define GTK_HOTKEY_X11_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_HOTKEY_TYPE_X11_LISTENER, GtkHotkeyX11ListenerClass))
typedef struct _GtkHotkeyX11Listener GtkHotkeyX11Listener;
typedef struct _GtkHotkeyX11ListenerClass GtkHotkeyX11ListenerClass;
typedef struct _GtkHotkeyX11ListenerPrivate GtkHotkeyX11ListenerPrivate;
struct _GtkHotkeyX11Listener {
GtkHotkeyListener parent;
GtkHotkeyX11ListenerPrivate * priv;
};
struct _GtkHotkeyX11ListenerClass {
GtkHotkeyListenerClass parent;
};
GType gtk_hotkey_x11_listener_get_type (void);
G_END_DECLS
#endif

View file

@ -0,0 +1,12 @@
#ifndef __GTK_HOTKEY_H__
#define __GTK_HOTKEY_H__
#include <gtk-hotkey-info.h>
#include <gtk-hotkey-registry.h>
#include <gtk-hotkey-key-file-registry.h>
#include <gtk-hotkey-listener.h>
#include <gtk-hotkey-x11-listener.h>
#include <gtk-hotkey-error.h>
#endif /* __GTK_HOTKEY_H__ */

View file

@ -0,0 +1,657 @@
/* eggaccelerators.c
* Copyright (C) 2002 Red Hat, Inc.; Copyright 1998, 2001 Tim Janik
* Developed by Havoc Pennington, Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "eggaccelerators.h"
#include <string.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
enum
{
EGG_MODMAP_ENTRY_SHIFT = 0,
EGG_MODMAP_ENTRY_LOCK = 1,
EGG_MODMAP_ENTRY_CONTROL = 2,
EGG_MODMAP_ENTRY_MOD1 = 3,
EGG_MODMAP_ENTRY_MOD2 = 4,
EGG_MODMAP_ENTRY_MOD3 = 5,
EGG_MODMAP_ENTRY_MOD4 = 6,
EGG_MODMAP_ENTRY_MOD5 = 7,
EGG_MODMAP_ENTRY_LAST = 8
};
#define MODMAP_ENTRY_TO_MODIFIER(x) (1 << (x))
typedef struct
{
EggVirtualModifierType mapping[EGG_MODMAP_ENTRY_LAST];
} EggModmap;
const EggModmap* egg_keymap_get_modmap (GdkKeymap *keymap);
static inline gboolean
is_alt (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'a' || string[1] == 'A') &&
(string[2] == 'l' || string[2] == 'L') &&
(string[3] == 't' || string[3] == 'T') &&
(string[4] == '>'));
}
static inline gboolean
is_ctl (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'c' || string[1] == 'C') &&
(string[2] == 't' || string[2] == 'T') &&
(string[3] == 'l' || string[3] == 'L') &&
(string[4] == '>'));
}
static inline gboolean
is_modx (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'm' || string[1] == 'M') &&
(string[2] == 'o' || string[2] == 'O') &&
(string[3] == 'd' || string[3] == 'D') &&
(string[4] >= '1' && string[4] <= '5') &&
(string[5] == '>'));
}
static inline gboolean
is_ctrl (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'c' || string[1] == 'C') &&
(string[2] == 't' || string[2] == 'T') &&
(string[3] == 'r' || string[3] == 'R') &&
(string[4] == 'l' || string[4] == 'L') &&
(string[5] == '>'));
}
static inline gboolean
is_shft (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 's' || string[1] == 'S') &&
(string[2] == 'h' || string[2] == 'H') &&
(string[3] == 'f' || string[3] == 'F') &&
(string[4] == 't' || string[4] == 'T') &&
(string[5] == '>'));
}
static inline gboolean
is_shift (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 's' || string[1] == 'S') &&
(string[2] == 'h' || string[2] == 'H') &&
(string[3] == 'i' || string[3] == 'I') &&
(string[4] == 'f' || string[4] == 'F') &&
(string[5] == 't' || string[5] == 'T') &&
(string[6] == '>'));
}
static inline gboolean
is_control (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'c' || string[1] == 'C') &&
(string[2] == 'o' || string[2] == 'O') &&
(string[3] == 'n' || string[3] == 'N') &&
(string[4] == 't' || string[4] == 'T') &&
(string[5] == 'r' || string[5] == 'R') &&
(string[6] == 'o' || string[6] == 'O') &&
(string[7] == 'l' || string[7] == 'L') &&
(string[8] == '>'));
}
static inline gboolean
is_release (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'r' || string[1] == 'R') &&
(string[2] == 'e' || string[2] == 'E') &&
(string[3] == 'l' || string[3] == 'L') &&
(string[4] == 'e' || string[4] == 'E') &&
(string[5] == 'a' || string[5] == 'A') &&
(string[6] == 's' || string[6] == 'S') &&
(string[7] == 'e' || string[7] == 'E') &&
(string[8] == '>'));
}
static inline gboolean
is_meta (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'm' || string[1] == 'M') &&
(string[2] == 'e' || string[2] == 'E') &&
(string[3] == 't' || string[3] == 'T') &&
(string[4] == 'a' || string[4] == 'A') &&
(string[5] == '>'));
}
static inline gboolean
is_super (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 's' || string[1] == 'S') &&
(string[2] == 'u' || string[2] == 'U') &&
(string[3] == 'p' || string[3] == 'P') &&
(string[4] == 'e' || string[4] == 'E') &&
(string[5] == 'r' || string[5] == 'R') &&
(string[6] == '>'));
}
static inline gboolean
is_hyper (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'h' || string[1] == 'H') &&
(string[2] == 'y' || string[2] == 'Y') &&
(string[3] == 'p' || string[3] == 'P') &&
(string[4] == 'e' || string[4] == 'E') &&
(string[5] == 'r' || string[5] == 'R') &&
(string[6] == '>'));
}
/**
* egg_accelerator_parse_virtual:
* @accelerator: string representing an accelerator
* @accelerator_key: return location for accelerator keyval
* @accelerator_mods: return location for accelerator modifier mask
*
* Parses a string representing a virtual accelerator. The format
* looks like "&lt;Control&gt;a" or "&lt;Shift&gt;&lt;Alt&gt;F1" or
* "&lt;Release&gt;z" (the last one is for key release). The parser
* is fairly liberal and allows lower or upper case, and also
* abbreviations such as "&lt;Ctl&gt;" and "&lt;Ctrl&gt;".
*
* If the parse fails, @accelerator_key and @accelerator_mods will
* be set to 0 (zero) and %FALSE will be returned. If the string contains
* only modifiers, @accelerator_key will be set to 0 but %TRUE will be
* returned.
*
* The virtual vs. concrete accelerator distinction is a relic of
* how the X Window System works; there are modifiers Mod2-Mod5 that
* can represent various keyboard keys (numlock, meta, hyper, etc.),
* the virtual modifier represents the keyboard key, the concrete
* modifier the actual Mod2-Mod5 bits in the key press event.
*
* Returns: %TRUE on success.
*/
gboolean
egg_accelerator_parse_virtual (const gchar *accelerator,
guint *accelerator_key,
EggVirtualModifierType *accelerator_mods)
{
guint keyval;
GdkModifierType mods;
gint len;
gboolean bad_keyval;
if (accelerator_key)
*accelerator_key = 0;
if (accelerator_mods)
*accelerator_mods = 0;
g_return_val_if_fail (accelerator != NULL, FALSE);
bad_keyval = FALSE;
keyval = 0;
mods = 0;
len = strlen (accelerator);
while (len)
{
if (*accelerator == '<')
{
if (len >= 9 && is_release (accelerator))
{
accelerator += 9;
len -= 9;
mods |= EGG_VIRTUAL_RELEASE_MASK;
}
else if (len >= 9 && is_control (accelerator))
{
accelerator += 9;
len -= 9;
mods |= EGG_VIRTUAL_CONTROL_MASK;
}
else if (len >= 7 && is_shift (accelerator))
{
accelerator += 7;
len -= 7;
mods |= EGG_VIRTUAL_SHIFT_MASK;
}
else if (len >= 6 && is_shft (accelerator))
{
accelerator += 6;
len -= 6;
mods |= EGG_VIRTUAL_SHIFT_MASK;
}
else if (len >= 6 && is_ctrl (accelerator))
{
accelerator += 6;
len -= 6;
mods |= EGG_VIRTUAL_CONTROL_MASK;
}
else if (len >= 6 && is_modx (accelerator))
{
static const guint mod_vals[] = {
EGG_VIRTUAL_ALT_MASK, EGG_VIRTUAL_MOD2_MASK, EGG_VIRTUAL_MOD3_MASK,
EGG_VIRTUAL_MOD4_MASK, EGG_VIRTUAL_MOD5_MASK
};
len -= 6;
accelerator += 4;
mods |= mod_vals[*accelerator - '1'];
accelerator += 2;
}
else if (len >= 5 && is_ctl (accelerator))
{
accelerator += 5;
len -= 5;
mods |= EGG_VIRTUAL_CONTROL_MASK;
}
else if (len >= 5 && is_alt (accelerator))
{
accelerator += 5;
len -= 5;
mods |= EGG_VIRTUAL_ALT_MASK;
}
else if (len >= 6 && is_meta (accelerator))
{
accelerator += 6;
len -= 6;
mods |= EGG_VIRTUAL_META_MASK;
}
else if (len >= 7 && is_hyper (accelerator))
{
accelerator += 7;
len -= 7;
mods |= EGG_VIRTUAL_HYPER_MASK;
}
else if (len >= 7 && is_super (accelerator))
{
accelerator += 7;
len -= 7;
mods |= EGG_VIRTUAL_SUPER_MASK;
}
else
{
gchar last_ch;
last_ch = *accelerator;
while (last_ch && last_ch != '>')
{
last_ch = *accelerator;
accelerator += 1;
len -= 1;
}
}
}
else
{
keyval = gdk_keyval_from_name (accelerator);
if (keyval == 0)
bad_keyval = TRUE;
accelerator += len;
len -= len;
}
}
if (accelerator_key)
*accelerator_key = gdk_keyval_to_lower (keyval);
if (accelerator_mods)
*accelerator_mods = mods;
return !bad_keyval;
}
/**
* egg_virtual_accelerator_name:
* @accelerator_key: accelerator keyval
* @accelerator_mods: accelerator modifier mask
* @returns: a newly-allocated accelerator name
*
* Converts an accelerator keyval and modifier mask
* into a string parseable by egg_accelerator_parse_virtual().
* For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
* this function returns "&lt;Control&gt;q".
*
* The caller of this function must free the returned string.
*/
gchar*
egg_virtual_accelerator_name (guint accelerator_key,
EggVirtualModifierType accelerator_mods)
{
static const gchar text_release[] = "<Release>";
static const gchar text_shift[] = "<Shift>";
static const gchar text_control[] = "<Control>";
static const gchar text_mod1[] = "<Alt>";
static const gchar text_mod2[] = "<Mod2>";
static const gchar text_mod3[] = "<Mod3>";
static const gchar text_mod4[] = "<Mod4>";
static const gchar text_mod5[] = "<Mod5>";
static const gchar text_meta[] = "<Meta>";
static const gchar text_super[] = "<Super>";
static const gchar text_hyper[] = "<Hyper>";
guint l;
gchar *keyval_name;
gchar *accelerator;
accelerator_mods &= EGG_VIRTUAL_MODIFIER_MASK;
keyval_name = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
if (!keyval_name)
keyval_name = "";
l = 0;
if (accelerator_mods & EGG_VIRTUAL_RELEASE_MASK)
l += sizeof (text_release) - 1;
if (accelerator_mods & EGG_VIRTUAL_SHIFT_MASK)
l += sizeof (text_shift) - 1;
if (accelerator_mods & EGG_VIRTUAL_CONTROL_MASK)
l += sizeof (text_control) - 1;
if (accelerator_mods & EGG_VIRTUAL_ALT_MASK)
l += sizeof (text_mod1) - 1;
if (accelerator_mods & EGG_VIRTUAL_MOD2_MASK)
l += sizeof (text_mod2) - 1;
if (accelerator_mods & EGG_VIRTUAL_MOD3_MASK)
l += sizeof (text_mod3) - 1;
if (accelerator_mods & EGG_VIRTUAL_MOD4_MASK)
l += sizeof (text_mod4) - 1;
if (accelerator_mods & EGG_VIRTUAL_MOD5_MASK)
l += sizeof (text_mod5) - 1;
if (accelerator_mods & EGG_VIRTUAL_META_MASK)
l += sizeof (text_meta) - 1;
if (accelerator_mods & EGG_VIRTUAL_HYPER_MASK)
l += sizeof (text_hyper) - 1;
if (accelerator_mods & EGG_VIRTUAL_SUPER_MASK)
l += sizeof (text_super) - 1;
l += strlen (keyval_name);
accelerator = g_new (gchar, l + 1);
l = 0;
accelerator[l] = 0;
if (accelerator_mods & EGG_VIRTUAL_RELEASE_MASK)
{
strcpy (accelerator + l, text_release);
l += sizeof (text_release) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_SHIFT_MASK)
{
strcpy (accelerator + l, text_shift);
l += sizeof (text_shift) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_CONTROL_MASK)
{
strcpy (accelerator + l, text_control);
l += sizeof (text_control) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_ALT_MASK)
{
strcpy (accelerator + l, text_mod1);
l += sizeof (text_mod1) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_MOD2_MASK)
{
strcpy (accelerator + l, text_mod2);
l += sizeof (text_mod2) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_MOD3_MASK)
{
strcpy (accelerator + l, text_mod3);
l += sizeof (text_mod3) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_MOD4_MASK)
{
strcpy (accelerator + l, text_mod4);
l += sizeof (text_mod4) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_MOD5_MASK)
{
strcpy (accelerator + l, text_mod5);
l += sizeof (text_mod5) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_META_MASK)
{
strcpy (accelerator + l, text_meta);
l += sizeof (text_meta) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_HYPER_MASK)
{
strcpy (accelerator + l, text_hyper);
l += sizeof (text_hyper) - 1;
}
if (accelerator_mods & EGG_VIRTUAL_SUPER_MASK)
{
strcpy (accelerator + l, text_super);
l += sizeof (text_super) - 1;
}
strcpy (accelerator + l, keyval_name);
return accelerator;
}
void
egg_keymap_resolve_virtual_modifiers (GdkKeymap *keymap,
EggVirtualModifierType virtual_mods,
GdkModifierType *concrete_mods)
{
GdkModifierType concrete;
int i;
const EggModmap *modmap;
g_return_if_fail (GDK_IS_KEYMAP (keymap));
g_return_if_fail (concrete_mods != NULL);
modmap = egg_keymap_get_modmap (keymap);
/* Not so sure about this algorithm. */
concrete = 0;
i = 0;
while (i < EGG_MODMAP_ENTRY_LAST)
{
if (modmap->mapping[i] & virtual_mods)
concrete |= (1 << i);
++i;
}
*concrete_mods = concrete;
}
void
egg_keymap_virtualize_modifiers (GdkKeymap *keymap,
GdkModifierType concrete_mods,
EggVirtualModifierType *virtual_mods)
{
GdkModifierType virtual;
int i;
const EggModmap *modmap;
g_return_if_fail (GDK_IS_KEYMAP (keymap));
g_return_if_fail (virtual_mods != NULL);
modmap = egg_keymap_get_modmap (keymap);
/* Not so sure about this algorithm. */
virtual = 0;
i = 0;
while (i < EGG_MODMAP_ENTRY_LAST)
{
if ((1 << i) & concrete_mods)
{
EggVirtualModifierType cleaned;
cleaned = modmap->mapping[i] & ~(EGG_VIRTUAL_MOD2_MASK |
EGG_VIRTUAL_MOD3_MASK |
EGG_VIRTUAL_MOD4_MASK |
EGG_VIRTUAL_MOD5_MASK);
if (cleaned != 0)
{
virtual |= cleaned;
}
else
{
/* Rather than dropping mod2->mod5 if not bound,
* go ahead and use the concrete names
*/
virtual |= modmap->mapping[i];
}
}
++i;
}
*virtual_mods = virtual;
}
static void
reload_modmap (GdkKeymap *keymap,
EggModmap *modmap)
{
XModifierKeymap *xmodmap;
int map_size;
int i;
/* FIXME multihead */
xmodmap = XGetModifierMapping (gdk_x11_get_default_xdisplay ());
memset (modmap->mapping, 0, sizeof (modmap->mapping));
/* there are 8 modifiers, and the first 3 are shift, shift lock,
* and control
*/
map_size = 8 * xmodmap->max_keypermod;
i = 3 * xmodmap->max_keypermod;
while (i < map_size)
{
/* get the key code at this point in the map,
* see if its keysym is one we're interested in
*/
int keycode = xmodmap->modifiermap[i];
GdkKeymapKey *keys;
guint *keyvals;
int n_entries;
int j;
EggVirtualModifierType mask;
keys = NULL;
keyvals = NULL;
n_entries = 0;
gdk_keymap_get_entries_for_keycode (keymap,
keycode,
&keys, &keyvals, &n_entries);
mask = 0;
j = 0;
while (j < n_entries)
{
if (keyvals[j] == GDK_Num_Lock)
mask |= EGG_VIRTUAL_NUM_LOCK_MASK;
else if (keyvals[j] == GDK_Scroll_Lock)
mask |= EGG_VIRTUAL_SCROLL_LOCK_MASK;
else if (keyvals[j] == GDK_Meta_L ||
keyvals[j] == GDK_Meta_R)
mask |= EGG_VIRTUAL_META_MASK;
else if (keyvals[j] == GDK_Hyper_L ||
keyvals[j] == GDK_Hyper_R)
mask |= EGG_VIRTUAL_HYPER_MASK;
else if (keyvals[j] == GDK_Super_L ||
keyvals[j] == GDK_Super_R)
mask |= EGG_VIRTUAL_SUPER_MASK;
else if (keyvals[j] == GDK_Mode_switch)
mask |= EGG_VIRTUAL_MODE_SWITCH_MASK;
++j;
}
/* Mod1Mask is 1 << 3 for example, i.e. the
* fourth modifier, i / keyspermod is the modifier
* index
*/
modmap->mapping[i/xmodmap->max_keypermod] |= mask;
g_free (keyvals);
g_free (keys);
++i;
}
/* Add in the not-really-virtual fixed entries */
modmap->mapping[EGG_MODMAP_ENTRY_SHIFT] |= EGG_VIRTUAL_SHIFT_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_CONTROL] |= EGG_VIRTUAL_CONTROL_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_LOCK] |= EGG_VIRTUAL_LOCK_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_MOD1] |= EGG_VIRTUAL_ALT_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_MOD2] |= EGG_VIRTUAL_MOD2_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_MOD3] |= EGG_VIRTUAL_MOD3_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_MOD4] |= EGG_VIRTUAL_MOD4_MASK;
modmap->mapping[EGG_MODMAP_ENTRY_MOD5] |= EGG_VIRTUAL_MOD5_MASK;
XFreeModifiermap (xmodmap);
}
const EggModmap*
egg_keymap_get_modmap (GdkKeymap *keymap)
{
EggModmap *modmap;
/* This is all a hack, much simpler when we can just
* modify GDK directly.
*/
modmap = g_object_get_data (G_OBJECT (keymap),
"egg-modmap");
if (modmap == NULL)
{
modmap = g_new0 (EggModmap, 1);
/* FIXME modify keymap change events with an event filter
* and force a reload if we get one
*/
reload_modmap (keymap, modmap);
g_object_set_data_full (G_OBJECT (keymap),
"egg-modmap",
modmap,
g_free);
}
g_assert (modmap != NULL);
return modmap;
}

View file

@ -0,0 +1,87 @@
/* eggaccelerators.h
* Copyright (C) 2002 Red Hat, Inc.
* Developed by Havoc Pennington
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __EGG_ACCELERATORS_H__
#define __EGG_ACCELERATORS_H__
#include <gtk/gtkaccelgroup.h>
#include <gdk/gdk.h>
G_BEGIN_DECLS
/* Where a value is also in GdkModifierType we coincide,
* otherwise we don't overlap.
*/
typedef enum
{
EGG_VIRTUAL_SHIFT_MASK = 1 << 0,
EGG_VIRTUAL_LOCK_MASK = 1 << 1,
EGG_VIRTUAL_CONTROL_MASK = 1 << 2,
EGG_VIRTUAL_ALT_MASK = 1 << 3, /* fixed as Mod1 */
EGG_VIRTUAL_MOD2_MASK = 1 << 4,
EGG_VIRTUAL_MOD3_MASK = 1 << 5,
EGG_VIRTUAL_MOD4_MASK = 1 << 6,
EGG_VIRTUAL_MOD5_MASK = 1 << 7,
#if 0
GDK_BUTTON1_MASK = 1 << 8,
GDK_BUTTON2_MASK = 1 << 9,
GDK_BUTTON3_MASK = 1 << 10,
GDK_BUTTON4_MASK = 1 << 11,
GDK_BUTTON5_MASK = 1 << 12,
/* 13, 14 are used by Xkb for the keyboard group */
#endif
EGG_VIRTUAL_META_MASK = 1 << 24,
EGG_VIRTUAL_SUPER_MASK = 1 << 25,
EGG_VIRTUAL_HYPER_MASK = 1 << 26,
EGG_VIRTUAL_MODE_SWITCH_MASK = 1 << 27,
EGG_VIRTUAL_NUM_LOCK_MASK = 1 << 28,
EGG_VIRTUAL_SCROLL_LOCK_MASK = 1 << 29,
/* Also in GdkModifierType */
EGG_VIRTUAL_RELEASE_MASK = 1 << 30,
/* 28-31 24-27 20-23 16-19 12-15 8-11 4-7 0-3
* 7 f 0 0 0 0 f f
*/
EGG_VIRTUAL_MODIFIER_MASK = 0x7f0000ff
} EggVirtualModifierType;
gboolean egg_accelerator_parse_virtual (const gchar *accelerator,
guint *accelerator_key,
EggVirtualModifierType *accelerator_mods);
void egg_keymap_resolve_virtual_modifiers (GdkKeymap *keymap,
EggVirtualModifierType virtual_mods,
GdkModifierType *concrete_mods);
void egg_keymap_virtualize_modifiers (GdkKeymap *keymap,
GdkModifierType concrete_mods,
EggVirtualModifierType *virtual_mods);
gchar* egg_virtual_accelerator_name (guint accelerator_key,
EggVirtualModifierType accelerator_mods);
G_END_DECLS
#endif /* __EGG_ACCELERATORS_H__ */

View file

@ -0,0 +1,328 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <gdk/gdk.h>
#include <gdk/gdkwindow.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include "eggaccelerators.h"
#include "tomboykeybinder.h"
/* Uncomment the next line to print a debug trace. */
//#define DEBUG 1
#ifdef DEBUG
# define TRACE(x) x
#else
# define TRACE(x) do {} while (FALSE);
#endif
typedef struct _Binding {
TomboyBindkeyHandler handler;
gpointer user_data;
char *keystring;
uint keycode;
uint modifiers;
} Binding;
static GSList *bindings = NULL;
static guint32 last_event_time = 0;
static gboolean processing_event = FALSE;
static guint num_lock_mask, caps_lock_mask, scroll_lock_mask;
static void
lookup_ignorable_modifiers (GdkKeymap *keymap)
{
egg_keymap_resolve_virtual_modifiers (keymap,
EGG_VIRTUAL_LOCK_MASK,
&caps_lock_mask);
egg_keymap_resolve_virtual_modifiers (keymap,
EGG_VIRTUAL_NUM_LOCK_MASK,
&num_lock_mask);
egg_keymap_resolve_virtual_modifiers (keymap,
EGG_VIRTUAL_SCROLL_LOCK_MASK,
&scroll_lock_mask);
}
static void
grab_ungrab_with_ignorable_modifiers (GdkWindow *rootwin,
Binding *binding,
gboolean grab)
{
guint mod_masks [] = {
0, /* modifier only */
num_lock_mask,
caps_lock_mask,
scroll_lock_mask,
num_lock_mask | caps_lock_mask,
num_lock_mask | scroll_lock_mask,
caps_lock_mask | scroll_lock_mask,
num_lock_mask | caps_lock_mask | scroll_lock_mask,
};
int i;
for (i = 0; i < G_N_ELEMENTS (mod_masks); i++) {
if (grab) {
XGrabKey (GDK_WINDOW_XDISPLAY (rootwin),
binding->keycode,
binding->modifiers | mod_masks [i],
GDK_WINDOW_XWINDOW (rootwin),
False,
GrabModeAsync,
GrabModeAsync);
} else {
XUngrabKey (GDK_WINDOW_XDISPLAY (rootwin),
binding->keycode,
binding->modifiers | mod_masks [i],
GDK_WINDOW_XWINDOW (rootwin));
}
}
}
static gboolean
do_grab_key (Binding *binding)
{
GdkKeymap *keymap = gdk_keymap_get_default ();
GdkWindow *rootwin = gdk_get_default_root_window ();
EggVirtualModifierType virtual_mods = 0;
guint keysym = 0;
TRACE (g_print ("Preparing to bind %s\n", binding->keystring));
g_return_val_if_fail (keymap != NULL, FALSE);
g_return_val_if_fail (rootwin != NULL, FALSE);
if (!egg_accelerator_parse_virtual (binding->keystring,
&keysym,
&virtual_mods)) {
TRACE (g_print("Failed to parse '%s'", binding->keystring));
return FALSE;
}
TRACE (g_print ("Got accel %d, %d\n", keysym, virtual_mods));
binding->keycode = XKeysymToKeycode (GDK_WINDOW_XDISPLAY (rootwin),
keysym);
if (binding->keycode == 0)
return FALSE;
TRACE (g_print ("Got keycode %d\n", binding->keycode));
egg_keymap_resolve_virtual_modifiers (keymap,
virtual_mods,
&binding->modifiers);
TRACE (g_print ("Got modmask %d\n", binding->modifiers));
gdk_error_trap_push ();
grab_ungrab_with_ignorable_modifiers (rootwin,
binding,
TRUE /* grab */);
gdk_flush ();
if (gdk_error_trap_pop ()) {
g_warning ("Binding '%s' failed!\n", binding->keystring);
return FALSE;
}
return TRUE;
}
static gboolean
do_ungrab_key (Binding *binding)
{
GdkWindow *rootwin = gdk_get_default_root_window ();
TRACE (g_print ("Removing grab for '%s'\n", binding->keystring));
grab_ungrab_with_ignorable_modifiers (rootwin,
binding,
FALSE /* ungrab */);
return TRUE;
}
static GdkFilterReturn
filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
{
GdkFilterReturn return_val = GDK_FILTER_CONTINUE;
XEvent *xevent = (XEvent *) gdk_xevent;
guint event_mods;
GSList *iter;
TRACE (g_print ("Got Event! %d, %d\n", xevent->type, event->type));
switch (xevent->type) {
case KeyPress:
TRACE (g_print ("Got KeyPress! keycode: %d, modifiers: %d\n",
xevent->xkey.keycode,
xevent->xkey.state));
/*
* Set the last event time for use when showing
* windows to avoid anti-focus-stealing code.
*/
processing_event = TRUE;
last_event_time = xevent->xkey.time;
event_mods = xevent->xkey.state & ~(num_lock_mask |
caps_lock_mask |
scroll_lock_mask);
for (iter = bindings; iter != NULL; iter = iter->next) {
Binding *binding = (Binding *) iter->data;
if (binding->keycode == xevent->xkey.keycode &&
binding->modifiers == event_mods) {
TRACE (g_print ("Calling handler for '%s'...\n",
binding->keystring));
(binding->handler) (binding->keystring,
binding->user_data);
}
}
processing_event = FALSE;
break;
case KeyRelease:
TRACE (g_print ("Got KeyRelease! \n"));
break;
}
return return_val;
}
static void
keymap_changed (GdkKeymap *map)
{
GdkKeymap *keymap = gdk_keymap_get_default ();
GSList *iter;
TRACE (g_print ("Keymap changed! Regrabbing keys..."));
for (iter = bindings; iter != NULL; iter = iter->next) {
Binding *binding = (Binding *) iter->data;
do_ungrab_key (binding);
}
lookup_ignorable_modifiers (keymap);
for (iter = bindings; iter != NULL; iter = iter->next) {
Binding *binding = (Binding *) iter->data;
do_grab_key (binding);
}
}
void
tomboy_keybinder_init (void)
{
GdkKeymap *keymap = gdk_keymap_get_default ();
GdkWindow *rootwin = gdk_get_default_root_window ();
lookup_ignorable_modifiers (keymap);
gdk_window_add_filter (rootwin,
filter_func,
NULL);
g_signal_connect (keymap,
"keys_changed",
G_CALLBACK (keymap_changed),
NULL);
}
gboolean
tomboy_keybinder_bind (const char *keystring,
TomboyBindkeyHandler handler,
gpointer user_data)
{
Binding *binding;
gboolean success;
binding = g_new0 (Binding, 1);
binding->keystring = g_strdup (keystring);
binding->handler = handler;
binding->user_data = user_data;
/* Sets the binding's keycode and modifiers */
success = do_grab_key (binding);
if (success) {
bindings = g_slist_prepend (bindings, binding);
} else {
g_free (binding->keystring);
g_free (binding);
}
return success;
}
void
tomboy_keybinder_unbind (const char *keystring,
TomboyBindkeyHandler handler)
{
GSList *iter;
for (iter = bindings; iter != NULL; iter = iter->next) {
Binding *binding = (Binding *) iter->data;
if (strcmp (keystring, binding->keystring) != 0 ||
handler != binding->handler)
continue;
do_ungrab_key (binding);
bindings = g_slist_remove (bindings, binding);
g_free (binding->keystring);
g_free (binding);
break;
}
}
/*
* From eggcellrenderkeys.c.
*/
gboolean
tomboy_keybinder_is_modifier (guint keycode)
{
gint i;
gint map_size;
XModifierKeymap *mod_keymap;
gboolean retval = FALSE;
mod_keymap = XGetModifierMapping (gdk_display);
map_size = 8 * mod_keymap->max_keypermod;
i = 0;
while (i < map_size) {
if (keycode == mod_keymap->modifiermap[i]) {
retval = TRUE;
break;
}
++i;
}
XFreeModifiermap (mod_keymap);
return retval;
}
guint32
tomboy_keybinder_get_current_event_time (void)
{
if (processing_event)
return last_event_time;
else
return GDK_CURRENT_TIME;
}

View file

@ -0,0 +1,27 @@
#ifndef __TOMBOY_KEY_BINDER_H__
#define __TOMBOY_KEY_BINDER_H__
#include <glib.h>
G_BEGIN_DECLS
typedef void (* TomboyBindkeyHandler) (char *keystring, gpointer user_data);
void tomboy_keybinder_init (void);
gboolean tomboy_keybinder_bind (const char *keystring,
TomboyBindkeyHandler handler,
gpointer user_data);
void tomboy_keybinder_unbind (const char *keystring,
TomboyBindkeyHandler handler);
gboolean tomboy_keybinder_is_modifier (guint keycode);
guint32 tomboy_keybinder_get_current_event_time (void);
G_END_DECLS
#endif /* __TOMBOY_KEY_BINDER_H__ */

View file

@ -158,7 +158,7 @@ static gboolean my_folder_item_update_hook(gpointer source, gpointer data)
#if defined(NOTIFICATION_LCDPROC) || defined(NOTIFICATION_TRAYICON) || defined(NOTIFICATION_INDICATOR)
notification_update_msg_counts(NULL);
#else
if(notify_config.urgency_hint)
if(notify_config.urgency_hint_new || notify_config.urgency_hint_unread)
notification_update_msg_counts(NULL);
#endif

View file

@ -5,8 +5,7 @@ plugin_LTLIBRARIES = spamreport.la
spamreport_la_SOURCES = \
spam_report.c \
spam_report_prefs.c \
spam_report_prefs.h \
gettext.h
spam_report_prefs.h
spamreport_la_LDFLAGS = \
-avoid-version -module \

View file

@ -342,9 +342,8 @@ gint plugin_init(gchar **error)
return -1;
spamreport_prefs_init();
#ifdef HAVE_LIBCURL
curl_global_init(CURL_GLOBAL_DEFAULT);
#endif
gtk_action_group_add_actions(mainwin->action_group, spamreport_main_menu,
1, (gpointer)mainwin);
@ -371,9 +370,9 @@ gboolean plugin_done(void)
MENUITEM_REMUI_MANAGER(mainwin->ui_manager,mainwin->action_group, "Message/ReportSpam", context_menu_id);
context_menu_id = 0;
#ifdef HAVE_LIBCURL
spamreport_prefs_done();
#endif
return TRUE;
}

View file

@ -49,8 +49,7 @@ tnef_parse_la_SOURCES = \
tnef_parse.c \
tnef_dump.c \
tnef_dump.h \
ytnef.c \
gettext.h
ytnef.c
tnef_parse_la_LDFLAGS = \
$(plugin_res_ldflag) $(no_undefined) $(export_symbols) \