From ddaceb232c8b537a7d29a9708928d3a3671b98e5 Mon Sep 17 00:00:00 2001 From: haxar Date: Tue, 21 Feb 2012 20:13:04 -0800 Subject: gsd to msd complete rename patch by NiceandGently; code changes commit --- plugins/a11y-keyboard/Makefile.am | 22 +- plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c | 156 ++++---- plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h | 34 +- plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c | 42 +-- plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h | 28 +- .../a11y-keyboard/gsd-a11y-preferences-dialog.c | 112 +++--- .../a11y-keyboard/gsd-a11y-preferences-dialog.h | 30 +- .../a11y-keyboard/test-a11y-preferences-dialog.c | 4 +- plugins/background/Makefile.am | 18 +- plugins/background/gsd-background-manager.c | 110 +++--- plugins/background/gsd-background-manager.h | 34 +- plugins/background/gsd-background-plugin.c | 42 +-- plugins/background/gsd-background-plugin.h | 28 +- plugins/background/test-background.c | 10 +- plugins/clipboard/Makefile.am | 12 +- plugins/clipboard/gsd-clipboard-manager.c | 114 +++--- plugins/clipboard/gsd-clipboard-manager.h | 34 +- plugins/clipboard/gsd-clipboard-plugin.c | 42 +-- plugins/clipboard/gsd-clipboard-plugin.h | 28 +- plugins/common/Makefile.am | 10 +- plugins/common/gsd-keygrab.c | 24 +- plugins/common/gsd-keygrab.h | 6 +- plugins/common/gsd-osd-window.c | 128 +++---- plugins/common/gsd-osd-window.h | 50 +-- plugins/datetime/Makefile.am | 26 +- plugins/datetime/gsd-datetime-mechanism-main.c | 6 +- plugins/datetime/gsd-datetime-mechanism.c | 148 ++++---- plugins/datetime/gsd-datetime-mechanism.h | 64 ++-- ...ate.SettingsDaemon.DateTimeMechanism.service.in | 2 +- plugins/dummy/Makefile.am | 12 +- plugins/dummy/gsd-dummy-manager.c | 84 ++--- plugins/dummy/gsd-dummy-manager.h | 34 +- plugins/dummy/gsd-dummy-plugin.c | 42 +-- plugins/dummy/gsd-dummy-plugin.h | 28 +- plugins/font/Makefile.am | 12 +- plugins/font/gsd-font-manager.c | 52 +-- plugins/font/gsd-font-manager.h | 34 +- plugins/font/gsd-font-plugin.c | 42 +-- plugins/font/gsd-font-plugin.h | 28 +- plugins/housekeeping/Makefile.am | 24 +- plugins/housekeeping/gsd-disk-space.c | 36 +- plugins/housekeeping/gsd-disk-space.h | 10 +- plugins/housekeeping/gsd-housekeeping-manager.c | 50 +-- plugins/housekeeping/gsd-housekeeping-manager.h | 34 +- plugins/housekeeping/gsd-housekeeping-plugin.c | 42 +-- plugins/housekeeping/gsd-housekeeping-plugin.h | 28 +- plugins/housekeeping/gsd-ldsm-dialog.c | 90 ++--- plugins/housekeeping/gsd-ldsm-dialog.h | 44 +-- plugins/housekeeping/gsd-ldsm-trash-empty.c | 10 +- plugins/housekeeping/gsd-ldsm-trash-empty.h | 14 +- plugins/keybindings/Makefile.am | 12 +- plugins/keybindings/gsd-keybindings-manager.c | 102 +++--- plugins/keybindings/gsd-keybindings-manager.h | 34 +- plugins/keybindings/gsd-keybindings-plugin.c | 42 +-- plugins/keybindings/gsd-keybindings-plugin.h | 28 +- plugins/keyboard/Makefile.am | 20 +- plugins/keyboard/delayed-dialog.c | 4 +- plugins/keyboard/delayed-dialog.h | 2 +- plugins/keyboard/gsd-keyboard-manager.c | 144 ++++---- plugins/keyboard/gsd-keyboard-manager.h | 36 +- plugins/keyboard/gsd-keyboard-plugin.c | 42 +-- plugins/keyboard/gsd-keyboard-plugin.h | 28 +- plugins/keyboard/gsd-keyboard-xkb.c | 70 ++-- plugins/keyboard/gsd-keyboard-xkb.h | 12 +- plugins/keyboard/gsd-xmodmap.c | 8 +- plugins/keyboard/gsd-xmodmap.h | 4 +- plugins/media-keys/Makefile.am | 52 +-- plugins/media-keys/acme.h | 2 +- plugins/media-keys/gsd-media-keys-manager.c | 194 +++++----- plugins/media-keys/gsd-media-keys-manager.h | 40 +-- plugins/media-keys/gsd-media-keys-manager.xml | 2 +- plugins/media-keys/gsd-media-keys-plugin.c | 42 +-- plugins/media-keys/gsd-media-keys-plugin.h | 28 +- plugins/media-keys/gsd-media-keys-window.c | 132 +++---- plugins/media-keys/gsd-media-keys-window.h | 54 +-- plugins/media-keys/test-media-keys.c | 8 +- plugins/media-keys/test-media-window.c | 42 +-- plugins/mouse/Makefile.am | 28 +- plugins/mouse/gsd-locate-pointer.c | 56 +-- plugins/mouse/gsd-locate-pointer.h | 2 +- plugins/mouse/gsd-mouse-manager.c | 116 +++--- plugins/mouse/gsd-mouse-manager.h | 34 +- plugins/mouse/gsd-mouse-plugin.c | 42 +-- plugins/mouse/gsd-mouse-plugin.h | 28 +- plugins/mouse/gsd-timeline.c | 376 +++++++++---------- plugins/mouse/gsd-timeline.h | 118 +++--- plugins/smartcard/Makefile.am | 18 +- plugins/smartcard/gsd-smartcard-manager.c | 400 ++++++++++----------- plugins/smartcard/gsd-smartcard-manager.h | 76 ++-- plugins/smartcard/gsd-smartcard-plugin.c | 146 ++++---- plugins/smartcard/gsd-smartcard-plugin.h | 28 +- plugins/smartcard/gsd-smartcard.c | 192 +++++----- plugins/smartcard/gsd-smartcard.h | 82 ++--- plugins/sound/Makefile.am | 12 +- plugins/sound/gsd-sound-manager.c | 82 ++--- plugins/sound/gsd-sound-manager.h | 34 +- plugins/sound/gsd-sound-plugin.c | 42 +-- plugins/sound/gsd-sound-plugin.h | 28 +- plugins/typing-break/Makefile.am | 12 +- plugins/typing-break/gsd-typing-break-manager.c | 96 ++--- plugins/typing-break/gsd-typing-break-manager.h | 34 +- plugins/typing-break/gsd-typing-break-plugin.c | 42 +-- plugins/typing-break/gsd-typing-break-plugin.h | 28 +- plugins/xrandr/Makefile.am | 50 +-- plugins/xrandr/gsd-xrandr-manager.c | 256 ++++++------- plugins/xrandr/gsd-xrandr-manager.h | 34 +- plugins/xrandr/gsd-xrandr-manager.xml | 4 +- plugins/xrandr/gsd-xrandr-plugin.c | 42 +-- plugins/xrandr/gsd-xrandr-plugin.h | 28 +- plugins/xrdb/Makefile.am | 12 +- plugins/xrdb/gsd-xrdb-manager.c | 92 ++--- plugins/xrdb/gsd-xrdb-manager.h | 34 +- plugins/xrdb/gsd-xrdb-plugin.c | 42 +-- plugins/xrdb/gsd-xrdb-plugin.h | 28 +- plugins/xsettings/Makefile.am | 12 +- plugins/xsettings/gsd-xsettings-manager.c | 14 +- plugins/xsettings/gsd-xsettings-plugin.c | 4 +- 117 files changed, 3051 insertions(+), 3051 deletions(-) (limited to 'plugins') diff --git a/plugins/a11y-keyboard/Makefile.am b/plugins/a11y-keyboard/Makefile.am index 8396513..78737a0 100644 --- a/plugins/a11y-keyboard/Makefile.am +++ b/plugins/a11y-keyboard/Makefile.am @@ -2,7 +2,7 @@ NULL = gtkbuilderdir = $(pkgdatadir) gtkbuilder_DATA = \ - gsd-a11y-preferences-dialog.ui \ + msd-a11y-preferences-dialog.ui \ $(NULL) noinst_PROGRAMS = \ @@ -10,8 +10,8 @@ noinst_PROGRAMS = \ $(NULL) test_a11y_preferences_dialog_SOURCES = \ - gsd-a11y-preferences-dialog.c \ - gsd-a11y-preferences-dialog.h \ + msd-a11y-preferences-dialog.c \ + msd-a11y-preferences-dialog.h \ test-a11y-preferences-dialog.c \ $(NULL) @@ -36,12 +36,12 @@ plugin_LTLIBRARIES = \ $(NULL) liba11y_keyboard_la_SOURCES = \ - gsd-a11y-keyboard-plugin.h \ - gsd-a11y-keyboard-plugin.c \ - gsd-a11y-keyboard-manager.h \ - gsd-a11y-keyboard-manager.c \ - gsd-a11y-preferences-dialog.h \ - gsd-a11y-preferences-dialog.c \ + msd-a11y-keyboard-plugin.h \ + msd-a11y-keyboard-plugin.c \ + msd-a11y-keyboard-manager.h \ + msd-a11y-keyboard-manager.c \ + msd-a11y-preferences-dialog.h \ + msd-a11y-preferences-dialog.c \ $(NULL) liba11y_keyboard_la_CPPFLAGS = \ @@ -56,7 +56,7 @@ liba11y_keyboard_la_CFLAGS = \ $(AM_CFLAGS) liba11y_keyboard_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) liba11y_keyboard_la_LIBADD = \ @@ -84,4 +84,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c index 668fddc..7505b14 100644 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c +++ b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c @@ -51,15 +51,15 @@ #endif /* HAVE_LIBMATENOTIFY */ #include "mate-settings-profile.h" -#include "gsd-a11y-keyboard-manager.h" -#include "gsd-a11y-preferences-dialog.h" +#include "msd-a11y-keyboard-manager.h" +#include "msd-a11y-preferences-dialog.h" #define CONFIG_ROOT "/desktop/mate/accessibility/keyboard" #define NOTIFICATION_TIMEOUT 30 -#define GSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManagerPrivate)) +#define MSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerPrivate)) -struct GsdA11yKeyboardManagerPrivate +struct MsdA11yKeyboardManagerPrivate { int xkbEventBase; gboolean stickykeys_shortcut_val; @@ -77,14 +77,14 @@ struct GsdA11yKeyboardManagerPrivate #endif /* HAVE_LIBMATENOTIFY */ }; -static void gsd_a11y_keyboard_manager_class_init (GsdA11yKeyboardManagerClass *klass); -static void gsd_a11y_keyboard_manager_init (GsdA11yKeyboardManager *a11y_keyboard_manager); -static void gsd_a11y_keyboard_manager_finalize (GObject *object); -static void gsd_a11y_keyboard_manager_ensure_status_icon (GsdA11yKeyboardManager *manager); -static void set_server_from_mateconf (GsdA11yKeyboardManager *manager, +static void msd_a11y_keyboard_manager_class_init (MsdA11yKeyboardManagerClass *klass); +static void msd_a11y_keyboard_manager_init (MsdA11yKeyboardManager *a11y_keyboard_manager); +static void msd_a11y_keyboard_manager_finalize (GObject *object); +static void msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager); +static void set_server_from_mateconf (MsdA11yKeyboardManager *manager, MateConfClient *client); -G_DEFINE_TYPE (GsdA11yKeyboardManager, gsd_a11y_keyboard_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdA11yKeyboardManager, msd_a11y_keyboard_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -133,7 +133,7 @@ supports_xinput_devices (void) } static void -set_devicepresence_handler (GsdA11yKeyboardManager *manager) +set_devicepresence_handler (MsdA11yKeyboardManager *manager) { Display *display; XEventClass class_presence; @@ -161,7 +161,7 @@ set_devicepresence_handler (GsdA11yKeyboardManager *manager) #endif static gboolean -xkb_enabled (GsdA11yKeyboardManager *manager) +xkb_enabled (MsdA11yKeyboardManager *manager) { gboolean have_xkb; int opcode, errorBase, major, minor; @@ -178,7 +178,7 @@ xkb_enabled (GsdA11yKeyboardManager *manager) } static XkbDescRec * -get_xkb_desc_rec (GsdA11yKeyboardManager *manager) +get_xkb_desc_rec (MsdA11yKeyboardManager *manager) { XkbDescRec *desc; Status status = Success; @@ -265,7 +265,7 @@ set_ctrl_from_mateconf (XkbDescRec *desc, } static void -set_server_from_mateconf (GsdA11yKeyboardManager *manager, +set_server_from_mateconf (MsdA11yKeyboardManager *manager, MateConfClient *client) { XkbDescRec *desc; @@ -404,7 +404,7 @@ set_server_from_mateconf (GsdA11yKeyboardManager *manager, } static gboolean -ax_response_callback (GsdA11yKeyboardManager *manager, +ax_response_callback (MsdA11yKeyboardManager *manager, GtkWindow *parent, gint response_id, guint revert_controls_mask, @@ -475,7 +475,7 @@ ax_response_callback (GsdA11yKeyboardManager *manager, static void ax_stickykeys_response (GtkDialog *dialog, gint response_id, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { if (ax_response_callback (manager, GTK_WINDOW (dialog), response_id, XkbStickyKeysMask, @@ -487,7 +487,7 @@ ax_stickykeys_response (GtkDialog *dialog, static void ax_slowkeys_response (GtkDialog *dialog, gint response_id, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { if (ax_response_callback (manager, GTK_WINDOW (dialog), response_id, XkbSlowKeysMask, @@ -497,7 +497,7 @@ ax_slowkeys_response (GtkDialog *dialog, } static void -maybe_show_status_icon (GsdA11yKeyboardManager *manager) +maybe_show_status_icon (MsdA11yKeyboardManager *manager) { gboolean show; MateConfClient *client; @@ -510,14 +510,14 @@ maybe_show_status_icon (GsdA11yKeyboardManager *manager) if (!show && manager->priv->status_icon == NULL) return; - gsd_a11y_keyboard_manager_ensure_status_icon (manager); + msd_a11y_keyboard_manager_ensure_status_icon (manager); gtk_status_icon_set_visible (manager->priv->status_icon, show); } #ifdef HAVE_LIBMATENOTIFY static void on_notification_closed (NotifyNotification *notification, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { g_object_unref (manager->priv->notification); manager->priv->notification = NULL; @@ -526,7 +526,7 @@ on_notification_closed (NotifyNotification *notification, static void on_slow_keys_action (NotifyNotification *notification, const char *action, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { gboolean res; int response_id; @@ -552,7 +552,7 @@ on_slow_keys_action (NotifyNotification *notification, static void on_sticky_keys_action (NotifyNotification *notification, const char *action, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { gboolean res; int response_id; @@ -578,7 +578,7 @@ on_sticky_keys_action (NotifyNotification *notification, #endif /* HAVE_LIBMATENOTIFY */ static gboolean -ax_slowkeys_warning_post_bubble (GsdA11yKeyboardManager *manager, +ax_slowkeys_warning_post_bubble (MsdA11yKeyboardManager *manager, gboolean enabled) { #ifdef HAVE_LIBMATENOTIFY @@ -605,7 +605,7 @@ ax_slowkeys_warning_post_bubble (GsdA11yKeyboardManager *manager, notify_notification_close (manager->priv->notification, NULL); } - gsd_a11y_keyboard_manager_ensure_status_icon (manager); + msd_a11y_keyboard_manager_ensure_status_icon (manager); manager->priv->notification = notify_notification_new (title, message, "preferences-desktop-accessibility", @@ -634,7 +634,7 @@ ax_slowkeys_warning_post_bubble (GsdA11yKeyboardManager *manager, error = NULL; res = notify_notification_show (manager->priv->notification, &error); if (! res) { - g_warning ("GsdA11yKeyboardManager: unable to show notification: %s", error->message); + g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message); g_error_free (error); notify_notification_close (manager->priv->notification, NULL); } @@ -647,7 +647,7 @@ ax_slowkeys_warning_post_bubble (GsdA11yKeyboardManager *manager, static void -ax_slowkeys_warning_post_dialog (GsdA11yKeyboardManager *manager, +ax_slowkeys_warning_post_dialog (MsdA11yKeyboardManager *manager, gboolean enabled) { const char *title; @@ -701,7 +701,7 @@ ax_slowkeys_warning_post_dialog (GsdA11yKeyboardManager *manager, } static void -ax_slowkeys_warning_post (GsdA11yKeyboardManager *manager, +ax_slowkeys_warning_post (MsdA11yKeyboardManager *manager, gboolean enabled) { @@ -714,7 +714,7 @@ ax_slowkeys_warning_post (GsdA11yKeyboardManager *manager, } static gboolean -ax_stickykeys_warning_post_bubble (GsdA11yKeyboardManager *manager, +ax_stickykeys_warning_post_bubble (MsdA11yKeyboardManager *manager, gboolean enabled) { #ifdef HAVE_LIBMATENOTIFY @@ -744,7 +744,7 @@ ax_stickykeys_warning_post_bubble (GsdA11yKeyboardManager *manager, notify_notification_close (manager->priv->notification, NULL); } - gsd_a11y_keyboard_manager_ensure_status_icon (manager); + msd_a11y_keyboard_manager_ensure_status_icon (manager); manager->priv->notification = notify_notification_new (title, message, "preferences-desktop-accessibility", @@ -773,7 +773,7 @@ ax_stickykeys_warning_post_bubble (GsdA11yKeyboardManager *manager, error = NULL; res = notify_notification_show (manager->priv->notification, &error); if (! res) { - g_warning ("GsdA11yKeyboardManager: unable to show notification: %s", error->message); + g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message); g_error_free (error); notify_notification_close (manager->priv->notification, NULL); } @@ -785,7 +785,7 @@ ax_stickykeys_warning_post_bubble (GsdA11yKeyboardManager *manager, } static void -ax_stickykeys_warning_post_dialog (GsdA11yKeyboardManager *manager, +ax_stickykeys_warning_post_dialog (MsdA11yKeyboardManager *manager, gboolean enabled) { const char *title; @@ -842,7 +842,7 @@ ax_stickykeys_warning_post_dialog (GsdA11yKeyboardManager *manager, } static void -ax_stickykeys_warning_post (GsdA11yKeyboardManager *manager, +ax_stickykeys_warning_post (MsdA11yKeyboardManager *manager, gboolean enabled) { @@ -855,7 +855,7 @@ ax_stickykeys_warning_post (GsdA11yKeyboardManager *manager, } static void -set_mateconf_from_server (GsdA11yKeyboardManager *manager) +set_mateconf_from_server (MsdA11yKeyboardManager *manager) { MateConfClient *client; MateConfChangeSet *cs; @@ -1003,7 +1003,7 @@ set_mateconf_from_server (GsdA11yKeyboardManager *manager) static GdkFilterReturn cb_xkb_event_filter (GdkXEvent *xevent, GdkEvent *ignored1, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { XEvent *xev = (XEvent *) xevent; XkbEvent *xkbEv = (XkbEvent *) xevent; @@ -1031,14 +1031,14 @@ static void keyboard_callback (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { set_server_from_mateconf (manager, client); maybe_show_status_icon (manager); } static void -register_config_callback (GsdA11yKeyboardManager *manager, +register_config_callback (MsdA11yKeyboardManager *manager, MateConfClient *client, const char *path, MateConfClientNotifyFunc func, @@ -1049,7 +1049,7 @@ register_config_callback (GsdA11yKeyboardManager *manager, } static gboolean -start_a11y_keyboard_idle_cb (GsdA11yKeyboardManager *manager) +start_a11y_keyboard_idle_cb (MsdA11yKeyboardManager *manager) { guint event_mask; MateConfClient *client; @@ -1104,7 +1104,7 @@ start_a11y_keyboard_idle_cb (GsdA11yKeyboardManager *manager) gboolean -gsd_a11y_keyboard_manager_start (GsdA11yKeyboardManager *manager, +msd_a11y_keyboard_manager_start (MsdA11yKeyboardManager *manager, GError **error) { mate_settings_profile_start (NULL); @@ -1117,7 +1117,7 @@ gsd_a11y_keyboard_manager_start (GsdA11yKeyboardManager *manager, } static void -restore_server_xkb_config (GsdA11yKeyboardManager *manager) +restore_server_xkb_config (MsdA11yKeyboardManager *manager) { gdk_error_trap_push (); XkbSetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), @@ -1142,9 +1142,9 @@ restore_server_xkb_config (GsdA11yKeyboardManager *manager) } void -gsd_a11y_keyboard_manager_stop (GsdA11yKeyboardManager *manager) +msd_a11y_keyboard_manager_stop (MsdA11yKeyboardManager *manager) { - GsdA11yKeyboardManagerPrivate *p = manager->priv; + MsdA11yKeyboardManagerPrivate *p = manager->priv; g_debug ("Stopping a11y_keyboard manager"); @@ -1182,14 +1182,14 @@ gsd_a11y_keyboard_manager_stop (GsdA11yKeyboardManager *manager) } static void -gsd_a11y_keyboard_manager_set_property (GObject *object, +msd_a11y_keyboard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdA11yKeyboardManager *self; + MsdA11yKeyboardManager *self; - self = GSD_A11Y_KEYBOARD_MANAGER (object); + self = MSD_A11Y_KEYBOARD_MANAGER (object); switch (prop_id) { default: @@ -1199,14 +1199,14 @@ gsd_a11y_keyboard_manager_set_property (GObject *object, } static void -gsd_a11y_keyboard_manager_get_property (GObject *object, +msd_a11y_keyboard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdA11yKeyboardManager *self; + MsdA11yKeyboardManager *self; - self = GSD_A11Y_KEYBOARD_MANAGER (object); + self = MSD_A11Y_KEYBOARD_MANAGER (object); switch (prop_id) { default: @@ -1216,16 +1216,16 @@ gsd_a11y_keyboard_manager_get_property (GObject *object, } static GObject * -gsd_a11y_keyboard_manager_constructor (GType type, +msd_a11y_keyboard_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdA11yKeyboardManager *a11y_keyboard_manager; - GsdA11yKeyboardManagerClass *klass; + MsdA11yKeyboardManager *a11y_keyboard_manager; + MsdA11yKeyboardManagerClass *klass; - klass = GSD_A11Y_KEYBOARD_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_A11Y_KEYBOARD_MANAGER)); + klass = MSD_A11Y_KEYBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_A11Y_KEYBOARD_MANAGER)); - a11y_keyboard_manager = GSD_A11Y_KEYBOARD_MANAGER (G_OBJECT_CLASS (gsd_a11y_keyboard_manager_parent_class)->constructor (type, + a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -1233,33 +1233,33 @@ gsd_a11y_keyboard_manager_constructor (GType type, } static void -gsd_a11y_keyboard_manager_dispose (GObject *object) +msd_a11y_keyboard_manager_dispose (GObject *object) { - GsdA11yKeyboardManager *a11y_keyboard_manager; + MsdA11yKeyboardManager *a11y_keyboard_manager; - a11y_keyboard_manager = GSD_A11Y_KEYBOARD_MANAGER (object); + a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (object); - G_OBJECT_CLASS (gsd_a11y_keyboard_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->dispose (object); } static void -gsd_a11y_keyboard_manager_class_init (GsdA11yKeyboardManagerClass *klass) +msd_a11y_keyboard_manager_class_init (MsdA11yKeyboardManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_a11y_keyboard_manager_get_property; - object_class->set_property = gsd_a11y_keyboard_manager_set_property; - object_class->constructor = gsd_a11y_keyboard_manager_constructor; - object_class->dispose = gsd_a11y_keyboard_manager_dispose; - object_class->finalize = gsd_a11y_keyboard_manager_finalize; + object_class->get_property = msd_a11y_keyboard_manager_get_property; + object_class->set_property = msd_a11y_keyboard_manager_set_property; + object_class->constructor = msd_a11y_keyboard_manager_constructor; + object_class->dispose = msd_a11y_keyboard_manager_dispose; + object_class->finalize = msd_a11y_keyboard_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdA11yKeyboardManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdA11yKeyboardManagerPrivate)); } static void on_preferences_dialog_response (GtkDialog *dialog, int response, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { g_signal_handlers_disconnect_by_func (dialog, on_preferences_dialog_response, @@ -1271,10 +1271,10 @@ on_preferences_dialog_response (GtkDialog *dialog, static void on_status_icon_activate (GtkStatusIcon *status_icon, - GsdA11yKeyboardManager *manager) + MsdA11yKeyboardManager *manager) { if (manager->priv->preferences_dialog == NULL) { - manager->priv->preferences_dialog = gsd_a11y_preferences_dialog_new (); + manager->priv->preferences_dialog = msd_a11y_preferences_dialog_new (); g_signal_connect (manager->priv->preferences_dialog, "response", G_CALLBACK (on_preferences_dialog_response), @@ -1291,7 +1291,7 @@ on_status_icon_activate (GtkStatusIcon *status_icon, } static void -gsd_a11y_keyboard_manager_ensure_status_icon (GsdA11yKeyboardManager *manager) +msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager) { mate_settings_profile_start (NULL); @@ -1308,9 +1308,9 @@ gsd_a11y_keyboard_manager_ensure_status_icon (GsdA11yKeyboardManager *manager) } static void -gsd_a11y_keyboard_manager_init (GsdA11yKeyboardManager *manager) +msd_a11y_keyboard_manager_init (MsdA11yKeyboardManager *manager) { - manager->priv = GSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE (manager); #ifdef HAVE_LIBMATENOTIFY notify_init ("mate-settings-daemon"); @@ -1318,30 +1318,30 @@ gsd_a11y_keyboard_manager_init (GsdA11yKeyboardManager *manager) } static void -gsd_a11y_keyboard_manager_finalize (GObject *object) +msd_a11y_keyboard_manager_finalize (GObject *object) { - GsdA11yKeyboardManager *a11y_keyboard_manager; + MsdA11yKeyboardManager *a11y_keyboard_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_A11Y_KEYBOARD_MANAGER (object)); + g_return_if_fail (MSD_IS_A11Y_KEYBOARD_MANAGER (object)); - a11y_keyboard_manager = GSD_A11Y_KEYBOARD_MANAGER (object); + a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (object); g_return_if_fail (a11y_keyboard_manager->priv != NULL); - G_OBJECT_CLASS (gsd_a11y_keyboard_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->finalize (object); } -GsdA11yKeyboardManager * -gsd_a11y_keyboard_manager_new (void) +MsdA11yKeyboardManager * +msd_a11y_keyboard_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_A11Y_KEYBOARD_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_A11Y_KEYBOARD_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_A11Y_KEYBOARD_MANAGER (manager_object); + return MSD_A11Y_KEYBOARD_MANAGER (manager_object); } diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h index 4fb817f..1869cf4 100644 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h +++ b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_A11Y_KEYBOARD_MANAGER_H -#define __GSD_A11Y_KEYBOARD_MANAGER_H +#ifndef __MSD_A11Y_KEYBOARD_MANAGER_H +#define __MSD_A11Y_KEYBOARD_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_A11Y_KEYBOARD_MANAGER (gsd_a11y_keyboard_manager_get_type ()) -#define GSD_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManager)) -#define GSD_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManagerClass)) -#define GSD_IS_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER)) -#define GSD_IS_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_A11Y_KEYBOARD_MANAGER)) -#define GSD_A11Y_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_A11Y_KEYBOARD_MANAGER, GsdA11yKeyboardManagerClass)) +#define MSD_TYPE_A11Y_KEYBOARD_MANAGER (msd_a11y_keyboard_manager_get_type ()) +#define MSD_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManager)) +#define MSD_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerClass)) +#define MSD_IS_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER)) +#define MSD_IS_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_KEYBOARD_MANAGER)) +#define MSD_A11Y_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerClass)) -typedef struct GsdA11yKeyboardManagerPrivate GsdA11yKeyboardManagerPrivate; +typedef struct MsdA11yKeyboardManagerPrivate MsdA11yKeyboardManagerPrivate; typedef struct { GObject parent; - GsdA11yKeyboardManagerPrivate *priv; -} GsdA11yKeyboardManager; + MsdA11yKeyboardManagerPrivate *priv; +} MsdA11yKeyboardManager; typedef struct { GObjectClass parent_class; -} GsdA11yKeyboardManagerClass; +} MsdA11yKeyboardManagerClass; -GType gsd_a11y_keyboard_manager_get_type (void); +GType msd_a11y_keyboard_manager_get_type (void); -GsdA11yKeyboardManager *gsd_a11y_keyboard_manager_new (void); -gboolean gsd_a11y_keyboard_manager_start (GsdA11yKeyboardManager *manager, +MsdA11yKeyboardManager *msd_a11y_keyboard_manager_new (void); +gboolean msd_a11y_keyboard_manager_start (MsdA11yKeyboardManager *manager, GError **error); -void gsd_a11y_keyboard_manager_stop (GsdA11yKeyboardManager *manager); +void msd_a11y_keyboard_manager_stop (MsdA11yKeyboardManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_A11Y_KEYBOARD_MANAGER_H */ +#endif /* __MSD_A11Y_KEYBOARD_MANAGER_H */ diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c b/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c index 7846ba6..7eed1c4 100644 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c +++ b/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-a11y-keyboard-plugin.h" -#include "gsd-a11y-keyboard-manager.h" +#include "msd-a11y-keyboard-plugin.h" +#include "msd-a11y-keyboard-manager.h" -struct GsdA11yKeyboardPluginPrivate { - GsdA11yKeyboardManager *manager; +struct MsdA11yKeyboardPluginPrivate { + MsdA11yKeyboardManager *manager; }; -#define GSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_A11Y_KEYBOARD_PLUGIN, GsdA11yKeyboardPluginPrivate)) +#define MSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdA11yKeyboardPlugin, gsd_a11y_keyboard_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdA11yKeyboardPlugin, msd_a11y_keyboard_plugin) static void -gsd_a11y_keyboard_plugin_init (GsdA11yKeyboardPlugin *plugin) +msd_a11y_keyboard_plugin_init (MsdA11yKeyboardPlugin *plugin) { - plugin->priv = GSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdA11yKeyboardPlugin initializing"); + g_debug ("MsdA11yKeyboardPlugin initializing"); - plugin->priv->manager = gsd_a11y_keyboard_manager_new (); + plugin->priv->manager = msd_a11y_keyboard_manager_new (); } static void -gsd_a11y_keyboard_plugin_finalize (GObject *object) +msd_a11y_keyboard_plugin_finalize (GObject *object) { - GsdA11yKeyboardPlugin *plugin; + MsdA11yKeyboardPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_A11Y_KEYBOARD_PLUGIN (object)); + g_return_if_fail (MSD_IS_A11Y_KEYBOARD_PLUGIN (object)); - g_debug ("GsdA11yKeyboardPlugin finalizing"); + g_debug ("MsdA11yKeyboardPlugin finalizing"); - plugin = GSD_A11Y_KEYBOARD_PLUGIN (object); + plugin = MSD_A11Y_KEYBOARD_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_a11y_keyboard_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_a11y_keyboard_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_a11y_keyboard_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating a11y_keyboard plugin"); error = NULL; - res = gsd_a11y_keyboard_manager_start (GSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); + res = msd_a11y_keyboard_manager_start (MSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start a11y_keyboard manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating a11y_keyboard plugin"); - gsd_a11y_keyboard_manager_stop (GSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager); + msd_a11y_keyboard_manager_stop (MSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager); } static void -gsd_a11y_keyboard_plugin_class_init (GsdA11yKeyboardPluginClass *klass) +msd_a11y_keyboard_plugin_class_init (MsdA11yKeyboardPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_a11y_keyboard_plugin_finalize; + object_class->finalize = msd_a11y_keyboard_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdA11yKeyboardPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdA11yKeyboardPluginPrivate)); } diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h b/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h index ebf246c..f4b8320 100644 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h +++ b/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_A11Y_KEYBOARD_PLUGIN_H__ -#define __GSD_A11Y_KEYBOARD_PLUGIN_H__ +#ifndef __MSD_A11Y_KEYBOARD_PLUGIN_H__ +#define __MSD_A11Y_KEYBOARD_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_A11Y_KEYBOARD_PLUGIN (gsd_a11y_keyboard_plugin_get_type ()) -#define GSD_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_A11Y_KEYBOARD_PLUGIN, GsdA11yKeyboardPlugin)) -#define GSD_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_A11Y_KEYBOARD_PLUGIN, GsdA11yKeyboardPluginClass)) -#define GSD_IS_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_A11Y_KEYBOARD_PLUGIN)) -#define GSD_IS_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_A11Y_KEYBOARD_PLUGIN)) -#define GSD_A11Y_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_A11Y_KEYBOARD_PLUGIN, GsdA11yKeyboardPluginClass)) +#define MSD_TYPE_A11Y_KEYBOARD_PLUGIN (msd_a11y_keyboard_plugin_get_type ()) +#define MSD_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPlugin)) +#define MSD_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginClass)) +#define MSD_IS_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN)) +#define MSD_IS_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_KEYBOARD_PLUGIN)) +#define MSD_A11Y_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginClass)) -typedef struct GsdA11yKeyboardPluginPrivate GsdA11yKeyboardPluginPrivate; +typedef struct MsdA11yKeyboardPluginPrivate MsdA11yKeyboardPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdA11yKeyboardPluginPrivate *priv; -} GsdA11yKeyboardPlugin; + MsdA11yKeyboardPluginPrivate *priv; +} MsdA11yKeyboardPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdA11yKeyboardPluginClass; +} MsdA11yKeyboardPluginClass; -GType gsd_a11y_keyboard_plugin_get_type (void) G_GNUC_CONST; +GType msd_a11y_keyboard_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_A11Y_KEYBOARD_PLUGIN_H__ */ +#endif /* __MSD_A11Y_KEYBOARD_PLUGIN_H__ */ diff --git a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c index 752ee18..a5db11c 100644 --- a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c +++ b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c @@ -34,16 +34,16 @@ #include -#include "gsd-a11y-preferences-dialog.h" +#include "msd-a11y-preferences-dialog.h" #define SM_DBUS_NAME "org.mate.SessionManager" #define SM_DBUS_PATH "/org/mate/SessionManager" #define SM_DBUS_INTERFACE "org.mate.SessionManager" -#define GSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_A11Y_PREFERENCES_DIALOG, GsdA11yPreferencesDialogPrivate)) +#define MSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogPrivate)) -#define GTKBUILDER_UI_FILE "gsd-a11y-preferences-dialog.ui" +#define GTKBUILDER_UI_FILE "msd-a11y-preferences-dialog.ui" #define KEY_A11Y_DIR "/desktop/mate/accessibility" #define KEY_STICKY_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/stickykeys_enable" @@ -83,7 +83,7 @@ #define HIGH_CONTRAST_THEME "HighContrast" -struct GsdA11yPreferencesDialogPrivate +struct MsdA11yPreferencesDialogPrivate { GtkWidget *sticky_keys_checkbutton; GtkWidget *slow_keys_checkbutton; @@ -97,21 +97,21 @@ struct GsdA11yPreferencesDialogPrivate GtkWidget *screen_magnifier_checkbutton; guint a11y_dir_cnxn; - guint gsd_a11y_dir_cnxn; + guint msd_a11y_dir_cnxn; }; enum { PROP_0, }; -static void gsd_a11y_preferences_dialog_class_init (GsdA11yPreferencesDialogClass *klass); -static void gsd_a11y_preferences_dialog_init (GsdA11yPreferencesDialog *a11y_preferences_dialog); -static void gsd_a11y_preferences_dialog_finalize (GObject *object); +static void msd_a11y_preferences_dialog_class_init (MsdA11yPreferencesDialogClass *klass); +static void msd_a11y_preferences_dialog_init (MsdA11yPreferencesDialog *a11y_preferences_dialog); +static void msd_a11y_preferences_dialog_finalize (GObject *object); -G_DEFINE_TYPE (GsdA11yPreferencesDialog, gsd_a11y_preferences_dialog, GTK_TYPE_DIALOG) +G_DEFINE_TYPE (MsdA11yPreferencesDialog, msd_a11y_preferences_dialog, GTK_TYPE_DIALOG) static void -gsd_a11y_preferences_dialog_set_property (GObject *object, +msd_a11y_preferences_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) @@ -124,7 +124,7 @@ gsd_a11y_preferences_dialog_set_property (GObject *object, } static void -gsd_a11y_preferences_dialog_get_property (GObject *object, +msd_a11y_preferences_dialog_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) @@ -137,13 +137,13 @@ gsd_a11y_preferences_dialog_get_property (GObject *object, } static GObject * -gsd_a11y_preferences_dialog_constructor (GType type, +msd_a11y_preferences_dialog_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdA11yPreferencesDialog *a11y_preferences_dialog; + MsdA11yPreferencesDialog *a11y_preferences_dialog; - a11y_preferences_dialog = GSD_A11Y_PREFERENCES_DIALOG (G_OBJECT_CLASS (gsd_a11y_preferences_dialog_parent_class)->constructor (type, + a11y_preferences_dialog = MSD_A11Y_PREFERENCES_DIALOG (G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -151,27 +151,27 @@ gsd_a11y_preferences_dialog_constructor (GType type, } static void -gsd_a11y_preferences_dialog_dispose (GObject *object) +msd_a11y_preferences_dialog_dispose (GObject *object) { - G_OBJECT_CLASS (gsd_a11y_preferences_dialog_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->dispose (object); } static void -gsd_a11y_preferences_dialog_class_init (GsdA11yPreferencesDialogClass *klass) +msd_a11y_preferences_dialog_class_init (MsdA11yPreferencesDialogClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_a11y_preferences_dialog_get_property; - object_class->set_property = gsd_a11y_preferences_dialog_set_property; - object_class->constructor = gsd_a11y_preferences_dialog_constructor; - object_class->dispose = gsd_a11y_preferences_dialog_dispose; - object_class->finalize = gsd_a11y_preferences_dialog_finalize; + object_class->get_property = msd_a11y_preferences_dialog_get_property; + object_class->set_property = msd_a11y_preferences_dialog_set_property; + object_class->constructor = msd_a11y_preferences_dialog_constructor; + object_class->dispose = msd_a11y_preferences_dialog_dispose; + object_class->finalize = msd_a11y_preferences_dialog_finalize; - g_type_class_add_private (klass, sizeof (GsdA11yPreferencesDialogPrivate)); + g_type_class_add_private (klass, sizeof (MsdA11yPreferencesDialogPrivate)); } static void -on_response (GsdA11yPreferencesDialog *dialog, +on_response (MsdA11yPreferencesDialog *dialog, gint response_id) { switch (response_id) { @@ -293,7 +293,7 @@ config_get_large_print (gboolean *is_writable) g_object_unref (client); - g_debug ("GsdA11yPreferences: got x-dpi=%f user-dpi=%f", x_dpi, u_dpi); + g_debug ("MsdA11yPreferences: got x-dpi=%f user-dpi=%f", x_dpi, u_dpi); ret = (((double)DPI_FACTOR_LARGE * x_dpi) < u_dpi); @@ -314,7 +314,7 @@ config_set_large_print (gboolean enabled) x_dpi = get_dpi_from_x_server (); u_dpi = (double)DPI_FACTOR_LARGER * x_dpi; - g_debug ("GsdA11yPreferences: setting x-dpi=%f user-dpi=%f", x_dpi, u_dpi); + g_debug ("MsdA11yPreferences: setting x-dpi=%f user-dpi=%f", x_dpi, u_dpi); mateconf_client_set_float (client, KEY_FONT_DPI, u_dpi, NULL); } else { @@ -501,62 +501,62 @@ config_set_at_screen_magnifier (gboolean enabled) static void on_sticky_keys_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_sticky_keys (gtk_toggle_button_get_active (button)); } static void on_bounce_keys_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_bounce_keys (gtk_toggle_button_get_active (button)); } static void on_slow_keys_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_slow_keys (gtk_toggle_button_get_active (button)); } static void on_high_contrast_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_high_contrast (gtk_toggle_button_get_active (button)); } static void on_at_screen_reader_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_at_screen_reader (gtk_toggle_button_get_active (button)); } static void on_at_screen_keyboard_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_at_screen_keyboard (gtk_toggle_button_get_active (button)); } static void on_at_screen_magnifier_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_at_screen_magnifier (gtk_toggle_button_get_active (button)); } static void on_large_print_checkbutton_toggled (GtkToggleButton *button, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { config_set_large_print (gtk_toggle_button_get_active (button)); } static void -ui_set_sticky_keys (GsdA11yPreferencesDialog *dialog, +ui_set_sticky_keys (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -568,7 +568,7 @@ ui_set_sticky_keys (GsdA11yPreferencesDialog *dialog, } static void -ui_set_bounce_keys (GsdA11yPreferencesDialog *dialog, +ui_set_bounce_keys (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -580,7 +580,7 @@ ui_set_bounce_keys (GsdA11yPreferencesDialog *dialog, } static void -ui_set_slow_keys (GsdA11yPreferencesDialog *dialog, +ui_set_slow_keys (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -592,7 +592,7 @@ ui_set_slow_keys (GsdA11yPreferencesDialog *dialog, } static void -ui_set_high_contrast (GsdA11yPreferencesDialog *dialog, +ui_set_high_contrast (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -604,7 +604,7 @@ ui_set_high_contrast (GsdA11yPreferencesDialog *dialog, } static void -ui_set_at_screen_reader (GsdA11yPreferencesDialog *dialog, +ui_set_at_screen_reader (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -616,7 +616,7 @@ ui_set_at_screen_reader (GsdA11yPreferencesDialog *dialog, } static void -ui_set_at_screen_keyboard (GsdA11yPreferencesDialog *dialog, +ui_set_at_screen_keyboard (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -628,7 +628,7 @@ ui_set_at_screen_keyboard (GsdA11yPreferencesDialog *dialog, } static void -ui_set_at_screen_magnifier (GsdA11yPreferencesDialog *dialog, +ui_set_at_screen_magnifier (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -640,7 +640,7 @@ ui_set_at_screen_magnifier (GsdA11yPreferencesDialog *dialog, } static void -ui_set_large_print (GsdA11yPreferencesDialog *dialog, +ui_set_large_print (MsdA11yPreferencesDialog *dialog, gboolean enabled) { gboolean active; @@ -655,7 +655,7 @@ static void key_changed_cb (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdA11yPreferencesDialog *dialog) + MsdA11yPreferencesDialog *dialog) { const char *key; MateConfValue *value; @@ -729,7 +729,7 @@ key_changed_cb (MateConfClient *client, } static void -setup_dialog (GsdA11yPreferencesDialog *dialog, +setup_dialog (MsdA11yPreferencesDialog *dialog, GtkBuilder *builder) { GtkWidget *widget; @@ -876,7 +876,7 @@ setup_dialog (GsdA11yPreferencesDialog *dialog, KEY_AT_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - dialog->priv->gsd_a11y_dir_cnxn = mateconf_client_notify_add (client, + dialog->priv->msd_a11y_dir_cnxn = mateconf_client_notify_add (client, KEY_AT_DIR, (MateConfClientNotifyFunc)key_changed_cb, dialog, @@ -887,14 +887,14 @@ setup_dialog (GsdA11yPreferencesDialog *dialog, } static void -gsd_a11y_preferences_dialog_init (GsdA11yPreferencesDialog *dialog) +msd_a11y_preferences_dialog_init (MsdA11yPreferencesDialog *dialog) { static const gchar *ui_file_path = GTKBUILDERDIR "/" GTKBUILDER_UI_FILE; gchar *objects[] = {"main_box", NULL}; GError *error = NULL; GtkBuilder *builder; - dialog->priv = GSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE (dialog); + dialog->priv = MSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE (dialog); builder = gtk_builder_new (); gtk_builder_set_translation_domain (builder, PACKAGE); @@ -937,15 +937,15 @@ gsd_a11y_preferences_dialog_init (GsdA11yPreferencesDialog *dialog) } static void -gsd_a11y_preferences_dialog_finalize (GObject *object) +msd_a11y_preferences_dialog_finalize (GObject *object) { - GsdA11yPreferencesDialog *dialog; + MsdA11yPreferencesDialog *dialog; MateConfClient *client; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_A11Y_PREFERENCES_DIALOG (object)); + g_return_if_fail (MSD_IS_A11Y_PREFERENCES_DIALOG (object)); - dialog = GSD_A11Y_PREFERENCES_DIALOG (object); + dialog = MSD_A11Y_PREFERENCES_DIALOG (object); g_return_if_fail (dialog->priv != NULL); @@ -954,21 +954,21 @@ gsd_a11y_preferences_dialog_finalize (GObject *object) if (dialog->priv->a11y_dir_cnxn > 0) { mateconf_client_notify_remove (client, dialog->priv->a11y_dir_cnxn); } - if (dialog->priv->gsd_a11y_dir_cnxn > 0) { - mateconf_client_notify_remove (client, dialog->priv->gsd_a11y_dir_cnxn); + if (dialog->priv->msd_a11y_dir_cnxn > 0) { + mateconf_client_notify_remove (client, dialog->priv->msd_a11y_dir_cnxn); } g_object_unref (client); - G_OBJECT_CLASS (gsd_a11y_preferences_dialog_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->finalize (object); } GtkWidget * -gsd_a11y_preferences_dialog_new (void) +msd_a11y_preferences_dialog_new (void) { GObject *object; - object = g_object_new (GSD_TYPE_A11Y_PREFERENCES_DIALOG, + object = g_object_new (MSD_TYPE_A11Y_PREFERENCES_DIALOG, NULL); return GTK_WIDGET (object); diff --git a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h index 2be096a..967a94e 100644 --- a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h +++ b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_A11Y_PREFERENCES_DIALOG_H -#define __GSD_A11Y_PREFERENCES_DIALOG_H +#ifndef __MSD_A11Y_PREFERENCES_DIALOG_H +#define __MSD_A11Y_PREFERENCES_DIALOG_H #include #include @@ -28,32 +28,32 @@ extern "C" { #endif -#define GSD_TYPE_A11Y_PREFERENCES_DIALOG (gsd_a11y_preferences_dialog_get_type ()) -#define GSD_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_A11Y_PREFERENCES_DIALOG, GsdA11yPreferencesDialog)) -#define GSD_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_A11Y_PREFERENCES_DIALOG, GsdA11yPreferencesDialogClass)) -#define GSD_IS_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_A11Y_PREFERENCES_DIALOG)) -#define GSD_IS_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_A11Y_PREFERENCES_DIALOG)) -#define GSD_A11Y_PREFERENCES_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_A11Y_PREFERENCES_DIALOG, GsdA11yPreferencesDialogClass)) +#define MSD_TYPE_A11Y_PREFERENCES_DIALOG (msd_a11y_preferences_dialog_get_type ()) +#define MSD_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialog)) +#define MSD_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogClass)) +#define MSD_IS_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG)) +#define MSD_IS_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_PREFERENCES_DIALOG)) +#define MSD_A11Y_PREFERENCES_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogClass)) -typedef struct GsdA11yPreferencesDialogPrivate GsdA11yPreferencesDialogPrivate; +typedef struct MsdA11yPreferencesDialogPrivate MsdA11yPreferencesDialogPrivate; typedef struct { GtkDialog parent; - GsdA11yPreferencesDialogPrivate *priv; -} GsdA11yPreferencesDialog; + MsdA11yPreferencesDialogPrivate *priv; +} MsdA11yPreferencesDialog; typedef struct { GtkDialogClass parent_class; -} GsdA11yPreferencesDialogClass; +} MsdA11yPreferencesDialogClass; -GType gsd_a11y_preferences_dialog_get_type (void); +GType msd_a11y_preferences_dialog_get_type (void); -GtkWidget * gsd_a11y_preferences_dialog_new (void); +GtkWidget * msd_a11y_preferences_dialog_new (void); #ifdef __cplusplus } #endif -#endif /* __GSD_A11Y_PREFERENCES_DIALOG_H */ +#endif /* __MSD_A11Y_PREFERENCES_DIALOG_H */ diff --git a/plugins/a11y-keyboard/test-a11y-preferences-dialog.c b/plugins/a11y-keyboard/test-a11y-preferences-dialog.c index 343f61c..0325a36 100644 --- a/plugins/a11y-keyboard/test-a11y-preferences-dialog.c +++ b/plugins/a11y-keyboard/test-a11y-preferences-dialog.c @@ -27,14 +27,14 @@ #include #include -#include "gsd-a11y-preferences-dialog.h" +#include "msd-a11y-preferences-dialog.h" static void test_window (void) { GtkWidget *window; - window = gsd_a11y_preferences_dialog_new (); + window = msd_a11y_preferences_dialog_new (); gtk_dialog_run (GTK_DIALOG (window)); } diff --git a/plugins/background/Makefile.am b/plugins/background/Makefile.am index f773144..a047573 100644 --- a/plugins/background/Makefile.am +++ b/plugins/background/Makefile.am @@ -6,8 +6,8 @@ noinst_PROGRAMS = \ test_background_SOURCES = \ test-background.c \ - gsd-background-manager.h \ - gsd-background-manager.c \ + msd-background-manager.h \ + msd-background-manager.c \ $(NULL) test_background_CPPFLAGS = \ @@ -20,7 +20,7 @@ test_background_CFLAGS = \ $(AM_CFLAGS) test_background_LDADD = \ - $(top_builddir)/mate-settings-daemon/libgsd-profile.la \ + $(top_builddir)/mate-settings-daemon/libmsd-profile.la \ $(SETTINGS_PLUGIN_LIBS) \ $(X11_LIBS) \ $(NULL) @@ -30,10 +30,10 @@ plugin_LTLIBRARIES = \ $(NULL) libbackground_la_SOURCES = \ - gsd-background-plugin.h \ - gsd-background-plugin.c \ - gsd-background-manager.h \ - gsd-background-manager.c \ + msd-background-plugin.h \ + msd-background-plugin.c \ + msd-background-manager.h \ + msd-background-manager.c \ $(NULL) libbackground_la_CPPFLAGS = \ @@ -47,7 +47,7 @@ libbackground_la_CFLAGS = \ $(AM_CFLAGS) libbackground_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libbackground_la_LIBADD = \ @@ -72,4 +72,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/background/gsd-background-manager.c b/plugins/background/gsd-background-manager.c index c05ec3f..25ab7ec 100644 --- a/plugins/background/gsd-background-manager.c +++ b/plugins/background/gsd-background-manager.c @@ -45,13 +45,13 @@ #include #include "mate-settings-profile.h" -#include "gsd-background-manager.h" +#include "msd-background-manager.h" #define CAJA_SHOW_DESKTOP_KEY "/apps/caja/preferences/show_desktop" -#define GSD_BACKGROUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManagerPrivate)) +#define MSD_BACKGROUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerPrivate)) -struct GsdBackgroundManagerPrivate +struct MsdBackgroundManagerPrivate { MateConfClient *client; MateBG *bg; @@ -61,11 +61,11 @@ struct GsdBackgroundManagerPrivate DBusConnection *dbus_connection; }; -static void gsd_background_manager_class_init (GsdBackgroundManagerClass *klass); -static void gsd_background_manager_init (GsdBackgroundManager *background_manager); -static void gsd_background_manager_finalize (GObject *object); +static void msd_background_manager_class_init (MsdBackgroundManagerClass *klass); +static void msd_background_manager_init (MsdBackgroundManager *background_manager); +static void msd_background_manager_finalize (GObject *object); -G_DEFINE_TYPE (GsdBackgroundManager, gsd_background_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdBackgroundManager, msd_background_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -161,7 +161,7 @@ caja_is_running (void) } static void -draw_background (GsdBackgroundManager *manager, +draw_background (MsdBackgroundManager *manager, gboolean use_crossfade) { GdkDisplay *display; @@ -210,14 +210,14 @@ draw_background (GsdBackgroundManager *manager, static void on_bg_changed (MateBG *bg, - GsdBackgroundManager *manager) + MsdBackgroundManager *manager) { draw_background (manager, TRUE); } static void on_bg_transitioned (MateBG *bg, - GsdBackgroundManager *manager) + MsdBackgroundManager *manager) { draw_background (manager, FALSE); } @@ -226,14 +226,14 @@ static void mateconf_changed_callback (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdBackgroundManager *manager) + MsdBackgroundManager *manager) { mate_bg_load_from_preferences (manager->priv->bg, manager->priv->client); } static void -watch_bg_preferences (GsdBackgroundManager *manager) +watch_bg_preferences (MsdBackgroundManager *manager) { g_assert (manager->priv->bg_notify_id == 0); @@ -250,7 +250,7 @@ watch_bg_preferences (GsdBackgroundManager *manager) } static void -setup_bg (GsdBackgroundManager *manager) +setup_bg (MsdBackgroundManager *manager) { g_return_if_fail (manager->priv->bg == NULL); @@ -272,7 +272,7 @@ setup_bg (GsdBackgroundManager *manager) } static gboolean -queue_draw_background (GsdBackgroundManager *manager) +queue_draw_background (MsdBackgroundManager *manager) { manager->priv->timeout_id = 0; if (caja_is_running ()) { @@ -288,7 +288,7 @@ on_bus_message (DBusConnection *connection, DBusMessage *message, void *user_data) { - GsdBackgroundManager *manager = user_data; + MsdBackgroundManager *manager = user_data; if (dbus_message_is_signal (message, "org.mate.SessionManager", @@ -315,7 +315,7 @@ on_bus_message (DBusConnection *connection, } static void -draw_background_after_session_loads (GsdBackgroundManager *manager) +draw_background_after_session_loads (MsdBackgroundManager *manager) { DBusConnection *connection; @@ -334,7 +334,7 @@ draw_background_after_session_loads (GsdBackgroundManager *manager) static void on_screen_size_changed (GdkScreen *screen, - GsdBackgroundManager *manager) + MsdBackgroundManager *manager) { gboolean caja_show_desktop; @@ -351,7 +351,7 @@ on_screen_size_changed (GdkScreen *screen, } static void -disconnect_screen_signals (GsdBackgroundManager *manager) +disconnect_screen_signals (MsdBackgroundManager *manager) { GdkDisplay *display; int i; @@ -370,7 +370,7 @@ disconnect_screen_signals (GsdBackgroundManager *manager) } static void -connect_screen_signals (GsdBackgroundManager *manager) +connect_screen_signals (MsdBackgroundManager *manager) { GdkDisplay *display; int i; @@ -394,7 +394,7 @@ connect_screen_signals (GsdBackgroundManager *manager) } gboolean -gsd_background_manager_start (GsdBackgroundManager *manager, +msd_background_manager_start (MsdBackgroundManager *manager, GError **error) { gboolean caja_show_desktop; @@ -429,9 +429,9 @@ gsd_background_manager_start (GsdBackgroundManager *manager, } void -gsd_background_manager_stop (GsdBackgroundManager *manager) +msd_background_manager_stop (MsdBackgroundManager *manager) { - GsdBackgroundManagerPrivate *p = manager->priv; + MsdBackgroundManagerPrivate *p = manager->priv; g_debug ("Stopping background manager"); @@ -469,14 +469,14 @@ gsd_background_manager_stop (GsdBackgroundManager *manager) } static void -gsd_background_manager_set_property (GObject *object, +msd_background_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdBackgroundManager *self; + MsdBackgroundManager *self; - self = GSD_BACKGROUND_MANAGER (object); + self = MSD_BACKGROUND_MANAGER (object); switch (prop_id) { default: @@ -486,14 +486,14 @@ gsd_background_manager_set_property (GObject *object, } static void -gsd_background_manager_get_property (GObject *object, +msd_background_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdBackgroundManager *self; + MsdBackgroundManager *self; - self = GSD_BACKGROUND_MANAGER (object); + self = MSD_BACKGROUND_MANAGER (object); switch (prop_id) { default: @@ -503,16 +503,16 @@ gsd_background_manager_get_property (GObject *object, } static GObject * -gsd_background_manager_constructor (GType type, +msd_background_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdBackgroundManager *background_manager; - GsdBackgroundManagerClass *klass; + MsdBackgroundManager *background_manager; + MsdBackgroundManagerClass *klass; - klass = GSD_BACKGROUND_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_BACKGROUND_MANAGER)); + klass = MSD_BACKGROUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_BACKGROUND_MANAGER)); - background_manager = GSD_BACKGROUND_MANAGER (G_OBJECT_CLASS (gsd_background_manager_parent_class)->constructor (type, + background_manager = MSD_BACKGROUND_MANAGER (G_OBJECT_CLASS (msd_background_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -520,60 +520,60 @@ gsd_background_manager_constructor (GType type, } static void -gsd_background_manager_dispose (GObject *object) +msd_background_manager_dispose (GObject *object) { - GsdBackgroundManager *background_manager; + MsdBackgroundManager *background_manager; - background_manager = GSD_BACKGROUND_MANAGER (object); + background_manager = MSD_BACKGROUND_MANAGER (object); - G_OBJECT_CLASS (gsd_background_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_background_manager_parent_class)->dispose (object); } static void -gsd_background_manager_class_init (GsdBackgroundManagerClass *klass) +msd_background_manager_class_init (MsdBackgroundManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_background_manager_get_property; - object_class->set_property = gsd_background_manager_set_property; - object_class->constructor = gsd_background_manager_constructor; - object_class->dispose = gsd_background_manager_dispose; - object_class->finalize = gsd_background_manager_finalize; + object_class->get_property = msd_background_manager_get_property; + object_class->set_property = msd_background_manager_set_property; + object_class->constructor = msd_background_manager_constructor; + object_class->dispose = msd_background_manager_dispose; + object_class->finalize = msd_background_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdBackgroundManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdBackgroundManagerPrivate)); } static void -gsd_background_manager_init (GsdBackgroundManager *manager) +msd_background_manager_init (MsdBackgroundManager *manager) { - manager->priv = GSD_BACKGROUND_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_BACKGROUND_MANAGER_GET_PRIVATE (manager); } static void -gsd_background_manager_finalize (GObject *object) +msd_background_manager_finalize (GObject *object) { - GsdBackgroundManager *background_manager; + MsdBackgroundManager *background_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_BACKGROUND_MANAGER (object)); + g_return_if_fail (MSD_IS_BACKGROUND_MANAGER (object)); - background_manager = GSD_BACKGROUND_MANAGER (object); + background_manager = MSD_BACKGROUND_MANAGER (object); g_return_if_fail (background_manager->priv != NULL); - G_OBJECT_CLASS (gsd_background_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_background_manager_parent_class)->finalize (object); } -GsdBackgroundManager * -gsd_background_manager_new (void) +MsdBackgroundManager * +msd_background_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_BACKGROUND_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_BACKGROUND_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_BACKGROUND_MANAGER (manager_object); + return MSD_BACKGROUND_MANAGER (manager_object); } diff --git a/plugins/background/gsd-background-manager.h b/plugins/background/gsd-background-manager.h index 27c900a..91e232c 100644 --- a/plugins/background/gsd-background-manager.h +++ b/plugins/background/gsd-background-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_BACKGROUND_MANAGER_H -#define __GSD_BACKGROUND_MANAGER_H +#ifndef __MSD_BACKGROUND_MANAGER_H +#define __MSD_BACKGROUND_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_BACKGROUND_MANAGER (gsd_background_manager_get_type ()) -#define GSD_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManager)) -#define GSD_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManagerClass)) -#define GSD_IS_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_BACKGROUND_MANAGER)) -#define GSD_IS_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_BACKGROUND_MANAGER)) -#define GSD_BACKGROUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_BACKGROUND_MANAGER, GsdBackgroundManagerClass)) +#define MSD_TYPE_BACKGROUND_MANAGER (msd_background_manager_get_type ()) +#define MSD_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManager)) +#define MSD_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass)) +#define MSD_IS_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_BACKGROUND_MANAGER)) +#define MSD_IS_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_BACKGROUND_MANAGER)) +#define MSD_BACKGROUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass)) -typedef struct GsdBackgroundManagerPrivate GsdBackgroundManagerPrivate; +typedef struct MsdBackgroundManagerPrivate MsdBackgroundManagerPrivate; typedef struct { GObject parent; - GsdBackgroundManagerPrivate *priv; -} GsdBackgroundManager; + MsdBackgroundManagerPrivate *priv; +} MsdBackgroundManager; typedef struct { GObjectClass parent_class; -} GsdBackgroundManagerClass; +} MsdBackgroundManagerClass; -GType gsd_background_manager_get_type (void); +GType msd_background_manager_get_type (void); -GsdBackgroundManager * gsd_background_manager_new (void); -gboolean gsd_background_manager_start (GsdBackgroundManager *manager, +MsdBackgroundManager * msd_background_manager_new (void); +gboolean msd_background_manager_start (MsdBackgroundManager *manager, GError **error); -void gsd_background_manager_stop (GsdBackgroundManager *manager); +void msd_background_manager_stop (MsdBackgroundManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_BACKGROUND_MANAGER_H */ +#endif /* __MSD_BACKGROUND_MANAGER_H */ diff --git a/plugins/background/gsd-background-plugin.c b/plugins/background/gsd-background-plugin.c index e001f39..d12bb2b 100644 --- a/plugins/background/gsd-background-plugin.c +++ b/plugins/background/gsd-background-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-background-plugin.h" -#include "gsd-background-manager.h" +#include "msd-background-plugin.h" +#include "msd-background-manager.h" -struct GsdBackgroundPluginPrivate { - GsdBackgroundManager *manager; +struct MsdBackgroundPluginPrivate { + MsdBackgroundManager *manager; }; -#define GSD_BACKGROUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_BACKGROUND_PLUGIN, GsdBackgroundPluginPrivate)) +#define MSD_BACKGROUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdBackgroundPlugin, gsd_background_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdBackgroundPlugin, msd_background_plugin) static void -gsd_background_plugin_init (GsdBackgroundPlugin *plugin) +msd_background_plugin_init (MsdBackgroundPlugin *plugin) { - plugin->priv = GSD_BACKGROUND_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_BACKGROUND_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdBackgroundPlugin initializing"); + g_debug ("MsdBackgroundPlugin initializing"); - plugin->priv->manager = gsd_background_manager_new (); + plugin->priv->manager = msd_background_manager_new (); } static void -gsd_background_plugin_finalize (GObject *object) +msd_background_plugin_finalize (GObject *object) { - GsdBackgroundPlugin *plugin; + MsdBackgroundPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_BACKGROUND_PLUGIN (object)); + g_return_if_fail (MSD_IS_BACKGROUND_PLUGIN (object)); - g_debug ("GsdBackgroundPlugin finalizing"); + g_debug ("MsdBackgroundPlugin finalizing"); - plugin = GSD_BACKGROUND_PLUGIN (object); + plugin = MSD_BACKGROUND_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_background_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_background_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_background_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating background plugin"); error = NULL; - res = gsd_background_manager_start (GSD_BACKGROUND_PLUGIN (plugin)->priv->manager, &error); + res = msd_background_manager_start (MSD_BACKGROUND_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start background manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating background plugin"); - gsd_background_manager_stop (GSD_BACKGROUND_PLUGIN (plugin)->priv->manager); + msd_background_manager_stop (MSD_BACKGROUND_PLUGIN (plugin)->priv->manager); } static void -gsd_background_plugin_class_init (GsdBackgroundPluginClass *klass) +msd_background_plugin_class_init (MsdBackgroundPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_background_plugin_finalize; + object_class->finalize = msd_background_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdBackgroundPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdBackgroundPluginPrivate)); } diff --git a/plugins/background/gsd-background-plugin.h b/plugins/background/gsd-background-plugin.h index 1acaf9f..dd52572 100644 --- a/plugins/background/gsd-background-plugin.h +++ b/plugins/background/gsd-background-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_BACKGROUND_PLUGIN_H__ -#define __GSD_BACKGROUND_PLUGIN_H__ +#ifndef __MSD_BACKGROUND_PLUGIN_H__ +#define __MSD_BACKGROUND_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_BACKGROUND_PLUGIN (gsd_background_plugin_get_type ()) -#define GSD_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_BACKGROUND_PLUGIN, GsdBackgroundPlugin)) -#define GSD_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_BACKGROUND_PLUGIN, GsdBackgroundPluginClass)) -#define GSD_IS_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_BACKGROUND_PLUGIN)) -#define GSD_IS_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_BACKGROUND_PLUGIN)) -#define GSD_BACKGROUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_BACKGROUND_PLUGIN, GsdBackgroundPluginClass)) +#define MSD_TYPE_BACKGROUND_PLUGIN (msd_background_plugin_get_type ()) +#define MSD_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPlugin)) +#define MSD_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginClass)) +#define MSD_IS_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_BACKGROUND_PLUGIN)) +#define MSD_IS_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_BACKGROUND_PLUGIN)) +#define MSD_BACKGROUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginClass)) -typedef struct GsdBackgroundPluginPrivate GsdBackgroundPluginPrivate; +typedef struct MsdBackgroundPluginPrivate MsdBackgroundPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdBackgroundPluginPrivate *priv; -} GsdBackgroundPlugin; + MsdBackgroundPluginPrivate *priv; +} MsdBackgroundPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdBackgroundPluginClass; +} MsdBackgroundPluginClass; -GType gsd_background_plugin_get_type (void) G_GNUC_CONST; +GType msd_background_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_BACKGROUND_PLUGIN_H__ */ +#endif /* __MSD_BACKGROUND_PLUGIN_H__ */ diff --git a/plugins/background/test-background.c b/plugins/background/test-background.c index a7b5ef7..f9b0849 100644 --- a/plugins/background/test-background.c +++ b/plugins/background/test-background.c @@ -28,19 +28,19 @@ #include #include -#include "gsd-background-manager.h" +#include "msd-background-manager.h" static gboolean -idle (GsdBackgroundManager *manager) +idle (MsdBackgroundManager *manager) { - gsd_background_manager_start (manager, NULL); + msd_background_manager_start (manager, NULL); return FALSE; } int main (int argc, char *argv[]) { - GsdBackgroundManager *manager; + MsdBackgroundManager *manager; bindtextdomain (GETTEXT_PACKAGE, MATE_SETTINGS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); @@ -50,7 +50,7 @@ main (int argc, char *argv[]) gtk_init (&argc, &argv); - manager = gsd_background_manager_new (); + manager = msd_background_manager_new (); g_idle_add ((GSourceFunc)idle, manager); gtk_main (); diff --git a/plugins/clipboard/Makefile.am b/plugins/clipboard/Makefile.am index f50a86e..4b1fdca 100644 --- a/plugins/clipboard/Makefile.am +++ b/plugins/clipboard/Makefile.am @@ -5,10 +5,10 @@ plugin_LTLIBRARIES = \ $(NULL) libclipboard_la_SOURCES = \ - gsd-clipboard-plugin.h \ - gsd-clipboard-plugin.c \ - gsd-clipboard-manager.h \ - gsd-clipboard-manager.c \ + msd-clipboard-plugin.h \ + msd-clipboard-plugin.c \ + msd-clipboard-manager.h \ + msd-clipboard-manager.c \ xutils.h \ xutils.c \ list.h \ @@ -25,7 +25,7 @@ libclipboard_la_CFLAGS = \ $(AM_CFLAGS) libclipboard_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libclipboard_la_LIBADD = \ @@ -50,4 +50,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/clipboard/gsd-clipboard-manager.c b/plugins/clipboard/gsd-clipboard-manager.c index fcbc839..c6d5a57 100644 --- a/plugins/clipboard/gsd-clipboard-manager.c +++ b/plugins/clipboard/gsd-clipboard-manager.c @@ -45,11 +45,11 @@ #include "list.h" #include "mate-settings-profile.h" -#include "gsd-clipboard-manager.h" +#include "msd-clipboard-manager.h" -#define GSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerPrivate)) +#define MSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerPrivate)) -struct GsdClipboardManagerPrivate +struct MsdClipboardManagerPrivate { Display *display; Window window; @@ -82,17 +82,17 @@ typedef struct int offset; } IncrConversion; -static void gsd_clipboard_manager_class_init (GsdClipboardManagerClass *klass); -static void gsd_clipboard_manager_init (GsdClipboardManager *clipboard_manager); -static void gsd_clipboard_manager_finalize (GObject *object); +static void msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass); +static void msd_clipboard_manager_init (MsdClipboardManager *clipboard_manager); +static void msd_clipboard_manager_finalize (GObject *object); -static void clipboard_manager_watch_cb (GsdClipboardManager *manager, +static void clipboard_manager_watch_cb (MsdClipboardManager *manager, Window window, Bool is_start, long mask, void *cb_data); -G_DEFINE_TYPE (GsdClipboardManager, gsd_clipboard_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdClipboardManager, msd_clipboard_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -127,7 +127,7 @@ conversion_free (IncrConversion *rdata) } static void -send_selection_notify (GsdClipboardManager *manager, +send_selection_notify (MsdClipboardManager *manager, Bool success) { XSelectionEvent notify; @@ -155,7 +155,7 @@ send_selection_notify (GsdClipboardManager *manager, } static void -finish_selection_request (GsdClipboardManager *manager, +finish_selection_request (MsdClipboardManager *manager, XEvent *xev, Bool success) { @@ -195,7 +195,7 @@ clipboard_bytes_per_item (int format) } static void -save_targets (GsdClipboardManager *manager, +save_targets (MsdClipboardManager *manager, Atom *save_targets, int nitems) { @@ -263,7 +263,7 @@ find_conversion_requestor (IncrConversion *rdata, static void get_property (TargetData *tdata, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { Atom type; int format; @@ -300,7 +300,7 @@ get_property (TargetData *tdata, } static Bool -receive_incrementally (GsdClipboardManager *manager, +receive_incrementally (MsdClipboardManager *manager, XEvent *xev) { List *list; @@ -359,7 +359,7 @@ receive_incrementally (GsdClipboardManager *manager, } static Bool -send_incrementally (GsdClipboardManager *manager, +send_incrementally (MsdClipboardManager *manager, XEvent *xev) { List *list; @@ -397,7 +397,7 @@ send_incrementally (GsdClipboardManager *manager, } static void -convert_clipboard_manager (GsdClipboardManager *manager, +convert_clipboard_manager (MsdClipboardManager *manager, XEvent *xev) { Atom type = None; @@ -486,7 +486,7 @@ convert_clipboard_manager (GsdClipboardManager *manager, static void convert_clipboard_target (IncrConversion *rdata, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { TargetData *tdata; Atom *targets; @@ -561,7 +561,7 @@ convert_clipboard_target (IncrConversion *rdata, static void collect_incremental (IncrConversion *rdata, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { if (rdata->offset >= 0) manager->priv->conversions = list_prepend (manager->priv->conversions, rdata); @@ -575,7 +575,7 @@ collect_incremental (IncrConversion *rdata, } static void -convert_clipboard (GsdClipboardManager *manager, +convert_clipboard (MsdClipboardManager *manager, XEvent *xev) { List *list; @@ -656,7 +656,7 @@ convert_clipboard (GsdClipboardManager *manager, } static Bool -clipboard_manager_process_event (GsdClipboardManager *manager, +clipboard_manager_process_event (MsdClipboardManager *manager, XEvent *xev) { Atom type; @@ -805,7 +805,7 @@ clipboard_manager_process_event (GsdClipboardManager *manager, static GdkFilterReturn clipboard_manager_event_filter (GdkXEvent *xevent, GdkEvent *event, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { if (clipboard_manager_process_event (manager, (XEvent *)xevent)) { return GDK_FILTER_REMOVE; @@ -815,7 +815,7 @@ clipboard_manager_event_filter (GdkXEvent *xevent, } static void -clipboard_manager_watch_cb (GsdClipboardManager *manager, +clipboard_manager_watch_cb (MsdClipboardManager *manager, Window window, Bool is_start, long mask, @@ -849,7 +849,7 @@ clipboard_manager_watch_cb (GsdClipboardManager *manager, } static gboolean -start_clipboard_idle_cb (GsdClipboardManager *manager) +start_clipboard_idle_cb (MsdClipboardManager *manager) { XClientMessageEvent xev; @@ -924,7 +924,7 @@ start_clipboard_idle_cb (GsdClipboardManager *manager) } gboolean -gsd_clipboard_manager_start (GsdClipboardManager *manager, +msd_clipboard_manager_start (MsdClipboardManager *manager, GError **error) { mate_settings_profile_start (NULL); @@ -937,7 +937,7 @@ gsd_clipboard_manager_start (GsdClipboardManager *manager, } void -gsd_clipboard_manager_stop (GsdClipboardManager *manager) +msd_clipboard_manager_stop (MsdClipboardManager *manager) { g_debug ("Stopping clipboard manager"); @@ -956,14 +956,14 @@ gsd_clipboard_manager_stop (GsdClipboardManager *manager) } static void -gsd_clipboard_manager_set_property (GObject *object, +msd_clipboard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdClipboardManager *self; + MsdClipboardManager *self; - self = GSD_CLIPBOARD_MANAGER (object); + self = MSD_CLIPBOARD_MANAGER (object); switch (prop_id) { default: @@ -973,14 +973,14 @@ gsd_clipboard_manager_set_property (GObject *object, } static void -gsd_clipboard_manager_get_property (GObject *object, +msd_clipboard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdClipboardManager *self; + MsdClipboardManager *self; - self = GSD_CLIPBOARD_MANAGER (object); + self = MSD_CLIPBOARD_MANAGER (object); switch (prop_id) { default: @@ -990,16 +990,16 @@ gsd_clipboard_manager_get_property (GObject *object, } static GObject * -gsd_clipboard_manager_constructor (GType type, +msd_clipboard_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdClipboardManager *clipboard_manager; - GsdClipboardManagerClass *klass; + MsdClipboardManager *clipboard_manager; + MsdClipboardManagerClass *klass; - klass = GSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_CLIPBOARD_MANAGER)); + klass = MSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_CLIPBOARD_MANAGER)); - clipboard_manager = GSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->constructor (type, + clipboard_manager = MSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -1007,63 +1007,63 @@ gsd_clipboard_manager_constructor (GType type, } static void -gsd_clipboard_manager_dispose (GObject *object) +msd_clipboard_manager_dispose (GObject *object) { - GsdClipboardManager *clipboard_manager; + MsdClipboardManager *clipboard_manager; - clipboard_manager = GSD_CLIPBOARD_MANAGER (object); + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); - G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->dispose (object); } static void -gsd_clipboard_manager_class_init (GsdClipboardManagerClass *klass) +msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_clipboard_manager_get_property; - object_class->set_property = gsd_clipboard_manager_set_property; - object_class->constructor = gsd_clipboard_manager_constructor; - object_class->dispose = gsd_clipboard_manager_dispose; - object_class->finalize = gsd_clipboard_manager_finalize; + object_class->get_property = msd_clipboard_manager_get_property; + object_class->set_property = msd_clipboard_manager_set_property; + object_class->constructor = msd_clipboard_manager_constructor; + object_class->dispose = msd_clipboard_manager_dispose; + object_class->finalize = msd_clipboard_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdClipboardManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdClipboardManagerPrivate)); } static void -gsd_clipboard_manager_init (GsdClipboardManager *manager) +msd_clipboard_manager_init (MsdClipboardManager *manager) { - manager->priv = GSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); } static void -gsd_clipboard_manager_finalize (GObject *object) +msd_clipboard_manager_finalize (GObject *object) { - GsdClipboardManager *clipboard_manager; + MsdClipboardManager *clipboard_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_CLIPBOARD_MANAGER (object)); + g_return_if_fail (MSD_IS_CLIPBOARD_MANAGER (object)); - clipboard_manager = GSD_CLIPBOARD_MANAGER (object); + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); g_return_if_fail (clipboard_manager->priv != NULL); - G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->finalize (object); } -GsdClipboardManager * -gsd_clipboard_manager_new (void) +MsdClipboardManager * +msd_clipboard_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_CLIPBOARD_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_CLIPBOARD_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_CLIPBOARD_MANAGER (manager_object); + return MSD_CLIPBOARD_MANAGER (manager_object); } diff --git a/plugins/clipboard/gsd-clipboard-manager.h b/plugins/clipboard/gsd-clipboard-manager.h index 0338799..e4af711 100644 --- a/plugins/clipboard/gsd-clipboard-manager.h +++ b/plugins/clipboard/gsd-clipboard-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_CLIPBOARD_MANAGER_H -#define __GSD_CLIPBOARD_MANAGER_H +#ifndef __MSD_CLIPBOARD_MANAGER_H +#define __MSD_CLIPBOARD_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_CLIPBOARD_MANAGER (gsd_clipboard_manager_get_type ()) -#define GSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManager)) -#define GSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerClass)) -#define GSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_CLIPBOARD_MANAGER)) -#define GSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_CLIPBOARD_MANAGER)) -#define GSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerClass)) +#define MSD_TYPE_CLIPBOARD_MANAGER (msd_clipboard_manager_get_type ()) +#define MSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManager)) +#define MSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) +#define MSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) -typedef struct GsdClipboardManagerPrivate GsdClipboardManagerPrivate; +typedef struct MsdClipboardManagerPrivate MsdClipboardManagerPrivate; typedef struct { GObject parent; - GsdClipboardManagerPrivate *priv; -} GsdClipboardManager; + MsdClipboardManagerPrivate *priv; +} MsdClipboardManager; typedef struct { GObjectClass parent_class; -} GsdClipboardManagerClass; +} MsdClipboardManagerClass; -GType gsd_clipboard_manager_get_type (void); +GType msd_clipboard_manager_get_type (void); -GsdClipboardManager * gsd_clipboard_manager_new (void); -gboolean gsd_clipboard_manager_start (GsdClipboardManager *manager, +MsdClipboardManager * msd_clipboard_manager_new (void); +gboolean msd_clipboard_manager_start (MsdClipboardManager *manager, GError **error); -void gsd_clipboard_manager_stop (GsdClipboardManager *manager); +void msd_clipboard_manager_stop (MsdClipboardManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_CLIPBOARD_MANAGER_H */ +#endif /* __MSD_CLIPBOARD_MANAGER_H */ diff --git a/plugins/clipboard/gsd-clipboard-plugin.c b/plugins/clipboard/gsd-clipboard-plugin.c index f384b52..6674265 100644 --- a/plugins/clipboard/gsd-clipboard-plugin.c +++ b/plugins/clipboard/gsd-clipboard-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-clipboard-plugin.h" -#include "gsd-clipboard-manager.h" +#include "msd-clipboard-plugin.h" +#include "msd-clipboard-manager.h" -struct GsdClipboardPluginPrivate { - GsdClipboardManager *manager; +struct MsdClipboardPluginPrivate { + MsdClipboardManager *manager; }; -#define GSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPluginPrivate)) +#define MSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdClipboardPlugin, gsd_clipboard_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdClipboardPlugin, msd_clipboard_plugin) static void -gsd_clipboard_plugin_init (GsdClipboardPlugin *plugin) +msd_clipboard_plugin_init (MsdClipboardPlugin *plugin) { - plugin->priv = GSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdClipboardPlugin initializing"); + g_debug ("MsdClipboardPlugin initializing"); - plugin->priv->manager = gsd_clipboard_manager_new (); + plugin->priv->manager = msd_clipboard_manager_new (); } static void -gsd_clipboard_plugin_finalize (GObject *object) +msd_clipboard_plugin_finalize (GObject *object) { - GsdClipboardPlugin *plugin; + MsdClipboardPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_CLIPBOARD_PLUGIN (object)); + g_return_if_fail (MSD_IS_CLIPBOARD_PLUGIN (object)); - g_debug ("GsdClipboardPlugin finalizing"); + g_debug ("MsdClipboardPlugin finalizing"); - plugin = GSD_CLIPBOARD_PLUGIN (object); + plugin = MSD_CLIPBOARD_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_clipboard_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_clipboard_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_clipboard_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating clipboard plugin"); error = NULL; - res = gsd_clipboard_manager_start (GSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); + res = msd_clipboard_manager_start (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start clipboard manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating clipboard plugin"); - gsd_clipboard_manager_stop (GSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); + msd_clipboard_manager_stop (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); } static void -gsd_clipboard_plugin_class_init (GsdClipboardPluginClass *klass) +msd_clipboard_plugin_class_init (MsdClipboardPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_clipboard_plugin_finalize; + object_class->finalize = msd_clipboard_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdClipboardPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdClipboardPluginPrivate)); } diff --git a/plugins/clipboard/gsd-clipboard-plugin.h b/plugins/clipboard/gsd-clipboard-plugin.h index 4148c09..7b2ea1e 100644 --- a/plugins/clipboard/gsd-clipboard-plugin.h +++ b/plugins/clipboard/gsd-clipboard-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_CLIPBOARD_PLUGIN_H__ -#define __GSD_CLIPBOARD_PLUGIN_H__ +#ifndef __MSD_CLIPBOARD_PLUGIN_H__ +#define __MSD_CLIPBOARD_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_CLIPBOARD_PLUGIN (gsd_clipboard_plugin_get_type ()) -#define GSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPlugin)) -#define GSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPluginClass)) -#define GSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_CLIPBOARD_PLUGIN)) -#define GSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_CLIPBOARD_PLUGIN)) -#define GSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPluginClass)) +#define MSD_TYPE_CLIPBOARD_PLUGIN (msd_clipboard_plugin_get_type ()) +#define MSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPlugin)) +#define MSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) +#define MSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) -typedef struct GsdClipboardPluginPrivate GsdClipboardPluginPrivate; +typedef struct MsdClipboardPluginPrivate MsdClipboardPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdClipboardPluginPrivate *priv; -} GsdClipboardPlugin; + MsdClipboardPluginPrivate *priv; +} MsdClipboardPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdClipboardPluginClass; +} MsdClipboardPluginClass; -GType gsd_clipboard_plugin_get_type (void) G_GNUC_CONST; +GType msd_clipboard_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_CLIPBOARD_PLUGIN_H__ */ +#endif /* __MSD_CLIPBOARD_PLUGIN_H__ */ diff --git a/plugins/common/Makefile.am b/plugins/common/Makefile.am index 447d02d..3733a90 100644 --- a/plugins/common/Makefile.am +++ b/plugins/common/Makefile.am @@ -4,10 +4,10 @@ noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = \ eggaccelerators.c \ eggaccelerators.h \ - gsd-keygrab.c \ - gsd-keygrab.h \ - gsd-osd-window.c \ - gsd-osd-window.h + msd-keygrab.c \ + msd-keygrab.h \ + msd-osd-window.c \ + msd-osd-window.h libcommon_la_CPPFLAGS = \ $(AM_CPPFLAGS) @@ -17,7 +17,7 @@ libcommon_la_CFLAGS = \ $(AM_CFLAGS) libcommon_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) $(X11_LIBS) + $(MSD_PLUGIN_LDFLAGS) $(X11_LIBS) libcommon_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) diff --git a/plugins/common/gsd-keygrab.c b/plugins/common/gsd-keygrab.c index d94fd29..7a16f4e 100644 --- a/plugins/common/gsd-keygrab.c +++ b/plugins/common/gsd-keygrab.c @@ -32,25 +32,25 @@ #include "eggaccelerators.h" -#include "gsd-keygrab.h" +#include "msd-keygrab.h" /* these are the mods whose combinations are ignored by the keygrabbing code */ -static GdkModifierType gsd_ignored_mods = 0; +static GdkModifierType msd_ignored_mods = 0; /* these are the ones we actually use for global keys, we always only check * for these set */ -static GdkModifierType gsd_used_mods = 0; +static GdkModifierType msd_used_mods = 0; static void setup_modifiers (void) { - if (gsd_used_mods == 0 || gsd_ignored_mods == 0) { + if (msd_used_mods == 0 || msd_ignored_mods == 0) { GdkModifierType dynmods; /* default modifiers */ - gsd_ignored_mods = \ + msd_ignored_mods = \ 0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK; - gsd_used_mods = \ + msd_used_mods = \ GDK_SHIFT_MASK | GDK_CONTROL_MASK |\ GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\ GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK; @@ -62,8 +62,8 @@ setup_modifiers (void) EGG_VIRTUAL_NUM_LOCK_MASK, &dynmods); - gsd_ignored_mods |= dynmods; - gsd_used_mods &= ~dynmods; + msd_ignored_mods |= dynmods; + msd_used_mods &= ~dynmods; } } @@ -89,7 +89,7 @@ grab_key_real (guint keycode, } } -/* Grab the key. In order to ignore GSD_IGNORED_MODS we need to grab +/* Grab the key. In order to ignore MSD_IGNORED_MODS we need to grab * all combinations of the ignored modifiers and those actually used * for the binding (if any). * @@ -124,7 +124,7 @@ grab_key_unsafe (Key *key, setup_modifiers (); - mask = gsd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; + mask = msd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; bit = 0; /* store the indexes of all set bits in mask in the array */ @@ -236,11 +236,11 @@ match_key (Key *key, XEvent *event) consumed &= ~GDK_SHIFT_MASK; return ((lower == key->keysym || upper == key->keysym) - && (event->xkey.state & ~consumed & gsd_used_mods) == key->state); + && (event->xkey.state & ~consumed & msd_used_mods) == key->state); } /* The key we passed doesn't have a keysym, so try with just the keycode */ return (key != NULL - && key->state == (event->xkey.state & gsd_used_mods) + && key->state == (event->xkey.state & msd_used_mods) && key_uses_keycode (key, event->xkey.keycode)); } diff --git a/plugins/common/gsd-keygrab.h b/plugins/common/gsd-keygrab.h index a157ab4..8ebef21 100644 --- a/plugins/common/gsd-keygrab.h +++ b/plugins/common/gsd-keygrab.h @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __GSD_COMMON_KEYGRAB_H -#define __GSD_COMMON_KEYGRAB_H +#ifndef __MSD_COMMON_KEYGRAB_H +#define __MSD_COMMON_KEYGRAB_H #ifdef __cplusplus extern "C" { @@ -48,4 +48,4 @@ gboolean key_uses_keycode (const Key *key, } #endif -#endif /* __GSD_COMMON_KEYGRAB_H */ +#endif /* __MSD_COMMON_KEYGRAB_H */ diff --git a/plugins/common/gsd-osd-window.c b/plugins/common/gsd-osd-window.c index 03ca316..123313c 100644 --- a/plugins/common/gsd-osd-window.c +++ b/plugins/common/gsd-osd-window.c @@ -36,7 +36,7 @@ #include #include -#include "gsd-osd-window.h" +#include "msd-osd-window.h" #define DIALOG_TIMEOUT 2000 /* dialog timeout in ms */ #define DIALOG_FADE_TIMEOUT 1500 /* timeout before fade starts */ @@ -44,9 +44,9 @@ #define BG_ALPHA 0.75 -#define GSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_OSD_WINDOW, GsdOsdWindowPrivate)) +#define MSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_OSD_WINDOW, MsdOsdWindowPrivate)) -struct GsdOsdWindowPrivate +struct MsdOsdWindowPrivate { guint is_composited : 1; guint hide_timeout_id; @@ -61,10 +61,10 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (GsdOsdWindow, gsd_osd_window, GTK_TYPE_WINDOW) +G_DEFINE_TYPE (MsdOsdWindow, msd_osd_window, GTK_TYPE_WINDOW) static gboolean -fade_timeout (GsdOsdWindow *window) +fade_timeout (MsdOsdWindow *window) { if (window->priv->fade_out_alpha <= 0.0) { gtk_widget_hide (GTK_WIDGET (window)); @@ -95,7 +95,7 @@ fade_timeout (GsdOsdWindow *window) } static gboolean -hide_timeout (GsdOsdWindow *window) +hide_timeout (MsdOsdWindow *window) { if (window->priv->is_composited) { window->priv->hide_timeout_id = 0; @@ -110,7 +110,7 @@ hide_timeout (GsdOsdWindow *window) } static void -remove_hide_timeout (GsdOsdWindow *window) +remove_hide_timeout (MsdOsdWindow *window) { if (window->priv->hide_timeout_id != 0) { g_source_remove (window->priv->hide_timeout_id); @@ -125,7 +125,7 @@ remove_hide_timeout (GsdOsdWindow *window) } static void -add_hide_timeout (GsdOsdWindow *window) +add_hide_timeout (MsdOsdWindow *window) { int timeout; @@ -140,7 +140,7 @@ add_hide_timeout (GsdOsdWindow *window) } void -gsd_osd_window_draw_rounded_rectangle (cairo_t* cr, +msd_osd_window_draw_rounded_rectangle (cairo_t* cr, gdouble aspect, gdouble x, gdouble y, @@ -192,7 +192,7 @@ gsd_osd_window_draw_rounded_rectangle (cairo_t* cr, } void -gsd_osd_window_color_reverse (const GdkColor *a, +msd_osd_window_color_reverse (const GdkColor *a, GdkColor *b) { gdouble red; @@ -228,7 +228,7 @@ gsd_osd_window_color_reverse (const GdkColor *a, static void expose_when_composited (GtkWidget *widget, GdkEventExpose *event) { - GsdOsdWindow *window; + MsdOsdWindow *window; cairo_t *context; cairo_t *cr; cairo_surface_t *surface; @@ -238,7 +238,7 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) GdkColor color; double r, g, b; - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); context = gdk_cairo_create (gtk_widget_get_window (widget)); @@ -264,15 +264,15 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) cairo_paint (cr); /* draw a box */ - gsd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); - gsd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); + msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); + msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); cairo_fill_preserve (cr); - gsd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); + msd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; @@ -308,10 +308,10 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) static void expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) { - GsdOsdWindow *window; + MsdOsdWindow *window; GtkAllocation allocation; - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); gtk_widget_get_allocation (widget, &allocation); @@ -321,7 +321,7 @@ expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) GTK_SHADOW_OUT, &event->area, widget, - NULL, /* NULL detail -> themes should use the GsdOsdWindow widget name, probably */ + NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ 0, 0, allocation.width, @@ -329,13 +329,13 @@ expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) } static gboolean -gsd_osd_window_expose_event (GtkWidget *widget, +msd_osd_window_expose_event (GtkWidget *widget, GdkEventExpose *event) { - GsdOsdWindow *window; + MsdOsdWindow *window; GtkWidget *child; - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); if (window->priv->is_composited) expose_when_composited (widget, event); @@ -350,34 +350,34 @@ gsd_osd_window_expose_event (GtkWidget *widget, } static void -gsd_osd_window_real_show (GtkWidget *widget) +msd_osd_window_real_show (GtkWidget *widget) { - GsdOsdWindow *window; + MsdOsdWindow *window; - if (GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->show) { - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->show (widget); + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show (widget); } - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); remove_hide_timeout (window); add_hide_timeout (window); } static void -gsd_osd_window_real_hide (GtkWidget *widget) +msd_osd_window_real_hide (GtkWidget *widget) { - GsdOsdWindow *window; + MsdOsdWindow *window; - if (GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->hide) { - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->hide (widget); + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide (widget); } - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); remove_hide_timeout (window); } static void -gsd_osd_window_real_realize (GtkWidget *widget) +msd_osd_window_real_realize (GtkWidget *widget) { GdkColormap *colormap; GtkAllocation allocation; @@ -390,8 +390,8 @@ gsd_osd_window_real_realize (GtkWidget *widget) gtk_widget_set_colormap (widget, colormap); } - if (GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->realize) { - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->realize (widget); + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); } gtk_widget_get_allocation (widget, &allocation); @@ -412,12 +412,12 @@ gsd_osd_window_real_realize (GtkWidget *widget) } static void -gsd_osd_window_style_set (GtkWidget *widget, +msd_osd_window_style_set (GtkWidget *widget, GtkStyle *previous_style) { GtkStyle *style; - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->style_set (widget, previous_style); + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->style_set (widget, previous_style); /* We set our border width to 12 (per the MATE standard), plus the * thickness of the frame that we draw in our expose handler. This will @@ -429,14 +429,14 @@ gsd_osd_window_style_set (GtkWidget *widget, } static void -gsd_osd_window_size_request (GtkWidget *widget, +msd_osd_window_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkStyle *style; - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->size_request (widget, requisition); + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->size_request (widget, requisition); - /* See the comment in gsd_osd_window_style_set() for why we add the thickness here */ + /* See the comment in msd_osd_window_style_set() for why we add the thickness here */ style = gtk_widget_get_style (widget); @@ -445,13 +445,13 @@ gsd_osd_window_size_request (GtkWidget *widget, } static GObject * -gsd_osd_window_constructor (GType type, +msd_osd_window_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { GObject *object; - object = G_OBJECT_CLASS (gsd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); + object = G_OBJECT_CLASS (msd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); g_object_set (object, "type", GTK_WINDOW_POPUP, @@ -465,64 +465,64 @@ gsd_osd_window_constructor (GType type, } static void -gsd_osd_window_class_init (GsdOsdWindowClass *klass) +msd_osd_window_class_init (MsdOsdWindowClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - gobject_class->constructor = gsd_osd_window_constructor; + gobject_class->constructor = msd_osd_window_constructor; - widget_class->show = gsd_osd_window_real_show; - widget_class->hide = gsd_osd_window_real_hide; - widget_class->realize = gsd_osd_window_real_realize; - widget_class->style_set = gsd_osd_window_style_set; - widget_class->size_request = gsd_osd_window_size_request; - widget_class->expose_event = gsd_osd_window_expose_event; + widget_class->show = msd_osd_window_real_show; + widget_class->hide = msd_osd_window_real_hide; + widget_class->realize = msd_osd_window_real_realize; + widget_class->style_set = msd_osd_window_style_set; + widget_class->size_request = msd_osd_window_size_request; + widget_class->expose_event = msd_osd_window_expose_event; signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("expose-when-composited", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GsdOsdWindowClass, expose_when_composited), + G_STRUCT_OFFSET (MsdOsdWindowClass, expose_when_composited), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - g_type_class_add_private (klass, sizeof (GsdOsdWindowPrivate)); + g_type_class_add_private (klass, sizeof (MsdOsdWindowPrivate)); } /** - * gsd_osd_window_is_composited: - * @window: a #GsdOsdWindow + * msd_osd_window_is_composited: + * @window: a #MsdOsdWindow * * Return value: whether the window was created on a composited screen. */ gboolean -gsd_osd_window_is_composited (GsdOsdWindow *window) +msd_osd_window_is_composited (MsdOsdWindow *window) { return window->priv->is_composited; } /** - * gsd_osd_window_is_valid: - * @window: a #GsdOsdWindow + * msd_osd_window_is_valid: + * @window: a #MsdOsdWindow * * Return value: TRUE if the @window's idea of being composited matches whether * its current screen is actually composited. */ gboolean -gsd_osd_window_is_valid (GsdOsdWindow *window) +msd_osd_window_is_valid (MsdOsdWindow *window) { GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window)); return gdk_screen_is_composited (screen) == window->priv->is_composited; } static void -gsd_osd_window_init (GsdOsdWindow *window) +msd_osd_window_init (MsdOsdWindow *window) { GdkScreen *screen; - window->priv = GSD_OSD_WINDOW_GET_PRIVATE (window); + window->priv = MSD_OSD_WINDOW_GET_PRIVATE (window); screen = gtk_widget_get_screen (GTK_WIDGET (window)); @@ -550,19 +550,19 @@ gsd_osd_window_init (GsdOsdWindow *window) } GtkWidget * -gsd_osd_window_new (void) +msd_osd_window_new (void) { - return g_object_new (GSD_TYPE_OSD_WINDOW, NULL); + return g_object_new (MSD_TYPE_OSD_WINDOW, NULL); } /** - * gsd_osd_window_update_and_hide: - * @window: a #GsdOsdWindow + * msd_osd_window_update_and_hide: + * @window: a #MsdOsdWindow * * Queues the @window for immediate drawing, and queues a timer to hide the window. */ void -gsd_osd_window_update_and_hide (GsdOsdWindow *window) +msd_osd_window_update_and_hide (MsdOsdWindow *window) { remove_hide_timeout (window); add_hide_timeout (window); diff --git a/plugins/common/gsd-osd-window.h b/plugins/common/gsd-osd-window.h index 0d8040b..f539e5e 100644 --- a/plugins/common/gsd-osd-window.h +++ b/plugins/common/gsd-osd-window.h @@ -27,18 +27,18 @@ * */ -/* GsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, +/* MsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, * semi-transparent, curved popup that appears when you press a hotkey global to * the desktop, such as to change the volume, switch your monitor's parameters, * etc. * - * You can create a GsdOsdWindow and use it as a normal GtkWindow. It will + * You can create a MsdOsdWindow and use it as a normal GtkWindow. It will * automatically center itself, figure out if it needs to be composited, etc. * Just pack your widgets in it, sit back, and enjoy the ride. */ -#ifndef GSD_OSD_WINDOW_H -#define GSD_OSD_WINDOW_H +#ifndef MSD_OSD_WINDOW_H +#define MSD_OSD_WINDOW_H #include #include @@ -48,39 +48,39 @@ extern "C" { #endif /* Alpha value to be used for foreground objects drawn in an OSD window */ -#define GSD_OSD_WINDOW_FG_ALPHA 1.0 +#define MSD_OSD_WINDOW_FG_ALPHA 1.0 -#define GSD_TYPE_OSD_WINDOW (gsd_osd_window_get_type ()) -#define GSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_OSD_WINDOW, GsdOsdWindow)) -#define GSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_OSD_WINDOW, GsdOsdWindowClass)) -#define GSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_OSD_WINDOW)) -#define GSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), GSD_TYPE_OSD_WINDOW)) -#define GSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_OSD_WINDOW, GsdOsdWindowClass)) +#define MSD_TYPE_OSD_WINDOW (msd_osd_window_get_type ()) +#define MSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindow)) +#define MSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) +#define MSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_OSD_WINDOW)) +#define MSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_OSD_WINDOW)) +#define MSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) -typedef struct GsdOsdWindow GsdOsdWindow; -typedef struct GsdOsdWindowClass GsdOsdWindowClass; -typedef struct GsdOsdWindowPrivate GsdOsdWindowPrivate; +typedef struct MsdOsdWindow MsdOsdWindow; +typedef struct MsdOsdWindowClass MsdOsdWindowClass; +typedef struct MsdOsdWindowPrivate MsdOsdWindowPrivate; -struct GsdOsdWindow { +struct MsdOsdWindow { GtkWindow parent; - GsdOsdWindowPrivate *priv; + MsdOsdWindowPrivate *priv; }; -struct GsdOsdWindowClass { +struct MsdOsdWindowClass { GtkWindowClass parent_class; - void (* expose_when_composited) (GsdOsdWindow *window, cairo_t *cr); + void (* expose_when_composited) (MsdOsdWindow *window, cairo_t *cr); }; -GType gsd_osd_window_get_type (void); +GType msd_osd_window_get_type (void); -GtkWidget * gsd_osd_window_new (void); -gboolean gsd_osd_window_is_composited (GsdOsdWindow *window); -gboolean gsd_osd_window_is_valid (GsdOsdWindow *window); -void gsd_osd_window_update_and_hide (GsdOsdWindow *window); +GtkWidget * msd_osd_window_new (void); +gboolean msd_osd_window_is_composited (MsdOsdWindow *window); +gboolean msd_osd_window_is_valid (MsdOsdWindow *window); +void msd_osd_window_update_and_hide (MsdOsdWindow *window); -void gsd_osd_window_draw_rounded_rectangle (cairo_t *cr, +void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, gdouble aspect, gdouble x, gdouble y, @@ -88,7 +88,7 @@ void gsd_osd_window_draw_rounded_rectangle (cairo_t *cr, gdouble width, gdouble height); -void gsd_osd_window_color_reverse (const GdkColor *a, +void msd_osd_window_color_reverse (const GdkColor *a, GdkColor *b); #ifdef __cplusplus diff --git a/plugins/datetime/Makefile.am b/plugins/datetime/Makefile.am index 1ae28f7..061443f 100644 --- a/plugins/datetime/Makefile.am +++ b/plugins/datetime/Makefile.am @@ -5,30 +5,30 @@ polkitdir = $(datadir)/polkit-1/actions dbus_services_in_files = org.mate.SettingsDaemon.DateTimeMechanism.service.in polkit_in_files = org.mate.settingsdaemon.datetimemechanism.policy.in -gsd-datetime-mechanism-glue.h: $(srcdir)/gsd-datetime-mechanism.xml +msd-datetime-mechanism-glue.h: $(srcdir)/msd-datetime-mechanism.xml $(AM_V_GEN)dbus-binding-tool \ - --prefix=gsd_datetime_mechanism --mode=glib-server \ - --output=gsd-datetime-mechanism-glue.h \ - $(srcdir)/gsd-datetime-mechanism.xml + --prefix=msd_datetime_mechanism --mode=glib-server \ + --output=msd-datetime-mechanism-glue.h \ + $(srcdir)/msd-datetime-mechanism.xml if HAVE_POLKIT -libexec_PROGRAMS = gsd-datetime-mechanism +libexec_PROGRAMS = msd-datetime-mechanism endif -gsd_datetime_mechanism_SOURCES = \ - gsd-datetime-mechanism.c \ - gsd-datetime-mechanism.h \ - gsd-datetime-mechanism-main.c \ +msd_datetime_mechanism_SOURCES = \ + msd-datetime-mechanism.c \ + msd-datetime-mechanism.h \ + msd-datetime-mechanism-main.c \ system-timezone.c \ system-timezone.h if HAVE_POLKIT -BUILT_SOURCES = gsd-datetime-mechanism-glue.h +BUILT_SOURCES = msd-datetime-mechanism-glue.h endif AM_CFLAGS = $(SETTINGS_PLUGIN_CFLAGS) $(POLKIT_CFLAGS) -gsd_datetime_mechanism_LDADD = $(POLKIT_LIBS) $(SETTINGS_PLUGIN_LIBS) +msd_datetime_mechanism_LDADD = $(POLKIT_LIBS) $(SETTINGS_PLUGIN_LIBS) if HAVE_POLKIT @@ -52,9 +52,9 @@ EXTRA_DIST = \ $(dbus_services_in_files) \ org.mate.SettingsDaemon.DateTimeMechanism.conf \ $(polkit_in_files) \ - gsd-datetime-mechanism.xml + msd-datetime-mechanism.xml CLEANFILES = \ org.mate.SettingsDaemon.DateTimeMechanism.service \ org.mate.settingsdaemon.datetimemechanism.policy \ - $(BUILT_SOURCES) \ No newline at end of file + $(BUILT_SOURCES) diff --git a/plugins/datetime/gsd-datetime-mechanism-main.c b/plugins/datetime/gsd-datetime-mechanism-main.c index 7d6089f..4d13630 100644 --- a/plugins/datetime/gsd-datetime-mechanism-main.c +++ b/plugins/datetime/gsd-datetime-mechanism-main.c @@ -39,7 +39,7 @@ #include -#include "gsd-datetime-mechanism.h" +#include "msd-datetime-mechanism.h" static DBusGProxy * get_bus_proxy (DBusGConnection *connection) @@ -123,7 +123,7 @@ int main (int argc, char **argv) { GMainLoop *loop; - GsdDatetimeMechanism *mechanism; + MsdDatetimeMechanism *mechanism; DBusGProxy *bus_proxy; DBusGConnection *connection; int ret; @@ -152,7 +152,7 @@ main (int argc, char **argv) goto out; } - mechanism = gsd_datetime_mechanism_new (); + mechanism = msd_datetime_mechanism_new (); if (mechanism == NULL) { goto out; diff --git a/plugins/datetime/gsd-datetime-mechanism.c b/plugins/datetime/gsd-datetime-mechanism.c index 5c18040..7b0d338 100644 --- a/plugins/datetime/gsd-datetime-mechanism.c +++ b/plugins/datetime/gsd-datetime-mechanism.c @@ -41,8 +41,8 @@ #include "system-timezone.h" -#include "gsd-datetime-mechanism.h" -#include "gsd-datetime-mechanism-glue.h" +#include "msd-datetime-mechanism.h" +#include "msd-datetime-mechanism-glue.h" static gboolean do_exit (gpointer user_data) @@ -64,26 +64,26 @@ reset_killtimer (void) timer_id = g_timeout_add_seconds (30, do_exit, NULL); } -struct GsdDatetimeMechanismPrivate +struct MsdDatetimeMechanismPrivate { DBusGConnection *system_bus_connection; DBusGProxy *system_bus_proxy; PolkitAuthority *auth; }; -static void gsd_datetime_mechanism_finalize (GObject *object); +static void msd_datetime_mechanism_finalize (GObject *object); -G_DEFINE_TYPE (GsdDatetimeMechanism, gsd_datetime_mechanism, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdDatetimeMechanism, msd_datetime_mechanism, G_TYPE_OBJECT) -#define GSD_DATETIME_MECHANISM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_DATETIME_TYPE_MECHANISM, GsdDatetimeMechanismPrivate)) +#define MSD_DATETIME_MECHANISM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismPrivate)) GQuark -gsd_datetime_mechanism_error_quark (void) +msd_datetime_mechanism_error_quark (void) { static GQuark ret = 0; if (ret == 0) { - ret = g_quark_from_static_string ("gsd_datetime_mechanism_error"); + ret = g_quark_from_static_string ("msd_datetime_mechanism_error"); } return ret; @@ -93,7 +93,7 @@ gsd_datetime_mechanism_error_quark (void) #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } GType -gsd_datetime_mechanism_error_get_type (void) +msd_datetime_mechanism_error_get_type (void) { static GType etype = 0; @@ -101,15 +101,15 @@ gsd_datetime_mechanism_error_get_type (void) { static const GEnumValue values[] = { - ENUM_ENTRY (GSD_DATETIME_MECHANISM_ERROR_GENERAL, "GeneralError"), - ENUM_ENTRY (GSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, "NotPrivileged"), - ENUM_ENTRY (GSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, "InvalidTimezoneFile"), + ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_GENERAL, "GeneralError"), + ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, "NotPrivileged"), + ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, "InvalidTimezoneFile"), { 0, 0, 0 } }; - g_assert (GSD_DATETIME_MECHANISM_NUM_ERRORS == G_N_ELEMENTS (values) - 1); + g_assert (MSD_DATETIME_MECHANISM_NUM_ERRORS == G_N_ELEMENTS (values) - 1); - etype = g_enum_register_static ("GsdDatetimeMechanismError", values); + etype = g_enum_register_static ("MsdDatetimeMechanismError", values); } return etype; @@ -117,13 +117,13 @@ gsd_datetime_mechanism_error_get_type (void) static GObject * -gsd_datetime_mechanism_constructor (GType type, +msd_datetime_mechanism_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdDatetimeMechanism *mechanism; + MsdDatetimeMechanism *mechanism; - mechanism = GSD_DATETIME_MECHANISM (G_OBJECT_CLASS (gsd_datetime_mechanism_parent_class)->constructor ( + mechanism = MSD_DATETIME_MECHANISM (G_OBJECT_CLASS (msd_datetime_mechanism_parent_class)->constructor ( type, n_construct_properties, construct_properties)); @@ -132,47 +132,47 @@ gsd_datetime_mechanism_constructor (GType type, } static void -gsd_datetime_mechanism_class_init (GsdDatetimeMechanismClass *klass) +msd_datetime_mechanism_class_init (MsdDatetimeMechanismClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->constructor = gsd_datetime_mechanism_constructor; - object_class->finalize = gsd_datetime_mechanism_finalize; + object_class->constructor = msd_datetime_mechanism_constructor; + object_class->finalize = msd_datetime_mechanism_finalize; - g_type_class_add_private (klass, sizeof (GsdDatetimeMechanismPrivate)); + g_type_class_add_private (klass, sizeof (MsdDatetimeMechanismPrivate)); - dbus_g_object_type_install_info (GSD_DATETIME_TYPE_MECHANISM, &dbus_glib_gsd_datetime_mechanism_object_info); + dbus_g_object_type_install_info (MSD_DATETIME_TYPE_MECHANISM, &dbus_glib_msd_datetime_mechanism_object_info); - dbus_g_error_domain_register (GSD_DATETIME_MECHANISM_ERROR, NULL, GSD_DATETIME_MECHANISM_TYPE_ERROR); + dbus_g_error_domain_register (MSD_DATETIME_MECHANISM_ERROR, NULL, MSD_DATETIME_MECHANISM_TYPE_ERROR); } static void -gsd_datetime_mechanism_init (GsdDatetimeMechanism *mechanism) +msd_datetime_mechanism_init (MsdDatetimeMechanism *mechanism) { - mechanism->priv = GSD_DATETIME_MECHANISM_GET_PRIVATE (mechanism); + mechanism->priv = MSD_DATETIME_MECHANISM_GET_PRIVATE (mechanism); } static void -gsd_datetime_mechanism_finalize (GObject *object) +msd_datetime_mechanism_finalize (GObject *object) { - GsdDatetimeMechanism *mechanism; + MsdDatetimeMechanism *mechanism; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_DATETIME_IS_MECHANISM (object)); + g_return_if_fail (MSD_DATETIME_IS_MECHANISM (object)); - mechanism = GSD_DATETIME_MECHANISM (object); + mechanism = MSD_DATETIME_MECHANISM (object); g_return_if_fail (mechanism->priv != NULL); g_object_unref (mechanism->priv->system_bus_proxy); - G_OBJECT_CLASS (gsd_datetime_mechanism_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_datetime_mechanism_parent_class)->finalize (object); } static gboolean -register_mechanism (GsdDatetimeMechanism *mechanism) +register_mechanism (MsdDatetimeMechanism *mechanism) { GError *error = NULL; @@ -205,25 +205,25 @@ error: } -GsdDatetimeMechanism * -gsd_datetime_mechanism_new (void) +MsdDatetimeMechanism * +msd_datetime_mechanism_new (void) { GObject *object; gboolean res; - object = g_object_new (GSD_DATETIME_TYPE_MECHANISM, NULL); + object = g_object_new (MSD_DATETIME_TYPE_MECHANISM, NULL); - res = register_mechanism (GSD_DATETIME_MECHANISM (object)); + res = register_mechanism (MSD_DATETIME_MECHANISM (object)); if (! res) { g_object_unref (object); return NULL; } - return GSD_DATETIME_MECHANISM (object); + return MSD_DATETIME_MECHANISM (object); } static gboolean -_check_polkit_for_action (GsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context, const char *action) +_check_polkit_for_action (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context, const char *action) { const char *sender; GError *error; @@ -252,8 +252,8 @@ _check_polkit_for_action (GsdDatetimeMechanism *mechanism, DBusGMethodInvocation } if (!polkit_authorization_result_get_is_authorized (result)) { - error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, "Not Authorized for action %s", action); dbus_g_method_return_error (context, error); g_error_free (error); @@ -269,7 +269,7 @@ _check_polkit_for_action (GsdDatetimeMechanism *mechanism, DBusGMethodInvocation static gboolean -_set_time (GsdDatetimeMechanism *mechanism, +_set_time (MsdDatetimeMechanism *mechanism, const struct timeval *tv, DBusGMethodInvocation *context) { @@ -279,8 +279,8 @@ _set_time (GsdDatetimeMechanism *mechanism, return FALSE; if (settimeofday (tv, NULL) != 0) { - error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error calling settimeofday({%lld,%lld}): %s", (gint64) tv->tv_sec, (gint64) tv->tv_usec, strerror (errno)); @@ -294,8 +294,8 @@ _set_time (GsdDatetimeMechanism *mechanism, int exit_status; if (!g_spawn_command_line_sync ("/sbin/hwclock --systohc", NULL, NULL, &exit_status, &error)) { GError *error2; - error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error spawning /sbin/hwclock: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); @@ -303,8 +303,8 @@ _set_time (GsdDatetimeMechanism *mechanism, return FALSE; } if (WEXITSTATUS (exit_status) != 0) { - error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "/sbin/hwclock returned %d", exit_status); dbus_g_method_return_error (context, error); g_error_free (error); @@ -332,8 +332,8 @@ _rh_update_etc_sysconfig_clock (DBusGMethodInvocation *context, const char *key, if (!g_file_get_contents ("/etc/sysconfig/clock", &data, &len, &error)) { GError *error2; - error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error reading /etc/sysconfig/clock file: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); @@ -364,8 +364,8 @@ _rh_update_etc_sysconfig_clock (DBusGMethodInvocation *context, const char *key, len = strlen (data); if (!g_file_set_contents ("/etc/sysconfig/clock", data, len, &error)) { GError *error2; - error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error updating /etc/sysconfig/clock: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); @@ -384,7 +384,7 @@ _rh_update_etc_sysconfig_clock (DBusGMethodInvocation *context, const char *key, /* exported methods */ gboolean -gsd_datetime_mechanism_set_time (GsdDatetimeMechanism *mechanism, +msd_datetime_mechanism_set_time (MsdDatetimeMechanism *mechanism, gint64 seconds_since_epoch, DBusGMethodInvocation *context) { @@ -399,7 +399,7 @@ gsd_datetime_mechanism_set_time (GsdDatetimeMechanism *mechanism, } gboolean -gsd_datetime_mechanism_adjust_time (GsdDatetimeMechanism *mechanism, +msd_datetime_mechanism_adjust_time (MsdDatetimeMechanism *mechanism, gint64 seconds_to_add, DBusGMethodInvocation *context) { @@ -410,8 +410,8 @@ gsd_datetime_mechanism_adjust_time (GsdDatetimeMechanism *mechanism, if (gettimeofday (&tv, NULL) != 0) { GError *error; - error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error calling gettimeofday(): %s", strerror (errno)); dbus_g_method_return_error (context, error); g_error_free (error); @@ -424,7 +424,7 @@ gsd_datetime_mechanism_adjust_time (GsdDatetimeMechanism *mechanism, gboolean -gsd_datetime_mechanism_set_timezone (GsdDatetimeMechanism *mechanism, +msd_datetime_mechanism_set_timezone (MsdDatetimeMechanism *mechanism, const char *zone_file, DBusGMethodInvocation *context) { @@ -443,11 +443,11 @@ gsd_datetime_mechanism_set_timezone (GsdDatetimeMechanism *mechanism, int code; if (error->code == SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE) - code = GSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE; + code = MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE; else - code = GSD_DATETIME_MECHANISM_ERROR_GENERAL; + code = MSD_DATETIME_MECHANISM_ERROR_GENERAL; - error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, code, "%s", error->message); g_error_free (error); @@ -464,7 +464,7 @@ gsd_datetime_mechanism_set_timezone (GsdDatetimeMechanism *mechanism, gboolean -gsd_datetime_mechanism_get_timezone (GsdDatetimeMechanism *mechism, +msd_datetime_mechanism_get_timezone (MsdDatetimeMechanism *mechism, DBusGMethodInvocation *context) { gchar *timezone; @@ -479,7 +479,7 @@ gsd_datetime_mechanism_get_timezone (GsdDatetimeMechanism *mechism, } gboolean -gsd_datetime_mechanism_get_hardware_clock_using_utc (GsdDatetimeMechanism *mechanism, +msd_datetime_mechanism_get_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context) { char **lines; @@ -492,8 +492,8 @@ gsd_datetime_mechanism_get_hardware_clock_using_utc (GsdDatetimeMechanism *mech if (!g_file_get_contents ("/etc/adjtime", &data, &len, &error)) { GError *error2; - error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error reading /etc/adjtime file: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); @@ -505,8 +505,8 @@ gsd_datetime_mechanism_get_hardware_clock_using_utc (GsdDatetimeMechanism *mech g_free (data); if (g_strv_length (lines) < 3) { - error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Cannot parse /etc/adjtime"); dbus_g_method_return_error (context, error); g_error_free (error); @@ -519,8 +519,8 @@ gsd_datetime_mechanism_get_hardware_clock_using_utc (GsdDatetimeMechanism *mech } else if (strcmp (lines[2], "LOCAL") == 0) { is_utc = FALSE; } else { - error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Expected UTC or LOCAL at line 3 of /etc/adjtime; found '%s'", lines[2]); dbus_g_method_return_error (context, error); g_error_free (error); @@ -533,7 +533,7 @@ gsd_datetime_mechanism_get_hardware_clock_using_utc (GsdDatetimeMechanism *mech } gboolean -gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDatetimeMechanism *mechanism, +msd_datetime_mechanism_set_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, gboolean using_utc, DBusGMethodInvocation *context) { @@ -552,8 +552,8 @@ gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDatetimeMechanism *mech cmd = g_strdup_printf ("/sbin/hwclock %s --systohc", using_utc ? "--utc" : "--localtime"); if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { GError *error2; - error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error spawning /sbin/hwclock: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); @@ -563,8 +563,8 @@ gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDatetimeMechanism *mech } g_free (cmd); if (WEXITSTATUS (exit_status) != 0) { - error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, - GSD_DATETIME_MECHANISM_ERROR_GENERAL, + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, "/sbin/hwclock returned %d", exit_status); dbus_g_method_return_error (context, error); g_error_free (error); @@ -580,7 +580,7 @@ gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDatetimeMechanism *mech } static void -check_can_do (GsdDatetimeMechanism *mechanism, +check_can_do (MsdDatetimeMechanism *mechanism, const char *action, DBusGMethodInvocation *context) { @@ -624,7 +624,7 @@ check_can_do (GsdDatetimeMechanism *mechanism, gboolean -gsd_datetime_mechanism_can_set_time (GsdDatetimeMechanism *mechanism, +msd_datetime_mechanism_can_set_time (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context) { check_can_do (mechanism, @@ -635,7 +635,7 @@ gsd_datetime_mechanism_can_set_time (GsdDatetimeMechanism *mechanism, } gboolean -gsd_datetime_mechanism_can_set_timezone (GsdDatetimeMechanism *mechanism, +msd_datetime_mechanism_can_set_timezone (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context) { check_can_do (mechanism, diff --git a/plugins/datetime/gsd-datetime-mechanism.h b/plugins/datetime/gsd-datetime-mechanism.h index 52b3b02..c8605b4 100644 --- a/plugins/datetime/gsd-datetime-mechanism.h +++ b/plugins/datetime/gsd-datetime-mechanism.h @@ -18,8 +18,8 @@ * */ -#ifndef GSD_DATETIME_MECHANISM_H -#define GSD_DATETIME_MECHANISM_H +#ifndef MSD_DATETIME_MECHANISM_H +#define MSD_DATETIME_MECHANISM_H #include #include @@ -28,69 +28,69 @@ extern "C" { #endif -#define GSD_DATETIME_TYPE_MECHANISM (gsd_datetime_mechanism_get_type ()) -#define GSD_DATETIME_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_DATETIME_TYPE_MECHANISM, GsdDatetimeMechanism)) -#define GSD_DATETIME_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_DATETIME_TYPE_MECHANISM, GsdDatetimeMechanismClass)) -#define GSD_DATETIME_IS_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_DATETIME_TYPE_MECHANISM)) -#define GSD_DATETIME_IS_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_DATETIME_TYPE_MECHANISM)) -#define GSD_DATETIME_MECHANISM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_DATETIME_TYPE_MECHANISM, GsdDatetimeMechanismClass)) +#define MSD_DATETIME_TYPE_MECHANISM (msd_datetime_mechanism_get_type ()) +#define MSD_DATETIME_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanism)) +#define MSD_DATETIME_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismClass)) +#define MSD_DATETIME_IS_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_DATETIME_TYPE_MECHANISM)) +#define MSD_DATETIME_IS_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_DATETIME_TYPE_MECHANISM)) +#define MSD_DATETIME_MECHANISM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismClass)) -typedef struct GsdDatetimeMechanismPrivate GsdDatetimeMechanismPrivate; +typedef struct MsdDatetimeMechanismPrivate MsdDatetimeMechanismPrivate; typedef struct { GObject parent; - GsdDatetimeMechanismPrivate *priv; -} GsdDatetimeMechanism; + MsdDatetimeMechanismPrivate *priv; +} MsdDatetimeMechanism; typedef struct { GObjectClass parent_class; -} GsdDatetimeMechanismClass; +} MsdDatetimeMechanismClass; typedef enum { - GSD_DATETIME_MECHANISM_ERROR_GENERAL, - GSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, - GSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, - GSD_DATETIME_MECHANISM_NUM_ERRORS -} GsdDatetimeMechanismError; + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, + MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, + MSD_DATETIME_MECHANISM_NUM_ERRORS +} MsdDatetimeMechanismError; -#define GSD_DATETIME_MECHANISM_ERROR gsd_datetime_mechanism_error_quark () +#define MSD_DATETIME_MECHANISM_ERROR msd_datetime_mechanism_error_quark () -GType gsd_datetime_mechanism_error_get_type (void); -#define GSD_DATETIME_MECHANISM_TYPE_ERROR (gsd_datetime_mechanism_error_get_type ()) +GType msd_datetime_mechanism_error_get_type (void); +#define MSD_DATETIME_MECHANISM_TYPE_ERROR (msd_datetime_mechanism_error_get_type ()) -GQuark gsd_datetime_mechanism_error_quark (void); -GType gsd_datetime_mechanism_get_type (void); -GsdDatetimeMechanism *gsd_datetime_mechanism_new (void); +GQuark msd_datetime_mechanism_error_quark (void); +GType msd_datetime_mechanism_get_type (void); +MsdDatetimeMechanism *msd_datetime_mechanism_new (void); /* exported methods */ -gboolean gsd_datetime_mechanism_get_timezone (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_get_timezone (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context); -gboolean gsd_datetime_mechanism_set_timezone (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_set_timezone (MsdDatetimeMechanism *mechanism, const char *zone_file, DBusGMethodInvocation *context); -gboolean gsd_datetime_mechanism_can_set_timezone (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_can_set_timezone (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context); -gboolean gsd_datetime_mechanism_set_time (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_set_time (MsdDatetimeMechanism *mechanism, gint64 seconds_since_epoch, DBusGMethodInvocation *context); -gboolean gsd_datetime_mechanism_can_set_time (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_can_set_time (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context); -gboolean gsd_datetime_mechanism_adjust_time (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_adjust_time (MsdDatetimeMechanism *mechanism, gint64 seconds_to_add, DBusGMethodInvocation *context); -gboolean gsd_datetime_mechanism_get_hardware_clock_using_utc (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_get_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context); -gboolean gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDatetimeMechanism *mechanism, +gboolean msd_datetime_mechanism_set_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, gboolean using_utc, DBusGMethodInvocation *context); @@ -98,4 +98,4 @@ gboolean gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDat } #endif -#endif /* GSD_DATETIME_MECHANISM_H */ +#endif /* MSD_DATETIME_MECHANISM_H */ diff --git a/plugins/datetime/org.mate.SettingsDaemon.DateTimeMechanism.service.in b/plugins/datetime/org.mate.SettingsDaemon.DateTimeMechanism.service.in index ac7fa29..ffc3bba 100644 --- a/plugins/datetime/org.mate.SettingsDaemon.DateTimeMechanism.service.in +++ b/plugins/datetime/org.mate.SettingsDaemon.DateTimeMechanism.service.in @@ -1,4 +1,4 @@ [D-BUS Service] Name=org.mate.SettingsDaemon.DateTimeMechanism -Exec=@LIBEXECDIR@/gsd-datetime-mechanism +Exec=@LIBEXECDIR@/msd-datetime-mechanism User=root diff --git a/plugins/dummy/Makefile.am b/plugins/dummy/Makefile.am index 0f77530..c578fd8 100644 --- a/plugins/dummy/Makefile.am +++ b/plugins/dummy/Makefile.am @@ -2,10 +2,10 @@ plugin_LTLIBRARIES = \ libdummy.la libdummy_la_SOURCES = \ - gsd-dummy-manager.c \ - gsd-dummy-manager.h \ - gsd-dummy-plugin.c \ - gsd-dummy-plugin.h + msd-dummy-manager.c \ + msd-dummy-manager.h \ + msd-dummy-plugin.c \ + msd-dummy-plugin.h libdummy_la_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ @@ -17,7 +17,7 @@ libdummy_la_CFLAGS = \ $(AM_CFLAGS) libdummy_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) + $(MSD_PLUGIN_LDFLAGS) libdummy_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) @@ -36,7 +36,7 @@ CLEANFILES = \ DISTCLEANFILES = \ $(plugin_DATA) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ # override to _not_ install the test plugin # do not copy into your plugin diff --git a/plugins/dummy/gsd-dummy-manager.c b/plugins/dummy/gsd-dummy-manager.c index 568c832..2744aeb 100644 --- a/plugins/dummy/gsd-dummy-manager.c +++ b/plugins/dummy/gsd-dummy-manager.c @@ -37,11 +37,11 @@ #include #include "mate-settings-profile.h" -#include "gsd-dummy-manager.h" +#include "msd-dummy-manager.h" -#define GSD_DUMMY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_DUMMY_MANAGER, GsdDummyManagerPrivate)) +#define MSD_DUMMY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerPrivate)) -struct GsdDummyManagerPrivate +struct MsdDummyManagerPrivate { gboolean padding; }; @@ -50,16 +50,16 @@ enum { PROP_0, }; -static void gsd_dummy_manager_class_init (GsdDummyManagerClass *klass); -static void gsd_dummy_manager_init (GsdDummyManager *dummy_manager); -static void gsd_dummy_manager_finalize (GObject *object); +static void msd_dummy_manager_class_init (MsdDummyManagerClass *klass); +static void msd_dummy_manager_init (MsdDummyManager *dummy_manager); +static void msd_dummy_manager_finalize (GObject *object); -G_DEFINE_TYPE (GsdDummyManager, gsd_dummy_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdDummyManager, msd_dummy_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; gboolean -gsd_dummy_manager_start (GsdDummyManager *manager, +msd_dummy_manager_start (MsdDummyManager *manager, GError **error) { g_debug ("Starting dummy manager"); @@ -69,20 +69,20 @@ gsd_dummy_manager_start (GsdDummyManager *manager, } void -gsd_dummy_manager_stop (GsdDummyManager *manager) +msd_dummy_manager_stop (MsdDummyManager *manager) { g_debug ("Stopping dummy manager"); } static void -gsd_dummy_manager_set_property (GObject *object, +msd_dummy_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdDummyManager *self; + MsdDummyManager *self; - self = GSD_DUMMY_MANAGER (object); + self = MSD_DUMMY_MANAGER (object); switch (prop_id) { default: @@ -92,14 +92,14 @@ gsd_dummy_manager_set_property (GObject *object, } static void -gsd_dummy_manager_get_property (GObject *object, +msd_dummy_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdDummyManager *self; + MsdDummyManager *self; - self = GSD_DUMMY_MANAGER (object); + self = MSD_DUMMY_MANAGER (object); switch (prop_id) { default: @@ -109,16 +109,16 @@ gsd_dummy_manager_get_property (GObject *object, } static GObject * -gsd_dummy_manager_constructor (GType type, +msd_dummy_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdDummyManager *dummy_manager; - GsdDummyManagerClass *klass; + MsdDummyManager *dummy_manager; + MsdDummyManagerClass *klass; - klass = GSD_DUMMY_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_DUMMY_MANAGER)); + klass = MSD_DUMMY_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_DUMMY_MANAGER)); - dummy_manager = GSD_DUMMY_MANAGER (G_OBJECT_CLASS (gsd_dummy_manager_parent_class)->constructor (type, + dummy_manager = MSD_DUMMY_MANAGER (G_OBJECT_CLASS (msd_dummy_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -126,61 +126,61 @@ gsd_dummy_manager_constructor (GType type, } static void -gsd_dummy_manager_dispose (GObject *object) +msd_dummy_manager_dispose (GObject *object) { - GsdDummyManager *dummy_manager; + MsdDummyManager *dummy_manager; - dummy_manager = GSD_DUMMY_MANAGER (object); + dummy_manager = MSD_DUMMY_MANAGER (object); - G_OBJECT_CLASS (gsd_dummy_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_dummy_manager_parent_class)->dispose (object); } static void -gsd_dummy_manager_class_init (GsdDummyManagerClass *klass) +msd_dummy_manager_class_init (MsdDummyManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_dummy_manager_get_property; - object_class->set_property = gsd_dummy_manager_set_property; - object_class->constructor = gsd_dummy_manager_constructor; - object_class->dispose = gsd_dummy_manager_dispose; - object_class->finalize = gsd_dummy_manager_finalize; + object_class->get_property = msd_dummy_manager_get_property; + object_class->set_property = msd_dummy_manager_set_property; + object_class->constructor = msd_dummy_manager_constructor; + object_class->dispose = msd_dummy_manager_dispose; + object_class->finalize = msd_dummy_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdDummyManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdDummyManagerPrivate)); } static void -gsd_dummy_manager_init (GsdDummyManager *manager) +msd_dummy_manager_init (MsdDummyManager *manager) { - manager->priv = GSD_DUMMY_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_DUMMY_MANAGER_GET_PRIVATE (manager); } static void -gsd_dummy_manager_finalize (GObject *object) +msd_dummy_manager_finalize (GObject *object) { - GsdDummyManager *dummy_manager; + MsdDummyManager *dummy_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_DUMMY_MANAGER (object)); + g_return_if_fail (MSD_IS_DUMMY_MANAGER (object)); - dummy_manager = GSD_DUMMY_MANAGER (object); + dummy_manager = MSD_DUMMY_MANAGER (object); g_return_if_fail (dummy_manager->priv != NULL); - G_OBJECT_CLASS (gsd_dummy_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_dummy_manager_parent_class)->finalize (object); } -GsdDummyManager * -gsd_dummy_manager_new (void) +MsdDummyManager * +msd_dummy_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_DUMMY_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_DUMMY_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_DUMMY_MANAGER (manager_object); + return MSD_DUMMY_MANAGER (manager_object); } diff --git a/plugins/dummy/gsd-dummy-manager.h b/plugins/dummy/gsd-dummy-manager.h index ba63560..91f989a 100644 --- a/plugins/dummy/gsd-dummy-manager.h +++ b/plugins/dummy/gsd-dummy-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_DUMMY_MANAGER_H -#define __GSD_DUMMY_MANAGER_H +#ifndef __MSD_DUMMY_MANAGER_H +#define __MSD_DUMMY_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_DUMMY_MANAGER (gsd_dummy_manager_get_type ()) -#define GSD_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_DUMMY_MANAGER, GsdDummyManager)) -#define GSD_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_DUMMY_MANAGER, GsdDummyManagerClass)) -#define GSD_IS_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_DUMMY_MANAGER)) -#define GSD_IS_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_DUMMY_MANAGER)) -#define GSD_DUMMY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_DUMMY_MANAGER, GsdDummyManagerClass)) +#define MSD_TYPE_DUMMY_MANAGER (msd_dummy_manager_get_type ()) +#define MSD_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManager)) +#define MSD_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerClass)) +#define MSD_IS_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_DUMMY_MANAGER)) +#define MSD_IS_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_DUMMY_MANAGER)) +#define MSD_DUMMY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerClass)) -typedef struct GsdDummyManagerPrivate GsdDummyManagerPrivate; +typedef struct MsdDummyManagerPrivate MsdDummyManagerPrivate; typedef struct { GObject parent; - GsdDummyManagerPrivate *priv; -} GsdDummyManager; + MsdDummyManagerPrivate *priv; +} MsdDummyManager; typedef struct { GObjectClass parent_class; -} GsdDummyManagerClass; +} MsdDummyManagerClass; -GType gsd_dummy_manager_get_type (void); +GType msd_dummy_manager_get_type (void); -GsdDummyManager * gsd_dummy_manager_new (void); -gboolean gsd_dummy_manager_start (GsdDummyManager *manager, +MsdDummyManager * msd_dummy_manager_new (void); +gboolean msd_dummy_manager_start (MsdDummyManager *manager, GError **error); -void gsd_dummy_manager_stop (GsdDummyManager *manager); +void msd_dummy_manager_stop (MsdDummyManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_DUMMY_MANAGER_H */ +#endif /* __MSD_DUMMY_MANAGER_H */ diff --git a/plugins/dummy/gsd-dummy-plugin.c b/plugins/dummy/gsd-dummy-plugin.c index f284423..c1e18bb 100644 --- a/plugins/dummy/gsd-dummy-plugin.c +++ b/plugins/dummy/gsd-dummy-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-dummy-plugin.h" -#include "gsd-dummy-manager.h" +#include "msd-dummy-plugin.h" +#include "msd-dummy-manager.h" -struct GsdDummyPluginPrivate { - GsdDummyManager *manager; +struct MsdDummyPluginPrivate { + MsdDummyManager *manager; }; -#define GSD_DUMMY_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_DUMMY_PLUGIN, GsdDummyPluginPrivate)) +#define MSD_DUMMY_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdDummyPlugin, gsd_dummy_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdDummyPlugin, msd_dummy_plugin) static void -gsd_dummy_plugin_init (GsdDummyPlugin *plugin) +msd_dummy_plugin_init (MsdDummyPlugin *plugin) { - plugin->priv = GSD_DUMMY_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_DUMMY_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdDummyPlugin initializing"); + g_debug ("MsdDummyPlugin initializing"); - plugin->priv->manager = gsd_dummy_manager_new (); + plugin->priv->manager = msd_dummy_manager_new (); } static void -gsd_dummy_plugin_finalize (GObject *object) +msd_dummy_plugin_finalize (GObject *object) { - GsdDummyPlugin *plugin; + MsdDummyPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_DUMMY_PLUGIN (object)); + g_return_if_fail (MSD_IS_DUMMY_PLUGIN (object)); - g_debug ("GsdDummyPlugin finalizing"); + g_debug ("MsdDummyPlugin finalizing"); - plugin = GSD_DUMMY_PLUGIN (object); + plugin = MSD_DUMMY_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_dummy_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_dummy_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_dummy_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating dummy plugin"); error = NULL; - res = gsd_dummy_manager_start (GSD_DUMMY_PLUGIN (plugin)->priv->manager, &error); + res = msd_dummy_manager_start (MSD_DUMMY_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start dummy manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating dummy plugin"); - gsd_dummy_manager_stop (GSD_DUMMY_PLUGIN (plugin)->priv->manager); + msd_dummy_manager_stop (MSD_DUMMY_PLUGIN (plugin)->priv->manager); } static void -gsd_dummy_plugin_class_init (GsdDummyPluginClass *klass) +msd_dummy_plugin_class_init (MsdDummyPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_dummy_plugin_finalize; + object_class->finalize = msd_dummy_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdDummyPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdDummyPluginPrivate)); } diff --git a/plugins/dummy/gsd-dummy-plugin.h b/plugins/dummy/gsd-dummy-plugin.h index 153e0fa..f07f78c 100644 --- a/plugins/dummy/gsd-dummy-plugin.h +++ b/plugins/dummy/gsd-dummy-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_DUMMY_PLUGIN_H__ -#define __GSD_DUMMY_PLUGIN_H__ +#ifndef __MSD_DUMMY_PLUGIN_H__ +#define __MSD_DUMMY_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_DUMMY_PLUGIN (gsd_dummy_plugin_get_type ()) -#define GSD_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_DUMMY_PLUGIN, GsdDummyPlugin)) -#define GSD_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_DUMMY_PLUGIN, GsdDummyPluginClass)) -#define GSD_IS_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_DUMMY_PLUGIN)) -#define GSD_IS_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_DUMMY_PLUGIN)) -#define GSD_DUMMY_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_DUMMY_PLUGIN, GsdDummyPluginClass)) +#define MSD_TYPE_DUMMY_PLUGIN (msd_dummy_plugin_get_type ()) +#define MSD_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPlugin)) +#define MSD_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginClass)) +#define MSD_IS_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_DUMMY_PLUGIN)) +#define MSD_IS_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_DUMMY_PLUGIN)) +#define MSD_DUMMY_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginClass)) -typedef struct GsdDummyPluginPrivate GsdDummyPluginPrivate; +typedef struct MsdDummyPluginPrivate MsdDummyPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdDummyPluginPrivate *priv; -} GsdDummyPlugin; + MsdDummyPluginPrivate *priv; +} MsdDummyPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdDummyPluginClass; +} MsdDummyPluginClass; -GType gsd_dummy_plugin_get_type (void) G_GNUC_CONST; +GType msd_dummy_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_DUMMY_PLUGIN_H__ */ +#endif /* __MSD_DUMMY_PLUGIN_H__ */ diff --git a/plugins/font/Makefile.am b/plugins/font/Makefile.am index 99dff34..d0cf9ce 100644 --- a/plugins/font/Makefile.am +++ b/plugins/font/Makefile.am @@ -5,10 +5,10 @@ plugin_LTLIBRARIES = \ $(NULL) libfont_la_SOURCES = \ - gsd-font-plugin.h \ - gsd-font-plugin.c \ - gsd-font-manager.h \ - gsd-font-manager.c \ + msd-font-plugin.h \ + msd-font-plugin.c \ + msd-font-manager.h \ + msd-font-manager.c \ delayed-dialog.h \ delayed-dialog.c \ $(NULL) @@ -23,7 +23,7 @@ libfont_la_CFLAGS = \ $(AM_CFLAGS) libfont_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libfont_la_LIBADD = \ @@ -48,4 +48,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/font/gsd-font-manager.c b/plugins/font/gsd-font-manager.c index 3db06ce..bcae037 100644 --- a/plugins/font/gsd-font-manager.c +++ b/plugins/font/gsd-font-manager.c @@ -44,13 +44,13 @@ #include #include "mate-settings-profile.h" -#include "gsd-font-manager.h" +#include "msd-font-manager.h" #include "delayed-dialog.h" -static void gsd_font_manager_class_init (GsdFontManagerClass *klass); -static void gsd_font_manager_init (GsdFontManager *font_manager); +static void msd_font_manager_class_init (MsdFontManagerClass *klass); +static void msd_font_manager_init (MsdFontManager *font_manager); -G_DEFINE_TYPE (GsdFontManager, gsd_font_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdFontManager, msd_font_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -338,7 +338,7 @@ done: } gboolean -gsd_font_manager_start (GsdFontManager *manager, +msd_font_manager_start (MsdFontManager *manager, GError **error) { MateConfClient *client; @@ -359,20 +359,20 @@ gsd_font_manager_start (GsdFontManager *manager, } void -gsd_font_manager_stop (GsdFontManager *manager) +msd_font_manager_stop (MsdFontManager *manager) { g_debug ("Stopping font manager"); } static void -gsd_font_manager_set_property (GObject *object, +msd_font_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdFontManager *self; + MsdFontManager *self; - self = GSD_FONT_MANAGER (object); + self = MSD_FONT_MANAGER (object); switch (prop_id) { default: @@ -382,14 +382,14 @@ gsd_font_manager_set_property (GObject *object, } static void -gsd_font_manager_get_property (GObject *object, +msd_font_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdFontManager *self; + MsdFontManager *self; - self = GSD_FONT_MANAGER (object); + self = MSD_FONT_MANAGER (object); switch (prop_id) { default: @@ -399,16 +399,16 @@ gsd_font_manager_get_property (GObject *object, } static GObject * -gsd_font_manager_constructor (GType type, +msd_font_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdFontManager *font_manager; - GsdFontManagerClass *klass; + MsdFontManager *font_manager; + MsdFontManagerClass *klass; - klass = GSD_FONT_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_FONT_MANAGER)); + klass = MSD_FONT_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_FONT_MANAGER)); - font_manager = GSD_FONT_MANAGER (G_OBJECT_CLASS (gsd_font_manager_parent_class)->constructor (type, + font_manager = MSD_FONT_MANAGER (G_OBJECT_CLASS (msd_font_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -416,30 +416,30 @@ gsd_font_manager_constructor (GType type, } static void -gsd_font_manager_class_init (GsdFontManagerClass *klass) +msd_font_manager_class_init (MsdFontManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_font_manager_get_property; - object_class->set_property = gsd_font_manager_set_property; - object_class->constructor = gsd_font_manager_constructor; + object_class->get_property = msd_font_manager_get_property; + object_class->set_property = msd_font_manager_set_property; + object_class->constructor = msd_font_manager_constructor; } static void -gsd_font_manager_init (GsdFontManager *manager) +msd_font_manager_init (MsdFontManager *manager) { } -GsdFontManager * -gsd_font_manager_new (void) +MsdFontManager * +msd_font_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_FONT_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_FONT_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_FONT_MANAGER (manager_object); + return MSD_FONT_MANAGER (manager_object); } diff --git a/plugins/font/gsd-font-manager.h b/plugins/font/gsd-font-manager.h index be53d98..3709d0f 100644 --- a/plugins/font/gsd-font-manager.h +++ b/plugins/font/gsd-font-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_FONT_MANAGER_H -#define __GSD_FONT_MANAGER_H +#ifndef __MSD_FONT_MANAGER_H +#define __MSD_FONT_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_FONT_MANAGER (gsd_font_manager_get_type ()) -#define GSD_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_FONT_MANAGER, GsdFontManager)) -#define GSD_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_FONT_MANAGER, GsdFontManagerClass)) -#define GSD_IS_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_FONT_MANAGER)) -#define GSD_IS_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_FONT_MANAGER)) -#define GSD_FONT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_FONT_MANAGER, GsdFontManagerClass)) +#define MSD_TYPE_FONT_MANAGER (msd_font_manager_get_type ()) +#define MSD_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_FONT_MANAGER, MsdFontManager)) +#define MSD_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_FONT_MANAGER, MsdFontManagerClass)) +#define MSD_IS_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_FONT_MANAGER)) +#define MSD_IS_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_FONT_MANAGER)) +#define MSD_FONT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_FONT_MANAGER, MsdFontManagerClass)) -typedef struct GsdFontManagerPrivate GsdFontManagerPrivate; +typedef struct MsdFontManagerPrivate MsdFontManagerPrivate; typedef struct { GObject parent; - GsdFontManagerPrivate *priv; -} GsdFontManager; + MsdFontManagerPrivate *priv; +} MsdFontManager; typedef struct { GObjectClass parent_class; -} GsdFontManagerClass; +} MsdFontManagerClass; -GType gsd_font_manager_get_type (void); +GType msd_font_manager_get_type (void); -GsdFontManager * gsd_font_manager_new (void); -gboolean gsd_font_manager_start (GsdFontManager *manager, +MsdFontManager * msd_font_manager_new (void); +gboolean msd_font_manager_start (MsdFontManager *manager, GError **error); -void gsd_font_manager_stop (GsdFontManager *manager); +void msd_font_manager_stop (MsdFontManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_FONT_MANAGER_H */ +#endif /* __MSD_FONT_MANAGER_H */ diff --git a/plugins/font/gsd-font-plugin.c b/plugins/font/gsd-font-plugin.c index dc34c6b..7711e19 100644 --- a/plugins/font/gsd-font-plugin.c +++ b/plugins/font/gsd-font-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-font-plugin.h" -#include "gsd-font-manager.h" +#include "msd-font-plugin.h" +#include "msd-font-manager.h" -struct GsdFontPluginPrivate { - GsdFontManager *manager; +struct MsdFontPluginPrivate { + MsdFontManager *manager; }; -#define GSD_FONT_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_FONT_PLUGIN, GsdFontPluginPrivate)) +#define MSD_FONT_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_FONT_PLUGIN, MsdFontPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdFontPlugin, gsd_font_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdFontPlugin, msd_font_plugin) static void -gsd_font_plugin_init (GsdFontPlugin *plugin) +msd_font_plugin_init (MsdFontPlugin *plugin) { - plugin->priv = GSD_FONT_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_FONT_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdFontPlugin initializing"); + g_debug ("MsdFontPlugin initializing"); - plugin->priv->manager = gsd_font_manager_new (); + plugin->priv->manager = msd_font_manager_new (); } static void -gsd_font_plugin_finalize (GObject *object) +msd_font_plugin_finalize (GObject *object) { - GsdFontPlugin *plugin; + MsdFontPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_FONT_PLUGIN (object)); + g_return_if_fail (MSD_IS_FONT_PLUGIN (object)); - g_debug ("GsdFontPlugin finalizing"); + g_debug ("MsdFontPlugin finalizing"); - plugin = GSD_FONT_PLUGIN (object); + plugin = MSD_FONT_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_font_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_font_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_font_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating font plugin"); error = NULL; - res = gsd_font_manager_start (GSD_FONT_PLUGIN (plugin)->priv->manager, &error); + res = msd_font_manager_start (MSD_FONT_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start font manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating font plugin"); - gsd_font_manager_stop (GSD_FONT_PLUGIN (plugin)->priv->manager); + msd_font_manager_stop (MSD_FONT_PLUGIN (plugin)->priv->manager); } static void -gsd_font_plugin_class_init (GsdFontPluginClass *klass) +msd_font_plugin_class_init (MsdFontPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_font_plugin_finalize; + object_class->finalize = msd_font_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdFontPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdFontPluginPrivate)); } diff --git a/plugins/font/gsd-font-plugin.h b/plugins/font/gsd-font-plugin.h index 06dd2be..9865412 100644 --- a/plugins/font/gsd-font-plugin.h +++ b/plugins/font/gsd-font-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_FONT_PLUGIN_H__ -#define __GSD_FONT_PLUGIN_H__ +#ifndef __MSD_FONT_PLUGIN_H__ +#define __MSD_FONT_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_FONT_PLUGIN (gsd_font_plugin_get_type ()) -#define GSD_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_FONT_PLUGIN, GsdFontPlugin)) -#define GSD_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_FONT_PLUGIN, GsdFontPluginClass)) -#define GSD_IS_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_FONT_PLUGIN)) -#define GSD_IS_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_FONT_PLUGIN)) -#define GSD_FONT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_FONT_PLUGIN, GsdFontPluginClass)) +#define MSD_TYPE_FONT_PLUGIN (msd_font_plugin_get_type ()) +#define MSD_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_FONT_PLUGIN, MsdFontPlugin)) +#define MSD_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_FONT_PLUGIN, MsdFontPluginClass)) +#define MSD_IS_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_FONT_PLUGIN)) +#define MSD_IS_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_FONT_PLUGIN)) +#define MSD_FONT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_FONT_PLUGIN, MsdFontPluginClass)) -typedef struct GsdFontPluginPrivate GsdFontPluginPrivate; +typedef struct MsdFontPluginPrivate MsdFontPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdFontPluginPrivate *priv; -} GsdFontPlugin; + MsdFontPluginPrivate *priv; +} MsdFontPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdFontPluginClass; +} MsdFontPluginClass; -GType gsd_font_plugin_get_type (void) G_GNUC_CONST; +GType msd_font_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_FONT_PLUGIN_H__ */ +#endif /* __MSD_FONT_PLUGIN_H__ */ diff --git a/plugins/housekeeping/Makefile.am b/plugins/housekeeping/Makefile.am index 485d4ed..4eb4517 100644 --- a/plugins/housekeeping/Makefile.am +++ b/plugins/housekeeping/Makefile.am @@ -1,16 +1,16 @@ plugin_LTLIBRARIES = libhousekeeping.la libhousekeeping_la_SOURCES = \ - gsd-ldsm-dialog.c \ - gsd-ldsm-dialog.h \ - gsd-ldsm-trash-empty.c \ - gsd-ldsm-trash-empty.h \ - gsd-disk-space.c \ - gsd-disk-space.h \ - gsd-housekeeping-manager.c \ - gsd-housekeeping-manager.h \ - gsd-housekeeping-plugin.c \ - gsd-housekeeping-plugin.h + msd-ldsm-dialog.c \ + msd-ldsm-dialog.h \ + msd-ldsm-trash-empty.c \ + msd-ldsm-trash-empty.h \ + msd-disk-space.c \ + msd-disk-space.h \ + msd-housekeeping-manager.c \ + msd-housekeeping-manager.h \ + msd-housekeeping-plugin.c \ + msd-housekeeping-plugin.h libhousekeeping_la_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ @@ -23,7 +23,7 @@ libhousekeeping_la_CFLAGS = \ $(LIBMATENOTIFY_CFLAGS) \ $(AM_CFLAGS) -libhousekeeping_la_LDFLAGS = $(GSD_PLUGIN_LDFLAGS) +libhousekeeping_la_LDFLAGS = $(MSD_PLUGIN_LDFLAGS) libhousekeeping_la_LIBADD = $(SETTINGS_PLUGIN_LIBS) $(GIOUNIX_LIBS) $(LIBMATENOTIFY_LIBS) @@ -37,4 +37,4 @@ CLEANFILES = $(plugin_DATA) DISTCLEANFILES = (plugin_DATA) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/housekeeping/gsd-disk-space.c b/plugins/housekeeping/gsd-disk-space.c index 97e2093..6842ae5 100644 --- a/plugins/housekeeping/gsd-disk-space.c +++ b/plugins/housekeeping/gsd-disk-space.c @@ -21,7 +21,7 @@ * */ -/* gcc -DHAVE_LIBMATENOTIFY -DTEST -Wall `pkg-config --cflags --libs gobject-2.0 gio-unix-2.0 glib-2.0 gtk+-2.0 libmatenotify` -o gsd-disk-space-test gsd-disk-space.c */ +/* gcc -DHAVE_LIBMATENOTIFY -DTEST -Wall `pkg-config --cflags --libs gobject-2.0 gio-unix-2.0 glib-2.0 gtk+-2.0 libmatenotify` -o msd-disk-space-test msd-disk-space.c */ #include "config.h" @@ -37,9 +37,9 @@ #include #include -#include "gsd-disk-space.h" -#include "gsd-ldsm-dialog.h" -#include "gsd-ldsm-trash-empty.h" +#include "msd-disk-space.h" +#include "msd-ldsm-dialog.h" +#include "msd-ldsm-trash-empty.h" #define GIGABYTE 1024 * 1024 * 1024 @@ -72,7 +72,7 @@ static unsigned int min_notify_period = 10; static GSList *ignore_paths = NULL; static unsigned int mateconf_notify_id; static MateConfClient *client = NULL; -static GsdLdsmDialog *dialog = NULL; +static MsdLdsmDialog *dialog = NULL; static guint64 *time_read; static gchar* @@ -196,7 +196,7 @@ ldsm_notify_for_mount (LdsmMountInfo *mount, has_disk_analyzer = (program != NULL); g_free (program); - dialog = gsd_ldsm_dialog_new (other_usable_volumes, + dialog = msd_ldsm_dialog_new (other_usable_volumes, multiple_volumes, has_disk_analyzer, has_trash, @@ -216,13 +216,13 @@ ldsm_notify_for_mount (LdsmMountInfo *mount, case GTK_RESPONSE_CANCEL: retval = FALSE; break; - case GSD_LDSM_DIALOG_RESPONSE_ANALYZE: + case MSD_LDSM_DIALOG_RESPONSE_ANALYZE: retval = FALSE; ldsm_analyze_path (g_unix_mount_get_mount_path (mount->mount)); break; - case GSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH: + case MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH: retval = TRUE; - gsd_ldsm_trash_empty (); + msd_ldsm_trash_empty (); break; case GTK_RESPONSE_NONE: case GTK_RESPONSE_DELETE_EVENT: @@ -566,7 +566,7 @@ ldsm_is_hash_item_in_ignore_paths (gpointer key, } static void -gsd_ldsm_get_config () +msd_ldsm_get_config () { GError *error = NULL; @@ -629,16 +629,16 @@ gsd_ldsm_get_config () } static void -gsd_ldsm_update_config (MateConfClient *client, +msd_ldsm_update_config (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, gpointer user_data) { - gsd_ldsm_get_config (); + msd_ldsm_get_config (); } void -gsd_ldsm_setup (gboolean check_now) +msd_ldsm_setup (gboolean check_now) { GError *error = NULL; @@ -653,10 +653,10 @@ gsd_ldsm_setup (gboolean check_now) client = mateconf_client_get_default (); if (client != NULL) { - gsd_ldsm_get_config (); + msd_ldsm_get_config (); mateconf_notify_id = mateconf_client_notify_add (client, MATECONF_HOUSEKEEPING_DIR, - (MateConfClientNotifyFunc) gsd_ldsm_update_config, + (MateConfClientNotifyFunc) msd_ldsm_update_config, NULL, NULL, &error); if (error != NULL) { g_warning ("Cannot register callback for MateConf notification"); @@ -680,7 +680,7 @@ gsd_ldsm_setup (gboolean check_now) } void -gsd_ldsm_clean (void) +msd_ldsm_clean (void) { if (ldsm_timeout_id) g_source_remove (ldsm_timeout_id); @@ -721,11 +721,11 @@ main (int argc, loop = g_main_loop_new (NULL, FALSE); - gsd_ldsm_setup (TRUE); + msd_ldsm_setup (TRUE); g_main_loop_run (loop); - gsd_ldsm_clean (); + msd_ldsm_clean (); g_main_loop_unref (loop); return 0; diff --git a/plugins/housekeeping/gsd-disk-space.h b/plugins/housekeeping/gsd-disk-space.h index 9a079a4..43f7059 100644 --- a/plugins/housekeeping/gsd-disk-space.h +++ b/plugins/housekeeping/gsd-disk-space.h @@ -21,8 +21,8 @@ * */ -#ifndef __GSD_DISK_SPACE_H -#define __GSD_DISK_SPACE_H +#ifndef __MSD_DISK_SPACE_H +#define __MSD_DISK_SPACE_H #include @@ -30,11 +30,11 @@ extern "C" { #endif -void gsd_ldsm_setup (gboolean check_now); -void gsd_ldsm_clean (void); +void msd_ldsm_setup (gboolean check_now); +void msd_ldsm_clean (void); #ifdef __cplusplus } #endif -#endif /* __GSD_DISK_SPACE_H */ +#endif /* __MSD_DISK_SPACE_H */ diff --git a/plugins/housekeeping/gsd-housekeeping-manager.c b/plugins/housekeeping/gsd-housekeeping-manager.c index bbdea2c..6cb3353 100644 --- a/plugins/housekeeping/gsd-housekeeping-manager.c +++ b/plugins/housekeeping/gsd-housekeeping-manager.c @@ -25,8 +25,8 @@ #include #include "mate-settings-profile.h" -#include "gsd-housekeeping-manager.h" -#include "gsd-disk-space.h" +#include "msd-housekeeping-manager.h" +#include "msd-disk-space.h" /* General */ @@ -42,19 +42,19 @@ #define MATECONF_THUMB_BINDING_DIR "/desktop/mate/thumbnail_cache" -struct GsdHousekeepingManagerPrivate { +struct MsdHousekeepingManagerPrivate { guint long_term_cb; guint short_term_cb; guint mateconf_notify; }; -#define GSD_HOUSEKEEPING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManagerPrivate)) +#define MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerPrivate)) -static void gsd_housekeeping_manager_class_init (GsdHousekeepingManagerClass *klass); -static void gsd_housekeeping_manager_init (GsdHousekeepingManager *housekeeping_manager); +static void msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass); +static void msd_housekeeping_manager_init (MsdHousekeepingManager *housekeeping_manager); -G_DEFINE_TYPE (GsdHousekeepingManager, gsd_housekeeping_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdHousekeepingManager, msd_housekeeping_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -241,7 +241,7 @@ purge_thumbnail_cache (void) static gboolean -do_cleanup (GsdHousekeepingManager *manager) +do_cleanup (MsdHousekeepingManager *manager) { purge_thumbnail_cache (); return TRUE; @@ -249,7 +249,7 @@ do_cleanup (GsdHousekeepingManager *manager) static gboolean -do_cleanup_once (GsdHousekeepingManager *manager) +do_cleanup_once (MsdHousekeepingManager *manager) { do_cleanup (manager); manager->priv->short_term_cb = 0; @@ -258,7 +258,7 @@ do_cleanup_once (GsdHousekeepingManager *manager) static void -do_cleanup_soon (GsdHousekeepingManager *manager) +do_cleanup_soon (MsdHousekeepingManager *manager) { if (manager->priv->short_term_cb == 0) { g_debug ("housekeeping: will tidy up in 2 minutes"); @@ -273,14 +273,14 @@ static void bindings_callback (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdHousekeepingManager *manager) + MsdHousekeepingManager *manager) { do_cleanup_soon (manager); } static guint -register_config_callback (GsdHousekeepingManager *manager, +register_config_callback (MsdHousekeepingManager *manager, const char *path, MateConfClientNotifyFunc func) { @@ -297,13 +297,13 @@ register_config_callback (GsdHousekeepingManager *manager, gboolean -gsd_housekeeping_manager_start (GsdHousekeepingManager *manager, +msd_housekeeping_manager_start (MsdHousekeepingManager *manager, GError **error) { g_debug ("Starting housekeeping manager"); mate_settings_profile_start (NULL); - gsd_ldsm_setup (FALSE); + msd_ldsm_setup (FALSE); manager->priv->mateconf_notify = register_config_callback (manager, MATECONF_THUMB_BINDING_DIR, @@ -323,9 +323,9 @@ gsd_housekeeping_manager_start (GsdHousekeepingManager *manager, void -gsd_housekeeping_manager_stop (GsdHousekeepingManager *manager) +msd_housekeeping_manager_stop (MsdHousekeepingManager *manager) { - GsdHousekeepingManagerPrivate *p = manager->priv; + MsdHousekeepingManagerPrivate *p = manager->priv; g_debug ("Stopping housekeeping manager"); @@ -356,34 +356,34 @@ gsd_housekeeping_manager_stop (GsdHousekeepingManager *manager) } } - gsd_ldsm_clean (); + msd_ldsm_clean (); } static void -gsd_housekeeping_manager_class_init (GsdHousekeepingManagerClass *klass) +msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass) { - g_type_class_add_private (klass, sizeof (GsdHousekeepingManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdHousekeepingManagerPrivate)); } static void -gsd_housekeeping_manager_init (GsdHousekeepingManager *manager) +msd_housekeeping_manager_init (MsdHousekeepingManager *manager) { - manager->priv = GSD_HOUSEKEEPING_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE (manager); } -GsdHousekeepingManager * -gsd_housekeeping_manager_new (void) +MsdHousekeepingManager * +msd_housekeeping_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_HOUSEKEEPING_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_HOUSEKEEPING_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_HOUSEKEEPING_MANAGER (manager_object); + return MSD_HOUSEKEEPING_MANAGER (manager_object); } diff --git a/plugins/housekeeping/gsd-housekeeping-manager.h b/plugins/housekeeping/gsd-housekeeping-manager.h index 3cba840..11f50a7 100644 --- a/plugins/housekeeping/gsd-housekeeping-manager.h +++ b/plugins/housekeeping/gsd-housekeeping-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_HOUSEKEEPING_MANAGER_H -#define __GSD_HOUSEKEEPING_MANAGER_H +#ifndef __MSD_HOUSEKEEPING_MANAGER_H +#define __MSD_HOUSEKEEPING_MANAGER_H #include @@ -27,33 +27,33 @@ extern "C" { #endif -#define GSD_TYPE_HOUSEKEEPING_MANAGER (gsd_housekeeping_manager_get_type ()) -#define GSD_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManager)) -#define GSD_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManagerClass)) -#define GSD_IS_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_HOUSEKEEPING_MANAGER)) -#define GSD_IS_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_HOUSEKEEPING_MANAGER)) -#define GSD_HOUSEKEEPING_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_HOUSEKEEPING_MANAGER, GsdHousekeepingManagerClass)) +#define MSD_TYPE_HOUSEKEEPING_MANAGER (msd_housekeeping_manager_get_type ()) +#define MSD_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManager)) +#define MSD_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerClass)) +#define MSD_IS_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_HOUSEKEEPING_MANAGER)) +#define MSD_IS_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_HOUSEKEEPING_MANAGER)) +#define MSD_HOUSEKEEPING_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerClass)) -typedef struct GsdHousekeepingManagerPrivate GsdHousekeepingManagerPrivate; +typedef struct MsdHousekeepingManagerPrivate MsdHousekeepingManagerPrivate; typedef struct { GObject parent; - GsdHousekeepingManagerPrivate *priv; -} GsdHousekeepingManager; + MsdHousekeepingManagerPrivate *priv; +} MsdHousekeepingManager; typedef struct { GObjectClass parent_class; -} GsdHousekeepingManagerClass; +} MsdHousekeepingManagerClass; -GType gsd_housekeeping_manager_get_type (void); +GType msd_housekeeping_manager_get_type (void); -GsdHousekeepingManager * gsd_housekeeping_manager_new (void); -gboolean gsd_housekeeping_manager_start (GsdHousekeepingManager *manager, +MsdHousekeepingManager * msd_housekeeping_manager_new (void); +gboolean msd_housekeeping_manager_start (MsdHousekeepingManager *manager, GError **error); -void gsd_housekeeping_manager_stop (GsdHousekeepingManager *manager); +void msd_housekeeping_manager_stop (MsdHousekeepingManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_HOUSEKEEPING_MANAGER_H */ +#endif /* __MSD_HOUSEKEEPING_MANAGER_H */ diff --git a/plugins/housekeeping/gsd-housekeeping-plugin.c b/plugins/housekeeping/gsd-housekeeping-plugin.c index 1bbddb0..5b0cfef 100644 --- a/plugins/housekeeping/gsd-housekeeping-plugin.c +++ b/plugins/housekeeping/gsd-housekeeping-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-housekeeping-plugin.h" -#include "gsd-housekeeping-manager.h" +#include "msd-housekeeping-plugin.h" +#include "msd-housekeeping-manager.h" -struct GsdHousekeepingPluginPrivate { - GsdHousekeepingManager *manager; +struct MsdHousekeepingPluginPrivate { + MsdHousekeepingManager *manager; }; -#define GSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_HOUSEKEEPING_PLUGIN, GsdHousekeepingPluginPrivate)) +#define MSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdHousekeepingPlugin, gsd_housekeeping_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdHousekeepingPlugin, msd_housekeeping_plugin) static void -gsd_housekeeping_plugin_init (GsdHousekeepingPlugin *plugin) +msd_housekeeping_plugin_init (MsdHousekeepingPlugin *plugin) { - plugin->priv = GSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdHousekeepingPlugin initializing"); + g_debug ("MsdHousekeepingPlugin initializing"); - plugin->priv->manager = gsd_housekeeping_manager_new (); + plugin->priv->manager = msd_housekeeping_manager_new (); } static void -gsd_housekeeping_plugin_finalize (GObject *object) +msd_housekeeping_plugin_finalize (GObject *object) { - GsdHousekeepingPlugin *plugin; + MsdHousekeepingPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_HOUSEKEEPING_PLUGIN (object)); + g_return_if_fail (MSD_IS_HOUSEKEEPING_PLUGIN (object)); - g_debug ("GsdHousekeepingPlugin finalizing"); + g_debug ("MsdHousekeepingPlugin finalizing"); - plugin = GSD_HOUSEKEEPING_PLUGIN (object); + plugin = MSD_HOUSEKEEPING_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_housekeeping_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_housekeeping_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_housekeeping_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating housekeeping plugin"); error = NULL; - res = gsd_housekeeping_manager_start (GSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager, &error); + res = msd_housekeeping_manager_start (MSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start housekeeping manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating housekeeping plugin"); - gsd_housekeeping_manager_stop (GSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager); + msd_housekeeping_manager_stop (MSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager); } static void -gsd_housekeeping_plugin_class_init (GsdHousekeepingPluginClass *klass) +msd_housekeeping_plugin_class_init (MsdHousekeepingPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_housekeeping_plugin_finalize; + object_class->finalize = msd_housekeeping_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdHousekeepingPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdHousekeepingPluginPrivate)); } diff --git a/plugins/housekeeping/gsd-housekeeping-plugin.h b/plugins/housekeeping/gsd-housekeeping-plugin.h index daca16b..1c2d816 100644 --- a/plugins/housekeeping/gsd-housekeeping-plugin.h +++ b/plugins/housekeeping/gsd-housekeeping-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_HOUSEKEEPING_PLUGIN_H__ -#define __GSD_HOUSEKEEPING_PLUGIN_H__ +#ifndef __MSD_HOUSEKEEPING_PLUGIN_H__ +#define __MSD_HOUSEKEEPING_PLUGIN_H__ #include #include @@ -31,25 +31,25 @@ extern "C" { #endif -#define GSD_TYPE_HOUSEKEEPING_PLUGIN (gsd_housekeeping_plugin_get_type ()) -#define GSD_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_HOUSEKEEPING_PLUGIN, GsdHousekeepingPlugin)) -#define GSD_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_HOUSEKEEPING_PLUGIN, GsdHousekeepingPluginClass)) -#define GSD_IS_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_HOUSEKEEPING_PLUGIN)) -#define GSD_IS_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_HOUSEKEEPING_PLUGIN)) -#define GSD_HOUSEKEEPING_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_HOUSEKEEPING_PLUGIN, GsdHousekeepingPluginClass)) +#define MSD_TYPE_HOUSEKEEPING_PLUGIN (msd_housekeeping_plugin_get_type ()) +#define MSD_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPlugin)) +#define MSD_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginClass)) +#define MSD_IS_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN)) +#define MSD_IS_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_HOUSEKEEPING_PLUGIN)) +#define MSD_HOUSEKEEPING_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginClass)) -typedef struct GsdHousekeepingPluginPrivate GsdHousekeepingPluginPrivate; +typedef struct MsdHousekeepingPluginPrivate MsdHousekeepingPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdHousekeepingPluginPrivate *priv; -} GsdHousekeepingPlugin; + MsdHousekeepingPluginPrivate *priv; +} MsdHousekeepingPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdHousekeepingPluginClass; +} MsdHousekeepingPluginClass; -GType gsd_housekeeping_plugin_get_type (void) G_GNUC_CONST; +GType msd_housekeeping_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -58,4 +58,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_HOUSEKEEPING_PLUGIN_H__ */ +#endif /* __MSD_HOUSEKEEPING_PLUGIN_H__ */ diff --git a/plugins/housekeeping/gsd-ldsm-dialog.c b/plugins/housekeeping/gsd-ldsm-dialog.c index 695db91..80ca857 100644 --- a/plugins/housekeeping/gsd-ldsm-dialog.c +++ b/plugins/housekeeping/gsd-ldsm-dialog.c @@ -1,14 +1,14 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * - * gsd-ldsm-dialog.c + * msd-ldsm-dialog.c * Copyright (C) Chris Coulson 2009 * - * gsd-ldsm-dialog.c is free software: you can redistribute it and/or modify it + * msd-ldsm-dialog.c is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * gsd-ldsm-dialog.c is distributed in the hope that it will be useful, but + * msd-ldsm-dialog.c 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 General Public License for more details. @@ -20,7 +20,7 @@ #include #include -#include "gsd-ldsm-dialog.h" +#include "msd-ldsm-dialog.h" #define MATECONF_CLIENT_IGNORE_PATHS "/apps/mate_settings_daemon/plugins/housekeeping/ignore_paths" @@ -35,7 +35,7 @@ enum PROP_MOUNT_PATH }; -struct GsdLdsmDialogPrivate +struct MsdLdsmDialogPrivate { GtkWidget *primary_label; GtkWidget *secondary_label; @@ -48,17 +48,17 @@ struct GsdLdsmDialogPrivate gchar *mount_path; }; -#define GSD_LDSM_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialogPrivate)) +#define MSD_LDSM_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogPrivate)) -static void gsd_ldsm_dialog_class_init (GsdLdsmDialogClass *klass); -static void gsd_ldsm_dialog_init (GsdLdsmDialog *dialog); +static void msd_ldsm_dialog_class_init (MsdLdsmDialogClass *klass); +static void msd_ldsm_dialog_init (MsdLdsmDialog *dialog); -G_DEFINE_TYPE (GsdLdsmDialog, gsd_ldsm_dialog, GTK_TYPE_DIALOG); +G_DEFINE_TYPE (MsdLdsmDialog, msd_ldsm_dialog, GTK_TYPE_DIALOG); static const gchar* -gsd_ldsm_dialog_get_checkbutton_text (GsdLdsmDialog *dialog) +msd_ldsm_dialog_get_checkbutton_text (MsdLdsmDialog *dialog) { - g_return_val_if_fail (GSD_IS_LDSM_DIALOG (dialog), NULL); + g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); if (dialog->priv->other_partitions) return _("Don't show any warnings again for this file system"); @@ -67,11 +67,11 @@ gsd_ldsm_dialog_get_checkbutton_text (GsdLdsmDialog *dialog) } static gchar* -gsd_ldsm_dialog_get_primary_text (GsdLdsmDialog *dialog) +msd_ldsm_dialog_get_primary_text (MsdLdsmDialog *dialog) { gchar *primary_text, *free_space; - g_return_val_if_fail (GSD_IS_LDSM_DIALOG (dialog), NULL); + g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); free_space = g_format_size_for_display (dialog->priv->space_remaining); @@ -89,9 +89,9 @@ gsd_ldsm_dialog_get_primary_text (GsdLdsmDialog *dialog) } static const gchar* -gsd_ldsm_dialog_get_secondary_text (GsdLdsmDialog *dialog) +msd_ldsm_dialog_get_secondary_text (MsdLdsmDialog *dialog) { - g_return_val_if_fail (GSD_IS_LDSM_DIALOG (dialog), NULL); + g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); if (dialog->priv->other_usable_partitions) { if (dialog->priv->has_trash) { @@ -148,7 +148,7 @@ static void ignore_check_button_toggled_cb (GtkToggleButton *button, gpointer user_data) { - GsdLdsmDialog *dialog = (GsdLdsmDialog *)user_data; + MsdLdsmDialog *dialog = (MsdLdsmDialog *)user_data; MateConfClient *client; GSList *ignore_paths; GError *error = NULL; @@ -191,12 +191,12 @@ ignore_check_button_toggled_cb (GtkToggleButton *button, } static void -gsd_ldsm_dialog_init (GsdLdsmDialog *dialog) +msd_ldsm_dialog_init (MsdLdsmDialog *dialog) { GtkWidget *main_vbox, *text_vbox, *hbox; GtkWidget *image; - dialog->priv = GSD_LDSM_DIALOG_GET_PRIVATE (dialog); + dialog->priv = MSD_LDSM_DIALOG_GET_PRIVATE (dialog); main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); @@ -261,14 +261,14 @@ gsd_ldsm_dialog_init (GsdLdsmDialog *dialog) } static void -gsd_ldsm_dialog_finalize (GObject *object) +msd_ldsm_dialog_finalize (GObject *object) { - GsdLdsmDialog *self; + MsdLdsmDialog *self; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_LDSM_DIALOG (object)); + g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); - self = GSD_LDSM_DIALOG (object); + self = MSD_LDSM_DIALOG (object); if (self->priv->partition_name) g_free (self->priv->partition_name); @@ -276,17 +276,17 @@ gsd_ldsm_dialog_finalize (GObject *object) if (self->priv->mount_path) g_free (self->priv->mount_path); - G_OBJECT_CLASS (gsd_ldsm_dialog_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_ldsm_dialog_parent_class)->finalize (object); } static void -gsd_ldsm_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +msd_ldsm_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdLdsmDialog *self; + MsdLdsmDialog *self; - g_return_if_fail (GSD_IS_LDSM_DIALOG (object)); + g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); - self = GSD_LDSM_DIALOG (object); + self = MSD_LDSM_DIALOG (object); switch (prop_id) { @@ -315,13 +315,13 @@ gsd_ldsm_dialog_set_property (GObject *object, guint prop_id, const GValue *valu } static void -gsd_ldsm_dialog_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +msd_ldsm_dialog_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdLdsmDialog *self; + MsdLdsmDialog *self; - g_return_if_fail (GSD_IS_LDSM_DIALOG (object)); + g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); - self = GSD_LDSM_DIALOG (object); + self = MSD_LDSM_DIALOG (object); switch (prop_id) { @@ -350,13 +350,13 @@ gsd_ldsm_dialog_get_property (GObject *object, guint prop_id, GValue *value, GPa } static void -gsd_ldsm_dialog_class_init (GsdLdsmDialogClass *klass) +msd_ldsm_dialog_class_init (MsdLdsmDialogClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); - object_class->finalize = gsd_ldsm_dialog_finalize; - object_class->set_property = gsd_ldsm_dialog_set_property; - object_class->get_property = gsd_ldsm_dialog_get_property; + object_class->finalize = msd_ldsm_dialog_finalize; + object_class->set_property = msd_ldsm_dialog_set_property; + object_class->get_property = msd_ldsm_dialog_get_property; g_object_class_install_property (object_class, PROP_OTHER_USABLE_PARTITIONS, @@ -406,11 +406,11 @@ gsd_ldsm_dialog_class_init (GsdLdsmDialogClass *klass) "Unknown", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - g_type_class_add_private (klass, sizeof (GsdLdsmDialogPrivate)); + g_type_class_add_private (klass, sizeof (MsdLdsmDialogPrivate)); } -GsdLdsmDialog* -gsd_ldsm_dialog_new (gboolean other_usable_partitions, +MsdLdsmDialog* +msd_ldsm_dialog_new (gboolean other_usable_partitions, gboolean other_partitions, gboolean display_baobab, gboolean display_empty_trash, @@ -418,13 +418,13 @@ gsd_ldsm_dialog_new (gboolean other_usable_partitions, const gchar *partition_name, const gchar *mount_path) { - GsdLdsmDialog *dialog; + MsdLdsmDialog *dialog; GtkWidget *button_empty_trash, *button_ignore, *button_analyze; GtkWidget *empty_trash_image, *analyze_image, *ignore_image; gchar *primary_text, *primary_text_markup; const gchar *secondary_text, *checkbutton_text; - dialog = GSD_LDSM_DIALOG (g_object_new (GSD_TYPE_LDSM_DIALOG, + dialog = MSD_LDSM_DIALOG (g_object_new (MSD_TYPE_LDSM_DIALOG, "other-usable-partitions", other_usable_partitions, "other-partitions", other_partitions, "has-trash", display_empty_trash, @@ -437,7 +437,7 @@ gsd_ldsm_dialog_new (gboolean other_usable_partitions, if (dialog->priv->has_trash) { button_empty_trash = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Empty Trash"), - GSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH); + MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH); empty_trash_image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button_empty_trash), empty_trash_image); } @@ -445,7 +445,7 @@ gsd_ldsm_dialog_new (gboolean other_usable_partitions, if (display_baobab) { button_analyze = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Examine…"), - GSD_LDSM_DIALOG_RESPONSE_ANALYZE); + MSD_LDSM_DIALOG_RESPONSE_ANALYZE); analyze_image = gtk_image_new_from_icon_name ("baobab", GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (button_analyze), analyze_image); } @@ -459,14 +459,14 @@ gsd_ldsm_dialog_new (gboolean other_usable_partitions, gtk_widget_grab_default (button_ignore); /* Set the label text */ - primary_text = gsd_ldsm_dialog_get_primary_text (dialog); + primary_text = msd_ldsm_dialog_get_primary_text (dialog); primary_text_markup = g_markup_printf_escaped ("%s", primary_text); gtk_label_set_markup (GTK_LABEL (dialog->priv->primary_label), primary_text_markup); - secondary_text = gsd_ldsm_dialog_get_secondary_text (dialog); + secondary_text = msd_ldsm_dialog_get_secondary_text (dialog); gtk_label_set_text (GTK_LABEL (dialog->priv->secondary_label), secondary_text); - checkbutton_text = gsd_ldsm_dialog_get_checkbutton_text (dialog); + checkbutton_text = msd_ldsm_dialog_get_checkbutton_text (dialog); gtk_button_set_label (GTK_BUTTON (dialog->priv->ignore_check_button), checkbutton_text); g_free (primary_text); diff --git a/plugins/housekeeping/gsd-ldsm-dialog.h b/plugins/housekeeping/gsd-ldsm-dialog.h index 81e2f1b..8b95fb9 100644 --- a/plugins/housekeeping/gsd-ldsm-dialog.h +++ b/plugins/housekeeping/gsd-ldsm-dialog.h @@ -1,14 +1,14 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * - * gsd-ldsm-dialog.c + * msd-ldsm-dialog.c * Copyright (C) Chris Coulson 2009 * - * gsd-ldsm-dialog.c is free software: you can redistribute it and/or modify it + * msd-ldsm-dialog.c is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * gsd-ldsm-dialog.c is distributed in the hope that it will be useful, but + * msd-ldsm-dialog.c 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 General Public License for more details. @@ -17,8 +17,8 @@ * with this program. If not, see . */ -#ifndef _GSD_LDSM_DIALOG_H_ -#define _GSD_LDSM_DIALOG_H_ +#ifndef _MSD_LDSM_DIALOG_H_ +#define _MSD_LDSM_DIALOG_H_ #include #include @@ -27,37 +27,37 @@ extern "C" { #endif -#define GSD_TYPE_LDSM_DIALOG (gsd_ldsm_dialog_get_type ()) -#define GSD_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialog)) -#define GSD_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialogClass)) -#define GSD_IS_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_LDSM_DIALOG)) -#define GSD_IS_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_LDSM_DIALOG)) -#define GSD_LDSM_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_LDSM_DIALOG, GsdLdsmDialogClass)) +#define MSD_TYPE_LDSM_DIALOG (msd_ldsm_dialog_get_type ()) +#define MSD_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialog)) +#define MSD_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogClass)) +#define MSD_IS_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_LDSM_DIALOG)) +#define MSD_IS_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_LDSM_DIALOG)) +#define MSD_LDSM_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogClass)) enum { - GSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH = -20, - GSD_LDSM_DIALOG_RESPONSE_ANALYZE = -21 + MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH = -20, + MSD_LDSM_DIALOG_RESPONSE_ANALYZE = -21 }; -typedef struct GsdLdsmDialogPrivate GsdLdsmDialogPrivate; -typedef struct _GsdLdsmDialogClass GsdLdsmDialogClass; -typedef struct _GsdLdsmDialog GsdLdsmDialog; +typedef struct MsdLdsmDialogPrivate MsdLdsmDialogPrivate; +typedef struct _MsdLdsmDialogClass MsdLdsmDialogClass; +typedef struct _MsdLdsmDialog MsdLdsmDialog; -struct _GsdLdsmDialogClass +struct _MsdLdsmDialogClass { GtkDialogClass parent_class; }; -struct _GsdLdsmDialog +struct _MsdLdsmDialog { GtkDialog parent_instance; - GsdLdsmDialogPrivate *priv; + MsdLdsmDialogPrivate *priv; }; -GType gsd_ldsm_dialog_get_type (void) G_GNUC_CONST; +GType msd_ldsm_dialog_get_type (void) G_GNUC_CONST; -GsdLdsmDialog * gsd_ldsm_dialog_new (gboolean other_usable_partitions, +MsdLdsmDialog * msd_ldsm_dialog_new (gboolean other_usable_partitions, gboolean other_partitions, gboolean display_baobab, gboolean display_empty_trash, @@ -69,4 +69,4 @@ GsdLdsmDialog * gsd_ldsm_dialog_new (gboolean other_usable_partitions, } #endif -#endif /* _GSD_LDSM_DIALOG_H_ */ +#endif /* _MSD_LDSM_DIALOG_H_ */ diff --git a/plugins/housekeeping/gsd-ldsm-trash-empty.c b/plugins/housekeeping/gsd-ldsm-trash-empty.c index d4ea183..05f82cd 100644 --- a/plugins/housekeeping/gsd-ldsm-trash-empty.c +++ b/plugins/housekeeping/gsd-ldsm-trash-empty.c @@ -1,15 +1,15 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * - * gsd-ldsm-trash-empty.c + * msd-ldsm-trash-empty.c * Copyright (C) Chris Coulson 2009 * (C) Ryan Lortie 2008 * - * gsd-ldsm-trash-empty.c is free software: you can redistribute it and/or modify it + * msd-ldsm-trash-empty.c is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * gsd-ldsm-trash-empty.c is distributed in the hope that it will be useful, but + * msd-ldsm-trash-empty.c 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 General Public License for more details. @@ -22,7 +22,7 @@ #include #include -#include "gsd-ldsm-trash-empty.h" +#include "msd-ldsm-trash-empty.h" #define CAJA_CONFIRM_TRASH_KEY "/apps/caja/preferences/confirm_trash" @@ -387,7 +387,7 @@ trash_empty_show_confirmation_dialog () } void -gsd_ldsm_trash_empty () +msd_ldsm_trash_empty () { if (trash_empty_confirm_dialog) gtk_window_present (GTK_WINDOW (trash_empty_confirm_dialog)); diff --git a/plugins/housekeeping/gsd-ldsm-trash-empty.h b/plugins/housekeeping/gsd-ldsm-trash-empty.h index 4d46a5b..85b09c0 100644 --- a/plugins/housekeeping/gsd-ldsm-trash-empty.h +++ b/plugins/housekeeping/gsd-ldsm-trash-empty.h @@ -1,14 +1,14 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * - * gsd-ldsm-trash-empty.h + * msd-ldsm-trash-empty.h * Copyright (C) Chris Coulson 2009 * - * gsd-ldsm-trash-empty.h is free software: you can redistribute it and/or modify it + * msd-ldsm-trash-empty.h is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * gsd-ldsm-trash-empty.h is distributed in the hope that it will be useful, but + * msd-ldsm-trash-empty.h 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 General Public License for more details. @@ -17,11 +17,11 @@ * with this program. If not, see . */ -#ifndef _gsd_ldsm_trash_empty_h_ -#define _gsd_ldsm_trash_empty_h_ +#ifndef _msd_ldsm_trash_empty_h_ +#define _msd_ldsm_trash_empty_h_ #include -void gsd_ldsm_trash_empty (); +void msd_ldsm_trash_empty (); -#endif /* _gsd_ldsm_trash_empty_h_ */ +#endif /* _msd_ldsm_trash_empty_h_ */ diff --git a/plugins/keybindings/Makefile.am b/plugins/keybindings/Makefile.am index c4fe7b2..d8e2b5f 100644 --- a/plugins/keybindings/Makefile.am +++ b/plugins/keybindings/Makefile.am @@ -5,10 +5,10 @@ plugin_LTLIBRARIES = \ $(NULL) libkeybindings_la_SOURCES = \ - gsd-keybindings-plugin.h \ - gsd-keybindings-plugin.c \ - gsd-keybindings-manager.h \ - gsd-keybindings-manager.c \ + msd-keybindings-plugin.h \ + msd-keybindings-plugin.c \ + msd-keybindings-manager.h \ + msd-keybindings-manager.c \ $(NULL) libkeybindings_la_CPPFLAGS = \ @@ -22,7 +22,7 @@ libkeybindings_la_CFLAGS = \ $(AM_CFLAGS) libkeybindings_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libkeybindings_la_LIBADD = \ @@ -48,4 +48,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/keybindings/gsd-keybindings-manager.c b/plugins/keybindings/gsd-keybindings-manager.c index 74014cc..c1f876c 100644 --- a/plugins/keybindings/gsd-keybindings-manager.c +++ b/plugins/keybindings/gsd-keybindings-manager.c @@ -39,15 +39,15 @@ #include #include "mate-settings-profile.h" -#include "gsd-keybindings-manager.h" +#include "msd-keybindings-manager.h" -#include "gsd-keygrab.h" +#include "msd-keygrab.h" #include "eggaccelerators.h" #define MATECONF_BINDING_DIR "/desktop/mate/keybindings" #define ALLOWED_KEYS_KEY MATECONF_BINDING_DIR "/allowed_keys" -#define GSD_KEYBINDINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_KEYBINDINGS_MANAGER, GsdKeybindingsManagerPrivate)) +#define MSD_KEYBINDINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerPrivate)) typedef struct { char *binding_str; @@ -57,7 +57,7 @@ typedef struct { Key previous_key; } Binding; -struct GsdKeybindingsManagerPrivate +struct MsdKeybindingsManagerPrivate { GSList *binding_list; GSList *allowed_keys; @@ -65,11 +65,11 @@ struct GsdKeybindingsManagerPrivate guint notify; }; -static void gsd_keybindings_manager_class_init (GsdKeybindingsManagerClass *klass); -static void gsd_keybindings_manager_init (GsdKeybindingsManager *keybindings_manager); -static void gsd_keybindings_manager_finalize (GObject *object); +static void msd_keybindings_manager_class_init (MsdKeybindingsManagerClass *klass); +static void msd_keybindings_manager_init (MsdKeybindingsManager *keybindings_manager); +static void msd_keybindings_manager_finalize (GObject *object); -G_DEFINE_TYPE (GsdKeybindingsManager, gsd_keybindings_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdKeybindingsManager, msd_keybindings_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -152,7 +152,7 @@ compare_bindings (gconstpointer a, } static gboolean -bindings_get_entry (GsdKeybindingsManager *manager, +bindings_get_entry (MsdKeybindingsManager *manager, MateConfClient *client, const char *subdir) { @@ -278,7 +278,7 @@ same_key (const Key *key, const Key *other) } static gboolean -key_already_used (GsdKeybindingsManager *manager, +key_already_used (MsdKeybindingsManager *manager, Binding *binding) { GSList *li; @@ -297,7 +297,7 @@ key_already_used (GsdKeybindingsManager *manager, } static void -binding_unregister_keys (GsdKeybindingsManager *manager) +binding_unregister_keys (MsdKeybindingsManager *manager) { GSList *li; gboolean need_flush = FALSE; @@ -319,7 +319,7 @@ binding_unregister_keys (GsdKeybindingsManager *manager) } static void -binding_register_keys (GsdKeybindingsManager *manager) +binding_register_keys (MsdKeybindingsManager *manager) { GSList *li; gboolean need_flush = FALSE; @@ -448,7 +448,7 @@ get_exec_environment (XEvent *xevent) static GdkFilterReturn keybindings_filter (GdkXEvent *gdk_xevent, GdkEvent *event, - GsdKeybindingsManager *manager) + MsdKeybindingsManager *manager) { XEvent *xevent = (XEvent *) gdk_xevent; GSList *li; @@ -510,7 +510,7 @@ static void bindings_callback (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdKeybindingsManager *manager) + MsdKeybindingsManager *manager) { char** key_elems; char* binding_entry; @@ -541,7 +541,7 @@ bindings_callback (MateConfClient *client, } static guint -register_config_callback (GsdKeybindingsManager *manager, +register_config_callback (MsdKeybindingsManager *manager, MateConfClient *client, const char *path, MateConfClientNotifyFunc func) @@ -551,7 +551,7 @@ register_config_callback (GsdKeybindingsManager *manager, } gboolean -gsd_keybindings_manager_start (GsdKeybindingsManager *manager, +msd_keybindings_manager_start (MsdKeybindingsManager *manager, GError **error) { MateConfClient *client; @@ -606,9 +606,9 @@ gsd_keybindings_manager_start (GsdKeybindingsManager *manager, } void -gsd_keybindings_manager_stop (GsdKeybindingsManager *manager) +msd_keybindings_manager_stop (MsdKeybindingsManager *manager) { - GsdKeybindingsManagerPrivate *p = manager->priv; + MsdKeybindingsManagerPrivate *p = manager->priv; GSList *l; g_debug ("Stopping keybindings manager"); @@ -647,14 +647,14 @@ gsd_keybindings_manager_stop (GsdKeybindingsManager *manager) } static void -gsd_keybindings_manager_set_property (GObject *object, +msd_keybindings_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdKeybindingsManager *self; + MsdKeybindingsManager *self; - self = GSD_KEYBINDINGS_MANAGER (object); + self = MSD_KEYBINDINGS_MANAGER (object); switch (prop_id) { default: @@ -664,14 +664,14 @@ gsd_keybindings_manager_set_property (GObject *object, } static void -gsd_keybindings_manager_get_property (GObject *object, +msd_keybindings_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdKeybindingsManager *self; + MsdKeybindingsManager *self; - self = GSD_KEYBINDINGS_MANAGER (object); + self = MSD_KEYBINDINGS_MANAGER (object); switch (prop_id) { default: @@ -681,16 +681,16 @@ gsd_keybindings_manager_get_property (GObject *object, } static GObject * -gsd_keybindings_manager_constructor (GType type, +msd_keybindings_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdKeybindingsManager *keybindings_manager; - GsdKeybindingsManagerClass *klass; + MsdKeybindingsManager *keybindings_manager; + MsdKeybindingsManagerClass *klass; - klass = GSD_KEYBINDINGS_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_KEYBINDINGS_MANAGER)); + klass = MSD_KEYBINDINGS_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_KEYBINDINGS_MANAGER)); - keybindings_manager = GSD_KEYBINDINGS_MANAGER (G_OBJECT_CLASS (gsd_keybindings_manager_parent_class)->constructor (type, + keybindings_manager = MSD_KEYBINDINGS_MANAGER (G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -698,61 +698,61 @@ gsd_keybindings_manager_constructor (GType type, } static void -gsd_keybindings_manager_dispose (GObject *object) +msd_keybindings_manager_dispose (GObject *object) { - GsdKeybindingsManager *keybindings_manager; + MsdKeybindingsManager *keybindings_manager; - keybindings_manager = GSD_KEYBINDINGS_MANAGER (object); + keybindings_manager = MSD_KEYBINDINGS_MANAGER (object); - G_OBJECT_CLASS (gsd_keybindings_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->dispose (object); } static void -gsd_keybindings_manager_class_init (GsdKeybindingsManagerClass *klass) +msd_keybindings_manager_class_init (MsdKeybindingsManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_keybindings_manager_get_property; - object_class->set_property = gsd_keybindings_manager_set_property; - object_class->constructor = gsd_keybindings_manager_constructor; - object_class->dispose = gsd_keybindings_manager_dispose; - object_class->finalize = gsd_keybindings_manager_finalize; + object_class->get_property = msd_keybindings_manager_get_property; + object_class->set_property = msd_keybindings_manager_set_property; + object_class->constructor = msd_keybindings_manager_constructor; + object_class->dispose = msd_keybindings_manager_dispose; + object_class->finalize = msd_keybindings_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdKeybindingsManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdKeybindingsManagerPrivate)); } static void -gsd_keybindings_manager_init (GsdKeybindingsManager *manager) +msd_keybindings_manager_init (MsdKeybindingsManager *manager) { - manager->priv = GSD_KEYBINDINGS_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_KEYBINDINGS_MANAGER_GET_PRIVATE (manager); } static void -gsd_keybindings_manager_finalize (GObject *object) +msd_keybindings_manager_finalize (GObject *object) { - GsdKeybindingsManager *keybindings_manager; + MsdKeybindingsManager *keybindings_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_KEYBINDINGS_MANAGER (object)); + g_return_if_fail (MSD_IS_KEYBINDINGS_MANAGER (object)); - keybindings_manager = GSD_KEYBINDINGS_MANAGER (object); + keybindings_manager = MSD_KEYBINDINGS_MANAGER (object); g_return_if_fail (keybindings_manager->priv != NULL); - G_OBJECT_CLASS (gsd_keybindings_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->finalize (object); } -GsdKeybindingsManager * -gsd_keybindings_manager_new (void) +MsdKeybindingsManager * +msd_keybindings_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_KEYBINDINGS_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_KEYBINDINGS_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_KEYBINDINGS_MANAGER (manager_object); + return MSD_KEYBINDINGS_MANAGER (manager_object); } diff --git a/plugins/keybindings/gsd-keybindings-manager.h b/plugins/keybindings/gsd-keybindings-manager.h index 7de64d9..95b1bed 100644 --- a/plugins/keybindings/gsd-keybindings-manager.h +++ b/plugins/keybindings/gsd-keybindings-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_KEYBINDINGS_MANAGER_H -#define __GSD_KEYBINDINGS_MANAGER_H +#ifndef __MSD_KEYBINDINGS_MANAGER_H +#define __MSD_KEYBINDINGS_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_KEYBINDINGS_MANAGER (gsd_keybindings_manager_get_type ()) -#define GSD_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_KEYBINDINGS_MANAGER, GsdKeybindingsManager)) -#define GSD_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_KEYBINDINGS_MANAGER, GsdKeybindingsManagerClass)) -#define GSD_IS_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_KEYBINDINGS_MANAGER)) -#define GSD_IS_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_KEYBINDINGS_MANAGER)) -#define GSD_KEYBINDINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_KEYBINDINGS_MANAGER, GsdKeybindingsManagerClass)) +#define MSD_TYPE_KEYBINDINGS_MANAGER (msd_keybindings_manager_get_type ()) +#define MSD_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManager)) +#define MSD_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerClass)) +#define MSD_IS_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBINDINGS_MANAGER)) +#define MSD_IS_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBINDINGS_MANAGER)) +#define MSD_KEYBINDINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerClass)) -typedef struct GsdKeybindingsManagerPrivate GsdKeybindingsManagerPrivate; +typedef struct MsdKeybindingsManagerPrivate MsdKeybindingsManagerPrivate; typedef struct { GObject parent; - GsdKeybindingsManagerPrivate *priv; -} GsdKeybindingsManager; + MsdKeybindingsManagerPrivate *priv; +} MsdKeybindingsManager; typedef struct { GObjectClass parent_class; -} GsdKeybindingsManagerClass; +} MsdKeybindingsManagerClass; -GType gsd_keybindings_manager_get_type (void); +GType msd_keybindings_manager_get_type (void); -GsdKeybindingsManager * gsd_keybindings_manager_new (void); -gboolean gsd_keybindings_manager_start (GsdKeybindingsManager *manager, +MsdKeybindingsManager * msd_keybindings_manager_new (void); +gboolean msd_keybindings_manager_start (MsdKeybindingsManager *manager, GError **error); -void gsd_keybindings_manager_stop (GsdKeybindingsManager *manager); +void msd_keybindings_manager_stop (MsdKeybindingsManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_KEYBINDINGS_MANAGER_H */ +#endif /* __MSD_KEYBINDINGS_MANAGER_H */ diff --git a/plugins/keybindings/gsd-keybindings-plugin.c b/plugins/keybindings/gsd-keybindings-plugin.c index a96f420..5b0cebb 100644 --- a/plugins/keybindings/gsd-keybindings-plugin.c +++ b/plugins/keybindings/gsd-keybindings-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-keybindings-plugin.h" -#include "gsd-keybindings-manager.h" +#include "msd-keybindings-plugin.h" +#include "msd-keybindings-manager.h" -struct GsdKeybindingsPluginPrivate { - GsdKeybindingsManager *manager; +struct MsdKeybindingsPluginPrivate { + MsdKeybindingsManager *manager; }; -#define GSD_KEYBINDINGS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_KEYBINDINGS_PLUGIN, GsdKeybindingsPluginPrivate)) +#define MSD_KEYBINDINGS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdKeybindingsPlugin, gsd_keybindings_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdKeybindingsPlugin, msd_keybindings_plugin) static void -gsd_keybindings_plugin_init (GsdKeybindingsPlugin *plugin) +msd_keybindings_plugin_init (MsdKeybindingsPlugin *plugin) { - plugin->priv = GSD_KEYBINDINGS_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_KEYBINDINGS_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdKeybindingsPlugin initializing"); + g_debug ("MsdKeybindingsPlugin initializing"); - plugin->priv->manager = gsd_keybindings_manager_new (); + plugin->priv->manager = msd_keybindings_manager_new (); } static void -gsd_keybindings_plugin_finalize (GObject *object) +msd_keybindings_plugin_finalize (GObject *object) { - GsdKeybindingsPlugin *plugin; + MsdKeybindingsPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_KEYBINDINGS_PLUGIN (object)); + g_return_if_fail (MSD_IS_KEYBINDINGS_PLUGIN (object)); - g_debug ("GsdKeybindingsPlugin finalizing"); + g_debug ("MsdKeybindingsPlugin finalizing"); - plugin = GSD_KEYBINDINGS_PLUGIN (object); + plugin = MSD_KEYBINDINGS_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_keybindings_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_keybindings_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_keybindings_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating keybindings plugin"); error = NULL; - res = gsd_keybindings_manager_start (GSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager, &error); + res = msd_keybindings_manager_start (MSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start keybindings manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating keybindings plugin"); - gsd_keybindings_manager_stop (GSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager); + msd_keybindings_manager_stop (MSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager); } static void -gsd_keybindings_plugin_class_init (GsdKeybindingsPluginClass *klass) +msd_keybindings_plugin_class_init (MsdKeybindingsPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_keybindings_plugin_finalize; + object_class->finalize = msd_keybindings_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdKeybindingsPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdKeybindingsPluginPrivate)); } diff --git a/plugins/keybindings/gsd-keybindings-plugin.h b/plugins/keybindings/gsd-keybindings-plugin.h index dea237d..f45d0f8 100644 --- a/plugins/keybindings/gsd-keybindings-plugin.h +++ b/plugins/keybindings/gsd-keybindings-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_KEYBINDINGS_PLUGIN_H__ -#define __GSD_KEYBINDINGS_PLUGIN_H__ +#ifndef __MSD_KEYBINDINGS_PLUGIN_H__ +#define __MSD_KEYBINDINGS_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_KEYBINDINGS_PLUGIN (gsd_keybindings_plugin_get_type ()) -#define GSD_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_KEYBINDINGS_PLUGIN, GsdKeybindingsPlugin)) -#define GSD_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_KEYBINDINGS_PLUGIN, GsdKeybindingsPluginClass)) -#define GSD_IS_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_KEYBINDINGS_PLUGIN)) -#define GSD_IS_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_KEYBINDINGS_PLUGIN)) -#define GSD_KEYBINDINGS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_KEYBINDINGS_PLUGIN, GsdKeybindingsPluginClass)) +#define MSD_TYPE_KEYBINDINGS_PLUGIN (msd_keybindings_plugin_get_type ()) +#define MSD_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPlugin)) +#define MSD_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginClass)) +#define MSD_IS_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBINDINGS_PLUGIN)) +#define MSD_IS_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBINDINGS_PLUGIN)) +#define MSD_KEYBINDINGS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginClass)) -typedef struct GsdKeybindingsPluginPrivate GsdKeybindingsPluginPrivate; +typedef struct MsdKeybindingsPluginPrivate MsdKeybindingsPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdKeybindingsPluginPrivate *priv; -} GsdKeybindingsPlugin; + MsdKeybindingsPluginPrivate *priv; +} MsdKeybindingsPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdKeybindingsPluginClass; +} MsdKeybindingsPluginClass; -GType gsd_keybindings_plugin_get_type (void) G_GNUC_CONST; +GType msd_keybindings_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_KEYBINDINGS_PLUGIN_H__ */ +#endif /* __MSD_KEYBINDINGS_PLUGIN_H__ */ diff --git a/plugins/keyboard/Makefile.am b/plugins/keyboard/Makefile.am index fdad2a8..327ad7e 100644 --- a/plugins/keyboard/Makefile.am +++ b/plugins/keyboard/Makefile.am @@ -17,14 +17,14 @@ uidir = $(pkgdatadir) ui_DATA = modmap-dialog.ui libkeyboard_la_SOURCES = \ - gsd-keyboard-plugin.h \ - gsd-keyboard-plugin.c \ - gsd-keyboard-manager.h \ - gsd-keyboard-manager.c \ - gsd-keyboard-xkb.h \ - gsd-keyboard-xkb.c \ - gsd-xmodmap.h \ - gsd-xmodmap.c \ + msd-keyboard-plugin.h \ + msd-keyboard-plugin.c \ + msd-keyboard-manager.h \ + msd-keyboard-manager.c \ + msd-keyboard-xkb.h \ + msd-keyboard-xkb.c \ + msd-xmodmap.h \ + msd-xmodmap.c \ delayed-dialog.h \ delayed-dialog.c \ $(NULL) @@ -41,7 +41,7 @@ libkeyboard_la_CFLAGS = \ $(AM_CFLAGS) libkeyboard_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libkeyboard_la_LIBADD = \ @@ -70,4 +70,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/keyboard/delayed-dialog.c b/plugins/keyboard/delayed-dialog.c index 1aa13e1..acbb99a 100644 --- a/plugins/keyboard/delayed-dialog.c +++ b/plugins/keyboard/delayed-dialog.c @@ -33,7 +33,7 @@ static GdkFilterReturn message_filter (GdkXEvent *xevent, static GSList *dialogs = NULL; /** - * gsd_delayed_show_dialog: + * msd_delayed_show_dialog: * @dialog: the dialog * * Shows the dialog as with gtk_widget_show(), unless a window manager @@ -41,7 +41,7 @@ static GSList *dialogs = NULL; * for that to happen before showing the dialog. **/ void -gsd_delayed_show_dialog (GtkWidget *dialog) +msd_delayed_show_dialog (GtkWidget *dialog) { GdkDisplay *display = gtk_widget_get_display (dialog); Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); diff --git a/plugins/keyboard/delayed-dialog.h b/plugins/keyboard/delayed-dialog.h index 353dbe6..a28bf90 100644 --- a/plugins/keyboard/delayed-dialog.h +++ b/plugins/keyboard/delayed-dialog.h @@ -27,7 +27,7 @@ extern "C" { #endif -void gsd_delayed_show_dialog (GtkWidget *dialog); +void msd_delayed_show_dialog (GtkWidget *dialog); #ifdef __cplusplus } diff --git a/plugins/keyboard/gsd-keyboard-manager.c b/plugins/keyboard/gsd-keyboard-manager.c index 24d6729..0969459 100644 --- a/plugins/keyboard/gsd-keyboard-manager.c +++ b/plugins/keyboard/gsd-keyboard-manager.c @@ -47,42 +47,42 @@ #endif #include "mate-settings-profile.h" -#include "gsd-keyboard-manager.h" +#include "msd-keyboard-manager.h" -#include "gsd-keyboard-xkb.h" -#include "gsd-xmodmap.h" +#include "msd-keyboard-xkb.h" +#include "msd-xmodmap.h" -#define GSD_KEYBOARD_MANAGER_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManagerPrivate)) +#define MSD_KEYBOARD_MANAGER_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerPrivate)) #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 255 #endif -#define GSD_KEYBOARD_KEY "/desktop/mate/peripherals/keyboard" +#define MSD_KEYBOARD_KEY "/desktop/mate/peripherals/keyboard" -#define KEY_REPEAT GSD_KEYBOARD_KEY "/repeat" -#define KEY_CLICK GSD_KEYBOARD_KEY "/click" -#define KEY_RATE GSD_KEYBOARD_KEY "/rate" -#define KEY_DELAY GSD_KEYBOARD_KEY "/delay" -#define KEY_CLICK_VOLUME GSD_KEYBOARD_KEY "/click_volume" +#define KEY_REPEAT MSD_KEYBOARD_KEY "/repeat" +#define KEY_CLICK MSD_KEYBOARD_KEY "/click" +#define KEY_RATE MSD_KEYBOARD_KEY "/rate" +#define KEY_DELAY MSD_KEYBOARD_KEY "/delay" +#define KEY_CLICK_VOLUME MSD_KEYBOARD_KEY "/click_volume" -#define KEY_BELL_VOLUME GSD_KEYBOARD_KEY "/bell_volume" -#define KEY_BELL_PITCH GSD_KEYBOARD_KEY "/bell_pitch" -#define KEY_BELL_DURATION GSD_KEYBOARD_KEY "/bell_duration" -#define KEY_BELL_MODE GSD_KEYBOARD_KEY "/bell_mode" +#define KEY_BELL_VOLUME MSD_KEYBOARD_KEY "/bell_volume" +#define KEY_BELL_PITCH MSD_KEYBOARD_KEY "/bell_pitch" +#define KEY_BELL_DURATION MSD_KEYBOARD_KEY "/bell_duration" +#define KEY_BELL_MODE MSD_KEYBOARD_KEY "/bell_mode" -struct GsdKeyboardManagerPrivate { +struct MsdKeyboardManagerPrivate { gboolean have_xkb; gint xkb_event_base; guint notify; }; -static void gsd_keyboard_manager_class_init (GsdKeyboardManagerClass* klass); -static void gsd_keyboard_manager_init (GsdKeyboardManager* keyboard_manager); -static void gsd_keyboard_manager_finalize (GObject* object); +static void msd_keyboard_manager_class_init (MsdKeyboardManagerClass* klass); +static void msd_keyboard_manager_init (MsdKeyboardManager* keyboard_manager); +static void msd_keyboard_manager_finalize (GObject* object); -G_DEFINE_TYPE (GsdKeyboardManager, gsd_keyboard_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdKeyboardManager, msd_keyboard_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -126,7 +126,7 @@ static gboolean xkb_set_keyboard_autorepeat_rate(int delay, int rate) } #endif -static char* gsd_keyboard_get_hostname_key (const char *subkey) +static char* msd_keyboard_get_hostname_key (const char *subkey) { char hostname[HOST_NAME_MAX + 1]; @@ -137,7 +137,7 @@ static char* gsd_keyboard_get_hostname_key (const char *subkey) char *key; escaped = mateconf_escape_key (hostname, -1); - key = g_strconcat (GSD_KEYBOARD_KEY + key = g_strconcat (MSD_KEYBOARD_KEY "/host-", escaped, "/0/", @@ -158,7 +158,7 @@ typedef enum { } NumLockState; static void -numlock_xkb_init (GsdKeyboardManager *manager) +numlock_xkb_init (MsdKeyboardManager *manager) { Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); gboolean have_xkb; @@ -206,7 +206,7 @@ numlock_set_xkb_state (NumLockState new_state) static char * numlock_mateconf_state_key (void) { - char *key = gsd_keyboard_get_hostname_key ("numlock_on"); + char *key = msd_keyboard_get_hostname_key ("numlock_on"); if (!key) { g_message ("NumLock remembering disabled because hostname is set to \"localhost\""); } @@ -274,7 +274,7 @@ numlock_xkb_callback (GdkXEvent *xev_, } static void -numlock_install_xkb_callback (GsdKeyboardManager *manager) +numlock_install_xkb_callback (MsdKeyboardManager *manager) { if (!manager->priv->have_xkb) return; @@ -290,7 +290,7 @@ static void apply_settings (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdKeyboardManager *manager) + MsdKeyboardManager *manager) { XKeyboardControl kbdcontrol; gboolean repeat; @@ -322,7 +322,7 @@ apply_settings (MateConfClient *client, g_free (volume_string); #ifdef HAVE_X11_EXTENSIONS_XKB_H - rnumlock = mateconf_client_get_bool (client, GSD_KEYBOARD_KEY "/remember_numlock_state", NULL); + rnumlock = mateconf_client_get_bool (client, MSD_KEYBOARD_KEY "/remember_numlock_state", NULL); #endif /* HAVE_X11_EXTENSIONS_XKB_H */ gdk_error_trap_push (); @@ -370,7 +370,7 @@ apply_settings (MateConfClient *client, } void -gsd_keyboard_manager_apply_settings (GsdKeyboardManager *manager) +msd_keyboard_manager_apply_settings (MsdKeyboardManager *manager) { MateConfClient *client; @@ -380,7 +380,7 @@ gsd_keyboard_manager_apply_settings (GsdKeyboardManager *manager) } static gboolean -start_keyboard_idle_cb (GsdKeyboardManager *manager) +start_keyboard_idle_cb (MsdKeyboardManager *manager) { MateConfClient *client; @@ -391,20 +391,20 @@ start_keyboard_idle_cb (GsdKeyboardManager *manager) manager->priv->have_xkb = 0; client = mateconf_client_get_default (); - mateconf_client_add_dir (client, GSD_KEYBOARD_KEY, MATECONF_CLIENT_PRELOAD_RECURSIVE, NULL); + mateconf_client_add_dir (client, MSD_KEYBOARD_KEY, MATECONF_CLIENT_PRELOAD_RECURSIVE, NULL); /* Essential - xkb initialization should happen before */ - gsd_keyboard_xkb_set_post_activation_callback ((PostActivationCallback) gsd_load_modmap_files, NULL); - gsd_keyboard_xkb_init (client, manager); + msd_keyboard_xkb_set_post_activation_callback ((PostActivationCallback) msd_load_modmap_files, NULL); + msd_keyboard_xkb_init (client, manager); #ifdef HAVE_X11_EXTENSIONS_XKB_H numlock_xkb_init (manager); #endif /* HAVE_X11_EXTENSIONS_XKB_H */ /* apply current settings before we install the callback */ - gsd_keyboard_manager_apply_settings (manager); + msd_keyboard_manager_apply_settings (manager); - manager->priv->notify = mateconf_client_notify_add (client, GSD_KEYBOARD_KEY, + manager->priv->notify = mateconf_client_notify_add (client, MSD_KEYBOARD_KEY, (MateConfClientNotifyFunc) apply_settings, manager, NULL, NULL); @@ -420,7 +420,7 @@ start_keyboard_idle_cb (GsdKeyboardManager *manager) } gboolean -gsd_keyboard_manager_start (GsdKeyboardManager *manager, +msd_keyboard_manager_start (MsdKeyboardManager *manager, GError **error) { mate_settings_profile_start (NULL); @@ -433,15 +433,15 @@ gsd_keyboard_manager_start (GsdKeyboardManager *manager, } void -gsd_keyboard_manager_stop (GsdKeyboardManager *manager) +msd_keyboard_manager_stop (MsdKeyboardManager *manager) { - GsdKeyboardManagerPrivate *p = manager->priv; + MsdKeyboardManagerPrivate *p = manager->priv; g_debug ("Stopping keyboard manager"); if (p->notify != 0) { MateConfClient *client = mateconf_client_get_default (); - mateconf_client_remove_dir (client, GSD_KEYBOARD_KEY, NULL); + mateconf_client_remove_dir (client, MSD_KEYBOARD_KEY, NULL); mateconf_client_notify_remove (client, p->notify); g_object_unref (client); p->notify = 0; @@ -455,18 +455,18 @@ gsd_keyboard_manager_stop (GsdKeyboardManager *manager) } #endif /* HAVE_X11_EXTENSIONS_XKB_H */ - gsd_keyboard_xkb_shutdown (); + msd_keyboard_xkb_shutdown (); } static void -gsd_keyboard_manager_set_property (GObject *object, +msd_keyboard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdKeyboardManager *self; + MsdKeyboardManager *self; - self = GSD_KEYBOARD_MANAGER (object); + self = MSD_KEYBOARD_MANAGER (object); switch (prop_id) { default: @@ -476,14 +476,14 @@ gsd_keyboard_manager_set_property (GObject *object, } static void -gsd_keyboard_manager_get_property (GObject *object, +msd_keyboard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdKeyboardManager *self; + MsdKeyboardManager *self; - self = GSD_KEYBOARD_MANAGER (object); + self = MSD_KEYBOARD_MANAGER (object); switch (prop_id) { default: @@ -493,16 +493,16 @@ gsd_keyboard_manager_get_property (GObject *object, } static GObject * -gsd_keyboard_manager_constructor (GType type, +msd_keyboard_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdKeyboardManager *keyboard_manager; - GsdKeyboardManagerClass *klass; + MsdKeyboardManager *keyboard_manager; + MsdKeyboardManagerClass *klass; - klass = GSD_KEYBOARD_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_KEYBOARD_MANAGER)); + klass = MSD_KEYBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_KEYBOARD_MANAGER)); - keyboard_manager = GSD_KEYBOARD_MANAGER (G_OBJECT_CLASS (gsd_keyboard_manager_parent_class)->constructor (type, + keyboard_manager = MSD_KEYBOARD_MANAGER (G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -510,60 +510,60 @@ gsd_keyboard_manager_constructor (GType type, } static void -gsd_keyboard_manager_dispose (GObject *object) +msd_keyboard_manager_dispose (GObject *object) { - GsdKeyboardManager *keyboard_manager; + MsdKeyboardManager *keyboard_manager; - keyboard_manager = GSD_KEYBOARD_MANAGER (object); + keyboard_manager = MSD_KEYBOARD_MANAGER (object); - G_OBJECT_CLASS (gsd_keyboard_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->dispose (object); } static void -gsd_keyboard_manager_class_init (GsdKeyboardManagerClass *klass) +msd_keyboard_manager_class_init (MsdKeyboardManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_keyboard_manager_get_property; - object_class->set_property = gsd_keyboard_manager_set_property; - object_class->constructor = gsd_keyboard_manager_constructor; - object_class->dispose = gsd_keyboard_manager_dispose; - object_class->finalize = gsd_keyboard_manager_finalize; + object_class->get_property = msd_keyboard_manager_get_property; + object_class->set_property = msd_keyboard_manager_set_property; + object_class->constructor = msd_keyboard_manager_constructor; + object_class->dispose = msd_keyboard_manager_dispose; + object_class->finalize = msd_keyboard_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdKeyboardManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdKeyboardManagerPrivate)); } static void -gsd_keyboard_manager_init (GsdKeyboardManager *manager) +msd_keyboard_manager_init (MsdKeyboardManager *manager) { - manager->priv = GSD_KEYBOARD_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_KEYBOARD_MANAGER_GET_PRIVATE (manager); } static void -gsd_keyboard_manager_finalize (GObject *object) +msd_keyboard_manager_finalize (GObject *object) { - GsdKeyboardManager *keyboard_manager; + MsdKeyboardManager *keyboard_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_KEYBOARD_MANAGER (object)); + g_return_if_fail (MSD_IS_KEYBOARD_MANAGER (object)); - keyboard_manager = GSD_KEYBOARD_MANAGER (object); + keyboard_manager = MSD_KEYBOARD_MANAGER (object); g_return_if_fail (keyboard_manager->priv != NULL); - G_OBJECT_CLASS (gsd_keyboard_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->finalize (object); } -GsdKeyboardManager * -gsd_keyboard_manager_new (void) +MsdKeyboardManager * +msd_keyboard_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_KEYBOARD_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_KEYBOARD_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_KEYBOARD_MANAGER (manager_object); + return MSD_KEYBOARD_MANAGER (manager_object); } diff --git a/plugins/keyboard/gsd-keyboard-manager.h b/plugins/keyboard/gsd-keyboard-manager.h index a518e9a..aa3ae95 100644 --- a/plugins/keyboard/gsd-keyboard-manager.h +++ b/plugins/keyboard/gsd-keyboard-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_KEYBOARD_MANAGER_H -#define __GSD_KEYBOARD_MANAGER_H +#ifndef __MSD_KEYBOARD_MANAGER_H +#define __MSD_KEYBOARD_MANAGER_H #include @@ -27,36 +27,36 @@ extern "C" { #endif -#define GSD_TYPE_KEYBOARD_MANAGER (gsd_keyboard_manager_get_type ()) -#define GSD_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManager)) -#define GSD_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManagerClass)) -#define GSD_IS_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_KEYBOARD_MANAGER)) -#define GSD_IS_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_KEYBOARD_MANAGER)) -#define GSD_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_KEYBOARD_MANAGER, GsdKeyboardManagerClass)) +#define MSD_TYPE_KEYBOARD_MANAGER (msd_keyboard_manager_get_type ()) +#define MSD_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManager)) +#define MSD_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerClass)) +#define MSD_IS_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBOARD_MANAGER)) +#define MSD_IS_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBOARD_MANAGER)) +#define MSD_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerClass)) -typedef struct GsdKeyboardManagerPrivate GsdKeyboardManagerPrivate; +typedef struct MsdKeyboardManagerPrivate MsdKeyboardManagerPrivate; typedef struct { GObject parent; - GsdKeyboardManagerPrivate *priv; -} GsdKeyboardManager; + MsdKeyboardManagerPrivate *priv; +} MsdKeyboardManager; typedef struct { GObjectClass parent_class; -} GsdKeyboardManagerClass; +} MsdKeyboardManagerClass; -GType gsd_keyboard_manager_get_type (void); +GType msd_keyboard_manager_get_type (void); -GsdKeyboardManager * gsd_keyboard_manager_new (void); -gboolean gsd_keyboard_manager_start (GsdKeyboardManager *manager, +MsdKeyboardManager * msd_keyboard_manager_new (void); +gboolean msd_keyboard_manager_start (MsdKeyboardManager *manager, GError **error); -void gsd_keyboard_manager_stop (GsdKeyboardManager *manager); -void gsd_keyboard_manager_apply_settings (GsdKeyboardManager *manager); +void msd_keyboard_manager_stop (MsdKeyboardManager *manager); +void msd_keyboard_manager_apply_settings (MsdKeyboardManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_KEYBOARD_MANAGER_H */ +#endif /* __MSD_KEYBOARD_MANAGER_H */ diff --git a/plugins/keyboard/gsd-keyboard-plugin.c b/plugins/keyboard/gsd-keyboard-plugin.c index b501d80..5f89ca2 100644 --- a/plugins/keyboard/gsd-keyboard-plugin.c +++ b/plugins/keyboard/gsd-keyboard-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-keyboard-plugin.h" -#include "gsd-keyboard-manager.h" +#include "msd-keyboard-plugin.h" +#include "msd-keyboard-manager.h" -struct GsdKeyboardPluginPrivate { - GsdKeyboardManager *manager; +struct MsdKeyboardPluginPrivate { + MsdKeyboardManager *manager; }; -#define GSD_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_KEYBOARD_PLUGIN, GsdKeyboardPluginPrivate)) +#define MSD_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdKeyboardPlugin, gsd_keyboard_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdKeyboardPlugin, msd_keyboard_plugin) static void -gsd_keyboard_plugin_init (GsdKeyboardPlugin *plugin) +msd_keyboard_plugin_init (MsdKeyboardPlugin *plugin) { - plugin->priv = GSD_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdKeyboardPlugin initializing"); + g_debug ("MsdKeyboardPlugin initializing"); - plugin->priv->manager = gsd_keyboard_manager_new (); + plugin->priv->manager = msd_keyboard_manager_new (); } static void -gsd_keyboard_plugin_finalize (GObject *object) +msd_keyboard_plugin_finalize (GObject *object) { - GsdKeyboardPlugin *plugin; + MsdKeyboardPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_KEYBOARD_PLUGIN (object)); + g_return_if_fail (MSD_IS_KEYBOARD_PLUGIN (object)); - g_debug ("GsdKeyboardPlugin finalizing"); + g_debug ("MsdKeyboardPlugin finalizing"); - plugin = GSD_KEYBOARD_PLUGIN (object); + plugin = MSD_KEYBOARD_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_keyboard_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_keyboard_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_keyboard_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating keyboard plugin"); error = NULL; - res = gsd_keyboard_manager_start (GSD_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); + res = msd_keyboard_manager_start (MSD_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start keyboard manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating keyboard plugin"); - gsd_keyboard_manager_stop (GSD_KEYBOARD_PLUGIN (plugin)->priv->manager); + msd_keyboard_manager_stop (MSD_KEYBOARD_PLUGIN (plugin)->priv->manager); } static void -gsd_keyboard_plugin_class_init (GsdKeyboardPluginClass *klass) +msd_keyboard_plugin_class_init (MsdKeyboardPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_keyboard_plugin_finalize; + object_class->finalize = msd_keyboard_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdKeyboardPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdKeyboardPluginPrivate)); } diff --git a/plugins/keyboard/gsd-keyboard-plugin.h b/plugins/keyboard/gsd-keyboard-plugin.h index 3d25861..84f2420 100644 --- a/plugins/keyboard/gsd-keyboard-plugin.h +++ b/plugins/keyboard/gsd-keyboard-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_KEYBOARD_PLUGIN_H__ -#define __GSD_KEYBOARD_PLUGIN_H__ +#ifndef __MSD_KEYBOARD_PLUGIN_H__ +#define __MSD_KEYBOARD_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_KEYBOARD_PLUGIN (gsd_keyboard_plugin_get_type ()) -#define GSD_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_KEYBOARD_PLUGIN, GsdKeyboardPlugin)) -#define GSD_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_KEYBOARD_PLUGIN, GsdKeyboardPluginClass)) -#define GSD_IS_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_KEYBOARD_PLUGIN)) -#define GSD_IS_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_KEYBOARD_PLUGIN)) -#define GSD_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_KEYBOARD_PLUGIN, GsdKeyboardPluginClass)) +#define MSD_TYPE_KEYBOARD_PLUGIN (msd_keyboard_plugin_get_type ()) +#define MSD_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPlugin)) +#define MSD_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginClass)) +#define MSD_IS_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBOARD_PLUGIN)) +#define MSD_IS_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBOARD_PLUGIN)) +#define MSD_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginClass)) -typedef struct GsdKeyboardPluginPrivate GsdKeyboardPluginPrivate; +typedef struct MsdKeyboardPluginPrivate MsdKeyboardPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdKeyboardPluginPrivate *priv; -} GsdKeyboardPlugin; + MsdKeyboardPluginPrivate *priv; +} MsdKeyboardPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdKeyboardPluginClass; +} MsdKeyboardPluginClass; -GType gsd_keyboard_plugin_get_type (void) G_GNUC_CONST; +GType msd_keyboard_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_KEYBOARD_PLUGIN_H__ */ +#endif /* __MSD_KEYBOARD_PLUGIN_H__ */ diff --git a/plugins/keyboard/gsd-keyboard-xkb.c b/plugins/keyboard/gsd-keyboard-xkb.c index 0808272..9042f03 100644 --- a/plugins/keyboard/gsd-keyboard-xkb.c +++ b/plugins/keyboard/gsd-keyboard-xkb.c @@ -37,14 +37,14 @@ #include #include -#include "gsd-xmodmap.h" -#include "gsd-keyboard-xkb.h" +#include "msd-xmodmap.h" +#include "msd-keyboard-xkb.h" #include "delayed-dialog.h" #include "mate-settings-profile.h" #define GTK_RESPONSE_PRINT 2 -static GsdKeyboardManager* manager = NULL; +static MsdKeyboardManager* manager = NULL; static XklEngine* xkl_engine; static XklConfigRegistry* xkl_registry = NULL; @@ -92,12 +92,12 @@ static const gchar* indicator_off_icon_names[] = { "kbd-capslock-off" }; -//#define noGSDKX +//#define noMSDKX -#ifdef GSDKX +#ifdef MSDKX static FILE *logfile; -static void gsd_keyboard_log_appender(const char file[], const char function[], int level, const char format[], va_list args) +static void msd_keyboard_log_appender(const char file[], const char function[], int level, const char format[], va_list args) { time_t now = time (NULL); fprintf (logfile, "[%08ld,%03d,%s:%s/] \t", now, @@ -150,7 +150,7 @@ activation_error (void) "mateconftool-2 -R /desktop/mate/peripherals/keyboard/kbd"); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); - gsd_delayed_show_dialog (dialog); + msd_delayed_show_dialog (dialog); } static void @@ -162,7 +162,7 @@ apply_desktop_settings (void) if (!inited_ok) return; - gsd_keyboard_manager_apply_settings (manager); + msd_keyboard_manager_apply_settings (manager); matekbd_desktop_config_load_from_mateconf (¤t_config); /* again, probably it would be nice to compare things before activating them */ @@ -600,7 +600,7 @@ apply_xkb_settings (void) } static void -gsd_keyboard_xkb_analyze_sysconfig (void) +msd_keyboard_xkb_analyze_sysconfig (void) { MateConfClient *conf_client; @@ -616,7 +616,7 @@ gsd_keyboard_xkb_analyze_sysconfig (void) } static gboolean -gsd_chk_file_list (void) +msd_chk_file_list (void) { GDir *home_dir; const char *fname; @@ -684,16 +684,16 @@ gsd_chk_file_list (void) } static void -gsd_keyboard_xkb_chk_lcl_xmm (void) +msd_keyboard_xkb_chk_lcl_xmm (void) { - if (gsd_chk_file_list ()) { - gsd_modmap_dialog_call (); + if (msd_chk_file_list ()) { + msd_modmap_dialog_call (); } - gsd_load_modmap_files (); + msd_load_modmap_files (); } void -gsd_keyboard_xkb_set_post_activation_callback (PostActivationCallback fun, +msd_keyboard_xkb_set_post_activation_callback (PostActivationCallback fun, void *user_data) { pa_callback = fun; @@ -701,7 +701,7 @@ gsd_keyboard_xkb_set_post_activation_callback (PostActivationCallback fun, } static GdkFilterReturn -gsd_keyboard_xkb_evt_filter (GdkXEvent * xev, GdkEvent * event) +msd_keyboard_xkb_evt_filter (GdkXEvent * xev, GdkEvent * event) { XEvent *xevent = (XEvent *) xev; xkl_engine_filter_events (xkl_engine, xevent); @@ -720,14 +720,14 @@ register_config_callback (MateConfClient * client, /* When new Keyboard is plugged in - reload the settings */ static void -gsd_keyboard_new_device (XklEngine * engine) +msd_keyboard_new_device (XklEngine * engine) { apply_desktop_settings (); apply_xkb_settings (); } static void -gsd_keyboard_update_indicator_icons () +msd_keyboard_update_indicator_icons () { Bool state; int new_state, i; @@ -758,20 +758,20 @@ gsd_keyboard_update_indicator_icons () } static void -gsd_keyboard_state_changed (XklEngine * engine, XklEngineStateChange type, +msd_keyboard_state_changed (XklEngine * engine, XklEngineStateChange type, gint new_group, gboolean restore) { xkl_debug (160, "State changed: type %d, new group: %d, restore: %d.\n", type, new_group, restore); if (type == INDICATORS_CHANGED) { - gsd_keyboard_update_indicator_icons (); + msd_keyboard_update_indicator_icons (); } } void -gsd_keyboard_xkb_init (MateConfClient * client, - GsdKeyboardManager * kbd_manager) +msd_keyboard_xkb_init (MateConfClient * client, + MsdKeyboardManager * kbd_manager) { int i; Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); @@ -792,12 +792,12 @@ gsd_keyboard_xkb_init (MateConfClient * client, (indicator_off_icon_names[i]); } - gsd_keyboard_update_indicator_icons (); + msd_keyboard_update_indicator_icons (); -#ifdef GSDKX +#ifdef MSDKX xkl_set_debug_level (200); - logfile = fopen ("/tmp/gsdkx.log", "a"); - xkl_set_log_appender (gsd_keyboard_log_appender); + logfile = fopen ("/tmp/msdkx.log", "a"); + xkl_set_log_appender (msd_keyboard_log_appender); #endif manager = kbd_manager; mate_settings_profile_start ("xkl_engine_get_instance"); @@ -813,12 +813,12 @@ gsd_keyboard_xkb_init (MateConfClient * client, matekbd_keyboard_config_init (¤t_kbd_config, client, xkl_engine); xkl_engine_backup_names_prop (xkl_engine); - gsd_keyboard_xkb_analyze_sysconfig (); + msd_keyboard_xkb_analyze_sysconfig (); mate_settings_profile_start - ("gsd_keyboard_xkb_chk_lcl_xmm"); - gsd_keyboard_xkb_chk_lcl_xmm (); + ("msd_keyboard_xkb_chk_lcl_xmm"); + msd_keyboard_xkb_chk_lcl_xmm (); mate_settings_profile_end - ("gsd_keyboard_xkb_chk_lcl_xmm"); + ("msd_keyboard_xkb_chk_lcl_xmm"); notify_desktop = register_config_callback (client, @@ -833,16 +833,16 @@ gsd_keyboard_xkb_init (MateConfClient * client, apply_xkb_settings); gdk_window_add_filter (NULL, (GdkFilterFunc) - gsd_keyboard_xkb_evt_filter, NULL); + msd_keyboard_xkb_evt_filter, NULL); if (xkl_engine_get_features (xkl_engine) & XKLF_DEVICE_DISCOVERY) g_signal_connect (xkl_engine, "X-new-device", G_CALLBACK - (gsd_keyboard_new_device), NULL); + (msd_keyboard_new_device), NULL); g_signal_connect (xkl_engine, "X-state-changed", G_CALLBACK - (gsd_keyboard_state_changed), NULL); + (msd_keyboard_state_changed), NULL); mate_settings_profile_start ("xkl_engine_start_listen"); xkl_engine_start_listen (xkl_engine, @@ -863,7 +863,7 @@ gsd_keyboard_xkb_init (MateConfClient * client, } void -gsd_keyboard_xkb_shutdown (void) +msd_keyboard_xkb_shutdown (void) { MateConfClient *client; int i; @@ -888,7 +888,7 @@ gsd_keyboard_xkb_shutdown (void) XKLL_MANAGE_WINDOW_STATES); gdk_window_remove_filter (NULL, (GdkFilterFunc) - gsd_keyboard_xkb_evt_filter, NULL); + msd_keyboard_xkb_evt_filter, NULL); client = mateconf_client_get_default (); diff --git a/plugins/keyboard/gsd-keyboard-xkb.h b/plugins/keyboard/gsd-keyboard-xkb.h index 41a50c6..7d2d558 100644 --- a/plugins/keyboard/gsd-keyboard-xkb.h +++ b/plugins/keyboard/gsd-keyboard-xkb.h @@ -21,20 +21,20 @@ * 02111-1307, USA. */ -#ifndef __GSD_KEYBOARD_XKB_H -#define __GSD_KEYBOARD_XKB_H +#ifndef __MSD_KEYBOARD_XKB_H +#define __MSD_KEYBOARD_XKB_H #include #include #include -#include "gsd-keyboard-manager.h" +#include "msd-keyboard-manager.h" -void gsd_keyboard_xkb_init(MateConfClient* client, GsdKeyboardManager* manager); -void gsd_keyboard_xkb_shutdown(void); +void msd_keyboard_xkb_init(MateConfClient* client, MsdKeyboardManager* manager); +void msd_keyboard_xkb_shutdown(void); typedef void (*PostActivationCallback) (void* userData); -void gsd_keyboard_xkb_set_post_activation_callback(PostActivationCallback fun, void* userData); +void msd_keyboard_xkb_set_post_activation_callback(PostActivationCallback fun, void* userData); #endif diff --git a/plugins/keyboard/gsd-xmodmap.c b/plugins/keyboard/gsd-xmodmap.c index b9ffc9c..5baf37c 100644 --- a/plugins/keyboard/gsd-xmodmap.c +++ b/plugins/keyboard/gsd-xmodmap.c @@ -28,7 +28,7 @@ #include #include -#include "gsd-xmodmap.h" +#include "msd-xmodmap.h" static const char DISABLE_XMM_WARNING_KEY[] = "/desktop/mate/peripherals/keyboard/disable_xmm_and_xkb_warning"; @@ -54,7 +54,7 @@ check_button_callback (GtkWidget *chk_button, } void -gsd_load_modmap_files (void) +msd_load_modmap_files (void) { MateConfClient *client; GSList *tmp; @@ -90,7 +90,7 @@ response_callback (GtkWidget *dialog, if (id == GTK_RESPONSE_OK) { GtkWidget *chk_button = g_object_get_data (G_OBJECT (dialog), "check_button"); check_button_callback (chk_button, NULL); - gsd_load_modmap_files (); + msd_load_modmap_files (); } gtk_widget_destroy (dialog); } @@ -256,7 +256,7 @@ out: } void -gsd_modmap_dialog_call (void) +msd_modmap_dialog_call (void) { GtkBuilder *builder; guint res; diff --git a/plugins/keyboard/gsd-xmodmap.h b/plugins/keyboard/gsd-xmodmap.h index 7cfff74..04b4505 100644 --- a/plugins/keyboard/gsd-xmodmap.h +++ b/plugins/keyboard/gsd-xmodmap.h @@ -23,7 +23,7 @@ #ifndef XMODMAP_H #define XMODMAP_H -void gsd_load_modmap_files (void); -void gsd_modmap_dialog_call (void); +void msd_load_modmap_files (void); +void msd_modmap_dialog_call (void); #endif diff --git a/plugins/media-keys/Makefile.am b/plugins/media-keys/Makefile.am index 3a2f65e..9bd9553 100644 --- a/plugins/media-keys/Makefile.am +++ b/plugins/media-keys/Makefile.am @@ -7,9 +7,9 @@ SUBDIRS = cut-n-paste plugin_LTLIBRARIES = libmedia-keys.la BUILT_SOURCES = \ - gsd-media-keys-manager-glue.h \ - gsd-marshal.h \ - gsd-marshal.c \ + msd-media-keys-manager-glue.h \ + msd-marshal.h \ + msd-marshal.c \ $(NULL) ICON_FILES = \ @@ -55,24 +55,24 @@ uninstall-local: rm -f $(DESTDIR)$(icondir)/32x32/$(context)/touchpad-disabled.png rm -f $(DESTDIR)$(icondir)/scalable/$(context)/touchpad-disabled.svg -gsd-media-keys-manager-glue.h: gsd-media-keys-manager.xml Makefile - dbus-binding-tool --prefix=gsd_media_keys_manager --mode=glib-server $< > xgen-$(@F) \ +msd-media-keys-manager-glue.h: msd-media-keys-manager.xml Makefile + dbus-binding-tool --prefix=msd_media_keys_manager --mode=glib-server $< > xgen-$(@F) \ && ( cmp -s xgen-$(@F) $@ || cp xgen-$(@F) $@ ) \ && rm -f xgen-$(@F) -gsd-marshal.c: gsd-marshal.list - $(GLIB_GENMARSHAL) --prefix=gsd_marshal $< --header --body --internal > $@ +msd-marshal.c: msd-marshal.list + $(GLIB_GENMARSHAL) --prefix=msd_marshal $< --header --body --internal > $@ -gsd-marshal.h: gsd-marshal.list - $(GLIB_GENMARSHAL) --prefix=gsd_marshal $< --header --internal > $@ +msd-marshal.h: msd-marshal.list + $(GLIB_GENMARSHAL) --prefix=msd_marshal $< --header --internal > $@ libmedia_keys_la_SOURCES = \ - gsd-media-keys-plugin.h \ - gsd-media-keys-plugin.c \ - gsd-media-keys-manager.h \ - gsd-media-keys-manager.c \ - gsd-media-keys-window.h \ - gsd-media-keys-window.c \ + msd-media-keys-plugin.h \ + msd-media-keys-plugin.c \ + msd-media-keys-manager.h \ + msd-media-keys-manager.c \ + msd-media-keys-window.h \ + msd-media-keys-window.c \ acme.h \ $(BUILT_SOURCES) \ $(NULL) @@ -91,7 +91,7 @@ libmedia_keys_la_CFLAGS = \ $(AM_CFLAGS) libmedia_keys_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) + $(MSD_PLUGIN_LDFLAGS) libmedia_keys_la_LIBADD = \ $(top_builddir)/plugins/common/libcommon.la \ @@ -111,8 +111,8 @@ noinst_PROGRAMS = \ $(NULL) test_media_window_SOURCES = \ - gsd-media-keys-window.c \ - gsd-media-keys-window.h \ + msd-media-keys-window.c \ + msd-media-keys-window.h \ test-media-window.c \ $(NULL) @@ -139,10 +139,10 @@ test_media_window_LDADD = \ -lm test_media_keys_SOURCES = \ - gsd-media-keys-manager.c \ - gsd-media-keys-manager.h \ - gsd-media-keys-window.h \ - gsd-media-keys-window.c \ + msd-media-keys-manager.c \ + msd-media-keys-manager.h \ + msd-media-keys-window.h \ + msd-media-keys-window.c \ test-media-keys.c \ $(BUILT_SOURCES) \ $(NULL) @@ -161,7 +161,7 @@ test_media_keys_CFLAGS = \ $(AM_CFLAGS) test_media_keys_LDADD = \ - $(top_builddir)/mate-settings-daemon/libgsd-profile.la \ + $(top_builddir)/mate-settings-daemon/libmsd-profile.la \ $(top_builddir)/plugins/common/libcommon.la \ $(SETTINGS_DAEMON_LIBS) \ $(SETTINGS_PLUGIN_LIBS) \ @@ -179,8 +179,8 @@ gtkbuilder_DATA = \ DIST_SUBDIRS = cut-n-paste EXTRA_DIST = \ - gsd-media-keys-manager.xml \ - gsd-marshal.list \ + msd-media-keys-manager.xml \ + msd-marshal.list \ $(plugin_in_files) \ $(gtkbuilder_DATA) \ $(pixmaps_DATA) \ @@ -195,4 +195,4 @@ CLEANFILES = \ DISTCLEANFILES = \ $(plugin_DATA) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/media-keys/acme.h b/plugins/media-keys/acme.h index 66e13bc..41228e0 100644 --- a/plugins/media-keys/acme.h +++ b/plugins/media-keys/acme.h @@ -21,7 +21,7 @@ #ifndef __ACME_H__ #define __ACME_H__ -#include "gsd-keygrab.h" +#include "msd-keygrab.h" #define MATECONF_BINDING_DIR "/apps/mate_settings_daemon/keybindings" #define MATECONF_MISC_DIR "/apps/mate_settings_daemon" diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c index 1110dd5..d7e1b04 100644 --- a/plugins/media-keys/gsd-media-keys-manager.c +++ b/plugins/media-keys/gsd-media-keys-manager.c @@ -42,13 +42,13 @@ #include #include "mate-settings-profile.h" -#include "gsd-marshal.h" -#include "gsd-media-keys-manager.h" -#include "gsd-media-keys-manager-glue.h" +#include "msd-marshal.h" +#include "msd-media-keys-manager.h" +#include "msd-media-keys-manager-glue.h" #include "eggaccelerators.h" #include "acme.h" -#include "gsd-media-keys-window.h" +#include "msd-media-keys-window.h" #ifdef HAVE_PULSE #include @@ -57,24 +57,24 @@ #include "gvc-gstreamer-acme-vol.h" #endif /* HAVE_PULSE */ -#define GSD_DBUS_PATH "/org/mate/SettingsDaemon" -#define GSD_DBUS_NAME "org.mate.SettingsDaemon" -#define GSD_MEDIA_KEYS_DBUS_PATH GSD_DBUS_PATH "/MediaKeys" -#define GSD_MEDIA_KEYS_DBUS_NAME GSD_DBUS_NAME ".MediaKeys" +#define MSD_DBUS_PATH "/org/mate/SettingsDaemon" +#define MSD_DBUS_NAME "org.mate.SettingsDaemon" +#define MSD_MEDIA_KEYS_DBUS_PATH MSD_DBUS_PATH "/MediaKeys" +#define MSD_MEDIA_KEYS_DBUS_NAME MSD_DBUS_NAME ".MediaKeys" #define TOUCHPAD_ENABLED_KEY "/desktop/mate/peripherals/touchpad/touchpad_enabled" #define VOLUME_STEP 6 /* percents for one volume button press */ #define MAX_VOLUME 65536.0 -#define GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerPrivate)) +#define MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerPrivate)) typedef struct { char *application; guint32 time; } MediaPlayer; -struct GsdMediaKeysManagerPrivate +struct MsdMediaKeysManagerPrivate { #ifdef HAVE_PULSE /* Volume bits */ @@ -104,17 +104,17 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -static void gsd_media_keys_manager_class_init (GsdMediaKeysManagerClass *klass); -static void gsd_media_keys_manager_init (GsdMediaKeysManager *media_keys_manager); -static void gsd_media_keys_manager_finalize (GObject *object); +static void msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass); +static void msd_media_keys_manager_init (MsdMediaKeysManager *media_keys_manager); +static void msd_media_keys_manager_finalize (GObject *object); -G_DEFINE_TYPE (GsdMediaKeysManager, gsd_media_keys_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdMediaKeysManager, msd_media_keys_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void -init_screens (GsdMediaKeysManager *manager) +init_screens (MsdMediaKeysManager *manager) { GdkDisplay *display; int i; @@ -154,7 +154,7 @@ acme_error (char * msg) } static char * -get_term_command (GsdMediaKeysManager *manager) +get_term_command (MsdMediaKeysManager *manager) { char *cmd_term; char *cmd = NULL; @@ -180,7 +180,7 @@ get_term_command (GsdMediaKeysManager *manager) } static void -execute (GsdMediaKeysManager *manager, +execute (MsdMediaKeysManager *manager, char *cmd, gboolean sync, gboolean need_term) @@ -247,16 +247,16 @@ execute (GsdMediaKeysManager *manager, } static void -dialog_init (GsdMediaKeysManager *manager) +dialog_init (MsdMediaKeysManager *manager) { if (manager->priv->dialog != NULL - && !gsd_osd_window_is_valid (GSD_OSD_WINDOW (manager->priv->dialog))) { + && !msd_osd_window_is_valid (MSD_OSD_WINDOW (manager->priv->dialog))) { gtk_widget_destroy (manager->priv->dialog); manager->priv->dialog = NULL; } if (manager->priv->dialog == NULL) { - manager->priv->dialog = gsd_media_keys_window_new (); + manager->priv->dialog = msd_media_keys_window_new (); } } @@ -277,7 +277,7 @@ static void update_kbd_cb (MateConfClient *client, guint id, MateConfEntry *entry, - GsdMediaKeysManager *manager) + MsdMediaKeysManager *manager) { int i; gboolean need_flush = TRUE; @@ -331,7 +331,7 @@ update_kbd_cb (MateConfClient *client, g_warning ("Grab failed for some keys, another application may already have access the them."); } -static void init_kbd(GsdMediaKeysManager* manager) +static void init_kbd(MsdMediaKeysManager* manager) { int i; gboolean need_flush = FALSE; @@ -395,7 +395,7 @@ static void init_kbd(GsdMediaKeysManager* manager) } static void -dialog_show (GsdMediaKeysManager *manager) +dialog_show (MsdMediaKeysManager *manager) { int orig_w; int orig_h; @@ -463,7 +463,7 @@ dialog_show (GsdMediaKeysManager *manager) } static void -do_unknown_action (GsdMediaKeysManager *manager, +do_unknown_action (MsdMediaKeysManager *manager, const char *url) { char *string; @@ -484,7 +484,7 @@ do_unknown_action (GsdMediaKeysManager *manager, } static void -do_help_action (GsdMediaKeysManager *manager) +do_help_action (MsdMediaKeysManager *manager) { char *string; @@ -505,7 +505,7 @@ do_help_action (GsdMediaKeysManager *manager) } static void -do_mail_action (GsdMediaKeysManager *manager) +do_mail_action (MsdMediaKeysManager *manager) { char *string; @@ -527,7 +527,7 @@ do_mail_action (GsdMediaKeysManager *manager) } static void -do_media_action (GsdMediaKeysManager *manager) +do_media_action (MsdMediaKeysManager *manager) { char *command; @@ -544,7 +544,7 @@ do_media_action (GsdMediaKeysManager *manager) } static void -do_www_action (GsdMediaKeysManager *manager, +do_www_action (MsdMediaKeysManager *manager, const char *url) { char *string; @@ -575,7 +575,7 @@ do_www_action (GsdMediaKeysManager *manager, } static void -do_exit_action (GsdMediaKeysManager *manager) +do_exit_action (MsdMediaKeysManager *manager) { execute (manager, "mate-session-save --shutdown-dialog", FALSE, FALSE); } @@ -583,7 +583,7 @@ do_exit_action (GsdMediaKeysManager *manager) static void do_eject_action_cb (GDrive *drive, GAsyncResult *res, - GsdMediaKeysManager *manager) + MsdMediaKeysManager *manager) { g_drive_eject_with_operation_finish (drive, res, NULL); } @@ -592,7 +592,7 @@ do_eject_action_cb (GDrive *drive, #define SCORE_CAN_EJECT 50 #define SCORE_HAS_MEDIA 100 static void -do_eject_action (GsdMediaKeysManager *manager) +do_eject_action (MsdMediaKeysManager *manager) { GList *drives, *l; GDrive *fav_drive; @@ -624,7 +624,7 @@ do_eject_action (GsdMediaKeysManager *manager) /* Show the dialogue */ dialog_init (manager); - gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), "media-eject", FALSE); dialog_show (manager); @@ -647,13 +647,13 @@ do_eject_action (GsdMediaKeysManager *manager) } static void -do_touchpad_action (GsdMediaKeysManager *manager) +do_touchpad_action (MsdMediaKeysManager *manager) { MateConfClient *client = manager->priv->conf_client; gboolean state = mateconf_client_get_bool (client, TOUCHPAD_ENABLED_KEY, NULL); dialog_init (manager); - gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), (!state) ? "touchpad-enabled" : "touchpad-disabled", FALSE); dialog_show (manager); @@ -663,7 +663,7 @@ do_touchpad_action (GsdMediaKeysManager *manager) #ifdef HAVE_PULSE static void -update_dialog (GsdMediaKeysManager *manager, +update_dialog (MsdMediaKeysManager *manager, guint vol, gboolean muted, gboolean sound_changed) @@ -672,11 +672,11 @@ update_dialog (GsdMediaKeysManager *manager, vol = CLAMP (vol, 0, 100); dialog_init (manager); - gsd_media_keys_window_set_volume_muted (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), muted); - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol); - gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); dialog_show (manager); if (sound_changed != FALSE && muted == FALSE) @@ -690,7 +690,7 @@ update_dialog (GsdMediaKeysManager *manager, #if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) static void -do_sound_action (GsdMediaKeysManager *manager, +do_sound_action (MsdMediaKeysManager *manager, int type) { gboolean muted; @@ -814,12 +814,12 @@ do_sound_action (GsdMediaKeysManager *manager, /* FIXME: AcmeVolume should probably emit signals instead of doing it like this */ dialog_init (manager); - gsd_media_keys_window_set_volume_muted (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), muted); - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol); - gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); dialog_show (manager); #endif /* HAVE_PULSE */ } @@ -827,7 +827,7 @@ do_sound_action (GsdMediaKeysManager *manager, #ifdef HAVE_PULSE static void -update_default_sink (GsdMediaKeysManager *manager) +update_default_sink (MsdMediaKeysManager *manager) { GvcMixerStream *stream; @@ -849,7 +849,7 @@ update_default_sink (GsdMediaKeysManager *manager) static void on_control_ready (GvcMixerControl *control, - GsdMediaKeysManager *manager) + MsdMediaKeysManager *manager) { update_default_sink (manager); } @@ -857,7 +857,7 @@ on_control_ready (GvcMixerControl *control, static void on_control_default_sink_changed (GvcMixerControl *control, guint id, - GsdMediaKeysManager *manager) + MsdMediaKeysManager *manager) { update_default_sink (manager); } @@ -886,7 +886,7 @@ find_by_time (gconstpointer a, * events only nobody is interested. */ gboolean -gsd_media_keys_manager_grab_media_player_keys (GsdMediaKeysManager *manager, +msd_media_keys_manager_grab_media_player_keys (MsdMediaKeysManager *manager, const char *application, guint32 time, GError **error) @@ -928,7 +928,7 @@ gsd_media_keys_manager_grab_media_player_keys (GsdMediaKeysManager *manager, } gboolean -gsd_media_keys_manager_release_media_player_keys (GsdMediaKeysManager *manager, +msd_media_keys_manager_release_media_player_keys (MsdMediaKeysManager *manager, const char *application, GError **error) { @@ -949,7 +949,7 @@ gsd_media_keys_manager_release_media_player_keys (GsdMediaKeysManager *manager, } static gboolean -gsd_media_player_key_pressed (GsdMediaKeysManager *manager, +msd_media_player_key_pressed (MsdMediaKeysManager *manager, const char *key) { const char *application = NULL; @@ -967,14 +967,14 @@ gsd_media_player_key_pressed (GsdMediaKeysManager *manager, } static gboolean -do_multimedia_player_action (GsdMediaKeysManager *manager, +do_multimedia_player_action (MsdMediaKeysManager *manager, const char *key) { - return gsd_media_player_key_pressed (manager, key); + return msd_media_player_key_pressed (manager, key); } static gboolean -do_action (GsdMediaKeysManager *manager, +do_action (MsdMediaKeysManager *manager, int type) { char *cmd; @@ -1062,7 +1062,7 @@ do_action (GsdMediaKeysManager *manager, } static GdkScreen * -acme_get_screen_from_event (GsdMediaKeysManager *manager, +acme_get_screen_from_event (MsdMediaKeysManager *manager, XAnyEvent *xanyev) { GdkWindow *window; @@ -1085,7 +1085,7 @@ acme_get_screen_from_event (GsdMediaKeysManager *manager, static GdkFilterReturn acme_filter_events (GdkXEvent *xevent, GdkEvent *event, - GsdMediaKeysManager *manager) + MsdMediaKeysManager *manager) { XEvent *xev = (XEvent *) xevent; XAnyEvent *xany = (XAnyEvent *) xevent; @@ -1126,7 +1126,7 @@ acme_filter_events (GdkXEvent *xevent, } static gboolean -start_media_keys_idle_cb (GsdMediaKeysManager *manager) +start_media_keys_idle_cb (MsdMediaKeysManager *manager) { GSList *l; @@ -1162,7 +1162,7 @@ start_media_keys_idle_cb (GsdMediaKeysManager *manager) } gboolean -gsd_media_keys_manager_start (GsdMediaKeysManager *manager, +msd_media_keys_manager_start (MsdMediaKeysManager *manager, GError **error) { mate_settings_profile_start (NULL); @@ -1203,9 +1203,9 @@ gsd_media_keys_manager_start (GsdMediaKeysManager *manager, } void -gsd_media_keys_manager_stop (GsdMediaKeysManager *manager) +msd_media_keys_manager_stop (MsdMediaKeysManager *manager) { - GsdMediaKeysManagerPrivate *priv = manager->priv; + MsdMediaKeysManagerPrivate *priv = manager->priv; GSList *ls; GList *l; int i; @@ -1295,14 +1295,14 @@ gsd_media_keys_manager_stop (GsdMediaKeysManager *manager) } static void -gsd_media_keys_manager_set_property (GObject *object, +msd_media_keys_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdMediaKeysManager *self; + MsdMediaKeysManager *self; - self = GSD_MEDIA_KEYS_MANAGER (object); + self = MSD_MEDIA_KEYS_MANAGER (object); switch (prop_id) { default: @@ -1312,14 +1312,14 @@ gsd_media_keys_manager_set_property (GObject *object, } static void -gsd_media_keys_manager_get_property (GObject *object, +msd_media_keys_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdMediaKeysManager *self; + MsdMediaKeysManager *self; - self = GSD_MEDIA_KEYS_MANAGER (object); + self = MSD_MEDIA_KEYS_MANAGER (object); switch (prop_id) { default: @@ -1329,16 +1329,16 @@ gsd_media_keys_manager_get_property (GObject *object, } static GObject * -gsd_media_keys_manager_constructor (GType type, +msd_media_keys_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdMediaKeysManager *media_keys_manager; - GsdMediaKeysManagerClass *klass; + MsdMediaKeysManager *media_keys_manager; + MsdMediaKeysManagerClass *klass; - klass = GSD_MEDIA_KEYS_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_MEDIA_KEYS_MANAGER)); + klass = MSD_MEDIA_KEYS_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_MEDIA_KEYS_MANAGER)); - media_keys_manager = GSD_MEDIA_KEYS_MANAGER (G_OBJECT_CLASS (gsd_media_keys_manager_parent_class)->constructor (type, + media_keys_manager = MSD_MEDIA_KEYS_MANAGER (G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -1346,68 +1346,68 @@ gsd_media_keys_manager_constructor (GType type, } static void -gsd_media_keys_manager_dispose (GObject *object) +msd_media_keys_manager_dispose (GObject *object) { - GsdMediaKeysManager *media_keys_manager; + MsdMediaKeysManager *media_keys_manager; - media_keys_manager = GSD_MEDIA_KEYS_MANAGER (object); + media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); - G_OBJECT_CLASS (gsd_media_keys_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->dispose (object); } static void -gsd_media_keys_manager_class_init (GsdMediaKeysManagerClass *klass) +msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_media_keys_manager_get_property; - object_class->set_property = gsd_media_keys_manager_set_property; - object_class->constructor = gsd_media_keys_manager_constructor; - object_class->dispose = gsd_media_keys_manager_dispose; - object_class->finalize = gsd_media_keys_manager_finalize; + object_class->get_property = msd_media_keys_manager_get_property; + object_class->set_property = msd_media_keys_manager_set_property; + object_class->constructor = msd_media_keys_manager_constructor; + object_class->dispose = msd_media_keys_manager_dispose; + object_class->finalize = msd_media_keys_manager_finalize; signals[MEDIA_PLAYER_KEY_PRESSED] = g_signal_new ("media-player-key-pressed", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdMediaKeysManagerClass, media_player_key_pressed), + G_STRUCT_OFFSET (MsdMediaKeysManagerClass, media_player_key_pressed), NULL, NULL, - gsd_marshal_VOID__STRING_STRING, + msd_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); - dbus_g_object_type_install_info (GSD_TYPE_MEDIA_KEYS_MANAGER, &dbus_glib_gsd_media_keys_manager_object_info); + dbus_g_object_type_install_info (MSD_TYPE_MEDIA_KEYS_MANAGER, &dbus_glib_msd_media_keys_manager_object_info); - g_type_class_add_private (klass, sizeof (GsdMediaKeysManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdMediaKeysManagerPrivate)); } static void -gsd_media_keys_manager_init (GsdMediaKeysManager *manager) +msd_media_keys_manager_init (MsdMediaKeysManager *manager) { - manager->priv = GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager); } static void -gsd_media_keys_manager_finalize (GObject *object) +msd_media_keys_manager_finalize (GObject *object) { - GsdMediaKeysManager *media_keys_manager; + MsdMediaKeysManager *media_keys_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_MEDIA_KEYS_MANAGER (object)); + g_return_if_fail (MSD_IS_MEDIA_KEYS_MANAGER (object)); - media_keys_manager = GSD_MEDIA_KEYS_MANAGER (object); + media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); g_return_if_fail (media_keys_manager->priv != NULL); - G_OBJECT_CLASS (gsd_media_keys_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->finalize (object); } static gboolean -register_manager (GsdMediaKeysManager *manager) +register_manager (MsdMediaKeysManager *manager) { GError *error = NULL; @@ -1420,20 +1420,20 @@ register_manager (GsdMediaKeysManager *manager) return FALSE; } - dbus_g_connection_register_g_object (manager->priv->connection, GSD_MEDIA_KEYS_DBUS_PATH, G_OBJECT (manager)); + dbus_g_connection_register_g_object (manager->priv->connection, MSD_MEDIA_KEYS_DBUS_PATH, G_OBJECT (manager)); return TRUE; } -GsdMediaKeysManager * -gsd_media_keys_manager_new (void) +MsdMediaKeysManager * +msd_media_keys_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { gboolean res; - manager_object = g_object_new (GSD_TYPE_MEDIA_KEYS_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_MEDIA_KEYS_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); res = register_manager (manager_object); @@ -1443,5 +1443,5 @@ gsd_media_keys_manager_new (void) } } - return GSD_MEDIA_KEYS_MANAGER (manager_object); + return MSD_MEDIA_KEYS_MANAGER (manager_object); } diff --git a/plugins/media-keys/gsd-media-keys-manager.h b/plugins/media-keys/gsd-media-keys-manager.h index 19dafd5..96c135f 100644 --- a/plugins/media-keys/gsd-media-keys-manager.h +++ b/plugins/media-keys/gsd-media-keys-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_MEDIA_KEYS_MANAGER_H -#define __GSD_MEDIA_KEYS_MANAGER_H +#ifndef __MSD_MEDIA_KEYS_MANAGER_H +#define __MSD_MEDIA_KEYS_MANAGER_H #include @@ -27,41 +27,41 @@ extern "C" { #endif -#define GSD_TYPE_MEDIA_KEYS_MANAGER (gsd_media_keys_manager_get_type ()) -#define GSD_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManager)) -#define GSD_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerClass)) -#define GSD_IS_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_MEDIA_KEYS_MANAGER)) -#define GSD_IS_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_MEDIA_KEYS_MANAGER)) -#define GSD_MEDIA_KEYS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerClass)) +#define MSD_TYPE_MEDIA_KEYS_MANAGER (msd_media_keys_manager_get_type ()) +#define MSD_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManager)) +#define MSD_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerClass)) +#define MSD_IS_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MEDIA_KEYS_MANAGER)) +#define MSD_IS_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_MANAGER)) +#define MSD_MEDIA_KEYS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerClass)) -typedef struct GsdMediaKeysManagerPrivate GsdMediaKeysManagerPrivate; +typedef struct MsdMediaKeysManagerPrivate MsdMediaKeysManagerPrivate; typedef struct { GObject parent; - GsdMediaKeysManagerPrivate *priv; -} GsdMediaKeysManager; + MsdMediaKeysManagerPrivate *priv; +} MsdMediaKeysManager; typedef struct { GObjectClass parent_class; - void (* media_player_key_pressed) (GsdMediaKeysManager *manager, + void (* media_player_key_pressed) (MsdMediaKeysManager *manager, const char *application, const char *key); -} GsdMediaKeysManagerClass; +} MsdMediaKeysManagerClass; -GType gsd_media_keys_manager_get_type (void); +GType msd_media_keys_manager_get_type (void); -GsdMediaKeysManager * gsd_media_keys_manager_new (void); -gboolean gsd_media_keys_manager_start (GsdMediaKeysManager *manager, +MsdMediaKeysManager * msd_media_keys_manager_new (void); +gboolean msd_media_keys_manager_start (MsdMediaKeysManager *manager, GError **error); -void gsd_media_keys_manager_stop (GsdMediaKeysManager *manager); +void msd_media_keys_manager_stop (MsdMediaKeysManager *manager); -gboolean gsd_media_keys_manager_grab_media_player_keys (GsdMediaKeysManager *manager, +gboolean msd_media_keys_manager_grab_media_player_keys (MsdMediaKeysManager *manager, const char *application, guint32 time, GError **error); -gboolean gsd_media_keys_manager_release_media_player_keys (GsdMediaKeysManager *manager, +gboolean msd_media_keys_manager_release_media_player_keys (MsdMediaKeysManager *manager, const char *application, GError **error); @@ -69,4 +69,4 @@ gboolean gsd_media_keys_manager_release_media_player_keys (GsdMedia } #endif -#endif /* __GSD_MEDIA_KEYS_MANAGER_H */ +#endif /* __MSD_MEDIA_KEYS_MANAGER_H */ diff --git a/plugins/media-keys/gsd-media-keys-manager.xml b/plugins/media-keys/gsd-media-keys-manager.xml index 12cd03a..db0552e 100644 --- a/plugins/media-keys/gsd-media-keys-manager.xml +++ b/plugins/media-keys/gsd-media-keys-manager.xml @@ -1,7 +1,7 @@ - + diff --git a/plugins/media-keys/gsd-media-keys-plugin.c b/plugins/media-keys/gsd-media-keys-plugin.c index 319a42a..d76e233 100644 --- a/plugins/media-keys/gsd-media-keys-plugin.c +++ b/plugins/media-keys/gsd-media-keys-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-media-keys-plugin.h" -#include "gsd-media-keys-manager.h" +#include "msd-media-keys-plugin.h" +#include "msd-media-keys-manager.h" -struct GsdMediaKeysPluginPrivate { - GsdMediaKeysManager *manager; +struct MsdMediaKeysPluginPrivate { + MsdMediaKeysManager *manager; }; -#define GSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_MEDIA_KEYS_PLUGIN, GsdMediaKeysPluginPrivate)) +#define MSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdMediaKeysPlugin, gsd_media_keys_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdMediaKeysPlugin, msd_media_keys_plugin) static void -gsd_media_keys_plugin_init (GsdMediaKeysPlugin *plugin) +msd_media_keys_plugin_init (MsdMediaKeysPlugin *plugin) { - plugin->priv = GSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdMediaKeysPlugin initializing"); + g_debug ("MsdMediaKeysPlugin initializing"); - plugin->priv->manager = gsd_media_keys_manager_new (); + plugin->priv->manager = msd_media_keys_manager_new (); } static void -gsd_media_keys_plugin_finalize (GObject *object) +msd_media_keys_plugin_finalize (GObject *object) { - GsdMediaKeysPlugin *plugin; + MsdMediaKeysPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_MEDIA_KEYS_PLUGIN (object)); + g_return_if_fail (MSD_IS_MEDIA_KEYS_PLUGIN (object)); - g_debug ("GsdMediaKeysPlugin finalizing"); + g_debug ("MsdMediaKeysPlugin finalizing"); - plugin = GSD_MEDIA_KEYS_PLUGIN (object); + plugin = MSD_MEDIA_KEYS_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_media_keys_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_media_keys_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_media_keys_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating media_keys plugin"); error = NULL; - res = gsd_media_keys_manager_start (GSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager, &error); + res = msd_media_keys_manager_start (MSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start media_keys manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating media_keys plugin"); - gsd_media_keys_manager_stop (GSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager); + msd_media_keys_manager_stop (MSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager); } static void -gsd_media_keys_plugin_class_init (GsdMediaKeysPluginClass *klass) +msd_media_keys_plugin_class_init (MsdMediaKeysPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_media_keys_plugin_finalize; + object_class->finalize = msd_media_keys_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdMediaKeysPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdMediaKeysPluginPrivate)); } diff --git a/plugins/media-keys/gsd-media-keys-plugin.h b/plugins/media-keys/gsd-media-keys-plugin.h index fa092b5..c869d62 100644 --- a/plugins/media-keys/gsd-media-keys-plugin.h +++ b/plugins/media-keys/gsd-media-keys-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_MEDIA_KEYS_PLUGIN_H__ -#define __GSD_MEDIA_KEYS_PLUGIN_H__ +#ifndef __MSD_MEDIA_KEYS_PLUGIN_H__ +#define __MSD_MEDIA_KEYS_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_MEDIA_KEYS_PLUGIN (gsd_media_keys_plugin_get_type ()) -#define GSD_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_MEDIA_KEYS_PLUGIN, GsdMediaKeysPlugin)) -#define GSD_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_MEDIA_KEYS_PLUGIN, GsdMediaKeysPluginClass)) -#define GSD_IS_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_MEDIA_KEYS_PLUGIN)) -#define GSD_IS_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_MEDIA_KEYS_PLUGIN)) -#define GSD_MEDIA_KEYS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_MEDIA_KEYS_PLUGIN, GsdMediaKeysPluginClass)) +#define MSD_TYPE_MEDIA_KEYS_PLUGIN (msd_media_keys_plugin_get_type ()) +#define MSD_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPlugin)) +#define MSD_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginClass)) +#define MSD_IS_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN)) +#define MSD_IS_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_PLUGIN)) +#define MSD_MEDIA_KEYS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginClass)) -typedef struct GsdMediaKeysPluginPrivate GsdMediaKeysPluginPrivate; +typedef struct MsdMediaKeysPluginPrivate MsdMediaKeysPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdMediaKeysPluginPrivate *priv; -} GsdMediaKeysPlugin; + MsdMediaKeysPluginPrivate *priv; +} MsdMediaKeysPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdMediaKeysPluginClass; +} MsdMediaKeysPluginClass; -GType gsd_media_keys_plugin_get_type (void) G_GNUC_CONST; +GType msd_media_keys_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_MEDIA_KEYS_PLUGIN_H__ */ +#endif /* __MSD_MEDIA_KEYS_PLUGIN_H__ */ diff --git a/plugins/media-keys/gsd-media-keys-window.c b/plugins/media-keys/gsd-media-keys-window.c index 2547068..8bd6c33 100644 --- a/plugins/media-keys/gsd-media-keys-window.c +++ b/plugins/media-keys/gsd-media-keys-window.c @@ -30,13 +30,13 @@ #include #include -#include "gsd-media-keys-window.h" +#include "msd-media-keys-window.h" -#define GSD_MEDIA_KEYS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MEDIA_KEYS_WINDOW, GsdMediaKeysWindowPrivate)) +#define MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindowPrivate)) -struct GsdMediaKeysWindowPrivate +struct MsdMediaKeysWindowPrivate { - GsdMediaKeysWindowAction action; + MsdMediaKeysWindowAction action; char *icon_name; gboolean show_level; @@ -47,10 +47,10 @@ struct GsdMediaKeysWindowPrivate GtkWidget *progress; }; -G_DEFINE_TYPE (GsdMediaKeysWindow, gsd_media_keys_window, GSD_TYPE_OSD_WINDOW) +G_DEFINE_TYPE (MsdMediaKeysWindow, msd_media_keys_window, MSD_TYPE_OSD_WINDOW) static void -volume_controls_set_visible (GsdMediaKeysWindow *window, +volume_controls_set_visible (MsdMediaKeysWindow *window, gboolean visible) { if (window->priv->progress == NULL) @@ -64,7 +64,7 @@ volume_controls_set_visible (GsdMediaKeysWindow *window, } static void -window_set_icon_name (GsdMediaKeysWindow *window, +window_set_icon_name (MsdMediaKeysWindow *window, const char *name) { if (window->priv->image == NULL) @@ -75,11 +75,11 @@ window_set_icon_name (GsdMediaKeysWindow *window, } static void -action_changed (GsdMediaKeysWindow *window) +action_changed (MsdMediaKeysWindow *window) { - if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) { + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { switch (window->priv->action) { - case GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: + case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: volume_controls_set_visible (window, TRUE); if (window->priv->volume_muted) { @@ -89,7 +89,7 @@ action_changed (GsdMediaKeysWindow *window) } break; - case GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: + case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: volume_controls_set_visible (window, window->priv->show_level); window_set_icon_name (window, window->priv->icon_name); break; @@ -99,15 +99,15 @@ action_changed (GsdMediaKeysWindow *window) } } - gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window)); + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); } static void -volume_level_changed (GsdMediaKeysWindow *window) +volume_level_changed (MsdMediaKeysWindow *window) { - gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window)); + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); - if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window)) && window->priv->progress != NULL) { + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window)) && window->priv->progress != NULL) { double fraction; fraction = (double) window->priv->volume_level / 100.0; @@ -118,11 +118,11 @@ volume_level_changed (GsdMediaKeysWindow *window) } static void -volume_muted_changed (GsdMediaKeysWindow *window) +volume_muted_changed (MsdMediaKeysWindow *window) { - gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window)); + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); - if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) { + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { if (window->priv->volume_muted) { window_set_icon_name (window, "audio-volume-muted"); } else { @@ -132,46 +132,46 @@ volume_muted_changed (GsdMediaKeysWindow *window) } void -gsd_media_keys_window_set_action (GsdMediaKeysWindow *window, - GsdMediaKeysWindowAction action) +msd_media_keys_window_set_action (MsdMediaKeysWindow *window, + MsdMediaKeysWindowAction action) { - g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window)); - g_return_if_fail (action == GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); + g_return_if_fail (action == MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); if (window->priv->action != action) { window->priv->action = action; action_changed (window); } else { - gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window)); + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); } } void -gsd_media_keys_window_set_action_custom (GsdMediaKeysWindow *window, +msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window, const char *icon_name, gboolean show_level) { - g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window)); + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); g_return_if_fail (icon_name != NULL); - if (window->priv->action != GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM || + if (window->priv->action != MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM || g_strcmp0 (window->priv->icon_name, icon_name) != 0 || window->priv->show_level != show_level) { - window->priv->action = GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM; + window->priv->action = MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM; g_free (window->priv->icon_name); window->priv->icon_name = g_strdup (icon_name); window->priv->show_level = show_level; action_changed (window); } else { - gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window)); + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); } } void -gsd_media_keys_window_set_volume_muted (GsdMediaKeysWindow *window, +msd_media_keys_window_set_volume_muted (MsdMediaKeysWindow *window, gboolean muted) { - g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window)); + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); if (window->priv->volume_muted != muted) { window->priv->volume_muted = muted; @@ -180,10 +180,10 @@ gsd_media_keys_window_set_volume_muted (GsdMediaKeysWindow *window, } void -gsd_media_keys_window_set_volume_level (GsdMediaKeysWindow *window, +msd_media_keys_window_set_volume_level (MsdMediaKeysWindow *window, int level) { - g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window)); + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); if (window->priv->volume_level != level) { window->priv->volume_level = level; @@ -192,7 +192,7 @@ gsd_media_keys_window_set_volume_level (GsdMediaKeysWindow *window, } static GdkPixbuf * -load_pixbuf (GsdMediaKeysWindow *window, +load_pixbuf (MsdMediaKeysWindow *window, const char *name, int icon_size) { @@ -236,10 +236,10 @@ draw_eject (cairo_t *cr, cairo_rel_line_to (cr, -width / 2, -tri_height); cairo_rel_line_to (cr, -width / 2, tri_height); cairo_close_path (cr); - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, GSD_OSD_WINDOW_FG_ALPHA); + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); cairo_fill_preserve (cr); - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, GSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); cairo_set_line_width (cr, 2); cairo_stroke (cr); } @@ -298,12 +298,12 @@ draw_cross (cairo_t *cr, cairo_move_to (cr, cx, cy + size/2.0); cairo_rel_line_to (cr, size, -size); - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, GSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); cairo_set_line_width (cr, 14); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_stroke_preserve (cr); - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, GSD_OSD_WINDOW_FG_ALPHA); + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); cairo_set_line_width (cr, 10); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_stroke (cr); @@ -337,16 +337,16 @@ draw_speaker (cairo_t *cr, cairo_line_to (cr, _x0, _y0); cairo_close_path (cr); - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, GSD_OSD_WINDOW_FG_ALPHA); + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); cairo_fill_preserve (cr); - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, GSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); cairo_set_line_width (cr, 2); cairo_stroke (cr); } static gboolean -render_speaker (GsdMediaKeysWindow *window, +render_speaker (MsdMediaKeysWindow *window, cairo_t *cr, double _x0, double _y0, @@ -385,7 +385,7 @@ render_speaker (GsdMediaKeysWindow *window, } gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0); - cairo_paint_with_alpha (cr, GSD_OSD_WINDOW_FG_ALPHA); + cairo_paint_with_alpha (cr, MSD_OSD_WINDOW_FG_ALPHA); g_object_unref (pixbuf); @@ -393,7 +393,7 @@ render_speaker (GsdMediaKeysWindow *window, } static void -draw_volume_boxes (GsdMediaKeysWindow *window, +draw_volume_boxes (MsdMediaKeysWindow *window, cairo_t *cr, double percentage, double _x0, @@ -414,20 +414,20 @@ draw_volume_boxes (GsdMediaKeysWindow *window, style = gtk_widget_get_style (GTK_WIDGET (window)); /* bar background */ - gsd_osd_window_color_reverse (&style->dark[GTK_STATE_NORMAL], &color); + msd_osd_window_color_reverse (&style->dark[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; - gsd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height); - cairo_set_source_rgba (cr, r, g, b, GSD_OSD_WINDOW_FG_ALPHA / 2); + msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height); + cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); cairo_fill_preserve (cr); /* bar border */ - gsd_osd_window_color_reverse (&style->light[GTK_STATE_NORMAL], &color); + msd_osd_window_color_reverse (&style->light[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; - cairo_set_source_rgba (cr, r, g, b, GSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); cairo_set_line_width (cr, 1); cairo_stroke (cr); @@ -438,13 +438,13 @@ draw_volume_boxes (GsdMediaKeysWindow *window, r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; - gsd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0 + 0.5, _y0 + 0.5, height / 6 - 0.5, x1, height - 1); - cairo_set_source_rgba (cr, r, g, b, GSD_OSD_WINDOW_FG_ALPHA); + msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0 + 0.5, _y0 + 0.5, height / 6 - 0.5, x1, height - 1); + cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA); cairo_fill (cr); } static void -draw_action_volume (GsdMediaKeysWindow *window, +draw_action_volume (MsdMediaKeysWindow *window, cairo_t *cr) { int window_width; @@ -546,7 +546,7 @@ draw_action_volume (GsdMediaKeysWindow *window, } static gboolean -render_custom (GsdMediaKeysWindow *window, +render_custom (MsdMediaKeysWindow *window, cairo_t *cr, double _x0, double _y0, @@ -573,7 +573,7 @@ render_custom (GsdMediaKeysWindow *window, } gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0); - cairo_paint_with_alpha (cr, GSD_OSD_WINDOW_FG_ALPHA); + cairo_paint_with_alpha (cr, MSD_OSD_WINDOW_FG_ALPHA); g_object_unref (pixbuf); @@ -581,7 +581,7 @@ render_custom (GsdMediaKeysWindow *window, } static void -draw_action_custom (GsdMediaKeysWindow *window, +draw_action_custom (MsdMediaKeysWindow *window, cairo_t *cr) { int window_width; @@ -645,16 +645,16 @@ draw_action_custom (GsdMediaKeysWindow *window, } static void -gsd_media_keys_window_expose_when_composited (GsdOsdWindow *osd_window, +msd_media_keys_window_expose_when_composited (MsdOsdWindow *osd_window, cairo_t *cr) { - GsdMediaKeysWindow *window = GSD_MEDIA_KEYS_WINDOW (osd_window); + MsdMediaKeysWindow *window = MSD_MEDIA_KEYS_WINDOW (osd_window); switch (window->priv->action) { - case GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: + case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: draw_action_volume (window, cr); break; - case GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: + case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: draw_action_custom (window, cr); break; default: @@ -663,25 +663,25 @@ gsd_media_keys_window_expose_when_composited (GsdOsdWindow *osd_window, } static void -gsd_media_keys_window_class_init (GsdMediaKeysWindowClass *klass) +msd_media_keys_window_class_init (MsdMediaKeysWindowClass *klass) { - GsdOsdWindowClass *osd_window_class = GSD_OSD_WINDOW_CLASS (klass); + MsdOsdWindowClass *osd_window_class = MSD_OSD_WINDOW_CLASS (klass); - osd_window_class->expose_when_composited = gsd_media_keys_window_expose_when_composited; + osd_window_class->expose_when_composited = msd_media_keys_window_expose_when_composited; - g_type_class_add_private (klass, sizeof (GsdMediaKeysWindowPrivate)); + g_type_class_add_private (klass, sizeof (MsdMediaKeysWindowPrivate)); } static void -gsd_media_keys_window_init (GsdMediaKeysWindow *window) +msd_media_keys_window_init (MsdMediaKeysWindow *window) { GdkScreen *screen; - window->priv = GSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window); + window->priv = MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window); screen = gtk_widget_get_screen (GTK_WIDGET (window)); - if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) { + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { GtkBuilder *builder; const gchar *objects[] = {"acme_box", NULL}; GtkWidget *box; @@ -708,7 +708,7 @@ gsd_media_keys_window_init (GsdMediaKeysWindow *window) } GtkWidget * -gsd_media_keys_window_new (void) +msd_media_keys_window_new (void) { - return g_object_new (GSD_TYPE_MEDIA_KEYS_WINDOW, NULL); + return g_object_new (MSD_TYPE_MEDIA_KEYS_WINDOW, NULL); } diff --git a/plugins/media-keys/gsd-media-keys-window.h b/plugins/media-keys/gsd-media-keys-window.h index 236d011..c0e5739 100644 --- a/plugins/media-keys/gsd-media-keys-window.h +++ b/plugins/media-keys/gsd-media-keys-window.h @@ -20,56 +20,56 @@ * */ -#ifndef GSD_MEDIA_KEYS_WINDOW_H -#define GSD_MEDIA_KEYS_WINDOW_H +#ifndef MSD_MEDIA_KEYS_WINDOW_H +#define MSD_MEDIA_KEYS_WINDOW_H #include #include -#include "gsd-osd-window.h" +#include "msd-osd-window.h" #ifdef __cplusplus extern "C" { #endif -#define GSD_TYPE_MEDIA_KEYS_WINDOW (gsd_media_keys_window_get_type ()) -#define GSD_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_MEDIA_KEYS_WINDOW, GsdMediaKeysWindow)) -#define GSD_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_MEDIA_KEYS_WINDOW, GsdMediaKeysWindowClass)) -#define GSD_IS_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_MEDIA_KEYS_WINDOW)) -#define GSD_IS_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), GSD_TYPE_MEDIA_KEYS_WINDOW)) +#define MSD_TYPE_MEDIA_KEYS_WINDOW (msd_media_keys_window_get_type ()) +#define MSD_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindow)) +#define MSD_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindowClass)) +#define MSD_IS_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_MEDIA_KEYS_WINDOW)) +#define MSD_IS_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_MEDIA_KEYS_WINDOW)) -typedef struct GsdMediaKeysWindow GsdMediaKeysWindow; -typedef struct GsdMediaKeysWindowClass GsdMediaKeysWindowClass; -typedef struct GsdMediaKeysWindowPrivate GsdMediaKeysWindowPrivate; +typedef struct MsdMediaKeysWindow MsdMediaKeysWindow; +typedef struct MsdMediaKeysWindowClass MsdMediaKeysWindowClass; +typedef struct MsdMediaKeysWindowPrivate MsdMediaKeysWindowPrivate; -struct GsdMediaKeysWindow { - GsdOsdWindow parent; +struct MsdMediaKeysWindow { + MsdOsdWindow parent; - GsdMediaKeysWindowPrivate *priv; + MsdMediaKeysWindowPrivate *priv; }; -struct GsdMediaKeysWindowClass { - GsdOsdWindowClass parent_class; +struct MsdMediaKeysWindowClass { + MsdOsdWindowClass parent_class; }; typedef enum { - GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME, - GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM -} GsdMediaKeysWindowAction; + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME, + MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM +} MsdMediaKeysWindowAction; -GType gsd_media_keys_window_get_type (void); +GType msd_media_keys_window_get_type (void); -GtkWidget * gsd_media_keys_window_new (void); -void gsd_media_keys_window_set_action (GsdMediaKeysWindow *window, - GsdMediaKeysWindowAction action); -void gsd_media_keys_window_set_action_custom (GsdMediaKeysWindow *window, +GtkWidget * msd_media_keys_window_new (void); +void msd_media_keys_window_set_action (MsdMediaKeysWindow *window, + MsdMediaKeysWindowAction action); +void msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window, const char *icon_name, gboolean show_level); -void gsd_media_keys_window_set_volume_muted (GsdMediaKeysWindow *window, +void msd_media_keys_window_set_volume_muted (MsdMediaKeysWindow *window, gboolean muted); -void gsd_media_keys_window_set_volume_level (GsdMediaKeysWindow *window, +void msd_media_keys_window_set_volume_level (MsdMediaKeysWindow *window, int level); -gboolean gsd_media_keys_window_is_valid (GsdMediaKeysWindow *window); +gboolean msd_media_keys_window_is_valid (MsdMediaKeysWindow *window); #ifdef __cplusplus } diff --git a/plugins/media-keys/test-media-keys.c b/plugins/media-keys/test-media-keys.c index e3345f9..6505550 100644 --- a/plugins/media-keys/test-media-keys.c +++ b/plugins/media-keys/test-media-keys.c @@ -27,9 +27,9 @@ #include #include -#include "gsd-media-keys-manager.h" +#include "msd-media-keys-manager.h" -static GsdMediaKeysManager *manager = NULL; +static MsdMediaKeysManager *manager = NULL; int main (int argc, @@ -53,10 +53,10 @@ main (int argc, exit (1); } - manager = gsd_media_keys_manager_new (); + manager = msd_media_keys_manager_new (); error = NULL; - res = gsd_media_keys_manager_start (manager, &error); + res = msd_media_keys_manager_start (manager, &error); gtk_main (); diff --git a/plugins/media-keys/test-media-window.c b/plugins/media-keys/test-media-window.c index c97f3d9..8860999 100644 --- a/plugins/media-keys/test-media-window.c +++ b/plugins/media-keys/test-media-window.c @@ -27,7 +27,7 @@ #include #include -#include "gsd-media-keys-window.h" +#include "msd-media-keys-window.h" static gboolean update_state (GtkWidget *window) @@ -38,58 +38,58 @@ update_state (GtkWidget *window) switch (count) { case 1: - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (window), 50); - gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window), - GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (window), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); gtk_widget_show (window); break; case 2: - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (window), 100); - gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window), - GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (window), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); gtk_widget_show (window); break; case 3: - gsd_media_keys_window_set_volume_muted (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (window), TRUE); - gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window), - GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (window), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); gtk_widget_show (window); break; case 4: - gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (window), "media-eject", FALSE); gtk_widget_show (window); break; case 5: - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (window), 0); - gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (window), "gpm-brightness-lcd", TRUE); gtk_widget_show (window); break; case 6: - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (window), 50); - gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (window), "gpm-brightness-lcd", TRUE); gtk_widget_show (window); break; case 7: - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (window), 100); - gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (window), "gpm-brightness-lcd", TRUE); @@ -108,13 +108,13 @@ test_window (void) { GtkWidget *window; - window = gsd_media_keys_window_new (); + window = msd_media_keys_window_new (); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS); - gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window), + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (window), 0); - gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window), - GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (window), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); gtk_widget_show (window); diff --git a/plugins/mouse/Makefile.am b/plugins/mouse/Makefile.am index f99aefc..8e1ab77 100644 --- a/plugins/mouse/Makefile.am +++ b/plugins/mouse/Makefile.am @@ -1,10 +1,10 @@ plugin_LTLIBRARIES = libmouse.la libmouse_la_SOURCES = \ - gsd-mouse-plugin.h \ - gsd-mouse-plugin.c \ - gsd-mouse-manager.h \ - gsd-mouse-manager.c + msd-mouse-plugin.h \ + msd-mouse-plugin.c \ + msd-mouse-manager.h \ + msd-mouse-manager.c libmouse_la_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ @@ -17,7 +17,7 @@ libmouse_la_CFLAGS = \ $(AM_CFLAGS) libmouse_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) + $(MSD_PLUGIN_LDFLAGS) libmouse_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) \ @@ -28,19 +28,19 @@ plugin_in_files = mouse.mate-settings-plugin.in plugin_DATA = $(plugin_in_files:.mate-settings-plugin.in=.mate-settings-plugin) -libexec_PROGRAMS = gsd-locate-pointer +libexec_PROGRAMS = msd-locate-pointer -gsd_locate_pointer_SOURCES = \ - gsd-locate-pointer.h \ - gsd-locate-pointer.c \ - gsd-timeline.h \ - gsd-timeline.c +msd_locate_pointer_SOURCES = \ + msd-locate-pointer.h \ + msd-locate-pointer.c \ + msd-timeline.h \ + msd-timeline.c -gsd_locate_pointer_CFLAGS = \ +msd_locate_pointer_CFLAGS = \ $(SETTINGS_PLUGIN_CFLAGS) \ $(AM_CFLAGS) -gsd_locate_pointer_LDADD = \ +msd_locate_pointer_LDADD = \ $(SETTINGS_PLUGIN_LIBS) \ $(X11_LIBS) \ -lm @@ -49,4 +49,4 @@ EXTRA_DIST = $(plugin_in_files) CLEANFILES = $(plugin_DATA) DISTCLEANFILES = $(plugin_DATA) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/mouse/gsd-locate-pointer.c b/plugins/mouse/gsd-locate-pointer.c index acb2445..8582074 100644 --- a/plugins/mouse/gsd-locate-pointer.c +++ b/plugins/mouse/gsd-locate-pointer.c @@ -1,4 +1,4 @@ -/* gsd-locate-pointer.c +/* msd-locate-pointer.c * * Copyright (C) 2008 Carlos Garnacho * @@ -18,8 +18,8 @@ */ #include -#include "gsd-timeline.h" -#include "gsd-locate-pointer.h" +#include "msd-timeline.h" +#include "msd-locate-pointer.h" #include #include @@ -37,21 +37,21 @@ #define CIRCLES_PROGRESS_INTERVAL (0.5 / N_CIRCLES) #define CIRCLE_PROGRESS(p) (MIN (1., ((gdouble) (p) * 2.))) -typedef struct GsdLocatePointerData GsdLocatePointerData; +typedef struct MsdLocatePointerData MsdLocatePointerData; -struct GsdLocatePointerData +struct MsdLocatePointerData { - GsdTimeline *timeline; + MsdTimeline *timeline; GtkWidget *widget; GdkWindow *window; gdouble progress; }; -static GsdLocatePointerData *data = NULL; +static MsdLocatePointerData *data = NULL; static void -locate_pointer_paint (GsdLocatePointerData *data, +locate_pointer_paint (MsdLocatePointerData *data, cairo_t *cr, gboolean composite) { @@ -131,7 +131,7 @@ locate_pointer_expose (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { - GsdLocatePointerData *data = (GsdLocatePointerData *) user_data; + MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; cairo_t *cr; if (event->window != data->window) @@ -145,7 +145,7 @@ locate_pointer_expose (GtkWidget *widget, } static void -update_shape (GsdLocatePointerData *data) +update_shape (MsdLocatePointerData *data) { cairo_t *cr; GdkBitmap *mask; @@ -159,11 +159,11 @@ update_shape (GsdLocatePointerData *data) } static void -timeline_frame_cb (GsdTimeline *timeline, +timeline_frame_cb (MsdTimeline *timeline, gdouble progress, gpointer user_data) { - GsdLocatePointerData *data = (GsdLocatePointerData *) user_data; + MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; GdkScreen *screen; gint cursor_x, cursor_y; @@ -214,7 +214,7 @@ unset_transparent_shape (GdkWindow *window) static void composited_changed (GtkWidget *widget, - GsdLocatePointerData *data) + MsdLocatePointerData *data) { if (!gtk_widget_is_composited (widget)) set_transparent_shape (data->window); @@ -223,10 +223,10 @@ composited_changed (GtkWidget *widget, } static void -timeline_finished_cb (GsdTimeline *timeline, +timeline_finished_cb (MsdTimeline *timeline, gpointer user_data) { - GsdLocatePointerData *data = (GsdLocatePointerData *) user_data; + MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; /* set transparent shape and hide window */ if (!gtk_widget_is_composited (data->widget)) @@ -236,7 +236,7 @@ timeline_finished_cb (GsdTimeline *timeline, } static void -create_window (GsdLocatePointerData *data, +create_window (MsdLocatePointerData *data, GdkScreen *screen) { GdkColormap *colormap; @@ -267,12 +267,12 @@ create_window (GsdLocatePointerData *data, gdk_window_set_user_data (data->window, data->widget); } -static GsdLocatePointerData * -gsd_locate_pointer_data_new (GdkScreen *screen) +static MsdLocatePointerData * +msd_locate_pointer_data_new (GdkScreen *screen) { - GsdLocatePointerData *data; + MsdLocatePointerData *data; - data = g_new0 (GsdLocatePointerData, 1); + data = g_new0 (MsdLocatePointerData, 1); /* this widget will never be shown, it's * mainly used to get signals/events from @@ -284,7 +284,7 @@ gsd_locate_pointer_data_new (GdkScreen *screen) G_CALLBACK (locate_pointer_expose), data); - data->timeline = gsd_timeline_new (ANIMATION_LENGTH); + data->timeline = msd_timeline_new (ANIMATION_LENGTH); g_signal_connect (data->timeline, "frame", G_CALLBACK (timeline_frame_cb), data); g_signal_connect (data->timeline, "finished", @@ -296,7 +296,7 @@ gsd_locate_pointer_data_new (GdkScreen *screen) } static void -move_locate_pointer_window (GsdLocatePointerData *data, +move_locate_pointer_window (MsdLocatePointerData *data, GdkScreen *screen) { gint cursor_x, cursor_y; @@ -326,13 +326,13 @@ move_locate_pointer_window (GsdLocatePointerData *data, } void -gsd_locate_pointer (GdkScreen *screen) +msd_locate_pointer (GdkScreen *screen) { if (!data) - data = gsd_locate_pointer_data_new (screen); + data = msd_locate_pointer_data_new (screen); - gsd_timeline_pause (data->timeline); - gsd_timeline_rewind (data->timeline); + msd_timeline_pause (data->timeline); + msd_timeline_rewind (data->timeline); /* Create again the window if it is not for the current screen */ if (gdk_screen_get_number (screen) != gdk_screen_get_number (gdk_drawable_get_screen (data->window))) @@ -352,7 +352,7 @@ gsd_locate_pointer (GdkScreen *screen) composited_changed (data->widget, data); gdk_window_show (data->window); - gsd_timeline_start (data->timeline); + msd_timeline_start (data->timeline); } @@ -394,7 +394,7 @@ filter (GdkXEvent *xevent, XAllowEvents (xev->xkey.display, AsyncKeyboard, xev->xkey.time); - gsd_locate_pointer (screen); + msd_locate_pointer (screen); } } else diff --git a/plugins/mouse/gsd-locate-pointer.h b/plugins/mouse/gsd-locate-pointer.h index 3b261a5..c21da43 100644 --- a/plugins/mouse/gsd-locate-pointer.h +++ b/plugins/mouse/gsd-locate-pointer.h @@ -19,6 +19,6 @@ #include -void gsd_locate_pointer (GdkScreen *screen); +void msd_locate_pointer (GdkScreen *screen); #endif diff --git a/plugins/mouse/gsd-mouse-manager.c b/plugins/mouse/gsd-mouse-manager.c index d843314..d7cb8e4 100644 --- a/plugins/mouse/gsd-mouse-manager.c +++ b/plugins/mouse/gsd-mouse-manager.c @@ -48,9 +48,9 @@ #include #include "mate-settings-profile.h" -#include "gsd-mouse-manager.h" +#include "msd-mouse-manager.h" -#define GSD_MOUSE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MOUSE_MANAGER, GsdMouseManagerPrivate)) +#define MSD_MOUSE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerPrivate)) #define MATECONF_MOUSE_DIR "/desktop/mate/peripherals/mouse" #define MATECONF_MOUSE_A11Y_DIR "/desktop/mate/accessibility/mouse" @@ -70,7 +70,7 @@ #define KEY_TOUCHPAD_ENABLED MATECONF_TOUCHPAD_DIR "/touchpad_enabled" #endif -struct GsdMouseManagerPrivate +struct MsdMouseManagerPrivate { guint notify; guint notify_a11y; @@ -83,28 +83,28 @@ struct GsdMouseManagerPrivate GPid locate_pointer_pid; }; -static void gsd_mouse_manager_class_init (GsdMouseManagerClass *klass); -static void gsd_mouse_manager_init (GsdMouseManager *mouse_manager); -static void gsd_mouse_manager_finalize (GObject *object); -static void set_mouse_settings (GsdMouseManager *manager); +static void msd_mouse_manager_class_init (MsdMouseManagerClass *klass); +static void msd_mouse_manager_init (MsdMouseManager *mouse_manager); +static void msd_mouse_manager_finalize (GObject *object); +static void set_mouse_settings (MsdMouseManager *manager); #ifdef HAVE_X11_EXTENSIONS_XINPUT_H static int set_tap_to_click (gboolean state, gboolean left_handed); static XDevice* device_is_touchpad (XDeviceInfo deviceinfo); #endif -G_DEFINE_TYPE (GsdMouseManager, gsd_mouse_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdMouseManager, msd_mouse_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void -gsd_mouse_manager_set_property (GObject *object, +msd_mouse_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdMouseManager *self; + MsdMouseManager *self; - self = GSD_MOUSE_MANAGER (object); + self = MSD_MOUSE_MANAGER (object); switch (prop_id) { default: @@ -114,14 +114,14 @@ gsd_mouse_manager_set_property (GObject *object, } static void -gsd_mouse_manager_get_property (GObject *object, +msd_mouse_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdMouseManager *self; + MsdMouseManager *self; - self = GSD_MOUSE_MANAGER (object); + self = MSD_MOUSE_MANAGER (object); switch (prop_id) { default: @@ -131,16 +131,16 @@ gsd_mouse_manager_get_property (GObject *object, } static GObject * -gsd_mouse_manager_constructor (GType type, +msd_mouse_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdMouseManager *mouse_manager; - GsdMouseManagerClass *klass; + MsdMouseManager *mouse_manager; + MsdMouseManagerClass *klass; - klass = GSD_MOUSE_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_MOUSE_MANAGER)); + klass = MSD_MOUSE_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_MOUSE_MANAGER)); - mouse_manager = GSD_MOUSE_MANAGER (G_OBJECT_CLASS (gsd_mouse_manager_parent_class)->constructor (type, + mouse_manager = MSD_MOUSE_MANAGER (G_OBJECT_CLASS (msd_mouse_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -148,27 +148,27 @@ gsd_mouse_manager_constructor (GType type, } static void -gsd_mouse_manager_dispose (GObject *object) +msd_mouse_manager_dispose (GObject *object) { - GsdMouseManager *mouse_manager; + MsdMouseManager *mouse_manager; - mouse_manager = GSD_MOUSE_MANAGER (object); + mouse_manager = MSD_MOUSE_MANAGER (object); - G_OBJECT_CLASS (gsd_mouse_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_mouse_manager_parent_class)->dispose (object); } static void -gsd_mouse_manager_class_init (GsdMouseManagerClass *klass) +msd_mouse_manager_class_init (MsdMouseManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_mouse_manager_get_property; - object_class->set_property = gsd_mouse_manager_set_property; - object_class->constructor = gsd_mouse_manager_constructor; - object_class->dispose = gsd_mouse_manager_dispose; - object_class->finalize = gsd_mouse_manager_finalize; + object_class->get_property = msd_mouse_manager_get_property; + object_class->set_property = msd_mouse_manager_set_property; + object_class->constructor = msd_mouse_manager_constructor; + object_class->dispose = msd_mouse_manager_dispose; + object_class->finalize = msd_mouse_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdMouseManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdMouseManagerPrivate)); } @@ -386,13 +386,13 @@ devicepresence_filter (GdkXEvent *xevent, { XDevicePresenceNotifyEvent *dpn = (XDevicePresenceNotifyEvent *) xev; if (dpn->devchange == DeviceEnabled) - set_mouse_settings ((GsdMouseManager *) data); + set_mouse_settings ((MsdMouseManager *) data); } return GDK_FILTER_CONTINUE; } static void -set_devicepresence_handler (GsdMouseManager *manager) +set_devicepresence_handler (MsdMouseManager *manager) { Display *display; XEventClass class_presence; @@ -416,7 +416,7 @@ set_devicepresence_handler (GsdMouseManager *manager) #endif static void -set_left_handed (GsdMouseManager *manager, +set_left_handed (MsdMouseManager *manager, gboolean left_handed) { guchar *buttons ; @@ -462,7 +462,7 @@ set_left_handed (GsdMouseManager *manager, } static void -set_motion_acceleration (GsdMouseManager *manager, +set_motion_acceleration (MsdMouseManager *manager, gfloat motion_acceleration) { gint numerator, denominator; @@ -498,7 +498,7 @@ set_motion_acceleration (GsdMouseManager *manager, } static void -set_motion_threshold (GsdMouseManager *manager, +set_motion_threshold (MsdMouseManager *manager, int motion_threshold) { XChangePointerControl (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), False, True, @@ -543,7 +543,7 @@ device_is_touchpad (XDeviceInfo deviceinfo) #endif static int -set_disable_w_typing (GsdMouseManager *manager, gboolean state) +set_disable_w_typing (MsdMouseManager *manager, gboolean state) { if (state) { @@ -805,7 +805,7 @@ set_touchpad_enabled (gboolean state) #endif static void -set_locate_pointer (GsdMouseManager *manager, +set_locate_pointer (MsdMouseManager *manager, gboolean state) { if (state) { @@ -815,7 +815,7 @@ set_locate_pointer (GsdMouseManager *manager, if (manager->priv->locate_pointer_spawned) return; - args[0] = LIBEXECDIR "/gsd-locate-pointer"; + args[0] = LIBEXECDIR "/msd-locate-pointer"; args[1] = NULL; g_spawn_async (NULL, args, NULL, @@ -841,7 +841,7 @@ set_locate_pointer (GsdMouseManager *manager, } static void -set_mousetweaks_daemon (GsdMouseManager *manager, +set_mousetweaks_daemon (MsdMouseManager *manager, gboolean dwell_enable, gboolean delay_enable) { @@ -896,7 +896,7 @@ set_mousetweaks_daemon (GsdMouseManager *manager, } static void -set_mouse_settings (GsdMouseManager *manager) +set_mouse_settings (MsdMouseManager *manager) { MateConfClient *client = mateconf_client_get_default (); gboolean left_handed = mateconf_client_get_bool (client, KEY_LEFT_HANDED, NULL); @@ -920,7 +920,7 @@ static void mouse_callback (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdMouseManager *manager) + MsdMouseManager *manager) { if (! strcmp (entry->key, KEY_LEFT_HANDED)) { if (entry->value->type == MATECONF_VALUE_BOOL) { @@ -978,7 +978,7 @@ mouse_callback (MateConfClient *client, } static guint -register_config_callback (GsdMouseManager *manager, +register_config_callback (MsdMouseManager *manager, MateConfClient *client, const char *path, MateConfClientNotifyFunc func) @@ -988,13 +988,13 @@ register_config_callback (GsdMouseManager *manager, } static void -gsd_mouse_manager_init (GsdMouseManager *manager) +msd_mouse_manager_init (MsdMouseManager *manager) { - manager->priv = GSD_MOUSE_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_MOUSE_MANAGER_GET_PRIVATE (manager); } static gboolean -gsd_mouse_manager_idle_cb (GsdMouseManager *manager) +msd_mouse_manager_idle_cb (MsdMouseManager *manager) { MateConfClient *client; @@ -1045,12 +1045,12 @@ gsd_mouse_manager_idle_cb (GsdMouseManager *manager) } gboolean -gsd_mouse_manager_start (GsdMouseManager *manager, +msd_mouse_manager_start (MsdMouseManager *manager, GError **error) { mate_settings_profile_start (NULL); - g_idle_add ((GSourceFunc) gsd_mouse_manager_idle_cb, manager); + g_idle_add ((GSourceFunc) msd_mouse_manager_idle_cb, manager); mate_settings_profile_end (NULL); @@ -1058,9 +1058,9 @@ gsd_mouse_manager_start (GsdMouseManager *manager, } void -gsd_mouse_manager_stop (GsdMouseManager *manager) +msd_mouse_manager_stop (MsdMouseManager *manager) { - GsdMouseManagerPrivate *p = manager->priv; + MsdMouseManagerPrivate *p = manager->priv; MateConfClient *client; g_debug ("Stopping mouse manager"); @@ -1095,30 +1095,30 @@ gsd_mouse_manager_stop (GsdMouseManager *manager) } static void -gsd_mouse_manager_finalize (GObject *object) +msd_mouse_manager_finalize (GObject *object) { - GsdMouseManager *mouse_manager; + MsdMouseManager *mouse_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_MOUSE_MANAGER (object)); + g_return_if_fail (MSD_IS_MOUSE_MANAGER (object)); - mouse_manager = GSD_MOUSE_MANAGER (object); + mouse_manager = MSD_MOUSE_MANAGER (object); g_return_if_fail (mouse_manager->priv != NULL); - G_OBJECT_CLASS (gsd_mouse_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_mouse_manager_parent_class)->finalize (object); } -GsdMouseManager * -gsd_mouse_manager_new (void) +MsdMouseManager * +msd_mouse_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_MOUSE_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_MOUSE_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_MOUSE_MANAGER (manager_object); + return MSD_MOUSE_MANAGER (manager_object); } diff --git a/plugins/mouse/gsd-mouse-manager.h b/plugins/mouse/gsd-mouse-manager.h index f8f513c..e691d7b 100644 --- a/plugins/mouse/gsd-mouse-manager.h +++ b/plugins/mouse/gsd-mouse-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_MOUSE_MANAGER_H -#define __GSD_MOUSE_MANAGER_H +#ifndef __MSD_MOUSE_MANAGER_H +#define __MSD_MOUSE_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_MOUSE_MANAGER (gsd_mouse_manager_get_type ()) -#define GSD_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_MOUSE_MANAGER, GsdMouseManager)) -#define GSD_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_MOUSE_MANAGER, GsdMouseManagerClass)) -#define GSD_IS_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_MOUSE_MANAGER)) -#define GSD_IS_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_MOUSE_MANAGER)) -#define GSD_MOUSE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_MOUSE_MANAGER, GsdMouseManagerClass)) +#define MSD_TYPE_MOUSE_MANAGER (msd_mouse_manager_get_type ()) +#define MSD_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManager)) +#define MSD_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerClass)) +#define MSD_IS_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MOUSE_MANAGER)) +#define MSD_IS_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MOUSE_MANAGER)) +#define MSD_MOUSE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerClass)) -typedef struct GsdMouseManagerPrivate GsdMouseManagerPrivate; +typedef struct MsdMouseManagerPrivate MsdMouseManagerPrivate; typedef struct { GObject parent; - GsdMouseManagerPrivate *priv; -} GsdMouseManager; + MsdMouseManagerPrivate *priv; +} MsdMouseManager; typedef struct { GObjectClass parent_class; -} GsdMouseManagerClass; +} MsdMouseManagerClass; -GType gsd_mouse_manager_get_type (void); +GType msd_mouse_manager_get_type (void); -GsdMouseManager * gsd_mouse_manager_new (void); -gboolean gsd_mouse_manager_start (GsdMouseManager *manager, +MsdMouseManager * msd_mouse_manager_new (void); +gboolean msd_mouse_manager_start (MsdMouseManager *manager, GError **error); -void gsd_mouse_manager_stop (GsdMouseManager *manager); +void msd_mouse_manager_stop (MsdMouseManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_MOUSE_MANAGER_H */ +#endif /* __MSD_MOUSE_MANAGER_H */ diff --git a/plugins/mouse/gsd-mouse-plugin.c b/plugins/mouse/gsd-mouse-plugin.c index 900a6d5..7203002 100644 --- a/plugins/mouse/gsd-mouse-plugin.c +++ b/plugins/mouse/gsd-mouse-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-mouse-plugin.h" -#include "gsd-mouse-manager.h" +#include "msd-mouse-plugin.h" +#include "msd-mouse-manager.h" -struct GsdMousePluginPrivate { - GsdMouseManager *manager; +struct MsdMousePluginPrivate { + MsdMouseManager *manager; }; -#define GSD_MOUSE_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_MOUSE_PLUGIN, GsdMousePluginPrivate)) +#define MSD_MOUSE_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdMousePlugin, gsd_mouse_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdMousePlugin, msd_mouse_plugin) static void -gsd_mouse_plugin_init (GsdMousePlugin *plugin) +msd_mouse_plugin_init (MsdMousePlugin *plugin) { - plugin->priv = GSD_MOUSE_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_MOUSE_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdMousePlugin initializing"); + g_debug ("MsdMousePlugin initializing"); - plugin->priv->manager = gsd_mouse_manager_new (); + plugin->priv->manager = msd_mouse_manager_new (); } static void -gsd_mouse_plugin_finalize (GObject *object) +msd_mouse_plugin_finalize (GObject *object) { - GsdMousePlugin *plugin; + MsdMousePlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_MOUSE_PLUGIN (object)); + g_return_if_fail (MSD_IS_MOUSE_PLUGIN (object)); - g_debug ("GsdMousePlugin finalizing"); + g_debug ("MsdMousePlugin finalizing"); - plugin = GSD_MOUSE_PLUGIN (object); + plugin = MSD_MOUSE_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_mouse_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_mouse_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_mouse_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating mouse plugin"); error = NULL; - res = gsd_mouse_manager_start (GSD_MOUSE_PLUGIN (plugin)->priv->manager, &error); + res = msd_mouse_manager_start (MSD_MOUSE_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start mouse manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating mouse plugin"); - gsd_mouse_manager_stop (GSD_MOUSE_PLUGIN (plugin)->priv->manager); + msd_mouse_manager_stop (MSD_MOUSE_PLUGIN (plugin)->priv->manager); } static void -gsd_mouse_plugin_class_init (GsdMousePluginClass *klass) +msd_mouse_plugin_class_init (MsdMousePluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_mouse_plugin_finalize; + object_class->finalize = msd_mouse_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdMousePluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdMousePluginPrivate)); } diff --git a/plugins/mouse/gsd-mouse-plugin.h b/plugins/mouse/gsd-mouse-plugin.h index e442450..2c2da6c 100644 --- a/plugins/mouse/gsd-mouse-plugin.h +++ b/plugins/mouse/gsd-mouse-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_MOUSE_PLUGIN_H__ -#define __GSD_MOUSE_PLUGIN_H__ +#ifndef __MSD_MOUSE_PLUGIN_H__ +#define __MSD_MOUSE_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_MOUSE_PLUGIN (gsd_mouse_plugin_get_type ()) -#define GSD_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_MOUSE_PLUGIN, GsdMousePlugin)) -#define GSD_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_MOUSE_PLUGIN, GsdMousePluginClass)) -#define GSD_IS_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_MOUSE_PLUGIN)) -#define GSD_IS_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_MOUSE_PLUGIN)) -#define GSD_MOUSE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_MOUSE_PLUGIN, GsdMousePluginClass)) +#define MSD_TYPE_MOUSE_PLUGIN (msd_mouse_plugin_get_type ()) +#define MSD_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MOUSE_PLUGIN, MsdMousePlugin)) +#define MSD_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginClass)) +#define MSD_IS_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MOUSE_PLUGIN)) +#define MSD_IS_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MOUSE_PLUGIN)) +#define MSD_MOUSE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginClass)) -typedef struct GsdMousePluginPrivate GsdMousePluginPrivate; +typedef struct MsdMousePluginPrivate MsdMousePluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdMousePluginPrivate *priv; -} GsdMousePlugin; + MsdMousePluginPrivate *priv; +} MsdMousePlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdMousePluginClass; +} MsdMousePluginClass; -GType gsd_mouse_plugin_get_type (void) G_GNUC_CONST; +GType msd_mouse_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_MOUSE_PLUGIN_H__ */ +#endif /* __MSD_MOUSE_PLUGIN_H__ */ diff --git a/plugins/mouse/gsd-timeline.c b/plugins/mouse/gsd-timeline.c index 748a0ad..9bcfd2f 100644 --- a/plugins/mouse/gsd-timeline.c +++ b/plugins/mouse/gsd-timeline.c @@ -1,4 +1,4 @@ -/* gsd-timeline.c +/* msd-timeline.c * * Copyright (C) 2008 Carlos Garnacho * @@ -20,16 +20,16 @@ #include #include #include -#include "gsd-timeline.h" +#include "msd-timeline.h" -#define GSD_TIMELINE_GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GSD_TYPE_TIMELINE, GsdTimelinePriv)) +#define MSD_TIMELINE_GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSD_TYPE_TIMELINE, MsdTimelinePriv)) #define MSECS_PER_SEC 1000 #define FRAME_INTERVAL(nframes) (MSECS_PER_SEC / nframes) #define DEFAULT_FPS 30 -typedef struct GsdTimelinePriv GsdTimelinePriv; +typedef struct MsdTimelinePriv MsdTimelinePriv; -struct GsdTimelinePriv +struct MsdTimelinePriv { guint duration; guint fps; @@ -38,8 +38,8 @@ struct GsdTimelinePriv GTimer *timer; GdkScreen *screen; - GsdTimelineProgressType progress_type; - GsdTimelineProgressFunc progress_func; + MsdTimelineProgressType progress_type; + MsdTimelineProgressFunc progress_func; guint loop : 1; guint direction : 1; @@ -66,67 +66,67 @@ enum { static guint signals [LAST_SIGNAL] = { 0, }; -static void gsd_timeline_set_property (GObject *object, +static void msd_timeline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gsd_timeline_get_property (GObject *object, +static void msd_timeline_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gsd_timeline_finalize (GObject *object); +static void msd_timeline_finalize (GObject *object); -G_DEFINE_TYPE (GsdTimeline, gsd_timeline, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdTimeline, msd_timeline, G_TYPE_OBJECT) GType -gsd_timeline_direction_get_type (void) +msd_timeline_direction_get_type (void) { static GType type = 0; if (G_UNLIKELY (type == 0)) { static const GEnumValue values[] = { - { GSD_TIMELINE_DIRECTION_FORWARD, "GSD_TIMELINE_DIRECTION_FORWARD", "forward" }, - { GSD_TIMELINE_DIRECTION_BACKWARD, "GSD_TIMELINE_DIRECTION_BACKWARD", "backward" }, + { MSD_TIMELINE_DIRECTION_FORWARD, "MSD_TIMELINE_DIRECTION_FORWARD", "forward" }, + { MSD_TIMELINE_DIRECTION_BACKWARD, "MSD_TIMELINE_DIRECTION_BACKWARD", "backward" }, { 0, NULL, NULL } }; - type = g_enum_register_static (g_intern_static_string ("GsdTimelineDirection"), values); + type = g_enum_register_static (g_intern_static_string ("MsdTimelineDirection"), values); } return type; } GType -gsd_timeline_progress_type_get_type (void) +msd_timeline_progress_type_get_type (void) { static GType type = 0; if (G_UNLIKELY (type == 0)) { static const GEnumValue values[] = { - { GSD_TIMELINE_PROGRESS_LINEAR, "GSD_TIMELINE_PROGRESS_LINEAR", "linear" }, - { GSD_TIMELINE_PROGRESS_SINUSOIDAL, "GSD_TIMELINE_PROGRESS_SINUSOIDAL", "sinusoidal" }, - { GSD_TIMELINE_PROGRESS_EXPONENTIAL, "GSD_TIMELINE_PROGRESS_EXPONENTIAL", "exponential" }, + { MSD_TIMELINE_PROGRESS_LINEAR, "MSD_TIMELINE_PROGRESS_LINEAR", "linear" }, + { MSD_TIMELINE_PROGRESS_SINUSOIDAL, "MSD_TIMELINE_PROGRESS_SINUSOIDAL", "sinusoidal" }, + { MSD_TIMELINE_PROGRESS_EXPONENTIAL, "MSD_TIMELINE_PROGRESS_EXPONENTIAL", "exponential" }, { 0, NULL, NULL } }; - type = g_enum_register_static (g_intern_static_string ("GsdTimelineProgressType"), values); + type = g_enum_register_static (g_intern_static_string ("MsdTimelineProgressType"), values); } return type; } static void -gsd_timeline_class_init (GsdTimelineClass *class) +msd_timeline_class_init (MsdTimelineClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); - object_class->set_property = gsd_timeline_set_property; - object_class->get_property = gsd_timeline_get_property; - object_class->finalize = gsd_timeline_finalize; + object_class->set_property = msd_timeline_set_property; + object_class->get_property = msd_timeline_get_property; + object_class->finalize = msd_timeline_finalize; g_object_class_install_property (object_class, PROP_FPS, @@ -158,16 +158,16 @@ gsd_timeline_class_init (GsdTimelineClass *class) g_param_spec_enum ("direction", "Direction", "Whether the timeline moves forward or backward in time", - GSD_TYPE_TIMELINE_DIRECTION, - GSD_TIMELINE_DIRECTION_FORWARD, + MSD_TYPE_TIMELINE_DIRECTION, + MSD_TIMELINE_DIRECTION_FORWARD, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_DIRECTION, g_param_spec_enum ("progress-type", "Progress type", "Type of progress through the timeline", - GSD_TYPE_TIMELINE_PROGRESS_TYPE, - GSD_TIMELINE_PROGRESS_LINEAR, + MSD_TYPE_TIMELINE_PROGRESS_TYPE, + MSD_TIMELINE_PROGRESS_LINEAR, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SCREEN, @@ -181,7 +181,7 @@ gsd_timeline_class_init (GsdTimelineClass *class) g_signal_new ("started", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdTimelineClass, started), + G_STRUCT_OFFSET (MsdTimelineClass, started), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -190,7 +190,7 @@ gsd_timeline_class_init (GsdTimelineClass *class) g_signal_new ("paused", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdTimelineClass, paused), + G_STRUCT_OFFSET (MsdTimelineClass, paused), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -199,7 +199,7 @@ gsd_timeline_class_init (GsdTimelineClass *class) g_signal_new ("finished", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdTimelineClass, finished), + G_STRUCT_OFFSET (MsdTimelineClass, finished), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -208,60 +208,60 @@ gsd_timeline_class_init (GsdTimelineClass *class) g_signal_new ("frame", G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdTimelineClass, frame), + G_STRUCT_OFFSET (MsdTimelineClass, frame), NULL, NULL, g_cclosure_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE); - g_type_class_add_private (class, sizeof (GsdTimelinePriv)); + g_type_class_add_private (class, sizeof (MsdTimelinePriv)); } static void -gsd_timeline_init (GsdTimeline *timeline) +msd_timeline_init (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); priv->fps = DEFAULT_FPS; priv->duration = 0; - priv->direction = GSD_TIMELINE_DIRECTION_FORWARD; + priv->direction = MSD_TIMELINE_DIRECTION_FORWARD; priv->screen = gdk_screen_get_default (); } static void -gsd_timeline_set_property (GObject *object, +msd_timeline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdTimeline *timeline; - GsdTimelinePriv *priv; + MsdTimeline *timeline; + MsdTimelinePriv *priv; - timeline = GSD_TIMELINE (object); - priv = GSD_TIMELINE_GET_PRIV (timeline); + timeline = MSD_TIMELINE (object); + priv = MSD_TIMELINE_GET_PRIV (timeline); switch (prop_id) { case PROP_FPS: - gsd_timeline_set_fps (timeline, g_value_get_uint (value)); + msd_timeline_set_fps (timeline, g_value_get_uint (value)); break; case PROP_DURATION: - gsd_timeline_set_duration (timeline, g_value_get_uint (value)); + msd_timeline_set_duration (timeline, g_value_get_uint (value)); break; case PROP_LOOP: - gsd_timeline_set_loop (timeline, g_value_get_boolean (value)); + msd_timeline_set_loop (timeline, g_value_get_boolean (value)); break; case PROP_DIRECTION: - gsd_timeline_set_direction (timeline, g_value_get_enum (value)); + msd_timeline_set_direction (timeline, g_value_get_enum (value)); break; case PROP_SCREEN: - gsd_timeline_set_screen (timeline, + msd_timeline_set_screen (timeline, GDK_SCREEN (g_value_get_object (value))); break; case PROP_PROGRESS_TYPE: - gsd_timeline_set_progress_type (timeline, g_value_get_enum (value)); + msd_timeline_set_progress_type (timeline, g_value_get_enum (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -269,16 +269,16 @@ gsd_timeline_set_property (GObject *object, } static void -gsd_timeline_get_property (GObject *object, +msd_timeline_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdTimeline *timeline; - GsdTimelinePriv *priv; + MsdTimeline *timeline; + MsdTimelinePriv *priv; - timeline = GSD_TIMELINE (object); - priv = GSD_TIMELINE_GET_PRIV (timeline); + timeline = MSD_TIMELINE (object); + priv = MSD_TIMELINE_GET_PRIV (timeline); switch (prop_id) { @@ -306,11 +306,11 @@ gsd_timeline_get_property (GObject *object, } static void -gsd_timeline_finalize (GObject *object) +msd_timeline_finalize (GObject *object) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - priv = GSD_TIMELINE_GET_PRIV (object); + priv = MSD_TIMELINE_GET_PRIV (object); if (priv->source_id) { @@ -321,7 +321,7 @@ gsd_timeline_finalize (GObject *object) if (priv->timer) g_timer_destroy (priv->timer); - G_OBJECT_CLASS (gsd_timeline_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_timeline_parent_class)->finalize (object); } /* Sinusoidal progress */ @@ -337,27 +337,27 @@ exponential_progress (gdouble progress) return progress * progress; } -static GsdTimelineProgressFunc -progress_type_to_func (GsdTimelineProgressType type) +static MsdTimelineProgressFunc +progress_type_to_func (MsdTimelineProgressType type) { - if (type == GSD_TIMELINE_PROGRESS_SINUSOIDAL) + if (type == MSD_TIMELINE_PROGRESS_SINUSOIDAL) return sinusoidal_progress; - else if (type == GSD_TIMELINE_PROGRESS_EXPONENTIAL) + else if (type == MSD_TIMELINE_PROGRESS_EXPONENTIAL) return exponential_progress; return NULL; } static gboolean -gsd_timeline_run_frame (GsdTimeline *timeline, +msd_timeline_run_frame (MsdTimeline *timeline, gboolean enable_animations) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; gdouble linear_progress, progress; guint elapsed_time; - GsdTimelineProgressFunc progress_func = NULL; + MsdTimelineProgressFunc progress_func = NULL; - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); if (enable_animations) { @@ -365,7 +365,7 @@ gsd_timeline_run_frame (GsdTimeline *timeline, linear_progress = (gdouble) elapsed_time / priv->duration; - if (priv->direction == GSD_TIMELINE_DIRECTION_BACKWARD) + if (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD) linear_progress = 1 - linear_progress; linear_progress = CLAMP (linear_progress, 0., 1.); @@ -381,13 +381,13 @@ gsd_timeline_run_frame (GsdTimeline *timeline, progress = linear_progress; } else - progress = (priv->direction == GSD_TIMELINE_DIRECTION_FORWARD) ? 1.0 : 0.0; + progress = (priv->direction == MSD_TIMELINE_DIRECTION_FORWARD) ? 1.0 : 0.0; g_signal_emit (timeline, signals [FRAME], 0, CLAMP (progress, 0.0, 1.0)); - if ((priv->direction == GSD_TIMELINE_DIRECTION_FORWARD && progress >= 1.0) || - (priv->direction == GSD_TIMELINE_DIRECTION_BACKWARD && progress <= 0.0)) + if ((priv->direction == MSD_TIMELINE_DIRECTION_FORWARD && progress >= 1.0) || + (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD && progress <= 0.0)) { if (!priv->loop) { @@ -401,60 +401,60 @@ gsd_timeline_run_frame (GsdTimeline *timeline, return FALSE; } else - gsd_timeline_rewind (timeline); + msd_timeline_rewind (timeline); } return TRUE; } static gboolean -gsd_timeline_frame_idle_func (GsdTimeline *timeline) +msd_timeline_frame_idle_func (MsdTimeline *timeline) { - return gsd_timeline_run_frame (timeline, TRUE); + return msd_timeline_run_frame (timeline, TRUE); } /** - * gsd_timeline_new: + * msd_timeline_new: * @duration: duration in milliseconds for the timeline * - * Creates a new #GsdTimeline with the specified number of frames. + * Creates a new #MsdTimeline with the specified number of frames. * - * Return Value: the newly created #GsdTimeline + * Return Value: the newly created #MsdTimeline **/ -GsdTimeline * -gsd_timeline_new (guint duration) +MsdTimeline * +msd_timeline_new (guint duration) { - return g_object_new (GSD_TYPE_TIMELINE, + return g_object_new (MSD_TYPE_TIMELINE, "duration", duration, NULL); } -GsdTimeline * -gsd_timeline_new_for_screen (guint duration, +MsdTimeline * +msd_timeline_new_for_screen (guint duration, GdkScreen *screen) { - return g_object_new (GSD_TYPE_TIMELINE, + return g_object_new (MSD_TYPE_TIMELINE, "duration", duration, "screen", screen, NULL); } /** - * gsd_timeline_start: - * @timeline: A #GsdTimeline + * msd_timeline_start: + * @timeline: A #MsdTimeline * * Runs the timeline from the current frame. **/ void -gsd_timeline_start (GsdTimeline *timeline) +msd_timeline_start (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; GtkSettings *settings; gboolean enable_animations = FALSE; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); if (priv->screen) { @@ -477,7 +477,7 @@ gsd_timeline_start (GsdTimeline *timeline) g_signal_emit (timeline, signals [STARTED], 0); priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), - (GSourceFunc) gsd_timeline_frame_idle_func, + (GSourceFunc) msd_timeline_frame_idle_func, timeline); } } @@ -490,24 +490,24 @@ gsd_timeline_start (GsdTimeline *timeline) * loop into this animation again. */ g_signal_emit (timeline, signals [STARTED], 0); - gsd_timeline_run_frame (timeline, FALSE); + msd_timeline_run_frame (timeline, FALSE); } } /** - * gsd_timeline_pause: - * @timeline: A #GsdTimeline + * msd_timeline_pause: + * @timeline: A #MsdTimeline * * Pauses the timeline. **/ void -gsd_timeline_pause (GsdTimeline *timeline) +msd_timeline_pause (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); if (priv->source_id) { @@ -519,26 +519,26 @@ gsd_timeline_pause (GsdTimeline *timeline) } /** - * gsd_timeline_rewind: - * @timeline: A #GsdTimeline + * msd_timeline_rewind: + * @timeline: A #MsdTimeline * * Rewinds the timeline. **/ void -gsd_timeline_rewind (GsdTimeline *timeline) +msd_timeline_rewind (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); /* destroy and re-create timer if neccesary */ if (priv->timer) { g_timer_destroy (priv->timer); - if (gsd_timeline_is_running (timeline)) + if (msd_timeline_is_running (timeline)) priv->timer = g_timer_new (); else priv->timer = NULL; @@ -546,70 +546,70 @@ gsd_timeline_rewind (GsdTimeline *timeline) } /** - * gsd_timeline_is_running: - * @timeline: A #GsdTimeline + * msd_timeline_is_running: + * @timeline: A #MsdTimeline * * Returns whether the timeline is running or not. * * Return Value: %TRUE if the timeline is running **/ gboolean -gsd_timeline_is_running (GsdTimeline *timeline) +msd_timeline_is_running (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), FALSE); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), FALSE); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); return (priv->source_id != 0); } /** - * gsd_timeline_get_fps: - * @timeline: A #GsdTimeline + * msd_timeline_get_fps: + * @timeline: A #MsdTimeline * * Returns the number of frames per second. * * Return Value: frames per second **/ guint -gsd_timeline_get_fps (GsdTimeline *timeline) +msd_timeline_get_fps (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), 1); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 1); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); return priv->fps; } /** - * gsd_timeline_set_fps: - * @timeline: A #GsdTimeline + * msd_timeline_set_fps: + * @timeline: A #MsdTimeline * @fps: frames per second * * Sets the number of frames per second that * the timeline will play. **/ void -gsd_timeline_set_fps (GsdTimeline *timeline, +msd_timeline_set_fps (MsdTimeline *timeline, guint fps) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); g_return_if_fail (fps > 0); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); priv->fps = fps; - if (gsd_timeline_is_running (timeline)) + if (msd_timeline_is_running (timeline)) { g_source_remove (priv->source_id); priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), - (GSourceFunc) gsd_timeline_run_frame, + (GSourceFunc) msd_timeline_run_frame, timeline); } @@ -617,8 +617,8 @@ gsd_timeline_set_fps (GsdTimeline *timeline, } /** - * gsd_timeline_get_loop: - * @timeline: A #GsdTimeline + * msd_timeline_get_loop: + * @timeline: A #MsdTimeline * * Returns whether the timeline loops to the * beginning when it has reached the end. @@ -626,47 +626,47 @@ gsd_timeline_set_fps (GsdTimeline *timeline, * Return Value: %TRUE if the timeline loops **/ gboolean -gsd_timeline_get_loop (GsdTimeline *timeline) +msd_timeline_get_loop (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), FALSE); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), FALSE); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); return priv->loop; } /** - * gsd_timeline_set_loop: - * @timeline: A #GsdTimeline + * msd_timeline_set_loop: + * @timeline: A #MsdTimeline * @loop: %TRUE to make the timeline loop * * Sets whether the timeline loops to the beginning * when it has reached the end. **/ void -gsd_timeline_set_loop (GsdTimeline *timeline, +msd_timeline_set_loop (MsdTimeline *timeline, gboolean loop) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); priv->loop = loop; g_object_notify (G_OBJECT (timeline), "loop"); } void -gsd_timeline_set_duration (GsdTimeline *timeline, +msd_timeline_set_duration (MsdTimeline *timeline, guint duration) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); priv->duration = duration; @@ -674,78 +674,78 @@ gsd_timeline_set_duration (GsdTimeline *timeline, } guint -gsd_timeline_get_duration (GsdTimeline *timeline) +msd_timeline_get_duration (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), 0); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 0); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); return priv->duration; } /** - * gsd_timeline_get_direction: - * @timeline: A #GsdTimeline + * msd_timeline_get_direction: + * @timeline: A #MsdTimeline * * Returns the direction of the timeline. * * Return Value: direction **/ -GsdTimelineDirection -gsd_timeline_get_direction (GsdTimeline *timeline) +MsdTimelineDirection +msd_timeline_get_direction (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), GSD_TIMELINE_DIRECTION_FORWARD); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), MSD_TIMELINE_DIRECTION_FORWARD); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); return priv->direction; } /** - * gsd_timeline_set_direction: - * @timeline: A #GsdTimeline + * msd_timeline_set_direction: + * @timeline: A #MsdTimeline * @direction: direction * * Sets the direction of the timeline. **/ void -gsd_timeline_set_direction (GsdTimeline *timeline, - GsdTimelineDirection direction) +msd_timeline_set_direction (MsdTimeline *timeline, + MsdTimelineDirection direction) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); priv->direction = direction; g_object_notify (G_OBJECT (timeline), "direction"); } GdkScreen * -gsd_timeline_get_screen (GsdTimeline *timeline) +msd_timeline_get_screen (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), NULL); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), NULL); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); return priv->screen; } void -gsd_timeline_set_screen (GsdTimeline *timeline, +msd_timeline_set_screen (MsdTimeline *timeline, GdkScreen *screen) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); g_return_if_fail (GDK_IS_SCREEN (screen)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); if (priv->screen) g_object_unref (priv->screen); @@ -756,38 +756,38 @@ gsd_timeline_set_screen (GsdTimeline *timeline, } void -gsd_timeline_set_progress_type (GsdTimeline *timeline, - GsdTimelineProgressType type) +msd_timeline_set_progress_type (MsdTimeline *timeline, + MsdTimelineProgressType type) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); priv->progress_type = type; g_object_notify (G_OBJECT (timeline), "progress-type"); } -GsdTimelineProgressType -gsd_timeline_get_progress_type (GsdTimeline *timeline) +MsdTimelineProgressType +msd_timeline_get_progress_type (MsdTimeline *timeline) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), GSD_TIMELINE_PROGRESS_LINEAR); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), MSD_TIMELINE_PROGRESS_LINEAR); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); if (priv->progress_func) - return GSD_TIMELINE_PROGRESS_LINEAR; + return MSD_TIMELINE_PROGRESS_LINEAR; return priv->progress_type; } /** - * gsd_timeline_set_progress_func: - * @timeline: A #GsdTimeline + * msd_timeline_set_progress_func: + * @timeline: A #MsdTimeline * @progress_func: progress function * * Sets the progress function. This function will be used to calculate @@ -799,28 +799,28 @@ gsd_timeline_get_progress_type (GsdTimeline *timeline) * All progresses are in the [0.0, 1.0] range. **/ void -gsd_timeline_set_progress_func (GsdTimeline *timeline, - GsdTimelineProgressFunc progress_func) +msd_timeline_set_progress_func (MsdTimeline *timeline, + MsdTimelineProgressFunc progress_func) { - GsdTimelinePriv *priv; + MsdTimelinePriv *priv; - g_return_if_fail (GSD_IS_TIMELINE (timeline)); + g_return_if_fail (MSD_IS_TIMELINE (timeline)); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); priv->progress_func = progress_func; } gdouble -gsd_timeline_get_progress (GsdTimeline *timeline) +msd_timeline_get_progress (MsdTimeline *timeline) { - GsdTimelinePriv *priv; - GsdTimelineProgressFunc progress_func = NULL; + MsdTimelinePriv *priv; + MsdTimelineProgressFunc progress_func = NULL; gdouble linear_progress, progress; guint elapsed_time; - g_return_val_if_fail (GSD_IS_TIMELINE (timeline), 0.0); + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 0.0); - priv = GSD_TIMELINE_GET_PRIV (timeline); + priv = MSD_TIMELINE_GET_PRIV (timeline); if (!priv->timer) return 0.; @@ -829,7 +829,7 @@ gsd_timeline_get_progress (GsdTimeline *timeline) linear_progress = (gdouble) elapsed_time / priv->duration; - if (priv->direction == GSD_TIMELINE_DIRECTION_BACKWARD) + if (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD) linear_progress = 1 - linear_progress; linear_progress = CLAMP (linear_progress, 0., 1.); diff --git a/plugins/mouse/gsd-timeline.h b/plugins/mouse/gsd-timeline.h index d4ecbcc..b8d40ca 100644 --- a/plugins/mouse/gsd-timeline.h +++ b/plugins/mouse/gsd-timeline.h @@ -1,4 +1,4 @@ -/* gsdtimeline.c +/* msdtimeline.c * * Copyright (C) 2008 Carlos Garnacho * @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __GSD_TIMELINE_H__ -#define __GSD_TIMELINE_H__ +#ifndef __MSD_TIMELINE_H__ +#define __MSD_TIMELINE_H__ #include #include @@ -27,101 +27,101 @@ extern "C" { #endif -#define GSD_TYPE_TIMELINE_DIRECTION (gsd_timeline_direction_get_type ()) -#define GSD_TYPE_TIMELINE_PROGRESS_TYPE (gsd_timeline_progress_type_get_type ()) -#define GSD_TYPE_TIMELINE (gsd_timeline_get_type ()) -#define GSD_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_TIMELINE, GsdTimeline)) -#define GSD_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_TIMELINE, GsdTimelineClass)) -#define GSD_IS_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_TIMELINE)) -#define GSD_IS_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_TIMELINE)) -#define GSD_TIMELINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_TIMELINE, GsdTimelineClass)) +#define MSD_TYPE_TIMELINE_DIRECTION (msd_timeline_direction_get_type ()) +#define MSD_TYPE_TIMELINE_PROGRESS_TYPE (msd_timeline_progress_type_get_type ()) +#define MSD_TYPE_TIMELINE (msd_timeline_get_type ()) +#define MSD_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_TIMELINE, MsdTimeline)) +#define MSD_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_TIMELINE, MsdTimelineClass)) +#define MSD_IS_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_TIMELINE)) +#define MSD_IS_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_TIMELINE)) +#define MSD_TIMELINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_TIMELINE, MsdTimelineClass)) typedef enum { - GSD_TIMELINE_DIRECTION_FORWARD, - GSD_TIMELINE_DIRECTION_BACKWARD -} GsdTimelineDirection; + MSD_TIMELINE_DIRECTION_FORWARD, + MSD_TIMELINE_DIRECTION_BACKWARD +} MsdTimelineDirection; typedef enum { - GSD_TIMELINE_PROGRESS_LINEAR, - GSD_TIMELINE_PROGRESS_SINUSOIDAL, - GSD_TIMELINE_PROGRESS_EXPONENTIAL -} GsdTimelineProgressType; + MSD_TIMELINE_PROGRESS_LINEAR, + MSD_TIMELINE_PROGRESS_SINUSOIDAL, + MSD_TIMELINE_PROGRESS_EXPONENTIAL +} MsdTimelineProgressType; -typedef struct GsdTimeline GsdTimeline; -typedef struct GsdTimelineClass GsdTimelineClass; +typedef struct MsdTimeline MsdTimeline; +typedef struct MsdTimelineClass MsdTimelineClass; -struct GsdTimeline +struct MsdTimeline { GObject parent_instance; }; -struct GsdTimelineClass +struct MsdTimelineClass { GObjectClass parent_class; - void (* started) (GsdTimeline *timeline); - void (* finished) (GsdTimeline *timeline); - void (* paused) (GsdTimeline *timeline); + void (* started) (MsdTimeline *timeline); + void (* finished) (MsdTimeline *timeline); + void (* paused) (MsdTimeline *timeline); - void (* frame) (GsdTimeline *timeline, + void (* frame) (MsdTimeline *timeline, gdouble progress); - void (* __gsd_reserved1) (void); - void (* __gsd_reserved2) (void); - void (* __gsd_reserved3) (void); - void (* __gsd_reserved4) (void); + void (* __msd_reserved1) (void); + void (* __msd_reserved2) (void); + void (* __msd_reserved3) (void); + void (* __msd_reserved4) (void); }; -typedef gdouble (*GsdTimelineProgressFunc) (gdouble progress); +typedef gdouble (*MsdTimelineProgressFunc) (gdouble progress); -GType gsd_timeline_get_type (void) G_GNUC_CONST; -GType gsd_timeline_direction_get_type (void) G_GNUC_CONST; -GType gsd_timeline_progress_type_get_type (void) G_GNUC_CONST; +GType msd_timeline_get_type (void) G_GNUC_CONST; +GType msd_timeline_direction_get_type (void) G_GNUC_CONST; +GType msd_timeline_progress_type_get_type (void) G_GNUC_CONST; -GsdTimeline *gsd_timeline_new (guint duration); -GsdTimeline *gsd_timeline_new_for_screen (guint duration, +MsdTimeline *msd_timeline_new (guint duration); +MsdTimeline *msd_timeline_new_for_screen (guint duration, GdkScreen *screen); -void gsd_timeline_start (GsdTimeline *timeline); -void gsd_timeline_pause (GsdTimeline *timeline); -void gsd_timeline_rewind (GsdTimeline *timeline); +void msd_timeline_start (MsdTimeline *timeline); +void msd_timeline_pause (MsdTimeline *timeline); +void msd_timeline_rewind (MsdTimeline *timeline); -gboolean gsd_timeline_is_running (GsdTimeline *timeline); +gboolean msd_timeline_is_running (MsdTimeline *timeline); -guint gsd_timeline_get_fps (GsdTimeline *timeline); -void gsd_timeline_set_fps (GsdTimeline *timeline, +guint msd_timeline_get_fps (MsdTimeline *timeline); +void msd_timeline_set_fps (MsdTimeline *timeline, guint fps); -gboolean gsd_timeline_get_loop (GsdTimeline *timeline); -void gsd_timeline_set_loop (GsdTimeline *timeline, +gboolean msd_timeline_get_loop (MsdTimeline *timeline); +void msd_timeline_set_loop (MsdTimeline *timeline, gboolean loop); -guint gsd_timeline_get_duration (GsdTimeline *timeline); -void gsd_timeline_set_duration (GsdTimeline *timeline, +guint msd_timeline_get_duration (MsdTimeline *timeline); +void msd_timeline_set_duration (MsdTimeline *timeline, guint duration); -GdkScreen *gsd_timeline_get_screen (GsdTimeline *timeline); -void gsd_timeline_set_screen (GsdTimeline *timeline, +GdkScreen *msd_timeline_get_screen (MsdTimeline *timeline); +void msd_timeline_set_screen (MsdTimeline *timeline, GdkScreen *screen); -GsdTimelineDirection gsd_timeline_get_direction (GsdTimeline *timeline); -void gsd_timeline_set_direction (GsdTimeline *timeline, - GsdTimelineDirection direction); +MsdTimelineDirection msd_timeline_get_direction (MsdTimeline *timeline); +void msd_timeline_set_direction (MsdTimeline *timeline, + MsdTimelineDirection direction); -GsdTimelineProgressType gsd_timeline_get_progress_type (GsdTimeline *timeline); -void gsd_timeline_set_progress_type (GsdTimeline *timeline, - GsdTimelineProgressType type); -void gsd_timeline_get_progress_func (GsdTimeline *timeline); +MsdTimelineProgressType msd_timeline_get_progress_type (MsdTimeline *timeline); +void msd_timeline_set_progress_type (MsdTimeline *timeline, + MsdTimelineProgressType type); +void msd_timeline_get_progress_func (MsdTimeline *timeline); -void gsd_timeline_set_progress_func (GsdTimeline *timeline, - GsdTimelineProgressFunc progress_func); +void msd_timeline_set_progress_func (MsdTimeline *timeline, + MsdTimelineProgressFunc progress_func); -gdouble gsd_timeline_get_progress (GsdTimeline *timeline); +gdouble msd_timeline_get_progress (MsdTimeline *timeline); #ifdef __cplusplus } #endif -#endif /* __GSD_TIMELINE_H__ */ +#endif /* __MSD_TIMELINE_H__ */ diff --git a/plugins/smartcard/Makefile.am b/plugins/smartcard/Makefile.am index a70e0a0..4e01be4 100644 --- a/plugins/smartcard/Makefile.am +++ b/plugins/smartcard/Makefile.am @@ -2,19 +2,19 @@ plugin_LTLIBRARIES = \ libsmartcard.la libsmartcard_la_SOURCES = \ - gsd-smartcard-plugin.h \ - gsd-smartcard-plugin.c \ - gsd-smartcard.h \ - gsd-smartcard.c \ - gsd-smartcard-manager.h \ - gsd-smartcard-manager.c + msd-smartcard-plugin.h \ + msd-smartcard-plugin.c \ + msd-smartcard.h \ + msd-smartcard.c \ + msd-smartcard-manager.h \ + msd-smartcard-manager.c libsmartcard_la_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ -DMATE_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ -DLIBDIR=\""$(libdir)"\" \ - -DGSD_SMARTCARD_MANAGER_NSS_DB=\""$(NSS_DATABASE)"\" \ + -DMSD_SMARTCARD_MANAGER_NSS_DB=\""$(NSS_DATABASE)"\" \ $(AM_CPPFLAGS) libsmartcard_la_CFLAGS = \ @@ -24,13 +24,13 @@ libsmartcard_la_CFLAGS = \ $(AM_CFLAGS) libsmartcard_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) + $(MSD_PLUGIN_LDFLAGS) libsmartcard_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) \ $(NSS_LIBS) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ plugin_in_files = \ smartcard.mate-settings-plugin.in diff --git a/plugins/smartcard/gsd-smartcard-manager.c b/plugins/smartcard/gsd-smartcard-manager.c index a231e20..ed823f4 100644 --- a/plugins/smartcard/gsd-smartcard-manager.c +++ b/plugins/smartcard/gsd-smartcard-manager.c @@ -1,4 +1,4 @@ -/* gsd-smartcard-manager.c - object for monitoring smartcard insertion and +/* msd-smartcard-manager.c - object for monitoring smartcard insertion and * removal events * * Copyright (C) 2006, 2009 Red Hat, Inc. @@ -22,10 +22,10 @@ */ #include "config.h" -#include "gsd-smartcard-manager.h" +#include "msd-smartcard-manager.h" #define SMARTCARD_ENABLE_INTERNAL_API -#include "gsd-smartcard.h" +#include "msd-smartcard.h" #include #include @@ -49,22 +49,22 @@ #include #include -#ifndef GSD_SMARTCARD_MANAGER_NSS_DB -#define GSD_SMARTCARD_MANAGER_NSS_DB SYSCONFDIR"/pki/nssdb" +#ifndef MSD_SMARTCARD_MANAGER_NSS_DB +#define MSD_SMARTCARD_MANAGER_NSS_DB SYSCONFDIR"/pki/nssdb" #endif -typedef enum _GsdSmartcardManagerState GsdSmartcardManagerState; -typedef struct _GsdSmartcardManagerWorker GsdSmartcardManagerWorker; +typedef enum _MsdSmartcardManagerState MsdSmartcardManagerState; +typedef struct _MsdSmartcardManagerWorker MsdSmartcardManagerWorker; -enum _GsdSmartcardManagerState { - GSD_SMARTCARD_MANAGER_STATE_STOPPED = 0, - GSD_SMARTCARD_MANAGER_STATE_STARTING, - GSD_SMARTCARD_MANAGER_STATE_STARTED, - GSD_SMARTCARD_MANAGER_STATE_STOPPING, +enum _MsdSmartcardManagerState { + MSD_SMARTCARD_MANAGER_STATE_STOPPED = 0, + MSD_SMARTCARD_MANAGER_STATE_STARTING, + MSD_SMARTCARD_MANAGER_STATE_STARTED, + MSD_SMARTCARD_MANAGER_STATE_STOPPING, }; -struct _GsdSmartcardManagerPrivate { - GsdSmartcardManagerState state; +struct _MsdSmartcardManagerPrivate { + MsdSmartcardManagerState state; SECMODModule *module; char *module_path; @@ -80,7 +80,7 @@ struct _GsdSmartcardManagerPrivate { guint32 nss_is_loaded : 1; }; -struct _GsdSmartcardManagerWorker { +struct _MsdSmartcardManagerWorker { SECMODModule *module; GHashTable *smartcards; int write_fd; @@ -88,36 +88,36 @@ struct _GsdSmartcardManagerWorker { guint32 nss_is_loaded : 1; }; -static void gsd_smartcard_manager_finalize (GObject *object); -static void gsd_smartcard_manager_class_install_signals (GsdSmartcardManagerClass *service_class); -static void gsd_smartcard_manager_class_install_properties (GsdSmartcardManagerClass *service_class); -static void gsd_smartcard_manager_set_property (GObject *object, +static void msd_smartcard_manager_finalize (GObject *object); +static void msd_smartcard_manager_class_install_signals (MsdSmartcardManagerClass *service_class); +static void msd_smartcard_manager_class_install_properties (MsdSmartcardManagerClass *service_class); +static void msd_smartcard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gsd_smartcard_manager_get_property (GObject *object, +static void msd_smartcard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gsd_smartcard_manager_set_module_path (GsdSmartcardManager *manager, +static void msd_smartcard_manager_set_module_path (MsdSmartcardManager *manager, const char *module_path); -static void gsd_smartcard_manager_card_removed_handler (GsdSmartcardManager *manager, - GsdSmartcard *card); -static void gsd_smartcard_manager_card_inserted_handler (GsdSmartcardManager *manager_class, - GsdSmartcard *card); -static gboolean gsd_smartcard_manager_stop_now (GsdSmartcardManager *manager); -static void gsd_smartcard_manager_queue_stop (GsdSmartcardManager *manager); - -static gboolean gsd_smartcard_manager_create_worker (GsdSmartcardManager *manager, +static void msd_smartcard_manager_card_removed_handler (MsdSmartcardManager *manager, + MsdSmartcard *card); +static void msd_smartcard_manager_card_inserted_handler (MsdSmartcardManager *manager_class, + MsdSmartcard *card); +static gboolean msd_smartcard_manager_stop_now (MsdSmartcardManager *manager); +static void msd_smartcard_manager_queue_stop (MsdSmartcardManager *manager); + +static gboolean msd_smartcard_manager_create_worker (MsdSmartcardManager *manager, int *worker_fd, GThread **worker_thread); -static GsdSmartcardManagerWorker * gsd_smartcard_manager_worker_new (int write_fd); -static void gsd_smartcard_manager_worker_free (GsdSmartcardManagerWorker *worker); +static MsdSmartcardManagerWorker * msd_smartcard_manager_worker_new (int write_fd); +static void msd_smartcard_manager_worker_free (MsdSmartcardManagerWorker *worker); static gboolean open_pipe (int *write_fd, int *read_fd); static gboolean read_bytes (int fd, gpointer bytes, gsize num_bytes); static gboolean write_bytes (int fd, gconstpointer bytes, gsize num_bytes); -static GsdSmartcard *read_smartcard (int fd, SECMODModule *module); -static gboolean write_smartcard (int fd, GsdSmartcard *card); +static MsdSmartcard *read_smartcard (int fd, SECMODModule *module); +static gboolean write_smartcard (int fd, MsdSmartcard *card); enum { PROP_0 = 0, @@ -132,37 +132,37 @@ enum { NUMBER_OF_SIGNALS }; -static guint gsd_smartcard_manager_signals[NUMBER_OF_SIGNALS]; +static guint msd_smartcard_manager_signals[NUMBER_OF_SIGNALS]; -G_DEFINE_TYPE (GsdSmartcardManager, - gsd_smartcard_manager, +G_DEFINE_TYPE (MsdSmartcardManager, + msd_smartcard_manager, G_TYPE_OBJECT); static void -gsd_smartcard_manager_class_init (GsdSmartcardManagerClass *manager_class) +msd_smartcard_manager_class_init (MsdSmartcardManagerClass *manager_class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (manager_class); - gobject_class->finalize = gsd_smartcard_manager_finalize; + gobject_class->finalize = msd_smartcard_manager_finalize; - gsd_smartcard_manager_class_install_signals (manager_class); - gsd_smartcard_manager_class_install_properties (manager_class); + msd_smartcard_manager_class_install_signals (manager_class); + msd_smartcard_manager_class_install_properties (manager_class); g_type_class_add_private (manager_class, - sizeof (GsdSmartcardManagerPrivate)); + sizeof (MsdSmartcardManagerPrivate)); } static void -gsd_smartcard_manager_class_install_properties (GsdSmartcardManagerClass *card_class) +msd_smartcard_manager_class_install_properties (MsdSmartcardManagerClass *card_class) { GObjectClass *object_class; GParamSpec *param_spec; object_class = G_OBJECT_CLASS (card_class); - object_class->set_property = gsd_smartcard_manager_set_property; - object_class->get_property = gsd_smartcard_manager_get_property; + object_class->set_property = msd_smartcard_manager_set_property; + object_class->get_property = msd_smartcard_manager_get_property; param_spec = g_param_spec_string ("module-path", _("Module Path"), _("path to smartcard PKCS #11 driver"), @@ -171,16 +171,16 @@ gsd_smartcard_manager_class_install_properties (GsdSmartcardManagerClass *card_c } static void -gsd_smartcard_manager_set_property (GObject *object, +msd_smartcard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdSmartcardManager *manager = GSD_SMARTCARD_MANAGER (object); + MsdSmartcardManager *manager = MSD_SMARTCARD_MANAGER (object); switch (prop_id) { case PROP_MODULE_PATH: - gsd_smartcard_manager_set_module_path (manager, + msd_smartcard_manager_set_module_path (manager, g_value_get_string (value)); break; @@ -191,17 +191,17 @@ gsd_smartcard_manager_set_property (GObject *object, } static void -gsd_smartcard_manager_get_property (GObject *object, +msd_smartcard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdSmartcardManager *manager = GSD_SMARTCARD_MANAGER (object); + MsdSmartcardManager *manager = MSD_SMARTCARD_MANAGER (object); char *module_path; switch (prop_id) { case PROP_MODULE_PATH: - module_path = gsd_smartcard_manager_get_module_path (manager); + module_path = msd_smartcard_manager_get_module_path (manager); g_value_set_string (value, module_path); g_free (module_path); break; @@ -213,13 +213,13 @@ gsd_smartcard_manager_get_property (GObject *object, } char * -gsd_smartcard_manager_get_module_path (GsdSmartcardManager *manager) +msd_smartcard_manager_get_module_path (MsdSmartcardManager *manager) { return manager->priv->module_path; } static void -gsd_smartcard_manager_set_module_path (GsdSmartcardManager *manager, +msd_smartcard_manager_set_module_path (MsdSmartcardManager *manager, const char *module_path) { if ((manager->priv->module_path == NULL) && (module_path == NULL)) { @@ -236,57 +236,57 @@ gsd_smartcard_manager_set_module_path (GsdSmartcardManager *manager, } static void -gsd_smartcard_manager_card_removed_handler (GsdSmartcardManager *manager, - GsdSmartcard *card) +msd_smartcard_manager_card_removed_handler (MsdSmartcardManager *manager, + MsdSmartcard *card) { g_debug ("informing smartcard of its removal"); - _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_REMOVED); + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); g_debug ("done"); } static void -gsd_smartcard_manager_card_inserted_handler (GsdSmartcardManager *manager, - GsdSmartcard *card) +msd_smartcard_manager_card_inserted_handler (MsdSmartcardManager *manager, + MsdSmartcard *card) { g_debug ("informing smartcard of its insertion"); - _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_INSERTED); + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); g_debug ("done"); } static void -gsd_smartcard_manager_class_install_signals (GsdSmartcardManagerClass *manager_class) +msd_smartcard_manager_class_install_signals (MsdSmartcardManagerClass *manager_class) { GObjectClass *object_class; object_class = G_OBJECT_CLASS (manager_class); - gsd_smartcard_manager_signals[SMARTCARD_INSERTED] = + msd_smartcard_manager_signals[SMARTCARD_INSERTED] = g_signal_new ("smartcard-inserted", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GsdSmartcardManagerClass, + G_STRUCT_OFFSET (MsdSmartcardManagerClass, smartcard_inserted), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - manager_class->smartcard_inserted = gsd_smartcard_manager_card_inserted_handler; + manager_class->smartcard_inserted = msd_smartcard_manager_card_inserted_handler; - gsd_smartcard_manager_signals[SMARTCARD_REMOVED] = + msd_smartcard_manager_signals[SMARTCARD_REMOVED] = g_signal_new ("smartcard-removed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GsdSmartcardManagerClass, + G_STRUCT_OFFSET (MsdSmartcardManagerClass, smartcard_removed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - manager_class->smartcard_removed = gsd_smartcard_manager_card_removed_handler; + manager_class->smartcard_removed = msd_smartcard_manager_card_removed_handler; - gsd_smartcard_manager_signals[ERROR] = + msd_smartcard_manager_signals[ERROR] = g_signal_new ("error", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdSmartcardManagerClass, error), + G_STRUCT_OFFSET (MsdSmartcardManagerClass, error), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); manager_class->error = NULL; @@ -324,13 +324,13 @@ slot_id_hash (CK_SLOT_ID *slot_id) } static void -gsd_smartcard_manager_init (GsdSmartcardManager *manager) +msd_smartcard_manager_init (MsdSmartcardManager *manager) { g_debug ("initializing smartcard manager"); manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, - GSD_TYPE_SMARTCARD_MANAGER, - GsdSmartcardManagerPrivate); + MSD_TYPE_SMARTCARD_MANAGER, + MsdSmartcardManagerPrivate); manager->priv->poll_timeout_id = 0; manager->priv->is_unstoppable = FALSE; manager->priv->module = NULL; @@ -348,16 +348,16 @@ gsd_smartcard_manager_init (GsdSmartcardManager *manager) } static void -gsd_smartcard_manager_finalize (GObject *object) +msd_smartcard_manager_finalize (GObject *object) { - GsdSmartcardManager *manager; + MsdSmartcardManager *manager; GObjectClass *gobject_class; - manager = GSD_SMARTCARD_MANAGER (object); + manager = MSD_SMARTCARD_MANAGER (object); gobject_class = - G_OBJECT_CLASS (gsd_smartcard_manager_parent_class); + G_OBJECT_CLASS (msd_smartcard_manager_parent_class); - gsd_smartcard_manager_stop_now (manager); + msd_smartcard_manager_stop_now (manager); g_hash_table_destroy (manager->priv->smartcards); manager->priv->smartcards = NULL; @@ -366,23 +366,23 @@ gsd_smartcard_manager_finalize (GObject *object) } GQuark -gsd_smartcard_manager_error_quark (void) +msd_smartcard_manager_error_quark (void) { static GQuark error_quark = 0; if (error_quark == 0) { - error_quark = g_quark_from_static_string ("gsd-smartcard-manager-error-quark"); + error_quark = g_quark_from_static_string ("msd-smartcard-manager-error-quark"); } return error_quark; } -GsdSmartcardManager * -gsd_smartcard_manager_new (const char *module_path) +MsdSmartcardManager * +msd_smartcard_manager_new (const char *module_path) { - GsdSmartcardManager *instance; + MsdSmartcardManager *instance; - instance = GSD_SMARTCARD_MANAGER (g_object_new (GSD_TYPE_SMARTCARD_MANAGER, + instance = MSD_SMARTCARD_MANAGER (g_object_new (MSD_TYPE_SMARTCARD_MANAGER, "module-path", module_path, NULL)); @@ -390,44 +390,44 @@ gsd_smartcard_manager_new (const char *module_path) } static void -gsd_smartcard_manager_emit_error (GsdSmartcardManager *manager, +msd_smartcard_manager_emit_error (MsdSmartcardManager *manager, GError *error) { manager->priv->is_unstoppable = TRUE; - g_signal_emit (manager, gsd_smartcard_manager_signals[ERROR], 0, + g_signal_emit (manager, msd_smartcard_manager_signals[ERROR], 0, error); manager->priv->is_unstoppable = FALSE; } static void -gsd_smartcard_manager_emit_smartcard_inserted (GsdSmartcardManager *manager, - GsdSmartcard *card) +msd_smartcard_manager_emit_smartcard_inserted (MsdSmartcardManager *manager, + MsdSmartcard *card) { manager->priv->is_unstoppable = TRUE; - g_signal_emit (manager, gsd_smartcard_manager_signals[SMARTCARD_INSERTED], 0, + g_signal_emit (manager, msd_smartcard_manager_signals[SMARTCARD_INSERTED], 0, card); manager->priv->is_unstoppable = FALSE; } static void -gsd_smartcard_manager_emit_smartcard_removed (GsdSmartcardManager *manager, - GsdSmartcard *card) +msd_smartcard_manager_emit_smartcard_removed (MsdSmartcardManager *manager, + MsdSmartcard *card) { - GsdSmartcardManagerState old_state; + MsdSmartcardManagerState old_state; old_state = manager->priv->state; manager->priv->is_unstoppable = TRUE; - g_signal_emit (manager, gsd_smartcard_manager_signals[SMARTCARD_REMOVED], 0, + g_signal_emit (manager, msd_smartcard_manager_signals[SMARTCARD_REMOVED], 0, card); manager->priv->is_unstoppable = FALSE; } static gboolean -gsd_smartcard_manager_check_for_and_process_events (GIOChannel *io_channel, +msd_smartcard_manager_check_for_and_process_events (GIOChannel *io_channel, GIOCondition condition, - GsdSmartcardManager *manager) + MsdSmartcardManager *manager) { - GsdSmartcard *card; + MsdSmartcard *card; gboolean should_stop; gchar event_type; char *card_name; @@ -464,7 +464,7 @@ gsd_smartcard_manager_check_for_and_process_events (GIOChannel *io_chan goto out; } - card_name = gsd_smartcard_get_name (card); + card_name = msd_smartcard_get_name (card); switch (event_type) { case 'I': @@ -472,12 +472,12 @@ gsd_smartcard_manager_check_for_and_process_events (GIOChannel *io_chan card_name, card); card_name = NULL; - gsd_smartcard_manager_emit_smartcard_inserted (manager, card); + msd_smartcard_manager_emit_smartcard_inserted (manager, card); card = NULL; break; case 'R': - gsd_smartcard_manager_emit_smartcard_removed (manager, card); + msd_smartcard_manager_emit_smartcard_removed (manager, card); if (!g_hash_table_remove (manager->priv->smartcards, card_name)) { g_debug ("got removal event of unknown card!"); } @@ -499,13 +499,13 @@ out: if (should_stop) { GError *error; - error = g_error_new (GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, + error = g_error_new (MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, "%s", (condition & G_IO_IN) ? g_strerror (errno) : _("received error or hang up from event source")); - gsd_smartcard_manager_emit_error (manager, error); + msd_smartcard_manager_emit_error (manager, error); g_error_free (error); - gsd_smartcard_manager_stop_now (manager); + msd_smartcard_manager_stop_now (manager); return FALSE; } @@ -513,10 +513,10 @@ out: } static void -gsd_smartcard_manager_event_processing_stopped_handler (GsdSmartcardManager *manager) +msd_smartcard_manager_event_processing_stopped_handler (MsdSmartcardManager *manager) { manager->priv->smartcard_event_source = NULL; - gsd_smartcard_manager_stop_now (manager); + msd_smartcard_manager_stop_now (manager); } static gboolean @@ -551,7 +551,7 @@ open_pipe (int *write_fd, } static void -gsd_smartcard_manager_stop_watching_for_events (GsdSmartcardManager *manager) +msd_smartcard_manager_stop_watching_for_events (MsdSmartcardManager *manager) { if (manager->priv->smartcard_event_source != NULL) { g_source_destroy (manager->priv->smartcard_event_source); @@ -574,9 +574,9 @@ load_nss (GError **error) NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD; g_debug ("attempting to load NSS database '%s'", - GSD_SMARTCARD_MANAGER_NSS_DB); + MSD_SMARTCARD_MANAGER_NSS_DB); - status = NSS_Initialize (GSD_SMARTCARD_MANAGER_NSS_DB, + status = NSS_Initialize (MSD_SMARTCARD_MANAGER_NSS_DB, "", "", SECMOD_DB, flags); if (status != SECSuccess) { @@ -588,8 +588,8 @@ load_nss (GError **error) if (error_message_size == 0) { g_debug ("NSS security system could not be initialized"); g_set_error (error, - GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, _("NSS security system could not be initialized")); goto out; } @@ -598,8 +598,8 @@ load_nss (GError **error) PR_GetErrorText (error_message); g_set_error (error, - GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, "%s", error_message); g_debug ("NSS security system could not be initialized - %s", error_message); @@ -657,8 +657,8 @@ load_driver (char *module_path, if (!module_explicitly_specified && module == NULL) { g_set_error (error, - GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, _("no suitable smartcard driver could be found")); } else if (module == NULL || !module->loaded) { @@ -677,8 +677,8 @@ load_driver (char *module_path, g_debug ("smartcard driver '%s' could not be loaded", module_path); g_set_error (error, - GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, _("smartcard driver '%s' could not be " "loaded"), module_path); goto out; @@ -688,8 +688,8 @@ load_driver (char *module_path, PR_GetErrorText (error_message); g_set_error (error, - GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, "%s", error_message); g_debug ("smartcard driver '%s' could not be loaded - %s", @@ -702,12 +702,12 @@ out: } static void -gsd_smartcard_manager_get_all_cards (GsdSmartcardManager *manager) +msd_smartcard_manager_get_all_cards (MsdSmartcardManager *manager) { int i; for (i = 0; i < manager->priv->module->slotCount; i++) { - GsdSmartcard *card; + MsdSmartcard *card; CK_SLOT_ID slot_id; int slot_series; char *card_name; @@ -715,10 +715,10 @@ gsd_smartcard_manager_get_all_cards (GsdSmartcardManager *manager) slot_id = PK11_GetSlotID (manager->priv->module->slots[i]); slot_series = PK11_GetSlotSeries (manager->priv->module->slots[i]); - card = _gsd_smartcard_new (manager->priv->module, + card = _msd_smartcard_new (manager->priv->module, slot_id, slot_series); - card_name = gsd_smartcard_get_name (card); + card_name = msd_smartcard_get_name (card); g_hash_table_replace (manager->priv->smartcards, card_name, card); @@ -726,7 +726,7 @@ gsd_smartcard_manager_get_all_cards (GsdSmartcardManager *manager) } gboolean -gsd_smartcard_manager_start (GsdSmartcardManager *manager, +msd_smartcard_manager_start (MsdSmartcardManager *manager, GError **error) { GError *watching_error; @@ -737,12 +737,12 @@ gsd_smartcard_manager_start (GsdSmartcardManager *manager, GIOFlags channel_flags; GError *nss_error; - if (manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STARTED) { + if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STARTED) { g_debug ("smartcard manager already started"); return TRUE; } - manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STARTING; + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STARTING; worker_fd = -1; worker_pid = 0; @@ -763,11 +763,11 @@ gsd_smartcard_manager_start (GsdSmartcardManager *manager, goto out; } - if (!gsd_smartcard_manager_create_worker (manager, &worker_fd, &manager->priv->worker_thread)) { + if (!msd_smartcard_manager_create_worker (manager, &worker_fd, &manager->priv->worker_thread)) { g_set_error (error, - GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, _("could not watch for incoming card events - %s"), g_strerror (errno)); @@ -787,41 +787,41 @@ gsd_smartcard_manager_start (GsdSmartcardManager *manager, g_source_set_callback (manager->priv->smartcard_event_source, (GSourceFunc) (GIOFunc) - gsd_smartcard_manager_check_for_and_process_events, + msd_smartcard_manager_check_for_and_process_events, manager, (GDestroyNotify) - gsd_smartcard_manager_event_processing_stopped_handler); + msd_smartcard_manager_event_processing_stopped_handler); g_source_attach (manager->priv->smartcard_event_source, NULL); g_source_unref (manager->priv->smartcard_event_source); /* populate the hash with cards that are already inserted */ - gsd_smartcard_manager_get_all_cards (manager); + msd_smartcard_manager_get_all_cards (manager); - manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STARTED; + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STARTED; out: /* don't leave it in a half started state */ - if (manager->priv->state != GSD_SMARTCARD_MANAGER_STATE_STARTED) { + if (manager->priv->state != MSD_SMARTCARD_MANAGER_STATE_STARTED) { g_debug ("smartcard manager could not be completely started"); - gsd_smartcard_manager_stop (manager); + msd_smartcard_manager_stop (manager); } else { g_debug ("smartcard manager started"); } - return manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STARTED; + return manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STARTED; } static gboolean -gsd_smartcard_manager_stop_now (GsdSmartcardManager *manager) +msd_smartcard_manager_stop_now (MsdSmartcardManager *manager) { - if (manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STOPPED) { + if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STOPPED) { return FALSE; } - manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STOPPED; - gsd_smartcard_manager_stop_watching_for_events (manager); + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STOPPED; + msd_smartcard_manager_stop_watching_for_events (manager); if (manager->priv->module != NULL) { SECMOD_DestroyModule (manager->priv->module); @@ -839,44 +839,44 @@ gsd_smartcard_manager_stop_now (GsdSmartcardManager *manager) } static void -gsd_smartcard_manager_queue_stop (GsdSmartcardManager *manager) +msd_smartcard_manager_queue_stop (MsdSmartcardManager *manager) { - manager->priv->state = GSD_SMARTCARD_MANAGER_STATE_STOPPING; + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STOPPING; - g_idle_add ((GSourceFunc) gsd_smartcard_manager_stop_now, manager); + g_idle_add ((GSourceFunc) msd_smartcard_manager_stop_now, manager); } void -gsd_smartcard_manager_stop (GsdSmartcardManager *manager) +msd_smartcard_manager_stop (MsdSmartcardManager *manager) { - if (manager->priv->state == GSD_SMARTCARD_MANAGER_STATE_STOPPED) { + if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STOPPED) { return; } if (manager->priv->is_unstoppable) { - gsd_smartcard_manager_queue_stop (manager); + msd_smartcard_manager_queue_stop (manager); return; } - gsd_smartcard_manager_stop_now (manager); + msd_smartcard_manager_stop_now (manager); } static void -gsd_smartcard_manager_check_for_login_card (CK_SLOT_ID slot_id, - GsdSmartcard *card, +msd_smartcard_manager_check_for_login_card (CK_SLOT_ID slot_id, + MsdSmartcard *card, gboolean *is_inserted) { g_assert (is_inserted != NULL); - if (gsd_smartcard_is_login_card (card)) { + if (msd_smartcard_is_login_card (card)) { *is_inserted = TRUE; } } gboolean -gsd_smartcard_manager_login_card_is_inserted (GsdSmartcardManager *manager) +msd_smartcard_manager_login_card_is_inserted (MsdSmartcardManager *manager) { gboolean is_inserted; @@ -884,17 +884,17 @@ gsd_smartcard_manager_login_card_is_inserted (GsdSmartcardManager *manager) is_inserted = FALSE; g_hash_table_foreach (manager->priv->smartcards, (GHFunc) - gsd_smartcard_manager_check_for_login_card, + msd_smartcard_manager_check_for_login_card, &is_inserted); return is_inserted; } -static GsdSmartcardManagerWorker * -gsd_smartcard_manager_worker_new (int write_fd) +static MsdSmartcardManagerWorker * +msd_smartcard_manager_worker_new (int write_fd) { - GsdSmartcardManagerWorker *worker; + MsdSmartcardManagerWorker *worker; - worker = g_slice_new0 (GsdSmartcardManagerWorker); + worker = g_slice_new0 (MsdSmartcardManagerWorker); worker->write_fd = write_fd; worker->module = NULL; @@ -908,14 +908,14 @@ gsd_smartcard_manager_worker_new (int write_fd) } static void -gsd_smartcard_manager_worker_free (GsdSmartcardManagerWorker *worker) +msd_smartcard_manager_worker_free (MsdSmartcardManagerWorker *worker) { if (worker->smartcards != NULL) { g_hash_table_destroy (worker->smartcards); worker->smartcards = NULL; } - g_slice_free (GsdSmartcardManagerWorker, worker); + g_slice_free (MsdSmartcardManagerWorker, worker); } static gboolean @@ -992,11 +992,11 @@ write_bytes (int fd, return TRUE; } -static GsdSmartcard * +static MsdSmartcard * read_smartcard (int fd, SECMODModule *module) { - GsdSmartcard *card; + MsdSmartcard *card; char *card_name; gsize card_name_size; @@ -1010,7 +1010,7 @@ read_smartcard (int fd, g_slice_free1 (card_name_size, card_name); return NULL; } - card = _gsd_smartcard_new_from_name (module, card_name); + card = _msd_smartcard_new_from_name (module, card_name); g_slice_free1 (card_name_size, card_name); return card; @@ -1018,12 +1018,12 @@ read_smartcard (int fd, static gboolean write_smartcard (int fd, - GsdSmartcard *card) + MsdSmartcard *card) { gsize card_name_size; char *card_name; - card_name = gsd_smartcard_get_name (card); + card_name = msd_smartcard_get_name (card); card_name_size = strlen (card_name) + 1; if (!write_bytes (fd, &card_name_size, sizeof (card_name_size))) { @@ -1041,11 +1041,11 @@ write_smartcard (int fd, } static gboolean -gsd_smartcard_manager_worker_emit_smartcard_removed (GsdSmartcardManagerWorker *worker, - GsdSmartcard *card, +msd_smartcard_manager_worker_emit_smartcard_removed (MsdSmartcardManagerWorker *worker, + MsdSmartcard *card, GError **error) { - g_debug ("card '%s' removed!", gsd_smartcard_get_name (card)); + g_debug ("card '%s' removed!", msd_smartcard_get_name (card)); if (!write_bytes (worker->write_fd, "R", 1)) { goto error_out; @@ -1058,21 +1058,21 @@ gsd_smartcard_manager_worker_emit_smartcard_removed (GsdSmartcardManagerWorker return TRUE; error_out: - g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, + g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, "%s", g_strerror (errno)); return FALSE; } static gboolean -gsd_smartcard_manager_worker_emit_smartcard_inserted (GsdSmartcardManagerWorker *worker, - GsdSmartcard *card, +msd_smartcard_manager_worker_emit_smartcard_inserted (MsdSmartcardManagerWorker *worker, + MsdSmartcard *card, GError **error) { GError *write_error; write_error = NULL; - g_debug ("card '%s' inserted!", gsd_smartcard_get_name (card)); + g_debug ("card '%s' inserted!", msd_smartcard_get_name (card)); if (!write_bytes (worker->write_fd, "I", 1)) { goto error_out; } @@ -1084,20 +1084,20 @@ gsd_smartcard_manager_worker_emit_smartcard_inserted (GsdSmartcardManagerWorker return TRUE; error_out: - g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, + g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, "%s", g_strerror (errno)); return FALSE; } static gboolean -gsd_smartcard_manager_worker_watch_for_and_process_event (GsdSmartcardManagerWorker *worker, +msd_smartcard_manager_worker_watch_for_and_process_event (MsdSmartcardManagerWorker *worker, GError **error) { PK11SlotInfo *slot; CK_SLOT_ID slot_id, *key; int slot_series, card_slot_series; - GsdSmartcard *card; + MsdSmartcard *card; GError *processing_error; gboolean ret; @@ -1119,8 +1119,8 @@ gsd_smartcard_manager_worker_watch_for_and_process_event (GsdSmartcardManagerWor /* FIXME: is there a function to convert from a PORT error * code to a translated string? */ - g_set_error (error, GSD_SMARTCARD_MANAGER_ERROR, - GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, _("encountered unexpected error while " "waiting for smartcard events")); goto out; @@ -1141,7 +1141,7 @@ gsd_smartcard_manager_worker_watch_for_and_process_event (GsdSmartcardManagerWor card = g_hash_table_lookup (worker->smartcards, key); if (card != NULL) { - card_slot_series = gsd_smartcard_get_slot_series (card); + card_slot_series = msd_smartcard_get_slot_series (card); } else { card_slot_series = -1; } @@ -1154,20 +1154,20 @@ gsd_smartcard_manager_worker_watch_for_and_process_event (GsdSmartcardManagerWor */ if ((card != NULL) && card_slot_series != slot_series) { - if (!gsd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { + if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } } - card = _gsd_smartcard_new (worker->module, + card = _msd_smartcard_new (worker->module, slot_id, slot_series); g_hash_table_replace (worker->smartcards, key, card); key = NULL; - if (!gsd_smartcard_manager_worker_emit_smartcard_inserted (worker, + if (!msd_smartcard_manager_worker_emit_smartcard_inserted (worker, card, &processing_error)) { g_propagate_error (error, processing_error); @@ -1188,24 +1188,24 @@ gsd_smartcard_manager_worker_watch_for_and_process_event (GsdSmartcardManagerWor */ if ((slot_series - card_slot_series) > 1) { - if (!gsd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { + if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } g_hash_table_remove (worker->smartcards, key); - card = _gsd_smartcard_new (worker->module, + card = _msd_smartcard_new (worker->module, slot_id, slot_series); g_hash_table_replace (worker->smartcards, key, card); key = NULL; - if (!gsd_smartcard_manager_worker_emit_smartcard_inserted (worker, card, &processing_error)) { + if (!msd_smartcard_manager_worker_emit_smartcard_inserted (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } } - if (!gsd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { + if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { g_propagate_error (error, processing_error); goto out; } @@ -1227,29 +1227,29 @@ out: } static void -gsd_smartcard_manager_worker_run (GsdSmartcardManagerWorker *worker) +msd_smartcard_manager_worker_run (MsdSmartcardManagerWorker *worker) { GError *error; error = NULL; - while (gsd_smartcard_manager_worker_watch_for_and_process_event (worker, &error)); + while (msd_smartcard_manager_worker_watch_for_and_process_event (worker, &error)); if (error != NULL) { g_debug ("could not process card event - %s", error->message); g_error_free (error); } - gsd_smartcard_manager_worker_free (worker); + msd_smartcard_manager_worker_free (worker); } static gboolean -gsd_smartcard_manager_create_worker (GsdSmartcardManager *manager, +msd_smartcard_manager_create_worker (MsdSmartcardManager *manager, int *worker_fd, GThread **worker_thread) { - GsdSmartcardManagerWorker *worker; + MsdSmartcardManagerWorker *worker; int write_fd, read_fd; write_fd = -1; @@ -1258,15 +1258,15 @@ gsd_smartcard_manager_create_worker (GsdSmartcardManager *manager, return FALSE; } - worker = gsd_smartcard_manager_worker_new (write_fd); + worker = msd_smartcard_manager_worker_new (write_fd); worker->module = manager->priv->module; *worker_thread = g_thread_create ((GThreadFunc) - gsd_smartcard_manager_worker_run, + msd_smartcard_manager_worker_run, worker, FALSE, NULL); if (*worker_thread == NULL) { - gsd_smartcard_manager_worker_free (worker); + msd_smartcard_manager_worker_free (worker); return FALSE; } @@ -1277,19 +1277,19 @@ gsd_smartcard_manager_create_worker (GsdSmartcardManager *manager, return TRUE; } -#ifdef GSD_SMARTCARD_MANAGER_ENABLE_TEST +#ifdef MSD_SMARTCARD_MANAGER_ENABLE_TEST #include static GMainLoop *event_loop; static gboolean should_exit_on_next_remove = FALSE; static gboolean -on_timeout (GsdSmartcardManager *manager) +on_timeout (MsdSmartcardManager *manager) { GError *error; g_print ("Re-enabling manager.\n"); - if (!gsd_smartcard_manager_start (manager, &error)) { + if (!msd_smartcard_manager_start (manager, &error)) { g_warning ("could not start smartcard manager - %s", error->message); g_error_free (error); @@ -1303,16 +1303,16 @@ on_timeout (GsdSmartcardManager *manager) } static void -on_device_inserted (GsdSmartcardManager *manager, - GsdSmartcard *card) +on_device_inserted (MsdSmartcardManager *manager, + MsdSmartcard *card) { g_print ("smartcard inserted!\n"); g_print ("Please remove it.\n"); } static void -on_device_removed (GsdSmartcardManager *manager, - GsdSmartcard *card) +on_device_removed (MsdSmartcardManager *manager, + MsdSmartcard *card) { g_print ("smartcard removed!\n"); @@ -1320,7 +1320,7 @@ on_device_removed (GsdSmartcardManager *manager, g_main_loop_quit (event_loop); } else { g_print ("disabling manager for 2 seconds\n"); - gsd_smartcard_manager_stop (manager); + msd_smartcard_manager_stop (manager); g_timeout_add (2000, (GSourceFunc) on_timeout, manager); } } @@ -1329,7 +1329,7 @@ int main (int argc, char *argv[]) { - GsdSmartcardManager *manager; + MsdSmartcardManager *manager; GError *error; g_log_set_always_fatal (G_LOG_LEVEL_ERROR @@ -1338,7 +1338,7 @@ main (int argc, g_type_init (); g_message ("creating instance of 'smartcard manager' object..."); - manager = gsd_smartcard_manager_new (NULL); + manager = msd_smartcard_manager_new (NULL); g_message ("'smartcard manager' object created successfully"); g_signal_connect (manager, "smartcard-inserted", @@ -1350,7 +1350,7 @@ main (int argc, g_message ("starting listener..."); error = NULL; - if (!gsd_smartcard_manager_start (manager, &error)) { + if (!msd_smartcard_manager_start (manager, &error)) { g_warning ("could not start smartcard manager - %s", error->message); g_error_free (error); diff --git a/plugins/smartcard/gsd-smartcard-manager.h b/plugins/smartcard/gsd-smartcard-manager.h index 9663124..269e1da 100644 --- a/plugins/smartcard/gsd-smartcard-manager.h +++ b/plugins/smartcard/gsd-smartcard-manager.h @@ -1,4 +1,4 @@ -/* gsd-smartcard-manager.h - object for monitoring smartcard insertion and +/* msd-smartcard-manager.h - object for monitoring smartcard insertion and * removal events * * Copyright (C) 2006, 2009 Red Hat, Inc. @@ -20,11 +20,11 @@ * * Written by: Ray Strode */ -#ifndef GSD_SMARTCARD_MANAGER_H -#define GSD_SMARTCARD_MANAGER_H +#ifndef MSD_SMARTCARD_MANAGER_H +#define MSD_SMARTCARD_MANAGER_H -#define GSD_SMARTCARD_ENABLE_INTERNAL_API -#include "gsd-smartcard.h" +#define MSD_SMARTCARD_ENABLE_INTERNAL_API +#include "msd-smartcard.h" #include #include @@ -32,59 +32,59 @@ #ifdef __cplusplus extern "C" { #endif -#define GSD_TYPE_SMARTCARD_MANAGER (gsd_smartcard_manager_get_type ()) -#define GSD_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_SMARTCARD_MANAGER, GsdSmartcardManager)) -#define GSD_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_SMARTCARD_MANAGER, GsdSmartcardManagerClass)) -#define GSD_IS_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_SMARTCARD_MANAGER)) -#define GSD_IS_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SC_TYPE_SMARTCARD_MANAGER)) -#define GSD_SMARTCARD_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GSD_TYPE_SMARTCARD_MANAGER, GsdSmartcardManagerClass)) -#define GSD_SMARTCARD_MANAGER_ERROR (gsd_smartcard_manager_error_quark ()) -typedef struct _GsdSmartcardManager GsdSmartcardManager; -typedef struct _GsdSmartcardManagerClass GsdSmartcardManagerClass; -typedef struct _GsdSmartcardManagerPrivate GsdSmartcardManagerPrivate; -typedef enum _GsdSmartcardManagerError GsdSmartcardManagerError; +#define MSD_TYPE_SMARTCARD_MANAGER (msd_smartcard_manager_get_type ()) +#define MSD_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManager)) +#define MSD_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManagerClass)) +#define MSD_IS_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_SMARTCARD_MANAGER)) +#define MSD_IS_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SC_TYPE_SMARTCARD_MANAGER)) +#define MSD_SMARTCARD_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManagerClass)) +#define MSD_SMARTCARD_MANAGER_ERROR (msd_smartcard_manager_error_quark ()) +typedef struct _MsdSmartcardManager MsdSmartcardManager; +typedef struct _MsdSmartcardManagerClass MsdSmartcardManagerClass; +typedef struct _MsdSmartcardManagerPrivate MsdSmartcardManagerPrivate; +typedef enum _MsdSmartcardManagerError MsdSmartcardManagerError; -struct _GsdSmartcardManager { +struct _MsdSmartcardManager { GObject parent; /*< private > */ - GsdSmartcardManagerPrivate *priv; + MsdSmartcardManagerPrivate *priv; }; -struct _GsdSmartcardManagerClass { +struct _MsdSmartcardManagerClass { GObjectClass parent_class; /* Signals */ - void (*smartcard_inserted) (GsdSmartcardManager *manager, - GsdSmartcard *token); - void (*smartcard_removed) (GsdSmartcardManager *manager, - GsdSmartcard *token); - void (*error) (GsdSmartcardManager *manager, + void (*smartcard_inserted) (MsdSmartcardManager *manager, + MsdSmartcard *token); + void (*smartcard_removed) (MsdSmartcardManager *manager, + MsdSmartcard *token); + void (*error) (MsdSmartcardManager *manager, GError *error); }; -enum _GsdSmartcardManagerError { - GSD_SMARTCARD_MANAGER_ERROR_GENERIC = 0, - GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, - GSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, - GSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, - GSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS +enum _MsdSmartcardManagerError { + MSD_SMARTCARD_MANAGER_ERROR_GENERIC = 0, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, + MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS }; -GType gsd_smartcard_manager_get_type (void) G_GNUC_CONST; -GQuark gsd_smartcard_manager_error_quark (void) G_GNUC_CONST; +GType msd_smartcard_manager_get_type (void) G_GNUC_CONST; +GQuark msd_smartcard_manager_error_quark (void) G_GNUC_CONST; -GsdSmartcardManager *gsd_smartcard_manager_new (const char *module); +MsdSmartcardManager *msd_smartcard_manager_new (const char *module); -gboolean gsd_smartcard_manager_start (GsdSmartcardManager *manager, +gboolean msd_smartcard_manager_start (MsdSmartcardManager *manager, GError **error); -void gsd_smartcard_manager_stop (GsdSmartcardManager *manager); +void msd_smartcard_manager_stop (MsdSmartcardManager *manager); -char *gsd_smartcard_manager_get_module_path (GsdSmartcardManager *manager); -gboolean gsd_smartcard_manager_login_card_is_inserted (GsdSmartcardManager *manager); +char *msd_smartcard_manager_get_module_path (MsdSmartcardManager *manager); +gboolean msd_smartcard_manager_login_card_is_inserted (MsdSmartcardManager *manager); #ifdef __cplusplus } #endif -#endif /* GSD_SMARTCARD_MANAGER_H */ +#endif /* MSD_SMARTCARD_MANAGER_H */ diff --git a/plugins/smartcard/gsd-smartcard-plugin.c b/plugins/smartcard/gsd-smartcard-plugin.c index 9e3b4f2..dc4cb8f 100644 --- a/plugins/smartcard/gsd-smartcard-plugin.c +++ b/plugins/smartcard/gsd-smartcard-plugin.c @@ -31,11 +31,11 @@ #include #include "mate-settings-plugin.h" -#include "gsd-smartcard-plugin.h" -#include "gsd-smartcard-manager.h" +#include "msd-smartcard-plugin.h" +#include "msd-smartcard-manager.h" -struct GsdSmartcardPluginPrivate { - GsdSmartcardManager *manager; +struct MsdSmartcardPluginPrivate { + MsdSmartcardManager *manager; DBusGConnection *bus_connection; guint32 is_active : 1; @@ -43,10 +43,10 @@ struct GsdSmartcardPluginPrivate { typedef enum { - GSD_SMARTCARD_REMOVE_ACTION_NONE, - GSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN, - GSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT, -} GsdSmartcardRemoveAction; + MSD_SMARTCARD_REMOVE_ACTION_NONE, + MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN, + MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT, +} MsdSmartcardRemoveAction; #define SCREENSAVER_DBUS_NAME "org.mate.ScreenSaver" #define SCREENSAVER_DBUS_PATH "/" @@ -57,19 +57,19 @@ typedef enum #define SM_DBUS_INTERFACE "org.mate.SessionManager" #define SM_LOGOUT_MODE_FORCE 2 -#define GSD_SMARTCARD_KEY "/desktop/mate/peripherals/smartcard" -#define KEY_REMOVE_ACTION GSD_SMARTCARD_KEY "/removal_action" +#define MSD_SMARTCARD_KEY "/desktop/mate/peripherals/smartcard" +#define KEY_REMOVE_ACTION MSD_SMARTCARD_KEY "/removal_action" -#define GSD_SMARTCARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPluginPrivate)) +#define MSD_SMARTCARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdSmartcardPlugin, gsd_smartcard_plugin); +MATE_SETTINGS_PLUGIN_REGISTER (MsdSmartcardPlugin, msd_smartcard_plugin); static void -simulate_user_activity (GsdSmartcardPlugin *plugin) +simulate_user_activity (MsdSmartcardPlugin *plugin) { DBusGProxy *screensaver_proxy; - g_debug ("GsdSmartcardPlugin telling screensaver about smart card insertion"); + g_debug ("MsdSmartcardPlugin telling screensaver about smart card insertion"); screensaver_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, SCREENSAVER_DBUS_NAME, SCREENSAVER_DBUS_PATH, @@ -83,11 +83,11 @@ simulate_user_activity (GsdSmartcardPlugin *plugin) } static void -lock_screen (GsdSmartcardPlugin *plugin) +lock_screen (MsdSmartcardPlugin *plugin) { DBusGProxy *screensaver_proxy; - g_debug ("GsdSmartcardPlugin telling screensaver to lock screen"); + g_debug ("MsdSmartcardPlugin telling screensaver to lock screen"); screensaver_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, SCREENSAVER_DBUS_NAME, SCREENSAVER_DBUS_PATH, @@ -101,13 +101,13 @@ lock_screen (GsdSmartcardPlugin *plugin) } static void -force_logout (GsdSmartcardPlugin *plugin) +force_logout (MsdSmartcardPlugin *plugin) { DBusGProxy *sm_proxy; GError *error; gboolean res; - g_debug ("GsdSmartcardPlugin telling session manager to force logout"); + g_debug ("MsdSmartcardPlugin telling session manager to force logout"); sm_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, SM_DBUS_NAME, SM_DBUS_PATH, @@ -121,7 +121,7 @@ force_logout (GsdSmartcardPlugin *plugin) G_TYPE_INVALID, G_TYPE_INVALID); if (! res) { - g_warning ("GsdSmartcardPlugin Unable to force logout: %s", error->message); + g_warning ("MsdSmartcardPlugin Unable to force logout: %s", error->message); g_error_free (error); } @@ -129,26 +129,26 @@ force_logout (GsdSmartcardPlugin *plugin) } static void -gsd_smartcard_plugin_init (GsdSmartcardPlugin *plugin) +msd_smartcard_plugin_init (MsdSmartcardPlugin *plugin) { - plugin->priv = GSD_SMARTCARD_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_SMARTCARD_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdSmartcardPlugin initializing"); + g_debug ("MsdSmartcardPlugin initializing"); - plugin->priv->manager = gsd_smartcard_manager_new (NULL); + plugin->priv->manager = msd_smartcard_manager_new (NULL); } static void -gsd_smartcard_plugin_finalize (GObject *object) +msd_smartcard_plugin_finalize (GObject *object) { - GsdSmartcardPlugin *plugin; + MsdSmartcardPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_SMARTCARD_PLUGIN (object)); + g_return_if_fail (MSD_IS_SMARTCARD_PLUGIN (object)); - g_debug ("GsdSmartcardPlugin finalizing"); + g_debug ("MsdSmartcardPlugin finalizing"); - plugin = GSD_SMARTCARD_PLUGIN (object); + plugin = MSD_SMARTCARD_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -156,18 +156,18 @@ gsd_smartcard_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_smartcard_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_smartcard_plugin_parent_class)->finalize (object); } static void -smartcard_inserted_cb (GsdSmartcardManager *card_monitor, - GsdSmartcard *card, - GsdSmartcardPlugin *plugin) +smartcard_inserted_cb (MsdSmartcardManager *card_monitor, + MsdSmartcard *card, + MsdSmartcardPlugin *plugin) { char *name; - name = gsd_smartcard_get_name (card); - g_debug ("GsdSmartcardPlugin smart card '%s' inserted", name); + name = msd_smartcard_get_name (card); + g_debug ("MsdSmartcardPlugin smart card '%s' inserted", name); g_free (name); simulate_user_activity (plugin); @@ -179,29 +179,29 @@ user_logged_in_with_smartcard (void) return g_getenv ("PKCS11_LOGIN_TOKEN_NAME") != NULL; } -static GsdSmartcardRemoveAction -get_configured_remove_action (GsdSmartcardPlugin *plugin) +static MsdSmartcardRemoveAction +get_configured_remove_action (MsdSmartcardPlugin *plugin) { MateConfClient *client; char *remove_action_string; - GsdSmartcardRemoveAction remove_action; + MsdSmartcardRemoveAction remove_action; client = mateconf_client_get_default (); remove_action_string = mateconf_client_get_string (client, KEY_REMOVE_ACTION, NULL); if (remove_action_string == NULL) { - g_warning ("GsdSmartcardPlugin unable to get smartcard remove action"); - remove_action = GSD_SMARTCARD_REMOVE_ACTION_NONE; + g_warning ("MsdSmartcardPlugin unable to get smartcard remove action"); + remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; } else if (strcmp (remove_action_string, "none") == 0) { - remove_action = GSD_SMARTCARD_REMOVE_ACTION_NONE; + remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; } else if (strcmp (remove_action_string, "lock_screen") == 0) { - remove_action = GSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN; + remove_action = MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN; } else if (strcmp (remove_action_string, "force_logout") == 0) { - remove_action = GSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT; + remove_action = MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT; } else { - g_warning ("GsdSmartcardPlugin unknown smartcard remove action"); - remove_action = GSD_SMARTCARD_REMOVE_ACTION_NONE; + g_warning ("MsdSmartcardPlugin unknown smartcard remove action"); + remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; } g_object_unref (client); @@ -210,40 +210,40 @@ get_configured_remove_action (GsdSmartcardPlugin *plugin) } static void -process_smartcard_removal (GsdSmartcardPlugin *plugin) +process_smartcard_removal (MsdSmartcardPlugin *plugin) { - GsdSmartcardRemoveAction remove_action; + MsdSmartcardRemoveAction remove_action; - g_debug ("GsdSmartcardPlugin processing smartcard removal"); + g_debug ("MsdSmartcardPlugin processing smartcard removal"); remove_action = get_configured_remove_action (plugin); switch (remove_action) { - case GSD_SMARTCARD_REMOVE_ACTION_NONE: + case MSD_SMARTCARD_REMOVE_ACTION_NONE: return; - case GSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN: + case MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN: lock_screen (plugin); break; - case GSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT: + case MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT: force_logout (plugin); break; } } static void -smartcard_removed_cb (GsdSmartcardManager *card_monitor, - GsdSmartcard *card, - GsdSmartcardPlugin *plugin) +smartcard_removed_cb (MsdSmartcardManager *card_monitor, + MsdSmartcard *card, + MsdSmartcardPlugin *plugin) { char *name; - name = gsd_smartcard_get_name (card); - g_debug ("GsdSmartcardPlugin smart card '%s' removed", name); + name = msd_smartcard_get_name (card); + g_debug ("MsdSmartcardPlugin smart card '%s' removed", name); g_free (name); - if (!gsd_smartcard_is_login_card (card)) { - g_debug ("GsdSmartcardPlugin removed smart card was not used to login"); + if (!msd_smartcard_is_login_card (card)) { + g_debug ("MsdSmartcardPlugin removed smart card was not used to login"); return; } @@ -254,33 +254,33 @@ static void impl_activate (MateSettingsPlugin *plugin) { GError *error; - GsdSmartcardPlugin *smartcard_plugin = GSD_SMARTCARD_PLUGIN (plugin); + MsdSmartcardPlugin *smartcard_plugin = MSD_SMARTCARD_PLUGIN (plugin); if (smartcard_plugin->priv->is_active) { - g_debug ("GsdSmartcardPlugin Not activating smartcard plugin, because it's " + g_debug ("MsdSmartcardPlugin Not activating smartcard plugin, because it's " "already active"); return; } if (!user_logged_in_with_smartcard ()) { - g_debug ("GsdSmartcardPlugin Not activating smartcard plugin, because user didn't use " + g_debug ("MsdSmartcardPlugin Not activating smartcard plugin, because user didn't use " " smartcard to log in"); smartcard_plugin->priv->is_active = FALSE; return; } - g_debug ("GsdSmartcardPlugin Activating smartcard plugin"); + g_debug ("MsdSmartcardPlugin Activating smartcard plugin"); error = NULL; smartcard_plugin->priv->bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (smartcard_plugin->priv->bus_connection == NULL) { - g_warning ("GsdSmartcardPlugin Unable to connect to session bus: %s", error->message); + g_warning ("MsdSmartcardPlugin Unable to connect to session bus: %s", error->message); return; } - if (!gsd_smartcard_manager_start (smartcard_plugin->priv->manager, &error)) { - g_warning ("GsdSmartcardPlugin Unable to start smartcard manager: %s", error->message); + if (!msd_smartcard_manager_start (smartcard_plugin->priv->manager, &error)) { + g_warning ("MsdSmartcardPlugin Unable to start smartcard manager: %s", error->message); g_error_free (error); } @@ -292,8 +292,8 @@ impl_activate (MateSettingsPlugin *plugin) "smartcard-inserted", G_CALLBACK (smartcard_inserted_cb), smartcard_plugin); - if (!gsd_smartcard_manager_login_card_is_inserted (smartcard_plugin->priv->manager)) { - g_debug ("GsdSmartcardPlugin processing smartcard removal immediately user logged in with smartcard " + if (!msd_smartcard_manager_login_card_is_inserted (smartcard_plugin->priv->manager)) { + g_debug ("MsdSmartcardPlugin processing smartcard removal immediately user logged in with smartcard " "and it's not inserted"); process_smartcard_removal (smartcard_plugin); } @@ -304,17 +304,17 @@ impl_activate (MateSettingsPlugin *plugin) static void impl_deactivate (MateSettingsPlugin *plugin) { - GsdSmartcardPlugin *smartcard_plugin = GSD_SMARTCARD_PLUGIN (plugin); + MsdSmartcardPlugin *smartcard_plugin = MSD_SMARTCARD_PLUGIN (plugin); if (!smartcard_plugin->priv->is_active) { - g_debug ("GsdSmartcardPlugin Not deactivating smartcard plugin, " + g_debug ("MsdSmartcardPlugin Not deactivating smartcard plugin, " "because it's already inactive"); return; } - g_debug ("GsdSmartcardPlugin Deactivating smartcard plugin"); + g_debug ("MsdSmartcardPlugin Deactivating smartcard plugin"); - gsd_smartcard_manager_stop (smartcard_plugin->priv->manager); + msd_smartcard_manager_stop (smartcard_plugin->priv->manager); g_signal_handlers_disconnect_by_func (smartcard_plugin->priv->manager, smartcard_removed_cb, smartcard_plugin); @@ -326,15 +326,15 @@ impl_deactivate (MateSettingsPlugin *plugin) } static void -gsd_smartcard_plugin_class_init (GsdSmartcardPluginClass *klass) +msd_smartcard_plugin_class_init (MsdSmartcardPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_smartcard_plugin_finalize; + object_class->finalize = msd_smartcard_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdSmartcardPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdSmartcardPluginPrivate)); } diff --git a/plugins/smartcard/gsd-smartcard-plugin.h b/plugins/smartcard/gsd-smartcard-plugin.h index 4c61686..206e58d 100644 --- a/plugins/smartcard/gsd-smartcard-plugin.h +++ b/plugins/smartcard/gsd-smartcard-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_SMARTCARD_PLUGIN_H__ -#define __GSD_SMARTCARD_PLUGIN_H__ +#ifndef __MSD_SMARTCARD_PLUGIN_H__ +#define __MSD_SMARTCARD_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_SMARTCARD_PLUGIN (gsd_smartcard_plugin_get_type ()) -#define GSD_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPlugin)) -#define GSD_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPluginClass)) -#define GSD_IS_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SMARTCARD_PLUGIN)) -#define GSD_IS_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SMARTCARD_PLUGIN)) -#define GSD_SMARTCARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SMARTCARD_PLUGIN, GsdSmartcardPluginClass)) +#define MSD_TYPE_SMARTCARD_PLUGIN (msd_smartcard_plugin_get_type ()) +#define MSD_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPlugin)) +#define MSD_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginClass)) +#define MSD_IS_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SMARTCARD_PLUGIN)) +#define MSD_IS_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SMARTCARD_PLUGIN)) +#define MSD_SMARTCARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginClass)) -typedef struct GsdSmartcardPluginPrivate GsdSmartcardPluginPrivate; +typedef struct MsdSmartcardPluginPrivate MsdSmartcardPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdSmartcardPluginPrivate *priv; -} GsdSmartcardPlugin; + MsdSmartcardPluginPrivate *priv; +} MsdSmartcardPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdSmartcardPluginClass; +} MsdSmartcardPluginClass; -GType gsd_smartcard_plugin_get_type (void) G_GNUC_CONST; +GType msd_smartcard_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_SMARTCARD_PLUGIN_H__ */ +#endif /* __MSD_SMARTCARD_PLUGIN_H__ */ diff --git a/plugins/smartcard/gsd-smartcard.c b/plugins/smartcard/gsd-smartcard.c index 22f4e12..9154200 100644 --- a/plugins/smartcard/gsd-smartcard.c +++ b/plugins/smartcard/gsd-smartcard.c @@ -1,4 +1,4 @@ -/* gsd-smartcard.c - smartcard object +/* msd-smartcard.c - smartcard object * * Copyright (C) 2006 Ray Strode * @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ -#define GSD_SMARTCARD_ENABLE_INTERNAL_API -#include "gsd-smartcard.h" +#define MSD_SMARTCARD_ENABLE_INTERNAL_API +#include "msd-smartcard.h" #include #include @@ -34,9 +34,9 @@ #include #include -struct _GsdSmartcardPrivate { +struct _MsdSmartcardPrivate { SECMODModule *module; - GsdSmartcardState state; + MsdSmartcardState state; CK_SLOT_ID slot_id; int slot_series; @@ -48,36 +48,36 @@ struct _GsdSmartcardPrivate { CERTCertificate *encryption_certificate; }; -static void gsd_smartcard_finalize (GObject *object); -static void gsd_smartcard_class_install_signals (GsdSmartcardClass *card_class); -static void gsd_smartcard_class_install_properties (GsdSmartcardClass *card_class); -static void gsd_smartcard_set_property (GObject *object, +static void msd_smartcard_finalize (GObject *object); +static void msd_smartcard_class_install_signals (MsdSmartcardClass *card_class); +static void msd_smartcard_class_install_properties (MsdSmartcardClass *card_class); +static void msd_smartcard_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gsd_smartcard_get_property (GObject *object, +static void msd_smartcard_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static void gsd_smartcard_set_name (GsdSmartcard *card, const char *name); -static void gsd_smartcard_set_slot_id (GsdSmartcard *card, +static void msd_smartcard_set_name (MsdSmartcard *card, const char *name); +static void msd_smartcard_set_slot_id (MsdSmartcard *card, int slot_id); -static void gsd_smartcard_set_slot_series (GsdSmartcard *card, +static void msd_smartcard_set_slot_series (MsdSmartcard *card, int slot_series); -static void gsd_smartcard_set_module (GsdSmartcard *card, +static void msd_smartcard_set_module (MsdSmartcard *card, SECMODModule *module); -static PK11SlotInfo *gsd_smartcard_find_slot_from_id (GsdSmartcard *card, +static PK11SlotInfo *msd_smartcard_find_slot_from_id (MsdSmartcard *card, int slot_id); -static PK11SlotInfo *gsd_smartcard_find_slot_from_card_name (GsdSmartcard *card, +static PK11SlotInfo *msd_smartcard_find_slot_from_card_name (MsdSmartcard *card, const char *card_name); -#ifndef GSD_SMARTCARD_DEFAULT_SLOT_ID -#define GSD_SMARTCARD_DEFAULT_SLOT_ID ((gulong) -1) +#ifndef MSD_SMARTCARD_DEFAULT_SLOT_ID +#define MSD_SMARTCARD_DEFAULT_SLOT_ID ((gulong) -1) #endif -#ifndef GSD_SMARTCARD_DEFAULT_SLOT_SERIES -#define GSD_SMARTCARD_DEFAULT_SLOT_SERIES -1 +#ifndef MSD_SMARTCARD_DEFAULT_SLOT_SERIES +#define MSD_SMARTCARD_DEFAULT_SLOT_SERIES -1 #endif enum { @@ -95,73 +95,73 @@ enum { NUMBER_OF_SIGNALS }; -static guint gsd_smartcard_signals[NUMBER_OF_SIGNALS]; +static guint msd_smartcard_signals[NUMBER_OF_SIGNALS]; -G_DEFINE_TYPE (GsdSmartcard, gsd_smartcard, G_TYPE_OBJECT); +G_DEFINE_TYPE (MsdSmartcard, msd_smartcard, G_TYPE_OBJECT); static void -gsd_smartcard_class_init (GsdSmartcardClass *card_class) +msd_smartcard_class_init (MsdSmartcardClass *card_class) { GObjectClass *gobject_class; gobject_class = G_OBJECT_CLASS (card_class); - gobject_class->finalize = gsd_smartcard_finalize; + gobject_class->finalize = msd_smartcard_finalize; - gsd_smartcard_class_install_signals (card_class); - gsd_smartcard_class_install_properties (card_class); + msd_smartcard_class_install_signals (card_class); + msd_smartcard_class_install_properties (card_class); g_type_class_add_private (card_class, - sizeof (GsdSmartcardPrivate)); + sizeof (MsdSmartcardPrivate)); } static void -gsd_smartcard_class_install_signals (GsdSmartcardClass *card_class) +msd_smartcard_class_install_signals (MsdSmartcardClass *card_class) { GObjectClass *object_class; object_class = G_OBJECT_CLASS (card_class); - gsd_smartcard_signals[INSERTED] = + msd_smartcard_signals[INSERTED] = g_signal_new ("inserted", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdSmartcardClass, + G_STRUCT_OFFSET (MsdSmartcardClass, inserted), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - gsd_smartcard_signals[REMOVED] = + msd_smartcard_signals[REMOVED] = g_signal_new ("removed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GsdSmartcardClass, + G_STRUCT_OFFSET (MsdSmartcardClass, removed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void -gsd_smartcard_class_install_properties (GsdSmartcardClass *card_class) +msd_smartcard_class_install_properties (MsdSmartcardClass *card_class) { GObjectClass *object_class; GParamSpec *param_spec; object_class = G_OBJECT_CLASS (card_class); - object_class->set_property = gsd_smartcard_set_property; - object_class->get_property = gsd_smartcard_get_property; + object_class->set_property = msd_smartcard_set_property; + object_class->get_property = msd_smartcard_get_property; param_spec = g_param_spec_ulong ("slot-id", _("Slot ID"), _("The slot the card is in"), 1, G_MAXULONG, - GSD_SMARTCARD_DEFAULT_SLOT_ID, + MSD_SMARTCARD_DEFAULT_SLOT_ID, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_SLOT_ID, param_spec); param_spec = g_param_spec_int ("slot-series", _("Slot Series"), _("per-slot card identifier"), -1, G_MAXINT, - GSD_SMARTCARD_DEFAULT_SLOT_SERIES, + MSD_SMARTCARD_DEFAULT_SLOT_SERIES, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_SLOT_SERIES, param_spec); @@ -177,30 +177,30 @@ gsd_smartcard_class_install_properties (GsdSmartcardClass *card_class) } static void -gsd_smartcard_set_property (GObject *object, +msd_smartcard_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdSmartcard *card = GSD_SMARTCARD (object); + MsdSmartcard *card = MSD_SMARTCARD (object); switch (prop_id) { case PROP_NAME: - gsd_smartcard_set_name (card, g_value_get_string (value)); + msd_smartcard_set_name (card, g_value_get_string (value)); break; case PROP_SLOT_ID: - gsd_smartcard_set_slot_id (card, + msd_smartcard_set_slot_id (card, g_value_get_ulong (value)); break; case PROP_SLOT_SERIES: - gsd_smartcard_set_slot_series (card, + msd_smartcard_set_slot_series (card, g_value_get_int (value)); break; case PROP_MODULE: - gsd_smartcard_set_module (card, + msd_smartcard_set_module (card, (SECMODModule *) g_value_get_pointer (value)); break; @@ -211,25 +211,25 @@ gsd_smartcard_set_property (GObject *object, } CK_SLOT_ID -gsd_smartcard_get_slot_id (GsdSmartcard *card) +msd_smartcard_get_slot_id (MsdSmartcard *card) { return card->priv->slot_id; } -GsdSmartcardState -gsd_smartcard_get_state (GsdSmartcard *card) +MsdSmartcardState +msd_smartcard_get_state (MsdSmartcard *card) { return card->priv->state; } char * -gsd_smartcard_get_name (GsdSmartcard *card) +msd_smartcard_get_name (MsdSmartcard *card) { return g_strdup (card->priv->name); } gboolean -gsd_smartcard_is_login_card (GsdSmartcard *card) +msd_smartcard_is_login_card (MsdSmartcard *card) { const char *login_card_name; login_card_name = g_getenv ("PKCS11_LOGIN_TOKEN_NAME"); @@ -246,27 +246,27 @@ gsd_smartcard_is_login_card (GsdSmartcard *card) } static void -gsd_smartcard_get_property (GObject *object, +msd_smartcard_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdSmartcard *card = GSD_SMARTCARD (object); + MsdSmartcard *card = MSD_SMARTCARD (object); switch (prop_id) { case PROP_NAME: g_value_take_string (value, - gsd_smartcard_get_name (card)); + msd_smartcard_get_name (card)); break; case PROP_SLOT_ID: g_value_set_ulong (value, - (gulong) gsd_smartcard_get_slot_id (card)); + (gulong) msd_smartcard_get_slot_id (card)); break; case PROP_SLOT_SERIES: g_value_set_int (value, - gsd_smartcard_get_slot_series (card)); + msd_smartcard_get_slot_series (card)); break; default: @@ -275,7 +275,7 @@ gsd_smartcard_get_property (GObject *object, } static void -gsd_smartcard_set_name (GsdSmartcard *card, +msd_smartcard_set_name (MsdSmartcard *card, const char *name) { if (name == NULL) { @@ -288,7 +288,7 @@ gsd_smartcard_set_name (GsdSmartcard *card, card->priv->name = g_strdup (name); if (card->priv->slot == NULL) { - card->priv->slot = gsd_smartcard_find_slot_from_card_name (card, + card->priv->slot = msd_smartcard_find_slot_from_card_name (card, card->priv->name); if (card->priv->slot != NULL) { @@ -296,17 +296,17 @@ gsd_smartcard_set_name (GsdSmartcard *card, slot_id = PK11_GetSlotID (card->priv->slot); if (slot_id != card->priv->slot_id) { - gsd_smartcard_set_slot_id (card, slot_id); + msd_smartcard_set_slot_id (card, slot_id); } slot_series = PK11_GetSlotSeries (card->priv->slot); if (slot_series != card->priv->slot_series) { - gsd_smartcard_set_slot_series (card, slot_series); + msd_smartcard_set_slot_series (card, slot_series); } - _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_INSERTED); + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); } else { - _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_REMOVED); + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); } } @@ -315,14 +315,14 @@ gsd_smartcard_set_name (GsdSmartcard *card, } static void -gsd_smartcard_set_slot_id (GsdSmartcard *card, +msd_smartcard_set_slot_id (MsdSmartcard *card, int slot_id) { if (card->priv->slot_id != slot_id) { card->priv->slot_id = slot_id; if (card->priv->slot == NULL) { - card->priv->slot = gsd_smartcard_find_slot_from_id (card, + card->priv->slot = msd_smartcard_find_slot_from_id (card, card->priv->slot_id); if (card->priv->slot != NULL) { @@ -332,12 +332,12 @@ gsd_smartcard_set_slot_id (GsdSmartcard *card, if ((card->priv->name == NULL) || ((card_name != NULL) && (strcmp (card_name, card->priv->name) != 0))) { - gsd_smartcard_set_name (card, card_name); + msd_smartcard_set_name (card, card_name); } - _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_INSERTED); + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); } else { - _gsd_smartcard_set_state (card, GSD_SMARTCARD_STATE_REMOVED); + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); } } @@ -346,7 +346,7 @@ gsd_smartcard_set_slot_id (GsdSmartcard *card, } static void -gsd_smartcard_set_slot_series (GsdSmartcard *card, +msd_smartcard_set_slot_series (MsdSmartcard *card, int slot_series) { if (card->priv->slot_series != slot_series) { @@ -356,7 +356,7 @@ gsd_smartcard_set_slot_series (GsdSmartcard *card, } static void -gsd_smartcard_set_module (GsdSmartcard *card, +msd_smartcard_set_module (MsdSmartcard *card, SECMODModule *module) { gboolean should_notify; @@ -382,66 +382,66 @@ gsd_smartcard_set_module (GsdSmartcard *card, } int -gsd_smartcard_get_slot_series (GsdSmartcard *card) +msd_smartcard_get_slot_series (MsdSmartcard *card) { return card->priv->slot_series; } static void -gsd_smartcard_init (GsdSmartcard *card) +msd_smartcard_init (MsdSmartcard *card) { g_debug ("initializing smartcard "); card->priv = G_TYPE_INSTANCE_GET_PRIVATE (card, - GSD_TYPE_SMARTCARD, - GsdSmartcardPrivate); + MSD_TYPE_SMARTCARD, + MsdSmartcardPrivate); if (card->priv->slot != NULL) { card->priv->name = g_strdup (PK11_GetTokenName (card->priv->slot)); } } -static void gsd_smartcard_finalize (GObject *object) +static void msd_smartcard_finalize (GObject *object) { - GsdSmartcard *card; + MsdSmartcard *card; GObjectClass *gobject_class; - card = GSD_SMARTCARD (object); + card = MSD_SMARTCARD (object); g_free (card->priv->name); - gsd_smartcard_set_module (card, NULL); + msd_smartcard_set_module (card, NULL); - gobject_class = G_OBJECT_CLASS (gsd_smartcard_parent_class); + gobject_class = G_OBJECT_CLASS (msd_smartcard_parent_class); gobject_class->finalize (object); } -GQuark gsd_smartcard_error_quark (void) +GQuark msd_smartcard_error_quark (void) { static GQuark error_quark = 0; if (error_quark == 0) { - error_quark = g_quark_from_static_string ("gsd-smartcard-error-quark"); + error_quark = g_quark_from_static_string ("msd-smartcard-error-quark"); } return error_quark; } -GsdSmartcard * -_gsd_smartcard_new (SECMODModule *module, +MsdSmartcard * +_msd_smartcard_new (SECMODModule *module, CK_SLOT_ID slot_id, int slot_series) { - GsdSmartcard *card; + MsdSmartcard *card; g_return_val_if_fail (module != NULL, NULL); g_return_val_if_fail (slot_id >= 1, NULL); g_return_val_if_fail (slot_series > 0, NULL); g_return_val_if_fail (sizeof (gulong) == sizeof (slot_id), NULL); - card = GSD_SMARTCARD (g_object_new (GSD_TYPE_SMARTCARD, + card = MSD_SMARTCARD (g_object_new (MSD_TYPE_SMARTCARD, "module", module, "slot-id", (gulong) slot_id, "slot-series", slot_series, @@ -449,16 +449,16 @@ _gsd_smartcard_new (SECMODModule *module, return card; } -GsdSmartcard * -_gsd_smartcard_new_from_name (SECMODModule *module, +MsdSmartcard * +_msd_smartcard_new_from_name (SECMODModule *module, const char *name) { - GsdSmartcard *card; + MsdSmartcard *card; g_return_val_if_fail (module != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); - card = GSD_SMARTCARD (g_object_new (GSD_TYPE_SMARTCARD, + card = MSD_SMARTCARD (g_object_new (MSD_TYPE_SMARTCARD, "module", module, "name", name, NULL)); @@ -466,16 +466,16 @@ _gsd_smartcard_new_from_name (SECMODModule *module, } void -_gsd_smartcard_set_state (GsdSmartcard *card, - GsdSmartcardState state) +_msd_smartcard_set_state (MsdSmartcard *card, + MsdSmartcardState state) { if (card->priv->state != state) { card->priv->state = state; - if (state == GSD_SMARTCARD_STATE_INSERTED) { - g_signal_emit (card, gsd_smartcard_signals[INSERTED], 0); - } else if (state == GSD_SMARTCARD_STATE_REMOVED) { - g_signal_emit (card, gsd_smartcard_signals[REMOVED], 0); + if (state == MSD_SMARTCARD_STATE_INSERTED) { + g_signal_emit (card, msd_smartcard_signals[INSERTED], 0); + } else if (state == MSD_SMARTCARD_STATE_REMOVED) { + g_signal_emit (card, msd_smartcard_signals[REMOVED], 0); } else { g_assert_not_reached (); } @@ -489,7 +489,7 @@ _gsd_smartcard_set_state (GsdSmartcard *card, * and strdup it using NSPR's memory allocation routines. */ static char * -gsd_smartcard_password_handler (PK11SlotInfo *slot, +msd_smartcard_password_handler (PK11SlotInfo *slot, PRBool is_retrying, const char *password) { @@ -501,12 +501,12 @@ gsd_smartcard_password_handler (PK11SlotInfo *slot, } gboolean -gsd_smartcard_unlock (GsdSmartcard *card, +msd_smartcard_unlock (MsdSmartcard *card, const char *password) { SECStatus status; - PK11_SetPasswordFunc ((PK11PasswordFunc) gsd_smartcard_password_handler); + PK11_SetPasswordFunc ((PK11PasswordFunc) msd_smartcard_password_handler); /* we pass PR_TRUE to load certificates */ @@ -520,7 +520,7 @@ gsd_smartcard_unlock (GsdSmartcard *card, } static PK11SlotInfo * -gsd_smartcard_find_slot_from_card_name (GsdSmartcard *card, +msd_smartcard_find_slot_from_card_name (MsdSmartcard *card, const char *card_name) { int i; @@ -540,7 +540,7 @@ gsd_smartcard_find_slot_from_card_name (GsdSmartcard *card, } static PK11SlotInfo * -gsd_smartcard_find_slot_from_id (GsdSmartcard *card, +msd_smartcard_find_slot_from_id (MsdSmartcard *card, int slot_id) { int i; diff --git a/plugins/smartcard/gsd-smartcard.h b/plugins/smartcard/gsd-smartcard.h index c8c1ea7..d00b8af 100644 --- a/plugins/smartcard/gsd-smartcard.h +++ b/plugins/smartcard/gsd-smartcard.h @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ -#ifndef GSD_SMARTCARD_H -#define GSD_SMARTCARD_H +#ifndef MSD_SMARTCARD_H +#define MSD_SMARTCARD_H #include #include @@ -28,71 +28,71 @@ #ifdef __cplusplus extern "C" { #endif -#define GSD_TYPE_SMARTCARD (gsd_smartcard_get_type ()) -#define GSD_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_SMARTCARD, GsdSmartcard)) -#define GSD_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_SMARTCARD, GsdSmartcardClass)) -#define GSD_IS_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_SMARTCARD)) -#define GSD_IS_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_SMARTCARD)) -#define GSD_SMARTCARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GSD_TYPE_SMARTCARD, GsdSmartcardClass)) -#define GSD_SMARTCARD_ERROR (gsd_smartcard_error_quark ()) -typedef struct _GsdSmartcardClass GsdSmartcardClass; -typedef struct _GsdSmartcard GsdSmartcard; -typedef struct _GsdSmartcardPrivate GsdSmartcardPrivate; -typedef enum _GsdSmartcardError GsdSmartcardError; -typedef enum _GsdSmartcardState GsdSmartcardState; - -typedef struct _GsdSmartcardRequest GsdSmartcardRequest; - -struct _GsdSmartcard { +#define MSD_TYPE_SMARTCARD (msd_smartcard_get_type ()) +#define MSD_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_SMARTCARD, MsdSmartcard)) +#define MSD_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_SMARTCARD, MsdSmartcardClass)) +#define MSD_IS_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_SMARTCARD)) +#define MSD_IS_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_SMARTCARD)) +#define MSD_SMARTCARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MSD_TYPE_SMARTCARD, MsdSmartcardClass)) +#define MSD_SMARTCARD_ERROR (msd_smartcard_error_quark ()) +typedef struct _MsdSmartcardClass MsdSmartcardClass; +typedef struct _MsdSmartcard MsdSmartcard; +typedef struct _MsdSmartcardPrivate MsdSmartcardPrivate; +typedef enum _MsdSmartcardError MsdSmartcardError; +typedef enum _MsdSmartcardState MsdSmartcardState; + +typedef struct _MsdSmartcardRequest MsdSmartcardRequest; + +struct _MsdSmartcard { GObject parent; /*< private > */ - GsdSmartcardPrivate *priv; + MsdSmartcardPrivate *priv; }; -struct _GsdSmartcardClass { +struct _MsdSmartcardClass { GObjectClass parent_class; - void (* inserted) (GsdSmartcard *card); - void (* removed) (GsdSmartcard *card); + void (* inserted) (MsdSmartcard *card); + void (* removed) (MsdSmartcard *card); }; -enum _GsdSmartcardError { - GSD_SMARTCARD_ERROR_GENERIC = 0, +enum _MsdSmartcardError { + MSD_SMARTCARD_ERROR_GENERIC = 0, }; -enum _GsdSmartcardState { - GSD_SMARTCARD_STATE_INSERTED = 0, - GSD_SMARTCARD_STATE_REMOVED, +enum _MsdSmartcardState { + MSD_SMARTCARD_STATE_INSERTED = 0, + MSD_SMARTCARD_STATE_REMOVED, }; -GType gsd_smartcard_get_type (void) G_GNUC_CONST; -GQuark gsd_smartcard_error_quark (void) G_GNUC_CONST; +GType msd_smartcard_get_type (void) G_GNUC_CONST; +GQuark msd_smartcard_error_quark (void) G_GNUC_CONST; -CK_SLOT_ID gsd_smartcard_get_slot_id (GsdSmartcard *card); -gint gsd_smartcard_get_slot_series (GsdSmartcard *card); -GsdSmartcardState gsd_smartcard_get_state (GsdSmartcard *card); +CK_SLOT_ID msd_smartcard_get_slot_id (MsdSmartcard *card); +gint msd_smartcard_get_slot_series (MsdSmartcard *card); +MsdSmartcardState msd_smartcard_get_state (MsdSmartcard *card); -char *gsd_smartcard_get_name (GsdSmartcard *card); -gboolean gsd_smartcard_is_login_card (GsdSmartcard *card); +char *msd_smartcard_get_name (MsdSmartcard *card); +gboolean msd_smartcard_is_login_card (MsdSmartcard *card); -gboolean gsd_smartcard_unlock (GsdSmartcard *card, +gboolean msd_smartcard_unlock (MsdSmartcard *card, const char *password); /* don't under any circumstances call these functions */ -#ifdef GSD_SMARTCARD_ENABLE_INTERNAL_API +#ifdef MSD_SMARTCARD_ENABLE_INTERNAL_API -GsdSmartcard *_gsd_smartcard_new (SECMODModule *module, +MsdSmartcard *_msd_smartcard_new (SECMODModule *module, CK_SLOT_ID slot_id, gint slot_series); -GsdSmartcard *_gsd_smartcard_new_from_name (SECMODModule *module, +MsdSmartcard *_msd_smartcard_new_from_name (SECMODModule *module, const char *name); -void _gsd_smartcard_set_state (GsdSmartcard *card, - GsdSmartcardState state); +void _msd_smartcard_set_state (MsdSmartcard *card, + MsdSmartcardState state); #endif #ifdef __cplusplus } #endif -#endif /* GSD_SMARTCARD_H */ +#endif /* MSD_SMARTCARD_H */ diff --git a/plugins/sound/Makefile.am b/plugins/sound/Makefile.am index 7caf2ac..3e93c7c 100644 --- a/plugins/sound/Makefile.am +++ b/plugins/sound/Makefile.am @@ -2,10 +2,10 @@ plugin_LTLIBRARIES = \ libsound.la libsound_la_SOURCES = \ - gsd-sound-plugin.h \ - gsd-sound-plugin.c \ - gsd-sound-manager.h \ - gsd-sound-manager.c + msd-sound-plugin.h \ + msd-sound-plugin.c \ + msd-sound-manager.h \ + msd-sound-manager.c libsound_la_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ @@ -19,7 +19,7 @@ libsound_la_CFLAGS = \ $(AM_CFLAGS) libsound_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) + $(MSD_PLUGIN_LDFLAGS) libsound_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) \ @@ -39,4 +39,4 @@ CLEANFILES = \ DISTCLEANFILES = \ $(plugin_DATA) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/sound/gsd-sound-manager.c b/plugins/sound/gsd-sound-manager.c index 4b32130..23fb240 100644 --- a/plugins/sound/gsd-sound-manager.c +++ b/plugins/sound/gsd-sound-manager.c @@ -40,12 +40,12 @@ #include #endif -#include "gsd-sound-manager.h" +#include "msd-sound-manager.h" #include "mate-settings-profile.h" -#define GSD_SOUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SOUND_MANAGER, GsdSoundManagerPrivate)) +#define MSD_SOUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerPrivate)) -struct GsdSoundManagerPrivate +struct MsdSoundManagerPrivate { guint mateconf_notify; GList* monitors; @@ -54,11 +54,11 @@ struct GsdSoundManagerPrivate #define MATECONF_SOUND_DIR "/desktop/mate/sound" -static void gsd_sound_manager_class_init (GsdSoundManagerClass *klass); -static void gsd_sound_manager_init (GsdSoundManager *sound_manager); -static void gsd_sound_manager_finalize (GObject *object); +static void msd_sound_manager_class_init (MsdSoundManagerClass *klass); +static void msd_sound_manager_init (MsdSoundManager *sound_manager); +static void msd_sound_manager_finalize (GObject *object); -G_DEFINE_TYPE (GsdSoundManager, gsd_sound_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdSoundManager, msd_sound_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -185,7 +185,7 @@ fail: } static gboolean -flush_cb (GsdSoundManager *manager) +flush_cb (MsdSoundManager *manager) { flush_cache (); manager->priv->timeout = 0; @@ -193,7 +193,7 @@ flush_cb (GsdSoundManager *manager) } static void -trigger_flush (GsdSoundManager *manager) +trigger_flush (MsdSoundManager *manager) { if (manager->priv->timeout) @@ -208,13 +208,13 @@ static void mateconf_client_notify_cb (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdSoundManager *manager) + MsdSoundManager *manager) { trigger_flush (manager); } static gboolean -register_config_callback (GsdSoundManager *manager, GError **error) +register_config_callback (MsdSoundManager *manager, GError **error) { MateConfClient *client; gboolean succ; @@ -239,14 +239,14 @@ file_monitor_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event, - GsdSoundManager *manager) + MsdSoundManager *manager) { g_debug ("Theme dir changed"); trigger_flush (manager); } static gboolean -register_directory_callback (GsdSoundManager *manager, +register_directory_callback (MsdSoundManager *manager, const char *path, GError **error) { @@ -276,7 +276,7 @@ register_directory_callback (GsdSoundManager *manager, #endif gboolean -gsd_sound_manager_start (GsdSoundManager *manager, +msd_sound_manager_start (MsdSoundManager *manager, GError **error) { @@ -326,7 +326,7 @@ gsd_sound_manager_start (GsdSoundManager *manager, } void -gsd_sound_manager_stop (GsdSoundManager *manager) +msd_sound_manager_stop (MsdSoundManager *manager) { g_debug ("Stopping sound manager"); @@ -356,17 +356,17 @@ gsd_sound_manager_stop (GsdSoundManager *manager) } static GObject * -gsd_sound_manager_constructor ( +msd_sound_manager_constructor ( GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdSoundManager *m; - GsdSoundManagerClass *klass; + MsdSoundManager *m; + MsdSoundManagerClass *klass; - klass = GSD_SOUND_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_SOUND_MANAGER)); + klass = MSD_SOUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_SOUND_MANAGER)); - m = GSD_SOUND_MANAGER (G_OBJECT_CLASS (gsd_sound_manager_parent_class)->constructor ( + m = MSD_SOUND_MANAGER (G_OBJECT_CLASS (msd_sound_manager_parent_class)->constructor ( type, n_construct_properties, construct_properties)); @@ -375,59 +375,59 @@ gsd_sound_manager_constructor ( } static void -gsd_sound_manager_dispose (GObject *object) +msd_sound_manager_dispose (GObject *object) { - GsdSoundManager *manager; + MsdSoundManager *manager; - manager = GSD_SOUND_MANAGER (object); + manager = MSD_SOUND_MANAGER (object); - gsd_sound_manager_stop (manager); + msd_sound_manager_stop (manager); - G_OBJECT_CLASS (gsd_sound_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_sound_manager_parent_class)->dispose (object); } static void -gsd_sound_manager_class_init (GsdSoundManagerClass *klass) +msd_sound_manager_class_init (MsdSoundManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->constructor = gsd_sound_manager_constructor; - object_class->dispose = gsd_sound_manager_dispose; - object_class->finalize = gsd_sound_manager_finalize; + object_class->constructor = msd_sound_manager_constructor; + object_class->dispose = msd_sound_manager_dispose; + object_class->finalize = msd_sound_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdSoundManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdSoundManagerPrivate)); } static void -gsd_sound_manager_init (GsdSoundManager *manager) +msd_sound_manager_init (MsdSoundManager *manager) { - manager->priv = GSD_SOUND_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_SOUND_MANAGER_GET_PRIVATE (manager); } static void -gsd_sound_manager_finalize (GObject *object) +msd_sound_manager_finalize (GObject *object) { - GsdSoundManager *sound_manager; + MsdSoundManager *sound_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_SOUND_MANAGER (object)); + g_return_if_fail (MSD_IS_SOUND_MANAGER (object)); - sound_manager = GSD_SOUND_MANAGER (object); + sound_manager = MSD_SOUND_MANAGER (object); g_return_if_fail (sound_manager->priv); - G_OBJECT_CLASS (gsd_sound_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_sound_manager_parent_class)->finalize (object); } -GsdSoundManager * -gsd_sound_manager_new (void) +MsdSoundManager * +msd_sound_manager_new (void) { if (manager_object) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_SOUND_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_SOUND_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_SOUND_MANAGER (manager_object); + return MSD_SOUND_MANAGER (manager_object); } diff --git a/plugins/sound/gsd-sound-manager.h b/plugins/sound/gsd-sound-manager.h index e640f09..ee4f6f5 100644 --- a/plugins/sound/gsd-sound-manager.h +++ b/plugins/sound/gsd-sound-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_SOUND_MANAGER_H -#define __GSD_SOUND_MANAGER_H +#ifndef __MSD_SOUND_MANAGER_H +#define __MSD_SOUND_MANAGER_H #include #include @@ -28,34 +28,34 @@ extern "C" { #endif -#define GSD_TYPE_SOUND_MANAGER (gsd_sound_manager_get_type ()) -#define GSD_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SOUND_MANAGER, GsdSoundManager)) -#define GSD_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_SOUND_MANAGER, GsdSoundManagerClass)) -#define GSD_IS_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SOUND_MANAGER)) -#define GSD_IS_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SOUND_MANAGER)) -#define GSD_SOUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SOUND_MANAGER, GsdSoundManagerClass)) +#define MSD_TYPE_SOUND_MANAGER (msd_sound_manager_get_type ()) +#define MSD_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManager)) +#define MSD_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) +#define MSD_IS_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_MANAGER)) +#define MSD_IS_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_MANAGER)) +#define MSD_SOUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) -typedef struct GsdSoundManagerPrivate GsdSoundManagerPrivate; +typedef struct MsdSoundManagerPrivate MsdSoundManagerPrivate; typedef struct { GObject parent; - GsdSoundManagerPrivate *priv; -} GsdSoundManager; + MsdSoundManagerPrivate *priv; +} MsdSoundManager; typedef struct { GObjectClass parent_class; -} GsdSoundManagerClass; +} MsdSoundManagerClass; -GType gsd_sound_manager_get_type (void) G_GNUC_CONST; +GType msd_sound_manager_get_type (void) G_GNUC_CONST; -GsdSoundManager *gsd_sound_manager_new (void); -gboolean gsd_sound_manager_start (GsdSoundManager *manager, GError **error); -void gsd_sound_manager_stop (GsdSoundManager *manager); +MsdSoundManager *msd_sound_manager_new (void); +gboolean msd_sound_manager_start (MsdSoundManager *manager, GError **error); +void msd_sound_manager_stop (MsdSoundManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_SOUND_MANAGER_H */ +#endif /* __MSD_SOUND_MANAGER_H */ diff --git a/plugins/sound/gsd-sound-plugin.c b/plugins/sound/gsd-sound-plugin.c index 88168bf..28a2c85 100644 --- a/plugins/sound/gsd-sound-plugin.c +++ b/plugins/sound/gsd-sound-plugin.c @@ -24,45 +24,45 @@ #include #include "mate-settings-plugin.h" -#include "gsd-sound-plugin.h" -#include "gsd-sound-manager.h" +#include "msd-sound-plugin.h" +#include "msd-sound-manager.h" -struct GsdSoundPluginPrivate { - GsdSoundManager *manager; +struct MsdSoundPluginPrivate { + MsdSoundManager *manager; }; -#define GSD_SOUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_SOUND_PLUGIN, GsdSoundPluginPrivate)) +#define MSD_SOUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdSoundPlugin, gsd_sound_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdSoundPlugin, msd_sound_plugin) static void -gsd_sound_plugin_init (GsdSoundPlugin *plugin) +msd_sound_plugin_init (MsdSoundPlugin *plugin) { - plugin->priv = GSD_SOUND_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_SOUND_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdSoundPlugin initializing"); + g_debug ("MsdSoundPlugin initializing"); - plugin->priv->manager = gsd_sound_manager_new (); + plugin->priv->manager = msd_sound_manager_new (); } static void -gsd_sound_plugin_finalize (GObject *object) +msd_sound_plugin_finalize (GObject *object) { - GsdSoundPlugin *plugin; + MsdSoundPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_SOUND_PLUGIN (object)); + g_return_if_fail (MSD_IS_SOUND_PLUGIN (object)); - g_debug ("GsdSoundPlugin finalizing"); + g_debug ("MsdSoundPlugin finalizing"); - plugin = GSD_SOUND_PLUGIN (object); + plugin = MSD_SOUND_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); if (plugin->priv->manager != NULL) g_object_unref (plugin->priv->manager); - G_OBJECT_CLASS (gsd_sound_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_sound_plugin_parent_class)->finalize (object); } static void @@ -72,7 +72,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating sound plugin"); - if (!gsd_sound_manager_start (GSD_SOUND_PLUGIN (plugin)->priv->manager, &error)) { + if (!msd_sound_manager_start (MSD_SOUND_PLUGIN (plugin)->priv->manager, &error)) { g_warning ("Unable to start sound manager: %s", error->message); g_error_free (error); } @@ -82,19 +82,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating sound plugin"); - gsd_sound_manager_stop (GSD_SOUND_PLUGIN (plugin)->priv->manager); + msd_sound_manager_stop (MSD_SOUND_PLUGIN (plugin)->priv->manager); } static void -gsd_sound_plugin_class_init (GsdSoundPluginClass *klass) +msd_sound_plugin_class_init (MsdSoundPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_sound_plugin_finalize; + object_class->finalize = msd_sound_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdSoundPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdSoundPluginPrivate)); } diff --git a/plugins/sound/gsd-sound-plugin.h b/plugins/sound/gsd-sound-plugin.h index 660e159..b1dac8a 100644 --- a/plugins/sound/gsd-sound-plugin.h +++ b/plugins/sound/gsd-sound-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_SOUND_PLUGIN_H__ -#define __GSD_SOUND_PLUGIN_H__ +#ifndef __MSD_SOUND_PLUGIN_H__ +#define __MSD_SOUND_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_SOUND_PLUGIN (gsd_sound_plugin_get_type ()) -#define GSD_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_SOUND_PLUGIN, GsdSoundPlugin)) -#define GSD_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSD_TYPE_SOUND_PLUGIN, GsdSoundPluginClass)) -#define GSD_IS_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_SOUND_PLUGIN)) -#define GSD_IS_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_SOUND_PLUGIN)) -#define GSD_SOUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_SOUND_PLUGIN, GsdSoundPluginClass)) +#define MSD_TYPE_SOUND_PLUGIN (msd_sound_plugin_get_type ()) +#define MSD_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPlugin)) +#define MSD_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) +#define MSD_IS_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_PLUGIN)) +#define MSD_IS_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_PLUGIN)) +#define MSD_SOUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) -typedef struct GsdSoundPluginPrivate GsdSoundPluginPrivate; +typedef struct MsdSoundPluginPrivate MsdSoundPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdSoundPluginPrivate *priv; -} GsdSoundPlugin; + MsdSoundPluginPrivate *priv; +} MsdSoundPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdSoundPluginClass; +} MsdSoundPluginClass; -GType gsd_sound_plugin_get_type (void) G_GNUC_CONST; +GType msd_sound_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_SOUND_PLUGIN_H__ */ +#endif /* __MSD_SOUND_PLUGIN_H__ */ diff --git a/plugins/typing-break/Makefile.am b/plugins/typing-break/Makefile.am index 0648007..334d03c 100644 --- a/plugins/typing-break/Makefile.am +++ b/plugins/typing-break/Makefile.am @@ -5,10 +5,10 @@ plugin_LTLIBRARIES = \ $(NULL) libtyping_break_la_SOURCES = \ - gsd-typing-break-plugin.h \ - gsd-typing-break-plugin.c \ - gsd-typing-break-manager.h \ - gsd-typing-break-manager.c \ + msd-typing-break-plugin.h \ + msd-typing-break-plugin.c \ + msd-typing-break-manager.h \ + msd-typing-break-manager.c \ $(NULL) libtyping_break_la_CPPFLAGS = \ @@ -21,7 +21,7 @@ libtyping_break_la_CFLAGS = \ $(AM_CFLAGS) libtyping_break_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libtyping_break_la_LIBADD = \ @@ -46,4 +46,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/typing-break/gsd-typing-break-manager.c b/plugins/typing-break/gsd-typing-break-manager.c index d157964..113f6be 100644 --- a/plugins/typing-break/gsd-typing-break-manager.c +++ b/plugins/typing-break/gsd-typing-break-manager.c @@ -39,13 +39,13 @@ #include #include "mate-settings-profile.h" -#include "gsd-typing-break-manager.h" +#include "msd-typing-break-manager.h" -#define GSD_TYPING_BREAK_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_TYPING_BREAK_MANAGER, GsdTypingBreakManagerPrivate)) +#define MSD_TYPING_BREAK_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerPrivate)) #define MATECONF_BREAK_DIR "/desktop/mate/typing_break" -struct GsdTypingBreakManagerPrivate +struct MsdTypingBreakManagerPrivate { GPid typing_monitor_pid; guint typing_monitor_idle_id; @@ -54,16 +54,16 @@ struct GsdTypingBreakManagerPrivate guint notify; }; -static void gsd_typing_break_manager_class_init (GsdTypingBreakManagerClass *klass); -static void gsd_typing_break_manager_init (GsdTypingBreakManager *typing_break_manager); -static void gsd_typing_break_manager_finalize (GObject *object); +static void msd_typing_break_manager_class_init (MsdTypingBreakManagerClass *klass); +static void msd_typing_break_manager_init (MsdTypingBreakManager *typing_break_manager); +static void msd_typing_break_manager_finalize (GObject *object); -G_DEFINE_TYPE (GsdTypingBreakManager, gsd_typing_break_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdTypingBreakManager, msd_typing_break_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static gboolean -typing_break_timeout (GsdTypingBreakManager *manager) +typing_break_timeout (MsdTypingBreakManager *manager) { if (manager->priv->typing_monitor_pid > 0) { kill (manager->priv->typing_monitor_pid, SIGKILL); @@ -77,7 +77,7 @@ typing_break_timeout (GsdTypingBreakManager *manager) static void child_watch (GPid pid, int status, - GsdTypingBreakManager *manager) + MsdTypingBreakManager *manager) { if (pid == manager->priv->typing_monitor_pid) { manager->priv->typing_monitor_pid = 0; @@ -86,7 +86,7 @@ child_watch (GPid pid, } static void -setup_typing_break (GsdTypingBreakManager *manager, +setup_typing_break (MsdTypingBreakManager *manager, gboolean enabled) { mate_settings_profile_start (NULL); @@ -140,7 +140,7 @@ static void typing_break_callback (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdTypingBreakManager *manager) + MsdTypingBreakManager *manager) { if (! strcmp (entry->key, "/desktop/mate/typing_break/enabled")) { if (entry->value->type == MATECONF_VALUE_BOOL) { @@ -150,7 +150,7 @@ typing_break_callback (MateConfClient *client, } static gboolean -really_setup_typing_break (GsdTypingBreakManager *manager) +really_setup_typing_break (MsdTypingBreakManager *manager) { setup_typing_break (manager, TRUE); manager->priv->setup_id = 0; @@ -158,7 +158,7 @@ really_setup_typing_break (GsdTypingBreakManager *manager) } gboolean -gsd_typing_break_manager_start (GsdTypingBreakManager *manager, +msd_typing_break_manager_start (MsdTypingBreakManager *manager, GError **error) { MateConfClient *client; @@ -191,9 +191,9 @@ gsd_typing_break_manager_start (GsdTypingBreakManager *manager, } void -gsd_typing_break_manager_stop (GsdTypingBreakManager *manager) +msd_typing_break_manager_stop (MsdTypingBreakManager *manager) { - GsdTypingBreakManagerPrivate *p = manager->priv; + MsdTypingBreakManagerPrivate *p = manager->priv; g_debug ("Stopping typing_break manager"); @@ -228,14 +228,14 @@ gsd_typing_break_manager_stop (GsdTypingBreakManager *manager) } static void -gsd_typing_break_manager_set_property (GObject *object, +msd_typing_break_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdTypingBreakManager *self; + MsdTypingBreakManager *self; - self = GSD_TYPING_BREAK_MANAGER (object); + self = MSD_TYPING_BREAK_MANAGER (object); switch (prop_id) { default: @@ -245,14 +245,14 @@ gsd_typing_break_manager_set_property (GObject *object, } static void -gsd_typing_break_manager_get_property (GObject *object, +msd_typing_break_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdTypingBreakManager *self; + MsdTypingBreakManager *self; - self = GSD_TYPING_BREAK_MANAGER (object); + self = MSD_TYPING_BREAK_MANAGER (object); switch (prop_id) { default: @@ -262,16 +262,16 @@ gsd_typing_break_manager_get_property (GObject *object, } static GObject * -gsd_typing_break_manager_constructor (GType type, +msd_typing_break_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdTypingBreakManager *typing_break_manager; - GsdTypingBreakManagerClass *klass; + MsdTypingBreakManager *typing_break_manager; + MsdTypingBreakManagerClass *klass; - klass = GSD_TYPING_BREAK_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_TYPING_BREAK_MANAGER)); + klass = MSD_TYPING_BREAK_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_TYPING_BREAK_MANAGER)); - typing_break_manager = GSD_TYPING_BREAK_MANAGER (G_OBJECT_CLASS (gsd_typing_break_manager_parent_class)->constructor (type, + typing_break_manager = MSD_TYPING_BREAK_MANAGER (G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -279,61 +279,61 @@ gsd_typing_break_manager_constructor (GType type, } static void -gsd_typing_break_manager_dispose (GObject *object) +msd_typing_break_manager_dispose (GObject *object) { - GsdTypingBreakManager *typing_break_manager; + MsdTypingBreakManager *typing_break_manager; - typing_break_manager = GSD_TYPING_BREAK_MANAGER (object); + typing_break_manager = MSD_TYPING_BREAK_MANAGER (object); - G_OBJECT_CLASS (gsd_typing_break_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->dispose (object); } static void -gsd_typing_break_manager_class_init (GsdTypingBreakManagerClass *klass) +msd_typing_break_manager_class_init (MsdTypingBreakManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_typing_break_manager_get_property; - object_class->set_property = gsd_typing_break_manager_set_property; - object_class->constructor = gsd_typing_break_manager_constructor; - object_class->dispose = gsd_typing_break_manager_dispose; - object_class->finalize = gsd_typing_break_manager_finalize; + object_class->get_property = msd_typing_break_manager_get_property; + object_class->set_property = msd_typing_break_manager_set_property; + object_class->constructor = msd_typing_break_manager_constructor; + object_class->dispose = msd_typing_break_manager_dispose; + object_class->finalize = msd_typing_break_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdTypingBreakManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdTypingBreakManagerPrivate)); } static void -gsd_typing_break_manager_init (GsdTypingBreakManager *manager) +msd_typing_break_manager_init (MsdTypingBreakManager *manager) { - manager->priv = GSD_TYPING_BREAK_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_TYPING_BREAK_MANAGER_GET_PRIVATE (manager); } static void -gsd_typing_break_manager_finalize (GObject *object) +msd_typing_break_manager_finalize (GObject *object) { - GsdTypingBreakManager *typing_break_manager; + MsdTypingBreakManager *typing_break_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_TYPING_BREAK_MANAGER (object)); + g_return_if_fail (MSD_IS_TYPING_BREAK_MANAGER (object)); - typing_break_manager = GSD_TYPING_BREAK_MANAGER (object); + typing_break_manager = MSD_TYPING_BREAK_MANAGER (object); g_return_if_fail (typing_break_manager->priv != NULL); - G_OBJECT_CLASS (gsd_typing_break_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->finalize (object); } -GsdTypingBreakManager * -gsd_typing_break_manager_new (void) +MsdTypingBreakManager * +msd_typing_break_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_TYPING_BREAK_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_TYPING_BREAK_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_TYPING_BREAK_MANAGER (manager_object); + return MSD_TYPING_BREAK_MANAGER (manager_object); } diff --git a/plugins/typing-break/gsd-typing-break-manager.h b/plugins/typing-break/gsd-typing-break-manager.h index e4ac24d..d490a0e 100644 --- a/plugins/typing-break/gsd-typing-break-manager.h +++ b/plugins/typing-break/gsd-typing-break-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_TYPING_BREAK_MANAGER_H -#define __GSD_TYPING_BREAK_MANAGER_H +#ifndef __MSD_TYPING_BREAK_MANAGER_H +#define __MSD_TYPING_BREAK_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_TYPING_BREAK_MANAGER (gsd_typing_break_manager_get_type ()) -#define GSD_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_TYPING_BREAK_MANAGER, GsdTypingBreakManager)) -#define GSD_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_TYPING_BREAK_MANAGER, GsdTypingBreakManagerClass)) -#define GSD_IS_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_TYPING_BREAK_MANAGER)) -#define GSD_IS_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_TYPING_BREAK_MANAGER)) -#define GSD_TYPING_BREAK_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_TYPING_BREAK_MANAGER, GsdTypingBreakManagerClass)) +#define MSD_TYPE_TYPING_BREAK_MANAGER (msd_typing_break_manager_get_type ()) +#define MSD_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManager)) +#define MSD_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerClass)) +#define MSD_IS_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_TYPING_BREAK_MANAGER)) +#define MSD_IS_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_TYPING_BREAK_MANAGER)) +#define MSD_TYPING_BREAK_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerClass)) -typedef struct GsdTypingBreakManagerPrivate GsdTypingBreakManagerPrivate; +typedef struct MsdTypingBreakManagerPrivate MsdTypingBreakManagerPrivate; typedef struct { GObject parent; - GsdTypingBreakManagerPrivate *priv; -} GsdTypingBreakManager; + MsdTypingBreakManagerPrivate *priv; +} MsdTypingBreakManager; typedef struct { GObjectClass parent_class; -} GsdTypingBreakManagerClass; +} MsdTypingBreakManagerClass; -GType gsd_typing_break_manager_get_type (void); +GType msd_typing_break_manager_get_type (void); -GsdTypingBreakManager * gsd_typing_break_manager_new (void); -gboolean gsd_typing_break_manager_start (GsdTypingBreakManager *manager, +MsdTypingBreakManager * msd_typing_break_manager_new (void); +gboolean msd_typing_break_manager_start (MsdTypingBreakManager *manager, GError **error); -void gsd_typing_break_manager_stop (GsdTypingBreakManager *manager); +void msd_typing_break_manager_stop (MsdTypingBreakManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_TYPING_BREAK_MANAGER_H */ +#endif /* __MSD_TYPING_BREAK_MANAGER_H */ diff --git a/plugins/typing-break/gsd-typing-break-plugin.c b/plugins/typing-break/gsd-typing-break-plugin.c index 0f0535d..dcf3326 100644 --- a/plugins/typing-break/gsd-typing-break-plugin.c +++ b/plugins/typing-break/gsd-typing-break-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-typing-break-plugin.h" -#include "gsd-typing-break-manager.h" +#include "msd-typing-break-plugin.h" +#include "msd-typing-break-manager.h" -struct GsdTypingBreakPluginPrivate { - GsdTypingBreakManager *manager; +struct MsdTypingBreakPluginPrivate { + MsdTypingBreakManager *manager; }; -#define GSD_TYPING_BREAK_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_TYPING_BREAK_PLUGIN, GsdTypingBreakPluginPrivate)) +#define MSD_TYPING_BREAK_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdTypingBreakPlugin, gsd_typing_break_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdTypingBreakPlugin, msd_typing_break_plugin) static void -gsd_typing_break_plugin_init (GsdTypingBreakPlugin *plugin) +msd_typing_break_plugin_init (MsdTypingBreakPlugin *plugin) { - plugin->priv = GSD_TYPING_BREAK_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_TYPING_BREAK_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdTypingBreakPlugin initializing"); + g_debug ("MsdTypingBreakPlugin initializing"); - plugin->priv->manager = gsd_typing_break_manager_new (); + plugin->priv->manager = msd_typing_break_manager_new (); } static void -gsd_typing_break_plugin_finalize (GObject *object) +msd_typing_break_plugin_finalize (GObject *object) { - GsdTypingBreakPlugin *plugin; + MsdTypingBreakPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_TYPING_BREAK_PLUGIN (object)); + g_return_if_fail (MSD_IS_TYPING_BREAK_PLUGIN (object)); - g_debug ("GsdTypingBreakPlugin finalizing"); + g_debug ("MsdTypingBreakPlugin finalizing"); - plugin = GSD_TYPING_BREAK_PLUGIN (object); + plugin = MSD_TYPING_BREAK_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_typing_break_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_typing_break_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_typing_break_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating typing_break plugin"); error = NULL; - res = gsd_typing_break_manager_start (GSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager, &error); + res = msd_typing_break_manager_start (MSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start typing_break manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating typing_break plugin"); - gsd_typing_break_manager_stop (GSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager); + msd_typing_break_manager_stop (MSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager); } static void -gsd_typing_break_plugin_class_init (GsdTypingBreakPluginClass *klass) +msd_typing_break_plugin_class_init (MsdTypingBreakPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_typing_break_plugin_finalize; + object_class->finalize = msd_typing_break_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdTypingBreakPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdTypingBreakPluginPrivate)); } diff --git a/plugins/typing-break/gsd-typing-break-plugin.h b/plugins/typing-break/gsd-typing-break-plugin.h index b7bbf16..54bde6e 100644 --- a/plugins/typing-break/gsd-typing-break-plugin.h +++ b/plugins/typing-break/gsd-typing-break-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_TYPING_BREAK_PLUGIN_H__ -#define __GSD_TYPING_BREAK_PLUGIN_H__ +#ifndef __MSD_TYPING_BREAK_PLUGIN_H__ +#define __MSD_TYPING_BREAK_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_TYPING_BREAK_PLUGIN (gsd_typing_break_plugin_get_type ()) -#define GSD_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_TYPING_BREAK_PLUGIN, GsdTypingBreakPlugin)) -#define GSD_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_TYPING_BREAK_PLUGIN, GsdTypingBreakPluginClass)) -#define GSD_IS_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_TYPING_BREAK_PLUGIN)) -#define GSD_IS_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_TYPING_BREAK_PLUGIN)) -#define GSD_TYPING_BREAK_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_TYPING_BREAK_PLUGIN, GsdTypingBreakPluginClass)) +#define MSD_TYPE_TYPING_BREAK_PLUGIN (msd_typing_break_plugin_get_type ()) +#define MSD_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPlugin)) +#define MSD_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginClass)) +#define MSD_IS_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_TYPING_BREAK_PLUGIN)) +#define MSD_IS_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_TYPING_BREAK_PLUGIN)) +#define MSD_TYPING_BREAK_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginClass)) -typedef struct GsdTypingBreakPluginPrivate GsdTypingBreakPluginPrivate; +typedef struct MsdTypingBreakPluginPrivate MsdTypingBreakPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdTypingBreakPluginPrivate *priv; -} GsdTypingBreakPlugin; + MsdTypingBreakPluginPrivate *priv; +} MsdTypingBreakPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdTypingBreakPluginClass; +} MsdTypingBreakPluginClass; -GType gsd_typing_break_plugin_get_type (void) G_GNUC_CONST; +GType msd_typing_break_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_TYPING_BREAK_PLUGIN_H__ */ +#endif /* __MSD_TYPING_BREAK_PLUGIN_H__ */ diff --git a/plugins/xrandr/Makefile.am b/plugins/xrandr/Makefile.am index b7d8684..1a398d7 100644 --- a/plugins/xrandr/Makefile.am +++ b/plugins/xrandr/Makefile.am @@ -2,14 +2,14 @@ icondir = $(datadir)/icons/mate context = apps BUILT_SOURCES = \ - gsd-xrandr-manager-glue.h + msd-xrandr-manager-glue.h ICON_FILES = \ - gsd-xrandr-16.png \ - gsd-xrandr-22.png \ - gsd-xrandr-24.png \ - gsd-xrandr-32.png \ - gsd-xrandr.svg + msd-xrandr-16.png \ + msd-xrandr-22.png \ + msd-xrandr-24.png \ + msd-xrandr-32.png \ + msd-xrandr.svg install-data-local: $(mkinstalldirs) $(DESTDIR)$(sysconfdir)/mate-settings-daemon/xrandr @@ -18,33 +18,33 @@ install-data-local: $(mkinstalldirs) $(DESTDIR)$(icondir)/24x24/$(context) $(mkinstalldirs) $(DESTDIR)$(icondir)/32x32/$(context) $(mkinstalldirs) $(DESTDIR)$(icondir)/scalable/$(context) - $(INSTALL_DATA) $(srcdir)/gsd-xrandr-16.png $(DESTDIR)$(icondir)/16x16/$(context)/gsd-xrandr.png - $(INSTALL_DATA) $(srcdir)/gsd-xrandr-22.png $(DESTDIR)$(icondir)/22x22/$(context)/gsd-xrandr.png - $(INSTALL_DATA) $(srcdir)/gsd-xrandr-24.png $(DESTDIR)$(icondir)/24x24/$(context)/gsd-xrandr.png - $(INSTALL_DATA) $(srcdir)/gsd-xrandr-32.png $(DESTDIR)$(icondir)/32x32/$(context)/gsd-xrandr.png - $(INSTALL_DATA) $(srcdir)/gsd-xrandr.svg $(DESTDIR)$(icondir)/scalable/$(context)/gsd-xrandr.svg + $(INSTALL_DATA) $(srcdir)/msd-xrandr-16.png $(DESTDIR)$(icondir)/16x16/$(context)/msd-xrandr.png + $(INSTALL_DATA) $(srcdir)/msd-xrandr-22.png $(DESTDIR)$(icondir)/22x22/$(context)/msd-xrandr.png + $(INSTALL_DATA) $(srcdir)/msd-xrandr-24.png $(DESTDIR)$(icondir)/24x24/$(context)/msd-xrandr.png + $(INSTALL_DATA) $(srcdir)/msd-xrandr-32.png $(DESTDIR)$(icondir)/32x32/$(context)/msd-xrandr.png + $(INSTALL_DATA) $(srcdir)/msd-xrandr.svg $(DESTDIR)$(icondir)/scalable/$(context)/msd-xrandr.svg uninstall-local: - rm -f $(DESTDIR)$(icondir)/16x16/$(context)/gsd-xrandr.png - rm -f $(DESTDIR)$(icondir)/22x22/$(context)/gsd-xrandr.png - rm -f $(DESTDIR)$(icondir)/24x24/$(context)/gsd-xrandr.png - rm -f $(DESTDIR)$(icondir)/32x32/$(context)/gsd-xrandr.png - rm -f $(DESTDIR)$(icondir)/scalable/$(context)/gsd-xrandr.svg + rm -f $(DESTDIR)$(icondir)/16x16/$(context)/msd-xrandr.png + rm -f $(DESTDIR)$(icondir)/22x22/$(context)/msd-xrandr.png + rm -f $(DESTDIR)$(icondir)/24x24/$(context)/msd-xrandr.png + rm -f $(DESTDIR)$(icondir)/32x32/$(context)/msd-xrandr.png + rm -f $(DESTDIR)$(icondir)/scalable/$(context)/msd-xrandr.svg plugin_LTLIBRARIES = \ libxrandr.la -gsd-xrandr-manager-glue.h: gsd-xrandr-manager.xml Makefile - dbus-binding-tool --prefix=gsd_xrandr_manager --mode=glib-server $< > xgen-$(@F) \ +msd-xrandr-manager-glue.h: msd-xrandr-manager.xml Makefile + dbus-binding-tool --prefix=msd_xrandr_manager --mode=glib-server $< > xgen-$(@F) \ && ( cmp -s xgen-$(@F) $@ || cp xgen-$(@F) $@ ) \ && rm -f xgen-$(@F) libxrandr_la_SOURCES = \ $(BUILT_SOURCES) \ - gsd-xrandr-plugin.h \ - gsd-xrandr-plugin.c \ - gsd-xrandr-manager.h \ - gsd-xrandr-manager.c + msd-xrandr-plugin.h \ + msd-xrandr-plugin.c \ + msd-xrandr-manager.h \ + msd-xrandr-manager.c libxrandr_la_CPPFLAGS = \ -I$(top_srcdir)/mate-settings-daemon \ @@ -58,7 +58,7 @@ libxrandr_la_CFLAGS = \ $(AM_CFLAGS) libxrandr_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) + $(MSD_PLUGIN_LDFLAGS) libxrandr_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) \ @@ -69,8 +69,8 @@ plugin_in_files = \ plugin_DATA = $(plugin_in_files:.mate-settings-plugin.in=.mate-settings-plugin) -EXTRA_DIST = $(plugin_in_files) $(ICON_FILES) gsd-xrandr-manager.xml +EXTRA_DIST = $(plugin_in_files) $(ICON_FILES) msd-xrandr-manager.xml CLEANFILES = $(plugin_DATA) $(BUILT_SOURCES) DISTCLEANFILES = $(plugin_DATA) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c index b8d9c66..dc00be1 100644 --- a/plugins/xrandr/gsd-xrandr-manager.c +++ b/plugins/xrandr/gsd-xrandr-manager.c @@ -51,13 +51,13 @@ #endif #include "mate-settings-profile.h" -#include "gsd-xrandr-manager.h" +#include "msd-xrandr-manager.h" #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 255 #endif -#define GSD_XRANDR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_XRANDR_MANAGER, GsdXrandrManagerPrivate)) +#define MSD_XRANDR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerPrivate)) #define CONF_DIR "/apps/mate_settings_daemon/xrandr" #define CONF_KEY_SHOW_NOTIFICATION_ICON (CONF_DIR "/show_notification_icon") @@ -73,18 +73,18 @@ */ #define CONFIRMATION_DIALOG_SECONDS 30 -/* name of the icon files (gsd-xrandr.svg, etc.) */ -#define GSD_XRANDR_ICON_NAME "gsd-xrandr" +/* name of the icon files (msd-xrandr.svg, etc.) */ +#define MSD_XRANDR_ICON_NAME "msd-xrandr" /* executable of the control center's display configuration capplet */ -#define GSD_XRANDR_DISPLAY_CAPPLET "mate-control-center display" +#define MSD_XRANDR_DISPLAY_CAPPLET "mate-control-center display" -#define GSD_DBUS_PATH "/org/mate/SettingsDaemon" -#define GSD_DBUS_NAME "org.mate.SettingsDaemon" -#define GSD_XRANDR_DBUS_PATH GSD_DBUS_PATH "/XRANDR" -#define GSD_XRANDR_DBUS_NAME GSD_DBUS_NAME ".XRANDR" +#define MSD_DBUS_PATH "/org/mate/SettingsDaemon" +#define MSD_DBUS_NAME "org.mate.SettingsDaemon" +#define MSD_XRANDR_DBUS_PATH MSD_DBUS_PATH "/XRANDR" +#define MSD_XRANDR_DBUS_NAME MSD_DBUS_NAME ".XRANDR" -struct GsdXrandrManagerPrivate +struct MsdXrandrManagerPrivate { DBusGConnection *dbus_connection; @@ -120,13 +120,13 @@ static const MateRRRotation possible_rotations[] = { /* We don't allow REFLECT_X or REFLECT_Y for now, as mate-display-properties doesn't allow them, either */ }; -static void gsd_xrandr_manager_class_init (GsdXrandrManagerClass *klass); -static void gsd_xrandr_manager_init (GsdXrandrManager *xrandr_manager); -static void gsd_xrandr_manager_finalize (GObject *object); +static void msd_xrandr_manager_class_init (MsdXrandrManagerClass *klass); +static void msd_xrandr_manager_init (MsdXrandrManager *xrandr_manager); +static void msd_xrandr_manager_finalize (GObject *object); -static void error_message (GsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text); +static void error_message (MsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text); -static void status_icon_popup_menu (GsdXrandrManager *manager, guint button, guint32 timestamp); +static void status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timestamp); static void run_display_capplet (GtkWidget *widget); static void get_allowed_rotations_for_output (MateRRConfig *config, MateRRScreen *rr_screen, @@ -134,7 +134,7 @@ static void get_allowed_rotations_for_output (MateRRConfig *config, int *out_num_rotations, MateRRRotation *out_rotations); -G_DEFINE_TYPE (GsdXrandrManager, gsd_xrandr_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdXrandrManager, msd_xrandr_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -150,8 +150,8 @@ log_open (void) if (log_file) return; - toggle_filename = g_build_filename (g_get_home_dir (), "gsd-debug-randr", NULL); - log_filename = g_build_filename (g_get_home_dir (), "gsd-debug-randr.log", NULL); + toggle_filename = g_build_filename (g_get_home_dir (), "msd-debug-randr", NULL); + log_filename = g_build_filename (g_get_home_dir (), "msd-debug-randr.log", NULL); if (stat (toggle_filename, &st) != 0) goto out; @@ -159,7 +159,7 @@ log_open (void) log_file = fopen (log_filename, "a"); if (log_file && ftell (log_file) == 0) - fprintf (log_file, "To keep this log from being created, please rm ~/gsd-debug-randr\n"); + fprintf (log_file, "To keep this log from being created, please rm ~/msd-debug-randr\n"); out: g_free (toggle_filename); @@ -282,12 +282,12 @@ log_configurations (MateRRConfig **configs) } static void -show_timestamps_dialog (GsdXrandrManager *manager, const char *msg) +show_timestamps_dialog (MsdXrandrManager *manager, const char *msg) { #if 1 return; #else - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; GtkWidget *dialog; guint32 change_timestamp, config_timestamp; static int serial; @@ -315,13 +315,13 @@ show_timestamps_dialog (GsdXrandrManager *manager, const char *msg) * mate_rr_config_apply_from_filename_with_time(), since that is not usually an error. */ static gboolean -apply_configuration_from_filename (GsdXrandrManager *manager, +apply_configuration_from_filename (MsdXrandrManager *manager, const char *filename, gboolean no_matching_config_is_an_error, guint32 timestamp, GError **error) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; GError *my_error; gboolean success; char *str; @@ -357,9 +357,9 @@ fail: * We just return whether setting the configuration succeeded. */ static gboolean -apply_configuration_and_display_error (GsdXrandrManager *manager, MateRRConfig *config, guint32 timestamp) +apply_configuration_and_display_error (MsdXrandrManager *manager, MateRRConfig *config, guint32 timestamp) { - GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManagerPrivate *priv = manager->priv; GError *error; gboolean success; @@ -383,7 +383,7 @@ restore_backup_configuration_without_messages (const char *backup_filename, cons } static void -restore_backup_configuration (GsdXrandrManager *manager, const char *backup_filename, const char *intended_filename, guint32 timestamp) +restore_backup_configuration (MsdXrandrManager *manager, const char *backup_filename, const char *intended_filename, guint32 timestamp) { int saved_errno; @@ -427,7 +427,7 @@ restore_backup_configuration (GsdXrandrManager *manager, const char *backup_file } typedef struct { - GsdXrandrManager *manager; + MsdXrandrManager *manager; GtkWidget *dialog; int countdown; @@ -476,7 +476,7 @@ timeout_response_cb (GtkDialog *dialog, int response_id, gpointer data) } static gboolean -user_says_things_are_ok (GsdXrandrManager *manager, GdkWindow *parent_window) +user_says_things_are_ok (MsdXrandrManager *manager, GdkWindow *parent_window) { TimeoutDialog timeout; guint timeout_id; @@ -523,7 +523,7 @@ user_says_things_are_ok (GsdXrandrManager *manager, GdkWindow *parent_window) } struct confirmation { - GsdXrandrManager *manager; + MsdXrandrManager *manager; GdkWindow *parent_window; guint32 timestamp; }; @@ -549,7 +549,7 @@ confirm_with_user_idle_cb (gpointer data) } static void -queue_confirmation_by_user (GsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp) +queue_confirmation_by_user (MsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp) { struct confirmation *confirmation; @@ -562,7 +562,7 @@ queue_confirmation_by_user (GsdXrandrManager *manager, GdkWindow *parent_window, } static gboolean -try_to_apply_intended_configuration (GsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp, GError **error) +try_to_apply_intended_configuration (MsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp, GError **error) { char *backup_filename; char *intended_filename; @@ -595,17 +595,17 @@ out: return result; } -/* DBus method for org.mate.SettingsDaemon.XRANDR ApplyConfiguration; see gsd-xrandr-manager.xml for the interface definition */ +/* DBus method for org.mate.SettingsDaemon.XRANDR ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ static gboolean -gsd_xrandr_manager_apply_configuration (GsdXrandrManager *manager, +msd_xrandr_manager_apply_configuration (MsdXrandrManager *manager, GError **error) { return try_to_apply_intended_configuration (manager, NULL, GDK_CURRENT_TIME, error); } -/* DBus method for org.mate.SettingsDaemon.XRANDR_2 ApplyConfiguration; see gsd-xrandr-manager.xml for the interface definition */ +/* DBus method for org.mate.SettingsDaemon.XRANDR_2 ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ static gboolean -gsd_xrandr_manager_2_apply_configuration (GsdXrandrManager *manager, +msd_xrandr_manager_2_apply_configuration (MsdXrandrManager *manager, gint64 parent_window_id, gint64 timestamp, GError **error) @@ -626,8 +626,8 @@ gsd_xrandr_manager_2_apply_configuration (GsdXrandrManager *manager, return result; } -/* We include this after the definition of gsd_xrandr_manager_apply_configuration() so the prototype will already exist */ -#include "gsd-xrandr-manager-glue.h" +/* We include this after the definition of msd_xrandr_manager_apply_configuration() so the prototype will already exist */ +#include "msd-xrandr-manager-glue.h" static gboolean is_laptop (MateRRScreen *screen, MateOutputInfo *output) @@ -956,7 +956,7 @@ make_other_setup (MateRRScreen *screen) } static GPtrArray * -sanitize (GsdXrandrManager *manager, GPtrArray *array) +sanitize (MsdXrandrManager *manager, GPtrArray *array) { int i; GPtrArray *new; @@ -1043,7 +1043,7 @@ sanitize (GsdXrandrManager *manager, GPtrArray *array) } static void -generate_fn_f7_configs (GsdXrandrManager *mgr) +generate_fn_f7_configs (MsdXrandrManager *mgr) { GPtrArray *array = g_ptr_array_new (); MateRRScreen *screen = mgr->priv->rw_screen; @@ -1077,10 +1077,10 @@ generate_fn_f7_configs (GsdXrandrManager *mgr) } static void -error_message (GsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text) +error_message (MsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text) { #ifdef HAVE_LIBMATENOTIFY - GsdXrandrManagerPrivate *priv = mgr->priv; + MsdXrandrManagerPrivate *priv = mgr->priv; NotifyNotification *notification; g_assert (error_to_display == NULL || secondary_text == NULL); @@ -1088,12 +1088,12 @@ error_message (GsdXrandrManager *mgr, const char *primary_text, GError *error_to if (priv->status_icon) notification = notify_notification_new_with_status_icon (primary_text, error_to_display ? error_to_display->message : secondary_text, - GSD_XRANDR_ICON_NAME, + MSD_XRANDR_ICON_NAME, priv->status_icon); else notification = notify_notification_new (primary_text, error_to_display ? error_to_display->message : secondary_text, - GSD_XRANDR_ICON_NAME, + MSD_XRANDR_ICON_NAME, NULL); notify_notification_show (notification, NULL); /* NULL-GError */ @@ -1111,9 +1111,9 @@ error_message (GsdXrandrManager *mgr, const char *primary_text, GError *error_to } static void -handle_fn_f7 (GsdXrandrManager *mgr, guint32 timestamp) +handle_fn_f7 (MsdXrandrManager *mgr, guint32 timestamp) { - GsdXrandrManagerPrivate *priv = mgr->priv; + MsdXrandrManagerPrivate *priv = mgr->priv; MateRRScreen *screen = priv->rw_screen; MateRRConfig *current; GError *error; @@ -1280,9 +1280,9 @@ get_next_rotation (MateRRRotation allowed_rotations, MateRRRotation current_rota * easily. */ static void -handle_rotate_windows (GsdXrandrManager *mgr, guint32 timestamp) +handle_rotate_windows (MsdXrandrManager *mgr, guint32 timestamp) { - GsdXrandrManagerPrivate *priv = mgr->priv; + MsdXrandrManagerPrivate *priv = mgr->priv; MateRRScreen *screen = priv->rw_screen; MateRRConfig *current; MateOutputInfo *rotatable_output_info; @@ -1327,7 +1327,7 @@ event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer data) { - GsdXrandrManager *manager = data; + MsdXrandrManager *manager = data; XEvent *xev = (XEvent *) xevent; if (!manager->priv->running) @@ -1350,9 +1350,9 @@ event_filter (GdkXEvent *xevent, } static void -refresh_tray_icon_menu_if_active (GsdXrandrManager *manager, guint32 timestamp) +refresh_tray_icon_menu_if_active (MsdXrandrManager *manager, guint32 timestamp) { - GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManagerPrivate *priv = manager->priv; if (priv->popup_menu) { gtk_menu_shell_cancel (GTK_MENU_SHELL (priv->popup_menu)); /* status_icon_popup_menu_selection_done_cb() will free everything */ @@ -1361,9 +1361,9 @@ refresh_tray_icon_menu_if_active (GsdXrandrManager *manager, guint32 timestamp) } static void -auto_configure_outputs (GsdXrandrManager *manager, guint32 timestamp) +auto_configure_outputs (MsdXrandrManager *manager, guint32 timestamp) { - GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManagerPrivate *priv = manager->priv; MateRRConfig *config; int i; GList *just_turned_on; @@ -1528,8 +1528,8 @@ apply_color_profiles (void) static void on_randr_event (MateRRScreen *screen, gpointer data) { - GsdXrandrManager *manager = GSD_XRANDR_MANAGER (data); - GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + MsdXrandrManagerPrivate *priv = manager->priv; guint32 change_timestamp, config_timestamp; if (!priv->running) @@ -1621,7 +1621,7 @@ run_display_capplet (GtkWidget *widget) screen = gdk_screen_get_default (); error = NULL; - if (!gdk_spawn_command_line_on_screen (screen, GSD_XRANDR_DISPLAY_CAPPLET, &error)) { + if (!gdk_spawn_command_line_on_screen (screen, MSD_XRANDR_DISPLAY_CAPPLET, &error)) { GtkWidget *dialog; dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -1645,8 +1645,8 @@ popup_menu_configure_display_cb (GtkMenuItem *item, gpointer data) static void status_icon_popup_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) { - GsdXrandrManager *manager = GSD_XRANDR_MANAGER (data); - struct GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + struct MsdXrandrManagerPrivate *priv = manager->priv; gtk_widget_destroy (priv->popup_menu); priv->popup_menu = NULL; @@ -1671,8 +1671,8 @@ status_icon_popup_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer dat static gboolean output_title_label_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) { - GsdXrandrManager *manager = GSD_XRANDR_MANAGER (data); - struct GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + struct MsdXrandrManagerPrivate *priv = manager->priv; MateOutputInfo *output; GdkColor color; cairo_t *cr; @@ -1776,7 +1776,7 @@ title_item_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpoin } static GtkWidget * -make_menu_item_for_output_title (GsdXrandrManager *manager, MateOutputInfo *output) +make_menu_item_for_output_title (MsdXrandrManager *manager, MateOutputInfo *output) { GtkWidget *item; GtkWidget *label; @@ -1864,9 +1864,9 @@ get_allowed_rotations_for_output (MateRRConfig *config, } static void -add_unsupported_rotation_item (GsdXrandrManager *manager) +add_unsupported_rotation_item (MsdXrandrManager *manager) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; GtkWidget *item; GtkWidget *label; gchar *markup; @@ -1911,8 +1911,8 @@ ensure_current_configuration_is_saved (void) static void output_rotation_item_activate_cb (GtkCheckMenuItem *item, gpointer data) { - GsdXrandrManager *manager = GSD_XRANDR_MANAGER (data); - struct GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + struct MsdXrandrManagerPrivate *priv = manager->priv; MateOutputInfo *output; MateRRRotation rotation; GError *error; @@ -1941,7 +1941,7 @@ output_rotation_item_activate_cb (GtkCheckMenuItem *item, gpointer data) } static void -add_items_for_rotations (GsdXrandrManager *manager, MateOutputInfo *output, MateRRRotation allowed_rotations) +add_items_for_rotations (MsdXrandrManager *manager, MateOutputInfo *output, MateRRRotation allowed_rotations) { typedef struct { MateRRRotation rotation; @@ -1955,7 +1955,7 @@ add_items_for_rotations (GsdXrandrManager *manager, MateOutputInfo *output, Mate /* We don't allow REFLECT_X or REFLECT_Y for now, as mate-display-properties doesn't allow them, either */ }; - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; int i; GSList *group; GtkWidget *active_item; @@ -2012,9 +2012,9 @@ add_items_for_rotations (GsdXrandrManager *manager, MateOutputInfo *output, Mate } static void -add_rotation_items_for_output (GsdXrandrManager *manager, MateOutputInfo *output) +add_rotation_items_for_output (MsdXrandrManager *manager, MateOutputInfo *output) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; int num_rotations; MateRRRotation rotations; @@ -2027,9 +2027,9 @@ add_rotation_items_for_output (GsdXrandrManager *manager, MateOutputInfo *output } static void -add_menu_items_for_output (GsdXrandrManager *manager, MateOutputInfo *output) +add_menu_items_for_output (MsdXrandrManager *manager, MateOutputInfo *output) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; GtkWidget *item; item = make_menu_item_for_output_title (manager, output); @@ -2039,9 +2039,9 @@ add_menu_items_for_output (GsdXrandrManager *manager, MateOutputInfo *output) } static void -add_menu_items_for_outputs (GsdXrandrManager *manager) +add_menu_items_for_outputs (MsdXrandrManager *manager) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; int i; for (i = 0; priv->configuration->outputs[i] != NULL; i++) { @@ -2051,9 +2051,9 @@ add_menu_items_for_outputs (GsdXrandrManager *manager) } static void -status_icon_popup_menu (GsdXrandrManager *manager, guint button, guint32 timestamp) +status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timestamp) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; GtkWidget *item; g_assert (priv->configuration == NULL); @@ -2088,7 +2088,7 @@ status_icon_popup_menu (GsdXrandrManager *manager, guint button, guint32 timesta static void status_icon_activate_cb (GtkStatusIcon *status_icon, gpointer data) { - GsdXrandrManager *manager = GSD_XRANDR_MANAGER (data); + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); /* Suck; we don't get a proper button/timestamp */ status_icon_popup_menu (manager, 0, gtk_get_current_event_time ()); @@ -2097,21 +2097,21 @@ status_icon_activate_cb (GtkStatusIcon *status_icon, gpointer data) static void status_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 timestamp, gpointer data) { - GsdXrandrManager *manager = GSD_XRANDR_MANAGER (data); + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); status_icon_popup_menu (manager, button, timestamp); } static void -status_icon_start (GsdXrandrManager *manager) +status_icon_start (MsdXrandrManager *manager) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; /* Ideally, we should detect if we are on a tablet and only display * the icon in that case. */ if (!priv->status_icon) { - priv->status_icon = gtk_status_icon_new_from_icon_name (GSD_XRANDR_ICON_NAME); + priv->status_icon = gtk_status_icon_new_from_icon_name (MSD_XRANDR_ICON_NAME); gtk_status_icon_set_tooltip_text (priv->status_icon, _("Configure display settings")); g_signal_connect (priv->status_icon, "activate", @@ -2122,9 +2122,9 @@ status_icon_start (GsdXrandrManager *manager) } static void -status_icon_stop (GsdXrandrManager *manager) +status_icon_stop (MsdXrandrManager *manager) { - struct GsdXrandrManagerPrivate *priv = manager->priv; + struct MsdXrandrManagerPrivate *priv = manager->priv; if (priv->status_icon) { g_signal_handlers_disconnect_by_func ( @@ -2141,7 +2141,7 @@ status_icon_stop (GsdXrandrManager *manager) } static void -start_or_stop_icon (GsdXrandrManager *manager) +start_or_stop_icon (MsdXrandrManager *manager) { if (mateconf_client_get_bool (manager->priv->client, CONF_KEY_SHOW_NOTIFICATION_ICON, NULL)) { status_icon_start (manager); @@ -2155,14 +2155,14 @@ static void on_config_changed (MateConfClient *client, guint cnxn_id, MateConfEntry *entry, - GsdXrandrManager *manager) + MsdXrandrManager *manager) { if (strcmp (entry->key, CONF_KEY_SHOW_NOTIFICATION_ICON) == 0) start_or_stop_icon (manager); } static gboolean -apply_intended_configuration (GsdXrandrManager *manager, const char *intended_filename, guint32 timestamp) +apply_intended_configuration (MsdXrandrManager *manager, const char *intended_filename, guint32 timestamp) { GError *my_error; gboolean result; @@ -2182,9 +2182,9 @@ apply_intended_configuration (GsdXrandrManager *manager, const char *intended_fi } static void -apply_default_boot_configuration (GsdXrandrManager *mgr, guint32 timestamp) +apply_default_boot_configuration (MsdXrandrManager *mgr, guint32 timestamp) { - GsdXrandrManagerPrivate *priv = mgr->priv; + MsdXrandrManagerPrivate *priv = mgr->priv; MateRRScreen *screen = priv->rw_screen; MateRRConfig *config; gboolean turn_on_external, turn_on_laptop; @@ -2210,7 +2210,7 @@ apply_default_boot_configuration (GsdXrandrManager *mgr, guint32 timestamp) } static gboolean -apply_stored_configuration_at_startup (GsdXrandrManager *manager, guint32 timestamp) +apply_stored_configuration_at_startup (MsdXrandrManager *manager, guint32 timestamp) { GError *my_error; gboolean success; @@ -2267,9 +2267,9 @@ out: } static gboolean -apply_default_configuration_from_file (GsdXrandrManager *manager, guint32 timestamp) +apply_default_configuration_from_file (MsdXrandrManager *manager, guint32 timestamp) { - GsdXrandrManagerPrivate *priv = manager->priv; + MsdXrandrManagerPrivate *priv = manager->priv; char *default_config_filename; gboolean result; @@ -2284,7 +2284,7 @@ apply_default_configuration_from_file (GsdXrandrManager *manager, guint32 timest } gboolean -gsd_xrandr_manager_start (GsdXrandrManager *manager, +msd_xrandr_manager_start (MsdXrandrManager *manager, GError **error) { g_debug ("Starting xrandr manager"); @@ -2368,7 +2368,7 @@ gsd_xrandr_manager_start (GsdXrandrManager *manager, } void -gsd_xrandr_manager_stop (GsdXrandrManager *manager) +msd_xrandr_manager_stop (MsdXrandrManager *manager) { g_debug ("Stopping xrandr manager"); @@ -2429,14 +2429,14 @@ gsd_xrandr_manager_stop (GsdXrandrManager *manager) } static void -gsd_xrandr_manager_set_property (GObject *object, +msd_xrandr_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdXrandrManager *self; + MsdXrandrManager *self; - self = GSD_XRANDR_MANAGER (object); + self = MSD_XRANDR_MANAGER (object); switch (prop_id) { default: @@ -2446,14 +2446,14 @@ gsd_xrandr_manager_set_property (GObject *object, } static void -gsd_xrandr_manager_get_property (GObject *object, +msd_xrandr_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdXrandrManager *self; + MsdXrandrManager *self; - self = GSD_XRANDR_MANAGER (object); + self = MSD_XRANDR_MANAGER (object); switch (prop_id) { default: @@ -2463,16 +2463,16 @@ gsd_xrandr_manager_get_property (GObject *object, } static GObject * -gsd_xrandr_manager_constructor (GType type, +msd_xrandr_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdXrandrManager *xrandr_manager; - GsdXrandrManagerClass *klass; + MsdXrandrManager *xrandr_manager; + MsdXrandrManagerClass *klass; - klass = GSD_XRANDR_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_XRANDR_MANAGER)); + klass = MSD_XRANDR_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_XRANDR_MANAGER)); - xrandr_manager = GSD_XRANDR_MANAGER (G_OBJECT_CLASS (gsd_xrandr_manager_parent_class)->constructor (type, + xrandr_manager = MSD_XRANDR_MANAGER (G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -2480,29 +2480,29 @@ gsd_xrandr_manager_constructor (GType type, } static void -gsd_xrandr_manager_dispose (GObject *object) +msd_xrandr_manager_dispose (GObject *object) { - GsdXrandrManager *xrandr_manager; + MsdXrandrManager *xrandr_manager; - xrandr_manager = GSD_XRANDR_MANAGER (object); + xrandr_manager = MSD_XRANDR_MANAGER (object); - G_OBJECT_CLASS (gsd_xrandr_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->dispose (object); } static void -gsd_xrandr_manager_class_init (GsdXrandrManagerClass *klass) +msd_xrandr_manager_class_init (MsdXrandrManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_xrandr_manager_get_property; - object_class->set_property = gsd_xrandr_manager_set_property; - object_class->constructor = gsd_xrandr_manager_constructor; - object_class->dispose = gsd_xrandr_manager_dispose; - object_class->finalize = gsd_xrandr_manager_finalize; + object_class->get_property = msd_xrandr_manager_get_property; + object_class->set_property = msd_xrandr_manager_set_property; + object_class->constructor = msd_xrandr_manager_constructor; + object_class->dispose = msd_xrandr_manager_dispose; + object_class->finalize = msd_xrandr_manager_finalize; - dbus_g_object_type_install_info (GSD_TYPE_XRANDR_MANAGER, &dbus_glib_gsd_xrandr_manager_object_info); + dbus_g_object_type_install_info (MSD_TYPE_XRANDR_MANAGER, &dbus_glib_msd_xrandr_manager_object_info); - g_type_class_add_private (klass, sizeof (GsdXrandrManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdXrandrManagerPrivate)); } static guint @@ -2518,9 +2518,9 @@ get_keycode_for_keysym_name (const char *name) } static void -gsd_xrandr_manager_init (GsdXrandrManager *manager) +msd_xrandr_manager_init (MsdXrandrManager *manager) { - manager->priv = GSD_XRANDR_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_XRANDR_MANAGER_GET_PRIVATE (manager); manager->priv->switch_video_mode_keycode = get_keycode_for_keysym_name (VIDEO_KEYSYM); manager->priv->rotate_windows_keycode = get_keycode_for_keysym_name (ROTATE_KEYSYM); @@ -2530,22 +2530,22 @@ gsd_xrandr_manager_init (GsdXrandrManager *manager) } static void -gsd_xrandr_manager_finalize (GObject *object) +msd_xrandr_manager_finalize (GObject *object) { - GsdXrandrManager *xrandr_manager; + MsdXrandrManager *xrandr_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_XRANDR_MANAGER (object)); + g_return_if_fail (MSD_IS_XRANDR_MANAGER (object)); - xrandr_manager = GSD_XRANDR_MANAGER (object); + xrandr_manager = MSD_XRANDR_MANAGER (object); g_return_if_fail (xrandr_manager->priv != NULL); - G_OBJECT_CLASS (gsd_xrandr_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->finalize (object); } static gboolean -register_manager_dbus (GsdXrandrManager *manager) +register_manager_dbus (MsdXrandrManager *manager) { GError *error = NULL; @@ -2558,19 +2558,19 @@ register_manager_dbus (GsdXrandrManager *manager) return FALSE; } - /* Hmm, should we do this in gsd_xrandr_manager_start()? */ - dbus_g_connection_register_g_object (manager->priv->dbus_connection, GSD_XRANDR_DBUS_PATH, G_OBJECT (manager)); + /* Hmm, should we do this in msd_xrandr_manager_start()? */ + dbus_g_connection_register_g_object (manager->priv->dbus_connection, MSD_XRANDR_DBUS_PATH, G_OBJECT (manager)); return TRUE; } -GsdXrandrManager * -gsd_xrandr_manager_new (void) +MsdXrandrManager * +msd_xrandr_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_XRANDR_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_XRANDR_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); @@ -2580,5 +2580,5 @@ gsd_xrandr_manager_new (void) } } - return GSD_XRANDR_MANAGER (manager_object); + return MSD_XRANDR_MANAGER (manager_object); } diff --git a/plugins/xrandr/gsd-xrandr-manager.h b/plugins/xrandr/gsd-xrandr-manager.h index c404bfe..dbb5dff 100644 --- a/plugins/xrandr/gsd-xrandr-manager.h +++ b/plugins/xrandr/gsd-xrandr-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_XRANDR_MANAGER_H -#define __GSD_XRANDR_MANAGER_H +#ifndef __MSD_XRANDR_MANAGER_H +#define __MSD_XRANDR_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_XRANDR_MANAGER (gsd_xrandr_manager_get_type ()) -#define GSD_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_XRANDR_MANAGER, GsdXrandrManager)) -#define GSD_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_XRANDR_MANAGER, GsdXrandrManagerClass)) -#define GSD_IS_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_XRANDR_MANAGER)) -#define GSD_IS_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_XRANDR_MANAGER)) -#define GSD_XRANDR_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_XRANDR_MANAGER, GsdXrandrManagerClass)) +#define MSD_TYPE_XRANDR_MANAGER (msd_xrandr_manager_get_type ()) +#define MSD_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManager)) +#define MSD_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerClass)) +#define MSD_IS_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRANDR_MANAGER)) +#define MSD_IS_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRANDR_MANAGER)) +#define MSD_XRANDR_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerClass)) -typedef struct GsdXrandrManagerPrivate GsdXrandrManagerPrivate; +typedef struct MsdXrandrManagerPrivate MsdXrandrManagerPrivate; typedef struct { GObject parent; - GsdXrandrManagerPrivate *priv; -} GsdXrandrManager; + MsdXrandrManagerPrivate *priv; +} MsdXrandrManager; typedef struct { GObjectClass parent_class; -} GsdXrandrManagerClass; +} MsdXrandrManagerClass; -GType gsd_xrandr_manager_get_type (void); +GType msd_xrandr_manager_get_type (void); -GsdXrandrManager * gsd_xrandr_manager_new (void); -gboolean gsd_xrandr_manager_start (GsdXrandrManager *manager, +MsdXrandrManager * msd_xrandr_manager_new (void); +gboolean msd_xrandr_manager_start (MsdXrandrManager *manager, GError **error); -void gsd_xrandr_manager_stop (GsdXrandrManager *manager); +void msd_xrandr_manager_stop (MsdXrandrManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_XRANDR_MANAGER_H */ +#endif /* __MSD_XRANDR_MANAGER_H */ diff --git a/plugins/xrandr/gsd-xrandr-manager.xml b/plugins/xrandr/gsd-xrandr-manager.xml index e8dde7c..c82a594 100644 --- a/plugins/xrandr/gsd-xrandr-manager.xml +++ b/plugins/xrandr/gsd-xrandr-manager.xml @@ -1,7 +1,7 @@ - + @@ -9,7 +9,7 @@ - + diff --git a/plugins/xrandr/gsd-xrandr-plugin.c b/plugins/xrandr/gsd-xrandr-plugin.c index e765124..9e78124 100644 --- a/plugins/xrandr/gsd-xrandr-plugin.c +++ b/plugins/xrandr/gsd-xrandr-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-xrandr-plugin.h" -#include "gsd-xrandr-manager.h" +#include "msd-xrandr-plugin.h" +#include "msd-xrandr-manager.h" -struct GsdXrandrPluginPrivate { - GsdXrandrManager *manager; +struct MsdXrandrPluginPrivate { + MsdXrandrManager *manager; }; -#define GSD_XRANDR_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_XRANDR_PLUGIN, GsdXrandrPluginPrivate)) +#define MSD_XRANDR_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdXrandrPlugin, gsd_xrandr_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdXrandrPlugin, msd_xrandr_plugin) static void -gsd_xrandr_plugin_init (GsdXrandrPlugin *plugin) +msd_xrandr_plugin_init (MsdXrandrPlugin *plugin) { - plugin->priv = GSD_XRANDR_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_XRANDR_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdXrandrPlugin initializing"); + g_debug ("MsdXrandrPlugin initializing"); - plugin->priv->manager = gsd_xrandr_manager_new (); + plugin->priv->manager = msd_xrandr_manager_new (); } static void -gsd_xrandr_plugin_finalize (GObject *object) +msd_xrandr_plugin_finalize (GObject *object) { - GsdXrandrPlugin *plugin; + MsdXrandrPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_XRANDR_PLUGIN (object)); + g_return_if_fail (MSD_IS_XRANDR_PLUGIN (object)); - g_debug ("GsdXrandrPlugin finalizing"); + g_debug ("MsdXrandrPlugin finalizing"); - plugin = GSD_XRANDR_PLUGIN (object); + plugin = MSD_XRANDR_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_xrandr_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_xrandr_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_xrandr_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating xrandr plugin"); error = NULL; - res = gsd_xrandr_manager_start (GSD_XRANDR_PLUGIN (plugin)->priv->manager, &error); + res = msd_xrandr_manager_start (MSD_XRANDR_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start xrandr manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating xrandr plugin"); - gsd_xrandr_manager_stop (GSD_XRANDR_PLUGIN (plugin)->priv->manager); + msd_xrandr_manager_stop (MSD_XRANDR_PLUGIN (plugin)->priv->manager); } static void -gsd_xrandr_plugin_class_init (GsdXrandrPluginClass *klass) +msd_xrandr_plugin_class_init (MsdXrandrPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_xrandr_plugin_finalize; + object_class->finalize = msd_xrandr_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdXrandrPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdXrandrPluginPrivate)); } diff --git a/plugins/xrandr/gsd-xrandr-plugin.h b/plugins/xrandr/gsd-xrandr-plugin.h index 18bb79a..62e742e 100644 --- a/plugins/xrandr/gsd-xrandr-plugin.h +++ b/plugins/xrandr/gsd-xrandr-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_XRANDR_PLUGIN_H__ -#define __GSD_XRANDR_PLUGIN_H__ +#ifndef __MSD_XRANDR_PLUGIN_H__ +#define __MSD_XRANDR_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_XRANDR_PLUGIN (gsd_xrandr_plugin_get_type ()) -#define GSD_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_XRANDR_PLUGIN, GsdXrandrPlugin)) -#define GSD_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_XRANDR_PLUGIN, GsdXrandrPluginClass)) -#define GSD_IS_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_XRANDR_PLUGIN)) -#define GSD_IS_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_XRANDR_PLUGIN)) -#define GSD_XRANDR_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_XRANDR_PLUGIN, GsdXrandrPluginClass)) +#define MSD_TYPE_XRANDR_PLUGIN (msd_xrandr_plugin_get_type ()) +#define MSD_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPlugin)) +#define MSD_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginClass)) +#define MSD_IS_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRANDR_PLUGIN)) +#define MSD_IS_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRANDR_PLUGIN)) +#define MSD_XRANDR_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginClass)) -typedef struct GsdXrandrPluginPrivate GsdXrandrPluginPrivate; +typedef struct MsdXrandrPluginPrivate MsdXrandrPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdXrandrPluginPrivate *priv; -} GsdXrandrPlugin; + MsdXrandrPluginPrivate *priv; +} MsdXrandrPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdXrandrPluginClass; +} MsdXrandrPluginClass; -GType gsd_xrandr_plugin_get_type (void) G_GNUC_CONST; +GType msd_xrandr_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_XRANDR_PLUGIN_H__ */ +#endif /* __MSD_XRANDR_PLUGIN_H__ */ diff --git a/plugins/xrdb/Makefile.am b/plugins/xrdb/Makefile.am index 1b8e82b..04946c8 100644 --- a/plugins/xrdb/Makefile.am +++ b/plugins/xrdb/Makefile.am @@ -9,10 +9,10 @@ plugin_LTLIBRARIES = \ $(NULL) libxrdb_la_SOURCES = \ - gsd-xrdb-plugin.h \ - gsd-xrdb-plugin.c \ - gsd-xrdb-manager.h \ - gsd-xrdb-manager.c \ + msd-xrdb-plugin.h \ + msd-xrdb-plugin.c \ + msd-xrdb-manager.h \ + msd-xrdb-manager.c \ $(NULL) libxrdb_la_CPPFLAGS = \ @@ -26,7 +26,7 @@ libxrdb_la_CFLAGS = \ $(AM_CFLAGS) libxrdb_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libxrdb_la_LIBADD = \ @@ -51,4 +51,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/xrdb/gsd-xrdb-manager.c b/plugins/xrdb/gsd-xrdb-manager.c index 5a53842..776d1e7 100644 --- a/plugins/xrdb/gsd-xrdb-manager.c +++ b/plugins/xrdb/gsd-xrdb-manager.c @@ -38,9 +38,9 @@ #include #include "mate-settings-profile.h" -#include "gsd-xrdb-manager.h" +#include "msd-xrdb-manager.h" -#define GSD_XRDB_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_XRDB_MANAGER, GsdXrdbManagerPrivate)) +#define MSD_XRDB_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerPrivate)) #define SYSTEM_AD_DIR DATADIR "/xrdb" #define GENERAL_AD SYSTEM_AD_DIR "/General.ad" @@ -50,15 +50,15 @@ #define GTK_THEME_KEY "/desktop/mate/interface/gtk_theme" -struct GsdXrdbManagerPrivate { +struct MsdXrdbManagerPrivate { GtkWidget* widget; }; -static void gsd_xrdb_manager_class_init (GsdXrdbManagerClass *klass); -static void gsd_xrdb_manager_init (GsdXrdbManager *xrdb_manager); -static void gsd_xrdb_manager_finalize (GObject *object); +static void msd_xrdb_manager_class_init (MsdXrdbManagerClass *klass); +static void msd_xrdb_manager_init (MsdXrdbManager *xrdb_manager); +static void msd_xrdb_manager_finalize (GObject *object); -G_DEFINE_TYPE (GsdXrdbManager, gsd_xrdb_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdXrdbManager, msd_xrdb_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static void @@ -207,7 +207,7 @@ compare_basenames (gconstpointer a, * right order for processing. */ static GSList* -scan_for_files (GsdXrdbManager *manager, +scan_for_files (MsdXrdbManager *manager, GError **error) { const char *home_dir; @@ -420,7 +420,7 @@ spawn_with_input (const char *command, } static void -apply_settings (GsdXrdbManager *manager, +apply_settings (MsdXrdbManager *manager, GtkStyle *style) { const char *command; @@ -480,13 +480,13 @@ apply_settings (GsdXrdbManager *manager, static void theme_changed (GtkSettings *settings, GParamSpec *pspec, - GsdXrdbManager *manager) + MsdXrdbManager *manager) { apply_settings (manager, gtk_widget_get_style (manager->priv->widget)); } gboolean -gsd_xrdb_manager_start (GsdXrdbManager *manager, +msd_xrdb_manager_start (MsdXrdbManager *manager, GError **error) { mate_settings_profile_start (NULL); @@ -509,9 +509,9 @@ gsd_xrdb_manager_start (GsdXrdbManager *manager, } void -gsd_xrdb_manager_stop (GsdXrdbManager *manager) +msd_xrdb_manager_stop (MsdXrdbManager *manager) { - GsdXrdbManagerPrivate *p = manager->priv; + MsdXrdbManagerPrivate *p = manager->priv; g_debug ("Stopping xrdb manager"); @@ -526,14 +526,14 @@ gsd_xrdb_manager_stop (GsdXrdbManager *manager) } static void -gsd_xrdb_manager_set_property (GObject *object, +msd_xrdb_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdXrdbManager *self; + MsdXrdbManager *self; - self = GSD_XRDB_MANAGER (object); + self = MSD_XRDB_MANAGER (object); switch (prop_id) { default: @@ -543,14 +543,14 @@ gsd_xrdb_manager_set_property (GObject *object, } static void -gsd_xrdb_manager_get_property (GObject *object, +msd_xrdb_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdXrdbManager *self; + MsdXrdbManager *self; - self = GSD_XRDB_MANAGER (object); + self = MSD_XRDB_MANAGER (object); switch (prop_id) { default: @@ -560,16 +560,16 @@ gsd_xrdb_manager_get_property (GObject *object, } static GObject * -gsd_xrdb_manager_constructor (GType type, +msd_xrdb_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdXrdbManager *xrdb_manager; - GsdXrdbManagerClass *klass; + MsdXrdbManager *xrdb_manager; + MsdXrdbManagerClass *klass; - klass = GSD_XRDB_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_XRDB_MANAGER)); + klass = MSD_XRDB_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_XRDB_MANAGER)); - xrdb_manager = GSD_XRDB_MANAGER (G_OBJECT_CLASS (gsd_xrdb_manager_parent_class)->constructor (type, + xrdb_manager = MSD_XRDB_MANAGER (G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -577,61 +577,61 @@ gsd_xrdb_manager_constructor (GType type, } static void -gsd_xrdb_manager_dispose (GObject *object) +msd_xrdb_manager_dispose (GObject *object) { - GsdXrdbManager *xrdb_manager; + MsdXrdbManager *xrdb_manager; - xrdb_manager = GSD_XRDB_MANAGER (object); + xrdb_manager = MSD_XRDB_MANAGER (object); - G_OBJECT_CLASS (gsd_xrdb_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->dispose (object); } static void -gsd_xrdb_manager_class_init (GsdXrdbManagerClass *klass) +msd_xrdb_manager_class_init (MsdXrdbManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_xrdb_manager_get_property; - object_class->set_property = gsd_xrdb_manager_set_property; - object_class->constructor = gsd_xrdb_manager_constructor; - object_class->dispose = gsd_xrdb_manager_dispose; - object_class->finalize = gsd_xrdb_manager_finalize; + object_class->get_property = msd_xrdb_manager_get_property; + object_class->set_property = msd_xrdb_manager_set_property; + object_class->constructor = msd_xrdb_manager_constructor; + object_class->dispose = msd_xrdb_manager_dispose; + object_class->finalize = msd_xrdb_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdXrdbManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdXrdbManagerPrivate)); } static void -gsd_xrdb_manager_init (GsdXrdbManager *manager) +msd_xrdb_manager_init (MsdXrdbManager *manager) { - manager->priv = GSD_XRDB_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_XRDB_MANAGER_GET_PRIVATE (manager); } static void -gsd_xrdb_manager_finalize (GObject *object) +msd_xrdb_manager_finalize (GObject *object) { - GsdXrdbManager *xrdb_manager; + MsdXrdbManager *xrdb_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_XRDB_MANAGER (object)); + g_return_if_fail (MSD_IS_XRDB_MANAGER (object)); - xrdb_manager = GSD_XRDB_MANAGER (object); + xrdb_manager = MSD_XRDB_MANAGER (object); g_return_if_fail (xrdb_manager->priv != NULL); - G_OBJECT_CLASS (gsd_xrdb_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->finalize (object); } -GsdXrdbManager * -gsd_xrdb_manager_new (void) +MsdXrdbManager * +msd_xrdb_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_XRDB_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_XRDB_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_XRDB_MANAGER (manager_object); + return MSD_XRDB_MANAGER (manager_object); } diff --git a/plugins/xrdb/gsd-xrdb-manager.h b/plugins/xrdb/gsd-xrdb-manager.h index 4588e69..cb83d24 100644 --- a/plugins/xrdb/gsd-xrdb-manager.h +++ b/plugins/xrdb/gsd-xrdb-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_XRDB_MANAGER_H -#define __GSD_XRDB_MANAGER_H +#ifndef __MSD_XRDB_MANAGER_H +#define __MSD_XRDB_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_XRDB_MANAGER (gsd_xrdb_manager_get_type ()) -#define GSD_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_XRDB_MANAGER, GsdXrdbManager)) -#define GSD_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_XRDB_MANAGER, GsdXrdbManagerClass)) -#define GSD_IS_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_XRDB_MANAGER)) -#define GSD_IS_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_XRDB_MANAGER)) -#define GSD_XRDB_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_XRDB_MANAGER, GsdXrdbManagerClass)) +#define MSD_TYPE_XRDB_MANAGER (msd_xrdb_manager_get_type ()) +#define MSD_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManager)) +#define MSD_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerClass)) +#define MSD_IS_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRDB_MANAGER)) +#define MSD_IS_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRDB_MANAGER)) +#define MSD_XRDB_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerClass)) -typedef struct GsdXrdbManagerPrivate GsdXrdbManagerPrivate; +typedef struct MsdXrdbManagerPrivate MsdXrdbManagerPrivate; typedef struct { GObject parent; - GsdXrdbManagerPrivate *priv; -} GsdXrdbManager; + MsdXrdbManagerPrivate *priv; +} MsdXrdbManager; typedef struct { GObjectClass parent_class; -} GsdXrdbManagerClass; +} MsdXrdbManagerClass; -GType gsd_xrdb_manager_get_type (void); +GType msd_xrdb_manager_get_type (void); -GsdXrdbManager * gsd_xrdb_manager_new (void); -gboolean gsd_xrdb_manager_start (GsdXrdbManager *manager, +MsdXrdbManager * msd_xrdb_manager_new (void); +gboolean msd_xrdb_manager_start (MsdXrdbManager *manager, GError **error); -void gsd_xrdb_manager_stop (GsdXrdbManager *manager); +void msd_xrdb_manager_stop (MsdXrdbManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_XRDB_MANAGER_H */ +#endif /* __MSD_XRDB_MANAGER_H */ diff --git a/plugins/xrdb/gsd-xrdb-plugin.c b/plugins/xrdb/gsd-xrdb-plugin.c index 870eb56..1efe570 100644 --- a/plugins/xrdb/gsd-xrdb-plugin.c +++ b/plugins/xrdb/gsd-xrdb-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-xrdb-plugin.h" -#include "gsd-xrdb-manager.h" +#include "msd-xrdb-plugin.h" +#include "msd-xrdb-manager.h" -struct GsdXrdbPluginPrivate { - GsdXrdbManager *manager; +struct MsdXrdbPluginPrivate { + MsdXrdbManager *manager; }; -#define GSD_XRDB_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_XRDB_PLUGIN, GsdXrdbPluginPrivate)) +#define MSD_XRDB_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdXrdbPlugin, gsd_xrdb_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdXrdbPlugin, msd_xrdb_plugin) static void -gsd_xrdb_plugin_init (GsdXrdbPlugin *plugin) +msd_xrdb_plugin_init (MsdXrdbPlugin *plugin) { - plugin->priv = GSD_XRDB_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_XRDB_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdXrdbPlugin initializing"); + g_debug ("MsdXrdbPlugin initializing"); - plugin->priv->manager = gsd_xrdb_manager_new (); + plugin->priv->manager = msd_xrdb_manager_new (); } static void -gsd_xrdb_plugin_finalize (GObject *object) +msd_xrdb_plugin_finalize (GObject *object) { - GsdXrdbPlugin *plugin; + MsdXrdbPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_XRDB_PLUGIN (object)); + g_return_if_fail (MSD_IS_XRDB_PLUGIN (object)); - g_debug ("GsdXrdbPlugin finalizing"); + g_debug ("MsdXrdbPlugin finalizing"); - plugin = GSD_XRDB_PLUGIN (object); + plugin = MSD_XRDB_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_xrdb_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_xrdb_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_xrdb_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating xrdb plugin"); error = NULL; - res = gsd_xrdb_manager_start (GSD_XRDB_PLUGIN (plugin)->priv->manager, &error); + res = msd_xrdb_manager_start (MSD_XRDB_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start xrdb manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating xrdb plugin"); - gsd_xrdb_manager_stop (GSD_XRDB_PLUGIN (plugin)->priv->manager); + msd_xrdb_manager_stop (MSD_XRDB_PLUGIN (plugin)->priv->manager); } static void -gsd_xrdb_plugin_class_init (GsdXrdbPluginClass *klass) +msd_xrdb_plugin_class_init (MsdXrdbPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_xrdb_plugin_finalize; + object_class->finalize = msd_xrdb_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdXrdbPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdXrdbPluginPrivate)); } diff --git a/plugins/xrdb/gsd-xrdb-plugin.h b/plugins/xrdb/gsd-xrdb-plugin.h index 9baa26a..893835b 100644 --- a/plugins/xrdb/gsd-xrdb-plugin.h +++ b/plugins/xrdb/gsd-xrdb-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_XRDB_PLUGIN_H__ -#define __GSD_XRDB_PLUGIN_H__ +#ifndef __MSD_XRDB_PLUGIN_H__ +#define __MSD_XRDB_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_XRDB_PLUGIN (gsd_xrdb_plugin_get_type ()) -#define GSD_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_XRDB_PLUGIN, GsdXrdbPlugin)) -#define GSD_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_XRDB_PLUGIN, GsdXrdbPluginClass)) -#define GSD_IS_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_XRDB_PLUGIN)) -#define GSD_IS_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_XRDB_PLUGIN)) -#define GSD_XRDB_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_XRDB_PLUGIN, GsdXrdbPluginClass)) +#define MSD_TYPE_XRDB_PLUGIN (msd_xrdb_plugin_get_type ()) +#define MSD_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPlugin)) +#define MSD_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginClass)) +#define MSD_IS_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRDB_PLUGIN)) +#define MSD_IS_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRDB_PLUGIN)) +#define MSD_XRDB_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginClass)) -typedef struct GsdXrdbPluginPrivate GsdXrdbPluginPrivate; +typedef struct MsdXrdbPluginPrivate MsdXrdbPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdXrdbPluginPrivate *priv; -} GsdXrdbPlugin; + MsdXrdbPluginPrivate *priv; +} MsdXrdbPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdXrdbPluginClass; +} MsdXrdbPluginClass; -GType gsd_xrdb_plugin_get_type (void) G_GNUC_CONST; +GType msd_xrdb_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_XRDB_PLUGIN_H__ */ +#endif /* __MSD_XRDB_PLUGIN_H__ */ diff --git a/plugins/xsettings/Makefile.am b/plugins/xsettings/Makefile.am index 8b861b9..87f0eab 100644 --- a/plugins/xsettings/Makefile.am +++ b/plugins/xsettings/Makefile.am @@ -5,10 +5,10 @@ plugin_LTLIBRARIES = \ $(NULL) libxsettings_la_SOURCES = \ - gsd-xsettings-plugin.h \ - gsd-xsettings-plugin.c \ - gsd-xsettings-manager.h \ - gsd-xsettings-manager.c \ + msd-xsettings-plugin.h \ + msd-xsettings-plugin.c \ + msd-xsettings-manager.h \ + msd-xsettings-manager.c \ xsettings-common.h \ xsettings-common.c \ xsettings-manager.h \ @@ -25,7 +25,7 @@ libxsettings_la_CFLAGS = \ $(AM_CFLAGS) libxsettings_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libxsettings_la_LIBADD = \ @@ -62,4 +62,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c index e7b4f9a..9df8f61 100644 --- a/plugins/xsettings/gsd-xsettings-manager.c +++ b/plugins/xsettings/gsd-xsettings-manager.c @@ -41,7 +41,7 @@ #include #include "mate-settings-profile.h" -#include "gsd-xsettings-manager.h" +#include "msd-xsettings-manager.h" #include "xsettings-manager.h" #ifdef HAVE_FONTCONFIG #include "fontconfig-monitor.h" @@ -100,10 +100,10 @@ struct MateXSettingsManagerPrivate #endif /* HAVE_FONTCONFIG */ }; -#define GSD_XSETTINGS_ERROR gsd_xsettings_error_quark () +#define MSD_XSETTINGS_ERROR msd_xsettings_error_quark () enum { - GSD_XSETTINGS_ERROR_INIT + MSD_XSETTINGS_ERROR_INIT }; static void mate_xsettings_manager_class_init (MateXSettingsManagerClass *klass); @@ -115,9 +115,9 @@ G_DEFINE_TYPE (MateXSettingsManager, mate_xsettings_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; static GQuark -gsd_xsettings_error_quark (void) +msd_xsettings_error_quark (void) { - return g_quark_from_static_string ("gsd-xsettings-error-quark"); + return g_quark_from_static_string ("msd-xsettings-error-quark"); } static void @@ -802,8 +802,8 @@ mate_xsettings_manager_start (MateXSettingsManager *manager, mate_settings_profile_start (NULL); if (!setup_xsettings_managers (manager)) { - g_set_error (error, GSD_XSETTINGS_ERROR, - GSD_XSETTINGS_ERROR_INIT, + g_set_error (error, MSD_XSETTINGS_ERROR, + MSD_XSETTINGS_ERROR_INIT, "Could not initialize xsettings manager."); return FALSE; } diff --git a/plugins/xsettings/gsd-xsettings-plugin.c b/plugins/xsettings/gsd-xsettings-plugin.c index 2280589..50af53a 100644 --- a/plugins/xsettings/gsd-xsettings-plugin.c +++ b/plugins/xsettings/gsd-xsettings-plugin.c @@ -24,8 +24,8 @@ #include #include "mate-settings-plugin.h" -#include "gsd-xsettings-plugin.h" -#include "gsd-xsettings-manager.h" +#include "msd-xsettings-plugin.h" +#include "msd-xsettings-manager.h" struct MateXSettingsPluginPrivate { MateXSettingsManager *manager; -- cgit v1.2.1 From e46b4adef5c6c6805b3ca6dbfbe99a4299252514 Mon Sep 17 00:00:00 2001 From: haxar Date: Tue, 21 Feb 2012 20:14:01 -0800 Subject: gsd to msd complete rename patch by NiceandGently; file rename commit --- plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c | 1347 ---------- plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h | 61 - plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c | 104 - plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h | 63 - .../a11y-keyboard/gsd-a11y-preferences-dialog.c | 975 -------- .../a11y-keyboard/gsd-a11y-preferences-dialog.h | 59 - .../a11y-keyboard/gsd-a11y-preferences-dialog.ui | 199 -- plugins/a11y-keyboard/msd-a11y-keyboard-manager.c | 1347 ++++++++++ plugins/a11y-keyboard/msd-a11y-keyboard-manager.h | 61 + plugins/a11y-keyboard/msd-a11y-keyboard-plugin.c | 104 + plugins/a11y-keyboard/msd-a11y-keyboard-plugin.h | 63 + .../a11y-keyboard/msd-a11y-preferences-dialog.c | 975 ++++++++ .../a11y-keyboard/msd-a11y-preferences-dialog.h | 59 + .../a11y-keyboard/msd-a11y-preferences-dialog.ui | 199 ++ plugins/background/gsd-background-manager.c | 579 ----- plugins/background/gsd-background-manager.h | 61 - plugins/background/gsd-background-plugin.c | 104 - plugins/background/gsd-background-plugin.h | 63 - plugins/background/msd-background-manager.c | 579 +++++ plugins/background/msd-background-manager.h | 61 + plugins/background/msd-background-plugin.c | 104 + plugins/background/msd-background-plugin.h | 63 + plugins/clipboard/gsd-clipboard-manager.c | 1069 -------- plugins/clipboard/gsd-clipboard-manager.h | 61 - plugins/clipboard/gsd-clipboard-plugin.c | 104 - plugins/clipboard/gsd-clipboard-plugin.h | 63 - plugins/clipboard/msd-clipboard-manager.c | 1069 ++++++++ plugins/clipboard/msd-clipboard-manager.h | 61 + plugins/clipboard/msd-clipboard-plugin.c | 104 + plugins/clipboard/msd-clipboard-plugin.h | 63 + plugins/common/gsd-keygrab.c | 246 -- plugins/common/gsd-keygrab.h | 51 - plugins/common/gsd-osd-window.c | 573 ----- plugins/common/gsd-osd-window.h | 98 - plugins/common/msd-keygrab.c | 246 ++ plugins/common/msd-keygrab.h | 51 + plugins/common/msd-osd-window.c | 573 +++++ plugins/common/msd-osd-window.h | 98 + plugins/datetime/gsd-datetime-mechanism-main.c | 171 -- plugins/datetime/gsd-datetime-mechanism.c | 646 ----- plugins/datetime/gsd-datetime-mechanism.h | 101 - plugins/datetime/gsd-datetime-mechanism.xml | 87 - plugins/datetime/msd-datetime-mechanism-main.c | 171 ++ plugins/datetime/msd-datetime-mechanism.c | 646 +++++ plugins/datetime/msd-datetime-mechanism.h | 101 + plugins/datetime/msd-datetime-mechanism.xml | 87 + plugins/dummy/gsd-dummy-manager.c | 186 -- plugins/dummy/gsd-dummy-manager.h | 61 - plugins/dummy/gsd-dummy-plugin.c | 104 - plugins/dummy/gsd-dummy-plugin.h | 63 - plugins/dummy/msd-dummy-manager.c | 186 ++ plugins/dummy/msd-dummy-manager.h | 61 + plugins/dummy/msd-dummy-plugin.c | 104 + plugins/dummy/msd-dummy-plugin.h | 63 + plugins/font/gsd-font-manager.c | 445 ---- plugins/font/gsd-font-manager.h | 61 - plugins/font/gsd-font-plugin.c | 104 - plugins/font/gsd-font-plugin.h | 63 - plugins/font/msd-font-manager.c | 445 ++++ plugins/font/msd-font-manager.h | 61 + plugins/font/msd-font-plugin.c | 104 + plugins/font/msd-font-plugin.h | 63 + plugins/housekeeping/gsd-disk-space.c | 733 ------ plugins/housekeeping/gsd-disk-space.h | 40 - plugins/housekeeping/gsd-housekeeping-manager.c | 389 --- plugins/housekeeping/gsd-housekeeping-manager.h | 59 - plugins/housekeeping/gsd-housekeeping-plugin.c | 104 - plugins/housekeeping/gsd-housekeeping-plugin.h | 61 - plugins/housekeeping/gsd-ldsm-dialog.c | 476 ---- plugins/housekeeping/gsd-ldsm-dialog.h | 72 - plugins/housekeeping/gsd-ldsm-trash-empty.c | 398 --- plugins/housekeeping/gsd-ldsm-trash-empty.h | 27 - plugins/housekeeping/msd-disk-space.c | 733 ++++++ plugins/housekeeping/msd-disk-space.h | 40 + plugins/housekeeping/msd-housekeeping-manager.c | 389 +++ plugins/housekeeping/msd-housekeeping-manager.h | 59 + plugins/housekeeping/msd-housekeeping-plugin.c | 104 + plugins/housekeeping/msd-housekeeping-plugin.h | 61 + plugins/housekeeping/msd-ldsm-dialog.c | 476 ++++ plugins/housekeeping/msd-ldsm-dialog.h | 72 + plugins/housekeeping/msd-ldsm-trash-empty.c | 398 +++ plugins/housekeeping/msd-ldsm-trash-empty.h | 27 + plugins/keybindings/gsd-keybindings-manager.c | 758 ------ plugins/keybindings/gsd-keybindings-manager.h | 61 - plugins/keybindings/gsd-keybindings-plugin.c | 104 - plugins/keybindings/gsd-keybindings-plugin.h | 63 - plugins/keybindings/msd-keybindings-manager.c | 758 ++++++ plugins/keybindings/msd-keybindings-manager.h | 61 + plugins/keybindings/msd-keybindings-plugin.c | 104 + plugins/keybindings/msd-keybindings-plugin.h | 63 + plugins/keyboard/gsd-keyboard-manager.c | 569 ----- plugins/keyboard/gsd-keyboard-manager.h | 62 - plugins/keyboard/gsd-keyboard-plugin.c | 104 - plugins/keyboard/gsd-keyboard-plugin.h | 63 - plugins/keyboard/gsd-keyboard-xkb.c | 918 ------- plugins/keyboard/gsd-keyboard-xkb.h | 40 - plugins/keyboard/gsd-xmodmap.c | 399 --- plugins/keyboard/gsd-xmodmap.h | 29 - plugins/keyboard/msd-keyboard-manager.c | 569 +++++ plugins/keyboard/msd-keyboard-manager.h | 62 + plugins/keyboard/msd-keyboard-plugin.c | 104 + plugins/keyboard/msd-keyboard-plugin.h | 63 + plugins/keyboard/msd-keyboard-xkb.c | 918 +++++++ plugins/keyboard/msd-keyboard-xkb.h | 40 + plugins/keyboard/msd-xmodmap.c | 399 +++ plugins/keyboard/msd-xmodmap.h | 29 + plugins/media-keys/gsd-marshal.list | 1 - plugins/media-keys/gsd-media-keys-manager.c | 1447 ----------- plugins/media-keys/gsd-media-keys-manager.h | 72 - plugins/media-keys/gsd-media-keys-manager.xml | 14 - plugins/media-keys/gsd-media-keys-plugin.c | 104 - plugins/media-keys/gsd-media-keys-plugin.h | 63 - plugins/media-keys/gsd-media-keys-window.c | 714 ------ plugins/media-keys/gsd-media-keys-window.h | 78 - plugins/media-keys/msd-marshal.list | 1 + plugins/media-keys/msd-media-keys-manager.c | 1447 +++++++++++ plugins/media-keys/msd-media-keys-manager.h | 72 + plugins/media-keys/msd-media-keys-manager.xml | 14 + plugins/media-keys/msd-media-keys-plugin.c | 104 + plugins/media-keys/msd-media-keys-plugin.h | 63 + plugins/media-keys/msd-media-keys-window.c | 714 ++++++ plugins/media-keys/msd-media-keys-window.h | 78 + plugins/mouse/gsd-locate-pointer.c | 504 ---- plugins/mouse/gsd-locate-pointer.h | 24 - plugins/mouse/gsd-mouse-manager.c | 1124 --------- plugins/mouse/gsd-mouse-manager.h | 61 - plugins/mouse/gsd-mouse-plugin.c | 104 - plugins/mouse/gsd-mouse-plugin.h | 63 - plugins/mouse/gsd-timeline.c | 848 ------- plugins/mouse/gsd-timeline.h | 127 - plugins/mouse/msd-locate-pointer.c | 504 ++++ plugins/mouse/msd-locate-pointer.h | 24 + plugins/mouse/msd-mouse-manager.c | 1124 +++++++++ plugins/mouse/msd-mouse-manager.h | 61 + plugins/mouse/msd-mouse-plugin.c | 104 + plugins/mouse/msd-mouse-plugin.h | 63 + plugins/mouse/msd-timeline.c | 848 +++++++ plugins/mouse/msd-timeline.h | 127 + plugins/smartcard/gsd-smartcard-manager.c | 1372 ----------- plugins/smartcard/gsd-smartcard-manager.h | 90 - plugins/smartcard/gsd-smartcard-plugin.c | 340 --- plugins/smartcard/gsd-smartcard-plugin.h | 63 - plugins/smartcard/gsd-smartcard.c | 555 ----- plugins/smartcard/gsd-smartcard.h | 98 - plugins/smartcard/msd-smartcard-manager.c | 1372 +++++++++++ plugins/smartcard/msd-smartcard-manager.h | 90 + plugins/smartcard/msd-smartcard-plugin.c | 340 +++ plugins/smartcard/msd-smartcard-plugin.h | 63 + plugins/smartcard/msd-smartcard.c | 555 +++++ plugins/smartcard/msd-smartcard.h | 98 + plugins/sound/gsd-sound-manager.c | 433 ---- plugins/sound/gsd-sound-manager.h | 61 - plugins/sound/gsd-sound-plugin.c | 100 - plugins/sound/gsd-sound-plugin.h | 63 - plugins/sound/msd-sound-manager.c | 433 ++++ plugins/sound/msd-sound-manager.h | 61 + plugins/sound/msd-sound-plugin.c | 100 + plugins/sound/msd-sound-plugin.h | 63 + plugins/typing-break/gsd-typing-break-manager.c | 339 --- plugins/typing-break/gsd-typing-break-manager.h | 61 - plugins/typing-break/gsd-typing-break-plugin.c | 104 - plugins/typing-break/gsd-typing-break-plugin.h | 63 - plugins/typing-break/msd-typing-break-manager.c | 339 +++ plugins/typing-break/msd-typing-break-manager.h | 61 + plugins/typing-break/msd-typing-break-plugin.c | 104 + plugins/typing-break/msd-typing-break-plugin.h | 63 + plugins/xrandr/gsd-xrandr-16.png | Bin 613 -> 0 bytes plugins/xrandr/gsd-xrandr-22.png | Bin 866 -> 0 bytes plugins/xrandr/gsd-xrandr-24.png | Bin 909 -> 0 bytes plugins/xrandr/gsd-xrandr-32.png | Bin 1602 -> 0 bytes plugins/xrandr/gsd-xrandr-manager.c | 2584 -------------------- plugins/xrandr/gsd-xrandr-manager.h | 61 - plugins/xrandr/gsd-xrandr-manager.xml | 23 - plugins/xrandr/gsd-xrandr-plugin.c | 104 - plugins/xrandr/gsd-xrandr-plugin.h | 63 - plugins/xrandr/gsd-xrandr.svg | 470 ---- plugins/xrandr/msd-xrandr-16.png | Bin 0 -> 613 bytes plugins/xrandr/msd-xrandr-22.png | Bin 0 -> 866 bytes plugins/xrandr/msd-xrandr-24.png | Bin 0 -> 909 bytes plugins/xrandr/msd-xrandr-32.png | Bin 0 -> 1602 bytes plugins/xrandr/msd-xrandr-manager.c | 2584 ++++++++++++++++++++ plugins/xrandr/msd-xrandr-manager.h | 61 + plugins/xrandr/msd-xrandr-manager.xml | 23 + plugins/xrandr/msd-xrandr-plugin.c | 104 + plugins/xrandr/msd-xrandr-plugin.h | 63 + plugins/xrandr/msd-xrandr.svg | 470 ++++ plugins/xrdb/gsd-xrdb-manager.c | 637 ----- plugins/xrdb/gsd-xrdb-manager.h | 61 - plugins/xrdb/gsd-xrdb-plugin.c | 104 - plugins/xrdb/gsd-xrdb-plugin.h | 63 - plugins/xrdb/msd-xrdb-manager.c | 637 +++++ plugins/xrdb/msd-xrdb-manager.h | 61 + plugins/xrdb/msd-xrdb-plugin.c | 104 + plugins/xrdb/msd-xrdb-plugin.h | 63 + plugins/xsettings/gsd-xsettings-manager.c | 1040 -------- plugins/xsettings/gsd-xsettings-manager.h | 61 - plugins/xsettings/gsd-xsettings-plugin.c | 104 - plugins/xsettings/gsd-xsettings-plugin.h | 63 - plugins/xsettings/msd-xsettings-manager.c | 1040 ++++++++ plugins/xsettings/msd-xsettings-manager.h | 61 + plugins/xsettings/msd-xsettings-plugin.c | 104 + plugins/xsettings/msd-xsettings-plugin.h | 63 + 202 files changed, 28029 insertions(+), 28029 deletions(-) delete mode 100644 plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c delete mode 100644 plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h delete mode 100644 plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c delete mode 100644 plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h delete mode 100644 plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c delete mode 100644 plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h delete mode 100644 plugins/a11y-keyboard/gsd-a11y-preferences-dialog.ui create mode 100644 plugins/a11y-keyboard/msd-a11y-keyboard-manager.c create mode 100644 plugins/a11y-keyboard/msd-a11y-keyboard-manager.h create mode 100644 plugins/a11y-keyboard/msd-a11y-keyboard-plugin.c create mode 100644 plugins/a11y-keyboard/msd-a11y-keyboard-plugin.h create mode 100644 plugins/a11y-keyboard/msd-a11y-preferences-dialog.c create mode 100644 plugins/a11y-keyboard/msd-a11y-preferences-dialog.h create mode 100644 plugins/a11y-keyboard/msd-a11y-preferences-dialog.ui delete mode 100644 plugins/background/gsd-background-manager.c delete mode 100644 plugins/background/gsd-background-manager.h delete mode 100644 plugins/background/gsd-background-plugin.c delete mode 100644 plugins/background/gsd-background-plugin.h create mode 100644 plugins/background/msd-background-manager.c create mode 100644 plugins/background/msd-background-manager.h create mode 100644 plugins/background/msd-background-plugin.c create mode 100644 plugins/background/msd-background-plugin.h delete mode 100644 plugins/clipboard/gsd-clipboard-manager.c delete mode 100644 plugins/clipboard/gsd-clipboard-manager.h delete mode 100644 plugins/clipboard/gsd-clipboard-plugin.c delete mode 100644 plugins/clipboard/gsd-clipboard-plugin.h create mode 100644 plugins/clipboard/msd-clipboard-manager.c create mode 100644 plugins/clipboard/msd-clipboard-manager.h create mode 100644 plugins/clipboard/msd-clipboard-plugin.c create mode 100644 plugins/clipboard/msd-clipboard-plugin.h delete mode 100644 plugins/common/gsd-keygrab.c delete mode 100644 plugins/common/gsd-keygrab.h delete mode 100644 plugins/common/gsd-osd-window.c delete mode 100644 plugins/common/gsd-osd-window.h create mode 100644 plugins/common/msd-keygrab.c create mode 100644 plugins/common/msd-keygrab.h create mode 100644 plugins/common/msd-osd-window.c create mode 100644 plugins/common/msd-osd-window.h delete mode 100644 plugins/datetime/gsd-datetime-mechanism-main.c delete mode 100644 plugins/datetime/gsd-datetime-mechanism.c delete mode 100644 plugins/datetime/gsd-datetime-mechanism.h delete mode 100644 plugins/datetime/gsd-datetime-mechanism.xml create mode 100644 plugins/datetime/msd-datetime-mechanism-main.c create mode 100644 plugins/datetime/msd-datetime-mechanism.c create mode 100644 plugins/datetime/msd-datetime-mechanism.h create mode 100644 plugins/datetime/msd-datetime-mechanism.xml delete mode 100644 plugins/dummy/gsd-dummy-manager.c delete mode 100644 plugins/dummy/gsd-dummy-manager.h delete mode 100644 plugins/dummy/gsd-dummy-plugin.c delete mode 100644 plugins/dummy/gsd-dummy-plugin.h create mode 100644 plugins/dummy/msd-dummy-manager.c create mode 100644 plugins/dummy/msd-dummy-manager.h create mode 100644 plugins/dummy/msd-dummy-plugin.c create mode 100644 plugins/dummy/msd-dummy-plugin.h delete mode 100644 plugins/font/gsd-font-manager.c delete mode 100644 plugins/font/gsd-font-manager.h delete mode 100644 plugins/font/gsd-font-plugin.c delete mode 100644 plugins/font/gsd-font-plugin.h create mode 100644 plugins/font/msd-font-manager.c create mode 100644 plugins/font/msd-font-manager.h create mode 100644 plugins/font/msd-font-plugin.c create mode 100644 plugins/font/msd-font-plugin.h delete mode 100644 plugins/housekeeping/gsd-disk-space.c delete mode 100644 plugins/housekeeping/gsd-disk-space.h delete mode 100644 plugins/housekeeping/gsd-housekeeping-manager.c delete mode 100644 plugins/housekeeping/gsd-housekeeping-manager.h delete mode 100644 plugins/housekeeping/gsd-housekeeping-plugin.c delete mode 100644 plugins/housekeeping/gsd-housekeeping-plugin.h delete mode 100644 plugins/housekeeping/gsd-ldsm-dialog.c delete mode 100644 plugins/housekeeping/gsd-ldsm-dialog.h delete mode 100644 plugins/housekeeping/gsd-ldsm-trash-empty.c delete mode 100644 plugins/housekeeping/gsd-ldsm-trash-empty.h create mode 100644 plugins/housekeeping/msd-disk-space.c create mode 100644 plugins/housekeeping/msd-disk-space.h create mode 100644 plugins/housekeeping/msd-housekeeping-manager.c create mode 100644 plugins/housekeeping/msd-housekeeping-manager.h create mode 100644 plugins/housekeeping/msd-housekeeping-plugin.c create mode 100644 plugins/housekeeping/msd-housekeeping-plugin.h create mode 100644 plugins/housekeeping/msd-ldsm-dialog.c create mode 100644 plugins/housekeeping/msd-ldsm-dialog.h create mode 100644 plugins/housekeeping/msd-ldsm-trash-empty.c create mode 100644 plugins/housekeeping/msd-ldsm-trash-empty.h delete mode 100644 plugins/keybindings/gsd-keybindings-manager.c delete mode 100644 plugins/keybindings/gsd-keybindings-manager.h delete mode 100644 plugins/keybindings/gsd-keybindings-plugin.c delete mode 100644 plugins/keybindings/gsd-keybindings-plugin.h create mode 100644 plugins/keybindings/msd-keybindings-manager.c create mode 100644 plugins/keybindings/msd-keybindings-manager.h create mode 100644 plugins/keybindings/msd-keybindings-plugin.c create mode 100644 plugins/keybindings/msd-keybindings-plugin.h delete mode 100644 plugins/keyboard/gsd-keyboard-manager.c delete mode 100644 plugins/keyboard/gsd-keyboard-manager.h delete mode 100644 plugins/keyboard/gsd-keyboard-plugin.c delete mode 100644 plugins/keyboard/gsd-keyboard-plugin.h delete mode 100644 plugins/keyboard/gsd-keyboard-xkb.c delete mode 100644 plugins/keyboard/gsd-keyboard-xkb.h delete mode 100644 plugins/keyboard/gsd-xmodmap.c delete mode 100644 plugins/keyboard/gsd-xmodmap.h create mode 100644 plugins/keyboard/msd-keyboard-manager.c create mode 100644 plugins/keyboard/msd-keyboard-manager.h create mode 100644 plugins/keyboard/msd-keyboard-plugin.c create mode 100644 plugins/keyboard/msd-keyboard-plugin.h create mode 100644 plugins/keyboard/msd-keyboard-xkb.c create mode 100644 plugins/keyboard/msd-keyboard-xkb.h create mode 100644 plugins/keyboard/msd-xmodmap.c create mode 100644 plugins/keyboard/msd-xmodmap.h delete mode 100644 plugins/media-keys/gsd-marshal.list delete mode 100644 plugins/media-keys/gsd-media-keys-manager.c delete mode 100644 plugins/media-keys/gsd-media-keys-manager.h delete mode 100644 plugins/media-keys/gsd-media-keys-manager.xml delete mode 100644 plugins/media-keys/gsd-media-keys-plugin.c delete mode 100644 plugins/media-keys/gsd-media-keys-plugin.h delete mode 100644 plugins/media-keys/gsd-media-keys-window.c delete mode 100644 plugins/media-keys/gsd-media-keys-window.h create mode 100644 plugins/media-keys/msd-marshal.list create mode 100644 plugins/media-keys/msd-media-keys-manager.c create mode 100644 plugins/media-keys/msd-media-keys-manager.h create mode 100644 plugins/media-keys/msd-media-keys-manager.xml create mode 100644 plugins/media-keys/msd-media-keys-plugin.c create mode 100644 plugins/media-keys/msd-media-keys-plugin.h create mode 100644 plugins/media-keys/msd-media-keys-window.c create mode 100644 plugins/media-keys/msd-media-keys-window.h delete mode 100644 plugins/mouse/gsd-locate-pointer.c delete mode 100644 plugins/mouse/gsd-locate-pointer.h delete mode 100644 plugins/mouse/gsd-mouse-manager.c delete mode 100644 plugins/mouse/gsd-mouse-manager.h delete mode 100644 plugins/mouse/gsd-mouse-plugin.c delete mode 100644 plugins/mouse/gsd-mouse-plugin.h delete mode 100644 plugins/mouse/gsd-timeline.c delete mode 100644 plugins/mouse/gsd-timeline.h create mode 100644 plugins/mouse/msd-locate-pointer.c create mode 100644 plugins/mouse/msd-locate-pointer.h create mode 100644 plugins/mouse/msd-mouse-manager.c create mode 100644 plugins/mouse/msd-mouse-manager.h create mode 100644 plugins/mouse/msd-mouse-plugin.c create mode 100644 plugins/mouse/msd-mouse-plugin.h create mode 100644 plugins/mouse/msd-timeline.c create mode 100644 plugins/mouse/msd-timeline.h delete mode 100644 plugins/smartcard/gsd-smartcard-manager.c delete mode 100644 plugins/smartcard/gsd-smartcard-manager.h delete mode 100644 plugins/smartcard/gsd-smartcard-plugin.c delete mode 100644 plugins/smartcard/gsd-smartcard-plugin.h delete mode 100644 plugins/smartcard/gsd-smartcard.c delete mode 100644 plugins/smartcard/gsd-smartcard.h create mode 100644 plugins/smartcard/msd-smartcard-manager.c create mode 100644 plugins/smartcard/msd-smartcard-manager.h create mode 100644 plugins/smartcard/msd-smartcard-plugin.c create mode 100644 plugins/smartcard/msd-smartcard-plugin.h create mode 100644 plugins/smartcard/msd-smartcard.c create mode 100644 plugins/smartcard/msd-smartcard.h delete mode 100644 plugins/sound/gsd-sound-manager.c delete mode 100644 plugins/sound/gsd-sound-manager.h delete mode 100644 plugins/sound/gsd-sound-plugin.c delete mode 100644 plugins/sound/gsd-sound-plugin.h create mode 100644 plugins/sound/msd-sound-manager.c create mode 100644 plugins/sound/msd-sound-manager.h create mode 100644 plugins/sound/msd-sound-plugin.c create mode 100644 plugins/sound/msd-sound-plugin.h delete mode 100644 plugins/typing-break/gsd-typing-break-manager.c delete mode 100644 plugins/typing-break/gsd-typing-break-manager.h delete mode 100644 plugins/typing-break/gsd-typing-break-plugin.c delete mode 100644 plugins/typing-break/gsd-typing-break-plugin.h create mode 100644 plugins/typing-break/msd-typing-break-manager.c create mode 100644 plugins/typing-break/msd-typing-break-manager.h create mode 100644 plugins/typing-break/msd-typing-break-plugin.c create mode 100644 plugins/typing-break/msd-typing-break-plugin.h delete mode 100644 plugins/xrandr/gsd-xrandr-16.png delete mode 100644 plugins/xrandr/gsd-xrandr-22.png delete mode 100644 plugins/xrandr/gsd-xrandr-24.png delete mode 100644 plugins/xrandr/gsd-xrandr-32.png delete mode 100644 plugins/xrandr/gsd-xrandr-manager.c delete mode 100644 plugins/xrandr/gsd-xrandr-manager.h delete mode 100644 plugins/xrandr/gsd-xrandr-manager.xml delete mode 100644 plugins/xrandr/gsd-xrandr-plugin.c delete mode 100644 plugins/xrandr/gsd-xrandr-plugin.h delete mode 100644 plugins/xrandr/gsd-xrandr.svg create mode 100644 plugins/xrandr/msd-xrandr-16.png create mode 100644 plugins/xrandr/msd-xrandr-22.png create mode 100644 plugins/xrandr/msd-xrandr-24.png create mode 100644 plugins/xrandr/msd-xrandr-32.png create mode 100644 plugins/xrandr/msd-xrandr-manager.c create mode 100644 plugins/xrandr/msd-xrandr-manager.h create mode 100644 plugins/xrandr/msd-xrandr-manager.xml create mode 100644 plugins/xrandr/msd-xrandr-plugin.c create mode 100644 plugins/xrandr/msd-xrandr-plugin.h create mode 100644 plugins/xrandr/msd-xrandr.svg delete mode 100644 plugins/xrdb/gsd-xrdb-manager.c delete mode 100644 plugins/xrdb/gsd-xrdb-manager.h delete mode 100644 plugins/xrdb/gsd-xrdb-plugin.c delete mode 100644 plugins/xrdb/gsd-xrdb-plugin.h create mode 100644 plugins/xrdb/msd-xrdb-manager.c create mode 100644 plugins/xrdb/msd-xrdb-manager.h create mode 100644 plugins/xrdb/msd-xrdb-plugin.c create mode 100644 plugins/xrdb/msd-xrdb-plugin.h delete mode 100644 plugins/xsettings/gsd-xsettings-manager.c delete mode 100644 plugins/xsettings/gsd-xsettings-manager.h delete mode 100644 plugins/xsettings/gsd-xsettings-plugin.c delete mode 100644 plugins/xsettings/gsd-xsettings-plugin.h create mode 100644 plugins/xsettings/msd-xsettings-manager.c create mode 100644 plugins/xsettings/msd-xsettings-manager.h create mode 100644 plugins/xsettings/msd-xsettings-plugin.c create mode 100644 plugins/xsettings/msd-xsettings-plugin.h (limited to 'plugins') diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c deleted file mode 100644 index 7505b14..0000000 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.c +++ /dev/null @@ -1,1347 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright © 2001 Ximian, Inc. - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -#include -#include -#endif - -#ifdef HAVE_LIBMATENOTIFY -#include -#endif /* HAVE_LIBMATENOTIFY */ - -#include "mate-settings-profile.h" -#include "msd-a11y-keyboard-manager.h" -#include "msd-a11y-preferences-dialog.h" - -#define CONFIG_ROOT "/desktop/mate/accessibility/keyboard" -#define NOTIFICATION_TIMEOUT 30 - -#define MSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerPrivate)) - -struct MsdA11yKeyboardManagerPrivate -{ - int xkbEventBase; - gboolean stickykeys_shortcut_val; - gboolean slowkeys_shortcut_val; - GtkWidget *stickykeys_alert; - GtkWidget *slowkeys_alert; - GtkWidget *preferences_dialog; - GtkStatusIcon *status_icon; - XkbDescRec *original_xkb_desc; - - guint mateconf_notify; - -#ifdef HAVE_LIBMATENOTIFY - NotifyNotification *notification; -#endif /* HAVE_LIBMATENOTIFY */ -}; - -static void msd_a11y_keyboard_manager_class_init (MsdA11yKeyboardManagerClass *klass); -static void msd_a11y_keyboard_manager_init (MsdA11yKeyboardManager *a11y_keyboard_manager); -static void msd_a11y_keyboard_manager_finalize (GObject *object); -static void msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager); -static void set_server_from_mateconf (MsdA11yKeyboardManager *manager, - MateConfClient *client); - -G_DEFINE_TYPE (MsdA11yKeyboardManager, msd_a11y_keyboard_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -#undef DEBUG_ACCESSIBILITY -#ifdef DEBUG_ACCESSIBILITY -#define d(str) g_debug (str) -#else -#define d(str) do { } while (0) -#endif - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -static GdkFilterReturn -devicepresence_filter (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) -{ - XEvent *xev = (XEvent *) xevent; - XEventClass class_presence; - int xi_presence; - - DevicePresence (gdk_x11_get_default_xdisplay (), xi_presence, class_presence); - - if (xev->type == xi_presence) - { - XDevicePresenceNotifyEvent *dpn = (XDevicePresenceNotifyEvent *) xev; - if (dpn->devchange == DeviceEnabled) { - MateConfClient *client; - client = mateconf_client_get_default (); - set_server_from_mateconf (data, client); - g_object_unref (client); - } - } - return GDK_FILTER_CONTINUE; -} - -static gboolean -supports_xinput_devices (void) -{ - gint op_code, event, error; - - return XQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - "XInputExtension", - &op_code, - &event, - &error); -} - -static void -set_devicepresence_handler (MsdA11yKeyboardManager *manager) -{ - Display *display; - XEventClass class_presence; - int xi_presence; - - if (!supports_xinput_devices ()) - return; - - display = gdk_x11_get_default_xdisplay (); - - gdk_error_trap_push (); - DevicePresence (display, xi_presence, class_presence); - /* FIXME: - * Note that this might overwrite other events, see: - * https://bugzilla.gnome.org/show_bug.cgi?id=610245#c2 - **/ - XSelectExtensionEvent (display, - RootWindow (display, DefaultScreen (display)), - &class_presence, 1); - - gdk_flush (); - if (!gdk_error_trap_pop ()) - gdk_window_add_filter (NULL, devicepresence_filter, manager); -} -#endif - -static gboolean -xkb_enabled (MsdA11yKeyboardManager *manager) -{ - gboolean have_xkb; - int opcode, errorBase, major, minor; - - have_xkb = XkbQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - &opcode, - &manager->priv->xkbEventBase, - &errorBase, - &major, - &minor) - && XkbUseExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &major, &minor); - - return have_xkb; -} - -static XkbDescRec * -get_xkb_desc_rec (MsdA11yKeyboardManager *manager) -{ - XkbDescRec *desc; - Status status = Success; - - gdk_error_trap_push (); - desc = XkbGetMap (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XkbAllMapComponentsMask, XkbUseCoreKbd); - if (desc != NULL) { - desc->ctrls = NULL; - status = XkbGetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XkbAllControlsMask, desc); - } - gdk_error_trap_pop (); - - g_return_val_if_fail (desc != NULL, NULL); - g_return_val_if_fail (desc->ctrls != NULL, NULL); - g_return_val_if_fail (status == Success, NULL); - - return desc; -} - -static int -get_int (MateConfClient *client, - char const *key) -{ - int res = mateconf_client_get_int (client, key, NULL); - if (res <= 0) { - res = 1; - } - return res; -} - -static gboolean -set_int (MateConfClient *client, - MateConfChangeSet *cs, - char const *key, - int val) -{ - mateconf_change_set_set_int (cs, key, val); -#ifdef DEBUG_ACCESSIBILITY - if (val != mateconf_client_get_int (client, key, NULL)) { - g_warning ("%s changed", key); - } -#endif - return val != mateconf_client_get_int (client, key, NULL); -} - -static gboolean -set_bool (MateConfClient *client, - MateConfChangeSet *cs, - char const *key, - int val) -{ - gboolean bval = (val != 0); - - mateconf_change_set_set_bool (cs, key, bval ? TRUE : FALSE); -#ifdef DEBUG_ACCESSIBILITY - if (bval != mateconf_client_get_bool (client, key, NULL)) { - d ("%s changed", key); - return TRUE; - } -#endif - return (bval != mateconf_client_get_bool (client, key, NULL)); -} - -static unsigned long -set_clear (gboolean flag, - unsigned long value, - unsigned long mask) -{ - if (flag) { - return value | mask; - } - return value & ~mask; -} - -static gboolean -set_ctrl_from_mateconf (XkbDescRec *desc, - MateConfClient *client, - char const *key, - unsigned long mask) -{ - gboolean result = mateconf_client_get_bool (client, key, NULL); - desc->ctrls->enabled_ctrls = set_clear (result, desc->ctrls->enabled_ctrls, mask); - return result; -} - -static void -set_server_from_mateconf (MsdA11yKeyboardManager *manager, - MateConfClient *client) -{ - XkbDescRec *desc; - gboolean enable_accessX; - - mate_settings_profile_start (NULL); - - desc = get_xkb_desc_rec (manager); - if (!desc) { - return; - } - - /* general */ - enable_accessX = mateconf_client_get_bool (client, CONFIG_ROOT "/enable", NULL); - - desc->ctrls->enabled_ctrls = set_clear (enable_accessX, - desc->ctrls->enabled_ctrls, - XkbAccessXKeysMask); - - if (set_ctrl_from_mateconf (desc, client, CONFIG_ROOT "/timeout_enable", - XkbAccessXTimeoutMask)) { - desc->ctrls->ax_timeout = get_int (client, - CONFIG_ROOT "/timeout"); - /* disable only the master flag via the server we will disable - * the rest on the rebound without affecting mateconf state - * don't change the option flags at all. - */ - desc->ctrls->axt_ctrls_mask = XkbAccessXKeysMask | XkbAccessXFeedbackMask; - desc->ctrls->axt_ctrls_values = 0; - desc->ctrls->axt_opts_mask = 0; - } - - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/feature_state_change_beep", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask); - - /* bounce keys */ - if (set_ctrl_from_mateconf (desc, - client, - CONFIG_ROOT "/bouncekeys_enable", - XkbBounceKeysMask)) { - desc->ctrls->debounce_delay = get_int (client, - CONFIG_ROOT "/bouncekeys_delay"); - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/bouncekeys_beep_reject", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_BKRejectFBMask); - } - - /* mouse keys */ - if (set_ctrl_from_mateconf (desc, - client, - CONFIG_ROOT "/mousekeys_enable", - XkbMouseKeysMask | XkbMouseKeysAccelMask)) { - desc->ctrls->mk_interval = 100; /* msec between mousekey events */ - desc->ctrls->mk_curve = 50; - - /* We store pixels / sec, XKB wants pixels / event */ - desc->ctrls->mk_max_speed = get_int (client, - CONFIG_ROOT "/mousekeys_max_speed") / (1000 / desc->ctrls->mk_interval); - if (desc->ctrls->mk_max_speed <= 0) - desc->ctrls->mk_max_speed = 1; - - desc->ctrls->mk_time_to_max = get_int (client, /* events before max */ - CONFIG_ROOT "/mousekeys_accel_time") / desc->ctrls->mk_interval; - if (desc->ctrls->mk_time_to_max <= 0) - desc->ctrls->mk_time_to_max = 1; - - desc->ctrls->mk_delay = get_int (client, /* ms before 1st event */ - CONFIG_ROOT "/mousekeys_init_delay"); - } - - /* slow keys */ - if (set_ctrl_from_mateconf (desc, - client, - CONFIG_ROOT "/slowkeys_enable", - XkbSlowKeysMask)) { - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_press", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_SKPressFBMask); - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_accept", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_SKAcceptFBMask); - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_reject", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_SKRejectFBMask); - desc->ctrls->slow_keys_delay = get_int (client, - CONFIG_ROOT "/slowkeys_delay"); - /* anything larger than 500 seems to loose all keyboard input */ - if (desc->ctrls->slow_keys_delay > 500) - desc->ctrls->slow_keys_delay = 500; - } - - /* sticky keys */ - if (set_ctrl_from_mateconf (desc, - client, - CONFIG_ROOT "/stickykeys_enable", - XkbStickyKeysMask)) { - desc->ctrls->ax_options |= XkbAX_LatchToLockMask; - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/stickykeys_two_key_off", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_TwoKeysMask); - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/stickykeys_modifier_beep", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_StickyKeysFBMask); - } - - /* toggle keys */ - desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/togglekeys_enable", NULL), - desc->ctrls->ax_options, - XkbAccessXFeedbackMask | XkbAX_IndicatorFBMask); - - /* - g_debug ("CHANGE to : 0x%x", desc->ctrls->enabled_ctrls); - g_debug ("CHANGE to : 0x%x (2)", desc->ctrls->ax_options); - */ - - gdk_error_trap_push (); - XkbSetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - XkbSlowKeysMask | - XkbBounceKeysMask | - XkbStickyKeysMask | - XkbMouseKeysMask | - XkbMouseKeysAccelMask | - XkbAccessXKeysMask | - XkbAccessXTimeoutMask | - XkbAccessXFeedbackMask | - XkbControlsEnabledMask, - desc); - - XkbFreeKeyboard (desc, XkbAllComponentsMask, True); - - XSync (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), FALSE); - gdk_error_trap_pop (); - - mate_settings_profile_end (NULL); -} - -static gboolean -ax_response_callback (MsdA11yKeyboardManager *manager, - GtkWindow *parent, - gint response_id, - guint revert_controls_mask, - gboolean enabled) -{ - MateConfClient *client; - GdkScreen *screen; - GError *err; - - switch (response_id) { - case GTK_RESPONSE_DELETE_EVENT: - case GTK_RESPONSE_REJECT: - case GTK_RESPONSE_CANCEL: - - client = mateconf_client_get_default (); - - /* we're reverting, so we invert sense of 'enabled' flag */ - d ("cancelling AccessX request"); - if (revert_controls_mask == XkbStickyKeysMask) { - mateconf_client_set_bool (client, - CONFIG_ROOT "/stickykeys_enable", - !enabled, - NULL); - } - else if (revert_controls_mask == XkbSlowKeysMask) { - mateconf_client_set_bool (client, - CONFIG_ROOT "/slowkeys_enable", - !enabled, - NULL); - } - mateconf_client_suggest_sync (client, NULL); - set_server_from_mateconf (manager, client); - - g_object_unref (client); - - break; - - case GTK_RESPONSE_HELP: - if (!parent) - screen = gdk_screen_get_default (); - else - screen = gtk_widget_get_screen (GTK_WIDGET (parent)); - - err = NULL; - if (!gtk_show_uri (screen, - "ghelp:user-guide#goscustaccess-6", - gtk_get_current_event_time(), - &err)) { - GtkWidget *error_dialog = gtk_message_dialog_new (parent, - 0, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - _("There was an error displaying help: %s"), - err->message); - g_signal_connect (error_dialog, "response", - G_CALLBACK (gtk_widget_destroy), NULL); - gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE); - gtk_widget_show (error_dialog); - g_error_free (err); - } - return FALSE; - default: - break; - } - return TRUE; -} - -static void -ax_stickykeys_response (GtkDialog *dialog, - gint response_id, - MsdA11yKeyboardManager *manager) -{ - if (ax_response_callback (manager, GTK_WINDOW (dialog), - response_id, XkbStickyKeysMask, - manager->priv->stickykeys_shortcut_val)) { - gtk_widget_destroy (GTK_WIDGET (dialog)); - } -} - -static void -ax_slowkeys_response (GtkDialog *dialog, - gint response_id, - MsdA11yKeyboardManager *manager) -{ - if (ax_response_callback (manager, GTK_WINDOW (dialog), - response_id, XkbSlowKeysMask, - manager->priv->slowkeys_shortcut_val)) { - gtk_widget_destroy (GTK_WIDGET (dialog)); - } -} - -static void -maybe_show_status_icon (MsdA11yKeyboardManager *manager) -{ - gboolean show; - MateConfClient *client; - - /* for now, show if accessx is enabled */ - client = mateconf_client_get_default (); - show = mateconf_client_get_bool (client, CONFIG_ROOT "/enable", NULL); - g_object_unref (client); - - if (!show && manager->priv->status_icon == NULL) - return; - - msd_a11y_keyboard_manager_ensure_status_icon (manager); - gtk_status_icon_set_visible (manager->priv->status_icon, show); -} - -#ifdef HAVE_LIBMATENOTIFY -static void -on_notification_closed (NotifyNotification *notification, - MsdA11yKeyboardManager *manager) -{ - g_object_unref (manager->priv->notification); - manager->priv->notification = NULL; -} - -static void -on_slow_keys_action (NotifyNotification *notification, - const char *action, - MsdA11yKeyboardManager *manager) -{ - gboolean res; - int response_id; - - g_assert (action != NULL); - - if (strcmp (action, "accept") == 0) { - response_id = GTK_RESPONSE_ACCEPT; - } else if (strcmp (action, "reject") == 0) { - response_id = GTK_RESPONSE_REJECT; - } else { - return; - } - - res = ax_response_callback (manager, NULL, - response_id, XkbSlowKeysMask, - manager->priv->slowkeys_shortcut_val); - if (res) { - notify_notification_close (manager->priv->notification, NULL); - } -} - -static void -on_sticky_keys_action (NotifyNotification *notification, - const char *action, - MsdA11yKeyboardManager *manager) -{ - gboolean res; - int response_id; - - g_assert (action != NULL); - - if (strcmp (action, "accept") == 0) { - response_id = GTK_RESPONSE_ACCEPT; - } else if (strcmp (action, "reject") == 0) { - response_id = GTK_RESPONSE_REJECT; - } else { - return; - } - - res = ax_response_callback (manager, NULL, - response_id, XkbStickyKeysMask, - manager->priv->stickykeys_shortcut_val); - if (res) { - notify_notification_close (manager->priv->notification, NULL); - } -} - -#endif /* HAVE_LIBMATENOTIFY */ - -static gboolean -ax_slowkeys_warning_post_bubble (MsdA11yKeyboardManager *manager, - gboolean enabled) -{ -#ifdef HAVE_LIBMATENOTIFY - gboolean res; - const char *title; - const char *message; - GError *error; - - title = enabled ? - _("Do you want to activate Slow Keys?") : - _("Do you want to deactivate Slow Keys?"); - message = _("You just held down the Shift key for 8 seconds. This is the shortcut " - "for the Slow Keys feature, which affects the way your keyboard works."); - - if (manager->priv->status_icon == NULL || ! gtk_status_icon_is_embedded (manager->priv->status_icon)) { - return FALSE; - } - - if (manager->priv->slowkeys_alert != NULL) { - gtk_widget_destroy (manager->priv->slowkeys_alert); - } - - if (manager->priv->notification != NULL) { - notify_notification_close (manager->priv->notification, NULL); - } - - msd_a11y_keyboard_manager_ensure_status_icon (manager); - manager->priv->notification = notify_notification_new (title, - message, - "preferences-desktop-accessibility", - NULL); - notify_notification_attach_to_status_icon (manager->priv->notification, manager->priv->status_icon); - notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000); - - notify_notification_add_action (manager->priv->notification, - "reject", - enabled ? _("Don't activate") : _("Don't deactivate"), - (NotifyActionCallback) on_slow_keys_action, - manager, - NULL); - notify_notification_add_action (manager->priv->notification, - "accept", - enabled ? _("Activate") : _("Deactivate"), - (NotifyActionCallback) on_slow_keys_action, - manager, - NULL); - - g_signal_connect (manager->priv->notification, - "closed", - G_CALLBACK (on_notification_closed), - manager); - - error = NULL; - res = notify_notification_show (manager->priv->notification, &error); - if (! res) { - g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message); - g_error_free (error); - notify_notification_close (manager->priv->notification, NULL); - } - - return res; -#else - return FALSE; -#endif /* HAVE_LIBMATENOTIFY */ -} - - -static void -ax_slowkeys_warning_post_dialog (MsdA11yKeyboardManager *manager, - gboolean enabled) -{ - const char *title; - const char *message; - - title = enabled ? - _("Do you want to activate Slow Keys?") : - _("Do you want to deactivate Slow Keys?"); - message = _("You just held down the Shift key for 8 seconds. This is the shortcut " - "for the Slow Keys feature, which affects the way your keyboard works."); - - if (manager->priv->slowkeys_alert != NULL) { - gtk_widget_show (manager->priv->slowkeys_alert); - return; - } - - manager->priv->slowkeys_alert = gtk_message_dialog_new (NULL, - 0, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, - "%s", title); - - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (manager->priv->slowkeys_alert), - "%s", message); - - gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert), - GTK_STOCK_HELP, - GTK_RESPONSE_HELP); - gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert), - enabled ? _("Do_n't activate") : _("Do_n't deactivate"), - GTK_RESPONSE_REJECT); - gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert), - enabled ? _("_Activate") : _("_Deactivate"), - GTK_RESPONSE_ACCEPT); - - gtk_window_set_title (GTK_WINDOW (manager->priv->slowkeys_alert), - _("Slow Keys Alert")); - gtk_window_set_icon_name (GTK_WINDOW (manager->priv->slowkeys_alert), - "input-keyboard"); - gtk_dialog_set_default_response (GTK_DIALOG (manager->priv->slowkeys_alert), - GTK_RESPONSE_ACCEPT); - - g_signal_connect (manager->priv->slowkeys_alert, - "response", - G_CALLBACK (ax_slowkeys_response), - manager); - gtk_widget_show (manager->priv->slowkeys_alert); - - g_object_add_weak_pointer (G_OBJECT (manager->priv->slowkeys_alert), - (gpointer*) &manager->priv->slowkeys_alert); -} - -static void -ax_slowkeys_warning_post (MsdA11yKeyboardManager *manager, - gboolean enabled) -{ - - manager->priv->slowkeys_shortcut_val = enabled; - - /* alway try to show something */ - if (! ax_slowkeys_warning_post_bubble (manager, enabled)) { - ax_slowkeys_warning_post_dialog (manager, enabled); - } -} - -static gboolean -ax_stickykeys_warning_post_bubble (MsdA11yKeyboardManager *manager, - gboolean enabled) -{ -#ifdef HAVE_LIBMATENOTIFY - gboolean res; - const char *title; - const char *message; - GError *error; - - title = enabled ? - _("Do you want to activate Sticky Keys?") : - _("Do you want to deactivate Sticky Keys?"); - message = enabled ? - _("You just pressed the Shift key 5 times in a row. This is the shortcut " - "for the Sticky Keys feature, which affects the way your keyboard works.") : - _("You just pressed two keys at once, or pressed the Shift key 5 times in a row. " - "This turns off the Sticky Keys feature, which affects the way your keyboard works."); - - if (manager->priv->status_icon == NULL || ! gtk_status_icon_is_embedded (manager->priv->status_icon)) { - return FALSE; - } - - if (manager->priv->slowkeys_alert != NULL) { - gtk_widget_destroy (manager->priv->slowkeys_alert); - } - - if (manager->priv->notification != NULL) { - notify_notification_close (manager->priv->notification, NULL); - } - - msd_a11y_keyboard_manager_ensure_status_icon (manager); - manager->priv->notification = notify_notification_new (title, - message, - "preferences-desktop-accessibility", - NULL); - notify_notification_attach_to_status_icon (manager->priv->notification, manager->priv->status_icon); - notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000); - - notify_notification_add_action (manager->priv->notification, - "reject", - enabled ? _("Don't activate") : _("Don't deactivate"), - (NotifyActionCallback) on_sticky_keys_action, - manager, - NULL); - notify_notification_add_action (manager->priv->notification, - "accept", - enabled ? _("Activate") : _("Deactivate"), - (NotifyActionCallback) on_sticky_keys_action, - manager, - NULL); - - g_signal_connect (manager->priv->notification, - "closed", - G_CALLBACK (on_notification_closed), - manager); - - error = NULL; - res = notify_notification_show (manager->priv->notification, &error); - if (! res) { - g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message); - g_error_free (error); - notify_notification_close (manager->priv->notification, NULL); - } - - return res; -#else - return FALSE; -#endif /* HAVE_LIBMATENOTIFY */ -} - -static void -ax_stickykeys_warning_post_dialog (MsdA11yKeyboardManager *manager, - gboolean enabled) -{ - const char *title; - const char *message; - - title = enabled ? - _("Do you want to activate Sticky Keys?") : - _("Do you want to deactivate Sticky Keys?"); - message = enabled ? - _("You just pressed the Shift key 5 times in a row. This is the shortcut " - "for the Sticky Keys feature, which affects the way your keyboard works.") : - _("You just pressed two keys at once, or pressed the Shift key 5 times in a row. " - "This turns off the Sticky Keys feature, which affects the way your keyboard works."); - - if (manager->priv->stickykeys_alert != NULL) { - gtk_widget_show (manager->priv->stickykeys_alert); - return; - } - - manager->priv->stickykeys_alert = gtk_message_dialog_new (NULL, - 0, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, - "%s", title); - - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (manager->priv->stickykeys_alert), - "%s", message); - - gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert), - GTK_STOCK_HELP, - GTK_RESPONSE_HELP); - gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert), - enabled ? _("Do_n't activate") : _("Do_n't deactivate"), - GTK_RESPONSE_REJECT); - gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert), - enabled ? _("_Activate") : _("_Deactivate"), - GTK_RESPONSE_ACCEPT); - - gtk_window_set_title (GTK_WINDOW (manager->priv->stickykeys_alert), - _("Sticky Keys Alert")); - gtk_window_set_icon_name (GTK_WINDOW (manager->priv->stickykeys_alert), - "input-keyboard"); - gtk_dialog_set_default_response (GTK_DIALOG (manager->priv->stickykeys_alert), - GTK_RESPONSE_ACCEPT); - - g_signal_connect (manager->priv->stickykeys_alert, - "response", - G_CALLBACK (ax_stickykeys_response), - manager); - gtk_widget_show (manager->priv->stickykeys_alert); - - g_object_add_weak_pointer (G_OBJECT (manager->priv->stickykeys_alert), - (gpointer*) &manager->priv->stickykeys_alert); -} - -static void -ax_stickykeys_warning_post (MsdA11yKeyboardManager *manager, - gboolean enabled) -{ - - manager->priv->stickykeys_shortcut_val = enabled; - - /* alway try to show something */ - if (! ax_stickykeys_warning_post_bubble (manager, enabled)) { - ax_stickykeys_warning_post_dialog (manager, enabled); - } -} - -static void -set_mateconf_from_server (MsdA11yKeyboardManager *manager) -{ - MateConfClient *client; - MateConfChangeSet *cs; - XkbDescRec *desc; - gboolean changed = FALSE; - gboolean slowkeys_changed; - gboolean stickykeys_changed; - - cs = mateconf_change_set_new (); - desc = get_xkb_desc_rec (manager); - if (! desc) { - return; - } - - client = mateconf_client_get_default (); - - /* - fprintf (stderr, "changed to : 0x%x\n", desc->ctrls->enabled_ctrls); - fprintf (stderr, "changed to : 0x%x (2)\n", desc->ctrls->ax_options); - */ - - changed |= set_bool (client, - cs, - CONFIG_ROOT "/enable", - desc->ctrls->enabled_ctrls & XkbAccessXKeysMask); - - changed |= set_bool (client, - cs, - CONFIG_ROOT "/feature_state_change_beep", - desc->ctrls->ax_options & (XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask)); - changed |= set_bool (client, - cs, - CONFIG_ROOT "/timeout_enable", - desc->ctrls->enabled_ctrls & XkbAccessXTimeoutMask); - changed |= set_int (client, - cs, - CONFIG_ROOT "/timeout", - desc->ctrls->ax_timeout); - - changed |= set_bool (client, - cs, - CONFIG_ROOT "/bouncekeys_enable", - desc->ctrls->enabled_ctrls & XkbBounceKeysMask); - changed |= set_int (client, - cs, - CONFIG_ROOT "/bouncekeys_delay", - desc->ctrls->debounce_delay); - changed |= set_bool (client, - cs, - CONFIG_ROOT "/bouncekeys_beep_reject", - desc->ctrls->ax_options & XkbAX_BKRejectFBMask); - - changed |= set_bool (client, - cs, - CONFIG_ROOT "/mousekeys_enable", - desc->ctrls->enabled_ctrls & XkbMouseKeysMask); - changed |= set_int (client, - cs, - CONFIG_ROOT "/mousekeys_max_speed", - desc->ctrls->mk_max_speed * (1000 / desc->ctrls->mk_interval)); - /* NOTE : mk_time_to_max is measured in events not time */ - changed |= set_int (client, - cs, - CONFIG_ROOT "/mousekeys_accel_time", - desc->ctrls->mk_time_to_max * desc->ctrls->mk_interval); - changed |= set_int (client, - cs, - CONFIG_ROOT "/mousekeys_init_delay", - desc->ctrls->mk_delay); - - slowkeys_changed = set_bool (client, - cs, - CONFIG_ROOT "/slowkeys_enable", - desc->ctrls->enabled_ctrls & XkbSlowKeysMask); - changed |= set_bool (client, - cs, - CONFIG_ROOT "/slowkeys_beep_press", - desc->ctrls->ax_options & XkbAX_SKPressFBMask); - changed |= set_bool (client, - cs, - CONFIG_ROOT "/slowkeys_beep_accept", - desc->ctrls->ax_options & XkbAX_SKAcceptFBMask); - changed |= set_bool (client, - cs, - CONFIG_ROOT "/slowkeys_beep_reject", - desc->ctrls->ax_options & XkbAX_SKRejectFBMask); - changed |= set_int (client, - cs, - CONFIG_ROOT "/slowkeys_delay", - desc->ctrls->slow_keys_delay); - - stickykeys_changed = set_bool (client, - cs, - CONFIG_ROOT "/stickykeys_enable", - desc->ctrls->enabled_ctrls & XkbStickyKeysMask); - changed |= set_bool (client, - cs, - CONFIG_ROOT "/stickykeys_two_key_off", - desc->ctrls->ax_options & XkbAX_TwoKeysMask); - changed |= set_bool (client, - cs, - CONFIG_ROOT "/stickykeys_modifier_beep", - desc->ctrls->ax_options & XkbAX_StickyKeysFBMask); - - changed |= set_bool (client, - cs, - CONFIG_ROOT "/togglekeys_enable", - desc->ctrls->ax_options & XkbAX_IndicatorFBMask); - - if (!changed && stickykeys_changed ^ slowkeys_changed) { - /* - * sticky or slowkeys has changed, singly, without our intervention. - * 99% chance this is due to a keyboard shortcut being used. - * we need to detect via this hack until we get - * XkbAXN_AXKWarning notifications working (probable XKB bug), - * at which time we can directly intercept such shortcuts instead. - * See cb_xkb_event_filter () below. - */ - - /* sanity check: are keyboard shortcuts available? */ - if (desc->ctrls->enabled_ctrls & XkbAccessXKeysMask) { - if (slowkeys_changed) { - ax_slowkeys_warning_post (manager, - desc->ctrls->enabled_ctrls & XkbSlowKeysMask); - } else { - ax_stickykeys_warning_post (manager, - desc->ctrls->enabled_ctrls & XkbStickyKeysMask); - } - } - } - - XkbFreeKeyboard (desc, XkbAllComponentsMask, True); - - changed |= (stickykeys_changed | slowkeys_changed); - - if (changed) { - mateconf_client_commit_change_set (client, cs, FALSE, NULL); - mateconf_client_suggest_sync (client, NULL); - } - mateconf_change_set_unref (cs); - - g_object_unref (client); -} - -static GdkFilterReturn -cb_xkb_event_filter (GdkXEvent *xevent, - GdkEvent *ignored1, - MsdA11yKeyboardManager *manager) -{ - XEvent *xev = (XEvent *) xevent; - XkbEvent *xkbEv = (XkbEvent *) xevent; - - if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) && - xkbEv->any.xkb_type == XkbControlsNotify) { - d ("XKB state changed"); - set_mateconf_from_server (manager); - } else if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) && - xkbEv->any.xkb_type == XkbAccessXNotify) { - if (xkbEv->accessx.detail == XkbAXN_AXKWarning) { - d ("About to turn on an AccessX feature from the keyboard!"); - /* - * TODO: when XkbAXN_AXKWarnings start working, we need to - * invoke ax_keys_warning_dialog_run here instead of in - * set_mateconf_from_server(). - */ - } - } - - return GDK_FILTER_CONTINUE; -} - -static void -keyboard_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdA11yKeyboardManager *manager) -{ - set_server_from_mateconf (manager, client); - maybe_show_status_icon (manager); -} - -static void -register_config_callback (MsdA11yKeyboardManager *manager, - MateConfClient *client, - const char *path, - MateConfClientNotifyFunc func, - guint *notify) -{ - mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - *notify = mateconf_client_notify_add (client, path, func, manager, NULL, NULL); -} - -static gboolean -start_a11y_keyboard_idle_cb (MsdA11yKeyboardManager *manager) -{ - guint event_mask; - MateConfClient *client; - - g_debug ("Starting a11y_keyboard manager"); - mate_settings_profile_start (NULL); - - if (!xkb_enabled (manager)) - goto out; - - client = mateconf_client_get_default (); - - register_config_callback (manager, - client, - CONFIG_ROOT, - (MateConfClientNotifyFunc) keyboard_callback, - &manager->priv->mateconf_notify); - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - set_devicepresence_handler (manager); -#endif - - /* Save current xkb state so we can restore it on exit - */ - manager->priv->original_xkb_desc = get_xkb_desc_rec (manager); - - event_mask = XkbControlsNotifyMask; -#ifdef DEBUG_ACCESSIBILITY - event_mask |= XkbAccessXNotifyMask; /* make default when AXN_AXKWarning works */ -#endif - - /* be sure to init before starting to monitor the server */ - set_server_from_mateconf (manager, client); - g_object_unref (client); - - XkbSelectEvents (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - XkbUseCoreKbd, - event_mask, - event_mask); - - gdk_window_add_filter (NULL, - (GdkFilterFunc) cb_xkb_event_filter, - manager); - - maybe_show_status_icon (manager); - - out: - mate_settings_profile_end (NULL); - - return FALSE; -} - - -gboolean -msd_a11y_keyboard_manager_start (MsdA11yKeyboardManager *manager, - GError **error) -{ - mate_settings_profile_start (NULL); - - g_idle_add ((GSourceFunc) start_a11y_keyboard_idle_cb, manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -static void -restore_server_xkb_config (MsdA11yKeyboardManager *manager) -{ - gdk_error_trap_push (); - XkbSetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - XkbSlowKeysMask | - XkbBounceKeysMask | - XkbStickyKeysMask | - XkbMouseKeysMask | - XkbMouseKeysAccelMask | - XkbAccessXKeysMask | - XkbAccessXTimeoutMask | - XkbAccessXFeedbackMask | - XkbControlsEnabledMask, - manager->priv->original_xkb_desc); - - XkbFreeKeyboard (manager->priv->original_xkb_desc, - XkbAllComponentsMask, True); - - XSync (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), FALSE); - gdk_error_trap_pop (); - - manager->priv->original_xkb_desc = NULL; -} - -void -msd_a11y_keyboard_manager_stop (MsdA11yKeyboardManager *manager) -{ - MsdA11yKeyboardManagerPrivate *p = manager->priv; - - g_debug ("Stopping a11y_keyboard manager"); - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - gdk_window_remove_filter (NULL, devicepresence_filter, manager); -#endif - - if (p->status_icon) - gtk_status_icon_set_visible (p->status_icon, FALSE); - - if (p->mateconf_notify != 0) { - MateConfClient *client = mateconf_client_get_default (); - mateconf_client_remove_dir (client, CONFIG_ROOT, NULL); - mateconf_client_notify_remove (client, p->mateconf_notify); - g_object_unref (client); - p->mateconf_notify = 0; - } - - gdk_window_remove_filter (NULL, - (GdkFilterFunc) cb_xkb_event_filter, - manager); - - /* Disable all the AccessX bits - */ - restore_server_xkb_config (manager); - - if (p->slowkeys_alert != NULL) - gtk_widget_destroy (p->slowkeys_alert); - - if (p->stickykeys_alert != NULL) - gtk_widget_destroy (p->stickykeys_alert); - - p->slowkeys_shortcut_val = FALSE; - p->stickykeys_shortcut_val = FALSE; -} - -static void -msd_a11y_keyboard_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdA11yKeyboardManager *self; - - self = MSD_A11Y_KEYBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_a11y_keyboard_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdA11yKeyboardManager *self; - - self = MSD_A11Y_KEYBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_a11y_keyboard_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdA11yKeyboardManager *a11y_keyboard_manager; - MsdA11yKeyboardManagerClass *klass; - - klass = MSD_A11Y_KEYBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_A11Y_KEYBOARD_MANAGER)); - - a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (a11y_keyboard_manager); -} - -static void -msd_a11y_keyboard_manager_dispose (GObject *object) -{ - MsdA11yKeyboardManager *a11y_keyboard_manager; - - a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (object); - - G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->dispose (object); -} - -static void -msd_a11y_keyboard_manager_class_init (MsdA11yKeyboardManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_a11y_keyboard_manager_get_property; - object_class->set_property = msd_a11y_keyboard_manager_set_property; - object_class->constructor = msd_a11y_keyboard_manager_constructor; - object_class->dispose = msd_a11y_keyboard_manager_dispose; - object_class->finalize = msd_a11y_keyboard_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdA11yKeyboardManagerPrivate)); -} - -static void -on_preferences_dialog_response (GtkDialog *dialog, - int response, - MsdA11yKeyboardManager *manager) -{ - g_signal_handlers_disconnect_by_func (dialog, - on_preferences_dialog_response, - manager); - - gtk_widget_destroy (GTK_WIDGET (dialog)); - manager->priv->preferences_dialog = NULL; -} - -static void -on_status_icon_activate (GtkStatusIcon *status_icon, - MsdA11yKeyboardManager *manager) -{ - if (manager->priv->preferences_dialog == NULL) { - manager->priv->preferences_dialog = msd_a11y_preferences_dialog_new (); - g_signal_connect (manager->priv->preferences_dialog, - "response", - G_CALLBACK (on_preferences_dialog_response), - manager); - - gtk_window_present (GTK_WINDOW (manager->priv->preferences_dialog)); - } else { - g_signal_handlers_disconnect_by_func (manager->priv->preferences_dialog, - on_preferences_dialog_response, - manager); - gtk_widget_destroy (GTK_WIDGET (manager->priv->preferences_dialog)); - manager->priv->preferences_dialog = NULL; - } -} - -static void -msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager) -{ - mate_settings_profile_start (NULL); - - if (!manager->priv->status_icon) { - - manager->priv->status_icon = gtk_status_icon_new_from_icon_name ("preferences-desktop-accessibility"); - g_signal_connect (manager->priv->status_icon, - "activate", - G_CALLBACK (on_status_icon_activate), - manager); - } - - mate_settings_profile_end (NULL); -} - -static void -msd_a11y_keyboard_manager_init (MsdA11yKeyboardManager *manager) -{ - manager->priv = MSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE (manager); - -#ifdef HAVE_LIBMATENOTIFY - notify_init ("mate-settings-daemon"); -#endif /* HAVE_LIBMATENOTIFY */ -} - -static void -msd_a11y_keyboard_manager_finalize (GObject *object) -{ - MsdA11yKeyboardManager *a11y_keyboard_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_A11Y_KEYBOARD_MANAGER (object)); - - a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (object); - - g_return_if_fail (a11y_keyboard_manager->priv != NULL); - - G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->finalize (object); -} - -MsdA11yKeyboardManager * -msd_a11y_keyboard_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_A11Y_KEYBOARD_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_A11Y_KEYBOARD_MANAGER (manager_object); -} diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h b/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h deleted file mode 100644 index 1869cf4..0000000 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_A11Y_KEYBOARD_MANAGER_H -#define __MSD_A11Y_KEYBOARD_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_A11Y_KEYBOARD_MANAGER (msd_a11y_keyboard_manager_get_type ()) -#define MSD_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManager)) -#define MSD_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerClass)) -#define MSD_IS_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER)) -#define MSD_IS_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_KEYBOARD_MANAGER)) -#define MSD_A11Y_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerClass)) - -typedef struct MsdA11yKeyboardManagerPrivate MsdA11yKeyboardManagerPrivate; - -typedef struct -{ - GObject parent; - MsdA11yKeyboardManagerPrivate *priv; -} MsdA11yKeyboardManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdA11yKeyboardManagerClass; - -GType msd_a11y_keyboard_manager_get_type (void); - -MsdA11yKeyboardManager *msd_a11y_keyboard_manager_new (void); -gboolean msd_a11y_keyboard_manager_start (MsdA11yKeyboardManager *manager, - GError **error); -void msd_a11y_keyboard_manager_stop (MsdA11yKeyboardManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_A11Y_KEYBOARD_MANAGER_H */ diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c b/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c deleted file mode 100644 index 7eed1c4..0000000 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-a11y-keyboard-plugin.h" -#include "msd-a11y-keyboard-manager.h" - -struct MsdA11yKeyboardPluginPrivate { - MsdA11yKeyboardManager *manager; -}; - -#define MSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdA11yKeyboardPlugin, msd_a11y_keyboard_plugin) - -static void -msd_a11y_keyboard_plugin_init (MsdA11yKeyboardPlugin *plugin) -{ - plugin->priv = MSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdA11yKeyboardPlugin initializing"); - - plugin->priv->manager = msd_a11y_keyboard_manager_new (); -} - -static void -msd_a11y_keyboard_plugin_finalize (GObject *object) -{ - MsdA11yKeyboardPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_A11Y_KEYBOARD_PLUGIN (object)); - - g_debug ("MsdA11yKeyboardPlugin finalizing"); - - plugin = MSD_A11Y_KEYBOARD_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_a11y_keyboard_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating a11y_keyboard plugin"); - - error = NULL; - res = msd_a11y_keyboard_manager_start (MSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start a11y_keyboard manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating a11y_keyboard plugin"); - msd_a11y_keyboard_manager_stop (MSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager); -} - -static void -msd_a11y_keyboard_plugin_class_init (MsdA11yKeyboardPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_a11y_keyboard_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdA11yKeyboardPluginPrivate)); -} diff --git a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h b/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h deleted file mode 100644 index f4b8320..0000000 --- a/plugins/a11y-keyboard/gsd-a11y-keyboard-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_A11Y_KEYBOARD_PLUGIN_H__ -#define __MSD_A11Y_KEYBOARD_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_A11Y_KEYBOARD_PLUGIN (msd_a11y_keyboard_plugin_get_type ()) -#define MSD_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPlugin)) -#define MSD_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginClass)) -#define MSD_IS_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN)) -#define MSD_IS_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_KEYBOARD_PLUGIN)) -#define MSD_A11Y_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginClass)) - -typedef struct MsdA11yKeyboardPluginPrivate MsdA11yKeyboardPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdA11yKeyboardPluginPrivate *priv; -} MsdA11yKeyboardPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdA11yKeyboardPluginClass; - -GType msd_a11y_keyboard_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_A11Y_KEYBOARD_PLUGIN_H__ */ diff --git a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c deleted file mode 100644 index a5db11c..0000000 --- a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.c +++ /dev/null @@ -1,975 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include - -#include "msd-a11y-preferences-dialog.h" - -#define SM_DBUS_NAME "org.mate.SessionManager" -#define SM_DBUS_PATH "/org/mate/SessionManager" -#define SM_DBUS_INTERFACE "org.mate.SessionManager" - - -#define MSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogPrivate)) - -#define GTKBUILDER_UI_FILE "msd-a11y-preferences-dialog.ui" - -#define KEY_A11Y_DIR "/desktop/mate/accessibility" -#define KEY_STICKY_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/stickykeys_enable" -#define KEY_BOUNCE_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/bouncekeys_enable" -#define KEY_SLOW_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/slowkeys_enable" -#define KEY_MOUSE_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/mousekeys_enable" - -#define KEY_AT_DIR "/desktop/mate/applications/at" -#define KEY_AT_SCREEN_KEYBOARD_ENABLED KEY_AT_DIR "/screen_keyboard_enabled" -#define KEY_AT_SCREEN_MAGNIFIER_ENABLED KEY_AT_DIR "/screen_magnifier_enabled" -#define KEY_AT_SCREEN_READER_ENABLED KEY_AT_DIR "/screen_reader_enabled" - -#define FONT_RENDER_DIR "/desktop/mate/font_rendering" -#define KEY_FONT_DPI FONT_RENDER_DIR "/dpi" -/* X servers sometimes lie about the screen's physical dimensions, so we cannot - * compute an accurate DPI value. When this happens, the user gets fonts that - * are too huge or too tiny. So, we see what the server returns: if it reports - * something outside of the range [DPI_LOW_REASONABLE_VALUE, - * DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use - * DPI_FALLBACK instead. - * - * See get_dpi_from_mateconf_or_server() below, and also - * https://bugzilla.novell.com/show_bug.cgi?id=217790 - */ -#define DPI_LOW_REASONABLE_VALUE 50 -#define DPI_HIGH_REASONABLE_VALUE 500 - -#define DPI_FACTOR_LARGE 1.25 -#define DPI_FACTOR_LARGER 1.5 -#define DPI_FACTOR_LARGEST 2.0 -#define DPI_DEFAULT 96 - -#define KEY_GTK_THEME "/desktop/mate/interface/gtk_theme" -#define KEY_COLOR_SCHEME "/desktop/mate/interface/gtk_color_scheme" -#define KEY_MARCO_THEME "/apps/marco/general/theme" -#define KEY_ICON_THEME "/desktop/mate/interface/icon_theme" - -#define HIGH_CONTRAST_THEME "HighContrast" - -struct MsdA11yPreferencesDialogPrivate -{ - GtkWidget *sticky_keys_checkbutton; - GtkWidget *slow_keys_checkbutton; - GtkWidget *bounce_keys_checkbutton; - - GtkWidget *large_print_checkbutton; - GtkWidget *high_contrast_checkbutton; - - GtkWidget *screen_reader_checkbutton; - GtkWidget *screen_keyboard_checkbutton; - GtkWidget *screen_magnifier_checkbutton; - - guint a11y_dir_cnxn; - guint msd_a11y_dir_cnxn; -}; - -enum { - PROP_0, -}; - -static void msd_a11y_preferences_dialog_class_init (MsdA11yPreferencesDialogClass *klass); -static void msd_a11y_preferences_dialog_init (MsdA11yPreferencesDialog *a11y_preferences_dialog); -static void msd_a11y_preferences_dialog_finalize (GObject *object); - -G_DEFINE_TYPE (MsdA11yPreferencesDialog, msd_a11y_preferences_dialog, GTK_TYPE_DIALOG) - -static void -msd_a11y_preferences_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_a11y_preferences_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_a11y_preferences_dialog_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdA11yPreferencesDialog *a11y_preferences_dialog; - - a11y_preferences_dialog = MSD_A11Y_PREFERENCES_DIALOG (G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (a11y_preferences_dialog); -} - -static void -msd_a11y_preferences_dialog_dispose (GObject *object) -{ - G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->dispose (object); -} - -static void -msd_a11y_preferences_dialog_class_init (MsdA11yPreferencesDialogClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_a11y_preferences_dialog_get_property; - object_class->set_property = msd_a11y_preferences_dialog_set_property; - object_class->constructor = msd_a11y_preferences_dialog_constructor; - object_class->dispose = msd_a11y_preferences_dialog_dispose; - object_class->finalize = msd_a11y_preferences_dialog_finalize; - - g_type_class_add_private (klass, sizeof (MsdA11yPreferencesDialogPrivate)); -} - -static void -on_response (MsdA11yPreferencesDialog *dialog, - gint response_id) -{ - switch (response_id) { - default: - break; - } -} - -static char * -config_get_string (const char *key, - gboolean *is_writable) -{ - char *str; - MateConfClient *client; - - client = mateconf_client_get_default (); - - if (is_writable) { - *is_writable = mateconf_client_key_is_writable (client, - key, - NULL); - } - - str = mateconf_client_get_string (client, key, NULL); - - g_object_unref (client); - - return str; -} - -static gboolean -config_get_bool (const char *key, - gboolean *is_writable) -{ - int enabled; - MateConfClient *client; - - client = mateconf_client_get_default (); - - if (is_writable) { - *is_writable = mateconf_client_key_is_writable (client, - key, - NULL); - } - - enabled = mateconf_client_get_bool (client, key, NULL); - - g_object_unref (client); - - return enabled; -} - -static double -dpi_from_pixels_and_mm (int pixels, - int mm) -{ - double dpi; - - if (mm >= 1) { - dpi = pixels / (mm / 25.4); - } else { - dpi = 0; - } - - return dpi; -} - -static double -get_dpi_from_x_server (void) -{ - GdkScreen *screen; - double dpi; - - screen = gdk_screen_get_default (); - if (screen != NULL) { - double width_dpi; - double height_dpi; - - width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen), - gdk_screen_get_width_mm (screen)); - height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen), - gdk_screen_get_height_mm (screen)); - if (width_dpi < DPI_LOW_REASONABLE_VALUE - || width_dpi > DPI_HIGH_REASONABLE_VALUE - || height_dpi < DPI_LOW_REASONABLE_VALUE - || height_dpi > DPI_HIGH_REASONABLE_VALUE) { - dpi = DPI_DEFAULT; - } else { - dpi = (width_dpi + height_dpi) / 2.0; - } - } else { - /* Huh!? No screen? */ - dpi = DPI_DEFAULT; - } - - return dpi; -} - -static gboolean -config_get_large_print (gboolean *is_writable) -{ - gboolean ret; - MateConfClient *client; - MateConfValue *value; - gdouble x_dpi; - gdouble u_dpi; - - client = mateconf_client_get_default (); - value = mateconf_client_get_without_default (client, KEY_FONT_DPI, NULL); - - if (value != NULL) { - u_dpi = mateconf_value_get_float (value); - mateconf_value_free (value); - } else { - u_dpi = DPI_DEFAULT; - } - - x_dpi = get_dpi_from_x_server (); - - g_object_unref (client); - - g_debug ("MsdA11yPreferences: got x-dpi=%f user-dpi=%f", x_dpi, u_dpi); - - ret = (((double)DPI_FACTOR_LARGE * x_dpi) < u_dpi); - - return ret; -} - -static void -config_set_large_print (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - - if (enabled) { - gdouble x_dpi; - gdouble u_dpi; - - x_dpi = get_dpi_from_x_server (); - u_dpi = (double)DPI_FACTOR_LARGER * x_dpi; - - g_debug ("MsdA11yPreferences: setting x-dpi=%f user-dpi=%f", x_dpi, u_dpi); - - mateconf_client_set_float (client, KEY_FONT_DPI, u_dpi, NULL); - } else { - mateconf_client_unset (client, KEY_FONT_DPI, NULL); - } - - g_object_unref (client); -} - -static gboolean -config_get_high_contrast (gboolean *is_writable) -{ - gboolean ret; - char *gtk_theme; - - ret = FALSE; - - gtk_theme = config_get_string (KEY_GTK_THEME, is_writable); - if (gtk_theme != NULL && strcmp (gtk_theme, HIGH_CONTRAST_THEME) == 0) { - ret = TRUE; - } - g_free (gtk_theme); - - return ret; -} - -static void -config_set_high_contrast (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - - if (enabled) { - mateconf_client_set_string (client, KEY_GTK_THEME, HIGH_CONTRAST_THEME, NULL); - mateconf_client_set_string (client, KEY_ICON_THEME, HIGH_CONTRAST_THEME, NULL); - /* there isn't a high contrast marco theme afaik */ - } else { - mateconf_client_unset (client, KEY_GTK_THEME, NULL); - mateconf_client_unset (client, KEY_ICON_THEME, NULL); - mateconf_client_unset (client, KEY_MARCO_THEME, NULL); - } - - g_object_unref (client); -} - -static gboolean -config_get_sticky_keys (gboolean *is_writable) -{ - return config_get_bool (KEY_STICKY_KEYS_ENABLED, is_writable); -} - -static void -config_set_sticky_keys (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_STICKY_KEYS_ENABLED, enabled, NULL); - g_object_unref (client); -} - -static gboolean -config_get_bounce_keys (gboolean *is_writable) -{ - return config_get_bool (KEY_BOUNCE_KEYS_ENABLED, is_writable); -} - -static void -config_set_bounce_keys (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_BOUNCE_KEYS_ENABLED, enabled, NULL); - g_object_unref (client); -} - -static gboolean -config_get_slow_keys (gboolean *is_writable) -{ - return config_get_bool (KEY_SLOW_KEYS_ENABLED, is_writable); -} - -static void -config_set_slow_keys (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_SLOW_KEYS_ENABLED, enabled, NULL); - g_object_unref (client); -} - -static gboolean -config_have_at_mateconf_condition (const char *condition) -{ - DBusGProxy *sm_proxy; - DBusGConnection *connection; - GError *error; - gboolean res; - gboolean is_handled; - - error = NULL; - connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (connection == NULL) { - g_warning ("Unable to connect to session bus: %s", error->message); - return FALSE; - } - sm_proxy = dbus_g_proxy_new_for_name (connection, - SM_DBUS_NAME, - SM_DBUS_PATH, - SM_DBUS_INTERFACE); - if (sm_proxy == NULL) { - return FALSE; - } - - is_handled = FALSE; - res = dbus_g_proxy_call (sm_proxy, - "IsAutostartConditionHandled", - &error, - G_TYPE_STRING, condition, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, &is_handled, - G_TYPE_INVALID); - if (! res) { - g_warning ("Unable to call IsAutostartConditionHandled (%s): %s", - condition, - error->message); - } - - g_object_unref (sm_proxy); - - return is_handled; -} - -static gboolean -config_get_at_screen_reader (gboolean *is_writable) -{ - return config_get_bool (KEY_AT_SCREEN_READER_ENABLED, is_writable); -} - -static gboolean -config_get_at_screen_keyboard (gboolean *is_writable) -{ - return config_get_bool (KEY_AT_SCREEN_KEYBOARD_ENABLED, is_writable); -} - -static gboolean -config_get_at_screen_magnifier (gboolean *is_writable) -{ - return config_get_bool (KEY_AT_SCREEN_MAGNIFIER_ENABLED, is_writable); -} - -static void -config_set_at_screen_reader (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_AT_SCREEN_READER_ENABLED, enabled, NULL); - g_object_unref (client); -} - -static void -config_set_at_screen_keyboard (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_AT_SCREEN_KEYBOARD_ENABLED, enabled, NULL); - g_object_unref (client); -} - -static void -config_set_at_screen_magnifier (gboolean enabled) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_AT_SCREEN_MAGNIFIER_ENABLED, enabled, NULL); - g_object_unref (client); -} - -static void -on_sticky_keys_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_sticky_keys (gtk_toggle_button_get_active (button)); -} - -static void -on_bounce_keys_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_bounce_keys (gtk_toggle_button_get_active (button)); -} - -static void -on_slow_keys_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_slow_keys (gtk_toggle_button_get_active (button)); -} - -static void -on_high_contrast_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_high_contrast (gtk_toggle_button_get_active (button)); -} - -static void -on_at_screen_reader_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_at_screen_reader (gtk_toggle_button_get_active (button)); -} - -static void -on_at_screen_keyboard_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_at_screen_keyboard (gtk_toggle_button_get_active (button)); -} - -static void -on_at_screen_magnifier_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_at_screen_magnifier (gtk_toggle_button_get_active (button)); -} - -static void -on_large_print_checkbutton_toggled (GtkToggleButton *button, - MsdA11yPreferencesDialog *dialog) -{ - config_set_large_print (gtk_toggle_button_get_active (button)); -} - -static void -ui_set_sticky_keys (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->sticky_keys_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->sticky_keys_checkbutton), enabled); - } -} - -static void -ui_set_bounce_keys (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->bounce_keys_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->bounce_keys_checkbutton), enabled); - } -} - -static void -ui_set_slow_keys (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->slow_keys_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->slow_keys_checkbutton), enabled); - } -} - -static void -ui_set_high_contrast (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->high_contrast_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->high_contrast_checkbutton), enabled); - } -} - -static void -ui_set_at_screen_reader (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_reader_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_reader_checkbutton), enabled); - } -} - -static void -ui_set_at_screen_keyboard (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_keyboard_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_keyboard_checkbutton), enabled); - } -} - -static void -ui_set_at_screen_magnifier (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_magnifier_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_magnifier_checkbutton), enabled); - } -} - -static void -ui_set_large_print (MsdA11yPreferencesDialog *dialog, - gboolean enabled) -{ - gboolean active; - - active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->large_print_checkbutton)); - if (active != enabled) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->large_print_checkbutton), enabled); - } -} - -static void -key_changed_cb (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdA11yPreferencesDialog *dialog) -{ - const char *key; - MateConfValue *value; - - key = mateconf_entry_get_key (entry); - value = mateconf_entry_get_value (entry); - - if (strcmp (key, KEY_STICKY_KEYS_ENABLED) == 0) { - if (value->type == MATECONF_VALUE_BOOL) { - gboolean enabled; - - enabled = mateconf_value_get_bool (value); - ui_set_sticky_keys (dialog, enabled); - } else { - g_warning ("Error retrieving configuration key '%s': Invalid type", - key); - } - } else if (strcmp (key, KEY_BOUNCE_KEYS_ENABLED) == 0) { - if (value->type == MATECONF_VALUE_BOOL) { - gboolean enabled; - - enabled = mateconf_value_get_bool (value); - ui_set_bounce_keys (dialog, enabled); - } else { - g_warning ("Error retrieving configuration key '%s': Invalid type", - key); - } - } else if (strcmp (key, KEY_SLOW_KEYS_ENABLED) == 0) { - if (value->type == MATECONF_VALUE_BOOL) { - gboolean enabled; - - enabled = mateconf_value_get_bool (value); - ui_set_slow_keys (dialog, enabled); - } else { - g_warning ("Error retrieving configuration key '%s': Invalid type", - key); - } - } else if (strcmp (key, KEY_AT_SCREEN_READER_ENABLED) == 0) { - if (value->type == MATECONF_VALUE_BOOL) { - gboolean enabled; - - enabled = mateconf_value_get_bool (value); - ui_set_at_screen_reader (dialog, enabled); - } else { - g_warning ("Error retrieving configuration key '%s': Invalid type", - key); - } - } else if (strcmp (key, KEY_AT_SCREEN_KEYBOARD_ENABLED) == 0) { - if (value->type == MATECONF_VALUE_BOOL) { - gboolean enabled; - - enabled = mateconf_value_get_bool (value); - ui_set_at_screen_keyboard (dialog, enabled); - } else { - g_warning ("Error retrieving configuration key '%s': Invalid type", - key); - } - } else if (strcmp (key, KEY_AT_SCREEN_MAGNIFIER_ENABLED) == 0) { - if (value->type == MATECONF_VALUE_BOOL) { - gboolean enabled; - - enabled = mateconf_value_get_bool (value); - ui_set_at_screen_magnifier (dialog, enabled); - } else { - g_warning ("Error retrieving configuration key '%s': Invalid type", - key); - } - } else { - g_debug ("Config key not handled: %s", key); - } -} - -static void -setup_dialog (MsdA11yPreferencesDialog *dialog, - GtkBuilder *builder) -{ - GtkWidget *widget; - gboolean enabled; - gboolean is_writable; - MateConfClient *client; - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "sticky_keys_checkbutton")); - dialog->priv->sticky_keys_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_sticky_keys_checkbutton_toggled), - NULL); - enabled = config_get_sticky_keys (&is_writable); - ui_set_sticky_keys (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "bounce_keys_checkbutton")); - dialog->priv->bounce_keys_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_bounce_keys_checkbutton_toggled), - NULL); - enabled = config_get_bounce_keys (&is_writable); - ui_set_bounce_keys (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "slow_keys_checkbutton")); - dialog->priv->slow_keys_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_slow_keys_checkbutton_toggled), - NULL); - enabled = config_get_slow_keys (&is_writable); - ui_set_slow_keys (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "high_contrast_checkbutton")); - dialog->priv->high_contrast_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_high_contrast_checkbutton_toggled), - NULL); - enabled = config_get_high_contrast (&is_writable); - ui_set_high_contrast (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "at_screen_keyboard_checkbutton")); - dialog->priv->screen_keyboard_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_at_screen_keyboard_checkbutton_toggled), - NULL); - enabled = config_get_at_screen_keyboard (&is_writable); - ui_set_at_screen_keyboard (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - gtk_widget_set_no_show_all (widget, TRUE); - if (config_have_at_mateconf_condition ("MATE " KEY_AT_SCREEN_KEYBOARD_ENABLED)) { - gtk_widget_show_all (widget); - } else { - gtk_widget_hide (widget); - } - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "at_screen_reader_checkbutton")); - dialog->priv->screen_reader_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_at_screen_reader_checkbutton_toggled), - NULL); - enabled = config_get_at_screen_reader (&is_writable); - ui_set_at_screen_reader (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - gtk_widget_set_no_show_all (widget, TRUE); - if (config_have_at_mateconf_condition ("MATE " KEY_AT_SCREEN_READER_ENABLED)) { - gtk_widget_show_all (widget); - } else { - gtk_widget_hide (widget); - } - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "at_screen_magnifier_checkbutton")); - dialog->priv->screen_magnifier_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_at_screen_magnifier_checkbutton_toggled), - NULL); - enabled = config_get_at_screen_magnifier (&is_writable); - ui_set_at_screen_magnifier (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - gtk_widget_set_no_show_all (widget, TRUE); - if (config_have_at_mateconf_condition ("MATE " KEY_AT_SCREEN_MAGNIFIER_ENABLED)) { - gtk_widget_show_all (widget); - } else { - gtk_widget_hide (widget); - } - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "large_print_checkbutton")); - dialog->priv->large_print_checkbutton = widget; - g_signal_connect (widget, - "toggled", - G_CALLBACK (on_large_print_checkbutton_toggled), - NULL); - enabled = config_get_large_print (&is_writable); - ui_set_large_print (dialog, enabled); - if (! is_writable) { - gtk_widget_set_sensitive (widget, FALSE); - } - - - client = mateconf_client_get_default (); - mateconf_client_add_dir (client, - KEY_A11Y_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - dialog->priv->a11y_dir_cnxn = mateconf_client_notify_add (client, - KEY_A11Y_DIR, - (MateConfClientNotifyFunc)key_changed_cb, - dialog, - NULL, - NULL); - - mateconf_client_add_dir (client, - KEY_AT_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - dialog->priv->msd_a11y_dir_cnxn = mateconf_client_notify_add (client, - KEY_AT_DIR, - (MateConfClientNotifyFunc)key_changed_cb, - dialog, - NULL, - NULL); - - g_object_unref (client); -} - -static void -msd_a11y_preferences_dialog_init (MsdA11yPreferencesDialog *dialog) -{ - static const gchar *ui_file_path = GTKBUILDERDIR "/" GTKBUILDER_UI_FILE; - gchar *objects[] = {"main_box", NULL}; - GError *error = NULL; - GtkBuilder *builder; - - dialog->priv = MSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE (dialog); - - builder = gtk_builder_new (); - gtk_builder_set_translation_domain (builder, PACKAGE); - if (gtk_builder_add_objects_from_file (builder, ui_file_path, objects, - &error) == 0) { - g_warning ("Could not load A11Y-UI: %s", error->message); - g_error_free (error); - } else { - GtkWidget *widget; - - widget = GTK_WIDGET (gtk_builder_get_object (builder, - "main_box")); - gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), - widget); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - setup_dialog (dialog, builder); - } - - g_object_unref (builder); - - gtk_container_set_border_width (GTK_CONTAINER (dialog), 12); - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_title (GTK_WINDOW (dialog), _("Universal Access Preferences")); - gtk_window_set_icon_name (GTK_WINDOW (dialog), "preferences-desktop-accessibility"); - g_object_set (dialog, - "allow-shrink", FALSE, - "allow-grow", FALSE, - NULL); - - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); - g_signal_connect (dialog, - "response", - G_CALLBACK (on_response), - dialog); - - - gtk_widget_show_all (GTK_WIDGET (dialog)); -} - -static void -msd_a11y_preferences_dialog_finalize (GObject *object) -{ - MsdA11yPreferencesDialog *dialog; - MateConfClient *client; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_A11Y_PREFERENCES_DIALOG (object)); - - dialog = MSD_A11Y_PREFERENCES_DIALOG (object); - - g_return_if_fail (dialog->priv != NULL); - - client = mateconf_client_get_default (); - - if (dialog->priv->a11y_dir_cnxn > 0) { - mateconf_client_notify_remove (client, dialog->priv->a11y_dir_cnxn); - } - if (dialog->priv->msd_a11y_dir_cnxn > 0) { - mateconf_client_notify_remove (client, dialog->priv->msd_a11y_dir_cnxn); - } - - g_object_unref (client); - - G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->finalize (object); -} - -GtkWidget * -msd_a11y_preferences_dialog_new (void) -{ - GObject *object; - - object = g_object_new (MSD_TYPE_A11Y_PREFERENCES_DIALOG, - NULL); - - return GTK_WIDGET (object); -} diff --git a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h deleted file mode 100644 index 967a94e..0000000 --- a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_A11Y_PREFERENCES_DIALOG_H -#define __MSD_A11Y_PREFERENCES_DIALOG_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_A11Y_PREFERENCES_DIALOG (msd_a11y_preferences_dialog_get_type ()) -#define MSD_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialog)) -#define MSD_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogClass)) -#define MSD_IS_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG)) -#define MSD_IS_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_PREFERENCES_DIALOG)) -#define MSD_A11Y_PREFERENCES_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogClass)) - -typedef struct MsdA11yPreferencesDialogPrivate MsdA11yPreferencesDialogPrivate; - -typedef struct -{ - GtkDialog parent; - MsdA11yPreferencesDialogPrivate *priv; -} MsdA11yPreferencesDialog; - -typedef struct -{ - GtkDialogClass parent_class; -} MsdA11yPreferencesDialogClass; - -GType msd_a11y_preferences_dialog_get_type (void); - -GtkWidget * msd_a11y_preferences_dialog_new (void); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_A11Y_PREFERENCES_DIALOG_H */ diff --git a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.ui b/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.ui deleted file mode 100644 index 6a0fcb0..0000000 --- a/plugins/a11y-keyboard/gsd-a11y-preferences-dialog.ui +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 - Universal Access Preferences - center-on-parent - preferences-desktop-accessibility - dialog - False - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 2 - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 - 10 - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - preferences-desktop-accessibility - 6 - - - 0 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 - 6 - - - Use on-screen _keyboard - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 0 - - - - - Use screen _reader - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 1 - - - - - Use screen _magnifier - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 2 - - - - - Enhance _contrast in colors - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 3 - - - - - Make _text larger and easier to read - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 4 - - - - - _Press keyboard shortcuts one key at a time (Sticky Keys) - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 5 - - - - - _Ignore duplicate keypresses (Bounce Keys) - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 6 - - - - - Press and _hold keys to accept them (Slow Keys) - True - True - False - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - True - - - 7 - - - - - False - False - 1 - - - - - 1 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - end - - - gtk-close - True - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True - - - False - False - 0 - - - - - False - end - 0 - - - - - - button1 - - - diff --git a/plugins/a11y-keyboard/msd-a11y-keyboard-manager.c b/plugins/a11y-keyboard/msd-a11y-keyboard-manager.c new file mode 100644 index 0000000..7505b14 --- /dev/null +++ b/plugins/a11y-keyboard/msd-a11y-keyboard-manager.c @@ -0,0 +1,1347 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright © 2001 Ximian, Inc. + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +#include +#include +#endif + +#ifdef HAVE_LIBMATENOTIFY +#include +#endif /* HAVE_LIBMATENOTIFY */ + +#include "mate-settings-profile.h" +#include "msd-a11y-keyboard-manager.h" +#include "msd-a11y-preferences-dialog.h" + +#define CONFIG_ROOT "/desktop/mate/accessibility/keyboard" +#define NOTIFICATION_TIMEOUT 30 + +#define MSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerPrivate)) + +struct MsdA11yKeyboardManagerPrivate +{ + int xkbEventBase; + gboolean stickykeys_shortcut_val; + gboolean slowkeys_shortcut_val; + GtkWidget *stickykeys_alert; + GtkWidget *slowkeys_alert; + GtkWidget *preferences_dialog; + GtkStatusIcon *status_icon; + XkbDescRec *original_xkb_desc; + + guint mateconf_notify; + +#ifdef HAVE_LIBMATENOTIFY + NotifyNotification *notification; +#endif /* HAVE_LIBMATENOTIFY */ +}; + +static void msd_a11y_keyboard_manager_class_init (MsdA11yKeyboardManagerClass *klass); +static void msd_a11y_keyboard_manager_init (MsdA11yKeyboardManager *a11y_keyboard_manager); +static void msd_a11y_keyboard_manager_finalize (GObject *object); +static void msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager); +static void set_server_from_mateconf (MsdA11yKeyboardManager *manager, + MateConfClient *client); + +G_DEFINE_TYPE (MsdA11yKeyboardManager, msd_a11y_keyboard_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +#undef DEBUG_ACCESSIBILITY +#ifdef DEBUG_ACCESSIBILITY +#define d(str) g_debug (str) +#else +#define d(str) do { } while (0) +#endif + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +static GdkFilterReturn +devicepresence_filter (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) +{ + XEvent *xev = (XEvent *) xevent; + XEventClass class_presence; + int xi_presence; + + DevicePresence (gdk_x11_get_default_xdisplay (), xi_presence, class_presence); + + if (xev->type == xi_presence) + { + XDevicePresenceNotifyEvent *dpn = (XDevicePresenceNotifyEvent *) xev; + if (dpn->devchange == DeviceEnabled) { + MateConfClient *client; + client = mateconf_client_get_default (); + set_server_from_mateconf (data, client); + g_object_unref (client); + } + } + return GDK_FILTER_CONTINUE; +} + +static gboolean +supports_xinput_devices (void) +{ + gint op_code, event, error; + + return XQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + "XInputExtension", + &op_code, + &event, + &error); +} + +static void +set_devicepresence_handler (MsdA11yKeyboardManager *manager) +{ + Display *display; + XEventClass class_presence; + int xi_presence; + + if (!supports_xinput_devices ()) + return; + + display = gdk_x11_get_default_xdisplay (); + + gdk_error_trap_push (); + DevicePresence (display, xi_presence, class_presence); + /* FIXME: + * Note that this might overwrite other events, see: + * https://bugzilla.gnome.org/show_bug.cgi?id=610245#c2 + **/ + XSelectExtensionEvent (display, + RootWindow (display, DefaultScreen (display)), + &class_presence, 1); + + gdk_flush (); + if (!gdk_error_trap_pop ()) + gdk_window_add_filter (NULL, devicepresence_filter, manager); +} +#endif + +static gboolean +xkb_enabled (MsdA11yKeyboardManager *manager) +{ + gboolean have_xkb; + int opcode, errorBase, major, minor; + + have_xkb = XkbQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + &opcode, + &manager->priv->xkbEventBase, + &errorBase, + &major, + &minor) + && XkbUseExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &major, &minor); + + return have_xkb; +} + +static XkbDescRec * +get_xkb_desc_rec (MsdA11yKeyboardManager *manager) +{ + XkbDescRec *desc; + Status status = Success; + + gdk_error_trap_push (); + desc = XkbGetMap (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XkbAllMapComponentsMask, XkbUseCoreKbd); + if (desc != NULL) { + desc->ctrls = NULL; + status = XkbGetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XkbAllControlsMask, desc); + } + gdk_error_trap_pop (); + + g_return_val_if_fail (desc != NULL, NULL); + g_return_val_if_fail (desc->ctrls != NULL, NULL); + g_return_val_if_fail (status == Success, NULL); + + return desc; +} + +static int +get_int (MateConfClient *client, + char const *key) +{ + int res = mateconf_client_get_int (client, key, NULL); + if (res <= 0) { + res = 1; + } + return res; +} + +static gboolean +set_int (MateConfClient *client, + MateConfChangeSet *cs, + char const *key, + int val) +{ + mateconf_change_set_set_int (cs, key, val); +#ifdef DEBUG_ACCESSIBILITY + if (val != mateconf_client_get_int (client, key, NULL)) { + g_warning ("%s changed", key); + } +#endif + return val != mateconf_client_get_int (client, key, NULL); +} + +static gboolean +set_bool (MateConfClient *client, + MateConfChangeSet *cs, + char const *key, + int val) +{ + gboolean bval = (val != 0); + + mateconf_change_set_set_bool (cs, key, bval ? TRUE : FALSE); +#ifdef DEBUG_ACCESSIBILITY + if (bval != mateconf_client_get_bool (client, key, NULL)) { + d ("%s changed", key); + return TRUE; + } +#endif + return (bval != mateconf_client_get_bool (client, key, NULL)); +} + +static unsigned long +set_clear (gboolean flag, + unsigned long value, + unsigned long mask) +{ + if (flag) { + return value | mask; + } + return value & ~mask; +} + +static gboolean +set_ctrl_from_mateconf (XkbDescRec *desc, + MateConfClient *client, + char const *key, + unsigned long mask) +{ + gboolean result = mateconf_client_get_bool (client, key, NULL); + desc->ctrls->enabled_ctrls = set_clear (result, desc->ctrls->enabled_ctrls, mask); + return result; +} + +static void +set_server_from_mateconf (MsdA11yKeyboardManager *manager, + MateConfClient *client) +{ + XkbDescRec *desc; + gboolean enable_accessX; + + mate_settings_profile_start (NULL); + + desc = get_xkb_desc_rec (manager); + if (!desc) { + return; + } + + /* general */ + enable_accessX = mateconf_client_get_bool (client, CONFIG_ROOT "/enable", NULL); + + desc->ctrls->enabled_ctrls = set_clear (enable_accessX, + desc->ctrls->enabled_ctrls, + XkbAccessXKeysMask); + + if (set_ctrl_from_mateconf (desc, client, CONFIG_ROOT "/timeout_enable", + XkbAccessXTimeoutMask)) { + desc->ctrls->ax_timeout = get_int (client, + CONFIG_ROOT "/timeout"); + /* disable only the master flag via the server we will disable + * the rest on the rebound without affecting mateconf state + * don't change the option flags at all. + */ + desc->ctrls->axt_ctrls_mask = XkbAccessXKeysMask | XkbAccessXFeedbackMask; + desc->ctrls->axt_ctrls_values = 0; + desc->ctrls->axt_opts_mask = 0; + } + + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/feature_state_change_beep", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask); + + /* bounce keys */ + if (set_ctrl_from_mateconf (desc, + client, + CONFIG_ROOT "/bouncekeys_enable", + XkbBounceKeysMask)) { + desc->ctrls->debounce_delay = get_int (client, + CONFIG_ROOT "/bouncekeys_delay"); + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/bouncekeys_beep_reject", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_BKRejectFBMask); + } + + /* mouse keys */ + if (set_ctrl_from_mateconf (desc, + client, + CONFIG_ROOT "/mousekeys_enable", + XkbMouseKeysMask | XkbMouseKeysAccelMask)) { + desc->ctrls->mk_interval = 100; /* msec between mousekey events */ + desc->ctrls->mk_curve = 50; + + /* We store pixels / sec, XKB wants pixels / event */ + desc->ctrls->mk_max_speed = get_int (client, + CONFIG_ROOT "/mousekeys_max_speed") / (1000 / desc->ctrls->mk_interval); + if (desc->ctrls->mk_max_speed <= 0) + desc->ctrls->mk_max_speed = 1; + + desc->ctrls->mk_time_to_max = get_int (client, /* events before max */ + CONFIG_ROOT "/mousekeys_accel_time") / desc->ctrls->mk_interval; + if (desc->ctrls->mk_time_to_max <= 0) + desc->ctrls->mk_time_to_max = 1; + + desc->ctrls->mk_delay = get_int (client, /* ms before 1st event */ + CONFIG_ROOT "/mousekeys_init_delay"); + } + + /* slow keys */ + if (set_ctrl_from_mateconf (desc, + client, + CONFIG_ROOT "/slowkeys_enable", + XkbSlowKeysMask)) { + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_press", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_SKPressFBMask); + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_accept", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_SKAcceptFBMask); + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/slowkeys_beep_reject", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_SKRejectFBMask); + desc->ctrls->slow_keys_delay = get_int (client, + CONFIG_ROOT "/slowkeys_delay"); + /* anything larger than 500 seems to loose all keyboard input */ + if (desc->ctrls->slow_keys_delay > 500) + desc->ctrls->slow_keys_delay = 500; + } + + /* sticky keys */ + if (set_ctrl_from_mateconf (desc, + client, + CONFIG_ROOT "/stickykeys_enable", + XkbStickyKeysMask)) { + desc->ctrls->ax_options |= XkbAX_LatchToLockMask; + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/stickykeys_two_key_off", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_TwoKeysMask); + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/stickykeys_modifier_beep", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_StickyKeysFBMask); + } + + /* toggle keys */ + desc->ctrls->ax_options = set_clear (mateconf_client_get_bool (client, CONFIG_ROOT "/togglekeys_enable", NULL), + desc->ctrls->ax_options, + XkbAccessXFeedbackMask | XkbAX_IndicatorFBMask); + + /* + g_debug ("CHANGE to : 0x%x", desc->ctrls->enabled_ctrls); + g_debug ("CHANGE to : 0x%x (2)", desc->ctrls->ax_options); + */ + + gdk_error_trap_push (); + XkbSetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + XkbSlowKeysMask | + XkbBounceKeysMask | + XkbStickyKeysMask | + XkbMouseKeysMask | + XkbMouseKeysAccelMask | + XkbAccessXKeysMask | + XkbAccessXTimeoutMask | + XkbAccessXFeedbackMask | + XkbControlsEnabledMask, + desc); + + XkbFreeKeyboard (desc, XkbAllComponentsMask, True); + + XSync (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), FALSE); + gdk_error_trap_pop (); + + mate_settings_profile_end (NULL); +} + +static gboolean +ax_response_callback (MsdA11yKeyboardManager *manager, + GtkWindow *parent, + gint response_id, + guint revert_controls_mask, + gboolean enabled) +{ + MateConfClient *client; + GdkScreen *screen; + GError *err; + + switch (response_id) { + case GTK_RESPONSE_DELETE_EVENT: + case GTK_RESPONSE_REJECT: + case GTK_RESPONSE_CANCEL: + + client = mateconf_client_get_default (); + + /* we're reverting, so we invert sense of 'enabled' flag */ + d ("cancelling AccessX request"); + if (revert_controls_mask == XkbStickyKeysMask) { + mateconf_client_set_bool (client, + CONFIG_ROOT "/stickykeys_enable", + !enabled, + NULL); + } + else if (revert_controls_mask == XkbSlowKeysMask) { + mateconf_client_set_bool (client, + CONFIG_ROOT "/slowkeys_enable", + !enabled, + NULL); + } + mateconf_client_suggest_sync (client, NULL); + set_server_from_mateconf (manager, client); + + g_object_unref (client); + + break; + + case GTK_RESPONSE_HELP: + if (!parent) + screen = gdk_screen_get_default (); + else + screen = gtk_widget_get_screen (GTK_WIDGET (parent)); + + err = NULL; + if (!gtk_show_uri (screen, + "ghelp:user-guide#goscustaccess-6", + gtk_get_current_event_time(), + &err)) { + GtkWidget *error_dialog = gtk_message_dialog_new (parent, + 0, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("There was an error displaying help: %s"), + err->message); + g_signal_connect (error_dialog, "response", + G_CALLBACK (gtk_widget_destroy), NULL); + gtk_window_set_resizable (GTK_WINDOW (error_dialog), FALSE); + gtk_widget_show (error_dialog); + g_error_free (err); + } + return FALSE; + default: + break; + } + return TRUE; +} + +static void +ax_stickykeys_response (GtkDialog *dialog, + gint response_id, + MsdA11yKeyboardManager *manager) +{ + if (ax_response_callback (manager, GTK_WINDOW (dialog), + response_id, XkbStickyKeysMask, + manager->priv->stickykeys_shortcut_val)) { + gtk_widget_destroy (GTK_WIDGET (dialog)); + } +} + +static void +ax_slowkeys_response (GtkDialog *dialog, + gint response_id, + MsdA11yKeyboardManager *manager) +{ + if (ax_response_callback (manager, GTK_WINDOW (dialog), + response_id, XkbSlowKeysMask, + manager->priv->slowkeys_shortcut_val)) { + gtk_widget_destroy (GTK_WIDGET (dialog)); + } +} + +static void +maybe_show_status_icon (MsdA11yKeyboardManager *manager) +{ + gboolean show; + MateConfClient *client; + + /* for now, show if accessx is enabled */ + client = mateconf_client_get_default (); + show = mateconf_client_get_bool (client, CONFIG_ROOT "/enable", NULL); + g_object_unref (client); + + if (!show && manager->priv->status_icon == NULL) + return; + + msd_a11y_keyboard_manager_ensure_status_icon (manager); + gtk_status_icon_set_visible (manager->priv->status_icon, show); +} + +#ifdef HAVE_LIBMATENOTIFY +static void +on_notification_closed (NotifyNotification *notification, + MsdA11yKeyboardManager *manager) +{ + g_object_unref (manager->priv->notification); + manager->priv->notification = NULL; +} + +static void +on_slow_keys_action (NotifyNotification *notification, + const char *action, + MsdA11yKeyboardManager *manager) +{ + gboolean res; + int response_id; + + g_assert (action != NULL); + + if (strcmp (action, "accept") == 0) { + response_id = GTK_RESPONSE_ACCEPT; + } else if (strcmp (action, "reject") == 0) { + response_id = GTK_RESPONSE_REJECT; + } else { + return; + } + + res = ax_response_callback (manager, NULL, + response_id, XkbSlowKeysMask, + manager->priv->slowkeys_shortcut_val); + if (res) { + notify_notification_close (manager->priv->notification, NULL); + } +} + +static void +on_sticky_keys_action (NotifyNotification *notification, + const char *action, + MsdA11yKeyboardManager *manager) +{ + gboolean res; + int response_id; + + g_assert (action != NULL); + + if (strcmp (action, "accept") == 0) { + response_id = GTK_RESPONSE_ACCEPT; + } else if (strcmp (action, "reject") == 0) { + response_id = GTK_RESPONSE_REJECT; + } else { + return; + } + + res = ax_response_callback (manager, NULL, + response_id, XkbStickyKeysMask, + manager->priv->stickykeys_shortcut_val); + if (res) { + notify_notification_close (manager->priv->notification, NULL); + } +} + +#endif /* HAVE_LIBMATENOTIFY */ + +static gboolean +ax_slowkeys_warning_post_bubble (MsdA11yKeyboardManager *manager, + gboolean enabled) +{ +#ifdef HAVE_LIBMATENOTIFY + gboolean res; + const char *title; + const char *message; + GError *error; + + title = enabled ? + _("Do you want to activate Slow Keys?") : + _("Do you want to deactivate Slow Keys?"); + message = _("You just held down the Shift key for 8 seconds. This is the shortcut " + "for the Slow Keys feature, which affects the way your keyboard works."); + + if (manager->priv->status_icon == NULL || ! gtk_status_icon_is_embedded (manager->priv->status_icon)) { + return FALSE; + } + + if (manager->priv->slowkeys_alert != NULL) { + gtk_widget_destroy (manager->priv->slowkeys_alert); + } + + if (manager->priv->notification != NULL) { + notify_notification_close (manager->priv->notification, NULL); + } + + msd_a11y_keyboard_manager_ensure_status_icon (manager); + manager->priv->notification = notify_notification_new (title, + message, + "preferences-desktop-accessibility", + NULL); + notify_notification_attach_to_status_icon (manager->priv->notification, manager->priv->status_icon); + notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000); + + notify_notification_add_action (manager->priv->notification, + "reject", + enabled ? _("Don't activate") : _("Don't deactivate"), + (NotifyActionCallback) on_slow_keys_action, + manager, + NULL); + notify_notification_add_action (manager->priv->notification, + "accept", + enabled ? _("Activate") : _("Deactivate"), + (NotifyActionCallback) on_slow_keys_action, + manager, + NULL); + + g_signal_connect (manager->priv->notification, + "closed", + G_CALLBACK (on_notification_closed), + manager); + + error = NULL; + res = notify_notification_show (manager->priv->notification, &error); + if (! res) { + g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message); + g_error_free (error); + notify_notification_close (manager->priv->notification, NULL); + } + + return res; +#else + return FALSE; +#endif /* HAVE_LIBMATENOTIFY */ +} + + +static void +ax_slowkeys_warning_post_dialog (MsdA11yKeyboardManager *manager, + gboolean enabled) +{ + const char *title; + const char *message; + + title = enabled ? + _("Do you want to activate Slow Keys?") : + _("Do you want to deactivate Slow Keys?"); + message = _("You just held down the Shift key for 8 seconds. This is the shortcut " + "for the Slow Keys feature, which affects the way your keyboard works."); + + if (manager->priv->slowkeys_alert != NULL) { + gtk_widget_show (manager->priv->slowkeys_alert); + return; + } + + manager->priv->slowkeys_alert = gtk_message_dialog_new (NULL, + 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + "%s", title); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (manager->priv->slowkeys_alert), + "%s", message); + + gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert), + GTK_STOCK_HELP, + GTK_RESPONSE_HELP); + gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert), + enabled ? _("Do_n't activate") : _("Do_n't deactivate"), + GTK_RESPONSE_REJECT); + gtk_dialog_add_button (GTK_DIALOG (manager->priv->slowkeys_alert), + enabled ? _("_Activate") : _("_Deactivate"), + GTK_RESPONSE_ACCEPT); + + gtk_window_set_title (GTK_WINDOW (manager->priv->slowkeys_alert), + _("Slow Keys Alert")); + gtk_window_set_icon_name (GTK_WINDOW (manager->priv->slowkeys_alert), + "input-keyboard"); + gtk_dialog_set_default_response (GTK_DIALOG (manager->priv->slowkeys_alert), + GTK_RESPONSE_ACCEPT); + + g_signal_connect (manager->priv->slowkeys_alert, + "response", + G_CALLBACK (ax_slowkeys_response), + manager); + gtk_widget_show (manager->priv->slowkeys_alert); + + g_object_add_weak_pointer (G_OBJECT (manager->priv->slowkeys_alert), + (gpointer*) &manager->priv->slowkeys_alert); +} + +static void +ax_slowkeys_warning_post (MsdA11yKeyboardManager *manager, + gboolean enabled) +{ + + manager->priv->slowkeys_shortcut_val = enabled; + + /* alway try to show something */ + if (! ax_slowkeys_warning_post_bubble (manager, enabled)) { + ax_slowkeys_warning_post_dialog (manager, enabled); + } +} + +static gboolean +ax_stickykeys_warning_post_bubble (MsdA11yKeyboardManager *manager, + gboolean enabled) +{ +#ifdef HAVE_LIBMATENOTIFY + gboolean res; + const char *title; + const char *message; + GError *error; + + title = enabled ? + _("Do you want to activate Sticky Keys?") : + _("Do you want to deactivate Sticky Keys?"); + message = enabled ? + _("You just pressed the Shift key 5 times in a row. This is the shortcut " + "for the Sticky Keys feature, which affects the way your keyboard works.") : + _("You just pressed two keys at once, or pressed the Shift key 5 times in a row. " + "This turns off the Sticky Keys feature, which affects the way your keyboard works."); + + if (manager->priv->status_icon == NULL || ! gtk_status_icon_is_embedded (manager->priv->status_icon)) { + return FALSE; + } + + if (manager->priv->slowkeys_alert != NULL) { + gtk_widget_destroy (manager->priv->slowkeys_alert); + } + + if (manager->priv->notification != NULL) { + notify_notification_close (manager->priv->notification, NULL); + } + + msd_a11y_keyboard_manager_ensure_status_icon (manager); + manager->priv->notification = notify_notification_new (title, + message, + "preferences-desktop-accessibility", + NULL); + notify_notification_attach_to_status_icon (manager->priv->notification, manager->priv->status_icon); + notify_notification_set_timeout (manager->priv->notification, NOTIFICATION_TIMEOUT * 1000); + + notify_notification_add_action (manager->priv->notification, + "reject", + enabled ? _("Don't activate") : _("Don't deactivate"), + (NotifyActionCallback) on_sticky_keys_action, + manager, + NULL); + notify_notification_add_action (manager->priv->notification, + "accept", + enabled ? _("Activate") : _("Deactivate"), + (NotifyActionCallback) on_sticky_keys_action, + manager, + NULL); + + g_signal_connect (manager->priv->notification, + "closed", + G_CALLBACK (on_notification_closed), + manager); + + error = NULL; + res = notify_notification_show (manager->priv->notification, &error); + if (! res) { + g_warning ("MsdA11yKeyboardManager: unable to show notification: %s", error->message); + g_error_free (error); + notify_notification_close (manager->priv->notification, NULL); + } + + return res; +#else + return FALSE; +#endif /* HAVE_LIBMATENOTIFY */ +} + +static void +ax_stickykeys_warning_post_dialog (MsdA11yKeyboardManager *manager, + gboolean enabled) +{ + const char *title; + const char *message; + + title = enabled ? + _("Do you want to activate Sticky Keys?") : + _("Do you want to deactivate Sticky Keys?"); + message = enabled ? + _("You just pressed the Shift key 5 times in a row. This is the shortcut " + "for the Sticky Keys feature, which affects the way your keyboard works.") : + _("You just pressed two keys at once, or pressed the Shift key 5 times in a row. " + "This turns off the Sticky Keys feature, which affects the way your keyboard works."); + + if (manager->priv->stickykeys_alert != NULL) { + gtk_widget_show (manager->priv->stickykeys_alert); + return; + } + + manager->priv->stickykeys_alert = gtk_message_dialog_new (NULL, + 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + "%s", title); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (manager->priv->stickykeys_alert), + "%s", message); + + gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert), + GTK_STOCK_HELP, + GTK_RESPONSE_HELP); + gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert), + enabled ? _("Do_n't activate") : _("Do_n't deactivate"), + GTK_RESPONSE_REJECT); + gtk_dialog_add_button (GTK_DIALOG (manager->priv->stickykeys_alert), + enabled ? _("_Activate") : _("_Deactivate"), + GTK_RESPONSE_ACCEPT); + + gtk_window_set_title (GTK_WINDOW (manager->priv->stickykeys_alert), + _("Sticky Keys Alert")); + gtk_window_set_icon_name (GTK_WINDOW (manager->priv->stickykeys_alert), + "input-keyboard"); + gtk_dialog_set_default_response (GTK_DIALOG (manager->priv->stickykeys_alert), + GTK_RESPONSE_ACCEPT); + + g_signal_connect (manager->priv->stickykeys_alert, + "response", + G_CALLBACK (ax_stickykeys_response), + manager); + gtk_widget_show (manager->priv->stickykeys_alert); + + g_object_add_weak_pointer (G_OBJECT (manager->priv->stickykeys_alert), + (gpointer*) &manager->priv->stickykeys_alert); +} + +static void +ax_stickykeys_warning_post (MsdA11yKeyboardManager *manager, + gboolean enabled) +{ + + manager->priv->stickykeys_shortcut_val = enabled; + + /* alway try to show something */ + if (! ax_stickykeys_warning_post_bubble (manager, enabled)) { + ax_stickykeys_warning_post_dialog (manager, enabled); + } +} + +static void +set_mateconf_from_server (MsdA11yKeyboardManager *manager) +{ + MateConfClient *client; + MateConfChangeSet *cs; + XkbDescRec *desc; + gboolean changed = FALSE; + gboolean slowkeys_changed; + gboolean stickykeys_changed; + + cs = mateconf_change_set_new (); + desc = get_xkb_desc_rec (manager); + if (! desc) { + return; + } + + client = mateconf_client_get_default (); + + /* + fprintf (stderr, "changed to : 0x%x\n", desc->ctrls->enabled_ctrls); + fprintf (stderr, "changed to : 0x%x (2)\n", desc->ctrls->ax_options); + */ + + changed |= set_bool (client, + cs, + CONFIG_ROOT "/enable", + desc->ctrls->enabled_ctrls & XkbAccessXKeysMask); + + changed |= set_bool (client, + cs, + CONFIG_ROOT "/feature_state_change_beep", + desc->ctrls->ax_options & (XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask)); + changed |= set_bool (client, + cs, + CONFIG_ROOT "/timeout_enable", + desc->ctrls->enabled_ctrls & XkbAccessXTimeoutMask); + changed |= set_int (client, + cs, + CONFIG_ROOT "/timeout", + desc->ctrls->ax_timeout); + + changed |= set_bool (client, + cs, + CONFIG_ROOT "/bouncekeys_enable", + desc->ctrls->enabled_ctrls & XkbBounceKeysMask); + changed |= set_int (client, + cs, + CONFIG_ROOT "/bouncekeys_delay", + desc->ctrls->debounce_delay); + changed |= set_bool (client, + cs, + CONFIG_ROOT "/bouncekeys_beep_reject", + desc->ctrls->ax_options & XkbAX_BKRejectFBMask); + + changed |= set_bool (client, + cs, + CONFIG_ROOT "/mousekeys_enable", + desc->ctrls->enabled_ctrls & XkbMouseKeysMask); + changed |= set_int (client, + cs, + CONFIG_ROOT "/mousekeys_max_speed", + desc->ctrls->mk_max_speed * (1000 / desc->ctrls->mk_interval)); + /* NOTE : mk_time_to_max is measured in events not time */ + changed |= set_int (client, + cs, + CONFIG_ROOT "/mousekeys_accel_time", + desc->ctrls->mk_time_to_max * desc->ctrls->mk_interval); + changed |= set_int (client, + cs, + CONFIG_ROOT "/mousekeys_init_delay", + desc->ctrls->mk_delay); + + slowkeys_changed = set_bool (client, + cs, + CONFIG_ROOT "/slowkeys_enable", + desc->ctrls->enabled_ctrls & XkbSlowKeysMask); + changed |= set_bool (client, + cs, + CONFIG_ROOT "/slowkeys_beep_press", + desc->ctrls->ax_options & XkbAX_SKPressFBMask); + changed |= set_bool (client, + cs, + CONFIG_ROOT "/slowkeys_beep_accept", + desc->ctrls->ax_options & XkbAX_SKAcceptFBMask); + changed |= set_bool (client, + cs, + CONFIG_ROOT "/slowkeys_beep_reject", + desc->ctrls->ax_options & XkbAX_SKRejectFBMask); + changed |= set_int (client, + cs, + CONFIG_ROOT "/slowkeys_delay", + desc->ctrls->slow_keys_delay); + + stickykeys_changed = set_bool (client, + cs, + CONFIG_ROOT "/stickykeys_enable", + desc->ctrls->enabled_ctrls & XkbStickyKeysMask); + changed |= set_bool (client, + cs, + CONFIG_ROOT "/stickykeys_two_key_off", + desc->ctrls->ax_options & XkbAX_TwoKeysMask); + changed |= set_bool (client, + cs, + CONFIG_ROOT "/stickykeys_modifier_beep", + desc->ctrls->ax_options & XkbAX_StickyKeysFBMask); + + changed |= set_bool (client, + cs, + CONFIG_ROOT "/togglekeys_enable", + desc->ctrls->ax_options & XkbAX_IndicatorFBMask); + + if (!changed && stickykeys_changed ^ slowkeys_changed) { + /* + * sticky or slowkeys has changed, singly, without our intervention. + * 99% chance this is due to a keyboard shortcut being used. + * we need to detect via this hack until we get + * XkbAXN_AXKWarning notifications working (probable XKB bug), + * at which time we can directly intercept such shortcuts instead. + * See cb_xkb_event_filter () below. + */ + + /* sanity check: are keyboard shortcuts available? */ + if (desc->ctrls->enabled_ctrls & XkbAccessXKeysMask) { + if (slowkeys_changed) { + ax_slowkeys_warning_post (manager, + desc->ctrls->enabled_ctrls & XkbSlowKeysMask); + } else { + ax_stickykeys_warning_post (manager, + desc->ctrls->enabled_ctrls & XkbStickyKeysMask); + } + } + } + + XkbFreeKeyboard (desc, XkbAllComponentsMask, True); + + changed |= (stickykeys_changed | slowkeys_changed); + + if (changed) { + mateconf_client_commit_change_set (client, cs, FALSE, NULL); + mateconf_client_suggest_sync (client, NULL); + } + mateconf_change_set_unref (cs); + + g_object_unref (client); +} + +static GdkFilterReturn +cb_xkb_event_filter (GdkXEvent *xevent, + GdkEvent *ignored1, + MsdA11yKeyboardManager *manager) +{ + XEvent *xev = (XEvent *) xevent; + XkbEvent *xkbEv = (XkbEvent *) xevent; + + if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) && + xkbEv->any.xkb_type == XkbControlsNotify) { + d ("XKB state changed"); + set_mateconf_from_server (manager); + } else if (xev->xany.type == (manager->priv->xkbEventBase + XkbEventCode) && + xkbEv->any.xkb_type == XkbAccessXNotify) { + if (xkbEv->accessx.detail == XkbAXN_AXKWarning) { + d ("About to turn on an AccessX feature from the keyboard!"); + /* + * TODO: when XkbAXN_AXKWarnings start working, we need to + * invoke ax_keys_warning_dialog_run here instead of in + * set_mateconf_from_server(). + */ + } + } + + return GDK_FILTER_CONTINUE; +} + +static void +keyboard_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdA11yKeyboardManager *manager) +{ + set_server_from_mateconf (manager, client); + maybe_show_status_icon (manager); +} + +static void +register_config_callback (MsdA11yKeyboardManager *manager, + MateConfClient *client, + const char *path, + MateConfClientNotifyFunc func, + guint *notify) +{ + mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + *notify = mateconf_client_notify_add (client, path, func, manager, NULL, NULL); +} + +static gboolean +start_a11y_keyboard_idle_cb (MsdA11yKeyboardManager *manager) +{ + guint event_mask; + MateConfClient *client; + + g_debug ("Starting a11y_keyboard manager"); + mate_settings_profile_start (NULL); + + if (!xkb_enabled (manager)) + goto out; + + client = mateconf_client_get_default (); + + register_config_callback (manager, + client, + CONFIG_ROOT, + (MateConfClientNotifyFunc) keyboard_callback, + &manager->priv->mateconf_notify); + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + set_devicepresence_handler (manager); +#endif + + /* Save current xkb state so we can restore it on exit + */ + manager->priv->original_xkb_desc = get_xkb_desc_rec (manager); + + event_mask = XkbControlsNotifyMask; +#ifdef DEBUG_ACCESSIBILITY + event_mask |= XkbAccessXNotifyMask; /* make default when AXN_AXKWarning works */ +#endif + + /* be sure to init before starting to monitor the server */ + set_server_from_mateconf (manager, client); + g_object_unref (client); + + XkbSelectEvents (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + XkbUseCoreKbd, + event_mask, + event_mask); + + gdk_window_add_filter (NULL, + (GdkFilterFunc) cb_xkb_event_filter, + manager); + + maybe_show_status_icon (manager); + + out: + mate_settings_profile_end (NULL); + + return FALSE; +} + + +gboolean +msd_a11y_keyboard_manager_start (MsdA11yKeyboardManager *manager, + GError **error) +{ + mate_settings_profile_start (NULL); + + g_idle_add ((GSourceFunc) start_a11y_keyboard_idle_cb, manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +static void +restore_server_xkb_config (MsdA11yKeyboardManager *manager) +{ + gdk_error_trap_push (); + XkbSetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + XkbSlowKeysMask | + XkbBounceKeysMask | + XkbStickyKeysMask | + XkbMouseKeysMask | + XkbMouseKeysAccelMask | + XkbAccessXKeysMask | + XkbAccessXTimeoutMask | + XkbAccessXFeedbackMask | + XkbControlsEnabledMask, + manager->priv->original_xkb_desc); + + XkbFreeKeyboard (manager->priv->original_xkb_desc, + XkbAllComponentsMask, True); + + XSync (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), FALSE); + gdk_error_trap_pop (); + + manager->priv->original_xkb_desc = NULL; +} + +void +msd_a11y_keyboard_manager_stop (MsdA11yKeyboardManager *manager) +{ + MsdA11yKeyboardManagerPrivate *p = manager->priv; + + g_debug ("Stopping a11y_keyboard manager"); + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + gdk_window_remove_filter (NULL, devicepresence_filter, manager); +#endif + + if (p->status_icon) + gtk_status_icon_set_visible (p->status_icon, FALSE); + + if (p->mateconf_notify != 0) { + MateConfClient *client = mateconf_client_get_default (); + mateconf_client_remove_dir (client, CONFIG_ROOT, NULL); + mateconf_client_notify_remove (client, p->mateconf_notify); + g_object_unref (client); + p->mateconf_notify = 0; + } + + gdk_window_remove_filter (NULL, + (GdkFilterFunc) cb_xkb_event_filter, + manager); + + /* Disable all the AccessX bits + */ + restore_server_xkb_config (manager); + + if (p->slowkeys_alert != NULL) + gtk_widget_destroy (p->slowkeys_alert); + + if (p->stickykeys_alert != NULL) + gtk_widget_destroy (p->stickykeys_alert); + + p->slowkeys_shortcut_val = FALSE; + p->stickykeys_shortcut_val = FALSE; +} + +static void +msd_a11y_keyboard_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdA11yKeyboardManager *self; + + self = MSD_A11Y_KEYBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_a11y_keyboard_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdA11yKeyboardManager *self; + + self = MSD_A11Y_KEYBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_a11y_keyboard_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdA11yKeyboardManager *a11y_keyboard_manager; + MsdA11yKeyboardManagerClass *klass; + + klass = MSD_A11Y_KEYBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_A11Y_KEYBOARD_MANAGER)); + + a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (a11y_keyboard_manager); +} + +static void +msd_a11y_keyboard_manager_dispose (GObject *object) +{ + MsdA11yKeyboardManager *a11y_keyboard_manager; + + a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (object); + + G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->dispose (object); +} + +static void +msd_a11y_keyboard_manager_class_init (MsdA11yKeyboardManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_a11y_keyboard_manager_get_property; + object_class->set_property = msd_a11y_keyboard_manager_set_property; + object_class->constructor = msd_a11y_keyboard_manager_constructor; + object_class->dispose = msd_a11y_keyboard_manager_dispose; + object_class->finalize = msd_a11y_keyboard_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdA11yKeyboardManagerPrivate)); +} + +static void +on_preferences_dialog_response (GtkDialog *dialog, + int response, + MsdA11yKeyboardManager *manager) +{ + g_signal_handlers_disconnect_by_func (dialog, + on_preferences_dialog_response, + manager); + + gtk_widget_destroy (GTK_WIDGET (dialog)); + manager->priv->preferences_dialog = NULL; +} + +static void +on_status_icon_activate (GtkStatusIcon *status_icon, + MsdA11yKeyboardManager *manager) +{ + if (manager->priv->preferences_dialog == NULL) { + manager->priv->preferences_dialog = msd_a11y_preferences_dialog_new (); + g_signal_connect (manager->priv->preferences_dialog, + "response", + G_CALLBACK (on_preferences_dialog_response), + manager); + + gtk_window_present (GTK_WINDOW (manager->priv->preferences_dialog)); + } else { + g_signal_handlers_disconnect_by_func (manager->priv->preferences_dialog, + on_preferences_dialog_response, + manager); + gtk_widget_destroy (GTK_WIDGET (manager->priv->preferences_dialog)); + manager->priv->preferences_dialog = NULL; + } +} + +static void +msd_a11y_keyboard_manager_ensure_status_icon (MsdA11yKeyboardManager *manager) +{ + mate_settings_profile_start (NULL); + + if (!manager->priv->status_icon) { + + manager->priv->status_icon = gtk_status_icon_new_from_icon_name ("preferences-desktop-accessibility"); + g_signal_connect (manager->priv->status_icon, + "activate", + G_CALLBACK (on_status_icon_activate), + manager); + } + + mate_settings_profile_end (NULL); +} + +static void +msd_a11y_keyboard_manager_init (MsdA11yKeyboardManager *manager) +{ + manager->priv = MSD_A11Y_KEYBOARD_MANAGER_GET_PRIVATE (manager); + +#ifdef HAVE_LIBMATENOTIFY + notify_init ("mate-settings-daemon"); +#endif /* HAVE_LIBMATENOTIFY */ +} + +static void +msd_a11y_keyboard_manager_finalize (GObject *object) +{ + MsdA11yKeyboardManager *a11y_keyboard_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_A11Y_KEYBOARD_MANAGER (object)); + + a11y_keyboard_manager = MSD_A11Y_KEYBOARD_MANAGER (object); + + g_return_if_fail (a11y_keyboard_manager->priv != NULL); + + G_OBJECT_CLASS (msd_a11y_keyboard_manager_parent_class)->finalize (object); +} + +MsdA11yKeyboardManager * +msd_a11y_keyboard_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_A11Y_KEYBOARD_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_A11Y_KEYBOARD_MANAGER (manager_object); +} diff --git a/plugins/a11y-keyboard/msd-a11y-keyboard-manager.h b/plugins/a11y-keyboard/msd-a11y-keyboard-manager.h new file mode 100644 index 0000000..1869cf4 --- /dev/null +++ b/plugins/a11y-keyboard/msd-a11y-keyboard-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_A11Y_KEYBOARD_MANAGER_H +#define __MSD_A11Y_KEYBOARD_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_A11Y_KEYBOARD_MANAGER (msd_a11y_keyboard_manager_get_type ()) +#define MSD_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManager)) +#define MSD_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerClass)) +#define MSD_IS_A11Y_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER)) +#define MSD_IS_A11Y_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_KEYBOARD_MANAGER)) +#define MSD_A11Y_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_KEYBOARD_MANAGER, MsdA11yKeyboardManagerClass)) + +typedef struct MsdA11yKeyboardManagerPrivate MsdA11yKeyboardManagerPrivate; + +typedef struct +{ + GObject parent; + MsdA11yKeyboardManagerPrivate *priv; +} MsdA11yKeyboardManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdA11yKeyboardManagerClass; + +GType msd_a11y_keyboard_manager_get_type (void); + +MsdA11yKeyboardManager *msd_a11y_keyboard_manager_new (void); +gboolean msd_a11y_keyboard_manager_start (MsdA11yKeyboardManager *manager, + GError **error); +void msd_a11y_keyboard_manager_stop (MsdA11yKeyboardManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_A11Y_KEYBOARD_MANAGER_H */ diff --git a/plugins/a11y-keyboard/msd-a11y-keyboard-plugin.c b/plugins/a11y-keyboard/msd-a11y-keyboard-plugin.c new file mode 100644 index 0000000..7eed1c4 --- /dev/null +++ b/plugins/a11y-keyboard/msd-a11y-keyboard-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-a11y-keyboard-plugin.h" +#include "msd-a11y-keyboard-manager.h" + +struct MsdA11yKeyboardPluginPrivate { + MsdA11yKeyboardManager *manager; +}; + +#define MSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdA11yKeyboardPlugin, msd_a11y_keyboard_plugin) + +static void +msd_a11y_keyboard_plugin_init (MsdA11yKeyboardPlugin *plugin) +{ + plugin->priv = MSD_A11Y_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdA11yKeyboardPlugin initializing"); + + plugin->priv->manager = msd_a11y_keyboard_manager_new (); +} + +static void +msd_a11y_keyboard_plugin_finalize (GObject *object) +{ + MsdA11yKeyboardPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_A11Y_KEYBOARD_PLUGIN (object)); + + g_debug ("MsdA11yKeyboardPlugin finalizing"); + + plugin = MSD_A11Y_KEYBOARD_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_a11y_keyboard_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating a11y_keyboard plugin"); + + error = NULL; + res = msd_a11y_keyboard_manager_start (MSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start a11y_keyboard manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating a11y_keyboard plugin"); + msd_a11y_keyboard_manager_stop (MSD_A11Y_KEYBOARD_PLUGIN (plugin)->priv->manager); +} + +static void +msd_a11y_keyboard_plugin_class_init (MsdA11yKeyboardPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_a11y_keyboard_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdA11yKeyboardPluginPrivate)); +} diff --git a/plugins/a11y-keyboard/msd-a11y-keyboard-plugin.h b/plugins/a11y-keyboard/msd-a11y-keyboard-plugin.h new file mode 100644 index 0000000..f4b8320 --- /dev/null +++ b/plugins/a11y-keyboard/msd-a11y-keyboard-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_A11Y_KEYBOARD_PLUGIN_H__ +#define __MSD_A11Y_KEYBOARD_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_A11Y_KEYBOARD_PLUGIN (msd_a11y_keyboard_plugin_get_type ()) +#define MSD_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPlugin)) +#define MSD_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginClass)) +#define MSD_IS_A11Y_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN)) +#define MSD_IS_A11Y_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_KEYBOARD_PLUGIN)) +#define MSD_A11Y_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_KEYBOARD_PLUGIN, MsdA11yKeyboardPluginClass)) + +typedef struct MsdA11yKeyboardPluginPrivate MsdA11yKeyboardPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdA11yKeyboardPluginPrivate *priv; +} MsdA11yKeyboardPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdA11yKeyboardPluginClass; + +GType msd_a11y_keyboard_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_A11Y_KEYBOARD_PLUGIN_H__ */ diff --git a/plugins/a11y-keyboard/msd-a11y-preferences-dialog.c b/plugins/a11y-keyboard/msd-a11y-preferences-dialog.c new file mode 100644 index 0000000..a5db11c --- /dev/null +++ b/plugins/a11y-keyboard/msd-a11y-preferences-dialog.c @@ -0,0 +1,975 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include "msd-a11y-preferences-dialog.h" + +#define SM_DBUS_NAME "org.mate.SessionManager" +#define SM_DBUS_PATH "/org/mate/SessionManager" +#define SM_DBUS_INTERFACE "org.mate.SessionManager" + + +#define MSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogPrivate)) + +#define GTKBUILDER_UI_FILE "msd-a11y-preferences-dialog.ui" + +#define KEY_A11Y_DIR "/desktop/mate/accessibility" +#define KEY_STICKY_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/stickykeys_enable" +#define KEY_BOUNCE_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/bouncekeys_enable" +#define KEY_SLOW_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/slowkeys_enable" +#define KEY_MOUSE_KEYS_ENABLED KEY_A11Y_DIR "/keyboard/mousekeys_enable" + +#define KEY_AT_DIR "/desktop/mate/applications/at" +#define KEY_AT_SCREEN_KEYBOARD_ENABLED KEY_AT_DIR "/screen_keyboard_enabled" +#define KEY_AT_SCREEN_MAGNIFIER_ENABLED KEY_AT_DIR "/screen_magnifier_enabled" +#define KEY_AT_SCREEN_READER_ENABLED KEY_AT_DIR "/screen_reader_enabled" + +#define FONT_RENDER_DIR "/desktop/mate/font_rendering" +#define KEY_FONT_DPI FONT_RENDER_DIR "/dpi" +/* X servers sometimes lie about the screen's physical dimensions, so we cannot + * compute an accurate DPI value. When this happens, the user gets fonts that + * are too huge or too tiny. So, we see what the server returns: if it reports + * something outside of the range [DPI_LOW_REASONABLE_VALUE, + * DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use + * DPI_FALLBACK instead. + * + * See get_dpi_from_mateconf_or_server() below, and also + * https://bugzilla.novell.com/show_bug.cgi?id=217790 + */ +#define DPI_LOW_REASONABLE_VALUE 50 +#define DPI_HIGH_REASONABLE_VALUE 500 + +#define DPI_FACTOR_LARGE 1.25 +#define DPI_FACTOR_LARGER 1.5 +#define DPI_FACTOR_LARGEST 2.0 +#define DPI_DEFAULT 96 + +#define KEY_GTK_THEME "/desktop/mate/interface/gtk_theme" +#define KEY_COLOR_SCHEME "/desktop/mate/interface/gtk_color_scheme" +#define KEY_MARCO_THEME "/apps/marco/general/theme" +#define KEY_ICON_THEME "/desktop/mate/interface/icon_theme" + +#define HIGH_CONTRAST_THEME "HighContrast" + +struct MsdA11yPreferencesDialogPrivate +{ + GtkWidget *sticky_keys_checkbutton; + GtkWidget *slow_keys_checkbutton; + GtkWidget *bounce_keys_checkbutton; + + GtkWidget *large_print_checkbutton; + GtkWidget *high_contrast_checkbutton; + + GtkWidget *screen_reader_checkbutton; + GtkWidget *screen_keyboard_checkbutton; + GtkWidget *screen_magnifier_checkbutton; + + guint a11y_dir_cnxn; + guint msd_a11y_dir_cnxn; +}; + +enum { + PROP_0, +}; + +static void msd_a11y_preferences_dialog_class_init (MsdA11yPreferencesDialogClass *klass); +static void msd_a11y_preferences_dialog_init (MsdA11yPreferencesDialog *a11y_preferences_dialog); +static void msd_a11y_preferences_dialog_finalize (GObject *object); + +G_DEFINE_TYPE (MsdA11yPreferencesDialog, msd_a11y_preferences_dialog, GTK_TYPE_DIALOG) + +static void +msd_a11y_preferences_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_a11y_preferences_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_a11y_preferences_dialog_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdA11yPreferencesDialog *a11y_preferences_dialog; + + a11y_preferences_dialog = MSD_A11Y_PREFERENCES_DIALOG (G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (a11y_preferences_dialog); +} + +static void +msd_a11y_preferences_dialog_dispose (GObject *object) +{ + G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->dispose (object); +} + +static void +msd_a11y_preferences_dialog_class_init (MsdA11yPreferencesDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_a11y_preferences_dialog_get_property; + object_class->set_property = msd_a11y_preferences_dialog_set_property; + object_class->constructor = msd_a11y_preferences_dialog_constructor; + object_class->dispose = msd_a11y_preferences_dialog_dispose; + object_class->finalize = msd_a11y_preferences_dialog_finalize; + + g_type_class_add_private (klass, sizeof (MsdA11yPreferencesDialogPrivate)); +} + +static void +on_response (MsdA11yPreferencesDialog *dialog, + gint response_id) +{ + switch (response_id) { + default: + break; + } +} + +static char * +config_get_string (const char *key, + gboolean *is_writable) +{ + char *str; + MateConfClient *client; + + client = mateconf_client_get_default (); + + if (is_writable) { + *is_writable = mateconf_client_key_is_writable (client, + key, + NULL); + } + + str = mateconf_client_get_string (client, key, NULL); + + g_object_unref (client); + + return str; +} + +static gboolean +config_get_bool (const char *key, + gboolean *is_writable) +{ + int enabled; + MateConfClient *client; + + client = mateconf_client_get_default (); + + if (is_writable) { + *is_writable = mateconf_client_key_is_writable (client, + key, + NULL); + } + + enabled = mateconf_client_get_bool (client, key, NULL); + + g_object_unref (client); + + return enabled; +} + +static double +dpi_from_pixels_and_mm (int pixels, + int mm) +{ + double dpi; + + if (mm >= 1) { + dpi = pixels / (mm / 25.4); + } else { + dpi = 0; + } + + return dpi; +} + +static double +get_dpi_from_x_server (void) +{ + GdkScreen *screen; + double dpi; + + screen = gdk_screen_get_default (); + if (screen != NULL) { + double width_dpi; + double height_dpi; + + width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen), + gdk_screen_get_width_mm (screen)); + height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen), + gdk_screen_get_height_mm (screen)); + if (width_dpi < DPI_LOW_REASONABLE_VALUE + || width_dpi > DPI_HIGH_REASONABLE_VALUE + || height_dpi < DPI_LOW_REASONABLE_VALUE + || height_dpi > DPI_HIGH_REASONABLE_VALUE) { + dpi = DPI_DEFAULT; + } else { + dpi = (width_dpi + height_dpi) / 2.0; + } + } else { + /* Huh!? No screen? */ + dpi = DPI_DEFAULT; + } + + return dpi; +} + +static gboolean +config_get_large_print (gboolean *is_writable) +{ + gboolean ret; + MateConfClient *client; + MateConfValue *value; + gdouble x_dpi; + gdouble u_dpi; + + client = mateconf_client_get_default (); + value = mateconf_client_get_without_default (client, KEY_FONT_DPI, NULL); + + if (value != NULL) { + u_dpi = mateconf_value_get_float (value); + mateconf_value_free (value); + } else { + u_dpi = DPI_DEFAULT; + } + + x_dpi = get_dpi_from_x_server (); + + g_object_unref (client); + + g_debug ("MsdA11yPreferences: got x-dpi=%f user-dpi=%f", x_dpi, u_dpi); + + ret = (((double)DPI_FACTOR_LARGE * x_dpi) < u_dpi); + + return ret; +} + +static void +config_set_large_print (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + + if (enabled) { + gdouble x_dpi; + gdouble u_dpi; + + x_dpi = get_dpi_from_x_server (); + u_dpi = (double)DPI_FACTOR_LARGER * x_dpi; + + g_debug ("MsdA11yPreferences: setting x-dpi=%f user-dpi=%f", x_dpi, u_dpi); + + mateconf_client_set_float (client, KEY_FONT_DPI, u_dpi, NULL); + } else { + mateconf_client_unset (client, KEY_FONT_DPI, NULL); + } + + g_object_unref (client); +} + +static gboolean +config_get_high_contrast (gboolean *is_writable) +{ + gboolean ret; + char *gtk_theme; + + ret = FALSE; + + gtk_theme = config_get_string (KEY_GTK_THEME, is_writable); + if (gtk_theme != NULL && strcmp (gtk_theme, HIGH_CONTRAST_THEME) == 0) { + ret = TRUE; + } + g_free (gtk_theme); + + return ret; +} + +static void +config_set_high_contrast (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + + if (enabled) { + mateconf_client_set_string (client, KEY_GTK_THEME, HIGH_CONTRAST_THEME, NULL); + mateconf_client_set_string (client, KEY_ICON_THEME, HIGH_CONTRAST_THEME, NULL); + /* there isn't a high contrast marco theme afaik */ + } else { + mateconf_client_unset (client, KEY_GTK_THEME, NULL); + mateconf_client_unset (client, KEY_ICON_THEME, NULL); + mateconf_client_unset (client, KEY_MARCO_THEME, NULL); + } + + g_object_unref (client); +} + +static gboolean +config_get_sticky_keys (gboolean *is_writable) +{ + return config_get_bool (KEY_STICKY_KEYS_ENABLED, is_writable); +} + +static void +config_set_sticky_keys (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_STICKY_KEYS_ENABLED, enabled, NULL); + g_object_unref (client); +} + +static gboolean +config_get_bounce_keys (gboolean *is_writable) +{ + return config_get_bool (KEY_BOUNCE_KEYS_ENABLED, is_writable); +} + +static void +config_set_bounce_keys (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_BOUNCE_KEYS_ENABLED, enabled, NULL); + g_object_unref (client); +} + +static gboolean +config_get_slow_keys (gboolean *is_writable) +{ + return config_get_bool (KEY_SLOW_KEYS_ENABLED, is_writable); +} + +static void +config_set_slow_keys (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_SLOW_KEYS_ENABLED, enabled, NULL); + g_object_unref (client); +} + +static gboolean +config_have_at_mateconf_condition (const char *condition) +{ + DBusGProxy *sm_proxy; + DBusGConnection *connection; + GError *error; + gboolean res; + gboolean is_handled; + + error = NULL; + connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (connection == NULL) { + g_warning ("Unable to connect to session bus: %s", error->message); + return FALSE; + } + sm_proxy = dbus_g_proxy_new_for_name (connection, + SM_DBUS_NAME, + SM_DBUS_PATH, + SM_DBUS_INTERFACE); + if (sm_proxy == NULL) { + return FALSE; + } + + is_handled = FALSE; + res = dbus_g_proxy_call (sm_proxy, + "IsAutostartConditionHandled", + &error, + G_TYPE_STRING, condition, + G_TYPE_INVALID, + G_TYPE_BOOLEAN, &is_handled, + G_TYPE_INVALID); + if (! res) { + g_warning ("Unable to call IsAutostartConditionHandled (%s): %s", + condition, + error->message); + } + + g_object_unref (sm_proxy); + + return is_handled; +} + +static gboolean +config_get_at_screen_reader (gboolean *is_writable) +{ + return config_get_bool (KEY_AT_SCREEN_READER_ENABLED, is_writable); +} + +static gboolean +config_get_at_screen_keyboard (gboolean *is_writable) +{ + return config_get_bool (KEY_AT_SCREEN_KEYBOARD_ENABLED, is_writable); +} + +static gboolean +config_get_at_screen_magnifier (gboolean *is_writable) +{ + return config_get_bool (KEY_AT_SCREEN_MAGNIFIER_ENABLED, is_writable); +} + +static void +config_set_at_screen_reader (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_AT_SCREEN_READER_ENABLED, enabled, NULL); + g_object_unref (client); +} + +static void +config_set_at_screen_keyboard (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_AT_SCREEN_KEYBOARD_ENABLED, enabled, NULL); + g_object_unref (client); +} + +static void +config_set_at_screen_magnifier (gboolean enabled) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_AT_SCREEN_MAGNIFIER_ENABLED, enabled, NULL); + g_object_unref (client); +} + +static void +on_sticky_keys_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_sticky_keys (gtk_toggle_button_get_active (button)); +} + +static void +on_bounce_keys_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_bounce_keys (gtk_toggle_button_get_active (button)); +} + +static void +on_slow_keys_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_slow_keys (gtk_toggle_button_get_active (button)); +} + +static void +on_high_contrast_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_high_contrast (gtk_toggle_button_get_active (button)); +} + +static void +on_at_screen_reader_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_at_screen_reader (gtk_toggle_button_get_active (button)); +} + +static void +on_at_screen_keyboard_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_at_screen_keyboard (gtk_toggle_button_get_active (button)); +} + +static void +on_at_screen_magnifier_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_at_screen_magnifier (gtk_toggle_button_get_active (button)); +} + +static void +on_large_print_checkbutton_toggled (GtkToggleButton *button, + MsdA11yPreferencesDialog *dialog) +{ + config_set_large_print (gtk_toggle_button_get_active (button)); +} + +static void +ui_set_sticky_keys (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->sticky_keys_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->sticky_keys_checkbutton), enabled); + } +} + +static void +ui_set_bounce_keys (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->bounce_keys_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->bounce_keys_checkbutton), enabled); + } +} + +static void +ui_set_slow_keys (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->slow_keys_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->slow_keys_checkbutton), enabled); + } +} + +static void +ui_set_high_contrast (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->high_contrast_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->high_contrast_checkbutton), enabled); + } +} + +static void +ui_set_at_screen_reader (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_reader_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_reader_checkbutton), enabled); + } +} + +static void +ui_set_at_screen_keyboard (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_keyboard_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_keyboard_checkbutton), enabled); + } +} + +static void +ui_set_at_screen_magnifier (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_magnifier_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->screen_magnifier_checkbutton), enabled); + } +} + +static void +ui_set_large_print (MsdA11yPreferencesDialog *dialog, + gboolean enabled) +{ + gboolean active; + + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->large_print_checkbutton)); + if (active != enabled) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->large_print_checkbutton), enabled); + } +} + +static void +key_changed_cb (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdA11yPreferencesDialog *dialog) +{ + const char *key; + MateConfValue *value; + + key = mateconf_entry_get_key (entry); + value = mateconf_entry_get_value (entry); + + if (strcmp (key, KEY_STICKY_KEYS_ENABLED) == 0) { + if (value->type == MATECONF_VALUE_BOOL) { + gboolean enabled; + + enabled = mateconf_value_get_bool (value); + ui_set_sticky_keys (dialog, enabled); + } else { + g_warning ("Error retrieving configuration key '%s': Invalid type", + key); + } + } else if (strcmp (key, KEY_BOUNCE_KEYS_ENABLED) == 0) { + if (value->type == MATECONF_VALUE_BOOL) { + gboolean enabled; + + enabled = mateconf_value_get_bool (value); + ui_set_bounce_keys (dialog, enabled); + } else { + g_warning ("Error retrieving configuration key '%s': Invalid type", + key); + } + } else if (strcmp (key, KEY_SLOW_KEYS_ENABLED) == 0) { + if (value->type == MATECONF_VALUE_BOOL) { + gboolean enabled; + + enabled = mateconf_value_get_bool (value); + ui_set_slow_keys (dialog, enabled); + } else { + g_warning ("Error retrieving configuration key '%s': Invalid type", + key); + } + } else if (strcmp (key, KEY_AT_SCREEN_READER_ENABLED) == 0) { + if (value->type == MATECONF_VALUE_BOOL) { + gboolean enabled; + + enabled = mateconf_value_get_bool (value); + ui_set_at_screen_reader (dialog, enabled); + } else { + g_warning ("Error retrieving configuration key '%s': Invalid type", + key); + } + } else if (strcmp (key, KEY_AT_SCREEN_KEYBOARD_ENABLED) == 0) { + if (value->type == MATECONF_VALUE_BOOL) { + gboolean enabled; + + enabled = mateconf_value_get_bool (value); + ui_set_at_screen_keyboard (dialog, enabled); + } else { + g_warning ("Error retrieving configuration key '%s': Invalid type", + key); + } + } else if (strcmp (key, KEY_AT_SCREEN_MAGNIFIER_ENABLED) == 0) { + if (value->type == MATECONF_VALUE_BOOL) { + gboolean enabled; + + enabled = mateconf_value_get_bool (value); + ui_set_at_screen_magnifier (dialog, enabled); + } else { + g_warning ("Error retrieving configuration key '%s': Invalid type", + key); + } + } else { + g_debug ("Config key not handled: %s", key); + } +} + +static void +setup_dialog (MsdA11yPreferencesDialog *dialog, + GtkBuilder *builder) +{ + GtkWidget *widget; + gboolean enabled; + gboolean is_writable; + MateConfClient *client; + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "sticky_keys_checkbutton")); + dialog->priv->sticky_keys_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_sticky_keys_checkbutton_toggled), + NULL); + enabled = config_get_sticky_keys (&is_writable); + ui_set_sticky_keys (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "bounce_keys_checkbutton")); + dialog->priv->bounce_keys_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_bounce_keys_checkbutton_toggled), + NULL); + enabled = config_get_bounce_keys (&is_writable); + ui_set_bounce_keys (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "slow_keys_checkbutton")); + dialog->priv->slow_keys_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_slow_keys_checkbutton_toggled), + NULL); + enabled = config_get_slow_keys (&is_writable); + ui_set_slow_keys (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "high_contrast_checkbutton")); + dialog->priv->high_contrast_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_high_contrast_checkbutton_toggled), + NULL); + enabled = config_get_high_contrast (&is_writable); + ui_set_high_contrast (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "at_screen_keyboard_checkbutton")); + dialog->priv->screen_keyboard_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_at_screen_keyboard_checkbutton_toggled), + NULL); + enabled = config_get_at_screen_keyboard (&is_writable); + ui_set_at_screen_keyboard (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + gtk_widget_set_no_show_all (widget, TRUE); + if (config_have_at_mateconf_condition ("MATE " KEY_AT_SCREEN_KEYBOARD_ENABLED)) { + gtk_widget_show_all (widget); + } else { + gtk_widget_hide (widget); + } + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "at_screen_reader_checkbutton")); + dialog->priv->screen_reader_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_at_screen_reader_checkbutton_toggled), + NULL); + enabled = config_get_at_screen_reader (&is_writable); + ui_set_at_screen_reader (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + gtk_widget_set_no_show_all (widget, TRUE); + if (config_have_at_mateconf_condition ("MATE " KEY_AT_SCREEN_READER_ENABLED)) { + gtk_widget_show_all (widget); + } else { + gtk_widget_hide (widget); + } + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "at_screen_magnifier_checkbutton")); + dialog->priv->screen_magnifier_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_at_screen_magnifier_checkbutton_toggled), + NULL); + enabled = config_get_at_screen_magnifier (&is_writable); + ui_set_at_screen_magnifier (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + gtk_widget_set_no_show_all (widget, TRUE); + if (config_have_at_mateconf_condition ("MATE " KEY_AT_SCREEN_MAGNIFIER_ENABLED)) { + gtk_widget_show_all (widget); + } else { + gtk_widget_hide (widget); + } + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "large_print_checkbutton")); + dialog->priv->large_print_checkbutton = widget; + g_signal_connect (widget, + "toggled", + G_CALLBACK (on_large_print_checkbutton_toggled), + NULL); + enabled = config_get_large_print (&is_writable); + ui_set_large_print (dialog, enabled); + if (! is_writable) { + gtk_widget_set_sensitive (widget, FALSE); + } + + + client = mateconf_client_get_default (); + mateconf_client_add_dir (client, + KEY_A11Y_DIR, + MATECONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + dialog->priv->a11y_dir_cnxn = mateconf_client_notify_add (client, + KEY_A11Y_DIR, + (MateConfClientNotifyFunc)key_changed_cb, + dialog, + NULL, + NULL); + + mateconf_client_add_dir (client, + KEY_AT_DIR, + MATECONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + dialog->priv->msd_a11y_dir_cnxn = mateconf_client_notify_add (client, + KEY_AT_DIR, + (MateConfClientNotifyFunc)key_changed_cb, + dialog, + NULL, + NULL); + + g_object_unref (client); +} + +static void +msd_a11y_preferences_dialog_init (MsdA11yPreferencesDialog *dialog) +{ + static const gchar *ui_file_path = GTKBUILDERDIR "/" GTKBUILDER_UI_FILE; + gchar *objects[] = {"main_box", NULL}; + GError *error = NULL; + GtkBuilder *builder; + + dialog->priv = MSD_A11Y_PREFERENCES_DIALOG_GET_PRIVATE (dialog); + + builder = gtk_builder_new (); + gtk_builder_set_translation_domain (builder, PACKAGE); + if (gtk_builder_add_objects_from_file (builder, ui_file_path, objects, + &error) == 0) { + g_warning ("Could not load A11Y-UI: %s", error->message); + g_error_free (error); + } else { + GtkWidget *widget; + + widget = GTK_WIDGET (gtk_builder_get_object (builder, + "main_box")); + gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), + widget); + gtk_container_set_border_width (GTK_CONTAINER (widget), 12); + setup_dialog (dialog, builder); + } + + g_object_unref (builder); + + gtk_container_set_border_width (GTK_CONTAINER (dialog), 12); + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + gtk_window_set_title (GTK_WINDOW (dialog), _("Universal Access Preferences")); + gtk_window_set_icon_name (GTK_WINDOW (dialog), "preferences-desktop-accessibility"); + g_object_set (dialog, + "allow-shrink", FALSE, + "allow-grow", FALSE, + NULL); + + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + NULL); + g_signal_connect (dialog, + "response", + G_CALLBACK (on_response), + dialog); + + + gtk_widget_show_all (GTK_WIDGET (dialog)); +} + +static void +msd_a11y_preferences_dialog_finalize (GObject *object) +{ + MsdA11yPreferencesDialog *dialog; + MateConfClient *client; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_A11Y_PREFERENCES_DIALOG (object)); + + dialog = MSD_A11Y_PREFERENCES_DIALOG (object); + + g_return_if_fail (dialog->priv != NULL); + + client = mateconf_client_get_default (); + + if (dialog->priv->a11y_dir_cnxn > 0) { + mateconf_client_notify_remove (client, dialog->priv->a11y_dir_cnxn); + } + if (dialog->priv->msd_a11y_dir_cnxn > 0) { + mateconf_client_notify_remove (client, dialog->priv->msd_a11y_dir_cnxn); + } + + g_object_unref (client); + + G_OBJECT_CLASS (msd_a11y_preferences_dialog_parent_class)->finalize (object); +} + +GtkWidget * +msd_a11y_preferences_dialog_new (void) +{ + GObject *object; + + object = g_object_new (MSD_TYPE_A11Y_PREFERENCES_DIALOG, + NULL); + + return GTK_WIDGET (object); +} diff --git a/plugins/a11y-keyboard/msd-a11y-preferences-dialog.h b/plugins/a11y-keyboard/msd-a11y-preferences-dialog.h new file mode 100644 index 0000000..967a94e --- /dev/null +++ b/plugins/a11y-keyboard/msd-a11y-preferences-dialog.h @@ -0,0 +1,59 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_A11Y_PREFERENCES_DIALOG_H +#define __MSD_A11Y_PREFERENCES_DIALOG_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_A11Y_PREFERENCES_DIALOG (msd_a11y_preferences_dialog_get_type ()) +#define MSD_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialog)) +#define MSD_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogClass)) +#define MSD_IS_A11Y_PREFERENCES_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG)) +#define MSD_IS_A11Y_PREFERENCES_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_A11Y_PREFERENCES_DIALOG)) +#define MSD_A11Y_PREFERENCES_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_A11Y_PREFERENCES_DIALOG, MsdA11yPreferencesDialogClass)) + +typedef struct MsdA11yPreferencesDialogPrivate MsdA11yPreferencesDialogPrivate; + +typedef struct +{ + GtkDialog parent; + MsdA11yPreferencesDialogPrivate *priv; +} MsdA11yPreferencesDialog; + +typedef struct +{ + GtkDialogClass parent_class; +} MsdA11yPreferencesDialogClass; + +GType msd_a11y_preferences_dialog_get_type (void); + +GtkWidget * msd_a11y_preferences_dialog_new (void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_A11Y_PREFERENCES_DIALOG_H */ diff --git a/plugins/a11y-keyboard/msd-a11y-preferences-dialog.ui b/plugins/a11y-keyboard/msd-a11y-preferences-dialog.ui new file mode 100644 index 0000000..6a0fcb0 --- /dev/null +++ b/plugins/a11y-keyboard/msd-a11y-preferences-dialog.ui @@ -0,0 +1,199 @@ + + + + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + Universal Access Preferences + center-on-parent + preferences-desktop-accessibility + dialog + False + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + 10 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + preferences-desktop-accessibility + 6 + + + 0 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + 6 + + + Use on-screen _keyboard + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 0 + + + + + Use screen _reader + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 1 + + + + + Use screen _magnifier + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 2 + + + + + Enhance _contrast in colors + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 3 + + + + + Make _text larger and easier to read + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 4 + + + + + _Press keyboard shortcuts one key at a time (Sticky Keys) + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 5 + + + + + _Ignore duplicate keypresses (Bounce Keys) + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 6 + + + + + Press and _hold keys to accept them (Slow Keys) + True + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + + + 7 + + + + + False + False + 1 + + + + + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + end + + + gtk-close + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + + + False + False + 0 + + + + + False + end + 0 + + + + + + button1 + + + diff --git a/plugins/background/gsd-background-manager.c b/plugins/background/gsd-background-manager.c deleted file mode 100644 index 25ab7ec..0000000 --- a/plugins/background/gsd-background-manager.c +++ /dev/null @@ -1,579 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright © 2001 Ximian, Inc. - * Copyright (C) 2007 William Jon McCann - * Copyright 2007 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include - -#define MATE_DESKTOP_USE_UNSTABLE_API -#include -#include - -#include "mate-settings-profile.h" -#include "msd-background-manager.h" - -#define CAJA_SHOW_DESKTOP_KEY "/apps/caja/preferences/show_desktop" - -#define MSD_BACKGROUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerPrivate)) - -struct MsdBackgroundManagerPrivate -{ - MateConfClient *client; - MateBG *bg; - guint bg_notify_id; - guint timeout_id; - - DBusConnection *dbus_connection; -}; - -static void msd_background_manager_class_init (MsdBackgroundManagerClass *klass); -static void msd_background_manager_init (MsdBackgroundManager *background_manager); -static void msd_background_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdBackgroundManager, msd_background_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -static gboolean -caja_is_running (void) -{ - Atom window_id_atom; - Window caja_xid; - Atom actual_type; - int actual_format; - unsigned long nitems; - unsigned long bytes_after; - unsigned char *data; - int retval; - Atom wmclass_atom; - gboolean running; - gint error; - - window_id_atom = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - "CAJA_DESKTOP_WINDOW_ID", True); - - if (window_id_atom == None) { - return FALSE; - } - - retval = XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - GDK_ROOT_WINDOW (), - window_id_atom, - 0, - 1, - False, - XA_WINDOW, - &actual_type, - &actual_format, - &nitems, - &bytes_after, - &data); - - if (data != NULL) { - caja_xid = *(Window *) data; - XFree (data); - } else { - return FALSE; - } - - if (actual_type != XA_WINDOW) { - return FALSE; - } - if (actual_format != 32) { - return FALSE; - } - - wmclass_atom = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "WM_CLASS", False); - - gdk_error_trap_push (); - - retval = XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - caja_xid, - wmclass_atom, - 0, - 24, - False, - XA_STRING, - &actual_type, - &actual_format, - &nitems, - &bytes_after, - &data); - - error = gdk_error_trap_pop (); - - if (error == BadWindow) { - return FALSE; - } - - if (actual_type == XA_STRING && - nitems == 24 && - bytes_after == 0 && - actual_format == 8 && - data != NULL && - !strcmp ((char *)data, "desktop_window") && - !strcmp ((char *)data + strlen ((char *)data) + 1, "Caja")) { - running = TRUE; - } else { - running = FALSE; - } - - if (data != NULL) { - XFree (data); - } - - return running; -} - -static void -draw_background (MsdBackgroundManager *manager, - gboolean use_crossfade) -{ - GdkDisplay *display; - int n_screens; - int i; - - if (caja_is_running ()) { - return; - } - - mate_settings_profile_start (NULL); - - display = gdk_display_get_default (); - n_screens = gdk_display_get_n_screens (display); - - for (i = 0; i < n_screens; ++i) { - GdkScreen *screen; - GdkWindow *root_window; - GdkPixmap *pixmap; - - screen = gdk_display_get_screen (display, i); - - root_window = gdk_screen_get_root_window (screen); - - pixmap = mate_bg_create_pixmap (manager->priv->bg, - root_window, - gdk_screen_get_width (screen), - gdk_screen_get_height (screen), - TRUE); - - if (use_crossfade) { - MateBGCrossfade *fade; - - fade = mate_bg_set_pixmap_as_root_with_crossfade (screen, pixmap); - g_signal_connect (fade, "finished", - G_CALLBACK (g_object_unref), NULL); - } else { - mate_bg_set_pixmap_as_root (screen, pixmap); - } - - g_object_unref (pixmap); - } - - mate_settings_profile_end (NULL); -} - -static void -on_bg_changed (MateBG *bg, - MsdBackgroundManager *manager) -{ - draw_background (manager, TRUE); -} - -static void -on_bg_transitioned (MateBG *bg, - MsdBackgroundManager *manager) -{ - draw_background (manager, FALSE); -} - -static void -mateconf_changed_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdBackgroundManager *manager) -{ - mate_bg_load_from_preferences (manager->priv->bg, - manager->priv->client); -} - -static void -watch_bg_preferences (MsdBackgroundManager *manager) -{ - g_assert (manager->priv->bg_notify_id == 0); - - mateconf_client_add_dir (manager->priv->client, - MATE_BG_KEY_DIR, - MATECONF_CLIENT_PRELOAD_NONE, - NULL); - manager->priv->bg_notify_id = mateconf_client_notify_add (manager->priv->client, - MATE_BG_KEY_DIR, - (MateConfClientNotifyFunc)mateconf_changed_callback, - manager, - NULL, - NULL); -} - -static void -setup_bg (MsdBackgroundManager *manager) -{ - g_return_if_fail (manager->priv->bg == NULL); - - manager->priv->bg = mate_bg_new (); - - g_signal_connect (manager->priv->bg, - "changed", - G_CALLBACK (on_bg_changed), - manager); - - g_signal_connect (manager->priv->bg, - "transitioned", - G_CALLBACK (on_bg_transitioned), - manager); - - watch_bg_preferences (manager); - mate_bg_load_from_preferences (manager->priv->bg, - manager->priv->client); -} - -static gboolean -queue_draw_background (MsdBackgroundManager *manager) -{ - manager->priv->timeout_id = 0; - if (caja_is_running ()) { - return FALSE; - } - setup_bg (manager); - draw_background (manager, FALSE); - return FALSE; -} - -static DBusHandlerResult -on_bus_message (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - MsdBackgroundManager *manager = user_data; - - if (dbus_message_is_signal (message, - "org.mate.SessionManager", - "SessionRunning")) { - /* If the session finishes then check if caja is - * running and if not, set the background. - * - * We wait a few seconds after the session is up - * because caja tells the session manager that its - * ready before it sets the background. - */ - manager->priv->timeout_id = g_timeout_add_seconds (8, - (GSourceFunc) - queue_draw_background, - manager); - dbus_connection_remove_filter (connection, - on_bus_message, - manager); - - manager->priv->dbus_connection = NULL; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static void -draw_background_after_session_loads (MsdBackgroundManager *manager) -{ - DBusConnection *connection; - - connection = dbus_bus_get (DBUS_BUS_SESSION, NULL); - - if (connection == NULL) { - return; - } - - if (!dbus_connection_add_filter (connection, on_bus_message, manager, NULL)) { - return; - }; - - manager->priv->dbus_connection = connection; -} - -static void -on_screen_size_changed (GdkScreen *screen, - MsdBackgroundManager *manager) -{ - gboolean caja_show_desktop; - - caja_show_desktop = mateconf_client_get_bool (manager->priv->client, - CAJA_SHOW_DESKTOP_KEY, - NULL); - - if (!caja_is_running () || !caja_show_desktop) { - if (manager->priv->bg == NULL) { - setup_bg (manager); - } - draw_background (manager, FALSE); - } -} - -static void -disconnect_screen_signals (MsdBackgroundManager *manager) -{ - GdkDisplay *display; - int i; - int n_screens; - - display = gdk_display_get_default (); - n_screens = gdk_display_get_n_screens (display); - - for (i = 0; i < n_screens; ++i) { - GdkScreen *screen; - screen = gdk_display_get_screen (display, i); - g_signal_handlers_disconnect_by_func (screen, - G_CALLBACK (on_screen_size_changed), - manager); - } -} - -static void -connect_screen_signals (MsdBackgroundManager *manager) -{ - GdkDisplay *display; - int i; - int n_screens; - - display = gdk_display_get_default (); - n_screens = gdk_display_get_n_screens (display); - - for (i = 0; i < n_screens; ++i) { - GdkScreen *screen; - screen = gdk_display_get_screen (display, i); - g_signal_connect (screen, - "monitors-changed", - G_CALLBACK (on_screen_size_changed), - manager); - g_signal_connect (screen, - "size-changed", - G_CALLBACK (on_screen_size_changed), - manager); - } -} - -gboolean -msd_background_manager_start (MsdBackgroundManager *manager, - GError **error) -{ - gboolean caja_show_desktop; - - g_debug ("Starting background manager"); - mate_settings_profile_start (NULL); - - manager->priv->client = mateconf_client_get_default (); - - /* If this is set, caja will draw the background and is - * almost definitely in our session. however, it may not be - * running yet (so is_caja_running() will fail). so, on - * startup, just don't do anything if this key is set so we - * don't waste time setting the background only to have - * caja overwrite it. - */ - caja_show_desktop = mateconf_client_get_bool (manager->priv->client, - CAJA_SHOW_DESKTOP_KEY, - NULL); - - if (!caja_show_desktop) { - setup_bg (manager); - } else { - draw_background_after_session_loads (manager); - } - - connect_screen_signals (manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_background_manager_stop (MsdBackgroundManager *manager) -{ - MsdBackgroundManagerPrivate *p = manager->priv; - - g_debug ("Stopping background manager"); - - disconnect_screen_signals (manager); - - if (manager->priv->dbus_connection != NULL) { - dbus_connection_remove_filter (manager->priv->dbus_connection, - on_bus_message, - manager); - } - - if (manager->priv->bg_notify_id != 0) { - mateconf_client_remove_dir (manager->priv->client, - MATE_BG_KEY_DIR, - NULL); - mateconf_client_notify_remove (manager->priv->client, - manager->priv->bg_notify_id); - manager->priv->bg_notify_id = 0; - } - - if (p->client != NULL) { - g_object_unref (p->client); - p->client = NULL; - } - - if (p->timeout_id != 0) { - g_source_remove (p->timeout_id); - p->timeout_id = 0; - } - - if (p->bg != NULL) { - g_object_unref (p->bg); - p->bg = NULL; - } -} - -static void -msd_background_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdBackgroundManager *self; - - self = MSD_BACKGROUND_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_background_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdBackgroundManager *self; - - self = MSD_BACKGROUND_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_background_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdBackgroundManager *background_manager; - MsdBackgroundManagerClass *klass; - - klass = MSD_BACKGROUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_BACKGROUND_MANAGER)); - - background_manager = MSD_BACKGROUND_MANAGER (G_OBJECT_CLASS (msd_background_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (background_manager); -} - -static void -msd_background_manager_dispose (GObject *object) -{ - MsdBackgroundManager *background_manager; - - background_manager = MSD_BACKGROUND_MANAGER (object); - - G_OBJECT_CLASS (msd_background_manager_parent_class)->dispose (object); -} - -static void -msd_background_manager_class_init (MsdBackgroundManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_background_manager_get_property; - object_class->set_property = msd_background_manager_set_property; - object_class->constructor = msd_background_manager_constructor; - object_class->dispose = msd_background_manager_dispose; - object_class->finalize = msd_background_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdBackgroundManagerPrivate)); -} - -static void -msd_background_manager_init (MsdBackgroundManager *manager) -{ - manager->priv = MSD_BACKGROUND_MANAGER_GET_PRIVATE (manager); -} - -static void -msd_background_manager_finalize (GObject *object) -{ - MsdBackgroundManager *background_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_BACKGROUND_MANAGER (object)); - - background_manager = MSD_BACKGROUND_MANAGER (object); - - g_return_if_fail (background_manager->priv != NULL); - - G_OBJECT_CLASS (msd_background_manager_parent_class)->finalize (object); -} - -MsdBackgroundManager * -msd_background_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_BACKGROUND_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_BACKGROUND_MANAGER (manager_object); -} diff --git a/plugins/background/gsd-background-manager.h b/plugins/background/gsd-background-manager.h deleted file mode 100644 index 91e232c..0000000 --- a/plugins/background/gsd-background-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_BACKGROUND_MANAGER_H -#define __MSD_BACKGROUND_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_BACKGROUND_MANAGER (msd_background_manager_get_type ()) -#define MSD_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManager)) -#define MSD_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass)) -#define MSD_IS_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_BACKGROUND_MANAGER)) -#define MSD_IS_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_BACKGROUND_MANAGER)) -#define MSD_BACKGROUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass)) - -typedef struct MsdBackgroundManagerPrivate MsdBackgroundManagerPrivate; - -typedef struct -{ - GObject parent; - MsdBackgroundManagerPrivate *priv; -} MsdBackgroundManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdBackgroundManagerClass; - -GType msd_background_manager_get_type (void); - -MsdBackgroundManager * msd_background_manager_new (void); -gboolean msd_background_manager_start (MsdBackgroundManager *manager, - GError **error); -void msd_background_manager_stop (MsdBackgroundManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_BACKGROUND_MANAGER_H */ diff --git a/plugins/background/gsd-background-plugin.c b/plugins/background/gsd-background-plugin.c deleted file mode 100644 index d12bb2b..0000000 --- a/plugins/background/gsd-background-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-background-plugin.h" -#include "msd-background-manager.h" - -struct MsdBackgroundPluginPrivate { - MsdBackgroundManager *manager; -}; - -#define MSD_BACKGROUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdBackgroundPlugin, msd_background_plugin) - -static void -msd_background_plugin_init (MsdBackgroundPlugin *plugin) -{ - plugin->priv = MSD_BACKGROUND_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdBackgroundPlugin initializing"); - - plugin->priv->manager = msd_background_manager_new (); -} - -static void -msd_background_plugin_finalize (GObject *object) -{ - MsdBackgroundPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_BACKGROUND_PLUGIN (object)); - - g_debug ("MsdBackgroundPlugin finalizing"); - - plugin = MSD_BACKGROUND_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_background_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating background plugin"); - - error = NULL; - res = msd_background_manager_start (MSD_BACKGROUND_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start background manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating background plugin"); - msd_background_manager_stop (MSD_BACKGROUND_PLUGIN (plugin)->priv->manager); -} - -static void -msd_background_plugin_class_init (MsdBackgroundPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_background_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdBackgroundPluginPrivate)); -} diff --git a/plugins/background/gsd-background-plugin.h b/plugins/background/gsd-background-plugin.h deleted file mode 100644 index dd52572..0000000 --- a/plugins/background/gsd-background-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_BACKGROUND_PLUGIN_H__ -#define __MSD_BACKGROUND_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_BACKGROUND_PLUGIN (msd_background_plugin_get_type ()) -#define MSD_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPlugin)) -#define MSD_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginClass)) -#define MSD_IS_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_BACKGROUND_PLUGIN)) -#define MSD_IS_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_BACKGROUND_PLUGIN)) -#define MSD_BACKGROUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginClass)) - -typedef struct MsdBackgroundPluginPrivate MsdBackgroundPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdBackgroundPluginPrivate *priv; -} MsdBackgroundPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdBackgroundPluginClass; - -GType msd_background_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_BACKGROUND_PLUGIN_H__ */ diff --git a/plugins/background/msd-background-manager.c b/plugins/background/msd-background-manager.c new file mode 100644 index 0000000..25ab7ec --- /dev/null +++ b/plugins/background/msd-background-manager.c @@ -0,0 +1,579 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright © 2001 Ximian, Inc. + * Copyright (C) 2007 William Jon McCann + * Copyright 2007 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#define MATE_DESKTOP_USE_UNSTABLE_API +#include +#include + +#include "mate-settings-profile.h" +#include "msd-background-manager.h" + +#define CAJA_SHOW_DESKTOP_KEY "/apps/caja/preferences/show_desktop" + +#define MSD_BACKGROUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerPrivate)) + +struct MsdBackgroundManagerPrivate +{ + MateConfClient *client; + MateBG *bg; + guint bg_notify_id; + guint timeout_id; + + DBusConnection *dbus_connection; +}; + +static void msd_background_manager_class_init (MsdBackgroundManagerClass *klass); +static void msd_background_manager_init (MsdBackgroundManager *background_manager); +static void msd_background_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdBackgroundManager, msd_background_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +static gboolean +caja_is_running (void) +{ + Atom window_id_atom; + Window caja_xid; + Atom actual_type; + int actual_format; + unsigned long nitems; + unsigned long bytes_after; + unsigned char *data; + int retval; + Atom wmclass_atom; + gboolean running; + gint error; + + window_id_atom = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + "CAJA_DESKTOP_WINDOW_ID", True); + + if (window_id_atom == None) { + return FALSE; + } + + retval = XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + GDK_ROOT_WINDOW (), + window_id_atom, + 0, + 1, + False, + XA_WINDOW, + &actual_type, + &actual_format, + &nitems, + &bytes_after, + &data); + + if (data != NULL) { + caja_xid = *(Window *) data; + XFree (data); + } else { + return FALSE; + } + + if (actual_type != XA_WINDOW) { + return FALSE; + } + if (actual_format != 32) { + return FALSE; + } + + wmclass_atom = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "WM_CLASS", False); + + gdk_error_trap_push (); + + retval = XGetWindowProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + caja_xid, + wmclass_atom, + 0, + 24, + False, + XA_STRING, + &actual_type, + &actual_format, + &nitems, + &bytes_after, + &data); + + error = gdk_error_trap_pop (); + + if (error == BadWindow) { + return FALSE; + } + + if (actual_type == XA_STRING && + nitems == 24 && + bytes_after == 0 && + actual_format == 8 && + data != NULL && + !strcmp ((char *)data, "desktop_window") && + !strcmp ((char *)data + strlen ((char *)data) + 1, "Caja")) { + running = TRUE; + } else { + running = FALSE; + } + + if (data != NULL) { + XFree (data); + } + + return running; +} + +static void +draw_background (MsdBackgroundManager *manager, + gboolean use_crossfade) +{ + GdkDisplay *display; + int n_screens; + int i; + + if (caja_is_running ()) { + return; + } + + mate_settings_profile_start (NULL); + + display = gdk_display_get_default (); + n_screens = gdk_display_get_n_screens (display); + + for (i = 0; i < n_screens; ++i) { + GdkScreen *screen; + GdkWindow *root_window; + GdkPixmap *pixmap; + + screen = gdk_display_get_screen (display, i); + + root_window = gdk_screen_get_root_window (screen); + + pixmap = mate_bg_create_pixmap (manager->priv->bg, + root_window, + gdk_screen_get_width (screen), + gdk_screen_get_height (screen), + TRUE); + + if (use_crossfade) { + MateBGCrossfade *fade; + + fade = mate_bg_set_pixmap_as_root_with_crossfade (screen, pixmap); + g_signal_connect (fade, "finished", + G_CALLBACK (g_object_unref), NULL); + } else { + mate_bg_set_pixmap_as_root (screen, pixmap); + } + + g_object_unref (pixmap); + } + + mate_settings_profile_end (NULL); +} + +static void +on_bg_changed (MateBG *bg, + MsdBackgroundManager *manager) +{ + draw_background (manager, TRUE); +} + +static void +on_bg_transitioned (MateBG *bg, + MsdBackgroundManager *manager) +{ + draw_background (manager, FALSE); +} + +static void +mateconf_changed_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdBackgroundManager *manager) +{ + mate_bg_load_from_preferences (manager->priv->bg, + manager->priv->client); +} + +static void +watch_bg_preferences (MsdBackgroundManager *manager) +{ + g_assert (manager->priv->bg_notify_id == 0); + + mateconf_client_add_dir (manager->priv->client, + MATE_BG_KEY_DIR, + MATECONF_CLIENT_PRELOAD_NONE, + NULL); + manager->priv->bg_notify_id = mateconf_client_notify_add (manager->priv->client, + MATE_BG_KEY_DIR, + (MateConfClientNotifyFunc)mateconf_changed_callback, + manager, + NULL, + NULL); +} + +static void +setup_bg (MsdBackgroundManager *manager) +{ + g_return_if_fail (manager->priv->bg == NULL); + + manager->priv->bg = mate_bg_new (); + + g_signal_connect (manager->priv->bg, + "changed", + G_CALLBACK (on_bg_changed), + manager); + + g_signal_connect (manager->priv->bg, + "transitioned", + G_CALLBACK (on_bg_transitioned), + manager); + + watch_bg_preferences (manager); + mate_bg_load_from_preferences (manager->priv->bg, + manager->priv->client); +} + +static gboolean +queue_draw_background (MsdBackgroundManager *manager) +{ + manager->priv->timeout_id = 0; + if (caja_is_running ()) { + return FALSE; + } + setup_bg (manager); + draw_background (manager, FALSE); + return FALSE; +} + +static DBusHandlerResult +on_bus_message (DBusConnection *connection, + DBusMessage *message, + void *user_data) +{ + MsdBackgroundManager *manager = user_data; + + if (dbus_message_is_signal (message, + "org.mate.SessionManager", + "SessionRunning")) { + /* If the session finishes then check if caja is + * running and if not, set the background. + * + * We wait a few seconds after the session is up + * because caja tells the session manager that its + * ready before it sets the background. + */ + manager->priv->timeout_id = g_timeout_add_seconds (8, + (GSourceFunc) + queue_draw_background, + manager); + dbus_connection_remove_filter (connection, + on_bus_message, + manager); + + manager->priv->dbus_connection = NULL; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static void +draw_background_after_session_loads (MsdBackgroundManager *manager) +{ + DBusConnection *connection; + + connection = dbus_bus_get (DBUS_BUS_SESSION, NULL); + + if (connection == NULL) { + return; + } + + if (!dbus_connection_add_filter (connection, on_bus_message, manager, NULL)) { + return; + }; + + manager->priv->dbus_connection = connection; +} + +static void +on_screen_size_changed (GdkScreen *screen, + MsdBackgroundManager *manager) +{ + gboolean caja_show_desktop; + + caja_show_desktop = mateconf_client_get_bool (manager->priv->client, + CAJA_SHOW_DESKTOP_KEY, + NULL); + + if (!caja_is_running () || !caja_show_desktop) { + if (manager->priv->bg == NULL) { + setup_bg (manager); + } + draw_background (manager, FALSE); + } +} + +static void +disconnect_screen_signals (MsdBackgroundManager *manager) +{ + GdkDisplay *display; + int i; + int n_screens; + + display = gdk_display_get_default (); + n_screens = gdk_display_get_n_screens (display); + + for (i = 0; i < n_screens; ++i) { + GdkScreen *screen; + screen = gdk_display_get_screen (display, i); + g_signal_handlers_disconnect_by_func (screen, + G_CALLBACK (on_screen_size_changed), + manager); + } +} + +static void +connect_screen_signals (MsdBackgroundManager *manager) +{ + GdkDisplay *display; + int i; + int n_screens; + + display = gdk_display_get_default (); + n_screens = gdk_display_get_n_screens (display); + + for (i = 0; i < n_screens; ++i) { + GdkScreen *screen; + screen = gdk_display_get_screen (display, i); + g_signal_connect (screen, + "monitors-changed", + G_CALLBACK (on_screen_size_changed), + manager); + g_signal_connect (screen, + "size-changed", + G_CALLBACK (on_screen_size_changed), + manager); + } +} + +gboolean +msd_background_manager_start (MsdBackgroundManager *manager, + GError **error) +{ + gboolean caja_show_desktop; + + g_debug ("Starting background manager"); + mate_settings_profile_start (NULL); + + manager->priv->client = mateconf_client_get_default (); + + /* If this is set, caja will draw the background and is + * almost definitely in our session. however, it may not be + * running yet (so is_caja_running() will fail). so, on + * startup, just don't do anything if this key is set so we + * don't waste time setting the background only to have + * caja overwrite it. + */ + caja_show_desktop = mateconf_client_get_bool (manager->priv->client, + CAJA_SHOW_DESKTOP_KEY, + NULL); + + if (!caja_show_desktop) { + setup_bg (manager); + } else { + draw_background_after_session_loads (manager); + } + + connect_screen_signals (manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_background_manager_stop (MsdBackgroundManager *manager) +{ + MsdBackgroundManagerPrivate *p = manager->priv; + + g_debug ("Stopping background manager"); + + disconnect_screen_signals (manager); + + if (manager->priv->dbus_connection != NULL) { + dbus_connection_remove_filter (manager->priv->dbus_connection, + on_bus_message, + manager); + } + + if (manager->priv->bg_notify_id != 0) { + mateconf_client_remove_dir (manager->priv->client, + MATE_BG_KEY_DIR, + NULL); + mateconf_client_notify_remove (manager->priv->client, + manager->priv->bg_notify_id); + manager->priv->bg_notify_id = 0; + } + + if (p->client != NULL) { + g_object_unref (p->client); + p->client = NULL; + } + + if (p->timeout_id != 0) { + g_source_remove (p->timeout_id); + p->timeout_id = 0; + } + + if (p->bg != NULL) { + g_object_unref (p->bg); + p->bg = NULL; + } +} + +static void +msd_background_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdBackgroundManager *self; + + self = MSD_BACKGROUND_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_background_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdBackgroundManager *self; + + self = MSD_BACKGROUND_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_background_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdBackgroundManager *background_manager; + MsdBackgroundManagerClass *klass; + + klass = MSD_BACKGROUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_BACKGROUND_MANAGER)); + + background_manager = MSD_BACKGROUND_MANAGER (G_OBJECT_CLASS (msd_background_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (background_manager); +} + +static void +msd_background_manager_dispose (GObject *object) +{ + MsdBackgroundManager *background_manager; + + background_manager = MSD_BACKGROUND_MANAGER (object); + + G_OBJECT_CLASS (msd_background_manager_parent_class)->dispose (object); +} + +static void +msd_background_manager_class_init (MsdBackgroundManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_background_manager_get_property; + object_class->set_property = msd_background_manager_set_property; + object_class->constructor = msd_background_manager_constructor; + object_class->dispose = msd_background_manager_dispose; + object_class->finalize = msd_background_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdBackgroundManagerPrivate)); +} + +static void +msd_background_manager_init (MsdBackgroundManager *manager) +{ + manager->priv = MSD_BACKGROUND_MANAGER_GET_PRIVATE (manager); +} + +static void +msd_background_manager_finalize (GObject *object) +{ + MsdBackgroundManager *background_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_BACKGROUND_MANAGER (object)); + + background_manager = MSD_BACKGROUND_MANAGER (object); + + g_return_if_fail (background_manager->priv != NULL); + + G_OBJECT_CLASS (msd_background_manager_parent_class)->finalize (object); +} + +MsdBackgroundManager * +msd_background_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_BACKGROUND_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_BACKGROUND_MANAGER (manager_object); +} diff --git a/plugins/background/msd-background-manager.h b/plugins/background/msd-background-manager.h new file mode 100644 index 0000000..91e232c --- /dev/null +++ b/plugins/background/msd-background-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_BACKGROUND_MANAGER_H +#define __MSD_BACKGROUND_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_BACKGROUND_MANAGER (msd_background_manager_get_type ()) +#define MSD_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManager)) +#define MSD_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass)) +#define MSD_IS_BACKGROUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_BACKGROUND_MANAGER)) +#define MSD_IS_BACKGROUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_BACKGROUND_MANAGER)) +#define MSD_BACKGROUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_BACKGROUND_MANAGER, MsdBackgroundManagerClass)) + +typedef struct MsdBackgroundManagerPrivate MsdBackgroundManagerPrivate; + +typedef struct +{ + GObject parent; + MsdBackgroundManagerPrivate *priv; +} MsdBackgroundManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdBackgroundManagerClass; + +GType msd_background_manager_get_type (void); + +MsdBackgroundManager * msd_background_manager_new (void); +gboolean msd_background_manager_start (MsdBackgroundManager *manager, + GError **error); +void msd_background_manager_stop (MsdBackgroundManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_BACKGROUND_MANAGER_H */ diff --git a/plugins/background/msd-background-plugin.c b/plugins/background/msd-background-plugin.c new file mode 100644 index 0000000..d12bb2b --- /dev/null +++ b/plugins/background/msd-background-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-background-plugin.h" +#include "msd-background-manager.h" + +struct MsdBackgroundPluginPrivate { + MsdBackgroundManager *manager; +}; + +#define MSD_BACKGROUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdBackgroundPlugin, msd_background_plugin) + +static void +msd_background_plugin_init (MsdBackgroundPlugin *plugin) +{ + plugin->priv = MSD_BACKGROUND_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdBackgroundPlugin initializing"); + + plugin->priv->manager = msd_background_manager_new (); +} + +static void +msd_background_plugin_finalize (GObject *object) +{ + MsdBackgroundPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_BACKGROUND_PLUGIN (object)); + + g_debug ("MsdBackgroundPlugin finalizing"); + + plugin = MSD_BACKGROUND_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_background_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating background plugin"); + + error = NULL; + res = msd_background_manager_start (MSD_BACKGROUND_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start background manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating background plugin"); + msd_background_manager_stop (MSD_BACKGROUND_PLUGIN (plugin)->priv->manager); +} + +static void +msd_background_plugin_class_init (MsdBackgroundPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_background_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdBackgroundPluginPrivate)); +} diff --git a/plugins/background/msd-background-plugin.h b/plugins/background/msd-background-plugin.h new file mode 100644 index 0000000..dd52572 --- /dev/null +++ b/plugins/background/msd-background-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_BACKGROUND_PLUGIN_H__ +#define __MSD_BACKGROUND_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_BACKGROUND_PLUGIN (msd_background_plugin_get_type ()) +#define MSD_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPlugin)) +#define MSD_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginClass)) +#define MSD_IS_BACKGROUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_BACKGROUND_PLUGIN)) +#define MSD_IS_BACKGROUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_BACKGROUND_PLUGIN)) +#define MSD_BACKGROUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_BACKGROUND_PLUGIN, MsdBackgroundPluginClass)) + +typedef struct MsdBackgroundPluginPrivate MsdBackgroundPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdBackgroundPluginPrivate *priv; +} MsdBackgroundPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdBackgroundPluginClass; + +GType msd_background_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_BACKGROUND_PLUGIN_H__ */ diff --git a/plugins/clipboard/gsd-clipboard-manager.c b/plugins/clipboard/gsd-clipboard-manager.c deleted file mode 100644 index c6d5a57..0000000 --- a/plugins/clipboard/gsd-clipboard-manager.c +++ /dev/null @@ -1,1069 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 Matthias Clasen - * Copyright (C) 2007 Anders Carlsson - * Copyright (C) 2007 Rodrigo Moya - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "xutils.h" -#include "list.h" - -#include "mate-settings-profile.h" -#include "msd-clipboard-manager.h" - -#define MSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerPrivate)) - -struct MsdClipboardManagerPrivate -{ - Display *display; - Window window; - Time timestamp; - - List *contents; - List *conversions; - - Window requestor; - Atom property; - Time time; -}; - -typedef struct -{ - unsigned char *data; - int length; - Atom target; - Atom type; - int format; - int refcount; -} TargetData; - -typedef struct -{ - Atom target; - TargetData *data; - Atom property; - Window requestor; - int offset; -} IncrConversion; - -static void msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass); -static void msd_clipboard_manager_init (MsdClipboardManager *clipboard_manager); -static void msd_clipboard_manager_finalize (GObject *object); - -static void clipboard_manager_watch_cb (MsdClipboardManager *manager, - Window window, - Bool is_start, - long mask, - void *cb_data); - -G_DEFINE_TYPE (MsdClipboardManager, msd_clipboard_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -/* We need to use reference counting for the target data, since we may - * need to keep the data around after loosing the CLIPBOARD ownership - * to complete incremental transfers. - */ -static TargetData * -target_data_ref (TargetData *data) -{ - data->refcount++; - return data; -} - -static void -target_data_unref (TargetData *data) -{ - data->refcount--; - if (data->refcount == 0) { - free (data->data); - free (data); - } -} - -static void -conversion_free (IncrConversion *rdata) -{ - if (rdata->data) { - target_data_unref (rdata->data); - } - free (rdata); -} - -static void -send_selection_notify (MsdClipboardManager *manager, - Bool success) -{ - XSelectionEvent notify; - - notify.type = SelectionNotify; - notify.serial = 0; - notify.send_event = True; - notify.display = manager->priv->display; - notify.requestor = manager->priv->requestor; - notify.selection = XA_CLIPBOARD_MANAGER; - notify.target = XA_SAVE_TARGETS; - notify.property = success ? manager->priv->property : None; - notify.time = manager->priv->time; - - gdk_error_trap_push (); - - XSendEvent (manager->priv->display, - manager->priv->requestor, - False, - NoEventMask, - (XEvent *)¬ify); - XSync (manager->priv->display, False); - - gdk_error_trap_pop (); -} - -static void -finish_selection_request (MsdClipboardManager *manager, - XEvent *xev, - Bool success) -{ - XSelectionEvent notify; - - notify.type = SelectionNotify; - notify.serial = 0; - notify.send_event = True; - notify.display = xev->xselectionrequest.display; - notify.requestor = xev->xselectionrequest.requestor; - notify.selection = xev->xselectionrequest.selection; - notify.target = xev->xselectionrequest.target; - notify.property = success ? xev->xselectionrequest.property : None; - notify.time = xev->xselectionrequest.time; - - gdk_error_trap_push (); - - XSendEvent (xev->xselectionrequest.display, - xev->xselectionrequest.requestor, - False, NoEventMask, (XEvent *) ¬ify); - XSync (manager->priv->display, False); - - gdk_error_trap_pop (); -} - -static int -clipboard_bytes_per_item (int format) -{ - switch (format) { - case 8: return sizeof (char); - case 16: return sizeof (short); - case 32: return sizeof (long); - default: ; - } - - return 0; -} - -static void -save_targets (MsdClipboardManager *manager, - Atom *save_targets, - int nitems) -{ - int nout, i; - Atom *multiple; - TargetData *tdata; - - multiple = (Atom *) malloc (2 * nitems * sizeof (Atom)); - - nout = 0; - for (i = 0; i < nitems; i++) { - if (save_targets[i] != XA_TARGETS && - save_targets[i] != XA_MULTIPLE && - save_targets[i] != XA_DELETE && - save_targets[i] != XA_INSERT_PROPERTY && - save_targets[i] != XA_INSERT_SELECTION && - save_targets[i] != XA_PIXMAP) { - tdata = (TargetData *) malloc (sizeof (TargetData)); - tdata->data = NULL; - tdata->length = 0; - tdata->target = save_targets[i]; - tdata->type = None; - tdata->format = 0; - tdata->refcount = 1; - manager->priv->contents = list_prepend (manager->priv->contents, tdata); - - multiple[nout++] = save_targets[i]; - multiple[nout++] = save_targets[i]; - } - } - - XFree (save_targets); - - XChangeProperty (manager->priv->display, manager->priv->window, - XA_MULTIPLE, XA_ATOM_PAIR, - 32, PropModeReplace, (const unsigned char *) multiple, nout); - free (multiple); - - XConvertSelection (manager->priv->display, XA_CLIPBOARD, - XA_MULTIPLE, XA_MULTIPLE, - manager->priv->window, manager->priv->time); -} - -static int -find_content_target (TargetData *tdata, - Atom target) -{ - return tdata->target == target; -} - -static int -find_content_type (TargetData *tdata, - Atom type) -{ - return tdata->type == type; -} - -static int -find_conversion_requestor (IncrConversion *rdata, - XEvent *xev) -{ - return (rdata->requestor == xev->xproperty.window && - rdata->property == xev->xproperty.atom); -} - -static void -get_property (TargetData *tdata, - MsdClipboardManager *manager) -{ - Atom type; - int format; - unsigned long length; - unsigned long remaining; - unsigned char *data; - - XGetWindowProperty (manager->priv->display, - manager->priv->window, - tdata->target, - 0, - 0x1FFFFFFF, - True, - AnyPropertyType, - &type, - &format, - &length, - &remaining, - &data); - - if (type == None) { - manager->priv->contents = list_remove (manager->priv->contents, tdata); - free (tdata); - } else if (type == XA_INCR) { - tdata->type = type; - tdata->length = 0; - XFree (data); - } else { - tdata->type = type; - tdata->data = data; - tdata->length = length * clipboard_bytes_per_item (format); - tdata->format = format; - } -} - -static Bool -receive_incrementally (MsdClipboardManager *manager, - XEvent *xev) -{ - List *list; - TargetData *tdata; - Atom type; - int format; - unsigned long length, nitems, remaining; - unsigned char *data; - - if (xev->xproperty.window != manager->priv->window) - return False; - - list = list_find (manager->priv->contents, - (ListFindFunc) find_content_target, (void *) xev->xproperty.atom); - - if (!list) - return False; - - tdata = (TargetData *) list->data; - - if (tdata->type != XA_INCR) - return False; - - XGetWindowProperty (xev->xproperty.display, - xev->xproperty.window, - xev->xproperty.atom, - 0, 0x1FFFFFFF, True, AnyPropertyType, - &type, &format, &nitems, &remaining, &data); - - length = nitems * clipboard_bytes_per_item (format); - if (length == 0) { - tdata->type = type; - tdata->format = format; - - if (!list_find (manager->priv->contents, - (ListFindFunc) find_content_type, (void *)XA_INCR)) { - /* all incremental transfers done */ - send_selection_notify (manager, True); - manager->priv->requestor = None; - } - - XFree (data); - } else { - if (!tdata->data) { - tdata->data = data; - tdata->length = length; - } else { - tdata->data = realloc (tdata->data, tdata->length + length + 1); - memcpy (tdata->data + tdata->length, data, length + 1); - tdata->length += length; - XFree (data); - } - } - - return True; -} - -static Bool -send_incrementally (MsdClipboardManager *manager, - XEvent *xev) -{ - List *list; - IncrConversion *rdata; - unsigned long length; - unsigned long items; - unsigned char *data; - - list = list_find (manager->priv->conversions, - (ListFindFunc) find_conversion_requestor, xev); - if (list == NULL) - return False; - - rdata = (IncrConversion *) list->data; - - data = rdata->data->data + rdata->offset; - length = rdata->data->length - rdata->offset; - if (length > SELECTION_MAX_SIZE) - length = SELECTION_MAX_SIZE; - - rdata->offset += length; - - items = length / clipboard_bytes_per_item (rdata->data->format); - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, rdata->data->type, - rdata->data->format, PropModeAppend, - data, items); - - if (length == 0) { - manager->priv->conversions = list_remove (manager->priv->conversions, rdata); - conversion_free (rdata); - } - - return True; -} - -static void -convert_clipboard_manager (MsdClipboardManager *manager, - XEvent *xev) -{ - Atom type = None; - int format; - unsigned long nitems; - unsigned long remaining; - Atom *targets = NULL; - - if (xev->xselectionrequest.target == XA_SAVE_TARGETS) { - if (manager->priv->requestor != None || manager->priv->contents != NULL) { - /* We're in the middle of a conversion request, or own - * the CLIPBOARD already - */ - finish_selection_request (manager, xev, False); - } else { - gdk_error_trap_push (); - - clipboard_manager_watch_cb (manager, - xev->xselectionrequest.requestor, - True, - StructureNotifyMask, - NULL); - XSelectInput (manager->priv->display, - xev->xselectionrequest.requestor, - StructureNotifyMask); - XSync (manager->priv->display, False); - - if (gdk_error_trap_pop () != Success) - return; - - gdk_error_trap_push (); - - if (xev->xselectionrequest.property != None) { - XGetWindowProperty (manager->priv->display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - 0, 0x1FFFFFFF, False, XA_ATOM, - &type, &format, &nitems, &remaining, - (unsigned char **) &targets); - - if (gdk_error_trap_pop () != Success) { - if (targets) - XFree (targets); - - return; - } - } - - manager->priv->requestor = xev->xselectionrequest.requestor; - manager->priv->property = xev->xselectionrequest.property; - manager->priv->time = xev->xselectionrequest.time; - - if (type == None) - XConvertSelection (manager->priv->display, XA_CLIPBOARD, - XA_TARGETS, XA_TARGETS, - manager->priv->window, manager->priv->time); - else - save_targets (manager, targets, nitems); - } - } else if (xev->xselectionrequest.target == XA_TIMESTAMP) { - XChangeProperty (manager->priv->display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - XA_INTEGER, 32, PropModeReplace, - (unsigned char *) &manager->priv->timestamp, 1); - - finish_selection_request (manager, xev, True); - } else if (xev->xselectionrequest.target == XA_TARGETS) { - int n_targets = 0; - Atom targets[3]; - - targets[n_targets++] = XA_TARGETS; - targets[n_targets++] = XA_TIMESTAMP; - targets[n_targets++] = XA_SAVE_TARGETS; - - XChangeProperty (manager->priv->display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *) targets, n_targets); - - finish_selection_request (manager, xev, True); - } else - finish_selection_request (manager, xev, False); -} - -static void -convert_clipboard_target (IncrConversion *rdata, - MsdClipboardManager *manager) -{ - TargetData *tdata; - Atom *targets; - int n_targets; - List *list; - unsigned long items; - XWindowAttributes atts; - - if (rdata->target == XA_TARGETS) { - n_targets = list_length (manager->priv->contents) + 2; - targets = (Atom *) malloc (n_targets * sizeof (Atom)); - - n_targets = 0; - - targets[n_targets++] = XA_TARGETS; - targets[n_targets++] = XA_MULTIPLE; - - for (list = manager->priv->contents; list; list = list->next) { - tdata = (TargetData *) list->data; - targets[n_targets++] = tdata->target; - } - - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *) targets, n_targets); - free (targets); - } else { - /* Convert from stored CLIPBOARD data */ - list = list_find (manager->priv->contents, - (ListFindFunc) find_content_target, (void *) rdata->target); - - /* We got a target that we don't support */ - if (!list) - return; - - tdata = (TargetData *)list->data; - if (tdata->type == XA_INCR) { - /* we haven't completely received this target yet */ - rdata->property = None; - return; - } - - rdata->data = target_data_ref (tdata); - items = tdata->length / clipboard_bytes_per_item (tdata->format); - if (tdata->length <= SELECTION_MAX_SIZE) - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, - tdata->type, tdata->format, PropModeReplace, - tdata->data, items); - else { - /* start incremental transfer */ - rdata->offset = 0; - - gdk_error_trap_push (); - - XGetWindowAttributes (manager->priv->display, rdata->requestor, &atts); - XSelectInput (manager->priv->display, rdata->requestor, - atts.your_event_mask | PropertyChangeMask); - - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, - XA_INCR, 32, PropModeReplace, - (unsigned char *) &items, 1); - - XSync (manager->priv->display, False); - - gdk_error_trap_pop (); - } - } -} - -static void -collect_incremental (IncrConversion *rdata, - MsdClipboardManager *manager) -{ - if (rdata->offset >= 0) - manager->priv->conversions = list_prepend (manager->priv->conversions, rdata); - else { - if (rdata->data) { - target_data_unref (rdata->data); - rdata->data = NULL; - } - free (rdata); - } -} - -static void -convert_clipboard (MsdClipboardManager *manager, - XEvent *xev) -{ - List *list; - List *conversions; - IncrConversion *rdata; - Atom type; - int i; - int format; - unsigned long nitems; - unsigned long remaining; - Atom *multiple; - - conversions = NULL; - type = None; - - if (xev->xselectionrequest.target == XA_MULTIPLE) { - XGetWindowProperty (xev->xselectionrequest.display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - 0, 0x1FFFFFFF, False, XA_ATOM_PAIR, - &type, &format, &nitems, &remaining, - (unsigned char **) &multiple); - - if (type != XA_ATOM_PAIR || nitems == 0) { - if (multiple) - free (multiple); - return; - } - - for (i = 0; i < nitems; i += 2) { - rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); - rdata->requestor = xev->xselectionrequest.requestor; - rdata->target = multiple[i]; - rdata->property = multiple[i+1]; - rdata->data = NULL; - rdata->offset = -1; - conversions = list_prepend (conversions, rdata); - } - } else { - multiple = NULL; - - rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); - rdata->requestor = xev->xselectionrequest.requestor; - rdata->target = xev->xselectionrequest.target; - rdata->property = xev->xselectionrequest.property; - rdata->data = NULL; - rdata->offset = -1; - conversions = list_prepend (conversions, rdata); - } - - list_foreach (conversions, (Callback) convert_clipboard_target, manager); - - if (conversions->next == NULL && - ((IncrConversion *) conversions->data)->property == None) { - finish_selection_request (manager, xev, False); - } else { - if (multiple) { - i = 0; - for (list = conversions; list; list = list->next) { - rdata = (IncrConversion *)list->data; - multiple[i++] = rdata->target; - multiple[i++] = rdata->property; - } - XChangeProperty (xev->xselectionrequest.display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - XA_ATOM_PAIR, 32, PropModeReplace, - (unsigned char *) multiple, nitems); - } - finish_selection_request (manager, xev, True); - } - - list_foreach (conversions, (Callback) collect_incremental, manager); - list_free (conversions); - - if (multiple) - free (multiple); -} - -static Bool -clipboard_manager_process_event (MsdClipboardManager *manager, - XEvent *xev) -{ - Atom type; - int format; - unsigned long nitems; - unsigned long remaining; - Atom *targets; - - targets = NULL; - - switch (xev->xany.type) { - case DestroyNotify: - if (xev->xdestroywindow.window == manager->priv->requestor) { - list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); - list_free (manager->priv->contents); - manager->priv->contents = NULL; - - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - } - break; - case PropertyNotify: - if (xev->xproperty.state == PropertyNewValue) { - return receive_incrementally (manager, xev); - } else { - return send_incrementally (manager, xev); - } - - case SelectionClear: - if (xev->xany.window != manager->priv->window) - return False; - - if (xev->xselectionclear.selection == XA_CLIPBOARD_MANAGER) { - /* We lost the manager selection */ - if (manager->priv->contents) { - list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); - list_free (manager->priv->contents); - manager->priv->contents = NULL; - - XSetSelectionOwner (manager->priv->display, - XA_CLIPBOARD, - None, manager->priv->time); - } - - return True; - } - if (xev->xselectionclear.selection == XA_CLIPBOARD) { - /* We lost the clipboard selection */ - list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); - list_free (manager->priv->contents); - manager->priv->contents = NULL; - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - - return True; - } - break; - - case SelectionNotify: - if (xev->xany.window != manager->priv->window) - return False; - - if (xev->xselection.selection == XA_CLIPBOARD) { - /* a CLIPBOARD conversion is done */ - if (xev->xselection.property == XA_TARGETS) { - XGetWindowProperty (xev->xselection.display, - xev->xselection.requestor, - xev->xselection.property, - 0, 0x1FFFFFFF, True, XA_ATOM, - &type, &format, &nitems, &remaining, - (unsigned char **) &targets); - - save_targets (manager, targets, nitems); - } else if (xev->xselection.property == XA_MULTIPLE) { - List *tmp; - - tmp = list_copy (manager->priv->contents); - list_foreach (tmp, (Callback) get_property, manager); - list_free (tmp); - - manager->priv->time = xev->xselection.time; - XSetSelectionOwner (manager->priv->display, XA_CLIPBOARD, - manager->priv->window, manager->priv->time); - - if (manager->priv->property != None) - XChangeProperty (manager->priv->display, - manager->priv->requestor, - manager->priv->property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *)&XA_NULL, 1); - - if (!list_find (manager->priv->contents, - (ListFindFunc)find_content_type, (void *)XA_INCR)) { - /* all transfers done */ - send_selection_notify (manager, True); - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - } - } - else if (xev->xselection.property == None) { - send_selection_notify (manager, False); - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - } - - return True; - } - break; - - case SelectionRequest: - if (xev->xany.window != manager->priv->window) { - return False; - } - - if (xev->xselectionrequest.selection == XA_CLIPBOARD_MANAGER) { - convert_clipboard_manager (manager, xev); - return True; - } else if (xev->xselectionrequest.selection == XA_CLIPBOARD) { - convert_clipboard (manager, xev); - return True; - } - break; - - default: ; - } - - return False; -} - -static GdkFilterReturn -clipboard_manager_event_filter (GdkXEvent *xevent, - GdkEvent *event, - MsdClipboardManager *manager) -{ - if (clipboard_manager_process_event (manager, (XEvent *)xevent)) { - return GDK_FILTER_REMOVE; - } else { - return GDK_FILTER_CONTINUE; - } -} - -static void -clipboard_manager_watch_cb (MsdClipboardManager *manager, - Window window, - Bool is_start, - long mask, - void *cb_data) -{ - GdkWindow *gdkwin; - GdkDisplay *display; - - display = gdk_display_get_default (); - gdkwin = gdk_window_lookup_for_display (display, window); - - if (is_start) { - if (gdkwin == NULL) { - gdkwin = gdk_window_foreign_new_for_display (display, window); - } else { - g_object_ref (gdkwin); - } - - gdk_window_add_filter (gdkwin, - (GdkFilterFunc)clipboard_manager_event_filter, - manager); - } else { - if (gdkwin == NULL) { - return; - } - gdk_window_remove_filter (gdkwin, - (GdkFilterFunc)clipboard_manager_event_filter, - manager); - g_object_unref (gdkwin); - } -} - -static gboolean -start_clipboard_idle_cb (MsdClipboardManager *manager) -{ - XClientMessageEvent xev; - - - mate_settings_profile_start (NULL); - - init_atoms (manager->priv->display); - - /* check if there is a clipboard manager running */ - if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER)) { - g_warning ("Clipboard manager is already running."); - return FALSE; - } - - manager->priv->contents = NULL; - manager->priv->conversions = NULL; - manager->priv->requestor = None; - - manager->priv->window = XCreateSimpleWindow (manager->priv->display, - DefaultRootWindow (manager->priv->display), - 0, 0, 10, 10, 0, - WhitePixel (manager->priv->display, - DefaultScreen (manager->priv->display)), - WhitePixel (manager->priv->display, - DefaultScreen (manager->priv->display))); - clipboard_manager_watch_cb (manager, - manager->priv->window, - True, - PropertyChangeMask, - NULL); - XSelectInput (manager->priv->display, - manager->priv->window, - PropertyChangeMask); - manager->priv->timestamp = get_server_time (manager->priv->display, manager->priv->window); - - XSetSelectionOwner (manager->priv->display, - XA_CLIPBOARD_MANAGER, - manager->priv->window, - manager->priv->timestamp); - - /* Check to see if we managed to claim the selection. If not, - * we treat it as if we got it then immediately lost it - */ - if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER) == manager->priv->window) { - xev.type = ClientMessage; - xev.window = DefaultRootWindow (manager->priv->display); - xev.message_type = XA_MANAGER; - xev.format = 32; - xev.data.l[0] = manager->priv->timestamp; - xev.data.l[1] = XA_CLIPBOARD_MANAGER; - xev.data.l[2] = manager->priv->window; - xev.data.l[3] = 0; /* manager specific data */ - xev.data.l[4] = 0; /* manager specific data */ - - XSendEvent (manager->priv->display, - DefaultRootWindow (manager->priv->display), - False, - StructureNotifyMask, - (XEvent *)&xev); - } else { - clipboard_manager_watch_cb (manager, - manager->priv->window, - False, - 0, - NULL); - /* FIXME: manager->priv->terminate (manager->priv->cb_data); */ - } - - mate_settings_profile_end (NULL); - - return FALSE; -} - -gboolean -msd_clipboard_manager_start (MsdClipboardManager *manager, - GError **error) -{ - mate_settings_profile_start (NULL); - - g_idle_add ((GSourceFunc) start_clipboard_idle_cb, manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_clipboard_manager_stop (MsdClipboardManager *manager) -{ - g_debug ("Stopping clipboard manager"); - - clipboard_manager_watch_cb (manager, - manager->priv->window, - FALSE, - 0, - NULL); - XDestroyWindow (manager->priv->display, manager->priv->window); - - list_foreach (manager->priv->conversions, (Callback) conversion_free, NULL); - list_free (manager->priv->conversions); - - list_foreach (manager->priv->contents, (Callback) target_data_unref, NULL); - list_free (manager->priv->contents); -} - -static void -msd_clipboard_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdClipboardManager *self; - - self = MSD_CLIPBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_clipboard_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdClipboardManager *self; - - self = MSD_CLIPBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_clipboard_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdClipboardManager *clipboard_manager; - MsdClipboardManagerClass *klass; - - klass = MSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_CLIPBOARD_MANAGER)); - - clipboard_manager = MSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (clipboard_manager); -} - -static void -msd_clipboard_manager_dispose (GObject *object) -{ - MsdClipboardManager *clipboard_manager; - - clipboard_manager = MSD_CLIPBOARD_MANAGER (object); - - G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->dispose (object); -} - -static void -msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_clipboard_manager_get_property; - object_class->set_property = msd_clipboard_manager_set_property; - object_class->constructor = msd_clipboard_manager_constructor; - object_class->dispose = msd_clipboard_manager_dispose; - object_class->finalize = msd_clipboard_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdClipboardManagerPrivate)); -} - -static void -msd_clipboard_manager_init (MsdClipboardManager *manager) -{ - manager->priv = MSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); - - manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - -} - -static void -msd_clipboard_manager_finalize (GObject *object) -{ - MsdClipboardManager *clipboard_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_CLIPBOARD_MANAGER (object)); - - clipboard_manager = MSD_CLIPBOARD_MANAGER (object); - - g_return_if_fail (clipboard_manager->priv != NULL); - - G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->finalize (object); -} - -MsdClipboardManager * -msd_clipboard_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_CLIPBOARD_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_CLIPBOARD_MANAGER (manager_object); -} diff --git a/plugins/clipboard/gsd-clipboard-manager.h b/plugins/clipboard/gsd-clipboard-manager.h deleted file mode 100644 index e4af711..0000000 --- a/plugins/clipboard/gsd-clipboard-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_CLIPBOARD_MANAGER_H -#define __MSD_CLIPBOARD_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_CLIPBOARD_MANAGER (msd_clipboard_manager_get_type ()) -#define MSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManager)) -#define MSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) -#define MSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_MANAGER)) -#define MSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_MANAGER)) -#define MSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) - -typedef struct MsdClipboardManagerPrivate MsdClipboardManagerPrivate; - -typedef struct -{ - GObject parent; - MsdClipboardManagerPrivate *priv; -} MsdClipboardManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdClipboardManagerClass; - -GType msd_clipboard_manager_get_type (void); - -MsdClipboardManager * msd_clipboard_manager_new (void); -gboolean msd_clipboard_manager_start (MsdClipboardManager *manager, - GError **error); -void msd_clipboard_manager_stop (MsdClipboardManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_CLIPBOARD_MANAGER_H */ diff --git a/plugins/clipboard/gsd-clipboard-plugin.c b/plugins/clipboard/gsd-clipboard-plugin.c deleted file mode 100644 index 6674265..0000000 --- a/plugins/clipboard/gsd-clipboard-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-clipboard-plugin.h" -#include "msd-clipboard-manager.h" - -struct MsdClipboardPluginPrivate { - MsdClipboardManager *manager; -}; - -#define MSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdClipboardPlugin, msd_clipboard_plugin) - -static void -msd_clipboard_plugin_init (MsdClipboardPlugin *plugin) -{ - plugin->priv = MSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdClipboardPlugin initializing"); - - plugin->priv->manager = msd_clipboard_manager_new (); -} - -static void -msd_clipboard_plugin_finalize (GObject *object) -{ - MsdClipboardPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_CLIPBOARD_PLUGIN (object)); - - g_debug ("MsdClipboardPlugin finalizing"); - - plugin = MSD_CLIPBOARD_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_clipboard_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating clipboard plugin"); - - error = NULL; - res = msd_clipboard_manager_start (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start clipboard manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating clipboard plugin"); - msd_clipboard_manager_stop (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); -} - -static void -msd_clipboard_plugin_class_init (MsdClipboardPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_clipboard_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdClipboardPluginPrivate)); -} diff --git a/plugins/clipboard/gsd-clipboard-plugin.h b/plugins/clipboard/gsd-clipboard-plugin.h deleted file mode 100644 index 7b2ea1e..0000000 --- a/plugins/clipboard/gsd-clipboard-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_CLIPBOARD_PLUGIN_H__ -#define __MSD_CLIPBOARD_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_CLIPBOARD_PLUGIN (msd_clipboard_plugin_get_type ()) -#define MSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPlugin)) -#define MSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) -#define MSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_PLUGIN)) -#define MSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_PLUGIN)) -#define MSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) - -typedef struct MsdClipboardPluginPrivate MsdClipboardPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdClipboardPluginPrivate *priv; -} MsdClipboardPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdClipboardPluginClass; - -GType msd_clipboard_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_CLIPBOARD_PLUGIN_H__ */ diff --git a/plugins/clipboard/msd-clipboard-manager.c b/plugins/clipboard/msd-clipboard-manager.c new file mode 100644 index 0000000..c6d5a57 --- /dev/null +++ b/plugins/clipboard/msd-clipboard-manager.c @@ -0,0 +1,1069 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 Matthias Clasen + * Copyright (C) 2007 Anders Carlsson + * Copyright (C) 2007 Rodrigo Moya + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "xutils.h" +#include "list.h" + +#include "mate-settings-profile.h" +#include "msd-clipboard-manager.h" + +#define MSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerPrivate)) + +struct MsdClipboardManagerPrivate +{ + Display *display; + Window window; + Time timestamp; + + List *contents; + List *conversions; + + Window requestor; + Atom property; + Time time; +}; + +typedef struct +{ + unsigned char *data; + int length; + Atom target; + Atom type; + int format; + int refcount; +} TargetData; + +typedef struct +{ + Atom target; + TargetData *data; + Atom property; + Window requestor; + int offset; +} IncrConversion; + +static void msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass); +static void msd_clipboard_manager_init (MsdClipboardManager *clipboard_manager); +static void msd_clipboard_manager_finalize (GObject *object); + +static void clipboard_manager_watch_cb (MsdClipboardManager *manager, + Window window, + Bool is_start, + long mask, + void *cb_data); + +G_DEFINE_TYPE (MsdClipboardManager, msd_clipboard_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +/* We need to use reference counting for the target data, since we may + * need to keep the data around after loosing the CLIPBOARD ownership + * to complete incremental transfers. + */ +static TargetData * +target_data_ref (TargetData *data) +{ + data->refcount++; + return data; +} + +static void +target_data_unref (TargetData *data) +{ + data->refcount--; + if (data->refcount == 0) { + free (data->data); + free (data); + } +} + +static void +conversion_free (IncrConversion *rdata) +{ + if (rdata->data) { + target_data_unref (rdata->data); + } + free (rdata); +} + +static void +send_selection_notify (MsdClipboardManager *manager, + Bool success) +{ + XSelectionEvent notify; + + notify.type = SelectionNotify; + notify.serial = 0; + notify.send_event = True; + notify.display = manager->priv->display; + notify.requestor = manager->priv->requestor; + notify.selection = XA_CLIPBOARD_MANAGER; + notify.target = XA_SAVE_TARGETS; + notify.property = success ? manager->priv->property : None; + notify.time = manager->priv->time; + + gdk_error_trap_push (); + + XSendEvent (manager->priv->display, + manager->priv->requestor, + False, + NoEventMask, + (XEvent *)¬ify); + XSync (manager->priv->display, False); + + gdk_error_trap_pop (); +} + +static void +finish_selection_request (MsdClipboardManager *manager, + XEvent *xev, + Bool success) +{ + XSelectionEvent notify; + + notify.type = SelectionNotify; + notify.serial = 0; + notify.send_event = True; + notify.display = xev->xselectionrequest.display; + notify.requestor = xev->xselectionrequest.requestor; + notify.selection = xev->xselectionrequest.selection; + notify.target = xev->xselectionrequest.target; + notify.property = success ? xev->xselectionrequest.property : None; + notify.time = xev->xselectionrequest.time; + + gdk_error_trap_push (); + + XSendEvent (xev->xselectionrequest.display, + xev->xselectionrequest.requestor, + False, NoEventMask, (XEvent *) ¬ify); + XSync (manager->priv->display, False); + + gdk_error_trap_pop (); +} + +static int +clipboard_bytes_per_item (int format) +{ + switch (format) { + case 8: return sizeof (char); + case 16: return sizeof (short); + case 32: return sizeof (long); + default: ; + } + + return 0; +} + +static void +save_targets (MsdClipboardManager *manager, + Atom *save_targets, + int nitems) +{ + int nout, i; + Atom *multiple; + TargetData *tdata; + + multiple = (Atom *) malloc (2 * nitems * sizeof (Atom)); + + nout = 0; + for (i = 0; i < nitems; i++) { + if (save_targets[i] != XA_TARGETS && + save_targets[i] != XA_MULTIPLE && + save_targets[i] != XA_DELETE && + save_targets[i] != XA_INSERT_PROPERTY && + save_targets[i] != XA_INSERT_SELECTION && + save_targets[i] != XA_PIXMAP) { + tdata = (TargetData *) malloc (sizeof (TargetData)); + tdata->data = NULL; + tdata->length = 0; + tdata->target = save_targets[i]; + tdata->type = None; + tdata->format = 0; + tdata->refcount = 1; + manager->priv->contents = list_prepend (manager->priv->contents, tdata); + + multiple[nout++] = save_targets[i]; + multiple[nout++] = save_targets[i]; + } + } + + XFree (save_targets); + + XChangeProperty (manager->priv->display, manager->priv->window, + XA_MULTIPLE, XA_ATOM_PAIR, + 32, PropModeReplace, (const unsigned char *) multiple, nout); + free (multiple); + + XConvertSelection (manager->priv->display, XA_CLIPBOARD, + XA_MULTIPLE, XA_MULTIPLE, + manager->priv->window, manager->priv->time); +} + +static int +find_content_target (TargetData *tdata, + Atom target) +{ + return tdata->target == target; +} + +static int +find_content_type (TargetData *tdata, + Atom type) +{ + return tdata->type == type; +} + +static int +find_conversion_requestor (IncrConversion *rdata, + XEvent *xev) +{ + return (rdata->requestor == xev->xproperty.window && + rdata->property == xev->xproperty.atom); +} + +static void +get_property (TargetData *tdata, + MsdClipboardManager *manager) +{ + Atom type; + int format; + unsigned long length; + unsigned long remaining; + unsigned char *data; + + XGetWindowProperty (manager->priv->display, + manager->priv->window, + tdata->target, + 0, + 0x1FFFFFFF, + True, + AnyPropertyType, + &type, + &format, + &length, + &remaining, + &data); + + if (type == None) { + manager->priv->contents = list_remove (manager->priv->contents, tdata); + free (tdata); + } else if (type == XA_INCR) { + tdata->type = type; + tdata->length = 0; + XFree (data); + } else { + tdata->type = type; + tdata->data = data; + tdata->length = length * clipboard_bytes_per_item (format); + tdata->format = format; + } +} + +static Bool +receive_incrementally (MsdClipboardManager *manager, + XEvent *xev) +{ + List *list; + TargetData *tdata; + Atom type; + int format; + unsigned long length, nitems, remaining; + unsigned char *data; + + if (xev->xproperty.window != manager->priv->window) + return False; + + list = list_find (manager->priv->contents, + (ListFindFunc) find_content_target, (void *) xev->xproperty.atom); + + if (!list) + return False; + + tdata = (TargetData *) list->data; + + if (tdata->type != XA_INCR) + return False; + + XGetWindowProperty (xev->xproperty.display, + xev->xproperty.window, + xev->xproperty.atom, + 0, 0x1FFFFFFF, True, AnyPropertyType, + &type, &format, &nitems, &remaining, &data); + + length = nitems * clipboard_bytes_per_item (format); + if (length == 0) { + tdata->type = type; + tdata->format = format; + + if (!list_find (manager->priv->contents, + (ListFindFunc) find_content_type, (void *)XA_INCR)) { + /* all incremental transfers done */ + send_selection_notify (manager, True); + manager->priv->requestor = None; + } + + XFree (data); + } else { + if (!tdata->data) { + tdata->data = data; + tdata->length = length; + } else { + tdata->data = realloc (tdata->data, tdata->length + length + 1); + memcpy (tdata->data + tdata->length, data, length + 1); + tdata->length += length; + XFree (data); + } + } + + return True; +} + +static Bool +send_incrementally (MsdClipboardManager *manager, + XEvent *xev) +{ + List *list; + IncrConversion *rdata; + unsigned long length; + unsigned long items; + unsigned char *data; + + list = list_find (manager->priv->conversions, + (ListFindFunc) find_conversion_requestor, xev); + if (list == NULL) + return False; + + rdata = (IncrConversion *) list->data; + + data = rdata->data->data + rdata->offset; + length = rdata->data->length - rdata->offset; + if (length > SELECTION_MAX_SIZE) + length = SELECTION_MAX_SIZE; + + rdata->offset += length; + + items = length / clipboard_bytes_per_item (rdata->data->format); + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, rdata->data->type, + rdata->data->format, PropModeAppend, + data, items); + + if (length == 0) { + manager->priv->conversions = list_remove (manager->priv->conversions, rdata); + conversion_free (rdata); + } + + return True; +} + +static void +convert_clipboard_manager (MsdClipboardManager *manager, + XEvent *xev) +{ + Atom type = None; + int format; + unsigned long nitems; + unsigned long remaining; + Atom *targets = NULL; + + if (xev->xselectionrequest.target == XA_SAVE_TARGETS) { + if (manager->priv->requestor != None || manager->priv->contents != NULL) { + /* We're in the middle of a conversion request, or own + * the CLIPBOARD already + */ + finish_selection_request (manager, xev, False); + } else { + gdk_error_trap_push (); + + clipboard_manager_watch_cb (manager, + xev->xselectionrequest.requestor, + True, + StructureNotifyMask, + NULL); + XSelectInput (manager->priv->display, + xev->xselectionrequest.requestor, + StructureNotifyMask); + XSync (manager->priv->display, False); + + if (gdk_error_trap_pop () != Success) + return; + + gdk_error_trap_push (); + + if (xev->xselectionrequest.property != None) { + XGetWindowProperty (manager->priv->display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + 0, 0x1FFFFFFF, False, XA_ATOM, + &type, &format, &nitems, &remaining, + (unsigned char **) &targets); + + if (gdk_error_trap_pop () != Success) { + if (targets) + XFree (targets); + + return; + } + } + + manager->priv->requestor = xev->xselectionrequest.requestor; + manager->priv->property = xev->xselectionrequest.property; + manager->priv->time = xev->xselectionrequest.time; + + if (type == None) + XConvertSelection (manager->priv->display, XA_CLIPBOARD, + XA_TARGETS, XA_TARGETS, + manager->priv->window, manager->priv->time); + else + save_targets (manager, targets, nitems); + } + } else if (xev->xselectionrequest.target == XA_TIMESTAMP) { + XChangeProperty (manager->priv->display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + XA_INTEGER, 32, PropModeReplace, + (unsigned char *) &manager->priv->timestamp, 1); + + finish_selection_request (manager, xev, True); + } else if (xev->xselectionrequest.target == XA_TARGETS) { + int n_targets = 0; + Atom targets[3]; + + targets[n_targets++] = XA_TARGETS; + targets[n_targets++] = XA_TIMESTAMP; + targets[n_targets++] = XA_SAVE_TARGETS; + + XChangeProperty (manager->priv->display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + XA_ATOM, 32, PropModeReplace, + (unsigned char *) targets, n_targets); + + finish_selection_request (manager, xev, True); + } else + finish_selection_request (manager, xev, False); +} + +static void +convert_clipboard_target (IncrConversion *rdata, + MsdClipboardManager *manager) +{ + TargetData *tdata; + Atom *targets; + int n_targets; + List *list; + unsigned long items; + XWindowAttributes atts; + + if (rdata->target == XA_TARGETS) { + n_targets = list_length (manager->priv->contents) + 2; + targets = (Atom *) malloc (n_targets * sizeof (Atom)); + + n_targets = 0; + + targets[n_targets++] = XA_TARGETS; + targets[n_targets++] = XA_MULTIPLE; + + for (list = manager->priv->contents; list; list = list->next) { + tdata = (TargetData *) list->data; + targets[n_targets++] = tdata->target; + } + + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, + XA_ATOM, 32, PropModeReplace, + (unsigned char *) targets, n_targets); + free (targets); + } else { + /* Convert from stored CLIPBOARD data */ + list = list_find (manager->priv->contents, + (ListFindFunc) find_content_target, (void *) rdata->target); + + /* We got a target that we don't support */ + if (!list) + return; + + tdata = (TargetData *)list->data; + if (tdata->type == XA_INCR) { + /* we haven't completely received this target yet */ + rdata->property = None; + return; + } + + rdata->data = target_data_ref (tdata); + items = tdata->length / clipboard_bytes_per_item (tdata->format); + if (tdata->length <= SELECTION_MAX_SIZE) + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, + tdata->type, tdata->format, PropModeReplace, + tdata->data, items); + else { + /* start incremental transfer */ + rdata->offset = 0; + + gdk_error_trap_push (); + + XGetWindowAttributes (manager->priv->display, rdata->requestor, &atts); + XSelectInput (manager->priv->display, rdata->requestor, + atts.your_event_mask | PropertyChangeMask); + + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, + XA_INCR, 32, PropModeReplace, + (unsigned char *) &items, 1); + + XSync (manager->priv->display, False); + + gdk_error_trap_pop (); + } + } +} + +static void +collect_incremental (IncrConversion *rdata, + MsdClipboardManager *manager) +{ + if (rdata->offset >= 0) + manager->priv->conversions = list_prepend (manager->priv->conversions, rdata); + else { + if (rdata->data) { + target_data_unref (rdata->data); + rdata->data = NULL; + } + free (rdata); + } +} + +static void +convert_clipboard (MsdClipboardManager *manager, + XEvent *xev) +{ + List *list; + List *conversions; + IncrConversion *rdata; + Atom type; + int i; + int format; + unsigned long nitems; + unsigned long remaining; + Atom *multiple; + + conversions = NULL; + type = None; + + if (xev->xselectionrequest.target == XA_MULTIPLE) { + XGetWindowProperty (xev->xselectionrequest.display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + 0, 0x1FFFFFFF, False, XA_ATOM_PAIR, + &type, &format, &nitems, &remaining, + (unsigned char **) &multiple); + + if (type != XA_ATOM_PAIR || nitems == 0) { + if (multiple) + free (multiple); + return; + } + + for (i = 0; i < nitems; i += 2) { + rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); + rdata->requestor = xev->xselectionrequest.requestor; + rdata->target = multiple[i]; + rdata->property = multiple[i+1]; + rdata->data = NULL; + rdata->offset = -1; + conversions = list_prepend (conversions, rdata); + } + } else { + multiple = NULL; + + rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); + rdata->requestor = xev->xselectionrequest.requestor; + rdata->target = xev->xselectionrequest.target; + rdata->property = xev->xselectionrequest.property; + rdata->data = NULL; + rdata->offset = -1; + conversions = list_prepend (conversions, rdata); + } + + list_foreach (conversions, (Callback) convert_clipboard_target, manager); + + if (conversions->next == NULL && + ((IncrConversion *) conversions->data)->property == None) { + finish_selection_request (manager, xev, False); + } else { + if (multiple) { + i = 0; + for (list = conversions; list; list = list->next) { + rdata = (IncrConversion *)list->data; + multiple[i++] = rdata->target; + multiple[i++] = rdata->property; + } + XChangeProperty (xev->xselectionrequest.display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + XA_ATOM_PAIR, 32, PropModeReplace, + (unsigned char *) multiple, nitems); + } + finish_selection_request (manager, xev, True); + } + + list_foreach (conversions, (Callback) collect_incremental, manager); + list_free (conversions); + + if (multiple) + free (multiple); +} + +static Bool +clipboard_manager_process_event (MsdClipboardManager *manager, + XEvent *xev) +{ + Atom type; + int format; + unsigned long nitems; + unsigned long remaining; + Atom *targets; + + targets = NULL; + + switch (xev->xany.type) { + case DestroyNotify: + if (xev->xdestroywindow.window == manager->priv->requestor) { + list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); + list_free (manager->priv->contents); + manager->priv->contents = NULL; + + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + } + break; + case PropertyNotify: + if (xev->xproperty.state == PropertyNewValue) { + return receive_incrementally (manager, xev); + } else { + return send_incrementally (manager, xev); + } + + case SelectionClear: + if (xev->xany.window != manager->priv->window) + return False; + + if (xev->xselectionclear.selection == XA_CLIPBOARD_MANAGER) { + /* We lost the manager selection */ + if (manager->priv->contents) { + list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); + list_free (manager->priv->contents); + manager->priv->contents = NULL; + + XSetSelectionOwner (manager->priv->display, + XA_CLIPBOARD, + None, manager->priv->time); + } + + return True; + } + if (xev->xselectionclear.selection == XA_CLIPBOARD) { + /* We lost the clipboard selection */ + list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); + list_free (manager->priv->contents); + manager->priv->contents = NULL; + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + + return True; + } + break; + + case SelectionNotify: + if (xev->xany.window != manager->priv->window) + return False; + + if (xev->xselection.selection == XA_CLIPBOARD) { + /* a CLIPBOARD conversion is done */ + if (xev->xselection.property == XA_TARGETS) { + XGetWindowProperty (xev->xselection.display, + xev->xselection.requestor, + xev->xselection.property, + 0, 0x1FFFFFFF, True, XA_ATOM, + &type, &format, &nitems, &remaining, + (unsigned char **) &targets); + + save_targets (manager, targets, nitems); + } else if (xev->xselection.property == XA_MULTIPLE) { + List *tmp; + + tmp = list_copy (manager->priv->contents); + list_foreach (tmp, (Callback) get_property, manager); + list_free (tmp); + + manager->priv->time = xev->xselection.time; + XSetSelectionOwner (manager->priv->display, XA_CLIPBOARD, + manager->priv->window, manager->priv->time); + + if (manager->priv->property != None) + XChangeProperty (manager->priv->display, + manager->priv->requestor, + manager->priv->property, + XA_ATOM, 32, PropModeReplace, + (unsigned char *)&XA_NULL, 1); + + if (!list_find (manager->priv->contents, + (ListFindFunc)find_content_type, (void *)XA_INCR)) { + /* all transfers done */ + send_selection_notify (manager, True); + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + } + } + else if (xev->xselection.property == None) { + send_selection_notify (manager, False); + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + } + + return True; + } + break; + + case SelectionRequest: + if (xev->xany.window != manager->priv->window) { + return False; + } + + if (xev->xselectionrequest.selection == XA_CLIPBOARD_MANAGER) { + convert_clipboard_manager (manager, xev); + return True; + } else if (xev->xselectionrequest.selection == XA_CLIPBOARD) { + convert_clipboard (manager, xev); + return True; + } + break; + + default: ; + } + + return False; +} + +static GdkFilterReturn +clipboard_manager_event_filter (GdkXEvent *xevent, + GdkEvent *event, + MsdClipboardManager *manager) +{ + if (clipboard_manager_process_event (manager, (XEvent *)xevent)) { + return GDK_FILTER_REMOVE; + } else { + return GDK_FILTER_CONTINUE; + } +} + +static void +clipboard_manager_watch_cb (MsdClipboardManager *manager, + Window window, + Bool is_start, + long mask, + void *cb_data) +{ + GdkWindow *gdkwin; + GdkDisplay *display; + + display = gdk_display_get_default (); + gdkwin = gdk_window_lookup_for_display (display, window); + + if (is_start) { + if (gdkwin == NULL) { + gdkwin = gdk_window_foreign_new_for_display (display, window); + } else { + g_object_ref (gdkwin); + } + + gdk_window_add_filter (gdkwin, + (GdkFilterFunc)clipboard_manager_event_filter, + manager); + } else { + if (gdkwin == NULL) { + return; + } + gdk_window_remove_filter (gdkwin, + (GdkFilterFunc)clipboard_manager_event_filter, + manager); + g_object_unref (gdkwin); + } +} + +static gboolean +start_clipboard_idle_cb (MsdClipboardManager *manager) +{ + XClientMessageEvent xev; + + + mate_settings_profile_start (NULL); + + init_atoms (manager->priv->display); + + /* check if there is a clipboard manager running */ + if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER)) { + g_warning ("Clipboard manager is already running."); + return FALSE; + } + + manager->priv->contents = NULL; + manager->priv->conversions = NULL; + manager->priv->requestor = None; + + manager->priv->window = XCreateSimpleWindow (manager->priv->display, + DefaultRootWindow (manager->priv->display), + 0, 0, 10, 10, 0, + WhitePixel (manager->priv->display, + DefaultScreen (manager->priv->display)), + WhitePixel (manager->priv->display, + DefaultScreen (manager->priv->display))); + clipboard_manager_watch_cb (manager, + manager->priv->window, + True, + PropertyChangeMask, + NULL); + XSelectInput (manager->priv->display, + manager->priv->window, + PropertyChangeMask); + manager->priv->timestamp = get_server_time (manager->priv->display, manager->priv->window); + + XSetSelectionOwner (manager->priv->display, + XA_CLIPBOARD_MANAGER, + manager->priv->window, + manager->priv->timestamp); + + /* Check to see if we managed to claim the selection. If not, + * we treat it as if we got it then immediately lost it + */ + if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER) == manager->priv->window) { + xev.type = ClientMessage; + xev.window = DefaultRootWindow (manager->priv->display); + xev.message_type = XA_MANAGER; + xev.format = 32; + xev.data.l[0] = manager->priv->timestamp; + xev.data.l[1] = XA_CLIPBOARD_MANAGER; + xev.data.l[2] = manager->priv->window; + xev.data.l[3] = 0; /* manager specific data */ + xev.data.l[4] = 0; /* manager specific data */ + + XSendEvent (manager->priv->display, + DefaultRootWindow (manager->priv->display), + False, + StructureNotifyMask, + (XEvent *)&xev); + } else { + clipboard_manager_watch_cb (manager, + manager->priv->window, + False, + 0, + NULL); + /* FIXME: manager->priv->terminate (manager->priv->cb_data); */ + } + + mate_settings_profile_end (NULL); + + return FALSE; +} + +gboolean +msd_clipboard_manager_start (MsdClipboardManager *manager, + GError **error) +{ + mate_settings_profile_start (NULL); + + g_idle_add ((GSourceFunc) start_clipboard_idle_cb, manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_clipboard_manager_stop (MsdClipboardManager *manager) +{ + g_debug ("Stopping clipboard manager"); + + clipboard_manager_watch_cb (manager, + manager->priv->window, + FALSE, + 0, + NULL); + XDestroyWindow (manager->priv->display, manager->priv->window); + + list_foreach (manager->priv->conversions, (Callback) conversion_free, NULL); + list_free (manager->priv->conversions); + + list_foreach (manager->priv->contents, (Callback) target_data_unref, NULL); + list_free (manager->priv->contents); +} + +static void +msd_clipboard_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdClipboardManager *self; + + self = MSD_CLIPBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_clipboard_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdClipboardManager *self; + + self = MSD_CLIPBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_clipboard_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdClipboardManager *clipboard_manager; + MsdClipboardManagerClass *klass; + + klass = MSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_CLIPBOARD_MANAGER)); + + clipboard_manager = MSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (clipboard_manager); +} + +static void +msd_clipboard_manager_dispose (GObject *object) +{ + MsdClipboardManager *clipboard_manager; + + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); + + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->dispose (object); +} + +static void +msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_clipboard_manager_get_property; + object_class->set_property = msd_clipboard_manager_set_property; + object_class->constructor = msd_clipboard_manager_constructor; + object_class->dispose = msd_clipboard_manager_dispose; + object_class->finalize = msd_clipboard_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdClipboardManagerPrivate)); +} + +static void +msd_clipboard_manager_init (MsdClipboardManager *manager) +{ + manager->priv = MSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); + + manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + +} + +static void +msd_clipboard_manager_finalize (GObject *object) +{ + MsdClipboardManager *clipboard_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_CLIPBOARD_MANAGER (object)); + + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); + + g_return_if_fail (clipboard_manager->priv != NULL); + + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->finalize (object); +} + +MsdClipboardManager * +msd_clipboard_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_CLIPBOARD_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_CLIPBOARD_MANAGER (manager_object); +} diff --git a/plugins/clipboard/msd-clipboard-manager.h b/plugins/clipboard/msd-clipboard-manager.h new file mode 100644 index 0000000..e4af711 --- /dev/null +++ b/plugins/clipboard/msd-clipboard-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_CLIPBOARD_MANAGER_H +#define __MSD_CLIPBOARD_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_CLIPBOARD_MANAGER (msd_clipboard_manager_get_type ()) +#define MSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManager)) +#define MSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) +#define MSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) + +typedef struct MsdClipboardManagerPrivate MsdClipboardManagerPrivate; + +typedef struct +{ + GObject parent; + MsdClipboardManagerPrivate *priv; +} MsdClipboardManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdClipboardManagerClass; + +GType msd_clipboard_manager_get_type (void); + +MsdClipboardManager * msd_clipboard_manager_new (void); +gboolean msd_clipboard_manager_start (MsdClipboardManager *manager, + GError **error); +void msd_clipboard_manager_stop (MsdClipboardManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_CLIPBOARD_MANAGER_H */ diff --git a/plugins/clipboard/msd-clipboard-plugin.c b/plugins/clipboard/msd-clipboard-plugin.c new file mode 100644 index 0000000..6674265 --- /dev/null +++ b/plugins/clipboard/msd-clipboard-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-clipboard-plugin.h" +#include "msd-clipboard-manager.h" + +struct MsdClipboardPluginPrivate { + MsdClipboardManager *manager; +}; + +#define MSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdClipboardPlugin, msd_clipboard_plugin) + +static void +msd_clipboard_plugin_init (MsdClipboardPlugin *plugin) +{ + plugin->priv = MSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdClipboardPlugin initializing"); + + plugin->priv->manager = msd_clipboard_manager_new (); +} + +static void +msd_clipboard_plugin_finalize (GObject *object) +{ + MsdClipboardPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_CLIPBOARD_PLUGIN (object)); + + g_debug ("MsdClipboardPlugin finalizing"); + + plugin = MSD_CLIPBOARD_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_clipboard_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating clipboard plugin"); + + error = NULL; + res = msd_clipboard_manager_start (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start clipboard manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating clipboard plugin"); + msd_clipboard_manager_stop (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); +} + +static void +msd_clipboard_plugin_class_init (MsdClipboardPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_clipboard_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdClipboardPluginPrivate)); +} diff --git a/plugins/clipboard/msd-clipboard-plugin.h b/plugins/clipboard/msd-clipboard-plugin.h new file mode 100644 index 0000000..7b2ea1e --- /dev/null +++ b/plugins/clipboard/msd-clipboard-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_CLIPBOARD_PLUGIN_H__ +#define __MSD_CLIPBOARD_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_CLIPBOARD_PLUGIN (msd_clipboard_plugin_get_type ()) +#define MSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPlugin)) +#define MSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) +#define MSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) + +typedef struct MsdClipboardPluginPrivate MsdClipboardPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdClipboardPluginPrivate *priv; +} MsdClipboardPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdClipboardPluginClass; + +GType msd_clipboard_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_CLIPBOARD_PLUGIN_H__ */ diff --git a/plugins/common/gsd-keygrab.c b/plugins/common/gsd-keygrab.c deleted file mode 100644 index 7a16f4e..0000000 --- a/plugins/common/gsd-keygrab.c +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2001-2003 Bastien Nocera - * Copyright (C) 2006-2007 William Jon McCann - * Copyright (C) 2008 Jens Granseuer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#ifdef HAVE_X11_EXTENSIONS_XKB_H -#include -#include -#include -#endif - -#include "eggaccelerators.h" - -#include "msd-keygrab.h" - -/* these are the mods whose combinations are ignored by the keygrabbing code */ -static GdkModifierType msd_ignored_mods = 0; - -/* these are the ones we actually use for global keys, we always only check - * for these set */ -static GdkModifierType msd_used_mods = 0; - -static void -setup_modifiers (void) -{ - if (msd_used_mods == 0 || msd_ignored_mods == 0) { - GdkModifierType dynmods; - - /* default modifiers */ - msd_ignored_mods = \ - 0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK; - msd_used_mods = \ - GDK_SHIFT_MASK | GDK_CONTROL_MASK |\ - GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\ - GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK; - - /* NumLock can be assigned to varying keys so we need to - * resolve and ignore it specially */ - dynmods = 0; - egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (), - EGG_VIRTUAL_NUM_LOCK_MASK, - &dynmods); - - msd_ignored_mods |= dynmods; - msd_used_mods &= ~dynmods; - } -} - -static void -grab_key_real (guint keycode, - GdkWindow *root, - gboolean grab, - int mask) -{ - if (grab) { - XGrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - keycode, - mask, - GDK_WINDOW_XID (root), - True, - GrabModeAsync, - GrabModeAsync); - } else { - XUngrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - keycode, - mask, - GDK_WINDOW_XID (root)); - } -} - -/* Grab the key. In order to ignore MSD_IGNORED_MODS we need to grab - * all combinations of the ignored modifiers and those actually used - * for the binding (if any). - * - * inspired by all_combinations from mate-panel/mate-panel/global-keys.c - * - * This may generate X errors. The correct way to use this is like: - * - * gdk_error_trap_push (); - * - * grab_key_unsafe (key, grab, screens); - * - * gdk_flush (); - * if (gdk_error_trap_pop ()) - * g_warning ("Grab failed, another application may already have access to key '%u'", - * key->keycode); - * - * This is not done in the function itself, to allow doing multiple grab_key - * operations with one flush only. - */ -#define N_BITS 32 -void -grab_key_unsafe (Key *key, - gboolean grab, - GSList *screens) -{ - int indexes[N_BITS]; /* indexes of bits we need to flip */ - int i; - int bit; - int bits_set_cnt; - int uppervalue; - guint mask; - - setup_modifiers (); - - mask = msd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; - - bit = 0; - /* store the indexes of all set bits in mask in the array */ - for (i = 0; mask; ++i, mask >>= 1) { - if (mask & 0x1) { - indexes[bit++] = i; - } - } - - bits_set_cnt = bit; - - uppervalue = 1 << bits_set_cnt; - /* grab all possible modifier combinations for our mask */ - for (i = 0; i < uppervalue; ++i) { - GSList *l; - int j; - int result = 0; - - /* map bits in the counter to those in the mask */ - for (j = 0; j < bits_set_cnt; ++j) { - if (i & (1 << j)) { - result |= (1 << indexes[j]); - } - } - - for (l = screens; l; l = l->next) { - GdkScreen *screen = l->data; - guint *code; - - for (code = key->keycodes; *code; ++code) { - grab_key_real (*code, - gdk_screen_get_root_window (screen), - grab, - result | key->state); - } - } - } -} - -static gboolean -have_xkb (Display *dpy) -{ - static int have_xkb = -1; - - if (have_xkb == -1) { -#ifdef HAVE_X11_EXTENSIONS_XKB_H - int opcode, error_base, major, minor, xkb_event_base; - - have_xkb = XkbQueryExtension (dpy, - &opcode, - &xkb_event_base, - &error_base, - &major, - &minor) - && XkbUseExtension (dpy, &major, &minor); -#else - have_xkb = 0; -#endif - } - - return have_xkb; -} - -gboolean -key_uses_keycode (const Key *key, guint keycode) -{ - if (key->keycodes != NULL) { - guint *c; - - for (c = key->keycodes; *c; ++c) { - if (*c == keycode) - return TRUE; - } - } - return FALSE; -} - -gboolean -match_key (Key *key, XEvent *event) -{ - guint keyval; - GdkModifierType consumed; - gint group; - - if (key == NULL) - return FALSE; - - setup_modifiers (); - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - if (have_xkb (event->xkey.display)) - group = XkbGroupForCoreState (event->xkey.state); - else -#endif - group = (event->xkey.state & GDK_Mode_switch) ? 1 : 0; - - /* Check if we find a keysym that matches our current state */ - if (gdk_keymap_translate_keyboard_state (NULL, event->xkey.keycode, - event->xkey.state, group, - &keyval, NULL, NULL, &consumed)) { - guint lower, upper; - - gdk_keyval_convert_case (keyval, &lower, &upper); - - /* If we are checking against the lower version of the - * keysym, we might need the Shift state for matching, - * so remove it from the consumed modifiers */ - if (lower == key->keysym) - consumed &= ~GDK_SHIFT_MASK; - - return ((lower == key->keysym || upper == key->keysym) - && (event->xkey.state & ~consumed & msd_used_mods) == key->state); - } - - /* The key we passed doesn't have a keysym, so try with just the keycode */ - return (key != NULL - && key->state == (event->xkey.state & msd_used_mods) - && key_uses_keycode (key, event->xkey.keycode)); -} diff --git a/plugins/common/gsd-keygrab.h b/plugins/common/gsd-keygrab.h deleted file mode 100644 index 8ebef21..0000000 --- a/plugins/common/gsd-keygrab.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Jens Granseuer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __MSD_COMMON_KEYGRAB_H -#define __MSD_COMMON_KEYGRAB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct { - guint keysym; - guint state; - guint *keycodes; -} Key; - - -void grab_key_unsafe (Key *key, - gboolean grab, - GSList *screens); - -gboolean match_key (Key *key, - XEvent *event); - -gboolean key_uses_keycode (const Key *key, - guint keycode); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_COMMON_KEYGRAB_H */ diff --git a/plugins/common/gsd-osd-window.c b/plugins/common/gsd-osd-window.c deleted file mode 100644 index 123313c..0000000 --- a/plugins/common/gsd-osd-window.c +++ /dev/null @@ -1,573 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * On-screen-display (OSD) window for mate-settings-daemon's plugins - * - * Copyright (C) 2006-2007 William Jon McCann - * Copyright (C) 2009 Novell, Inc - * - * Authors: - * William Jon McCann - * Federico Mena-Quintero - * - * This program 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 2, or (at your option) any later version. - * - * This program 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 this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "msd-osd-window.h" - -#define DIALOG_TIMEOUT 2000 /* dialog timeout in ms */ -#define DIALOG_FADE_TIMEOUT 1500 /* timeout before fade starts */ -#define FADE_TIMEOUT 10 /* timeout in ms between each frame of the fade */ - -#define BG_ALPHA 0.75 - -#define MSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_OSD_WINDOW, MsdOsdWindowPrivate)) - -struct MsdOsdWindowPrivate -{ - guint is_composited : 1; - guint hide_timeout_id; - guint fade_timeout_id; - double fade_out_alpha; -}; - -enum { - EXPOSE_WHEN_COMPOSITED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (MsdOsdWindow, msd_osd_window, GTK_TYPE_WINDOW) - -static gboolean -fade_timeout (MsdOsdWindow *window) -{ - if (window->priv->fade_out_alpha <= 0.0) { - gtk_widget_hide (GTK_WIDGET (window)); - - /* Reset it for the next time */ - window->priv->fade_out_alpha = 1.0; - window->priv->fade_timeout_id = 0; - - return FALSE; - } else { - GdkRectangle rect; - GtkWidget *win = GTK_WIDGET (window); - GtkAllocation allocation; - - window->priv->fade_out_alpha -= 0.10; - - rect.x = 0; - rect.y = 0; - gtk_widget_get_allocation (win, &allocation); - rect.width = allocation.width; - rect.height = allocation.height; - - gtk_widget_realize (win); - gdk_window_invalidate_rect (gtk_widget_get_window (win), &rect, FALSE); - } - - return TRUE; -} - -static gboolean -hide_timeout (MsdOsdWindow *window) -{ - if (window->priv->is_composited) { - window->priv->hide_timeout_id = 0; - window->priv->fade_timeout_id = g_timeout_add (FADE_TIMEOUT, - (GSourceFunc) fade_timeout, - window); - } else { - gtk_widget_hide (GTK_WIDGET (window)); - } - - return FALSE; -} - -static void -remove_hide_timeout (MsdOsdWindow *window) -{ - if (window->priv->hide_timeout_id != 0) { - g_source_remove (window->priv->hide_timeout_id); - window->priv->hide_timeout_id = 0; - } - - if (window->priv->fade_timeout_id != 0) { - g_source_remove (window->priv->fade_timeout_id); - window->priv->fade_timeout_id = 0; - window->priv->fade_out_alpha = 1.0; - } -} - -static void -add_hide_timeout (MsdOsdWindow *window) -{ - int timeout; - - if (window->priv->is_composited) { - timeout = DIALOG_FADE_TIMEOUT; - } else { - timeout = DIALOG_TIMEOUT; - } - window->priv->hide_timeout_id = g_timeout_add (timeout, - (GSourceFunc) hide_timeout, - window); -} - -void -msd_osd_window_draw_rounded_rectangle (cairo_t* cr, - gdouble aspect, - gdouble x, - gdouble y, - gdouble corner_radius, - gdouble width, - gdouble height) -{ - gdouble radius = corner_radius / aspect; - - cairo_move_to (cr, x + radius, y); - - cairo_line_to (cr, - x + width - radius, - y); - cairo_arc (cr, - x + width - radius, - y + radius, - radius, - -90.0f * G_PI / 180.0f, - 0.0f * G_PI / 180.0f); - cairo_line_to (cr, - x + width, - y + height - radius); - cairo_arc (cr, - x + width - radius, - y + height - radius, - radius, - 0.0f * G_PI / 180.0f, - 90.0f * G_PI / 180.0f); - cairo_line_to (cr, - x + radius, - y + height); - cairo_arc (cr, - x + radius, - y + height - radius, - radius, - 90.0f * G_PI / 180.0f, - 180.0f * G_PI / 180.0f); - cairo_line_to (cr, - x, - y + radius); - cairo_arc (cr, - x + radius, - y + radius, - radius, - 180.0f * G_PI / 180.0f, - 270.0f * G_PI / 180.0f); - cairo_close_path (cr); -} - -void -msd_osd_window_color_reverse (const GdkColor *a, - GdkColor *b) -{ - gdouble red; - gdouble green; - gdouble blue; - gdouble h; - gdouble s; - gdouble v; - - red = (gdouble) a->red / 65535.0; - green = (gdouble) a->green / 65535.0; - blue = (gdouble) a->blue / 65535.0; - - gtk_rgb_to_hsv (red, green, blue, &h, &s, &v); - - v = 0.5 + (0.5 - v); - if (v > 1.0) - v = 1.0; - else if (v < 0.0) - v = 0.0; - - gtk_hsv_to_rgb (h, s, v, &red, &green, &blue); - - b->red = red * 65535.0; - b->green = green * 65535.0; - b->blue = blue * 65535.0; -} - -/* This is our expose-event handler when the window is in a compositing manager. - * We draw everything by hand, using Cairo, so that we can have a nice - * transparent/rounded look. - */ -static void -expose_when_composited (GtkWidget *widget, GdkEventExpose *event) -{ - MsdOsdWindow *window; - cairo_t *context; - cairo_t *cr; - cairo_surface_t *surface; - int width; - int height; - GtkStyle *style; - GdkColor color; - double r, g, b; - - window = MSD_OSD_WINDOW (widget); - - context = gdk_cairo_create (gtk_widget_get_window (widget)); - - style = gtk_widget_get_style (widget); - cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); - gtk_window_get_size (GTK_WINDOW (widget), &width, &height); - - surface = cairo_surface_create_similar (cairo_get_target (context), - CAIRO_CONTENT_COLOR_ALPHA, - width, - height); - - if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { - goto done; - } - - cr = cairo_create (surface); - if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { - goto done; - } - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); - cairo_set_operator (cr, CAIRO_OPERATOR_OVER); - cairo_paint (cr); - - /* draw a box */ - msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); - msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); - r = (float)color.red / 65535.0; - g = (float)color.green / 65535.0; - b = (float)color.blue / 65535.0; - cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); - cairo_fill_preserve (cr); - - msd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); - r = (float)color.red / 65535.0; - g = (float)color.green / 65535.0; - b = (float)color.blue / 65535.0; - cairo_set_source_rgba (cr, r, g, b, BG_ALPHA / 2); - cairo_set_line_width (cr, 1); - cairo_stroke (cr); - - g_signal_emit (window, signals[EXPOSE_WHEN_COMPOSITED], 0, cr); - - cairo_destroy (cr); - - /* Make sure we have a transparent background */ - cairo_rectangle (context, 0, 0, width, height); - cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); - cairo_fill (context); - - cairo_set_source_surface (context, surface, 0, 0); - cairo_paint_with_alpha (context, window->priv->fade_out_alpha); - - done: - if (surface != NULL) { - cairo_surface_destroy (surface); - } - cairo_destroy (context); -} - -/* This is our expose-event handler when the window is *not* in a compositing manager. - * We just draw a rectangular frame by hand. We do this with hardcoded drawing code, - * instead of GtkFrame, to avoid changing the window's internal widget hierarchy: in - * either case (composited or non-composited), callers can assume that this works - * identically to a GtkWindow without any intermediate widgetry. - */ -static void -expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) -{ - MsdOsdWindow *window; - GtkAllocation allocation; - - window = MSD_OSD_WINDOW (widget); - - gtk_widget_get_allocation (widget, &allocation); - - gtk_paint_shadow (gtk_widget_get_style (widget), - gtk_widget_get_window (widget), - gtk_widget_get_state (widget), - GTK_SHADOW_OUT, - &event->area, - widget, - NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ - 0, - 0, - allocation.width, - allocation.height); -} - -static gboolean -msd_osd_window_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - MsdOsdWindow *window; - GtkWidget *child; - - window = MSD_OSD_WINDOW (widget); - - if (window->priv->is_composited) - expose_when_composited (widget, event); - else - expose_when_not_composited (widget, event); - - child = gtk_bin_get_child (GTK_BIN (window)); - if (child) - gtk_container_propagate_expose (GTK_CONTAINER (window), child, event); - - return FALSE; -} - -static void -msd_osd_window_real_show (GtkWidget *widget) -{ - MsdOsdWindow *window; - - if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show) { - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show (widget); - } - - window = MSD_OSD_WINDOW (widget); - remove_hide_timeout (window); - add_hide_timeout (window); -} - -static void -msd_osd_window_real_hide (GtkWidget *widget) -{ - MsdOsdWindow *window; - - if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide) { - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide (widget); - } - - window = MSD_OSD_WINDOW (widget); - remove_hide_timeout (window); -} - -static void -msd_osd_window_real_realize (GtkWidget *widget) -{ - GdkColormap *colormap; - GtkAllocation allocation; - GdkBitmap *mask; - cairo_t *cr; - - colormap = gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)); - - if (colormap != NULL) { - gtk_widget_set_colormap (widget, colormap); - } - - if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); - } - - gtk_widget_get_allocation (widget, &allocation); - mask = gdk_pixmap_new (gtk_widget_get_window (widget), - allocation.width, - allocation.height, - 1); - cr = gdk_cairo_create (mask); - - cairo_set_source_rgba (cr, 1., 1., 1., 0.); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_paint (cr); - - /* make the whole window ignore events */ - gdk_window_input_shape_combine_mask (gtk_widget_get_window (widget), mask, 0, 0); - g_object_unref (mask); - cairo_destroy (cr); -} - -static void -msd_osd_window_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - GtkStyle *style; - - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->style_set (widget, previous_style); - - /* We set our border width to 12 (per the MATE standard), plus the - * thickness of the frame that we draw in our expose handler. This will - * make our child be 12 pixels away from the frame. - */ - - style = gtk_widget_get_style (widget); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12 + MAX (style->xthickness, style->ythickness)); -} - -static void -msd_osd_window_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - GtkStyle *style; - - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->size_request (widget, requisition); - - /* See the comment in msd_osd_window_style_set() for why we add the thickness here */ - - style = gtk_widget_get_style (widget); - - requisition->width += style->xthickness; - requisition->height += style->ythickness; -} - -static GObject * -msd_osd_window_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_params) -{ - GObject *object; - - object = G_OBJECT_CLASS (msd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); - - g_object_set (object, - "type", GTK_WINDOW_POPUP, - "type-hint", GDK_WINDOW_TYPE_HINT_NOTIFICATION, - "skip-taskbar-hint", TRUE, - "skip-pager-hint", TRUE, - "focus-on-map", FALSE, - NULL); - - return object; -} - -static void -msd_osd_window_class_init (MsdOsdWindowClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - gobject_class->constructor = msd_osd_window_constructor; - - widget_class->show = msd_osd_window_real_show; - widget_class->hide = msd_osd_window_real_hide; - widget_class->realize = msd_osd_window_real_realize; - widget_class->style_set = msd_osd_window_style_set; - widget_class->size_request = msd_osd_window_size_request; - widget_class->expose_event = msd_osd_window_expose_event; - - signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("expose-when-composited", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (MsdOsdWindowClass, expose_when_composited), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - g_type_class_add_private (klass, sizeof (MsdOsdWindowPrivate)); -} - -/** - * msd_osd_window_is_composited: - * @window: a #MsdOsdWindow - * - * Return value: whether the window was created on a composited screen. - */ -gboolean -msd_osd_window_is_composited (MsdOsdWindow *window) -{ - return window->priv->is_composited; -} - -/** - * msd_osd_window_is_valid: - * @window: a #MsdOsdWindow - * - * Return value: TRUE if the @window's idea of being composited matches whether - * its current screen is actually composited. - */ -gboolean -msd_osd_window_is_valid (MsdOsdWindow *window) -{ - GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window)); - return gdk_screen_is_composited (screen) == window->priv->is_composited; -} - -static void -msd_osd_window_init (MsdOsdWindow *window) -{ - GdkScreen *screen; - - window->priv = MSD_OSD_WINDOW_GET_PRIVATE (window); - - screen = gtk_widget_get_screen (GTK_WIDGET (window)); - - window->priv->is_composited = gdk_screen_is_composited (screen); - - if (window->priv->is_composited) { - gdouble scalew, scaleh, scale; - gint size; - - gtk_window_set_decorated (GTK_WINDOW (window), FALSE); - gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); - - /* assume 130x130 on a 640x480 display and scale from there */ - scalew = gdk_screen_get_width (screen) / 640.0; - scaleh = gdk_screen_get_height (screen) / 480.0; - scale = MIN (scalew, scaleh); - size = 130 * MAX (1, scale); - - gtk_window_set_default_size (GTK_WINDOW (window), size, size); - - window->priv->fade_out_alpha = 1.0; - } else { - gtk_container_set_border_width (GTK_CONTAINER (window), 12); - } -} - -GtkWidget * -msd_osd_window_new (void) -{ - return g_object_new (MSD_TYPE_OSD_WINDOW, NULL); -} - -/** - * msd_osd_window_update_and_hide: - * @window: a #MsdOsdWindow - * - * Queues the @window for immediate drawing, and queues a timer to hide the window. - */ -void -msd_osd_window_update_and_hide (MsdOsdWindow *window) -{ - remove_hide_timeout (window); - add_hide_timeout (window); - - if (window->priv->is_composited) { - gtk_widget_queue_draw (GTK_WIDGET (window)); - } -} diff --git a/plugins/common/gsd-osd-window.h b/plugins/common/gsd-osd-window.h deleted file mode 100644 index f539e5e..0000000 --- a/plugins/common/gsd-osd-window.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- - * - * On-screen-display (OSD) window for mate-settings-daemon's plugins - * - * Copyright (C) 2006 William Jon McCann - * Copyright (C) 2009 Novell, Inc - * - * Authors: - * William Jon McCann - * Federico Mena-Quintero - * - * This program 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 2, or (at your option) any later version. - * - * This program 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 this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -/* MsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, - * semi-transparent, curved popup that appears when you press a hotkey global to - * the desktop, such as to change the volume, switch your monitor's parameters, - * etc. - * - * You can create a MsdOsdWindow and use it as a normal GtkWindow. It will - * automatically center itself, figure out if it needs to be composited, etc. - * Just pack your widgets in it, sit back, and enjoy the ride. - */ - -#ifndef MSD_OSD_WINDOW_H -#define MSD_OSD_WINDOW_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Alpha value to be used for foreground objects drawn in an OSD window */ -#define MSD_OSD_WINDOW_FG_ALPHA 1.0 - -#define MSD_TYPE_OSD_WINDOW (msd_osd_window_get_type ()) -#define MSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindow)) -#define MSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) -#define MSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_OSD_WINDOW)) -#define MSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_OSD_WINDOW)) -#define MSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) - -typedef struct MsdOsdWindow MsdOsdWindow; -typedef struct MsdOsdWindowClass MsdOsdWindowClass; -typedef struct MsdOsdWindowPrivate MsdOsdWindowPrivate; - -struct MsdOsdWindow { - GtkWindow parent; - - MsdOsdWindowPrivate *priv; -}; - -struct MsdOsdWindowClass { - GtkWindowClass parent_class; - - void (* expose_when_composited) (MsdOsdWindow *window, cairo_t *cr); -}; - -GType msd_osd_window_get_type (void); - -GtkWidget * msd_osd_window_new (void); -gboolean msd_osd_window_is_composited (MsdOsdWindow *window); -gboolean msd_osd_window_is_valid (MsdOsdWindow *window); -void msd_osd_window_update_and_hide (MsdOsdWindow *window); - -void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, - gdouble aspect, - gdouble x, - gdouble y, - gdouble corner_radius, - gdouble width, - gdouble height); - -void msd_osd_window_color_reverse (const GdkColor *a, - GdkColor *b); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/plugins/common/msd-keygrab.c b/plugins/common/msd-keygrab.c new file mode 100644 index 0000000..7a16f4e --- /dev/null +++ b/plugins/common/msd-keygrab.c @@ -0,0 +1,246 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2001-2003 Bastien Nocera + * Copyright (C) 2006-2007 William Jon McCann + * Copyright (C) 2008 Jens Granseuer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#ifdef HAVE_X11_EXTENSIONS_XKB_H +#include +#include +#include +#endif + +#include "eggaccelerators.h" + +#include "msd-keygrab.h" + +/* these are the mods whose combinations are ignored by the keygrabbing code */ +static GdkModifierType msd_ignored_mods = 0; + +/* these are the ones we actually use for global keys, we always only check + * for these set */ +static GdkModifierType msd_used_mods = 0; + +static void +setup_modifiers (void) +{ + if (msd_used_mods == 0 || msd_ignored_mods == 0) { + GdkModifierType dynmods; + + /* default modifiers */ + msd_ignored_mods = \ + 0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK; + msd_used_mods = \ + GDK_SHIFT_MASK | GDK_CONTROL_MASK |\ + GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\ + GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK; + + /* NumLock can be assigned to varying keys so we need to + * resolve and ignore it specially */ + dynmods = 0; + egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (), + EGG_VIRTUAL_NUM_LOCK_MASK, + &dynmods); + + msd_ignored_mods |= dynmods; + msd_used_mods &= ~dynmods; + } +} + +static void +grab_key_real (guint keycode, + GdkWindow *root, + gboolean grab, + int mask) +{ + if (grab) { + XGrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + keycode, + mask, + GDK_WINDOW_XID (root), + True, + GrabModeAsync, + GrabModeAsync); + } else { + XUngrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + keycode, + mask, + GDK_WINDOW_XID (root)); + } +} + +/* Grab the key. In order to ignore MSD_IGNORED_MODS we need to grab + * all combinations of the ignored modifiers and those actually used + * for the binding (if any). + * + * inspired by all_combinations from mate-panel/mate-panel/global-keys.c + * + * This may generate X errors. The correct way to use this is like: + * + * gdk_error_trap_push (); + * + * grab_key_unsafe (key, grab, screens); + * + * gdk_flush (); + * if (gdk_error_trap_pop ()) + * g_warning ("Grab failed, another application may already have access to key '%u'", + * key->keycode); + * + * This is not done in the function itself, to allow doing multiple grab_key + * operations with one flush only. + */ +#define N_BITS 32 +void +grab_key_unsafe (Key *key, + gboolean grab, + GSList *screens) +{ + int indexes[N_BITS]; /* indexes of bits we need to flip */ + int i; + int bit; + int bits_set_cnt; + int uppervalue; + guint mask; + + setup_modifiers (); + + mask = msd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; + + bit = 0; + /* store the indexes of all set bits in mask in the array */ + for (i = 0; mask; ++i, mask >>= 1) { + if (mask & 0x1) { + indexes[bit++] = i; + } + } + + bits_set_cnt = bit; + + uppervalue = 1 << bits_set_cnt; + /* grab all possible modifier combinations for our mask */ + for (i = 0; i < uppervalue; ++i) { + GSList *l; + int j; + int result = 0; + + /* map bits in the counter to those in the mask */ + for (j = 0; j < bits_set_cnt; ++j) { + if (i & (1 << j)) { + result |= (1 << indexes[j]); + } + } + + for (l = screens; l; l = l->next) { + GdkScreen *screen = l->data; + guint *code; + + for (code = key->keycodes; *code; ++code) { + grab_key_real (*code, + gdk_screen_get_root_window (screen), + grab, + result | key->state); + } + } + } +} + +static gboolean +have_xkb (Display *dpy) +{ + static int have_xkb = -1; + + if (have_xkb == -1) { +#ifdef HAVE_X11_EXTENSIONS_XKB_H + int opcode, error_base, major, minor, xkb_event_base; + + have_xkb = XkbQueryExtension (dpy, + &opcode, + &xkb_event_base, + &error_base, + &major, + &minor) + && XkbUseExtension (dpy, &major, &minor); +#else + have_xkb = 0; +#endif + } + + return have_xkb; +} + +gboolean +key_uses_keycode (const Key *key, guint keycode) +{ + if (key->keycodes != NULL) { + guint *c; + + for (c = key->keycodes; *c; ++c) { + if (*c == keycode) + return TRUE; + } + } + return FALSE; +} + +gboolean +match_key (Key *key, XEvent *event) +{ + guint keyval; + GdkModifierType consumed; + gint group; + + if (key == NULL) + return FALSE; + + setup_modifiers (); + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + if (have_xkb (event->xkey.display)) + group = XkbGroupForCoreState (event->xkey.state); + else +#endif + group = (event->xkey.state & GDK_Mode_switch) ? 1 : 0; + + /* Check if we find a keysym that matches our current state */ + if (gdk_keymap_translate_keyboard_state (NULL, event->xkey.keycode, + event->xkey.state, group, + &keyval, NULL, NULL, &consumed)) { + guint lower, upper; + + gdk_keyval_convert_case (keyval, &lower, &upper); + + /* If we are checking against the lower version of the + * keysym, we might need the Shift state for matching, + * so remove it from the consumed modifiers */ + if (lower == key->keysym) + consumed &= ~GDK_SHIFT_MASK; + + return ((lower == key->keysym || upper == key->keysym) + && (event->xkey.state & ~consumed & msd_used_mods) == key->state); + } + + /* The key we passed doesn't have a keysym, so try with just the keycode */ + return (key != NULL + && key->state == (event->xkey.state & msd_used_mods) + && key_uses_keycode (key, event->xkey.keycode)); +} diff --git a/plugins/common/msd-keygrab.h b/plugins/common/msd-keygrab.h new file mode 100644 index 0000000..8ebef21 --- /dev/null +++ b/plugins/common/msd-keygrab.h @@ -0,0 +1,51 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Jens Granseuer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __MSD_COMMON_KEYGRAB_H +#define __MSD_COMMON_KEYGRAB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct { + guint keysym; + guint state; + guint *keycodes; +} Key; + + +void grab_key_unsafe (Key *key, + gboolean grab, + GSList *screens); + +gboolean match_key (Key *key, + XEvent *event); + +gboolean key_uses_keycode (const Key *key, + guint keycode); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_COMMON_KEYGRAB_H */ diff --git a/plugins/common/msd-osd-window.c b/plugins/common/msd-osd-window.c new file mode 100644 index 0000000..123313c --- /dev/null +++ b/plugins/common/msd-osd-window.c @@ -0,0 +1,573 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * On-screen-display (OSD) window for mate-settings-daemon's plugins + * + * Copyright (C) 2006-2007 William Jon McCann + * Copyright (C) 2009 Novell, Inc + * + * Authors: + * William Jon McCann + * Federico Mena-Quintero + * + * This program 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 2, or (at your option) any later version. + * + * This program 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 this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "msd-osd-window.h" + +#define DIALOG_TIMEOUT 2000 /* dialog timeout in ms */ +#define DIALOG_FADE_TIMEOUT 1500 /* timeout before fade starts */ +#define FADE_TIMEOUT 10 /* timeout in ms between each frame of the fade */ + +#define BG_ALPHA 0.75 + +#define MSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_OSD_WINDOW, MsdOsdWindowPrivate)) + +struct MsdOsdWindowPrivate +{ + guint is_composited : 1; + guint hide_timeout_id; + guint fade_timeout_id; + double fade_out_alpha; +}; + +enum { + EXPOSE_WHEN_COMPOSITED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE (MsdOsdWindow, msd_osd_window, GTK_TYPE_WINDOW) + +static gboolean +fade_timeout (MsdOsdWindow *window) +{ + if (window->priv->fade_out_alpha <= 0.0) { + gtk_widget_hide (GTK_WIDGET (window)); + + /* Reset it for the next time */ + window->priv->fade_out_alpha = 1.0; + window->priv->fade_timeout_id = 0; + + return FALSE; + } else { + GdkRectangle rect; + GtkWidget *win = GTK_WIDGET (window); + GtkAllocation allocation; + + window->priv->fade_out_alpha -= 0.10; + + rect.x = 0; + rect.y = 0; + gtk_widget_get_allocation (win, &allocation); + rect.width = allocation.width; + rect.height = allocation.height; + + gtk_widget_realize (win); + gdk_window_invalidate_rect (gtk_widget_get_window (win), &rect, FALSE); + } + + return TRUE; +} + +static gboolean +hide_timeout (MsdOsdWindow *window) +{ + if (window->priv->is_composited) { + window->priv->hide_timeout_id = 0; + window->priv->fade_timeout_id = g_timeout_add (FADE_TIMEOUT, + (GSourceFunc) fade_timeout, + window); + } else { + gtk_widget_hide (GTK_WIDGET (window)); + } + + return FALSE; +} + +static void +remove_hide_timeout (MsdOsdWindow *window) +{ + if (window->priv->hide_timeout_id != 0) { + g_source_remove (window->priv->hide_timeout_id); + window->priv->hide_timeout_id = 0; + } + + if (window->priv->fade_timeout_id != 0) { + g_source_remove (window->priv->fade_timeout_id); + window->priv->fade_timeout_id = 0; + window->priv->fade_out_alpha = 1.0; + } +} + +static void +add_hide_timeout (MsdOsdWindow *window) +{ + int timeout; + + if (window->priv->is_composited) { + timeout = DIALOG_FADE_TIMEOUT; + } else { + timeout = DIALOG_TIMEOUT; + } + window->priv->hide_timeout_id = g_timeout_add (timeout, + (GSourceFunc) hide_timeout, + window); +} + +void +msd_osd_window_draw_rounded_rectangle (cairo_t* cr, + gdouble aspect, + gdouble x, + gdouble y, + gdouble corner_radius, + gdouble width, + gdouble height) +{ + gdouble radius = corner_radius / aspect; + + cairo_move_to (cr, x + radius, y); + + cairo_line_to (cr, + x + width - radius, + y); + cairo_arc (cr, + x + width - radius, + y + radius, + radius, + -90.0f * G_PI / 180.0f, + 0.0f * G_PI / 180.0f); + cairo_line_to (cr, + x + width, + y + height - radius); + cairo_arc (cr, + x + width - radius, + y + height - radius, + radius, + 0.0f * G_PI / 180.0f, + 90.0f * G_PI / 180.0f); + cairo_line_to (cr, + x + radius, + y + height); + cairo_arc (cr, + x + radius, + y + height - radius, + radius, + 90.0f * G_PI / 180.0f, + 180.0f * G_PI / 180.0f); + cairo_line_to (cr, + x, + y + radius); + cairo_arc (cr, + x + radius, + y + radius, + radius, + 180.0f * G_PI / 180.0f, + 270.0f * G_PI / 180.0f); + cairo_close_path (cr); +} + +void +msd_osd_window_color_reverse (const GdkColor *a, + GdkColor *b) +{ + gdouble red; + gdouble green; + gdouble blue; + gdouble h; + gdouble s; + gdouble v; + + red = (gdouble) a->red / 65535.0; + green = (gdouble) a->green / 65535.0; + blue = (gdouble) a->blue / 65535.0; + + gtk_rgb_to_hsv (red, green, blue, &h, &s, &v); + + v = 0.5 + (0.5 - v); + if (v > 1.0) + v = 1.0; + else if (v < 0.0) + v = 0.0; + + gtk_hsv_to_rgb (h, s, v, &red, &green, &blue); + + b->red = red * 65535.0; + b->green = green * 65535.0; + b->blue = blue * 65535.0; +} + +/* This is our expose-event handler when the window is in a compositing manager. + * We draw everything by hand, using Cairo, so that we can have a nice + * transparent/rounded look. + */ +static void +expose_when_composited (GtkWidget *widget, GdkEventExpose *event) +{ + MsdOsdWindow *window; + cairo_t *context; + cairo_t *cr; + cairo_surface_t *surface; + int width; + int height; + GtkStyle *style; + GdkColor color; + double r, g, b; + + window = MSD_OSD_WINDOW (widget); + + context = gdk_cairo_create (gtk_widget_get_window (widget)); + + style = gtk_widget_get_style (widget); + cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); + gtk_window_get_size (GTK_WINDOW (widget), &width, &height); + + surface = cairo_surface_create_similar (cairo_get_target (context), + CAIRO_CONTENT_COLOR_ALPHA, + width, + height); + + if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { + goto done; + } + + cr = cairo_create (surface); + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { + goto done; + } + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); + cairo_paint (cr); + + /* draw a box */ + msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); + msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); + cairo_fill_preserve (cr); + + msd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + cairo_set_source_rgba (cr, r, g, b, BG_ALPHA / 2); + cairo_set_line_width (cr, 1); + cairo_stroke (cr); + + g_signal_emit (window, signals[EXPOSE_WHEN_COMPOSITED], 0, cr); + + cairo_destroy (cr); + + /* Make sure we have a transparent background */ + cairo_rectangle (context, 0, 0, width, height); + cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); + cairo_fill (context); + + cairo_set_source_surface (context, surface, 0, 0); + cairo_paint_with_alpha (context, window->priv->fade_out_alpha); + + done: + if (surface != NULL) { + cairo_surface_destroy (surface); + } + cairo_destroy (context); +} + +/* This is our expose-event handler when the window is *not* in a compositing manager. + * We just draw a rectangular frame by hand. We do this with hardcoded drawing code, + * instead of GtkFrame, to avoid changing the window's internal widget hierarchy: in + * either case (composited or non-composited), callers can assume that this works + * identically to a GtkWindow without any intermediate widgetry. + */ +static void +expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) +{ + MsdOsdWindow *window; + GtkAllocation allocation; + + window = MSD_OSD_WINDOW (widget); + + gtk_widget_get_allocation (widget, &allocation); + + gtk_paint_shadow (gtk_widget_get_style (widget), + gtk_widget_get_window (widget), + gtk_widget_get_state (widget), + GTK_SHADOW_OUT, + &event->area, + widget, + NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ + 0, + 0, + allocation.width, + allocation.height); +} + +static gboolean +msd_osd_window_expose_event (GtkWidget *widget, + GdkEventExpose *event) +{ + MsdOsdWindow *window; + GtkWidget *child; + + window = MSD_OSD_WINDOW (widget); + + if (window->priv->is_composited) + expose_when_composited (widget, event); + else + expose_when_not_composited (widget, event); + + child = gtk_bin_get_child (GTK_BIN (window)); + if (child) + gtk_container_propagate_expose (GTK_CONTAINER (window), child, event); + + return FALSE; +} + +static void +msd_osd_window_real_show (GtkWidget *widget) +{ + MsdOsdWindow *window; + + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show (widget); + } + + window = MSD_OSD_WINDOW (widget); + remove_hide_timeout (window); + add_hide_timeout (window); +} + +static void +msd_osd_window_real_hide (GtkWidget *widget) +{ + MsdOsdWindow *window; + + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide (widget); + } + + window = MSD_OSD_WINDOW (widget); + remove_hide_timeout (window); +} + +static void +msd_osd_window_real_realize (GtkWidget *widget) +{ + GdkColormap *colormap; + GtkAllocation allocation; + GdkBitmap *mask; + cairo_t *cr; + + colormap = gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)); + + if (colormap != NULL) { + gtk_widget_set_colormap (widget, colormap); + } + + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); + } + + gtk_widget_get_allocation (widget, &allocation); + mask = gdk_pixmap_new (gtk_widget_get_window (widget), + allocation.width, + allocation.height, + 1); + cr = gdk_cairo_create (mask); + + cairo_set_source_rgba (cr, 1., 1., 1., 0.); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr); + + /* make the whole window ignore events */ + gdk_window_input_shape_combine_mask (gtk_widget_get_window (widget), mask, 0, 0); + g_object_unref (mask); + cairo_destroy (cr); +} + +static void +msd_osd_window_style_set (GtkWidget *widget, + GtkStyle *previous_style) +{ + GtkStyle *style; + + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->style_set (widget, previous_style); + + /* We set our border width to 12 (per the MATE standard), plus the + * thickness of the frame that we draw in our expose handler. This will + * make our child be 12 pixels away from the frame. + */ + + style = gtk_widget_get_style (widget); + gtk_container_set_border_width (GTK_CONTAINER (widget), 12 + MAX (style->xthickness, style->ythickness)); +} + +static void +msd_osd_window_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + GtkStyle *style; + + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->size_request (widget, requisition); + + /* See the comment in msd_osd_window_style_set() for why we add the thickness here */ + + style = gtk_widget_get_style (widget); + + requisition->width += style->xthickness; + requisition->height += style->ythickness; +} + +static GObject * +msd_osd_window_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_params) +{ + GObject *object; + + object = G_OBJECT_CLASS (msd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); + + g_object_set (object, + "type", GTK_WINDOW_POPUP, + "type-hint", GDK_WINDOW_TYPE_HINT_NOTIFICATION, + "skip-taskbar-hint", TRUE, + "skip-pager-hint", TRUE, + "focus-on-map", FALSE, + NULL); + + return object; +} + +static void +msd_osd_window_class_init (MsdOsdWindowClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gobject_class->constructor = msd_osd_window_constructor; + + widget_class->show = msd_osd_window_real_show; + widget_class->hide = msd_osd_window_real_hide; + widget_class->realize = msd_osd_window_real_realize; + widget_class->style_set = msd_osd_window_style_set; + widget_class->size_request = msd_osd_window_size_request; + widget_class->expose_event = msd_osd_window_expose_event; + + signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("expose-when-composited", + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (MsdOsdWindowClass, expose_when_composited), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); + + g_type_class_add_private (klass, sizeof (MsdOsdWindowPrivate)); +} + +/** + * msd_osd_window_is_composited: + * @window: a #MsdOsdWindow + * + * Return value: whether the window was created on a composited screen. + */ +gboolean +msd_osd_window_is_composited (MsdOsdWindow *window) +{ + return window->priv->is_composited; +} + +/** + * msd_osd_window_is_valid: + * @window: a #MsdOsdWindow + * + * Return value: TRUE if the @window's idea of being composited matches whether + * its current screen is actually composited. + */ +gboolean +msd_osd_window_is_valid (MsdOsdWindow *window) +{ + GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window)); + return gdk_screen_is_composited (screen) == window->priv->is_composited; +} + +static void +msd_osd_window_init (MsdOsdWindow *window) +{ + GdkScreen *screen; + + window->priv = MSD_OSD_WINDOW_GET_PRIVATE (window); + + screen = gtk_widget_get_screen (GTK_WIDGET (window)); + + window->priv->is_composited = gdk_screen_is_composited (screen); + + if (window->priv->is_composited) { + gdouble scalew, scaleh, scale; + gint size; + + gtk_window_set_decorated (GTK_WINDOW (window), FALSE); + gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); + + /* assume 130x130 on a 640x480 display and scale from there */ + scalew = gdk_screen_get_width (screen) / 640.0; + scaleh = gdk_screen_get_height (screen) / 480.0; + scale = MIN (scalew, scaleh); + size = 130 * MAX (1, scale); + + gtk_window_set_default_size (GTK_WINDOW (window), size, size); + + window->priv->fade_out_alpha = 1.0; + } else { + gtk_container_set_border_width (GTK_CONTAINER (window), 12); + } +} + +GtkWidget * +msd_osd_window_new (void) +{ + return g_object_new (MSD_TYPE_OSD_WINDOW, NULL); +} + +/** + * msd_osd_window_update_and_hide: + * @window: a #MsdOsdWindow + * + * Queues the @window for immediate drawing, and queues a timer to hide the window. + */ +void +msd_osd_window_update_and_hide (MsdOsdWindow *window) +{ + remove_hide_timeout (window); + add_hide_timeout (window); + + if (window->priv->is_composited) { + gtk_widget_queue_draw (GTK_WIDGET (window)); + } +} diff --git a/plugins/common/msd-osd-window.h b/plugins/common/msd-osd-window.h new file mode 100644 index 0000000..f539e5e --- /dev/null +++ b/plugins/common/msd-osd-window.h @@ -0,0 +1,98 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- + * + * On-screen-display (OSD) window for mate-settings-daemon's plugins + * + * Copyright (C) 2006 William Jon McCann + * Copyright (C) 2009 Novell, Inc + * + * Authors: + * William Jon McCann + * Federico Mena-Quintero + * + * This program 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 2, or (at your option) any later version. + * + * This program 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 this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +/* MsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, + * semi-transparent, curved popup that appears when you press a hotkey global to + * the desktop, such as to change the volume, switch your monitor's parameters, + * etc. + * + * You can create a MsdOsdWindow and use it as a normal GtkWindow. It will + * automatically center itself, figure out if it needs to be composited, etc. + * Just pack your widgets in it, sit back, and enjoy the ride. + */ + +#ifndef MSD_OSD_WINDOW_H +#define MSD_OSD_WINDOW_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Alpha value to be used for foreground objects drawn in an OSD window */ +#define MSD_OSD_WINDOW_FG_ALPHA 1.0 + +#define MSD_TYPE_OSD_WINDOW (msd_osd_window_get_type ()) +#define MSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindow)) +#define MSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) +#define MSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_OSD_WINDOW)) +#define MSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_OSD_WINDOW)) +#define MSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) + +typedef struct MsdOsdWindow MsdOsdWindow; +typedef struct MsdOsdWindowClass MsdOsdWindowClass; +typedef struct MsdOsdWindowPrivate MsdOsdWindowPrivate; + +struct MsdOsdWindow { + GtkWindow parent; + + MsdOsdWindowPrivate *priv; +}; + +struct MsdOsdWindowClass { + GtkWindowClass parent_class; + + void (* expose_when_composited) (MsdOsdWindow *window, cairo_t *cr); +}; + +GType msd_osd_window_get_type (void); + +GtkWidget * msd_osd_window_new (void); +gboolean msd_osd_window_is_composited (MsdOsdWindow *window); +gboolean msd_osd_window_is_valid (MsdOsdWindow *window); +void msd_osd_window_update_and_hide (MsdOsdWindow *window); + +void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, + gdouble aspect, + gdouble x, + gdouble y, + gdouble corner_radius, + gdouble width, + gdouble height); + +void msd_osd_window_color_reverse (const GdkColor *a, + GdkColor *b); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/plugins/datetime/gsd-datetime-mechanism-main.c b/plugins/datetime/gsd-datetime-mechanism-main.c deleted file mode 100644 index 4d13630..0000000 --- a/plugins/datetime/gsd-datetime-mechanism-main.c +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 David Zeuthen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - - -#include "msd-datetime-mechanism.h" - -static DBusGProxy * -get_bus_proxy (DBusGConnection *connection) -{ - DBusGProxy *bus_proxy; - - bus_proxy = dbus_g_proxy_new_for_name (connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - return bus_proxy; -} - -#define BUS_NAME "org.mate.SettingsDaemon.DateTimeMechanism" - -static gboolean -acquire_name_on_proxy (DBusGProxy *bus_proxy) -{ - GError *error; - guint result; - gboolean res; - gboolean ret; - - ret = FALSE; - - if (bus_proxy == NULL) { - goto out; - } - - error = NULL; - res = dbus_g_proxy_call (bus_proxy, - "RequestName", - &error, - G_TYPE_STRING, BUS_NAME, - G_TYPE_UINT, 0, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID); - if (! res) { - if (error != NULL) { - g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message); - g_error_free (error); - } else { - g_warning ("Failed to acquire %s", BUS_NAME); - } - goto out; - } - - if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - if (error != NULL) { - g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message); - g_error_free (error); - } else { - g_warning ("Failed to acquire %s", BUS_NAME); - } - goto out; - } - - ret = TRUE; - - out: - return ret; -} - -static DBusGConnection * -get_system_bus (void) -{ - GError *error; - DBusGConnection *bus; - - error = NULL; - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (bus == NULL) { - g_warning ("Couldn't connect to system bus: %s", error->message); - g_error_free (error); - } - return bus; -} - -int -main (int argc, char **argv) -{ - GMainLoop *loop; - MsdDatetimeMechanism *mechanism; - DBusGProxy *bus_proxy; - DBusGConnection *connection; - int ret; - - ret = 1; - - if (! g_thread_supported ()) { - g_thread_init (NULL); - } - dbus_g_thread_init (); - g_type_init (); - - connection = get_system_bus (); - if (connection == NULL) { - goto out; - } - - bus_proxy = get_bus_proxy (connection); - if (bus_proxy == NULL) { - g_warning ("Could not construct bus_proxy object; bailing out"); - goto out; - } - - if (!acquire_name_on_proxy (bus_proxy) ) { - g_warning ("Could not acquire name; bailing out"); - goto out; - } - - mechanism = msd_datetime_mechanism_new (); - - if (mechanism == NULL) { - goto out; - } - - loop = g_main_loop_new (NULL, FALSE); - - g_main_loop_run (loop); - - g_object_unref (mechanism); - g_main_loop_unref (loop); - ret = 0; - -out: - return ret; -} diff --git a/plugins/datetime/gsd-datetime-mechanism.c b/plugins/datetime/gsd-datetime-mechanism.c deleted file mode 100644 index 7b0d338..0000000 --- a/plugins/datetime/gsd-datetime-mechanism.c +++ /dev/null @@ -1,646 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 David Zeuthen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include - -#include "system-timezone.h" - -#include "msd-datetime-mechanism.h" -#include "msd-datetime-mechanism-glue.h" - -static gboolean -do_exit (gpointer user_data) -{ - g_debug ("Exiting due to inactivity"); - exit (1); - return FALSE; -} - -static void -reset_killtimer (void) -{ - static guint timer_id = 0; - - if (timer_id > 0) { - g_source_remove (timer_id); - } - g_debug ("Setting killtimer to 30 seconds..."); - timer_id = g_timeout_add_seconds (30, do_exit, NULL); -} - -struct MsdDatetimeMechanismPrivate -{ - DBusGConnection *system_bus_connection; - DBusGProxy *system_bus_proxy; - PolkitAuthority *auth; -}; - -static void msd_datetime_mechanism_finalize (GObject *object); - -G_DEFINE_TYPE (MsdDatetimeMechanism, msd_datetime_mechanism, G_TYPE_OBJECT) - -#define MSD_DATETIME_MECHANISM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismPrivate)) - -GQuark -msd_datetime_mechanism_error_quark (void) -{ - static GQuark ret = 0; - - if (ret == 0) { - ret = g_quark_from_static_string ("msd_datetime_mechanism_error"); - } - - return ret; -} - - -#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } - -GType -msd_datetime_mechanism_error_get_type (void) -{ - static GType etype = 0; - - if (etype == 0) - { - static const GEnumValue values[] = - { - ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_GENERAL, "GeneralError"), - ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, "NotPrivileged"), - ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, "InvalidTimezoneFile"), - { 0, 0, 0 } - }; - - g_assert (MSD_DATETIME_MECHANISM_NUM_ERRORS == G_N_ELEMENTS (values) - 1); - - etype = g_enum_register_static ("MsdDatetimeMechanismError", values); - } - - return etype; -} - - -static GObject * -msd_datetime_mechanism_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdDatetimeMechanism *mechanism; - - mechanism = MSD_DATETIME_MECHANISM (G_OBJECT_CLASS (msd_datetime_mechanism_parent_class)->constructor ( - type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (mechanism); -} - -static void -msd_datetime_mechanism_class_init (MsdDatetimeMechanismClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructor = msd_datetime_mechanism_constructor; - object_class->finalize = msd_datetime_mechanism_finalize; - - g_type_class_add_private (klass, sizeof (MsdDatetimeMechanismPrivate)); - - dbus_g_object_type_install_info (MSD_DATETIME_TYPE_MECHANISM, &dbus_glib_msd_datetime_mechanism_object_info); - - dbus_g_error_domain_register (MSD_DATETIME_MECHANISM_ERROR, NULL, MSD_DATETIME_MECHANISM_TYPE_ERROR); - -} - -static void -msd_datetime_mechanism_init (MsdDatetimeMechanism *mechanism) -{ - mechanism->priv = MSD_DATETIME_MECHANISM_GET_PRIVATE (mechanism); - -} - -static void -msd_datetime_mechanism_finalize (GObject *object) -{ - MsdDatetimeMechanism *mechanism; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_DATETIME_IS_MECHANISM (object)); - - mechanism = MSD_DATETIME_MECHANISM (object); - - g_return_if_fail (mechanism->priv != NULL); - - g_object_unref (mechanism->priv->system_bus_proxy); - - G_OBJECT_CLASS (msd_datetime_mechanism_parent_class)->finalize (object); -} - -static gboolean -register_mechanism (MsdDatetimeMechanism *mechanism) -{ - GError *error = NULL; - - mechanism->priv->auth = polkit_authority_get (); - - error = NULL; - mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (mechanism->priv->system_bus_connection == NULL) { - if (error != NULL) { - g_critical ("error getting system bus: %s", error->message); - g_error_free (error); - } - goto error; - } - - dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/", - G_OBJECT (mechanism)); - - mechanism->priv->system_bus_proxy = dbus_g_proxy_new_for_name (mechanism->priv->system_bus_connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - - reset_killtimer (); - - return TRUE; - -error: - return FALSE; -} - - -MsdDatetimeMechanism * -msd_datetime_mechanism_new (void) -{ - GObject *object; - gboolean res; - - object = g_object_new (MSD_DATETIME_TYPE_MECHANISM, NULL); - - res = register_mechanism (MSD_DATETIME_MECHANISM (object)); - if (! res) { - g_object_unref (object); - return NULL; - } - - return MSD_DATETIME_MECHANISM (object); -} - -static gboolean -_check_polkit_for_action (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context, const char *action) -{ - const char *sender; - GError *error; - PolkitSubject *subject; - PolkitAuthorizationResult *result; - - error = NULL; - - /* Check that caller is privileged */ - sender = dbus_g_method_get_sender (context); - subject = polkit_system_bus_name_new (sender); - - result = polkit_authority_check_authorization_sync (mechanism->priv->auth, - subject, - action, - NULL, - POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, - NULL, &error); - g_object_unref (subject); - - if (error) { - dbus_g_method_return_error (context, error); - g_error_free (error); - - return FALSE; - } - - if (!polkit_authorization_result_get_is_authorized (result)) { - error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, - "Not Authorized for action %s", action); - dbus_g_method_return_error (context, error); - g_error_free (error); - g_object_unref (result); - - return FALSE; - } - - g_object_unref (result); - - return TRUE; -} - - -static gboolean -_set_time (MsdDatetimeMechanism *mechanism, - const struct timeval *tv, - DBusGMethodInvocation *context) -{ - GError *error; - - if (!_check_polkit_for_action (mechanism, context, "org.mate.settingsdaemon.datetimemechanism.settime")) - return FALSE; - - if (settimeofday (tv, NULL) != 0) { - error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Error calling settimeofday({%lld,%lld}): %s", - (gint64) tv->tv_sec, (gint64) tv->tv_usec, - strerror (errno)); - dbus_g_method_return_error (context, error); - g_error_free (error); - return FALSE; - } - - if (g_file_test ("/sbin/hwclock", - G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { - int exit_status; - if (!g_spawn_command_line_sync ("/sbin/hwclock --systohc", NULL, NULL, &exit_status, &error)) { - GError *error2; - error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Error spawning /sbin/hwclock: %s", error->message); - g_error_free (error); - dbus_g_method_return_error (context, error2); - g_error_free (error2); - return FALSE; - } - if (WEXITSTATUS (exit_status) != 0) { - error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "/sbin/hwclock returned %d", exit_status); - dbus_g_method_return_error (context, error); - g_error_free (error); - return FALSE; - } - } - - dbus_g_method_return (context); - return TRUE; -} - -static gboolean -_rh_update_etc_sysconfig_clock (DBusGMethodInvocation *context, const char *key, const char *value) -{ - /* On Red Hat / Fedora, the /etc/sysconfig/clock file needs to be kept in sync */ - if (g_file_test ("/etc/sysconfig/clock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { - char **lines; - int n; - gboolean replaced; - char *data; - gsize len; - GError *error; - - error = NULL; - - if (!g_file_get_contents ("/etc/sysconfig/clock", &data, &len, &error)) { - GError *error2; - error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Error reading /etc/sysconfig/clock file: %s", error->message); - g_error_free (error); - dbus_g_method_return_error (context, error2); - g_error_free (error2); - return FALSE; - } - replaced = FALSE; - lines = g_strsplit (data, "\n", 0); - g_free (data); - - for (n = 0; lines[n] != NULL; n++) { - if (g_str_has_prefix (lines[n], key)) { - g_free (lines[n]); - lines[n] = g_strdup_printf ("%s%s", key, value); - replaced = TRUE; - } - } - if (replaced) { - GString *str; - - str = g_string_new (NULL); - for (n = 0; lines[n] != NULL; n++) { - g_string_append (str, lines[n]); - if (lines[n + 1] != NULL) - g_string_append_c (str, '\n'); - } - data = g_string_free (str, FALSE); - len = strlen (data); - if (!g_file_set_contents ("/etc/sysconfig/clock", data, len, &error)) { - GError *error2; - error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Error updating /etc/sysconfig/clock: %s", error->message); - g_error_free (error); - dbus_g_method_return_error (context, error2); - g_error_free (error2); - g_free (data); - return FALSE; - } - g_free (data); - } - g_strfreev (lines); - } - - return TRUE; -} - -/* exported methods */ - -gboolean -msd_datetime_mechanism_set_time (MsdDatetimeMechanism *mechanism, - gint64 seconds_since_epoch, - DBusGMethodInvocation *context) -{ - struct timeval tv; - - reset_killtimer (); - g_debug ("SetTime(%lld) called", seconds_since_epoch); - - tv.tv_sec = (time_t) seconds_since_epoch; - tv.tv_usec = 0; - return _set_time (mechanism, &tv, context); -} - -gboolean -msd_datetime_mechanism_adjust_time (MsdDatetimeMechanism *mechanism, - gint64 seconds_to_add, - DBusGMethodInvocation *context) -{ - struct timeval tv; - - reset_killtimer (); - g_debug ("AdjustTime(%lld) called", seconds_to_add); - - if (gettimeofday (&tv, NULL) != 0) { - GError *error; - error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Error calling gettimeofday(): %s", strerror (errno)); - dbus_g_method_return_error (context, error); - g_error_free (error); - return FALSE; - } - - tv.tv_sec += (time_t) seconds_to_add; - return _set_time (mechanism, &tv, context); -} - - -gboolean -msd_datetime_mechanism_set_timezone (MsdDatetimeMechanism *mechanism, - const char *zone_file, - DBusGMethodInvocation *context) -{ - GError *error; - - reset_killtimer (); - g_debug ("SetTimezone('%s') called", zone_file); - - if (!_check_polkit_for_action (mechanism, context, "org.mate.settingsdaemon.datetimemechanism.settimezone")) - return FALSE; - - error = NULL; - - if (!system_timezone_set_from_file (zone_file, &error)) { - GError *error2; - int code; - - if (error->code == SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE) - code = MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE; - else - code = MSD_DATETIME_MECHANISM_ERROR_GENERAL; - - error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - code, "%s", error->message); - - g_error_free (error); - - dbus_g_method_return_error (context, error2); - g_error_free (error2); - - return FALSE; - } - - dbus_g_method_return (context); - return TRUE; -} - - -gboolean -msd_datetime_mechanism_get_timezone (MsdDatetimeMechanism *mechism, - DBusGMethodInvocation *context) -{ - gchar *timezone; - - reset_killtimer (); - - timezone = system_timezone_find (); - - dbus_g_method_return (context, timezone); - - return TRUE; -} - -gboolean -msd_datetime_mechanism_get_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, - DBusGMethodInvocation *context) -{ - char **lines; - char *data; - gsize len; - GError *error; - gboolean is_utc; - - error = NULL; - - if (!g_file_get_contents ("/etc/adjtime", &data, &len, &error)) { - GError *error2; - error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Error reading /etc/adjtime file: %s", error->message); - g_error_free (error); - dbus_g_method_return_error (context, error2); - g_error_free (error2); - return FALSE; - } - - lines = g_strsplit (data, "\n", 0); - g_free (data); - - if (g_strv_length (lines) < 3) { - error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Cannot parse /etc/adjtime"); - dbus_g_method_return_error (context, error); - g_error_free (error); - g_strfreev (lines); - return FALSE; - } - - if (strcmp (lines[2], "UTC") == 0) { - is_utc = TRUE; - } else if (strcmp (lines[2], "LOCAL") == 0) { - is_utc = FALSE; - } else { - error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Expected UTC or LOCAL at line 3 of /etc/adjtime; found '%s'", lines[2]); - dbus_g_method_return_error (context, error); - g_error_free (error); - g_strfreev (lines); - return FALSE; - } - g_strfreev (lines); - dbus_g_method_return (context, is_utc); - return TRUE; -} - -gboolean -msd_datetime_mechanism_set_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, - gboolean using_utc, - DBusGMethodInvocation *context) -{ - GError *error; - - error = NULL; - - if (!_check_polkit_for_action (mechanism, context, - "org.mate.settingsdaemon.datetimemechanism.configurehwclock")) - return FALSE; - - if (g_file_test ("/sbin/hwclock", - G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { - int exit_status; - char *cmd; - cmd = g_strdup_printf ("/sbin/hwclock %s --systohc", using_utc ? "--utc" : "--localtime"); - if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { - GError *error2; - error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "Error spawning /sbin/hwclock: %s", error->message); - g_error_free (error); - dbus_g_method_return_error (context, error2); - g_error_free (error2); - g_free (cmd); - return FALSE; - } - g_free (cmd); - if (WEXITSTATUS (exit_status) != 0) { - error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - "/sbin/hwclock returned %d", exit_status); - dbus_g_method_return_error (context, error); - g_error_free (error); - return FALSE; - } - - if (!_rh_update_etc_sysconfig_clock (context, "UTC=", using_utc ? "true" : "false")) - return FALSE; - - } - dbus_g_method_return (context); - return TRUE; -} - -static void -check_can_do (MsdDatetimeMechanism *mechanism, - const char *action, - DBusGMethodInvocation *context) -{ - const char *sender; - PolkitSubject *subject; - PolkitAuthorizationResult *result; - GError *error; - - /* Check that caller is privileged */ - sender = dbus_g_method_get_sender (context); - subject = polkit_system_bus_name_new (sender); - - error = NULL; - result = polkit_authority_check_authorization_sync (mechanism->priv->auth, - subject, - action, - NULL, - 0, - NULL, - &error); - g_object_unref (subject); - - if (error) { - dbus_g_method_return_error (context, error); - g_error_free (error); - return; - } - - if (polkit_authorization_result_get_is_authorized (result)) { - dbus_g_method_return (context, 2); - } - else if (polkit_authorization_result_get_is_challenge (result)) { - dbus_g_method_return (context, 1); - } - else { - dbus_g_method_return (context, 0); - } - - g_object_unref (result); -} - - -gboolean -msd_datetime_mechanism_can_set_time (MsdDatetimeMechanism *mechanism, - DBusGMethodInvocation *context) -{ - check_can_do (mechanism, - "org.mate.settingsdaemon.datetimemechanism.settime", - context); - - return TRUE; -} - -gboolean -msd_datetime_mechanism_can_set_timezone (MsdDatetimeMechanism *mechanism, - DBusGMethodInvocation *context) -{ - check_can_do (mechanism, - "org.mate.settingsdaemon.datetimemechanism.settimezone", - context); - - return TRUE; -} diff --git a/plugins/datetime/gsd-datetime-mechanism.h b/plugins/datetime/gsd-datetime-mechanism.h deleted file mode 100644 index c8605b4..0000000 --- a/plugins/datetime/gsd-datetime-mechanism.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 David Zeuthen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef MSD_DATETIME_MECHANISM_H -#define MSD_DATETIME_MECHANISM_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_DATETIME_TYPE_MECHANISM (msd_datetime_mechanism_get_type ()) -#define MSD_DATETIME_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanism)) -#define MSD_DATETIME_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismClass)) -#define MSD_DATETIME_IS_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_DATETIME_TYPE_MECHANISM)) -#define MSD_DATETIME_IS_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_DATETIME_TYPE_MECHANISM)) -#define MSD_DATETIME_MECHANISM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismClass)) - -typedef struct MsdDatetimeMechanismPrivate MsdDatetimeMechanismPrivate; - -typedef struct -{ - GObject parent; - MsdDatetimeMechanismPrivate *priv; -} MsdDatetimeMechanism; - -typedef struct -{ - GObjectClass parent_class; -} MsdDatetimeMechanismClass; - -typedef enum -{ - MSD_DATETIME_MECHANISM_ERROR_GENERAL, - MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, - MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, - MSD_DATETIME_MECHANISM_NUM_ERRORS -} MsdDatetimeMechanismError; - -#define MSD_DATETIME_MECHANISM_ERROR msd_datetime_mechanism_error_quark () - -GType msd_datetime_mechanism_error_get_type (void); -#define MSD_DATETIME_MECHANISM_TYPE_ERROR (msd_datetime_mechanism_error_get_type ()) - - -GQuark msd_datetime_mechanism_error_quark (void); -GType msd_datetime_mechanism_get_type (void); -MsdDatetimeMechanism *msd_datetime_mechanism_new (void); - -/* exported methods */ -gboolean msd_datetime_mechanism_get_timezone (MsdDatetimeMechanism *mechanism, - DBusGMethodInvocation *context); -gboolean msd_datetime_mechanism_set_timezone (MsdDatetimeMechanism *mechanism, - const char *zone_file, - DBusGMethodInvocation *context); - -gboolean msd_datetime_mechanism_can_set_timezone (MsdDatetimeMechanism *mechanism, - DBusGMethodInvocation *context); - -gboolean msd_datetime_mechanism_set_time (MsdDatetimeMechanism *mechanism, - gint64 seconds_since_epoch, - DBusGMethodInvocation *context); - -gboolean msd_datetime_mechanism_can_set_time (MsdDatetimeMechanism *mechanism, - DBusGMethodInvocation *context); - -gboolean msd_datetime_mechanism_adjust_time (MsdDatetimeMechanism *mechanism, - gint64 seconds_to_add, - DBusGMethodInvocation *context); - -gboolean msd_datetime_mechanism_get_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, - DBusGMethodInvocation *context); - -gboolean msd_datetime_mechanism_set_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, - gboolean using_utc, - DBusGMethodInvocation *context); - -#ifdef __cplusplus -} -#endif - -#endif /* MSD_DATETIME_MECHANISM_H */ diff --git a/plugins/datetime/gsd-datetime-mechanism.xml b/plugins/datetime/gsd-datetime-mechanism.xml deleted file mode 100644 index 1962235..0000000 --- a/plugins/datetime/gsd-datetime-mechanism.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - Whether the caller can set the timezone - - - The return value is not a boolean, but an integer with the following meaning: - - - 0 - the caller cannot set the timezone - - - 1 - the caller will be challenged before being able to set the timezone - - - 2 - the caller is authorized to set the timezone - - - - - - - - - - - - - - - - Whether the caller can set the time - - - The return value is not a boolean, but an integer with the following meaning: - - - 0 - the caller cannot set the time - - - 1 - the caller will be challenged before being able to set the time - - - 2 - the caller is authorized to set the time - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/datetime/msd-datetime-mechanism-main.c b/plugins/datetime/msd-datetime-mechanism-main.c new file mode 100644 index 0000000..4d13630 --- /dev/null +++ b/plugins/datetime/msd-datetime-mechanism-main.c @@ -0,0 +1,171 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 David Zeuthen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + + +#include "msd-datetime-mechanism.h" + +static DBusGProxy * +get_bus_proxy (DBusGConnection *connection) +{ + DBusGProxy *bus_proxy; + + bus_proxy = dbus_g_proxy_new_for_name (connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); + return bus_proxy; +} + +#define BUS_NAME "org.mate.SettingsDaemon.DateTimeMechanism" + +static gboolean +acquire_name_on_proxy (DBusGProxy *bus_proxy) +{ + GError *error; + guint result; + gboolean res; + gboolean ret; + + ret = FALSE; + + if (bus_proxy == NULL) { + goto out; + } + + error = NULL; + res = dbus_g_proxy_call (bus_proxy, + "RequestName", + &error, + G_TYPE_STRING, BUS_NAME, + G_TYPE_UINT, 0, + G_TYPE_INVALID, + G_TYPE_UINT, &result, + G_TYPE_INVALID); + if (! res) { + if (error != NULL) { + g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message); + g_error_free (error); + } else { + g_warning ("Failed to acquire %s", BUS_NAME); + } + goto out; + } + + if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + if (error != NULL) { + g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message); + g_error_free (error); + } else { + g_warning ("Failed to acquire %s", BUS_NAME); + } + goto out; + } + + ret = TRUE; + + out: + return ret; +} + +static DBusGConnection * +get_system_bus (void) +{ + GError *error; + DBusGConnection *bus; + + error = NULL; + bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (bus == NULL) { + g_warning ("Couldn't connect to system bus: %s", error->message); + g_error_free (error); + } + return bus; +} + +int +main (int argc, char **argv) +{ + GMainLoop *loop; + MsdDatetimeMechanism *mechanism; + DBusGProxy *bus_proxy; + DBusGConnection *connection; + int ret; + + ret = 1; + + if (! g_thread_supported ()) { + g_thread_init (NULL); + } + dbus_g_thread_init (); + g_type_init (); + + connection = get_system_bus (); + if (connection == NULL) { + goto out; + } + + bus_proxy = get_bus_proxy (connection); + if (bus_proxy == NULL) { + g_warning ("Could not construct bus_proxy object; bailing out"); + goto out; + } + + if (!acquire_name_on_proxy (bus_proxy) ) { + g_warning ("Could not acquire name; bailing out"); + goto out; + } + + mechanism = msd_datetime_mechanism_new (); + + if (mechanism == NULL) { + goto out; + } + + loop = g_main_loop_new (NULL, FALSE); + + g_main_loop_run (loop); + + g_object_unref (mechanism); + g_main_loop_unref (loop); + ret = 0; + +out: + return ret; +} diff --git a/plugins/datetime/msd-datetime-mechanism.c b/plugins/datetime/msd-datetime-mechanism.c new file mode 100644 index 0000000..7b0d338 --- /dev/null +++ b/plugins/datetime/msd-datetime-mechanism.c @@ -0,0 +1,646 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 David Zeuthen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include "system-timezone.h" + +#include "msd-datetime-mechanism.h" +#include "msd-datetime-mechanism-glue.h" + +static gboolean +do_exit (gpointer user_data) +{ + g_debug ("Exiting due to inactivity"); + exit (1); + return FALSE; +} + +static void +reset_killtimer (void) +{ + static guint timer_id = 0; + + if (timer_id > 0) { + g_source_remove (timer_id); + } + g_debug ("Setting killtimer to 30 seconds..."); + timer_id = g_timeout_add_seconds (30, do_exit, NULL); +} + +struct MsdDatetimeMechanismPrivate +{ + DBusGConnection *system_bus_connection; + DBusGProxy *system_bus_proxy; + PolkitAuthority *auth; +}; + +static void msd_datetime_mechanism_finalize (GObject *object); + +G_DEFINE_TYPE (MsdDatetimeMechanism, msd_datetime_mechanism, G_TYPE_OBJECT) + +#define MSD_DATETIME_MECHANISM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismPrivate)) + +GQuark +msd_datetime_mechanism_error_quark (void) +{ + static GQuark ret = 0; + + if (ret == 0) { + ret = g_quark_from_static_string ("msd_datetime_mechanism_error"); + } + + return ret; +} + + +#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } + +GType +msd_datetime_mechanism_error_get_type (void) +{ + static GType etype = 0; + + if (etype == 0) + { + static const GEnumValue values[] = + { + ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_GENERAL, "GeneralError"), + ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, "NotPrivileged"), + ENUM_ENTRY (MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, "InvalidTimezoneFile"), + { 0, 0, 0 } + }; + + g_assert (MSD_DATETIME_MECHANISM_NUM_ERRORS == G_N_ELEMENTS (values) - 1); + + etype = g_enum_register_static ("MsdDatetimeMechanismError", values); + } + + return etype; +} + + +static GObject * +msd_datetime_mechanism_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdDatetimeMechanism *mechanism; + + mechanism = MSD_DATETIME_MECHANISM (G_OBJECT_CLASS (msd_datetime_mechanism_parent_class)->constructor ( + type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (mechanism); +} + +static void +msd_datetime_mechanism_class_init (MsdDatetimeMechanismClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructor = msd_datetime_mechanism_constructor; + object_class->finalize = msd_datetime_mechanism_finalize; + + g_type_class_add_private (klass, sizeof (MsdDatetimeMechanismPrivate)); + + dbus_g_object_type_install_info (MSD_DATETIME_TYPE_MECHANISM, &dbus_glib_msd_datetime_mechanism_object_info); + + dbus_g_error_domain_register (MSD_DATETIME_MECHANISM_ERROR, NULL, MSD_DATETIME_MECHANISM_TYPE_ERROR); + +} + +static void +msd_datetime_mechanism_init (MsdDatetimeMechanism *mechanism) +{ + mechanism->priv = MSD_DATETIME_MECHANISM_GET_PRIVATE (mechanism); + +} + +static void +msd_datetime_mechanism_finalize (GObject *object) +{ + MsdDatetimeMechanism *mechanism; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_DATETIME_IS_MECHANISM (object)); + + mechanism = MSD_DATETIME_MECHANISM (object); + + g_return_if_fail (mechanism->priv != NULL); + + g_object_unref (mechanism->priv->system_bus_proxy); + + G_OBJECT_CLASS (msd_datetime_mechanism_parent_class)->finalize (object); +} + +static gboolean +register_mechanism (MsdDatetimeMechanism *mechanism) +{ + GError *error = NULL; + + mechanism->priv->auth = polkit_authority_get (); + + error = NULL; + mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (mechanism->priv->system_bus_connection == NULL) { + if (error != NULL) { + g_critical ("error getting system bus: %s", error->message); + g_error_free (error); + } + goto error; + } + + dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/", + G_OBJECT (mechanism)); + + mechanism->priv->system_bus_proxy = dbus_g_proxy_new_for_name (mechanism->priv->system_bus_connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); + + reset_killtimer (); + + return TRUE; + +error: + return FALSE; +} + + +MsdDatetimeMechanism * +msd_datetime_mechanism_new (void) +{ + GObject *object; + gboolean res; + + object = g_object_new (MSD_DATETIME_TYPE_MECHANISM, NULL); + + res = register_mechanism (MSD_DATETIME_MECHANISM (object)); + if (! res) { + g_object_unref (object); + return NULL; + } + + return MSD_DATETIME_MECHANISM (object); +} + +static gboolean +_check_polkit_for_action (MsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context, const char *action) +{ + const char *sender; + GError *error; + PolkitSubject *subject; + PolkitAuthorizationResult *result; + + error = NULL; + + /* Check that caller is privileged */ + sender = dbus_g_method_get_sender (context); + subject = polkit_system_bus_name_new (sender); + + result = polkit_authority_check_authorization_sync (mechanism->priv->auth, + subject, + action, + NULL, + POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, + NULL, &error); + g_object_unref (subject); + + if (error) { + dbus_g_method_return_error (context, error); + g_error_free (error); + + return FALSE; + } + + if (!polkit_authorization_result_get_is_authorized (result)) { + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, + "Not Authorized for action %s", action); + dbus_g_method_return_error (context, error); + g_error_free (error); + g_object_unref (result); + + return FALSE; + } + + g_object_unref (result); + + return TRUE; +} + + +static gboolean +_set_time (MsdDatetimeMechanism *mechanism, + const struct timeval *tv, + DBusGMethodInvocation *context) +{ + GError *error; + + if (!_check_polkit_for_action (mechanism, context, "org.mate.settingsdaemon.datetimemechanism.settime")) + return FALSE; + + if (settimeofday (tv, NULL) != 0) { + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Error calling settimeofday({%lld,%lld}): %s", + (gint64) tv->tv_sec, (gint64) tv->tv_usec, + strerror (errno)); + dbus_g_method_return_error (context, error); + g_error_free (error); + return FALSE; + } + + if (g_file_test ("/sbin/hwclock", + G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { + int exit_status; + if (!g_spawn_command_line_sync ("/sbin/hwclock --systohc", NULL, NULL, &exit_status, &error)) { + GError *error2; + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Error spawning /sbin/hwclock: %s", error->message); + g_error_free (error); + dbus_g_method_return_error (context, error2); + g_error_free (error2); + return FALSE; + } + if (WEXITSTATUS (exit_status) != 0) { + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "/sbin/hwclock returned %d", exit_status); + dbus_g_method_return_error (context, error); + g_error_free (error); + return FALSE; + } + } + + dbus_g_method_return (context); + return TRUE; +} + +static gboolean +_rh_update_etc_sysconfig_clock (DBusGMethodInvocation *context, const char *key, const char *value) +{ + /* On Red Hat / Fedora, the /etc/sysconfig/clock file needs to be kept in sync */ + if (g_file_test ("/etc/sysconfig/clock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { + char **lines; + int n; + gboolean replaced; + char *data; + gsize len; + GError *error; + + error = NULL; + + if (!g_file_get_contents ("/etc/sysconfig/clock", &data, &len, &error)) { + GError *error2; + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Error reading /etc/sysconfig/clock file: %s", error->message); + g_error_free (error); + dbus_g_method_return_error (context, error2); + g_error_free (error2); + return FALSE; + } + replaced = FALSE; + lines = g_strsplit (data, "\n", 0); + g_free (data); + + for (n = 0; lines[n] != NULL; n++) { + if (g_str_has_prefix (lines[n], key)) { + g_free (lines[n]); + lines[n] = g_strdup_printf ("%s%s", key, value); + replaced = TRUE; + } + } + if (replaced) { + GString *str; + + str = g_string_new (NULL); + for (n = 0; lines[n] != NULL; n++) { + g_string_append (str, lines[n]); + if (lines[n + 1] != NULL) + g_string_append_c (str, '\n'); + } + data = g_string_free (str, FALSE); + len = strlen (data); + if (!g_file_set_contents ("/etc/sysconfig/clock", data, len, &error)) { + GError *error2; + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Error updating /etc/sysconfig/clock: %s", error->message); + g_error_free (error); + dbus_g_method_return_error (context, error2); + g_error_free (error2); + g_free (data); + return FALSE; + } + g_free (data); + } + g_strfreev (lines); + } + + return TRUE; +} + +/* exported methods */ + +gboolean +msd_datetime_mechanism_set_time (MsdDatetimeMechanism *mechanism, + gint64 seconds_since_epoch, + DBusGMethodInvocation *context) +{ + struct timeval tv; + + reset_killtimer (); + g_debug ("SetTime(%lld) called", seconds_since_epoch); + + tv.tv_sec = (time_t) seconds_since_epoch; + tv.tv_usec = 0; + return _set_time (mechanism, &tv, context); +} + +gboolean +msd_datetime_mechanism_adjust_time (MsdDatetimeMechanism *mechanism, + gint64 seconds_to_add, + DBusGMethodInvocation *context) +{ + struct timeval tv; + + reset_killtimer (); + g_debug ("AdjustTime(%lld) called", seconds_to_add); + + if (gettimeofday (&tv, NULL) != 0) { + GError *error; + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Error calling gettimeofday(): %s", strerror (errno)); + dbus_g_method_return_error (context, error); + g_error_free (error); + return FALSE; + } + + tv.tv_sec += (time_t) seconds_to_add; + return _set_time (mechanism, &tv, context); +} + + +gboolean +msd_datetime_mechanism_set_timezone (MsdDatetimeMechanism *mechanism, + const char *zone_file, + DBusGMethodInvocation *context) +{ + GError *error; + + reset_killtimer (); + g_debug ("SetTimezone('%s') called", zone_file); + + if (!_check_polkit_for_action (mechanism, context, "org.mate.settingsdaemon.datetimemechanism.settimezone")) + return FALSE; + + error = NULL; + + if (!system_timezone_set_from_file (zone_file, &error)) { + GError *error2; + int code; + + if (error->code == SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE) + code = MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE; + else + code = MSD_DATETIME_MECHANISM_ERROR_GENERAL; + + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + code, "%s", error->message); + + g_error_free (error); + + dbus_g_method_return_error (context, error2); + g_error_free (error2); + + return FALSE; + } + + dbus_g_method_return (context); + return TRUE; +} + + +gboolean +msd_datetime_mechanism_get_timezone (MsdDatetimeMechanism *mechism, + DBusGMethodInvocation *context) +{ + gchar *timezone; + + reset_killtimer (); + + timezone = system_timezone_find (); + + dbus_g_method_return (context, timezone); + + return TRUE; +} + +gboolean +msd_datetime_mechanism_get_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, + DBusGMethodInvocation *context) +{ + char **lines; + char *data; + gsize len; + GError *error; + gboolean is_utc; + + error = NULL; + + if (!g_file_get_contents ("/etc/adjtime", &data, &len, &error)) { + GError *error2; + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Error reading /etc/adjtime file: %s", error->message); + g_error_free (error); + dbus_g_method_return_error (context, error2); + g_error_free (error2); + return FALSE; + } + + lines = g_strsplit (data, "\n", 0); + g_free (data); + + if (g_strv_length (lines) < 3) { + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Cannot parse /etc/adjtime"); + dbus_g_method_return_error (context, error); + g_error_free (error); + g_strfreev (lines); + return FALSE; + } + + if (strcmp (lines[2], "UTC") == 0) { + is_utc = TRUE; + } else if (strcmp (lines[2], "LOCAL") == 0) { + is_utc = FALSE; + } else { + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Expected UTC or LOCAL at line 3 of /etc/adjtime; found '%s'", lines[2]); + dbus_g_method_return_error (context, error); + g_error_free (error); + g_strfreev (lines); + return FALSE; + } + g_strfreev (lines); + dbus_g_method_return (context, is_utc); + return TRUE; +} + +gboolean +msd_datetime_mechanism_set_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, + gboolean using_utc, + DBusGMethodInvocation *context) +{ + GError *error; + + error = NULL; + + if (!_check_polkit_for_action (mechanism, context, + "org.mate.settingsdaemon.datetimemechanism.configurehwclock")) + return FALSE; + + if (g_file_test ("/sbin/hwclock", + G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { + int exit_status; + char *cmd; + cmd = g_strdup_printf ("/sbin/hwclock %s --systohc", using_utc ? "--utc" : "--localtime"); + if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { + GError *error2; + error2 = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "Error spawning /sbin/hwclock: %s", error->message); + g_error_free (error); + dbus_g_method_return_error (context, error2); + g_error_free (error2); + g_free (cmd); + return FALSE; + } + g_free (cmd); + if (WEXITSTATUS (exit_status) != 0) { + error = g_error_new (MSD_DATETIME_MECHANISM_ERROR, + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + "/sbin/hwclock returned %d", exit_status); + dbus_g_method_return_error (context, error); + g_error_free (error); + return FALSE; + } + + if (!_rh_update_etc_sysconfig_clock (context, "UTC=", using_utc ? "true" : "false")) + return FALSE; + + } + dbus_g_method_return (context); + return TRUE; +} + +static void +check_can_do (MsdDatetimeMechanism *mechanism, + const char *action, + DBusGMethodInvocation *context) +{ + const char *sender; + PolkitSubject *subject; + PolkitAuthorizationResult *result; + GError *error; + + /* Check that caller is privileged */ + sender = dbus_g_method_get_sender (context); + subject = polkit_system_bus_name_new (sender); + + error = NULL; + result = polkit_authority_check_authorization_sync (mechanism->priv->auth, + subject, + action, + NULL, + 0, + NULL, + &error); + g_object_unref (subject); + + if (error) { + dbus_g_method_return_error (context, error); + g_error_free (error); + return; + } + + if (polkit_authorization_result_get_is_authorized (result)) { + dbus_g_method_return (context, 2); + } + else if (polkit_authorization_result_get_is_challenge (result)) { + dbus_g_method_return (context, 1); + } + else { + dbus_g_method_return (context, 0); + } + + g_object_unref (result); +} + + +gboolean +msd_datetime_mechanism_can_set_time (MsdDatetimeMechanism *mechanism, + DBusGMethodInvocation *context) +{ + check_can_do (mechanism, + "org.mate.settingsdaemon.datetimemechanism.settime", + context); + + return TRUE; +} + +gboolean +msd_datetime_mechanism_can_set_timezone (MsdDatetimeMechanism *mechanism, + DBusGMethodInvocation *context) +{ + check_can_do (mechanism, + "org.mate.settingsdaemon.datetimemechanism.settimezone", + context); + + return TRUE; +} diff --git a/plugins/datetime/msd-datetime-mechanism.h b/plugins/datetime/msd-datetime-mechanism.h new file mode 100644 index 0000000..c8605b4 --- /dev/null +++ b/plugins/datetime/msd-datetime-mechanism.h @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 David Zeuthen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef MSD_DATETIME_MECHANISM_H +#define MSD_DATETIME_MECHANISM_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_DATETIME_TYPE_MECHANISM (msd_datetime_mechanism_get_type ()) +#define MSD_DATETIME_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanism)) +#define MSD_DATETIME_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismClass)) +#define MSD_DATETIME_IS_MECHANISM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_DATETIME_TYPE_MECHANISM)) +#define MSD_DATETIME_IS_MECHANISM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_DATETIME_TYPE_MECHANISM)) +#define MSD_DATETIME_MECHANISM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_DATETIME_TYPE_MECHANISM, MsdDatetimeMechanismClass)) + +typedef struct MsdDatetimeMechanismPrivate MsdDatetimeMechanismPrivate; + +typedef struct +{ + GObject parent; + MsdDatetimeMechanismPrivate *priv; +} MsdDatetimeMechanism; + +typedef struct +{ + GObjectClass parent_class; +} MsdDatetimeMechanismClass; + +typedef enum +{ + MSD_DATETIME_MECHANISM_ERROR_GENERAL, + MSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, + MSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, + MSD_DATETIME_MECHANISM_NUM_ERRORS +} MsdDatetimeMechanismError; + +#define MSD_DATETIME_MECHANISM_ERROR msd_datetime_mechanism_error_quark () + +GType msd_datetime_mechanism_error_get_type (void); +#define MSD_DATETIME_MECHANISM_TYPE_ERROR (msd_datetime_mechanism_error_get_type ()) + + +GQuark msd_datetime_mechanism_error_quark (void); +GType msd_datetime_mechanism_get_type (void); +MsdDatetimeMechanism *msd_datetime_mechanism_new (void); + +/* exported methods */ +gboolean msd_datetime_mechanism_get_timezone (MsdDatetimeMechanism *mechanism, + DBusGMethodInvocation *context); +gboolean msd_datetime_mechanism_set_timezone (MsdDatetimeMechanism *mechanism, + const char *zone_file, + DBusGMethodInvocation *context); + +gboolean msd_datetime_mechanism_can_set_timezone (MsdDatetimeMechanism *mechanism, + DBusGMethodInvocation *context); + +gboolean msd_datetime_mechanism_set_time (MsdDatetimeMechanism *mechanism, + gint64 seconds_since_epoch, + DBusGMethodInvocation *context); + +gboolean msd_datetime_mechanism_can_set_time (MsdDatetimeMechanism *mechanism, + DBusGMethodInvocation *context); + +gboolean msd_datetime_mechanism_adjust_time (MsdDatetimeMechanism *mechanism, + gint64 seconds_to_add, + DBusGMethodInvocation *context); + +gboolean msd_datetime_mechanism_get_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, + DBusGMethodInvocation *context); + +gboolean msd_datetime_mechanism_set_hardware_clock_using_utc (MsdDatetimeMechanism *mechanism, + gboolean using_utc, + DBusGMethodInvocation *context); + +#ifdef __cplusplus +} +#endif + +#endif /* MSD_DATETIME_MECHANISM_H */ diff --git a/plugins/datetime/msd-datetime-mechanism.xml b/plugins/datetime/msd-datetime-mechanism.xml new file mode 100644 index 0000000..1962235 --- /dev/null +++ b/plugins/datetime/msd-datetime-mechanism.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + Whether the caller can set the timezone + + + The return value is not a boolean, but an integer with the following meaning: + + + 0 + the caller cannot set the timezone + + + 1 + the caller will be challenged before being able to set the timezone + + + 2 + the caller is authorized to set the timezone + + + + + + + + + + + + + + + + Whether the caller can set the time + + + The return value is not a boolean, but an integer with the following meaning: + + + 0 + the caller cannot set the time + + + 1 + the caller will be challenged before being able to set the time + + + 2 + the caller is authorized to set the time + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/dummy/gsd-dummy-manager.c b/plugins/dummy/gsd-dummy-manager.c deleted file mode 100644 index 2744aeb..0000000 --- a/plugins/dummy/gsd-dummy-manager.c +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "mate-settings-profile.h" -#include "msd-dummy-manager.h" - -#define MSD_DUMMY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerPrivate)) - -struct MsdDummyManagerPrivate -{ - gboolean padding; -}; - -enum { - PROP_0, -}; - -static void msd_dummy_manager_class_init (MsdDummyManagerClass *klass); -static void msd_dummy_manager_init (MsdDummyManager *dummy_manager); -static void msd_dummy_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdDummyManager, msd_dummy_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -gboolean -msd_dummy_manager_start (MsdDummyManager *manager, - GError **error) -{ - g_debug ("Starting dummy manager"); - mate_settings_profile_start (NULL); - mate_settings_profile_end (NULL); - return TRUE; -} - -void -msd_dummy_manager_stop (MsdDummyManager *manager) -{ - g_debug ("Stopping dummy manager"); -} - -static void -msd_dummy_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdDummyManager *self; - - self = MSD_DUMMY_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_dummy_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdDummyManager *self; - - self = MSD_DUMMY_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_dummy_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdDummyManager *dummy_manager; - MsdDummyManagerClass *klass; - - klass = MSD_DUMMY_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_DUMMY_MANAGER)); - - dummy_manager = MSD_DUMMY_MANAGER (G_OBJECT_CLASS (msd_dummy_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (dummy_manager); -} - -static void -msd_dummy_manager_dispose (GObject *object) -{ - MsdDummyManager *dummy_manager; - - dummy_manager = MSD_DUMMY_MANAGER (object); - - G_OBJECT_CLASS (msd_dummy_manager_parent_class)->dispose (object); -} - -static void -msd_dummy_manager_class_init (MsdDummyManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_dummy_manager_get_property; - object_class->set_property = msd_dummy_manager_set_property; - object_class->constructor = msd_dummy_manager_constructor; - object_class->dispose = msd_dummy_manager_dispose; - object_class->finalize = msd_dummy_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdDummyManagerPrivate)); -} - -static void -msd_dummy_manager_init (MsdDummyManager *manager) -{ - manager->priv = MSD_DUMMY_MANAGER_GET_PRIVATE (manager); - -} - -static void -msd_dummy_manager_finalize (GObject *object) -{ - MsdDummyManager *dummy_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_DUMMY_MANAGER (object)); - - dummy_manager = MSD_DUMMY_MANAGER (object); - - g_return_if_fail (dummy_manager->priv != NULL); - - G_OBJECT_CLASS (msd_dummy_manager_parent_class)->finalize (object); -} - -MsdDummyManager * -msd_dummy_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_DUMMY_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_DUMMY_MANAGER (manager_object); -} diff --git a/plugins/dummy/gsd-dummy-manager.h b/plugins/dummy/gsd-dummy-manager.h deleted file mode 100644 index 91f989a..0000000 --- a/plugins/dummy/gsd-dummy-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_DUMMY_MANAGER_H -#define __MSD_DUMMY_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_DUMMY_MANAGER (msd_dummy_manager_get_type ()) -#define MSD_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManager)) -#define MSD_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerClass)) -#define MSD_IS_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_DUMMY_MANAGER)) -#define MSD_IS_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_DUMMY_MANAGER)) -#define MSD_DUMMY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerClass)) - -typedef struct MsdDummyManagerPrivate MsdDummyManagerPrivate; - -typedef struct -{ - GObject parent; - MsdDummyManagerPrivate *priv; -} MsdDummyManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdDummyManagerClass; - -GType msd_dummy_manager_get_type (void); - -MsdDummyManager * msd_dummy_manager_new (void); -gboolean msd_dummy_manager_start (MsdDummyManager *manager, - GError **error); -void msd_dummy_manager_stop (MsdDummyManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_DUMMY_MANAGER_H */ diff --git a/plugins/dummy/gsd-dummy-plugin.c b/plugins/dummy/gsd-dummy-plugin.c deleted file mode 100644 index c1e18bb..0000000 --- a/plugins/dummy/gsd-dummy-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-dummy-plugin.h" -#include "msd-dummy-manager.h" - -struct MsdDummyPluginPrivate { - MsdDummyManager *manager; -}; - -#define MSD_DUMMY_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdDummyPlugin, msd_dummy_plugin) - -static void -msd_dummy_plugin_init (MsdDummyPlugin *plugin) -{ - plugin->priv = MSD_DUMMY_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdDummyPlugin initializing"); - - plugin->priv->manager = msd_dummy_manager_new (); -} - -static void -msd_dummy_plugin_finalize (GObject *object) -{ - MsdDummyPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_DUMMY_PLUGIN (object)); - - g_debug ("MsdDummyPlugin finalizing"); - - plugin = MSD_DUMMY_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_dummy_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating dummy plugin"); - - error = NULL; - res = msd_dummy_manager_start (MSD_DUMMY_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start dummy manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating dummy plugin"); - msd_dummy_manager_stop (MSD_DUMMY_PLUGIN (plugin)->priv->manager); -} - -static void -msd_dummy_plugin_class_init (MsdDummyPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_dummy_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdDummyPluginPrivate)); -} diff --git a/plugins/dummy/gsd-dummy-plugin.h b/plugins/dummy/gsd-dummy-plugin.h deleted file mode 100644 index f07f78c..0000000 --- a/plugins/dummy/gsd-dummy-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_DUMMY_PLUGIN_H__ -#define __MSD_DUMMY_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_DUMMY_PLUGIN (msd_dummy_plugin_get_type ()) -#define MSD_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPlugin)) -#define MSD_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginClass)) -#define MSD_IS_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_DUMMY_PLUGIN)) -#define MSD_IS_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_DUMMY_PLUGIN)) -#define MSD_DUMMY_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginClass)) - -typedef struct MsdDummyPluginPrivate MsdDummyPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdDummyPluginPrivate *priv; -} MsdDummyPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdDummyPluginClass; - -GType msd_dummy_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_DUMMY_PLUGIN_H__ */ diff --git a/plugins/dummy/msd-dummy-manager.c b/plugins/dummy/msd-dummy-manager.c new file mode 100644 index 0000000..2744aeb --- /dev/null +++ b/plugins/dummy/msd-dummy-manager.c @@ -0,0 +1,186 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "mate-settings-profile.h" +#include "msd-dummy-manager.h" + +#define MSD_DUMMY_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerPrivate)) + +struct MsdDummyManagerPrivate +{ + gboolean padding; +}; + +enum { + PROP_0, +}; + +static void msd_dummy_manager_class_init (MsdDummyManagerClass *klass); +static void msd_dummy_manager_init (MsdDummyManager *dummy_manager); +static void msd_dummy_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdDummyManager, msd_dummy_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +gboolean +msd_dummy_manager_start (MsdDummyManager *manager, + GError **error) +{ + g_debug ("Starting dummy manager"); + mate_settings_profile_start (NULL); + mate_settings_profile_end (NULL); + return TRUE; +} + +void +msd_dummy_manager_stop (MsdDummyManager *manager) +{ + g_debug ("Stopping dummy manager"); +} + +static void +msd_dummy_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdDummyManager *self; + + self = MSD_DUMMY_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_dummy_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdDummyManager *self; + + self = MSD_DUMMY_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_dummy_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdDummyManager *dummy_manager; + MsdDummyManagerClass *klass; + + klass = MSD_DUMMY_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_DUMMY_MANAGER)); + + dummy_manager = MSD_DUMMY_MANAGER (G_OBJECT_CLASS (msd_dummy_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (dummy_manager); +} + +static void +msd_dummy_manager_dispose (GObject *object) +{ + MsdDummyManager *dummy_manager; + + dummy_manager = MSD_DUMMY_MANAGER (object); + + G_OBJECT_CLASS (msd_dummy_manager_parent_class)->dispose (object); +} + +static void +msd_dummy_manager_class_init (MsdDummyManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_dummy_manager_get_property; + object_class->set_property = msd_dummy_manager_set_property; + object_class->constructor = msd_dummy_manager_constructor; + object_class->dispose = msd_dummy_manager_dispose; + object_class->finalize = msd_dummy_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdDummyManagerPrivate)); +} + +static void +msd_dummy_manager_init (MsdDummyManager *manager) +{ + manager->priv = MSD_DUMMY_MANAGER_GET_PRIVATE (manager); + +} + +static void +msd_dummy_manager_finalize (GObject *object) +{ + MsdDummyManager *dummy_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_DUMMY_MANAGER (object)); + + dummy_manager = MSD_DUMMY_MANAGER (object); + + g_return_if_fail (dummy_manager->priv != NULL); + + G_OBJECT_CLASS (msd_dummy_manager_parent_class)->finalize (object); +} + +MsdDummyManager * +msd_dummy_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_DUMMY_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_DUMMY_MANAGER (manager_object); +} diff --git a/plugins/dummy/msd-dummy-manager.h b/plugins/dummy/msd-dummy-manager.h new file mode 100644 index 0000000..91f989a --- /dev/null +++ b/plugins/dummy/msd-dummy-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_DUMMY_MANAGER_H +#define __MSD_DUMMY_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_DUMMY_MANAGER (msd_dummy_manager_get_type ()) +#define MSD_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManager)) +#define MSD_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerClass)) +#define MSD_IS_DUMMY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_DUMMY_MANAGER)) +#define MSD_IS_DUMMY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_DUMMY_MANAGER)) +#define MSD_DUMMY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_DUMMY_MANAGER, MsdDummyManagerClass)) + +typedef struct MsdDummyManagerPrivate MsdDummyManagerPrivate; + +typedef struct +{ + GObject parent; + MsdDummyManagerPrivate *priv; +} MsdDummyManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdDummyManagerClass; + +GType msd_dummy_manager_get_type (void); + +MsdDummyManager * msd_dummy_manager_new (void); +gboolean msd_dummy_manager_start (MsdDummyManager *manager, + GError **error); +void msd_dummy_manager_stop (MsdDummyManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_DUMMY_MANAGER_H */ diff --git a/plugins/dummy/msd-dummy-plugin.c b/plugins/dummy/msd-dummy-plugin.c new file mode 100644 index 0000000..c1e18bb --- /dev/null +++ b/plugins/dummy/msd-dummy-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-dummy-plugin.h" +#include "msd-dummy-manager.h" + +struct MsdDummyPluginPrivate { + MsdDummyManager *manager; +}; + +#define MSD_DUMMY_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdDummyPlugin, msd_dummy_plugin) + +static void +msd_dummy_plugin_init (MsdDummyPlugin *plugin) +{ + plugin->priv = MSD_DUMMY_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdDummyPlugin initializing"); + + plugin->priv->manager = msd_dummy_manager_new (); +} + +static void +msd_dummy_plugin_finalize (GObject *object) +{ + MsdDummyPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_DUMMY_PLUGIN (object)); + + g_debug ("MsdDummyPlugin finalizing"); + + plugin = MSD_DUMMY_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_dummy_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating dummy plugin"); + + error = NULL; + res = msd_dummy_manager_start (MSD_DUMMY_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start dummy manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating dummy plugin"); + msd_dummy_manager_stop (MSD_DUMMY_PLUGIN (plugin)->priv->manager); +} + +static void +msd_dummy_plugin_class_init (MsdDummyPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_dummy_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdDummyPluginPrivate)); +} diff --git a/plugins/dummy/msd-dummy-plugin.h b/plugins/dummy/msd-dummy-plugin.h new file mode 100644 index 0000000..f07f78c --- /dev/null +++ b/plugins/dummy/msd-dummy-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_DUMMY_PLUGIN_H__ +#define __MSD_DUMMY_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_DUMMY_PLUGIN (msd_dummy_plugin_get_type ()) +#define MSD_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPlugin)) +#define MSD_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginClass)) +#define MSD_IS_DUMMY_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_DUMMY_PLUGIN)) +#define MSD_IS_DUMMY_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_DUMMY_PLUGIN)) +#define MSD_DUMMY_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_DUMMY_PLUGIN, MsdDummyPluginClass)) + +typedef struct MsdDummyPluginPrivate MsdDummyPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdDummyPluginPrivate *priv; +} MsdDummyPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdDummyPluginClass; + +GType msd_dummy_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_DUMMY_PLUGIN_H__ */ diff --git a/plugins/font/gsd-font-manager.c b/plugins/font/gsd-font-manager.c deleted file mode 100644 index bcae037..0000000 --- a/plugins/font/gsd-font-manager.c +++ /dev/null @@ -1,445 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 The MATE Foundation - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "mate-settings-profile.h" -#include "msd-font-manager.h" -#include "delayed-dialog.h" - -static void msd_font_manager_class_init (MsdFontManagerClass *klass); -static void msd_font_manager_init (MsdFontManager *font_manager); - -G_DEFINE_TYPE (MsdFontManager, msd_font_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -static void -update_property (GString *props, const gchar* key, const gchar* value) -{ - gchar* needle; - size_t needle_len; - gchar* found = NULL; - - /* update an existing property */ - needle = g_strconcat (key, ":", NULL); - needle_len = strlen (needle); - if (g_str_has_prefix (props->str, needle)) - found = props->str; - else - found = strstr (props->str, needle); - - if (found) { - size_t value_index; - gchar* end; - - end = strchr (found, '\n'); - value_index = (found - props->str) + needle_len + 1; - g_string_erase (props, value_index, end ? (end - found - needle_len) : -1); - g_string_insert (props, value_index, "\n"); - g_string_insert (props, value_index, value); - } else { - g_string_append_printf (props, "%s:\t%s\n", key, value); - } -} - -static void -load_xcursor_theme (MateConfClient *client) -{ - char *cursor_theme; - int size; - GString *add_string; - Display *dpy; - gchar numbuf[20]; - - mate_settings_profile_start (NULL); - - size = mateconf_client_get_int (client, - "/desktop/mate/peripherals/mouse/cursor_size", - NULL); - if (size <= 0) { - return; - } - - cursor_theme = mateconf_client_get_string (client, - "/desktop/mate/peripherals/mouse/cursor_theme", - NULL); - if (cursor_theme == NULL) { - return; - } - - /* get existing properties */ - dpy = XOpenDisplay (NULL); - g_return_if_fail (dpy != NULL); - add_string = g_string_new (XResourceManagerString (dpy)); - g_debug("load_xcursor_theme: existing res '%s'", add_string->str); - - update_property (add_string, "Xcursor.theme", cursor_theme); - update_property (add_string, "Xcursor.theme_core", "true"); - g_snprintf (numbuf, sizeof (numbuf), "%i", size); - update_property (add_string, "Xcursor.size", numbuf); - - g_debug("load_xcursor_theme: new res '%s'", add_string->str); - - /* Set the new X property */ - XChangeProperty(dpy, RootWindow (dpy, 0), - XA_RESOURCE_MANAGER, XA_STRING, 8, PropModeReplace, add_string->str, add_string->len); - XCloseDisplay (dpy); - - g_free (cursor_theme); - g_string_free (add_string, TRUE); - - mate_settings_profile_end (NULL); -} - -static char* setup_dir(const char* font_dir_name, gboolean create) -{ - #if GLIB_CHECK_VERSION(2, 6, 0) - char* font_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "mate", "share", font_dir_name, NULL); - #else // glib version < 2.6.0 - char* font_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_home_dir(), ".config", "mate", "share", font_dir_name, NULL); - #endif - - if (create) - { - if (g_mkdir_with_parents(font_dir, 0755) != 0) - { - g_warning("Cannot create needed directory \"%s\".", font_dir); - g_free(font_dir); - font_dir = NULL; - } - } - else if (!g_file_test(font_dir, G_FILE_TEST_EXISTS)) - { - g_free (font_dir); - font_dir = NULL; - } - - return font_dir; -} - -static char * -empty_check_dir (char *font_dir) -{ - char *file_name; - - if (!font_dir) - return NULL; - - /* remove the fonts.dir and fonts.scale files that mkfontdir generates. */ - - file_name = g_build_filename (G_DIR_SEPARATOR_S, font_dir, "fonts.dir", NULL); - unlink (file_name); - g_free (file_name); - - file_name = g_build_filename (G_DIR_SEPARATOR_S, font_dir, "fonts.scale", NULL); - unlink (file_name); - g_free (file_name); - - /* if it's empty, get rid of it. */ - if (0 == rmdir (font_dir)) { - g_free (font_dir); - font_dir = NULL; - } - - return font_dir; -} - -static char* -setup_font_dir (MateConfClient *client) -{ - return empty_check_dir (setup_dir ("fonts", FALSE)); -} - -static char* -setup_cursor_dir (MateConfClient *client) -{ - char *cursor_dir; - char *cursor_font; - DIR *dir; - struct dirent *file_dirent; - - cursor_font = mateconf_client_get_string (client, - "/desktop/mate/peripherals/mouse/cursor_font", - NULL); - if (cursor_font != NULL) { - if (!g_path_is_absolute (cursor_font) || - !g_file_test (cursor_font, G_FILE_TEST_IS_REGULAR)) { - /* font file is not usable */ - g_free (cursor_font); - cursor_font = NULL; - } - } - - cursor_dir = setup_dir ("cursor-fonts", cursor_font != NULL); - - /* remove previously made symlinks, if any */ - if (cursor_dir) { - dir = opendir (cursor_dir); - while ((file_dirent = readdir (dir)) != NULL) { - struct stat st; - char *link_name; - - link_name = g_build_filename (cursor_dir, file_dirent->d_name, NULL); - if (lstat (link_name, &st)) { - g_free (link_name); - continue; - } - g_free (link_name); - - if (S_ISLNK (st.st_mode)) - unlink (link_name); - } - closedir (dir); - } - - if (cursor_font && cursor_dir) { - char *newpath; - char *font_name; - - font_name = strrchr (cursor_font, G_DIR_SEPARATOR); - newpath = g_build_filename (cursor_dir, font_name, NULL); - symlink (cursor_font, newpath); - g_free (newpath); - g_free (cursor_font); - cursor_font = NULL; - } else { - cursor_dir = empty_check_dir (cursor_dir); - } - - return cursor_dir; -} - -static void -load_font_paths (MateConfClient *client) -{ - char *font_dir_name; - char *cursor_dir_name; - - char **font_path; - char **new_font_path; - int n_fonts; - int new_n_fonts; - - int i; - - const char *argv[4]; - int argc = 0; - - mate_settings_profile_start (NULL); - - font_dir_name = setup_font_dir (client); - cursor_dir_name = setup_cursor_dir (client); - - if (font_dir_name == NULL && cursor_dir_name == NULL) - goto done; - - /* run mkfontdir */ - argv[argc++] = "mkfontdir"; - if (font_dir_name) - argv[argc++] = font_dir_name; - if (cursor_dir_name) - argv[argc++] = cursor_dir_name; - argv[argc] = NULL; - g_spawn_sync (NULL, /* current dir */ - (char **) (void *) argv, NULL /* envp */, - G_SPAWN_SEARCH_PATH, - NULL, NULL, /* child_setup */ - NULL, NULL, NULL, NULL); - - /* Set the font path */ - font_path = XGetFontPath (gdk_x11_get_default_xdisplay (), &n_fonts); - new_n_fonts = n_fonts; - if (cursor_dir_name && (n_fonts == 0 || strcmp (font_path[0], cursor_dir_name))) - new_n_fonts++; - if (font_dir_name && (n_fonts == 0 || strcmp (font_path[n_fonts-1], font_dir_name))) - new_n_fonts++; - - if (new_n_fonts == n_fonts) - new_font_path = font_path; - else { - new_font_path = g_new0 (char *, new_n_fonts); - - if (cursor_dir_name && (n_fonts == 0 || strcmp (font_path[0], cursor_dir_name))) { - new_font_path[0] = cursor_dir_name; - for (i = 0; i < n_fonts; i++) - new_font_path [i+1] = font_path [i]; - } else { - for (i = 0; i < n_fonts; i++) - new_font_path [i] = font_path [i]; - } - - if (font_dir_name && (n_fonts == 0 || strcmp (font_path[n_fonts-1], font_dir_name))) { - new_font_path[new_n_fonts-1] = font_dir_name; - } - } - - /* We set font path even if it was not changed, to enforce dropping - * caches in the server */ - gdk_error_trap_push (); - XSetFontPath (gdk_display, new_font_path, new_n_fonts); - gdk_flush (); - - /* if there was an error setting the new path, revert */ - if (gdk_error_trap_pop ()) { - XSetFontPath (gdk_display, font_path, n_fonts); - } - - g_free (font_dir_name); - g_free (cursor_dir_name); - - if (new_font_path != font_path) - g_free (new_font_path); - - XFreeFontPath (font_path); - -done: - mate_settings_profile_end (NULL); -} - -gboolean -msd_font_manager_start (MsdFontManager *manager, - GError **error) -{ - MateConfClient *client; - - g_debug ("Starting font manager"); - mate_settings_profile_start (NULL); - - client = mateconf_client_get_default (); - - load_xcursor_theme (client); - load_font_paths (client); - - g_object_unref (client); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_font_manager_stop (MsdFontManager *manager) -{ - g_debug ("Stopping font manager"); -} - -static void -msd_font_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdFontManager *self; - - self = MSD_FONT_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_font_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdFontManager *self; - - self = MSD_FONT_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_font_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdFontManager *font_manager; - MsdFontManagerClass *klass; - - klass = MSD_FONT_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_FONT_MANAGER)); - - font_manager = MSD_FONT_MANAGER (G_OBJECT_CLASS (msd_font_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (font_manager); -} - -static void -msd_font_manager_class_init (MsdFontManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_font_manager_get_property; - object_class->set_property = msd_font_manager_set_property; - object_class->constructor = msd_font_manager_constructor; -} - -static void -msd_font_manager_init (MsdFontManager *manager) -{ -} - -MsdFontManager * -msd_font_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_FONT_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_FONT_MANAGER (manager_object); -} diff --git a/plugins/font/gsd-font-manager.h b/plugins/font/gsd-font-manager.h deleted file mode 100644 index 3709d0f..0000000 --- a/plugins/font/gsd-font-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_FONT_MANAGER_H -#define __MSD_FONT_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_FONT_MANAGER (msd_font_manager_get_type ()) -#define MSD_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_FONT_MANAGER, MsdFontManager)) -#define MSD_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_FONT_MANAGER, MsdFontManagerClass)) -#define MSD_IS_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_FONT_MANAGER)) -#define MSD_IS_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_FONT_MANAGER)) -#define MSD_FONT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_FONT_MANAGER, MsdFontManagerClass)) - -typedef struct MsdFontManagerPrivate MsdFontManagerPrivate; - -typedef struct -{ - GObject parent; - MsdFontManagerPrivate *priv; -} MsdFontManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdFontManagerClass; - -GType msd_font_manager_get_type (void); - -MsdFontManager * msd_font_manager_new (void); -gboolean msd_font_manager_start (MsdFontManager *manager, - GError **error); -void msd_font_manager_stop (MsdFontManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_FONT_MANAGER_H */ diff --git a/plugins/font/gsd-font-plugin.c b/plugins/font/gsd-font-plugin.c deleted file mode 100644 index 7711e19..0000000 --- a/plugins/font/gsd-font-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-font-plugin.h" -#include "msd-font-manager.h" - -struct MsdFontPluginPrivate { - MsdFontManager *manager; -}; - -#define MSD_FONT_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_FONT_PLUGIN, MsdFontPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdFontPlugin, msd_font_plugin) - -static void -msd_font_plugin_init (MsdFontPlugin *plugin) -{ - plugin->priv = MSD_FONT_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdFontPlugin initializing"); - - plugin->priv->manager = msd_font_manager_new (); -} - -static void -msd_font_plugin_finalize (GObject *object) -{ - MsdFontPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_FONT_PLUGIN (object)); - - g_debug ("MsdFontPlugin finalizing"); - - plugin = MSD_FONT_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_font_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating font plugin"); - - error = NULL; - res = msd_font_manager_start (MSD_FONT_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start font manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating font plugin"); - msd_font_manager_stop (MSD_FONT_PLUGIN (plugin)->priv->manager); -} - -static void -msd_font_plugin_class_init (MsdFontPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_font_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdFontPluginPrivate)); -} diff --git a/plugins/font/gsd-font-plugin.h b/plugins/font/gsd-font-plugin.h deleted file mode 100644 index 9865412..0000000 --- a/plugins/font/gsd-font-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_FONT_PLUGIN_H__ -#define __MSD_FONT_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_FONT_PLUGIN (msd_font_plugin_get_type ()) -#define MSD_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_FONT_PLUGIN, MsdFontPlugin)) -#define MSD_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_FONT_PLUGIN, MsdFontPluginClass)) -#define MSD_IS_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_FONT_PLUGIN)) -#define MSD_IS_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_FONT_PLUGIN)) -#define MSD_FONT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_FONT_PLUGIN, MsdFontPluginClass)) - -typedef struct MsdFontPluginPrivate MsdFontPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdFontPluginPrivate *priv; -} MsdFontPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdFontPluginClass; - -GType msd_font_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_FONT_PLUGIN_H__ */ diff --git a/plugins/font/msd-font-manager.c b/plugins/font/msd-font-manager.c new file mode 100644 index 0000000..bcae037 --- /dev/null +++ b/plugins/font/msd-font-manager.c @@ -0,0 +1,445 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 The MATE Foundation + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "mate-settings-profile.h" +#include "msd-font-manager.h" +#include "delayed-dialog.h" + +static void msd_font_manager_class_init (MsdFontManagerClass *klass); +static void msd_font_manager_init (MsdFontManager *font_manager); + +G_DEFINE_TYPE (MsdFontManager, msd_font_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +static void +update_property (GString *props, const gchar* key, const gchar* value) +{ + gchar* needle; + size_t needle_len; + gchar* found = NULL; + + /* update an existing property */ + needle = g_strconcat (key, ":", NULL); + needle_len = strlen (needle); + if (g_str_has_prefix (props->str, needle)) + found = props->str; + else + found = strstr (props->str, needle); + + if (found) { + size_t value_index; + gchar* end; + + end = strchr (found, '\n'); + value_index = (found - props->str) + needle_len + 1; + g_string_erase (props, value_index, end ? (end - found - needle_len) : -1); + g_string_insert (props, value_index, "\n"); + g_string_insert (props, value_index, value); + } else { + g_string_append_printf (props, "%s:\t%s\n", key, value); + } +} + +static void +load_xcursor_theme (MateConfClient *client) +{ + char *cursor_theme; + int size; + GString *add_string; + Display *dpy; + gchar numbuf[20]; + + mate_settings_profile_start (NULL); + + size = mateconf_client_get_int (client, + "/desktop/mate/peripherals/mouse/cursor_size", + NULL); + if (size <= 0) { + return; + } + + cursor_theme = mateconf_client_get_string (client, + "/desktop/mate/peripherals/mouse/cursor_theme", + NULL); + if (cursor_theme == NULL) { + return; + } + + /* get existing properties */ + dpy = XOpenDisplay (NULL); + g_return_if_fail (dpy != NULL); + add_string = g_string_new (XResourceManagerString (dpy)); + g_debug("load_xcursor_theme: existing res '%s'", add_string->str); + + update_property (add_string, "Xcursor.theme", cursor_theme); + update_property (add_string, "Xcursor.theme_core", "true"); + g_snprintf (numbuf, sizeof (numbuf), "%i", size); + update_property (add_string, "Xcursor.size", numbuf); + + g_debug("load_xcursor_theme: new res '%s'", add_string->str); + + /* Set the new X property */ + XChangeProperty(dpy, RootWindow (dpy, 0), + XA_RESOURCE_MANAGER, XA_STRING, 8, PropModeReplace, add_string->str, add_string->len); + XCloseDisplay (dpy); + + g_free (cursor_theme); + g_string_free (add_string, TRUE); + + mate_settings_profile_end (NULL); +} + +static char* setup_dir(const char* font_dir_name, gboolean create) +{ + #if GLIB_CHECK_VERSION(2, 6, 0) + char* font_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "mate", "share", font_dir_name, NULL); + #else // glib version < 2.6.0 + char* font_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_home_dir(), ".config", "mate", "share", font_dir_name, NULL); + #endif + + if (create) + { + if (g_mkdir_with_parents(font_dir, 0755) != 0) + { + g_warning("Cannot create needed directory \"%s\".", font_dir); + g_free(font_dir); + font_dir = NULL; + } + } + else if (!g_file_test(font_dir, G_FILE_TEST_EXISTS)) + { + g_free (font_dir); + font_dir = NULL; + } + + return font_dir; +} + +static char * +empty_check_dir (char *font_dir) +{ + char *file_name; + + if (!font_dir) + return NULL; + + /* remove the fonts.dir and fonts.scale files that mkfontdir generates. */ + + file_name = g_build_filename (G_DIR_SEPARATOR_S, font_dir, "fonts.dir", NULL); + unlink (file_name); + g_free (file_name); + + file_name = g_build_filename (G_DIR_SEPARATOR_S, font_dir, "fonts.scale", NULL); + unlink (file_name); + g_free (file_name); + + /* if it's empty, get rid of it. */ + if (0 == rmdir (font_dir)) { + g_free (font_dir); + font_dir = NULL; + } + + return font_dir; +} + +static char* +setup_font_dir (MateConfClient *client) +{ + return empty_check_dir (setup_dir ("fonts", FALSE)); +} + +static char* +setup_cursor_dir (MateConfClient *client) +{ + char *cursor_dir; + char *cursor_font; + DIR *dir; + struct dirent *file_dirent; + + cursor_font = mateconf_client_get_string (client, + "/desktop/mate/peripherals/mouse/cursor_font", + NULL); + if (cursor_font != NULL) { + if (!g_path_is_absolute (cursor_font) || + !g_file_test (cursor_font, G_FILE_TEST_IS_REGULAR)) { + /* font file is not usable */ + g_free (cursor_font); + cursor_font = NULL; + } + } + + cursor_dir = setup_dir ("cursor-fonts", cursor_font != NULL); + + /* remove previously made symlinks, if any */ + if (cursor_dir) { + dir = opendir (cursor_dir); + while ((file_dirent = readdir (dir)) != NULL) { + struct stat st; + char *link_name; + + link_name = g_build_filename (cursor_dir, file_dirent->d_name, NULL); + if (lstat (link_name, &st)) { + g_free (link_name); + continue; + } + g_free (link_name); + + if (S_ISLNK (st.st_mode)) + unlink (link_name); + } + closedir (dir); + } + + if (cursor_font && cursor_dir) { + char *newpath; + char *font_name; + + font_name = strrchr (cursor_font, G_DIR_SEPARATOR); + newpath = g_build_filename (cursor_dir, font_name, NULL); + symlink (cursor_font, newpath); + g_free (newpath); + g_free (cursor_font); + cursor_font = NULL; + } else { + cursor_dir = empty_check_dir (cursor_dir); + } + + return cursor_dir; +} + +static void +load_font_paths (MateConfClient *client) +{ + char *font_dir_name; + char *cursor_dir_name; + + char **font_path; + char **new_font_path; + int n_fonts; + int new_n_fonts; + + int i; + + const char *argv[4]; + int argc = 0; + + mate_settings_profile_start (NULL); + + font_dir_name = setup_font_dir (client); + cursor_dir_name = setup_cursor_dir (client); + + if (font_dir_name == NULL && cursor_dir_name == NULL) + goto done; + + /* run mkfontdir */ + argv[argc++] = "mkfontdir"; + if (font_dir_name) + argv[argc++] = font_dir_name; + if (cursor_dir_name) + argv[argc++] = cursor_dir_name; + argv[argc] = NULL; + g_spawn_sync (NULL, /* current dir */ + (char **) (void *) argv, NULL /* envp */, + G_SPAWN_SEARCH_PATH, + NULL, NULL, /* child_setup */ + NULL, NULL, NULL, NULL); + + /* Set the font path */ + font_path = XGetFontPath (gdk_x11_get_default_xdisplay (), &n_fonts); + new_n_fonts = n_fonts; + if (cursor_dir_name && (n_fonts == 0 || strcmp (font_path[0], cursor_dir_name))) + new_n_fonts++; + if (font_dir_name && (n_fonts == 0 || strcmp (font_path[n_fonts-1], font_dir_name))) + new_n_fonts++; + + if (new_n_fonts == n_fonts) + new_font_path = font_path; + else { + new_font_path = g_new0 (char *, new_n_fonts); + + if (cursor_dir_name && (n_fonts == 0 || strcmp (font_path[0], cursor_dir_name))) { + new_font_path[0] = cursor_dir_name; + for (i = 0; i < n_fonts; i++) + new_font_path [i+1] = font_path [i]; + } else { + for (i = 0; i < n_fonts; i++) + new_font_path [i] = font_path [i]; + } + + if (font_dir_name && (n_fonts == 0 || strcmp (font_path[n_fonts-1], font_dir_name))) { + new_font_path[new_n_fonts-1] = font_dir_name; + } + } + + /* We set font path even if it was not changed, to enforce dropping + * caches in the server */ + gdk_error_trap_push (); + XSetFontPath (gdk_display, new_font_path, new_n_fonts); + gdk_flush (); + + /* if there was an error setting the new path, revert */ + if (gdk_error_trap_pop ()) { + XSetFontPath (gdk_display, font_path, n_fonts); + } + + g_free (font_dir_name); + g_free (cursor_dir_name); + + if (new_font_path != font_path) + g_free (new_font_path); + + XFreeFontPath (font_path); + +done: + mate_settings_profile_end (NULL); +} + +gboolean +msd_font_manager_start (MsdFontManager *manager, + GError **error) +{ + MateConfClient *client; + + g_debug ("Starting font manager"); + mate_settings_profile_start (NULL); + + client = mateconf_client_get_default (); + + load_xcursor_theme (client); + load_font_paths (client); + + g_object_unref (client); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_font_manager_stop (MsdFontManager *manager) +{ + g_debug ("Stopping font manager"); +} + +static void +msd_font_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdFontManager *self; + + self = MSD_FONT_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_font_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdFontManager *self; + + self = MSD_FONT_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_font_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdFontManager *font_manager; + MsdFontManagerClass *klass; + + klass = MSD_FONT_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_FONT_MANAGER)); + + font_manager = MSD_FONT_MANAGER (G_OBJECT_CLASS (msd_font_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (font_manager); +} + +static void +msd_font_manager_class_init (MsdFontManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_font_manager_get_property; + object_class->set_property = msd_font_manager_set_property; + object_class->constructor = msd_font_manager_constructor; +} + +static void +msd_font_manager_init (MsdFontManager *manager) +{ +} + +MsdFontManager * +msd_font_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_FONT_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_FONT_MANAGER (manager_object); +} diff --git a/plugins/font/msd-font-manager.h b/plugins/font/msd-font-manager.h new file mode 100644 index 0000000..3709d0f --- /dev/null +++ b/plugins/font/msd-font-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_FONT_MANAGER_H +#define __MSD_FONT_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_FONT_MANAGER (msd_font_manager_get_type ()) +#define MSD_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_FONT_MANAGER, MsdFontManager)) +#define MSD_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_FONT_MANAGER, MsdFontManagerClass)) +#define MSD_IS_FONT_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_FONT_MANAGER)) +#define MSD_IS_FONT_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_FONT_MANAGER)) +#define MSD_FONT_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_FONT_MANAGER, MsdFontManagerClass)) + +typedef struct MsdFontManagerPrivate MsdFontManagerPrivate; + +typedef struct +{ + GObject parent; + MsdFontManagerPrivate *priv; +} MsdFontManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdFontManagerClass; + +GType msd_font_manager_get_type (void); + +MsdFontManager * msd_font_manager_new (void); +gboolean msd_font_manager_start (MsdFontManager *manager, + GError **error); +void msd_font_manager_stop (MsdFontManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_FONT_MANAGER_H */ diff --git a/plugins/font/msd-font-plugin.c b/plugins/font/msd-font-plugin.c new file mode 100644 index 0000000..7711e19 --- /dev/null +++ b/plugins/font/msd-font-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-font-plugin.h" +#include "msd-font-manager.h" + +struct MsdFontPluginPrivate { + MsdFontManager *manager; +}; + +#define MSD_FONT_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_FONT_PLUGIN, MsdFontPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdFontPlugin, msd_font_plugin) + +static void +msd_font_plugin_init (MsdFontPlugin *plugin) +{ + plugin->priv = MSD_FONT_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdFontPlugin initializing"); + + plugin->priv->manager = msd_font_manager_new (); +} + +static void +msd_font_plugin_finalize (GObject *object) +{ + MsdFontPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_FONT_PLUGIN (object)); + + g_debug ("MsdFontPlugin finalizing"); + + plugin = MSD_FONT_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_font_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating font plugin"); + + error = NULL; + res = msd_font_manager_start (MSD_FONT_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start font manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating font plugin"); + msd_font_manager_stop (MSD_FONT_PLUGIN (plugin)->priv->manager); +} + +static void +msd_font_plugin_class_init (MsdFontPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_font_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdFontPluginPrivate)); +} diff --git a/plugins/font/msd-font-plugin.h b/plugins/font/msd-font-plugin.h new file mode 100644 index 0000000..9865412 --- /dev/null +++ b/plugins/font/msd-font-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_FONT_PLUGIN_H__ +#define __MSD_FONT_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_FONT_PLUGIN (msd_font_plugin_get_type ()) +#define MSD_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_FONT_PLUGIN, MsdFontPlugin)) +#define MSD_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_FONT_PLUGIN, MsdFontPluginClass)) +#define MSD_IS_FONT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_FONT_PLUGIN)) +#define MSD_IS_FONT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_FONT_PLUGIN)) +#define MSD_FONT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_FONT_PLUGIN, MsdFontPluginClass)) + +typedef struct MsdFontPluginPrivate MsdFontPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdFontPluginPrivate *priv; +} MsdFontPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdFontPluginClass; + +GType msd_font_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_FONT_PLUGIN_H__ */ diff --git a/plugins/housekeeping/gsd-disk-space.c b/plugins/housekeeping/gsd-disk-space.c deleted file mode 100644 index 6842ae5..0000000 --- a/plugins/housekeeping/gsd-disk-space.c +++ /dev/null @@ -1,733 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * vim: set et sw=8 ts=8: - * - * Copyright (c) 2008, Novell, Inc. - * - * Authors: Vincent Untz - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -/* gcc -DHAVE_LIBMATENOTIFY -DTEST -Wall `pkg-config --cflags --libs gobject-2.0 gio-unix-2.0 glib-2.0 gtk+-2.0 libmatenotify` -o msd-disk-space-test msd-disk-space.c */ - -#include "config.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "msd-disk-space.h" -#include "msd-ldsm-dialog.h" -#include "msd-ldsm-trash-empty.h" - - -#define GIGABYTE 1024 * 1024 * 1024 - -#define CHECK_EVERY_X_SECONDS 60 - -#define DISK_SPACE_ANALYZER "baobab" - -#define MATECONF_HOUSEKEEPING_DIR "/apps/mate_settings_daemon/plugins/housekeeping" -#define MATECONF_FREE_PC_NOTIFY_KEY "free_percent_notify" -#define MATECONF_FREE_PC_NOTIFY_AGAIN_KEY "free_percent_notify_again" -#define MATECONF_FREE_SIZE_NO_NOTIFY "free_size_gb_no_notify" -#define MATECONF_MIN_NOTIFY_PERIOD "min_notify_period" -#define MATECONF_IGNORE_PATHS "ignore_paths" - -typedef struct -{ - GUnixMountEntry *mount; - struct statvfs buf; - time_t notify_time; -} LdsmMountInfo; - -static GHashTable *ldsm_notified_hash = NULL; -static unsigned int ldsm_timeout_id = 0; -static GUnixMountMonitor *ldsm_monitor = NULL; -static double free_percent_notify = 0.05; -static double free_percent_notify_again = 0.01; -static unsigned int free_size_gb_no_notify = 2; -static unsigned int min_notify_period = 10; -static GSList *ignore_paths = NULL; -static unsigned int mateconf_notify_id; -static MateConfClient *client = NULL; -static MsdLdsmDialog *dialog = NULL; -static guint64 *time_read; - -static gchar* -ldsm_get_fs_id_for_path (const gchar *path) -{ - GFile *file; - GFileInfo *fileinfo; - gchar *attr_id_fs; - - file = g_file_new_for_path (path); - fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); - if (fileinfo) { - attr_id_fs = g_strdup (g_file_info_get_attribute_string (fileinfo, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); - g_object_unref (fileinfo); - } else { - attr_id_fs = NULL; - } - - g_object_unref (file); - - return attr_id_fs; -} - -static gboolean -ldsm_mount_has_trash (LdsmMountInfo *mount) -{ - const gchar *user_data_dir; - gchar *user_data_attr_id_fs; - gchar *path_attr_id_fs; - gboolean mount_uses_user_trash = FALSE; - gchar *trash_files_dir; - gboolean has_trash = FALSE; - GDir *dir; - const gchar *path; - - user_data_dir = g_get_user_data_dir (); - user_data_attr_id_fs = ldsm_get_fs_id_for_path (user_data_dir); - - path = g_unix_mount_get_mount_path (mount->mount); - path_attr_id_fs = ldsm_get_fs_id_for_path (path); - - if (g_strcmp0 (user_data_attr_id_fs, path_attr_id_fs) == 0) { - /* The volume that is low on space is on the same volume as our home - * directory. This means the trash is at $XDG_DATA_HOME/Trash, - * not at the root of the volume which is full. - */ - mount_uses_user_trash = TRUE; - } - - g_free (user_data_attr_id_fs); - g_free (path_attr_id_fs); - - /* I can't think of a better way to find out if a volume has any trash. Any suggestions? */ - if (mount_uses_user_trash) { - trash_files_dir = g_build_filename (g_get_user_data_dir (), "Trash", "files", NULL); - } else { - gchar *uid; - - uid = g_strdup_printf ("%d", getuid ()); - trash_files_dir = g_build_filename (path, ".Trash", uid, "files", NULL); - if (!g_file_test (trash_files_dir, G_FILE_TEST_IS_DIR)) { - gchar *trash_dir; - - g_free (trash_files_dir); - trash_dir = g_strdup_printf (".Trash-%s", uid); - trash_files_dir = g_build_filename (path, trash_dir, "files", NULL); - g_free (trash_dir); - if (!g_file_test (trash_files_dir, G_FILE_TEST_IS_DIR)) { - g_free (trash_files_dir); - g_free (uid); - return has_trash; - } - } - g_free (uid); - } - - dir = g_dir_open (trash_files_dir, 0, NULL); - if (dir) { - if (g_dir_read_name (dir)) - has_trash = TRUE; - g_dir_close (dir); - } - - g_free (trash_files_dir); - - return has_trash; -} - -static void -ldsm_analyze_path (const gchar *path) -{ - const gchar *argv[] = { DISK_SPACE_ANALYZER, path, NULL }; - - g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, NULL); -} - -static gboolean -ldsm_notify_for_mount (LdsmMountInfo *mount, - gboolean multiple_volumes, - gboolean other_usable_volumes) -{ - gchar *name, *program; - gint64 free_space; - gint response; - gboolean has_trash; - gboolean has_disk_analyzer; - gboolean retval = TRUE; - const gchar *path; - - /* Don't show a dialog if one is already displayed */ - if (dialog) - return retval; - - name = g_unix_mount_guess_name (mount->mount); - free_space = (gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail; - has_trash = ldsm_mount_has_trash (mount); - path = g_unix_mount_get_mount_path (mount->mount); - - program = g_find_program_in_path (DISK_SPACE_ANALYZER); - has_disk_analyzer = (program != NULL); - g_free (program); - - dialog = msd_ldsm_dialog_new (other_usable_volumes, - multiple_volumes, - has_disk_analyzer, - has_trash, - free_space, - name, - path); - - g_free (name); - - g_object_ref (G_OBJECT (dialog)); - response = gtk_dialog_run (GTK_DIALOG (dialog)); - - gtk_object_destroy (GTK_OBJECT (dialog)); - dialog = NULL; - - switch (response) { - case GTK_RESPONSE_CANCEL: - retval = FALSE; - break; - case MSD_LDSM_DIALOG_RESPONSE_ANALYZE: - retval = FALSE; - ldsm_analyze_path (g_unix_mount_get_mount_path (mount->mount)); - break; - case MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH: - retval = TRUE; - msd_ldsm_trash_empty (); - break; - case GTK_RESPONSE_NONE: - case GTK_RESPONSE_DELETE_EVENT: - retval = TRUE; - break; - default: - g_assert_not_reached (); - } - - return retval; -} - -static gboolean -ldsm_mount_has_space (LdsmMountInfo *mount) -{ - gdouble free_space; - - free_space = (double) mount->buf.f_bavail / (double) mount->buf.f_blocks; - /* enough free space, nothing to do */ - if (free_space > free_percent_notify) - return TRUE; - - if (((gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail) > ((gint64) free_size_gb_no_notify * GIGABYTE)) - return TRUE; - - /* If we got here, then this volume is low on space */ - return FALSE; -} - -static gboolean -ldsm_mount_is_virtual (LdsmMountInfo *mount) -{ - if (mount->buf.f_blocks == 0) { - /* Filesystems with zero blocks are virtual */ - return TRUE; - } - - return FALSE; -} - -static gint -ldsm_ignore_path_compare (gconstpointer a, - gconstpointer b) -{ - return g_strcmp0 ((const gchar *)a, (const gchar *)b); -} - -static gboolean -ldsm_mount_is_user_ignore (const gchar *path) -{ - if (g_slist_find_custom (ignore_paths, path, (GCompareFunc) ldsm_ignore_path_compare) != NULL) - return TRUE; - else - return FALSE; -} - - -static gboolean -is_in (const gchar *value, const gchar *set[]) -{ - int i; - for (i = 0; set[i] != NULL; i++) - { - if (strcmp (set[i], value) == 0) - return TRUE; - } - return FALSE; -} - -static gboolean -ldsm_mount_should_ignore (GUnixMountEntry *mount) -{ - const gchar *fs, *device, *path; - - path = g_unix_mount_get_mount_path (mount); - if (ldsm_mount_is_user_ignore (path)) - return TRUE; - - /* This is borrowed from GLib and used as a way to determine - * which mounts we should ignore by default. GLib doesn't - * expose this in a way that allows it to be used for this - * purpose - */ - - const gchar *ignore_fs[] = { - "auto", - "autofs", - "devfs", - "devpts", - "ecryptfs", - "kernfs", - "linprocfs", - "proc", - "procfs", - "ptyfs", - "selinuxfs", - "linsysfs", - "sysfs", - "tmpfs", - "usbfs", - "nfsd", - "rpc_pipefs", - "zfs", - NULL - }; - const gchar *ignore_devices[] = { - "none", - "sunrpc", - "devpts", - "nfsd", - "/dev/loop", - "/dev/vn", - NULL - }; - - fs = g_unix_mount_get_fs_type (mount); - device = g_unix_mount_get_device_path (mount); - - if (is_in (fs, ignore_fs)) - return TRUE; - - if (is_in (device, ignore_devices)) - return TRUE; - - return FALSE; -} - -static void -ldsm_free_mount_info (gpointer data) -{ - LdsmMountInfo *mount = data; - - g_return_if_fail (mount != NULL); - - g_unix_mount_free (mount->mount); - g_free (mount); -} - -static void -ldsm_maybe_warn_mounts (GList *mounts, - gboolean multiple_volumes, - gboolean other_usable_volumes) -{ - GList *l; - gboolean done = FALSE; - - for (l = mounts; l != NULL; l = l->next) { - LdsmMountInfo *mount_info = l->data; - LdsmMountInfo *previous_mount_info; - gdouble free_space; - gdouble previous_free_space; - time_t curr_time; - const gchar *path; - gboolean show_notify; - - if (done) { - /* Don't show any more dialogs if the user took action with the last one. The user action - * might free up space on multiple volumes, making the next dialog redundant. - */ - ldsm_free_mount_info (mount_info); - continue; - } - - path = g_unix_mount_get_mount_path (mount_info->mount); - - previous_mount_info = g_hash_table_lookup (ldsm_notified_hash, path); - if (previous_mount_info != NULL) - previous_free_space = (gdouble) previous_mount_info->buf.f_bavail / (gdouble) previous_mount_info->buf.f_blocks; - - free_space = (gdouble) mount_info->buf.f_bavail / (gdouble) mount_info->buf.f_blocks; - - if (previous_mount_info == NULL) { - /* We haven't notified for this mount yet */ - show_notify = TRUE; - mount_info->notify_time = time (NULL); - g_hash_table_replace (ldsm_notified_hash, g_strdup (path), mount_info); - } else if ((previous_free_space - free_space) > free_percent_notify_again) { - /* We've notified for this mount before and free space has decreased sufficiently since last time to notify again */ - curr_time = time (NULL); - if (difftime (curr_time, previous_mount_info->notify_time) > (gdouble)(min_notify_period * 60)) { - show_notify = TRUE; - mount_info->notify_time = curr_time; - } else { - /* It's too soon to show the dialog again. However, we still replace the LdsmMountInfo - * struct in the hash table, but give it the notfiy time from the previous dialog. - * This will stop the notification from reappearing unnecessarily as soon as the timeout expires. - */ - show_notify = FALSE; - mount_info->notify_time = previous_mount_info->notify_time; - } - g_hash_table_replace (ldsm_notified_hash, g_strdup (path), mount_info); - } else { - /* We've notified for this mount before, but the free space hasn't decreased sufficiently to notify again */ - ldsm_free_mount_info (mount_info); - show_notify = FALSE; - } - - if (show_notify) { - if (ldsm_notify_for_mount (mount_info, multiple_volumes, other_usable_volumes)) - done = TRUE; - } - } -} - -static gboolean -ldsm_check_all_mounts (gpointer data) -{ - GList *mounts; - GList *l; - GList *check_mounts = NULL; - GList *full_mounts = NULL; - guint number_of_mounts; - guint number_of_full_mounts; - gboolean multiple_volumes = FALSE; - gboolean other_usable_volumes = FALSE; - - /* We iterate through the static mounts in /etc/fstab first, seeing if - * they're mounted by checking if the GUnixMountPoint has a corresponding GUnixMountEntry. - * Iterating through the static mounts means we automatically ignore dynamically mounted media. - */ - mounts = g_unix_mount_points_get (time_read); - - for (l = mounts; l != NULL; l = l->next) { - GUnixMountPoint *mount_point = l->data; - GUnixMountEntry *mount; - LdsmMountInfo *mount_info; - const gchar *path; - - path = g_unix_mount_point_get_mount_path (mount_point); - mount = g_unix_mount_at (path, time_read); - g_unix_mount_point_free (mount_point); - if (mount == NULL) { - /* The GUnixMountPoint is not mounted */ - continue; - } - - mount_info = g_new0 (LdsmMountInfo, 1); - mount_info->mount = mount; - - path = g_unix_mount_get_mount_path (mount); - - if (g_unix_mount_is_readonly (mount)) { - ldsm_free_mount_info (mount_info); - continue; - } - - if (ldsm_mount_should_ignore (mount)) { - ldsm_free_mount_info (mount_info); - continue; - } - - if (statvfs (path, &mount_info->buf) != 0) { - ldsm_free_mount_info (mount_info); - continue; - } - - if (ldsm_mount_is_virtual (mount_info)) { - ldsm_free_mount_info (mount_info); - continue; - } - - check_mounts = g_list_prepend (check_mounts, mount_info); - } - - number_of_mounts = g_list_length (check_mounts); - if (number_of_mounts > 1) - multiple_volumes = TRUE; - - for (l = check_mounts; l != NULL; l = l->next) { - LdsmMountInfo *mount_info = l->data; - - if (!ldsm_mount_has_space (mount_info)) { - full_mounts = g_list_prepend (full_mounts, mount_info); - } else { - g_hash_table_remove (ldsm_notified_hash, g_unix_mount_get_mount_path (mount_info->mount)); - ldsm_free_mount_info (mount_info); - } - } - - number_of_full_mounts = g_list_length (full_mounts); - if (number_of_mounts > number_of_full_mounts) - other_usable_volumes = TRUE; - - ldsm_maybe_warn_mounts (full_mounts, multiple_volumes, - other_usable_volumes); - - g_list_free (check_mounts); - g_list_free (full_mounts); - - return TRUE; -} - -static gboolean -ldsm_is_hash_item_not_in_mounts (gpointer key, - gpointer value, - gpointer user_data) -{ - GList *l; - - for (l = (GList *) user_data; l != NULL; l = l->next) { - GUnixMountEntry *mount = l->data; - const char *path; - - path = g_unix_mount_get_mount_path (mount); - - if (strcmp (path, key) == 0) - return FALSE; - } - - return TRUE; -} - -static void -ldsm_mounts_changed (GObject *monitor, - gpointer data) -{ - GList *mounts; - - /* remove the saved data for mounts that got removed */ - mounts = g_unix_mounts_get (time_read); - g_hash_table_foreach_remove (ldsm_notified_hash, - ldsm_is_hash_item_not_in_mounts, mounts); - g_list_foreach (mounts, (GFunc) g_unix_mount_free, NULL); - - /* check the status now, for the new mounts */ - ldsm_check_all_mounts (NULL); - - /* and reset the timeout */ - if (ldsm_timeout_id) - g_source_remove (ldsm_timeout_id); - ldsm_timeout_id = g_timeout_add_seconds (CHECK_EVERY_X_SECONDS, - ldsm_check_all_mounts, NULL); -} - -static gboolean -ldsm_is_hash_item_in_ignore_paths (gpointer key, - gpointer value, - gpointer user_data) -{ - return ldsm_mount_is_user_ignore (key); -} - -static void -msd_ldsm_get_config () -{ - GError *error = NULL; - - free_percent_notify = mateconf_client_get_float (client, - MATECONF_HOUSEKEEPING_DIR "/" MATECONF_FREE_PC_NOTIFY_KEY, - &error); - if (error != NULL) { - g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); - g_clear_error (&error); - } - if (free_percent_notify >= 1 || free_percent_notify < 0) { - g_warning ("Invalid configuration of free_percent_notify: %f\n" \ - "Using sensible default", free_percent_notify); - free_percent_notify = 0.05; - } - - free_percent_notify_again = mateconf_client_get_float (client, - MATECONF_HOUSEKEEPING_DIR "/" MATECONF_FREE_PC_NOTIFY_AGAIN_KEY, - &error); - if (error != NULL) { - g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); - g_clear_error (&error); - } - if (free_percent_notify_again >= 1 || free_percent_notify_again < 0) { - g_warning ("Invalid configuration of free_percent_notify_again: %f\n" \ - "Using sensible default\n", free_percent_notify_again); - free_percent_notify_again = 0.01; - } - - free_size_gb_no_notify = mateconf_client_get_int (client, - MATECONF_HOUSEKEEPING_DIR "/" MATECONF_FREE_SIZE_NO_NOTIFY, - &error); - if (error != NULL) { - g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); - g_clear_error (&error); - } - min_notify_period = mateconf_client_get_int (client, - MATECONF_HOUSEKEEPING_DIR "/" MATECONF_MIN_NOTIFY_PERIOD, - &error); - if (error != NULL) { - g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); - g_clear_error (&error); - } - - if (ignore_paths != NULL) { - g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); - g_slist_free (ignore_paths); - } - ignore_paths = mateconf_client_get_list (client, - MATECONF_HOUSEKEEPING_DIR "/" MATECONF_IGNORE_PATHS, - MATECONF_VALUE_STRING, &error); - if (error != NULL) { - g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); - g_clear_error (&error); - } else { - /* Make sure we dont leave stale entries in ldsm_notified_hash */ - g_hash_table_foreach_remove (ldsm_notified_hash, - ldsm_is_hash_item_in_ignore_paths, NULL); - } -} - -static void -msd_ldsm_update_config (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - gpointer user_data) -{ - msd_ldsm_get_config (); -} - -void -msd_ldsm_setup (gboolean check_now) -{ - GError *error = NULL; - - if (ldsm_notified_hash || ldsm_timeout_id || ldsm_monitor) { - g_warning ("Low disk space monitor already initialized."); - return; - } - - ldsm_notified_hash = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, - ldsm_free_mount_info); - - client = mateconf_client_get_default (); - if (client != NULL) { - msd_ldsm_get_config (); - mateconf_notify_id = mateconf_client_notify_add (client, - MATECONF_HOUSEKEEPING_DIR, - (MateConfClientNotifyFunc) msd_ldsm_update_config, - NULL, NULL, &error); - if (error != NULL) { - g_warning ("Cannot register callback for MateConf notification"); - g_clear_error (&error); - } - } else { - g_warning ("Failed to get default client"); - } - - ldsm_monitor = g_unix_mount_monitor_new (); - g_unix_mount_monitor_set_rate_limit (ldsm_monitor, 1000); - g_signal_connect (ldsm_monitor, "mounts-changed", - G_CALLBACK (ldsm_mounts_changed), NULL); - - if (check_now) - ldsm_check_all_mounts (NULL); - - ldsm_timeout_id = g_timeout_add_seconds (CHECK_EVERY_X_SECONDS, - ldsm_check_all_mounts, NULL); - -} - -void -msd_ldsm_clean (void) -{ - if (ldsm_timeout_id) - g_source_remove (ldsm_timeout_id); - ldsm_timeout_id = 0; - - if (ldsm_notified_hash) - g_hash_table_destroy (ldsm_notified_hash); - ldsm_notified_hash = NULL; - - if (ldsm_monitor) - g_object_unref (ldsm_monitor); - ldsm_monitor = NULL; - - if (client) { - mateconf_client_notify_remove (client, mateconf_notify_id); - g_object_unref (client); - } - - if (dialog) { - gtk_widget_destroy (GTK_WIDGET (dialog)); - dialog = NULL; - } - - if (ignore_paths) { - g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); - g_slist_free (ignore_paths); - } -} - -#ifdef TEST -int -main (int argc, - char **argv) -{ - GMainLoop *loop; - - gtk_init (&argc, &argv); - - loop = g_main_loop_new (NULL, FALSE); - - msd_ldsm_setup (TRUE); - - g_main_loop_run (loop); - - msd_ldsm_clean (); - g_main_loop_unref (loop); - - return 0; -} -#endif /* TEST */ diff --git a/plugins/housekeeping/gsd-disk-space.h b/plugins/housekeeping/gsd-disk-space.h deleted file mode 100644 index 43f7059..0000000 --- a/plugins/housekeeping/gsd-disk-space.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * vim: set et sw=8 ts=8: - * - * Copyright (c) 2008, Novell, Inc. - * - * Authors: Vincent Untz - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_DISK_SPACE_H -#define __MSD_DISK_SPACE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void msd_ldsm_setup (gboolean check_now); -void msd_ldsm_clean (void); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_DISK_SPACE_H */ diff --git a/plugins/housekeeping/gsd-housekeeping-manager.c b/plugins/housekeeping/gsd-housekeeping-manager.c deleted file mode 100644 index 6cb3353..0000000 --- a/plugins/housekeeping/gsd-housekeeping-manager.c +++ /dev/null @@ -1,389 +0,0 @@ -/* - * Copyright (C) 2008 Michael J. Chudobiak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include - -#include "mate-settings-profile.h" -#include "msd-housekeeping-manager.h" -#include "msd-disk-space.h" - - -/* General */ -#define INTERVAL_ONCE_A_DAY 24*60*60 -#define INTERVAL_TWO_MINUTES 2*60 - - -/* Thumbnail cleaner */ -#define MATECONF_THUMB_AGE "/desktop/mate/thumbnail_cache/maximum_age" -#define DEFAULT_MAX_AGE_IN_DAYS 180 -#define MATECONF_THUMB_SIZE "/desktop/mate/thumbnail_cache/maximum_size" -#define DEFAULT_MAX_SIZE_IN_MB 512 -#define MATECONF_THUMB_BINDING_DIR "/desktop/mate/thumbnail_cache" - - -struct MsdHousekeepingManagerPrivate { - guint long_term_cb; - guint short_term_cb; - guint mateconf_notify; -}; - - -#define MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerPrivate)) - -static void msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass); -static void msd_housekeeping_manager_init (MsdHousekeepingManager *housekeeping_manager); - -G_DEFINE_TYPE (MsdHousekeepingManager, msd_housekeeping_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - - -typedef struct { - glong now; - glong max_age; - goffset total_size; - goffset max_size; -} PurgeData; - - -typedef struct { - time_t mtime; - char *path; - glong size; -} ThumbData; - - -static void -thumb_data_free (gpointer data) -{ - ThumbData *info = data; - - if (info) { - g_free (info->path); - g_free (info); - } -} - - -static GList * -read_dir_for_purge (const char *path, GList *files) -{ - GFile *read_path; - GFileEnumerator *enum_dir; - - read_path = g_file_new_for_path (path); - enum_dir = g_file_enumerate_children (read_path, - G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_TIME_MODIFIED "," - G_FILE_ATTRIBUTE_STANDARD_SIZE, - G_FILE_QUERY_INFO_NONE, - NULL, - NULL); - - if (enum_dir != NULL) { - GFileInfo *info; - while ((info = g_file_enumerator_next_file (enum_dir, NULL, NULL)) != NULL) { - const char *name; - name = g_file_info_get_name (info); - - if (strlen (name) == 36 && strcmp (name + 32, ".png") == 0) { - ThumbData *td; - GFile *entry; - char *entry_path; - GTimeVal mod_time; - - entry = g_file_get_child (read_path, name); - entry_path = g_file_get_path (entry); - g_object_unref (entry); - - g_file_info_get_modification_time (info, &mod_time); - - td = g_new0 (ThumbData, 1); - td->path = entry_path; - td->mtime = mod_time.tv_sec; - td->size = g_file_info_get_size (info); - - files = g_list_prepend (files, td); - } - g_object_unref (info); - } - g_object_unref (enum_dir); - } - g_object_unref (read_path); - - return files; -} - - -static void -purge_old_thumbnails (ThumbData *info, PurgeData *purge_data) -{ - if ((purge_data->now - info->mtime) > purge_data->max_age) { - g_unlink (info->path); - info->size = 0; - } else { - purge_data->total_size += info->size; - } -} - - -static int -sort_file_mtime (ThumbData *file1, ThumbData *file2) -{ - return file1->mtime - file2->mtime; -} - - -static int -get_mateconf_int_with_default (char *key, int default_value) -{ - /* If the key is unset, we use a non-zero default value. - A zero value corresponds to an extra-paranoid level - of cleaning - it deletes all files. We don't want that - as a default condition. */ - - MateConfValue *value; - MateConfClient *client; - int res; - - client = mateconf_client_get_default (); - value = mateconf_client_get (client, key, NULL); - g_object_unref (client); - - if (value == NULL || value->type != MATECONF_VALUE_INT) { - res = default_value; - } else { - res = mateconf_value_get_int (value); - mateconf_value_free (value); - } - - return res; -} - - -static void -purge_thumbnail_cache (void) -{ - - char *path; - GList *files; - PurgeData purge_data; - GTimeVal current_time; - - g_debug ("housekeeping: checking thumbnail cache size and freshness"); - - path = g_build_filename (g_get_home_dir (), - ".thumbnails", - "normal", - NULL); - files = read_dir_for_purge (path, NULL); - g_free (path); - - path = g_build_filename (g_get_home_dir (), - ".thumbnails", - "large", - NULL); - files = read_dir_for_purge (path, files); - g_free (path); - - path = g_build_filename (g_get_home_dir (), - ".thumbnails", - "fail", - "mate-thumbnail-factory", - NULL); - files = read_dir_for_purge (path, files); - g_free (path); - - g_get_current_time (¤t_time); - - purge_data.now = current_time.tv_sec; - purge_data.max_age = get_mateconf_int_with_default (MATECONF_THUMB_AGE, DEFAULT_MAX_AGE_IN_DAYS) * 24 * 60 * 60; - purge_data.max_size = get_mateconf_int_with_default (MATECONF_THUMB_SIZE, DEFAULT_MAX_SIZE_IN_MB) * 1024 * 1024; - purge_data.total_size = 0; - - if (purge_data.max_age >= 0) - g_list_foreach (files, (GFunc) purge_old_thumbnails, &purge_data); - - if ((purge_data.total_size > purge_data.max_size) && (purge_data.max_size >= 0)) { - GList *scan; - files = g_list_sort (files, (GCompareFunc) sort_file_mtime); - for (scan = files; scan && (purge_data.total_size > purge_data.max_size); scan = scan->next) { - ThumbData *info = scan->data; - g_unlink (info->path); - purge_data.total_size -= info->size; - } - } - - g_list_foreach (files, (GFunc) thumb_data_free, NULL); - g_list_free (files); -} - - -static gboolean -do_cleanup (MsdHousekeepingManager *manager) -{ - purge_thumbnail_cache (); - return TRUE; -} - - -static gboolean -do_cleanup_once (MsdHousekeepingManager *manager) -{ - do_cleanup (manager); - manager->priv->short_term_cb = 0; - return FALSE; -} - - -static void -do_cleanup_soon (MsdHousekeepingManager *manager) -{ - if (manager->priv->short_term_cb == 0) { - g_debug ("housekeeping: will tidy up in 2 minutes"); - manager->priv->short_term_cb = g_timeout_add_seconds (INTERVAL_TWO_MINUTES, - (GSourceFunc) do_cleanup_once, - manager); - } -} - - -static void -bindings_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdHousekeepingManager *manager) -{ - do_cleanup_soon (manager); -} - - -static guint -register_config_callback (MsdHousekeepingManager *manager, - const char *path, - MateConfClientNotifyFunc func) -{ - MateConfClient *client = mateconf_client_get_default (); - guint notify; - - mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_NONE, NULL); - notify = mateconf_client_notify_add (client, path, func, manager, NULL, NULL); - - g_object_unref (client); - - return notify; -} - - -gboolean -msd_housekeeping_manager_start (MsdHousekeepingManager *manager, - GError **error) -{ - g_debug ("Starting housekeeping manager"); - mate_settings_profile_start (NULL); - - msd_ldsm_setup (FALSE); - - manager->priv->mateconf_notify = register_config_callback (manager, - MATECONF_THUMB_BINDING_DIR, - (MateConfClientNotifyFunc) bindings_callback); - - /* Clean once, a few minutes after start-up */ - do_cleanup_soon (manager); - - /* Clean periodically, on a daily basis. */ - manager->priv->long_term_cb = g_timeout_add_seconds (INTERVAL_ONCE_A_DAY, - (GSourceFunc) do_cleanup, - manager); - mate_settings_profile_end (NULL); - - return TRUE; -} - - -void -msd_housekeeping_manager_stop (MsdHousekeepingManager *manager) -{ - MsdHousekeepingManagerPrivate *p = manager->priv; - - g_debug ("Stopping housekeeping manager"); - - if (p->mateconf_notify != 0) { - MateConfClient *client = mateconf_client_get_default (); - - mateconf_client_remove_dir (client, MATECONF_THUMB_BINDING_DIR, NULL); - mateconf_client_notify_remove (client, p->mateconf_notify); - - g_object_unref (client); - p->mateconf_notify = 0; - } - - if (p->short_term_cb) { - g_source_remove (p->short_term_cb); - p->short_term_cb = 0; - } - - if (p->long_term_cb) { - g_source_remove (p->long_term_cb); - p->long_term_cb = 0; - - /* Do a clean-up on shutdown if and only if the size or age - limits have been set to paranoid levels (zero) */ - if ((get_mateconf_int_with_default (MATECONF_THUMB_AGE, DEFAULT_MAX_AGE_IN_DAYS) == 0) || - (get_mateconf_int_with_default (MATECONF_THUMB_SIZE, DEFAULT_MAX_SIZE_IN_MB) == 0)) { - do_cleanup (manager); - } - } - - msd_ldsm_clean (); -} - - -static void -msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass) -{ - g_type_class_add_private (klass, sizeof (MsdHousekeepingManagerPrivate)); -} - - -static void -msd_housekeeping_manager_init (MsdHousekeepingManager *manager) -{ - manager->priv = MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE (manager); -} - - -MsdHousekeepingManager * -msd_housekeeping_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_HOUSEKEEPING_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_HOUSEKEEPING_MANAGER (manager_object); -} diff --git a/plugins/housekeeping/gsd-housekeeping-manager.h b/plugins/housekeeping/gsd-housekeeping-manager.h deleted file mode 100644 index 11f50a7..0000000 --- a/plugins/housekeeping/gsd-housekeeping-manager.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Michael J. Chudobiak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_HOUSEKEEPING_MANAGER_H -#define __MSD_HOUSEKEEPING_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_HOUSEKEEPING_MANAGER (msd_housekeeping_manager_get_type ()) -#define MSD_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManager)) -#define MSD_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerClass)) -#define MSD_IS_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_HOUSEKEEPING_MANAGER)) -#define MSD_IS_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_HOUSEKEEPING_MANAGER)) -#define MSD_HOUSEKEEPING_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerClass)) - -typedef struct MsdHousekeepingManagerPrivate MsdHousekeepingManagerPrivate; - -typedef struct { - GObject parent; - MsdHousekeepingManagerPrivate *priv; -} MsdHousekeepingManager; - -typedef struct { - GObjectClass parent_class; -} MsdHousekeepingManagerClass; - -GType msd_housekeeping_manager_get_type (void); - -MsdHousekeepingManager * msd_housekeeping_manager_new (void); -gboolean msd_housekeeping_manager_start (MsdHousekeepingManager *manager, - GError **error); -void msd_housekeeping_manager_stop (MsdHousekeepingManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_HOUSEKEEPING_MANAGER_H */ diff --git a/plugins/housekeeping/gsd-housekeeping-plugin.c b/plugins/housekeeping/gsd-housekeeping-plugin.c deleted file mode 100644 index 5b0cfef..0000000 --- a/plugins/housekeeping/gsd-housekeeping-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Michael J. Chudobiak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-housekeeping-plugin.h" -#include "msd-housekeeping-manager.h" - -struct MsdHousekeepingPluginPrivate { - MsdHousekeepingManager *manager; -}; - -#define MSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdHousekeepingPlugin, msd_housekeeping_plugin) - -static void -msd_housekeeping_plugin_init (MsdHousekeepingPlugin *plugin) -{ - plugin->priv = MSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdHousekeepingPlugin initializing"); - - plugin->priv->manager = msd_housekeeping_manager_new (); -} - -static void -msd_housekeeping_plugin_finalize (GObject *object) -{ - MsdHousekeepingPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_HOUSEKEEPING_PLUGIN (object)); - - g_debug ("MsdHousekeepingPlugin finalizing"); - - plugin = MSD_HOUSEKEEPING_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_housekeeping_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating housekeeping plugin"); - - error = NULL; - res = msd_housekeeping_manager_start (MSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start housekeeping manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating housekeeping plugin"); - msd_housekeeping_manager_stop (MSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager); -} - -static void -msd_housekeeping_plugin_class_init (MsdHousekeepingPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_housekeeping_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdHousekeepingPluginPrivate)); -} diff --git a/plugins/housekeeping/gsd-housekeeping-plugin.h b/plugins/housekeeping/gsd-housekeeping-plugin.h deleted file mode 100644 index 1c2d816..0000000 --- a/plugins/housekeeping/gsd-housekeeping-plugin.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Michael J. Chudobiak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_HOUSEKEEPING_PLUGIN_H__ -#define __MSD_HOUSEKEEPING_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_HOUSEKEEPING_PLUGIN (msd_housekeeping_plugin_get_type ()) -#define MSD_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPlugin)) -#define MSD_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginClass)) -#define MSD_IS_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN)) -#define MSD_IS_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_HOUSEKEEPING_PLUGIN)) -#define MSD_HOUSEKEEPING_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginClass)) - -typedef struct MsdHousekeepingPluginPrivate MsdHousekeepingPluginPrivate; - -typedef struct { - MateSettingsPlugin parent; - MsdHousekeepingPluginPrivate *priv; -} MsdHousekeepingPlugin; - -typedef struct { - MateSettingsPluginClass parent_class; -} MsdHousekeepingPluginClass; - -GType msd_housekeeping_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_HOUSEKEEPING_PLUGIN_H__ */ diff --git a/plugins/housekeeping/gsd-ldsm-dialog.c b/plugins/housekeeping/gsd-ldsm-dialog.c deleted file mode 100644 index 80ca857..0000000 --- a/plugins/housekeeping/gsd-ldsm-dialog.c +++ /dev/null @@ -1,476 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * msd-ldsm-dialog.c - * Copyright (C) Chris Coulson 2009 - * - * msd-ldsm-dialog.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * msd-ldsm-dialog.c 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include -#include - -#include "msd-ldsm-dialog.h" - -#define MATECONF_CLIENT_IGNORE_PATHS "/apps/mate_settings_daemon/plugins/housekeeping/ignore_paths" - -enum -{ - PROP_0, - PROP_OTHER_USABLE_PARTITIONS, - PROP_OTHER_PARTITIONS, - PROP_HAS_TRASH, - PROP_SPACE_REMAINING, - PROP_PARTITION_NAME, - PROP_MOUNT_PATH -}; - -struct MsdLdsmDialogPrivate -{ - GtkWidget *primary_label; - GtkWidget *secondary_label; - GtkWidget *ignore_check_button; - gboolean other_usable_partitions; - gboolean other_partitions; - gboolean has_trash; - gint64 space_remaining; - gchar *partition_name; - gchar *mount_path; -}; - -#define MSD_LDSM_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogPrivate)) - -static void msd_ldsm_dialog_class_init (MsdLdsmDialogClass *klass); -static void msd_ldsm_dialog_init (MsdLdsmDialog *dialog); - -G_DEFINE_TYPE (MsdLdsmDialog, msd_ldsm_dialog, GTK_TYPE_DIALOG); - -static const gchar* -msd_ldsm_dialog_get_checkbutton_text (MsdLdsmDialog *dialog) -{ - g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); - - if (dialog->priv->other_partitions) - return _("Don't show any warnings again for this file system"); - else - return _("Don't show any warnings again"); -} - -static gchar* -msd_ldsm_dialog_get_primary_text (MsdLdsmDialog *dialog) -{ - gchar *primary_text, *free_space; - - g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); - - free_space = g_format_size_for_display (dialog->priv->space_remaining); - - if (dialog->priv->other_partitions) { - primary_text = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."), - dialog->priv->partition_name, free_space); - } else { - primary_text = g_strdup_printf (_("This computer has only %s disk space remaining."), - free_space); - } - - g_free (free_space); - - return primary_text; -} - -static const gchar* -msd_ldsm_dialog_get_secondary_text (MsdLdsmDialog *dialog) -{ - g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); - - if (dialog->priv->other_usable_partitions) { - if (dialog->priv->has_trash) { - return _("You can free up disk space by emptying the Trash, removing " \ - "unused programs or files, or moving files to another disk or partition."); - } else { - return _("You can free up disk space by removing unused programs or files, " \ - "or by moving files to another disk or partition."); - } - } else { - if (dialog->priv->has_trash) { - return _("You can free up disk space by emptying the Trash, removing unused " \ - "programs or files, or moving files to an external disk."); - } else { - return _("You can free up disk space by removing unused programs or files, " \ - "or by moving files to an external disk."); - } - } -} - -static gint -ignore_path_compare (gconstpointer a, - gconstpointer b) -{ - return g_strcmp0 ((const gchar *)a, (const gchar *)b); -} - -static gboolean -update_ignore_paths (GSList **ignore_paths, - const gchar *mount_path, - gboolean ignore) -{ - GSList *found; - gchar *path_to_remove; - - found = g_slist_find_custom (*ignore_paths, mount_path, (GCompareFunc) ignore_path_compare); - - if (ignore && (found == NULL)) { - *ignore_paths = g_slist_prepend (*ignore_paths, g_strdup (mount_path)); - return TRUE; - } - - if (!ignore && (found != NULL)) { - path_to_remove = found->data; - *ignore_paths = g_slist_remove (*ignore_paths, path_to_remove); - g_free (path_to_remove); - return TRUE; - } - - return FALSE; -} - -static void -ignore_check_button_toggled_cb (GtkToggleButton *button, - gpointer user_data) -{ - MsdLdsmDialog *dialog = (MsdLdsmDialog *)user_data; - MateConfClient *client; - GSList *ignore_paths; - GError *error = NULL; - gboolean ignore, ret, updated; - - client = mateconf_client_get_default (); - if (client != NULL) { - ignore_paths = mateconf_client_get_list (client, - MATECONF_CLIENT_IGNORE_PATHS, - MATECONF_VALUE_STRING, &error); - if (error != NULL) { - g_warning ("Cannot change ignore preference - failed to read existing configuration: %s", - error->message ? error->message : "Unkown error"); - g_clear_error (&error); - return; - } else { - ignore = gtk_toggle_button_get_active (button); - updated = update_ignore_paths (&ignore_paths, dialog->priv->mount_path, ignore); - } - - if (!updated) - return; - - ret = mateconf_client_set_list (client, - MATECONF_CLIENT_IGNORE_PATHS, - MATECONF_VALUE_STRING, - ignore_paths, &error); - if (!ret || error != NULL) { - g_warning ("Cannot change ignore preference - failed to commit changes: %s", - error->message ? error->message : "Unkown error"); - g_clear_error (&error); - } - - g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); - g_slist_free (ignore_paths); - g_object_unref (client); - } else { - g_warning ("Cannot change ignore preference - failed to get MateConfClient"); - } -} - -static void -msd_ldsm_dialog_init (MsdLdsmDialog *dialog) -{ - GtkWidget *main_vbox, *text_vbox, *hbox; - GtkWidget *image; - - dialog->priv = MSD_LDSM_DIALOG_GET_PRIVATE (dialog); - - main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); - - /* Set up all the window stuff here */ - gtk_window_set_title (GTK_WINDOW (dialog), _("Low Disk Space")); - gtk_window_set_icon_name (GTK_WINDOW (dialog), - GTK_STOCK_DIALOG_WARNING); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); - gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); - gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - - /* We don't want a separator - they're really ugly */ - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - - /* Create the image */ - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); - - /* Create the labels */ - dialog->priv->primary_label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (dialog->priv->primary_label), TRUE); - gtk_label_set_single_line_mode (GTK_LABEL (dialog->priv->primary_label), FALSE); - gtk_misc_set_alignment (GTK_MISC (dialog->priv->primary_label), 0.0, 0.0); - - dialog->priv->secondary_label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (dialog->priv->secondary_label), TRUE); - gtk_label_set_single_line_mode (GTK_LABEL (dialog->priv->secondary_label), FALSE); - gtk_misc_set_alignment (GTK_MISC (dialog->priv->secondary_label), 0.0, 0.0); - - /* Create the check button to ignore future warnings */ - dialog->priv->ignore_check_button = gtk_check_button_new (); - /* The button should be inactive if the dialog was just called. - * I suppose it could be possible for the user to manually edit the MateConf key between - * the mount being checked and the dialog appearing, but I don't think it matters - * too much */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->ignore_check_button), FALSE); - g_signal_connect (dialog->priv->ignore_check_button, "toggled", - G_CALLBACK (ignore_check_button_toggled_cb), dialog); - - /* Now set up the dialog's GtkBox's' */ - gtk_box_set_spacing (GTK_BOX (main_vbox), 14); - - hbox = gtk_hbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); - - text_vbox = gtk_vbox_new (FALSE, 12); - - gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->primary_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->secondary_label, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->ignore_check_button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), text_vbox, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); - - /* Set up the action area */ - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), 6); - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), 5); - - gtk_widget_show_all (hbox); -} - -static void -msd_ldsm_dialog_finalize (GObject *object) -{ - MsdLdsmDialog *self; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); - - self = MSD_LDSM_DIALOG (object); - - if (self->priv->partition_name) - g_free (self->priv->partition_name); - - if (self->priv->mount_path) - g_free (self->priv->mount_path); - - G_OBJECT_CLASS (msd_ldsm_dialog_parent_class)->finalize (object); -} - -static void -msd_ldsm_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - MsdLdsmDialog *self; - - g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); - - self = MSD_LDSM_DIALOG (object); - - switch (prop_id) - { - case PROP_OTHER_USABLE_PARTITIONS: - self->priv->other_usable_partitions = g_value_get_boolean (value); - break; - case PROP_OTHER_PARTITIONS: - self->priv->other_partitions = g_value_get_boolean (value); - break; - case PROP_HAS_TRASH: - self->priv->has_trash = g_value_get_boolean (value); - break; - case PROP_SPACE_REMAINING: - self->priv->space_remaining = g_value_get_int64 (value); - break; - case PROP_PARTITION_NAME: - self->priv->partition_name = g_value_dup_string (value); - break; - case PROP_MOUNT_PATH: - self->priv->mount_path = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_ldsm_dialog_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - MsdLdsmDialog *self; - - g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); - - self = MSD_LDSM_DIALOG (object); - - switch (prop_id) - { - case PROP_OTHER_USABLE_PARTITIONS: - g_value_set_boolean (value, self->priv->other_usable_partitions); - break; - case PROP_OTHER_PARTITIONS: - g_value_set_boolean (value, self->priv->other_partitions); - break; - case PROP_HAS_TRASH: - g_value_set_boolean (value, self->priv->has_trash); - break; - case PROP_SPACE_REMAINING: - g_value_set_int64 (value, self->priv->space_remaining); - break; - case PROP_PARTITION_NAME: - g_value_set_string (value, self->priv->partition_name); - break; - case PROP_MOUNT_PATH: - g_value_set_string (value, self->priv->mount_path); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_ldsm_dialog_class_init (MsdLdsmDialogClass *klass) -{ - GObjectClass* object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = msd_ldsm_dialog_finalize; - object_class->set_property = msd_ldsm_dialog_set_property; - object_class->get_property = msd_ldsm_dialog_get_property; - - g_object_class_install_property (object_class, - PROP_OTHER_USABLE_PARTITIONS, - g_param_spec_boolean ("other-usable-partitions", - "other-usable-partitions", - "Set to TRUE if there are other usable partitions on the system", - FALSE, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_OTHER_PARTITIONS, - g_param_spec_boolean ("other-partitions", - "other-partitions", - "Set to TRUE if there are other partitions on the system", - FALSE, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_HAS_TRASH, - g_param_spec_boolean ("has-trash", - "has-trash", - "Set to TRUE if the partition has files in it's trash folder that can be deleted", - FALSE, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_SPACE_REMAINING, - g_param_spec_int64 ("space-remaining", - "space-remaining", - "Specify how much space is remaining in bytes", - G_MININT64, G_MAXINT64, 0, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_PARTITION_NAME, - g_param_spec_string ("partition-name", - "partition-name", - "Specify the name of the partition", - "Unknown", - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, - PROP_MOUNT_PATH, - g_param_spec_string ("mount-path", - "mount-path", - "Specify the mount path for the partition", - "Unknown", - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); - - g_type_class_add_private (klass, sizeof (MsdLdsmDialogPrivate)); -} - -MsdLdsmDialog* -msd_ldsm_dialog_new (gboolean other_usable_partitions, - gboolean other_partitions, - gboolean display_baobab, - gboolean display_empty_trash, - gint64 space_remaining, - const gchar *partition_name, - const gchar *mount_path) -{ - MsdLdsmDialog *dialog; - GtkWidget *button_empty_trash, *button_ignore, *button_analyze; - GtkWidget *empty_trash_image, *analyze_image, *ignore_image; - gchar *primary_text, *primary_text_markup; - const gchar *secondary_text, *checkbutton_text; - - dialog = MSD_LDSM_DIALOG (g_object_new (MSD_TYPE_LDSM_DIALOG, - "other-usable-partitions", other_usable_partitions, - "other-partitions", other_partitions, - "has-trash", display_empty_trash, - "space-remaining", space_remaining, - "partition-name", partition_name, - "mount-path", mount_path, - NULL)); - - /* Add some buttons */ - if (dialog->priv->has_trash) { - button_empty_trash = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("Empty Trash"), - MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH); - empty_trash_image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (button_empty_trash), empty_trash_image); - } - - if (display_baobab) { - button_analyze = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("Examine…"), - MSD_LDSM_DIALOG_RESPONSE_ANALYZE); - analyze_image = gtk_image_new_from_icon_name ("baobab", GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (button_analyze), analyze_image); - } - - button_ignore = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("Ignore"), - GTK_RESPONSE_CANCEL); - ignore_image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (button_ignore), ignore_image); - - gtk_widget_grab_default (button_ignore); - - /* Set the label text */ - primary_text = msd_ldsm_dialog_get_primary_text (dialog); - primary_text_markup = g_markup_printf_escaped ("%s", primary_text); - gtk_label_set_markup (GTK_LABEL (dialog->priv->primary_label), primary_text_markup); - - secondary_text = msd_ldsm_dialog_get_secondary_text (dialog); - gtk_label_set_text (GTK_LABEL (dialog->priv->secondary_label), secondary_text); - - checkbutton_text = msd_ldsm_dialog_get_checkbutton_text (dialog); - gtk_button_set_label (GTK_BUTTON (dialog->priv->ignore_check_button), checkbutton_text); - - g_free (primary_text); - g_free (primary_text_markup); - - return dialog; -} diff --git a/plugins/housekeeping/gsd-ldsm-dialog.h b/plugins/housekeeping/gsd-ldsm-dialog.h deleted file mode 100644 index 8b95fb9..0000000 --- a/plugins/housekeeping/gsd-ldsm-dialog.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * msd-ldsm-dialog.c - * Copyright (C) Chris Coulson 2009 - * - * msd-ldsm-dialog.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * msd-ldsm-dialog.c 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef _MSD_LDSM_DIALOG_H_ -#define _MSD_LDSM_DIALOG_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_LDSM_DIALOG (msd_ldsm_dialog_get_type ()) -#define MSD_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialog)) -#define MSD_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogClass)) -#define MSD_IS_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_LDSM_DIALOG)) -#define MSD_IS_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_LDSM_DIALOG)) -#define MSD_LDSM_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogClass)) - -enum -{ - MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH = -20, - MSD_LDSM_DIALOG_RESPONSE_ANALYZE = -21 -}; - -typedef struct MsdLdsmDialogPrivate MsdLdsmDialogPrivate; -typedef struct _MsdLdsmDialogClass MsdLdsmDialogClass; -typedef struct _MsdLdsmDialog MsdLdsmDialog; - -struct _MsdLdsmDialogClass -{ - GtkDialogClass parent_class; -}; - -struct _MsdLdsmDialog -{ - GtkDialog parent_instance; - MsdLdsmDialogPrivate *priv; -}; - -GType msd_ldsm_dialog_get_type (void) G_GNUC_CONST; - -MsdLdsmDialog * msd_ldsm_dialog_new (gboolean other_usable_partitions, - gboolean other_partitions, - gboolean display_baobab, - gboolean display_empty_trash, - gint64 space_remaining, - const gchar *partition_name, - const gchar *mount_path); - -#ifdef __cplusplus -} -#endif - -#endif /* _MSD_LDSM_DIALOG_H_ */ diff --git a/plugins/housekeeping/gsd-ldsm-trash-empty.c b/plugins/housekeeping/gsd-ldsm-trash-empty.c deleted file mode 100644 index 05f82cd..0000000 --- a/plugins/housekeeping/gsd-ldsm-trash-empty.c +++ /dev/null @@ -1,398 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * msd-ldsm-trash-empty.c - * Copyright (C) Chris Coulson 2009 - * (C) Ryan Lortie 2008 - * - * msd-ldsm-trash-empty.c is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * msd-ldsm-trash-empty.c 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include -#include -#include - -#include "msd-ldsm-trash-empty.h" - -#define CAJA_CONFIRM_TRASH_KEY "/apps/caja/preferences/confirm_trash" - -/* Some of this code has been borrowed from the trash-applet, courtesy of Ryan Lortie */ - -static GtkWidget *trash_empty_confirm_dialog = NULL; -static GtkWidget *trash_empty_dialog = NULL; -static GtkWidget *location_label; -static GtkWidget *file_label; -static GtkWidget *progressbar; - -static gsize trash_empty_total_files; -static gboolean trash_empty_update_pending = FALSE; -static GFile *trash_empty_current_file = NULL; -static gsize trash_empty_deleted_files; -static GTimer *timer = NULL; -static gboolean trash_empty_actually_deleting; - -static gboolean -trash_empty_done (gpointer data) -{ - gtk_widget_destroy (trash_empty_dialog); - trash_empty_dialog = NULL; - if (timer) { - g_timer_destroy (timer); - timer = NULL; - } - - return FALSE; -} - -static gboolean -trash_empty_update_dialog (gpointer user_data) -{ - gsize deleted, total; - GFile *file; - gboolean actually_deleting; - - g_assert (trash_empty_update_pending); - - deleted = trash_empty_deleted_files; - total = trash_empty_total_files; - file = trash_empty_current_file; - actually_deleting = trash_empty_actually_deleting; - - /* maybe the done() got processed first. */ - if (!trash_empty_dialog) - goto out; - - if (!actually_deleting) { - /* If we havent finished counting yet, then pulse the progressbar every 100ms. - * This stops the user from thinking the dialog has frozen if there are - * a lot of files to delete. We don't pulse it every time we are called from the - * worker thread, otherwise it moves to fast and looks hideous - */ - if (timer) { - if (g_timer_elapsed (timer, NULL) > 0.1) { - gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progressbar)); - g_timer_start (timer); - } - } else { - timer = g_timer_new (); - g_timer_start (timer); - gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progressbar)); - } - } else { - gchar *text; - gchar *tmp; - gchar *markup; - GFile *parent; - - text = g_strdup_printf (_("Removing item %lu of %lu"), - deleted, total); - gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar), text); - - g_free (text); - - if (deleted > total) - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progressbar), 1.0); - else - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progressbar), - (gdouble) deleted / (gdouble) total); - - parent = g_file_get_parent (file); - text = g_file_get_uri (parent); - g_object_unref (parent); - - gtk_label_set_text (GTK_LABEL (location_label), text); - g_free (text); - - tmp = g_file_get_basename (file); - text = g_markup_printf_escaped (_("Removing: %s"), tmp); - markup = g_strdup_printf ("%s", text); - gtk_label_set_markup (GTK_LABEL (file_label), text); - g_free (markup); - g_free (text); - g_free (tmp); - - /* unhide the labels */ - gtk_widget_show_all (GTK_WIDGET (trash_empty_dialog)); - } - -out: - trash_empty_current_file = NULL; - g_object_unref (file); - - trash_empty_update_pending = FALSE; - - return FALSE; -} - -/* Worker thread begin */ - -static void -trash_empty_maybe_schedule_update (GIOSchedulerJob *job, - GFile *file, - gsize deleted, - gboolean actually_deleting) -{ - if (!trash_empty_update_pending) { - g_assert (trash_empty_current_file == NULL); - - trash_empty_current_file = g_object_ref (file); - trash_empty_deleted_files = deleted; - trash_empty_actually_deleting = actually_deleting; - - trash_empty_update_pending = TRUE; - g_io_scheduler_job_send_to_mainloop_async (job, - trash_empty_update_dialog, - NULL, NULL); - } -} - -static void -trash_empty_delete_contents (GIOSchedulerJob *job, - GCancellable *cancellable, - GFile *file, - gboolean actually_delete, - gsize *deleted) -{ - GFileEnumerator *enumerator; - GFileInfo *info; - GFile *child; - - if (g_cancellable_is_cancelled (cancellable)) - return; - - enumerator = g_file_enumerate_children (file, - G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_STANDARD_TYPE, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, NULL); - - if (enumerator) { - while ((info = g_file_enumerator_next_file (enumerator, - cancellable, NULL)) != NULL) { - child = g_file_get_child (file, g_file_info_get_name (info)); - - if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) - trash_empty_delete_contents (job, cancellable, child, - actually_delete, deleted); - - trash_empty_maybe_schedule_update (job, child, *deleted, actually_delete); - if (actually_delete) - g_file_delete (child, cancellable, NULL); - - (*deleted)++; - - g_object_unref (child); - g_object_unref (info); - - if (g_cancellable_is_cancelled (cancellable)) - break; - } - - g_object_unref (enumerator); - } -} - -static gboolean -trash_empty_job (GIOSchedulerJob *job, - GCancellable *cancellable, - gpointer user_data) -{ - gsize deleted; - GFile *trash; - - trash = g_file_new_for_uri ("trash:///"); - - /* first do a dry run to count the number of files */ - deleted = 0; - trash_empty_delete_contents (job, cancellable, trash, FALSE, &deleted); - trash_empty_total_files = deleted; - - /* now do the real thing */ - deleted = 0; - trash_empty_delete_contents (job, cancellable, trash, TRUE, &deleted); - - /* done */ - g_object_unref (trash); - g_io_scheduler_job_send_to_mainloop_async (job, - trash_empty_done, - NULL, NULL); - - return FALSE; -} - -/* Worker thread end */ - -static void -trash_empty_start () -{ - GtkWidget *vbox1, *vbox2, *hbox; - GtkWidget *label1, *label3; - gchar *markup; - GCancellable *cancellable; - - trash_empty_dialog = gtk_dialog_new (); - gtk_window_set_default_size (GTK_WINDOW (trash_empty_dialog), 400, -1); - gtk_window_set_icon_name (GTK_WINDOW (trash_empty_dialog), "user-trash"); - gtk_window_set_title (GTK_WINDOW (trash_empty_dialog), - _("Emptying the trash")); - - vbox1 = gtk_vbox_new (FALSE, 12); - vbox2 = gtk_vbox_new (FALSE, 0); - hbox = gtk_hbox_new (FALSE, 0); - - label1 = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (label1), TRUE); - gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5); - - label3 = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (label3), TRUE); - gtk_misc_set_alignment (GTK_MISC (label3), 0.0, 0.5); - gtk_widget_hide (label3); - - location_label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (location_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (location_label), 0.0, 0.5); - - file_label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (file_label), TRUE); - gtk_misc_set_alignment (GTK_MISC (file_label), 0.0, 0.5); - - progressbar = gtk_progress_bar_new (); - gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (progressbar), 0.1); - gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar), _("Preparing to empty trash…")); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (trash_empty_dialog))), vbox1, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox1), label1, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), label3, FALSE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), location_label, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox2), progressbar, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox2), file_label, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0); - - gtk_widget_show (label1); - gtk_widget_show (vbox1); - gtk_widget_show_all (vbox2); - gtk_widget_show (hbox); - gtk_widget_show (location_label); - - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (trash_empty_dialog))), 6); - gtk_container_set_border_width (GTK_CONTAINER (vbox1), 6); - - gtk_dialog_add_button (GTK_DIALOG (trash_empty_dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - - markup = g_markup_printf_escaped ("%s", _("Emptying the trash")); - gtk_label_set_markup (GTK_LABEL (label1), markup); - /* Translators: "Emptying trash from " */ - gtk_label_set_text (GTK_LABEL (label3), _("From: ")); - - cancellable = g_cancellable_new (); - g_signal_connect_object (trash_empty_dialog, "response", - G_CALLBACK (g_cancellable_cancel), - cancellable, G_CONNECT_SWAPPED); - g_io_scheduler_push_job (trash_empty_job, NULL, NULL, 0, cancellable); - - gtk_widget_show (trash_empty_dialog); - - g_free (markup); - g_object_unref (cancellable); -} - -static void -trash_empty_confirmation_response (GtkDialog *dialog, - gint response_id, - gpointer user_data) -{ - if (response_id == GTK_RESPONSE_YES) - trash_empty_start (); - - gtk_object_destroy (GTK_OBJECT (dialog)); - trash_empty_confirm_dialog = NULL; -} - -static gboolean -trash_empty_require_confirmation () -{ - MateConfClient *client; - gboolean require_confirmation = TRUE; - GError *error = NULL; - - client = mateconf_client_get_default (); - if (client) { - require_confirmation = mateconf_client_get_bool (client, CAJA_CONFIRM_TRASH_KEY, &error); - if (error) { - g_warning ("Failed to read confirm_trash key from MateConf: %s", error->message ? error->message : "Unknown error"); - /* It's safest to assume that confirmation is required here */ - require_confirmation = TRUE; - g_error_free (error); - } - g_object_unref (client); - } - - return require_confirmation; -} - -static void -trash_empty_show_confirmation_dialog () -{ - GtkWidget *button; - - if (!trash_empty_require_confirmation ()) { - trash_empty_start (); - return; - } - - trash_empty_confirm_dialog = gtk_message_dialog_new (NULL, 0, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_NONE, - _("Empty all of the items from the trash?")); - - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (trash_empty_confirm_dialog), - _("If you choose to empty the trash, all items in " - "it will be permanently lost. Please note that " - "you can also delete them separately.")); - - gtk_dialog_add_button (GTK_DIALOG (trash_empty_confirm_dialog), GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - - button = gtk_button_new_with_mnemonic (_("_Empty Trash")); - gtk_widget_show (button); - gtk_widget_set_can_default (button, TRUE); - - gtk_dialog_add_action_widget (GTK_DIALOG (trash_empty_confirm_dialog), - button, GTK_RESPONSE_YES); - - gtk_dialog_set_default_response (GTK_DIALOG (trash_empty_confirm_dialog), - GTK_RESPONSE_YES); - - gtk_window_set_icon_name (GTK_WINDOW (trash_empty_confirm_dialog), - "user-trash"); - - gtk_widget_show (trash_empty_confirm_dialog); - - g_signal_connect (trash_empty_confirm_dialog, "response", - G_CALLBACK (trash_empty_confirmation_response), NULL); -} - -void -msd_ldsm_trash_empty () -{ - if (trash_empty_confirm_dialog) - gtk_window_present (GTK_WINDOW (trash_empty_confirm_dialog)); - else if (trash_empty_dialog) - gtk_window_present (GTK_WINDOW (trash_empty_dialog)); - else - trash_empty_show_confirmation_dialog (); -} diff --git a/plugins/housekeeping/gsd-ldsm-trash-empty.h b/plugins/housekeeping/gsd-ldsm-trash-empty.h deleted file mode 100644 index 85b09c0..0000000 --- a/plugins/housekeeping/gsd-ldsm-trash-empty.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * msd-ldsm-trash-empty.h - * Copyright (C) Chris Coulson 2009 - * - * msd-ldsm-trash-empty.h is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * msd-ldsm-trash-empty.h 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef _msd_ldsm_trash_empty_h_ -#define _msd_ldsm_trash_empty_h_ - -#include - -void msd_ldsm_trash_empty (); - -#endif /* _msd_ldsm_trash_empty_h_ */ diff --git a/plugins/housekeeping/msd-disk-space.c b/plugins/housekeeping/msd-disk-space.c new file mode 100644 index 0000000..6842ae5 --- /dev/null +++ b/plugins/housekeeping/msd-disk-space.c @@ -0,0 +1,733 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * vim: set et sw=8 ts=8: + * + * Copyright (c) 2008, Novell, Inc. + * + * Authors: Vincent Untz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* gcc -DHAVE_LIBMATENOTIFY -DTEST -Wall `pkg-config --cflags --libs gobject-2.0 gio-unix-2.0 glib-2.0 gtk+-2.0 libmatenotify` -o msd-disk-space-test msd-disk-space.c */ + +#include "config.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "msd-disk-space.h" +#include "msd-ldsm-dialog.h" +#include "msd-ldsm-trash-empty.h" + + +#define GIGABYTE 1024 * 1024 * 1024 + +#define CHECK_EVERY_X_SECONDS 60 + +#define DISK_SPACE_ANALYZER "baobab" + +#define MATECONF_HOUSEKEEPING_DIR "/apps/mate_settings_daemon/plugins/housekeeping" +#define MATECONF_FREE_PC_NOTIFY_KEY "free_percent_notify" +#define MATECONF_FREE_PC_NOTIFY_AGAIN_KEY "free_percent_notify_again" +#define MATECONF_FREE_SIZE_NO_NOTIFY "free_size_gb_no_notify" +#define MATECONF_MIN_NOTIFY_PERIOD "min_notify_period" +#define MATECONF_IGNORE_PATHS "ignore_paths" + +typedef struct +{ + GUnixMountEntry *mount; + struct statvfs buf; + time_t notify_time; +} LdsmMountInfo; + +static GHashTable *ldsm_notified_hash = NULL; +static unsigned int ldsm_timeout_id = 0; +static GUnixMountMonitor *ldsm_monitor = NULL; +static double free_percent_notify = 0.05; +static double free_percent_notify_again = 0.01; +static unsigned int free_size_gb_no_notify = 2; +static unsigned int min_notify_period = 10; +static GSList *ignore_paths = NULL; +static unsigned int mateconf_notify_id; +static MateConfClient *client = NULL; +static MsdLdsmDialog *dialog = NULL; +static guint64 *time_read; + +static gchar* +ldsm_get_fs_id_for_path (const gchar *path) +{ + GFile *file; + GFileInfo *fileinfo; + gchar *attr_id_fs; + + file = g_file_new_for_path (path); + fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_ID_FILESYSTEM, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); + if (fileinfo) { + attr_id_fs = g_strdup (g_file_info_get_attribute_string (fileinfo, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); + g_object_unref (fileinfo); + } else { + attr_id_fs = NULL; + } + + g_object_unref (file); + + return attr_id_fs; +} + +static gboolean +ldsm_mount_has_trash (LdsmMountInfo *mount) +{ + const gchar *user_data_dir; + gchar *user_data_attr_id_fs; + gchar *path_attr_id_fs; + gboolean mount_uses_user_trash = FALSE; + gchar *trash_files_dir; + gboolean has_trash = FALSE; + GDir *dir; + const gchar *path; + + user_data_dir = g_get_user_data_dir (); + user_data_attr_id_fs = ldsm_get_fs_id_for_path (user_data_dir); + + path = g_unix_mount_get_mount_path (mount->mount); + path_attr_id_fs = ldsm_get_fs_id_for_path (path); + + if (g_strcmp0 (user_data_attr_id_fs, path_attr_id_fs) == 0) { + /* The volume that is low on space is on the same volume as our home + * directory. This means the trash is at $XDG_DATA_HOME/Trash, + * not at the root of the volume which is full. + */ + mount_uses_user_trash = TRUE; + } + + g_free (user_data_attr_id_fs); + g_free (path_attr_id_fs); + + /* I can't think of a better way to find out if a volume has any trash. Any suggestions? */ + if (mount_uses_user_trash) { + trash_files_dir = g_build_filename (g_get_user_data_dir (), "Trash", "files", NULL); + } else { + gchar *uid; + + uid = g_strdup_printf ("%d", getuid ()); + trash_files_dir = g_build_filename (path, ".Trash", uid, "files", NULL); + if (!g_file_test (trash_files_dir, G_FILE_TEST_IS_DIR)) { + gchar *trash_dir; + + g_free (trash_files_dir); + trash_dir = g_strdup_printf (".Trash-%s", uid); + trash_files_dir = g_build_filename (path, trash_dir, "files", NULL); + g_free (trash_dir); + if (!g_file_test (trash_files_dir, G_FILE_TEST_IS_DIR)) { + g_free (trash_files_dir); + g_free (uid); + return has_trash; + } + } + g_free (uid); + } + + dir = g_dir_open (trash_files_dir, 0, NULL); + if (dir) { + if (g_dir_read_name (dir)) + has_trash = TRUE; + g_dir_close (dir); + } + + g_free (trash_files_dir); + + return has_trash; +} + +static void +ldsm_analyze_path (const gchar *path) +{ + const gchar *argv[] = { DISK_SPACE_ANALYZER, path, NULL }; + + g_spawn_async (NULL, (gchar **) argv, NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, NULL); +} + +static gboolean +ldsm_notify_for_mount (LdsmMountInfo *mount, + gboolean multiple_volumes, + gboolean other_usable_volumes) +{ + gchar *name, *program; + gint64 free_space; + gint response; + gboolean has_trash; + gboolean has_disk_analyzer; + gboolean retval = TRUE; + const gchar *path; + + /* Don't show a dialog if one is already displayed */ + if (dialog) + return retval; + + name = g_unix_mount_guess_name (mount->mount); + free_space = (gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail; + has_trash = ldsm_mount_has_trash (mount); + path = g_unix_mount_get_mount_path (mount->mount); + + program = g_find_program_in_path (DISK_SPACE_ANALYZER); + has_disk_analyzer = (program != NULL); + g_free (program); + + dialog = msd_ldsm_dialog_new (other_usable_volumes, + multiple_volumes, + has_disk_analyzer, + has_trash, + free_space, + name, + path); + + g_free (name); + + g_object_ref (G_OBJECT (dialog)); + response = gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_object_destroy (GTK_OBJECT (dialog)); + dialog = NULL; + + switch (response) { + case GTK_RESPONSE_CANCEL: + retval = FALSE; + break; + case MSD_LDSM_DIALOG_RESPONSE_ANALYZE: + retval = FALSE; + ldsm_analyze_path (g_unix_mount_get_mount_path (mount->mount)); + break; + case MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH: + retval = TRUE; + msd_ldsm_trash_empty (); + break; + case GTK_RESPONSE_NONE: + case GTK_RESPONSE_DELETE_EVENT: + retval = TRUE; + break; + default: + g_assert_not_reached (); + } + + return retval; +} + +static gboolean +ldsm_mount_has_space (LdsmMountInfo *mount) +{ + gdouble free_space; + + free_space = (double) mount->buf.f_bavail / (double) mount->buf.f_blocks; + /* enough free space, nothing to do */ + if (free_space > free_percent_notify) + return TRUE; + + if (((gint64) mount->buf.f_frsize * (gint64) mount->buf.f_bavail) > ((gint64) free_size_gb_no_notify * GIGABYTE)) + return TRUE; + + /* If we got here, then this volume is low on space */ + return FALSE; +} + +static gboolean +ldsm_mount_is_virtual (LdsmMountInfo *mount) +{ + if (mount->buf.f_blocks == 0) { + /* Filesystems with zero blocks are virtual */ + return TRUE; + } + + return FALSE; +} + +static gint +ldsm_ignore_path_compare (gconstpointer a, + gconstpointer b) +{ + return g_strcmp0 ((const gchar *)a, (const gchar *)b); +} + +static gboolean +ldsm_mount_is_user_ignore (const gchar *path) +{ + if (g_slist_find_custom (ignore_paths, path, (GCompareFunc) ldsm_ignore_path_compare) != NULL) + return TRUE; + else + return FALSE; +} + + +static gboolean +is_in (const gchar *value, const gchar *set[]) +{ + int i; + for (i = 0; set[i] != NULL; i++) + { + if (strcmp (set[i], value) == 0) + return TRUE; + } + return FALSE; +} + +static gboolean +ldsm_mount_should_ignore (GUnixMountEntry *mount) +{ + const gchar *fs, *device, *path; + + path = g_unix_mount_get_mount_path (mount); + if (ldsm_mount_is_user_ignore (path)) + return TRUE; + + /* This is borrowed from GLib and used as a way to determine + * which mounts we should ignore by default. GLib doesn't + * expose this in a way that allows it to be used for this + * purpose + */ + + const gchar *ignore_fs[] = { + "auto", + "autofs", + "devfs", + "devpts", + "ecryptfs", + "kernfs", + "linprocfs", + "proc", + "procfs", + "ptyfs", + "selinuxfs", + "linsysfs", + "sysfs", + "tmpfs", + "usbfs", + "nfsd", + "rpc_pipefs", + "zfs", + NULL + }; + const gchar *ignore_devices[] = { + "none", + "sunrpc", + "devpts", + "nfsd", + "/dev/loop", + "/dev/vn", + NULL + }; + + fs = g_unix_mount_get_fs_type (mount); + device = g_unix_mount_get_device_path (mount); + + if (is_in (fs, ignore_fs)) + return TRUE; + + if (is_in (device, ignore_devices)) + return TRUE; + + return FALSE; +} + +static void +ldsm_free_mount_info (gpointer data) +{ + LdsmMountInfo *mount = data; + + g_return_if_fail (mount != NULL); + + g_unix_mount_free (mount->mount); + g_free (mount); +} + +static void +ldsm_maybe_warn_mounts (GList *mounts, + gboolean multiple_volumes, + gboolean other_usable_volumes) +{ + GList *l; + gboolean done = FALSE; + + for (l = mounts; l != NULL; l = l->next) { + LdsmMountInfo *mount_info = l->data; + LdsmMountInfo *previous_mount_info; + gdouble free_space; + gdouble previous_free_space; + time_t curr_time; + const gchar *path; + gboolean show_notify; + + if (done) { + /* Don't show any more dialogs if the user took action with the last one. The user action + * might free up space on multiple volumes, making the next dialog redundant. + */ + ldsm_free_mount_info (mount_info); + continue; + } + + path = g_unix_mount_get_mount_path (mount_info->mount); + + previous_mount_info = g_hash_table_lookup (ldsm_notified_hash, path); + if (previous_mount_info != NULL) + previous_free_space = (gdouble) previous_mount_info->buf.f_bavail / (gdouble) previous_mount_info->buf.f_blocks; + + free_space = (gdouble) mount_info->buf.f_bavail / (gdouble) mount_info->buf.f_blocks; + + if (previous_mount_info == NULL) { + /* We haven't notified for this mount yet */ + show_notify = TRUE; + mount_info->notify_time = time (NULL); + g_hash_table_replace (ldsm_notified_hash, g_strdup (path), mount_info); + } else if ((previous_free_space - free_space) > free_percent_notify_again) { + /* We've notified for this mount before and free space has decreased sufficiently since last time to notify again */ + curr_time = time (NULL); + if (difftime (curr_time, previous_mount_info->notify_time) > (gdouble)(min_notify_period * 60)) { + show_notify = TRUE; + mount_info->notify_time = curr_time; + } else { + /* It's too soon to show the dialog again. However, we still replace the LdsmMountInfo + * struct in the hash table, but give it the notfiy time from the previous dialog. + * This will stop the notification from reappearing unnecessarily as soon as the timeout expires. + */ + show_notify = FALSE; + mount_info->notify_time = previous_mount_info->notify_time; + } + g_hash_table_replace (ldsm_notified_hash, g_strdup (path), mount_info); + } else { + /* We've notified for this mount before, but the free space hasn't decreased sufficiently to notify again */ + ldsm_free_mount_info (mount_info); + show_notify = FALSE; + } + + if (show_notify) { + if (ldsm_notify_for_mount (mount_info, multiple_volumes, other_usable_volumes)) + done = TRUE; + } + } +} + +static gboolean +ldsm_check_all_mounts (gpointer data) +{ + GList *mounts; + GList *l; + GList *check_mounts = NULL; + GList *full_mounts = NULL; + guint number_of_mounts; + guint number_of_full_mounts; + gboolean multiple_volumes = FALSE; + gboolean other_usable_volumes = FALSE; + + /* We iterate through the static mounts in /etc/fstab first, seeing if + * they're mounted by checking if the GUnixMountPoint has a corresponding GUnixMountEntry. + * Iterating through the static mounts means we automatically ignore dynamically mounted media. + */ + mounts = g_unix_mount_points_get (time_read); + + for (l = mounts; l != NULL; l = l->next) { + GUnixMountPoint *mount_point = l->data; + GUnixMountEntry *mount; + LdsmMountInfo *mount_info; + const gchar *path; + + path = g_unix_mount_point_get_mount_path (mount_point); + mount = g_unix_mount_at (path, time_read); + g_unix_mount_point_free (mount_point); + if (mount == NULL) { + /* The GUnixMountPoint is not mounted */ + continue; + } + + mount_info = g_new0 (LdsmMountInfo, 1); + mount_info->mount = mount; + + path = g_unix_mount_get_mount_path (mount); + + if (g_unix_mount_is_readonly (mount)) { + ldsm_free_mount_info (mount_info); + continue; + } + + if (ldsm_mount_should_ignore (mount)) { + ldsm_free_mount_info (mount_info); + continue; + } + + if (statvfs (path, &mount_info->buf) != 0) { + ldsm_free_mount_info (mount_info); + continue; + } + + if (ldsm_mount_is_virtual (mount_info)) { + ldsm_free_mount_info (mount_info); + continue; + } + + check_mounts = g_list_prepend (check_mounts, mount_info); + } + + number_of_mounts = g_list_length (check_mounts); + if (number_of_mounts > 1) + multiple_volumes = TRUE; + + for (l = check_mounts; l != NULL; l = l->next) { + LdsmMountInfo *mount_info = l->data; + + if (!ldsm_mount_has_space (mount_info)) { + full_mounts = g_list_prepend (full_mounts, mount_info); + } else { + g_hash_table_remove (ldsm_notified_hash, g_unix_mount_get_mount_path (mount_info->mount)); + ldsm_free_mount_info (mount_info); + } + } + + number_of_full_mounts = g_list_length (full_mounts); + if (number_of_mounts > number_of_full_mounts) + other_usable_volumes = TRUE; + + ldsm_maybe_warn_mounts (full_mounts, multiple_volumes, + other_usable_volumes); + + g_list_free (check_mounts); + g_list_free (full_mounts); + + return TRUE; +} + +static gboolean +ldsm_is_hash_item_not_in_mounts (gpointer key, + gpointer value, + gpointer user_data) +{ + GList *l; + + for (l = (GList *) user_data; l != NULL; l = l->next) { + GUnixMountEntry *mount = l->data; + const char *path; + + path = g_unix_mount_get_mount_path (mount); + + if (strcmp (path, key) == 0) + return FALSE; + } + + return TRUE; +} + +static void +ldsm_mounts_changed (GObject *monitor, + gpointer data) +{ + GList *mounts; + + /* remove the saved data for mounts that got removed */ + mounts = g_unix_mounts_get (time_read); + g_hash_table_foreach_remove (ldsm_notified_hash, + ldsm_is_hash_item_not_in_mounts, mounts); + g_list_foreach (mounts, (GFunc) g_unix_mount_free, NULL); + + /* check the status now, for the new mounts */ + ldsm_check_all_mounts (NULL); + + /* and reset the timeout */ + if (ldsm_timeout_id) + g_source_remove (ldsm_timeout_id); + ldsm_timeout_id = g_timeout_add_seconds (CHECK_EVERY_X_SECONDS, + ldsm_check_all_mounts, NULL); +} + +static gboolean +ldsm_is_hash_item_in_ignore_paths (gpointer key, + gpointer value, + gpointer user_data) +{ + return ldsm_mount_is_user_ignore (key); +} + +static void +msd_ldsm_get_config () +{ + GError *error = NULL; + + free_percent_notify = mateconf_client_get_float (client, + MATECONF_HOUSEKEEPING_DIR "/" MATECONF_FREE_PC_NOTIFY_KEY, + &error); + if (error != NULL) { + g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); + g_clear_error (&error); + } + if (free_percent_notify >= 1 || free_percent_notify < 0) { + g_warning ("Invalid configuration of free_percent_notify: %f\n" \ + "Using sensible default", free_percent_notify); + free_percent_notify = 0.05; + } + + free_percent_notify_again = mateconf_client_get_float (client, + MATECONF_HOUSEKEEPING_DIR "/" MATECONF_FREE_PC_NOTIFY_AGAIN_KEY, + &error); + if (error != NULL) { + g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); + g_clear_error (&error); + } + if (free_percent_notify_again >= 1 || free_percent_notify_again < 0) { + g_warning ("Invalid configuration of free_percent_notify_again: %f\n" \ + "Using sensible default\n", free_percent_notify_again); + free_percent_notify_again = 0.01; + } + + free_size_gb_no_notify = mateconf_client_get_int (client, + MATECONF_HOUSEKEEPING_DIR "/" MATECONF_FREE_SIZE_NO_NOTIFY, + &error); + if (error != NULL) { + g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); + g_clear_error (&error); + } + min_notify_period = mateconf_client_get_int (client, + MATECONF_HOUSEKEEPING_DIR "/" MATECONF_MIN_NOTIFY_PERIOD, + &error); + if (error != NULL) { + g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); + g_clear_error (&error); + } + + if (ignore_paths != NULL) { + g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); + g_slist_free (ignore_paths); + } + ignore_paths = mateconf_client_get_list (client, + MATECONF_HOUSEKEEPING_DIR "/" MATECONF_IGNORE_PATHS, + MATECONF_VALUE_STRING, &error); + if (error != NULL) { + g_warning ("Error reading configuration from MateConf: %s", error->message ? error->message : "Unknown error"); + g_clear_error (&error); + } else { + /* Make sure we dont leave stale entries in ldsm_notified_hash */ + g_hash_table_foreach_remove (ldsm_notified_hash, + ldsm_is_hash_item_in_ignore_paths, NULL); + } +} + +static void +msd_ldsm_update_config (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + gpointer user_data) +{ + msd_ldsm_get_config (); +} + +void +msd_ldsm_setup (gboolean check_now) +{ + GError *error = NULL; + + if (ldsm_notified_hash || ldsm_timeout_id || ldsm_monitor) { + g_warning ("Low disk space monitor already initialized."); + return; + } + + ldsm_notified_hash = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, + ldsm_free_mount_info); + + client = mateconf_client_get_default (); + if (client != NULL) { + msd_ldsm_get_config (); + mateconf_notify_id = mateconf_client_notify_add (client, + MATECONF_HOUSEKEEPING_DIR, + (MateConfClientNotifyFunc) msd_ldsm_update_config, + NULL, NULL, &error); + if (error != NULL) { + g_warning ("Cannot register callback for MateConf notification"); + g_clear_error (&error); + } + } else { + g_warning ("Failed to get default client"); + } + + ldsm_monitor = g_unix_mount_monitor_new (); + g_unix_mount_monitor_set_rate_limit (ldsm_monitor, 1000); + g_signal_connect (ldsm_monitor, "mounts-changed", + G_CALLBACK (ldsm_mounts_changed), NULL); + + if (check_now) + ldsm_check_all_mounts (NULL); + + ldsm_timeout_id = g_timeout_add_seconds (CHECK_EVERY_X_SECONDS, + ldsm_check_all_mounts, NULL); + +} + +void +msd_ldsm_clean (void) +{ + if (ldsm_timeout_id) + g_source_remove (ldsm_timeout_id); + ldsm_timeout_id = 0; + + if (ldsm_notified_hash) + g_hash_table_destroy (ldsm_notified_hash); + ldsm_notified_hash = NULL; + + if (ldsm_monitor) + g_object_unref (ldsm_monitor); + ldsm_monitor = NULL; + + if (client) { + mateconf_client_notify_remove (client, mateconf_notify_id); + g_object_unref (client); + } + + if (dialog) { + gtk_widget_destroy (GTK_WIDGET (dialog)); + dialog = NULL; + } + + if (ignore_paths) { + g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); + g_slist_free (ignore_paths); + } +} + +#ifdef TEST +int +main (int argc, + char **argv) +{ + GMainLoop *loop; + + gtk_init (&argc, &argv); + + loop = g_main_loop_new (NULL, FALSE); + + msd_ldsm_setup (TRUE); + + g_main_loop_run (loop); + + msd_ldsm_clean (); + g_main_loop_unref (loop); + + return 0; +} +#endif /* TEST */ diff --git a/plugins/housekeeping/msd-disk-space.h b/plugins/housekeeping/msd-disk-space.h new file mode 100644 index 0000000..43f7059 --- /dev/null +++ b/plugins/housekeeping/msd-disk-space.h @@ -0,0 +1,40 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * vim: set et sw=8 ts=8: + * + * Copyright (c) 2008, Novell, Inc. + * + * Authors: Vincent Untz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_DISK_SPACE_H +#define __MSD_DISK_SPACE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void msd_ldsm_setup (gboolean check_now); +void msd_ldsm_clean (void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_DISK_SPACE_H */ diff --git a/plugins/housekeeping/msd-housekeeping-manager.c b/plugins/housekeeping/msd-housekeeping-manager.c new file mode 100644 index 0000000..6cb3353 --- /dev/null +++ b/plugins/housekeeping/msd-housekeeping-manager.c @@ -0,0 +1,389 @@ +/* + * Copyright (C) 2008 Michael J. Chudobiak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include + +#include "mate-settings-profile.h" +#include "msd-housekeeping-manager.h" +#include "msd-disk-space.h" + + +/* General */ +#define INTERVAL_ONCE_A_DAY 24*60*60 +#define INTERVAL_TWO_MINUTES 2*60 + + +/* Thumbnail cleaner */ +#define MATECONF_THUMB_AGE "/desktop/mate/thumbnail_cache/maximum_age" +#define DEFAULT_MAX_AGE_IN_DAYS 180 +#define MATECONF_THUMB_SIZE "/desktop/mate/thumbnail_cache/maximum_size" +#define DEFAULT_MAX_SIZE_IN_MB 512 +#define MATECONF_THUMB_BINDING_DIR "/desktop/mate/thumbnail_cache" + + +struct MsdHousekeepingManagerPrivate { + guint long_term_cb; + guint short_term_cb; + guint mateconf_notify; +}; + + +#define MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerPrivate)) + +static void msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass); +static void msd_housekeeping_manager_init (MsdHousekeepingManager *housekeeping_manager); + +G_DEFINE_TYPE (MsdHousekeepingManager, msd_housekeeping_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + + +typedef struct { + glong now; + glong max_age; + goffset total_size; + goffset max_size; +} PurgeData; + + +typedef struct { + time_t mtime; + char *path; + glong size; +} ThumbData; + + +static void +thumb_data_free (gpointer data) +{ + ThumbData *info = data; + + if (info) { + g_free (info->path); + g_free (info); + } +} + + +static GList * +read_dir_for_purge (const char *path, GList *files) +{ + GFile *read_path; + GFileEnumerator *enum_dir; + + read_path = g_file_new_for_path (path); + enum_dir = g_file_enumerate_children (read_path, + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_TIME_MODIFIED "," + G_FILE_ATTRIBUTE_STANDARD_SIZE, + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); + + if (enum_dir != NULL) { + GFileInfo *info; + while ((info = g_file_enumerator_next_file (enum_dir, NULL, NULL)) != NULL) { + const char *name; + name = g_file_info_get_name (info); + + if (strlen (name) == 36 && strcmp (name + 32, ".png") == 0) { + ThumbData *td; + GFile *entry; + char *entry_path; + GTimeVal mod_time; + + entry = g_file_get_child (read_path, name); + entry_path = g_file_get_path (entry); + g_object_unref (entry); + + g_file_info_get_modification_time (info, &mod_time); + + td = g_new0 (ThumbData, 1); + td->path = entry_path; + td->mtime = mod_time.tv_sec; + td->size = g_file_info_get_size (info); + + files = g_list_prepend (files, td); + } + g_object_unref (info); + } + g_object_unref (enum_dir); + } + g_object_unref (read_path); + + return files; +} + + +static void +purge_old_thumbnails (ThumbData *info, PurgeData *purge_data) +{ + if ((purge_data->now - info->mtime) > purge_data->max_age) { + g_unlink (info->path); + info->size = 0; + } else { + purge_data->total_size += info->size; + } +} + + +static int +sort_file_mtime (ThumbData *file1, ThumbData *file2) +{ + return file1->mtime - file2->mtime; +} + + +static int +get_mateconf_int_with_default (char *key, int default_value) +{ + /* If the key is unset, we use a non-zero default value. + A zero value corresponds to an extra-paranoid level + of cleaning - it deletes all files. We don't want that + as a default condition. */ + + MateConfValue *value; + MateConfClient *client; + int res; + + client = mateconf_client_get_default (); + value = mateconf_client_get (client, key, NULL); + g_object_unref (client); + + if (value == NULL || value->type != MATECONF_VALUE_INT) { + res = default_value; + } else { + res = mateconf_value_get_int (value); + mateconf_value_free (value); + } + + return res; +} + + +static void +purge_thumbnail_cache (void) +{ + + char *path; + GList *files; + PurgeData purge_data; + GTimeVal current_time; + + g_debug ("housekeeping: checking thumbnail cache size and freshness"); + + path = g_build_filename (g_get_home_dir (), + ".thumbnails", + "normal", + NULL); + files = read_dir_for_purge (path, NULL); + g_free (path); + + path = g_build_filename (g_get_home_dir (), + ".thumbnails", + "large", + NULL); + files = read_dir_for_purge (path, files); + g_free (path); + + path = g_build_filename (g_get_home_dir (), + ".thumbnails", + "fail", + "mate-thumbnail-factory", + NULL); + files = read_dir_for_purge (path, files); + g_free (path); + + g_get_current_time (¤t_time); + + purge_data.now = current_time.tv_sec; + purge_data.max_age = get_mateconf_int_with_default (MATECONF_THUMB_AGE, DEFAULT_MAX_AGE_IN_DAYS) * 24 * 60 * 60; + purge_data.max_size = get_mateconf_int_with_default (MATECONF_THUMB_SIZE, DEFAULT_MAX_SIZE_IN_MB) * 1024 * 1024; + purge_data.total_size = 0; + + if (purge_data.max_age >= 0) + g_list_foreach (files, (GFunc) purge_old_thumbnails, &purge_data); + + if ((purge_data.total_size > purge_data.max_size) && (purge_data.max_size >= 0)) { + GList *scan; + files = g_list_sort (files, (GCompareFunc) sort_file_mtime); + for (scan = files; scan && (purge_data.total_size > purge_data.max_size); scan = scan->next) { + ThumbData *info = scan->data; + g_unlink (info->path); + purge_data.total_size -= info->size; + } + } + + g_list_foreach (files, (GFunc) thumb_data_free, NULL); + g_list_free (files); +} + + +static gboolean +do_cleanup (MsdHousekeepingManager *manager) +{ + purge_thumbnail_cache (); + return TRUE; +} + + +static gboolean +do_cleanup_once (MsdHousekeepingManager *manager) +{ + do_cleanup (manager); + manager->priv->short_term_cb = 0; + return FALSE; +} + + +static void +do_cleanup_soon (MsdHousekeepingManager *manager) +{ + if (manager->priv->short_term_cb == 0) { + g_debug ("housekeeping: will tidy up in 2 minutes"); + manager->priv->short_term_cb = g_timeout_add_seconds (INTERVAL_TWO_MINUTES, + (GSourceFunc) do_cleanup_once, + manager); + } +} + + +static void +bindings_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdHousekeepingManager *manager) +{ + do_cleanup_soon (manager); +} + + +static guint +register_config_callback (MsdHousekeepingManager *manager, + const char *path, + MateConfClientNotifyFunc func) +{ + MateConfClient *client = mateconf_client_get_default (); + guint notify; + + mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_NONE, NULL); + notify = mateconf_client_notify_add (client, path, func, manager, NULL, NULL); + + g_object_unref (client); + + return notify; +} + + +gboolean +msd_housekeeping_manager_start (MsdHousekeepingManager *manager, + GError **error) +{ + g_debug ("Starting housekeeping manager"); + mate_settings_profile_start (NULL); + + msd_ldsm_setup (FALSE); + + manager->priv->mateconf_notify = register_config_callback (manager, + MATECONF_THUMB_BINDING_DIR, + (MateConfClientNotifyFunc) bindings_callback); + + /* Clean once, a few minutes after start-up */ + do_cleanup_soon (manager); + + /* Clean periodically, on a daily basis. */ + manager->priv->long_term_cb = g_timeout_add_seconds (INTERVAL_ONCE_A_DAY, + (GSourceFunc) do_cleanup, + manager); + mate_settings_profile_end (NULL); + + return TRUE; +} + + +void +msd_housekeeping_manager_stop (MsdHousekeepingManager *manager) +{ + MsdHousekeepingManagerPrivate *p = manager->priv; + + g_debug ("Stopping housekeeping manager"); + + if (p->mateconf_notify != 0) { + MateConfClient *client = mateconf_client_get_default (); + + mateconf_client_remove_dir (client, MATECONF_THUMB_BINDING_DIR, NULL); + mateconf_client_notify_remove (client, p->mateconf_notify); + + g_object_unref (client); + p->mateconf_notify = 0; + } + + if (p->short_term_cb) { + g_source_remove (p->short_term_cb); + p->short_term_cb = 0; + } + + if (p->long_term_cb) { + g_source_remove (p->long_term_cb); + p->long_term_cb = 0; + + /* Do a clean-up on shutdown if and only if the size or age + limits have been set to paranoid levels (zero) */ + if ((get_mateconf_int_with_default (MATECONF_THUMB_AGE, DEFAULT_MAX_AGE_IN_DAYS) == 0) || + (get_mateconf_int_with_default (MATECONF_THUMB_SIZE, DEFAULT_MAX_SIZE_IN_MB) == 0)) { + do_cleanup (manager); + } + } + + msd_ldsm_clean (); +} + + +static void +msd_housekeeping_manager_class_init (MsdHousekeepingManagerClass *klass) +{ + g_type_class_add_private (klass, sizeof (MsdHousekeepingManagerPrivate)); +} + + +static void +msd_housekeeping_manager_init (MsdHousekeepingManager *manager) +{ + manager->priv = MSD_HOUSEKEEPING_MANAGER_GET_PRIVATE (manager); +} + + +MsdHousekeepingManager * +msd_housekeeping_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_HOUSEKEEPING_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_HOUSEKEEPING_MANAGER (manager_object); +} diff --git a/plugins/housekeeping/msd-housekeeping-manager.h b/plugins/housekeeping/msd-housekeeping-manager.h new file mode 100644 index 0000000..11f50a7 --- /dev/null +++ b/plugins/housekeeping/msd-housekeeping-manager.h @@ -0,0 +1,59 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Michael J. Chudobiak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_HOUSEKEEPING_MANAGER_H +#define __MSD_HOUSEKEEPING_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_HOUSEKEEPING_MANAGER (msd_housekeeping_manager_get_type ()) +#define MSD_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManager)) +#define MSD_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerClass)) +#define MSD_IS_HOUSEKEEPING_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_HOUSEKEEPING_MANAGER)) +#define MSD_IS_HOUSEKEEPING_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_HOUSEKEEPING_MANAGER)) +#define MSD_HOUSEKEEPING_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_HOUSEKEEPING_MANAGER, MsdHousekeepingManagerClass)) + +typedef struct MsdHousekeepingManagerPrivate MsdHousekeepingManagerPrivate; + +typedef struct { + GObject parent; + MsdHousekeepingManagerPrivate *priv; +} MsdHousekeepingManager; + +typedef struct { + GObjectClass parent_class; +} MsdHousekeepingManagerClass; + +GType msd_housekeeping_manager_get_type (void); + +MsdHousekeepingManager * msd_housekeeping_manager_new (void); +gboolean msd_housekeeping_manager_start (MsdHousekeepingManager *manager, + GError **error); +void msd_housekeeping_manager_stop (MsdHousekeepingManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_HOUSEKEEPING_MANAGER_H */ diff --git a/plugins/housekeeping/msd-housekeeping-plugin.c b/plugins/housekeeping/msd-housekeeping-plugin.c new file mode 100644 index 0000000..5b0cfef --- /dev/null +++ b/plugins/housekeeping/msd-housekeeping-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Michael J. Chudobiak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-housekeeping-plugin.h" +#include "msd-housekeeping-manager.h" + +struct MsdHousekeepingPluginPrivate { + MsdHousekeepingManager *manager; +}; + +#define MSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdHousekeepingPlugin, msd_housekeeping_plugin) + +static void +msd_housekeeping_plugin_init (MsdHousekeepingPlugin *plugin) +{ + plugin->priv = MSD_HOUSEKEEPING_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdHousekeepingPlugin initializing"); + + plugin->priv->manager = msd_housekeeping_manager_new (); +} + +static void +msd_housekeeping_plugin_finalize (GObject *object) +{ + MsdHousekeepingPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_HOUSEKEEPING_PLUGIN (object)); + + g_debug ("MsdHousekeepingPlugin finalizing"); + + plugin = MSD_HOUSEKEEPING_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_housekeeping_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating housekeeping plugin"); + + error = NULL; + res = msd_housekeeping_manager_start (MSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start housekeeping manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating housekeeping plugin"); + msd_housekeeping_manager_stop (MSD_HOUSEKEEPING_PLUGIN (plugin)->priv->manager); +} + +static void +msd_housekeeping_plugin_class_init (MsdHousekeepingPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_housekeeping_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdHousekeepingPluginPrivate)); +} diff --git a/plugins/housekeeping/msd-housekeeping-plugin.h b/plugins/housekeeping/msd-housekeeping-plugin.h new file mode 100644 index 0000000..1c2d816 --- /dev/null +++ b/plugins/housekeeping/msd-housekeeping-plugin.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Michael J. Chudobiak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_HOUSEKEEPING_PLUGIN_H__ +#define __MSD_HOUSEKEEPING_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_HOUSEKEEPING_PLUGIN (msd_housekeeping_plugin_get_type ()) +#define MSD_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPlugin)) +#define MSD_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginClass)) +#define MSD_IS_HOUSEKEEPING_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN)) +#define MSD_IS_HOUSEKEEPING_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_HOUSEKEEPING_PLUGIN)) +#define MSD_HOUSEKEEPING_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_HOUSEKEEPING_PLUGIN, MsdHousekeepingPluginClass)) + +typedef struct MsdHousekeepingPluginPrivate MsdHousekeepingPluginPrivate; + +typedef struct { + MateSettingsPlugin parent; + MsdHousekeepingPluginPrivate *priv; +} MsdHousekeepingPlugin; + +typedef struct { + MateSettingsPluginClass parent_class; +} MsdHousekeepingPluginClass; + +GType msd_housekeeping_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_HOUSEKEEPING_PLUGIN_H__ */ diff --git a/plugins/housekeeping/msd-ldsm-dialog.c b/plugins/housekeeping/msd-ldsm-dialog.c new file mode 100644 index 0000000..80ca857 --- /dev/null +++ b/plugins/housekeeping/msd-ldsm-dialog.c @@ -0,0 +1,476 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * msd-ldsm-dialog.c + * Copyright (C) Chris Coulson 2009 + * + * msd-ldsm-dialog.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * msd-ldsm-dialog.c 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include + +#include "msd-ldsm-dialog.h" + +#define MATECONF_CLIENT_IGNORE_PATHS "/apps/mate_settings_daemon/plugins/housekeeping/ignore_paths" + +enum +{ + PROP_0, + PROP_OTHER_USABLE_PARTITIONS, + PROP_OTHER_PARTITIONS, + PROP_HAS_TRASH, + PROP_SPACE_REMAINING, + PROP_PARTITION_NAME, + PROP_MOUNT_PATH +}; + +struct MsdLdsmDialogPrivate +{ + GtkWidget *primary_label; + GtkWidget *secondary_label; + GtkWidget *ignore_check_button; + gboolean other_usable_partitions; + gboolean other_partitions; + gboolean has_trash; + gint64 space_remaining; + gchar *partition_name; + gchar *mount_path; +}; + +#define MSD_LDSM_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogPrivate)) + +static void msd_ldsm_dialog_class_init (MsdLdsmDialogClass *klass); +static void msd_ldsm_dialog_init (MsdLdsmDialog *dialog); + +G_DEFINE_TYPE (MsdLdsmDialog, msd_ldsm_dialog, GTK_TYPE_DIALOG); + +static const gchar* +msd_ldsm_dialog_get_checkbutton_text (MsdLdsmDialog *dialog) +{ + g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); + + if (dialog->priv->other_partitions) + return _("Don't show any warnings again for this file system"); + else + return _("Don't show any warnings again"); +} + +static gchar* +msd_ldsm_dialog_get_primary_text (MsdLdsmDialog *dialog) +{ + gchar *primary_text, *free_space; + + g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); + + free_space = g_format_size_for_display (dialog->priv->space_remaining); + + if (dialog->priv->other_partitions) { + primary_text = g_strdup_printf (_("The volume \"%s\" has only %s disk space remaining."), + dialog->priv->partition_name, free_space); + } else { + primary_text = g_strdup_printf (_("This computer has only %s disk space remaining."), + free_space); + } + + g_free (free_space); + + return primary_text; +} + +static const gchar* +msd_ldsm_dialog_get_secondary_text (MsdLdsmDialog *dialog) +{ + g_return_val_if_fail (MSD_IS_LDSM_DIALOG (dialog), NULL); + + if (dialog->priv->other_usable_partitions) { + if (dialog->priv->has_trash) { + return _("You can free up disk space by emptying the Trash, removing " \ + "unused programs or files, or moving files to another disk or partition."); + } else { + return _("You can free up disk space by removing unused programs or files, " \ + "or by moving files to another disk or partition."); + } + } else { + if (dialog->priv->has_trash) { + return _("You can free up disk space by emptying the Trash, removing unused " \ + "programs or files, or moving files to an external disk."); + } else { + return _("You can free up disk space by removing unused programs or files, " \ + "or by moving files to an external disk."); + } + } +} + +static gint +ignore_path_compare (gconstpointer a, + gconstpointer b) +{ + return g_strcmp0 ((const gchar *)a, (const gchar *)b); +} + +static gboolean +update_ignore_paths (GSList **ignore_paths, + const gchar *mount_path, + gboolean ignore) +{ + GSList *found; + gchar *path_to_remove; + + found = g_slist_find_custom (*ignore_paths, mount_path, (GCompareFunc) ignore_path_compare); + + if (ignore && (found == NULL)) { + *ignore_paths = g_slist_prepend (*ignore_paths, g_strdup (mount_path)); + return TRUE; + } + + if (!ignore && (found != NULL)) { + path_to_remove = found->data; + *ignore_paths = g_slist_remove (*ignore_paths, path_to_remove); + g_free (path_to_remove); + return TRUE; + } + + return FALSE; +} + +static void +ignore_check_button_toggled_cb (GtkToggleButton *button, + gpointer user_data) +{ + MsdLdsmDialog *dialog = (MsdLdsmDialog *)user_data; + MateConfClient *client; + GSList *ignore_paths; + GError *error = NULL; + gboolean ignore, ret, updated; + + client = mateconf_client_get_default (); + if (client != NULL) { + ignore_paths = mateconf_client_get_list (client, + MATECONF_CLIENT_IGNORE_PATHS, + MATECONF_VALUE_STRING, &error); + if (error != NULL) { + g_warning ("Cannot change ignore preference - failed to read existing configuration: %s", + error->message ? error->message : "Unkown error"); + g_clear_error (&error); + return; + } else { + ignore = gtk_toggle_button_get_active (button); + updated = update_ignore_paths (&ignore_paths, dialog->priv->mount_path, ignore); + } + + if (!updated) + return; + + ret = mateconf_client_set_list (client, + MATECONF_CLIENT_IGNORE_PATHS, + MATECONF_VALUE_STRING, + ignore_paths, &error); + if (!ret || error != NULL) { + g_warning ("Cannot change ignore preference - failed to commit changes: %s", + error->message ? error->message : "Unkown error"); + g_clear_error (&error); + } + + g_slist_foreach (ignore_paths, (GFunc) g_free, NULL); + g_slist_free (ignore_paths); + g_object_unref (client); + } else { + g_warning ("Cannot change ignore preference - failed to get MateConfClient"); + } +} + +static void +msd_ldsm_dialog_init (MsdLdsmDialog *dialog) +{ + GtkWidget *main_vbox, *text_vbox, *hbox; + GtkWidget *image; + + dialog->priv = MSD_LDSM_DIALOG_GET_PRIVATE (dialog); + + main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + + /* Set up all the window stuff here */ + gtk_window_set_title (GTK_WINDOW (dialog), _("Low Disk Space")); + gtk_window_set_icon_name (GTK_WINDOW (dialog), + GTK_STOCK_DIALOG_WARNING); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); + gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); + gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); + + /* We don't want a separator - they're really ugly */ + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + + /* Create the image */ + image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); + + /* Create the labels */ + dialog->priv->primary_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (dialog->priv->primary_label), TRUE); + gtk_label_set_single_line_mode (GTK_LABEL (dialog->priv->primary_label), FALSE); + gtk_misc_set_alignment (GTK_MISC (dialog->priv->primary_label), 0.0, 0.0); + + dialog->priv->secondary_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (dialog->priv->secondary_label), TRUE); + gtk_label_set_single_line_mode (GTK_LABEL (dialog->priv->secondary_label), FALSE); + gtk_misc_set_alignment (GTK_MISC (dialog->priv->secondary_label), 0.0, 0.0); + + /* Create the check button to ignore future warnings */ + dialog->priv->ignore_check_button = gtk_check_button_new (); + /* The button should be inactive if the dialog was just called. + * I suppose it could be possible for the user to manually edit the MateConf key between + * the mount being checked and the dialog appearing, but I don't think it matters + * too much */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->ignore_check_button), FALSE); + g_signal_connect (dialog->priv->ignore_check_button, "toggled", + G_CALLBACK (ignore_check_button_toggled_cb), dialog); + + /* Now set up the dialog's GtkBox's' */ + gtk_box_set_spacing (GTK_BOX (main_vbox), 14); + + hbox = gtk_hbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); + + text_vbox = gtk_vbox_new (FALSE, 12); + + gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->primary_label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->secondary_label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (text_vbox), dialog->priv->ignore_check_button, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), text_vbox, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0); + + /* Set up the action area */ + gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), 6); + gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), 5); + + gtk_widget_show_all (hbox); +} + +static void +msd_ldsm_dialog_finalize (GObject *object) +{ + MsdLdsmDialog *self; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); + + self = MSD_LDSM_DIALOG (object); + + if (self->priv->partition_name) + g_free (self->priv->partition_name); + + if (self->priv->mount_path) + g_free (self->priv->mount_path); + + G_OBJECT_CLASS (msd_ldsm_dialog_parent_class)->finalize (object); +} + +static void +msd_ldsm_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + MsdLdsmDialog *self; + + g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); + + self = MSD_LDSM_DIALOG (object); + + switch (prop_id) + { + case PROP_OTHER_USABLE_PARTITIONS: + self->priv->other_usable_partitions = g_value_get_boolean (value); + break; + case PROP_OTHER_PARTITIONS: + self->priv->other_partitions = g_value_get_boolean (value); + break; + case PROP_HAS_TRASH: + self->priv->has_trash = g_value_get_boolean (value); + break; + case PROP_SPACE_REMAINING: + self->priv->space_remaining = g_value_get_int64 (value); + break; + case PROP_PARTITION_NAME: + self->priv->partition_name = g_value_dup_string (value); + break; + case PROP_MOUNT_PATH: + self->priv->mount_path = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_ldsm_dialog_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + MsdLdsmDialog *self; + + g_return_if_fail (MSD_IS_LDSM_DIALOG (object)); + + self = MSD_LDSM_DIALOG (object); + + switch (prop_id) + { + case PROP_OTHER_USABLE_PARTITIONS: + g_value_set_boolean (value, self->priv->other_usable_partitions); + break; + case PROP_OTHER_PARTITIONS: + g_value_set_boolean (value, self->priv->other_partitions); + break; + case PROP_HAS_TRASH: + g_value_set_boolean (value, self->priv->has_trash); + break; + case PROP_SPACE_REMAINING: + g_value_set_int64 (value, self->priv->space_remaining); + break; + case PROP_PARTITION_NAME: + g_value_set_string (value, self->priv->partition_name); + break; + case PROP_MOUNT_PATH: + g_value_set_string (value, self->priv->mount_path); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_ldsm_dialog_class_init (MsdLdsmDialogClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = msd_ldsm_dialog_finalize; + object_class->set_property = msd_ldsm_dialog_set_property; + object_class->get_property = msd_ldsm_dialog_get_property; + + g_object_class_install_property (object_class, + PROP_OTHER_USABLE_PARTITIONS, + g_param_spec_boolean ("other-usable-partitions", + "other-usable-partitions", + "Set to TRUE if there are other usable partitions on the system", + FALSE, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_OTHER_PARTITIONS, + g_param_spec_boolean ("other-partitions", + "other-partitions", + "Set to TRUE if there are other partitions on the system", + FALSE, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_HAS_TRASH, + g_param_spec_boolean ("has-trash", + "has-trash", + "Set to TRUE if the partition has files in it's trash folder that can be deleted", + FALSE, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_SPACE_REMAINING, + g_param_spec_int64 ("space-remaining", + "space-remaining", + "Specify how much space is remaining in bytes", + G_MININT64, G_MAXINT64, 0, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_PARTITION_NAME, + g_param_spec_string ("partition-name", + "partition-name", + "Specify the name of the partition", + "Unknown", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_MOUNT_PATH, + g_param_spec_string ("mount-path", + "mount-path", + "Specify the mount path for the partition", + "Unknown", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_type_class_add_private (klass, sizeof (MsdLdsmDialogPrivate)); +} + +MsdLdsmDialog* +msd_ldsm_dialog_new (gboolean other_usable_partitions, + gboolean other_partitions, + gboolean display_baobab, + gboolean display_empty_trash, + gint64 space_remaining, + const gchar *partition_name, + const gchar *mount_path) +{ + MsdLdsmDialog *dialog; + GtkWidget *button_empty_trash, *button_ignore, *button_analyze; + GtkWidget *empty_trash_image, *analyze_image, *ignore_image; + gchar *primary_text, *primary_text_markup; + const gchar *secondary_text, *checkbutton_text; + + dialog = MSD_LDSM_DIALOG (g_object_new (MSD_TYPE_LDSM_DIALOG, + "other-usable-partitions", other_usable_partitions, + "other-partitions", other_partitions, + "has-trash", display_empty_trash, + "space-remaining", space_remaining, + "partition-name", partition_name, + "mount-path", mount_path, + NULL)); + + /* Add some buttons */ + if (dialog->priv->has_trash) { + button_empty_trash = gtk_dialog_add_button (GTK_DIALOG (dialog), + _("Empty Trash"), + MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH); + empty_trash_image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button_empty_trash), empty_trash_image); + } + + if (display_baobab) { + button_analyze = gtk_dialog_add_button (GTK_DIALOG (dialog), + _("Examine…"), + MSD_LDSM_DIALOG_RESPONSE_ANALYZE); + analyze_image = gtk_image_new_from_icon_name ("baobab", GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button_analyze), analyze_image); + } + + button_ignore = gtk_dialog_add_button (GTK_DIALOG (dialog), + _("Ignore"), + GTK_RESPONSE_CANCEL); + ignore_image = gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button_ignore), ignore_image); + + gtk_widget_grab_default (button_ignore); + + /* Set the label text */ + primary_text = msd_ldsm_dialog_get_primary_text (dialog); + primary_text_markup = g_markup_printf_escaped ("%s", primary_text); + gtk_label_set_markup (GTK_LABEL (dialog->priv->primary_label), primary_text_markup); + + secondary_text = msd_ldsm_dialog_get_secondary_text (dialog); + gtk_label_set_text (GTK_LABEL (dialog->priv->secondary_label), secondary_text); + + checkbutton_text = msd_ldsm_dialog_get_checkbutton_text (dialog); + gtk_button_set_label (GTK_BUTTON (dialog->priv->ignore_check_button), checkbutton_text); + + g_free (primary_text); + g_free (primary_text_markup); + + return dialog; +} diff --git a/plugins/housekeeping/msd-ldsm-dialog.h b/plugins/housekeeping/msd-ldsm-dialog.h new file mode 100644 index 0000000..8b95fb9 --- /dev/null +++ b/plugins/housekeeping/msd-ldsm-dialog.h @@ -0,0 +1,72 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * msd-ldsm-dialog.c + * Copyright (C) Chris Coulson 2009 + * + * msd-ldsm-dialog.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * msd-ldsm-dialog.c 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _MSD_LDSM_DIALOG_H_ +#define _MSD_LDSM_DIALOG_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_LDSM_DIALOG (msd_ldsm_dialog_get_type ()) +#define MSD_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialog)) +#define MSD_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogClass)) +#define MSD_IS_LDSM_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_LDSM_DIALOG)) +#define MSD_IS_LDSM_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_LDSM_DIALOG)) +#define MSD_LDSM_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_LDSM_DIALOG, MsdLdsmDialogClass)) + +enum +{ + MSD_LDSM_DIALOG_RESPONSE_EMPTY_TRASH = -20, + MSD_LDSM_DIALOG_RESPONSE_ANALYZE = -21 +}; + +typedef struct MsdLdsmDialogPrivate MsdLdsmDialogPrivate; +typedef struct _MsdLdsmDialogClass MsdLdsmDialogClass; +typedef struct _MsdLdsmDialog MsdLdsmDialog; + +struct _MsdLdsmDialogClass +{ + GtkDialogClass parent_class; +}; + +struct _MsdLdsmDialog +{ + GtkDialog parent_instance; + MsdLdsmDialogPrivate *priv; +}; + +GType msd_ldsm_dialog_get_type (void) G_GNUC_CONST; + +MsdLdsmDialog * msd_ldsm_dialog_new (gboolean other_usable_partitions, + gboolean other_partitions, + gboolean display_baobab, + gboolean display_empty_trash, + gint64 space_remaining, + const gchar *partition_name, + const gchar *mount_path); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSD_LDSM_DIALOG_H_ */ diff --git a/plugins/housekeeping/msd-ldsm-trash-empty.c b/plugins/housekeeping/msd-ldsm-trash-empty.c new file mode 100644 index 0000000..05f82cd --- /dev/null +++ b/plugins/housekeeping/msd-ldsm-trash-empty.c @@ -0,0 +1,398 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * msd-ldsm-trash-empty.c + * Copyright (C) Chris Coulson 2009 + * (C) Ryan Lortie 2008 + * + * msd-ldsm-trash-empty.c is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * msd-ldsm-trash-empty.c 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include +#include + +#include "msd-ldsm-trash-empty.h" + +#define CAJA_CONFIRM_TRASH_KEY "/apps/caja/preferences/confirm_trash" + +/* Some of this code has been borrowed from the trash-applet, courtesy of Ryan Lortie */ + +static GtkWidget *trash_empty_confirm_dialog = NULL; +static GtkWidget *trash_empty_dialog = NULL; +static GtkWidget *location_label; +static GtkWidget *file_label; +static GtkWidget *progressbar; + +static gsize trash_empty_total_files; +static gboolean trash_empty_update_pending = FALSE; +static GFile *trash_empty_current_file = NULL; +static gsize trash_empty_deleted_files; +static GTimer *timer = NULL; +static gboolean trash_empty_actually_deleting; + +static gboolean +trash_empty_done (gpointer data) +{ + gtk_widget_destroy (trash_empty_dialog); + trash_empty_dialog = NULL; + if (timer) { + g_timer_destroy (timer); + timer = NULL; + } + + return FALSE; +} + +static gboolean +trash_empty_update_dialog (gpointer user_data) +{ + gsize deleted, total; + GFile *file; + gboolean actually_deleting; + + g_assert (trash_empty_update_pending); + + deleted = trash_empty_deleted_files; + total = trash_empty_total_files; + file = trash_empty_current_file; + actually_deleting = trash_empty_actually_deleting; + + /* maybe the done() got processed first. */ + if (!trash_empty_dialog) + goto out; + + if (!actually_deleting) { + /* If we havent finished counting yet, then pulse the progressbar every 100ms. + * This stops the user from thinking the dialog has frozen if there are + * a lot of files to delete. We don't pulse it every time we are called from the + * worker thread, otherwise it moves to fast and looks hideous + */ + if (timer) { + if (g_timer_elapsed (timer, NULL) > 0.1) { + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progressbar)); + g_timer_start (timer); + } + } else { + timer = g_timer_new (); + g_timer_start (timer); + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progressbar)); + } + } else { + gchar *text; + gchar *tmp; + gchar *markup; + GFile *parent; + + text = g_strdup_printf (_("Removing item %lu of %lu"), + deleted, total); + gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar), text); + + g_free (text); + + if (deleted > total) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progressbar), 1.0); + else + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progressbar), + (gdouble) deleted / (gdouble) total); + + parent = g_file_get_parent (file); + text = g_file_get_uri (parent); + g_object_unref (parent); + + gtk_label_set_text (GTK_LABEL (location_label), text); + g_free (text); + + tmp = g_file_get_basename (file); + text = g_markup_printf_escaped (_("Removing: %s"), tmp); + markup = g_strdup_printf ("%s", text); + gtk_label_set_markup (GTK_LABEL (file_label), text); + g_free (markup); + g_free (text); + g_free (tmp); + + /* unhide the labels */ + gtk_widget_show_all (GTK_WIDGET (trash_empty_dialog)); + } + +out: + trash_empty_current_file = NULL; + g_object_unref (file); + + trash_empty_update_pending = FALSE; + + return FALSE; +} + +/* Worker thread begin */ + +static void +trash_empty_maybe_schedule_update (GIOSchedulerJob *job, + GFile *file, + gsize deleted, + gboolean actually_deleting) +{ + if (!trash_empty_update_pending) { + g_assert (trash_empty_current_file == NULL); + + trash_empty_current_file = g_object_ref (file); + trash_empty_deleted_files = deleted; + trash_empty_actually_deleting = actually_deleting; + + trash_empty_update_pending = TRUE; + g_io_scheduler_job_send_to_mainloop_async (job, + trash_empty_update_dialog, + NULL, NULL); + } +} + +static void +trash_empty_delete_contents (GIOSchedulerJob *job, + GCancellable *cancellable, + GFile *file, + gboolean actually_delete, + gsize *deleted) +{ + GFileEnumerator *enumerator; + GFileInfo *info; + GFile *child; + + if (g_cancellable_is_cancelled (cancellable)) + return; + + enumerator = g_file_enumerate_children (file, + G_FILE_ATTRIBUTE_STANDARD_NAME "," + G_FILE_ATTRIBUTE_STANDARD_TYPE, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + cancellable, NULL); + + if (enumerator) { + while ((info = g_file_enumerator_next_file (enumerator, + cancellable, NULL)) != NULL) { + child = g_file_get_child (file, g_file_info_get_name (info)); + + if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) + trash_empty_delete_contents (job, cancellable, child, + actually_delete, deleted); + + trash_empty_maybe_schedule_update (job, child, *deleted, actually_delete); + if (actually_delete) + g_file_delete (child, cancellable, NULL); + + (*deleted)++; + + g_object_unref (child); + g_object_unref (info); + + if (g_cancellable_is_cancelled (cancellable)) + break; + } + + g_object_unref (enumerator); + } +} + +static gboolean +trash_empty_job (GIOSchedulerJob *job, + GCancellable *cancellable, + gpointer user_data) +{ + gsize deleted; + GFile *trash; + + trash = g_file_new_for_uri ("trash:///"); + + /* first do a dry run to count the number of files */ + deleted = 0; + trash_empty_delete_contents (job, cancellable, trash, FALSE, &deleted); + trash_empty_total_files = deleted; + + /* now do the real thing */ + deleted = 0; + trash_empty_delete_contents (job, cancellable, trash, TRUE, &deleted); + + /* done */ + g_object_unref (trash); + g_io_scheduler_job_send_to_mainloop_async (job, + trash_empty_done, + NULL, NULL); + + return FALSE; +} + +/* Worker thread end */ + +static void +trash_empty_start () +{ + GtkWidget *vbox1, *vbox2, *hbox; + GtkWidget *label1, *label3; + gchar *markup; + GCancellable *cancellable; + + trash_empty_dialog = gtk_dialog_new (); + gtk_window_set_default_size (GTK_WINDOW (trash_empty_dialog), 400, -1); + gtk_window_set_icon_name (GTK_WINDOW (trash_empty_dialog), "user-trash"); + gtk_window_set_title (GTK_WINDOW (trash_empty_dialog), + _("Emptying the trash")); + + vbox1 = gtk_vbox_new (FALSE, 12); + vbox2 = gtk_vbox_new (FALSE, 0); + hbox = gtk_hbox_new (FALSE, 0); + + label1 = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (label1), TRUE); + gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5); + + label3 = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (label3), TRUE); + gtk_misc_set_alignment (GTK_MISC (label3), 0.0, 0.5); + gtk_widget_hide (label3); + + location_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (location_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (location_label), 0.0, 0.5); + + file_label = gtk_label_new (NULL); + gtk_label_set_line_wrap (GTK_LABEL (file_label), TRUE); + gtk_misc_set_alignment (GTK_MISC (file_label), 0.0, 0.5); + + progressbar = gtk_progress_bar_new (); + gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (progressbar), 0.1); + gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar), _("Preparing to empty trash…")); + + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (trash_empty_dialog))), vbox1, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), label1, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), label3, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), location_label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), hbox, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox2), progressbar, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox2), file_label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0); + + gtk_widget_show (label1); + gtk_widget_show (vbox1); + gtk_widget_show_all (vbox2); + gtk_widget_show (hbox); + gtk_widget_show (location_label); + + gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (trash_empty_dialog))), 6); + gtk_container_set_border_width (GTK_CONTAINER (vbox1), 6); + + gtk_dialog_add_button (GTK_DIALOG (trash_empty_dialog), + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + + markup = g_markup_printf_escaped ("%s", _("Emptying the trash")); + gtk_label_set_markup (GTK_LABEL (label1), markup); + /* Translators: "Emptying trash from " */ + gtk_label_set_text (GTK_LABEL (label3), _("From: ")); + + cancellable = g_cancellable_new (); + g_signal_connect_object (trash_empty_dialog, "response", + G_CALLBACK (g_cancellable_cancel), + cancellable, G_CONNECT_SWAPPED); + g_io_scheduler_push_job (trash_empty_job, NULL, NULL, 0, cancellable); + + gtk_widget_show (trash_empty_dialog); + + g_free (markup); + g_object_unref (cancellable); +} + +static void +trash_empty_confirmation_response (GtkDialog *dialog, + gint response_id, + gpointer user_data) +{ + if (response_id == GTK_RESPONSE_YES) + trash_empty_start (); + + gtk_object_destroy (GTK_OBJECT (dialog)); + trash_empty_confirm_dialog = NULL; +} + +static gboolean +trash_empty_require_confirmation () +{ + MateConfClient *client; + gboolean require_confirmation = TRUE; + GError *error = NULL; + + client = mateconf_client_get_default (); + if (client) { + require_confirmation = mateconf_client_get_bool (client, CAJA_CONFIRM_TRASH_KEY, &error); + if (error) { + g_warning ("Failed to read confirm_trash key from MateConf: %s", error->message ? error->message : "Unknown error"); + /* It's safest to assume that confirmation is required here */ + require_confirmation = TRUE; + g_error_free (error); + } + g_object_unref (client); + } + + return require_confirmation; +} + +static void +trash_empty_show_confirmation_dialog () +{ + GtkWidget *button; + + if (!trash_empty_require_confirmation ()) { + trash_empty_start (); + return; + } + + trash_empty_confirm_dialog = gtk_message_dialog_new (NULL, 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_NONE, + _("Empty all of the items from the trash?")); + + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (trash_empty_confirm_dialog), + _("If you choose to empty the trash, all items in " + "it will be permanently lost. Please note that " + "you can also delete them separately.")); + + gtk_dialog_add_button (GTK_DIALOG (trash_empty_confirm_dialog), GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + + button = gtk_button_new_with_mnemonic (_("_Empty Trash")); + gtk_widget_show (button); + gtk_widget_set_can_default (button, TRUE); + + gtk_dialog_add_action_widget (GTK_DIALOG (trash_empty_confirm_dialog), + button, GTK_RESPONSE_YES); + + gtk_dialog_set_default_response (GTK_DIALOG (trash_empty_confirm_dialog), + GTK_RESPONSE_YES); + + gtk_window_set_icon_name (GTK_WINDOW (trash_empty_confirm_dialog), + "user-trash"); + + gtk_widget_show (trash_empty_confirm_dialog); + + g_signal_connect (trash_empty_confirm_dialog, "response", + G_CALLBACK (trash_empty_confirmation_response), NULL); +} + +void +msd_ldsm_trash_empty () +{ + if (trash_empty_confirm_dialog) + gtk_window_present (GTK_WINDOW (trash_empty_confirm_dialog)); + else if (trash_empty_dialog) + gtk_window_present (GTK_WINDOW (trash_empty_dialog)); + else + trash_empty_show_confirmation_dialog (); +} diff --git a/plugins/housekeeping/msd-ldsm-trash-empty.h b/plugins/housekeeping/msd-ldsm-trash-empty.h new file mode 100644 index 0000000..85b09c0 --- /dev/null +++ b/plugins/housekeeping/msd-ldsm-trash-empty.h @@ -0,0 +1,27 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * msd-ldsm-trash-empty.h + * Copyright (C) Chris Coulson 2009 + * + * msd-ldsm-trash-empty.h is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * msd-ldsm-trash-empty.h 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _msd_ldsm_trash_empty_h_ +#define _msd_ldsm_trash_empty_h_ + +#include + +void msd_ldsm_trash_empty (); + +#endif /* _msd_ldsm_trash_empty_h_ */ diff --git a/plugins/keybindings/gsd-keybindings-manager.c b/plugins/keybindings/gsd-keybindings-manager.c deleted file mode 100644 index c1f876c..0000000 --- a/plugins/keybindings/gsd-keybindings-manager.c +++ /dev/null @@ -1,758 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "mate-settings-profile.h" -#include "msd-keybindings-manager.h" - -#include "msd-keygrab.h" -#include "eggaccelerators.h" - -#define MATECONF_BINDING_DIR "/desktop/mate/keybindings" -#define ALLOWED_KEYS_KEY MATECONF_BINDING_DIR "/allowed_keys" - -#define MSD_KEYBINDINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerPrivate)) - -typedef struct { - char *binding_str; - char *action; - char *mateconf_key; - Key key; - Key previous_key; -} Binding; - -struct MsdKeybindingsManagerPrivate -{ - GSList *binding_list; - GSList *allowed_keys; - GSList *screens; - guint notify; -}; - -static void msd_keybindings_manager_class_init (MsdKeybindingsManagerClass *klass); -static void msd_keybindings_manager_init (MsdKeybindingsManager *keybindings_manager); -static void msd_keybindings_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdKeybindingsManager, msd_keybindings_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -static GSList * -get_screens_list (void) -{ - GdkDisplay *display = gdk_display_get_default(); - int n_screens; - GSList *list = NULL; - int i; - - n_screens = gdk_display_get_n_screens (display); - - if (n_screens == 1) { - list = g_slist_append (list, gdk_screen_get_default ()); - } else { - for (i = 0; i < n_screens; i++) { - GdkScreen *screen; - - screen = gdk_display_get_screen (display, i); - if (screen != NULL) { - list = g_slist_prepend (list, screen); - } - } - list = g_slist_reverse (list); - } - - return list; -} - -static char * -entry_get_string (MateConfEntry *entry) -{ - MateConfValue *value = mateconf_entry_get_value (entry); - - if (value == NULL || value->type != MATECONF_VALUE_STRING) { - return NULL; - } - - return g_strdup (mateconf_value_get_string (value)); -} - -static gboolean -parse_binding (Binding *binding) -{ - gboolean success; - - g_return_val_if_fail (binding != NULL, FALSE); - - binding->key.keysym = 0; - binding->key.state = 0; - g_free (binding->key.keycodes); - binding->key.keycodes = NULL; - - if (binding->binding_str == NULL || - binding->binding_str[0] == '\0' || - strcmp (binding->binding_str, "Disabled") == 0) { - return FALSE; - } - - success = egg_accelerator_parse_virtual (binding->binding_str, - &binding->key.keysym, - &binding->key.keycodes, - &binding->key.state); - - if (!success) - g_warning (_("Key binding (%s) is invalid"), binding->mateconf_key); - - return success; -} - -static gint -compare_bindings (gconstpointer a, - gconstpointer b) -{ - Binding *key_a = (Binding *) a; - char *key_b = (char *) b; - - return strcmp (key_b, key_a->mateconf_key); -} - -static gboolean -bindings_get_entry (MsdKeybindingsManager *manager, - MateConfClient *client, - const char *subdir) -{ - Binding *new_binding; - GSList *tmp_elem; - GSList *list; - GSList *li; - char *mateconf_key; - char *action = NULL; - char *key = NULL; - - g_return_val_if_fail (subdir != NULL, FALSE); - - mateconf_key = g_path_get_basename (subdir); - - if (!mateconf_key) { - return FALSE; - } - - /* Get entries for this binding */ - list = mateconf_client_all_entries (client, subdir, NULL); - - for (li = list; li != NULL; li = li->next) { - MateConfEntry *entry = li->data; - char *key_name = g_path_get_basename (mateconf_entry_get_key (entry)); - - if (key_name == NULL) { - /* ignore entry */ - } else if (strcmp (key_name, "action") == 0) { - action = entry_get_string (entry); - } else if (strcmp (key_name, "binding") == 0) { - key = entry_get_string (entry); - } - - g_free (key_name); - mateconf_entry_free (entry); - } - - g_slist_free (list); - - if (!action || !key) { - g_warning (_("Key binding (%s) is incomplete"), mateconf_key); - g_free (mateconf_key); - g_free (action); - g_free (key); - return FALSE; - } - - tmp_elem = g_slist_find_custom (manager->priv->binding_list, - mateconf_key, - compare_bindings); - - if (!tmp_elem) { - new_binding = g_new0 (Binding, 1); - } else { - new_binding = (Binding *) tmp_elem->data; - g_free (new_binding->binding_str); - g_free (new_binding->action); - g_free (new_binding->mateconf_key); - - new_binding->previous_key.keysym = new_binding->key.keysym; - new_binding->previous_key.state = new_binding->key.state; - new_binding->previous_key.keycodes = new_binding->key.keycodes; - new_binding->key.keycodes = NULL; - } - - new_binding->binding_str = key; - new_binding->action = action; - new_binding->mateconf_key = mateconf_key; - - if (parse_binding (new_binding)) { - if (!tmp_elem) - manager->priv->binding_list = g_slist_prepend (manager->priv->binding_list, new_binding); - } else { - g_free (new_binding->binding_str); - g_free (new_binding->action); - g_free (new_binding->mateconf_key); - g_free (new_binding->previous_key.keycodes); - g_free (new_binding); - - if (tmp_elem) - manager->priv->binding_list = g_slist_delete_link (manager->priv->binding_list, tmp_elem); - return FALSE; - } - - return TRUE; -} - -static gboolean -same_keycode (const Key *key, const Key *other) -{ - if (key->keycodes != NULL && other->keycodes != NULL) { - guint *c; - - for (c = key->keycodes; *c; ++c) { - if (key_uses_keycode (other, *c)) - return TRUE; - } - } - return FALSE; -} - -static gboolean -same_key (const Key *key, const Key *other) -{ - if (key->state == other->state) { - if (key->keycodes != NULL && other->keycodes != NULL) { - guint *c1, *c2; - - for (c1 = key->keycodes, c2 = other->keycodes; - *c1 || *c2; ++c1, ++c2) { - if (*c1 != *c2) - return FALSE; - } - } else if (key->keycodes != NULL || other->keycodes != NULL) - return FALSE; - - - return TRUE; - } - - return FALSE; -} - -static gboolean -key_already_used (MsdKeybindingsManager *manager, - Binding *binding) -{ - GSList *li; - - for (li = manager->priv->binding_list; li != NULL; li = li->next) { - Binding *tmp_binding = (Binding*) li->data; - - if (tmp_binding != binding && - same_keycode (&tmp_binding->key, &binding->key) && - tmp_binding->key.state == binding->key.state) { - return TRUE; - } - } - - return FALSE; -} - -static void -binding_unregister_keys (MsdKeybindingsManager *manager) -{ - GSList *li; - gboolean need_flush = FALSE; - - gdk_error_trap_push (); - - for (li = manager->priv->binding_list; li != NULL; li = li->next) { - Binding *binding = (Binding *) li->data; - - if (binding->key.keycodes) { - need_flush = TRUE; - grab_key_unsafe (&binding->key, FALSE, manager->priv->screens); - } - } - - if (need_flush) - gdk_flush (); - gdk_error_trap_pop (); -} - -static void -binding_register_keys (MsdKeybindingsManager *manager) -{ - GSList *li; - gboolean need_flush = FALSE; - - gdk_error_trap_push (); - - /* Now check for changes and grab new key if not already used */ - for (li = manager->priv->binding_list; li != NULL; li = li->next) { - Binding *binding = (Binding *) li->data; - - if (manager->priv->allowed_keys != NULL && - !g_slist_find_custom (manager->priv->allowed_keys, - binding->mateconf_key, - (GCompareFunc) g_strcmp0)) { - continue; - } - - if (!same_key (&binding->previous_key, &binding->key)) { - /* Ungrab key if it changed and not clashing with previously set binding */ - if (!key_already_used (manager, binding)) { - gint i; - - need_flush = TRUE; - if (binding->previous_key.keycodes) { - grab_key_unsafe (&binding->previous_key, FALSE, manager->priv->screens); - } - grab_key_unsafe (&binding->key, TRUE, manager->priv->screens); - - binding->previous_key.keysym = binding->key.keysym; - binding->previous_key.state = binding->key.state; - g_free (binding->previous_key.keycodes); - for (i = 0; binding->key.keycodes[i]; ++i); - binding->previous_key.keycodes = g_new0 (guint, i); - for (i = 0; binding->key.keycodes[i]; ++i) - binding->previous_key.keycodes[i] = binding->key.keycodes[i]; - } else - g_warning ("Key binding (%s) is already in use", binding->binding_str); - } - } - - if (need_flush) - gdk_flush (); - if (gdk_error_trap_pop ()) - g_warning ("Grab failed for some keys, another application may already have access the them."); -} - -extern char **environ; - -static char * -screen_exec_display_string (GdkScreen *screen) -{ - GString *str; - const char *old_display; - char *p; - - g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); - - old_display = gdk_display_get_name (gdk_screen_get_display (screen)); - - str = g_string_new ("DISPLAY="); - g_string_append (str, old_display); - - p = strrchr (str->str, '.'); - if (p && p > strchr (str->str, ':')) { - g_string_truncate (str, p - str->str); - } - - g_string_append_printf (str, ".%d", gdk_screen_get_number (screen)); - - return g_string_free (str, FALSE); -} - -/** - * get_exec_environment: - * - * Description: Modifies the current program environment to - * ensure that $DISPLAY is set such that a launched application - * inheriting this environment would appear on screen. - * - * Returns: a newly-allocated %NULL-terminated array of strings or - * %NULL on error. Use g_strfreev() to free it. - * - * mainly ripped from egg_screen_exec_display_string in - * mate-panel/egg-screen-exec.c - **/ -static char ** -get_exec_environment (XEvent *xevent) -{ - char **retval = NULL; - int i; - int display_index = -1; - GdkScreen *screen = NULL; - GdkWindow *window = gdk_xid_table_lookup (xevent->xkey.root); - - if (window) { - screen = gdk_drawable_get_screen (GDK_DRAWABLE (window)); - } - - g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); - - for (i = 0; environ [i]; i++) { - if (!strncmp (environ [i], "DISPLAY", 7)) { - display_index = i; - } - } - - if (display_index == -1) { - display_index = i++; - } - - retval = g_new (char *, i + 1); - - for (i = 0; environ [i]; i++) { - if (i == display_index) { - retval [i] = screen_exec_display_string (screen); - } else { - retval [i] = g_strdup (environ [i]); - } - } - - retval [i] = NULL; - - return retval; -} - -static GdkFilterReturn -keybindings_filter (GdkXEvent *gdk_xevent, - GdkEvent *event, - MsdKeybindingsManager *manager) -{ - XEvent *xevent = (XEvent *) gdk_xevent; - GSList *li; - - if (xevent->type != KeyPress) { - return GDK_FILTER_CONTINUE; - } - - for (li = manager->priv->binding_list; li != NULL; li = li->next) { - Binding *binding = (Binding *) li->data; - - if (match_key (&binding->key, xevent)) { - GError *error = NULL; - gboolean retval; - gchar **argv = NULL; - gchar **envp = NULL; - - g_return_val_if_fail (binding->action != NULL, GDK_FILTER_CONTINUE); - - if (!g_shell_parse_argv (binding->action, - NULL, &argv, - &error)) { - return GDK_FILTER_CONTINUE; - } - - envp = get_exec_environment (xevent); - - retval = g_spawn_async (NULL, - argv, - envp, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - &error); - g_strfreev (argv); - g_strfreev (envp); - - if (!retval) { - GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, - _("Error while trying to run (%s)\n"\ - "which is linked to the key (%s)"), - binding->action, - binding->binding_str); - g_signal_connect (dialog, - "response", - G_CALLBACK (gtk_widget_destroy), - NULL); - gtk_widget_show (dialog); - } - return GDK_FILTER_REMOVE; - } - } - return GDK_FILTER_CONTINUE; -} - -static void -bindings_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdKeybindingsManager *manager) -{ - char** key_elems; - char* binding_entry; - - if (strcmp (mateconf_entry_get_key (entry), ALLOWED_KEYS_KEY) == 0) { - g_slist_foreach (manager->priv->allowed_keys, (GFunc)g_free, NULL); - g_slist_free (manager->priv->allowed_keys); - manager->priv->allowed_keys = mateconf_client_get_list (client, - ALLOWED_KEYS_KEY, - MATECONF_VALUE_STRING, - NULL); - } - else { - /* ensure we get binding dir not a sub component */ - key_elems = g_strsplit (mateconf_entry_get_key (entry), "/", 15); - binding_entry = g_strdup_printf ("/%s/%s/%s/%s", - key_elems[1], - key_elems[2], - key_elems[3], - key_elems[4]); - g_strfreev (key_elems); - - bindings_get_entry (manager, client, binding_entry); - g_free (binding_entry); - } - - binding_register_keys (manager); -} - -static guint -register_config_callback (MsdKeybindingsManager *manager, - MateConfClient *client, - const char *path, - MateConfClientNotifyFunc func) -{ - mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_RECURSIVE, NULL); - return mateconf_client_notify_add (client, path, func, manager, NULL, NULL); -} - -gboolean -msd_keybindings_manager_start (MsdKeybindingsManager *manager, - GError **error) -{ - MateConfClient *client; - GSList *list; - GSList *li; - GdkDisplay *dpy; - GdkScreen *screen; - int screen_num; - int i; - - g_debug ("Starting keybindings manager"); - mate_settings_profile_start (NULL); - - client = mateconf_client_get_default (); - - manager->priv->notify = register_config_callback (manager, - client, - MATECONF_BINDING_DIR, - (MateConfClientNotifyFunc) bindings_callback); - - manager->priv->allowed_keys = mateconf_client_get_list (client, - ALLOWED_KEYS_KEY, - MATECONF_VALUE_STRING, - NULL); - - dpy = gdk_display_get_default (); - screen_num = gdk_display_get_n_screens (dpy); - - for (i = 0; i < screen_num; i++) { - screen = gdk_display_get_screen (dpy, i); - gdk_window_add_filter (gdk_screen_get_root_window (screen), - (GdkFilterFunc) keybindings_filter, - manager); - } - - list = mateconf_client_all_dirs (client, MATECONF_BINDING_DIR, NULL); - manager->priv->screens = get_screens_list (); - - for (li = list; li != NULL; li = li->next) { - bindings_get_entry (manager, client, li->data); - g_free (li->data); - } - - g_slist_free (list); - g_object_unref (client); - - binding_register_keys (manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_keybindings_manager_stop (MsdKeybindingsManager *manager) -{ - MsdKeybindingsManagerPrivate *p = manager->priv; - GSList *l; - - g_debug ("Stopping keybindings manager"); - - if (p->notify != 0) { - MateConfClient *client = mateconf_client_get_default (); - mateconf_client_remove_dir (client, MATECONF_BINDING_DIR, NULL); - mateconf_client_notify_remove (client, p->notify); - g_object_unref (client); - p->notify = 0; - } - - for (l = p->screens; l; l = l->next) { - GdkScreen *screen = l->data; - gdk_window_remove_filter (gdk_screen_get_root_window (screen), - (GdkFilterFunc) keybindings_filter, - manager); - } - - binding_unregister_keys (manager); - - g_slist_free (p->screens); - p->screens = NULL; - - for (l = p->binding_list; l; l = l->next) { - Binding *b = l->data; - g_free (b->binding_str); - g_free (b->action); - g_free (b->mateconf_key); - g_free (b->previous_key.keycodes); - g_free (b->key.keycodes); - g_free (b); - } - g_slist_free (p->binding_list); - p->binding_list = NULL; -} - -static void -msd_keybindings_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdKeybindingsManager *self; - - self = MSD_KEYBINDINGS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_keybindings_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdKeybindingsManager *self; - - self = MSD_KEYBINDINGS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_keybindings_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdKeybindingsManager *keybindings_manager; - MsdKeybindingsManagerClass *klass; - - klass = MSD_KEYBINDINGS_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_KEYBINDINGS_MANAGER)); - - keybindings_manager = MSD_KEYBINDINGS_MANAGER (G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (keybindings_manager); -} - -static void -msd_keybindings_manager_dispose (GObject *object) -{ - MsdKeybindingsManager *keybindings_manager; - - keybindings_manager = MSD_KEYBINDINGS_MANAGER (object); - - G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->dispose (object); -} - -static void -msd_keybindings_manager_class_init (MsdKeybindingsManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_keybindings_manager_get_property; - object_class->set_property = msd_keybindings_manager_set_property; - object_class->constructor = msd_keybindings_manager_constructor; - object_class->dispose = msd_keybindings_manager_dispose; - object_class->finalize = msd_keybindings_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdKeybindingsManagerPrivate)); -} - -static void -msd_keybindings_manager_init (MsdKeybindingsManager *manager) -{ - manager->priv = MSD_KEYBINDINGS_MANAGER_GET_PRIVATE (manager); - -} - -static void -msd_keybindings_manager_finalize (GObject *object) -{ - MsdKeybindingsManager *keybindings_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_KEYBINDINGS_MANAGER (object)); - - keybindings_manager = MSD_KEYBINDINGS_MANAGER (object); - - g_return_if_fail (keybindings_manager->priv != NULL); - - G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->finalize (object); -} - -MsdKeybindingsManager * -msd_keybindings_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_KEYBINDINGS_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_KEYBINDINGS_MANAGER (manager_object); -} diff --git a/plugins/keybindings/gsd-keybindings-manager.h b/plugins/keybindings/gsd-keybindings-manager.h deleted file mode 100644 index 95b1bed..0000000 --- a/plugins/keybindings/gsd-keybindings-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_KEYBINDINGS_MANAGER_H -#define __MSD_KEYBINDINGS_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_KEYBINDINGS_MANAGER (msd_keybindings_manager_get_type ()) -#define MSD_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManager)) -#define MSD_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerClass)) -#define MSD_IS_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBINDINGS_MANAGER)) -#define MSD_IS_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBINDINGS_MANAGER)) -#define MSD_KEYBINDINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerClass)) - -typedef struct MsdKeybindingsManagerPrivate MsdKeybindingsManagerPrivate; - -typedef struct -{ - GObject parent; - MsdKeybindingsManagerPrivate *priv; -} MsdKeybindingsManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdKeybindingsManagerClass; - -GType msd_keybindings_manager_get_type (void); - -MsdKeybindingsManager * msd_keybindings_manager_new (void); -gboolean msd_keybindings_manager_start (MsdKeybindingsManager *manager, - GError **error); -void msd_keybindings_manager_stop (MsdKeybindingsManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_KEYBINDINGS_MANAGER_H */ diff --git a/plugins/keybindings/gsd-keybindings-plugin.c b/plugins/keybindings/gsd-keybindings-plugin.c deleted file mode 100644 index 5b0cebb..0000000 --- a/plugins/keybindings/gsd-keybindings-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-keybindings-plugin.h" -#include "msd-keybindings-manager.h" - -struct MsdKeybindingsPluginPrivate { - MsdKeybindingsManager *manager; -}; - -#define MSD_KEYBINDINGS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdKeybindingsPlugin, msd_keybindings_plugin) - -static void -msd_keybindings_plugin_init (MsdKeybindingsPlugin *plugin) -{ - plugin->priv = MSD_KEYBINDINGS_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdKeybindingsPlugin initializing"); - - plugin->priv->manager = msd_keybindings_manager_new (); -} - -static void -msd_keybindings_plugin_finalize (GObject *object) -{ - MsdKeybindingsPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_KEYBINDINGS_PLUGIN (object)); - - g_debug ("MsdKeybindingsPlugin finalizing"); - - plugin = MSD_KEYBINDINGS_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_keybindings_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating keybindings plugin"); - - error = NULL; - res = msd_keybindings_manager_start (MSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start keybindings manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating keybindings plugin"); - msd_keybindings_manager_stop (MSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager); -} - -static void -msd_keybindings_plugin_class_init (MsdKeybindingsPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_keybindings_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdKeybindingsPluginPrivate)); -} diff --git a/plugins/keybindings/gsd-keybindings-plugin.h b/plugins/keybindings/gsd-keybindings-plugin.h deleted file mode 100644 index f45d0f8..0000000 --- a/plugins/keybindings/gsd-keybindings-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_KEYBINDINGS_PLUGIN_H__ -#define __MSD_KEYBINDINGS_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_KEYBINDINGS_PLUGIN (msd_keybindings_plugin_get_type ()) -#define MSD_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPlugin)) -#define MSD_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginClass)) -#define MSD_IS_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBINDINGS_PLUGIN)) -#define MSD_IS_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBINDINGS_PLUGIN)) -#define MSD_KEYBINDINGS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginClass)) - -typedef struct MsdKeybindingsPluginPrivate MsdKeybindingsPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdKeybindingsPluginPrivate *priv; -} MsdKeybindingsPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdKeybindingsPluginClass; - -GType msd_keybindings_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_KEYBINDINGS_PLUGIN_H__ */ diff --git a/plugins/keybindings/msd-keybindings-manager.c b/plugins/keybindings/msd-keybindings-manager.c new file mode 100644 index 0000000..c1f876c --- /dev/null +++ b/plugins/keybindings/msd-keybindings-manager.c @@ -0,0 +1,758 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "mate-settings-profile.h" +#include "msd-keybindings-manager.h" + +#include "msd-keygrab.h" +#include "eggaccelerators.h" + +#define MATECONF_BINDING_DIR "/desktop/mate/keybindings" +#define ALLOWED_KEYS_KEY MATECONF_BINDING_DIR "/allowed_keys" + +#define MSD_KEYBINDINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerPrivate)) + +typedef struct { + char *binding_str; + char *action; + char *mateconf_key; + Key key; + Key previous_key; +} Binding; + +struct MsdKeybindingsManagerPrivate +{ + GSList *binding_list; + GSList *allowed_keys; + GSList *screens; + guint notify; +}; + +static void msd_keybindings_manager_class_init (MsdKeybindingsManagerClass *klass); +static void msd_keybindings_manager_init (MsdKeybindingsManager *keybindings_manager); +static void msd_keybindings_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdKeybindingsManager, msd_keybindings_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +static GSList * +get_screens_list (void) +{ + GdkDisplay *display = gdk_display_get_default(); + int n_screens; + GSList *list = NULL; + int i; + + n_screens = gdk_display_get_n_screens (display); + + if (n_screens == 1) { + list = g_slist_append (list, gdk_screen_get_default ()); + } else { + for (i = 0; i < n_screens; i++) { + GdkScreen *screen; + + screen = gdk_display_get_screen (display, i); + if (screen != NULL) { + list = g_slist_prepend (list, screen); + } + } + list = g_slist_reverse (list); + } + + return list; +} + +static char * +entry_get_string (MateConfEntry *entry) +{ + MateConfValue *value = mateconf_entry_get_value (entry); + + if (value == NULL || value->type != MATECONF_VALUE_STRING) { + return NULL; + } + + return g_strdup (mateconf_value_get_string (value)); +} + +static gboolean +parse_binding (Binding *binding) +{ + gboolean success; + + g_return_val_if_fail (binding != NULL, FALSE); + + binding->key.keysym = 0; + binding->key.state = 0; + g_free (binding->key.keycodes); + binding->key.keycodes = NULL; + + if (binding->binding_str == NULL || + binding->binding_str[0] == '\0' || + strcmp (binding->binding_str, "Disabled") == 0) { + return FALSE; + } + + success = egg_accelerator_parse_virtual (binding->binding_str, + &binding->key.keysym, + &binding->key.keycodes, + &binding->key.state); + + if (!success) + g_warning (_("Key binding (%s) is invalid"), binding->mateconf_key); + + return success; +} + +static gint +compare_bindings (gconstpointer a, + gconstpointer b) +{ + Binding *key_a = (Binding *) a; + char *key_b = (char *) b; + + return strcmp (key_b, key_a->mateconf_key); +} + +static gboolean +bindings_get_entry (MsdKeybindingsManager *manager, + MateConfClient *client, + const char *subdir) +{ + Binding *new_binding; + GSList *tmp_elem; + GSList *list; + GSList *li; + char *mateconf_key; + char *action = NULL; + char *key = NULL; + + g_return_val_if_fail (subdir != NULL, FALSE); + + mateconf_key = g_path_get_basename (subdir); + + if (!mateconf_key) { + return FALSE; + } + + /* Get entries for this binding */ + list = mateconf_client_all_entries (client, subdir, NULL); + + for (li = list; li != NULL; li = li->next) { + MateConfEntry *entry = li->data; + char *key_name = g_path_get_basename (mateconf_entry_get_key (entry)); + + if (key_name == NULL) { + /* ignore entry */ + } else if (strcmp (key_name, "action") == 0) { + action = entry_get_string (entry); + } else if (strcmp (key_name, "binding") == 0) { + key = entry_get_string (entry); + } + + g_free (key_name); + mateconf_entry_free (entry); + } + + g_slist_free (list); + + if (!action || !key) { + g_warning (_("Key binding (%s) is incomplete"), mateconf_key); + g_free (mateconf_key); + g_free (action); + g_free (key); + return FALSE; + } + + tmp_elem = g_slist_find_custom (manager->priv->binding_list, + mateconf_key, + compare_bindings); + + if (!tmp_elem) { + new_binding = g_new0 (Binding, 1); + } else { + new_binding = (Binding *) tmp_elem->data; + g_free (new_binding->binding_str); + g_free (new_binding->action); + g_free (new_binding->mateconf_key); + + new_binding->previous_key.keysym = new_binding->key.keysym; + new_binding->previous_key.state = new_binding->key.state; + new_binding->previous_key.keycodes = new_binding->key.keycodes; + new_binding->key.keycodes = NULL; + } + + new_binding->binding_str = key; + new_binding->action = action; + new_binding->mateconf_key = mateconf_key; + + if (parse_binding (new_binding)) { + if (!tmp_elem) + manager->priv->binding_list = g_slist_prepend (manager->priv->binding_list, new_binding); + } else { + g_free (new_binding->binding_str); + g_free (new_binding->action); + g_free (new_binding->mateconf_key); + g_free (new_binding->previous_key.keycodes); + g_free (new_binding); + + if (tmp_elem) + manager->priv->binding_list = g_slist_delete_link (manager->priv->binding_list, tmp_elem); + return FALSE; + } + + return TRUE; +} + +static gboolean +same_keycode (const Key *key, const Key *other) +{ + if (key->keycodes != NULL && other->keycodes != NULL) { + guint *c; + + for (c = key->keycodes; *c; ++c) { + if (key_uses_keycode (other, *c)) + return TRUE; + } + } + return FALSE; +} + +static gboolean +same_key (const Key *key, const Key *other) +{ + if (key->state == other->state) { + if (key->keycodes != NULL && other->keycodes != NULL) { + guint *c1, *c2; + + for (c1 = key->keycodes, c2 = other->keycodes; + *c1 || *c2; ++c1, ++c2) { + if (*c1 != *c2) + return FALSE; + } + } else if (key->keycodes != NULL || other->keycodes != NULL) + return FALSE; + + + return TRUE; + } + + return FALSE; +} + +static gboolean +key_already_used (MsdKeybindingsManager *manager, + Binding *binding) +{ + GSList *li; + + for (li = manager->priv->binding_list; li != NULL; li = li->next) { + Binding *tmp_binding = (Binding*) li->data; + + if (tmp_binding != binding && + same_keycode (&tmp_binding->key, &binding->key) && + tmp_binding->key.state == binding->key.state) { + return TRUE; + } + } + + return FALSE; +} + +static void +binding_unregister_keys (MsdKeybindingsManager *manager) +{ + GSList *li; + gboolean need_flush = FALSE; + + gdk_error_trap_push (); + + for (li = manager->priv->binding_list; li != NULL; li = li->next) { + Binding *binding = (Binding *) li->data; + + if (binding->key.keycodes) { + need_flush = TRUE; + grab_key_unsafe (&binding->key, FALSE, manager->priv->screens); + } + } + + if (need_flush) + gdk_flush (); + gdk_error_trap_pop (); +} + +static void +binding_register_keys (MsdKeybindingsManager *manager) +{ + GSList *li; + gboolean need_flush = FALSE; + + gdk_error_trap_push (); + + /* Now check for changes and grab new key if not already used */ + for (li = manager->priv->binding_list; li != NULL; li = li->next) { + Binding *binding = (Binding *) li->data; + + if (manager->priv->allowed_keys != NULL && + !g_slist_find_custom (manager->priv->allowed_keys, + binding->mateconf_key, + (GCompareFunc) g_strcmp0)) { + continue; + } + + if (!same_key (&binding->previous_key, &binding->key)) { + /* Ungrab key if it changed and not clashing with previously set binding */ + if (!key_already_used (manager, binding)) { + gint i; + + need_flush = TRUE; + if (binding->previous_key.keycodes) { + grab_key_unsafe (&binding->previous_key, FALSE, manager->priv->screens); + } + grab_key_unsafe (&binding->key, TRUE, manager->priv->screens); + + binding->previous_key.keysym = binding->key.keysym; + binding->previous_key.state = binding->key.state; + g_free (binding->previous_key.keycodes); + for (i = 0; binding->key.keycodes[i]; ++i); + binding->previous_key.keycodes = g_new0 (guint, i); + for (i = 0; binding->key.keycodes[i]; ++i) + binding->previous_key.keycodes[i] = binding->key.keycodes[i]; + } else + g_warning ("Key binding (%s) is already in use", binding->binding_str); + } + } + + if (need_flush) + gdk_flush (); + if (gdk_error_trap_pop ()) + g_warning ("Grab failed for some keys, another application may already have access the them."); +} + +extern char **environ; + +static char * +screen_exec_display_string (GdkScreen *screen) +{ + GString *str; + const char *old_display; + char *p; + + g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + + old_display = gdk_display_get_name (gdk_screen_get_display (screen)); + + str = g_string_new ("DISPLAY="); + g_string_append (str, old_display); + + p = strrchr (str->str, '.'); + if (p && p > strchr (str->str, ':')) { + g_string_truncate (str, p - str->str); + } + + g_string_append_printf (str, ".%d", gdk_screen_get_number (screen)); + + return g_string_free (str, FALSE); +} + +/** + * get_exec_environment: + * + * Description: Modifies the current program environment to + * ensure that $DISPLAY is set such that a launched application + * inheriting this environment would appear on screen. + * + * Returns: a newly-allocated %NULL-terminated array of strings or + * %NULL on error. Use g_strfreev() to free it. + * + * mainly ripped from egg_screen_exec_display_string in + * mate-panel/egg-screen-exec.c + **/ +static char ** +get_exec_environment (XEvent *xevent) +{ + char **retval = NULL; + int i; + int display_index = -1; + GdkScreen *screen = NULL; + GdkWindow *window = gdk_xid_table_lookup (xevent->xkey.root); + + if (window) { + screen = gdk_drawable_get_screen (GDK_DRAWABLE (window)); + } + + g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + + for (i = 0; environ [i]; i++) { + if (!strncmp (environ [i], "DISPLAY", 7)) { + display_index = i; + } + } + + if (display_index == -1) { + display_index = i++; + } + + retval = g_new (char *, i + 1); + + for (i = 0; environ [i]; i++) { + if (i == display_index) { + retval [i] = screen_exec_display_string (screen); + } else { + retval [i] = g_strdup (environ [i]); + } + } + + retval [i] = NULL; + + return retval; +} + +static GdkFilterReturn +keybindings_filter (GdkXEvent *gdk_xevent, + GdkEvent *event, + MsdKeybindingsManager *manager) +{ + XEvent *xevent = (XEvent *) gdk_xevent; + GSList *li; + + if (xevent->type != KeyPress) { + return GDK_FILTER_CONTINUE; + } + + for (li = manager->priv->binding_list; li != NULL; li = li->next) { + Binding *binding = (Binding *) li->data; + + if (match_key (&binding->key, xevent)) { + GError *error = NULL; + gboolean retval; + gchar **argv = NULL; + gchar **envp = NULL; + + g_return_val_if_fail (binding->action != NULL, GDK_FILTER_CONTINUE); + + if (!g_shell_parse_argv (binding->action, + NULL, &argv, + &error)) { + return GDK_FILTER_CONTINUE; + } + + envp = get_exec_environment (xevent); + + retval = g_spawn_async (NULL, + argv, + envp, + G_SPAWN_SEARCH_PATH, + NULL, + NULL, + NULL, + &error); + g_strfreev (argv); + g_strfreev (envp); + + if (!retval) { + GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_WARNING, + GTK_BUTTONS_CLOSE, + _("Error while trying to run (%s)\n"\ + "which is linked to the key (%s)"), + binding->action, + binding->binding_str); + g_signal_connect (dialog, + "response", + G_CALLBACK (gtk_widget_destroy), + NULL); + gtk_widget_show (dialog); + } + return GDK_FILTER_REMOVE; + } + } + return GDK_FILTER_CONTINUE; +} + +static void +bindings_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdKeybindingsManager *manager) +{ + char** key_elems; + char* binding_entry; + + if (strcmp (mateconf_entry_get_key (entry), ALLOWED_KEYS_KEY) == 0) { + g_slist_foreach (manager->priv->allowed_keys, (GFunc)g_free, NULL); + g_slist_free (manager->priv->allowed_keys); + manager->priv->allowed_keys = mateconf_client_get_list (client, + ALLOWED_KEYS_KEY, + MATECONF_VALUE_STRING, + NULL); + } + else { + /* ensure we get binding dir not a sub component */ + key_elems = g_strsplit (mateconf_entry_get_key (entry), "/", 15); + binding_entry = g_strdup_printf ("/%s/%s/%s/%s", + key_elems[1], + key_elems[2], + key_elems[3], + key_elems[4]); + g_strfreev (key_elems); + + bindings_get_entry (manager, client, binding_entry); + g_free (binding_entry); + } + + binding_register_keys (manager); +} + +static guint +register_config_callback (MsdKeybindingsManager *manager, + MateConfClient *client, + const char *path, + MateConfClientNotifyFunc func) +{ + mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_RECURSIVE, NULL); + return mateconf_client_notify_add (client, path, func, manager, NULL, NULL); +} + +gboolean +msd_keybindings_manager_start (MsdKeybindingsManager *manager, + GError **error) +{ + MateConfClient *client; + GSList *list; + GSList *li; + GdkDisplay *dpy; + GdkScreen *screen; + int screen_num; + int i; + + g_debug ("Starting keybindings manager"); + mate_settings_profile_start (NULL); + + client = mateconf_client_get_default (); + + manager->priv->notify = register_config_callback (manager, + client, + MATECONF_BINDING_DIR, + (MateConfClientNotifyFunc) bindings_callback); + + manager->priv->allowed_keys = mateconf_client_get_list (client, + ALLOWED_KEYS_KEY, + MATECONF_VALUE_STRING, + NULL); + + dpy = gdk_display_get_default (); + screen_num = gdk_display_get_n_screens (dpy); + + for (i = 0; i < screen_num; i++) { + screen = gdk_display_get_screen (dpy, i); + gdk_window_add_filter (gdk_screen_get_root_window (screen), + (GdkFilterFunc) keybindings_filter, + manager); + } + + list = mateconf_client_all_dirs (client, MATECONF_BINDING_DIR, NULL); + manager->priv->screens = get_screens_list (); + + for (li = list; li != NULL; li = li->next) { + bindings_get_entry (manager, client, li->data); + g_free (li->data); + } + + g_slist_free (list); + g_object_unref (client); + + binding_register_keys (manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_keybindings_manager_stop (MsdKeybindingsManager *manager) +{ + MsdKeybindingsManagerPrivate *p = manager->priv; + GSList *l; + + g_debug ("Stopping keybindings manager"); + + if (p->notify != 0) { + MateConfClient *client = mateconf_client_get_default (); + mateconf_client_remove_dir (client, MATECONF_BINDING_DIR, NULL); + mateconf_client_notify_remove (client, p->notify); + g_object_unref (client); + p->notify = 0; + } + + for (l = p->screens; l; l = l->next) { + GdkScreen *screen = l->data; + gdk_window_remove_filter (gdk_screen_get_root_window (screen), + (GdkFilterFunc) keybindings_filter, + manager); + } + + binding_unregister_keys (manager); + + g_slist_free (p->screens); + p->screens = NULL; + + for (l = p->binding_list; l; l = l->next) { + Binding *b = l->data; + g_free (b->binding_str); + g_free (b->action); + g_free (b->mateconf_key); + g_free (b->previous_key.keycodes); + g_free (b->key.keycodes); + g_free (b); + } + g_slist_free (p->binding_list); + p->binding_list = NULL; +} + +static void +msd_keybindings_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdKeybindingsManager *self; + + self = MSD_KEYBINDINGS_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_keybindings_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdKeybindingsManager *self; + + self = MSD_KEYBINDINGS_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_keybindings_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdKeybindingsManager *keybindings_manager; + MsdKeybindingsManagerClass *klass; + + klass = MSD_KEYBINDINGS_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_KEYBINDINGS_MANAGER)); + + keybindings_manager = MSD_KEYBINDINGS_MANAGER (G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (keybindings_manager); +} + +static void +msd_keybindings_manager_dispose (GObject *object) +{ + MsdKeybindingsManager *keybindings_manager; + + keybindings_manager = MSD_KEYBINDINGS_MANAGER (object); + + G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->dispose (object); +} + +static void +msd_keybindings_manager_class_init (MsdKeybindingsManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_keybindings_manager_get_property; + object_class->set_property = msd_keybindings_manager_set_property; + object_class->constructor = msd_keybindings_manager_constructor; + object_class->dispose = msd_keybindings_manager_dispose; + object_class->finalize = msd_keybindings_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdKeybindingsManagerPrivate)); +} + +static void +msd_keybindings_manager_init (MsdKeybindingsManager *manager) +{ + manager->priv = MSD_KEYBINDINGS_MANAGER_GET_PRIVATE (manager); + +} + +static void +msd_keybindings_manager_finalize (GObject *object) +{ + MsdKeybindingsManager *keybindings_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_KEYBINDINGS_MANAGER (object)); + + keybindings_manager = MSD_KEYBINDINGS_MANAGER (object); + + g_return_if_fail (keybindings_manager->priv != NULL); + + G_OBJECT_CLASS (msd_keybindings_manager_parent_class)->finalize (object); +} + +MsdKeybindingsManager * +msd_keybindings_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_KEYBINDINGS_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_KEYBINDINGS_MANAGER (manager_object); +} diff --git a/plugins/keybindings/msd-keybindings-manager.h b/plugins/keybindings/msd-keybindings-manager.h new file mode 100644 index 0000000..95b1bed --- /dev/null +++ b/plugins/keybindings/msd-keybindings-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_KEYBINDINGS_MANAGER_H +#define __MSD_KEYBINDINGS_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_KEYBINDINGS_MANAGER (msd_keybindings_manager_get_type ()) +#define MSD_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManager)) +#define MSD_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerClass)) +#define MSD_IS_KEYBINDINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBINDINGS_MANAGER)) +#define MSD_IS_KEYBINDINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBINDINGS_MANAGER)) +#define MSD_KEYBINDINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBINDINGS_MANAGER, MsdKeybindingsManagerClass)) + +typedef struct MsdKeybindingsManagerPrivate MsdKeybindingsManagerPrivate; + +typedef struct +{ + GObject parent; + MsdKeybindingsManagerPrivate *priv; +} MsdKeybindingsManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdKeybindingsManagerClass; + +GType msd_keybindings_manager_get_type (void); + +MsdKeybindingsManager * msd_keybindings_manager_new (void); +gboolean msd_keybindings_manager_start (MsdKeybindingsManager *manager, + GError **error); +void msd_keybindings_manager_stop (MsdKeybindingsManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_KEYBINDINGS_MANAGER_H */ diff --git a/plugins/keybindings/msd-keybindings-plugin.c b/plugins/keybindings/msd-keybindings-plugin.c new file mode 100644 index 0000000..5b0cebb --- /dev/null +++ b/plugins/keybindings/msd-keybindings-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-keybindings-plugin.h" +#include "msd-keybindings-manager.h" + +struct MsdKeybindingsPluginPrivate { + MsdKeybindingsManager *manager; +}; + +#define MSD_KEYBINDINGS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdKeybindingsPlugin, msd_keybindings_plugin) + +static void +msd_keybindings_plugin_init (MsdKeybindingsPlugin *plugin) +{ + plugin->priv = MSD_KEYBINDINGS_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdKeybindingsPlugin initializing"); + + plugin->priv->manager = msd_keybindings_manager_new (); +} + +static void +msd_keybindings_plugin_finalize (GObject *object) +{ + MsdKeybindingsPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_KEYBINDINGS_PLUGIN (object)); + + g_debug ("MsdKeybindingsPlugin finalizing"); + + plugin = MSD_KEYBINDINGS_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_keybindings_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating keybindings plugin"); + + error = NULL; + res = msd_keybindings_manager_start (MSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start keybindings manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating keybindings plugin"); + msd_keybindings_manager_stop (MSD_KEYBINDINGS_PLUGIN (plugin)->priv->manager); +} + +static void +msd_keybindings_plugin_class_init (MsdKeybindingsPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_keybindings_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdKeybindingsPluginPrivate)); +} diff --git a/plugins/keybindings/msd-keybindings-plugin.h b/plugins/keybindings/msd-keybindings-plugin.h new file mode 100644 index 0000000..f45d0f8 --- /dev/null +++ b/plugins/keybindings/msd-keybindings-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_KEYBINDINGS_PLUGIN_H__ +#define __MSD_KEYBINDINGS_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_KEYBINDINGS_PLUGIN (msd_keybindings_plugin_get_type ()) +#define MSD_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPlugin)) +#define MSD_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginClass)) +#define MSD_IS_KEYBINDINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBINDINGS_PLUGIN)) +#define MSD_IS_KEYBINDINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBINDINGS_PLUGIN)) +#define MSD_KEYBINDINGS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBINDINGS_PLUGIN, MsdKeybindingsPluginClass)) + +typedef struct MsdKeybindingsPluginPrivate MsdKeybindingsPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdKeybindingsPluginPrivate *priv; +} MsdKeybindingsPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdKeybindingsPluginClass; + +GType msd_keybindings_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_KEYBINDINGS_PLUGIN_H__ */ diff --git a/plugins/keyboard/gsd-keyboard-manager.c b/plugins/keyboard/gsd-keyboard-manager.c deleted file mode 100644 index 0969459..0000000 --- a/plugins/keyboard/gsd-keyboard-manager.c +++ /dev/null @@ -1,569 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright © 2001 Ximian, Inc. - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H - #include -#endif - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - #include - #include -#endif - -#include "mate-settings-profile.h" -#include "msd-keyboard-manager.h" - -#include "msd-keyboard-xkb.h" -#include "msd-xmodmap.h" - -#define MSD_KEYBOARD_MANAGER_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerPrivate)) - -#ifndef HOST_NAME_MAX - #define HOST_NAME_MAX 255 -#endif - -#define MSD_KEYBOARD_KEY "/desktop/mate/peripherals/keyboard" - -#define KEY_REPEAT MSD_KEYBOARD_KEY "/repeat" -#define KEY_CLICK MSD_KEYBOARD_KEY "/click" -#define KEY_RATE MSD_KEYBOARD_KEY "/rate" -#define KEY_DELAY MSD_KEYBOARD_KEY "/delay" -#define KEY_CLICK_VOLUME MSD_KEYBOARD_KEY "/click_volume" - -#define KEY_BELL_VOLUME MSD_KEYBOARD_KEY "/bell_volume" -#define KEY_BELL_PITCH MSD_KEYBOARD_KEY "/bell_pitch" -#define KEY_BELL_DURATION MSD_KEYBOARD_KEY "/bell_duration" -#define KEY_BELL_MODE MSD_KEYBOARD_KEY "/bell_mode" - -struct MsdKeyboardManagerPrivate { - gboolean have_xkb; - gint xkb_event_base; - guint notify; -}; - -static void msd_keyboard_manager_class_init (MsdKeyboardManagerClass* klass); -static void msd_keyboard_manager_init (MsdKeyboardManager* keyboard_manager); -static void msd_keyboard_manager_finalize (GObject* object); - -G_DEFINE_TYPE (MsdKeyboardManager, msd_keyboard_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - - -#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H -static gboolean xfree86_set_keyboard_autorepeat_rate(int delay, int rate) -{ - gboolean res = FALSE; - int event_base_return; - int error_base_return; - - if (XF86MiscQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - &event_base_return, - &error_base_return) == True) { - /* load the current settings */ - XF86MiscKbdSettings kbdsettings; - XF86MiscGetKbdSettings (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &kbdsettings); - - /* assign the new values */ - kbdsettings.delay = delay; - kbdsettings.rate = rate; - XF86MiscSetKbdSettings (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &kbdsettings); - res = TRUE; - } - - return res; -} -#endif /* HAVE_X11_EXTENSIONS_XF86MISC_H */ - -#ifdef HAVE_X11_EXTENSIONS_XKB_H -static gboolean xkb_set_keyboard_autorepeat_rate(int delay, int rate) -{ - int interval = (rate <= 0) ? 1000000 : 1000/rate; - - if (delay <= 0) - { - delay = 1; - } - - return XkbSetAutoRepeatRate(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XkbUseCoreKbd, delay, interval); -} -#endif - -static char* msd_keyboard_get_hostname_key (const char *subkey) -{ - char hostname[HOST_NAME_MAX + 1]; - - if (gethostname (hostname, sizeof (hostname)) == 0 && - strcmp (hostname, "localhost") != 0 && - strcmp (hostname, "localhost.localdomain") != 0) { - char *escaped; - char *key; - - escaped = mateconf_escape_key (hostname, -1); - key = g_strconcat (MSD_KEYBOARD_KEY - "/host-", - escaped, - "/0/", - subkey, - NULL); - g_free (escaped); - return key; - } else - return NULL; -} - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - -typedef enum { - NUMLOCK_STATE_OFF = 0, - NUMLOCK_STATE_ON = 1, - NUMLOCK_STATE_UNKNOWN = 2 -} NumLockState; - -static void -numlock_xkb_init (MsdKeyboardManager *manager) -{ - Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - gboolean have_xkb; - int opcode, error_base, major, minor; - - have_xkb = XkbQueryExtension (dpy, - &opcode, - &manager->priv->xkb_event_base, - &error_base, - &major, - &minor) - && XkbUseExtension (dpy, &major, &minor); - - if (have_xkb) { - XkbSelectEventDetails (dpy, - XkbUseCoreKbd, - XkbStateNotifyMask, - XkbModifierLockMask, - XkbModifierLockMask); - } else { - g_warning ("XKB extension not available"); - } - - manager->priv->have_xkb = have_xkb; -} - -static unsigned -numlock_NumLock_modifier_mask (void) -{ - Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - return XkbKeysymToModifiers (dpy, XK_Num_Lock); -} - -static void -numlock_set_xkb_state (NumLockState new_state) -{ - unsigned int num_mask; - Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - if (new_state != NUMLOCK_STATE_ON && new_state != NUMLOCK_STATE_OFF) - return; - num_mask = numlock_NumLock_modifier_mask (); - XkbLockModifiers (dpy, XkbUseCoreKbd, num_mask, new_state ? num_mask : 0); -} - -static char * -numlock_mateconf_state_key (void) -{ - char *key = msd_keyboard_get_hostname_key ("numlock_on"); - if (!key) { - g_message ("NumLock remembering disabled because hostname is set to \"localhost\""); - } - return key; -} - -static NumLockState -numlock_get_mateconf_state (MateConfClient *client) -{ - int curr_state; - GError *err = NULL; - char *key = numlock_mateconf_state_key (); - - if (!key) { - return NUMLOCK_STATE_UNKNOWN; - } - - curr_state = mateconf_client_get_bool (client, key, &err); - if (err) { - curr_state = NUMLOCK_STATE_UNKNOWN; - g_error_free (err); - } - - g_free (key); - return curr_state; -} - -static void numlock_set_mateconf_state(MateConfClient *client, NumLockState new_state) -{ - //printf("numlock_set_mateconf_state\n"); - char* key; - - if (new_state != NUMLOCK_STATE_ON && new_state != NUMLOCK_STATE_OFF) { - return; - } - - key = numlock_mateconf_state_key (); - - if (key) { - mateconf_client_set_bool (client, key, new_state, NULL); - g_free (key); - } -} - -static GdkFilterReturn -numlock_xkb_callback (GdkXEvent *xev_, - GdkEvent *gdkev_, - gpointer xkb_event_code) -{ - XEvent *xev = (XEvent *) xev_; - - if (xev->type == GPOINTER_TO_INT (xkb_event_code)) { - XkbEvent *xkbev = (XkbEvent *)xev; - if (xkbev->any.xkb_type == XkbStateNotify) - if (xkbev->state.changed & XkbModifierLockMask) { - unsigned num_mask = numlock_NumLock_modifier_mask (); - unsigned locked_mods = xkbev->state.locked_mods; - int numlock_state = !! (num_mask & locked_mods); - MateConfClient *client = mateconf_client_get_default (); - numlock_set_mateconf_state (client, numlock_state); - g_object_unref (client); - } - } - return GDK_FILTER_CONTINUE; -} - -static void -numlock_install_xkb_callback (MsdKeyboardManager *manager) -{ - if (!manager->priv->have_xkb) - return; - - gdk_window_add_filter (NULL, - numlock_xkb_callback, - GINT_TO_POINTER (manager->priv->xkb_event_base)); -} - -#endif /* HAVE_X11_EXTENSIONS_XKB_H */ - -static void -apply_settings (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdKeyboardManager *manager) -{ - XKeyboardControl kbdcontrol; - gboolean repeat; - gboolean click; - int rate; - int delay; - int click_volume; - int bell_volume; - int bell_pitch; - int bell_duration; - char *volume_string; -#ifdef HAVE_X11_EXTENSIONS_XKB_H - gboolean rnumlock; -#endif /* HAVE_X11_EXTENSIONS_XKB_H */ - - repeat = mateconf_client_get_bool (client, KEY_REPEAT, NULL); - click = mateconf_client_get_bool (client, KEY_CLICK, NULL); - rate = mateconf_client_get_int (client, KEY_RATE, NULL); - delay = mateconf_client_get_int (client, KEY_DELAY, NULL); - click_volume = mateconf_client_get_int (client, KEY_CLICK_VOLUME, NULL); -#if 0 - bell_volume = mateconf_client_get_int (client, KEY_BELL_VOLUME, NULL); -#endif - bell_pitch = mateconf_client_get_int (client, KEY_BELL_PITCH, NULL); - bell_duration = mateconf_client_get_int (client, KEY_BELL_DURATION, NULL); - - volume_string = mateconf_client_get_string (client, KEY_BELL_MODE, NULL); - bell_volume = (volume_string && !strcmp (volume_string, "on")) ? 50 : 0; - g_free (volume_string); - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - rnumlock = mateconf_client_get_bool (client, MSD_KEYBOARD_KEY "/remember_numlock_state", NULL); -#endif /* HAVE_X11_EXTENSIONS_XKB_H */ - - gdk_error_trap_push (); - if (repeat) { - gboolean rate_set = FALSE; - - XAutoRepeatOn (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); - /* Use XKB in preference */ -#ifdef HAVE_X11_EXTENSIONS_XKB_H - rate_set = xkb_set_keyboard_autorepeat_rate (delay, rate); -#endif -#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H - if (!rate_set) - rate_set = xfree86_set_keyboard_autorepeat_rate (delay, rate); -#endif - if (!rate_set) - g_warning ("Neither XKeyboard not Xfree86's keyboard extensions are available,\n" - "no way to support keyboard autorepeat rate settings"); - } else { - XAutoRepeatOff (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); - } - - /* as percentage from 0..100 inclusive */ - if (click_volume < 0) { - click_volume = 0; - } else if (click_volume > 100) { - click_volume = 100; - } - kbdcontrol.key_click_percent = click ? click_volume : 0; - kbdcontrol.bell_percent = bell_volume; - kbdcontrol.bell_pitch = bell_pitch; - kbdcontrol.bell_duration = bell_duration; - XChangeKeyboardControl (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration, - &kbdcontrol); - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - if (manager->priv->have_xkb && rnumlock) { - numlock_set_xkb_state (numlock_get_mateconf_state (client)); - } -#endif /* HAVE_X11_EXTENSIONS_XKB_H */ - - XSync (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), FALSE); - gdk_error_trap_pop (); -} - -void -msd_keyboard_manager_apply_settings (MsdKeyboardManager *manager) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - apply_settings (client, 0, NULL, manager); - g_object_unref (client); -} - -static gboolean -start_keyboard_idle_cb (MsdKeyboardManager *manager) -{ - MateConfClient *client; - - mate_settings_profile_start (NULL); - - g_debug ("Starting keyboard manager"); - - manager->priv->have_xkb = 0; - client = mateconf_client_get_default (); - - mateconf_client_add_dir (client, MSD_KEYBOARD_KEY, MATECONF_CLIENT_PRELOAD_RECURSIVE, NULL); - - /* Essential - xkb initialization should happen before */ - msd_keyboard_xkb_set_post_activation_callback ((PostActivationCallback) msd_load_modmap_files, NULL); - msd_keyboard_xkb_init (client, manager); - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - numlock_xkb_init (manager); -#endif /* HAVE_X11_EXTENSIONS_XKB_H */ - - /* apply current settings before we install the callback */ - msd_keyboard_manager_apply_settings (manager); - - manager->priv->notify = mateconf_client_notify_add (client, MSD_KEYBOARD_KEY, - (MateConfClientNotifyFunc) apply_settings, manager, - NULL, NULL); - - g_object_unref (client); - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - numlock_install_xkb_callback (manager); -#endif /* HAVE_X11_EXTENSIONS_XKB_H */ - - mate_settings_profile_end (NULL); - - return FALSE; -} - -gboolean -msd_keyboard_manager_start (MsdKeyboardManager *manager, - GError **error) -{ - mate_settings_profile_start (NULL); - - g_idle_add ((GSourceFunc) start_keyboard_idle_cb, manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_keyboard_manager_stop (MsdKeyboardManager *manager) -{ - MsdKeyboardManagerPrivate *p = manager->priv; - - g_debug ("Stopping keyboard manager"); - - if (p->notify != 0) { - MateConfClient *client = mateconf_client_get_default (); - mateconf_client_remove_dir (client, MSD_KEYBOARD_KEY, NULL); - mateconf_client_notify_remove (client, p->notify); - g_object_unref (client); - p->notify = 0; - } - -#if HAVE_X11_EXTENSIONS_XKB_H - if (p->have_xkb) { - gdk_window_remove_filter (NULL, - numlock_xkb_callback, - GINT_TO_POINTER (p->xkb_event_base)); - } -#endif /* HAVE_X11_EXTENSIONS_XKB_H */ - - msd_keyboard_xkb_shutdown (); -} - -static void -msd_keyboard_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdKeyboardManager *self; - - self = MSD_KEYBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_keyboard_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdKeyboardManager *self; - - self = MSD_KEYBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_keyboard_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdKeyboardManager *keyboard_manager; - MsdKeyboardManagerClass *klass; - - klass = MSD_KEYBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_KEYBOARD_MANAGER)); - - keyboard_manager = MSD_KEYBOARD_MANAGER (G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (keyboard_manager); -} - -static void -msd_keyboard_manager_dispose (GObject *object) -{ - MsdKeyboardManager *keyboard_manager; - - keyboard_manager = MSD_KEYBOARD_MANAGER (object); - - G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->dispose (object); -} - -static void -msd_keyboard_manager_class_init (MsdKeyboardManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_keyboard_manager_get_property; - object_class->set_property = msd_keyboard_manager_set_property; - object_class->constructor = msd_keyboard_manager_constructor; - object_class->dispose = msd_keyboard_manager_dispose; - object_class->finalize = msd_keyboard_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdKeyboardManagerPrivate)); -} - -static void -msd_keyboard_manager_init (MsdKeyboardManager *manager) -{ - manager->priv = MSD_KEYBOARD_MANAGER_GET_PRIVATE (manager); -} - -static void -msd_keyboard_manager_finalize (GObject *object) -{ - MsdKeyboardManager *keyboard_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_KEYBOARD_MANAGER (object)); - - keyboard_manager = MSD_KEYBOARD_MANAGER (object); - - g_return_if_fail (keyboard_manager->priv != NULL); - - G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->finalize (object); -} - -MsdKeyboardManager * -msd_keyboard_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_KEYBOARD_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_KEYBOARD_MANAGER (manager_object); -} diff --git a/plugins/keyboard/gsd-keyboard-manager.h b/plugins/keyboard/gsd-keyboard-manager.h deleted file mode 100644 index aa3ae95..0000000 --- a/plugins/keyboard/gsd-keyboard-manager.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_KEYBOARD_MANAGER_H -#define __MSD_KEYBOARD_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_KEYBOARD_MANAGER (msd_keyboard_manager_get_type ()) -#define MSD_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManager)) -#define MSD_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerClass)) -#define MSD_IS_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBOARD_MANAGER)) -#define MSD_IS_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBOARD_MANAGER)) -#define MSD_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerClass)) - -typedef struct MsdKeyboardManagerPrivate MsdKeyboardManagerPrivate; - -typedef struct -{ - GObject parent; - MsdKeyboardManagerPrivate *priv; -} MsdKeyboardManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdKeyboardManagerClass; - -GType msd_keyboard_manager_get_type (void); - -MsdKeyboardManager * msd_keyboard_manager_new (void); -gboolean msd_keyboard_manager_start (MsdKeyboardManager *manager, - GError **error); -void msd_keyboard_manager_stop (MsdKeyboardManager *manager); -void msd_keyboard_manager_apply_settings (MsdKeyboardManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_KEYBOARD_MANAGER_H */ diff --git a/plugins/keyboard/gsd-keyboard-plugin.c b/plugins/keyboard/gsd-keyboard-plugin.c deleted file mode 100644 index 5f89ca2..0000000 --- a/plugins/keyboard/gsd-keyboard-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-keyboard-plugin.h" -#include "msd-keyboard-manager.h" - -struct MsdKeyboardPluginPrivate { - MsdKeyboardManager *manager; -}; - -#define MSD_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdKeyboardPlugin, msd_keyboard_plugin) - -static void -msd_keyboard_plugin_init (MsdKeyboardPlugin *plugin) -{ - plugin->priv = MSD_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdKeyboardPlugin initializing"); - - plugin->priv->manager = msd_keyboard_manager_new (); -} - -static void -msd_keyboard_plugin_finalize (GObject *object) -{ - MsdKeyboardPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_KEYBOARD_PLUGIN (object)); - - g_debug ("MsdKeyboardPlugin finalizing"); - - plugin = MSD_KEYBOARD_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_keyboard_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating keyboard plugin"); - - error = NULL; - res = msd_keyboard_manager_start (MSD_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start keyboard manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating keyboard plugin"); - msd_keyboard_manager_stop (MSD_KEYBOARD_PLUGIN (plugin)->priv->manager); -} - -static void -msd_keyboard_plugin_class_init (MsdKeyboardPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_keyboard_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdKeyboardPluginPrivate)); -} diff --git a/plugins/keyboard/gsd-keyboard-plugin.h b/plugins/keyboard/gsd-keyboard-plugin.h deleted file mode 100644 index 84f2420..0000000 --- a/plugins/keyboard/gsd-keyboard-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_KEYBOARD_PLUGIN_H__ -#define __MSD_KEYBOARD_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_KEYBOARD_PLUGIN (msd_keyboard_plugin_get_type ()) -#define MSD_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPlugin)) -#define MSD_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginClass)) -#define MSD_IS_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBOARD_PLUGIN)) -#define MSD_IS_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBOARD_PLUGIN)) -#define MSD_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginClass)) - -typedef struct MsdKeyboardPluginPrivate MsdKeyboardPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdKeyboardPluginPrivate *priv; -} MsdKeyboardPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdKeyboardPluginClass; - -GType msd_keyboard_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_KEYBOARD_PLUGIN_H__ */ diff --git a/plugins/keyboard/gsd-keyboard-xkb.c b/plugins/keyboard/gsd-keyboard-xkb.c deleted file mode 100644 index 9042f03..0000000 --- a/plugins/keyboard/gsd-keyboard-xkb.c +++ /dev/null @@ -1,918 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2001 Udaltsoft - * - * Written by Sergey V. Oudaltsov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include "config.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "msd-xmodmap.h" -#include "msd-keyboard-xkb.h" -#include "delayed-dialog.h" -#include "mate-settings-profile.h" - -#define GTK_RESPONSE_PRINT 2 - -static MsdKeyboardManager* manager = NULL; - -static XklEngine* xkl_engine; -static XklConfigRegistry* xkl_registry = NULL; - -static MatekbdDesktopConfig current_config; -static MatekbdKeyboardConfig current_kbd_config; - -/* never terminated */ -static MatekbdKeyboardConfig initial_sys_kbd_config; - -static gboolean inited_ok = FALSE; - -static guint notify_desktop = 0; -static guint notify_keyboard = 0; - -static PostActivationCallback pa_callback = NULL; -static void *pa_callback_user_data = NULL; - -static const char KNOWN_FILES_KEY[] = "/desktop/mate/peripherals/keyboard/general/known_file_list"; - -static const char DISABLE_INDICATOR_KEY[] = "/desktop/mate/peripherals/keyboard/general/disable_indicator"; - -static const char DUPLICATE_LEDS_KEY[] = "/desktop/mate/peripherals/keyboard/general/duplicate_leds"; - -static const char* mdm_keyboard_layout = NULL; - -static GtkStatusIcon* icon = NULL; - -static GHashTable* preview_dialogs = NULL; - -static Atom caps_lock; -static Atom num_lock; -static Atom scroll_lock; - -static GtkStatusIcon* indicator_icons[3]; -static const gchar* indicator_on_icon_names[] = { - "kbd-scrolllock-on", - "kbd-numlock-on", - "kbd-capslock-on" -}; - -static const gchar* indicator_off_icon_names[] = { - "kbd-scrolllock-off", - "kbd-numlock-off", - "kbd-capslock-off" -}; - -//#define noMSDKX - -#ifdef MSDKX -static FILE *logfile; - -static void msd_keyboard_log_appender(const char file[], const char function[], int level, const char format[], va_list args) -{ - time_t now = time (NULL); - fprintf (logfile, "[%08ld,%03d,%s:%s/] \t", now, - level, file, function); - vfprintf (logfile, format, args); - fflush (logfile); -} -#endif - -static void -activation_error (void) -{ - char const *vendor = ServerVendor (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); - int release = VendorRelease (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); - GtkWidget *dialog; - gboolean badXFree430Release; - - badXFree430Release = (vendor != NULL) - && (0 == strcmp (vendor, "The XFree86 Project, Inc")) - && (release / 100000 == 403); - - /* VNC viewers will not work, do not barrage them with warnings */ - if (NULL != vendor && NULL != strstr (vendor, "VNC")) - return; - - dialog = gtk_message_dialog_new_with_markup (NULL, - 0, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - _ - ("Error activating XKB configuration.\n" - "It can happen under various circumstances:\n" - " • a bug in libxklavier library\n" - " • a bug in X server (xkbcomp, xmodmap utilities)\n" - " • X server with incompatible libxkbfile implementation\n\n" - "X server version data:\n%s\n%d\n%s\n" - "If you report this situation as a bug, please include:\n" - " • The result of %s\n" - " • The result of %s"), - vendor, - release, - badXFree430Release - ? - _ - ("You are using XFree 4.3.0.\n" - "There are known problems with complex XKB configurations.\n" - "Try using a simpler configuration or using a later version of the XFree software.") - : "", - "xprop -root | grep XKB", - "mateconftool-2 -R /desktop/mate/peripherals/keyboard/kbd"); - g_signal_connect (dialog, "response", - G_CALLBACK (gtk_widget_destroy), NULL); - msd_delayed_show_dialog (dialog); -} - -static void -apply_desktop_settings (void) -{ - MateConfClient *conf_client; - gboolean show_leds; - int i; - if (!inited_ok) - return; - - msd_keyboard_manager_apply_settings (manager); - matekbd_desktop_config_load_from_mateconf (¤t_config); - /* again, probably it would be nice to compare things - before activating them */ - matekbd_desktop_config_activate (¤t_config); - - conf_client = mateconf_client_get_default (); - show_leds = - mateconf_client_get_bool (conf_client, DUPLICATE_LEDS_KEY, NULL); - g_object_unref (conf_client); - for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); - --i >= 0;) { - gtk_status_icon_set_visible (indicator_icons[i], - show_leds); - } -} - -static void -popup_menu_launch_capplet () -{ - GError *error = NULL; - - gdk_spawn_command_line_on_screen (gdk_screen_get_default (), - "mate-keyboard-properties", - &error); - - if (error != NULL) { - g_warning - ("Could not execute keyboard properties capplet: [%s]\n", - error->message); - g_error_free (error); - } -} - -static void -show_layout_destroy (GtkWidget * dialog, gint group) -{ - g_hash_table_remove (preview_dialogs, GINT_TO_POINTER (group)); -} - -static void -popup_menu_show_layout () -{ - GtkWidget *dialog; - XklEngine *engine = xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); - XklState *xkl_state = xkl_engine_get_current_state (engine); - gpointer p = g_hash_table_lookup (preview_dialogs, - GINT_TO_POINTER - (xkl_state->group)); - gchar **group_names = matekbd_status_get_group_names (); - - if (xkl_state->group < 0 - || xkl_state->group >= g_strv_length (group_names)) { - return; - } - - if (p != NULL) { - /* existing window */ - gtk_window_present (GTK_WINDOW (p)); - return; - } - - dialog = - matekbd_keyboard_drawing_new_dialog (xkl_state->group, - group_names - [xkl_state->group]); - g_signal_connect (GTK_OBJECT (dialog), "destroy", - G_CALLBACK (show_layout_destroy), - GINT_TO_POINTER (xkl_state->group)); - g_hash_table_insert (preview_dialogs, - GINT_TO_POINTER (xkl_state->group), dialog); -} - -static void -popup_menu_set_group (GtkMenuItem * item, gpointer param) -{ - gint group_number = GPOINTER_TO_INT (param); - XklEngine *engine = matekbd_status_get_xkl_engine (); - XklState st; - Window cur; - - st.group = group_number; - xkl_engine_allow_one_switch_to_secondary_group (engine); - cur = xkl_engine_get_current_window (engine); - if (cur != (Window) NULL) { - xkl_debug (150, "Enforcing the state %d for window %lx\n", - st.group, cur); - xkl_engine_save_state (engine, - xkl_engine_get_current_window - (engine), &st); -/* XSetInputFocus(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), cur, RevertToNone, CurrentTime );*/ - } else { - xkl_debug (150, - "??? Enforcing the state %d for unknown window\n", - st.group); - /* strange situation - bad things can happen */ - } - xkl_engine_lock_group (engine, st.group); -} - -static void -status_icon_popup_menu_cb (GtkStatusIcon * icon, guint button, guint time) -{ - GtkMenu *popup_menu = GTK_MENU (gtk_menu_new ()); - GtkMenu *groups_menu = GTK_MENU (gtk_menu_new ()); - int i = 0; - gchar **current_name = matekbd_status_get_group_names (); - - GtkWidget *item = gtk_menu_item_new_with_mnemonic (_("_Layouts")); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), - GTK_WIDGET (groups_menu)); - - item = - gtk_menu_item_new_with_mnemonic (_("Keyboard _Preferences")); - gtk_widget_show (item); - g_signal_connect (item, "activate", popup_menu_launch_capplet, - NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item); - - item = gtk_menu_item_new_with_mnemonic (_("Show _Current Layout")); - gtk_widget_show (item); - g_signal_connect (item, "activate", popup_menu_show_layout, NULL); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item); - - for (i = 0; *current_name; i++, current_name++) { - gchar *image_file = matekbd_status_get_image_filename (i); - - if (image_file == NULL) { - item = - gtk_menu_item_new_with_label (*current_name); - } else { - GdkPixbuf *pixbuf = - gdk_pixbuf_new_from_file_at_size (image_file, - 24, 24, - NULL); - GtkWidget *img = - gtk_image_new_from_pixbuf (pixbuf); - item = - gtk_image_menu_item_new_with_label - (*current_name); - gtk_widget_show (img); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM - (item), img); - gtk_image_menu_item_set_always_show_image - (GTK_IMAGE_MENU_ITEM (item), TRUE); - g_free (image_file); - } - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (groups_menu), item); - g_signal_connect (item, "activate", - G_CALLBACK (popup_menu_set_group), - GINT_TO_POINTER (i)); - } - - gtk_menu_popup (popup_menu, NULL, NULL, - gtk_status_icon_position_menu, - (gpointer) icon, button, time); -} - -static void -show_hide_icon () -{ - if (g_slist_length (current_kbd_config.layouts_variants) > 1) { - if (icon == NULL) { - MateConfClient *conf_client = - mateconf_client_get_default (); - gboolean disable = - mateconf_client_get_bool (conf_client, - DISABLE_INDICATOR_KEY, - NULL); - g_object_unref (conf_client); - if (disable) - return; - - xkl_debug (150, "Creating new icon\n"); - icon = matekbd_status_new (); - g_signal_connect (icon, "popup-menu", - G_CALLBACK - (status_icon_popup_menu_cb), - NULL); - - } - } else { - if (icon != NULL) { - xkl_debug (150, "Destroying icon\n"); - g_object_unref (icon); - icon = NULL; - } - } -} - -static gboolean -try_activating_xkb_config_if_new (MatekbdKeyboardConfig * - current_sys_kbd_config) -{ - /* Activate - only if different! */ - if (!matekbd_keyboard_config_equals - (¤t_kbd_config, current_sys_kbd_config)) { - if (matekbd_keyboard_config_activate (¤t_kbd_config)) { - if (pa_callback != NULL) { - (*pa_callback) (pa_callback_user_data); - return TRUE; - } - } else { - return FALSE; - } - } - return TRUE; -} - -static gboolean -filter_xkb_config (void) -{ - XklConfigItem *item; - gchar *lname; - gchar *vname; - GSList *lv; - GSList *filtered; - gboolean any_change = FALSE; - - xkl_debug (100, "Filtering configuration against the registry\n"); - if (!xkl_registry) { - xkl_registry = - xkl_config_registry_get_instance (xkl_engine); - /* load all materials, unconditionally! */ - if (!xkl_config_registry_load (xkl_registry, TRUE)) { - g_object_unref (xkl_registry); - xkl_registry = NULL; - return FALSE; - } - } - lv = current_kbd_config.layouts_variants; - item = xkl_config_item_new (); - while (lv) { - xkl_debug (100, "Checking [%s]\n", lv->data); - if (matekbd_keyboard_config_split_items - (lv->data, &lname, &vname)) { - g_snprintf (item->name, sizeof (item->name), "%s", - lname); - if (!xkl_config_registry_find_layout - (xkl_registry, item)) { - xkl_debug (100, "Bad layout [%s]\n", - lname); - filtered = lv; - lv = lv->next; - g_free (filtered->data); - current_kbd_config.layouts_variants = - g_slist_delete_link - (current_kbd_config.layouts_variants, - filtered); - any_change = TRUE; - continue; - } - if (vname) { - g_snprintf (item->name, - sizeof (item->name), "%s", - vname); - if (!xkl_config_registry_find_variant - (xkl_registry, lname, item)) { - xkl_debug (100, - "Bad variant [%s(%s)]\n", - lname, vname); - filtered = lv; - lv = lv->next; - g_free (filtered->data); - current_kbd_config.layouts_variants - = - g_slist_delete_link - (current_kbd_config.layouts_variants, - filtered); - any_change = TRUE; - continue; - } - } - } - lv = lv->next; - } - g_object_unref (item); - return any_change; -} - -static void -apply_xkb_settings (void) -{ - MateConfClient *conf_client; - MatekbdKeyboardConfig current_sys_kbd_config; - int group_to_activate = -1; - char *mdm_layout; - char *s; - - if (!inited_ok) - return; - - conf_client = mateconf_client_get_default (); - - /* With MDM the user can already set a layout from the login - * screen. Try to keep that setting. - * We clear mdm_keyboard_layout early, so we don't risk - * recursion from mateconf notification. - */ - mdm_layout = g_strdup (mdm_keyboard_layout); - mdm_keyboard_layout = NULL; - - /* mdm's configuration and $MDM_KEYBOARD_LAYOUT separates layout and - * variant with a space, but mateconf uses tabs; so convert to be robust - * with both */ - for (s = mdm_layout; s && *s; ++s) { - if (*s == ' ') { - *s = '\t'; - } - } - - if (mdm_layout != NULL) { - GSList *layouts; - GSList *found_node; - int max_groups; - - max_groups = - MAX (xkl_engine_get_max_num_groups (xkl_engine), 1); - layouts = - mateconf_client_get_list (conf_client, - MATEKBD_KEYBOARD_CONFIG_KEY_LAYOUTS, - MATECONF_VALUE_STRING, NULL); - - /* Use system layouts as a default if we do not have - * user configuration */ - if (layouts == NULL) { - GSList *i; - int len; - - for (i = initial_sys_kbd_config.layouts_variants; - i; i = g_slist_next (i)) { - s = g_strdup (i->data); - - /* chop off empty variants to avoid duplicates */ - len = strlen (s); - if (s[len - 1] == '\t') - s[len - 1] = '\0'; - layouts = g_slist_append (layouts, s); - } - } - - /* Add the layout if it doesn't already exist. XKB limits the - * total number of layouts. If we already have the maximum - * number of layouts configured, we replace the last one. This - * prevents the list from becoming full if the user has a habit - * of selecting many different keyboard layouts in MDM. */ - - found_node = - g_slist_find_custom (layouts, mdm_layout, - (GCompareFunc) g_strcmp0); - - if (!found_node) { - /* Insert at the last valid place, or at the end of - * list, whichever comes first */ - layouts = - g_slist_insert (layouts, g_strdup (mdm_layout), - max_groups - 1); - if (g_slist_length (layouts) > max_groups) { - GSList *last; - GSList *free_layouts; - - last = - g_slist_nth (layouts, max_groups - 1); - free_layouts = last->next; - last->next = NULL; - - g_slist_foreach (free_layouts, - (GFunc) g_free, NULL); - g_slist_free (free_layouts); - } - - mateconf_client_set_list (conf_client, - MATEKBD_KEYBOARD_CONFIG_KEY_LAYOUTS, - MATECONF_VALUE_STRING, layouts, - NULL); - } - - g_slist_foreach (layouts, (GFunc) g_free, NULL); - g_slist_free (layouts); - } - - matekbd_keyboard_config_init (¤t_sys_kbd_config, - conf_client, xkl_engine); - - matekbd_keyboard_config_load_from_mateconf (¤t_kbd_config, - &initial_sys_kbd_config); - - matekbd_keyboard_config_load_from_x_current (¤t_sys_kbd_config, - NULL); - - if (!try_activating_xkb_config_if_new (¤t_sys_kbd_config)) { - if (filter_xkb_config ()) { - if (!try_activating_xkb_config_if_new - (¤t_sys_kbd_config)) { - g_warning - ("Could not activate the filtered XKB configuration"); - activation_error (); - } - } else { - g_warning - ("Could not activate the XKB configuration"); - activation_error (); - } - } else - xkl_debug (100, - "Actual KBD configuration was not changed: redundant notification\n"); - - if (mdm_layout != NULL) { - /* If there are multiple layouts, - * try to find the one closest to the mdm layout - */ - GSList *l; - int i; - size_t len = strlen (mdm_layout); - for (i = 0, l = current_kbd_config.layouts_variants; l; - i++, l = l->next) { - char *lv = l->data; - if (strncmp (lv, mdm_layout, len) == 0 - && (lv[len] == '\0' || lv[len] == '\t')) { - group_to_activate = i; - break; - } - } - } - - g_free (mdm_layout); - - if (group_to_activate != -1) - xkl_engine_lock_group (current_config.engine, - group_to_activate); - matekbd_keyboard_config_term (¤t_sys_kbd_config); - show_hide_icon (); -} - -static void -msd_keyboard_xkb_analyze_sysconfig (void) -{ - MateConfClient *conf_client; - - if (!inited_ok) - return; - - conf_client = mateconf_client_get_default (); - matekbd_keyboard_config_init (&initial_sys_kbd_config, - conf_client, xkl_engine); - matekbd_keyboard_config_load_from_x_initial (&initial_sys_kbd_config, - NULL); - g_object_unref (conf_client); -} - -static gboolean -msd_chk_file_list (void) -{ - GDir *home_dir; - const char *fname; - GSList *file_list = NULL; - GSList *last_login_file_list = NULL; - GSList *tmp = NULL; - GSList *tmp_l = NULL; - gboolean new_file_exist = FALSE; - MateConfClient *conf_client; - - home_dir = g_dir_open (g_get_home_dir (), 0, NULL); - while ((fname = g_dir_read_name (home_dir)) != NULL) { - if (g_strrstr (fname, "modmap")) { - file_list = - g_slist_append (file_list, g_strdup (fname)); - } - } - g_dir_close (home_dir); - - conf_client = mateconf_client_get_default (); - - last_login_file_list = mateconf_client_get_list (conf_client, - KNOWN_FILES_KEY, - MATECONF_VALUE_STRING, - NULL); - - /* Compare between the two file list, currently available modmap files - and the files available in the last log in */ - tmp = file_list; - while (tmp != NULL) { - tmp_l = last_login_file_list; - new_file_exist = TRUE; - while (tmp_l != NULL) { - if (strcmp (tmp->data, tmp_l->data) == 0) { - new_file_exist = FALSE; - break; - } else { - tmp_l = tmp_l->next; - } - } - if (new_file_exist) { - break; - } else { - tmp = tmp->next; - } - } - - if (new_file_exist) { - mateconf_client_set_list (conf_client, - KNOWN_FILES_KEY, - MATECONF_VALUE_STRING, - file_list, NULL); - } - - g_object_unref (conf_client); - - g_slist_foreach (file_list, (GFunc) g_free, NULL); - g_slist_free (file_list); - - g_slist_foreach (last_login_file_list, (GFunc) g_free, NULL); - g_slist_free (last_login_file_list); - - return new_file_exist; - -} - -static void -msd_keyboard_xkb_chk_lcl_xmm (void) -{ - if (msd_chk_file_list ()) { - msd_modmap_dialog_call (); - } - msd_load_modmap_files (); -} - -void -msd_keyboard_xkb_set_post_activation_callback (PostActivationCallback fun, - void *user_data) -{ - pa_callback = fun; - pa_callback_user_data = user_data; -} - -static GdkFilterReturn -msd_keyboard_xkb_evt_filter (GdkXEvent * xev, GdkEvent * event) -{ - XEvent *xevent = (XEvent *) xev; - xkl_engine_filter_events (xkl_engine, xevent); - return GDK_FILTER_CONTINUE; -} - -static guint -register_config_callback (MateConfClient * client, - const char *path, MateConfClientNotifyFunc func) -{ - mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - return mateconf_client_notify_add (client, path, func, NULL, NULL, - NULL); -} - -/* When new Keyboard is plugged in - reload the settings */ -static void -msd_keyboard_new_device (XklEngine * engine) -{ - apply_desktop_settings (); - apply_xkb_settings (); -} - -static void -msd_keyboard_update_indicator_icons () -{ - Bool state; - int new_state, i; - Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); - XkbGetNamedIndicator (display, caps_lock, NULL, &state, - NULL, NULL); - new_state = state ? 1 : 0; - XkbGetNamedIndicator (display, num_lock, NULL, &state, NULL, NULL); - new_state <<= 1; - new_state |= (state ? 1 : 0); - XkbGetNamedIndicator (display, scroll_lock, NULL, &state, - NULL, NULL); - new_state <<= 1; - new_state |= (state ? 1 : 0); - xkl_debug (160, "Indicators state: %d\n", new_state); - - - for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); - --i >= 0;) { - gtk_status_icon_set_from_icon_name (indicator_icons[i], - (new_state & (1 << i)) - ? - indicator_on_icon_names - [i] : - indicator_off_icon_names - [i]); - } -} - -static void -msd_keyboard_state_changed (XklEngine * engine, XklEngineStateChange type, - gint new_group, gboolean restore) -{ - xkl_debug (160, - "State changed: type %d, new group: %d, restore: %d.\n", - type, new_group, restore); - if (type == INDICATORS_CHANGED) { - msd_keyboard_update_indicator_icons (); - } -} - -void -msd_keyboard_xkb_init (MateConfClient * client, - MsdKeyboardManager * kbd_manager) -{ - int i; - Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); - mate_settings_profile_start (NULL); - - gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), - DATADIR G_DIR_SEPARATOR_S - "icons"); - - caps_lock = XInternAtom (display, "Caps Lock", False); - num_lock = XInternAtom (display, "Num Lock", False); - scroll_lock = XInternAtom (display, "Scroll Lock", False); - - for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); - --i >= 0;) { - indicator_icons[i] = - gtk_status_icon_new_from_icon_name - (indicator_off_icon_names[i]); - } - - msd_keyboard_update_indicator_icons (); - -#ifdef MSDKX - xkl_set_debug_level (200); - logfile = fopen ("/tmp/msdkx.log", "a"); - xkl_set_log_appender (msd_keyboard_log_appender); -#endif - manager = kbd_manager; - mate_settings_profile_start ("xkl_engine_get_instance"); - xkl_engine = xkl_engine_get_instance (display); - mate_settings_profile_end ("xkl_engine_get_instance"); - if (xkl_engine) { - inited_ok = TRUE; - - mdm_keyboard_layout = g_getenv ("MDM_KEYBOARD_LAYOUT"); - - matekbd_desktop_config_init (¤t_config, - client, xkl_engine); - matekbd_keyboard_config_init (¤t_kbd_config, - client, xkl_engine); - xkl_engine_backup_names_prop (xkl_engine); - msd_keyboard_xkb_analyze_sysconfig (); - mate_settings_profile_start - ("msd_keyboard_xkb_chk_lcl_xmm"); - msd_keyboard_xkb_chk_lcl_xmm (); - mate_settings_profile_end - ("msd_keyboard_xkb_chk_lcl_xmm"); - - notify_desktop = - register_config_callback (client, - MATEKBD_DESKTOP_CONFIG_DIR, - (MateConfClientNotifyFunc) - apply_desktop_settings); - - notify_keyboard = - register_config_callback (client, - MATEKBD_KEYBOARD_CONFIG_DIR, - (MateConfClientNotifyFunc) - apply_xkb_settings); - - gdk_window_add_filter (NULL, (GdkFilterFunc) - msd_keyboard_xkb_evt_filter, NULL); - - if (xkl_engine_get_features (xkl_engine) & - XKLF_DEVICE_DISCOVERY) - g_signal_connect (xkl_engine, "X-new-device", - G_CALLBACK - (msd_keyboard_new_device), NULL); - g_signal_connect (xkl_engine, "X-state-changed", - G_CALLBACK - (msd_keyboard_state_changed), NULL); - - mate_settings_profile_start ("xkl_engine_start_listen"); - xkl_engine_start_listen (xkl_engine, - XKLL_MANAGE_LAYOUTS | - XKLL_MANAGE_WINDOW_STATES); - mate_settings_profile_end ("xkl_engine_start_listen"); - - mate_settings_profile_start ("apply_desktop_settings"); - apply_desktop_settings (); - mate_settings_profile_end ("apply_desktop_settings"); - mate_settings_profile_start ("apply_xkb_settings"); - apply_xkb_settings (); - mate_settings_profile_end ("apply_xkb_settings"); - } - preview_dialogs = g_hash_table_new (g_direct_hash, g_direct_equal); - - mate_settings_profile_end (NULL); -} - -void -msd_keyboard_xkb_shutdown (void) -{ - MateConfClient *client; - int i; - - pa_callback = NULL; - pa_callback_user_data = NULL; - manager = NULL; - - for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); - --i >= 0;) { - g_object_unref (G_OBJECT (indicator_icons[i])); - indicator_icons[i] = NULL; - } - - g_hash_table_destroy (preview_dialogs); - - if (!inited_ok) - return; - - xkl_engine_stop_listen (xkl_engine, - XKLL_MANAGE_LAYOUTS | - XKLL_MANAGE_WINDOW_STATES); - - gdk_window_remove_filter (NULL, (GdkFilterFunc) - msd_keyboard_xkb_evt_filter, NULL); - - client = mateconf_client_get_default (); - - if (notify_desktop != 0) { - mateconf_client_remove_dir (client, MATEKBD_DESKTOP_CONFIG_DIR, - NULL); - mateconf_client_notify_remove (client, notify_desktop); - notify_desktop = 0; - } - - if (notify_keyboard != 0) { - mateconf_client_remove_dir (client, MATEKBD_KEYBOARD_CONFIG_DIR, - NULL); - mateconf_client_notify_remove (client, notify_keyboard); - notify_keyboard = 0; - } - - if (xkl_registry) { - g_object_unref (xkl_registry); - } - - g_object_unref (client); - g_object_unref (xkl_engine); - - xkl_engine = NULL; - inited_ok = FALSE; -} diff --git a/plugins/keyboard/gsd-keyboard-xkb.h b/plugins/keyboard/gsd-keyboard-xkb.h deleted file mode 100644 index 7d2d558..0000000 --- a/plugins/keyboard/gsd-keyboard-xkb.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * mate-settings-keyboard-xkb.h - * - * Copyright (C) 2001 Udaltsoft - * - * Written by Sergey V. Oudaltsov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef __MSD_KEYBOARD_XKB_H -#define __MSD_KEYBOARD_XKB_H - -#include -#include - -#include -#include "msd-keyboard-manager.h" - -void msd_keyboard_xkb_init(MateConfClient* client, MsdKeyboardManager* manager); -void msd_keyboard_xkb_shutdown(void); - -typedef void (*PostActivationCallback) (void* userData); - -void msd_keyboard_xkb_set_post_activation_callback(PostActivationCallback fun, void* userData); - -#endif diff --git a/plugins/keyboard/gsd-xmodmap.c b/plugins/keyboard/gsd-xmodmap.c deleted file mode 100644 index 5baf37c..0000000 --- a/plugins/keyboard/gsd-xmodmap.c +++ /dev/null @@ -1,399 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright © 2005 Novell Inc. - * - * Written by Shakti Sen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include "config.h" - -#include - -#include -#include -#include - -#include "msd-xmodmap.h" - -static const char DISABLE_XMM_WARNING_KEY[] = - "/desktop/mate/peripherals/keyboard/disable_xmm_and_xkb_warning"; - -static const char LOADED_FILES_KEY[] = - "/desktop/mate/peripherals/keyboard/general/update_handlers"; - - -static void -check_button_callback (GtkWidget *chk_button, - gpointer data) -{ - MateConfClient *client; - - client = mateconf_client_get_default (); - - mateconf_client_set_bool (client, - DISABLE_XMM_WARNING_KEY, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chk_button)), - NULL); - - g_object_unref (client); -} - -void -msd_load_modmap_files (void) -{ - MateConfClient *client; - GSList *tmp; - GSList *loaded_file_list; - - client = mateconf_client_get_default (); - - loaded_file_list = mateconf_client_get_list (client, LOADED_FILES_KEY, MATECONF_VALUE_STRING, NULL); - - for (tmp = loaded_file_list; tmp != NULL; tmp = tmp->next) { - gchar *file; - gchar *command; - - file = g_build_filename (g_get_home_dir (), (gchar *) tmp->data, NULL); - command = g_strconcat ("xmodmap ", file, NULL); - g_free (file); - - g_spawn_command_line_async (command, NULL); - - g_free (command); - g_free (tmp->data); - } - - g_slist_free (loaded_file_list); - g_object_unref (client); -} - -static void -response_callback (GtkWidget *dialog, - int id, - void *data) -{ - if (id == GTK_RESPONSE_OK) { - GtkWidget *chk_button = g_object_get_data (G_OBJECT (dialog), "check_button"); - check_button_callback (chk_button, NULL); - msd_load_modmap_files (); - } - gtk_widget_destroy (dialog); -} - -static void -get_selected_files_func (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - GSList **list = data; - gchar *filename; - - filename = NULL; - gtk_tree_model_get (model, - iter, - 0, - &filename, - -1); - - *list = g_slist_prepend (*list, filename); -} - -static GSList* -remove_string_from_list (GSList *list, - const char *str) -{ - GSList *tmp; - - for (tmp = list; tmp != NULL; tmp = tmp->next) { - if (strcmp (tmp->data, str) == 0) { - g_free (tmp->data); - list = g_slist_delete_link (list, tmp); - break; - } - } - - return list; -} - - -static void -remove_button_clicked_callback (GtkWidget *button, - void *data) -{ - GtkWidget *dialog; - GtkListStore *tree = NULL; - GtkTreeSelection *selection; - GtkWidget *treeview; - MateConfClient *client; - GSList *filenames = NULL; - GSList *tmp = NULL; - GSList *loaded_files = NULL; - - dialog = data; - - treeview = g_object_get_data (G_OBJECT (dialog), "treeview1"); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_selected_foreach (selection, - get_selected_files_func, - &filenames); - - if (!filenames) - return; - - /* Remove the selected file */ - - client = mateconf_client_get_default (); - - loaded_files = mateconf_client_get_list (client, - LOADED_FILES_KEY, - MATECONF_VALUE_STRING, - NULL); - loaded_files = remove_string_from_list (loaded_files, (char *)filenames->data); - - mateconf_client_set_list (client, - LOADED_FILES_KEY, - MATECONF_VALUE_STRING, - loaded_files, - NULL); - g_object_unref (client); - - tree = g_object_get_data (G_OBJECT (dialog), "tree"); - - gtk_list_store_clear (tree); - for (tmp = loaded_files; tmp != NULL; tmp = tmp->next) { - GtkTreeIter iter; - gtk_list_store_append (tree, &iter); - gtk_list_store_set (tree, &iter, - 0, - tmp->data, - -1); - } - - g_slist_foreach (loaded_files, (GFunc) g_free, NULL); - g_slist_free (loaded_files); -} - -static void -load_button_clicked_callback (GtkWidget *button, - void *data) -{ - GtkWidget *dialog; - GtkListStore *tree = NULL; - GtkTreeSelection *selection; - GtkWidget *treeview; - GSList *filenames = NULL; - GSList *tmp = NULL; - GSList *loaded_files = NULL; - MateConfClient *client; - - dialog = data; - - treeview = g_object_get_data (G_OBJECT (dialog), - "loaded-treeview"); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_selected_foreach (selection, - get_selected_files_func, - &filenames); - - if (!filenames) - return; - - /* Add the files to left-tree-view */ - client = mateconf_client_get_default (); - - loaded_files = mateconf_client_get_list (client, - LOADED_FILES_KEY, - MATECONF_VALUE_STRING, - NULL); - - if (g_slist_find_custom (loaded_files, filenames->data, (GCompareFunc) strcmp)) { - g_free (filenames->data); - g_slist_free (filenames); - goto out; - } - - loaded_files = g_slist_append (loaded_files, filenames->data); - mateconf_client_set_list (client, - LOADED_FILES_KEY, - MATECONF_VALUE_STRING, - loaded_files, - NULL); - - - tree = g_object_get_data (G_OBJECT (dialog), "tree"); - - gtk_list_store_clear (tree); - for (tmp = loaded_files; tmp != NULL; tmp = tmp->next) { - GtkTreeIter iter; - gtk_list_store_append (tree, &iter); - gtk_list_store_set (tree, &iter, - 0, - tmp->data, - -1); - } - -out: - g_object_unref (client); - g_slist_foreach (loaded_files, (GFunc) g_free, NULL); - g_slist_free (loaded_files); -} - -void -msd_modmap_dialog_call (void) -{ - GtkBuilder *builder; - guint res; - GError *error; - GtkWidget *load_dialog; - GtkListStore *tree; - GtkCellRenderer *cell_renderer; - GtkTreeIter parent_iter; - GtkTreeIter iter; - GtkTreeModel *sort_model; - GtkTreeSelection *selection; - GtkWidget *treeview; - GtkWidget *treeview1; - GtkTreeViewColumn *column; - GtkWidget *add_button; - GtkWidget *remove_button; - GtkWidget *chk_button; - GSList *tmp; - GDir *homeDir; - GSList *loaded_files; - const char *fname; - MateConfClient *client; - - homeDir = g_dir_open (g_get_home_dir (), 0, NULL); - if (homeDir == NULL) - return; - - error = NULL; - builder = gtk_builder_new (); - res = gtk_builder_add_from_file (builder, - DATADIR "/modmap-dialog.ui", - &error); - - if (res == 0) { - g_warning ("Could not load UI file: %s", error->message); - g_error_free (error); - g_object_unref (builder); - g_dir_close (homeDir); - return; - } - - load_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dialog1")); - gtk_window_set_modal (GTK_WINDOW (load_dialog), TRUE); - g_signal_connect (load_dialog, - "response", - G_CALLBACK (response_callback), - builder); - add_button = GTK_WIDGET (gtk_builder_get_object (builder, "button7")); - g_signal_connect (add_button, - "clicked", - G_CALLBACK (load_button_clicked_callback), - load_dialog); - remove_button = GTK_WIDGET (gtk_builder_get_object (builder, - "button6")); - g_signal_connect (remove_button, - "clicked", - G_CALLBACK (remove_button_clicked_callback), - load_dialog); - chk_button = GTK_WIDGET (gtk_builder_get_object (builder, - "checkbutton1")); - g_signal_connect (chk_button, - "toggled", - G_CALLBACK (check_button_callback), - NULL); - g_object_set_data (G_OBJECT (load_dialog), "check_button", chk_button); - treeview = GTK_WIDGET (gtk_builder_get_object (builder, "treeview1")); - g_object_set_data (G_OBJECT (load_dialog), "treeview1", treeview); - treeview = GTK_WIDGET (gtk_builder_get_object (builder, "treeview2")); - g_object_set_data (G_OBJECT (load_dialog), "loaded-treeview", treeview); - tree = gtk_list_store_new (1, G_TYPE_STRING); - cell_renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("modmap", - cell_renderer, - "text", 0, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); - gtk_tree_view_column_set_sort_column_id (column, 0); - - /* Add the data */ - while ((fname = g_dir_read_name (homeDir)) != NULL) { - if (g_strrstr (fname, "modmap")) { - gtk_list_store_append (tree, &parent_iter); - gtk_list_store_set (tree, &parent_iter, - 0, - fname, - -1); - } - } - sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), - 0, - GTK_SORT_ASCENDING); - gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), sort_model); - g_object_unref (G_OBJECT (tree)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), - GTK_SELECTION_MULTIPLE); - gtk_widget_show (load_dialog); - - g_dir_close (homeDir); - - /* Left treeview */ - treeview1 = GTK_WIDGET (gtk_builder_get_object (builder, "treeview1")); - tree = gtk_list_store_new (1, G_TYPE_STRING); - cell_renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("modmap", - cell_renderer, - "text", 0, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (treeview1), column); - gtk_tree_view_column_set_sort_column_id (column, 0); - - client = mateconf_client_get_default (); - loaded_files = mateconf_client_get_list (client, LOADED_FILES_KEY, MATECONF_VALUE_STRING, NULL); - g_object_unref (client); - - /* Add the data */ - for (tmp = loaded_files; tmp != NULL; tmp = tmp->next) { - gtk_list_store_append (tree, &iter); - gtk_list_store_set (tree, &iter, - 0, - tmp->data, - -1); - } - - g_slist_foreach (loaded_files, (GFunc) g_free, NULL); - g_slist_free (loaded_files); - - sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), - 0, - GTK_SORT_ASCENDING); - gtk_tree_view_set_model (GTK_TREE_VIEW (treeview1), sort_model); - g_object_unref (G_OBJECT (tree)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview1)); - gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), - GTK_SELECTION_MULTIPLE); - g_object_set_data (G_OBJECT (load_dialog), "tree", tree); - g_object_unref (builder); -} diff --git a/plugins/keyboard/gsd-xmodmap.h b/plugins/keyboard/gsd-xmodmap.h deleted file mode 100644 index 04b4505..0000000 --- a/plugins/keyboard/gsd-xmodmap.h +++ /dev/null @@ -1,29 +0,0 @@ -/* mate-settings-xmodmap.h - * - * Copyright © 2005 Novell Inc. - * - * Written by Shakti Sen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef XMODMAP_H -#define XMODMAP_H - -void msd_load_modmap_files (void); -void msd_modmap_dialog_call (void); - -#endif diff --git a/plugins/keyboard/msd-keyboard-manager.c b/plugins/keyboard/msd-keyboard-manager.c new file mode 100644 index 0000000..0969459 --- /dev/null +++ b/plugins/keyboard/msd-keyboard-manager.c @@ -0,0 +1,569 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright © 2001 Ximian, Inc. + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H + #include +#endif + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + #include + #include +#endif + +#include "mate-settings-profile.h" +#include "msd-keyboard-manager.h" + +#include "msd-keyboard-xkb.h" +#include "msd-xmodmap.h" + +#define MSD_KEYBOARD_MANAGER_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerPrivate)) + +#ifndef HOST_NAME_MAX + #define HOST_NAME_MAX 255 +#endif + +#define MSD_KEYBOARD_KEY "/desktop/mate/peripherals/keyboard" + +#define KEY_REPEAT MSD_KEYBOARD_KEY "/repeat" +#define KEY_CLICK MSD_KEYBOARD_KEY "/click" +#define KEY_RATE MSD_KEYBOARD_KEY "/rate" +#define KEY_DELAY MSD_KEYBOARD_KEY "/delay" +#define KEY_CLICK_VOLUME MSD_KEYBOARD_KEY "/click_volume" + +#define KEY_BELL_VOLUME MSD_KEYBOARD_KEY "/bell_volume" +#define KEY_BELL_PITCH MSD_KEYBOARD_KEY "/bell_pitch" +#define KEY_BELL_DURATION MSD_KEYBOARD_KEY "/bell_duration" +#define KEY_BELL_MODE MSD_KEYBOARD_KEY "/bell_mode" + +struct MsdKeyboardManagerPrivate { + gboolean have_xkb; + gint xkb_event_base; + guint notify; +}; + +static void msd_keyboard_manager_class_init (MsdKeyboardManagerClass* klass); +static void msd_keyboard_manager_init (MsdKeyboardManager* keyboard_manager); +static void msd_keyboard_manager_finalize (GObject* object); + +G_DEFINE_TYPE (MsdKeyboardManager, msd_keyboard_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + + +#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H +static gboolean xfree86_set_keyboard_autorepeat_rate(int delay, int rate) +{ + gboolean res = FALSE; + int event_base_return; + int error_base_return; + + if (XF86MiscQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + &event_base_return, + &error_base_return) == True) { + /* load the current settings */ + XF86MiscKbdSettings kbdsettings; + XF86MiscGetKbdSettings (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &kbdsettings); + + /* assign the new values */ + kbdsettings.delay = delay; + kbdsettings.rate = rate; + XF86MiscSetKbdSettings (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &kbdsettings); + res = TRUE; + } + + return res; +} +#endif /* HAVE_X11_EXTENSIONS_XF86MISC_H */ + +#ifdef HAVE_X11_EXTENSIONS_XKB_H +static gboolean xkb_set_keyboard_autorepeat_rate(int delay, int rate) +{ + int interval = (rate <= 0) ? 1000000 : 1000/rate; + + if (delay <= 0) + { + delay = 1; + } + + return XkbSetAutoRepeatRate(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XkbUseCoreKbd, delay, interval); +} +#endif + +static char* msd_keyboard_get_hostname_key (const char *subkey) +{ + char hostname[HOST_NAME_MAX + 1]; + + if (gethostname (hostname, sizeof (hostname)) == 0 && + strcmp (hostname, "localhost") != 0 && + strcmp (hostname, "localhost.localdomain") != 0) { + char *escaped; + char *key; + + escaped = mateconf_escape_key (hostname, -1); + key = g_strconcat (MSD_KEYBOARD_KEY + "/host-", + escaped, + "/0/", + subkey, + NULL); + g_free (escaped); + return key; + } else + return NULL; +} + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + +typedef enum { + NUMLOCK_STATE_OFF = 0, + NUMLOCK_STATE_ON = 1, + NUMLOCK_STATE_UNKNOWN = 2 +} NumLockState; + +static void +numlock_xkb_init (MsdKeyboardManager *manager) +{ + Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + gboolean have_xkb; + int opcode, error_base, major, minor; + + have_xkb = XkbQueryExtension (dpy, + &opcode, + &manager->priv->xkb_event_base, + &error_base, + &major, + &minor) + && XkbUseExtension (dpy, &major, &minor); + + if (have_xkb) { + XkbSelectEventDetails (dpy, + XkbUseCoreKbd, + XkbStateNotifyMask, + XkbModifierLockMask, + XkbModifierLockMask); + } else { + g_warning ("XKB extension not available"); + } + + manager->priv->have_xkb = have_xkb; +} + +static unsigned +numlock_NumLock_modifier_mask (void) +{ + Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + return XkbKeysymToModifiers (dpy, XK_Num_Lock); +} + +static void +numlock_set_xkb_state (NumLockState new_state) +{ + unsigned int num_mask; + Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + if (new_state != NUMLOCK_STATE_ON && new_state != NUMLOCK_STATE_OFF) + return; + num_mask = numlock_NumLock_modifier_mask (); + XkbLockModifiers (dpy, XkbUseCoreKbd, num_mask, new_state ? num_mask : 0); +} + +static char * +numlock_mateconf_state_key (void) +{ + char *key = msd_keyboard_get_hostname_key ("numlock_on"); + if (!key) { + g_message ("NumLock remembering disabled because hostname is set to \"localhost\""); + } + return key; +} + +static NumLockState +numlock_get_mateconf_state (MateConfClient *client) +{ + int curr_state; + GError *err = NULL; + char *key = numlock_mateconf_state_key (); + + if (!key) { + return NUMLOCK_STATE_UNKNOWN; + } + + curr_state = mateconf_client_get_bool (client, key, &err); + if (err) { + curr_state = NUMLOCK_STATE_UNKNOWN; + g_error_free (err); + } + + g_free (key); + return curr_state; +} + +static void numlock_set_mateconf_state(MateConfClient *client, NumLockState new_state) +{ + //printf("numlock_set_mateconf_state\n"); + char* key; + + if (new_state != NUMLOCK_STATE_ON && new_state != NUMLOCK_STATE_OFF) { + return; + } + + key = numlock_mateconf_state_key (); + + if (key) { + mateconf_client_set_bool (client, key, new_state, NULL); + g_free (key); + } +} + +static GdkFilterReturn +numlock_xkb_callback (GdkXEvent *xev_, + GdkEvent *gdkev_, + gpointer xkb_event_code) +{ + XEvent *xev = (XEvent *) xev_; + + if (xev->type == GPOINTER_TO_INT (xkb_event_code)) { + XkbEvent *xkbev = (XkbEvent *)xev; + if (xkbev->any.xkb_type == XkbStateNotify) + if (xkbev->state.changed & XkbModifierLockMask) { + unsigned num_mask = numlock_NumLock_modifier_mask (); + unsigned locked_mods = xkbev->state.locked_mods; + int numlock_state = !! (num_mask & locked_mods); + MateConfClient *client = mateconf_client_get_default (); + numlock_set_mateconf_state (client, numlock_state); + g_object_unref (client); + } + } + return GDK_FILTER_CONTINUE; +} + +static void +numlock_install_xkb_callback (MsdKeyboardManager *manager) +{ + if (!manager->priv->have_xkb) + return; + + gdk_window_add_filter (NULL, + numlock_xkb_callback, + GINT_TO_POINTER (manager->priv->xkb_event_base)); +} + +#endif /* HAVE_X11_EXTENSIONS_XKB_H */ + +static void +apply_settings (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdKeyboardManager *manager) +{ + XKeyboardControl kbdcontrol; + gboolean repeat; + gboolean click; + int rate; + int delay; + int click_volume; + int bell_volume; + int bell_pitch; + int bell_duration; + char *volume_string; +#ifdef HAVE_X11_EXTENSIONS_XKB_H + gboolean rnumlock; +#endif /* HAVE_X11_EXTENSIONS_XKB_H */ + + repeat = mateconf_client_get_bool (client, KEY_REPEAT, NULL); + click = mateconf_client_get_bool (client, KEY_CLICK, NULL); + rate = mateconf_client_get_int (client, KEY_RATE, NULL); + delay = mateconf_client_get_int (client, KEY_DELAY, NULL); + click_volume = mateconf_client_get_int (client, KEY_CLICK_VOLUME, NULL); +#if 0 + bell_volume = mateconf_client_get_int (client, KEY_BELL_VOLUME, NULL); +#endif + bell_pitch = mateconf_client_get_int (client, KEY_BELL_PITCH, NULL); + bell_duration = mateconf_client_get_int (client, KEY_BELL_DURATION, NULL); + + volume_string = mateconf_client_get_string (client, KEY_BELL_MODE, NULL); + bell_volume = (volume_string && !strcmp (volume_string, "on")) ? 50 : 0; + g_free (volume_string); + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + rnumlock = mateconf_client_get_bool (client, MSD_KEYBOARD_KEY "/remember_numlock_state", NULL); +#endif /* HAVE_X11_EXTENSIONS_XKB_H */ + + gdk_error_trap_push (); + if (repeat) { + gboolean rate_set = FALSE; + + XAutoRepeatOn (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); + /* Use XKB in preference */ +#ifdef HAVE_X11_EXTENSIONS_XKB_H + rate_set = xkb_set_keyboard_autorepeat_rate (delay, rate); +#endif +#ifdef HAVE_X11_EXTENSIONS_XF86MISC_H + if (!rate_set) + rate_set = xfree86_set_keyboard_autorepeat_rate (delay, rate); +#endif + if (!rate_set) + g_warning ("Neither XKeyboard not Xfree86's keyboard extensions are available,\n" + "no way to support keyboard autorepeat rate settings"); + } else { + XAutoRepeatOff (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); + } + + /* as percentage from 0..100 inclusive */ + if (click_volume < 0) { + click_volume = 0; + } else if (click_volume > 100) { + click_volume = 100; + } + kbdcontrol.key_click_percent = click ? click_volume : 0; + kbdcontrol.bell_percent = bell_volume; + kbdcontrol.bell_pitch = bell_pitch; + kbdcontrol.bell_duration = bell_duration; + XChangeKeyboardControl (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration, + &kbdcontrol); + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + if (manager->priv->have_xkb && rnumlock) { + numlock_set_xkb_state (numlock_get_mateconf_state (client)); + } +#endif /* HAVE_X11_EXTENSIONS_XKB_H */ + + XSync (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), FALSE); + gdk_error_trap_pop (); +} + +void +msd_keyboard_manager_apply_settings (MsdKeyboardManager *manager) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + apply_settings (client, 0, NULL, manager); + g_object_unref (client); +} + +static gboolean +start_keyboard_idle_cb (MsdKeyboardManager *manager) +{ + MateConfClient *client; + + mate_settings_profile_start (NULL); + + g_debug ("Starting keyboard manager"); + + manager->priv->have_xkb = 0; + client = mateconf_client_get_default (); + + mateconf_client_add_dir (client, MSD_KEYBOARD_KEY, MATECONF_CLIENT_PRELOAD_RECURSIVE, NULL); + + /* Essential - xkb initialization should happen before */ + msd_keyboard_xkb_set_post_activation_callback ((PostActivationCallback) msd_load_modmap_files, NULL); + msd_keyboard_xkb_init (client, manager); + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + numlock_xkb_init (manager); +#endif /* HAVE_X11_EXTENSIONS_XKB_H */ + + /* apply current settings before we install the callback */ + msd_keyboard_manager_apply_settings (manager); + + manager->priv->notify = mateconf_client_notify_add (client, MSD_KEYBOARD_KEY, + (MateConfClientNotifyFunc) apply_settings, manager, + NULL, NULL); + + g_object_unref (client); + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + numlock_install_xkb_callback (manager); +#endif /* HAVE_X11_EXTENSIONS_XKB_H */ + + mate_settings_profile_end (NULL); + + return FALSE; +} + +gboolean +msd_keyboard_manager_start (MsdKeyboardManager *manager, + GError **error) +{ + mate_settings_profile_start (NULL); + + g_idle_add ((GSourceFunc) start_keyboard_idle_cb, manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_keyboard_manager_stop (MsdKeyboardManager *manager) +{ + MsdKeyboardManagerPrivate *p = manager->priv; + + g_debug ("Stopping keyboard manager"); + + if (p->notify != 0) { + MateConfClient *client = mateconf_client_get_default (); + mateconf_client_remove_dir (client, MSD_KEYBOARD_KEY, NULL); + mateconf_client_notify_remove (client, p->notify); + g_object_unref (client); + p->notify = 0; + } + +#if HAVE_X11_EXTENSIONS_XKB_H + if (p->have_xkb) { + gdk_window_remove_filter (NULL, + numlock_xkb_callback, + GINT_TO_POINTER (p->xkb_event_base)); + } +#endif /* HAVE_X11_EXTENSIONS_XKB_H */ + + msd_keyboard_xkb_shutdown (); +} + +static void +msd_keyboard_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdKeyboardManager *self; + + self = MSD_KEYBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_keyboard_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdKeyboardManager *self; + + self = MSD_KEYBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_keyboard_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdKeyboardManager *keyboard_manager; + MsdKeyboardManagerClass *klass; + + klass = MSD_KEYBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_KEYBOARD_MANAGER)); + + keyboard_manager = MSD_KEYBOARD_MANAGER (G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (keyboard_manager); +} + +static void +msd_keyboard_manager_dispose (GObject *object) +{ + MsdKeyboardManager *keyboard_manager; + + keyboard_manager = MSD_KEYBOARD_MANAGER (object); + + G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->dispose (object); +} + +static void +msd_keyboard_manager_class_init (MsdKeyboardManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_keyboard_manager_get_property; + object_class->set_property = msd_keyboard_manager_set_property; + object_class->constructor = msd_keyboard_manager_constructor; + object_class->dispose = msd_keyboard_manager_dispose; + object_class->finalize = msd_keyboard_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdKeyboardManagerPrivate)); +} + +static void +msd_keyboard_manager_init (MsdKeyboardManager *manager) +{ + manager->priv = MSD_KEYBOARD_MANAGER_GET_PRIVATE (manager); +} + +static void +msd_keyboard_manager_finalize (GObject *object) +{ + MsdKeyboardManager *keyboard_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_KEYBOARD_MANAGER (object)); + + keyboard_manager = MSD_KEYBOARD_MANAGER (object); + + g_return_if_fail (keyboard_manager->priv != NULL); + + G_OBJECT_CLASS (msd_keyboard_manager_parent_class)->finalize (object); +} + +MsdKeyboardManager * +msd_keyboard_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_KEYBOARD_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_KEYBOARD_MANAGER (manager_object); +} diff --git a/plugins/keyboard/msd-keyboard-manager.h b/plugins/keyboard/msd-keyboard-manager.h new file mode 100644 index 0000000..aa3ae95 --- /dev/null +++ b/plugins/keyboard/msd-keyboard-manager.h @@ -0,0 +1,62 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_KEYBOARD_MANAGER_H +#define __MSD_KEYBOARD_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_KEYBOARD_MANAGER (msd_keyboard_manager_get_type ()) +#define MSD_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManager)) +#define MSD_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerClass)) +#define MSD_IS_KEYBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBOARD_MANAGER)) +#define MSD_IS_KEYBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBOARD_MANAGER)) +#define MSD_KEYBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBOARD_MANAGER, MsdKeyboardManagerClass)) + +typedef struct MsdKeyboardManagerPrivate MsdKeyboardManagerPrivate; + +typedef struct +{ + GObject parent; + MsdKeyboardManagerPrivate *priv; +} MsdKeyboardManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdKeyboardManagerClass; + +GType msd_keyboard_manager_get_type (void); + +MsdKeyboardManager * msd_keyboard_manager_new (void); +gboolean msd_keyboard_manager_start (MsdKeyboardManager *manager, + GError **error); +void msd_keyboard_manager_stop (MsdKeyboardManager *manager); +void msd_keyboard_manager_apply_settings (MsdKeyboardManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_KEYBOARD_MANAGER_H */ diff --git a/plugins/keyboard/msd-keyboard-plugin.c b/plugins/keyboard/msd-keyboard-plugin.c new file mode 100644 index 0000000..5f89ca2 --- /dev/null +++ b/plugins/keyboard/msd-keyboard-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-keyboard-plugin.h" +#include "msd-keyboard-manager.h" + +struct MsdKeyboardPluginPrivate { + MsdKeyboardManager *manager; +}; + +#define MSD_KEYBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdKeyboardPlugin, msd_keyboard_plugin) + +static void +msd_keyboard_plugin_init (MsdKeyboardPlugin *plugin) +{ + plugin->priv = MSD_KEYBOARD_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdKeyboardPlugin initializing"); + + plugin->priv->manager = msd_keyboard_manager_new (); +} + +static void +msd_keyboard_plugin_finalize (GObject *object) +{ + MsdKeyboardPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_KEYBOARD_PLUGIN (object)); + + g_debug ("MsdKeyboardPlugin finalizing"); + + plugin = MSD_KEYBOARD_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_keyboard_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating keyboard plugin"); + + error = NULL; + res = msd_keyboard_manager_start (MSD_KEYBOARD_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start keyboard manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating keyboard plugin"); + msd_keyboard_manager_stop (MSD_KEYBOARD_PLUGIN (plugin)->priv->manager); +} + +static void +msd_keyboard_plugin_class_init (MsdKeyboardPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_keyboard_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdKeyboardPluginPrivate)); +} diff --git a/plugins/keyboard/msd-keyboard-plugin.h b/plugins/keyboard/msd-keyboard-plugin.h new file mode 100644 index 0000000..84f2420 --- /dev/null +++ b/plugins/keyboard/msd-keyboard-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_KEYBOARD_PLUGIN_H__ +#define __MSD_KEYBOARD_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_KEYBOARD_PLUGIN (msd_keyboard_plugin_get_type ()) +#define MSD_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPlugin)) +#define MSD_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginClass)) +#define MSD_IS_KEYBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_KEYBOARD_PLUGIN)) +#define MSD_IS_KEYBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_KEYBOARD_PLUGIN)) +#define MSD_KEYBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_KEYBOARD_PLUGIN, MsdKeyboardPluginClass)) + +typedef struct MsdKeyboardPluginPrivate MsdKeyboardPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdKeyboardPluginPrivate *priv; +} MsdKeyboardPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdKeyboardPluginClass; + +GType msd_keyboard_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_KEYBOARD_PLUGIN_H__ */ diff --git a/plugins/keyboard/msd-keyboard-xkb.c b/plugins/keyboard/msd-keyboard-xkb.c new file mode 100644 index 0000000..9042f03 --- /dev/null +++ b/plugins/keyboard/msd-keyboard-xkb.c @@ -0,0 +1,918 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2001 Udaltsoft + * + * Written by Sergey V. Oudaltsov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include "config.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "msd-xmodmap.h" +#include "msd-keyboard-xkb.h" +#include "delayed-dialog.h" +#include "mate-settings-profile.h" + +#define GTK_RESPONSE_PRINT 2 + +static MsdKeyboardManager* manager = NULL; + +static XklEngine* xkl_engine; +static XklConfigRegistry* xkl_registry = NULL; + +static MatekbdDesktopConfig current_config; +static MatekbdKeyboardConfig current_kbd_config; + +/* never terminated */ +static MatekbdKeyboardConfig initial_sys_kbd_config; + +static gboolean inited_ok = FALSE; + +static guint notify_desktop = 0; +static guint notify_keyboard = 0; + +static PostActivationCallback pa_callback = NULL; +static void *pa_callback_user_data = NULL; + +static const char KNOWN_FILES_KEY[] = "/desktop/mate/peripherals/keyboard/general/known_file_list"; + +static const char DISABLE_INDICATOR_KEY[] = "/desktop/mate/peripherals/keyboard/general/disable_indicator"; + +static const char DUPLICATE_LEDS_KEY[] = "/desktop/mate/peripherals/keyboard/general/duplicate_leds"; + +static const char* mdm_keyboard_layout = NULL; + +static GtkStatusIcon* icon = NULL; + +static GHashTable* preview_dialogs = NULL; + +static Atom caps_lock; +static Atom num_lock; +static Atom scroll_lock; + +static GtkStatusIcon* indicator_icons[3]; +static const gchar* indicator_on_icon_names[] = { + "kbd-scrolllock-on", + "kbd-numlock-on", + "kbd-capslock-on" +}; + +static const gchar* indicator_off_icon_names[] = { + "kbd-scrolllock-off", + "kbd-numlock-off", + "kbd-capslock-off" +}; + +//#define noMSDKX + +#ifdef MSDKX +static FILE *logfile; + +static void msd_keyboard_log_appender(const char file[], const char function[], int level, const char format[], va_list args) +{ + time_t now = time (NULL); + fprintf (logfile, "[%08ld,%03d,%s:%s/] \t", now, + level, file, function); + vfprintf (logfile, format, args); + fflush (logfile); +} +#endif + +static void +activation_error (void) +{ + char const *vendor = ServerVendor (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); + int release = VendorRelease (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); + GtkWidget *dialog; + gboolean badXFree430Release; + + badXFree430Release = (vendor != NULL) + && (0 == strcmp (vendor, "The XFree86 Project, Inc")) + && (release / 100000 == 403); + + /* VNC viewers will not work, do not barrage them with warnings */ + if (NULL != vendor && NULL != strstr (vendor, "VNC")) + return; + + dialog = gtk_message_dialog_new_with_markup (NULL, + 0, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _ + ("Error activating XKB configuration.\n" + "It can happen under various circumstances:\n" + " • a bug in libxklavier library\n" + " • a bug in X server (xkbcomp, xmodmap utilities)\n" + " • X server with incompatible libxkbfile implementation\n\n" + "X server version data:\n%s\n%d\n%s\n" + "If you report this situation as a bug, please include:\n" + " • The result of %s\n" + " • The result of %s"), + vendor, + release, + badXFree430Release + ? + _ + ("You are using XFree 4.3.0.\n" + "There are known problems with complex XKB configurations.\n" + "Try using a simpler configuration or using a later version of the XFree software.") + : "", + "xprop -root | grep XKB", + "mateconftool-2 -R /desktop/mate/peripherals/keyboard/kbd"); + g_signal_connect (dialog, "response", + G_CALLBACK (gtk_widget_destroy), NULL); + msd_delayed_show_dialog (dialog); +} + +static void +apply_desktop_settings (void) +{ + MateConfClient *conf_client; + gboolean show_leds; + int i; + if (!inited_ok) + return; + + msd_keyboard_manager_apply_settings (manager); + matekbd_desktop_config_load_from_mateconf (¤t_config); + /* again, probably it would be nice to compare things + before activating them */ + matekbd_desktop_config_activate (¤t_config); + + conf_client = mateconf_client_get_default (); + show_leds = + mateconf_client_get_bool (conf_client, DUPLICATE_LEDS_KEY, NULL); + g_object_unref (conf_client); + for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); + --i >= 0;) { + gtk_status_icon_set_visible (indicator_icons[i], + show_leds); + } +} + +static void +popup_menu_launch_capplet () +{ + GError *error = NULL; + + gdk_spawn_command_line_on_screen (gdk_screen_get_default (), + "mate-keyboard-properties", + &error); + + if (error != NULL) { + g_warning + ("Could not execute keyboard properties capplet: [%s]\n", + error->message); + g_error_free (error); + } +} + +static void +show_layout_destroy (GtkWidget * dialog, gint group) +{ + g_hash_table_remove (preview_dialogs, GINT_TO_POINTER (group)); +} + +static void +popup_menu_show_layout () +{ + GtkWidget *dialog; + XklEngine *engine = xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY(gdk_display_get_default())); + XklState *xkl_state = xkl_engine_get_current_state (engine); + gpointer p = g_hash_table_lookup (preview_dialogs, + GINT_TO_POINTER + (xkl_state->group)); + gchar **group_names = matekbd_status_get_group_names (); + + if (xkl_state->group < 0 + || xkl_state->group >= g_strv_length (group_names)) { + return; + } + + if (p != NULL) { + /* existing window */ + gtk_window_present (GTK_WINDOW (p)); + return; + } + + dialog = + matekbd_keyboard_drawing_new_dialog (xkl_state->group, + group_names + [xkl_state->group]); + g_signal_connect (GTK_OBJECT (dialog), "destroy", + G_CALLBACK (show_layout_destroy), + GINT_TO_POINTER (xkl_state->group)); + g_hash_table_insert (preview_dialogs, + GINT_TO_POINTER (xkl_state->group), dialog); +} + +static void +popup_menu_set_group (GtkMenuItem * item, gpointer param) +{ + gint group_number = GPOINTER_TO_INT (param); + XklEngine *engine = matekbd_status_get_xkl_engine (); + XklState st; + Window cur; + + st.group = group_number; + xkl_engine_allow_one_switch_to_secondary_group (engine); + cur = xkl_engine_get_current_window (engine); + if (cur != (Window) NULL) { + xkl_debug (150, "Enforcing the state %d for window %lx\n", + st.group, cur); + xkl_engine_save_state (engine, + xkl_engine_get_current_window + (engine), &st); +/* XSetInputFocus(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), cur, RevertToNone, CurrentTime );*/ + } else { + xkl_debug (150, + "??? Enforcing the state %d for unknown window\n", + st.group); + /* strange situation - bad things can happen */ + } + xkl_engine_lock_group (engine, st.group); +} + +static void +status_icon_popup_menu_cb (GtkStatusIcon * icon, guint button, guint time) +{ + GtkMenu *popup_menu = GTK_MENU (gtk_menu_new ()); + GtkMenu *groups_menu = GTK_MENU (gtk_menu_new ()); + int i = 0; + gchar **current_name = matekbd_status_get_group_names (); + + GtkWidget *item = gtk_menu_item_new_with_mnemonic (_("_Layouts")); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), + GTK_WIDGET (groups_menu)); + + item = + gtk_menu_item_new_with_mnemonic (_("Keyboard _Preferences")); + gtk_widget_show (item); + g_signal_connect (item, "activate", popup_menu_launch_capplet, + NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item); + + item = gtk_menu_item_new_with_mnemonic (_("Show _Current Layout")); + gtk_widget_show (item); + g_signal_connect (item, "activate", popup_menu_show_layout, NULL); + gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item); + + for (i = 0; *current_name; i++, current_name++) { + gchar *image_file = matekbd_status_get_image_filename (i); + + if (image_file == NULL) { + item = + gtk_menu_item_new_with_label (*current_name); + } else { + GdkPixbuf *pixbuf = + gdk_pixbuf_new_from_file_at_size (image_file, + 24, 24, + NULL); + GtkWidget *img = + gtk_image_new_from_pixbuf (pixbuf); + item = + gtk_image_menu_item_new_with_label + (*current_name); + gtk_widget_show (img); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM + (item), img); + gtk_image_menu_item_set_always_show_image + (GTK_IMAGE_MENU_ITEM (item), TRUE); + g_free (image_file); + } + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (groups_menu), item); + g_signal_connect (item, "activate", + G_CALLBACK (popup_menu_set_group), + GINT_TO_POINTER (i)); + } + + gtk_menu_popup (popup_menu, NULL, NULL, + gtk_status_icon_position_menu, + (gpointer) icon, button, time); +} + +static void +show_hide_icon () +{ + if (g_slist_length (current_kbd_config.layouts_variants) > 1) { + if (icon == NULL) { + MateConfClient *conf_client = + mateconf_client_get_default (); + gboolean disable = + mateconf_client_get_bool (conf_client, + DISABLE_INDICATOR_KEY, + NULL); + g_object_unref (conf_client); + if (disable) + return; + + xkl_debug (150, "Creating new icon\n"); + icon = matekbd_status_new (); + g_signal_connect (icon, "popup-menu", + G_CALLBACK + (status_icon_popup_menu_cb), + NULL); + + } + } else { + if (icon != NULL) { + xkl_debug (150, "Destroying icon\n"); + g_object_unref (icon); + icon = NULL; + } + } +} + +static gboolean +try_activating_xkb_config_if_new (MatekbdKeyboardConfig * + current_sys_kbd_config) +{ + /* Activate - only if different! */ + if (!matekbd_keyboard_config_equals + (¤t_kbd_config, current_sys_kbd_config)) { + if (matekbd_keyboard_config_activate (¤t_kbd_config)) { + if (pa_callback != NULL) { + (*pa_callback) (pa_callback_user_data); + return TRUE; + } + } else { + return FALSE; + } + } + return TRUE; +} + +static gboolean +filter_xkb_config (void) +{ + XklConfigItem *item; + gchar *lname; + gchar *vname; + GSList *lv; + GSList *filtered; + gboolean any_change = FALSE; + + xkl_debug (100, "Filtering configuration against the registry\n"); + if (!xkl_registry) { + xkl_registry = + xkl_config_registry_get_instance (xkl_engine); + /* load all materials, unconditionally! */ + if (!xkl_config_registry_load (xkl_registry, TRUE)) { + g_object_unref (xkl_registry); + xkl_registry = NULL; + return FALSE; + } + } + lv = current_kbd_config.layouts_variants; + item = xkl_config_item_new (); + while (lv) { + xkl_debug (100, "Checking [%s]\n", lv->data); + if (matekbd_keyboard_config_split_items + (lv->data, &lname, &vname)) { + g_snprintf (item->name, sizeof (item->name), "%s", + lname); + if (!xkl_config_registry_find_layout + (xkl_registry, item)) { + xkl_debug (100, "Bad layout [%s]\n", + lname); + filtered = lv; + lv = lv->next; + g_free (filtered->data); + current_kbd_config.layouts_variants = + g_slist_delete_link + (current_kbd_config.layouts_variants, + filtered); + any_change = TRUE; + continue; + } + if (vname) { + g_snprintf (item->name, + sizeof (item->name), "%s", + vname); + if (!xkl_config_registry_find_variant + (xkl_registry, lname, item)) { + xkl_debug (100, + "Bad variant [%s(%s)]\n", + lname, vname); + filtered = lv; + lv = lv->next; + g_free (filtered->data); + current_kbd_config.layouts_variants + = + g_slist_delete_link + (current_kbd_config.layouts_variants, + filtered); + any_change = TRUE; + continue; + } + } + } + lv = lv->next; + } + g_object_unref (item); + return any_change; +} + +static void +apply_xkb_settings (void) +{ + MateConfClient *conf_client; + MatekbdKeyboardConfig current_sys_kbd_config; + int group_to_activate = -1; + char *mdm_layout; + char *s; + + if (!inited_ok) + return; + + conf_client = mateconf_client_get_default (); + + /* With MDM the user can already set a layout from the login + * screen. Try to keep that setting. + * We clear mdm_keyboard_layout early, so we don't risk + * recursion from mateconf notification. + */ + mdm_layout = g_strdup (mdm_keyboard_layout); + mdm_keyboard_layout = NULL; + + /* mdm's configuration and $MDM_KEYBOARD_LAYOUT separates layout and + * variant with a space, but mateconf uses tabs; so convert to be robust + * with both */ + for (s = mdm_layout; s && *s; ++s) { + if (*s == ' ') { + *s = '\t'; + } + } + + if (mdm_layout != NULL) { + GSList *layouts; + GSList *found_node; + int max_groups; + + max_groups = + MAX (xkl_engine_get_max_num_groups (xkl_engine), 1); + layouts = + mateconf_client_get_list (conf_client, + MATEKBD_KEYBOARD_CONFIG_KEY_LAYOUTS, + MATECONF_VALUE_STRING, NULL); + + /* Use system layouts as a default if we do not have + * user configuration */ + if (layouts == NULL) { + GSList *i; + int len; + + for (i = initial_sys_kbd_config.layouts_variants; + i; i = g_slist_next (i)) { + s = g_strdup (i->data); + + /* chop off empty variants to avoid duplicates */ + len = strlen (s); + if (s[len - 1] == '\t') + s[len - 1] = '\0'; + layouts = g_slist_append (layouts, s); + } + } + + /* Add the layout if it doesn't already exist. XKB limits the + * total number of layouts. If we already have the maximum + * number of layouts configured, we replace the last one. This + * prevents the list from becoming full if the user has a habit + * of selecting many different keyboard layouts in MDM. */ + + found_node = + g_slist_find_custom (layouts, mdm_layout, + (GCompareFunc) g_strcmp0); + + if (!found_node) { + /* Insert at the last valid place, or at the end of + * list, whichever comes first */ + layouts = + g_slist_insert (layouts, g_strdup (mdm_layout), + max_groups - 1); + if (g_slist_length (layouts) > max_groups) { + GSList *last; + GSList *free_layouts; + + last = + g_slist_nth (layouts, max_groups - 1); + free_layouts = last->next; + last->next = NULL; + + g_slist_foreach (free_layouts, + (GFunc) g_free, NULL); + g_slist_free (free_layouts); + } + + mateconf_client_set_list (conf_client, + MATEKBD_KEYBOARD_CONFIG_KEY_LAYOUTS, + MATECONF_VALUE_STRING, layouts, + NULL); + } + + g_slist_foreach (layouts, (GFunc) g_free, NULL); + g_slist_free (layouts); + } + + matekbd_keyboard_config_init (¤t_sys_kbd_config, + conf_client, xkl_engine); + + matekbd_keyboard_config_load_from_mateconf (¤t_kbd_config, + &initial_sys_kbd_config); + + matekbd_keyboard_config_load_from_x_current (¤t_sys_kbd_config, + NULL); + + if (!try_activating_xkb_config_if_new (¤t_sys_kbd_config)) { + if (filter_xkb_config ()) { + if (!try_activating_xkb_config_if_new + (¤t_sys_kbd_config)) { + g_warning + ("Could not activate the filtered XKB configuration"); + activation_error (); + } + } else { + g_warning + ("Could not activate the XKB configuration"); + activation_error (); + } + } else + xkl_debug (100, + "Actual KBD configuration was not changed: redundant notification\n"); + + if (mdm_layout != NULL) { + /* If there are multiple layouts, + * try to find the one closest to the mdm layout + */ + GSList *l; + int i; + size_t len = strlen (mdm_layout); + for (i = 0, l = current_kbd_config.layouts_variants; l; + i++, l = l->next) { + char *lv = l->data; + if (strncmp (lv, mdm_layout, len) == 0 + && (lv[len] == '\0' || lv[len] == '\t')) { + group_to_activate = i; + break; + } + } + } + + g_free (mdm_layout); + + if (group_to_activate != -1) + xkl_engine_lock_group (current_config.engine, + group_to_activate); + matekbd_keyboard_config_term (¤t_sys_kbd_config); + show_hide_icon (); +} + +static void +msd_keyboard_xkb_analyze_sysconfig (void) +{ + MateConfClient *conf_client; + + if (!inited_ok) + return; + + conf_client = mateconf_client_get_default (); + matekbd_keyboard_config_init (&initial_sys_kbd_config, + conf_client, xkl_engine); + matekbd_keyboard_config_load_from_x_initial (&initial_sys_kbd_config, + NULL); + g_object_unref (conf_client); +} + +static gboolean +msd_chk_file_list (void) +{ + GDir *home_dir; + const char *fname; + GSList *file_list = NULL; + GSList *last_login_file_list = NULL; + GSList *tmp = NULL; + GSList *tmp_l = NULL; + gboolean new_file_exist = FALSE; + MateConfClient *conf_client; + + home_dir = g_dir_open (g_get_home_dir (), 0, NULL); + while ((fname = g_dir_read_name (home_dir)) != NULL) { + if (g_strrstr (fname, "modmap")) { + file_list = + g_slist_append (file_list, g_strdup (fname)); + } + } + g_dir_close (home_dir); + + conf_client = mateconf_client_get_default (); + + last_login_file_list = mateconf_client_get_list (conf_client, + KNOWN_FILES_KEY, + MATECONF_VALUE_STRING, + NULL); + + /* Compare between the two file list, currently available modmap files + and the files available in the last log in */ + tmp = file_list; + while (tmp != NULL) { + tmp_l = last_login_file_list; + new_file_exist = TRUE; + while (tmp_l != NULL) { + if (strcmp (tmp->data, tmp_l->data) == 0) { + new_file_exist = FALSE; + break; + } else { + tmp_l = tmp_l->next; + } + } + if (new_file_exist) { + break; + } else { + tmp = tmp->next; + } + } + + if (new_file_exist) { + mateconf_client_set_list (conf_client, + KNOWN_FILES_KEY, + MATECONF_VALUE_STRING, + file_list, NULL); + } + + g_object_unref (conf_client); + + g_slist_foreach (file_list, (GFunc) g_free, NULL); + g_slist_free (file_list); + + g_slist_foreach (last_login_file_list, (GFunc) g_free, NULL); + g_slist_free (last_login_file_list); + + return new_file_exist; + +} + +static void +msd_keyboard_xkb_chk_lcl_xmm (void) +{ + if (msd_chk_file_list ()) { + msd_modmap_dialog_call (); + } + msd_load_modmap_files (); +} + +void +msd_keyboard_xkb_set_post_activation_callback (PostActivationCallback fun, + void *user_data) +{ + pa_callback = fun; + pa_callback_user_data = user_data; +} + +static GdkFilterReturn +msd_keyboard_xkb_evt_filter (GdkXEvent * xev, GdkEvent * event) +{ + XEvent *xevent = (XEvent *) xev; + xkl_engine_filter_events (xkl_engine, xevent); + return GDK_FILTER_CONTINUE; +} + +static guint +register_config_callback (MateConfClient * client, + const char *path, MateConfClientNotifyFunc func) +{ + mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + return mateconf_client_notify_add (client, path, func, NULL, NULL, + NULL); +} + +/* When new Keyboard is plugged in - reload the settings */ +static void +msd_keyboard_new_device (XklEngine * engine) +{ + apply_desktop_settings (); + apply_xkb_settings (); +} + +static void +msd_keyboard_update_indicator_icons () +{ + Bool state; + int new_state, i; + Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + XkbGetNamedIndicator (display, caps_lock, NULL, &state, + NULL, NULL); + new_state = state ? 1 : 0; + XkbGetNamedIndicator (display, num_lock, NULL, &state, NULL, NULL); + new_state <<= 1; + new_state |= (state ? 1 : 0); + XkbGetNamedIndicator (display, scroll_lock, NULL, &state, + NULL, NULL); + new_state <<= 1; + new_state |= (state ? 1 : 0); + xkl_debug (160, "Indicators state: %d\n", new_state); + + + for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); + --i >= 0;) { + gtk_status_icon_set_from_icon_name (indicator_icons[i], + (new_state & (1 << i)) + ? + indicator_on_icon_names + [i] : + indicator_off_icon_names + [i]); + } +} + +static void +msd_keyboard_state_changed (XklEngine * engine, XklEngineStateChange type, + gint new_group, gboolean restore) +{ + xkl_debug (160, + "State changed: type %d, new group: %d, restore: %d.\n", + type, new_group, restore); + if (type == INDICATORS_CHANGED) { + msd_keyboard_update_indicator_icons (); + } +} + +void +msd_keyboard_xkb_init (MateConfClient * client, + MsdKeyboardManager * kbd_manager) +{ + int i; + Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + mate_settings_profile_start (NULL); + + gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), + DATADIR G_DIR_SEPARATOR_S + "icons"); + + caps_lock = XInternAtom (display, "Caps Lock", False); + num_lock = XInternAtom (display, "Num Lock", False); + scroll_lock = XInternAtom (display, "Scroll Lock", False); + + for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); + --i >= 0;) { + indicator_icons[i] = + gtk_status_icon_new_from_icon_name + (indicator_off_icon_names[i]); + } + + msd_keyboard_update_indicator_icons (); + +#ifdef MSDKX + xkl_set_debug_level (200); + logfile = fopen ("/tmp/msdkx.log", "a"); + xkl_set_log_appender (msd_keyboard_log_appender); +#endif + manager = kbd_manager; + mate_settings_profile_start ("xkl_engine_get_instance"); + xkl_engine = xkl_engine_get_instance (display); + mate_settings_profile_end ("xkl_engine_get_instance"); + if (xkl_engine) { + inited_ok = TRUE; + + mdm_keyboard_layout = g_getenv ("MDM_KEYBOARD_LAYOUT"); + + matekbd_desktop_config_init (¤t_config, + client, xkl_engine); + matekbd_keyboard_config_init (¤t_kbd_config, + client, xkl_engine); + xkl_engine_backup_names_prop (xkl_engine); + msd_keyboard_xkb_analyze_sysconfig (); + mate_settings_profile_start + ("msd_keyboard_xkb_chk_lcl_xmm"); + msd_keyboard_xkb_chk_lcl_xmm (); + mate_settings_profile_end + ("msd_keyboard_xkb_chk_lcl_xmm"); + + notify_desktop = + register_config_callback (client, + MATEKBD_DESKTOP_CONFIG_DIR, + (MateConfClientNotifyFunc) + apply_desktop_settings); + + notify_keyboard = + register_config_callback (client, + MATEKBD_KEYBOARD_CONFIG_DIR, + (MateConfClientNotifyFunc) + apply_xkb_settings); + + gdk_window_add_filter (NULL, (GdkFilterFunc) + msd_keyboard_xkb_evt_filter, NULL); + + if (xkl_engine_get_features (xkl_engine) & + XKLF_DEVICE_DISCOVERY) + g_signal_connect (xkl_engine, "X-new-device", + G_CALLBACK + (msd_keyboard_new_device), NULL); + g_signal_connect (xkl_engine, "X-state-changed", + G_CALLBACK + (msd_keyboard_state_changed), NULL); + + mate_settings_profile_start ("xkl_engine_start_listen"); + xkl_engine_start_listen (xkl_engine, + XKLL_MANAGE_LAYOUTS | + XKLL_MANAGE_WINDOW_STATES); + mate_settings_profile_end ("xkl_engine_start_listen"); + + mate_settings_profile_start ("apply_desktop_settings"); + apply_desktop_settings (); + mate_settings_profile_end ("apply_desktop_settings"); + mate_settings_profile_start ("apply_xkb_settings"); + apply_xkb_settings (); + mate_settings_profile_end ("apply_xkb_settings"); + } + preview_dialogs = g_hash_table_new (g_direct_hash, g_direct_equal); + + mate_settings_profile_end (NULL); +} + +void +msd_keyboard_xkb_shutdown (void) +{ + MateConfClient *client; + int i; + + pa_callback = NULL; + pa_callback_user_data = NULL; + manager = NULL; + + for (i = sizeof (indicator_icons) / sizeof (indicator_icons[0]); + --i >= 0;) { + g_object_unref (G_OBJECT (indicator_icons[i])); + indicator_icons[i] = NULL; + } + + g_hash_table_destroy (preview_dialogs); + + if (!inited_ok) + return; + + xkl_engine_stop_listen (xkl_engine, + XKLL_MANAGE_LAYOUTS | + XKLL_MANAGE_WINDOW_STATES); + + gdk_window_remove_filter (NULL, (GdkFilterFunc) + msd_keyboard_xkb_evt_filter, NULL); + + client = mateconf_client_get_default (); + + if (notify_desktop != 0) { + mateconf_client_remove_dir (client, MATEKBD_DESKTOP_CONFIG_DIR, + NULL); + mateconf_client_notify_remove (client, notify_desktop); + notify_desktop = 0; + } + + if (notify_keyboard != 0) { + mateconf_client_remove_dir (client, MATEKBD_KEYBOARD_CONFIG_DIR, + NULL); + mateconf_client_notify_remove (client, notify_keyboard); + notify_keyboard = 0; + } + + if (xkl_registry) { + g_object_unref (xkl_registry); + } + + g_object_unref (client); + g_object_unref (xkl_engine); + + xkl_engine = NULL; + inited_ok = FALSE; +} diff --git a/plugins/keyboard/msd-keyboard-xkb.h b/plugins/keyboard/msd-keyboard-xkb.h new file mode 100644 index 0000000..7d2d558 --- /dev/null +++ b/plugins/keyboard/msd-keyboard-xkb.h @@ -0,0 +1,40 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * mate-settings-keyboard-xkb.h + * + * Copyright (C) 2001 Udaltsoft + * + * Written by Sergey V. Oudaltsov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef __MSD_KEYBOARD_XKB_H +#define __MSD_KEYBOARD_XKB_H + +#include +#include + +#include +#include "msd-keyboard-manager.h" + +void msd_keyboard_xkb_init(MateConfClient* client, MsdKeyboardManager* manager); +void msd_keyboard_xkb_shutdown(void); + +typedef void (*PostActivationCallback) (void* userData); + +void msd_keyboard_xkb_set_post_activation_callback(PostActivationCallback fun, void* userData); + +#endif diff --git a/plugins/keyboard/msd-xmodmap.c b/plugins/keyboard/msd-xmodmap.c new file mode 100644 index 0000000..5baf37c --- /dev/null +++ b/plugins/keyboard/msd-xmodmap.c @@ -0,0 +1,399 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright © 2005 Novell Inc. + * + * Written by Shakti Sen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include +#include +#include + +#include "msd-xmodmap.h" + +static const char DISABLE_XMM_WARNING_KEY[] = + "/desktop/mate/peripherals/keyboard/disable_xmm_and_xkb_warning"; + +static const char LOADED_FILES_KEY[] = + "/desktop/mate/peripherals/keyboard/general/update_handlers"; + + +static void +check_button_callback (GtkWidget *chk_button, + gpointer data) +{ + MateConfClient *client; + + client = mateconf_client_get_default (); + + mateconf_client_set_bool (client, + DISABLE_XMM_WARNING_KEY, + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chk_button)), + NULL); + + g_object_unref (client); +} + +void +msd_load_modmap_files (void) +{ + MateConfClient *client; + GSList *tmp; + GSList *loaded_file_list; + + client = mateconf_client_get_default (); + + loaded_file_list = mateconf_client_get_list (client, LOADED_FILES_KEY, MATECONF_VALUE_STRING, NULL); + + for (tmp = loaded_file_list; tmp != NULL; tmp = tmp->next) { + gchar *file; + gchar *command; + + file = g_build_filename (g_get_home_dir (), (gchar *) tmp->data, NULL); + command = g_strconcat ("xmodmap ", file, NULL); + g_free (file); + + g_spawn_command_line_async (command, NULL); + + g_free (command); + g_free (tmp->data); + } + + g_slist_free (loaded_file_list); + g_object_unref (client); +} + +static void +response_callback (GtkWidget *dialog, + int id, + void *data) +{ + if (id == GTK_RESPONSE_OK) { + GtkWidget *chk_button = g_object_get_data (G_OBJECT (dialog), "check_button"); + check_button_callback (chk_button, NULL); + msd_load_modmap_files (); + } + gtk_widget_destroy (dialog); +} + +static void +get_selected_files_func (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + GSList **list = data; + gchar *filename; + + filename = NULL; + gtk_tree_model_get (model, + iter, + 0, + &filename, + -1); + + *list = g_slist_prepend (*list, filename); +} + +static GSList* +remove_string_from_list (GSList *list, + const char *str) +{ + GSList *tmp; + + for (tmp = list; tmp != NULL; tmp = tmp->next) { + if (strcmp (tmp->data, str) == 0) { + g_free (tmp->data); + list = g_slist_delete_link (list, tmp); + break; + } + } + + return list; +} + + +static void +remove_button_clicked_callback (GtkWidget *button, + void *data) +{ + GtkWidget *dialog; + GtkListStore *tree = NULL; + GtkTreeSelection *selection; + GtkWidget *treeview; + MateConfClient *client; + GSList *filenames = NULL; + GSList *tmp = NULL; + GSList *loaded_files = NULL; + + dialog = data; + + treeview = g_object_get_data (G_OBJECT (dialog), "treeview1"); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + gtk_tree_selection_selected_foreach (selection, + get_selected_files_func, + &filenames); + + if (!filenames) + return; + + /* Remove the selected file */ + + client = mateconf_client_get_default (); + + loaded_files = mateconf_client_get_list (client, + LOADED_FILES_KEY, + MATECONF_VALUE_STRING, + NULL); + loaded_files = remove_string_from_list (loaded_files, (char *)filenames->data); + + mateconf_client_set_list (client, + LOADED_FILES_KEY, + MATECONF_VALUE_STRING, + loaded_files, + NULL); + g_object_unref (client); + + tree = g_object_get_data (G_OBJECT (dialog), "tree"); + + gtk_list_store_clear (tree); + for (tmp = loaded_files; tmp != NULL; tmp = tmp->next) { + GtkTreeIter iter; + gtk_list_store_append (tree, &iter); + gtk_list_store_set (tree, &iter, + 0, + tmp->data, + -1); + } + + g_slist_foreach (loaded_files, (GFunc) g_free, NULL); + g_slist_free (loaded_files); +} + +static void +load_button_clicked_callback (GtkWidget *button, + void *data) +{ + GtkWidget *dialog; + GtkListStore *tree = NULL; + GtkTreeSelection *selection; + GtkWidget *treeview; + GSList *filenames = NULL; + GSList *tmp = NULL; + GSList *loaded_files = NULL; + MateConfClient *client; + + dialog = data; + + treeview = g_object_get_data (G_OBJECT (dialog), + "loaded-treeview"); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + gtk_tree_selection_selected_foreach (selection, + get_selected_files_func, + &filenames); + + if (!filenames) + return; + + /* Add the files to left-tree-view */ + client = mateconf_client_get_default (); + + loaded_files = mateconf_client_get_list (client, + LOADED_FILES_KEY, + MATECONF_VALUE_STRING, + NULL); + + if (g_slist_find_custom (loaded_files, filenames->data, (GCompareFunc) strcmp)) { + g_free (filenames->data); + g_slist_free (filenames); + goto out; + } + + loaded_files = g_slist_append (loaded_files, filenames->data); + mateconf_client_set_list (client, + LOADED_FILES_KEY, + MATECONF_VALUE_STRING, + loaded_files, + NULL); + + + tree = g_object_get_data (G_OBJECT (dialog), "tree"); + + gtk_list_store_clear (tree); + for (tmp = loaded_files; tmp != NULL; tmp = tmp->next) { + GtkTreeIter iter; + gtk_list_store_append (tree, &iter); + gtk_list_store_set (tree, &iter, + 0, + tmp->data, + -1); + } + +out: + g_object_unref (client); + g_slist_foreach (loaded_files, (GFunc) g_free, NULL); + g_slist_free (loaded_files); +} + +void +msd_modmap_dialog_call (void) +{ + GtkBuilder *builder; + guint res; + GError *error; + GtkWidget *load_dialog; + GtkListStore *tree; + GtkCellRenderer *cell_renderer; + GtkTreeIter parent_iter; + GtkTreeIter iter; + GtkTreeModel *sort_model; + GtkTreeSelection *selection; + GtkWidget *treeview; + GtkWidget *treeview1; + GtkTreeViewColumn *column; + GtkWidget *add_button; + GtkWidget *remove_button; + GtkWidget *chk_button; + GSList *tmp; + GDir *homeDir; + GSList *loaded_files; + const char *fname; + MateConfClient *client; + + homeDir = g_dir_open (g_get_home_dir (), 0, NULL); + if (homeDir == NULL) + return; + + error = NULL; + builder = gtk_builder_new (); + res = gtk_builder_add_from_file (builder, + DATADIR "/modmap-dialog.ui", + &error); + + if (res == 0) { + g_warning ("Could not load UI file: %s", error->message); + g_error_free (error); + g_object_unref (builder); + g_dir_close (homeDir); + return; + } + + load_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dialog1")); + gtk_window_set_modal (GTK_WINDOW (load_dialog), TRUE); + g_signal_connect (load_dialog, + "response", + G_CALLBACK (response_callback), + builder); + add_button = GTK_WIDGET (gtk_builder_get_object (builder, "button7")); + g_signal_connect (add_button, + "clicked", + G_CALLBACK (load_button_clicked_callback), + load_dialog); + remove_button = GTK_WIDGET (gtk_builder_get_object (builder, + "button6")); + g_signal_connect (remove_button, + "clicked", + G_CALLBACK (remove_button_clicked_callback), + load_dialog); + chk_button = GTK_WIDGET (gtk_builder_get_object (builder, + "checkbutton1")); + g_signal_connect (chk_button, + "toggled", + G_CALLBACK (check_button_callback), + NULL); + g_object_set_data (G_OBJECT (load_dialog), "check_button", chk_button); + treeview = GTK_WIDGET (gtk_builder_get_object (builder, "treeview1")); + g_object_set_data (G_OBJECT (load_dialog), "treeview1", treeview); + treeview = GTK_WIDGET (gtk_builder_get_object (builder, "treeview2")); + g_object_set_data (G_OBJECT (load_dialog), "loaded-treeview", treeview); + tree = gtk_list_store_new (1, G_TYPE_STRING); + cell_renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("modmap", + cell_renderer, + "text", 0, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); + gtk_tree_view_column_set_sort_column_id (column, 0); + + /* Add the data */ + while ((fname = g_dir_read_name (homeDir)) != NULL) { + if (g_strrstr (fname, "modmap")) { + gtk_list_store_append (tree, &parent_iter); + gtk_list_store_set (tree, &parent_iter, + 0, + fname, + -1); + } + } + sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree)); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), + 0, + GTK_SORT_ASCENDING); + gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), sort_model); + g_object_unref (G_OBJECT (tree)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), + GTK_SELECTION_MULTIPLE); + gtk_widget_show (load_dialog); + + g_dir_close (homeDir); + + /* Left treeview */ + treeview1 = GTK_WIDGET (gtk_builder_get_object (builder, "treeview1")); + tree = gtk_list_store_new (1, G_TYPE_STRING); + cell_renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("modmap", + cell_renderer, + "text", 0, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview1), column); + gtk_tree_view_column_set_sort_column_id (column, 0); + + client = mateconf_client_get_default (); + loaded_files = mateconf_client_get_list (client, LOADED_FILES_KEY, MATECONF_VALUE_STRING, NULL); + g_object_unref (client); + + /* Add the data */ + for (tmp = loaded_files; tmp != NULL; tmp = tmp->next) { + gtk_list_store_append (tree, &iter); + gtk_list_store_set (tree, &iter, + 0, + tmp->data, + -1); + } + + g_slist_foreach (loaded_files, (GFunc) g_free, NULL); + g_slist_free (loaded_files); + + sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (tree)); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), + 0, + GTK_SORT_ASCENDING); + gtk_tree_view_set_model (GTK_TREE_VIEW (treeview1), sort_model); + g_object_unref (G_OBJECT (tree)); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview1)); + gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), + GTK_SELECTION_MULTIPLE); + g_object_set_data (G_OBJECT (load_dialog), "tree", tree); + g_object_unref (builder); +} diff --git a/plugins/keyboard/msd-xmodmap.h b/plugins/keyboard/msd-xmodmap.h new file mode 100644 index 0000000..04b4505 --- /dev/null +++ b/plugins/keyboard/msd-xmodmap.h @@ -0,0 +1,29 @@ +/* mate-settings-xmodmap.h + * + * Copyright © 2005 Novell Inc. + * + * Written by Shakti Sen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef XMODMAP_H +#define XMODMAP_H + +void msd_load_modmap_files (void); +void msd_modmap_dialog_call (void); + +#endif diff --git a/plugins/media-keys/gsd-marshal.list b/plugins/media-keys/gsd-marshal.list deleted file mode 100644 index 72f9937..0000000 --- a/plugins/media-keys/gsd-marshal.list +++ /dev/null @@ -1 +0,0 @@ -VOID:STRING,STRING diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c deleted file mode 100644 index d7e1b04..0000000 --- a/plugins/media-keys/gsd-media-keys-manager.c +++ /dev/null @@ -1,1447 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2001-2003 Bastien Nocera - * Copyright (C) 2006-2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "mate-settings-profile.h" -#include "msd-marshal.h" -#include "msd-media-keys-manager.h" -#include "msd-media-keys-manager-glue.h" - -#include "eggaccelerators.h" -#include "acme.h" -#include "msd-media-keys-window.h" - -#ifdef HAVE_PULSE -#include -#include "gvc-mixer-control.h" -#elif defined(HAVE_GSTREAMER) -#include "gvc-gstreamer-acme-vol.h" -#endif /* HAVE_PULSE */ - -#define MSD_DBUS_PATH "/org/mate/SettingsDaemon" -#define MSD_DBUS_NAME "org.mate.SettingsDaemon" -#define MSD_MEDIA_KEYS_DBUS_PATH MSD_DBUS_PATH "/MediaKeys" -#define MSD_MEDIA_KEYS_DBUS_NAME MSD_DBUS_NAME ".MediaKeys" - -#define TOUCHPAD_ENABLED_KEY "/desktop/mate/peripherals/touchpad/touchpad_enabled" - -#define VOLUME_STEP 6 /* percents for one volume button press */ -#define MAX_VOLUME 65536.0 - -#define MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerPrivate)) - -typedef struct { - char *application; - guint32 time; -} MediaPlayer; - -struct MsdMediaKeysManagerPrivate -{ -#ifdef HAVE_PULSE - /* Volume bits */ - GvcMixerControl *volume; - GvcMixerStream *stream; -#elif defined(HAVE_GSTREAMER) - AcmeVolume *volume; -#endif /* HAVE_PULSE */ - GtkWidget *dialog; - MateConfClient *conf_client; - GVolumeMonitor *volume_monitor; - - /* Multihead stuff */ - GdkScreen *current_screen; - GSList *screens; - - GList *media_players; - - DBusGConnection *connection; - guint notify[HANDLED_KEYS]; -}; - -enum { - MEDIA_PLAYER_KEY_PRESSED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -static void msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass); -static void msd_media_keys_manager_init (MsdMediaKeysManager *media_keys_manager); -static void msd_media_keys_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdMediaKeysManager, msd_media_keys_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - - -static void -init_screens (MsdMediaKeysManager *manager) -{ - GdkDisplay *display; - int i; - - display = gdk_display_get_default (); - for (i = 0; i < gdk_display_get_n_screens (display); i++) { - GdkScreen *screen; - - screen = gdk_display_get_screen (display, i); - if (screen == NULL) { - continue; - } - manager->priv->screens = g_slist_append (manager->priv->screens, screen); - } - - manager->priv->current_screen = manager->priv->screens->data; -} - - -static void -acme_error (char * msg) -{ - GtkWidget *error_dialog; - - error_dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - msg, NULL); - gtk_dialog_set_default_response (GTK_DIALOG (error_dialog), - GTK_RESPONSE_OK); - gtk_widget_show (error_dialog); - g_signal_connect (error_dialog, - "response", - G_CALLBACK (gtk_widget_destroy), - NULL); -} - -static char * -get_term_command (MsdMediaKeysManager *manager) -{ - char *cmd_term; - char *cmd = NULL; - - cmd_term = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/applications/terminal/exec", NULL); - if ((cmd_term != NULL) && (strcmp (cmd_term, "") != 0)) { - char *cmd_args; - cmd_args = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/applications/terminal/exec_arg", NULL); - if ((cmd_args != NULL) && (strcmp (cmd_term, "") != 0)) { - cmd = g_strdup_printf ("%s %s -e", cmd_term, cmd_args); - } else { - cmd = g_strdup_printf ("%s -e", cmd_term); - } - - g_free (cmd_args); - } - - g_free (cmd_term); - - return cmd; -} - -static void -execute (MsdMediaKeysManager *manager, - char *cmd, - gboolean sync, - gboolean need_term) -{ - gboolean retval; - char **argv; - int argc; - char *exec; - char *term = NULL; - - retval = FALSE; - - if (need_term) { - term = get_term_command (manager); - if (term == NULL) { - acme_error (_("Could not get default terminal. Verify that your default " - "terminal command is set and points to a valid application.")); - return; - } - } - - if (term) { - exec = g_strdup_printf ("%s %s", term, cmd); - g_free (term); - } else { - exec = g_strdup (cmd); - } - - if (g_shell_parse_argv (exec, &argc, &argv, NULL)) { - if (sync != FALSE) { - retval = g_spawn_sync (g_get_home_dir (), - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL); - } else { - retval = g_spawn_async (g_get_home_dir (), - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - NULL); - } - g_strfreev (argv); - } - - if (retval == FALSE) { - char *msg; - msg = g_strdup_printf (_("Couldn't execute command: %s\n" - "Verify that this is a valid command."), - exec); - - acme_error (msg); - g_free (msg); - } - g_free (exec); -} - -static void -dialog_init (MsdMediaKeysManager *manager) -{ - if (manager->priv->dialog != NULL - && !msd_osd_window_is_valid (MSD_OSD_WINDOW (manager->priv->dialog))) { - gtk_widget_destroy (manager->priv->dialog); - manager->priv->dialog = NULL; - } - - if (manager->priv->dialog == NULL) { - manager->priv->dialog = msd_media_keys_window_new (); - } -} - -static gboolean -is_valid_shortcut (const char *string) -{ - if (string == NULL || string[0] == '\0') { - return FALSE; - } - if (strcmp (string, "disabled") == 0) { - return FALSE; - } - - return TRUE; -} - -static void -update_kbd_cb (MateConfClient *client, - guint id, - MateConfEntry *entry, - MsdMediaKeysManager *manager) -{ - int i; - gboolean need_flush = TRUE; - - g_return_if_fail (entry->key != NULL); - - gdk_error_trap_push (); - - /* Find the key that was modified */ - for (i = 0; i < HANDLED_KEYS; i++) { - if (strcmp (entry->key, keys[i].mateconf_key) == 0) { - char *tmp; - Key *key; - - if (keys[i].key != NULL) { - need_flush = TRUE; - grab_key_unsafe (keys[i].key, FALSE, manager->priv->screens); - } - - g_free (keys[i].key); - keys[i].key = NULL; - - tmp = mateconf_client_get_string (manager->priv->conf_client, - keys[i].mateconf_key, NULL); - - if (is_valid_shortcut (tmp) == FALSE) { - g_free (tmp); - break; - } - - key = g_new0 (Key, 1); - if (!egg_accelerator_parse_virtual (tmp, &key->keysym, &key->keycodes, &key->state)) { - g_free (tmp); - g_free (key); - break; - } - - need_flush = TRUE; - grab_key_unsafe (key, TRUE, manager->priv->screens); - keys[i].key = key; - - g_free (tmp); - - break; - } - } - - if (need_flush) - gdk_flush (); - if (gdk_error_trap_pop ()) - g_warning ("Grab failed for some keys, another application may already have access the them."); -} - -static void init_kbd(MsdMediaKeysManager* manager) -{ - int i; - gboolean need_flush = FALSE; - - mate_settings_profile_start(NULL); - - gdk_error_trap_push(); - - for (i = 0; i < HANDLED_KEYS; i++) - { - char* tmp; - Key* key; - - manager->priv->notify[i] = mateconf_client_notify_add(manager->priv->conf_client, - keys[i].mateconf_key, - (MateConfClientNotifyFunc) update_kbd_cb, - manager, - NULL, - NULL); - - tmp = mateconf_client_get_string(manager->priv->conf_client, - keys[i].mateconf_key, - NULL); - - if (!is_valid_shortcut(tmp)) - { - g_debug("Not a valid shortcut: '%s'", tmp); - g_free(tmp); - continue; - } - - key = g_new0(Key, 1); - - if (!egg_accelerator_parse_virtual(tmp, &key->keysym, &key->keycodes, &key->state)) - { - g_debug("Unable to parse: '%s'", tmp); - g_free(tmp); - g_free(key); - continue; - } - - g_free(tmp); - - keys[i].key = key; - - need_flush = TRUE; - grab_key_unsafe(key, TRUE, manager->priv->screens); - } - - if (need_flush) - { - gdk_flush(); - } - - if (gdk_error_trap_pop ()) - { - g_warning("Grab failed for some keys, another application may already have access the them."); - } - - mate_settings_profile_end(NULL); -} - -static void -dialog_show (MsdMediaKeysManager *manager) -{ - int orig_w; - int orig_h; - int screen_w; - int screen_h; - int x; - int y; - int pointer_x; - int pointer_y; - GtkRequisition win_req; - GdkScreen *pointer_screen; - GdkRectangle geometry; - int monitor; - - gtk_window_set_screen (GTK_WINDOW (manager->priv->dialog), - manager->priv->current_screen); - - /* - * get the window size - * if the window hasn't been mapped, it doesn't necessarily - * know its true size, yet, so we need to jump through hoops - */ - gtk_window_get_default_size (GTK_WINDOW (manager->priv->dialog), &orig_w, &orig_h); - gtk_widget_size_request (manager->priv->dialog, &win_req); - - if (win_req.width > orig_w) { - orig_w = win_req.width; - } - if (win_req.height > orig_h) { - orig_h = win_req.height; - } - - pointer_screen = NULL; - gdk_display_get_pointer (gdk_screen_get_display (manager->priv->current_screen), - &pointer_screen, - &pointer_x, - &pointer_y, - NULL); - if (pointer_screen != manager->priv->current_screen) { - /* The pointer isn't on the current screen, so just - * assume the default monitor - */ - monitor = 0; - } else { - monitor = gdk_screen_get_monitor_at_point (manager->priv->current_screen, - pointer_x, - pointer_y); - } - - gdk_screen_get_monitor_geometry (manager->priv->current_screen, - monitor, - &geometry); - - screen_w = geometry.width; - screen_h = geometry.height; - - x = ((screen_w - orig_w) / 2) + geometry.x; - y = geometry.y + (screen_h / 2) + (screen_h / 2 - orig_h) / 2; - - gtk_window_move (GTK_WINDOW (manager->priv->dialog), x, y); - - gtk_widget_show (manager->priv->dialog); - - gdk_display_sync (gdk_screen_get_display (manager->priv->current_screen)); -} - -static void -do_unknown_action (MsdMediaKeysManager *manager, - const char *url) -{ - char *string; - - g_return_if_fail (url != NULL); - - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/unknown/command", - NULL); - - if ((string != NULL) && (strcmp (string, "") != 0)) { - char *cmd; - cmd = g_strdup_printf (string, url); - execute (manager, cmd, FALSE, FALSE); - g_free (cmd); - } - g_free (string); -} - -static void -do_help_action (MsdMediaKeysManager *manager) -{ - char *string; - - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/ghelp/command", - NULL); - - if ((string != NULL) && (strcmp (string, "") != 0)) { - char *cmd; - cmd = g_strdup_printf (string, ""); - execute (manager, cmd, FALSE, FALSE); - g_free (cmd); - } else { - do_unknown_action (manager, "ghelp:"); - } - - g_free (string); -} - -static void -do_mail_action (MsdMediaKeysManager *manager) -{ - char *string; - - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/mailto/command", - NULL); - - if ((string != NULL) && (strcmp (string, "") != 0)) { - char *cmd; - cmd = g_strdup_printf (string, ""); - execute (manager, - cmd, - FALSE, - mateconf_client_get_bool (manager->priv->conf_client, - "/desktop/mate/url-handlers/mailto/needs_terminal", NULL)); - g_free (cmd); - } - g_free (string); -} - -static void -do_media_action (MsdMediaKeysManager *manager) -{ - char *command; - - command = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/applications/media/exec", NULL); - if ((command != NULL) && (strcmp (command, "") != 0)) { - execute (manager, - command, - FALSE, - mateconf_client_get_bool (manager->priv->conf_client, - "/desktop/mate/applications/media/needs_term", NULL)); - } - g_free (command); -} - -static void -do_www_action (MsdMediaKeysManager *manager, - const char *url) -{ - char *string; - - string = mateconf_client_get_string (manager->priv->conf_client, - "/desktop/mate/url-handlers/http/command", - NULL); - - if ((string != NULL) && (strcmp (string, "") != 0)) { - gchar *cmd; - - if (url == NULL) { - cmd = g_strdup_printf (string, ""); - } else { - cmd = g_strdup_printf (string, url); - } - - execute (manager, - cmd, - FALSE, - mateconf_client_get_bool (manager->priv->conf_client, - "/desktop/mate/url-handlers/http/needs_terminal", NULL)); - g_free (cmd); - } else { - do_unknown_action (manager, url ? url : ""); - } - g_free (string); -} - -static void -do_exit_action (MsdMediaKeysManager *manager) -{ - execute (manager, "mate-session-save --shutdown-dialog", FALSE, FALSE); -} - -static void -do_eject_action_cb (GDrive *drive, - GAsyncResult *res, - MsdMediaKeysManager *manager) -{ - g_drive_eject_with_operation_finish (drive, res, NULL); -} - -#define NO_SCORE 0 -#define SCORE_CAN_EJECT 50 -#define SCORE_HAS_MEDIA 100 -static void -do_eject_action (MsdMediaKeysManager *manager) -{ - GList *drives, *l; - GDrive *fav_drive; - guint score; - - /* Find the best drive to eject */ - fav_drive = NULL; - score = NO_SCORE; - drives = g_volume_monitor_get_connected_drives (manager->priv->volume_monitor); - for (l = drives; l != NULL; l = l->next) { - GDrive *drive = l->data; - - if (g_drive_can_eject (drive) == FALSE) - continue; - if (g_drive_is_media_removable (drive) == FALSE) - continue; - if (score < SCORE_CAN_EJECT) { - fav_drive = drive; - score = SCORE_CAN_EJECT; - } - if (g_drive_has_media (drive) == FALSE) - continue; - if (score < SCORE_HAS_MEDIA) { - fav_drive = drive; - score = SCORE_HAS_MEDIA; - break; - } - } - - /* Show the dialogue */ - dialog_init (manager); - msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - "media-eject", - FALSE); - dialog_show (manager); - - /* Clean up the drive selection and exit if no suitable - * drives are found */ - if (fav_drive != NULL) - fav_drive = g_object_ref (fav_drive); - - g_list_foreach (drives, (GFunc) g_object_unref, NULL); - if (fav_drive == NULL) - return; - - /* Eject! */ - g_drive_eject_with_operation (fav_drive, G_MOUNT_UNMOUNT_FORCE, - NULL, NULL, - (GAsyncReadyCallback) do_eject_action_cb, - manager); - g_object_unref (fav_drive); -} - -static void -do_touchpad_action (MsdMediaKeysManager *manager) -{ - MateConfClient *client = manager->priv->conf_client; - gboolean state = mateconf_client_get_bool (client, TOUCHPAD_ENABLED_KEY, NULL); - - dialog_init (manager); - msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - (!state) ? "touchpad-enabled" : "touchpad-disabled", - FALSE); - dialog_show (manager); - - mateconf_client_set_bool (client, TOUCHPAD_ENABLED_KEY, !state, NULL); -} - -#ifdef HAVE_PULSE -static void -update_dialog (MsdMediaKeysManager *manager, - guint vol, - gboolean muted, - gboolean sound_changed) -{ - vol = (int) (100 * (double) vol / PA_VOLUME_NORM); - vol = CLAMP (vol, 0, 100); - - dialog_init (manager); - msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - muted); - msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol); - msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); - dialog_show (manager); - - if (sound_changed != FALSE && muted == FALSE) - ca_gtk_play_for_widget (manager->priv->dialog, 0, - CA_PROP_EVENT_ID, "audio-volume-change", - CA_PROP_EVENT_DESCRIPTION, "volume changed through key press", - CA_PROP_APPLICATION_ID, "org.mate.VolumeControl", - NULL); -} -#endif /* HAVE_PULSE */ - -#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) -static void -do_sound_action (MsdMediaKeysManager *manager, - int type) -{ - gboolean muted; - guint vol, norm_vol_step; - int vol_step; - gboolean sound_changed; - -#ifdef HAVE_PULSE - if (manager->priv->stream == NULL) - return; -#elif defined(HAVE_GSTREAMER) - if (manager->priv->volume == NULL) - return; -#endif - - vol_step = mateconf_client_get_int (manager->priv->conf_client, - MATECONF_MISC_DIR "/volume_step", - NULL); - - if (vol_step <= 0 || vol_step > 100) - vol_step = VOLUME_STEP; - -#ifdef HAVE_PULSE - norm_vol_step = PA_VOLUME_NORM * vol_step / 100; - - /* FIXME: this is racy */ - vol = gvc_mixer_stream_get_volume (manager->priv->stream); - muted = gvc_mixer_stream_get_is_muted (manager->priv->stream); -#else - if (vol_step > 0) { - gint threshold = acme_volume_get_threshold (manager->priv->volume); - if (vol_step < threshold) - vol_step = threshold; - g_debug ("Using volume step of %d", vol_step); - } - vol = acme_volume_get_volume (manager->priv->volume); - muted = acme_volume_get_mute (manager->priv->volume); -#endif - sound_changed = FALSE; - - switch (type) { - case MUTE_KEY: -#ifdef HAVE_PULSE - muted = !muted; - gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); - sound_changed = TRUE; -#else - acme_volume_mute_toggle (manager->priv->volume); -#endif - break; - case VOLUME_DOWN_KEY: -#ifdef HAVE_PULSE - if (!muted && (vol <= norm_vol_step)) { - muted = !muted; - vol = 0; - gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); - if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { - gvc_mixer_stream_push_volume (manager->priv->stream); - sound_changed = TRUE; - } - } else if (!muted) { - vol = vol - norm_vol_step; - if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { - gvc_mixer_stream_push_volume (manager->priv->stream); - sound_changed = TRUE; - } - } -#else - if (!muted && (vol <= vol_step)) - acme_volume_mute_toggle (manager->priv->volume); - acme_volume_set_volume (manager->priv->volume, vol - vol_step); -#endif - break; - case VOLUME_UP_KEY: - if (muted) { - muted = !muted; - if (vol == 0) { -#ifdef HAVE_PULSE - vol = vol + norm_vol_step; - gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); - if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { - gvc_mixer_stream_push_volume (manager->priv->stream); - sound_changed = TRUE; - } - } else { - gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); - sound_changed = TRUE; - } -#else - /* We need to unmute otherwise vol is blocked (and muted) */ - acme_volume_set_mute (manager->priv->volume, FALSE); - } - acme_volume_set_volume (manager->priv->volume, vol + vol_step); -#endif - } else { -#ifdef HAVE_PULSE - if (vol < MAX_VOLUME) { - if (vol + norm_vol_step >= MAX_VOLUME) { - vol = MAX_VOLUME; - } else { - vol = vol + norm_vol_step; - } - if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { - gvc_mixer_stream_push_volume (manager->priv->stream); - sound_changed = TRUE; - } - } -#else - acme_volume_set_volume (manager->priv->volume, vol + vol_step); -#endif - } - break; - } - -#ifdef HAVE_PULSE - update_dialog (manager, vol, muted, sound_changed); -#else - muted = acme_volume_get_mute (manager->priv->volume); - vol = acme_volume_get_volume (manager->priv->volume); - - /* FIXME: AcmeVolume should probably emit signals - instead of doing it like this */ - dialog_init (manager); - msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - muted); - msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - vol); - msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), - MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); - dialog_show (manager); -#endif /* HAVE_PULSE */ -} -#endif /* defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) */ - -#ifdef HAVE_PULSE -static void -update_default_sink (MsdMediaKeysManager *manager) -{ - GvcMixerStream *stream; - - stream = gvc_mixer_control_get_default_sink (manager->priv->volume); - if (stream == manager->priv->stream) - return; - - if (manager->priv->stream != NULL) { - g_object_unref (manager->priv->stream); - manager->priv->stream = NULL; - } - - if (stream != NULL) { - manager->priv->stream = g_object_ref (stream); - } else { - g_warning ("Unable to get default sink"); - } -} - -static void -on_control_ready (GvcMixerControl *control, - MsdMediaKeysManager *manager) -{ - update_default_sink (manager); -} - -static void -on_control_default_sink_changed (GvcMixerControl *control, - guint id, - MsdMediaKeysManager *manager) -{ - update_default_sink (manager); -} - -#endif /* HAVE_PULSE */ - -static gint -find_by_application (gconstpointer a, - gconstpointer b) -{ - return strcmp (((MediaPlayer *)a)->application, b); -} - -static gint -find_by_time (gconstpointer a, - gconstpointer b) -{ - return ((MediaPlayer *)a)->time < ((MediaPlayer *)b)->time; -} - -/* - * Register a new media player. Most applications will want to call - * this with time = GDK_CURRENT_TIME. This way, the last registered - * player will receive media events. In some cases, applications - * may want to register with a lower priority (usually 1), to grab - * events only nobody is interested. - */ -gboolean -msd_media_keys_manager_grab_media_player_keys (MsdMediaKeysManager *manager, - const char *application, - guint32 time, - GError **error) -{ - GList *iter; - MediaPlayer *media_player; - - if (time == GDK_CURRENT_TIME) { - GTimeVal tv; - - g_get_current_time (&tv); - time = tv.tv_sec * 1000 + tv.tv_usec / 1000; - } - - iter = g_list_find_custom (manager->priv->media_players, - application, - find_by_application); - - if (iter != NULL) { - if (((MediaPlayer *)iter->data)->time < time) { - g_free (((MediaPlayer *)iter->data)->application); - g_free (iter->data); - manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); - } else { - return TRUE; - } - } - - g_debug ("Registering %s at %u", application, time); - media_player = g_new0 (MediaPlayer, 1); - media_player->application = g_strdup (application); - media_player->time = time; - - manager->priv->media_players = g_list_insert_sorted (manager->priv->media_players, - media_player, - find_by_time); - - return TRUE; -} - -gboolean -msd_media_keys_manager_release_media_player_keys (MsdMediaKeysManager *manager, - const char *application, - GError **error) -{ - GList *iter; - - iter = g_list_find_custom (manager->priv->media_players, - application, - find_by_application); - - if (iter != NULL) { - g_debug ("Deregistering %s", application); - g_free (((MediaPlayer *)iter->data)->application); - g_free (iter->data); - manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); - } - - return TRUE; -} - -static gboolean -msd_media_player_key_pressed (MsdMediaKeysManager *manager, - const char *key) -{ - const char *application = NULL; - gboolean have_listeners; - - have_listeners = (manager->priv->media_players != NULL); - - if (have_listeners) { - application = ((MediaPlayer *)manager->priv->media_players->data)->application; - } - - g_signal_emit (manager, signals[MEDIA_PLAYER_KEY_PRESSED], 0, application, key); - - return !have_listeners; -} - -static gboolean -do_multimedia_player_action (MsdMediaKeysManager *manager, - const char *key) -{ - return msd_media_player_key_pressed (manager, key); -} - -static gboolean -do_action (MsdMediaKeysManager *manager, - int type) -{ - char *cmd; - char *path; - - switch (type) { - case TOUCHPAD_KEY: - do_touchpad_action (manager); - break; - case MUTE_KEY: - case VOLUME_DOWN_KEY: - case VOLUME_UP_KEY: -#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) - do_sound_action (manager, type); -#endif /* HAVE_PULSE || HAVE_GSTREAMER */ - break; - case POWER_KEY: - do_exit_action (manager); - break; - case EJECT_KEY: - do_eject_action (manager); - break; - case HOME_KEY: - path = g_shell_quote (g_get_home_dir ()); - cmd = g_strconcat ("caja --no-desktop ", path, NULL); - g_free (path); - execute (manager, cmd, FALSE, FALSE); - g_free (cmd); - break; - case SEARCH_KEY: - cmd = NULL; - if ((cmd = g_find_program_in_path ("beagle-search"))) { - execute (manager, "beagle-search", FALSE, FALSE); - } else if ((cmd = g_find_program_in_path ("tracker-search-tool"))) { - execute (manager, "tracker-search-tool", FALSE, FALSE); - } else { - execute (manager, "mate-search-tool", FALSE, FALSE); - } - g_free (cmd); - break; - case EMAIL_KEY: - do_mail_action (manager); - break; - case SCREENSAVER_KEY: - if ((cmd = g_find_program_in_path ("mate-screensaver-command"))) { - execute (manager, "mate-screensaver-command --lock", FALSE, FALSE); - } else { - execute (manager, "xscreensaver-command -lock", FALSE, FALSE); - } - - g_free (cmd); - break; - case HELP_KEY: - do_help_action (manager); - break; - case WWW_KEY: - do_www_action (manager, NULL); - break; - case MEDIA_KEY: - do_media_action (manager); - break; - case CALCULATOR_KEY: - execute (manager, "gcalctool", FALSE, FALSE); - break; - case PLAY_KEY: - return do_multimedia_player_action (manager, "Play"); - break; - case PAUSE_KEY: - return do_multimedia_player_action (manager, "Pause"); - break; - case STOP_KEY: - return do_multimedia_player_action (manager, "Stop"); - break; - case PREVIOUS_KEY: - return do_multimedia_player_action (manager, "Previous"); - break; - case NEXT_KEY: - return do_multimedia_player_action (manager, "Next"); - break; - default: - g_assert_not_reached (); - } - - return FALSE; -} - -static GdkScreen * -acme_get_screen_from_event (MsdMediaKeysManager *manager, - XAnyEvent *xanyev) -{ - GdkWindow *window; - GdkScreen *screen; - GSList *l; - - /* Look for which screen we're receiving events */ - for (l = manager->priv->screens; l != NULL; l = l->next) { - screen = (GdkScreen *) l->data; - window = gdk_screen_get_root_window (screen); - - if (GDK_WINDOW_XID (window) == xanyev->window) { - return screen; - } - } - - return NULL; -} - -static GdkFilterReturn -acme_filter_events (GdkXEvent *xevent, - GdkEvent *event, - MsdMediaKeysManager *manager) -{ - XEvent *xev = (XEvent *) xevent; - XAnyEvent *xany = (XAnyEvent *) xevent; - int i; - - /* verify we have a key event */ - if (xev->type != KeyPress && xev->type != KeyRelease) { - return GDK_FILTER_CONTINUE; - } - - for (i = 0; i < HANDLED_KEYS; i++) { - if (match_key (keys[i].key, xev)) { - switch (keys[i].key_type) { - case VOLUME_DOWN_KEY: - case VOLUME_UP_KEY: - /* auto-repeatable keys */ - if (xev->type != KeyPress) { - return GDK_FILTER_CONTINUE; - } - break; - default: - if (xev->type != KeyRelease) { - return GDK_FILTER_CONTINUE; - } - } - - manager->priv->current_screen = acme_get_screen_from_event (manager, xany); - - if (do_action (manager, keys[i].key_type) == FALSE) { - return GDK_FILTER_REMOVE; - } else { - return GDK_FILTER_CONTINUE; - } - } - } - - return GDK_FILTER_CONTINUE; -} - -static gboolean -start_media_keys_idle_cb (MsdMediaKeysManager *manager) -{ - GSList *l; - - g_debug ("Starting media_keys manager"); - mate_settings_profile_start (NULL); - manager->priv->volume_monitor = g_volume_monitor_get (); - manager->priv->conf_client = mateconf_client_get_default (); - - mateconf_client_add_dir (manager->priv->conf_client, - MATECONF_BINDING_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - - init_screens (manager); - init_kbd (manager); - - /* Start filtering the events */ - for (l = manager->priv->screens; l != NULL; l = l->next) { - mate_settings_profile_start ("gdk_window_add_filter"); - - g_debug ("adding key filter for screen: %d", - gdk_screen_get_number (l->data)); - - gdk_window_add_filter (gdk_screen_get_root_window (l->data), - (GdkFilterFunc)acme_filter_events, - manager); - mate_settings_profile_end ("gdk_window_add_filter"); - } - - mate_settings_profile_end (NULL); - - return FALSE; -} - -gboolean -msd_media_keys_manager_start (MsdMediaKeysManager *manager, - GError **error) -{ - mate_settings_profile_start (NULL); - -#ifdef HAVE_PULSE - /* initialise Volume handler - * - * We do this one here to force checking gstreamer cache, etc. - * The rest (grabbing and setting the keys) can happen in an - * idle. - */ - mate_settings_profile_start ("gvc_mixer_control_new"); - - manager->priv->volume = gvc_mixer_control_new ("MATE Volume Control Media Keys"); - - g_signal_connect (manager->priv->volume, - "ready", - G_CALLBACK (on_control_ready), - manager); - g_signal_connect (manager->priv->volume, - "default-sink-changed", - G_CALLBACK (on_control_default_sink_changed), - manager); - - gvc_mixer_control_open (manager->priv->volume); - - mate_settings_profile_end ("gvc_mixer_control_new"); -#elif defined(HAVE_GSTREAMER) - mate_settings_profile_start ("acme_volume_new"); - manager->priv->volume = acme_volume_new (); - mate_settings_profile_end ("acme_volume_new"); -#endif /* HAVE_PULSE */ - g_idle_add ((GSourceFunc) start_media_keys_idle_cb, manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_media_keys_manager_stop (MsdMediaKeysManager *manager) -{ - MsdMediaKeysManagerPrivate *priv = manager->priv; - GSList *ls; - GList *l; - int i; - gboolean need_flush; - - g_debug ("Stopping media_keys manager"); - - for (ls = priv->screens; ls != NULL; ls = ls->next) { - gdk_window_remove_filter (gdk_screen_get_root_window (ls->data), - (GdkFilterFunc) acme_filter_events, - manager); - } - - if (priv->conf_client) { - mateconf_client_remove_dir (priv->conf_client, - MATECONF_BINDING_DIR, - NULL); - - for (i = 0; i < HANDLED_KEYS; ++i) { - if (priv->notify[i] != 0) { - mateconf_client_notify_remove (priv->conf_client, priv->notify[i]); - priv->notify[i] = 0; - } - } - - g_object_unref (priv->conf_client); - priv->conf_client = NULL; - } - - if (priv->volume_monitor != NULL) { - g_object_unref (priv->volume_monitor); - priv->volume_monitor = NULL; - } - - if (priv->connection != NULL) { - dbus_g_connection_unref (priv->connection); - priv->connection = NULL; - } - - need_flush = FALSE; - gdk_error_trap_push (); - - for (i = 0; i < HANDLED_KEYS; ++i) { - if (keys[i].key) { - need_flush = TRUE; - grab_key_unsafe (keys[i].key, FALSE, priv->screens); - - g_free (keys[i].key->keycodes); - g_free (keys[i].key); - keys[i].key = NULL; - } - } - - if (need_flush) - gdk_flush (); - gdk_error_trap_pop (); - - g_slist_free (priv->screens); - priv->screens = NULL; - -#ifdef HAVE_PULSE - if (priv->stream) { - g_object_unref (priv->stream); - priv->stream = NULL; - } -#endif /* HAVE_PULSE */ - -#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) - if (priv->volume) { - g_object_unref (priv->volume); - priv->volume = NULL; - } -#endif /* defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) */ - - if (priv->dialog != NULL) { - gtk_widget_destroy (priv->dialog); - priv->dialog = NULL; - } - - for (l = priv->media_players; l; l = l->next) { - MediaPlayer *mp = l->data; - g_free (mp->application); - g_free (mp); - } - g_list_free (priv->media_players); - priv->media_players = NULL; -} - -static void -msd_media_keys_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdMediaKeysManager *self; - - self = MSD_MEDIA_KEYS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_media_keys_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdMediaKeysManager *self; - - self = MSD_MEDIA_KEYS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_media_keys_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdMediaKeysManager *media_keys_manager; - MsdMediaKeysManagerClass *klass; - - klass = MSD_MEDIA_KEYS_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_MEDIA_KEYS_MANAGER)); - - media_keys_manager = MSD_MEDIA_KEYS_MANAGER (G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (media_keys_manager); -} - -static void -msd_media_keys_manager_dispose (GObject *object) -{ - MsdMediaKeysManager *media_keys_manager; - - media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); - - G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->dispose (object); -} - -static void -msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_media_keys_manager_get_property; - object_class->set_property = msd_media_keys_manager_set_property; - object_class->constructor = msd_media_keys_manager_constructor; - object_class->dispose = msd_media_keys_manager_dispose; - object_class->finalize = msd_media_keys_manager_finalize; - - signals[MEDIA_PLAYER_KEY_PRESSED] = - g_signal_new ("media-player-key-pressed", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdMediaKeysManagerClass, media_player_key_pressed), - NULL, - NULL, - msd_marshal_VOID__STRING_STRING, - G_TYPE_NONE, - 2, - G_TYPE_STRING, - G_TYPE_STRING); - - dbus_g_object_type_install_info (MSD_TYPE_MEDIA_KEYS_MANAGER, &dbus_glib_msd_media_keys_manager_object_info); - - g_type_class_add_private (klass, sizeof (MsdMediaKeysManagerPrivate)); -} - -static void -msd_media_keys_manager_init (MsdMediaKeysManager *manager) -{ - manager->priv = MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager); - -} - -static void -msd_media_keys_manager_finalize (GObject *object) -{ - MsdMediaKeysManager *media_keys_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_MEDIA_KEYS_MANAGER (object)); - - media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); - - g_return_if_fail (media_keys_manager->priv != NULL); - - G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->finalize (object); -} - -static gboolean -register_manager (MsdMediaKeysManager *manager) -{ - GError *error = NULL; - - manager->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (manager->priv->connection == NULL) { - if (error != NULL) { - g_error ("Error getting session bus: %s", error->message); - g_error_free (error); - } - return FALSE; - } - - dbus_g_connection_register_g_object (manager->priv->connection, MSD_MEDIA_KEYS_DBUS_PATH, G_OBJECT (manager)); - - return TRUE; -} - -MsdMediaKeysManager * -msd_media_keys_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - gboolean res; - - manager_object = g_object_new (MSD_TYPE_MEDIA_KEYS_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - res = register_manager (manager_object); - if (! res) { - g_object_unref (manager_object); - return NULL; - } - } - - return MSD_MEDIA_KEYS_MANAGER (manager_object); -} diff --git a/plugins/media-keys/gsd-media-keys-manager.h b/plugins/media-keys/gsd-media-keys-manager.h deleted file mode 100644 index 96c135f..0000000 --- a/plugins/media-keys/gsd-media-keys-manager.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_MEDIA_KEYS_MANAGER_H -#define __MSD_MEDIA_KEYS_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_MEDIA_KEYS_MANAGER (msd_media_keys_manager_get_type ()) -#define MSD_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManager)) -#define MSD_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerClass)) -#define MSD_IS_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MEDIA_KEYS_MANAGER)) -#define MSD_IS_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_MANAGER)) -#define MSD_MEDIA_KEYS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerClass)) - -typedef struct MsdMediaKeysManagerPrivate MsdMediaKeysManagerPrivate; - -typedef struct -{ - GObject parent; - MsdMediaKeysManagerPrivate *priv; -} MsdMediaKeysManager; - -typedef struct -{ - GObjectClass parent_class; - void (* media_player_key_pressed) (MsdMediaKeysManager *manager, - const char *application, - const char *key); -} MsdMediaKeysManagerClass; - -GType msd_media_keys_manager_get_type (void); - -MsdMediaKeysManager * msd_media_keys_manager_new (void); -gboolean msd_media_keys_manager_start (MsdMediaKeysManager *manager, - GError **error); -void msd_media_keys_manager_stop (MsdMediaKeysManager *manager); - -gboolean msd_media_keys_manager_grab_media_player_keys (MsdMediaKeysManager *manager, - const char *application, - guint32 time, - GError **error); -gboolean msd_media_keys_manager_release_media_player_keys (MsdMediaKeysManager *manager, - const char *application, - GError **error); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_MEDIA_KEYS_MANAGER_H */ diff --git a/plugins/media-keys/gsd-media-keys-manager.xml b/plugins/media-keys/gsd-media-keys-manager.xml deleted file mode 100644 index db0552e..0000000 --- a/plugins/media-keys/gsd-media-keys-manager.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/plugins/media-keys/gsd-media-keys-plugin.c b/plugins/media-keys/gsd-media-keys-plugin.c deleted file mode 100644 index d76e233..0000000 --- a/plugins/media-keys/gsd-media-keys-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-media-keys-plugin.h" -#include "msd-media-keys-manager.h" - -struct MsdMediaKeysPluginPrivate { - MsdMediaKeysManager *manager; -}; - -#define MSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdMediaKeysPlugin, msd_media_keys_plugin) - -static void -msd_media_keys_plugin_init (MsdMediaKeysPlugin *plugin) -{ - plugin->priv = MSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdMediaKeysPlugin initializing"); - - plugin->priv->manager = msd_media_keys_manager_new (); -} - -static void -msd_media_keys_plugin_finalize (GObject *object) -{ - MsdMediaKeysPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_MEDIA_KEYS_PLUGIN (object)); - - g_debug ("MsdMediaKeysPlugin finalizing"); - - plugin = MSD_MEDIA_KEYS_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_media_keys_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating media_keys plugin"); - - error = NULL; - res = msd_media_keys_manager_start (MSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start media_keys manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating media_keys plugin"); - msd_media_keys_manager_stop (MSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager); -} - -static void -msd_media_keys_plugin_class_init (MsdMediaKeysPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_media_keys_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdMediaKeysPluginPrivate)); -} diff --git a/plugins/media-keys/gsd-media-keys-plugin.h b/plugins/media-keys/gsd-media-keys-plugin.h deleted file mode 100644 index c869d62..0000000 --- a/plugins/media-keys/gsd-media-keys-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_MEDIA_KEYS_PLUGIN_H__ -#define __MSD_MEDIA_KEYS_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_MEDIA_KEYS_PLUGIN (msd_media_keys_plugin_get_type ()) -#define MSD_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPlugin)) -#define MSD_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginClass)) -#define MSD_IS_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN)) -#define MSD_IS_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_PLUGIN)) -#define MSD_MEDIA_KEYS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginClass)) - -typedef struct MsdMediaKeysPluginPrivate MsdMediaKeysPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdMediaKeysPluginPrivate *priv; -} MsdMediaKeysPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdMediaKeysPluginClass; - -GType msd_media_keys_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_MEDIA_KEYS_PLUGIN_H__ */ diff --git a/plugins/media-keys/gsd-media-keys-window.c b/plugins/media-keys/gsd-media-keys-window.c deleted file mode 100644 index 8bd6c33..0000000 --- a/plugins/media-keys/gsd-media-keys-window.c +++ /dev/null @@ -1,714 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2006-2007 William Jon McCann - * - * - * This program 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 2, or (at your option) any later version. - * - * This program 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 this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "msd-media-keys-window.h" - -#define MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindowPrivate)) - -struct MsdMediaKeysWindowPrivate -{ - MsdMediaKeysWindowAction action; - char *icon_name; - gboolean show_level; - - guint volume_muted : 1; - int volume_level; - - GtkImage *image; - GtkWidget *progress; -}; - -G_DEFINE_TYPE (MsdMediaKeysWindow, msd_media_keys_window, MSD_TYPE_OSD_WINDOW) - -static void -volume_controls_set_visible (MsdMediaKeysWindow *window, - gboolean visible) -{ - if (window->priv->progress == NULL) - return; - - if (visible) { - gtk_widget_show (window->priv->progress); - } else { - gtk_widget_hide (window->priv->progress); - } -} - -static void -window_set_icon_name (MsdMediaKeysWindow *window, - const char *name) -{ - if (window->priv->image == NULL) - return; - - gtk_image_set_from_icon_name (window->priv->image, - name, GTK_ICON_SIZE_DIALOG); -} - -static void -action_changed (MsdMediaKeysWindow *window) -{ - if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { - switch (window->priv->action) { - case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: - volume_controls_set_visible (window, TRUE); - - if (window->priv->volume_muted) { - window_set_icon_name (window, "audio-volume-muted"); - } else { - window_set_icon_name (window, "audio-volume-high"); - } - - break; - case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: - volume_controls_set_visible (window, window->priv->show_level); - window_set_icon_name (window, window->priv->icon_name); - break; - default: - g_assert_not_reached (); - break; - } - } - - msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); -} - -static void -volume_level_changed (MsdMediaKeysWindow *window) -{ - msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); - - if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window)) && window->priv->progress != NULL) { - double fraction; - - fraction = (double) window->priv->volume_level / 100.0; - - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (window->priv->progress), - fraction); - } -} - -static void -volume_muted_changed (MsdMediaKeysWindow *window) -{ - msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); - - if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { - if (window->priv->volume_muted) { - window_set_icon_name (window, "audio-volume-muted"); - } else { - window_set_icon_name (window, "audio-volume-high"); - } - } -} - -void -msd_media_keys_window_set_action (MsdMediaKeysWindow *window, - MsdMediaKeysWindowAction action) -{ - g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); - g_return_if_fail (action == MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); - - if (window->priv->action != action) { - window->priv->action = action; - action_changed (window); - } else { - msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); - } -} - -void -msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window, - const char *icon_name, - gboolean show_level) -{ - g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); - g_return_if_fail (icon_name != NULL); - - if (window->priv->action != MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM || - g_strcmp0 (window->priv->icon_name, icon_name) != 0 || - window->priv->show_level != show_level) { - window->priv->action = MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM; - g_free (window->priv->icon_name); - window->priv->icon_name = g_strdup (icon_name); - window->priv->show_level = show_level; - action_changed (window); - } else { - msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); - } -} - -void -msd_media_keys_window_set_volume_muted (MsdMediaKeysWindow *window, - gboolean muted) -{ - g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); - - if (window->priv->volume_muted != muted) { - window->priv->volume_muted = muted; - volume_muted_changed (window); - } -} - -void -msd_media_keys_window_set_volume_level (MsdMediaKeysWindow *window, - int level) -{ - g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); - - if (window->priv->volume_level != level) { - window->priv->volume_level = level; - volume_level_changed (window); - } -} - -static GdkPixbuf * -load_pixbuf (MsdMediaKeysWindow *window, - const char *name, - int icon_size) -{ - GtkIconTheme *theme; - GdkPixbuf *pixbuf; - - if (window != NULL && gtk_widget_has_screen (GTK_WIDGET (window))) { - theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))); - } else { - theme = gtk_icon_theme_get_default (); - } - - pixbuf = gtk_icon_theme_load_icon (theme, - name, - icon_size, - GTK_ICON_LOOKUP_FORCE_SIZE, - NULL); - - return pixbuf; -} - -static void -draw_eject (cairo_t *cr, - double _x0, - double _y0, - double width, - double height) -{ - int box_height; - int tri_height; - int separation; - - box_height = height * 0.2; - separation = box_height / 3; - tri_height = height - box_height - separation; - - cairo_rectangle (cr, _x0, _y0 + height - box_height, width, box_height); - - cairo_move_to (cr, _x0, _y0 + tri_height); - cairo_rel_line_to (cr, width, 0); - cairo_rel_line_to (cr, -width / 2, -tri_height); - cairo_rel_line_to (cr, -width / 2, tri_height); - cairo_close_path (cr); - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); - cairo_fill_preserve (cr); - - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); - cairo_set_line_width (cr, 2); - cairo_stroke (cr); -} - -static void -draw_waves (cairo_t *cr, - double cx, - double cy, - double max_radius, - int volume_level) -{ - const int n_waves = 3; - int last_wave; - int i; - - last_wave = n_waves * volume_level / 100; - - for (i = 0; i < n_waves; i++) { - double angle1; - double angle2; - double radius; - double alpha; - - angle1 = -M_PI / 4; - angle2 = M_PI / 4; - - if (i < last_wave) - alpha = 1.0; - else if (i > last_wave) - alpha = 0.1; - else alpha = 0.1 + 0.9 * (n_waves * volume_level % 100) / 100.0; - - radius = (i + 1) * (max_radius / n_waves); - cairo_arc (cr, cx, cy, radius, angle1, angle2); - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, alpha / 2); - cairo_set_line_width (cr, 14); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_stroke_preserve (cr); - - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, alpha); - cairo_set_line_width (cr, 10); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_stroke (cr); - } -} - -static void -draw_cross (cairo_t *cr, - double cx, - double cy, - double size) -{ - cairo_move_to (cr, cx, cy - size/2.0); - cairo_rel_line_to (cr, size, size); - - cairo_move_to (cr, cx, cy + size/2.0); - cairo_rel_line_to (cr, size, -size); - - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); - cairo_set_line_width (cr, 14); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_stroke_preserve (cr); - - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); - cairo_set_line_width (cr, 10); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_stroke (cr); -} - -static void -draw_speaker (cairo_t *cr, - double cx, - double cy, - double width, - double height) -{ - double box_width; - double box_height; - double _x0; - double _y0; - - box_width = width / 3; - box_height = height / 3; - - _x0 = cx - (width / 2) + box_width; - _y0 = cy - box_height / 2; - - cairo_move_to (cr, _x0, _y0); - cairo_rel_line_to (cr, - box_width, 0); - cairo_rel_line_to (cr, 0, box_height); - cairo_rel_line_to (cr, box_width, 0); - - cairo_line_to (cr, cx + box_width, cy + height / 2); - cairo_rel_line_to (cr, 0, -height); - cairo_line_to (cr, _x0, _y0); - cairo_close_path (cr); - - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); - cairo_fill_preserve (cr); - - cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); - cairo_set_line_width (cr, 2); - cairo_stroke (cr); -} - -static gboolean -render_speaker (MsdMediaKeysWindow *window, - cairo_t *cr, - double _x0, - double _y0, - double width, - double height) -{ - GdkPixbuf *pixbuf; - int icon_size; - int n; - static const char *icon_names[] = { - "audio-volume-muted", - "audio-volume-low", - "audio-volume-medium", - "audio-volume-high", - NULL - }; - - if (window->priv->volume_muted) { - n = 0; - } else { - /* select image */ - n = 3 * window->priv->volume_level / 100 + 1; - if (n < 1) { - n = 1; - } else if (n > 3) { - n = 3; - } - } - - icon_size = (int)width; - - pixbuf = load_pixbuf (window, icon_names[n], icon_size); - - if (pixbuf == NULL) { - return FALSE; - } - - gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0); - cairo_paint_with_alpha (cr, MSD_OSD_WINDOW_FG_ALPHA); - - g_object_unref (pixbuf); - - return TRUE; -} - -static void -draw_volume_boxes (MsdMediaKeysWindow *window, - cairo_t *cr, - double percentage, - double _x0, - double _y0, - double width, - double height) -{ - gdouble x1; - GdkColor color; - double r, g, b; - GtkStyle *style; - - _x0 += 0.5; - _y0 += 0.5; - height = round (height) - 1; - width = round (width) - 1; - x1 = round ((width - 1) * percentage); - style = gtk_widget_get_style (GTK_WIDGET (window)); - - /* bar background */ - msd_osd_window_color_reverse (&style->dark[GTK_STATE_NORMAL], &color); - r = (float)color.red / 65535.0; - g = (float)color.green / 65535.0; - b = (float)color.blue / 65535.0; - msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height); - cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); - cairo_fill_preserve (cr); - - /* bar border */ - msd_osd_window_color_reverse (&style->light[GTK_STATE_NORMAL], &color); - r = (float)color.red / 65535.0; - g = (float)color.green / 65535.0; - b = (float)color.blue / 65535.0; - cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); - cairo_set_line_width (cr, 1); - cairo_stroke (cr); - - /* bar progress */ - if (percentage < 0.01) - return; - color = style->bg[GTK_STATE_NORMAL]; - r = (float)color.red / 65535.0; - g = (float)color.green / 65535.0; - b = (float)color.blue / 65535.0; - msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0 + 0.5, _y0 + 0.5, height / 6 - 0.5, x1, height - 1); - cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA); - cairo_fill (cr); -} - -static void -draw_action_volume (MsdMediaKeysWindow *window, - cairo_t *cr) -{ - int window_width; - int window_height; - double icon_box_width; - double icon_box_height; - double icon_box_x0; - double icon_box_y0; - double volume_box_x0; - double volume_box_y0; - double volume_box_width; - double volume_box_height; - gboolean res; - - gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height); - - icon_box_width = round (window_width * 0.65); - icon_box_height = round (window_height * 0.65); - volume_box_width = icon_box_width; - volume_box_height = round (window_height * 0.05); - - icon_box_x0 = (window_width - icon_box_width) / 2; - icon_box_y0 = (window_height - icon_box_height - volume_box_height) / 2; - volume_box_x0 = round (icon_box_x0); - volume_box_y0 = round (icon_box_height + icon_box_y0); - -#if 0 - g_message ("icon box: w=%f h=%f _x0=%f _y0=%f", - icon_box_width, - icon_box_height, - icon_box_x0, - icon_box_y0); - g_message ("volume box: w=%f h=%f _x0=%f _y0=%f", - volume_box_width, - volume_box_height, - volume_box_x0, - volume_box_y0); -#endif - - res = render_speaker (window, - cr, - icon_box_x0, icon_box_y0, - icon_box_width, icon_box_height); - if (! res) { - double speaker_width; - double speaker_height; - double speaker_cx; - double speaker_cy; - - speaker_width = icon_box_width * 0.5; - speaker_height = icon_box_height * 0.75; - speaker_cx = icon_box_x0 + speaker_width / 2; - speaker_cy = icon_box_y0 + speaker_height / 2; - -#if 0 - g_message ("speaker box: w=%f h=%f cx=%f cy=%f", - speaker_width, - speaker_height, - speaker_cx, - speaker_cy); -#endif - - /* draw speaker symbol */ - draw_speaker (cr, speaker_cx, speaker_cy, speaker_width, speaker_height); - - if (! window->priv->volume_muted) { - /* draw sound waves */ - double wave_x0; - double wave_y0; - double wave_radius; - - wave_x0 = window_width / 2; - wave_y0 = speaker_cy; - wave_radius = icon_box_width / 2; - - draw_waves (cr, wave_x0, wave_y0, wave_radius, window->priv->volume_level); - } else { - /* draw 'mute' cross */ - double cross_x0; - double cross_y0; - double cross_size; - - cross_size = speaker_width * 3 / 4; - cross_x0 = icon_box_x0 + icon_box_width - cross_size; - cross_y0 = speaker_cy; - - draw_cross (cr, cross_x0, cross_y0, cross_size); - } - } - - /* draw volume meter */ - draw_volume_boxes (window, - cr, - (double)window->priv->volume_level / 100.0, - volume_box_x0, - volume_box_y0, - volume_box_width, - volume_box_height); -} - -static gboolean -render_custom (MsdMediaKeysWindow *window, - cairo_t *cr, - double _x0, - double _y0, - double width, - double height) -{ - GdkPixbuf *pixbuf; - int icon_size; - - icon_size = (int)width; - - pixbuf = load_pixbuf (window, window->priv->icon_name, icon_size); - - if (pixbuf == NULL) { - char *name; - if (gtk_widget_get_direction (GTK_WIDGET (window)) == GTK_TEXT_DIR_RTL) - name = g_strdup_printf ("%s-rtl", window->priv->icon_name); - else - name = g_strdup_printf ("%s-ltr", window->priv->icon_name); - pixbuf = load_pixbuf (window, name, icon_size); - g_free (name); - if (pixbuf == NULL) - return FALSE; - } - - gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0); - cairo_paint_with_alpha (cr, MSD_OSD_WINDOW_FG_ALPHA); - - g_object_unref (pixbuf); - - return TRUE; -} - -static void -draw_action_custom (MsdMediaKeysWindow *window, - cairo_t *cr) -{ - int window_width; - int window_height; - double icon_box_width; - double icon_box_height; - double icon_box_x0; - double icon_box_y0; - double bright_box_x0; - double bright_box_y0; - double bright_box_width; - double bright_box_height; - gboolean res; - - gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height); - - icon_box_width = round (window_width * 0.65); - icon_box_height = round (window_height * 0.65); - bright_box_width = round (icon_box_width); - bright_box_height = round (window_height * 0.05); - - icon_box_x0 = (window_width - icon_box_width) / 2; - icon_box_y0 = (window_height - icon_box_height - bright_box_height) / 2; - bright_box_x0 = round (icon_box_x0); - bright_box_y0 = round (icon_box_height + icon_box_y0); - -#if 0 - g_message ("icon box: w=%f h=%f _x0=%f _y0=%f", - icon_box_width, - icon_box_height, - icon_box_x0, - icon_box_y0); - g_message ("brightness box: w=%f h=%f _x0=%f _y0=%f", - bright_box_width, - bright_box_height, - bright_box_x0, - bright_box_y0); -#endif - - res = render_custom (window, - cr, - icon_box_x0, icon_box_y0, - icon_box_width, icon_box_height); - if (! res && g_strcmp0 (window->priv->icon_name, "media-eject") == 0) { - /* draw eject symbol */ - draw_eject (cr, - icon_box_x0, icon_box_y0, - icon_box_width, icon_box_height); - } - - if (window->priv->show_level != FALSE) { - /* draw volume meter */ - draw_volume_boxes (window, - cr, - (double)window->priv->volume_level / 100.0, - bright_box_x0, - bright_box_y0, - bright_box_width, - bright_box_height); - } -} - -static void -msd_media_keys_window_expose_when_composited (MsdOsdWindow *osd_window, - cairo_t *cr) -{ - MsdMediaKeysWindow *window = MSD_MEDIA_KEYS_WINDOW (osd_window); - - switch (window->priv->action) { - case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: - draw_action_volume (window, cr); - break; - case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: - draw_action_custom (window, cr); - break; - default: - break; - } -} - -static void -msd_media_keys_window_class_init (MsdMediaKeysWindowClass *klass) -{ - MsdOsdWindowClass *osd_window_class = MSD_OSD_WINDOW_CLASS (klass); - - osd_window_class->expose_when_composited = msd_media_keys_window_expose_when_composited; - - g_type_class_add_private (klass, sizeof (MsdMediaKeysWindowPrivate)); -} - -static void -msd_media_keys_window_init (MsdMediaKeysWindow *window) -{ - GdkScreen *screen; - - window->priv = MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window); - - screen = gtk_widget_get_screen (GTK_WIDGET (window)); - - if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { - GtkBuilder *builder; - const gchar *objects[] = {"acme_box", NULL}; - GtkWidget *box; - - builder = gtk_builder_new (); - gtk_builder_add_objects_from_file (builder, - GTKBUILDERDIR "/acme.ui", - (char **) objects, - NULL); - - window->priv->image = GTK_IMAGE (gtk_builder_get_object (builder, "acme_image")); - window->priv->progress = GTK_WIDGET (gtk_builder_get_object (builder, "acme_volume_progressbar")); - box = GTK_WIDGET (gtk_builder_get_object (builder, "acme_box")); - - if (box != NULL) { - gtk_container_add (GTK_CONTAINER (window), box); - gtk_widget_show_all (box); - } - - /* The builder needs to stay alive until the window - takes ownership of the box (and its children) */ - g_object_unref (builder); - } -} - -GtkWidget * -msd_media_keys_window_new (void) -{ - return g_object_new (MSD_TYPE_MEDIA_KEYS_WINDOW, NULL); -} diff --git a/plugins/media-keys/gsd-media-keys-window.h b/plugins/media-keys/gsd-media-keys-window.h deleted file mode 100644 index c0e5739..0000000 --- a/plugins/media-keys/gsd-media-keys-window.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- - * - * Copyright (C) 2006 William Jon McCann - * - * This program 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 2, or (at your option) any later version. - * - * This program 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 this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - -#ifndef MSD_MEDIA_KEYS_WINDOW_H -#define MSD_MEDIA_KEYS_WINDOW_H - -#include -#include - -#include "msd-osd-window.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_MEDIA_KEYS_WINDOW (msd_media_keys_window_get_type ()) -#define MSD_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindow)) -#define MSD_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindowClass)) -#define MSD_IS_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_MEDIA_KEYS_WINDOW)) -#define MSD_IS_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_MEDIA_KEYS_WINDOW)) - -typedef struct MsdMediaKeysWindow MsdMediaKeysWindow; -typedef struct MsdMediaKeysWindowClass MsdMediaKeysWindowClass; -typedef struct MsdMediaKeysWindowPrivate MsdMediaKeysWindowPrivate; - -struct MsdMediaKeysWindow { - MsdOsdWindow parent; - - MsdMediaKeysWindowPrivate *priv; -}; - -struct MsdMediaKeysWindowClass { - MsdOsdWindowClass parent_class; -}; - -typedef enum { - MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME, - MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM -} MsdMediaKeysWindowAction; - -GType msd_media_keys_window_get_type (void); - -GtkWidget * msd_media_keys_window_new (void); -void msd_media_keys_window_set_action (MsdMediaKeysWindow *window, - MsdMediaKeysWindowAction action); -void msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window, - const char *icon_name, - gboolean show_level); -void msd_media_keys_window_set_volume_muted (MsdMediaKeysWindow *window, - gboolean muted); -void msd_media_keys_window_set_volume_level (MsdMediaKeysWindow *window, - int level); -gboolean msd_media_keys_window_is_valid (MsdMediaKeysWindow *window); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/plugins/media-keys/msd-marshal.list b/plugins/media-keys/msd-marshal.list new file mode 100644 index 0000000..72f9937 --- /dev/null +++ b/plugins/media-keys/msd-marshal.list @@ -0,0 +1 @@ +VOID:STRING,STRING diff --git a/plugins/media-keys/msd-media-keys-manager.c b/plugins/media-keys/msd-media-keys-manager.c new file mode 100644 index 0000000..d7e1b04 --- /dev/null +++ b/plugins/media-keys/msd-media-keys-manager.c @@ -0,0 +1,1447 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2001-2003 Bastien Nocera + * Copyright (C) 2006-2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "mate-settings-profile.h" +#include "msd-marshal.h" +#include "msd-media-keys-manager.h" +#include "msd-media-keys-manager-glue.h" + +#include "eggaccelerators.h" +#include "acme.h" +#include "msd-media-keys-window.h" + +#ifdef HAVE_PULSE +#include +#include "gvc-mixer-control.h" +#elif defined(HAVE_GSTREAMER) +#include "gvc-gstreamer-acme-vol.h" +#endif /* HAVE_PULSE */ + +#define MSD_DBUS_PATH "/org/mate/SettingsDaemon" +#define MSD_DBUS_NAME "org.mate.SettingsDaemon" +#define MSD_MEDIA_KEYS_DBUS_PATH MSD_DBUS_PATH "/MediaKeys" +#define MSD_MEDIA_KEYS_DBUS_NAME MSD_DBUS_NAME ".MediaKeys" + +#define TOUCHPAD_ENABLED_KEY "/desktop/mate/peripherals/touchpad/touchpad_enabled" + +#define VOLUME_STEP 6 /* percents for one volume button press */ +#define MAX_VOLUME 65536.0 + +#define MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerPrivate)) + +typedef struct { + char *application; + guint32 time; +} MediaPlayer; + +struct MsdMediaKeysManagerPrivate +{ +#ifdef HAVE_PULSE + /* Volume bits */ + GvcMixerControl *volume; + GvcMixerStream *stream; +#elif defined(HAVE_GSTREAMER) + AcmeVolume *volume; +#endif /* HAVE_PULSE */ + GtkWidget *dialog; + MateConfClient *conf_client; + GVolumeMonitor *volume_monitor; + + /* Multihead stuff */ + GdkScreen *current_screen; + GSList *screens; + + GList *media_players; + + DBusGConnection *connection; + guint notify[HANDLED_KEYS]; +}; + +enum { + MEDIA_PLAYER_KEY_PRESSED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +static void msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass); +static void msd_media_keys_manager_init (MsdMediaKeysManager *media_keys_manager); +static void msd_media_keys_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdMediaKeysManager, msd_media_keys_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + + +static void +init_screens (MsdMediaKeysManager *manager) +{ + GdkDisplay *display; + int i; + + display = gdk_display_get_default (); + for (i = 0; i < gdk_display_get_n_screens (display); i++) { + GdkScreen *screen; + + screen = gdk_display_get_screen (display, i); + if (screen == NULL) { + continue; + } + manager->priv->screens = g_slist_append (manager->priv->screens, screen); + } + + manager->priv->current_screen = manager->priv->screens->data; +} + + +static void +acme_error (char * msg) +{ + GtkWidget *error_dialog; + + error_dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + msg, NULL); + gtk_dialog_set_default_response (GTK_DIALOG (error_dialog), + GTK_RESPONSE_OK); + gtk_widget_show (error_dialog); + g_signal_connect (error_dialog, + "response", + G_CALLBACK (gtk_widget_destroy), + NULL); +} + +static char * +get_term_command (MsdMediaKeysManager *manager) +{ + char *cmd_term; + char *cmd = NULL; + + cmd_term = mateconf_client_get_string (manager->priv->conf_client, + "/desktop/mate/applications/terminal/exec", NULL); + if ((cmd_term != NULL) && (strcmp (cmd_term, "") != 0)) { + char *cmd_args; + cmd_args = mateconf_client_get_string (manager->priv->conf_client, + "/desktop/mate/applications/terminal/exec_arg", NULL); + if ((cmd_args != NULL) && (strcmp (cmd_term, "") != 0)) { + cmd = g_strdup_printf ("%s %s -e", cmd_term, cmd_args); + } else { + cmd = g_strdup_printf ("%s -e", cmd_term); + } + + g_free (cmd_args); + } + + g_free (cmd_term); + + return cmd; +} + +static void +execute (MsdMediaKeysManager *manager, + char *cmd, + gboolean sync, + gboolean need_term) +{ + gboolean retval; + char **argv; + int argc; + char *exec; + char *term = NULL; + + retval = FALSE; + + if (need_term) { + term = get_term_command (manager); + if (term == NULL) { + acme_error (_("Could not get default terminal. Verify that your default " + "terminal command is set and points to a valid application.")); + return; + } + } + + if (term) { + exec = g_strdup_printf ("%s %s", term, cmd); + g_free (term); + } else { + exec = g_strdup (cmd); + } + + if (g_shell_parse_argv (exec, &argc, &argv, NULL)) { + if (sync != FALSE) { + retval = g_spawn_sync (g_get_home_dir (), + argv, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL); + } else { + retval = g_spawn_async (g_get_home_dir (), + argv, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, + NULL, + NULL, + NULL); + } + g_strfreev (argv); + } + + if (retval == FALSE) { + char *msg; + msg = g_strdup_printf (_("Couldn't execute command: %s\n" + "Verify that this is a valid command."), + exec); + + acme_error (msg); + g_free (msg); + } + g_free (exec); +} + +static void +dialog_init (MsdMediaKeysManager *manager) +{ + if (manager->priv->dialog != NULL + && !msd_osd_window_is_valid (MSD_OSD_WINDOW (manager->priv->dialog))) { + gtk_widget_destroy (manager->priv->dialog); + manager->priv->dialog = NULL; + } + + if (manager->priv->dialog == NULL) { + manager->priv->dialog = msd_media_keys_window_new (); + } +} + +static gboolean +is_valid_shortcut (const char *string) +{ + if (string == NULL || string[0] == '\0') { + return FALSE; + } + if (strcmp (string, "disabled") == 0) { + return FALSE; + } + + return TRUE; +} + +static void +update_kbd_cb (MateConfClient *client, + guint id, + MateConfEntry *entry, + MsdMediaKeysManager *manager) +{ + int i; + gboolean need_flush = TRUE; + + g_return_if_fail (entry->key != NULL); + + gdk_error_trap_push (); + + /* Find the key that was modified */ + for (i = 0; i < HANDLED_KEYS; i++) { + if (strcmp (entry->key, keys[i].mateconf_key) == 0) { + char *tmp; + Key *key; + + if (keys[i].key != NULL) { + need_flush = TRUE; + grab_key_unsafe (keys[i].key, FALSE, manager->priv->screens); + } + + g_free (keys[i].key); + keys[i].key = NULL; + + tmp = mateconf_client_get_string (manager->priv->conf_client, + keys[i].mateconf_key, NULL); + + if (is_valid_shortcut (tmp) == FALSE) { + g_free (tmp); + break; + } + + key = g_new0 (Key, 1); + if (!egg_accelerator_parse_virtual (tmp, &key->keysym, &key->keycodes, &key->state)) { + g_free (tmp); + g_free (key); + break; + } + + need_flush = TRUE; + grab_key_unsafe (key, TRUE, manager->priv->screens); + keys[i].key = key; + + g_free (tmp); + + break; + } + } + + if (need_flush) + gdk_flush (); + if (gdk_error_trap_pop ()) + g_warning ("Grab failed for some keys, another application may already have access the them."); +} + +static void init_kbd(MsdMediaKeysManager* manager) +{ + int i; + gboolean need_flush = FALSE; + + mate_settings_profile_start(NULL); + + gdk_error_trap_push(); + + for (i = 0; i < HANDLED_KEYS; i++) + { + char* tmp; + Key* key; + + manager->priv->notify[i] = mateconf_client_notify_add(manager->priv->conf_client, + keys[i].mateconf_key, + (MateConfClientNotifyFunc) update_kbd_cb, + manager, + NULL, + NULL); + + tmp = mateconf_client_get_string(manager->priv->conf_client, + keys[i].mateconf_key, + NULL); + + if (!is_valid_shortcut(tmp)) + { + g_debug("Not a valid shortcut: '%s'", tmp); + g_free(tmp); + continue; + } + + key = g_new0(Key, 1); + + if (!egg_accelerator_parse_virtual(tmp, &key->keysym, &key->keycodes, &key->state)) + { + g_debug("Unable to parse: '%s'", tmp); + g_free(tmp); + g_free(key); + continue; + } + + g_free(tmp); + + keys[i].key = key; + + need_flush = TRUE; + grab_key_unsafe(key, TRUE, manager->priv->screens); + } + + if (need_flush) + { + gdk_flush(); + } + + if (gdk_error_trap_pop ()) + { + g_warning("Grab failed for some keys, another application may already have access the them."); + } + + mate_settings_profile_end(NULL); +} + +static void +dialog_show (MsdMediaKeysManager *manager) +{ + int orig_w; + int orig_h; + int screen_w; + int screen_h; + int x; + int y; + int pointer_x; + int pointer_y; + GtkRequisition win_req; + GdkScreen *pointer_screen; + GdkRectangle geometry; + int monitor; + + gtk_window_set_screen (GTK_WINDOW (manager->priv->dialog), + manager->priv->current_screen); + + /* + * get the window size + * if the window hasn't been mapped, it doesn't necessarily + * know its true size, yet, so we need to jump through hoops + */ + gtk_window_get_default_size (GTK_WINDOW (manager->priv->dialog), &orig_w, &orig_h); + gtk_widget_size_request (manager->priv->dialog, &win_req); + + if (win_req.width > orig_w) { + orig_w = win_req.width; + } + if (win_req.height > orig_h) { + orig_h = win_req.height; + } + + pointer_screen = NULL; + gdk_display_get_pointer (gdk_screen_get_display (manager->priv->current_screen), + &pointer_screen, + &pointer_x, + &pointer_y, + NULL); + if (pointer_screen != manager->priv->current_screen) { + /* The pointer isn't on the current screen, so just + * assume the default monitor + */ + monitor = 0; + } else { + monitor = gdk_screen_get_monitor_at_point (manager->priv->current_screen, + pointer_x, + pointer_y); + } + + gdk_screen_get_monitor_geometry (manager->priv->current_screen, + monitor, + &geometry); + + screen_w = geometry.width; + screen_h = geometry.height; + + x = ((screen_w - orig_w) / 2) + geometry.x; + y = geometry.y + (screen_h / 2) + (screen_h / 2 - orig_h) / 2; + + gtk_window_move (GTK_WINDOW (manager->priv->dialog), x, y); + + gtk_widget_show (manager->priv->dialog); + + gdk_display_sync (gdk_screen_get_display (manager->priv->current_screen)); +} + +static void +do_unknown_action (MsdMediaKeysManager *manager, + const char *url) +{ + char *string; + + g_return_if_fail (url != NULL); + + string = mateconf_client_get_string (manager->priv->conf_client, + "/desktop/mate/url-handlers/unknown/command", + NULL); + + if ((string != NULL) && (strcmp (string, "") != 0)) { + char *cmd; + cmd = g_strdup_printf (string, url); + execute (manager, cmd, FALSE, FALSE); + g_free (cmd); + } + g_free (string); +} + +static void +do_help_action (MsdMediaKeysManager *manager) +{ + char *string; + + string = mateconf_client_get_string (manager->priv->conf_client, + "/desktop/mate/url-handlers/ghelp/command", + NULL); + + if ((string != NULL) && (strcmp (string, "") != 0)) { + char *cmd; + cmd = g_strdup_printf (string, ""); + execute (manager, cmd, FALSE, FALSE); + g_free (cmd); + } else { + do_unknown_action (manager, "ghelp:"); + } + + g_free (string); +} + +static void +do_mail_action (MsdMediaKeysManager *manager) +{ + char *string; + + string = mateconf_client_get_string (manager->priv->conf_client, + "/desktop/mate/url-handlers/mailto/command", + NULL); + + if ((string != NULL) && (strcmp (string, "") != 0)) { + char *cmd; + cmd = g_strdup_printf (string, ""); + execute (manager, + cmd, + FALSE, + mateconf_client_get_bool (manager->priv->conf_client, + "/desktop/mate/url-handlers/mailto/needs_terminal", NULL)); + g_free (cmd); + } + g_free (string); +} + +static void +do_media_action (MsdMediaKeysManager *manager) +{ + char *command; + + command = mateconf_client_get_string (manager->priv->conf_client, + "/desktop/mate/applications/media/exec", NULL); + if ((command != NULL) && (strcmp (command, "") != 0)) { + execute (manager, + command, + FALSE, + mateconf_client_get_bool (manager->priv->conf_client, + "/desktop/mate/applications/media/needs_term", NULL)); + } + g_free (command); +} + +static void +do_www_action (MsdMediaKeysManager *manager, + const char *url) +{ + char *string; + + string = mateconf_client_get_string (manager->priv->conf_client, + "/desktop/mate/url-handlers/http/command", + NULL); + + if ((string != NULL) && (strcmp (string, "") != 0)) { + gchar *cmd; + + if (url == NULL) { + cmd = g_strdup_printf (string, ""); + } else { + cmd = g_strdup_printf (string, url); + } + + execute (manager, + cmd, + FALSE, + mateconf_client_get_bool (manager->priv->conf_client, + "/desktop/mate/url-handlers/http/needs_terminal", NULL)); + g_free (cmd); + } else { + do_unknown_action (manager, url ? url : ""); + } + g_free (string); +} + +static void +do_exit_action (MsdMediaKeysManager *manager) +{ + execute (manager, "mate-session-save --shutdown-dialog", FALSE, FALSE); +} + +static void +do_eject_action_cb (GDrive *drive, + GAsyncResult *res, + MsdMediaKeysManager *manager) +{ + g_drive_eject_with_operation_finish (drive, res, NULL); +} + +#define NO_SCORE 0 +#define SCORE_CAN_EJECT 50 +#define SCORE_HAS_MEDIA 100 +static void +do_eject_action (MsdMediaKeysManager *manager) +{ + GList *drives, *l; + GDrive *fav_drive; + guint score; + + /* Find the best drive to eject */ + fav_drive = NULL; + score = NO_SCORE; + drives = g_volume_monitor_get_connected_drives (manager->priv->volume_monitor); + for (l = drives; l != NULL; l = l->next) { + GDrive *drive = l->data; + + if (g_drive_can_eject (drive) == FALSE) + continue; + if (g_drive_is_media_removable (drive) == FALSE) + continue; + if (score < SCORE_CAN_EJECT) { + fav_drive = drive; + score = SCORE_CAN_EJECT; + } + if (g_drive_has_media (drive) == FALSE) + continue; + if (score < SCORE_HAS_MEDIA) { + fav_drive = drive; + score = SCORE_HAS_MEDIA; + break; + } + } + + /* Show the dialogue */ + dialog_init (manager); + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + "media-eject", + FALSE); + dialog_show (manager); + + /* Clean up the drive selection and exit if no suitable + * drives are found */ + if (fav_drive != NULL) + fav_drive = g_object_ref (fav_drive); + + g_list_foreach (drives, (GFunc) g_object_unref, NULL); + if (fav_drive == NULL) + return; + + /* Eject! */ + g_drive_eject_with_operation (fav_drive, G_MOUNT_UNMOUNT_FORCE, + NULL, NULL, + (GAsyncReadyCallback) do_eject_action_cb, + manager); + g_object_unref (fav_drive); +} + +static void +do_touchpad_action (MsdMediaKeysManager *manager) +{ + MateConfClient *client = manager->priv->conf_client; + gboolean state = mateconf_client_get_bool (client, TOUCHPAD_ENABLED_KEY, NULL); + + dialog_init (manager); + msd_media_keys_window_set_action_custom (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + (!state) ? "touchpad-enabled" : "touchpad-disabled", + FALSE); + dialog_show (manager); + + mateconf_client_set_bool (client, TOUCHPAD_ENABLED_KEY, !state, NULL); +} + +#ifdef HAVE_PULSE +static void +update_dialog (MsdMediaKeysManager *manager, + guint vol, + gboolean muted, + gboolean sound_changed) +{ + vol = (int) (100 * (double) vol / PA_VOLUME_NORM); + vol = CLAMP (vol, 0, 100); + + dialog_init (manager); + msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + muted); + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), vol); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + dialog_show (manager); + + if (sound_changed != FALSE && muted == FALSE) + ca_gtk_play_for_widget (manager->priv->dialog, 0, + CA_PROP_EVENT_ID, "audio-volume-change", + CA_PROP_EVENT_DESCRIPTION, "volume changed through key press", + CA_PROP_APPLICATION_ID, "org.mate.VolumeControl", + NULL); +} +#endif /* HAVE_PULSE */ + +#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) +static void +do_sound_action (MsdMediaKeysManager *manager, + int type) +{ + gboolean muted; + guint vol, norm_vol_step; + int vol_step; + gboolean sound_changed; + +#ifdef HAVE_PULSE + if (manager->priv->stream == NULL) + return; +#elif defined(HAVE_GSTREAMER) + if (manager->priv->volume == NULL) + return; +#endif + + vol_step = mateconf_client_get_int (manager->priv->conf_client, + MATECONF_MISC_DIR "/volume_step", + NULL); + + if (vol_step <= 0 || vol_step > 100) + vol_step = VOLUME_STEP; + +#ifdef HAVE_PULSE + norm_vol_step = PA_VOLUME_NORM * vol_step / 100; + + /* FIXME: this is racy */ + vol = gvc_mixer_stream_get_volume (manager->priv->stream); + muted = gvc_mixer_stream_get_is_muted (manager->priv->stream); +#else + if (vol_step > 0) { + gint threshold = acme_volume_get_threshold (manager->priv->volume); + if (vol_step < threshold) + vol_step = threshold; + g_debug ("Using volume step of %d", vol_step); + } + vol = acme_volume_get_volume (manager->priv->volume); + muted = acme_volume_get_mute (manager->priv->volume); +#endif + sound_changed = FALSE; + + switch (type) { + case MUTE_KEY: +#ifdef HAVE_PULSE + muted = !muted; + gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); + sound_changed = TRUE; +#else + acme_volume_mute_toggle (manager->priv->volume); +#endif + break; + case VOLUME_DOWN_KEY: +#ifdef HAVE_PULSE + if (!muted && (vol <= norm_vol_step)) { + muted = !muted; + vol = 0; + gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); + if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { + gvc_mixer_stream_push_volume (manager->priv->stream); + sound_changed = TRUE; + } + } else if (!muted) { + vol = vol - norm_vol_step; + if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { + gvc_mixer_stream_push_volume (manager->priv->stream); + sound_changed = TRUE; + } + } +#else + if (!muted && (vol <= vol_step)) + acme_volume_mute_toggle (manager->priv->volume); + acme_volume_set_volume (manager->priv->volume, vol - vol_step); +#endif + break; + case VOLUME_UP_KEY: + if (muted) { + muted = !muted; + if (vol == 0) { +#ifdef HAVE_PULSE + vol = vol + norm_vol_step; + gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); + if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { + gvc_mixer_stream_push_volume (manager->priv->stream); + sound_changed = TRUE; + } + } else { + gvc_mixer_stream_change_is_muted (manager->priv->stream, muted); + sound_changed = TRUE; + } +#else + /* We need to unmute otherwise vol is blocked (and muted) */ + acme_volume_set_mute (manager->priv->volume, FALSE); + } + acme_volume_set_volume (manager->priv->volume, vol + vol_step); +#endif + } else { +#ifdef HAVE_PULSE + if (vol < MAX_VOLUME) { + if (vol + norm_vol_step >= MAX_VOLUME) { + vol = MAX_VOLUME; + } else { + vol = vol + norm_vol_step; + } + if (gvc_mixer_stream_set_volume (manager->priv->stream, vol) != FALSE) { + gvc_mixer_stream_push_volume (manager->priv->stream); + sound_changed = TRUE; + } + } +#else + acme_volume_set_volume (manager->priv->volume, vol + vol_step); +#endif + } + break; + } + +#ifdef HAVE_PULSE + update_dialog (manager, vol, muted, sound_changed); +#else + muted = acme_volume_get_mute (manager->priv->volume); + vol = acme_volume_get_volume (manager->priv->volume); + + /* FIXME: AcmeVolume should probably emit signals + instead of doing it like this */ + dialog_init (manager); + msd_media_keys_window_set_volume_muted (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + muted); + msd_media_keys_window_set_volume_level (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + vol); + msd_media_keys_window_set_action (MSD_MEDIA_KEYS_WINDOW (manager->priv->dialog), + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + dialog_show (manager); +#endif /* HAVE_PULSE */ +} +#endif /* defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) */ + +#ifdef HAVE_PULSE +static void +update_default_sink (MsdMediaKeysManager *manager) +{ + GvcMixerStream *stream; + + stream = gvc_mixer_control_get_default_sink (manager->priv->volume); + if (stream == manager->priv->stream) + return; + + if (manager->priv->stream != NULL) { + g_object_unref (manager->priv->stream); + manager->priv->stream = NULL; + } + + if (stream != NULL) { + manager->priv->stream = g_object_ref (stream); + } else { + g_warning ("Unable to get default sink"); + } +} + +static void +on_control_ready (GvcMixerControl *control, + MsdMediaKeysManager *manager) +{ + update_default_sink (manager); +} + +static void +on_control_default_sink_changed (GvcMixerControl *control, + guint id, + MsdMediaKeysManager *manager) +{ + update_default_sink (manager); +} + +#endif /* HAVE_PULSE */ + +static gint +find_by_application (gconstpointer a, + gconstpointer b) +{ + return strcmp (((MediaPlayer *)a)->application, b); +} + +static gint +find_by_time (gconstpointer a, + gconstpointer b) +{ + return ((MediaPlayer *)a)->time < ((MediaPlayer *)b)->time; +} + +/* + * Register a new media player. Most applications will want to call + * this with time = GDK_CURRENT_TIME. This way, the last registered + * player will receive media events. In some cases, applications + * may want to register with a lower priority (usually 1), to grab + * events only nobody is interested. + */ +gboolean +msd_media_keys_manager_grab_media_player_keys (MsdMediaKeysManager *manager, + const char *application, + guint32 time, + GError **error) +{ + GList *iter; + MediaPlayer *media_player; + + if (time == GDK_CURRENT_TIME) { + GTimeVal tv; + + g_get_current_time (&tv); + time = tv.tv_sec * 1000 + tv.tv_usec / 1000; + } + + iter = g_list_find_custom (manager->priv->media_players, + application, + find_by_application); + + if (iter != NULL) { + if (((MediaPlayer *)iter->data)->time < time) { + g_free (((MediaPlayer *)iter->data)->application); + g_free (iter->data); + manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); + } else { + return TRUE; + } + } + + g_debug ("Registering %s at %u", application, time); + media_player = g_new0 (MediaPlayer, 1); + media_player->application = g_strdup (application); + media_player->time = time; + + manager->priv->media_players = g_list_insert_sorted (manager->priv->media_players, + media_player, + find_by_time); + + return TRUE; +} + +gboolean +msd_media_keys_manager_release_media_player_keys (MsdMediaKeysManager *manager, + const char *application, + GError **error) +{ + GList *iter; + + iter = g_list_find_custom (manager->priv->media_players, + application, + find_by_application); + + if (iter != NULL) { + g_debug ("Deregistering %s", application); + g_free (((MediaPlayer *)iter->data)->application); + g_free (iter->data); + manager->priv->media_players = g_list_delete_link (manager->priv->media_players, iter); + } + + return TRUE; +} + +static gboolean +msd_media_player_key_pressed (MsdMediaKeysManager *manager, + const char *key) +{ + const char *application = NULL; + gboolean have_listeners; + + have_listeners = (manager->priv->media_players != NULL); + + if (have_listeners) { + application = ((MediaPlayer *)manager->priv->media_players->data)->application; + } + + g_signal_emit (manager, signals[MEDIA_PLAYER_KEY_PRESSED], 0, application, key); + + return !have_listeners; +} + +static gboolean +do_multimedia_player_action (MsdMediaKeysManager *manager, + const char *key) +{ + return msd_media_player_key_pressed (manager, key); +} + +static gboolean +do_action (MsdMediaKeysManager *manager, + int type) +{ + char *cmd; + char *path; + + switch (type) { + case TOUCHPAD_KEY: + do_touchpad_action (manager); + break; + case MUTE_KEY: + case VOLUME_DOWN_KEY: + case VOLUME_UP_KEY: +#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) + do_sound_action (manager, type); +#endif /* HAVE_PULSE || HAVE_GSTREAMER */ + break; + case POWER_KEY: + do_exit_action (manager); + break; + case EJECT_KEY: + do_eject_action (manager); + break; + case HOME_KEY: + path = g_shell_quote (g_get_home_dir ()); + cmd = g_strconcat ("caja --no-desktop ", path, NULL); + g_free (path); + execute (manager, cmd, FALSE, FALSE); + g_free (cmd); + break; + case SEARCH_KEY: + cmd = NULL; + if ((cmd = g_find_program_in_path ("beagle-search"))) { + execute (manager, "beagle-search", FALSE, FALSE); + } else if ((cmd = g_find_program_in_path ("tracker-search-tool"))) { + execute (manager, "tracker-search-tool", FALSE, FALSE); + } else { + execute (manager, "mate-search-tool", FALSE, FALSE); + } + g_free (cmd); + break; + case EMAIL_KEY: + do_mail_action (manager); + break; + case SCREENSAVER_KEY: + if ((cmd = g_find_program_in_path ("mate-screensaver-command"))) { + execute (manager, "mate-screensaver-command --lock", FALSE, FALSE); + } else { + execute (manager, "xscreensaver-command -lock", FALSE, FALSE); + } + + g_free (cmd); + break; + case HELP_KEY: + do_help_action (manager); + break; + case WWW_KEY: + do_www_action (manager, NULL); + break; + case MEDIA_KEY: + do_media_action (manager); + break; + case CALCULATOR_KEY: + execute (manager, "gcalctool", FALSE, FALSE); + break; + case PLAY_KEY: + return do_multimedia_player_action (manager, "Play"); + break; + case PAUSE_KEY: + return do_multimedia_player_action (manager, "Pause"); + break; + case STOP_KEY: + return do_multimedia_player_action (manager, "Stop"); + break; + case PREVIOUS_KEY: + return do_multimedia_player_action (manager, "Previous"); + break; + case NEXT_KEY: + return do_multimedia_player_action (manager, "Next"); + break; + default: + g_assert_not_reached (); + } + + return FALSE; +} + +static GdkScreen * +acme_get_screen_from_event (MsdMediaKeysManager *manager, + XAnyEvent *xanyev) +{ + GdkWindow *window; + GdkScreen *screen; + GSList *l; + + /* Look for which screen we're receiving events */ + for (l = manager->priv->screens; l != NULL; l = l->next) { + screen = (GdkScreen *) l->data; + window = gdk_screen_get_root_window (screen); + + if (GDK_WINDOW_XID (window) == xanyev->window) { + return screen; + } + } + + return NULL; +} + +static GdkFilterReturn +acme_filter_events (GdkXEvent *xevent, + GdkEvent *event, + MsdMediaKeysManager *manager) +{ + XEvent *xev = (XEvent *) xevent; + XAnyEvent *xany = (XAnyEvent *) xevent; + int i; + + /* verify we have a key event */ + if (xev->type != KeyPress && xev->type != KeyRelease) { + return GDK_FILTER_CONTINUE; + } + + for (i = 0; i < HANDLED_KEYS; i++) { + if (match_key (keys[i].key, xev)) { + switch (keys[i].key_type) { + case VOLUME_DOWN_KEY: + case VOLUME_UP_KEY: + /* auto-repeatable keys */ + if (xev->type != KeyPress) { + return GDK_FILTER_CONTINUE; + } + break; + default: + if (xev->type != KeyRelease) { + return GDK_FILTER_CONTINUE; + } + } + + manager->priv->current_screen = acme_get_screen_from_event (manager, xany); + + if (do_action (manager, keys[i].key_type) == FALSE) { + return GDK_FILTER_REMOVE; + } else { + return GDK_FILTER_CONTINUE; + } + } + } + + return GDK_FILTER_CONTINUE; +} + +static gboolean +start_media_keys_idle_cb (MsdMediaKeysManager *manager) +{ + GSList *l; + + g_debug ("Starting media_keys manager"); + mate_settings_profile_start (NULL); + manager->priv->volume_monitor = g_volume_monitor_get (); + manager->priv->conf_client = mateconf_client_get_default (); + + mateconf_client_add_dir (manager->priv->conf_client, + MATECONF_BINDING_DIR, + MATECONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + + init_screens (manager); + init_kbd (manager); + + /* Start filtering the events */ + for (l = manager->priv->screens; l != NULL; l = l->next) { + mate_settings_profile_start ("gdk_window_add_filter"); + + g_debug ("adding key filter for screen: %d", + gdk_screen_get_number (l->data)); + + gdk_window_add_filter (gdk_screen_get_root_window (l->data), + (GdkFilterFunc)acme_filter_events, + manager); + mate_settings_profile_end ("gdk_window_add_filter"); + } + + mate_settings_profile_end (NULL); + + return FALSE; +} + +gboolean +msd_media_keys_manager_start (MsdMediaKeysManager *manager, + GError **error) +{ + mate_settings_profile_start (NULL); + +#ifdef HAVE_PULSE + /* initialise Volume handler + * + * We do this one here to force checking gstreamer cache, etc. + * The rest (grabbing and setting the keys) can happen in an + * idle. + */ + mate_settings_profile_start ("gvc_mixer_control_new"); + + manager->priv->volume = gvc_mixer_control_new ("MATE Volume Control Media Keys"); + + g_signal_connect (manager->priv->volume, + "ready", + G_CALLBACK (on_control_ready), + manager); + g_signal_connect (manager->priv->volume, + "default-sink-changed", + G_CALLBACK (on_control_default_sink_changed), + manager); + + gvc_mixer_control_open (manager->priv->volume); + + mate_settings_profile_end ("gvc_mixer_control_new"); +#elif defined(HAVE_GSTREAMER) + mate_settings_profile_start ("acme_volume_new"); + manager->priv->volume = acme_volume_new (); + mate_settings_profile_end ("acme_volume_new"); +#endif /* HAVE_PULSE */ + g_idle_add ((GSourceFunc) start_media_keys_idle_cb, manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_media_keys_manager_stop (MsdMediaKeysManager *manager) +{ + MsdMediaKeysManagerPrivate *priv = manager->priv; + GSList *ls; + GList *l; + int i; + gboolean need_flush; + + g_debug ("Stopping media_keys manager"); + + for (ls = priv->screens; ls != NULL; ls = ls->next) { + gdk_window_remove_filter (gdk_screen_get_root_window (ls->data), + (GdkFilterFunc) acme_filter_events, + manager); + } + + if (priv->conf_client) { + mateconf_client_remove_dir (priv->conf_client, + MATECONF_BINDING_DIR, + NULL); + + for (i = 0; i < HANDLED_KEYS; ++i) { + if (priv->notify[i] != 0) { + mateconf_client_notify_remove (priv->conf_client, priv->notify[i]); + priv->notify[i] = 0; + } + } + + g_object_unref (priv->conf_client); + priv->conf_client = NULL; + } + + if (priv->volume_monitor != NULL) { + g_object_unref (priv->volume_monitor); + priv->volume_monitor = NULL; + } + + if (priv->connection != NULL) { + dbus_g_connection_unref (priv->connection); + priv->connection = NULL; + } + + need_flush = FALSE; + gdk_error_trap_push (); + + for (i = 0; i < HANDLED_KEYS; ++i) { + if (keys[i].key) { + need_flush = TRUE; + grab_key_unsafe (keys[i].key, FALSE, priv->screens); + + g_free (keys[i].key->keycodes); + g_free (keys[i].key); + keys[i].key = NULL; + } + } + + if (need_flush) + gdk_flush (); + gdk_error_trap_pop (); + + g_slist_free (priv->screens); + priv->screens = NULL; + +#ifdef HAVE_PULSE + if (priv->stream) { + g_object_unref (priv->stream); + priv->stream = NULL; + } +#endif /* HAVE_PULSE */ + +#if defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) + if (priv->volume) { + g_object_unref (priv->volume); + priv->volume = NULL; + } +#endif /* defined(HAVE_PULSE) || defined(HAVE_GSTREAMER) */ + + if (priv->dialog != NULL) { + gtk_widget_destroy (priv->dialog); + priv->dialog = NULL; + } + + for (l = priv->media_players; l; l = l->next) { + MediaPlayer *mp = l->data; + g_free (mp->application); + g_free (mp); + } + g_list_free (priv->media_players); + priv->media_players = NULL; +} + +static void +msd_media_keys_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdMediaKeysManager *self; + + self = MSD_MEDIA_KEYS_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_media_keys_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdMediaKeysManager *self; + + self = MSD_MEDIA_KEYS_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_media_keys_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdMediaKeysManager *media_keys_manager; + MsdMediaKeysManagerClass *klass; + + klass = MSD_MEDIA_KEYS_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_MEDIA_KEYS_MANAGER)); + + media_keys_manager = MSD_MEDIA_KEYS_MANAGER (G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (media_keys_manager); +} + +static void +msd_media_keys_manager_dispose (GObject *object) +{ + MsdMediaKeysManager *media_keys_manager; + + media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); + + G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->dispose (object); +} + +static void +msd_media_keys_manager_class_init (MsdMediaKeysManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_media_keys_manager_get_property; + object_class->set_property = msd_media_keys_manager_set_property; + object_class->constructor = msd_media_keys_manager_constructor; + object_class->dispose = msd_media_keys_manager_dispose; + object_class->finalize = msd_media_keys_manager_finalize; + + signals[MEDIA_PLAYER_KEY_PRESSED] = + g_signal_new ("media-player-key-pressed", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdMediaKeysManagerClass, media_player_key_pressed), + NULL, + NULL, + msd_marshal_VOID__STRING_STRING, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_STRING); + + dbus_g_object_type_install_info (MSD_TYPE_MEDIA_KEYS_MANAGER, &dbus_glib_msd_media_keys_manager_object_info); + + g_type_class_add_private (klass, sizeof (MsdMediaKeysManagerPrivate)); +} + +static void +msd_media_keys_manager_init (MsdMediaKeysManager *manager) +{ + manager->priv = MSD_MEDIA_KEYS_MANAGER_GET_PRIVATE (manager); + +} + +static void +msd_media_keys_manager_finalize (GObject *object) +{ + MsdMediaKeysManager *media_keys_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_MEDIA_KEYS_MANAGER (object)); + + media_keys_manager = MSD_MEDIA_KEYS_MANAGER (object); + + g_return_if_fail (media_keys_manager->priv != NULL); + + G_OBJECT_CLASS (msd_media_keys_manager_parent_class)->finalize (object); +} + +static gboolean +register_manager (MsdMediaKeysManager *manager) +{ + GError *error = NULL; + + manager->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (manager->priv->connection == NULL) { + if (error != NULL) { + g_error ("Error getting session bus: %s", error->message); + g_error_free (error); + } + return FALSE; + } + + dbus_g_connection_register_g_object (manager->priv->connection, MSD_MEDIA_KEYS_DBUS_PATH, G_OBJECT (manager)); + + return TRUE; +} + +MsdMediaKeysManager * +msd_media_keys_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + gboolean res; + + manager_object = g_object_new (MSD_TYPE_MEDIA_KEYS_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + res = register_manager (manager_object); + if (! res) { + g_object_unref (manager_object); + return NULL; + } + } + + return MSD_MEDIA_KEYS_MANAGER (manager_object); +} diff --git a/plugins/media-keys/msd-media-keys-manager.h b/plugins/media-keys/msd-media-keys-manager.h new file mode 100644 index 0000000..96c135f --- /dev/null +++ b/plugins/media-keys/msd-media-keys-manager.h @@ -0,0 +1,72 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_MEDIA_KEYS_MANAGER_H +#define __MSD_MEDIA_KEYS_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_MEDIA_KEYS_MANAGER (msd_media_keys_manager_get_type ()) +#define MSD_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManager)) +#define MSD_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerClass)) +#define MSD_IS_MEDIA_KEYS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MEDIA_KEYS_MANAGER)) +#define MSD_IS_MEDIA_KEYS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_MANAGER)) +#define MSD_MEDIA_KEYS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_MANAGER, MsdMediaKeysManagerClass)) + +typedef struct MsdMediaKeysManagerPrivate MsdMediaKeysManagerPrivate; + +typedef struct +{ + GObject parent; + MsdMediaKeysManagerPrivate *priv; +} MsdMediaKeysManager; + +typedef struct +{ + GObjectClass parent_class; + void (* media_player_key_pressed) (MsdMediaKeysManager *manager, + const char *application, + const char *key); +} MsdMediaKeysManagerClass; + +GType msd_media_keys_manager_get_type (void); + +MsdMediaKeysManager * msd_media_keys_manager_new (void); +gboolean msd_media_keys_manager_start (MsdMediaKeysManager *manager, + GError **error); +void msd_media_keys_manager_stop (MsdMediaKeysManager *manager); + +gboolean msd_media_keys_manager_grab_media_player_keys (MsdMediaKeysManager *manager, + const char *application, + guint32 time, + GError **error); +gboolean msd_media_keys_manager_release_media_player_keys (MsdMediaKeysManager *manager, + const char *application, + GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_MEDIA_KEYS_MANAGER_H */ diff --git a/plugins/media-keys/msd-media-keys-manager.xml b/plugins/media-keys/msd-media-keys-manager.xml new file mode 100644 index 0000000..db0552e --- /dev/null +++ b/plugins/media-keys/msd-media-keys-manager.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/plugins/media-keys/msd-media-keys-plugin.c b/plugins/media-keys/msd-media-keys-plugin.c new file mode 100644 index 0000000..d76e233 --- /dev/null +++ b/plugins/media-keys/msd-media-keys-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-media-keys-plugin.h" +#include "msd-media-keys-manager.h" + +struct MsdMediaKeysPluginPrivate { + MsdMediaKeysManager *manager; +}; + +#define MSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdMediaKeysPlugin, msd_media_keys_plugin) + +static void +msd_media_keys_plugin_init (MsdMediaKeysPlugin *plugin) +{ + plugin->priv = MSD_MEDIA_KEYS_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdMediaKeysPlugin initializing"); + + plugin->priv->manager = msd_media_keys_manager_new (); +} + +static void +msd_media_keys_plugin_finalize (GObject *object) +{ + MsdMediaKeysPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_MEDIA_KEYS_PLUGIN (object)); + + g_debug ("MsdMediaKeysPlugin finalizing"); + + plugin = MSD_MEDIA_KEYS_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_media_keys_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating media_keys plugin"); + + error = NULL; + res = msd_media_keys_manager_start (MSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start media_keys manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating media_keys plugin"); + msd_media_keys_manager_stop (MSD_MEDIA_KEYS_PLUGIN (plugin)->priv->manager); +} + +static void +msd_media_keys_plugin_class_init (MsdMediaKeysPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_media_keys_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdMediaKeysPluginPrivate)); +} diff --git a/plugins/media-keys/msd-media-keys-plugin.h b/plugins/media-keys/msd-media-keys-plugin.h new file mode 100644 index 0000000..c869d62 --- /dev/null +++ b/plugins/media-keys/msd-media-keys-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_MEDIA_KEYS_PLUGIN_H__ +#define __MSD_MEDIA_KEYS_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_MEDIA_KEYS_PLUGIN (msd_media_keys_plugin_get_type ()) +#define MSD_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPlugin)) +#define MSD_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginClass)) +#define MSD_IS_MEDIA_KEYS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN)) +#define MSD_IS_MEDIA_KEYS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MEDIA_KEYS_PLUGIN)) +#define MSD_MEDIA_KEYS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MEDIA_KEYS_PLUGIN, MsdMediaKeysPluginClass)) + +typedef struct MsdMediaKeysPluginPrivate MsdMediaKeysPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdMediaKeysPluginPrivate *priv; +} MsdMediaKeysPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdMediaKeysPluginClass; + +GType msd_media_keys_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_MEDIA_KEYS_PLUGIN_H__ */ diff --git a/plugins/media-keys/msd-media-keys-window.c b/plugins/media-keys/msd-media-keys-window.c new file mode 100644 index 0000000..8bd6c33 --- /dev/null +++ b/plugins/media-keys/msd-media-keys-window.c @@ -0,0 +1,714 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2006-2007 William Jon McCann + * + * + * This program 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 2, or (at your option) any later version. + * + * This program 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 this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "msd-media-keys-window.h" + +#define MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindowPrivate)) + +struct MsdMediaKeysWindowPrivate +{ + MsdMediaKeysWindowAction action; + char *icon_name; + gboolean show_level; + + guint volume_muted : 1; + int volume_level; + + GtkImage *image; + GtkWidget *progress; +}; + +G_DEFINE_TYPE (MsdMediaKeysWindow, msd_media_keys_window, MSD_TYPE_OSD_WINDOW) + +static void +volume_controls_set_visible (MsdMediaKeysWindow *window, + gboolean visible) +{ + if (window->priv->progress == NULL) + return; + + if (visible) { + gtk_widget_show (window->priv->progress); + } else { + gtk_widget_hide (window->priv->progress); + } +} + +static void +window_set_icon_name (MsdMediaKeysWindow *window, + const char *name) +{ + if (window->priv->image == NULL) + return; + + gtk_image_set_from_icon_name (window->priv->image, + name, GTK_ICON_SIZE_DIALOG); +} + +static void +action_changed (MsdMediaKeysWindow *window) +{ + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { + switch (window->priv->action) { + case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: + volume_controls_set_visible (window, TRUE); + + if (window->priv->volume_muted) { + window_set_icon_name (window, "audio-volume-muted"); + } else { + window_set_icon_name (window, "audio-volume-high"); + } + + break; + case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: + volume_controls_set_visible (window, window->priv->show_level); + window_set_icon_name (window, window->priv->icon_name); + break; + default: + g_assert_not_reached (); + break; + } + } + + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); +} + +static void +volume_level_changed (MsdMediaKeysWindow *window) +{ + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); + + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window)) && window->priv->progress != NULL) { + double fraction; + + fraction = (double) window->priv->volume_level / 100.0; + + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (window->priv->progress), + fraction); + } +} + +static void +volume_muted_changed (MsdMediaKeysWindow *window) +{ + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); + + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { + if (window->priv->volume_muted) { + window_set_icon_name (window, "audio-volume-muted"); + } else { + window_set_icon_name (window, "audio-volume-high"); + } + } +} + +void +msd_media_keys_window_set_action (MsdMediaKeysWindow *window, + MsdMediaKeysWindowAction action) +{ + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); + g_return_if_fail (action == MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME); + + if (window->priv->action != action) { + window->priv->action = action; + action_changed (window); + } else { + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); + } +} + +void +msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window, + const char *icon_name, + gboolean show_level) +{ + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); + g_return_if_fail (icon_name != NULL); + + if (window->priv->action != MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM || + g_strcmp0 (window->priv->icon_name, icon_name) != 0 || + window->priv->show_level != show_level) { + window->priv->action = MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM; + g_free (window->priv->icon_name); + window->priv->icon_name = g_strdup (icon_name); + window->priv->show_level = show_level; + action_changed (window); + } else { + msd_osd_window_update_and_hide (MSD_OSD_WINDOW (window)); + } +} + +void +msd_media_keys_window_set_volume_muted (MsdMediaKeysWindow *window, + gboolean muted) +{ + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); + + if (window->priv->volume_muted != muted) { + window->priv->volume_muted = muted; + volume_muted_changed (window); + } +} + +void +msd_media_keys_window_set_volume_level (MsdMediaKeysWindow *window, + int level) +{ + g_return_if_fail (MSD_IS_MEDIA_KEYS_WINDOW (window)); + + if (window->priv->volume_level != level) { + window->priv->volume_level = level; + volume_level_changed (window); + } +} + +static GdkPixbuf * +load_pixbuf (MsdMediaKeysWindow *window, + const char *name, + int icon_size) +{ + GtkIconTheme *theme; + GdkPixbuf *pixbuf; + + if (window != NULL && gtk_widget_has_screen (GTK_WIDGET (window))) { + theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))); + } else { + theme = gtk_icon_theme_get_default (); + } + + pixbuf = gtk_icon_theme_load_icon (theme, + name, + icon_size, + GTK_ICON_LOOKUP_FORCE_SIZE, + NULL); + + return pixbuf; +} + +static void +draw_eject (cairo_t *cr, + double _x0, + double _y0, + double width, + double height) +{ + int box_height; + int tri_height; + int separation; + + box_height = height * 0.2; + separation = box_height / 3; + tri_height = height - box_height - separation; + + cairo_rectangle (cr, _x0, _y0 + height - box_height, width, box_height); + + cairo_move_to (cr, _x0, _y0 + tri_height); + cairo_rel_line_to (cr, width, 0); + cairo_rel_line_to (cr, -width / 2, -tri_height); + cairo_rel_line_to (cr, -width / 2, tri_height); + cairo_close_path (cr); + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); + cairo_fill_preserve (cr); + + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_line_width (cr, 2); + cairo_stroke (cr); +} + +static void +draw_waves (cairo_t *cr, + double cx, + double cy, + double max_radius, + int volume_level) +{ + const int n_waves = 3; + int last_wave; + int i; + + last_wave = n_waves * volume_level / 100; + + for (i = 0; i < n_waves; i++) { + double angle1; + double angle2; + double radius; + double alpha; + + angle1 = -M_PI / 4; + angle2 = M_PI / 4; + + if (i < last_wave) + alpha = 1.0; + else if (i > last_wave) + alpha = 0.1; + else alpha = 0.1 + 0.9 * (n_waves * volume_level % 100) / 100.0; + + radius = (i + 1) * (max_radius / n_waves); + cairo_arc (cr, cx, cy, radius, angle1, angle2); + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, alpha / 2); + cairo_set_line_width (cr, 14); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_stroke_preserve (cr); + + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, alpha); + cairo_set_line_width (cr, 10); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_stroke (cr); + } +} + +static void +draw_cross (cairo_t *cr, + double cx, + double cy, + double size) +{ + cairo_move_to (cr, cx, cy - size/2.0); + cairo_rel_line_to (cr, size, size); + + cairo_move_to (cr, cx, cy + size/2.0); + cairo_rel_line_to (cr, size, -size); + + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_line_width (cr, 14); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_stroke_preserve (cr); + + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); + cairo_set_line_width (cr, 10); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_stroke (cr); +} + +static void +draw_speaker (cairo_t *cr, + double cx, + double cy, + double width, + double height) +{ + double box_width; + double box_height; + double _x0; + double _y0; + + box_width = width / 3; + box_height = height / 3; + + _x0 = cx - (width / 2) + box_width; + _y0 = cy - box_height / 2; + + cairo_move_to (cr, _x0, _y0); + cairo_rel_line_to (cr, - box_width, 0); + cairo_rel_line_to (cr, 0, box_height); + cairo_rel_line_to (cr, box_width, 0); + + cairo_line_to (cr, cx + box_width, cy + height / 2); + cairo_rel_line_to (cr, 0, -height); + cairo_line_to (cr, _x0, _y0); + cairo_close_path (cr); + + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, MSD_OSD_WINDOW_FG_ALPHA); + cairo_fill_preserve (cr); + + cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, MSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_line_width (cr, 2); + cairo_stroke (cr); +} + +static gboolean +render_speaker (MsdMediaKeysWindow *window, + cairo_t *cr, + double _x0, + double _y0, + double width, + double height) +{ + GdkPixbuf *pixbuf; + int icon_size; + int n; + static const char *icon_names[] = { + "audio-volume-muted", + "audio-volume-low", + "audio-volume-medium", + "audio-volume-high", + NULL + }; + + if (window->priv->volume_muted) { + n = 0; + } else { + /* select image */ + n = 3 * window->priv->volume_level / 100 + 1; + if (n < 1) { + n = 1; + } else if (n > 3) { + n = 3; + } + } + + icon_size = (int)width; + + pixbuf = load_pixbuf (window, icon_names[n], icon_size); + + if (pixbuf == NULL) { + return FALSE; + } + + gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0); + cairo_paint_with_alpha (cr, MSD_OSD_WINDOW_FG_ALPHA); + + g_object_unref (pixbuf); + + return TRUE; +} + +static void +draw_volume_boxes (MsdMediaKeysWindow *window, + cairo_t *cr, + double percentage, + double _x0, + double _y0, + double width, + double height) +{ + gdouble x1; + GdkColor color; + double r, g, b; + GtkStyle *style; + + _x0 += 0.5; + _y0 += 0.5; + height = round (height) - 1; + width = round (width) - 1; + x1 = round ((width - 1) * percentage); + style = gtk_widget_get_style (GTK_WIDGET (window)); + + /* bar background */ + msd_osd_window_color_reverse (&style->dark[GTK_STATE_NORMAL], &color); + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height); + cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_fill_preserve (cr); + + /* bar border */ + msd_osd_window_color_reverse (&style->light[GTK_STATE_NORMAL], &color); + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); + cairo_set_line_width (cr, 1); + cairo_stroke (cr); + + /* bar progress */ + if (percentage < 0.01) + return; + color = style->bg[GTK_STATE_NORMAL]; + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0 + 0.5, _y0 + 0.5, height / 6 - 0.5, x1, height - 1); + cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA); + cairo_fill (cr); +} + +static void +draw_action_volume (MsdMediaKeysWindow *window, + cairo_t *cr) +{ + int window_width; + int window_height; + double icon_box_width; + double icon_box_height; + double icon_box_x0; + double icon_box_y0; + double volume_box_x0; + double volume_box_y0; + double volume_box_width; + double volume_box_height; + gboolean res; + + gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height); + + icon_box_width = round (window_width * 0.65); + icon_box_height = round (window_height * 0.65); + volume_box_width = icon_box_width; + volume_box_height = round (window_height * 0.05); + + icon_box_x0 = (window_width - icon_box_width) / 2; + icon_box_y0 = (window_height - icon_box_height - volume_box_height) / 2; + volume_box_x0 = round (icon_box_x0); + volume_box_y0 = round (icon_box_height + icon_box_y0); + +#if 0 + g_message ("icon box: w=%f h=%f _x0=%f _y0=%f", + icon_box_width, + icon_box_height, + icon_box_x0, + icon_box_y0); + g_message ("volume box: w=%f h=%f _x0=%f _y0=%f", + volume_box_width, + volume_box_height, + volume_box_x0, + volume_box_y0); +#endif + + res = render_speaker (window, + cr, + icon_box_x0, icon_box_y0, + icon_box_width, icon_box_height); + if (! res) { + double speaker_width; + double speaker_height; + double speaker_cx; + double speaker_cy; + + speaker_width = icon_box_width * 0.5; + speaker_height = icon_box_height * 0.75; + speaker_cx = icon_box_x0 + speaker_width / 2; + speaker_cy = icon_box_y0 + speaker_height / 2; + +#if 0 + g_message ("speaker box: w=%f h=%f cx=%f cy=%f", + speaker_width, + speaker_height, + speaker_cx, + speaker_cy); +#endif + + /* draw speaker symbol */ + draw_speaker (cr, speaker_cx, speaker_cy, speaker_width, speaker_height); + + if (! window->priv->volume_muted) { + /* draw sound waves */ + double wave_x0; + double wave_y0; + double wave_radius; + + wave_x0 = window_width / 2; + wave_y0 = speaker_cy; + wave_radius = icon_box_width / 2; + + draw_waves (cr, wave_x0, wave_y0, wave_radius, window->priv->volume_level); + } else { + /* draw 'mute' cross */ + double cross_x0; + double cross_y0; + double cross_size; + + cross_size = speaker_width * 3 / 4; + cross_x0 = icon_box_x0 + icon_box_width - cross_size; + cross_y0 = speaker_cy; + + draw_cross (cr, cross_x0, cross_y0, cross_size); + } + } + + /* draw volume meter */ + draw_volume_boxes (window, + cr, + (double)window->priv->volume_level / 100.0, + volume_box_x0, + volume_box_y0, + volume_box_width, + volume_box_height); +} + +static gboolean +render_custom (MsdMediaKeysWindow *window, + cairo_t *cr, + double _x0, + double _y0, + double width, + double height) +{ + GdkPixbuf *pixbuf; + int icon_size; + + icon_size = (int)width; + + pixbuf = load_pixbuf (window, window->priv->icon_name, icon_size); + + if (pixbuf == NULL) { + char *name; + if (gtk_widget_get_direction (GTK_WIDGET (window)) == GTK_TEXT_DIR_RTL) + name = g_strdup_printf ("%s-rtl", window->priv->icon_name); + else + name = g_strdup_printf ("%s-ltr", window->priv->icon_name); + pixbuf = load_pixbuf (window, name, icon_size); + g_free (name); + if (pixbuf == NULL) + return FALSE; + } + + gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0); + cairo_paint_with_alpha (cr, MSD_OSD_WINDOW_FG_ALPHA); + + g_object_unref (pixbuf); + + return TRUE; +} + +static void +draw_action_custom (MsdMediaKeysWindow *window, + cairo_t *cr) +{ + int window_width; + int window_height; + double icon_box_width; + double icon_box_height; + double icon_box_x0; + double icon_box_y0; + double bright_box_x0; + double bright_box_y0; + double bright_box_width; + double bright_box_height; + gboolean res; + + gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height); + + icon_box_width = round (window_width * 0.65); + icon_box_height = round (window_height * 0.65); + bright_box_width = round (icon_box_width); + bright_box_height = round (window_height * 0.05); + + icon_box_x0 = (window_width - icon_box_width) / 2; + icon_box_y0 = (window_height - icon_box_height - bright_box_height) / 2; + bright_box_x0 = round (icon_box_x0); + bright_box_y0 = round (icon_box_height + icon_box_y0); + +#if 0 + g_message ("icon box: w=%f h=%f _x0=%f _y0=%f", + icon_box_width, + icon_box_height, + icon_box_x0, + icon_box_y0); + g_message ("brightness box: w=%f h=%f _x0=%f _y0=%f", + bright_box_width, + bright_box_height, + bright_box_x0, + bright_box_y0); +#endif + + res = render_custom (window, + cr, + icon_box_x0, icon_box_y0, + icon_box_width, icon_box_height); + if (! res && g_strcmp0 (window->priv->icon_name, "media-eject") == 0) { + /* draw eject symbol */ + draw_eject (cr, + icon_box_x0, icon_box_y0, + icon_box_width, icon_box_height); + } + + if (window->priv->show_level != FALSE) { + /* draw volume meter */ + draw_volume_boxes (window, + cr, + (double)window->priv->volume_level / 100.0, + bright_box_x0, + bright_box_y0, + bright_box_width, + bright_box_height); + } +} + +static void +msd_media_keys_window_expose_when_composited (MsdOsdWindow *osd_window, + cairo_t *cr) +{ + MsdMediaKeysWindow *window = MSD_MEDIA_KEYS_WINDOW (osd_window); + + switch (window->priv->action) { + case MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME: + draw_action_volume (window, cr); + break; + case MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM: + draw_action_custom (window, cr); + break; + default: + break; + } +} + +static void +msd_media_keys_window_class_init (MsdMediaKeysWindowClass *klass) +{ + MsdOsdWindowClass *osd_window_class = MSD_OSD_WINDOW_CLASS (klass); + + osd_window_class->expose_when_composited = msd_media_keys_window_expose_when_composited; + + g_type_class_add_private (klass, sizeof (MsdMediaKeysWindowPrivate)); +} + +static void +msd_media_keys_window_init (MsdMediaKeysWindow *window) +{ + GdkScreen *screen; + + window->priv = MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window); + + screen = gtk_widget_get_screen (GTK_WIDGET (window)); + + if (!msd_osd_window_is_composited (MSD_OSD_WINDOW (window))) { + GtkBuilder *builder; + const gchar *objects[] = {"acme_box", NULL}; + GtkWidget *box; + + builder = gtk_builder_new (); + gtk_builder_add_objects_from_file (builder, + GTKBUILDERDIR "/acme.ui", + (char **) objects, + NULL); + + window->priv->image = GTK_IMAGE (gtk_builder_get_object (builder, "acme_image")); + window->priv->progress = GTK_WIDGET (gtk_builder_get_object (builder, "acme_volume_progressbar")); + box = GTK_WIDGET (gtk_builder_get_object (builder, "acme_box")); + + if (box != NULL) { + gtk_container_add (GTK_CONTAINER (window), box); + gtk_widget_show_all (box); + } + + /* The builder needs to stay alive until the window + takes ownership of the box (and its children) */ + g_object_unref (builder); + } +} + +GtkWidget * +msd_media_keys_window_new (void) +{ + return g_object_new (MSD_TYPE_MEDIA_KEYS_WINDOW, NULL); +} diff --git a/plugins/media-keys/msd-media-keys-window.h b/plugins/media-keys/msd-media-keys-window.h new file mode 100644 index 0000000..c0e5739 --- /dev/null +++ b/plugins/media-keys/msd-media-keys-window.h @@ -0,0 +1,78 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- + * + * Copyright (C) 2006 William Jon McCann + * + * This program 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 2, or (at your option) any later version. + * + * This program 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 this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#ifndef MSD_MEDIA_KEYS_WINDOW_H +#define MSD_MEDIA_KEYS_WINDOW_H + +#include +#include + +#include "msd-osd-window.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_MEDIA_KEYS_WINDOW (msd_media_keys_window_get_type ()) +#define MSD_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindow)) +#define MSD_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindowClass)) +#define MSD_IS_MEDIA_KEYS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_MEDIA_KEYS_WINDOW)) +#define MSD_IS_MEDIA_KEYS_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_MEDIA_KEYS_WINDOW)) + +typedef struct MsdMediaKeysWindow MsdMediaKeysWindow; +typedef struct MsdMediaKeysWindowClass MsdMediaKeysWindowClass; +typedef struct MsdMediaKeysWindowPrivate MsdMediaKeysWindowPrivate; + +struct MsdMediaKeysWindow { + MsdOsdWindow parent; + + MsdMediaKeysWindowPrivate *priv; +}; + +struct MsdMediaKeysWindowClass { + MsdOsdWindowClass parent_class; +}; + +typedef enum { + MSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME, + MSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM +} MsdMediaKeysWindowAction; + +GType msd_media_keys_window_get_type (void); + +GtkWidget * msd_media_keys_window_new (void); +void msd_media_keys_window_set_action (MsdMediaKeysWindow *window, + MsdMediaKeysWindowAction action); +void msd_media_keys_window_set_action_custom (MsdMediaKeysWindow *window, + const char *icon_name, + gboolean show_level); +void msd_media_keys_window_set_volume_muted (MsdMediaKeysWindow *window, + gboolean muted); +void msd_media_keys_window_set_volume_level (MsdMediaKeysWindow *window, + int level); +gboolean msd_media_keys_window_is_valid (MsdMediaKeysWindow *window); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/plugins/mouse/gsd-locate-pointer.c b/plugins/mouse/gsd-locate-pointer.c deleted file mode 100644 index 8582074..0000000 --- a/plugins/mouse/gsd-locate-pointer.c +++ /dev/null @@ -1,504 +0,0 @@ -/* msd-locate-pointer.c - * - * Copyright (C) 2008 Carlos Garnacho - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include -#include "msd-timeline.h" -#include "msd-locate-pointer.h" - -#include -#include -#include - -#define ANIMATION_LENGTH 750 -#define WINDOW_SIZE 101 -#define N_CIRCLES 4 - -/* All circles are supposed to be moving when progress - * reaches 0.5, and each of them are supposed to long - * for half of the progress, hence the need of 0.5 to - * get the circles interval, and the multiplication - * by 2 to know a circle progress */ -#define CIRCLES_PROGRESS_INTERVAL (0.5 / N_CIRCLES) -#define CIRCLE_PROGRESS(p) (MIN (1., ((gdouble) (p) * 2.))) - -typedef struct MsdLocatePointerData MsdLocatePointerData; - -struct MsdLocatePointerData -{ - MsdTimeline *timeline; - GtkWidget *widget; - GdkWindow *window; - - gdouble progress; -}; - -static MsdLocatePointerData *data = NULL; - -static void -locate_pointer_paint (MsdLocatePointerData *data, - cairo_t *cr, - gboolean composite) -{ - GdkColor color; - gdouble progress, circle_progress; - gint width, height, i; - GtkStyle *style; - - progress = data->progress; - - #if GTK_CHECK_VERSION(3, 0, 0) - width = gdk_window_get_width(GDK_WINDOW(data->window)); - height = gdk_window_get_height(GDK_WINDOW(data->window)); - #else - gdk_drawable_get_size(data->window, &width, &height); - #endif - - style = gtk_widget_get_style (data->widget); - color = style->bg[GTK_STATE_SELECTED]; - - cairo_set_source_rgba (cr, 1., 1., 1., 0.); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_paint (cr); - - for (i = 0; i <= N_CIRCLES; i++) - { - if (progress < 0.) - break; - - circle_progress = MIN (1., (progress * 2)); - progress -= CIRCLES_PROGRESS_INTERVAL; - - if (circle_progress >= 1.) - continue; - - if (composite) - { - cairo_set_source_rgba (cr, - color.red / 65535., - color.green / 65535., - color.blue / 65535., - 1 - circle_progress); - cairo_arc (cr, - width / 2, - height / 2, - circle_progress * width / 2, - 0, 2 * G_PI); - - cairo_fill (cr); - cairo_stroke (cr); - } - else - { - cairo_set_source_rgb (cr, 0., 0., 0.); - cairo_set_line_width (cr, 3.); - cairo_arc (cr, - width / 2, - height / 2, - circle_progress * width / 2, - 0, 2 * G_PI); - cairo_stroke (cr); - - cairo_set_source_rgb (cr, 1., 1., 1.); - cairo_set_line_width (cr, 1.); - cairo_arc (cr, - width / 2, - height / 2, - circle_progress * width / 2, - 0, 2 * G_PI); - cairo_stroke (cr); - } - } -} - -static gboolean -locate_pointer_expose (GtkWidget *widget, - GdkEventExpose *event, - gpointer user_data) -{ - MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; - cairo_t *cr; - - if (event->window != data->window) - return FALSE; - - cr = gdk_cairo_create (data->window); - locate_pointer_paint (data, cr, gtk_widget_is_composited (data->widget)); - cairo_destroy (cr); - - return TRUE; -} - -static void -update_shape (MsdLocatePointerData *data) -{ - cairo_t *cr; - GdkBitmap *mask; - - mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1); - cr = gdk_cairo_create (mask); - locate_pointer_paint (data, cr, FALSE); - gdk_window_shape_combine_mask (data->window, mask, 0, 0); - g_object_unref (mask); - cairo_destroy (cr); -} - -static void -timeline_frame_cb (MsdTimeline *timeline, - gdouble progress, - gpointer user_data) -{ - MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; - GdkScreen *screen; - gint cursor_x, cursor_y; - - if (gtk_widget_is_composited (data->widget)) - { - gdk_window_invalidate_rect (data->window, NULL, FALSE); - data->progress = progress; - } - else if (progress >= data->progress + CIRCLES_PROGRESS_INTERVAL) - { - /* only invalidate window each circle interval */ - update_shape (data); - gdk_window_invalidate_rect (data->window, NULL, FALSE); - data->progress += CIRCLES_PROGRESS_INTERVAL; - } - - screen = gdk_drawable_get_screen (data->window); - gdk_window_get_pointer (gdk_screen_get_root_window (screen), - &cursor_x, &cursor_y, NULL); - gdk_window_move (data->window, - cursor_x - WINDOW_SIZE / 2, - cursor_y - WINDOW_SIZE / 2); -} - -static void -set_transparent_shape (GdkWindow *window) -{ - GdkBitmap *mask; - cairo_t *cr; - - mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1); - cr = gdk_cairo_create (mask); - - cairo_set_source_rgba (cr, 1., 1., 1., 0.); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_paint (cr); - - gdk_window_shape_combine_mask (data->window, mask, 0, 0); - g_object_unref (mask); - cairo_destroy (cr); -} - -static void -unset_transparent_shape (GdkWindow *window) -{ - gdk_window_shape_combine_mask (data->window, NULL, 0, 0); -} - -static void -composited_changed (GtkWidget *widget, - MsdLocatePointerData *data) -{ - if (!gtk_widget_is_composited (widget)) - set_transparent_shape (data->window); - else - unset_transparent_shape (data->window); -} - -static void -timeline_finished_cb (MsdTimeline *timeline, - gpointer user_data) -{ - MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; - - /* set transparent shape and hide window */ - if (!gtk_widget_is_composited (data->widget)) - set_transparent_shape (data->window); - - gdk_window_hide (data->window); -} - -static void -create_window (MsdLocatePointerData *data, - GdkScreen *screen) -{ - GdkColormap *colormap; - GdkVisual *visual; - GdkWindowAttr attributes; - - colormap = gdk_screen_get_rgba_colormap (screen); - visual = gdk_screen_get_rgba_visual (screen); - - if (!colormap) - { - colormap = gdk_screen_get_rgb_colormap (screen); - visual = gdk_screen_get_rgb_visual (screen); - } - - attributes.window_type = GDK_WINDOW_TEMP; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = visual; - attributes.colormap = colormap; - attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK; - attributes.width = 1; - attributes.height = 1; - - data->window = gdk_window_new (gdk_screen_get_root_window (screen), - &attributes, - GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP); - - gdk_window_set_user_data (data->window, data->widget); -} - -static MsdLocatePointerData * -msd_locate_pointer_data_new (GdkScreen *screen) -{ - MsdLocatePointerData *data; - - data = g_new0 (MsdLocatePointerData, 1); - - /* this widget will never be shown, it's - * mainly used to get signals/events from - */ - data->widget = gtk_window_new (GTK_WINDOW_POPUP); - gtk_widget_realize (data->widget); - - g_signal_connect (G_OBJECT (data->widget), "expose_event", - G_CALLBACK (locate_pointer_expose), - data); - - data->timeline = msd_timeline_new (ANIMATION_LENGTH); - g_signal_connect (data->timeline, "frame", - G_CALLBACK (timeline_frame_cb), data); - g_signal_connect (data->timeline, "finished", - G_CALLBACK (timeline_finished_cb), data); - - create_window (data, screen); - - return data; -} - -static void -move_locate_pointer_window (MsdLocatePointerData *data, - GdkScreen *screen) -{ - gint cursor_x, cursor_y; - GdkBitmap *mask; - GdkColor col; - GdkGC *gc; - - gdk_window_get_pointer (gdk_screen_get_root_window (screen), &cursor_x, &cursor_y, NULL); - - gdk_window_move_resize (data->window, - cursor_x - WINDOW_SIZE / 2, - cursor_y - WINDOW_SIZE / 2, - WINDOW_SIZE, WINDOW_SIZE); - - col.pixel = 0; - mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1); - - gc = gdk_gc_new (mask); - gdk_gc_set_foreground (gc, &col); - gdk_draw_rectangle (mask, gc, TRUE, 0, 0, WINDOW_SIZE, WINDOW_SIZE); - - /* allow events to happen through the window */ - gdk_window_input_shape_combine_mask (data->window, mask, 0, 0); - - g_object_unref (mask); - g_object_unref (gc); -} - -void -msd_locate_pointer (GdkScreen *screen) -{ - if (!data) - data = msd_locate_pointer_data_new (screen); - - msd_timeline_pause (data->timeline); - msd_timeline_rewind (data->timeline); - - /* Create again the window if it is not for the current screen */ - if (gdk_screen_get_number (screen) != gdk_screen_get_number (gdk_drawable_get_screen (data->window))) - { - gdk_window_set_user_data (data->window, NULL); - gdk_window_destroy (data->window); - - create_window (data, screen); - } - - data->progress = 0.; - - g_signal_connect (data->widget, "composited-changed", - G_CALLBACK (composited_changed), data); - - move_locate_pointer_window (data, screen); - composited_changed (data->widget, data); - gdk_window_show (data->window); - - msd_timeline_start (data->timeline); -} - - -#define KEYBOARD_GROUP_SHIFT 13 -#define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14)) - -/* Owen magic */ -static GdkFilterReturn -filter (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) -{ - XEvent *xev = (XEvent *) xevent; - guint keyval; - gint group; - - GdkScreen *screen = (GdkScreen *)data; - - if (xev->type == KeyPress || xev->type == KeyRelease) - { - /* get the keysym */ - group = (xev->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT; - gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), - xev->xkey.keycode, - xev->xkey.state, - group, - &keyval, - NULL, NULL, NULL); - if (keyval == GDK_Control_L || keyval == GDK_Control_R) - { - if (xev->type == KeyPress) - { - XAllowEvents (xev->xkey.display, - SyncKeyboard, - xev->xkey.time); - } - else - { - XAllowEvents (xev->xkey.display, - AsyncKeyboard, - xev->xkey.time); - msd_locate_pointer (screen); - } - } - else - { - XAllowEvents (xev->xkey.display, - ReplayKeyboard, - xev->xkey.time); - XUngrabKeyboard (gdk_x11_get_default_xdisplay (), - xev->xkey.time); - } - } - - return GDK_FILTER_CONTINUE; -} - -static void -set_locate_pointer (void) -{ - GdkKeymapKey *keys; - GdkDisplay *display; - int n_screens; - int n_keys; - gboolean has_entries; - static const guint keyvals[] = { GDK_Control_L, GDK_Control_R }; - unsigned j; - - display = gdk_display_get_default (); - n_screens = gdk_display_get_n_screens (display); - - for (j = 0 ; j < G_N_ELEMENTS (keyvals) ; j++) - { - has_entries = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), - keyvals[j], - &keys, - &n_keys); - if (has_entries) - { - gint i, j; - for (i = 0; i < n_keys; i++) - { - for (j=0; j< n_screens; j++) - { - GdkScreen *screen; - Window xroot; - - screen = gdk_display_get_screen (display, j); - xroot = gdk_x11_drawable_get_xid (gdk_screen_get_root_window (screen)); - - XGrabKey (GDK_DISPLAY_XDISPLAY (display), - keys[i].keycode, - 0, - xroot, - False, - GrabModeAsync, - GrabModeSync); - XGrabKey (GDK_DISPLAY_XDISPLAY (display), - keys[i].keycode, - LockMask, - xroot, - False, - GrabModeAsync, - GrabModeSync); - XGrabKey (GDK_DISPLAY_XDISPLAY (display), - keys[i].keycode, - Mod2Mask, - xroot, - False, - GrabModeAsync, - GrabModeSync); - XGrabKey (GDK_DISPLAY_XDISPLAY (display), - keys[i].keycode, - Mod4Mask, - xroot, - False, - GrabModeAsync, - GrabModeSync); - } - } - - g_free (keys); - - for (i = 0; i < n_screens; i++) - { - GdkScreen *screen; - - screen = gdk_display_get_screen (display, i); - gdk_window_add_filter (gdk_screen_get_root_window (screen), - filter, - screen); - } - } - } -} - - -int -main (int argc, char *argv[]) -{ - gtk_init (&argc, &argv); - - set_locate_pointer (); - - gtk_main (); - - return 0; -} - diff --git a/plugins/mouse/gsd-locate-pointer.h b/plugins/mouse/gsd-locate-pointer.h deleted file mode 100644 index c21da43..0000000 --- a/plugins/mouse/gsd-locate-pointer.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright © 2001 Jonathan Blandford - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Red Hat not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. Red Hat makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * Authors: Jonathan Blandford - */ - -#ifndef LOCATE_POINTER_H -#define LOCATE_POINTER_H - -#include - -void msd_locate_pointer (GdkScreen *screen); - -#endif diff --git a/plugins/mouse/gsd-mouse-manager.c b/plugins/mouse/gsd-mouse-manager.c deleted file mode 100644 index d7cb8e4..0000000 --- a/plugins/mouse/gsd-mouse-manager.c +++ /dev/null @@ -1,1124 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -#include -#include -#endif -#include -#include - -#include "mate-settings-profile.h" -#include "msd-mouse-manager.h" - -#define MSD_MOUSE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerPrivate)) - -#define MATECONF_MOUSE_DIR "/desktop/mate/peripherals/mouse" -#define MATECONF_MOUSE_A11Y_DIR "/desktop/mate/accessibility/mouse" -#define MATECONF_TOUCHPAD_DIR "/desktop/mate/peripherals/touchpad" - -#define KEY_LEFT_HANDED MATECONF_MOUSE_DIR "/left_handed" -#define KEY_MOTION_ACCELERATION MATECONF_MOUSE_DIR "/motion_acceleration" -#define KEY_MOTION_THRESHOLD MATECONF_MOUSE_DIR "/motion_threshold" -#define KEY_LOCATE_POINTER MATECONF_MOUSE_DIR "/locate_pointer" -#define KEY_DWELL_ENABLE MATECONF_MOUSE_A11Y_DIR "/dwell_enable" -#define KEY_DELAY_ENABLE MATECONF_MOUSE_A11Y_DIR "/delay_enable" -#define KEY_TOUCHPAD_DISABLE_W_TYPING MATECONF_TOUCHPAD_DIR "/disable_while_typing" -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -#define KEY_TAP_TO_CLICK MATECONF_TOUCHPAD_DIR "/tap_to_click" -#define KEY_SCROLL_METHOD MATECONF_TOUCHPAD_DIR "/scroll_method" -#define KEY_PAD_HORIZ_SCROLL MATECONF_TOUCHPAD_DIR "/horiz_scroll_enabled" -#define KEY_TOUCHPAD_ENABLED MATECONF_TOUCHPAD_DIR "/touchpad_enabled" -#endif - -struct MsdMouseManagerPrivate -{ - guint notify; - guint notify_a11y; - guint notify_touchpad; - - gboolean mousetweaks_daemon_running; - gboolean syndaemon_spawned; - GPid syndaemon_pid; - gboolean locate_pointer_spawned; - GPid locate_pointer_pid; -}; - -static void msd_mouse_manager_class_init (MsdMouseManagerClass *klass); -static void msd_mouse_manager_init (MsdMouseManager *mouse_manager); -static void msd_mouse_manager_finalize (GObject *object); -static void set_mouse_settings (MsdMouseManager *manager); -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -static int set_tap_to_click (gboolean state, gboolean left_handed); -static XDevice* device_is_touchpad (XDeviceInfo deviceinfo); -#endif - -G_DEFINE_TYPE (MsdMouseManager, msd_mouse_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -static void -msd_mouse_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdMouseManager *self; - - self = MSD_MOUSE_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_mouse_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdMouseManager *self; - - self = MSD_MOUSE_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_mouse_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdMouseManager *mouse_manager; - MsdMouseManagerClass *klass; - - klass = MSD_MOUSE_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_MOUSE_MANAGER)); - - mouse_manager = MSD_MOUSE_MANAGER (G_OBJECT_CLASS (msd_mouse_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (mouse_manager); -} - -static void -msd_mouse_manager_dispose (GObject *object) -{ - MsdMouseManager *mouse_manager; - - mouse_manager = MSD_MOUSE_MANAGER (object); - - G_OBJECT_CLASS (msd_mouse_manager_parent_class)->dispose (object); -} - -static void -msd_mouse_manager_class_init (MsdMouseManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_mouse_manager_get_property; - object_class->set_property = msd_mouse_manager_set_property; - object_class->constructor = msd_mouse_manager_constructor; - object_class->dispose = msd_mouse_manager_dispose; - object_class->finalize = msd_mouse_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdMouseManagerPrivate)); -} - - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -static gboolean -supports_xinput_devices (void) -{ - gint op_code, event, error; - - return XQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - "XInputExtension", - &op_code, - &event, - &error); -} -#endif - -static void -configure_button_layout (guchar *buttons, - gint n_buttons, - gboolean left_handed) -{ - const gint left_button = 1; - gint right_button; - gint i; - - /* if the button is higher than 2 (3rd button) then it's - * probably one direction of a scroll wheel or something else - * uninteresting - */ - right_button = MIN (n_buttons, 3); - - /* If we change things we need to make sure we only swap buttons. - * If we end up with multiple physical buttons assigned to the same - * logical button the server will complain. This code assumes physical - * button 0 is the physical left mouse button, and that the physical - * button other than 0 currently assigned left_button or right_button - * is the physical right mouse button. - */ - - /* check if the current mapping satisfies the above assumptions */ - if (buttons[left_button - 1] != left_button && - buttons[left_button - 1] != right_button) - /* The current mapping is weird. Swapping buttons is probably not a - * good idea. - */ - return; - - /* check if we are left_handed and currently not swapped */ - if (left_handed && buttons[left_button - 1] == left_button) { - /* find the right button */ - for (i = 0; i < n_buttons; i++) { - if (buttons[i] == right_button) { - buttons[i] = left_button; - break; - } - } - /* swap the buttons */ - buttons[left_button - 1] = right_button; - } - /* check if we are not left_handed but are swapped */ - else if (!left_handed && buttons[left_button - 1] == right_button) { - /* find the right button */ - for (i = 0; i < n_buttons; i++) { - if (buttons[i] == left_button) { - buttons[i] = right_button; - break; - } - } - /* swap the buttons */ - buttons[left_button - 1] = left_button; - } -} - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -static gboolean -xinput_device_has_buttons (XDeviceInfo *device_info) -{ - int i; - XAnyClassInfo *class_info; - - class_info = device_info->inputclassinfo; - for (i = 0; i < device_info->num_classes; i++) { - if (class_info->class == ButtonClass) { - XButtonInfo *button_info; - - button_info = (XButtonInfo *) class_info; - if (button_info->num_buttons > 0) - return TRUE; - } - - class_info = (XAnyClassInfo *) (((guchar *) class_info) + - class_info->length); - } - return FALSE; -} - -static gboolean -touchpad_has_single_button (XDevice *device) -{ - Atom type, prop; - int format; - unsigned long nitems, bytes_after; - unsigned char *data; - gboolean is_single_button = FALSE; - int rc; - - prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Capabilities", False); - if (!prop) - return FALSE; - - gdk_error_trap_push (); - rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 1, False, - XA_INTEGER, &type, &format, &nitems, - &bytes_after, &data); - if (rc == Success && type == XA_INTEGER && format == 8 && nitems >= 3) - is_single_button = (data[0] == 1 && data[1] == 0 && data[2] == 0); - - if (rc == Success) - XFree (data); - - gdk_error_trap_pop (); - - return is_single_button; -} - - -static void -set_xinput_devices_left_handed (gboolean left_handed) -{ - XDeviceInfo *device_info; - gint n_devices; - guchar *buttons; - gsize buttons_capacity = 16; - gint n_buttons; - gint i; - - device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &n_devices); - - if (n_devices > 0) - buttons = g_new (guchar, buttons_capacity); - else - buttons = NULL; - - for (i = 0; i < n_devices; i++) { - XDevice *device = NULL; - - if ((device_info[i].use == IsXPointer) || - (device_info[i].use == IsXKeyboard) || - (!xinput_device_has_buttons (&device_info[i]))) - continue; - - /* If the device is a touchpad, swap tap buttons - * around too, otherwise a tap would be a right-click */ - device = device_is_touchpad (device_info[i]); - if (device != NULL) { - MateConfClient *client = mateconf_client_get_default (); - gboolean tap = mateconf_client_get_bool (client, KEY_TAP_TO_CLICK, NULL); - gboolean single_button = touchpad_has_single_button (device); - - if (tap && !single_button) - set_tap_to_click (tap, left_handed); - XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); - g_object_unref (client); - - if (single_button) - continue; - } - - gdk_error_trap_push (); - - device = XOpenDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device_info[i].id); - - if ((gdk_error_trap_pop () != 0) || - (device == NULL)) - continue; - - n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - buttons, - buttons_capacity); - - while (n_buttons > buttons_capacity) { - buttons_capacity = n_buttons; - buttons = (guchar *) g_realloc (buttons, - buttons_capacity * sizeof (guchar)); - - n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - buttons, - buttons_capacity); - } - - configure_button_layout (buttons, n_buttons, left_handed); - - XSetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, buttons, n_buttons); - XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); - } - g_free (buttons); - - if (device_info != NULL) - XFreeDeviceList (device_info); -} - -static GdkFilterReturn -devicepresence_filter (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) -{ - XEvent *xev = (XEvent *) xevent; - XEventClass class_presence; - int xi_presence; - - DevicePresence (gdk_x11_get_default_xdisplay (), xi_presence, class_presence); - - if (xev->type == xi_presence) - { - XDevicePresenceNotifyEvent *dpn = (XDevicePresenceNotifyEvent *) xev; - if (dpn->devchange == DeviceEnabled) - set_mouse_settings ((MsdMouseManager *) data); - } - return GDK_FILTER_CONTINUE; -} - -static void -set_devicepresence_handler (MsdMouseManager *manager) -{ - Display *display; - XEventClass class_presence; - int xi_presence; - - if (!supports_xinput_devices ()) - return; - - display = gdk_x11_get_default_xdisplay (); - - gdk_error_trap_push (); - DevicePresence (display, xi_presence, class_presence); - XSelectExtensionEvent (display, - RootWindow (display, DefaultScreen (display)), - &class_presence, 1); - - gdk_flush (); - if (!gdk_error_trap_pop ()) - gdk_window_add_filter (NULL, devicepresence_filter, manager); -} -#endif - -static void -set_left_handed (MsdMouseManager *manager, - gboolean left_handed) -{ - guchar *buttons ; - gsize buttons_capacity = 16; - gint n_buttons, i; - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - if (supports_xinput_devices ()) { - /* When XInput support is available, never set the - * button ordering on the core pointer as that would - * revert the changes we make on the devices themselves */ - set_xinput_devices_left_handed (left_handed); - return; - } -#endif - - buttons = g_new (guchar, buttons_capacity); - n_buttons = XGetPointerMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - buttons, - (gint) buttons_capacity); - while (n_buttons > buttons_capacity) { - buttons_capacity = n_buttons; - buttons = (guchar *) g_realloc (buttons, - buttons_capacity * sizeof (guchar)); - - n_buttons = XGetPointerMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - buttons, - (gint) buttons_capacity); - } - - configure_button_layout (buttons, n_buttons, left_handed); - - /* X refuses to change the mapping while buttons are engaged, - * so if this is the case we'll retry a few times - */ - for (i = 0; - i < 20 && XSetPointerMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), buttons, n_buttons) == MappingBusy; - ++i) { - g_usleep (300); - } - - g_free (buttons); -} - -static void -set_motion_acceleration (MsdMouseManager *manager, - gfloat motion_acceleration) -{ - gint numerator, denominator; - - if (motion_acceleration >= 1.0) { - /* we want to get the acceleration, with a resolution of 0.5 - */ - if ((motion_acceleration - floor (motion_acceleration)) < 0.25) { - numerator = floor (motion_acceleration); - denominator = 1; - } else if ((motion_acceleration - floor (motion_acceleration)) < 0.5) { - numerator = ceil (2.0 * motion_acceleration); - denominator = 2; - } else if ((motion_acceleration - floor (motion_acceleration)) < 0.75) { - numerator = floor (2.0 *motion_acceleration); - denominator = 2; - } else { - numerator = ceil (motion_acceleration); - denominator = 1; - } - } else if (motion_acceleration < 1.0 && motion_acceleration > 0) { - /* This we do to 1/10ths */ - numerator = floor (motion_acceleration * 10) + 1; - denominator= 10; - } else { - numerator = -1; - denominator = -1; - } - - XChangePointerControl (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), True, False, - numerator, denominator, - 0); -} - -static void -set_motion_threshold (MsdMouseManager *manager, - int motion_threshold) -{ - XChangePointerControl (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), False, True, - 0, 0, motion_threshold); -} - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -static XDevice* -device_is_touchpad (XDeviceInfo deviceinfo) -{ - XDevice *device; - Atom realtype, prop; - int realformat; - unsigned long nitems, bytes_after; - unsigned char *data; - - if (deviceinfo.type != XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XI_TOUCHPAD, False)) - return NULL; - - prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Off", False); - if (!prop) - return NULL; - - gdk_error_trap_push (); - device = XOpenDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), deviceinfo.id); - if (gdk_error_trap_pop () || (device == NULL)) - return NULL; - - gdk_error_trap_push (); - if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 1, False, - XA_INTEGER, &realtype, &realformat, &nitems, - &bytes_after, &data) == Success) && (realtype != None)) { - gdk_error_trap_pop (); - XFree (data); - return device; - } - gdk_error_trap_pop (); - - XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); - return NULL; -} -#endif - -static int -set_disable_w_typing (MsdMouseManager *manager, gboolean state) -{ - - if (state) { - GError *error = NULL; - char *args[5]; - - if (manager->priv->syndaemon_spawned) - return 0; - - args[0] = "syndaemon"; - args[1] = "-i"; - args[2] = "0.5"; - args[3] = "-k"; - args[4] = NULL; - - if (!g_find_program_in_path (args[0])) - return 0; - - g_spawn_async (g_get_home_dir (), args, NULL, - G_SPAWN_SEARCH_PATH, NULL, NULL, - &manager->priv->syndaemon_pid, &error); - - manager->priv->syndaemon_spawned = (error == NULL); - - if (error) { - MateConfClient *client; - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_TOUCHPAD_DISABLE_W_TYPING, FALSE, NULL); - g_object_unref (client); - g_error_free (error); - } - - } else if (manager->priv->syndaemon_spawned) - { - kill (manager->priv->syndaemon_pid, SIGHUP); - g_spawn_close_pid (manager->priv->syndaemon_pid); - manager->priv->syndaemon_spawned = FALSE; - } - - return 0; -} - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H -static int -set_tap_to_click (gboolean state, gboolean left_handed) -{ - int numdevices, i, format, rc; - unsigned long nitems, bytes_after; - XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); - XDevice * device; - unsigned char* data; - Atom prop, type; - - if (devicelist == NULL) - return 0; - - prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Tap Action", False); - - if (!prop) - return 0; - - for (i = 0; i < numdevices; i++) { - if ((device = device_is_touchpad (devicelist[i]))) { - gdk_error_trap_push (); - rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 2, - False, XA_INTEGER, &type, &format, &nitems, - &bytes_after, &data); - - if (rc == Success && type == XA_INTEGER && format == 8 && nitems >= 7) - { - /* Set RLM mapping for 1/2/3 fingers*/ - data[4] = (state) ? ((left_handed) ? 3 : 1) : 0; - data[5] = (state) ? ((left_handed) ? 1 : 3) : 0; - data[6] = (state) ? 2 : 0; - XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, XA_INTEGER, 8, - PropModeReplace, data, nitems); - } - - if (rc == Success) - XFree (data); - XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); - if (gdk_error_trap_pop ()) { - g_warning ("Error in setting tap to click on \"%s\"", devicelist[i].name); - continue; - } - } - } - - XFreeDeviceList (devicelist); - return 0; -} - -static int -set_horiz_scroll (gboolean state) -{ - int numdevices, i, rc; - XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); - XDevice *device; - Atom act_type, prop_edge, prop_twofinger; - int act_format; - unsigned long nitems, bytes_after; - unsigned char *data; - - if (devicelist == NULL) - return 0; - - prop_edge = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Edge Scrolling", False); - prop_twofinger = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Two-Finger Scrolling", False); - - if (!prop_edge || !prop_twofinger) - return 0; - - for (i = 0; i < numdevices; i++) { - if ((device = device_is_touchpad (devicelist[i]))) { - gdk_error_trap_push (); - rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_edge, 0, 1, False, - XA_INTEGER, &act_type, &act_format, &nitems, - &bytes_after, &data); - if (rc == Success && act_type == XA_INTEGER && - act_format == 8 && nitems >= 2) { - data[1] = (state && data[0]); - XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_edge, XA_INTEGER, 8, - PropModeReplace, data, nitems); - } - - XFree (data); - - rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_twofinger, 0, 1, False, - XA_INTEGER, &act_type, &act_format, &nitems, - &bytes_after, &data); - if (rc == Success && act_type == XA_INTEGER && - act_format == 8 && nitems >= 2) { - data[1] = (state && data[0]); - XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_twofinger, XA_INTEGER, 8, - PropModeReplace, data, nitems); - } - - XFree (data); - XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); - if (gdk_error_trap_pop ()) { - g_warning ("Error in setting horiz scroll on \"%s\"", devicelist[i].name); - continue; - } - } - } - - XFreeDeviceList (devicelist); - return 0; -} - - -/** - * Scroll methods are: 0 - disabled, 1 - edge scrolling, 2 - twofinger - * scrolling - */ -static int -set_edge_scroll (int method) -{ - int numdevices, i, rc; - XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); - XDevice *device; - Atom act_type, prop_edge, prop_twofinger; - int act_format; - unsigned long nitems, bytes_after; - unsigned char *data; - - if (devicelist == NULL) - return 0; - - prop_edge = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Edge Scrolling", False); - prop_twofinger = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Two-Finger Scrolling", False); - - if (!prop_edge || !prop_twofinger) - return 0; - - for (i = 0; i < numdevices; i++) { - if ((device = device_is_touchpad (devicelist[i]))) { - gdk_error_trap_push (); - rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_edge, 0, 1, False, - XA_INTEGER, &act_type, &act_format, &nitems, - &bytes_after, &data); - if (rc == Success && act_type == XA_INTEGER && - act_format == 8 && nitems >= 2) { - data[0] = (method == 1) ? 1 : 0; - XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_edge, XA_INTEGER, 8, - PropModeReplace, data, nitems); - } - - XFree (data); - - rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_twofinger, 0, 1, False, - XA_INTEGER, &act_type, &act_format, &nitems, - &bytes_after, &data); - if (rc == Success && act_type == XA_INTEGER && - act_format == 8 && nitems >= 2) { - data[0] = (method == 2) ? 1 : 0; - XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_twofinger, XA_INTEGER, 8, - PropModeReplace, data, nitems); - } - - XFree (data); - XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); - if (gdk_error_trap_pop ()) { - g_warning ("Error in setting edge scroll on \"%s\"", devicelist[i].name); - continue; - } - } - } - - XFreeDeviceList (devicelist); - return 0; -} - -static int -set_touchpad_enabled (gboolean state) -{ - int numdevices, i; - XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); - XDevice *device; - Atom prop_enabled; - - if (devicelist == NULL) - return 0; - - prop_enabled = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Device Enabled", False); - - if (!prop_enabled) - return 0; - - for (i = 0; i < numdevices; i++) { - if ((device = device_is_touchpad (devicelist[i]))) { - unsigned char data = state; - gdk_error_trap_push (); - XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, - prop_enabled, XA_INTEGER, 8, - PropModeReplace, &data, 1); - XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); - gdk_flush (); - if (gdk_error_trap_pop ()) { - g_warning ("Error %s device \"%s\"", - (state) ? "enabling" : "disabling", - devicelist[i].name); - continue; - } - } - } - - XFreeDeviceList (devicelist); - return 0; -} -#endif - -static void -set_locate_pointer (MsdMouseManager *manager, - gboolean state) -{ - if (state) { - GError *error = NULL; - char *args[2]; - - if (manager->priv->locate_pointer_spawned) - return; - - args[0] = LIBEXECDIR "/msd-locate-pointer"; - args[1] = NULL; - - g_spawn_async (NULL, args, NULL, - 0, NULL, NULL, - &manager->priv->locate_pointer_pid, &error); - - manager->priv->locate_pointer_spawned = (error == NULL); - - if (error) { - MateConfClient *client; - client = mateconf_client_get_default (); - mateconf_client_set_bool (client, KEY_LOCATE_POINTER, FALSE, NULL); - g_object_unref (client); - g_error_free (error); - } - - } - else if (manager->priv->locate_pointer_spawned) { - kill (manager->priv->locate_pointer_pid, SIGHUP); - g_spawn_close_pid (manager->priv->locate_pointer_pid); - manager->priv->locate_pointer_spawned = FALSE; - } -} - -static void -set_mousetweaks_daemon (MsdMouseManager *manager, - gboolean dwell_enable, - gboolean delay_enable) -{ - GError *error = NULL; - gchar *comm; - gboolean run_daemon = dwell_enable || delay_enable; - - if (run_daemon || manager->priv->mousetweaks_daemon_running) - comm = g_strdup_printf ("mousetweaks %s", - run_daemon ? "" : "-s"); - else - return; - - if (run_daemon) - manager->priv->mousetweaks_daemon_running = TRUE; - - - if (! g_spawn_command_line_async (comm, &error)) { - if (error->code == G_SPAWN_ERROR_NOENT && - (dwell_enable || delay_enable)) { - GtkWidget *dialog; - MateConfClient *client; - - client = mateconf_client_get_default (); - if (dwell_enable) - mateconf_client_set_bool (client, - KEY_DWELL_ENABLE, - FALSE, NULL); - else if (delay_enable) - mateconf_client_set_bool (client, - KEY_DELAY_ENABLE, - FALSE, NULL); - g_object_unref (client); - - dialog = gtk_message_dialog_new (NULL, 0, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - _("Could not enable mouse accessibility features")); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - _("Mouse accessibility requires Mousetweaks " - "to be installed on your system.")); - gtk_window_set_title (GTK_WINDOW (dialog), - _("Mouse Preferences")); - gtk_window_set_icon_name (GTK_WINDOW (dialog), - "input-mouse"); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - } - g_error_free (error); - } - g_free (comm); -} - -static void -set_mouse_settings (MsdMouseManager *manager) -{ - MateConfClient *client = mateconf_client_get_default (); - gboolean left_handed = mateconf_client_get_bool (client, KEY_LEFT_HANDED, NULL); - - set_left_handed (manager, left_handed); - set_motion_acceleration (manager, mateconf_client_get_float (client, KEY_MOTION_ACCELERATION , NULL)); - set_motion_threshold (manager, mateconf_client_get_int (client, KEY_MOTION_THRESHOLD, NULL)); - - set_disable_w_typing (manager, mateconf_client_get_bool (client, KEY_TOUCHPAD_DISABLE_W_TYPING, NULL)); -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - set_tap_to_click (mateconf_client_get_bool (client, KEY_TAP_TO_CLICK, NULL), left_handed); - set_edge_scroll (mateconf_client_get_int (client, KEY_SCROLL_METHOD, NULL)); - set_horiz_scroll (mateconf_client_get_bool (client, KEY_PAD_HORIZ_SCROLL, NULL)); - set_touchpad_enabled (mateconf_client_get_bool (client, KEY_TOUCHPAD_ENABLED, NULL)); -#endif - - g_object_unref (client); -} - -static void -mouse_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdMouseManager *manager) -{ - if (! strcmp (entry->key, KEY_LEFT_HANDED)) { - if (entry->value->type == MATECONF_VALUE_BOOL) { - set_left_handed (manager, mateconf_value_get_bool (entry->value)); - } - } else if (! strcmp (entry->key, KEY_MOTION_ACCELERATION)) { - if (entry->value->type == MATECONF_VALUE_FLOAT) { - set_motion_acceleration (manager, mateconf_value_get_float (entry->value)); - } - } else if (! strcmp (entry->key, KEY_MOTION_THRESHOLD)) { - if (entry->value->type == MATECONF_VALUE_INT) { - set_motion_threshold (manager, mateconf_value_get_int (entry->value)); - } - } else if (! strcmp (entry->key, KEY_TOUCHPAD_DISABLE_W_TYPING)) { - if (entry->value->type == MATECONF_VALUE_BOOL) - set_disable_w_typing (manager, mateconf_value_get_bool (entry->value)); -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - } else if (! strcmp (entry->key, KEY_TAP_TO_CLICK)) { - if (entry->value->type == MATECONF_VALUE_BOOL) { - set_tap_to_click (mateconf_value_get_bool (entry->value), - mateconf_client_get_bool (client, KEY_LEFT_HANDED, NULL)); - } - } else if (! strcmp (entry->key, KEY_SCROLL_METHOD)) { - if (entry->value->type == MATECONF_VALUE_INT) { - set_edge_scroll (mateconf_value_get_int (entry->value)); - set_horiz_scroll (mateconf_client_get_bool (client, KEY_PAD_HORIZ_SCROLL, NULL)); - } - } else if (! strcmp (entry->key, KEY_PAD_HORIZ_SCROLL)) { - if (entry->value->type == MATECONF_VALUE_BOOL) - set_horiz_scroll (mateconf_value_get_bool (entry->value)); -#endif - } else if (! strcmp (entry->key, KEY_LOCATE_POINTER)) { - if (entry->value->type == MATECONF_VALUE_BOOL) { - set_locate_pointer (manager, mateconf_value_get_bool (entry->value)); - } -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - } else if (! strcmp (entry->key, KEY_TOUCHPAD_ENABLED)) { - if (entry->value->type == MATECONF_VALUE_BOOL) { - set_touchpad_enabled (mateconf_value_get_bool (entry->value)); - } -#endif - } else if (! strcmp (entry->key, KEY_DWELL_ENABLE)) { - if (entry->value->type == MATECONF_VALUE_BOOL) { - set_mousetweaks_daemon (manager, - mateconf_value_get_bool (entry->value), - mateconf_client_get_bool (client, KEY_DELAY_ENABLE, NULL)); - } - } else if (! strcmp (entry->key, KEY_DELAY_ENABLE)) { - if (entry->value->type == MATECONF_VALUE_BOOL) { - set_mousetweaks_daemon (manager, - mateconf_client_get_bool (client, KEY_DWELL_ENABLE, NULL), - mateconf_value_get_bool (entry->value)); - } - } -} - -static guint -register_config_callback (MsdMouseManager *manager, - MateConfClient *client, - const char *path, - MateConfClientNotifyFunc func) -{ - mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - return mateconf_client_notify_add (client, path, func, manager, NULL, NULL); -} - -static void -msd_mouse_manager_init (MsdMouseManager *manager) -{ - manager->priv = MSD_MOUSE_MANAGER_GET_PRIVATE (manager); -} - -static gboolean -msd_mouse_manager_idle_cb (MsdMouseManager *manager) -{ - MateConfClient *client; - - mate_settings_profile_start (NULL); - - client = mateconf_client_get_default (); - - manager->priv->notify = - register_config_callback (manager, - client, - MATECONF_MOUSE_DIR, - (MateConfClientNotifyFunc) mouse_callback); - manager->priv->notify_a11y = - register_config_callback (manager, - client, - MATECONF_MOUSE_A11Y_DIR, - (MateConfClientNotifyFunc) mouse_callback); - manager->priv->notify_touchpad = - register_config_callback (manager, - client, - MATECONF_TOUCHPAD_DIR, - (MateConfClientNotifyFunc) mouse_callback); - manager->priv->syndaemon_spawned = FALSE; - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - set_devicepresence_handler (manager); -#endif - set_mouse_settings (manager); - set_locate_pointer (manager, mateconf_client_get_bool (client, KEY_LOCATE_POINTER, NULL)); - set_mousetweaks_daemon (manager, - mateconf_client_get_bool (client, KEY_DWELL_ENABLE, NULL), - mateconf_client_get_bool (client, KEY_DELAY_ENABLE, NULL)); - - set_disable_w_typing (manager, mateconf_client_get_bool (client, KEY_TOUCHPAD_DISABLE_W_TYPING, NULL)); -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - set_tap_to_click (mateconf_client_get_bool (client, KEY_TAP_TO_CLICK, NULL), - mateconf_client_get_bool (client, KEY_LEFT_HANDED, NULL)); - set_edge_scroll (mateconf_client_get_int (client, KEY_SCROLL_METHOD, NULL)); - set_horiz_scroll (mateconf_client_get_bool (client, KEY_PAD_HORIZ_SCROLL, NULL)); - set_touchpad_enabled (mateconf_client_get_bool (client, KEY_TOUCHPAD_ENABLED, NULL)); -#endif - - g_object_unref (client); - - mate_settings_profile_end (NULL); - - return FALSE; -} - -gboolean -msd_mouse_manager_start (MsdMouseManager *manager, - GError **error) -{ - mate_settings_profile_start (NULL); - - g_idle_add ((GSourceFunc) msd_mouse_manager_idle_cb, manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_mouse_manager_stop (MsdMouseManager *manager) -{ - MsdMouseManagerPrivate *p = manager->priv; - MateConfClient *client; - - g_debug ("Stopping mouse manager"); - - client = mateconf_client_get_default (); - - if (p->notify != 0) { - mateconf_client_remove_dir (client, MATECONF_MOUSE_DIR, NULL); - mateconf_client_notify_remove (client, p->notify); - p->notify = 0; - } - - if (p->notify_a11y != 0) { - mateconf_client_remove_dir (client, MATECONF_MOUSE_A11Y_DIR, NULL); - mateconf_client_notify_remove (client, p->notify_a11y); - p->notify_a11y = 0; - } - - if (p->notify_touchpad != 0) { - mateconf_client_remove_dir (client, MATECONF_TOUCHPAD_DIR, NULL); - mateconf_client_notify_remove (client, p->notify_touchpad); - p->notify_touchpad = 0; - } - - g_object_unref (client); - - set_locate_pointer (manager, FALSE); - -#ifdef HAVE_X11_EXTENSIONS_XINPUT_H - gdk_window_remove_filter (NULL, devicepresence_filter, manager); -#endif -} - -static void -msd_mouse_manager_finalize (GObject *object) -{ - MsdMouseManager *mouse_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_MOUSE_MANAGER (object)); - - mouse_manager = MSD_MOUSE_MANAGER (object); - - g_return_if_fail (mouse_manager->priv != NULL); - - G_OBJECT_CLASS (msd_mouse_manager_parent_class)->finalize (object); -} - -MsdMouseManager * -msd_mouse_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_MOUSE_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_MOUSE_MANAGER (manager_object); -} diff --git a/plugins/mouse/gsd-mouse-manager.h b/plugins/mouse/gsd-mouse-manager.h deleted file mode 100644 index e691d7b..0000000 --- a/plugins/mouse/gsd-mouse-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_MOUSE_MANAGER_H -#define __MSD_MOUSE_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_MOUSE_MANAGER (msd_mouse_manager_get_type ()) -#define MSD_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManager)) -#define MSD_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerClass)) -#define MSD_IS_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MOUSE_MANAGER)) -#define MSD_IS_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MOUSE_MANAGER)) -#define MSD_MOUSE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerClass)) - -typedef struct MsdMouseManagerPrivate MsdMouseManagerPrivate; - -typedef struct -{ - GObject parent; - MsdMouseManagerPrivate *priv; -} MsdMouseManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdMouseManagerClass; - -GType msd_mouse_manager_get_type (void); - -MsdMouseManager * msd_mouse_manager_new (void); -gboolean msd_mouse_manager_start (MsdMouseManager *manager, - GError **error); -void msd_mouse_manager_stop (MsdMouseManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_MOUSE_MANAGER_H */ diff --git a/plugins/mouse/gsd-mouse-plugin.c b/plugins/mouse/gsd-mouse-plugin.c deleted file mode 100644 index 7203002..0000000 --- a/plugins/mouse/gsd-mouse-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-mouse-plugin.h" -#include "msd-mouse-manager.h" - -struct MsdMousePluginPrivate { - MsdMouseManager *manager; -}; - -#define MSD_MOUSE_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdMousePlugin, msd_mouse_plugin) - -static void -msd_mouse_plugin_init (MsdMousePlugin *plugin) -{ - plugin->priv = MSD_MOUSE_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdMousePlugin initializing"); - - plugin->priv->manager = msd_mouse_manager_new (); -} - -static void -msd_mouse_plugin_finalize (GObject *object) -{ - MsdMousePlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_MOUSE_PLUGIN (object)); - - g_debug ("MsdMousePlugin finalizing"); - - plugin = MSD_MOUSE_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_mouse_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating mouse plugin"); - - error = NULL; - res = msd_mouse_manager_start (MSD_MOUSE_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start mouse manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating mouse plugin"); - msd_mouse_manager_stop (MSD_MOUSE_PLUGIN (plugin)->priv->manager); -} - -static void -msd_mouse_plugin_class_init (MsdMousePluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_mouse_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdMousePluginPrivate)); -} diff --git a/plugins/mouse/gsd-mouse-plugin.h b/plugins/mouse/gsd-mouse-plugin.h deleted file mode 100644 index 2c2da6c..0000000 --- a/plugins/mouse/gsd-mouse-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_MOUSE_PLUGIN_H__ -#define __MSD_MOUSE_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_MOUSE_PLUGIN (msd_mouse_plugin_get_type ()) -#define MSD_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MOUSE_PLUGIN, MsdMousePlugin)) -#define MSD_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginClass)) -#define MSD_IS_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MOUSE_PLUGIN)) -#define MSD_IS_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MOUSE_PLUGIN)) -#define MSD_MOUSE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginClass)) - -typedef struct MsdMousePluginPrivate MsdMousePluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdMousePluginPrivate *priv; -} MsdMousePlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdMousePluginClass; - -GType msd_mouse_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_MOUSE_PLUGIN_H__ */ diff --git a/plugins/mouse/gsd-timeline.c b/plugins/mouse/gsd-timeline.c deleted file mode 100644 index 9bcfd2f..0000000 --- a/plugins/mouse/gsd-timeline.c +++ /dev/null @@ -1,848 +0,0 @@ -/* msd-timeline.c - * - * Copyright (C) 2008 Carlos Garnacho - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include -#include -#include -#include "msd-timeline.h" - -#define MSD_TIMELINE_GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSD_TYPE_TIMELINE, MsdTimelinePriv)) -#define MSECS_PER_SEC 1000 -#define FRAME_INTERVAL(nframes) (MSECS_PER_SEC / nframes) -#define DEFAULT_FPS 30 - -typedef struct MsdTimelinePriv MsdTimelinePriv; - -struct MsdTimelinePriv -{ - guint duration; - guint fps; - guint source_id; - - GTimer *timer; - - GdkScreen *screen; - MsdTimelineProgressType progress_type; - MsdTimelineProgressFunc progress_func; - - guint loop : 1; - guint direction : 1; -}; - -enum { - PROP_0, - PROP_FPS, - PROP_DURATION, - PROP_LOOP, - PROP_DIRECTION, - PROP_SCREEN, - PROP_PROGRESS_TYPE, -}; - -enum { - STARTED, - PAUSED, - FINISHED, - FRAME, - LAST_SIGNAL -}; - -static guint signals [LAST_SIGNAL] = { 0, }; - - -static void msd_timeline_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void msd_timeline_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void msd_timeline_finalize (GObject *object); - - -G_DEFINE_TYPE (MsdTimeline, msd_timeline, G_TYPE_OBJECT) - - -GType -msd_timeline_direction_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - static const GEnumValue values[] = { - { MSD_TIMELINE_DIRECTION_FORWARD, "MSD_TIMELINE_DIRECTION_FORWARD", "forward" }, - { MSD_TIMELINE_DIRECTION_BACKWARD, "MSD_TIMELINE_DIRECTION_BACKWARD", "backward" }, - { 0, NULL, NULL } - }; - - type = g_enum_register_static (g_intern_static_string ("MsdTimelineDirection"), values); - } - - return type; -} - -GType -msd_timeline_progress_type_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - static const GEnumValue values[] = { - { MSD_TIMELINE_PROGRESS_LINEAR, "MSD_TIMELINE_PROGRESS_LINEAR", "linear" }, - { MSD_TIMELINE_PROGRESS_SINUSOIDAL, "MSD_TIMELINE_PROGRESS_SINUSOIDAL", "sinusoidal" }, - { MSD_TIMELINE_PROGRESS_EXPONENTIAL, "MSD_TIMELINE_PROGRESS_EXPONENTIAL", "exponential" }, - { 0, NULL, NULL } - }; - - type = g_enum_register_static (g_intern_static_string ("MsdTimelineProgressType"), values); - } - - return type; -} - -static void -msd_timeline_class_init (MsdTimelineClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->set_property = msd_timeline_set_property; - object_class->get_property = msd_timeline_get_property; - object_class->finalize = msd_timeline_finalize; - - g_object_class_install_property (object_class, - PROP_FPS, - g_param_spec_uint ("fps", - "FPS", - "Frames per second for the timeline", - 1, - G_MAXUINT, - DEFAULT_FPS, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_DURATION, - g_param_spec_uint ("duration", - "Animation Duration", - "Animation Duration", - 0, - G_MAXUINT, - 0, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_LOOP, - g_param_spec_boolean ("loop", - "Loop", - "Whether the timeline loops or not", - FALSE, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_DIRECTION, - g_param_spec_enum ("direction", - "Direction", - "Whether the timeline moves forward or backward in time", - MSD_TYPE_TIMELINE_DIRECTION, - MSD_TIMELINE_DIRECTION_FORWARD, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_DIRECTION, - g_param_spec_enum ("progress-type", - "Progress type", - "Type of progress through the timeline", - MSD_TYPE_TIMELINE_PROGRESS_TYPE, - MSD_TIMELINE_PROGRESS_LINEAR, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_SCREEN, - g_param_spec_object ("screen", - "Screen", - "Screen to get the settings from", - GDK_TYPE_SCREEN, - G_PARAM_READWRITE)); - - signals[STARTED] = - g_signal_new ("started", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdTimelineClass, started), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[PAUSED] = - g_signal_new ("paused", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdTimelineClass, paused), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[FINISHED] = - g_signal_new ("finished", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdTimelineClass, finished), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[FRAME] = - g_signal_new ("frame", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdTimelineClass, frame), - NULL, NULL, - g_cclosure_marshal_VOID__DOUBLE, - G_TYPE_NONE, 1, - G_TYPE_DOUBLE); - - g_type_class_add_private (class, sizeof (MsdTimelinePriv)); -} - -static void -msd_timeline_init (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - priv->fps = DEFAULT_FPS; - priv->duration = 0; - priv->direction = MSD_TIMELINE_DIRECTION_FORWARD; - priv->screen = gdk_screen_get_default (); -} - -static void -msd_timeline_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdTimeline *timeline; - MsdTimelinePriv *priv; - - timeline = MSD_TIMELINE (object); - priv = MSD_TIMELINE_GET_PRIV (timeline); - - switch (prop_id) - { - case PROP_FPS: - msd_timeline_set_fps (timeline, g_value_get_uint (value)); - break; - case PROP_DURATION: - msd_timeline_set_duration (timeline, g_value_get_uint (value)); - break; - case PROP_LOOP: - msd_timeline_set_loop (timeline, g_value_get_boolean (value)); - break; - case PROP_DIRECTION: - msd_timeline_set_direction (timeline, g_value_get_enum (value)); - break; - case PROP_SCREEN: - msd_timeline_set_screen (timeline, - GDK_SCREEN (g_value_get_object (value))); - break; - case PROP_PROGRESS_TYPE: - msd_timeline_set_progress_type (timeline, g_value_get_enum (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -msd_timeline_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdTimeline *timeline; - MsdTimelinePriv *priv; - - timeline = MSD_TIMELINE (object); - priv = MSD_TIMELINE_GET_PRIV (timeline); - - switch (prop_id) - { - case PROP_FPS: - g_value_set_uint (value, priv->fps); - break; - case PROP_DURATION: - g_value_set_uint (value, priv->duration); - break; - case PROP_LOOP: - g_value_set_boolean (value, priv->loop); - break; - case PROP_DIRECTION: - g_value_set_enum (value, priv->direction); - break; - case PROP_SCREEN: - g_value_set_object (value, priv->screen); - break; - case PROP_PROGRESS_TYPE: - g_value_set_enum (value, priv->progress_type); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -msd_timeline_finalize (GObject *object) -{ - MsdTimelinePriv *priv; - - priv = MSD_TIMELINE_GET_PRIV (object); - - if (priv->source_id) - { - g_source_remove (priv->source_id); - priv->source_id = 0; - } - - if (priv->timer) - g_timer_destroy (priv->timer); - - G_OBJECT_CLASS (msd_timeline_parent_class)->finalize (object); -} - -/* Sinusoidal progress */ -static gdouble -sinusoidal_progress (gdouble progress) -{ - return (sinf ((progress * G_PI) / 2)); -} - -static gdouble -exponential_progress (gdouble progress) -{ - return progress * progress; -} - -static MsdTimelineProgressFunc -progress_type_to_func (MsdTimelineProgressType type) -{ - if (type == MSD_TIMELINE_PROGRESS_SINUSOIDAL) - return sinusoidal_progress; - else if (type == MSD_TIMELINE_PROGRESS_EXPONENTIAL) - return exponential_progress; - - return NULL; -} - -static gboolean -msd_timeline_run_frame (MsdTimeline *timeline, - gboolean enable_animations) -{ - MsdTimelinePriv *priv; - gdouble linear_progress, progress; - guint elapsed_time; - MsdTimelineProgressFunc progress_func = NULL; - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - if (enable_animations) - { - elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000); - - linear_progress = (gdouble) elapsed_time / priv->duration; - - if (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD) - linear_progress = 1 - linear_progress; - - linear_progress = CLAMP (linear_progress, 0., 1.); - - if (priv->progress_func) - progress_func = priv->progress_func; - else if (priv->progress_type) - progress_func = progress_type_to_func (priv->progress_type); - - if (progress_func) - progress = (progress_func) (linear_progress); - else - progress = linear_progress; - } - else - progress = (priv->direction == MSD_TIMELINE_DIRECTION_FORWARD) ? 1.0 : 0.0; - - g_signal_emit (timeline, signals [FRAME], 0, - CLAMP (progress, 0.0, 1.0)); - - if ((priv->direction == MSD_TIMELINE_DIRECTION_FORWARD && progress >= 1.0) || - (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD && progress <= 0.0)) - { - if (!priv->loop) - { - if (priv->source_id) - { - g_source_remove (priv->source_id); - priv->source_id = 0; - } - - g_signal_emit (timeline, signals [FINISHED], 0); - return FALSE; - } - else - msd_timeline_rewind (timeline); - } - - return TRUE; -} - -static gboolean -msd_timeline_frame_idle_func (MsdTimeline *timeline) -{ - return msd_timeline_run_frame (timeline, TRUE); -} - -/** - * msd_timeline_new: - * @duration: duration in milliseconds for the timeline - * - * Creates a new #MsdTimeline with the specified number of frames. - * - * Return Value: the newly created #MsdTimeline - **/ -MsdTimeline * -msd_timeline_new (guint duration) -{ - return g_object_new (MSD_TYPE_TIMELINE, - "duration", duration, - NULL); -} - -MsdTimeline * -msd_timeline_new_for_screen (guint duration, - GdkScreen *screen) -{ - return g_object_new (MSD_TYPE_TIMELINE, - "duration", duration, - "screen", screen, - NULL); -} - -/** - * msd_timeline_start: - * @timeline: A #MsdTimeline - * - * Runs the timeline from the current frame. - **/ -void -msd_timeline_start (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - GtkSettings *settings; - gboolean enable_animations = FALSE; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - if (priv->screen) - { - settings = gtk_settings_get_for_screen (priv->screen); - g_object_get (settings, "gtk-enable-animations", &enable_animations, NULL); - } - - if (enable_animations) - { - if (!priv->source_id) - { - if (priv->timer) - g_timer_continue (priv->timer); - else - priv->timer = g_timer_new (); - - /* sanity check */ - g_assert (priv->fps > 0); - - g_signal_emit (timeline, signals [STARTED], 0); - - priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), - (GSourceFunc) msd_timeline_frame_idle_func, - timeline); - } - } - else - { - /* If animations are not enabled, only run the last frame, - * it take us instantaneously to the last state of the animation. - * The only potential flaw happens when people use the ::finished - * signal to trigger another animation, or even worse, finally - * loop into this animation again. - */ - g_signal_emit (timeline, signals [STARTED], 0); - msd_timeline_run_frame (timeline, FALSE); - } -} - -/** - * msd_timeline_pause: - * @timeline: A #MsdTimeline - * - * Pauses the timeline. - **/ -void -msd_timeline_pause (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - if (priv->source_id) - { - g_source_remove (priv->source_id); - priv->source_id = 0; - g_timer_stop (priv->timer); - g_signal_emit (timeline, signals [PAUSED], 0); - } -} - -/** - * msd_timeline_rewind: - * @timeline: A #MsdTimeline - * - * Rewinds the timeline. - **/ -void -msd_timeline_rewind (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - /* destroy and re-create timer if neccesary */ - if (priv->timer) - { - g_timer_destroy (priv->timer); - - if (msd_timeline_is_running (timeline)) - priv->timer = g_timer_new (); - else - priv->timer = NULL; - } -} - -/** - * msd_timeline_is_running: - * @timeline: A #MsdTimeline - * - * Returns whether the timeline is running or not. - * - * Return Value: %TRUE if the timeline is running - **/ -gboolean -msd_timeline_is_running (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), FALSE); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - return (priv->source_id != 0); -} - -/** - * msd_timeline_get_fps: - * @timeline: A #MsdTimeline - * - * Returns the number of frames per second. - * - * Return Value: frames per second - **/ -guint -msd_timeline_get_fps (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 1); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - return priv->fps; -} - -/** - * msd_timeline_set_fps: - * @timeline: A #MsdTimeline - * @fps: frames per second - * - * Sets the number of frames per second that - * the timeline will play. - **/ -void -msd_timeline_set_fps (MsdTimeline *timeline, - guint fps) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - g_return_if_fail (fps > 0); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - priv->fps = fps; - - if (msd_timeline_is_running (timeline)) - { - g_source_remove (priv->source_id); - priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), - (GSourceFunc) msd_timeline_run_frame, - timeline); - } - - g_object_notify (G_OBJECT (timeline), "fps"); -} - -/** - * msd_timeline_get_loop: - * @timeline: A #MsdTimeline - * - * Returns whether the timeline loops to the - * beginning when it has reached the end. - * - * Return Value: %TRUE if the timeline loops - **/ -gboolean -msd_timeline_get_loop (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), FALSE); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - return priv->loop; -} - -/** - * msd_timeline_set_loop: - * @timeline: A #MsdTimeline - * @loop: %TRUE to make the timeline loop - * - * Sets whether the timeline loops to the beginning - * when it has reached the end. - **/ -void -msd_timeline_set_loop (MsdTimeline *timeline, - gboolean loop) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - priv->loop = loop; - - g_object_notify (G_OBJECT (timeline), "loop"); -} - -void -msd_timeline_set_duration (MsdTimeline *timeline, - guint duration) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - priv->duration = duration; - - g_object_notify (G_OBJECT (timeline), "duration"); -} - -guint -msd_timeline_get_duration (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 0); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - return priv->duration; -} - -/** - * msd_timeline_get_direction: - * @timeline: A #MsdTimeline - * - * Returns the direction of the timeline. - * - * Return Value: direction - **/ -MsdTimelineDirection -msd_timeline_get_direction (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), MSD_TIMELINE_DIRECTION_FORWARD); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - return priv->direction; -} - -/** - * msd_timeline_set_direction: - * @timeline: A #MsdTimeline - * @direction: direction - * - * Sets the direction of the timeline. - **/ -void -msd_timeline_set_direction (MsdTimeline *timeline, - MsdTimelineDirection direction) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - priv->direction = direction; - - g_object_notify (G_OBJECT (timeline), "direction"); -} - -GdkScreen * -msd_timeline_get_screen (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), NULL); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - return priv->screen; -} - -void -msd_timeline_set_screen (MsdTimeline *timeline, - GdkScreen *screen) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - g_return_if_fail (GDK_IS_SCREEN (screen)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - if (priv->screen) - g_object_unref (priv->screen); - - priv->screen = g_object_ref (screen); - - g_object_notify (G_OBJECT (timeline), "screen"); -} - -void -msd_timeline_set_progress_type (MsdTimeline *timeline, - MsdTimelineProgressType type) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - priv->progress_type = type; - - g_object_notify (G_OBJECT (timeline), "progress-type"); -} - -MsdTimelineProgressType -msd_timeline_get_progress_type (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), MSD_TIMELINE_PROGRESS_LINEAR); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - if (priv->progress_func) - return MSD_TIMELINE_PROGRESS_LINEAR; - - return priv->progress_type; -} - -/** - * msd_timeline_set_progress_func: - * @timeline: A #MsdTimeline - * @progress_func: progress function - * - * Sets the progress function. This function will be used to calculate - * a different progress to pass to the ::frame signal based on the - * linear progress through the timeline. Setting progress_func - * to %NULL will make the timeline use the default function, - * which is just a linear progress. - * - * All progresses are in the [0.0, 1.0] range. - **/ -void -msd_timeline_set_progress_func (MsdTimeline *timeline, - MsdTimelineProgressFunc progress_func) -{ - MsdTimelinePriv *priv; - - g_return_if_fail (MSD_IS_TIMELINE (timeline)); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - priv->progress_func = progress_func; -} - -gdouble -msd_timeline_get_progress (MsdTimeline *timeline) -{ - MsdTimelinePriv *priv; - MsdTimelineProgressFunc progress_func = NULL; - gdouble linear_progress, progress; - guint elapsed_time; - - g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 0.0); - - priv = MSD_TIMELINE_GET_PRIV (timeline); - - if (!priv->timer) - return 0.; - - elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000); - - linear_progress = (gdouble) elapsed_time / priv->duration; - - if (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD) - linear_progress = 1 - linear_progress; - - linear_progress = CLAMP (linear_progress, 0., 1.); - - if (priv->progress_func) - progress_func = priv->progress_func; - else if (priv->progress_type) - progress_func = progress_type_to_func (priv->progress_type); - - if (progress_func) - progress = (progress_func) (linear_progress); - else - progress = linear_progress; - - return CLAMP (progress, 0., 1.); -} diff --git a/plugins/mouse/gsd-timeline.h b/plugins/mouse/gsd-timeline.h deleted file mode 100644 index b8d40ca..0000000 --- a/plugins/mouse/gsd-timeline.h +++ /dev/null @@ -1,127 +0,0 @@ -/* msdtimeline.c - * - * Copyright (C) 2008 Carlos Garnacho - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __MSD_TIMELINE_H__ -#define __MSD_TIMELINE_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_TIMELINE_DIRECTION (msd_timeline_direction_get_type ()) -#define MSD_TYPE_TIMELINE_PROGRESS_TYPE (msd_timeline_progress_type_get_type ()) -#define MSD_TYPE_TIMELINE (msd_timeline_get_type ()) -#define MSD_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_TIMELINE, MsdTimeline)) -#define MSD_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_TIMELINE, MsdTimelineClass)) -#define MSD_IS_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_TIMELINE)) -#define MSD_IS_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_TIMELINE)) -#define MSD_TIMELINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_TIMELINE, MsdTimelineClass)) - -typedef enum { - MSD_TIMELINE_DIRECTION_FORWARD, - MSD_TIMELINE_DIRECTION_BACKWARD -} MsdTimelineDirection; - -typedef enum { - MSD_TIMELINE_PROGRESS_LINEAR, - MSD_TIMELINE_PROGRESS_SINUSOIDAL, - MSD_TIMELINE_PROGRESS_EXPONENTIAL -} MsdTimelineProgressType; - -typedef struct MsdTimeline MsdTimeline; -typedef struct MsdTimelineClass MsdTimelineClass; - -struct MsdTimeline -{ - GObject parent_instance; -}; - -struct MsdTimelineClass -{ - GObjectClass parent_class; - - void (* started) (MsdTimeline *timeline); - void (* finished) (MsdTimeline *timeline); - void (* paused) (MsdTimeline *timeline); - - void (* frame) (MsdTimeline *timeline, - gdouble progress); - - void (* __msd_reserved1) (void); - void (* __msd_reserved2) (void); - void (* __msd_reserved3) (void); - void (* __msd_reserved4) (void); -}; - -typedef gdouble (*MsdTimelineProgressFunc) (gdouble progress); - - -GType msd_timeline_get_type (void) G_GNUC_CONST; -GType msd_timeline_direction_get_type (void) G_GNUC_CONST; -GType msd_timeline_progress_type_get_type (void) G_GNUC_CONST; - -MsdTimeline *msd_timeline_new (guint duration); -MsdTimeline *msd_timeline_new_for_screen (guint duration, - GdkScreen *screen); - -void msd_timeline_start (MsdTimeline *timeline); -void msd_timeline_pause (MsdTimeline *timeline); -void msd_timeline_rewind (MsdTimeline *timeline); - -gboolean msd_timeline_is_running (MsdTimeline *timeline); - -guint msd_timeline_get_fps (MsdTimeline *timeline); -void msd_timeline_set_fps (MsdTimeline *timeline, - guint fps); - -gboolean msd_timeline_get_loop (MsdTimeline *timeline); -void msd_timeline_set_loop (MsdTimeline *timeline, - gboolean loop); - -guint msd_timeline_get_duration (MsdTimeline *timeline); -void msd_timeline_set_duration (MsdTimeline *timeline, - guint duration); - -GdkScreen *msd_timeline_get_screen (MsdTimeline *timeline); -void msd_timeline_set_screen (MsdTimeline *timeline, - GdkScreen *screen); - -MsdTimelineDirection msd_timeline_get_direction (MsdTimeline *timeline); -void msd_timeline_set_direction (MsdTimeline *timeline, - MsdTimelineDirection direction); - -MsdTimelineProgressType msd_timeline_get_progress_type (MsdTimeline *timeline); -void msd_timeline_set_progress_type (MsdTimeline *timeline, - MsdTimelineProgressType type); -void msd_timeline_get_progress_func (MsdTimeline *timeline); - -void msd_timeline_set_progress_func (MsdTimeline *timeline, - MsdTimelineProgressFunc progress_func); - -gdouble msd_timeline_get_progress (MsdTimeline *timeline); - - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_TIMELINE_H__ */ diff --git a/plugins/mouse/msd-locate-pointer.c b/plugins/mouse/msd-locate-pointer.c new file mode 100644 index 0000000..8582074 --- /dev/null +++ b/plugins/mouse/msd-locate-pointer.c @@ -0,0 +1,504 @@ +/* msd-locate-pointer.c + * + * Copyright (C) 2008 Carlos Garnacho + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include "msd-timeline.h" +#include "msd-locate-pointer.h" + +#include +#include +#include + +#define ANIMATION_LENGTH 750 +#define WINDOW_SIZE 101 +#define N_CIRCLES 4 + +/* All circles are supposed to be moving when progress + * reaches 0.5, and each of them are supposed to long + * for half of the progress, hence the need of 0.5 to + * get the circles interval, and the multiplication + * by 2 to know a circle progress */ +#define CIRCLES_PROGRESS_INTERVAL (0.5 / N_CIRCLES) +#define CIRCLE_PROGRESS(p) (MIN (1., ((gdouble) (p) * 2.))) + +typedef struct MsdLocatePointerData MsdLocatePointerData; + +struct MsdLocatePointerData +{ + MsdTimeline *timeline; + GtkWidget *widget; + GdkWindow *window; + + gdouble progress; +}; + +static MsdLocatePointerData *data = NULL; + +static void +locate_pointer_paint (MsdLocatePointerData *data, + cairo_t *cr, + gboolean composite) +{ + GdkColor color; + gdouble progress, circle_progress; + gint width, height, i; + GtkStyle *style; + + progress = data->progress; + + #if GTK_CHECK_VERSION(3, 0, 0) + width = gdk_window_get_width(GDK_WINDOW(data->window)); + height = gdk_window_get_height(GDK_WINDOW(data->window)); + #else + gdk_drawable_get_size(data->window, &width, &height); + #endif + + style = gtk_widget_get_style (data->widget); + color = style->bg[GTK_STATE_SELECTED]; + + cairo_set_source_rgba (cr, 1., 1., 1., 0.); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr); + + for (i = 0; i <= N_CIRCLES; i++) + { + if (progress < 0.) + break; + + circle_progress = MIN (1., (progress * 2)); + progress -= CIRCLES_PROGRESS_INTERVAL; + + if (circle_progress >= 1.) + continue; + + if (composite) + { + cairo_set_source_rgba (cr, + color.red / 65535., + color.green / 65535., + color.blue / 65535., + 1 - circle_progress); + cairo_arc (cr, + width / 2, + height / 2, + circle_progress * width / 2, + 0, 2 * G_PI); + + cairo_fill (cr); + cairo_stroke (cr); + } + else + { + cairo_set_source_rgb (cr, 0., 0., 0.); + cairo_set_line_width (cr, 3.); + cairo_arc (cr, + width / 2, + height / 2, + circle_progress * width / 2, + 0, 2 * G_PI); + cairo_stroke (cr); + + cairo_set_source_rgb (cr, 1., 1., 1.); + cairo_set_line_width (cr, 1.); + cairo_arc (cr, + width / 2, + height / 2, + circle_progress * width / 2, + 0, 2 * G_PI); + cairo_stroke (cr); + } + } +} + +static gboolean +locate_pointer_expose (GtkWidget *widget, + GdkEventExpose *event, + gpointer user_data) +{ + MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; + cairo_t *cr; + + if (event->window != data->window) + return FALSE; + + cr = gdk_cairo_create (data->window); + locate_pointer_paint (data, cr, gtk_widget_is_composited (data->widget)); + cairo_destroy (cr); + + return TRUE; +} + +static void +update_shape (MsdLocatePointerData *data) +{ + cairo_t *cr; + GdkBitmap *mask; + + mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1); + cr = gdk_cairo_create (mask); + locate_pointer_paint (data, cr, FALSE); + gdk_window_shape_combine_mask (data->window, mask, 0, 0); + g_object_unref (mask); + cairo_destroy (cr); +} + +static void +timeline_frame_cb (MsdTimeline *timeline, + gdouble progress, + gpointer user_data) +{ + MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; + GdkScreen *screen; + gint cursor_x, cursor_y; + + if (gtk_widget_is_composited (data->widget)) + { + gdk_window_invalidate_rect (data->window, NULL, FALSE); + data->progress = progress; + } + else if (progress >= data->progress + CIRCLES_PROGRESS_INTERVAL) + { + /* only invalidate window each circle interval */ + update_shape (data); + gdk_window_invalidate_rect (data->window, NULL, FALSE); + data->progress += CIRCLES_PROGRESS_INTERVAL; + } + + screen = gdk_drawable_get_screen (data->window); + gdk_window_get_pointer (gdk_screen_get_root_window (screen), + &cursor_x, &cursor_y, NULL); + gdk_window_move (data->window, + cursor_x - WINDOW_SIZE / 2, + cursor_y - WINDOW_SIZE / 2); +} + +static void +set_transparent_shape (GdkWindow *window) +{ + GdkBitmap *mask; + cairo_t *cr; + + mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1); + cr = gdk_cairo_create (mask); + + cairo_set_source_rgba (cr, 1., 1., 1., 0.); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr); + + gdk_window_shape_combine_mask (data->window, mask, 0, 0); + g_object_unref (mask); + cairo_destroy (cr); +} + +static void +unset_transparent_shape (GdkWindow *window) +{ + gdk_window_shape_combine_mask (data->window, NULL, 0, 0); +} + +static void +composited_changed (GtkWidget *widget, + MsdLocatePointerData *data) +{ + if (!gtk_widget_is_composited (widget)) + set_transparent_shape (data->window); + else + unset_transparent_shape (data->window); +} + +static void +timeline_finished_cb (MsdTimeline *timeline, + gpointer user_data) +{ + MsdLocatePointerData *data = (MsdLocatePointerData *) user_data; + + /* set transparent shape and hide window */ + if (!gtk_widget_is_composited (data->widget)) + set_transparent_shape (data->window); + + gdk_window_hide (data->window); +} + +static void +create_window (MsdLocatePointerData *data, + GdkScreen *screen) +{ + GdkColormap *colormap; + GdkVisual *visual; + GdkWindowAttr attributes; + + colormap = gdk_screen_get_rgba_colormap (screen); + visual = gdk_screen_get_rgba_visual (screen); + + if (!colormap) + { + colormap = gdk_screen_get_rgb_colormap (screen); + visual = gdk_screen_get_rgb_visual (screen); + } + + attributes.window_type = GDK_WINDOW_TEMP; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.visual = visual; + attributes.colormap = colormap; + attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK; + attributes.width = 1; + attributes.height = 1; + + data->window = gdk_window_new (gdk_screen_get_root_window (screen), + &attributes, + GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP); + + gdk_window_set_user_data (data->window, data->widget); +} + +static MsdLocatePointerData * +msd_locate_pointer_data_new (GdkScreen *screen) +{ + MsdLocatePointerData *data; + + data = g_new0 (MsdLocatePointerData, 1); + + /* this widget will never be shown, it's + * mainly used to get signals/events from + */ + data->widget = gtk_window_new (GTK_WINDOW_POPUP); + gtk_widget_realize (data->widget); + + g_signal_connect (G_OBJECT (data->widget), "expose_event", + G_CALLBACK (locate_pointer_expose), + data); + + data->timeline = msd_timeline_new (ANIMATION_LENGTH); + g_signal_connect (data->timeline, "frame", + G_CALLBACK (timeline_frame_cb), data); + g_signal_connect (data->timeline, "finished", + G_CALLBACK (timeline_finished_cb), data); + + create_window (data, screen); + + return data; +} + +static void +move_locate_pointer_window (MsdLocatePointerData *data, + GdkScreen *screen) +{ + gint cursor_x, cursor_y; + GdkBitmap *mask; + GdkColor col; + GdkGC *gc; + + gdk_window_get_pointer (gdk_screen_get_root_window (screen), &cursor_x, &cursor_y, NULL); + + gdk_window_move_resize (data->window, + cursor_x - WINDOW_SIZE / 2, + cursor_y - WINDOW_SIZE / 2, + WINDOW_SIZE, WINDOW_SIZE); + + col.pixel = 0; + mask = gdk_pixmap_new (data->window, WINDOW_SIZE, WINDOW_SIZE, 1); + + gc = gdk_gc_new (mask); + gdk_gc_set_foreground (gc, &col); + gdk_draw_rectangle (mask, gc, TRUE, 0, 0, WINDOW_SIZE, WINDOW_SIZE); + + /* allow events to happen through the window */ + gdk_window_input_shape_combine_mask (data->window, mask, 0, 0); + + g_object_unref (mask); + g_object_unref (gc); +} + +void +msd_locate_pointer (GdkScreen *screen) +{ + if (!data) + data = msd_locate_pointer_data_new (screen); + + msd_timeline_pause (data->timeline); + msd_timeline_rewind (data->timeline); + + /* Create again the window if it is not for the current screen */ + if (gdk_screen_get_number (screen) != gdk_screen_get_number (gdk_drawable_get_screen (data->window))) + { + gdk_window_set_user_data (data->window, NULL); + gdk_window_destroy (data->window); + + create_window (data, screen); + } + + data->progress = 0.; + + g_signal_connect (data->widget, "composited-changed", + G_CALLBACK (composited_changed), data); + + move_locate_pointer_window (data, screen); + composited_changed (data->widget, data); + gdk_window_show (data->window); + + msd_timeline_start (data->timeline); +} + + +#define KEYBOARD_GROUP_SHIFT 13 +#define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14)) + +/* Owen magic */ +static GdkFilterReturn +filter (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) +{ + XEvent *xev = (XEvent *) xevent; + guint keyval; + gint group; + + GdkScreen *screen = (GdkScreen *)data; + + if (xev->type == KeyPress || xev->type == KeyRelease) + { + /* get the keysym */ + group = (xev->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT; + gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), + xev->xkey.keycode, + xev->xkey.state, + group, + &keyval, + NULL, NULL, NULL); + if (keyval == GDK_Control_L || keyval == GDK_Control_R) + { + if (xev->type == KeyPress) + { + XAllowEvents (xev->xkey.display, + SyncKeyboard, + xev->xkey.time); + } + else + { + XAllowEvents (xev->xkey.display, + AsyncKeyboard, + xev->xkey.time); + msd_locate_pointer (screen); + } + } + else + { + XAllowEvents (xev->xkey.display, + ReplayKeyboard, + xev->xkey.time); + XUngrabKeyboard (gdk_x11_get_default_xdisplay (), + xev->xkey.time); + } + } + + return GDK_FILTER_CONTINUE; +} + +static void +set_locate_pointer (void) +{ + GdkKeymapKey *keys; + GdkDisplay *display; + int n_screens; + int n_keys; + gboolean has_entries; + static const guint keyvals[] = { GDK_Control_L, GDK_Control_R }; + unsigned j; + + display = gdk_display_get_default (); + n_screens = gdk_display_get_n_screens (display); + + for (j = 0 ; j < G_N_ELEMENTS (keyvals) ; j++) + { + has_entries = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), + keyvals[j], + &keys, + &n_keys); + if (has_entries) + { + gint i, j; + for (i = 0; i < n_keys; i++) + { + for (j=0; j< n_screens; j++) + { + GdkScreen *screen; + Window xroot; + + screen = gdk_display_get_screen (display, j); + xroot = gdk_x11_drawable_get_xid (gdk_screen_get_root_window (screen)); + + XGrabKey (GDK_DISPLAY_XDISPLAY (display), + keys[i].keycode, + 0, + xroot, + False, + GrabModeAsync, + GrabModeSync); + XGrabKey (GDK_DISPLAY_XDISPLAY (display), + keys[i].keycode, + LockMask, + xroot, + False, + GrabModeAsync, + GrabModeSync); + XGrabKey (GDK_DISPLAY_XDISPLAY (display), + keys[i].keycode, + Mod2Mask, + xroot, + False, + GrabModeAsync, + GrabModeSync); + XGrabKey (GDK_DISPLAY_XDISPLAY (display), + keys[i].keycode, + Mod4Mask, + xroot, + False, + GrabModeAsync, + GrabModeSync); + } + } + + g_free (keys); + + for (i = 0; i < n_screens; i++) + { + GdkScreen *screen; + + screen = gdk_display_get_screen (display, i); + gdk_window_add_filter (gdk_screen_get_root_window (screen), + filter, + screen); + } + } + } +} + + +int +main (int argc, char *argv[]) +{ + gtk_init (&argc, &argv); + + set_locate_pointer (); + + gtk_main (); + + return 0; +} + diff --git a/plugins/mouse/msd-locate-pointer.h b/plugins/mouse/msd-locate-pointer.h new file mode 100644 index 0000000..c21da43 --- /dev/null +++ b/plugins/mouse/msd-locate-pointer.h @@ -0,0 +1,24 @@ +/* + * Copyright © 2001 Jonathan Blandford + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Red Hat not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Red Hat makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * Authors: Jonathan Blandford + */ + +#ifndef LOCATE_POINTER_H +#define LOCATE_POINTER_H + +#include + +void msd_locate_pointer (GdkScreen *screen); + +#endif diff --git a/plugins/mouse/msd-mouse-manager.c b/plugins/mouse/msd-mouse-manager.c new file mode 100644 index 0000000..d7cb8e4 --- /dev/null +++ b/plugins/mouse/msd-mouse-manager.c @@ -0,0 +1,1124 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +#include +#include +#endif +#include +#include + +#include "mate-settings-profile.h" +#include "msd-mouse-manager.h" + +#define MSD_MOUSE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerPrivate)) + +#define MATECONF_MOUSE_DIR "/desktop/mate/peripherals/mouse" +#define MATECONF_MOUSE_A11Y_DIR "/desktop/mate/accessibility/mouse" +#define MATECONF_TOUCHPAD_DIR "/desktop/mate/peripherals/touchpad" + +#define KEY_LEFT_HANDED MATECONF_MOUSE_DIR "/left_handed" +#define KEY_MOTION_ACCELERATION MATECONF_MOUSE_DIR "/motion_acceleration" +#define KEY_MOTION_THRESHOLD MATECONF_MOUSE_DIR "/motion_threshold" +#define KEY_LOCATE_POINTER MATECONF_MOUSE_DIR "/locate_pointer" +#define KEY_DWELL_ENABLE MATECONF_MOUSE_A11Y_DIR "/dwell_enable" +#define KEY_DELAY_ENABLE MATECONF_MOUSE_A11Y_DIR "/delay_enable" +#define KEY_TOUCHPAD_DISABLE_W_TYPING MATECONF_TOUCHPAD_DIR "/disable_while_typing" +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +#define KEY_TAP_TO_CLICK MATECONF_TOUCHPAD_DIR "/tap_to_click" +#define KEY_SCROLL_METHOD MATECONF_TOUCHPAD_DIR "/scroll_method" +#define KEY_PAD_HORIZ_SCROLL MATECONF_TOUCHPAD_DIR "/horiz_scroll_enabled" +#define KEY_TOUCHPAD_ENABLED MATECONF_TOUCHPAD_DIR "/touchpad_enabled" +#endif + +struct MsdMouseManagerPrivate +{ + guint notify; + guint notify_a11y; + guint notify_touchpad; + + gboolean mousetweaks_daemon_running; + gboolean syndaemon_spawned; + GPid syndaemon_pid; + gboolean locate_pointer_spawned; + GPid locate_pointer_pid; +}; + +static void msd_mouse_manager_class_init (MsdMouseManagerClass *klass); +static void msd_mouse_manager_init (MsdMouseManager *mouse_manager); +static void msd_mouse_manager_finalize (GObject *object); +static void set_mouse_settings (MsdMouseManager *manager); +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +static int set_tap_to_click (gboolean state, gboolean left_handed); +static XDevice* device_is_touchpad (XDeviceInfo deviceinfo); +#endif + +G_DEFINE_TYPE (MsdMouseManager, msd_mouse_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +static void +msd_mouse_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdMouseManager *self; + + self = MSD_MOUSE_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_mouse_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdMouseManager *self; + + self = MSD_MOUSE_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_mouse_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdMouseManager *mouse_manager; + MsdMouseManagerClass *klass; + + klass = MSD_MOUSE_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_MOUSE_MANAGER)); + + mouse_manager = MSD_MOUSE_MANAGER (G_OBJECT_CLASS (msd_mouse_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (mouse_manager); +} + +static void +msd_mouse_manager_dispose (GObject *object) +{ + MsdMouseManager *mouse_manager; + + mouse_manager = MSD_MOUSE_MANAGER (object); + + G_OBJECT_CLASS (msd_mouse_manager_parent_class)->dispose (object); +} + +static void +msd_mouse_manager_class_init (MsdMouseManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_mouse_manager_get_property; + object_class->set_property = msd_mouse_manager_set_property; + object_class->constructor = msd_mouse_manager_constructor; + object_class->dispose = msd_mouse_manager_dispose; + object_class->finalize = msd_mouse_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdMouseManagerPrivate)); +} + + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +static gboolean +supports_xinput_devices (void) +{ + gint op_code, event, error; + + return XQueryExtension (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + "XInputExtension", + &op_code, + &event, + &error); +} +#endif + +static void +configure_button_layout (guchar *buttons, + gint n_buttons, + gboolean left_handed) +{ + const gint left_button = 1; + gint right_button; + gint i; + + /* if the button is higher than 2 (3rd button) then it's + * probably one direction of a scroll wheel or something else + * uninteresting + */ + right_button = MIN (n_buttons, 3); + + /* If we change things we need to make sure we only swap buttons. + * If we end up with multiple physical buttons assigned to the same + * logical button the server will complain. This code assumes physical + * button 0 is the physical left mouse button, and that the physical + * button other than 0 currently assigned left_button or right_button + * is the physical right mouse button. + */ + + /* check if the current mapping satisfies the above assumptions */ + if (buttons[left_button - 1] != left_button && + buttons[left_button - 1] != right_button) + /* The current mapping is weird. Swapping buttons is probably not a + * good idea. + */ + return; + + /* check if we are left_handed and currently not swapped */ + if (left_handed && buttons[left_button - 1] == left_button) { + /* find the right button */ + for (i = 0; i < n_buttons; i++) { + if (buttons[i] == right_button) { + buttons[i] = left_button; + break; + } + } + /* swap the buttons */ + buttons[left_button - 1] = right_button; + } + /* check if we are not left_handed but are swapped */ + else if (!left_handed && buttons[left_button - 1] == right_button) { + /* find the right button */ + for (i = 0; i < n_buttons; i++) { + if (buttons[i] == left_button) { + buttons[i] = right_button; + break; + } + } + /* swap the buttons */ + buttons[left_button - 1] = left_button; + } +} + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +static gboolean +xinput_device_has_buttons (XDeviceInfo *device_info) +{ + int i; + XAnyClassInfo *class_info; + + class_info = device_info->inputclassinfo; + for (i = 0; i < device_info->num_classes; i++) { + if (class_info->class == ButtonClass) { + XButtonInfo *button_info; + + button_info = (XButtonInfo *) class_info; + if (button_info->num_buttons > 0) + return TRUE; + } + + class_info = (XAnyClassInfo *) (((guchar *) class_info) + + class_info->length); + } + return FALSE; +} + +static gboolean +touchpad_has_single_button (XDevice *device) +{ + Atom type, prop; + int format; + unsigned long nitems, bytes_after; + unsigned char *data; + gboolean is_single_button = FALSE; + int rc; + + prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Capabilities", False); + if (!prop) + return FALSE; + + gdk_error_trap_push (); + rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 1, False, + XA_INTEGER, &type, &format, &nitems, + &bytes_after, &data); + if (rc == Success && type == XA_INTEGER && format == 8 && nitems >= 3) + is_single_button = (data[0] == 1 && data[1] == 0 && data[2] == 0); + + if (rc == Success) + XFree (data); + + gdk_error_trap_pop (); + + return is_single_button; +} + + +static void +set_xinput_devices_left_handed (gboolean left_handed) +{ + XDeviceInfo *device_info; + gint n_devices; + guchar *buttons; + gsize buttons_capacity = 16; + gint n_buttons; + gint i; + + device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &n_devices); + + if (n_devices > 0) + buttons = g_new (guchar, buttons_capacity); + else + buttons = NULL; + + for (i = 0; i < n_devices; i++) { + XDevice *device = NULL; + + if ((device_info[i].use == IsXPointer) || + (device_info[i].use == IsXKeyboard) || + (!xinput_device_has_buttons (&device_info[i]))) + continue; + + /* If the device is a touchpad, swap tap buttons + * around too, otherwise a tap would be a right-click */ + device = device_is_touchpad (device_info[i]); + if (device != NULL) { + MateConfClient *client = mateconf_client_get_default (); + gboolean tap = mateconf_client_get_bool (client, KEY_TAP_TO_CLICK, NULL); + gboolean single_button = touchpad_has_single_button (device); + + if (tap && !single_button) + set_tap_to_click (tap, left_handed); + XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); + g_object_unref (client); + + if (single_button) + continue; + } + + gdk_error_trap_push (); + + device = XOpenDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device_info[i].id); + + if ((gdk_error_trap_pop () != 0) || + (device == NULL)) + continue; + + n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + buttons, + buttons_capacity); + + while (n_buttons > buttons_capacity) { + buttons_capacity = n_buttons; + buttons = (guchar *) g_realloc (buttons, + buttons_capacity * sizeof (guchar)); + + n_buttons = XGetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + buttons, + buttons_capacity); + } + + configure_button_layout (buttons, n_buttons, left_handed); + + XSetDeviceButtonMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, buttons, n_buttons); + XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); + } + g_free (buttons); + + if (device_info != NULL) + XFreeDeviceList (device_info); +} + +static GdkFilterReturn +devicepresence_filter (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) +{ + XEvent *xev = (XEvent *) xevent; + XEventClass class_presence; + int xi_presence; + + DevicePresence (gdk_x11_get_default_xdisplay (), xi_presence, class_presence); + + if (xev->type == xi_presence) + { + XDevicePresenceNotifyEvent *dpn = (XDevicePresenceNotifyEvent *) xev; + if (dpn->devchange == DeviceEnabled) + set_mouse_settings ((MsdMouseManager *) data); + } + return GDK_FILTER_CONTINUE; +} + +static void +set_devicepresence_handler (MsdMouseManager *manager) +{ + Display *display; + XEventClass class_presence; + int xi_presence; + + if (!supports_xinput_devices ()) + return; + + display = gdk_x11_get_default_xdisplay (); + + gdk_error_trap_push (); + DevicePresence (display, xi_presence, class_presence); + XSelectExtensionEvent (display, + RootWindow (display, DefaultScreen (display)), + &class_presence, 1); + + gdk_flush (); + if (!gdk_error_trap_pop ()) + gdk_window_add_filter (NULL, devicepresence_filter, manager); +} +#endif + +static void +set_left_handed (MsdMouseManager *manager, + gboolean left_handed) +{ + guchar *buttons ; + gsize buttons_capacity = 16; + gint n_buttons, i; + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + if (supports_xinput_devices ()) { + /* When XInput support is available, never set the + * button ordering on the core pointer as that would + * revert the changes we make on the devices themselves */ + set_xinput_devices_left_handed (left_handed); + return; + } +#endif + + buttons = g_new (guchar, buttons_capacity); + n_buttons = XGetPointerMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + buttons, + (gint) buttons_capacity); + while (n_buttons > buttons_capacity) { + buttons_capacity = n_buttons; + buttons = (guchar *) g_realloc (buttons, + buttons_capacity * sizeof (guchar)); + + n_buttons = XGetPointerMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + buttons, + (gint) buttons_capacity); + } + + configure_button_layout (buttons, n_buttons, left_handed); + + /* X refuses to change the mapping while buttons are engaged, + * so if this is the case we'll retry a few times + */ + for (i = 0; + i < 20 && XSetPointerMapping (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), buttons, n_buttons) == MappingBusy; + ++i) { + g_usleep (300); + } + + g_free (buttons); +} + +static void +set_motion_acceleration (MsdMouseManager *manager, + gfloat motion_acceleration) +{ + gint numerator, denominator; + + if (motion_acceleration >= 1.0) { + /* we want to get the acceleration, with a resolution of 0.5 + */ + if ((motion_acceleration - floor (motion_acceleration)) < 0.25) { + numerator = floor (motion_acceleration); + denominator = 1; + } else if ((motion_acceleration - floor (motion_acceleration)) < 0.5) { + numerator = ceil (2.0 * motion_acceleration); + denominator = 2; + } else if ((motion_acceleration - floor (motion_acceleration)) < 0.75) { + numerator = floor (2.0 *motion_acceleration); + denominator = 2; + } else { + numerator = ceil (motion_acceleration); + denominator = 1; + } + } else if (motion_acceleration < 1.0 && motion_acceleration > 0) { + /* This we do to 1/10ths */ + numerator = floor (motion_acceleration * 10) + 1; + denominator= 10; + } else { + numerator = -1; + denominator = -1; + } + + XChangePointerControl (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), True, False, + numerator, denominator, + 0); +} + +static void +set_motion_threshold (MsdMouseManager *manager, + int motion_threshold) +{ + XChangePointerControl (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), False, True, + 0, 0, motion_threshold); +} + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +static XDevice* +device_is_touchpad (XDeviceInfo deviceinfo) +{ + XDevice *device; + Atom realtype, prop; + int realformat; + unsigned long nitems, bytes_after; + unsigned char *data; + + if (deviceinfo.type != XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), XI_TOUCHPAD, False)) + return NULL; + + prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Off", False); + if (!prop) + return NULL; + + gdk_error_trap_push (); + device = XOpenDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), deviceinfo.id); + if (gdk_error_trap_pop () || (device == NULL)) + return NULL; + + gdk_error_trap_push (); + if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 1, False, + XA_INTEGER, &realtype, &realformat, &nitems, + &bytes_after, &data) == Success) && (realtype != None)) { + gdk_error_trap_pop (); + XFree (data); + return device; + } + gdk_error_trap_pop (); + + XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); + return NULL; +} +#endif + +static int +set_disable_w_typing (MsdMouseManager *manager, gboolean state) +{ + + if (state) { + GError *error = NULL; + char *args[5]; + + if (manager->priv->syndaemon_spawned) + return 0; + + args[0] = "syndaemon"; + args[1] = "-i"; + args[2] = "0.5"; + args[3] = "-k"; + args[4] = NULL; + + if (!g_find_program_in_path (args[0])) + return 0; + + g_spawn_async (g_get_home_dir (), args, NULL, + G_SPAWN_SEARCH_PATH, NULL, NULL, + &manager->priv->syndaemon_pid, &error); + + manager->priv->syndaemon_spawned = (error == NULL); + + if (error) { + MateConfClient *client; + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_TOUCHPAD_DISABLE_W_TYPING, FALSE, NULL); + g_object_unref (client); + g_error_free (error); + } + + } else if (manager->priv->syndaemon_spawned) + { + kill (manager->priv->syndaemon_pid, SIGHUP); + g_spawn_close_pid (manager->priv->syndaemon_pid); + manager->priv->syndaemon_spawned = FALSE; + } + + return 0; +} + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H +static int +set_tap_to_click (gboolean state, gboolean left_handed) +{ + int numdevices, i, format, rc; + unsigned long nitems, bytes_after; + XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); + XDevice * device; + unsigned char* data; + Atom prop, type; + + if (devicelist == NULL) + return 0; + + prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Tap Action", False); + + if (!prop) + return 0; + + for (i = 0; i < numdevices; i++) { + if ((device = device_is_touchpad (devicelist[i]))) { + gdk_error_trap_push (); + rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 2, + False, XA_INTEGER, &type, &format, &nitems, + &bytes_after, &data); + + if (rc == Success && type == XA_INTEGER && format == 8 && nitems >= 7) + { + /* Set RLM mapping for 1/2/3 fingers*/ + data[4] = (state) ? ((left_handed) ? 3 : 1) : 0; + data[5] = (state) ? ((left_handed) ? 1 : 3) : 0; + data[6] = (state) ? 2 : 0; + XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, XA_INTEGER, 8, + PropModeReplace, data, nitems); + } + + if (rc == Success) + XFree (data); + XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); + if (gdk_error_trap_pop ()) { + g_warning ("Error in setting tap to click on \"%s\"", devicelist[i].name); + continue; + } + } + } + + XFreeDeviceList (devicelist); + return 0; +} + +static int +set_horiz_scroll (gboolean state) +{ + int numdevices, i, rc; + XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); + XDevice *device; + Atom act_type, prop_edge, prop_twofinger; + int act_format; + unsigned long nitems, bytes_after; + unsigned char *data; + + if (devicelist == NULL) + return 0; + + prop_edge = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Edge Scrolling", False); + prop_twofinger = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Two-Finger Scrolling", False); + + if (!prop_edge || !prop_twofinger) + return 0; + + for (i = 0; i < numdevices; i++) { + if ((device = device_is_touchpad (devicelist[i]))) { + gdk_error_trap_push (); + rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_edge, 0, 1, False, + XA_INTEGER, &act_type, &act_format, &nitems, + &bytes_after, &data); + if (rc == Success && act_type == XA_INTEGER && + act_format == 8 && nitems >= 2) { + data[1] = (state && data[0]); + XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_edge, XA_INTEGER, 8, + PropModeReplace, data, nitems); + } + + XFree (data); + + rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_twofinger, 0, 1, False, + XA_INTEGER, &act_type, &act_format, &nitems, + &bytes_after, &data); + if (rc == Success && act_type == XA_INTEGER && + act_format == 8 && nitems >= 2) { + data[1] = (state && data[0]); + XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_twofinger, XA_INTEGER, 8, + PropModeReplace, data, nitems); + } + + XFree (data); + XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); + if (gdk_error_trap_pop ()) { + g_warning ("Error in setting horiz scroll on \"%s\"", devicelist[i].name); + continue; + } + } + } + + XFreeDeviceList (devicelist); + return 0; +} + + +/** + * Scroll methods are: 0 - disabled, 1 - edge scrolling, 2 - twofinger + * scrolling + */ +static int +set_edge_scroll (int method) +{ + int numdevices, i, rc; + XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); + XDevice *device; + Atom act_type, prop_edge, prop_twofinger; + int act_format; + unsigned long nitems, bytes_after; + unsigned char *data; + + if (devicelist == NULL) + return 0; + + prop_edge = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Edge Scrolling", False); + prop_twofinger = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Two-Finger Scrolling", False); + + if (!prop_edge || !prop_twofinger) + return 0; + + for (i = 0; i < numdevices; i++) { + if ((device = device_is_touchpad (devicelist[i]))) { + gdk_error_trap_push (); + rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_edge, 0, 1, False, + XA_INTEGER, &act_type, &act_format, &nitems, + &bytes_after, &data); + if (rc == Success && act_type == XA_INTEGER && + act_format == 8 && nitems >= 2) { + data[0] = (method == 1) ? 1 : 0; + XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_edge, XA_INTEGER, 8, + PropModeReplace, data, nitems); + } + + XFree (data); + + rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_twofinger, 0, 1, False, + XA_INTEGER, &act_type, &act_format, &nitems, + &bytes_after, &data); + if (rc == Success && act_type == XA_INTEGER && + act_format == 8 && nitems >= 2) { + data[0] = (method == 2) ? 1 : 0; + XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_twofinger, XA_INTEGER, 8, + PropModeReplace, data, nitems); + } + + XFree (data); + XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); + if (gdk_error_trap_pop ()) { + g_warning ("Error in setting edge scroll on \"%s\"", devicelist[i].name); + continue; + } + } + } + + XFreeDeviceList (devicelist); + return 0; +} + +static int +set_touchpad_enabled (gboolean state) +{ + int numdevices, i; + XDeviceInfo *devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); + XDevice *device; + Atom prop_enabled; + + if (devicelist == NULL) + return 0; + + prop_enabled = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Device Enabled", False); + + if (!prop_enabled) + return 0; + + for (i = 0; i < numdevices; i++) { + if ((device = device_is_touchpad (devicelist[i]))) { + unsigned char data = state; + gdk_error_trap_push (); + XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, + prop_enabled, XA_INTEGER, 8, + PropModeReplace, &data, 1); + XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); + gdk_flush (); + if (gdk_error_trap_pop ()) { + g_warning ("Error %s device \"%s\"", + (state) ? "enabling" : "disabling", + devicelist[i].name); + continue; + } + } + } + + XFreeDeviceList (devicelist); + return 0; +} +#endif + +static void +set_locate_pointer (MsdMouseManager *manager, + gboolean state) +{ + if (state) { + GError *error = NULL; + char *args[2]; + + if (manager->priv->locate_pointer_spawned) + return; + + args[0] = LIBEXECDIR "/msd-locate-pointer"; + args[1] = NULL; + + g_spawn_async (NULL, args, NULL, + 0, NULL, NULL, + &manager->priv->locate_pointer_pid, &error); + + manager->priv->locate_pointer_spawned = (error == NULL); + + if (error) { + MateConfClient *client; + client = mateconf_client_get_default (); + mateconf_client_set_bool (client, KEY_LOCATE_POINTER, FALSE, NULL); + g_object_unref (client); + g_error_free (error); + } + + } + else if (manager->priv->locate_pointer_spawned) { + kill (manager->priv->locate_pointer_pid, SIGHUP); + g_spawn_close_pid (manager->priv->locate_pointer_pid); + manager->priv->locate_pointer_spawned = FALSE; + } +} + +static void +set_mousetweaks_daemon (MsdMouseManager *manager, + gboolean dwell_enable, + gboolean delay_enable) +{ + GError *error = NULL; + gchar *comm; + gboolean run_daemon = dwell_enable || delay_enable; + + if (run_daemon || manager->priv->mousetweaks_daemon_running) + comm = g_strdup_printf ("mousetweaks %s", + run_daemon ? "" : "-s"); + else + return; + + if (run_daemon) + manager->priv->mousetweaks_daemon_running = TRUE; + + + if (! g_spawn_command_line_async (comm, &error)) { + if (error->code == G_SPAWN_ERROR_NOENT && + (dwell_enable || delay_enable)) { + GtkWidget *dialog; + MateConfClient *client; + + client = mateconf_client_get_default (); + if (dwell_enable) + mateconf_client_set_bool (client, + KEY_DWELL_ENABLE, + FALSE, NULL); + else if (delay_enable) + mateconf_client_set_bool (client, + KEY_DELAY_ENABLE, + FALSE, NULL); + g_object_unref (client); + + dialog = gtk_message_dialog_new (NULL, 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + _("Could not enable mouse accessibility features")); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("Mouse accessibility requires Mousetweaks " + "to be installed on your system.")); + gtk_window_set_title (GTK_WINDOW (dialog), + _("Mouse Preferences")); + gtk_window_set_icon_name (GTK_WINDOW (dialog), + "input-mouse"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } + g_error_free (error); + } + g_free (comm); +} + +static void +set_mouse_settings (MsdMouseManager *manager) +{ + MateConfClient *client = mateconf_client_get_default (); + gboolean left_handed = mateconf_client_get_bool (client, KEY_LEFT_HANDED, NULL); + + set_left_handed (manager, left_handed); + set_motion_acceleration (manager, mateconf_client_get_float (client, KEY_MOTION_ACCELERATION , NULL)); + set_motion_threshold (manager, mateconf_client_get_int (client, KEY_MOTION_THRESHOLD, NULL)); + + set_disable_w_typing (manager, mateconf_client_get_bool (client, KEY_TOUCHPAD_DISABLE_W_TYPING, NULL)); +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + set_tap_to_click (mateconf_client_get_bool (client, KEY_TAP_TO_CLICK, NULL), left_handed); + set_edge_scroll (mateconf_client_get_int (client, KEY_SCROLL_METHOD, NULL)); + set_horiz_scroll (mateconf_client_get_bool (client, KEY_PAD_HORIZ_SCROLL, NULL)); + set_touchpad_enabled (mateconf_client_get_bool (client, KEY_TOUCHPAD_ENABLED, NULL)); +#endif + + g_object_unref (client); +} + +static void +mouse_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdMouseManager *manager) +{ + if (! strcmp (entry->key, KEY_LEFT_HANDED)) { + if (entry->value->type == MATECONF_VALUE_BOOL) { + set_left_handed (manager, mateconf_value_get_bool (entry->value)); + } + } else if (! strcmp (entry->key, KEY_MOTION_ACCELERATION)) { + if (entry->value->type == MATECONF_VALUE_FLOAT) { + set_motion_acceleration (manager, mateconf_value_get_float (entry->value)); + } + } else if (! strcmp (entry->key, KEY_MOTION_THRESHOLD)) { + if (entry->value->type == MATECONF_VALUE_INT) { + set_motion_threshold (manager, mateconf_value_get_int (entry->value)); + } + } else if (! strcmp (entry->key, KEY_TOUCHPAD_DISABLE_W_TYPING)) { + if (entry->value->type == MATECONF_VALUE_BOOL) + set_disable_w_typing (manager, mateconf_value_get_bool (entry->value)); +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + } else if (! strcmp (entry->key, KEY_TAP_TO_CLICK)) { + if (entry->value->type == MATECONF_VALUE_BOOL) { + set_tap_to_click (mateconf_value_get_bool (entry->value), + mateconf_client_get_bool (client, KEY_LEFT_HANDED, NULL)); + } + } else if (! strcmp (entry->key, KEY_SCROLL_METHOD)) { + if (entry->value->type == MATECONF_VALUE_INT) { + set_edge_scroll (mateconf_value_get_int (entry->value)); + set_horiz_scroll (mateconf_client_get_bool (client, KEY_PAD_HORIZ_SCROLL, NULL)); + } + } else if (! strcmp (entry->key, KEY_PAD_HORIZ_SCROLL)) { + if (entry->value->type == MATECONF_VALUE_BOOL) + set_horiz_scroll (mateconf_value_get_bool (entry->value)); +#endif + } else if (! strcmp (entry->key, KEY_LOCATE_POINTER)) { + if (entry->value->type == MATECONF_VALUE_BOOL) { + set_locate_pointer (manager, mateconf_value_get_bool (entry->value)); + } +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + } else if (! strcmp (entry->key, KEY_TOUCHPAD_ENABLED)) { + if (entry->value->type == MATECONF_VALUE_BOOL) { + set_touchpad_enabled (mateconf_value_get_bool (entry->value)); + } +#endif + } else if (! strcmp (entry->key, KEY_DWELL_ENABLE)) { + if (entry->value->type == MATECONF_VALUE_BOOL) { + set_mousetweaks_daemon (manager, + mateconf_value_get_bool (entry->value), + mateconf_client_get_bool (client, KEY_DELAY_ENABLE, NULL)); + } + } else if (! strcmp (entry->key, KEY_DELAY_ENABLE)) { + if (entry->value->type == MATECONF_VALUE_BOOL) { + set_mousetweaks_daemon (manager, + mateconf_client_get_bool (client, KEY_DWELL_ENABLE, NULL), + mateconf_value_get_bool (entry->value)); + } + } +} + +static guint +register_config_callback (MsdMouseManager *manager, + MateConfClient *client, + const char *path, + MateConfClientNotifyFunc func) +{ + mateconf_client_add_dir (client, path, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + return mateconf_client_notify_add (client, path, func, manager, NULL, NULL); +} + +static void +msd_mouse_manager_init (MsdMouseManager *manager) +{ + manager->priv = MSD_MOUSE_MANAGER_GET_PRIVATE (manager); +} + +static gboolean +msd_mouse_manager_idle_cb (MsdMouseManager *manager) +{ + MateConfClient *client; + + mate_settings_profile_start (NULL); + + client = mateconf_client_get_default (); + + manager->priv->notify = + register_config_callback (manager, + client, + MATECONF_MOUSE_DIR, + (MateConfClientNotifyFunc) mouse_callback); + manager->priv->notify_a11y = + register_config_callback (manager, + client, + MATECONF_MOUSE_A11Y_DIR, + (MateConfClientNotifyFunc) mouse_callback); + manager->priv->notify_touchpad = + register_config_callback (manager, + client, + MATECONF_TOUCHPAD_DIR, + (MateConfClientNotifyFunc) mouse_callback); + manager->priv->syndaemon_spawned = FALSE; + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + set_devicepresence_handler (manager); +#endif + set_mouse_settings (manager); + set_locate_pointer (manager, mateconf_client_get_bool (client, KEY_LOCATE_POINTER, NULL)); + set_mousetweaks_daemon (manager, + mateconf_client_get_bool (client, KEY_DWELL_ENABLE, NULL), + mateconf_client_get_bool (client, KEY_DELAY_ENABLE, NULL)); + + set_disable_w_typing (manager, mateconf_client_get_bool (client, KEY_TOUCHPAD_DISABLE_W_TYPING, NULL)); +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + set_tap_to_click (mateconf_client_get_bool (client, KEY_TAP_TO_CLICK, NULL), + mateconf_client_get_bool (client, KEY_LEFT_HANDED, NULL)); + set_edge_scroll (mateconf_client_get_int (client, KEY_SCROLL_METHOD, NULL)); + set_horiz_scroll (mateconf_client_get_bool (client, KEY_PAD_HORIZ_SCROLL, NULL)); + set_touchpad_enabled (mateconf_client_get_bool (client, KEY_TOUCHPAD_ENABLED, NULL)); +#endif + + g_object_unref (client); + + mate_settings_profile_end (NULL); + + return FALSE; +} + +gboolean +msd_mouse_manager_start (MsdMouseManager *manager, + GError **error) +{ + mate_settings_profile_start (NULL); + + g_idle_add ((GSourceFunc) msd_mouse_manager_idle_cb, manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_mouse_manager_stop (MsdMouseManager *manager) +{ + MsdMouseManagerPrivate *p = manager->priv; + MateConfClient *client; + + g_debug ("Stopping mouse manager"); + + client = mateconf_client_get_default (); + + if (p->notify != 0) { + mateconf_client_remove_dir (client, MATECONF_MOUSE_DIR, NULL); + mateconf_client_notify_remove (client, p->notify); + p->notify = 0; + } + + if (p->notify_a11y != 0) { + mateconf_client_remove_dir (client, MATECONF_MOUSE_A11Y_DIR, NULL); + mateconf_client_notify_remove (client, p->notify_a11y); + p->notify_a11y = 0; + } + + if (p->notify_touchpad != 0) { + mateconf_client_remove_dir (client, MATECONF_TOUCHPAD_DIR, NULL); + mateconf_client_notify_remove (client, p->notify_touchpad); + p->notify_touchpad = 0; + } + + g_object_unref (client); + + set_locate_pointer (manager, FALSE); + +#ifdef HAVE_X11_EXTENSIONS_XINPUT_H + gdk_window_remove_filter (NULL, devicepresence_filter, manager); +#endif +} + +static void +msd_mouse_manager_finalize (GObject *object) +{ + MsdMouseManager *mouse_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_MOUSE_MANAGER (object)); + + mouse_manager = MSD_MOUSE_MANAGER (object); + + g_return_if_fail (mouse_manager->priv != NULL); + + G_OBJECT_CLASS (msd_mouse_manager_parent_class)->finalize (object); +} + +MsdMouseManager * +msd_mouse_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_MOUSE_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_MOUSE_MANAGER (manager_object); +} diff --git a/plugins/mouse/msd-mouse-manager.h b/plugins/mouse/msd-mouse-manager.h new file mode 100644 index 0000000..e691d7b --- /dev/null +++ b/plugins/mouse/msd-mouse-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_MOUSE_MANAGER_H +#define __MSD_MOUSE_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_MOUSE_MANAGER (msd_mouse_manager_get_type ()) +#define MSD_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManager)) +#define MSD_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerClass)) +#define MSD_IS_MOUSE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MOUSE_MANAGER)) +#define MSD_IS_MOUSE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MOUSE_MANAGER)) +#define MSD_MOUSE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MOUSE_MANAGER, MsdMouseManagerClass)) + +typedef struct MsdMouseManagerPrivate MsdMouseManagerPrivate; + +typedef struct +{ + GObject parent; + MsdMouseManagerPrivate *priv; +} MsdMouseManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdMouseManagerClass; + +GType msd_mouse_manager_get_type (void); + +MsdMouseManager * msd_mouse_manager_new (void); +gboolean msd_mouse_manager_start (MsdMouseManager *manager, + GError **error); +void msd_mouse_manager_stop (MsdMouseManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_MOUSE_MANAGER_H */ diff --git a/plugins/mouse/msd-mouse-plugin.c b/plugins/mouse/msd-mouse-plugin.c new file mode 100644 index 0000000..7203002 --- /dev/null +++ b/plugins/mouse/msd-mouse-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-mouse-plugin.h" +#include "msd-mouse-manager.h" + +struct MsdMousePluginPrivate { + MsdMouseManager *manager; +}; + +#define MSD_MOUSE_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdMousePlugin, msd_mouse_plugin) + +static void +msd_mouse_plugin_init (MsdMousePlugin *plugin) +{ + plugin->priv = MSD_MOUSE_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdMousePlugin initializing"); + + plugin->priv->manager = msd_mouse_manager_new (); +} + +static void +msd_mouse_plugin_finalize (GObject *object) +{ + MsdMousePlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_MOUSE_PLUGIN (object)); + + g_debug ("MsdMousePlugin finalizing"); + + plugin = MSD_MOUSE_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_mouse_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating mouse plugin"); + + error = NULL; + res = msd_mouse_manager_start (MSD_MOUSE_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start mouse manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating mouse plugin"); + msd_mouse_manager_stop (MSD_MOUSE_PLUGIN (plugin)->priv->manager); +} + +static void +msd_mouse_plugin_class_init (MsdMousePluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_mouse_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdMousePluginPrivate)); +} diff --git a/plugins/mouse/msd-mouse-plugin.h b/plugins/mouse/msd-mouse-plugin.h new file mode 100644 index 0000000..2c2da6c --- /dev/null +++ b/plugins/mouse/msd-mouse-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_MOUSE_PLUGIN_H__ +#define __MSD_MOUSE_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_MOUSE_PLUGIN (msd_mouse_plugin_get_type ()) +#define MSD_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_MOUSE_PLUGIN, MsdMousePlugin)) +#define MSD_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginClass)) +#define MSD_IS_MOUSE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_MOUSE_PLUGIN)) +#define MSD_IS_MOUSE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_MOUSE_PLUGIN)) +#define MSD_MOUSE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_MOUSE_PLUGIN, MsdMousePluginClass)) + +typedef struct MsdMousePluginPrivate MsdMousePluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdMousePluginPrivate *priv; +} MsdMousePlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdMousePluginClass; + +GType msd_mouse_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_MOUSE_PLUGIN_H__ */ diff --git a/plugins/mouse/msd-timeline.c b/plugins/mouse/msd-timeline.c new file mode 100644 index 0000000..9bcfd2f --- /dev/null +++ b/plugins/mouse/msd-timeline.c @@ -0,0 +1,848 @@ +/* msd-timeline.c + * + * Copyright (C) 2008 Carlos Garnacho + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include "msd-timeline.h" + +#define MSD_TIMELINE_GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MSD_TYPE_TIMELINE, MsdTimelinePriv)) +#define MSECS_PER_SEC 1000 +#define FRAME_INTERVAL(nframes) (MSECS_PER_SEC / nframes) +#define DEFAULT_FPS 30 + +typedef struct MsdTimelinePriv MsdTimelinePriv; + +struct MsdTimelinePriv +{ + guint duration; + guint fps; + guint source_id; + + GTimer *timer; + + GdkScreen *screen; + MsdTimelineProgressType progress_type; + MsdTimelineProgressFunc progress_func; + + guint loop : 1; + guint direction : 1; +}; + +enum { + PROP_0, + PROP_FPS, + PROP_DURATION, + PROP_LOOP, + PROP_DIRECTION, + PROP_SCREEN, + PROP_PROGRESS_TYPE, +}; + +enum { + STARTED, + PAUSED, + FINISHED, + FRAME, + LAST_SIGNAL +}; + +static guint signals [LAST_SIGNAL] = { 0, }; + + +static void msd_timeline_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void msd_timeline_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void msd_timeline_finalize (GObject *object); + + +G_DEFINE_TYPE (MsdTimeline, msd_timeline, G_TYPE_OBJECT) + + +GType +msd_timeline_direction_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) + { + static const GEnumValue values[] = { + { MSD_TIMELINE_DIRECTION_FORWARD, "MSD_TIMELINE_DIRECTION_FORWARD", "forward" }, + { MSD_TIMELINE_DIRECTION_BACKWARD, "MSD_TIMELINE_DIRECTION_BACKWARD", "backward" }, + { 0, NULL, NULL } + }; + + type = g_enum_register_static (g_intern_static_string ("MsdTimelineDirection"), values); + } + + return type; +} + +GType +msd_timeline_progress_type_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) + { + static const GEnumValue values[] = { + { MSD_TIMELINE_PROGRESS_LINEAR, "MSD_TIMELINE_PROGRESS_LINEAR", "linear" }, + { MSD_TIMELINE_PROGRESS_SINUSOIDAL, "MSD_TIMELINE_PROGRESS_SINUSOIDAL", "sinusoidal" }, + { MSD_TIMELINE_PROGRESS_EXPONENTIAL, "MSD_TIMELINE_PROGRESS_EXPONENTIAL", "exponential" }, + { 0, NULL, NULL } + }; + + type = g_enum_register_static (g_intern_static_string ("MsdTimelineProgressType"), values); + } + + return type; +} + +static void +msd_timeline_class_init (MsdTimelineClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->set_property = msd_timeline_set_property; + object_class->get_property = msd_timeline_get_property; + object_class->finalize = msd_timeline_finalize; + + g_object_class_install_property (object_class, + PROP_FPS, + g_param_spec_uint ("fps", + "FPS", + "Frames per second for the timeline", + 1, + G_MAXUINT, + DEFAULT_FPS, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_DURATION, + g_param_spec_uint ("duration", + "Animation Duration", + "Animation Duration", + 0, + G_MAXUINT, + 0, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_LOOP, + g_param_spec_boolean ("loop", + "Loop", + "Whether the timeline loops or not", + FALSE, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_DIRECTION, + g_param_spec_enum ("direction", + "Direction", + "Whether the timeline moves forward or backward in time", + MSD_TYPE_TIMELINE_DIRECTION, + MSD_TIMELINE_DIRECTION_FORWARD, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_DIRECTION, + g_param_spec_enum ("progress-type", + "Progress type", + "Type of progress through the timeline", + MSD_TYPE_TIMELINE_PROGRESS_TYPE, + MSD_TIMELINE_PROGRESS_LINEAR, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_SCREEN, + g_param_spec_object ("screen", + "Screen", + "Screen to get the settings from", + GDK_TYPE_SCREEN, + G_PARAM_READWRITE)); + + signals[STARTED] = + g_signal_new ("started", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdTimelineClass, started), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[PAUSED] = + g_signal_new ("paused", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdTimelineClass, paused), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[FINISHED] = + g_signal_new ("finished", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdTimelineClass, finished), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + signals[FRAME] = + g_signal_new ("frame", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdTimelineClass, frame), + NULL, NULL, + g_cclosure_marshal_VOID__DOUBLE, + G_TYPE_NONE, 1, + G_TYPE_DOUBLE); + + g_type_class_add_private (class, sizeof (MsdTimelinePriv)); +} + +static void +msd_timeline_init (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + priv->fps = DEFAULT_FPS; + priv->duration = 0; + priv->direction = MSD_TIMELINE_DIRECTION_FORWARD; + priv->screen = gdk_screen_get_default (); +} + +static void +msd_timeline_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdTimeline *timeline; + MsdTimelinePriv *priv; + + timeline = MSD_TIMELINE (object); + priv = MSD_TIMELINE_GET_PRIV (timeline); + + switch (prop_id) + { + case PROP_FPS: + msd_timeline_set_fps (timeline, g_value_get_uint (value)); + break; + case PROP_DURATION: + msd_timeline_set_duration (timeline, g_value_get_uint (value)); + break; + case PROP_LOOP: + msd_timeline_set_loop (timeline, g_value_get_boolean (value)); + break; + case PROP_DIRECTION: + msd_timeline_set_direction (timeline, g_value_get_enum (value)); + break; + case PROP_SCREEN: + msd_timeline_set_screen (timeline, + GDK_SCREEN (g_value_get_object (value))); + break; + case PROP_PROGRESS_TYPE: + msd_timeline_set_progress_type (timeline, g_value_get_enum (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +msd_timeline_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdTimeline *timeline; + MsdTimelinePriv *priv; + + timeline = MSD_TIMELINE (object); + priv = MSD_TIMELINE_GET_PRIV (timeline); + + switch (prop_id) + { + case PROP_FPS: + g_value_set_uint (value, priv->fps); + break; + case PROP_DURATION: + g_value_set_uint (value, priv->duration); + break; + case PROP_LOOP: + g_value_set_boolean (value, priv->loop); + break; + case PROP_DIRECTION: + g_value_set_enum (value, priv->direction); + break; + case PROP_SCREEN: + g_value_set_object (value, priv->screen); + break; + case PROP_PROGRESS_TYPE: + g_value_set_enum (value, priv->progress_type); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +msd_timeline_finalize (GObject *object) +{ + MsdTimelinePriv *priv; + + priv = MSD_TIMELINE_GET_PRIV (object); + + if (priv->source_id) + { + g_source_remove (priv->source_id); + priv->source_id = 0; + } + + if (priv->timer) + g_timer_destroy (priv->timer); + + G_OBJECT_CLASS (msd_timeline_parent_class)->finalize (object); +} + +/* Sinusoidal progress */ +static gdouble +sinusoidal_progress (gdouble progress) +{ + return (sinf ((progress * G_PI) / 2)); +} + +static gdouble +exponential_progress (gdouble progress) +{ + return progress * progress; +} + +static MsdTimelineProgressFunc +progress_type_to_func (MsdTimelineProgressType type) +{ + if (type == MSD_TIMELINE_PROGRESS_SINUSOIDAL) + return sinusoidal_progress; + else if (type == MSD_TIMELINE_PROGRESS_EXPONENTIAL) + return exponential_progress; + + return NULL; +} + +static gboolean +msd_timeline_run_frame (MsdTimeline *timeline, + gboolean enable_animations) +{ + MsdTimelinePriv *priv; + gdouble linear_progress, progress; + guint elapsed_time; + MsdTimelineProgressFunc progress_func = NULL; + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + if (enable_animations) + { + elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000); + + linear_progress = (gdouble) elapsed_time / priv->duration; + + if (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD) + linear_progress = 1 - linear_progress; + + linear_progress = CLAMP (linear_progress, 0., 1.); + + if (priv->progress_func) + progress_func = priv->progress_func; + else if (priv->progress_type) + progress_func = progress_type_to_func (priv->progress_type); + + if (progress_func) + progress = (progress_func) (linear_progress); + else + progress = linear_progress; + } + else + progress = (priv->direction == MSD_TIMELINE_DIRECTION_FORWARD) ? 1.0 : 0.0; + + g_signal_emit (timeline, signals [FRAME], 0, + CLAMP (progress, 0.0, 1.0)); + + if ((priv->direction == MSD_TIMELINE_DIRECTION_FORWARD && progress >= 1.0) || + (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD && progress <= 0.0)) + { + if (!priv->loop) + { + if (priv->source_id) + { + g_source_remove (priv->source_id); + priv->source_id = 0; + } + + g_signal_emit (timeline, signals [FINISHED], 0); + return FALSE; + } + else + msd_timeline_rewind (timeline); + } + + return TRUE; +} + +static gboolean +msd_timeline_frame_idle_func (MsdTimeline *timeline) +{ + return msd_timeline_run_frame (timeline, TRUE); +} + +/** + * msd_timeline_new: + * @duration: duration in milliseconds for the timeline + * + * Creates a new #MsdTimeline with the specified number of frames. + * + * Return Value: the newly created #MsdTimeline + **/ +MsdTimeline * +msd_timeline_new (guint duration) +{ + return g_object_new (MSD_TYPE_TIMELINE, + "duration", duration, + NULL); +} + +MsdTimeline * +msd_timeline_new_for_screen (guint duration, + GdkScreen *screen) +{ + return g_object_new (MSD_TYPE_TIMELINE, + "duration", duration, + "screen", screen, + NULL); +} + +/** + * msd_timeline_start: + * @timeline: A #MsdTimeline + * + * Runs the timeline from the current frame. + **/ +void +msd_timeline_start (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + GtkSettings *settings; + gboolean enable_animations = FALSE; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + if (priv->screen) + { + settings = gtk_settings_get_for_screen (priv->screen); + g_object_get (settings, "gtk-enable-animations", &enable_animations, NULL); + } + + if (enable_animations) + { + if (!priv->source_id) + { + if (priv->timer) + g_timer_continue (priv->timer); + else + priv->timer = g_timer_new (); + + /* sanity check */ + g_assert (priv->fps > 0); + + g_signal_emit (timeline, signals [STARTED], 0); + + priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), + (GSourceFunc) msd_timeline_frame_idle_func, + timeline); + } + } + else + { + /* If animations are not enabled, only run the last frame, + * it take us instantaneously to the last state of the animation. + * The only potential flaw happens when people use the ::finished + * signal to trigger another animation, or even worse, finally + * loop into this animation again. + */ + g_signal_emit (timeline, signals [STARTED], 0); + msd_timeline_run_frame (timeline, FALSE); + } +} + +/** + * msd_timeline_pause: + * @timeline: A #MsdTimeline + * + * Pauses the timeline. + **/ +void +msd_timeline_pause (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + if (priv->source_id) + { + g_source_remove (priv->source_id); + priv->source_id = 0; + g_timer_stop (priv->timer); + g_signal_emit (timeline, signals [PAUSED], 0); + } +} + +/** + * msd_timeline_rewind: + * @timeline: A #MsdTimeline + * + * Rewinds the timeline. + **/ +void +msd_timeline_rewind (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + /* destroy and re-create timer if neccesary */ + if (priv->timer) + { + g_timer_destroy (priv->timer); + + if (msd_timeline_is_running (timeline)) + priv->timer = g_timer_new (); + else + priv->timer = NULL; + } +} + +/** + * msd_timeline_is_running: + * @timeline: A #MsdTimeline + * + * Returns whether the timeline is running or not. + * + * Return Value: %TRUE if the timeline is running + **/ +gboolean +msd_timeline_is_running (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), FALSE); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + return (priv->source_id != 0); +} + +/** + * msd_timeline_get_fps: + * @timeline: A #MsdTimeline + * + * Returns the number of frames per second. + * + * Return Value: frames per second + **/ +guint +msd_timeline_get_fps (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 1); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + return priv->fps; +} + +/** + * msd_timeline_set_fps: + * @timeline: A #MsdTimeline + * @fps: frames per second + * + * Sets the number of frames per second that + * the timeline will play. + **/ +void +msd_timeline_set_fps (MsdTimeline *timeline, + guint fps) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + g_return_if_fail (fps > 0); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + priv->fps = fps; + + if (msd_timeline_is_running (timeline)) + { + g_source_remove (priv->source_id); + priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), + (GSourceFunc) msd_timeline_run_frame, + timeline); + } + + g_object_notify (G_OBJECT (timeline), "fps"); +} + +/** + * msd_timeline_get_loop: + * @timeline: A #MsdTimeline + * + * Returns whether the timeline loops to the + * beginning when it has reached the end. + * + * Return Value: %TRUE if the timeline loops + **/ +gboolean +msd_timeline_get_loop (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), FALSE); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + return priv->loop; +} + +/** + * msd_timeline_set_loop: + * @timeline: A #MsdTimeline + * @loop: %TRUE to make the timeline loop + * + * Sets whether the timeline loops to the beginning + * when it has reached the end. + **/ +void +msd_timeline_set_loop (MsdTimeline *timeline, + gboolean loop) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + priv->loop = loop; + + g_object_notify (G_OBJECT (timeline), "loop"); +} + +void +msd_timeline_set_duration (MsdTimeline *timeline, + guint duration) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + priv->duration = duration; + + g_object_notify (G_OBJECT (timeline), "duration"); +} + +guint +msd_timeline_get_duration (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 0); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + return priv->duration; +} + +/** + * msd_timeline_get_direction: + * @timeline: A #MsdTimeline + * + * Returns the direction of the timeline. + * + * Return Value: direction + **/ +MsdTimelineDirection +msd_timeline_get_direction (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), MSD_TIMELINE_DIRECTION_FORWARD); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + return priv->direction; +} + +/** + * msd_timeline_set_direction: + * @timeline: A #MsdTimeline + * @direction: direction + * + * Sets the direction of the timeline. + **/ +void +msd_timeline_set_direction (MsdTimeline *timeline, + MsdTimelineDirection direction) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + priv->direction = direction; + + g_object_notify (G_OBJECT (timeline), "direction"); +} + +GdkScreen * +msd_timeline_get_screen (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), NULL); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + return priv->screen; +} + +void +msd_timeline_set_screen (MsdTimeline *timeline, + GdkScreen *screen) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + g_return_if_fail (GDK_IS_SCREEN (screen)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + if (priv->screen) + g_object_unref (priv->screen); + + priv->screen = g_object_ref (screen); + + g_object_notify (G_OBJECT (timeline), "screen"); +} + +void +msd_timeline_set_progress_type (MsdTimeline *timeline, + MsdTimelineProgressType type) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + priv->progress_type = type; + + g_object_notify (G_OBJECT (timeline), "progress-type"); +} + +MsdTimelineProgressType +msd_timeline_get_progress_type (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), MSD_TIMELINE_PROGRESS_LINEAR); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + if (priv->progress_func) + return MSD_TIMELINE_PROGRESS_LINEAR; + + return priv->progress_type; +} + +/** + * msd_timeline_set_progress_func: + * @timeline: A #MsdTimeline + * @progress_func: progress function + * + * Sets the progress function. This function will be used to calculate + * a different progress to pass to the ::frame signal based on the + * linear progress through the timeline. Setting progress_func + * to %NULL will make the timeline use the default function, + * which is just a linear progress. + * + * All progresses are in the [0.0, 1.0] range. + **/ +void +msd_timeline_set_progress_func (MsdTimeline *timeline, + MsdTimelineProgressFunc progress_func) +{ + MsdTimelinePriv *priv; + + g_return_if_fail (MSD_IS_TIMELINE (timeline)); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + priv->progress_func = progress_func; +} + +gdouble +msd_timeline_get_progress (MsdTimeline *timeline) +{ + MsdTimelinePriv *priv; + MsdTimelineProgressFunc progress_func = NULL; + gdouble linear_progress, progress; + guint elapsed_time; + + g_return_val_if_fail (MSD_IS_TIMELINE (timeline), 0.0); + + priv = MSD_TIMELINE_GET_PRIV (timeline); + + if (!priv->timer) + return 0.; + + elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000); + + linear_progress = (gdouble) elapsed_time / priv->duration; + + if (priv->direction == MSD_TIMELINE_DIRECTION_BACKWARD) + linear_progress = 1 - linear_progress; + + linear_progress = CLAMP (linear_progress, 0., 1.); + + if (priv->progress_func) + progress_func = priv->progress_func; + else if (priv->progress_type) + progress_func = progress_type_to_func (priv->progress_type); + + if (progress_func) + progress = (progress_func) (linear_progress); + else + progress = linear_progress; + + return CLAMP (progress, 0., 1.); +} diff --git a/plugins/mouse/msd-timeline.h b/plugins/mouse/msd-timeline.h new file mode 100644 index 0000000..b8d40ca --- /dev/null +++ b/plugins/mouse/msd-timeline.h @@ -0,0 +1,127 @@ +/* msdtimeline.c + * + * Copyright (C) 2008 Carlos Garnacho + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __MSD_TIMELINE_H__ +#define __MSD_TIMELINE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_TIMELINE_DIRECTION (msd_timeline_direction_get_type ()) +#define MSD_TYPE_TIMELINE_PROGRESS_TYPE (msd_timeline_progress_type_get_type ()) +#define MSD_TYPE_TIMELINE (msd_timeline_get_type ()) +#define MSD_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_TIMELINE, MsdTimeline)) +#define MSD_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_TIMELINE, MsdTimelineClass)) +#define MSD_IS_TIMELINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_TIMELINE)) +#define MSD_IS_TIMELINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_TIMELINE)) +#define MSD_TIMELINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_TIMELINE, MsdTimelineClass)) + +typedef enum { + MSD_TIMELINE_DIRECTION_FORWARD, + MSD_TIMELINE_DIRECTION_BACKWARD +} MsdTimelineDirection; + +typedef enum { + MSD_TIMELINE_PROGRESS_LINEAR, + MSD_TIMELINE_PROGRESS_SINUSOIDAL, + MSD_TIMELINE_PROGRESS_EXPONENTIAL +} MsdTimelineProgressType; + +typedef struct MsdTimeline MsdTimeline; +typedef struct MsdTimelineClass MsdTimelineClass; + +struct MsdTimeline +{ + GObject parent_instance; +}; + +struct MsdTimelineClass +{ + GObjectClass parent_class; + + void (* started) (MsdTimeline *timeline); + void (* finished) (MsdTimeline *timeline); + void (* paused) (MsdTimeline *timeline); + + void (* frame) (MsdTimeline *timeline, + gdouble progress); + + void (* __msd_reserved1) (void); + void (* __msd_reserved2) (void); + void (* __msd_reserved3) (void); + void (* __msd_reserved4) (void); +}; + +typedef gdouble (*MsdTimelineProgressFunc) (gdouble progress); + + +GType msd_timeline_get_type (void) G_GNUC_CONST; +GType msd_timeline_direction_get_type (void) G_GNUC_CONST; +GType msd_timeline_progress_type_get_type (void) G_GNUC_CONST; + +MsdTimeline *msd_timeline_new (guint duration); +MsdTimeline *msd_timeline_new_for_screen (guint duration, + GdkScreen *screen); + +void msd_timeline_start (MsdTimeline *timeline); +void msd_timeline_pause (MsdTimeline *timeline); +void msd_timeline_rewind (MsdTimeline *timeline); + +gboolean msd_timeline_is_running (MsdTimeline *timeline); + +guint msd_timeline_get_fps (MsdTimeline *timeline); +void msd_timeline_set_fps (MsdTimeline *timeline, + guint fps); + +gboolean msd_timeline_get_loop (MsdTimeline *timeline); +void msd_timeline_set_loop (MsdTimeline *timeline, + gboolean loop); + +guint msd_timeline_get_duration (MsdTimeline *timeline); +void msd_timeline_set_duration (MsdTimeline *timeline, + guint duration); + +GdkScreen *msd_timeline_get_screen (MsdTimeline *timeline); +void msd_timeline_set_screen (MsdTimeline *timeline, + GdkScreen *screen); + +MsdTimelineDirection msd_timeline_get_direction (MsdTimeline *timeline); +void msd_timeline_set_direction (MsdTimeline *timeline, + MsdTimelineDirection direction); + +MsdTimelineProgressType msd_timeline_get_progress_type (MsdTimeline *timeline); +void msd_timeline_set_progress_type (MsdTimeline *timeline, + MsdTimelineProgressType type); +void msd_timeline_get_progress_func (MsdTimeline *timeline); + +void msd_timeline_set_progress_func (MsdTimeline *timeline, + MsdTimelineProgressFunc progress_func); + +gdouble msd_timeline_get_progress (MsdTimeline *timeline); + + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_TIMELINE_H__ */ diff --git a/plugins/smartcard/gsd-smartcard-manager.c b/plugins/smartcard/gsd-smartcard-manager.c deleted file mode 100644 index ed823f4..0000000 --- a/plugins/smartcard/gsd-smartcard-manager.c +++ /dev/null @@ -1,1372 +0,0 @@ -/* msd-smartcard-manager.c - object for monitoring smartcard insertion and - * removal events - * - * Copyright (C) 2006, 2009 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * Written By: Ray Strode - */ -#include "config.h" - -#include "msd-smartcard-manager.h" - -#define SMARTCARD_ENABLE_INTERNAL_API -#include "msd-smartcard.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#ifndef MSD_SMARTCARD_MANAGER_NSS_DB -#define MSD_SMARTCARD_MANAGER_NSS_DB SYSCONFDIR"/pki/nssdb" -#endif - -typedef enum _MsdSmartcardManagerState MsdSmartcardManagerState; -typedef struct _MsdSmartcardManagerWorker MsdSmartcardManagerWorker; - -enum _MsdSmartcardManagerState { - MSD_SMARTCARD_MANAGER_STATE_STOPPED = 0, - MSD_SMARTCARD_MANAGER_STATE_STARTING, - MSD_SMARTCARD_MANAGER_STATE_STARTED, - MSD_SMARTCARD_MANAGER_STATE_STOPPING, -}; - -struct _MsdSmartcardManagerPrivate { - MsdSmartcardManagerState state; - SECMODModule *module; - char *module_path; - - GSource *smartcard_event_source; - GPid smartcard_event_watcher_pid; - GHashTable *smartcards; - - GThread *worker_thread; - - guint poll_timeout_id; - - guint32 is_unstoppable : 1; - guint32 nss_is_loaded : 1; -}; - -struct _MsdSmartcardManagerWorker { - SECMODModule *module; - GHashTable *smartcards; - int write_fd; - - guint32 nss_is_loaded : 1; -}; - -static void msd_smartcard_manager_finalize (GObject *object); -static void msd_smartcard_manager_class_install_signals (MsdSmartcardManagerClass *service_class); -static void msd_smartcard_manager_class_install_properties (MsdSmartcardManagerClass *service_class); -static void msd_smartcard_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void msd_smartcard_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void msd_smartcard_manager_set_module_path (MsdSmartcardManager *manager, - const char *module_path); -static void msd_smartcard_manager_card_removed_handler (MsdSmartcardManager *manager, - MsdSmartcard *card); -static void msd_smartcard_manager_card_inserted_handler (MsdSmartcardManager *manager_class, - MsdSmartcard *card); -static gboolean msd_smartcard_manager_stop_now (MsdSmartcardManager *manager); -static void msd_smartcard_manager_queue_stop (MsdSmartcardManager *manager); - -static gboolean msd_smartcard_manager_create_worker (MsdSmartcardManager *manager, - int *worker_fd, GThread **worker_thread); - -static MsdSmartcardManagerWorker * msd_smartcard_manager_worker_new (int write_fd); -static void msd_smartcard_manager_worker_free (MsdSmartcardManagerWorker *worker); -static gboolean open_pipe (int *write_fd, int *read_fd); -static gboolean read_bytes (int fd, gpointer bytes, gsize num_bytes); -static gboolean write_bytes (int fd, gconstpointer bytes, gsize num_bytes); -static MsdSmartcard *read_smartcard (int fd, SECMODModule *module); -static gboolean write_smartcard (int fd, MsdSmartcard *card); - -enum { - PROP_0 = 0, - PROP_MODULE_PATH, - NUMBER_OF_PROPERTIES -}; - -enum { - SMARTCARD_INSERTED = 0, - SMARTCARD_REMOVED, - ERROR, - NUMBER_OF_SIGNALS -}; - -static guint msd_smartcard_manager_signals[NUMBER_OF_SIGNALS]; - -G_DEFINE_TYPE (MsdSmartcardManager, - msd_smartcard_manager, - G_TYPE_OBJECT); - -static void -msd_smartcard_manager_class_init (MsdSmartcardManagerClass *manager_class) -{ - GObjectClass *gobject_class; - - gobject_class = G_OBJECT_CLASS (manager_class); - - gobject_class->finalize = msd_smartcard_manager_finalize; - - msd_smartcard_manager_class_install_signals (manager_class); - msd_smartcard_manager_class_install_properties (manager_class); - - g_type_class_add_private (manager_class, - sizeof (MsdSmartcardManagerPrivate)); -} - -static void -msd_smartcard_manager_class_install_properties (MsdSmartcardManagerClass *card_class) -{ - GObjectClass *object_class; - GParamSpec *param_spec; - - object_class = G_OBJECT_CLASS (card_class); - object_class->set_property = msd_smartcard_manager_set_property; - object_class->get_property = msd_smartcard_manager_get_property; - - param_spec = g_param_spec_string ("module-path", _("Module Path"), - _("path to smartcard PKCS #11 driver"), - NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, PROP_MODULE_PATH, param_spec); -} - -static void -msd_smartcard_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdSmartcardManager *manager = MSD_SMARTCARD_MANAGER (object); - - switch (prop_id) { - case PROP_MODULE_PATH: - msd_smartcard_manager_set_module_path (manager, - g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_smartcard_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdSmartcardManager *manager = MSD_SMARTCARD_MANAGER (object); - char *module_path; - - switch (prop_id) { - case PROP_MODULE_PATH: - module_path = msd_smartcard_manager_get_module_path (manager); - g_value_set_string (value, module_path); - g_free (module_path); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -char * -msd_smartcard_manager_get_module_path (MsdSmartcardManager *manager) -{ - return manager->priv->module_path; -} - -static void -msd_smartcard_manager_set_module_path (MsdSmartcardManager *manager, - const char *module_path) -{ - if ((manager->priv->module_path == NULL) && (module_path == NULL)) { - return; - } - - if (((manager->priv->module_path == NULL) || - (module_path == NULL) || - (strcmp (manager->priv->module_path, module_path) != 0))) { - g_free (manager->priv->module_path); - manager->priv->module_path = g_strdup (module_path); - g_object_notify (G_OBJECT (manager), "module-path"); - } -} - -static void -msd_smartcard_manager_card_removed_handler (MsdSmartcardManager *manager, - MsdSmartcard *card) -{ - g_debug ("informing smartcard of its removal"); - _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); - g_debug ("done"); -} - -static void -msd_smartcard_manager_card_inserted_handler (MsdSmartcardManager *manager, - MsdSmartcard *card) -{ - g_debug ("informing smartcard of its insertion"); - - _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); - g_debug ("done"); - -} - -static void -msd_smartcard_manager_class_install_signals (MsdSmartcardManagerClass *manager_class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (manager_class); - - msd_smartcard_manager_signals[SMARTCARD_INSERTED] = - g_signal_new ("smartcard-inserted", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (MsdSmartcardManagerClass, - smartcard_inserted), - NULL, NULL, g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - manager_class->smartcard_inserted = msd_smartcard_manager_card_inserted_handler; - - msd_smartcard_manager_signals[SMARTCARD_REMOVED] = - g_signal_new ("smartcard-removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (MsdSmartcardManagerClass, - smartcard_removed), - NULL, NULL, g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - manager_class->smartcard_removed = msd_smartcard_manager_card_removed_handler; - - msd_smartcard_manager_signals[ERROR] = - g_signal_new ("error", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdSmartcardManagerClass, error), - NULL, NULL, g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - manager_class->error = NULL; -} - -static gboolean -slot_id_equal (CK_SLOT_ID *slot_id_1, - CK_SLOT_ID *slot_id_2) -{ - g_assert (slot_id_1 != NULL); - g_assert (slot_id_2 != NULL); - - return *slot_id_1 == *slot_id_2; -} - -static gboolean -slot_id_hash (CK_SLOT_ID *slot_id) -{ - guint32 upper_bits, lower_bits; - int temp; - - if (sizeof (CK_SLOT_ID) == sizeof (int)) { - return g_int_hash (slot_id); - } - - upper_bits = ((*slot_id) >> 31) - 1; - lower_bits = (*slot_id) & 0xffffffff; - - /* The upper bits are almost certainly always zero, - * so let's degenerate to g_int_hash for the - * (very) common case - */ - temp = lower_bits + upper_bits; - return upper_bits + g_int_hash (&temp); -} - -static void -msd_smartcard_manager_init (MsdSmartcardManager *manager) -{ - g_debug ("initializing smartcard manager"); - - manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, - MSD_TYPE_SMARTCARD_MANAGER, - MsdSmartcardManagerPrivate); - manager->priv->poll_timeout_id = 0; - manager->priv->is_unstoppable = FALSE; - manager->priv->module = NULL; - - manager->priv->smartcards = - g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_object_unref); - - if (!g_thread_supported ()) { - g_thread_init (NULL); - } - -} - -static void -msd_smartcard_manager_finalize (GObject *object) -{ - MsdSmartcardManager *manager; - GObjectClass *gobject_class; - - manager = MSD_SMARTCARD_MANAGER (object); - gobject_class = - G_OBJECT_CLASS (msd_smartcard_manager_parent_class); - - msd_smartcard_manager_stop_now (manager); - - g_hash_table_destroy (manager->priv->smartcards); - manager->priv->smartcards = NULL; - - gobject_class->finalize (object); -} - -GQuark -msd_smartcard_manager_error_quark (void) -{ - static GQuark error_quark = 0; - - if (error_quark == 0) { - error_quark = g_quark_from_static_string ("msd-smartcard-manager-error-quark"); - } - - return error_quark; -} - -MsdSmartcardManager * -msd_smartcard_manager_new (const char *module_path) -{ - MsdSmartcardManager *instance; - - instance = MSD_SMARTCARD_MANAGER (g_object_new (MSD_TYPE_SMARTCARD_MANAGER, - "module-path", module_path, - NULL)); - - return instance; -} - -static void -msd_smartcard_manager_emit_error (MsdSmartcardManager *manager, - GError *error) -{ - manager->priv->is_unstoppable = TRUE; - g_signal_emit (manager, msd_smartcard_manager_signals[ERROR], 0, - error); - manager->priv->is_unstoppable = FALSE; -} - -static void -msd_smartcard_manager_emit_smartcard_inserted (MsdSmartcardManager *manager, - MsdSmartcard *card) -{ - manager->priv->is_unstoppable = TRUE; - g_signal_emit (manager, msd_smartcard_manager_signals[SMARTCARD_INSERTED], 0, - card); - manager->priv->is_unstoppable = FALSE; -} - -static void -msd_smartcard_manager_emit_smartcard_removed (MsdSmartcardManager *manager, - MsdSmartcard *card) -{ - MsdSmartcardManagerState old_state; - - old_state = manager->priv->state; - manager->priv->is_unstoppable = TRUE; - g_signal_emit (manager, msd_smartcard_manager_signals[SMARTCARD_REMOVED], 0, - card); - manager->priv->is_unstoppable = FALSE; -} - -static gboolean -msd_smartcard_manager_check_for_and_process_events (GIOChannel *io_channel, - GIOCondition condition, - MsdSmartcardManager *manager) -{ - MsdSmartcard *card; - gboolean should_stop; - gchar event_type; - char *card_name; - int fd; - - card = NULL; - should_stop = (condition & G_IO_HUP) || (condition & G_IO_ERR); - - if (should_stop) { - g_debug ("received %s on event socket, stopping " - "manager...", - (condition & G_IO_HUP) && (condition & G_IO_ERR)? - "error and hangup" : - (condition & G_IO_HUP)? - "hangup" : "error"); - } - - if (!(condition & G_IO_IN)) { - goto out; - } - - fd = g_io_channel_unix_get_fd (io_channel); - - event_type = '\0'; - if (!read_bytes (fd, &event_type, 1)) { - should_stop = TRUE; - goto out; - } - - card = read_smartcard (fd, manager->priv->module); - - if (card == NULL) { - should_stop = TRUE; - goto out; - } - - card_name = msd_smartcard_get_name (card); - - switch (event_type) { - case 'I': - g_hash_table_replace (manager->priv->smartcards, - card_name, card); - card_name = NULL; - - msd_smartcard_manager_emit_smartcard_inserted (manager, card); - card = NULL; - break; - - case 'R': - msd_smartcard_manager_emit_smartcard_removed (manager, card); - if (!g_hash_table_remove (manager->priv->smartcards, card_name)) { - g_debug ("got removal event of unknown card!"); - } - g_free (card_name); - card_name = NULL; - card = NULL; - break; - - default: - g_free (card_name); - card_name = NULL; - g_object_unref (card); - - should_stop = TRUE; - break; - } - -out: - if (should_stop) { - GError *error; - - error = g_error_new (MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, - "%s", (condition & G_IO_IN) ? g_strerror (errno) : _("received error or hang up from event source")); - - msd_smartcard_manager_emit_error (manager, error); - g_error_free (error); - msd_smartcard_manager_stop_now (manager); - return FALSE; - } - - return TRUE; -} - -static void -msd_smartcard_manager_event_processing_stopped_handler (MsdSmartcardManager *manager) -{ - manager->priv->smartcard_event_source = NULL; - msd_smartcard_manager_stop_now (manager); -} - -static gboolean -open_pipe (int *write_fd, - int *read_fd) -{ - int pipe_fds[2] = { -1, -1 }; - - g_assert (write_fd != NULL); - g_assert (read_fd != NULL); - - if (pipe (pipe_fds) < 0) { - return FALSE; - } - - if (fcntl (pipe_fds[0], F_SETFD, FD_CLOEXEC) < 0) { - close (pipe_fds[0]); - close (pipe_fds[1]); - return FALSE; - } - - if (fcntl (pipe_fds[1], F_SETFD, FD_CLOEXEC) < 0) { - close (pipe_fds[0]); - close (pipe_fds[1]); - return FALSE; - } - - *read_fd = pipe_fds[0]; - *write_fd = pipe_fds[1]; - - return TRUE; -} - -static void -msd_smartcard_manager_stop_watching_for_events (MsdSmartcardManager *manager) -{ - if (manager->priv->smartcard_event_source != NULL) { - g_source_destroy (manager->priv->smartcard_event_source); - manager->priv->smartcard_event_source = NULL; - } - - if (manager->priv->worker_thread != NULL) { - SECMOD_CancelWait (manager->priv->module); - manager->priv->worker_thread = NULL; - } -} - -static gboolean -load_nss (GError **error) -{ - SECStatus status = SECSuccess; - static const guint32 flags = - NSS_INIT_READONLY | NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | - NSS_INIT_FORCEOPEN | NSS_INIT_NOROOTINIT | - NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD; - - g_debug ("attempting to load NSS database '%s'", - MSD_SMARTCARD_MANAGER_NSS_DB); - - status = NSS_Initialize (MSD_SMARTCARD_MANAGER_NSS_DB, - "", "", SECMOD_DB, flags); - - if (status != SECSuccess) { - gsize error_message_size; - char *error_message; - - error_message_size = PR_GetErrorTextLength (); - - if (error_message_size == 0) { - g_debug ("NSS security system could not be initialized"); - g_set_error (error, - MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, - _("NSS security system could not be initialized")); - goto out; - } - - error_message = g_slice_alloc0 (error_message_size); - PR_GetErrorText (error_message); - - g_set_error (error, - MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, - "%s", error_message); - g_debug ("NSS security system could not be initialized - %s", - error_message); - - g_slice_free1 (error_message_size, error_message); - - goto out; - } - - g_debug ("NSS database sucessfully loaded"); - return TRUE; - -out: - g_debug ("NSS database couldn't be sucessfully loaded"); - return FALSE; -} - -static SECMODModule * -load_driver (char *module_path, - GError **error) -{ - SECMODModule *module; - char *module_spec; - gboolean module_explicitly_specified; - - g_debug ("attempting to load driver..."); - - module = NULL; - module_explicitly_specified = module_path != NULL; - if (module_explicitly_specified) { - module_spec = g_strdup_printf ("library=\"%s\"", module_path); - g_debug ("loading smartcard driver using spec '%s'", - module_spec); - - module = SECMOD_LoadUserModule (module_spec, - NULL /* parent */, - FALSE /* recurse */); - g_free (module_spec); - module_spec = NULL; - - } else { - SECMODModuleList *modules, *tmp; - - modules = SECMOD_GetDefaultModuleList (); - - for (tmp = modules; tmp != NULL; tmp = tmp->next) { - if (!SECMOD_HasRemovableSlots (tmp->module) || - !tmp->module->loaded) - continue; - - module = SECMOD_ReferenceModule (tmp->module); - break; - } - } - - if (!module_explicitly_specified && module == NULL) { - g_set_error (error, - MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, - _("no suitable smartcard driver could be found")); - } else if (module == NULL || !module->loaded) { - - gsize error_message_size; - char *error_message; - - if (module != NULL && !module->loaded) { - g_debug ("module found but not loaded?!"); - SECMOD_DestroyModule (module); - module = NULL; - } - - error_message_size = PR_GetErrorTextLength (); - - if (error_message_size == 0) { - g_debug ("smartcard driver '%s' could not be loaded", - module_path); - g_set_error (error, - MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, - _("smartcard driver '%s' could not be " - "loaded"), module_path); - goto out; - } - - error_message = g_slice_alloc0 (error_message_size); - PR_GetErrorText (error_message); - - g_set_error (error, - MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, - "%s", error_message); - - g_debug ("smartcard driver '%s' could not be loaded - %s", - module_path, error_message); - g_slice_free1 (error_message_size, error_message); - } - -out: - return module; -} - -static void -msd_smartcard_manager_get_all_cards (MsdSmartcardManager *manager) -{ - int i; - - for (i = 0; i < manager->priv->module->slotCount; i++) { - MsdSmartcard *card; - CK_SLOT_ID slot_id; - int slot_series; - char *card_name; - - slot_id = PK11_GetSlotID (manager->priv->module->slots[i]); - slot_series = PK11_GetSlotSeries (manager->priv->module->slots[i]); - - card = _msd_smartcard_new (manager->priv->module, - slot_id, slot_series); - - card_name = msd_smartcard_get_name (card); - - g_hash_table_replace (manager->priv->smartcards, - card_name, card); - } -} - -gboolean -msd_smartcard_manager_start (MsdSmartcardManager *manager, - GError **error) -{ - GError *watching_error; - int worker_fd; - GPid worker_pid; - GIOChannel *io_channel; - GSource *source; - GIOFlags channel_flags; - GError *nss_error; - - if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STARTED) { - g_debug ("smartcard manager already started"); - return TRUE; - } - - manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STARTING; - - worker_fd = -1; - worker_pid = 0; - - nss_error = NULL; - if (!manager->priv->nss_is_loaded && !load_nss (&nss_error)) { - g_propagate_error (error, nss_error); - goto out; - } - manager->priv->nss_is_loaded = TRUE; - - if (manager->priv->module == NULL) { - manager->priv->module = load_driver (manager->priv->module_path, &nss_error); - } - - if (manager->priv->module == NULL) { - g_propagate_error (error, nss_error); - goto out; - } - - if (!msd_smartcard_manager_create_worker (manager, &worker_fd, &manager->priv->worker_thread)) { - - g_set_error (error, - MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, - _("could not watch for incoming card events - %s"), - g_strerror (errno)); - - goto out; - } - - io_channel = g_io_channel_unix_new (worker_fd); - - channel_flags = g_io_channel_get_flags (io_channel); - watching_error = NULL; - - source = g_io_create_watch (io_channel, G_IO_IN | G_IO_HUP); - g_io_channel_unref (io_channel); - io_channel = NULL; - - manager->priv->smartcard_event_source = source; - - g_source_set_callback (manager->priv->smartcard_event_source, - (GSourceFunc) (GIOFunc) - msd_smartcard_manager_check_for_and_process_events, - manager, - (GDestroyNotify) - msd_smartcard_manager_event_processing_stopped_handler); - g_source_attach (manager->priv->smartcard_event_source, NULL); - g_source_unref (manager->priv->smartcard_event_source); - - /* populate the hash with cards that are already inserted - */ - msd_smartcard_manager_get_all_cards (manager); - - manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STARTED; - -out: - /* don't leave it in a half started state - */ - if (manager->priv->state != MSD_SMARTCARD_MANAGER_STATE_STARTED) { - g_debug ("smartcard manager could not be completely started"); - msd_smartcard_manager_stop (manager); - } else { - g_debug ("smartcard manager started"); - } - - return manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STARTED; -} - -static gboolean -msd_smartcard_manager_stop_now (MsdSmartcardManager *manager) -{ - if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STOPPED) { - return FALSE; - } - - manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STOPPED; - msd_smartcard_manager_stop_watching_for_events (manager); - - if (manager->priv->module != NULL) { - SECMOD_DestroyModule (manager->priv->module); - manager->priv->module = NULL; - } - - if (manager->priv->nss_is_loaded) { - NSS_Shutdown (); - manager->priv->nss_is_loaded = FALSE; - } - - g_debug ("smartcard manager stopped"); - - return FALSE; -} - -static void -msd_smartcard_manager_queue_stop (MsdSmartcardManager *manager) -{ - - manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STOPPING; - - g_idle_add ((GSourceFunc) msd_smartcard_manager_stop_now, manager); -} - -void -msd_smartcard_manager_stop (MsdSmartcardManager *manager) -{ - if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STOPPED) { - return; - } - - if (manager->priv->is_unstoppable) { - msd_smartcard_manager_queue_stop (manager); - return; - } - - msd_smartcard_manager_stop_now (manager); -} - -static void -msd_smartcard_manager_check_for_login_card (CK_SLOT_ID slot_id, - MsdSmartcard *card, - gboolean *is_inserted) -{ - g_assert (is_inserted != NULL); - - if (msd_smartcard_is_login_card (card)) { - *is_inserted = TRUE; - } - -} - -gboolean -msd_smartcard_manager_login_card_is_inserted (MsdSmartcardManager *manager) - -{ - gboolean is_inserted; - - is_inserted = FALSE; - g_hash_table_foreach (manager->priv->smartcards, - (GHFunc) - msd_smartcard_manager_check_for_login_card, - &is_inserted); - return is_inserted; -} - -static MsdSmartcardManagerWorker * -msd_smartcard_manager_worker_new (int write_fd) -{ - MsdSmartcardManagerWorker *worker; - - worker = g_slice_new0 (MsdSmartcardManagerWorker); - worker->write_fd = write_fd; - worker->module = NULL; - - worker->smartcards = - g_hash_table_new_full ((GHashFunc) slot_id_hash, - (GEqualFunc) slot_id_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_object_unref); - - return worker; -} - -static void -msd_smartcard_manager_worker_free (MsdSmartcardManagerWorker *worker) -{ - if (worker->smartcards != NULL) { - g_hash_table_destroy (worker->smartcards); - worker->smartcards = NULL; - } - - g_slice_free (MsdSmartcardManagerWorker, worker); -} - -static gboolean -read_bytes (int fd, - gpointer bytes, - gsize num_bytes) -{ - size_t bytes_left; - size_t total_bytes_read; - ssize_t bytes_read; - - bytes_left = (size_t) num_bytes; - total_bytes_read = 0; - - do { - bytes_read = read (fd, - (char *) bytes + total_bytes_read, - bytes_left); - g_assert (bytes_read <= (ssize_t) bytes_left); - - if (bytes_read <= 0) { - if ((bytes_read < 0) && (errno == EINTR || errno == EAGAIN)) { - continue; - } - - bytes_left = 0; - } else { - bytes_left -= bytes_read; - total_bytes_read += bytes_read; - } - } while (bytes_left > 0); - - if (total_bytes_read < (size_t) num_bytes) { - return FALSE; - } - - return TRUE; -} - -static gboolean -write_bytes (int fd, - gconstpointer bytes, - gsize num_bytes) -{ - size_t bytes_left; - size_t total_bytes_written; - ssize_t bytes_written; - - bytes_left = (size_t) num_bytes; - total_bytes_written = 0; - - do { - bytes_written = write (fd, - (char *) bytes + total_bytes_written, - bytes_left); - g_assert (bytes_written <= (ssize_t) bytes_left); - - if (bytes_written <= 0) { - if ((bytes_written < 0) && (errno == EINTR || errno == EAGAIN)) { - continue; - } - - bytes_left = 0; - } else { - bytes_left -= bytes_written; - total_bytes_written += bytes_written; - } - } while (bytes_left > 0); - - if (total_bytes_written < (size_t) num_bytes) { - return FALSE; - } - - return TRUE; -} - -static MsdSmartcard * -read_smartcard (int fd, - SECMODModule *module) -{ - MsdSmartcard *card; - char *card_name; - gsize card_name_size; - - card_name_size = 0; - if (!read_bytes (fd, &card_name_size, sizeof (card_name_size))) { - return NULL; - } - - card_name = g_slice_alloc0 (card_name_size); - if (!read_bytes (fd, card_name, card_name_size)) { - g_slice_free1 (card_name_size, card_name); - return NULL; - } - card = _msd_smartcard_new_from_name (module, card_name); - g_slice_free1 (card_name_size, card_name); - - return card; -} - -static gboolean -write_smartcard (int fd, - MsdSmartcard *card) -{ - gsize card_name_size; - char *card_name; - - card_name = msd_smartcard_get_name (card); - card_name_size = strlen (card_name) + 1; - - if (!write_bytes (fd, &card_name_size, sizeof (card_name_size))) { - g_free (card_name); - return FALSE; - } - - if (!write_bytes (fd, card_name, card_name_size)) { - g_free (card_name); - return FALSE; - } - g_free (card_name); - - return TRUE; -} - -static gboolean -msd_smartcard_manager_worker_emit_smartcard_removed (MsdSmartcardManagerWorker *worker, - MsdSmartcard *card, - GError **error) -{ - g_debug ("card '%s' removed!", msd_smartcard_get_name (card)); - - if (!write_bytes (worker->write_fd, "R", 1)) { - goto error_out; - } - - if (!write_smartcard (worker->write_fd, card)) { - goto error_out; - } - - return TRUE; - -error_out: - g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, - "%s", g_strerror (errno)); - return FALSE; -} - -static gboolean -msd_smartcard_manager_worker_emit_smartcard_inserted (MsdSmartcardManagerWorker *worker, - MsdSmartcard *card, - GError **error) -{ - GError *write_error; - - write_error = NULL; - g_debug ("card '%s' inserted!", msd_smartcard_get_name (card)); - if (!write_bytes (worker->write_fd, "I", 1)) { - goto error_out; - } - - if (!write_smartcard (worker->write_fd, card)) { - goto error_out; - } - - return TRUE; - -error_out: - g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, - "%s", g_strerror (errno)); - return FALSE; -} - -static gboolean -msd_smartcard_manager_worker_watch_for_and_process_event (MsdSmartcardManagerWorker *worker, - GError **error) -{ - PK11SlotInfo *slot; - CK_SLOT_ID slot_id, *key; - int slot_series, card_slot_series; - MsdSmartcard *card; - GError *processing_error; - gboolean ret; - - g_debug ("waiting for card event"); - ret = FALSE; - - slot = SECMOD_WaitForAnyTokenEvent (worker->module, 0, PR_SecondsToInterval (1)); - processing_error = NULL; - - if (slot == NULL) { - int error_code; - - error_code = PORT_GetError (); - if ((error_code == 0) || (error_code == SEC_ERROR_NO_EVENT)) { - g_debug ("spurrious event occurred"); - return TRUE; - } - - /* FIXME: is there a function to convert from a PORT error - * code to a translated string? - */ - g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, - MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, - _("encountered unexpected error while " - "waiting for smartcard events")); - goto out; - } - - /* the slot id and series together uniquely identify a card. - * You can never have two cards with the same slot id at the - * same time, however (I think), so we can key off of it. - */ - slot_id = PK11_GetSlotID (slot); - slot_series = PK11_GetSlotSeries (slot); - - /* First check to see if there is a card that we're currently - * tracking in the slot. - */ - key = g_new (CK_SLOT_ID, 1); - *key = slot_id; - card = g_hash_table_lookup (worker->smartcards, key); - - if (card != NULL) { - card_slot_series = msd_smartcard_get_slot_series (card); - } else { - card_slot_series = -1; - } - - if (PK11_IsPresent (slot)) { - /* Now, check to see if their is a new card in the slot. - * If there was a different card in the slot now than - * there was before, then we need to emit a removed signal - * for the old card (we don't want unpaired insertion events). - */ - if ((card != NULL) && - card_slot_series != slot_series) { - if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { - g_propagate_error (error, processing_error); - goto out; - } - } - - card = _msd_smartcard_new (worker->module, - slot_id, slot_series); - - g_hash_table_replace (worker->smartcards, - key, card); - key = NULL; - - if (!msd_smartcard_manager_worker_emit_smartcard_inserted (worker, - card, - &processing_error)) { - g_propagate_error (error, processing_error); - goto out; - } - } else { - /* if we aren't tracking the card, just discard the event. - * We don't want unpaired remove events. Note on startup - * NSS will generate an "insertion" event if a card is - * already inserted in the slot. - */ - if ((card != NULL)) { - /* FIXME: i'm not sure about this code. Maybe we - * shouldn't do this at all, or maybe we should do it - * n times (where n = slot_series - card_slot_series + 1) - * - * Right now, i'm just doing it once. - */ - if ((slot_series - card_slot_series) > 1) { - - if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { - g_propagate_error (error, processing_error); - goto out; - } - g_hash_table_remove (worker->smartcards, key); - - card = _msd_smartcard_new (worker->module, - slot_id, slot_series); - g_hash_table_replace (worker->smartcards, - key, card); - key = NULL; - if (!msd_smartcard_manager_worker_emit_smartcard_inserted (worker, card, &processing_error)) { - g_propagate_error (error, processing_error); - goto out; - } - } - - if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { - g_propagate_error (error, processing_error); - goto out; - } - - g_hash_table_remove (worker->smartcards, key); - card = NULL; - } else { - g_debug ("got spurious remove event"); - } - } - - ret = TRUE; - -out: - g_free (key); - PK11_FreeSlot (slot); - - return ret; -} - -static void -msd_smartcard_manager_worker_run (MsdSmartcardManagerWorker *worker) -{ - GError *error; - - - error = NULL; - - while (msd_smartcard_manager_worker_watch_for_and_process_event (worker, &error)); - - if (error != NULL) { - g_debug ("could not process card event - %s", error->message); - g_error_free (error); - } - - msd_smartcard_manager_worker_free (worker); -} - -static gboolean -msd_smartcard_manager_create_worker (MsdSmartcardManager *manager, - int *worker_fd, - GThread **worker_thread) -{ - MsdSmartcardManagerWorker *worker; - int write_fd, read_fd; - - write_fd = -1; - read_fd = -1; - if (!open_pipe (&write_fd, &read_fd)) { - return FALSE; - } - - worker = msd_smartcard_manager_worker_new (write_fd); - worker->module = manager->priv->module; - - *worker_thread = g_thread_create ((GThreadFunc) - msd_smartcard_manager_worker_run, - worker, FALSE, NULL); - - if (*worker_thread == NULL) { - msd_smartcard_manager_worker_free (worker); - return FALSE; - } - - if (worker_fd) { - *worker_fd = read_fd; - } - - return TRUE; -} - -#ifdef MSD_SMARTCARD_MANAGER_ENABLE_TEST -#include - -static GMainLoop *event_loop; -static gboolean should_exit_on_next_remove = FALSE; - -static gboolean -on_timeout (MsdSmartcardManager *manager) -{ - GError *error; - g_print ("Re-enabling manager.\n"); - - if (!msd_smartcard_manager_start (manager, &error)) { - g_warning ("could not start smartcard manager - %s", - error->message); - g_error_free (error); - return 1; - } - g_print ("Please re-insert smartcard\n"); - - should_exit_on_next_remove = TRUE; - - return FALSE; -} - -static void -on_device_inserted (MsdSmartcardManager *manager, - MsdSmartcard *card) -{ - g_print ("smartcard inserted!\n"); - g_print ("Please remove it.\n"); -} - -static void -on_device_removed (MsdSmartcardManager *manager, - MsdSmartcard *card) -{ - g_print ("smartcard removed!\n"); - - if (should_exit_on_next_remove) { - g_main_loop_quit (event_loop); - } else { - g_print ("disabling manager for 2 seconds\n"); - msd_smartcard_manager_stop (manager); - g_timeout_add (2000, (GSourceFunc) on_timeout, manager); - } -} - -int -main (int argc, - char *argv[]) -{ - MsdSmartcardManager *manager; - GError *error; - - g_log_set_always_fatal (G_LOG_LEVEL_ERROR - | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); - - g_type_init (); - - g_message ("creating instance of 'smartcard manager' object..."); - manager = msd_smartcard_manager_new (NULL); - g_message ("'smartcard manager' object created successfully"); - - g_signal_connect (manager, "smartcard-inserted", - G_CALLBACK (on_device_inserted), NULL); - - g_signal_connect (manager, "smartcard-removed", - G_CALLBACK (on_device_removed), NULL); - - g_message ("starting listener..."); - - error = NULL; - if (!msd_smartcard_manager_start (manager, &error)) { - g_warning ("could not start smartcard manager - %s", - error->message); - g_error_free (error); - return 1; - } - - event_loop = g_main_loop_new (NULL, FALSE); - g_main_loop_run (event_loop); - g_main_loop_unref (event_loop); - event_loop = NULL; - - g_message ("destroying previously created 'smartcard manager' object..."); - g_object_unref (manager); - manager = NULL; - g_message ("'smartcard manager' object destroyed successfully"); - - return 0; -} -#endif diff --git a/plugins/smartcard/gsd-smartcard-manager.h b/plugins/smartcard/gsd-smartcard-manager.h deleted file mode 100644 index 269e1da..0000000 --- a/plugins/smartcard/gsd-smartcard-manager.h +++ /dev/null @@ -1,90 +0,0 @@ -/* msd-smartcard-manager.h - object for monitoring smartcard insertion and - * removal events - * - * Copyright (C) 2006, 2009 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * Written by: Ray Strode - */ -#ifndef MSD_SMARTCARD_MANAGER_H -#define MSD_SMARTCARD_MANAGER_H - -#define MSD_SMARTCARD_ENABLE_INTERNAL_API -#include "msd-smartcard.h" - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif -#define MSD_TYPE_SMARTCARD_MANAGER (msd_smartcard_manager_get_type ()) -#define MSD_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManager)) -#define MSD_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManagerClass)) -#define MSD_IS_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_SMARTCARD_MANAGER)) -#define MSD_IS_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SC_TYPE_SMARTCARD_MANAGER)) -#define MSD_SMARTCARD_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManagerClass)) -#define MSD_SMARTCARD_MANAGER_ERROR (msd_smartcard_manager_error_quark ()) -typedef struct _MsdSmartcardManager MsdSmartcardManager; -typedef struct _MsdSmartcardManagerClass MsdSmartcardManagerClass; -typedef struct _MsdSmartcardManagerPrivate MsdSmartcardManagerPrivate; -typedef enum _MsdSmartcardManagerError MsdSmartcardManagerError; - -struct _MsdSmartcardManager { - GObject parent; - - /*< private > */ - MsdSmartcardManagerPrivate *priv; -}; - -struct _MsdSmartcardManagerClass { - GObjectClass parent_class; - - /* Signals */ - void (*smartcard_inserted) (MsdSmartcardManager *manager, - MsdSmartcard *token); - void (*smartcard_removed) (MsdSmartcardManager *manager, - MsdSmartcard *token); - void (*error) (MsdSmartcardManager *manager, - GError *error); -}; - -enum _MsdSmartcardManagerError { - MSD_SMARTCARD_MANAGER_ERROR_GENERIC = 0, - MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, - MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, - MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, - MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS -}; - -GType msd_smartcard_manager_get_type (void) G_GNUC_CONST; -GQuark msd_smartcard_manager_error_quark (void) G_GNUC_CONST; - -MsdSmartcardManager *msd_smartcard_manager_new (const char *module); - -gboolean msd_smartcard_manager_start (MsdSmartcardManager *manager, - GError **error); - -void msd_smartcard_manager_stop (MsdSmartcardManager *manager); - -char *msd_smartcard_manager_get_module_path (MsdSmartcardManager *manager); -gboolean msd_smartcard_manager_login_card_is_inserted (MsdSmartcardManager *manager); - -#ifdef __cplusplus -} -#endif -#endif /* MSD_SMARTCARD_MANAGER_H */ diff --git a/plugins/smartcard/gsd-smartcard-plugin.c b/plugins/smartcard/gsd-smartcard-plugin.c deleted file mode 100644 index dc4cb8f..0000000 --- a/plugins/smartcard/gsd-smartcard-plugin.c +++ /dev/null @@ -1,340 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2010 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include -#include - -#include - -#include - -#include "mate-settings-plugin.h" -#include "msd-smartcard-plugin.h" -#include "msd-smartcard-manager.h" - -struct MsdSmartcardPluginPrivate { - MsdSmartcardManager *manager; - DBusGConnection *bus_connection; - - guint32 is_active : 1; -}; - -typedef enum -{ - MSD_SMARTCARD_REMOVE_ACTION_NONE, - MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN, - MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT, -} MsdSmartcardRemoveAction; - -#define SCREENSAVER_DBUS_NAME "org.mate.ScreenSaver" -#define SCREENSAVER_DBUS_PATH "/" -#define SCREENSAVER_DBUS_INTERFACE "org.mate.ScreenSaver" - -#define SM_DBUS_NAME "org.mate.SessionManager" -#define SM_DBUS_PATH "/org/mate/SessionManager" -#define SM_DBUS_INTERFACE "org.mate.SessionManager" -#define SM_LOGOUT_MODE_FORCE 2 - -#define MSD_SMARTCARD_KEY "/desktop/mate/peripherals/smartcard" -#define KEY_REMOVE_ACTION MSD_SMARTCARD_KEY "/removal_action" - -#define MSD_SMARTCARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdSmartcardPlugin, msd_smartcard_plugin); - -static void -simulate_user_activity (MsdSmartcardPlugin *plugin) -{ - DBusGProxy *screensaver_proxy; - - g_debug ("MsdSmartcardPlugin telling screensaver about smart card insertion"); - screensaver_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, - SCREENSAVER_DBUS_NAME, - SCREENSAVER_DBUS_PATH, - SCREENSAVER_DBUS_INTERFACE); - - dbus_g_proxy_call_no_reply (screensaver_proxy, - "SimulateUserActivity", - G_TYPE_INVALID, G_TYPE_INVALID); - - g_object_unref (screensaver_proxy); -} - -static void -lock_screen (MsdSmartcardPlugin *plugin) -{ - DBusGProxy *screensaver_proxy; - - g_debug ("MsdSmartcardPlugin telling screensaver to lock screen"); - screensaver_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, - SCREENSAVER_DBUS_NAME, - SCREENSAVER_DBUS_PATH, - SCREENSAVER_DBUS_INTERFACE); - - dbus_g_proxy_call_no_reply (screensaver_proxy, - "Lock", - G_TYPE_INVALID, G_TYPE_INVALID); - - g_object_unref (screensaver_proxy); -} - -static void -force_logout (MsdSmartcardPlugin *plugin) -{ - DBusGProxy *sm_proxy; - GError *error; - gboolean res; - - g_debug ("MsdSmartcardPlugin telling session manager to force logout"); - sm_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, - SM_DBUS_NAME, - SM_DBUS_PATH, - SM_DBUS_INTERFACE); - - error = NULL; - res = dbus_g_proxy_call (sm_proxy, - "Logout", - &error, - G_TYPE_UINT, SM_LOGOUT_MODE_FORCE, - G_TYPE_INVALID, G_TYPE_INVALID); - - if (! res) { - g_warning ("MsdSmartcardPlugin Unable to force logout: %s", error->message); - g_error_free (error); - } - - g_object_unref (sm_proxy); -} - -static void -msd_smartcard_plugin_init (MsdSmartcardPlugin *plugin) -{ - plugin->priv = MSD_SMARTCARD_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdSmartcardPlugin initializing"); - - plugin->priv->manager = msd_smartcard_manager_new (NULL); -} - -static void -msd_smartcard_plugin_finalize (GObject *object) -{ - MsdSmartcardPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_SMARTCARD_PLUGIN (object)); - - g_debug ("MsdSmartcardPlugin finalizing"); - - plugin = MSD_SMARTCARD_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_smartcard_plugin_parent_class)->finalize (object); -} - -static void -smartcard_inserted_cb (MsdSmartcardManager *card_monitor, - MsdSmartcard *card, - MsdSmartcardPlugin *plugin) -{ - char *name; - - name = msd_smartcard_get_name (card); - g_debug ("MsdSmartcardPlugin smart card '%s' inserted", name); - g_free (name); - - simulate_user_activity (plugin); -} - -static gboolean -user_logged_in_with_smartcard (void) -{ - return g_getenv ("PKCS11_LOGIN_TOKEN_NAME") != NULL; -} - -static MsdSmartcardRemoveAction -get_configured_remove_action (MsdSmartcardPlugin *plugin) -{ - MateConfClient *client; - char *remove_action_string; - MsdSmartcardRemoveAction remove_action; - - client = mateconf_client_get_default (); - remove_action_string = mateconf_client_get_string (client, - KEY_REMOVE_ACTION, NULL); - - if (remove_action_string == NULL) { - g_warning ("MsdSmartcardPlugin unable to get smartcard remove action"); - remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; - } else if (strcmp (remove_action_string, "none") == 0) { - remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; - } else if (strcmp (remove_action_string, "lock_screen") == 0) { - remove_action = MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN; - } else if (strcmp (remove_action_string, "force_logout") == 0) { - remove_action = MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT; - } else { - g_warning ("MsdSmartcardPlugin unknown smartcard remove action"); - remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; - } - - g_object_unref (client); - - return remove_action; -} - -static void -process_smartcard_removal (MsdSmartcardPlugin *plugin) -{ - MsdSmartcardRemoveAction remove_action; - - g_debug ("MsdSmartcardPlugin processing smartcard removal"); - remove_action = get_configured_remove_action (plugin); - - switch (remove_action) - { - case MSD_SMARTCARD_REMOVE_ACTION_NONE: - return; - case MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN: - lock_screen (plugin); - break; - case MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT: - force_logout (plugin); - break; - } -} - -static void -smartcard_removed_cb (MsdSmartcardManager *card_monitor, - MsdSmartcard *card, - MsdSmartcardPlugin *plugin) -{ - - char *name; - - name = msd_smartcard_get_name (card); - g_debug ("MsdSmartcardPlugin smart card '%s' removed", name); - g_free (name); - - if (!msd_smartcard_is_login_card (card)) { - g_debug ("MsdSmartcardPlugin removed smart card was not used to login"); - return; - } - - process_smartcard_removal (plugin); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - GError *error; - MsdSmartcardPlugin *smartcard_plugin = MSD_SMARTCARD_PLUGIN (plugin); - - if (smartcard_plugin->priv->is_active) { - g_debug ("MsdSmartcardPlugin Not activating smartcard plugin, because it's " - "already active"); - return; - } - - if (!user_logged_in_with_smartcard ()) { - g_debug ("MsdSmartcardPlugin Not activating smartcard plugin, because user didn't use " - " smartcard to log in"); - smartcard_plugin->priv->is_active = FALSE; - return; - } - - g_debug ("MsdSmartcardPlugin Activating smartcard plugin"); - - error = NULL; - smartcard_plugin->priv->bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - - if (smartcard_plugin->priv->bus_connection == NULL) { - g_warning ("MsdSmartcardPlugin Unable to connect to session bus: %s", error->message); - return; - } - - if (!msd_smartcard_manager_start (smartcard_plugin->priv->manager, &error)) { - g_warning ("MsdSmartcardPlugin Unable to start smartcard manager: %s", error->message); - g_error_free (error); - } - - g_signal_connect (smartcard_plugin->priv->manager, - "smartcard-removed", - G_CALLBACK (smartcard_removed_cb), smartcard_plugin); - - g_signal_connect (smartcard_plugin->priv->manager, - "smartcard-inserted", - G_CALLBACK (smartcard_inserted_cb), smartcard_plugin); - - if (!msd_smartcard_manager_login_card_is_inserted (smartcard_plugin->priv->manager)) { - g_debug ("MsdSmartcardPlugin processing smartcard removal immediately user logged in with smartcard " - "and it's not inserted"); - process_smartcard_removal (smartcard_plugin); - } - - smartcard_plugin->priv->is_active = TRUE; -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - MsdSmartcardPlugin *smartcard_plugin = MSD_SMARTCARD_PLUGIN (plugin); - - if (!smartcard_plugin->priv->is_active) { - g_debug ("MsdSmartcardPlugin Not deactivating smartcard plugin, " - "because it's already inactive"); - return; - } - - g_debug ("MsdSmartcardPlugin Deactivating smartcard plugin"); - - msd_smartcard_manager_stop (smartcard_plugin->priv->manager); - - g_signal_handlers_disconnect_by_func (smartcard_plugin->priv->manager, - smartcard_removed_cb, smartcard_plugin); - - g_signal_handlers_disconnect_by_func (smartcard_plugin->priv->manager, - smartcard_inserted_cb, smartcard_plugin); - smartcard_plugin->priv->bus_connection = NULL; - smartcard_plugin->priv->is_active = FALSE; -} - -static void -msd_smartcard_plugin_class_init (MsdSmartcardPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_smartcard_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdSmartcardPluginPrivate)); -} diff --git a/plugins/smartcard/gsd-smartcard-plugin.h b/plugins/smartcard/gsd-smartcard-plugin.h deleted file mode 100644 index 206e58d..0000000 --- a/plugins/smartcard/gsd-smartcard-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2010 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_SMARTCARD_PLUGIN_H__ -#define __MSD_SMARTCARD_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_SMARTCARD_PLUGIN (msd_smartcard_plugin_get_type ()) -#define MSD_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPlugin)) -#define MSD_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginClass)) -#define MSD_IS_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SMARTCARD_PLUGIN)) -#define MSD_IS_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SMARTCARD_PLUGIN)) -#define MSD_SMARTCARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginClass)) - -typedef struct MsdSmartcardPluginPrivate MsdSmartcardPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdSmartcardPluginPrivate *priv; -} MsdSmartcardPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdSmartcardPluginClass; - -GType msd_smartcard_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_SMARTCARD_PLUGIN_H__ */ diff --git a/plugins/smartcard/gsd-smartcard.c b/plugins/smartcard/gsd-smartcard.c deleted file mode 100644 index 9154200..0000000 --- a/plugins/smartcard/gsd-smartcard.c +++ /dev/null @@ -1,555 +0,0 @@ -/* msd-smartcard.c - smartcard object - * - * Copyright (C) 2006 Ray Strode - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ -#define MSD_SMARTCARD_ENABLE_INTERNAL_API -#include "msd-smartcard.h" - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -struct _MsdSmartcardPrivate { - SECMODModule *module; - MsdSmartcardState state; - - CK_SLOT_ID slot_id; - int slot_series; - - PK11SlotInfo *slot; - char *name; - - CERTCertificate *signing_certificate; - CERTCertificate *encryption_certificate; -}; - -static void msd_smartcard_finalize (GObject *object); -static void msd_smartcard_class_install_signals (MsdSmartcardClass *card_class); -static void msd_smartcard_class_install_properties (MsdSmartcardClass *card_class); -static void msd_smartcard_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void msd_smartcard_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void msd_smartcard_set_name (MsdSmartcard *card, const char *name); -static void msd_smartcard_set_slot_id (MsdSmartcard *card, - int slot_id); -static void msd_smartcard_set_slot_series (MsdSmartcard *card, - int slot_series); -static void msd_smartcard_set_module (MsdSmartcard *card, - SECMODModule *module); - -static PK11SlotInfo *msd_smartcard_find_slot_from_id (MsdSmartcard *card, - int slot_id); - -static PK11SlotInfo *msd_smartcard_find_slot_from_card_name (MsdSmartcard *card, - const char *card_name); -#ifndef MSD_SMARTCARD_DEFAULT_SLOT_ID -#define MSD_SMARTCARD_DEFAULT_SLOT_ID ((gulong) -1) -#endif - -#ifndef MSD_SMARTCARD_DEFAULT_SLOT_SERIES -#define MSD_SMARTCARD_DEFAULT_SLOT_SERIES -1 -#endif - -enum { - PROP_0 = 0, - PROP_NAME, - PROP_SLOT_ID, - PROP_SLOT_SERIES, - PROP_MODULE, - NUMBER_OF_PROPERTIES -}; - -enum { - INSERTED, - REMOVED, - NUMBER_OF_SIGNALS -}; - -static guint msd_smartcard_signals[NUMBER_OF_SIGNALS]; - -G_DEFINE_TYPE (MsdSmartcard, msd_smartcard, G_TYPE_OBJECT); - -static void -msd_smartcard_class_init (MsdSmartcardClass *card_class) -{ - GObjectClass *gobject_class; - - gobject_class = G_OBJECT_CLASS (card_class); - - gobject_class->finalize = msd_smartcard_finalize; - - msd_smartcard_class_install_signals (card_class); - msd_smartcard_class_install_properties (card_class); - - g_type_class_add_private (card_class, - sizeof (MsdSmartcardPrivate)); -} - -static void -msd_smartcard_class_install_signals (MsdSmartcardClass *card_class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (card_class); - - msd_smartcard_signals[INSERTED] = - g_signal_new ("inserted", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdSmartcardClass, - inserted), - NULL, NULL, g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - msd_smartcard_signals[REMOVED] = - g_signal_new ("removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MsdSmartcardClass, - removed), - NULL, NULL, g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -msd_smartcard_class_install_properties (MsdSmartcardClass *card_class) -{ - GObjectClass *object_class; - GParamSpec *param_spec; - - object_class = G_OBJECT_CLASS (card_class); - object_class->set_property = msd_smartcard_set_property; - object_class->get_property = msd_smartcard_get_property; - - param_spec = g_param_spec_ulong ("slot-id", _("Slot ID"), - _("The slot the card is in"), - 1, G_MAXULONG, - MSD_SMARTCARD_DEFAULT_SLOT_ID, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, PROP_SLOT_ID, param_spec); - - param_spec = g_param_spec_int ("slot-series", _("Slot Series"), - _("per-slot card identifier"), - -1, G_MAXINT, - MSD_SMARTCARD_DEFAULT_SLOT_SERIES, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, PROP_SLOT_SERIES, param_spec); - - param_spec = g_param_spec_string ("name", _("name"), - _("name"), NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, PROP_NAME, param_spec); - - param_spec = g_param_spec_pointer ("module", _("Module"), - _("smartcard driver"), - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property (object_class, PROP_MODULE, param_spec); -} - -static void -msd_smartcard_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdSmartcard *card = MSD_SMARTCARD (object); - - switch (prop_id) { - case PROP_NAME: - msd_smartcard_set_name (card, g_value_get_string (value)); - break; - - case PROP_SLOT_ID: - msd_smartcard_set_slot_id (card, - g_value_get_ulong (value)); - break; - - case PROP_SLOT_SERIES: - msd_smartcard_set_slot_series (card, - g_value_get_int (value)); - break; - - case PROP_MODULE: - msd_smartcard_set_module (card, - (SECMODModule *) - g_value_get_pointer (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -CK_SLOT_ID -msd_smartcard_get_slot_id (MsdSmartcard *card) -{ - return card->priv->slot_id; -} - -MsdSmartcardState -msd_smartcard_get_state (MsdSmartcard *card) -{ - return card->priv->state; -} - -char * -msd_smartcard_get_name (MsdSmartcard *card) -{ - return g_strdup (card->priv->name); -} - -gboolean -msd_smartcard_is_login_card (MsdSmartcard *card) -{ - const char *login_card_name; - login_card_name = g_getenv ("PKCS11_LOGIN_TOKEN_NAME"); - - if ((login_card_name == NULL) || (card->priv->name == NULL)) { - return FALSE; - } - - if (strcmp (card->priv->name, login_card_name) == 0) { - return TRUE; - } - - return FALSE; -} - -static void -msd_smartcard_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdSmartcard *card = MSD_SMARTCARD (object); - - switch (prop_id) { - case PROP_NAME: - g_value_take_string (value, - msd_smartcard_get_name (card)); - break; - - case PROP_SLOT_ID: - g_value_set_ulong (value, - (gulong) msd_smartcard_get_slot_id (card)); - break; - - case PROP_SLOT_SERIES: - g_value_set_int (value, - msd_smartcard_get_slot_series (card)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -msd_smartcard_set_name (MsdSmartcard *card, - const char *name) -{ - if (name == NULL) { - return; - } - - if ((card->priv->name == NULL) || - (strcmp (card->priv->name, name) != 0)) { - g_free (card->priv->name); - card->priv->name = g_strdup (name); - - if (card->priv->slot == NULL) { - card->priv->slot = msd_smartcard_find_slot_from_card_name (card, - card->priv->name); - - if (card->priv->slot != NULL) { - int slot_id, slot_series; - - slot_id = PK11_GetSlotID (card->priv->slot); - if (slot_id != card->priv->slot_id) { - msd_smartcard_set_slot_id (card, slot_id); - } - - slot_series = PK11_GetSlotSeries (card->priv->slot); - if (slot_series != card->priv->slot_series) { - msd_smartcard_set_slot_series (card, slot_series); - } - - _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); - } else { - _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); - } - } - - g_object_notify (G_OBJECT (card), "name"); - } -} - -static void -msd_smartcard_set_slot_id (MsdSmartcard *card, - int slot_id) -{ - if (card->priv->slot_id != slot_id) { - card->priv->slot_id = slot_id; - - if (card->priv->slot == NULL) { - card->priv->slot = msd_smartcard_find_slot_from_id (card, - card->priv->slot_id); - - if (card->priv->slot != NULL) { - const char *card_name; - - card_name = PK11_GetTokenName (card->priv->slot); - if ((card->priv->name == NULL) || - ((card_name != NULL) && - (strcmp (card_name, card->priv->name) != 0))) { - msd_smartcard_set_name (card, card_name); - } - - _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); - } else { - _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); - } - } - - g_object_notify (G_OBJECT (card), "slot-id"); - } -} - -static void -msd_smartcard_set_slot_series (MsdSmartcard *card, - int slot_series) -{ - if (card->priv->slot_series != slot_series) { - card->priv->slot_series = slot_series; - g_object_notify (G_OBJECT (card), "slot-series"); - } -} - -static void -msd_smartcard_set_module (MsdSmartcard *card, - SECMODModule *module) -{ - gboolean should_notify; - - if (card->priv->module != module) { - should_notify = TRUE; - } else { - should_notify = FALSE; - } - - if (card->priv->module != NULL) { - SECMOD_DestroyModule (card->priv->module); - card->priv->module = NULL; - } - - if (module != NULL) { - card->priv->module = SECMOD_ReferenceModule (module); - } - - if (should_notify) { - g_object_notify (G_OBJECT (card), "module"); - } -} - -int -msd_smartcard_get_slot_series (MsdSmartcard *card) -{ - return card->priv->slot_series; -} - -static void -msd_smartcard_init (MsdSmartcard *card) -{ - - g_debug ("initializing smartcard "); - - card->priv = G_TYPE_INSTANCE_GET_PRIVATE (card, - MSD_TYPE_SMARTCARD, - MsdSmartcardPrivate); - - if (card->priv->slot != NULL) { - card->priv->name = g_strdup (PK11_GetTokenName (card->priv->slot)); - } -} - -static void msd_smartcard_finalize (GObject *object) -{ - MsdSmartcard *card; - GObjectClass *gobject_class; - - card = MSD_SMARTCARD (object); - - g_free (card->priv->name); - - msd_smartcard_set_module (card, NULL); - - gobject_class = G_OBJECT_CLASS (msd_smartcard_parent_class); - - gobject_class->finalize (object); -} - -GQuark msd_smartcard_error_quark (void) -{ - static GQuark error_quark = 0; - - if (error_quark == 0) { - error_quark = g_quark_from_static_string ("msd-smartcard-error-quark"); - } - - return error_quark; -} - -MsdSmartcard * -_msd_smartcard_new (SECMODModule *module, - CK_SLOT_ID slot_id, - int slot_series) -{ - MsdSmartcard *card; - - g_return_val_if_fail (module != NULL, NULL); - g_return_val_if_fail (slot_id >= 1, NULL); - g_return_val_if_fail (slot_series > 0, NULL); - g_return_val_if_fail (sizeof (gulong) == sizeof (slot_id), NULL); - - card = MSD_SMARTCARD (g_object_new (MSD_TYPE_SMARTCARD, - "module", module, - "slot-id", (gulong) slot_id, - "slot-series", slot_series, - NULL)); - return card; -} - -MsdSmartcard * -_msd_smartcard_new_from_name (SECMODModule *module, - const char *name) -{ - MsdSmartcard *card; - - g_return_val_if_fail (module != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - card = MSD_SMARTCARD (g_object_new (MSD_TYPE_SMARTCARD, - "module", module, - "name", name, - NULL)); - return card; -} - -void -_msd_smartcard_set_state (MsdSmartcard *card, - MsdSmartcardState state) -{ - if (card->priv->state != state) { - card->priv->state = state; - - if (state == MSD_SMARTCARD_STATE_INSERTED) { - g_signal_emit (card, msd_smartcard_signals[INSERTED], 0); - } else if (state == MSD_SMARTCARD_STATE_REMOVED) { - g_signal_emit (card, msd_smartcard_signals[REMOVED], 0); - } else { - g_assert_not_reached (); - } - } -} - -/* So we could conceivably make the closure data a pointer to the card - * or something similiar and then emit signals when we want passwords, - * but it's probably easier to just get the password up front and use - * it. So we just take the passed in g_malloc'd (well probably, who knows) - * and strdup it using NSPR's memory allocation routines. - */ -static char * -msd_smartcard_password_handler (PK11SlotInfo *slot, - PRBool is_retrying, - const char *password) -{ - if (is_retrying) { - return NULL; - } - - return password != NULL? PL_strdup (password): NULL; -} - -gboolean -msd_smartcard_unlock (MsdSmartcard *card, - const char *password) -{ - SECStatus status; - - PK11_SetPasswordFunc ((PK11PasswordFunc) msd_smartcard_password_handler); - - /* we pass PR_TRUE to load certificates - */ - status = PK11_Authenticate (card->priv->slot, PR_TRUE, (gpointer) password); - - if (status != SECSuccess) { - g_debug ("could not unlock card - %d", status); - return FALSE; - } - return TRUE; -} - -static PK11SlotInfo * -msd_smartcard_find_slot_from_card_name (MsdSmartcard *card, - const char *card_name) -{ - int i; - - for (i = 0; i < card->priv->module->slotCount; i++) { - const char *slot_card_name; - - slot_card_name = PK11_GetTokenName (card->priv->module->slots[i]); - - if ((slot_card_name != NULL) && - (strcmp (slot_card_name, card_name) == 0)) { - return card->priv->module->slots[i]; - } - } - - return NULL; -} - -static PK11SlotInfo * -msd_smartcard_find_slot_from_id (MsdSmartcard *card, - int slot_id) -{ - int i; - - for (i = 0; i < card->priv->module->slotCount; i++) { - if (PK11_GetSlotID (card->priv->module->slots[i]) == slot_id) { - return card->priv->module->slots[i]; - } - } - - return NULL; -} diff --git a/plugins/smartcard/gsd-smartcard.h b/plugins/smartcard/gsd-smartcard.h deleted file mode 100644 index d00b8af..0000000 --- a/plugins/smartcard/gsd-smartcard.h +++ /dev/null @@ -1,98 +0,0 @@ -/* securitycard.h - api for reading and writing data to a security card - * - * Copyright (C) 2006 Ray Strode - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ -#ifndef MSD_SMARTCARD_H -#define MSD_SMARTCARD_H - -#include -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif -#define MSD_TYPE_SMARTCARD (msd_smartcard_get_type ()) -#define MSD_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_SMARTCARD, MsdSmartcard)) -#define MSD_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_SMARTCARD, MsdSmartcardClass)) -#define MSD_IS_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_SMARTCARD)) -#define MSD_IS_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_SMARTCARD)) -#define MSD_SMARTCARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MSD_TYPE_SMARTCARD, MsdSmartcardClass)) -#define MSD_SMARTCARD_ERROR (msd_smartcard_error_quark ()) -typedef struct _MsdSmartcardClass MsdSmartcardClass; -typedef struct _MsdSmartcard MsdSmartcard; -typedef struct _MsdSmartcardPrivate MsdSmartcardPrivate; -typedef enum _MsdSmartcardError MsdSmartcardError; -typedef enum _MsdSmartcardState MsdSmartcardState; - -typedef struct _MsdSmartcardRequest MsdSmartcardRequest; - -struct _MsdSmartcard { - GObject parent; - - /*< private > */ - MsdSmartcardPrivate *priv; -}; - -struct _MsdSmartcardClass { - GObjectClass parent_class; - - void (* inserted) (MsdSmartcard *card); - void (* removed) (MsdSmartcard *card); -}; - -enum _MsdSmartcardError { - MSD_SMARTCARD_ERROR_GENERIC = 0, -}; - -enum _MsdSmartcardState { - MSD_SMARTCARD_STATE_INSERTED = 0, - MSD_SMARTCARD_STATE_REMOVED, -}; - -GType msd_smartcard_get_type (void) G_GNUC_CONST; -GQuark msd_smartcard_error_quark (void) G_GNUC_CONST; - -CK_SLOT_ID msd_smartcard_get_slot_id (MsdSmartcard *card); -gint msd_smartcard_get_slot_series (MsdSmartcard *card); -MsdSmartcardState msd_smartcard_get_state (MsdSmartcard *card); - -char *msd_smartcard_get_name (MsdSmartcard *card); -gboolean msd_smartcard_is_login_card (MsdSmartcard *card); - -gboolean msd_smartcard_unlock (MsdSmartcard *card, - const char *password); - -/* don't under any circumstances call these functions */ -#ifdef MSD_SMARTCARD_ENABLE_INTERNAL_API - -MsdSmartcard *_msd_smartcard_new (SECMODModule *module, - CK_SLOT_ID slot_id, - gint slot_series); -MsdSmartcard *_msd_smartcard_new_from_name (SECMODModule *module, - const char *name); - -void _msd_smartcard_set_state (MsdSmartcard *card, - MsdSmartcardState state); -#endif - -#ifdef __cplusplus -} -#endif -#endif /* MSD_SMARTCARD_H */ diff --git a/plugins/smartcard/msd-smartcard-manager.c b/plugins/smartcard/msd-smartcard-manager.c new file mode 100644 index 0000000..ed823f4 --- /dev/null +++ b/plugins/smartcard/msd-smartcard-manager.c @@ -0,0 +1,1372 @@ +/* msd-smartcard-manager.c - object for monitoring smartcard insertion and + * removal events + * + * Copyright (C) 2006, 2009 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written By: Ray Strode + */ +#include "config.h" + +#include "msd-smartcard-manager.h" + +#define SMARTCARD_ENABLE_INTERNAL_API +#include "msd-smartcard.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#ifndef MSD_SMARTCARD_MANAGER_NSS_DB +#define MSD_SMARTCARD_MANAGER_NSS_DB SYSCONFDIR"/pki/nssdb" +#endif + +typedef enum _MsdSmartcardManagerState MsdSmartcardManagerState; +typedef struct _MsdSmartcardManagerWorker MsdSmartcardManagerWorker; + +enum _MsdSmartcardManagerState { + MSD_SMARTCARD_MANAGER_STATE_STOPPED = 0, + MSD_SMARTCARD_MANAGER_STATE_STARTING, + MSD_SMARTCARD_MANAGER_STATE_STARTED, + MSD_SMARTCARD_MANAGER_STATE_STOPPING, +}; + +struct _MsdSmartcardManagerPrivate { + MsdSmartcardManagerState state; + SECMODModule *module; + char *module_path; + + GSource *smartcard_event_source; + GPid smartcard_event_watcher_pid; + GHashTable *smartcards; + + GThread *worker_thread; + + guint poll_timeout_id; + + guint32 is_unstoppable : 1; + guint32 nss_is_loaded : 1; +}; + +struct _MsdSmartcardManagerWorker { + SECMODModule *module; + GHashTable *smartcards; + int write_fd; + + guint32 nss_is_loaded : 1; +}; + +static void msd_smartcard_manager_finalize (GObject *object); +static void msd_smartcard_manager_class_install_signals (MsdSmartcardManagerClass *service_class); +static void msd_smartcard_manager_class_install_properties (MsdSmartcardManagerClass *service_class); +static void msd_smartcard_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void msd_smartcard_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void msd_smartcard_manager_set_module_path (MsdSmartcardManager *manager, + const char *module_path); +static void msd_smartcard_manager_card_removed_handler (MsdSmartcardManager *manager, + MsdSmartcard *card); +static void msd_smartcard_manager_card_inserted_handler (MsdSmartcardManager *manager_class, + MsdSmartcard *card); +static gboolean msd_smartcard_manager_stop_now (MsdSmartcardManager *manager); +static void msd_smartcard_manager_queue_stop (MsdSmartcardManager *manager); + +static gboolean msd_smartcard_manager_create_worker (MsdSmartcardManager *manager, + int *worker_fd, GThread **worker_thread); + +static MsdSmartcardManagerWorker * msd_smartcard_manager_worker_new (int write_fd); +static void msd_smartcard_manager_worker_free (MsdSmartcardManagerWorker *worker); +static gboolean open_pipe (int *write_fd, int *read_fd); +static gboolean read_bytes (int fd, gpointer bytes, gsize num_bytes); +static gboolean write_bytes (int fd, gconstpointer bytes, gsize num_bytes); +static MsdSmartcard *read_smartcard (int fd, SECMODModule *module); +static gboolean write_smartcard (int fd, MsdSmartcard *card); + +enum { + PROP_0 = 0, + PROP_MODULE_PATH, + NUMBER_OF_PROPERTIES +}; + +enum { + SMARTCARD_INSERTED = 0, + SMARTCARD_REMOVED, + ERROR, + NUMBER_OF_SIGNALS +}; + +static guint msd_smartcard_manager_signals[NUMBER_OF_SIGNALS]; + +G_DEFINE_TYPE (MsdSmartcardManager, + msd_smartcard_manager, + G_TYPE_OBJECT); + +static void +msd_smartcard_manager_class_init (MsdSmartcardManagerClass *manager_class) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (manager_class); + + gobject_class->finalize = msd_smartcard_manager_finalize; + + msd_smartcard_manager_class_install_signals (manager_class); + msd_smartcard_manager_class_install_properties (manager_class); + + g_type_class_add_private (manager_class, + sizeof (MsdSmartcardManagerPrivate)); +} + +static void +msd_smartcard_manager_class_install_properties (MsdSmartcardManagerClass *card_class) +{ + GObjectClass *object_class; + GParamSpec *param_spec; + + object_class = G_OBJECT_CLASS (card_class); + object_class->set_property = msd_smartcard_manager_set_property; + object_class->get_property = msd_smartcard_manager_get_property; + + param_spec = g_param_spec_string ("module-path", _("Module Path"), + _("path to smartcard PKCS #11 driver"), + NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, PROP_MODULE_PATH, param_spec); +} + +static void +msd_smartcard_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdSmartcardManager *manager = MSD_SMARTCARD_MANAGER (object); + + switch (prop_id) { + case PROP_MODULE_PATH: + msd_smartcard_manager_set_module_path (manager, + g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_smartcard_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdSmartcardManager *manager = MSD_SMARTCARD_MANAGER (object); + char *module_path; + + switch (prop_id) { + case PROP_MODULE_PATH: + module_path = msd_smartcard_manager_get_module_path (manager); + g_value_set_string (value, module_path); + g_free (module_path); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +char * +msd_smartcard_manager_get_module_path (MsdSmartcardManager *manager) +{ + return manager->priv->module_path; +} + +static void +msd_smartcard_manager_set_module_path (MsdSmartcardManager *manager, + const char *module_path) +{ + if ((manager->priv->module_path == NULL) && (module_path == NULL)) { + return; + } + + if (((manager->priv->module_path == NULL) || + (module_path == NULL) || + (strcmp (manager->priv->module_path, module_path) != 0))) { + g_free (manager->priv->module_path); + manager->priv->module_path = g_strdup (module_path); + g_object_notify (G_OBJECT (manager), "module-path"); + } +} + +static void +msd_smartcard_manager_card_removed_handler (MsdSmartcardManager *manager, + MsdSmartcard *card) +{ + g_debug ("informing smartcard of its removal"); + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); + g_debug ("done"); +} + +static void +msd_smartcard_manager_card_inserted_handler (MsdSmartcardManager *manager, + MsdSmartcard *card) +{ + g_debug ("informing smartcard of its insertion"); + + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); + g_debug ("done"); + +} + +static void +msd_smartcard_manager_class_install_signals (MsdSmartcardManagerClass *manager_class) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (manager_class); + + msd_smartcard_manager_signals[SMARTCARD_INSERTED] = + g_signal_new ("smartcard-inserted", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (MsdSmartcardManagerClass, + smartcard_inserted), + NULL, NULL, g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); + manager_class->smartcard_inserted = msd_smartcard_manager_card_inserted_handler; + + msd_smartcard_manager_signals[SMARTCARD_REMOVED] = + g_signal_new ("smartcard-removed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (MsdSmartcardManagerClass, + smartcard_removed), + NULL, NULL, g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); + manager_class->smartcard_removed = msd_smartcard_manager_card_removed_handler; + + msd_smartcard_manager_signals[ERROR] = + g_signal_new ("error", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdSmartcardManagerClass, error), + NULL, NULL, g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); + manager_class->error = NULL; +} + +static gboolean +slot_id_equal (CK_SLOT_ID *slot_id_1, + CK_SLOT_ID *slot_id_2) +{ + g_assert (slot_id_1 != NULL); + g_assert (slot_id_2 != NULL); + + return *slot_id_1 == *slot_id_2; +} + +static gboolean +slot_id_hash (CK_SLOT_ID *slot_id) +{ + guint32 upper_bits, lower_bits; + int temp; + + if (sizeof (CK_SLOT_ID) == sizeof (int)) { + return g_int_hash (slot_id); + } + + upper_bits = ((*slot_id) >> 31) - 1; + lower_bits = (*slot_id) & 0xffffffff; + + /* The upper bits are almost certainly always zero, + * so let's degenerate to g_int_hash for the + * (very) common case + */ + temp = lower_bits + upper_bits; + return upper_bits + g_int_hash (&temp); +} + +static void +msd_smartcard_manager_init (MsdSmartcardManager *manager) +{ + g_debug ("initializing smartcard manager"); + + manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, + MSD_TYPE_SMARTCARD_MANAGER, + MsdSmartcardManagerPrivate); + manager->priv->poll_timeout_id = 0; + manager->priv->is_unstoppable = FALSE; + manager->priv->module = NULL; + + manager->priv->smartcards = + g_hash_table_new_full (g_str_hash, + g_str_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) g_object_unref); + + if (!g_thread_supported ()) { + g_thread_init (NULL); + } + +} + +static void +msd_smartcard_manager_finalize (GObject *object) +{ + MsdSmartcardManager *manager; + GObjectClass *gobject_class; + + manager = MSD_SMARTCARD_MANAGER (object); + gobject_class = + G_OBJECT_CLASS (msd_smartcard_manager_parent_class); + + msd_smartcard_manager_stop_now (manager); + + g_hash_table_destroy (manager->priv->smartcards); + manager->priv->smartcards = NULL; + + gobject_class->finalize (object); +} + +GQuark +msd_smartcard_manager_error_quark (void) +{ + static GQuark error_quark = 0; + + if (error_quark == 0) { + error_quark = g_quark_from_static_string ("msd-smartcard-manager-error-quark"); + } + + return error_quark; +} + +MsdSmartcardManager * +msd_smartcard_manager_new (const char *module_path) +{ + MsdSmartcardManager *instance; + + instance = MSD_SMARTCARD_MANAGER (g_object_new (MSD_TYPE_SMARTCARD_MANAGER, + "module-path", module_path, + NULL)); + + return instance; +} + +static void +msd_smartcard_manager_emit_error (MsdSmartcardManager *manager, + GError *error) +{ + manager->priv->is_unstoppable = TRUE; + g_signal_emit (manager, msd_smartcard_manager_signals[ERROR], 0, + error); + manager->priv->is_unstoppable = FALSE; +} + +static void +msd_smartcard_manager_emit_smartcard_inserted (MsdSmartcardManager *manager, + MsdSmartcard *card) +{ + manager->priv->is_unstoppable = TRUE; + g_signal_emit (manager, msd_smartcard_manager_signals[SMARTCARD_INSERTED], 0, + card); + manager->priv->is_unstoppable = FALSE; +} + +static void +msd_smartcard_manager_emit_smartcard_removed (MsdSmartcardManager *manager, + MsdSmartcard *card) +{ + MsdSmartcardManagerState old_state; + + old_state = manager->priv->state; + manager->priv->is_unstoppable = TRUE; + g_signal_emit (manager, msd_smartcard_manager_signals[SMARTCARD_REMOVED], 0, + card); + manager->priv->is_unstoppable = FALSE; +} + +static gboolean +msd_smartcard_manager_check_for_and_process_events (GIOChannel *io_channel, + GIOCondition condition, + MsdSmartcardManager *manager) +{ + MsdSmartcard *card; + gboolean should_stop; + gchar event_type; + char *card_name; + int fd; + + card = NULL; + should_stop = (condition & G_IO_HUP) || (condition & G_IO_ERR); + + if (should_stop) { + g_debug ("received %s on event socket, stopping " + "manager...", + (condition & G_IO_HUP) && (condition & G_IO_ERR)? + "error and hangup" : + (condition & G_IO_HUP)? + "hangup" : "error"); + } + + if (!(condition & G_IO_IN)) { + goto out; + } + + fd = g_io_channel_unix_get_fd (io_channel); + + event_type = '\0'; + if (!read_bytes (fd, &event_type, 1)) { + should_stop = TRUE; + goto out; + } + + card = read_smartcard (fd, manager->priv->module); + + if (card == NULL) { + should_stop = TRUE; + goto out; + } + + card_name = msd_smartcard_get_name (card); + + switch (event_type) { + case 'I': + g_hash_table_replace (manager->priv->smartcards, + card_name, card); + card_name = NULL; + + msd_smartcard_manager_emit_smartcard_inserted (manager, card); + card = NULL; + break; + + case 'R': + msd_smartcard_manager_emit_smartcard_removed (manager, card); + if (!g_hash_table_remove (manager->priv->smartcards, card_name)) { + g_debug ("got removal event of unknown card!"); + } + g_free (card_name); + card_name = NULL; + card = NULL; + break; + + default: + g_free (card_name); + card_name = NULL; + g_object_unref (card); + + should_stop = TRUE; + break; + } + +out: + if (should_stop) { + GError *error; + + error = g_error_new (MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, + "%s", (condition & G_IO_IN) ? g_strerror (errno) : _("received error or hang up from event source")); + + msd_smartcard_manager_emit_error (manager, error); + g_error_free (error); + msd_smartcard_manager_stop_now (manager); + return FALSE; + } + + return TRUE; +} + +static void +msd_smartcard_manager_event_processing_stopped_handler (MsdSmartcardManager *manager) +{ + manager->priv->smartcard_event_source = NULL; + msd_smartcard_manager_stop_now (manager); +} + +static gboolean +open_pipe (int *write_fd, + int *read_fd) +{ + int pipe_fds[2] = { -1, -1 }; + + g_assert (write_fd != NULL); + g_assert (read_fd != NULL); + + if (pipe (pipe_fds) < 0) { + return FALSE; + } + + if (fcntl (pipe_fds[0], F_SETFD, FD_CLOEXEC) < 0) { + close (pipe_fds[0]); + close (pipe_fds[1]); + return FALSE; + } + + if (fcntl (pipe_fds[1], F_SETFD, FD_CLOEXEC) < 0) { + close (pipe_fds[0]); + close (pipe_fds[1]); + return FALSE; + } + + *read_fd = pipe_fds[0]; + *write_fd = pipe_fds[1]; + + return TRUE; +} + +static void +msd_smartcard_manager_stop_watching_for_events (MsdSmartcardManager *manager) +{ + if (manager->priv->smartcard_event_source != NULL) { + g_source_destroy (manager->priv->smartcard_event_source); + manager->priv->smartcard_event_source = NULL; + } + + if (manager->priv->worker_thread != NULL) { + SECMOD_CancelWait (manager->priv->module); + manager->priv->worker_thread = NULL; + } +} + +static gboolean +load_nss (GError **error) +{ + SECStatus status = SECSuccess; + static const guint32 flags = + NSS_INIT_READONLY | NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | + NSS_INIT_FORCEOPEN | NSS_INIT_NOROOTINIT | + NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD; + + g_debug ("attempting to load NSS database '%s'", + MSD_SMARTCARD_MANAGER_NSS_DB); + + status = NSS_Initialize (MSD_SMARTCARD_MANAGER_NSS_DB, + "", "", SECMOD_DB, flags); + + if (status != SECSuccess) { + gsize error_message_size; + char *error_message; + + error_message_size = PR_GetErrorTextLength (); + + if (error_message_size == 0) { + g_debug ("NSS security system could not be initialized"); + g_set_error (error, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + _("NSS security system could not be initialized")); + goto out; + } + + error_message = g_slice_alloc0 (error_message_size); + PR_GetErrorText (error_message); + + g_set_error (error, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + "%s", error_message); + g_debug ("NSS security system could not be initialized - %s", + error_message); + + g_slice_free1 (error_message_size, error_message); + + goto out; + } + + g_debug ("NSS database sucessfully loaded"); + return TRUE; + +out: + g_debug ("NSS database couldn't be sucessfully loaded"); + return FALSE; +} + +static SECMODModule * +load_driver (char *module_path, + GError **error) +{ + SECMODModule *module; + char *module_spec; + gboolean module_explicitly_specified; + + g_debug ("attempting to load driver..."); + + module = NULL; + module_explicitly_specified = module_path != NULL; + if (module_explicitly_specified) { + module_spec = g_strdup_printf ("library=\"%s\"", module_path); + g_debug ("loading smartcard driver using spec '%s'", + module_spec); + + module = SECMOD_LoadUserModule (module_spec, + NULL /* parent */, + FALSE /* recurse */); + g_free (module_spec); + module_spec = NULL; + + } else { + SECMODModuleList *modules, *tmp; + + modules = SECMOD_GetDefaultModuleList (); + + for (tmp = modules; tmp != NULL; tmp = tmp->next) { + if (!SECMOD_HasRemovableSlots (tmp->module) || + !tmp->module->loaded) + continue; + + module = SECMOD_ReferenceModule (tmp->module); + break; + } + } + + if (!module_explicitly_specified && module == NULL) { + g_set_error (error, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + _("no suitable smartcard driver could be found")); + } else if (module == NULL || !module->loaded) { + + gsize error_message_size; + char *error_message; + + if (module != NULL && !module->loaded) { + g_debug ("module found but not loaded?!"); + SECMOD_DestroyModule (module); + module = NULL; + } + + error_message_size = PR_GetErrorTextLength (); + + if (error_message_size == 0) { + g_debug ("smartcard driver '%s' could not be loaded", + module_path); + g_set_error (error, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + _("smartcard driver '%s' could not be " + "loaded"), module_path); + goto out; + } + + error_message = g_slice_alloc0 (error_message_size); + PR_GetErrorText (error_message); + + g_set_error (error, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + "%s", error_message); + + g_debug ("smartcard driver '%s' could not be loaded - %s", + module_path, error_message); + g_slice_free1 (error_message_size, error_message); + } + +out: + return module; +} + +static void +msd_smartcard_manager_get_all_cards (MsdSmartcardManager *manager) +{ + int i; + + for (i = 0; i < manager->priv->module->slotCount; i++) { + MsdSmartcard *card; + CK_SLOT_ID slot_id; + int slot_series; + char *card_name; + + slot_id = PK11_GetSlotID (manager->priv->module->slots[i]); + slot_series = PK11_GetSlotSeries (manager->priv->module->slots[i]); + + card = _msd_smartcard_new (manager->priv->module, + slot_id, slot_series); + + card_name = msd_smartcard_get_name (card); + + g_hash_table_replace (manager->priv->smartcards, + card_name, card); + } +} + +gboolean +msd_smartcard_manager_start (MsdSmartcardManager *manager, + GError **error) +{ + GError *watching_error; + int worker_fd; + GPid worker_pid; + GIOChannel *io_channel; + GSource *source; + GIOFlags channel_flags; + GError *nss_error; + + if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STARTED) { + g_debug ("smartcard manager already started"); + return TRUE; + } + + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STARTING; + + worker_fd = -1; + worker_pid = 0; + + nss_error = NULL; + if (!manager->priv->nss_is_loaded && !load_nss (&nss_error)) { + g_propagate_error (error, nss_error); + goto out; + } + manager->priv->nss_is_loaded = TRUE; + + if (manager->priv->module == NULL) { + manager->priv->module = load_driver (manager->priv->module_path, &nss_error); + } + + if (manager->priv->module == NULL) { + g_propagate_error (error, nss_error); + goto out; + } + + if (!msd_smartcard_manager_create_worker (manager, &worker_fd, &manager->priv->worker_thread)) { + + g_set_error (error, + MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, + _("could not watch for incoming card events - %s"), + g_strerror (errno)); + + goto out; + } + + io_channel = g_io_channel_unix_new (worker_fd); + + channel_flags = g_io_channel_get_flags (io_channel); + watching_error = NULL; + + source = g_io_create_watch (io_channel, G_IO_IN | G_IO_HUP); + g_io_channel_unref (io_channel); + io_channel = NULL; + + manager->priv->smartcard_event_source = source; + + g_source_set_callback (manager->priv->smartcard_event_source, + (GSourceFunc) (GIOFunc) + msd_smartcard_manager_check_for_and_process_events, + manager, + (GDestroyNotify) + msd_smartcard_manager_event_processing_stopped_handler); + g_source_attach (manager->priv->smartcard_event_source, NULL); + g_source_unref (manager->priv->smartcard_event_source); + + /* populate the hash with cards that are already inserted + */ + msd_smartcard_manager_get_all_cards (manager); + + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STARTED; + +out: + /* don't leave it in a half started state + */ + if (manager->priv->state != MSD_SMARTCARD_MANAGER_STATE_STARTED) { + g_debug ("smartcard manager could not be completely started"); + msd_smartcard_manager_stop (manager); + } else { + g_debug ("smartcard manager started"); + } + + return manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STARTED; +} + +static gboolean +msd_smartcard_manager_stop_now (MsdSmartcardManager *manager) +{ + if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STOPPED) { + return FALSE; + } + + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STOPPED; + msd_smartcard_manager_stop_watching_for_events (manager); + + if (manager->priv->module != NULL) { + SECMOD_DestroyModule (manager->priv->module); + manager->priv->module = NULL; + } + + if (manager->priv->nss_is_loaded) { + NSS_Shutdown (); + manager->priv->nss_is_loaded = FALSE; + } + + g_debug ("smartcard manager stopped"); + + return FALSE; +} + +static void +msd_smartcard_manager_queue_stop (MsdSmartcardManager *manager) +{ + + manager->priv->state = MSD_SMARTCARD_MANAGER_STATE_STOPPING; + + g_idle_add ((GSourceFunc) msd_smartcard_manager_stop_now, manager); +} + +void +msd_smartcard_manager_stop (MsdSmartcardManager *manager) +{ + if (manager->priv->state == MSD_SMARTCARD_MANAGER_STATE_STOPPED) { + return; + } + + if (manager->priv->is_unstoppable) { + msd_smartcard_manager_queue_stop (manager); + return; + } + + msd_smartcard_manager_stop_now (manager); +} + +static void +msd_smartcard_manager_check_for_login_card (CK_SLOT_ID slot_id, + MsdSmartcard *card, + gboolean *is_inserted) +{ + g_assert (is_inserted != NULL); + + if (msd_smartcard_is_login_card (card)) { + *is_inserted = TRUE; + } + +} + +gboolean +msd_smartcard_manager_login_card_is_inserted (MsdSmartcardManager *manager) + +{ + gboolean is_inserted; + + is_inserted = FALSE; + g_hash_table_foreach (manager->priv->smartcards, + (GHFunc) + msd_smartcard_manager_check_for_login_card, + &is_inserted); + return is_inserted; +} + +static MsdSmartcardManagerWorker * +msd_smartcard_manager_worker_new (int write_fd) +{ + MsdSmartcardManagerWorker *worker; + + worker = g_slice_new0 (MsdSmartcardManagerWorker); + worker->write_fd = write_fd; + worker->module = NULL; + + worker->smartcards = + g_hash_table_new_full ((GHashFunc) slot_id_hash, + (GEqualFunc) slot_id_equal, + (GDestroyNotify) g_free, + (GDestroyNotify) g_object_unref); + + return worker; +} + +static void +msd_smartcard_manager_worker_free (MsdSmartcardManagerWorker *worker) +{ + if (worker->smartcards != NULL) { + g_hash_table_destroy (worker->smartcards); + worker->smartcards = NULL; + } + + g_slice_free (MsdSmartcardManagerWorker, worker); +} + +static gboolean +read_bytes (int fd, + gpointer bytes, + gsize num_bytes) +{ + size_t bytes_left; + size_t total_bytes_read; + ssize_t bytes_read; + + bytes_left = (size_t) num_bytes; + total_bytes_read = 0; + + do { + bytes_read = read (fd, + (char *) bytes + total_bytes_read, + bytes_left); + g_assert (bytes_read <= (ssize_t) bytes_left); + + if (bytes_read <= 0) { + if ((bytes_read < 0) && (errno == EINTR || errno == EAGAIN)) { + continue; + } + + bytes_left = 0; + } else { + bytes_left -= bytes_read; + total_bytes_read += bytes_read; + } + } while (bytes_left > 0); + + if (total_bytes_read < (size_t) num_bytes) { + return FALSE; + } + + return TRUE; +} + +static gboolean +write_bytes (int fd, + gconstpointer bytes, + gsize num_bytes) +{ + size_t bytes_left; + size_t total_bytes_written; + ssize_t bytes_written; + + bytes_left = (size_t) num_bytes; + total_bytes_written = 0; + + do { + bytes_written = write (fd, + (char *) bytes + total_bytes_written, + bytes_left); + g_assert (bytes_written <= (ssize_t) bytes_left); + + if (bytes_written <= 0) { + if ((bytes_written < 0) && (errno == EINTR || errno == EAGAIN)) { + continue; + } + + bytes_left = 0; + } else { + bytes_left -= bytes_written; + total_bytes_written += bytes_written; + } + } while (bytes_left > 0); + + if (total_bytes_written < (size_t) num_bytes) { + return FALSE; + } + + return TRUE; +} + +static MsdSmartcard * +read_smartcard (int fd, + SECMODModule *module) +{ + MsdSmartcard *card; + char *card_name; + gsize card_name_size; + + card_name_size = 0; + if (!read_bytes (fd, &card_name_size, sizeof (card_name_size))) { + return NULL; + } + + card_name = g_slice_alloc0 (card_name_size); + if (!read_bytes (fd, card_name, card_name_size)) { + g_slice_free1 (card_name_size, card_name); + return NULL; + } + card = _msd_smartcard_new_from_name (module, card_name); + g_slice_free1 (card_name_size, card_name); + + return card; +} + +static gboolean +write_smartcard (int fd, + MsdSmartcard *card) +{ + gsize card_name_size; + char *card_name; + + card_name = msd_smartcard_get_name (card); + card_name_size = strlen (card_name) + 1; + + if (!write_bytes (fd, &card_name_size, sizeof (card_name_size))) { + g_free (card_name); + return FALSE; + } + + if (!write_bytes (fd, card_name, card_name_size)) { + g_free (card_name); + return FALSE; + } + g_free (card_name); + + return TRUE; +} + +static gboolean +msd_smartcard_manager_worker_emit_smartcard_removed (MsdSmartcardManagerWorker *worker, + MsdSmartcard *card, + GError **error) +{ + g_debug ("card '%s' removed!", msd_smartcard_get_name (card)); + + if (!write_bytes (worker->write_fd, "R", 1)) { + goto error_out; + } + + if (!write_smartcard (worker->write_fd, card)) { + goto error_out; + } + + return TRUE; + +error_out: + g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, + "%s", g_strerror (errno)); + return FALSE; +} + +static gboolean +msd_smartcard_manager_worker_emit_smartcard_inserted (MsdSmartcardManagerWorker *worker, + MsdSmartcard *card, + GError **error) +{ + GError *write_error; + + write_error = NULL; + g_debug ("card '%s' inserted!", msd_smartcard_get_name (card)); + if (!write_bytes (worker->write_fd, "I", 1)) { + goto error_out; + } + + if (!write_smartcard (worker->write_fd, card)) { + goto error_out; + } + + return TRUE; + +error_out: + g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS, + "%s", g_strerror (errno)); + return FALSE; +} + +static gboolean +msd_smartcard_manager_worker_watch_for_and_process_event (MsdSmartcardManagerWorker *worker, + GError **error) +{ + PK11SlotInfo *slot; + CK_SLOT_ID slot_id, *key; + int slot_series, card_slot_series; + MsdSmartcard *card; + GError *processing_error; + gboolean ret; + + g_debug ("waiting for card event"); + ret = FALSE; + + slot = SECMOD_WaitForAnyTokenEvent (worker->module, 0, PR_SecondsToInterval (1)); + processing_error = NULL; + + if (slot == NULL) { + int error_code; + + error_code = PORT_GetError (); + if ((error_code == 0) || (error_code == SEC_ERROR_NO_EVENT)) { + g_debug ("spurrious event occurred"); + return TRUE; + } + + /* FIXME: is there a function to convert from a PORT error + * code to a translated string? + */ + g_set_error (error, MSD_SMARTCARD_MANAGER_ERROR, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + _("encountered unexpected error while " + "waiting for smartcard events")); + goto out; + } + + /* the slot id and series together uniquely identify a card. + * You can never have two cards with the same slot id at the + * same time, however (I think), so we can key off of it. + */ + slot_id = PK11_GetSlotID (slot); + slot_series = PK11_GetSlotSeries (slot); + + /* First check to see if there is a card that we're currently + * tracking in the slot. + */ + key = g_new (CK_SLOT_ID, 1); + *key = slot_id; + card = g_hash_table_lookup (worker->smartcards, key); + + if (card != NULL) { + card_slot_series = msd_smartcard_get_slot_series (card); + } else { + card_slot_series = -1; + } + + if (PK11_IsPresent (slot)) { + /* Now, check to see if their is a new card in the slot. + * If there was a different card in the slot now than + * there was before, then we need to emit a removed signal + * for the old card (we don't want unpaired insertion events). + */ + if ((card != NULL) && + card_slot_series != slot_series) { + if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { + g_propagate_error (error, processing_error); + goto out; + } + } + + card = _msd_smartcard_new (worker->module, + slot_id, slot_series); + + g_hash_table_replace (worker->smartcards, + key, card); + key = NULL; + + if (!msd_smartcard_manager_worker_emit_smartcard_inserted (worker, + card, + &processing_error)) { + g_propagate_error (error, processing_error); + goto out; + } + } else { + /* if we aren't tracking the card, just discard the event. + * We don't want unpaired remove events. Note on startup + * NSS will generate an "insertion" event if a card is + * already inserted in the slot. + */ + if ((card != NULL)) { + /* FIXME: i'm not sure about this code. Maybe we + * shouldn't do this at all, or maybe we should do it + * n times (where n = slot_series - card_slot_series + 1) + * + * Right now, i'm just doing it once. + */ + if ((slot_series - card_slot_series) > 1) { + + if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { + g_propagate_error (error, processing_error); + goto out; + } + g_hash_table_remove (worker->smartcards, key); + + card = _msd_smartcard_new (worker->module, + slot_id, slot_series); + g_hash_table_replace (worker->smartcards, + key, card); + key = NULL; + if (!msd_smartcard_manager_worker_emit_smartcard_inserted (worker, card, &processing_error)) { + g_propagate_error (error, processing_error); + goto out; + } + } + + if (!msd_smartcard_manager_worker_emit_smartcard_removed (worker, card, &processing_error)) { + g_propagate_error (error, processing_error); + goto out; + } + + g_hash_table_remove (worker->smartcards, key); + card = NULL; + } else { + g_debug ("got spurious remove event"); + } + } + + ret = TRUE; + +out: + g_free (key); + PK11_FreeSlot (slot); + + return ret; +} + +static void +msd_smartcard_manager_worker_run (MsdSmartcardManagerWorker *worker) +{ + GError *error; + + + error = NULL; + + while (msd_smartcard_manager_worker_watch_for_and_process_event (worker, &error)); + + if (error != NULL) { + g_debug ("could not process card event - %s", error->message); + g_error_free (error); + } + + msd_smartcard_manager_worker_free (worker); +} + +static gboolean +msd_smartcard_manager_create_worker (MsdSmartcardManager *manager, + int *worker_fd, + GThread **worker_thread) +{ + MsdSmartcardManagerWorker *worker; + int write_fd, read_fd; + + write_fd = -1; + read_fd = -1; + if (!open_pipe (&write_fd, &read_fd)) { + return FALSE; + } + + worker = msd_smartcard_manager_worker_new (write_fd); + worker->module = manager->priv->module; + + *worker_thread = g_thread_create ((GThreadFunc) + msd_smartcard_manager_worker_run, + worker, FALSE, NULL); + + if (*worker_thread == NULL) { + msd_smartcard_manager_worker_free (worker); + return FALSE; + } + + if (worker_fd) { + *worker_fd = read_fd; + } + + return TRUE; +} + +#ifdef MSD_SMARTCARD_MANAGER_ENABLE_TEST +#include + +static GMainLoop *event_loop; +static gboolean should_exit_on_next_remove = FALSE; + +static gboolean +on_timeout (MsdSmartcardManager *manager) +{ + GError *error; + g_print ("Re-enabling manager.\n"); + + if (!msd_smartcard_manager_start (manager, &error)) { + g_warning ("could not start smartcard manager - %s", + error->message); + g_error_free (error); + return 1; + } + g_print ("Please re-insert smartcard\n"); + + should_exit_on_next_remove = TRUE; + + return FALSE; +} + +static void +on_device_inserted (MsdSmartcardManager *manager, + MsdSmartcard *card) +{ + g_print ("smartcard inserted!\n"); + g_print ("Please remove it.\n"); +} + +static void +on_device_removed (MsdSmartcardManager *manager, + MsdSmartcard *card) +{ + g_print ("smartcard removed!\n"); + + if (should_exit_on_next_remove) { + g_main_loop_quit (event_loop); + } else { + g_print ("disabling manager for 2 seconds\n"); + msd_smartcard_manager_stop (manager); + g_timeout_add (2000, (GSourceFunc) on_timeout, manager); + } +} + +int +main (int argc, + char *argv[]) +{ + MsdSmartcardManager *manager; + GError *error; + + g_log_set_always_fatal (G_LOG_LEVEL_ERROR + | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); + + g_type_init (); + + g_message ("creating instance of 'smartcard manager' object..."); + manager = msd_smartcard_manager_new (NULL); + g_message ("'smartcard manager' object created successfully"); + + g_signal_connect (manager, "smartcard-inserted", + G_CALLBACK (on_device_inserted), NULL); + + g_signal_connect (manager, "smartcard-removed", + G_CALLBACK (on_device_removed), NULL); + + g_message ("starting listener..."); + + error = NULL; + if (!msd_smartcard_manager_start (manager, &error)) { + g_warning ("could not start smartcard manager - %s", + error->message); + g_error_free (error); + return 1; + } + + event_loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (event_loop); + g_main_loop_unref (event_loop); + event_loop = NULL; + + g_message ("destroying previously created 'smartcard manager' object..."); + g_object_unref (manager); + manager = NULL; + g_message ("'smartcard manager' object destroyed successfully"); + + return 0; +} +#endif diff --git a/plugins/smartcard/msd-smartcard-manager.h b/plugins/smartcard/msd-smartcard-manager.h new file mode 100644 index 0000000..269e1da --- /dev/null +++ b/plugins/smartcard/msd-smartcard-manager.h @@ -0,0 +1,90 @@ +/* msd-smartcard-manager.h - object for monitoring smartcard insertion and + * removal events + * + * Copyright (C) 2006, 2009 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: Ray Strode + */ +#ifndef MSD_SMARTCARD_MANAGER_H +#define MSD_SMARTCARD_MANAGER_H + +#define MSD_SMARTCARD_ENABLE_INTERNAL_API +#include "msd-smartcard.h" + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +#define MSD_TYPE_SMARTCARD_MANAGER (msd_smartcard_manager_get_type ()) +#define MSD_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManager)) +#define MSD_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManagerClass)) +#define MSD_IS_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SC_TYPE_SMARTCARD_MANAGER)) +#define MSD_IS_SMARTCARD_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SC_TYPE_SMARTCARD_MANAGER)) +#define MSD_SMARTCARD_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MSD_TYPE_SMARTCARD_MANAGER, MsdSmartcardManagerClass)) +#define MSD_SMARTCARD_MANAGER_ERROR (msd_smartcard_manager_error_quark ()) +typedef struct _MsdSmartcardManager MsdSmartcardManager; +typedef struct _MsdSmartcardManagerClass MsdSmartcardManagerClass; +typedef struct _MsdSmartcardManagerPrivate MsdSmartcardManagerPrivate; +typedef enum _MsdSmartcardManagerError MsdSmartcardManagerError; + +struct _MsdSmartcardManager { + GObject parent; + + /*< private > */ + MsdSmartcardManagerPrivate *priv; +}; + +struct _MsdSmartcardManagerClass { + GObjectClass parent_class; + + /* Signals */ + void (*smartcard_inserted) (MsdSmartcardManager *manager, + MsdSmartcard *token); + void (*smartcard_removed) (MsdSmartcardManager *manager, + MsdSmartcard *token); + void (*error) (MsdSmartcardManager *manager, + GError *error); +}; + +enum _MsdSmartcardManagerError { + MSD_SMARTCARD_MANAGER_ERROR_GENERIC = 0, + MSD_SMARTCARD_MANAGER_ERROR_WITH_NSS, + MSD_SMARTCARD_MANAGER_ERROR_LOADING_DRIVER, + MSD_SMARTCARD_MANAGER_ERROR_WATCHING_FOR_EVENTS, + MSD_SMARTCARD_MANAGER_ERROR_REPORTING_EVENTS +}; + +GType msd_smartcard_manager_get_type (void) G_GNUC_CONST; +GQuark msd_smartcard_manager_error_quark (void) G_GNUC_CONST; + +MsdSmartcardManager *msd_smartcard_manager_new (const char *module); + +gboolean msd_smartcard_manager_start (MsdSmartcardManager *manager, + GError **error); + +void msd_smartcard_manager_stop (MsdSmartcardManager *manager); + +char *msd_smartcard_manager_get_module_path (MsdSmartcardManager *manager); +gboolean msd_smartcard_manager_login_card_is_inserted (MsdSmartcardManager *manager); + +#ifdef __cplusplus +} +#endif +#endif /* MSD_SMARTCARD_MANAGER_H */ diff --git a/plugins/smartcard/msd-smartcard-plugin.c b/plugins/smartcard/msd-smartcard-plugin.c new file mode 100644 index 0000000..dc4cb8f --- /dev/null +++ b/plugins/smartcard/msd-smartcard-plugin.c @@ -0,0 +1,340 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2010 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include +#include + +#include + +#include + +#include "mate-settings-plugin.h" +#include "msd-smartcard-plugin.h" +#include "msd-smartcard-manager.h" + +struct MsdSmartcardPluginPrivate { + MsdSmartcardManager *manager; + DBusGConnection *bus_connection; + + guint32 is_active : 1; +}; + +typedef enum +{ + MSD_SMARTCARD_REMOVE_ACTION_NONE, + MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN, + MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT, +} MsdSmartcardRemoveAction; + +#define SCREENSAVER_DBUS_NAME "org.mate.ScreenSaver" +#define SCREENSAVER_DBUS_PATH "/" +#define SCREENSAVER_DBUS_INTERFACE "org.mate.ScreenSaver" + +#define SM_DBUS_NAME "org.mate.SessionManager" +#define SM_DBUS_PATH "/org/mate/SessionManager" +#define SM_DBUS_INTERFACE "org.mate.SessionManager" +#define SM_LOGOUT_MODE_FORCE 2 + +#define MSD_SMARTCARD_KEY "/desktop/mate/peripherals/smartcard" +#define KEY_REMOVE_ACTION MSD_SMARTCARD_KEY "/removal_action" + +#define MSD_SMARTCARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdSmartcardPlugin, msd_smartcard_plugin); + +static void +simulate_user_activity (MsdSmartcardPlugin *plugin) +{ + DBusGProxy *screensaver_proxy; + + g_debug ("MsdSmartcardPlugin telling screensaver about smart card insertion"); + screensaver_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, + SCREENSAVER_DBUS_NAME, + SCREENSAVER_DBUS_PATH, + SCREENSAVER_DBUS_INTERFACE); + + dbus_g_proxy_call_no_reply (screensaver_proxy, + "SimulateUserActivity", + G_TYPE_INVALID, G_TYPE_INVALID); + + g_object_unref (screensaver_proxy); +} + +static void +lock_screen (MsdSmartcardPlugin *plugin) +{ + DBusGProxy *screensaver_proxy; + + g_debug ("MsdSmartcardPlugin telling screensaver to lock screen"); + screensaver_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, + SCREENSAVER_DBUS_NAME, + SCREENSAVER_DBUS_PATH, + SCREENSAVER_DBUS_INTERFACE); + + dbus_g_proxy_call_no_reply (screensaver_proxy, + "Lock", + G_TYPE_INVALID, G_TYPE_INVALID); + + g_object_unref (screensaver_proxy); +} + +static void +force_logout (MsdSmartcardPlugin *plugin) +{ + DBusGProxy *sm_proxy; + GError *error; + gboolean res; + + g_debug ("MsdSmartcardPlugin telling session manager to force logout"); + sm_proxy = dbus_g_proxy_new_for_name (plugin->priv->bus_connection, + SM_DBUS_NAME, + SM_DBUS_PATH, + SM_DBUS_INTERFACE); + + error = NULL; + res = dbus_g_proxy_call (sm_proxy, + "Logout", + &error, + G_TYPE_UINT, SM_LOGOUT_MODE_FORCE, + G_TYPE_INVALID, G_TYPE_INVALID); + + if (! res) { + g_warning ("MsdSmartcardPlugin Unable to force logout: %s", error->message); + g_error_free (error); + } + + g_object_unref (sm_proxy); +} + +static void +msd_smartcard_plugin_init (MsdSmartcardPlugin *plugin) +{ + plugin->priv = MSD_SMARTCARD_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdSmartcardPlugin initializing"); + + plugin->priv->manager = msd_smartcard_manager_new (NULL); +} + +static void +msd_smartcard_plugin_finalize (GObject *object) +{ + MsdSmartcardPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_SMARTCARD_PLUGIN (object)); + + g_debug ("MsdSmartcardPlugin finalizing"); + + plugin = MSD_SMARTCARD_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_smartcard_plugin_parent_class)->finalize (object); +} + +static void +smartcard_inserted_cb (MsdSmartcardManager *card_monitor, + MsdSmartcard *card, + MsdSmartcardPlugin *plugin) +{ + char *name; + + name = msd_smartcard_get_name (card); + g_debug ("MsdSmartcardPlugin smart card '%s' inserted", name); + g_free (name); + + simulate_user_activity (plugin); +} + +static gboolean +user_logged_in_with_smartcard (void) +{ + return g_getenv ("PKCS11_LOGIN_TOKEN_NAME") != NULL; +} + +static MsdSmartcardRemoveAction +get_configured_remove_action (MsdSmartcardPlugin *plugin) +{ + MateConfClient *client; + char *remove_action_string; + MsdSmartcardRemoveAction remove_action; + + client = mateconf_client_get_default (); + remove_action_string = mateconf_client_get_string (client, + KEY_REMOVE_ACTION, NULL); + + if (remove_action_string == NULL) { + g_warning ("MsdSmartcardPlugin unable to get smartcard remove action"); + remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; + } else if (strcmp (remove_action_string, "none") == 0) { + remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; + } else if (strcmp (remove_action_string, "lock_screen") == 0) { + remove_action = MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN; + } else if (strcmp (remove_action_string, "force_logout") == 0) { + remove_action = MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT; + } else { + g_warning ("MsdSmartcardPlugin unknown smartcard remove action"); + remove_action = MSD_SMARTCARD_REMOVE_ACTION_NONE; + } + + g_object_unref (client); + + return remove_action; +} + +static void +process_smartcard_removal (MsdSmartcardPlugin *plugin) +{ + MsdSmartcardRemoveAction remove_action; + + g_debug ("MsdSmartcardPlugin processing smartcard removal"); + remove_action = get_configured_remove_action (plugin); + + switch (remove_action) + { + case MSD_SMARTCARD_REMOVE_ACTION_NONE: + return; + case MSD_SMARTCARD_REMOVE_ACTION_LOCK_SCREEN: + lock_screen (plugin); + break; + case MSD_SMARTCARD_REMOVE_ACTION_FORCE_LOGOUT: + force_logout (plugin); + break; + } +} + +static void +smartcard_removed_cb (MsdSmartcardManager *card_monitor, + MsdSmartcard *card, + MsdSmartcardPlugin *plugin) +{ + + char *name; + + name = msd_smartcard_get_name (card); + g_debug ("MsdSmartcardPlugin smart card '%s' removed", name); + g_free (name); + + if (!msd_smartcard_is_login_card (card)) { + g_debug ("MsdSmartcardPlugin removed smart card was not used to login"); + return; + } + + process_smartcard_removal (plugin); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + GError *error; + MsdSmartcardPlugin *smartcard_plugin = MSD_SMARTCARD_PLUGIN (plugin); + + if (smartcard_plugin->priv->is_active) { + g_debug ("MsdSmartcardPlugin Not activating smartcard plugin, because it's " + "already active"); + return; + } + + if (!user_logged_in_with_smartcard ()) { + g_debug ("MsdSmartcardPlugin Not activating smartcard plugin, because user didn't use " + " smartcard to log in"); + smartcard_plugin->priv->is_active = FALSE; + return; + } + + g_debug ("MsdSmartcardPlugin Activating smartcard plugin"); + + error = NULL; + smartcard_plugin->priv->bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + + if (smartcard_plugin->priv->bus_connection == NULL) { + g_warning ("MsdSmartcardPlugin Unable to connect to session bus: %s", error->message); + return; + } + + if (!msd_smartcard_manager_start (smartcard_plugin->priv->manager, &error)) { + g_warning ("MsdSmartcardPlugin Unable to start smartcard manager: %s", error->message); + g_error_free (error); + } + + g_signal_connect (smartcard_plugin->priv->manager, + "smartcard-removed", + G_CALLBACK (smartcard_removed_cb), smartcard_plugin); + + g_signal_connect (smartcard_plugin->priv->manager, + "smartcard-inserted", + G_CALLBACK (smartcard_inserted_cb), smartcard_plugin); + + if (!msd_smartcard_manager_login_card_is_inserted (smartcard_plugin->priv->manager)) { + g_debug ("MsdSmartcardPlugin processing smartcard removal immediately user logged in with smartcard " + "and it's not inserted"); + process_smartcard_removal (smartcard_plugin); + } + + smartcard_plugin->priv->is_active = TRUE; +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + MsdSmartcardPlugin *smartcard_plugin = MSD_SMARTCARD_PLUGIN (plugin); + + if (!smartcard_plugin->priv->is_active) { + g_debug ("MsdSmartcardPlugin Not deactivating smartcard plugin, " + "because it's already inactive"); + return; + } + + g_debug ("MsdSmartcardPlugin Deactivating smartcard plugin"); + + msd_smartcard_manager_stop (smartcard_plugin->priv->manager); + + g_signal_handlers_disconnect_by_func (smartcard_plugin->priv->manager, + smartcard_removed_cb, smartcard_plugin); + + g_signal_handlers_disconnect_by_func (smartcard_plugin->priv->manager, + smartcard_inserted_cb, smartcard_plugin); + smartcard_plugin->priv->bus_connection = NULL; + smartcard_plugin->priv->is_active = FALSE; +} + +static void +msd_smartcard_plugin_class_init (MsdSmartcardPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_smartcard_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdSmartcardPluginPrivate)); +} diff --git a/plugins/smartcard/msd-smartcard-plugin.h b/plugins/smartcard/msd-smartcard-plugin.h new file mode 100644 index 0000000..206e58d --- /dev/null +++ b/plugins/smartcard/msd-smartcard-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2010 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_SMARTCARD_PLUGIN_H__ +#define __MSD_SMARTCARD_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_SMARTCARD_PLUGIN (msd_smartcard_plugin_get_type ()) +#define MSD_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPlugin)) +#define MSD_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginClass)) +#define MSD_IS_SMARTCARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SMARTCARD_PLUGIN)) +#define MSD_IS_SMARTCARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SMARTCARD_PLUGIN)) +#define MSD_SMARTCARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SMARTCARD_PLUGIN, MsdSmartcardPluginClass)) + +typedef struct MsdSmartcardPluginPrivate MsdSmartcardPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdSmartcardPluginPrivate *priv; +} MsdSmartcardPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdSmartcardPluginClass; + +GType msd_smartcard_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_SMARTCARD_PLUGIN_H__ */ diff --git a/plugins/smartcard/msd-smartcard.c b/plugins/smartcard/msd-smartcard.c new file mode 100644 index 0000000..9154200 --- /dev/null +++ b/plugins/smartcard/msd-smartcard.c @@ -0,0 +1,555 @@ +/* msd-smartcard.c - smartcard object + * + * Copyright (C) 2006 Ray Strode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#define MSD_SMARTCARD_ENABLE_INTERNAL_API +#include "msd-smartcard.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +struct _MsdSmartcardPrivate { + SECMODModule *module; + MsdSmartcardState state; + + CK_SLOT_ID slot_id; + int slot_series; + + PK11SlotInfo *slot; + char *name; + + CERTCertificate *signing_certificate; + CERTCertificate *encryption_certificate; +}; + +static void msd_smartcard_finalize (GObject *object); +static void msd_smartcard_class_install_signals (MsdSmartcardClass *card_class); +static void msd_smartcard_class_install_properties (MsdSmartcardClass *card_class); +static void msd_smartcard_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void msd_smartcard_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void msd_smartcard_set_name (MsdSmartcard *card, const char *name); +static void msd_smartcard_set_slot_id (MsdSmartcard *card, + int slot_id); +static void msd_smartcard_set_slot_series (MsdSmartcard *card, + int slot_series); +static void msd_smartcard_set_module (MsdSmartcard *card, + SECMODModule *module); + +static PK11SlotInfo *msd_smartcard_find_slot_from_id (MsdSmartcard *card, + int slot_id); + +static PK11SlotInfo *msd_smartcard_find_slot_from_card_name (MsdSmartcard *card, + const char *card_name); +#ifndef MSD_SMARTCARD_DEFAULT_SLOT_ID +#define MSD_SMARTCARD_DEFAULT_SLOT_ID ((gulong) -1) +#endif + +#ifndef MSD_SMARTCARD_DEFAULT_SLOT_SERIES +#define MSD_SMARTCARD_DEFAULT_SLOT_SERIES -1 +#endif + +enum { + PROP_0 = 0, + PROP_NAME, + PROP_SLOT_ID, + PROP_SLOT_SERIES, + PROP_MODULE, + NUMBER_OF_PROPERTIES +}; + +enum { + INSERTED, + REMOVED, + NUMBER_OF_SIGNALS +}; + +static guint msd_smartcard_signals[NUMBER_OF_SIGNALS]; + +G_DEFINE_TYPE (MsdSmartcard, msd_smartcard, G_TYPE_OBJECT); + +static void +msd_smartcard_class_init (MsdSmartcardClass *card_class) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (card_class); + + gobject_class->finalize = msd_smartcard_finalize; + + msd_smartcard_class_install_signals (card_class); + msd_smartcard_class_install_properties (card_class); + + g_type_class_add_private (card_class, + sizeof (MsdSmartcardPrivate)); +} + +static void +msd_smartcard_class_install_signals (MsdSmartcardClass *card_class) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (card_class); + + msd_smartcard_signals[INSERTED] = + g_signal_new ("inserted", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdSmartcardClass, + inserted), + NULL, NULL, g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + msd_smartcard_signals[REMOVED] = + g_signal_new ("removed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MsdSmartcardClass, + removed), + NULL, NULL, g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +static void +msd_smartcard_class_install_properties (MsdSmartcardClass *card_class) +{ + GObjectClass *object_class; + GParamSpec *param_spec; + + object_class = G_OBJECT_CLASS (card_class); + object_class->set_property = msd_smartcard_set_property; + object_class->get_property = msd_smartcard_get_property; + + param_spec = g_param_spec_ulong ("slot-id", _("Slot ID"), + _("The slot the card is in"), + 1, G_MAXULONG, + MSD_SMARTCARD_DEFAULT_SLOT_ID, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, PROP_SLOT_ID, param_spec); + + param_spec = g_param_spec_int ("slot-series", _("Slot Series"), + _("per-slot card identifier"), + -1, G_MAXINT, + MSD_SMARTCARD_DEFAULT_SLOT_SERIES, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, PROP_SLOT_SERIES, param_spec); + + param_spec = g_param_spec_string ("name", _("name"), + _("name"), NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, PROP_NAME, param_spec); + + param_spec = g_param_spec_pointer ("module", _("Module"), + _("smartcard driver"), + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, PROP_MODULE, param_spec); +} + +static void +msd_smartcard_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdSmartcard *card = MSD_SMARTCARD (object); + + switch (prop_id) { + case PROP_NAME: + msd_smartcard_set_name (card, g_value_get_string (value)); + break; + + case PROP_SLOT_ID: + msd_smartcard_set_slot_id (card, + g_value_get_ulong (value)); + break; + + case PROP_SLOT_SERIES: + msd_smartcard_set_slot_series (card, + g_value_get_int (value)); + break; + + case PROP_MODULE: + msd_smartcard_set_module (card, + (SECMODModule *) + g_value_get_pointer (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +CK_SLOT_ID +msd_smartcard_get_slot_id (MsdSmartcard *card) +{ + return card->priv->slot_id; +} + +MsdSmartcardState +msd_smartcard_get_state (MsdSmartcard *card) +{ + return card->priv->state; +} + +char * +msd_smartcard_get_name (MsdSmartcard *card) +{ + return g_strdup (card->priv->name); +} + +gboolean +msd_smartcard_is_login_card (MsdSmartcard *card) +{ + const char *login_card_name; + login_card_name = g_getenv ("PKCS11_LOGIN_TOKEN_NAME"); + + if ((login_card_name == NULL) || (card->priv->name == NULL)) { + return FALSE; + } + + if (strcmp (card->priv->name, login_card_name) == 0) { + return TRUE; + } + + return FALSE; +} + +static void +msd_smartcard_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdSmartcard *card = MSD_SMARTCARD (object); + + switch (prop_id) { + case PROP_NAME: + g_value_take_string (value, + msd_smartcard_get_name (card)); + break; + + case PROP_SLOT_ID: + g_value_set_ulong (value, + (gulong) msd_smartcard_get_slot_id (card)); + break; + + case PROP_SLOT_SERIES: + g_value_set_int (value, + msd_smartcard_get_slot_series (card)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +msd_smartcard_set_name (MsdSmartcard *card, + const char *name) +{ + if (name == NULL) { + return; + } + + if ((card->priv->name == NULL) || + (strcmp (card->priv->name, name) != 0)) { + g_free (card->priv->name); + card->priv->name = g_strdup (name); + + if (card->priv->slot == NULL) { + card->priv->slot = msd_smartcard_find_slot_from_card_name (card, + card->priv->name); + + if (card->priv->slot != NULL) { + int slot_id, slot_series; + + slot_id = PK11_GetSlotID (card->priv->slot); + if (slot_id != card->priv->slot_id) { + msd_smartcard_set_slot_id (card, slot_id); + } + + slot_series = PK11_GetSlotSeries (card->priv->slot); + if (slot_series != card->priv->slot_series) { + msd_smartcard_set_slot_series (card, slot_series); + } + + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); + } else { + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); + } + } + + g_object_notify (G_OBJECT (card), "name"); + } +} + +static void +msd_smartcard_set_slot_id (MsdSmartcard *card, + int slot_id) +{ + if (card->priv->slot_id != slot_id) { + card->priv->slot_id = slot_id; + + if (card->priv->slot == NULL) { + card->priv->slot = msd_smartcard_find_slot_from_id (card, + card->priv->slot_id); + + if (card->priv->slot != NULL) { + const char *card_name; + + card_name = PK11_GetTokenName (card->priv->slot); + if ((card->priv->name == NULL) || + ((card_name != NULL) && + (strcmp (card_name, card->priv->name) != 0))) { + msd_smartcard_set_name (card, card_name); + } + + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_INSERTED); + } else { + _msd_smartcard_set_state (card, MSD_SMARTCARD_STATE_REMOVED); + } + } + + g_object_notify (G_OBJECT (card), "slot-id"); + } +} + +static void +msd_smartcard_set_slot_series (MsdSmartcard *card, + int slot_series) +{ + if (card->priv->slot_series != slot_series) { + card->priv->slot_series = slot_series; + g_object_notify (G_OBJECT (card), "slot-series"); + } +} + +static void +msd_smartcard_set_module (MsdSmartcard *card, + SECMODModule *module) +{ + gboolean should_notify; + + if (card->priv->module != module) { + should_notify = TRUE; + } else { + should_notify = FALSE; + } + + if (card->priv->module != NULL) { + SECMOD_DestroyModule (card->priv->module); + card->priv->module = NULL; + } + + if (module != NULL) { + card->priv->module = SECMOD_ReferenceModule (module); + } + + if (should_notify) { + g_object_notify (G_OBJECT (card), "module"); + } +} + +int +msd_smartcard_get_slot_series (MsdSmartcard *card) +{ + return card->priv->slot_series; +} + +static void +msd_smartcard_init (MsdSmartcard *card) +{ + + g_debug ("initializing smartcard "); + + card->priv = G_TYPE_INSTANCE_GET_PRIVATE (card, + MSD_TYPE_SMARTCARD, + MsdSmartcardPrivate); + + if (card->priv->slot != NULL) { + card->priv->name = g_strdup (PK11_GetTokenName (card->priv->slot)); + } +} + +static void msd_smartcard_finalize (GObject *object) +{ + MsdSmartcard *card; + GObjectClass *gobject_class; + + card = MSD_SMARTCARD (object); + + g_free (card->priv->name); + + msd_smartcard_set_module (card, NULL); + + gobject_class = G_OBJECT_CLASS (msd_smartcard_parent_class); + + gobject_class->finalize (object); +} + +GQuark msd_smartcard_error_quark (void) +{ + static GQuark error_quark = 0; + + if (error_quark == 0) { + error_quark = g_quark_from_static_string ("msd-smartcard-error-quark"); + } + + return error_quark; +} + +MsdSmartcard * +_msd_smartcard_new (SECMODModule *module, + CK_SLOT_ID slot_id, + int slot_series) +{ + MsdSmartcard *card; + + g_return_val_if_fail (module != NULL, NULL); + g_return_val_if_fail (slot_id >= 1, NULL); + g_return_val_if_fail (slot_series > 0, NULL); + g_return_val_if_fail (sizeof (gulong) == sizeof (slot_id), NULL); + + card = MSD_SMARTCARD (g_object_new (MSD_TYPE_SMARTCARD, + "module", module, + "slot-id", (gulong) slot_id, + "slot-series", slot_series, + NULL)); + return card; +} + +MsdSmartcard * +_msd_smartcard_new_from_name (SECMODModule *module, + const char *name) +{ + MsdSmartcard *card; + + g_return_val_if_fail (module != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + card = MSD_SMARTCARD (g_object_new (MSD_TYPE_SMARTCARD, + "module", module, + "name", name, + NULL)); + return card; +} + +void +_msd_smartcard_set_state (MsdSmartcard *card, + MsdSmartcardState state) +{ + if (card->priv->state != state) { + card->priv->state = state; + + if (state == MSD_SMARTCARD_STATE_INSERTED) { + g_signal_emit (card, msd_smartcard_signals[INSERTED], 0); + } else if (state == MSD_SMARTCARD_STATE_REMOVED) { + g_signal_emit (card, msd_smartcard_signals[REMOVED], 0); + } else { + g_assert_not_reached (); + } + } +} + +/* So we could conceivably make the closure data a pointer to the card + * or something similiar and then emit signals when we want passwords, + * but it's probably easier to just get the password up front and use + * it. So we just take the passed in g_malloc'd (well probably, who knows) + * and strdup it using NSPR's memory allocation routines. + */ +static char * +msd_smartcard_password_handler (PK11SlotInfo *slot, + PRBool is_retrying, + const char *password) +{ + if (is_retrying) { + return NULL; + } + + return password != NULL? PL_strdup (password): NULL; +} + +gboolean +msd_smartcard_unlock (MsdSmartcard *card, + const char *password) +{ + SECStatus status; + + PK11_SetPasswordFunc ((PK11PasswordFunc) msd_smartcard_password_handler); + + /* we pass PR_TRUE to load certificates + */ + status = PK11_Authenticate (card->priv->slot, PR_TRUE, (gpointer) password); + + if (status != SECSuccess) { + g_debug ("could not unlock card - %d", status); + return FALSE; + } + return TRUE; +} + +static PK11SlotInfo * +msd_smartcard_find_slot_from_card_name (MsdSmartcard *card, + const char *card_name) +{ + int i; + + for (i = 0; i < card->priv->module->slotCount; i++) { + const char *slot_card_name; + + slot_card_name = PK11_GetTokenName (card->priv->module->slots[i]); + + if ((slot_card_name != NULL) && + (strcmp (slot_card_name, card_name) == 0)) { + return card->priv->module->slots[i]; + } + } + + return NULL; +} + +static PK11SlotInfo * +msd_smartcard_find_slot_from_id (MsdSmartcard *card, + int slot_id) +{ + int i; + + for (i = 0; i < card->priv->module->slotCount; i++) { + if (PK11_GetSlotID (card->priv->module->slots[i]) == slot_id) { + return card->priv->module->slots[i]; + } + } + + return NULL; +} diff --git a/plugins/smartcard/msd-smartcard.h b/plugins/smartcard/msd-smartcard.h new file mode 100644 index 0000000..d00b8af --- /dev/null +++ b/plugins/smartcard/msd-smartcard.h @@ -0,0 +1,98 @@ +/* securitycard.h - api for reading and writing data to a security card + * + * Copyright (C) 2006 Ray Strode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef MSD_SMARTCARD_H +#define MSD_SMARTCARD_H + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif +#define MSD_TYPE_SMARTCARD (msd_smartcard_get_type ()) +#define MSD_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_SMARTCARD, MsdSmartcard)) +#define MSD_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_SMARTCARD, MsdSmartcardClass)) +#define MSD_IS_SMARTCARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_SMARTCARD)) +#define MSD_IS_SMARTCARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MSD_TYPE_SMARTCARD)) +#define MSD_SMARTCARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MSD_TYPE_SMARTCARD, MsdSmartcardClass)) +#define MSD_SMARTCARD_ERROR (msd_smartcard_error_quark ()) +typedef struct _MsdSmartcardClass MsdSmartcardClass; +typedef struct _MsdSmartcard MsdSmartcard; +typedef struct _MsdSmartcardPrivate MsdSmartcardPrivate; +typedef enum _MsdSmartcardError MsdSmartcardError; +typedef enum _MsdSmartcardState MsdSmartcardState; + +typedef struct _MsdSmartcardRequest MsdSmartcardRequest; + +struct _MsdSmartcard { + GObject parent; + + /*< private > */ + MsdSmartcardPrivate *priv; +}; + +struct _MsdSmartcardClass { + GObjectClass parent_class; + + void (* inserted) (MsdSmartcard *card); + void (* removed) (MsdSmartcard *card); +}; + +enum _MsdSmartcardError { + MSD_SMARTCARD_ERROR_GENERIC = 0, +}; + +enum _MsdSmartcardState { + MSD_SMARTCARD_STATE_INSERTED = 0, + MSD_SMARTCARD_STATE_REMOVED, +}; + +GType msd_smartcard_get_type (void) G_GNUC_CONST; +GQuark msd_smartcard_error_quark (void) G_GNUC_CONST; + +CK_SLOT_ID msd_smartcard_get_slot_id (MsdSmartcard *card); +gint msd_smartcard_get_slot_series (MsdSmartcard *card); +MsdSmartcardState msd_smartcard_get_state (MsdSmartcard *card); + +char *msd_smartcard_get_name (MsdSmartcard *card); +gboolean msd_smartcard_is_login_card (MsdSmartcard *card); + +gboolean msd_smartcard_unlock (MsdSmartcard *card, + const char *password); + +/* don't under any circumstances call these functions */ +#ifdef MSD_SMARTCARD_ENABLE_INTERNAL_API + +MsdSmartcard *_msd_smartcard_new (SECMODModule *module, + CK_SLOT_ID slot_id, + gint slot_series); +MsdSmartcard *_msd_smartcard_new_from_name (SECMODModule *module, + const char *name); + +void _msd_smartcard_set_state (MsdSmartcard *card, + MsdSmartcardState state); +#endif + +#ifdef __cplusplus +} +#endif +#endif /* MSD_SMARTCARD_H */ diff --git a/plugins/sound/gsd-sound-manager.c b/plugins/sound/gsd-sound-manager.c deleted file mode 100644 index 23fb240..0000000 --- a/plugins/sound/gsd-sound-manager.c +++ /dev/null @@ -1,433 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#ifdef HAVE_PULSE -#include -#endif - -#include "msd-sound-manager.h" -#include "mate-settings-profile.h" - -#define MSD_SOUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerPrivate)) - -struct MsdSoundManagerPrivate -{ - guint mateconf_notify; - GList* monitors; - guint timeout; -}; - -#define MATECONF_SOUND_DIR "/desktop/mate/sound" - -static void msd_sound_manager_class_init (MsdSoundManagerClass *klass); -static void msd_sound_manager_init (MsdSoundManager *sound_manager); -static void msd_sound_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdSoundManager, msd_sound_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -#ifdef HAVE_PULSE - -static void -sample_info_cb (pa_context *c, const pa_sample_info *i, int eol, void *userdata) -{ - pa_operation *o; - - if (!i) - return; - - g_debug ("Found sample %s", i->name); - - /* We only flush those samples which have an XDG sound name - * attached, because only those originate from themeing */ - if (!(pa_proplist_gets (i->proplist, PA_PROP_EVENT_ID))) - return; - - g_debug ("Dropping sample %s from cache", i->name); - - if (!(o = pa_context_remove_sample (c, i->name, NULL, NULL))) { - g_debug ("pa_context_remove_sample (): %s", pa_strerror (pa_context_errno (c))); - return; - } - - pa_operation_unref (o); - - /* We won't wait until the operation is actually executed to - * speed things up a bit.*/ -} - -static void -flush_cache (void) -{ - pa_mainloop *ml = NULL; - pa_context *c = NULL; - pa_proplist *pl = NULL; - pa_operation *o = NULL; - - g_debug ("Flushing sample cache"); - - if (!(ml = pa_mainloop_new ())) { - g_debug ("Failed to allocate pa_mainloop"); - goto fail; - } - - if (!(pl = pa_proplist_new ())) { - g_debug ("Failed to allocate pa_proplist"); - goto fail; - } - - pa_proplist_sets (pl, PA_PROP_APPLICATION_NAME, PACKAGE_NAME); - pa_proplist_sets (pl, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); - pa_proplist_sets (pl, PA_PROP_APPLICATION_ID, "org.mate.SettingsDaemon"); - - if (!(c = pa_context_new_with_proplist (pa_mainloop_get_api (ml), PACKAGE_NAME, pl))) { - g_debug ("Failed to allocate pa_context"); - goto fail; - } - - pa_proplist_free (pl); - pl = NULL; - - if (pa_context_connect (c, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { - g_debug ("pa_context_connect(): %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - /* Wait until the connection is established */ - while (pa_context_get_state (c) != PA_CONTEXT_READY) { - - if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { - g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { - g_debug ("pa_mainloop_iterate() failed"); - goto fail; - } - } - - /* Enumerate all cached samples */ - if (!(o = pa_context_get_sample_info_list (c, sample_info_cb, NULL))) { - g_debug ("pa_context_get_sample_info_list(): %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - /* Wait until our operation is finished and there's nothing - * more queued to send to the server */ - while (pa_operation_get_state (o) == PA_OPERATION_RUNNING || pa_context_is_pending (c)) { - - if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { - g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); - goto fail; - } - - if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { - g_debug ("pa_mainloop_iterate() failed"); - goto fail; - } - } - - g_debug ("Sample cache flushed"); - -fail: - if (o) { - pa_operation_cancel (o); - pa_operation_unref (o); - } - - if (c) { - pa_context_disconnect (c); - pa_context_unref (c); - } - - if (pl) - pa_proplist_free (pl); - - if (ml) - pa_mainloop_free (ml); -} - -static gboolean -flush_cb (MsdSoundManager *manager) -{ - flush_cache (); - manager->priv->timeout = 0; - return FALSE; -} - -static void -trigger_flush (MsdSoundManager *manager) -{ - - if (manager->priv->timeout) - g_source_remove (manager->priv->timeout); - - /* We delay the flushing a bit so that we can coalesce - * multiple changes into a single cache flush */ - manager->priv->timeout = g_timeout_add (500, (GSourceFunc) flush_cb, manager); -} - -static void -mateconf_client_notify_cb (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdSoundManager *manager) -{ - trigger_flush (manager); -} - -static gboolean -register_config_callback (MsdSoundManager *manager, GError **error) -{ - MateConfClient *client; - gboolean succ; - - client = mateconf_client_get_default (); - - mateconf_client_add_dir (client, MATECONF_SOUND_DIR, MATECONF_CLIENT_PRELOAD_NONE, error); - succ = !error || !*error; - - if (!error) { - manager->priv->mateconf_notify = mateconf_client_notify_add (client, MATECONF_SOUND_DIR, (MateConfClientNotifyFunc) mateconf_client_notify_cb, manager, NULL, error); - succ = !error || !*error; - } - - g_object_unref (client); - - return succ; -} - -static void -file_monitor_changed_cb (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event, - MsdSoundManager *manager) -{ - g_debug ("Theme dir changed"); - trigger_flush (manager); -} - -static gboolean -register_directory_callback (MsdSoundManager *manager, - const char *path, - GError **error) -{ - GFile *f; - GFileMonitor *m; - gboolean succ = FALSE; - - g_debug ("Registering directory monitor for %s", path); - - f = g_file_new_for_path (path); - - m = g_file_monitor_directory (f, 0, NULL, error); - - if (m != NULL) { - g_signal_connect (m, "changed", G_CALLBACK (file_monitor_changed_cb), manager); - - manager->priv->monitors = g_list_prepend (manager->priv->monitors, m); - - succ = TRUE; - } - - g_object_unref (f); - - return succ; -} - -#endif - -gboolean -msd_sound_manager_start (MsdSoundManager *manager, - GError **error) -{ - -#ifdef HAVE_PULSE - char *p, **ps, **k; - const char *env, *dd; -#endif - - g_debug ("Starting sound manager"); - mate_settings_profile_start (NULL); - -#ifdef HAVE_PULSE - - /* We listen for change of the selected theme ... */ - register_config_callback (manager, NULL); - - /* ... and we listen to changes of the theme base directories - * in $HOME ...*/ - - if ((env = g_getenv ("XDG_DATA_HOME")) && *env == '/') - p = g_build_filename (env, "sounds", NULL); - else if (((env = g_getenv ("HOME")) && *env == '/') || (env = g_get_home_dir ())) - p = g_build_filename (env, ".local", "share", "sounds", NULL); - else - p = NULL; - - if (p) { - register_directory_callback (manager, p, NULL); - g_free (p); - } - - /* ... and globally. */ - if (!(dd = g_getenv ("XDG_DATA_DIRS")) || *dd == 0) - dd = "/usr/local/share:/usr/share"; - - ps = g_strsplit (dd, ":", 0); - - for (k = ps; *k; ++k) - register_directory_callback (manager, *k, NULL); - - g_strfreev (ps); -#endif - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_sound_manager_stop (MsdSoundManager *manager) -{ - g_debug ("Stopping sound manager"); - -#ifdef HAVE_PULSE - if (manager->priv->mateconf_notify != 0) { - MateConfClient *client = mateconf_client_get_default (); - - mateconf_client_remove_dir (client, MATECONF_SOUND_DIR, NULL); - - mateconf_client_notify_remove (client, manager->priv->mateconf_notify); - manager->priv->mateconf_notify = 0; - - g_object_unref (client); - } - - if (manager->priv->timeout) { - g_source_remove (manager->priv->timeout); - manager->priv->timeout = 0; - } - - while (manager->priv->monitors) { - g_file_monitor_cancel (G_FILE_MONITOR (manager->priv->monitors->data)); - g_object_unref (manager->priv->monitors->data); - manager->priv->monitors = g_list_delete_link (manager->priv->monitors, manager->priv->monitors); - } -#endif -} - -static GObject * -msd_sound_manager_constructor ( - GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdSoundManager *m; - MsdSoundManagerClass *klass; - - klass = MSD_SOUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_SOUND_MANAGER)); - - m = MSD_SOUND_MANAGER (G_OBJECT_CLASS (msd_sound_manager_parent_class)->constructor ( - type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (m); -} - -static void -msd_sound_manager_dispose (GObject *object) -{ - MsdSoundManager *manager; - - manager = MSD_SOUND_MANAGER (object); - - msd_sound_manager_stop (manager); - - G_OBJECT_CLASS (msd_sound_manager_parent_class)->dispose (object); -} - -static void -msd_sound_manager_class_init (MsdSoundManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructor = msd_sound_manager_constructor; - object_class->dispose = msd_sound_manager_dispose; - object_class->finalize = msd_sound_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdSoundManagerPrivate)); -} - -static void -msd_sound_manager_init (MsdSoundManager *manager) -{ - manager->priv = MSD_SOUND_MANAGER_GET_PRIVATE (manager); -} - -static void -msd_sound_manager_finalize (GObject *object) -{ - MsdSoundManager *sound_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_SOUND_MANAGER (object)); - - sound_manager = MSD_SOUND_MANAGER (object); - - g_return_if_fail (sound_manager->priv); - - G_OBJECT_CLASS (msd_sound_manager_parent_class)->finalize (object); -} - -MsdSoundManager * -msd_sound_manager_new (void) -{ - if (manager_object) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_SOUND_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); - } - - return MSD_SOUND_MANAGER (manager_object); -} diff --git a/plugins/sound/gsd-sound-manager.h b/plugins/sound/gsd-sound-manager.h deleted file mode 100644 index ee4f6f5..0000000 --- a/plugins/sound/gsd-sound-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_SOUND_MANAGER_H -#define __MSD_SOUND_MANAGER_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_SOUND_MANAGER (msd_sound_manager_get_type ()) -#define MSD_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManager)) -#define MSD_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) -#define MSD_IS_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_MANAGER)) -#define MSD_IS_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_MANAGER)) -#define MSD_SOUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) - -typedef struct MsdSoundManagerPrivate MsdSoundManagerPrivate; - -typedef struct -{ - GObject parent; - MsdSoundManagerPrivate *priv; -} MsdSoundManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdSoundManagerClass; - -GType msd_sound_manager_get_type (void) G_GNUC_CONST; - -MsdSoundManager *msd_sound_manager_new (void); -gboolean msd_sound_manager_start (MsdSoundManager *manager, GError **error); -void msd_sound_manager_stop (MsdSoundManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_SOUND_MANAGER_H */ diff --git a/plugins/sound/gsd-sound-plugin.c b/plugins/sound/gsd-sound-plugin.c deleted file mode 100644 index 28a2c85..0000000 --- a/plugins/sound/gsd-sound-plugin.c +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-sound-plugin.h" -#include "msd-sound-manager.h" - -struct MsdSoundPluginPrivate { - MsdSoundManager *manager; -}; - -#define MSD_SOUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdSoundPlugin, msd_sound_plugin) - -static void -msd_sound_plugin_init (MsdSoundPlugin *plugin) -{ - plugin->priv = MSD_SOUND_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdSoundPlugin initializing"); - - plugin->priv->manager = msd_sound_manager_new (); -} - -static void -msd_sound_plugin_finalize (GObject *object) -{ - MsdSoundPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_SOUND_PLUGIN (object)); - - g_debug ("MsdSoundPlugin finalizing"); - - plugin = MSD_SOUND_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) - g_object_unref (plugin->priv->manager); - - G_OBJECT_CLASS (msd_sound_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - GError *error = NULL; - - g_debug ("Activating sound plugin"); - - if (!msd_sound_manager_start (MSD_SOUND_PLUGIN (plugin)->priv->manager, &error)) { - g_warning ("Unable to start sound manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating sound plugin"); - msd_sound_manager_stop (MSD_SOUND_PLUGIN (plugin)->priv->manager); -} - -static void -msd_sound_plugin_class_init (MsdSoundPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_sound_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdSoundPluginPrivate)); -} diff --git a/plugins/sound/gsd-sound-plugin.h b/plugins/sound/gsd-sound-plugin.h deleted file mode 100644 index b1dac8a..0000000 --- a/plugins/sound/gsd-sound-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Lennart Poettering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_SOUND_PLUGIN_H__ -#define __MSD_SOUND_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_SOUND_PLUGIN (msd_sound_plugin_get_type ()) -#define MSD_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPlugin)) -#define MSD_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) -#define MSD_IS_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_PLUGIN)) -#define MSD_IS_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_PLUGIN)) -#define MSD_SOUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) - -typedef struct MsdSoundPluginPrivate MsdSoundPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdSoundPluginPrivate *priv; -} MsdSoundPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdSoundPluginClass; - -GType msd_sound_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_SOUND_PLUGIN_H__ */ diff --git a/plugins/sound/msd-sound-manager.c b/plugins/sound/msd-sound-manager.c new file mode 100644 index 0000000..23fb240 --- /dev/null +++ b/plugins/sound/msd-sound-manager.c @@ -0,0 +1,433 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#ifdef HAVE_PULSE +#include +#endif + +#include "msd-sound-manager.h" +#include "mate-settings-profile.h" + +#define MSD_SOUND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerPrivate)) + +struct MsdSoundManagerPrivate +{ + guint mateconf_notify; + GList* monitors; + guint timeout; +}; + +#define MATECONF_SOUND_DIR "/desktop/mate/sound" + +static void msd_sound_manager_class_init (MsdSoundManagerClass *klass); +static void msd_sound_manager_init (MsdSoundManager *sound_manager); +static void msd_sound_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdSoundManager, msd_sound_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +#ifdef HAVE_PULSE + +static void +sample_info_cb (pa_context *c, const pa_sample_info *i, int eol, void *userdata) +{ + pa_operation *o; + + if (!i) + return; + + g_debug ("Found sample %s", i->name); + + /* We only flush those samples which have an XDG sound name + * attached, because only those originate from themeing */ + if (!(pa_proplist_gets (i->proplist, PA_PROP_EVENT_ID))) + return; + + g_debug ("Dropping sample %s from cache", i->name); + + if (!(o = pa_context_remove_sample (c, i->name, NULL, NULL))) { + g_debug ("pa_context_remove_sample (): %s", pa_strerror (pa_context_errno (c))); + return; + } + + pa_operation_unref (o); + + /* We won't wait until the operation is actually executed to + * speed things up a bit.*/ +} + +static void +flush_cache (void) +{ + pa_mainloop *ml = NULL; + pa_context *c = NULL; + pa_proplist *pl = NULL; + pa_operation *o = NULL; + + g_debug ("Flushing sample cache"); + + if (!(ml = pa_mainloop_new ())) { + g_debug ("Failed to allocate pa_mainloop"); + goto fail; + } + + if (!(pl = pa_proplist_new ())) { + g_debug ("Failed to allocate pa_proplist"); + goto fail; + } + + pa_proplist_sets (pl, PA_PROP_APPLICATION_NAME, PACKAGE_NAME); + pa_proplist_sets (pl, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); + pa_proplist_sets (pl, PA_PROP_APPLICATION_ID, "org.mate.SettingsDaemon"); + + if (!(c = pa_context_new_with_proplist (pa_mainloop_get_api (ml), PACKAGE_NAME, pl))) { + g_debug ("Failed to allocate pa_context"); + goto fail; + } + + pa_proplist_free (pl); + pl = NULL; + + if (pa_context_connect (c, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { + g_debug ("pa_context_connect(): %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + /* Wait until the connection is established */ + while (pa_context_get_state (c) != PA_CONTEXT_READY) { + + if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { + g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { + g_debug ("pa_mainloop_iterate() failed"); + goto fail; + } + } + + /* Enumerate all cached samples */ + if (!(o = pa_context_get_sample_info_list (c, sample_info_cb, NULL))) { + g_debug ("pa_context_get_sample_info_list(): %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + /* Wait until our operation is finished and there's nothing + * more queued to send to the server */ + while (pa_operation_get_state (o) == PA_OPERATION_RUNNING || pa_context_is_pending (c)) { + + if (!PA_CONTEXT_IS_GOOD (pa_context_get_state (c))) { + g_debug ("Connection failed: %s", pa_strerror (pa_context_errno (c))); + goto fail; + } + + if (pa_mainloop_iterate (ml, TRUE, NULL) < 0) { + g_debug ("pa_mainloop_iterate() failed"); + goto fail; + } + } + + g_debug ("Sample cache flushed"); + +fail: + if (o) { + pa_operation_cancel (o); + pa_operation_unref (o); + } + + if (c) { + pa_context_disconnect (c); + pa_context_unref (c); + } + + if (pl) + pa_proplist_free (pl); + + if (ml) + pa_mainloop_free (ml); +} + +static gboolean +flush_cb (MsdSoundManager *manager) +{ + flush_cache (); + manager->priv->timeout = 0; + return FALSE; +} + +static void +trigger_flush (MsdSoundManager *manager) +{ + + if (manager->priv->timeout) + g_source_remove (manager->priv->timeout); + + /* We delay the flushing a bit so that we can coalesce + * multiple changes into a single cache flush */ + manager->priv->timeout = g_timeout_add (500, (GSourceFunc) flush_cb, manager); +} + +static void +mateconf_client_notify_cb (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdSoundManager *manager) +{ + trigger_flush (manager); +} + +static gboolean +register_config_callback (MsdSoundManager *manager, GError **error) +{ + MateConfClient *client; + gboolean succ; + + client = mateconf_client_get_default (); + + mateconf_client_add_dir (client, MATECONF_SOUND_DIR, MATECONF_CLIENT_PRELOAD_NONE, error); + succ = !error || !*error; + + if (!error) { + manager->priv->mateconf_notify = mateconf_client_notify_add (client, MATECONF_SOUND_DIR, (MateConfClientNotifyFunc) mateconf_client_notify_cb, manager, NULL, error); + succ = !error || !*error; + } + + g_object_unref (client); + + return succ; +} + +static void +file_monitor_changed_cb (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event, + MsdSoundManager *manager) +{ + g_debug ("Theme dir changed"); + trigger_flush (manager); +} + +static gboolean +register_directory_callback (MsdSoundManager *manager, + const char *path, + GError **error) +{ + GFile *f; + GFileMonitor *m; + gboolean succ = FALSE; + + g_debug ("Registering directory monitor for %s", path); + + f = g_file_new_for_path (path); + + m = g_file_monitor_directory (f, 0, NULL, error); + + if (m != NULL) { + g_signal_connect (m, "changed", G_CALLBACK (file_monitor_changed_cb), manager); + + manager->priv->monitors = g_list_prepend (manager->priv->monitors, m); + + succ = TRUE; + } + + g_object_unref (f); + + return succ; +} + +#endif + +gboolean +msd_sound_manager_start (MsdSoundManager *manager, + GError **error) +{ + +#ifdef HAVE_PULSE + char *p, **ps, **k; + const char *env, *dd; +#endif + + g_debug ("Starting sound manager"); + mate_settings_profile_start (NULL); + +#ifdef HAVE_PULSE + + /* We listen for change of the selected theme ... */ + register_config_callback (manager, NULL); + + /* ... and we listen to changes of the theme base directories + * in $HOME ...*/ + + if ((env = g_getenv ("XDG_DATA_HOME")) && *env == '/') + p = g_build_filename (env, "sounds", NULL); + else if (((env = g_getenv ("HOME")) && *env == '/') || (env = g_get_home_dir ())) + p = g_build_filename (env, ".local", "share", "sounds", NULL); + else + p = NULL; + + if (p) { + register_directory_callback (manager, p, NULL); + g_free (p); + } + + /* ... and globally. */ + if (!(dd = g_getenv ("XDG_DATA_DIRS")) || *dd == 0) + dd = "/usr/local/share:/usr/share"; + + ps = g_strsplit (dd, ":", 0); + + for (k = ps; *k; ++k) + register_directory_callback (manager, *k, NULL); + + g_strfreev (ps); +#endif + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_sound_manager_stop (MsdSoundManager *manager) +{ + g_debug ("Stopping sound manager"); + +#ifdef HAVE_PULSE + if (manager->priv->mateconf_notify != 0) { + MateConfClient *client = mateconf_client_get_default (); + + mateconf_client_remove_dir (client, MATECONF_SOUND_DIR, NULL); + + mateconf_client_notify_remove (client, manager->priv->mateconf_notify); + manager->priv->mateconf_notify = 0; + + g_object_unref (client); + } + + if (manager->priv->timeout) { + g_source_remove (manager->priv->timeout); + manager->priv->timeout = 0; + } + + while (manager->priv->monitors) { + g_file_monitor_cancel (G_FILE_MONITOR (manager->priv->monitors->data)); + g_object_unref (manager->priv->monitors->data); + manager->priv->monitors = g_list_delete_link (manager->priv->monitors, manager->priv->monitors); + } +#endif +} + +static GObject * +msd_sound_manager_constructor ( + GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdSoundManager *m; + MsdSoundManagerClass *klass; + + klass = MSD_SOUND_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_SOUND_MANAGER)); + + m = MSD_SOUND_MANAGER (G_OBJECT_CLASS (msd_sound_manager_parent_class)->constructor ( + type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (m); +} + +static void +msd_sound_manager_dispose (GObject *object) +{ + MsdSoundManager *manager; + + manager = MSD_SOUND_MANAGER (object); + + msd_sound_manager_stop (manager); + + G_OBJECT_CLASS (msd_sound_manager_parent_class)->dispose (object); +} + +static void +msd_sound_manager_class_init (MsdSoundManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructor = msd_sound_manager_constructor; + object_class->dispose = msd_sound_manager_dispose; + object_class->finalize = msd_sound_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdSoundManagerPrivate)); +} + +static void +msd_sound_manager_init (MsdSoundManager *manager) +{ + manager->priv = MSD_SOUND_MANAGER_GET_PRIVATE (manager); +} + +static void +msd_sound_manager_finalize (GObject *object) +{ + MsdSoundManager *sound_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_SOUND_MANAGER (object)); + + sound_manager = MSD_SOUND_MANAGER (object); + + g_return_if_fail (sound_manager->priv); + + G_OBJECT_CLASS (msd_sound_manager_parent_class)->finalize (object); +} + +MsdSoundManager * +msd_sound_manager_new (void) +{ + if (manager_object) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_SOUND_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); + } + + return MSD_SOUND_MANAGER (manager_object); +} diff --git a/plugins/sound/msd-sound-manager.h b/plugins/sound/msd-sound-manager.h new file mode 100644 index 0000000..ee4f6f5 --- /dev/null +++ b/plugins/sound/msd-sound-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_SOUND_MANAGER_H +#define __MSD_SOUND_MANAGER_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_SOUND_MANAGER (msd_sound_manager_get_type ()) +#define MSD_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManager)) +#define MSD_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) +#define MSD_IS_SOUND_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_MANAGER)) +#define MSD_IS_SOUND_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_MANAGER)) +#define MSD_SOUND_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_MANAGER, MsdSoundManagerClass)) + +typedef struct MsdSoundManagerPrivate MsdSoundManagerPrivate; + +typedef struct +{ + GObject parent; + MsdSoundManagerPrivate *priv; +} MsdSoundManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdSoundManagerClass; + +GType msd_sound_manager_get_type (void) G_GNUC_CONST; + +MsdSoundManager *msd_sound_manager_new (void); +gboolean msd_sound_manager_start (MsdSoundManager *manager, GError **error); +void msd_sound_manager_stop (MsdSoundManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_SOUND_MANAGER_H */ diff --git a/plugins/sound/msd-sound-plugin.c b/plugins/sound/msd-sound-plugin.c new file mode 100644 index 0000000..28a2c85 --- /dev/null +++ b/plugins/sound/msd-sound-plugin.c @@ -0,0 +1,100 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-sound-plugin.h" +#include "msd-sound-manager.h" + +struct MsdSoundPluginPrivate { + MsdSoundManager *manager; +}; + +#define MSD_SOUND_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdSoundPlugin, msd_sound_plugin) + +static void +msd_sound_plugin_init (MsdSoundPlugin *plugin) +{ + plugin->priv = MSD_SOUND_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdSoundPlugin initializing"); + + plugin->priv->manager = msd_sound_manager_new (); +} + +static void +msd_sound_plugin_finalize (GObject *object) +{ + MsdSoundPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_SOUND_PLUGIN (object)); + + g_debug ("MsdSoundPlugin finalizing"); + + plugin = MSD_SOUND_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) + g_object_unref (plugin->priv->manager); + + G_OBJECT_CLASS (msd_sound_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + GError *error = NULL; + + g_debug ("Activating sound plugin"); + + if (!msd_sound_manager_start (MSD_SOUND_PLUGIN (plugin)->priv->manager, &error)) { + g_warning ("Unable to start sound manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating sound plugin"); + msd_sound_manager_stop (MSD_SOUND_PLUGIN (plugin)->priv->manager); +} + +static void +msd_sound_plugin_class_init (MsdSoundPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_sound_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdSoundPluginPrivate)); +} diff --git a/plugins/sound/msd-sound-plugin.h b/plugins/sound/msd-sound-plugin.h new file mode 100644 index 0000000..b1dac8a --- /dev/null +++ b/plugins/sound/msd-sound-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Lennart Poettering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_SOUND_PLUGIN_H__ +#define __MSD_SOUND_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_SOUND_PLUGIN (msd_sound_plugin_get_type ()) +#define MSD_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPlugin)) +#define MSD_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) +#define MSD_IS_SOUND_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_SOUND_PLUGIN)) +#define MSD_IS_SOUND_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_SOUND_PLUGIN)) +#define MSD_SOUND_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_SOUND_PLUGIN, MsdSoundPluginClass)) + +typedef struct MsdSoundPluginPrivate MsdSoundPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdSoundPluginPrivate *priv; +} MsdSoundPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdSoundPluginClass; + +GType msd_sound_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_SOUND_PLUGIN_H__ */ diff --git a/plugins/typing-break/gsd-typing-break-manager.c b/plugins/typing-break/gsd-typing-break-manager.c deleted file mode 100644 index 113f6be..0000000 --- a/plugins/typing-break/gsd-typing-break-manager.c +++ /dev/null @@ -1,339 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include "mate-settings-profile.h" -#include "msd-typing-break-manager.h" - -#define MSD_TYPING_BREAK_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerPrivate)) - -#define MATECONF_BREAK_DIR "/desktop/mate/typing_break" - -struct MsdTypingBreakManagerPrivate -{ - GPid typing_monitor_pid; - guint typing_monitor_idle_id; - guint child_watch_id; - guint setup_id; - guint notify; -}; - -static void msd_typing_break_manager_class_init (MsdTypingBreakManagerClass *klass); -static void msd_typing_break_manager_init (MsdTypingBreakManager *typing_break_manager); -static void msd_typing_break_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdTypingBreakManager, msd_typing_break_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -static gboolean -typing_break_timeout (MsdTypingBreakManager *manager) -{ - if (manager->priv->typing_monitor_pid > 0) { - kill (manager->priv->typing_monitor_pid, SIGKILL); - } - - manager->priv->typing_monitor_idle_id = 0; - - return FALSE; -} - -static void -child_watch (GPid pid, - int status, - MsdTypingBreakManager *manager) -{ - if (pid == manager->priv->typing_monitor_pid) { - manager->priv->typing_monitor_pid = 0; - g_spawn_close_pid (pid); - } -} - -static void -setup_typing_break (MsdTypingBreakManager *manager, - gboolean enabled) -{ - mate_settings_profile_start (NULL); - - if (! enabled) { - if (manager->priv->typing_monitor_pid != 0) { - manager->priv->typing_monitor_idle_id = g_timeout_add_seconds (3, (GSourceFunc) typing_break_timeout, manager); - } - return; - } - - if (manager->priv->typing_monitor_idle_id != 0) { - g_source_remove (manager->priv->typing_monitor_idle_id); - manager->priv->typing_monitor_idle_id = 0; - } - - if (manager->priv->typing_monitor_pid == 0) { - GError *error; - char *argv[] = { "mate-typing-monitor", "-n", NULL }; - gboolean res; - - error = NULL; - res = g_spawn_async ("/", - argv, - NULL, - G_SPAWN_STDOUT_TO_DEV_NULL - | G_SPAWN_STDERR_TO_DEV_NULL - | G_SPAWN_SEARCH_PATH - | G_SPAWN_DO_NOT_REAP_CHILD, - NULL, - NULL, - &manager->priv->typing_monitor_pid, - &error); - if (! res) { - /* FIXME: put up a warning */ - g_warning ("failed: %s\n", error->message); - g_error_free (error); - manager->priv->typing_monitor_pid = 0; - return; - } - - manager->priv->child_watch_id = g_child_watch_add (manager->priv->typing_monitor_pid, - (GChildWatchFunc)child_watch, - manager); - } - - mate_settings_profile_end (NULL); -} - -static void -typing_break_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdTypingBreakManager *manager) -{ - if (! strcmp (entry->key, "/desktop/mate/typing_break/enabled")) { - if (entry->value->type == MATECONF_VALUE_BOOL) { - setup_typing_break (manager, mateconf_value_get_bool (entry->value)); - } - } -} - -static gboolean -really_setup_typing_break (MsdTypingBreakManager *manager) -{ - setup_typing_break (manager, TRUE); - manager->priv->setup_id = 0; - return FALSE; -} - -gboolean -msd_typing_break_manager_start (MsdTypingBreakManager *manager, - GError **error) -{ - MateConfClient *client; - gboolean enabled; - - g_debug ("Starting typing_break manager"); - mate_settings_profile_start (NULL); - - client = mateconf_client_get_default (); - - mateconf_client_add_dir (client, MATECONF_BREAK_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - manager->priv->notify = - mateconf_client_notify_add (client, - MATECONF_BREAK_DIR, - (MateConfClientNotifyFunc) typing_break_callback, manager, - NULL, NULL); - - enabled = mateconf_client_get_bool (client, MATECONF_BREAK_DIR "/enabled", NULL); - g_object_unref (client); - if (enabled) { - manager->priv->setup_id = - g_timeout_add_seconds (3, - (GSourceFunc) really_setup_typing_break, - manager); - } - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_typing_break_manager_stop (MsdTypingBreakManager *manager) -{ - MsdTypingBreakManagerPrivate *p = manager->priv; - - g_debug ("Stopping typing_break manager"); - - if (p->setup_id != 0) { - g_source_remove (p->setup_id); - p->setup_id = 0; - } - - if (p->child_watch_id != 0) { - g_source_remove (p->child_watch_id); - p->child_watch_id = 0; - } - - if (p->typing_monitor_idle_id != 0) { - g_source_remove (p->typing_monitor_idle_id); - p->typing_monitor_idle_id = 0; - } - - if (p->typing_monitor_pid > 0) { - kill (p->typing_monitor_pid, SIGKILL); - g_spawn_close_pid (p->typing_monitor_pid); - p->typing_monitor_pid = 0; - } - - if (p->notify != 0) { - MateConfClient *client = mateconf_client_get_default (); - mateconf_client_remove_dir (client, MATECONF_BREAK_DIR, NULL); - mateconf_client_notify_remove (client, p->notify); - g_object_unref (client); - p->notify = 0; - } -} - -static void -msd_typing_break_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdTypingBreakManager *self; - - self = MSD_TYPING_BREAK_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_typing_break_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdTypingBreakManager *self; - - self = MSD_TYPING_BREAK_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_typing_break_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdTypingBreakManager *typing_break_manager; - MsdTypingBreakManagerClass *klass; - - klass = MSD_TYPING_BREAK_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_TYPING_BREAK_MANAGER)); - - typing_break_manager = MSD_TYPING_BREAK_MANAGER (G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (typing_break_manager); -} - -static void -msd_typing_break_manager_dispose (GObject *object) -{ - MsdTypingBreakManager *typing_break_manager; - - typing_break_manager = MSD_TYPING_BREAK_MANAGER (object); - - G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->dispose (object); -} - -static void -msd_typing_break_manager_class_init (MsdTypingBreakManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_typing_break_manager_get_property; - object_class->set_property = msd_typing_break_manager_set_property; - object_class->constructor = msd_typing_break_manager_constructor; - object_class->dispose = msd_typing_break_manager_dispose; - object_class->finalize = msd_typing_break_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdTypingBreakManagerPrivate)); -} - -static void -msd_typing_break_manager_init (MsdTypingBreakManager *manager) -{ - manager->priv = MSD_TYPING_BREAK_MANAGER_GET_PRIVATE (manager); - -} - -static void -msd_typing_break_manager_finalize (GObject *object) -{ - MsdTypingBreakManager *typing_break_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_TYPING_BREAK_MANAGER (object)); - - typing_break_manager = MSD_TYPING_BREAK_MANAGER (object); - - g_return_if_fail (typing_break_manager->priv != NULL); - - G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->finalize (object); -} - -MsdTypingBreakManager * -msd_typing_break_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_TYPING_BREAK_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_TYPING_BREAK_MANAGER (manager_object); -} diff --git a/plugins/typing-break/gsd-typing-break-manager.h b/plugins/typing-break/gsd-typing-break-manager.h deleted file mode 100644 index d490a0e..0000000 --- a/plugins/typing-break/gsd-typing-break-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_TYPING_BREAK_MANAGER_H -#define __MSD_TYPING_BREAK_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_TYPING_BREAK_MANAGER (msd_typing_break_manager_get_type ()) -#define MSD_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManager)) -#define MSD_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerClass)) -#define MSD_IS_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_TYPING_BREAK_MANAGER)) -#define MSD_IS_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_TYPING_BREAK_MANAGER)) -#define MSD_TYPING_BREAK_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerClass)) - -typedef struct MsdTypingBreakManagerPrivate MsdTypingBreakManagerPrivate; - -typedef struct -{ - GObject parent; - MsdTypingBreakManagerPrivate *priv; -} MsdTypingBreakManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdTypingBreakManagerClass; - -GType msd_typing_break_manager_get_type (void); - -MsdTypingBreakManager * msd_typing_break_manager_new (void); -gboolean msd_typing_break_manager_start (MsdTypingBreakManager *manager, - GError **error); -void msd_typing_break_manager_stop (MsdTypingBreakManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_TYPING_BREAK_MANAGER_H */ diff --git a/plugins/typing-break/gsd-typing-break-plugin.c b/plugins/typing-break/gsd-typing-break-plugin.c deleted file mode 100644 index dcf3326..0000000 --- a/plugins/typing-break/gsd-typing-break-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-typing-break-plugin.h" -#include "msd-typing-break-manager.h" - -struct MsdTypingBreakPluginPrivate { - MsdTypingBreakManager *manager; -}; - -#define MSD_TYPING_BREAK_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdTypingBreakPlugin, msd_typing_break_plugin) - -static void -msd_typing_break_plugin_init (MsdTypingBreakPlugin *plugin) -{ - plugin->priv = MSD_TYPING_BREAK_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdTypingBreakPlugin initializing"); - - plugin->priv->manager = msd_typing_break_manager_new (); -} - -static void -msd_typing_break_plugin_finalize (GObject *object) -{ - MsdTypingBreakPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_TYPING_BREAK_PLUGIN (object)); - - g_debug ("MsdTypingBreakPlugin finalizing"); - - plugin = MSD_TYPING_BREAK_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_typing_break_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating typing_break plugin"); - - error = NULL; - res = msd_typing_break_manager_start (MSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start typing_break manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating typing_break plugin"); - msd_typing_break_manager_stop (MSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager); -} - -static void -msd_typing_break_plugin_class_init (MsdTypingBreakPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_typing_break_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdTypingBreakPluginPrivate)); -} diff --git a/plugins/typing-break/gsd-typing-break-plugin.h b/plugins/typing-break/gsd-typing-break-plugin.h deleted file mode 100644 index 54bde6e..0000000 --- a/plugins/typing-break/gsd-typing-break-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_TYPING_BREAK_PLUGIN_H__ -#define __MSD_TYPING_BREAK_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_TYPING_BREAK_PLUGIN (msd_typing_break_plugin_get_type ()) -#define MSD_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPlugin)) -#define MSD_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginClass)) -#define MSD_IS_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_TYPING_BREAK_PLUGIN)) -#define MSD_IS_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_TYPING_BREAK_PLUGIN)) -#define MSD_TYPING_BREAK_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginClass)) - -typedef struct MsdTypingBreakPluginPrivate MsdTypingBreakPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdTypingBreakPluginPrivate *priv; -} MsdTypingBreakPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdTypingBreakPluginClass; - -GType msd_typing_break_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_TYPING_BREAK_PLUGIN_H__ */ diff --git a/plugins/typing-break/msd-typing-break-manager.c b/plugins/typing-break/msd-typing-break-manager.c new file mode 100644 index 0000000..113f6be --- /dev/null +++ b/plugins/typing-break/msd-typing-break-manager.c @@ -0,0 +1,339 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "mate-settings-profile.h" +#include "msd-typing-break-manager.h" + +#define MSD_TYPING_BREAK_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerPrivate)) + +#define MATECONF_BREAK_DIR "/desktop/mate/typing_break" + +struct MsdTypingBreakManagerPrivate +{ + GPid typing_monitor_pid; + guint typing_monitor_idle_id; + guint child_watch_id; + guint setup_id; + guint notify; +}; + +static void msd_typing_break_manager_class_init (MsdTypingBreakManagerClass *klass); +static void msd_typing_break_manager_init (MsdTypingBreakManager *typing_break_manager); +static void msd_typing_break_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdTypingBreakManager, msd_typing_break_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +static gboolean +typing_break_timeout (MsdTypingBreakManager *manager) +{ + if (manager->priv->typing_monitor_pid > 0) { + kill (manager->priv->typing_monitor_pid, SIGKILL); + } + + manager->priv->typing_monitor_idle_id = 0; + + return FALSE; +} + +static void +child_watch (GPid pid, + int status, + MsdTypingBreakManager *manager) +{ + if (pid == manager->priv->typing_monitor_pid) { + manager->priv->typing_monitor_pid = 0; + g_spawn_close_pid (pid); + } +} + +static void +setup_typing_break (MsdTypingBreakManager *manager, + gboolean enabled) +{ + mate_settings_profile_start (NULL); + + if (! enabled) { + if (manager->priv->typing_monitor_pid != 0) { + manager->priv->typing_monitor_idle_id = g_timeout_add_seconds (3, (GSourceFunc) typing_break_timeout, manager); + } + return; + } + + if (manager->priv->typing_monitor_idle_id != 0) { + g_source_remove (manager->priv->typing_monitor_idle_id); + manager->priv->typing_monitor_idle_id = 0; + } + + if (manager->priv->typing_monitor_pid == 0) { + GError *error; + char *argv[] = { "mate-typing-monitor", "-n", NULL }; + gboolean res; + + error = NULL; + res = g_spawn_async ("/", + argv, + NULL, + G_SPAWN_STDOUT_TO_DEV_NULL + | G_SPAWN_STDERR_TO_DEV_NULL + | G_SPAWN_SEARCH_PATH + | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, + NULL, + &manager->priv->typing_monitor_pid, + &error); + if (! res) { + /* FIXME: put up a warning */ + g_warning ("failed: %s\n", error->message); + g_error_free (error); + manager->priv->typing_monitor_pid = 0; + return; + } + + manager->priv->child_watch_id = g_child_watch_add (manager->priv->typing_monitor_pid, + (GChildWatchFunc)child_watch, + manager); + } + + mate_settings_profile_end (NULL); +} + +static void +typing_break_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdTypingBreakManager *manager) +{ + if (! strcmp (entry->key, "/desktop/mate/typing_break/enabled")) { + if (entry->value->type == MATECONF_VALUE_BOOL) { + setup_typing_break (manager, mateconf_value_get_bool (entry->value)); + } + } +} + +static gboolean +really_setup_typing_break (MsdTypingBreakManager *manager) +{ + setup_typing_break (manager, TRUE); + manager->priv->setup_id = 0; + return FALSE; +} + +gboolean +msd_typing_break_manager_start (MsdTypingBreakManager *manager, + GError **error) +{ + MateConfClient *client; + gboolean enabled; + + g_debug ("Starting typing_break manager"); + mate_settings_profile_start (NULL); + + client = mateconf_client_get_default (); + + mateconf_client_add_dir (client, MATECONF_BREAK_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + manager->priv->notify = + mateconf_client_notify_add (client, + MATECONF_BREAK_DIR, + (MateConfClientNotifyFunc) typing_break_callback, manager, + NULL, NULL); + + enabled = mateconf_client_get_bool (client, MATECONF_BREAK_DIR "/enabled", NULL); + g_object_unref (client); + if (enabled) { + manager->priv->setup_id = + g_timeout_add_seconds (3, + (GSourceFunc) really_setup_typing_break, + manager); + } + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_typing_break_manager_stop (MsdTypingBreakManager *manager) +{ + MsdTypingBreakManagerPrivate *p = manager->priv; + + g_debug ("Stopping typing_break manager"); + + if (p->setup_id != 0) { + g_source_remove (p->setup_id); + p->setup_id = 0; + } + + if (p->child_watch_id != 0) { + g_source_remove (p->child_watch_id); + p->child_watch_id = 0; + } + + if (p->typing_monitor_idle_id != 0) { + g_source_remove (p->typing_monitor_idle_id); + p->typing_monitor_idle_id = 0; + } + + if (p->typing_monitor_pid > 0) { + kill (p->typing_monitor_pid, SIGKILL); + g_spawn_close_pid (p->typing_monitor_pid); + p->typing_monitor_pid = 0; + } + + if (p->notify != 0) { + MateConfClient *client = mateconf_client_get_default (); + mateconf_client_remove_dir (client, MATECONF_BREAK_DIR, NULL); + mateconf_client_notify_remove (client, p->notify); + g_object_unref (client); + p->notify = 0; + } +} + +static void +msd_typing_break_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdTypingBreakManager *self; + + self = MSD_TYPING_BREAK_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_typing_break_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdTypingBreakManager *self; + + self = MSD_TYPING_BREAK_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_typing_break_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdTypingBreakManager *typing_break_manager; + MsdTypingBreakManagerClass *klass; + + klass = MSD_TYPING_BREAK_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_TYPING_BREAK_MANAGER)); + + typing_break_manager = MSD_TYPING_BREAK_MANAGER (G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (typing_break_manager); +} + +static void +msd_typing_break_manager_dispose (GObject *object) +{ + MsdTypingBreakManager *typing_break_manager; + + typing_break_manager = MSD_TYPING_BREAK_MANAGER (object); + + G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->dispose (object); +} + +static void +msd_typing_break_manager_class_init (MsdTypingBreakManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_typing_break_manager_get_property; + object_class->set_property = msd_typing_break_manager_set_property; + object_class->constructor = msd_typing_break_manager_constructor; + object_class->dispose = msd_typing_break_manager_dispose; + object_class->finalize = msd_typing_break_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdTypingBreakManagerPrivate)); +} + +static void +msd_typing_break_manager_init (MsdTypingBreakManager *manager) +{ + manager->priv = MSD_TYPING_BREAK_MANAGER_GET_PRIVATE (manager); + +} + +static void +msd_typing_break_manager_finalize (GObject *object) +{ + MsdTypingBreakManager *typing_break_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_TYPING_BREAK_MANAGER (object)); + + typing_break_manager = MSD_TYPING_BREAK_MANAGER (object); + + g_return_if_fail (typing_break_manager->priv != NULL); + + G_OBJECT_CLASS (msd_typing_break_manager_parent_class)->finalize (object); +} + +MsdTypingBreakManager * +msd_typing_break_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_TYPING_BREAK_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_TYPING_BREAK_MANAGER (manager_object); +} diff --git a/plugins/typing-break/msd-typing-break-manager.h b/plugins/typing-break/msd-typing-break-manager.h new file mode 100644 index 0000000..d490a0e --- /dev/null +++ b/plugins/typing-break/msd-typing-break-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_TYPING_BREAK_MANAGER_H +#define __MSD_TYPING_BREAK_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_TYPING_BREAK_MANAGER (msd_typing_break_manager_get_type ()) +#define MSD_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManager)) +#define MSD_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerClass)) +#define MSD_IS_TYPING_BREAK_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_TYPING_BREAK_MANAGER)) +#define MSD_IS_TYPING_BREAK_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_TYPING_BREAK_MANAGER)) +#define MSD_TYPING_BREAK_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_TYPING_BREAK_MANAGER, MsdTypingBreakManagerClass)) + +typedef struct MsdTypingBreakManagerPrivate MsdTypingBreakManagerPrivate; + +typedef struct +{ + GObject parent; + MsdTypingBreakManagerPrivate *priv; +} MsdTypingBreakManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdTypingBreakManagerClass; + +GType msd_typing_break_manager_get_type (void); + +MsdTypingBreakManager * msd_typing_break_manager_new (void); +gboolean msd_typing_break_manager_start (MsdTypingBreakManager *manager, + GError **error); +void msd_typing_break_manager_stop (MsdTypingBreakManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_TYPING_BREAK_MANAGER_H */ diff --git a/plugins/typing-break/msd-typing-break-plugin.c b/plugins/typing-break/msd-typing-break-plugin.c new file mode 100644 index 0000000..dcf3326 --- /dev/null +++ b/plugins/typing-break/msd-typing-break-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-typing-break-plugin.h" +#include "msd-typing-break-manager.h" + +struct MsdTypingBreakPluginPrivate { + MsdTypingBreakManager *manager; +}; + +#define MSD_TYPING_BREAK_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdTypingBreakPlugin, msd_typing_break_plugin) + +static void +msd_typing_break_plugin_init (MsdTypingBreakPlugin *plugin) +{ + plugin->priv = MSD_TYPING_BREAK_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdTypingBreakPlugin initializing"); + + plugin->priv->manager = msd_typing_break_manager_new (); +} + +static void +msd_typing_break_plugin_finalize (GObject *object) +{ + MsdTypingBreakPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_TYPING_BREAK_PLUGIN (object)); + + g_debug ("MsdTypingBreakPlugin finalizing"); + + plugin = MSD_TYPING_BREAK_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_typing_break_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating typing_break plugin"); + + error = NULL; + res = msd_typing_break_manager_start (MSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start typing_break manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating typing_break plugin"); + msd_typing_break_manager_stop (MSD_TYPING_BREAK_PLUGIN (plugin)->priv->manager); +} + +static void +msd_typing_break_plugin_class_init (MsdTypingBreakPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_typing_break_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdTypingBreakPluginPrivate)); +} diff --git a/plugins/typing-break/msd-typing-break-plugin.h b/plugins/typing-break/msd-typing-break-plugin.h new file mode 100644 index 0000000..54bde6e --- /dev/null +++ b/plugins/typing-break/msd-typing-break-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_TYPING_BREAK_PLUGIN_H__ +#define __MSD_TYPING_BREAK_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_TYPING_BREAK_PLUGIN (msd_typing_break_plugin_get_type ()) +#define MSD_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPlugin)) +#define MSD_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginClass)) +#define MSD_IS_TYPING_BREAK_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_TYPING_BREAK_PLUGIN)) +#define MSD_IS_TYPING_BREAK_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_TYPING_BREAK_PLUGIN)) +#define MSD_TYPING_BREAK_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_TYPING_BREAK_PLUGIN, MsdTypingBreakPluginClass)) + +typedef struct MsdTypingBreakPluginPrivate MsdTypingBreakPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdTypingBreakPluginPrivate *priv; +} MsdTypingBreakPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdTypingBreakPluginClass; + +GType msd_typing_break_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_TYPING_BREAK_PLUGIN_H__ */ diff --git a/plugins/xrandr/gsd-xrandr-16.png b/plugins/xrandr/gsd-xrandr-16.png deleted file mode 100644 index f996ddf..0000000 Binary files a/plugins/xrandr/gsd-xrandr-16.png and /dev/null differ diff --git a/plugins/xrandr/gsd-xrandr-22.png b/plugins/xrandr/gsd-xrandr-22.png deleted file mode 100644 index cc47eec..0000000 Binary files a/plugins/xrandr/gsd-xrandr-22.png and /dev/null differ diff --git a/plugins/xrandr/gsd-xrandr-24.png b/plugins/xrandr/gsd-xrandr-24.png deleted file mode 100644 index 49b4e12..0000000 Binary files a/plugins/xrandr/gsd-xrandr-24.png and /dev/null differ diff --git a/plugins/xrandr/gsd-xrandr-32.png b/plugins/xrandr/gsd-xrandr-32.png deleted file mode 100644 index 95de3ea..0000000 Binary files a/plugins/xrandr/gsd-xrandr-32.png and /dev/null differ diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c deleted file mode 100644 index dc00be1..0000000 --- a/plugins/xrandr/gsd-xrandr-manager.c +++ /dev/null @@ -1,2584 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * Copyright (C) 2007, 2008 Red Hat, Inc - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#define MATE_DESKTOP_USE_UNSTABLE_API - -#include -#include -#include - -#ifdef HAVE_LIBMATENOTIFY -#include -#endif - -#include "mate-settings-profile.h" -#include "msd-xrandr-manager.h" - -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 255 -#endif - -#define MSD_XRANDR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerPrivate)) - -#define CONF_DIR "/apps/mate_settings_daemon/xrandr" -#define CONF_KEY_SHOW_NOTIFICATION_ICON (CONF_DIR "/show_notification_icon") -#define CONF_KEY_TURN_ON_EXTERNAL_MONITORS_AT_STARTUP (CONF_DIR "/turn_on_external_monitors_at_startup") -#define CONF_KEY_TURN_ON_LAPTOP_MONITOR_AT_STARTUP (CONF_DIR "/turn_on_laptop_monitor_at_startup") -#define CONF_KEY_DEFAULT_CONFIGURATION_FILE (CONF_DIR "/default_configuration_file") - -#define VIDEO_KEYSYM "XF86Display" -#define ROTATE_KEYSYM "XF86RotateWindows" - -/* Number of seconds that the confirmation dialog will last before it resets the - * RANDR configuration to its old state. - */ -#define CONFIRMATION_DIALOG_SECONDS 30 - -/* name of the icon files (msd-xrandr.svg, etc.) */ -#define MSD_XRANDR_ICON_NAME "msd-xrandr" - -/* executable of the control center's display configuration capplet */ -#define MSD_XRANDR_DISPLAY_CAPPLET "mate-control-center display" - -#define MSD_DBUS_PATH "/org/mate/SettingsDaemon" -#define MSD_DBUS_NAME "org.mate.SettingsDaemon" -#define MSD_XRANDR_DBUS_PATH MSD_DBUS_PATH "/XRANDR" -#define MSD_XRANDR_DBUS_NAME MSD_DBUS_NAME ".XRANDR" - -struct MsdXrandrManagerPrivate -{ - DBusGConnection *dbus_connection; - - /* Key code of the XF86Display key (Fn-F7 on Thinkpads, Fn-F4 on HP machines, etc.) */ - guint switch_video_mode_keycode; - - /* Key code of the XF86RotateWindows key (present on some tablets) */ - guint rotate_windows_keycode; - - MateRRScreen *rw_screen; - gboolean running; - - GtkStatusIcon *status_icon; - GtkWidget *popup_menu; - MateRRConfig *configuration; - MateRRLabeler *labeler; - MateConfClient *client; - int notify_id; - - /* fn-F7 status */ - int current_fn_f7_config; /* -1 if no configs */ - MateRRConfig **fn_f7_configs; /* NULL terminated, NULL if there are no configs */ - - /* Last time at which we got a "screen got reconfigured" event; see on_randr_event() */ - guint32 last_config_timestamp; -}; - -static const MateRRRotation possible_rotations[] = { - MATE_RR_ROTATION_0, - MATE_RR_ROTATION_90, - MATE_RR_ROTATION_180, - MATE_RR_ROTATION_270 - /* We don't allow REFLECT_X or REFLECT_Y for now, as mate-display-properties doesn't allow them, either */ -}; - -static void msd_xrandr_manager_class_init (MsdXrandrManagerClass *klass); -static void msd_xrandr_manager_init (MsdXrandrManager *xrandr_manager); -static void msd_xrandr_manager_finalize (GObject *object); - -static void error_message (MsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text); - -static void status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timestamp); -static void run_display_capplet (GtkWidget *widget); -static void get_allowed_rotations_for_output (MateRRConfig *config, - MateRRScreen *rr_screen, - MateOutputInfo *output, - int *out_num_rotations, - MateRRRotation *out_rotations); - -G_DEFINE_TYPE (MsdXrandrManager, msd_xrandr_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -static FILE *log_file; - -static void -log_open (void) -{ - char *toggle_filename; - char *log_filename; - struct stat st; - - if (log_file) - return; - - toggle_filename = g_build_filename (g_get_home_dir (), "msd-debug-randr", NULL); - log_filename = g_build_filename (g_get_home_dir (), "msd-debug-randr.log", NULL); - - if (stat (toggle_filename, &st) != 0) - goto out; - - log_file = fopen (log_filename, "a"); - - if (log_file && ftell (log_file) == 0) - fprintf (log_file, "To keep this log from being created, please rm ~/msd-debug-randr\n"); - -out: - g_free (toggle_filename); - g_free (log_filename); -} - -static void -log_close (void) -{ - if (log_file) { - fclose (log_file); - log_file = NULL; - } -} - -static void -log_msg (const char *format, ...) -{ - if (log_file) { - va_list args; - - va_start (args, format); - vfprintf (log_file, format, args); - va_end (args); - } -} - -static void -log_output (MateOutputInfo *output) -{ - log_msg (" %s: ", output->name ? output->name : "unknown"); - - if (output->connected) { - if (output->on) { - log_msg ("%dx%d@%d +%d+%d", - output->width, - output->height, - output->rate, - output->x, - output->y); - } else - log_msg ("off"); - } else - log_msg ("disconnected"); - - if (output->display_name) - log_msg (" (%s)", output->display_name); - - if (output->primary) - log_msg (" (primary output)"); - - log_msg ("\n"); -} - -static void -log_configuration (MateRRConfig *config) -{ - int i; - - log_msg (" cloned: %s\n", config->clone ? "yes" : "no"); - - for (i = 0; config->outputs[i] != NULL; i++) - log_output (config->outputs[i]); - - if (i == 0) - log_msg (" no outputs!\n"); -} - -static char -timestamp_relationship (guint32 a, guint32 b) -{ - if (a < b) - return '<'; - else if (a > b) - return '>'; - else - return '='; -} - -static void -log_screen (MateRRScreen *screen) -{ - MateRRConfig *config; - int min_w, min_h, max_w, max_h; - guint32 change_timestamp, config_timestamp; - - if (!log_file) - return; - - config = mate_rr_config_new_current (screen); - - mate_rr_screen_get_ranges (screen, &min_w, &max_w, &min_h, &max_h); - mate_rr_screen_get_timestamps (screen, &change_timestamp, &config_timestamp); - - log_msg (" Screen min(%d, %d), max(%d, %d), change=%u %c config=%u\n", - min_w, min_h, - max_w, max_h, - change_timestamp, - timestamp_relationship (change_timestamp, config_timestamp), - config_timestamp); - - log_configuration (config); - mate_rr_config_free (config); -} - -static void -log_configurations (MateRRConfig **configs) -{ - int i; - - if (!configs) { - log_msg (" No configurations\n"); - return; - } - - for (i = 0; configs[i]; i++) { - log_msg (" Configuration %d\n", i); - log_configuration (configs[i]); - } -} - -static void -show_timestamps_dialog (MsdXrandrManager *manager, const char *msg) -{ -#if 1 - return; -#else - struct MsdXrandrManagerPrivate *priv = manager->priv; - GtkWidget *dialog; - guint32 change_timestamp, config_timestamp; - static int serial; - - mate_rr_screen_get_timestamps (priv->rw_screen, &change_timestamp, &config_timestamp); - - dialog = gtk_message_dialog_new (NULL, - 0, - GTK_MESSAGE_INFO, - GTK_BUTTONS_CLOSE, - "RANDR timestamps (%d):\n%s\nchange: %u\nconfig: %u", - serial++, - msg, - change_timestamp, - config_timestamp); - g_signal_connect (dialog, "response", - G_CALLBACK (gtk_widget_destroy), NULL); - gtk_widget_show (dialog); -#endif -} - -/* This function centralizes the use of mate_rr_config_apply_from_filename_with_time(). - * - * Optionally filters out MATE_RR_ERROR_NO_MATCHING_CONFIG from - * mate_rr_config_apply_from_filename_with_time(), since that is not usually an error. - */ -static gboolean -apply_configuration_from_filename (MsdXrandrManager *manager, - const char *filename, - gboolean no_matching_config_is_an_error, - guint32 timestamp, - GError **error) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - GError *my_error; - gboolean success; - char *str; - - str = g_strdup_printf ("Applying %s with timestamp %d", filename, timestamp); - show_timestamps_dialog (manager, str); - g_free (str); - - my_error = NULL; - success = mate_rr_config_apply_from_filename_with_time (priv->rw_screen, filename, timestamp, &my_error); - if (success) - return TRUE; - - if (g_error_matches (my_error, MATE_RR_ERROR, MATE_RR_ERROR_NO_MATCHING_CONFIG)) { - if (no_matching_config_is_an_error) - goto fail; - - /* This is not an error; the user probably changed his monitors - * and so they don't match any of the stored configurations. - */ - g_error_free (my_error); - return TRUE; - } - -fail: - g_propagate_error (error, my_error); - return FALSE; -} - -/* This function centralizes the use of mate_rr_config_apply_with_time(). - * - * Applies a configuration and displays an error message if an error happens. - * We just return whether setting the configuration succeeded. - */ -static gboolean -apply_configuration_and_display_error (MsdXrandrManager *manager, MateRRConfig *config, guint32 timestamp) -{ - MsdXrandrManagerPrivate *priv = manager->priv; - GError *error; - gboolean success; - - error = NULL; - success = mate_rr_config_apply_with_time (config, priv->rw_screen, timestamp, &error); - if (!success) { - log_msg ("Could not switch to the following configuration (timestamp %u): %s\n", timestamp, error->message); - log_configuration (config); - error_message (manager, _("Could not switch the monitor configuration"), error, NULL); - g_error_free (error); - } - - return success; -} - -static void -restore_backup_configuration_without_messages (const char *backup_filename, const char *intended_filename) -{ - backup_filename = mate_rr_config_get_backup_filename (); - rename (backup_filename, intended_filename); -} - -static void -restore_backup_configuration (MsdXrandrManager *manager, const char *backup_filename, const char *intended_filename, guint32 timestamp) -{ - int saved_errno; - - if (rename (backup_filename, intended_filename) == 0) { - GError *error; - - error = NULL; - if (!apply_configuration_from_filename (manager, intended_filename, FALSE, timestamp, &error)) { - error_message (manager, _("Could not restore the display's configuration"), error, NULL); - - if (error) - g_error_free (error); - } - - return; - } - - saved_errno = errno; - - /* ENOENT means the original file didn't exist. That is *not* an error; - * the backup was not created because there wasn't even an original - * monitors.xml (such as on a first-time login). Note that *here* there - * is a "didn't work" monitors.xml, so we must delete that one. - */ - if (saved_errno == ENOENT) - unlink (intended_filename); - else { - char *msg; - - msg = g_strdup_printf ("Could not rename %s to %s: %s", - backup_filename, intended_filename, - g_strerror (saved_errno)); - error_message (manager, - _("Could not restore the display's configuration from a backup"), - NULL, - msg); - g_free (msg); - } - - unlink (backup_filename); -} - -typedef struct { - MsdXrandrManager *manager; - GtkWidget *dialog; - - int countdown; - int response_id; -} TimeoutDialog; - -static void -print_countdown_text (TimeoutDialog *timeout) -{ - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (timeout->dialog), - ngettext ("The display will be reset to its previous configuration in %d second", - "The display will be reset to its previous configuration in %d seconds", - timeout->countdown), - timeout->countdown); -} - -static gboolean -timeout_cb (gpointer data) -{ - TimeoutDialog *timeout = data; - - timeout->countdown--; - - if (timeout->countdown == 0) { - timeout->response_id = GTK_RESPONSE_CANCEL; - gtk_main_quit (); - } else { - print_countdown_text (timeout); - } - - return TRUE; -} - -static void -timeout_response_cb (GtkDialog *dialog, int response_id, gpointer data) -{ - TimeoutDialog *timeout = data; - - if (response_id == GTK_RESPONSE_DELETE_EVENT) { - /* The user closed the dialog or pressed ESC, revert */ - timeout->response_id = GTK_RESPONSE_CANCEL; - } else - timeout->response_id = response_id; - - gtk_main_quit (); -} - -static gboolean -user_says_things_are_ok (MsdXrandrManager *manager, GdkWindow *parent_window) -{ - TimeoutDialog timeout; - guint timeout_id; - - timeout.manager = manager; - - timeout.dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - _("Does the display look OK?")); - - timeout.countdown = CONFIRMATION_DIALOG_SECONDS; - - print_countdown_text (&timeout); - - gtk_dialog_add_button (GTK_DIALOG (timeout.dialog), _("_Restore Previous Configuration"), GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (GTK_DIALOG (timeout.dialog), _("_Keep This Configuration"), GTK_RESPONSE_ACCEPT); - gtk_dialog_set_default_response (GTK_DIALOG (timeout.dialog), GTK_RESPONSE_ACCEPT); /* ah, the optimism */ - - g_signal_connect (timeout.dialog, "response", - G_CALLBACK (timeout_response_cb), - &timeout); - - gtk_widget_realize (timeout.dialog); - - if (parent_window) - gdk_window_set_transient_for (gtk_widget_get_window (timeout.dialog), parent_window); - - gtk_widget_show_all (timeout.dialog); - /* We don't use g_timeout_add_seconds() since we actually care that the user sees "real" second ticks in the dialog */ - timeout_id = g_timeout_add (1000, - timeout_cb, - &timeout); - gtk_main (); - - gtk_widget_destroy (timeout.dialog); - g_source_remove (timeout_id); - - if (timeout.response_id == GTK_RESPONSE_ACCEPT) - return TRUE; - else - return FALSE; -} - -struct confirmation { - MsdXrandrManager *manager; - GdkWindow *parent_window; - guint32 timestamp; -}; - -static gboolean -confirm_with_user_idle_cb (gpointer data) -{ - struct confirmation *confirmation = data; - char *backup_filename; - char *intended_filename; - - backup_filename = mate_rr_config_get_backup_filename (); - intended_filename = mate_rr_config_get_intended_filename (); - - if (user_says_things_are_ok (confirmation->manager, confirmation->parent_window)) - unlink (backup_filename); - else - restore_backup_configuration (confirmation->manager, backup_filename, intended_filename, confirmation->timestamp); - - g_free (confirmation); - - return FALSE; -} - -static void -queue_confirmation_by_user (MsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp) -{ - struct confirmation *confirmation; - - confirmation = g_new (struct confirmation, 1); - confirmation->manager = manager; - confirmation->parent_window = parent_window; - confirmation->timestamp = timestamp; - - g_idle_add (confirm_with_user_idle_cb, confirmation); -} - -static gboolean -try_to_apply_intended_configuration (MsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp, GError **error) -{ - char *backup_filename; - char *intended_filename; - gboolean result; - - /* Try to apply the intended configuration */ - - backup_filename = mate_rr_config_get_backup_filename (); - intended_filename = mate_rr_config_get_intended_filename (); - - result = apply_configuration_from_filename (manager, intended_filename, FALSE, timestamp, error); - if (!result) { - error_message (manager, _("The selected configuration for displays could not be applied"), error ? *error : NULL, NULL); - restore_backup_configuration_without_messages (backup_filename, intended_filename); - goto out; - } else { - /* We need to return as quickly as possible, so instead of - * confirming with the user right here, we do it in an idle - * handler. The caller only expects a status for "could you - * change the RANDR configuration?", not "is the user OK with it - * as well?". - */ - queue_confirmation_by_user (manager, parent_window, timestamp); - } - -out: - g_free (backup_filename); - g_free (intended_filename); - - return result; -} - -/* DBus method for org.mate.SettingsDaemon.XRANDR ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ -static gboolean -msd_xrandr_manager_apply_configuration (MsdXrandrManager *manager, - GError **error) -{ - return try_to_apply_intended_configuration (manager, NULL, GDK_CURRENT_TIME, error); -} - -/* DBus method for org.mate.SettingsDaemon.XRANDR_2 ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ -static gboolean -msd_xrandr_manager_2_apply_configuration (MsdXrandrManager *manager, - gint64 parent_window_id, - gint64 timestamp, - GError **error) -{ - GdkWindow *parent_window; - gboolean result; - - if (parent_window_id != 0) - parent_window = gdk_window_foreign_new_for_display (gdk_display_get_default (), (GdkNativeWindow) parent_window_id); - else - parent_window = NULL; - - result = try_to_apply_intended_configuration (manager, parent_window, (guint32) timestamp, error); - - if (parent_window) - g_object_unref (parent_window); - - return result; -} - -/* We include this after the definition of msd_xrandr_manager_apply_configuration() so the prototype will already exist */ -#include "msd-xrandr-manager-glue.h" - -static gboolean -is_laptop (MateRRScreen *screen, MateOutputInfo *output) -{ - MateRROutput *rr_output; - - rr_output = mate_rr_screen_get_output_by_name (screen, output->name); - return mate_rr_output_is_laptop (rr_output); -} - -static gboolean -get_clone_size (MateRRScreen *screen, int *width, int *height) -{ - MateRRMode **modes = mate_rr_screen_list_clone_modes (screen); - int best_w, best_h; - int i; - - best_w = 0; - best_h = 0; - - for (i = 0; modes[i] != NULL; ++i) { - MateRRMode *mode = modes[i]; - int w, h; - - w = mate_rr_mode_get_width (mode); - h = mate_rr_mode_get_height (mode); - - if (w * h > best_w * best_h) { - best_w = w; - best_h = h; - } - } - - if (best_w > 0 && best_h > 0) { - if (width) - *width = best_w; - if (height) - *height = best_h; - - return TRUE; - } - - return FALSE; -} - -static void -print_output (MateOutputInfo *info) -{ - g_print (" Output: %s attached to %s\n", info->display_name, info->name); - g_print (" status: %s\n", info->on ? "on" : "off"); - g_print (" width: %d\n", info->width); - g_print (" height: %d\n", info->height); - g_print (" rate: %d\n", info->rate); - g_print (" position: %d %d\n", info->x, info->y); -} - -static void -print_configuration (MateRRConfig *config, const char *header) -{ - int i; - - g_print ("=== %s Configuration ===\n", header); - if (!config) { - g_print (" none\n"); - return; - } - - for (i = 0; config->outputs[i] != NULL; ++i) - print_output (config->outputs[i]); -} - -static gboolean -config_is_all_off (MateRRConfig *config) -{ - int j; - - for (j = 0; config->outputs[j] != NULL; ++j) { - if (config->outputs[j]->on) { - return FALSE; - } - } - - return TRUE; -} - -static MateRRConfig * -make_clone_setup (MateRRScreen *screen) -{ - MateRRConfig *result; - int width, height; - int i; - - if (!get_clone_size (screen, &width, &height)) - return NULL; - - result = mate_rr_config_new_current (screen); - - for (i = 0; result->outputs[i] != NULL; ++i) { - MateOutputInfo *info = result->outputs[i]; - - info->on = FALSE; - if (info->connected) { - MateRROutput *output = - mate_rr_screen_get_output_by_name (screen, info->name); - MateRRMode **modes = mate_rr_output_list_modes (output); - int j; - int best_rate = 0; - - for (j = 0; modes[j] != NULL; ++j) { - MateRRMode *mode = modes[j]; - int w, h; - - w = mate_rr_mode_get_width (mode); - h = mate_rr_mode_get_height (mode); - - if (w == width && h == height) { - int r = mate_rr_mode_get_freq (mode); - if (r > best_rate) - best_rate = r; - } - } - - if (best_rate > 0) { - info->on = TRUE; - info->width = width; - info->height = height; - info->rate = best_rate; - info->rotation = MATE_RR_ROTATION_0; - info->x = 0; - info->y = 0; - } - } - } - - if (config_is_all_off (result)) { - mate_rr_config_free (result); - result = NULL; - } - - print_configuration (result, "clone setup"); - - return result; -} - -static MateRRMode * -find_best_mode (MateRROutput *output) -{ - MateRRMode *preferred; - MateRRMode **modes; - int best_size; - int best_width, best_height, best_rate; - int i; - MateRRMode *best_mode; - - preferred = mate_rr_output_get_preferred_mode (output); - if (preferred) - return preferred; - - modes = mate_rr_output_list_modes (output); - if (!modes) - return NULL; - - best_size = best_width = best_height = best_rate = 0; - best_mode = NULL; - - for (i = 0; modes[i] != NULL; i++) { - int w, h, r; - int size; - - w = mate_rr_mode_get_width (modes[i]); - h = mate_rr_mode_get_height (modes[i]); - r = mate_rr_mode_get_freq (modes[i]); - - size = w * h; - - if (size > best_size) { - best_size = size; - best_width = w; - best_height = h; - best_rate = r; - best_mode = modes[i]; - } else if (size == best_size) { - if (r > best_rate) { - best_rate = r; - best_mode = modes[i]; - } - } - } - - return best_mode; -} - -static gboolean -turn_on (MateRRScreen *screen, - MateOutputInfo *info, - int x, int y) -{ - MateRROutput *output = mate_rr_screen_get_output_by_name (screen, info->name); - MateRRMode *mode = find_best_mode (output); - - if (mode) { - info->on = TRUE; - info->x = x; - info->y = y; - info->width = mate_rr_mode_get_width (mode); - info->height = mate_rr_mode_get_height (mode); - info->rotation = MATE_RR_ROTATION_0; - info->rate = mate_rr_mode_get_freq (mode); - - return TRUE; - } - - return FALSE; -} - -static MateRRConfig * -make_laptop_setup (MateRRScreen *screen) -{ - /* Turn on the laptop, disable everything else */ - MateRRConfig *result = mate_rr_config_new_current (screen); - int i; - - for (i = 0; result->outputs[i] != NULL; ++i) { - MateOutputInfo *info = result->outputs[i]; - - if (is_laptop (screen, info)) { - if (!turn_on (screen, info, 0, 0)) { - mate_rr_config_free (result); - result = NULL; - break; - } - } - else { - info->on = FALSE; - } - } - - if (config_is_all_off (result)) { - mate_rr_config_free (result); - result = NULL; - } - - print_configuration (result, "Laptop setup"); - - /* FIXME - Maybe we should return NULL if there is more than - * one connected "laptop" screen? - */ - return result; - -} - -static int -turn_on_and_get_rightmost_offset (MateRRScreen *screen, MateOutputInfo *info, int x) -{ - if (turn_on (screen, info, x, 0)) - x += info->width; - - return x; -} - -static MateRRConfig * -make_xinerama_setup (MateRRScreen *screen) -{ - /* Turn on everything that has a preferred mode, and - * position it from left to right - */ - MateRRConfig *result = mate_rr_config_new_current (screen); - int i; - int x; - - x = 0; - for (i = 0; result->outputs[i] != NULL; ++i) { - MateOutputInfo *info = result->outputs[i]; - - if (is_laptop (screen, info)) - x = turn_on_and_get_rightmost_offset (screen, info, x); - } - - for (i = 0; result->outputs[i] != NULL; ++i) { - MateOutputInfo *info = result->outputs[i]; - - if (info->connected && !is_laptop (screen, info)) - x = turn_on_and_get_rightmost_offset (screen, info, x); - } - - if (config_is_all_off (result)) { - mate_rr_config_free (result); - result = NULL; - } - - print_configuration (result, "xinerama setup"); - - return result; -} - -static MateRRConfig * -make_other_setup (MateRRScreen *screen) -{ - /* Turn off all laptops, and make all external monitors clone - * from (0, 0) - */ - - MateRRConfig *result = mate_rr_config_new_current (screen); - int i; - - for (i = 0; result->outputs[i] != NULL; ++i) { - MateOutputInfo *info = result->outputs[i]; - - if (is_laptop (screen, info)) { - info->on = FALSE; - } - else { - if (info->connected) - turn_on (screen, info, 0, 0); - } - } - - if (config_is_all_off (result)) { - mate_rr_config_free (result); - result = NULL; - } - - print_configuration (result, "other setup"); - - return result; -} - -static GPtrArray * -sanitize (MsdXrandrManager *manager, GPtrArray *array) -{ - int i; - GPtrArray *new; - - g_debug ("before sanitizing"); - - for (i = 0; i < array->len; ++i) { - if (array->pdata[i]) { - print_configuration (array->pdata[i], "before"); - } - } - - - /* Remove configurations that are duplicates of - * configurations earlier in the cycle - */ - for (i = 0; i < array->len; i++) { - int j; - - for (j = i + 1; j < array->len; j++) { - MateRRConfig *this = array->pdata[j]; - MateRRConfig *other = array->pdata[i]; - - if (this && other && mate_rr_config_equal (this, other)) { - g_debug ("removing duplicate configuration"); - mate_rr_config_free (this); - array->pdata[j] = NULL; - break; - } - } - } - - for (i = 0; i < array->len; ++i) { - MateRRConfig *config = array->pdata[i]; - - if (config && config_is_all_off (config)) { - g_debug ("removing configuration as all outputs are off"); - mate_rr_config_free (array->pdata[i]); - array->pdata[i] = NULL; - } - } - - /* Do a final sanitization pass. This will remove configurations that - * don't fit in the framebuffer's Virtual size. - */ - - for (i = 0; i < array->len; i++) { - MateRRConfig *config = array->pdata[i]; - - if (config) { - GError *error; - - error = NULL; - if (!mate_rr_config_applicable (config, manager->priv->rw_screen, &error)) { /* NULL-GError */ - g_debug ("removing configuration which is not applicable because %s", error->message); - g_error_free (error); - - mate_rr_config_free (config); - array->pdata[i] = NULL; - } - } - } - - /* Remove NULL configurations */ - new = g_ptr_array_new (); - - for (i = 0; i < array->len; ++i) { - if (array->pdata[i]) { - g_ptr_array_add (new, array->pdata[i]); - print_configuration (array->pdata[i], "Final"); - } - } - - if (new->len > 0) { - g_ptr_array_add (new, NULL); - } else { - g_ptr_array_free (new, TRUE); - new = NULL; - } - - g_ptr_array_free (array, TRUE); - - return new; -} - -static void -generate_fn_f7_configs (MsdXrandrManager *mgr) -{ - GPtrArray *array = g_ptr_array_new (); - MateRRScreen *screen = mgr->priv->rw_screen; - - g_debug ("Generating configurations"); - - /* Free any existing list of configurations */ - if (mgr->priv->fn_f7_configs) { - int i; - - for (i = 0; mgr->priv->fn_f7_configs[i] != NULL; ++i) - mate_rr_config_free (mgr->priv->fn_f7_configs[i]); - g_free (mgr->priv->fn_f7_configs); - - mgr->priv->fn_f7_configs = NULL; - mgr->priv->current_fn_f7_config = -1; - } - - g_ptr_array_add (array, mate_rr_config_new_current (screen)); - g_ptr_array_add (array, make_clone_setup (screen)); - g_ptr_array_add (array, make_xinerama_setup (screen)); - g_ptr_array_add (array, make_laptop_setup (screen)); - g_ptr_array_add (array, make_other_setup (screen)); - - array = sanitize (mgr, array); - - if (array) { - mgr->priv->fn_f7_configs = (MateRRConfig **)g_ptr_array_free (array, FALSE); - mgr->priv->current_fn_f7_config = 0; - } -} - -static void -error_message (MsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text) -{ -#ifdef HAVE_LIBMATENOTIFY - MsdXrandrManagerPrivate *priv = mgr->priv; - NotifyNotification *notification; - - g_assert (error_to_display == NULL || secondary_text == NULL); - - if (priv->status_icon) - notification = notify_notification_new_with_status_icon (primary_text, - error_to_display ? error_to_display->message : secondary_text, - MSD_XRANDR_ICON_NAME, - priv->status_icon); - else - notification = notify_notification_new (primary_text, - error_to_display ? error_to_display->message : secondary_text, - MSD_XRANDR_ICON_NAME, - NULL); - - notify_notification_show (notification, NULL); /* NULL-GError */ -#else - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "%s", primary_text); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", - error_to_display ? error_to_display->message : secondary_text); - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -#endif /* HAVE_LIBMATENOTIFY */ -} - -static void -handle_fn_f7 (MsdXrandrManager *mgr, guint32 timestamp) -{ - MsdXrandrManagerPrivate *priv = mgr->priv; - MateRRScreen *screen = priv->rw_screen; - MateRRConfig *current; - GError *error; - - /* Theory of fn-F7 operation - * - * We maintain a datastructure "fn_f7_status", that contains - * a list of MateRRConfig's. Each of the MateRRConfigs has a - * mode (or "off") for each connected output. - * - * When the user hits fn-F7, we cycle to the next MateRRConfig - * in the data structure. If the data structure does not exist, it - * is generated. If the configs in the data structure do not match - * the current hardware reality, it is regenerated. - * - */ - g_debug ("Handling fn-f7"); - - log_open (); - log_msg ("Handling XF86Display hotkey - timestamp %u\n", timestamp); - - error = NULL; - if (!mate_rr_screen_refresh (screen, &error) && error) { - char *str; - - str = g_strdup_printf (_("Could not refresh the screen information: %s"), error->message); - g_error_free (error); - - log_msg ("%s\n", str); - error_message (mgr, str, NULL, _("Trying to switch the monitor configuration anyway.")); - g_free (str); - } - - if (!priv->fn_f7_configs) { - log_msg ("Generating stock configurations:\n"); - generate_fn_f7_configs (mgr); - log_configurations (priv->fn_f7_configs); - } - - current = mate_rr_config_new_current (screen); - - if (priv->fn_f7_configs && - (!mate_rr_config_match (current, priv->fn_f7_configs[0]) || - !mate_rr_config_equal (current, priv->fn_f7_configs[mgr->priv->current_fn_f7_config]))) { - /* Our view of the world is incorrect, so regenerate the - * configurations - */ - generate_fn_f7_configs (mgr); - log_msg ("Regenerated stock configurations:\n"); - log_configurations (priv->fn_f7_configs); - } - - mate_rr_config_free (current); - - if (priv->fn_f7_configs) { - guint32 server_timestamp; - gboolean success; - - mgr->priv->current_fn_f7_config++; - - if (priv->fn_f7_configs[mgr->priv->current_fn_f7_config] == NULL) - mgr->priv->current_fn_f7_config = 0; - - g_debug ("cycling to next configuration (%d)", mgr->priv->current_fn_f7_config); - - print_configuration (priv->fn_f7_configs[mgr->priv->current_fn_f7_config], "new config"); - - g_debug ("applying"); - - /* See https://bugzilla.gnome.org/show_bug.cgi?id=610482 - * - * Sometimes we'll get two rapid XF86Display keypress events, - * but their timestamps will be out of order with respect to the - * RANDR timestamps. This *may* be due to stupid BIOSes sending - * out display-switch keystrokes "to make Windows work". - * - * The X server will error out if the timestamp provided is - * older than a previous change configuration timestamp. We - * assume here that we do want this event to go through still, - * since kernel timestamps may be skewed wrt the X server. - */ - mate_rr_screen_get_timestamps (screen, NULL, &server_timestamp); - if (timestamp < server_timestamp) - timestamp = server_timestamp; - - success = apply_configuration_and_display_error (mgr, priv->fn_f7_configs[mgr->priv->current_fn_f7_config], timestamp); - - if (success) { - log_msg ("Successfully switched to configuration (timestamp %u):\n", timestamp); - log_configuration (priv->fn_f7_configs[mgr->priv->current_fn_f7_config]); - } - } - else { - g_debug ("no configurations generated"); - } - - log_close (); - - g_debug ("done handling fn-f7"); -} - -static MateOutputInfo * -get_laptop_output_info (MateRRScreen *screen, MateRRConfig *config) -{ - int i; - - for (i = 0; config->outputs[i] != NULL; i++) { - MateOutputInfo *info; - - info = config->outputs[i]; - if (is_laptop (screen, info)) - return info; - } - - return NULL; - -} - -static MateRRRotation -get_next_rotation (MateRRRotation allowed_rotations, MateRRRotation current_rotation) -{ - int i; - int current_index; - - /* First, find the index of the current rotation */ - - current_index = -1; - - for (i = 0; i < G_N_ELEMENTS (possible_rotations); i++) { - MateRRRotation r; - - r = possible_rotations[i]; - if (r == current_rotation) { - current_index = i; - break; - } - } - - if (current_index == -1) { - /* Huh, the current_rotation was not one of the supported rotations. Bail out. */ - return current_rotation; - } - - /* Then, find the next rotation that is allowed */ - - i = (current_index + 1) % G_N_ELEMENTS (possible_rotations); - - while (1) { - MateRRRotation r; - - r = possible_rotations[i]; - if (r == current_rotation) { - /* We wrapped around and no other rotation is suported. Bummer. */ - return current_rotation; - } else if (r & allowed_rotations) - return r; - - i = (i + 1) % G_N_ELEMENTS (possible_rotations); - } -} - -/* We use this when the XF86RotateWindows key is pressed. That key is present - * on some tablet PCs; they use it so that the user can rotate the tablet - * easily. - */ -static void -handle_rotate_windows (MsdXrandrManager *mgr, guint32 timestamp) -{ - MsdXrandrManagerPrivate *priv = mgr->priv; - MateRRScreen *screen = priv->rw_screen; - MateRRConfig *current; - MateOutputInfo *rotatable_output_info; - int num_allowed_rotations; - MateRRRotation allowed_rotations; - MateRRRotation next_rotation; - - g_debug ("Handling XF86RotateWindows"); - - /* Which output? */ - - current = mate_rr_config_new_current (screen); - - rotatable_output_info = get_laptop_output_info (screen, current); - if (rotatable_output_info == NULL) { - g_debug ("No laptop outputs found to rotate; XF86RotateWindows key will do nothing"); - goto out; - } - - /* Which rotation? */ - - get_allowed_rotations_for_output (current, priv->rw_screen, rotatable_output_info, &num_allowed_rotations, &allowed_rotations); - next_rotation = get_next_rotation (allowed_rotations, rotatable_output_info->rotation); - - if (next_rotation == rotatable_output_info->rotation) { - g_debug ("No rotations are supported other than the current one; XF86RotateWindows key will do nothing"); - goto out; - } - - /* Rotate */ - - rotatable_output_info->rotation = next_rotation; - - apply_configuration_and_display_error (mgr, current, timestamp); - -out: - mate_rr_config_free (current); -} - -static GdkFilterReturn -event_filter (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) -{ - MsdXrandrManager *manager = data; - XEvent *xev = (XEvent *) xevent; - - if (!manager->priv->running) - return GDK_FILTER_CONTINUE; - - /* verify we have a key event */ - if (xev->xany.type != KeyPress && xev->xany.type != KeyRelease) - return GDK_FILTER_CONTINUE; - - if (xev->xany.type == KeyPress) { - if (xev->xkey.keycode == manager->priv->switch_video_mode_keycode) - handle_fn_f7 (manager, xev->xkey.time); - else if (xev->xkey.keycode == manager->priv->rotate_windows_keycode) - handle_rotate_windows (manager, xev->xkey.time); - - return GDK_FILTER_CONTINUE; - } - - return GDK_FILTER_CONTINUE; -} - -static void -refresh_tray_icon_menu_if_active (MsdXrandrManager *manager, guint32 timestamp) -{ - MsdXrandrManagerPrivate *priv = manager->priv; - - if (priv->popup_menu) { - gtk_menu_shell_cancel (GTK_MENU_SHELL (priv->popup_menu)); /* status_icon_popup_menu_selection_done_cb() will free everything */ - status_icon_popup_menu (manager, 0, timestamp); - } -} - -static void -auto_configure_outputs (MsdXrandrManager *manager, guint32 timestamp) -{ - MsdXrandrManagerPrivate *priv = manager->priv; - MateRRConfig *config; - int i; - GList *just_turned_on; - GList *l; - int x; - GError *error; - gboolean applicable; - - config = mate_rr_config_new_current (priv->rw_screen); - - /* For outputs that are connected and on (i.e. they have a CRTC assigned - * to them, so they are getting a signal), we leave them as they are - * with their current modes. - * - * For other outputs, we will turn on connected-but-off outputs and turn - * off disconnected-but-on outputs. - * - * FIXME: If an output remained connected+on, it would be nice to ensure - * that the output's CRTCs still has a reasonable mode (think of - * changing one monitor for another with different capabilities). - */ - - just_turned_on = NULL; - - for (i = 0; config->outputs[i] != NULL; i++) { - MateOutputInfo *output = config->outputs[i]; - - if (output->connected && !output->on) { - output->on = TRUE; - output->rotation = MATE_RR_ROTATION_0; - just_turned_on = g_list_prepend (just_turned_on, GINT_TO_POINTER (i)); - } else if (!output->connected && output->on) - output->on = FALSE; - } - - /* Now, lay out the outputs from left to right. Put first the outputs - * which remained on; put last the outputs that were newly turned on. - */ - - x = 0; - - /* First, outputs that remained on */ - - for (i = 0; config->outputs[i] != NULL; i++) { - MateOutputInfo *output = config->outputs[i]; - - if (g_list_find (just_turned_on, GINT_TO_POINTER (i))) - continue; - - if (output->on) { - g_assert (output->connected); - - output->x = x; - output->y = 0; - - x += output->width; - } - } - - /* Second, outputs that were newly-turned on */ - - for (l = just_turned_on; l; l = l->next) { - MateOutputInfo *output; - - i = GPOINTER_TO_INT (l->data); - output = config->outputs[i]; - - g_assert (output->on && output->connected); - - output->x = x; - output->y = 0; - - /* since the output was off, use its preferred width/height (it doesn't have a real width/height yet) */ - output->width = output->pref_width; - output->height = output->pref_height; - - x += output->width; - } - - /* Check if we have a large enough framebuffer size. If not, turn off - * outputs from right to left until we reach a usable size. - */ - - just_turned_on = g_list_reverse (just_turned_on); /* now the outputs here are from right to left */ - - l = just_turned_on; - while (1) { - MateOutputInfo *output; - gboolean is_bounds_error; - - error = NULL; - applicable = mate_rr_config_applicable (config, priv->rw_screen, &error); - - if (applicable) - break; - - is_bounds_error = g_error_matches (error, MATE_RR_ERROR, MATE_RR_ERROR_BOUNDS_ERROR); - g_error_free (error); - - if (!is_bounds_error) - break; - - if (l) { - i = GPOINTER_TO_INT (l->data); - l = l->next; - - output = config->outputs[i]; - output->on = FALSE; - } else - break; - } - - /* Apply the configuration! */ - - if (applicable) - apply_configuration_and_display_error (manager, config, timestamp); - - g_list_free (just_turned_on); - mate_rr_config_free (config); - - /* Finally, even though we did a best-effort job in sanitizing the - * outputs, we don't know the physical layout of the monitors. We'll - * start the display capplet so that the user can tweak things to his - * liking. - */ - -#if 0 - /* FIXME: This is disabled for now. The capplet is not a single-instance application. - * If you do this: - * - * 1. Start the display capplet - * - * 2. Plug an extra monitor - * - * 3. Hit the "Detect displays" button - * - * Then we will get a RANDR event because X re-probes the outputs. We don't want to - * start up a second display capplet right there! - */ - - run_display_capplet (NULL); -#endif -} - -static void -apply_color_profiles (void) -{ - gboolean ret; - GError *error = NULL; - - /* run the mate-color-manager apply program */ - ret = g_spawn_command_line_async (BINDIR "/gcm-apply", &error); - if (!ret) { - /* only print the warning if the binary is installed */ - if (error->code != G_SPAWN_ERROR_NOENT) { - g_warning ("failed to apply color profiles: %s", error->message); - } - g_error_free (error); - } -} - -static void -on_randr_event (MateRRScreen *screen, gpointer data) -{ - MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); - MsdXrandrManagerPrivate *priv = manager->priv; - guint32 change_timestamp, config_timestamp; - - if (!priv->running) - return; - - mate_rr_screen_get_timestamps (screen, &change_timestamp, &config_timestamp); - - log_open (); - log_msg ("Got RANDR event with timestamps change=%u %c config=%u\n", - change_timestamp, - timestamp_relationship (change_timestamp, config_timestamp), - config_timestamp); - - if (change_timestamp >= config_timestamp) { - /* The event is due to an explicit configuration change. - * - * If the change was performed by us, then we need to do nothing. - * - * If the change was done by some other X client, we don't need - * to do anything, either; the screen is already configured. - */ - show_timestamps_dialog (manager, "ignoring since change > config"); - log_msg (" Ignoring event since change >= config\n"); - } else { - /* Here, config_timestamp > change_timestamp. This means that - * the screen got reconfigured because of hotplug/unplug; the X - * server is just notifying us, and we need to configure the - * outputs in a sane way. - */ - - char *intended_filename; - GError *error; - gboolean success; - - show_timestamps_dialog (manager, "need to deal with reconfiguration, as config > change"); - - intended_filename = mate_rr_config_get_intended_filename (); - - error = NULL; - success = apply_configuration_from_filename (manager, intended_filename, TRUE, config_timestamp, &error); - g_free (intended_filename); - - if (!success) { - /* We don't bother checking the error type. - * - * Both G_FILE_ERROR_NOENT and - * MATE_RR_ERROR_NO_MATCHING_CONFIG would mean, "there - * was no configuration to apply, or none that matched - * the current outputs", and in that case we need to run - * our fallback. - * - * Any other error means "we couldn't do the smart thing - * of using a previously- saved configuration, anyway, - * for some other reason. In that case, we also need to - * run our fallback to avoid leaving the user with a - * bogus configuration. - */ - - if (error) - g_error_free (error); - - if (config_timestamp != priv->last_config_timestamp) { - priv->last_config_timestamp = config_timestamp; - auto_configure_outputs (manager, config_timestamp); - log_msg (" Automatically configured outputs to deal with event\n"); - } else - log_msg (" Ignored event as old and new config timestamps are the same\n"); - } else - log_msg ("Applied stored configuration to deal with event\n"); - } - - /* poke mate-color-manager */ - apply_color_profiles (); - - refresh_tray_icon_menu_if_active (manager, MAX (change_timestamp, config_timestamp)); - - log_close (); -} - -static void -run_display_capplet (GtkWidget *widget) -{ - GdkScreen *screen; - GError *error; - - if (widget) - screen = gtk_widget_get_screen (widget); - else - screen = gdk_screen_get_default (); - - error = NULL; - if (!gdk_spawn_command_line_on_screen (screen, MSD_XRANDR_DISPLAY_CAPPLET, &error)) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "" - "Display configuration could not be run" - "\n\n" - "%s", error->message); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - g_error_free (error); - } -} - -static void -popup_menu_configure_display_cb (GtkMenuItem *item, gpointer data) -{ - run_display_capplet (GTK_WIDGET (item)); -} - -static void -status_icon_popup_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) -{ - MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); - struct MsdXrandrManagerPrivate *priv = manager->priv; - - gtk_widget_destroy (priv->popup_menu); - priv->popup_menu = NULL; - - mate_rr_labeler_hide (priv->labeler); - g_object_unref (priv->labeler); - priv->labeler = NULL; - - mate_rr_config_free (priv->configuration); - priv->configuration = NULL; -} - -#define OUTPUT_TITLE_ITEM_BORDER 2 -#define OUTPUT_TITLE_ITEM_PADDING 4 - -/* This is an expose-event hander for the title label for each MateRROutput. - * We want each title to have a colored background, so we paint that background, then - * return FALSE to let GtkLabel expose itself (i.e. paint the label's text), and then - * we have a signal_connect_after handler as well. See the comments below - * to see why that "after" handler is needed. - */ -static gboolean -output_title_label_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) -{ - MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); - struct MsdXrandrManagerPrivate *priv = manager->priv; - MateOutputInfo *output; - GdkColor color; - cairo_t *cr; - GtkAllocation allocation; - - g_assert (GTK_IS_LABEL (widget)); - - output = g_object_get_data (G_OBJECT (widget), "output"); - g_assert (output != NULL); - - g_assert (priv->labeler != NULL); - - /* Draw a black rectangular border, filled with the color that corresponds to this output */ - - mate_rr_labeler_get_color_for_output (priv->labeler, output, &color); - - cr = gdk_cairo_create (gtk_widget_get_window (widget)); - - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_set_line_width (cr, OUTPUT_TITLE_ITEM_BORDER); - gtk_widget_get_allocation (widget, &allocation); - cairo_rectangle (cr, - allocation.x + OUTPUT_TITLE_ITEM_BORDER / 2.0, - allocation.y + OUTPUT_TITLE_ITEM_BORDER / 2.0, - allocation.width - OUTPUT_TITLE_ITEM_BORDER, - allocation.height - OUTPUT_TITLE_ITEM_BORDER); - cairo_stroke (cr); - - gdk_cairo_set_source_color (cr, &color); - cairo_rectangle (cr, - allocation.x + OUTPUT_TITLE_ITEM_BORDER, - allocation.y + OUTPUT_TITLE_ITEM_BORDER, - allocation.width - 2 * OUTPUT_TITLE_ITEM_BORDER, - allocation.height - 2 * OUTPUT_TITLE_ITEM_BORDER); - - cairo_fill (cr); - - /* We want the label to always show up as if it were sensitive - * ("style->fg[GTK_STATE_NORMAL]"), even though the label is insensitive - * due to being inside an insensitive menu item. So, here we have a - * HACK in which we frob the label's state directly. GtkLabel's expose - * handler will be run after this function, so it will think that the - * label is in GTK_STATE_NORMAL. We reset the label's state back to - * insensitive in output_title_label_after_expose_event_cb(). - * - * Yay for fucking with GTK+'s internals. - */ - - gtk_widget_set_state (widget, GTK_STATE_NORMAL); - - return FALSE; -} - -/* See the comment in output_title_event_box_expose_event_cb() about this funny label widget */ -static gboolean -output_title_label_after_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) -{ - g_assert (GTK_IS_LABEL (widget)); - gtk_widget_set_state (widget, GTK_STATE_INSENSITIVE); - - return FALSE; -} - -static void -title_item_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer data) -{ - /* When GtkMenu does size_request on its items, it asks them for their "toggle size", - * which will be non-zero when there are check/radio items. GtkMenu remembers - * the largest of those sizes. During the size_allocate pass, GtkMenu calls - * gtk_menu_item_toggle_size_allocate() with that value, to tell the menu item - * that it should later paint its child a bit to the right of its edge. - * - * However, we want the "title" menu items for each RANDR output to span the *whole* - * allocation of the menu item, not just the "allocation minus toggle" area. - * - * So, we let the menu item size_allocate itself as usual, but this - * callback gets run afterward. Here we hack a toggle size of 0 into - * the menu item, and size_allocate it by hand *again*. We also need to - * avoid recursing into this function. - */ - - g_assert (GTK_IS_MENU_ITEM (widget)); - - gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (widget), 0); - - g_signal_handlers_block_by_func (widget, title_item_size_allocate_cb, NULL); - - /* Sigh. There is no way to turn on GTK_ALLOC_NEEDED outside of GTK+ - * itself; also, since calling size_allocate on a widget with the same - * allcation is a no-op, we need to allocate with a "different" size - * first. - */ - - allocation->width++; - gtk_widget_size_allocate (widget, allocation); - - allocation->width--; - gtk_widget_size_allocate (widget, allocation); - - g_signal_handlers_unblock_by_func (widget, title_item_size_allocate_cb, NULL); -} - -static GtkWidget * -make_menu_item_for_output_title (MsdXrandrManager *manager, MateOutputInfo *output) -{ - GtkWidget *item; - GtkWidget *label; - char *str; - GdkColor black = { 0, 0, 0, 0 }; - - item = gtk_menu_item_new (); - - g_signal_connect (item, "size-allocate", - G_CALLBACK (title_item_size_allocate_cb), NULL); - - str = g_markup_printf_escaped ("%s", output->display_name); - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), str); - g_free (str); - - /* Make the label explicitly black. We don't want it to follow the - * theme's colors, since the label is always shown against a light - * pastel background. See bgo#556050 - */ - gtk_widget_modify_fg (label, gtk_widget_get_state (label), &black); - - /* Add padding around the label to fit the box that we'll draw for color-coding */ - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), - OUTPUT_TITLE_ITEM_BORDER + OUTPUT_TITLE_ITEM_PADDING, - OUTPUT_TITLE_ITEM_BORDER + OUTPUT_TITLE_ITEM_PADDING); - - gtk_container_add (GTK_CONTAINER (item), label); - - /* We want to paint a colored box as the background of the label, so we connect - * to its expose-event signal. See the comment in *** to see why need to connect - * to the label both 'before' and 'after'. - */ - g_signal_connect (label, "expose-event", - G_CALLBACK (output_title_label_expose_event_cb), manager); - g_signal_connect_after (label, "expose-event", - G_CALLBACK (output_title_label_after_expose_event_cb), manager); - - g_object_set_data (G_OBJECT (label), "output", output); - - gtk_widget_set_sensitive (item, FALSE); /* the title is not selectable */ - gtk_widget_show_all (item); - - return item; -} - -static void -get_allowed_rotations_for_output (MateRRConfig *config, - MateRRScreen *rr_screen, - MateOutputInfo *output, - int *out_num_rotations, - MateRRRotation *out_rotations) -{ - MateRRRotation current_rotation; - int i; - - *out_num_rotations = 0; - *out_rotations = 0; - - current_rotation = output->rotation; - - /* Yay for brute force */ - - for (i = 0; i < G_N_ELEMENTS (possible_rotations); i++) { - MateRRRotation rotation_to_test; - - rotation_to_test = possible_rotations[i]; - - output->rotation = rotation_to_test; - - if (mate_rr_config_applicable (config, rr_screen, NULL)) { /* NULL-GError */ - (*out_num_rotations)++; - (*out_rotations) |= rotation_to_test; - } - } - - output->rotation = current_rotation; - - if (*out_num_rotations == 0 || *out_rotations == 0) { - g_warning ("Huh, output %p says it doesn't support any rotations, and yet it has a current rotation?", output); - *out_num_rotations = 1; - *out_rotations = output->rotation; - } -} - -static void -add_unsupported_rotation_item (MsdXrandrManager *manager) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - GtkWidget *item; - GtkWidget *label; - gchar *markup; - - item = gtk_menu_item_new (); - - label = gtk_label_new (NULL); - markup = g_strdup_printf ("%s", _("Rotation not supported")); - gtk_label_set_markup (GTK_LABEL (label), markup); - g_free (markup); - gtk_container_add (GTK_CONTAINER (item), label); - - gtk_widget_show_all (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); -} - -static void -ensure_current_configuration_is_saved (void) -{ - MateRRScreen *rr_screen; - MateRRConfig *rr_config; - - /* Normally, mate_rr_config_save() creates a backup file based on the - * old monitors.xml. However, if *that* file didn't exist, there is - * nothing from which to create a backup. So, here we'll save the - * current/unchanged configuration and then let our caller call - * mate_rr_config_save() again with the new/changed configuration, so - * that there *will* be a backup file in the end. - */ - - rr_screen = mate_rr_screen_new (gdk_screen_get_default (), NULL, NULL, NULL); /* NULL-GError */ - if (!rr_screen) - return; - - rr_config = mate_rr_config_new_current (rr_screen); - mate_rr_config_save (rr_config, NULL); /* NULL-GError */ - - mate_rr_config_free (rr_config); - mate_rr_screen_destroy (rr_screen); -} - -static void -output_rotation_item_activate_cb (GtkCheckMenuItem *item, gpointer data) -{ - MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); - struct MsdXrandrManagerPrivate *priv = manager->priv; - MateOutputInfo *output; - MateRRRotation rotation; - GError *error; - - /* Not interested in deselected items */ - if (!gtk_check_menu_item_get_active (item)) - return; - - ensure_current_configuration_is_saved (); - - output = g_object_get_data (G_OBJECT (item), "output"); - rotation = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "rotation")); - - output->rotation = rotation; - - error = NULL; - if (!mate_rr_config_save (priv->configuration, &error)) { - error_message (manager, _("Could not save monitor configuration"), error, NULL); - if (error) - g_error_free (error); - - return; - } - - try_to_apply_intended_configuration (manager, NULL, gtk_get_current_event_time (), NULL); /* NULL-GError */ -} - -static void -add_items_for_rotations (MsdXrandrManager *manager, MateOutputInfo *output, MateRRRotation allowed_rotations) -{ - typedef struct { - MateRRRotation rotation; - const char * name; - } RotationInfo; - static const RotationInfo rotations[] = { - { MATE_RR_ROTATION_0, N_("Normal") }, - { MATE_RR_ROTATION_90, N_("Left") }, - { MATE_RR_ROTATION_270, N_("Right") }, - { MATE_RR_ROTATION_180, N_("Upside Down") }, - /* We don't allow REFLECT_X or REFLECT_Y for now, as mate-display-properties doesn't allow them, either */ - }; - - struct MsdXrandrManagerPrivate *priv = manager->priv; - int i; - GSList *group; - GtkWidget *active_item; - gulong active_item_activate_id; - - group = NULL; - active_item = NULL; - active_item_activate_id = 0; - - for (i = 0; i < G_N_ELEMENTS (rotations); i++) { - MateRRRotation rot; - GtkWidget *item; - gulong activate_id; - - rot = rotations[i].rotation; - - if ((allowed_rotations & rot) == 0) { - /* don't display items for rotations which are - * unavailable. Their availability is not under the - * user's control, anyway. - */ - continue; - } - - item = gtk_radio_menu_item_new_with_label (group, _(rotations[i].name)); - gtk_widget_show_all (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - - g_object_set_data (G_OBJECT (item), "output", output); - g_object_set_data (G_OBJECT (item), "rotation", GINT_TO_POINTER (rot)); - - activate_id = g_signal_connect (item, "activate", - G_CALLBACK (output_rotation_item_activate_cb), manager); - - group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item)); - - if (rot == output->rotation) { - active_item = item; - active_item_activate_id = activate_id; - } - } - - if (active_item) { - /* Block the signal temporarily so our callback won't be called; - * we are just setting up the UI. - */ - g_signal_handler_block (active_item, active_item_activate_id); - - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (active_item), TRUE); - - g_signal_handler_unblock (active_item, active_item_activate_id); - } - -} - -static void -add_rotation_items_for_output (MsdXrandrManager *manager, MateOutputInfo *output) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - int num_rotations; - MateRRRotation rotations; - - get_allowed_rotations_for_output (priv->configuration, priv->rw_screen, output, &num_rotations, &rotations); - - if (num_rotations == 1) - add_unsupported_rotation_item (manager); - else - add_items_for_rotations (manager, output, rotations); -} - -static void -add_menu_items_for_output (MsdXrandrManager *manager, MateOutputInfo *output) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - GtkWidget *item; - - item = make_menu_item_for_output_title (manager, output); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - - add_rotation_items_for_output (manager, output); -} - -static void -add_menu_items_for_outputs (MsdXrandrManager *manager) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - int i; - - for (i = 0; priv->configuration->outputs[i] != NULL; i++) { - if (priv->configuration->outputs[i]->connected) - add_menu_items_for_output (manager, priv->configuration->outputs[i]); - } -} - -static void -status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timestamp) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - GtkWidget *item; - - g_assert (priv->configuration == NULL); - priv->configuration = mate_rr_config_new_current (priv->rw_screen); - - g_assert (priv->labeler == NULL); - priv->labeler = mate_rr_labeler_new (priv->configuration); - - g_assert (priv->popup_menu == NULL); - priv->popup_menu = gtk_menu_new (); - - add_menu_items_for_outputs (manager); - - item = gtk_separator_menu_item_new (); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - - item = gtk_menu_item_new_with_mnemonic (_("_Configure Display Settings…")); - g_signal_connect (item, "activate", - G_CALLBACK (popup_menu_configure_display_cb), manager); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - - g_signal_connect (priv->popup_menu, "selection-done", - G_CALLBACK (status_icon_popup_menu_selection_done_cb), manager); - - gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL, - gtk_status_icon_position_menu, - priv->status_icon, button, timestamp); -} - -static void -status_icon_activate_cb (GtkStatusIcon *status_icon, gpointer data) -{ - MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); - - /* Suck; we don't get a proper button/timestamp */ - status_icon_popup_menu (manager, 0, gtk_get_current_event_time ()); -} - -static void -status_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 timestamp, gpointer data) -{ - MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); - - status_icon_popup_menu (manager, button, timestamp); -} - -static void -status_icon_start (MsdXrandrManager *manager) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - - /* Ideally, we should detect if we are on a tablet and only display - * the icon in that case. - */ - if (!priv->status_icon) { - priv->status_icon = gtk_status_icon_new_from_icon_name (MSD_XRANDR_ICON_NAME); - gtk_status_icon_set_tooltip_text (priv->status_icon, _("Configure display settings")); - - g_signal_connect (priv->status_icon, "activate", - G_CALLBACK (status_icon_activate_cb), manager); - g_signal_connect (priv->status_icon, "popup-menu", - G_CALLBACK (status_icon_popup_menu_cb), manager); - } -} - -static void -status_icon_stop (MsdXrandrManager *manager) -{ - struct MsdXrandrManagerPrivate *priv = manager->priv; - - if (priv->status_icon) { - g_signal_handlers_disconnect_by_func ( - priv->status_icon, G_CALLBACK (status_icon_activate_cb), manager); - g_signal_handlers_disconnect_by_func ( - priv->status_icon, G_CALLBACK (status_icon_popup_menu_cb), manager); - - /* hide the icon before unreffing it; otherwise we will leak - whitespace in the notification area due to a bug in there */ - gtk_status_icon_set_visible (priv->status_icon, FALSE); - g_object_unref (priv->status_icon); - priv->status_icon = NULL; - } -} - -static void -start_or_stop_icon (MsdXrandrManager *manager) -{ - if (mateconf_client_get_bool (manager->priv->client, CONF_KEY_SHOW_NOTIFICATION_ICON, NULL)) { - status_icon_start (manager); - } - else { - status_icon_stop (manager); - } -} - -static void -on_config_changed (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MsdXrandrManager *manager) -{ - if (strcmp (entry->key, CONF_KEY_SHOW_NOTIFICATION_ICON) == 0) - start_or_stop_icon (manager); -} - -static gboolean -apply_intended_configuration (MsdXrandrManager *manager, const char *intended_filename, guint32 timestamp) -{ - GError *my_error; - gboolean result; - - my_error = NULL; - result = apply_configuration_from_filename (manager, intended_filename, FALSE, timestamp, &my_error); - if (!result) { - if (my_error) { - if (!g_error_matches (my_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) - error_message (manager, _("Could not apply the stored configuration for monitors"), my_error, NULL); - - g_error_free (my_error); - } - } - - return result; -} - -static void -apply_default_boot_configuration (MsdXrandrManager *mgr, guint32 timestamp) -{ - MsdXrandrManagerPrivate *priv = mgr->priv; - MateRRScreen *screen = priv->rw_screen; - MateRRConfig *config; - gboolean turn_on_external, turn_on_laptop; - - turn_on_external = - mateconf_client_get_bool (mgr->priv->client, CONF_KEY_TURN_ON_EXTERNAL_MONITORS_AT_STARTUP, NULL); - turn_on_laptop = - mateconf_client_get_bool (mgr->priv->client, CONF_KEY_TURN_ON_LAPTOP_MONITOR_AT_STARTUP, NULL); - - if (turn_on_external && turn_on_laptop) - config = make_clone_setup (screen); - else if (!turn_on_external && turn_on_laptop) - config = make_laptop_setup (screen); - else if (turn_on_external && !turn_on_laptop) - config = make_other_setup (screen); - else - config = make_laptop_setup (screen); - - if (config) { - apply_configuration_and_display_error (mgr, config, timestamp); - mate_rr_config_free (config); - } -} - -static gboolean -apply_stored_configuration_at_startup (MsdXrandrManager *manager, guint32 timestamp) -{ - GError *my_error; - gboolean success; - char *backup_filename; - char *intended_filename; - - backup_filename = mate_rr_config_get_backup_filename (); - intended_filename = mate_rr_config_get_intended_filename (); - - /* 1. See if there was a "saved" configuration. If there is one, it means - * that the user had selected to change the display configuration, but the - * machine crashed. In that case, we'll apply *that* configuration and save it on top of the - * "intended" one. - */ - - my_error = NULL; - - success = apply_configuration_from_filename (manager, backup_filename, FALSE, timestamp, &my_error); - if (success) { - /* The backup configuration existed, and could be applied - * successfully, so we must restore it on top of the - * failed/intended one. - */ - restore_backup_configuration (manager, backup_filename, intended_filename, timestamp); - goto out; - } - - if (!g_error_matches (my_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { - /* Epic fail: there (probably) was a backup configuration, but - * we could not apply it. The only thing we can do is delete - * the backup configuration. Let's hope that the user doesn't - * get left with an unusable display... - */ - - unlink (backup_filename); - goto out; - } - - /* 2. There was no backup configuration! This means we are - * good. Apply the intended configuration instead. - */ - - success = apply_intended_configuration (manager, intended_filename, timestamp); - -out: - - if (my_error) - g_error_free (my_error); - - g_free (backup_filename); - g_free (intended_filename); - - return success; -} - -static gboolean -apply_default_configuration_from_file (MsdXrandrManager *manager, guint32 timestamp) -{ - MsdXrandrManagerPrivate *priv = manager->priv; - char *default_config_filename; - gboolean result; - - default_config_filename = mateconf_client_get_string (priv->client, CONF_KEY_DEFAULT_CONFIGURATION_FILE, NULL); - if (!default_config_filename) - return FALSE; - - result = apply_configuration_from_filename (manager, default_config_filename, TRUE, timestamp, NULL); - - g_free (default_config_filename); - return result; -} - -gboolean -msd_xrandr_manager_start (MsdXrandrManager *manager, - GError **error) -{ - g_debug ("Starting xrandr manager"); - mate_settings_profile_start (NULL); - - log_open (); - log_msg ("------------------------------------------------------------\nSTARTING XRANDR PLUGIN\n"); - - manager->priv->rw_screen = mate_rr_screen_new ( - gdk_screen_get_default (), on_randr_event, manager, error); - - if (manager->priv->rw_screen == NULL) { - log_msg ("Could not initialize the RANDR plugin%s%s\n", - (error && *error) ? ": " : "", - (error && *error) ? (*error)->message : ""); - log_close (); - return FALSE; - } - - log_msg ("State of screen at startup:\n"); - log_screen (manager->priv->rw_screen); - - manager->priv->running = TRUE; - manager->priv->client = mateconf_client_get_default (); - - g_assert (manager->priv->notify_id == 0); - - mateconf_client_add_dir (manager->priv->client, CONF_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - - manager->priv->notify_id = - mateconf_client_notify_add ( - manager->priv->client, CONF_DIR, - (MateConfClientNotifyFunc)on_config_changed, - manager, NULL, NULL); - - if (manager->priv->switch_video_mode_keycode) { - gdk_error_trap_push (); - - XGrabKey (gdk_x11_get_default_xdisplay(), - manager->priv->switch_video_mode_keycode, AnyModifier, - gdk_x11_get_default_root_xwindow(), - True, GrabModeAsync, GrabModeAsync); - - gdk_flush (); - gdk_error_trap_pop (); - } - - if (manager->priv->rotate_windows_keycode) { - gdk_error_trap_push (); - - XGrabKey (gdk_x11_get_default_xdisplay(), - manager->priv->rotate_windows_keycode, AnyModifier, - gdk_x11_get_default_root_xwindow(), - True, GrabModeAsync, GrabModeAsync); - - gdk_flush (); - gdk_error_trap_pop (); - } - - show_timestamps_dialog (manager, "Startup"); - if (!apply_stored_configuration_at_startup (manager, GDK_CURRENT_TIME)) /* we don't have a real timestamp at startup anyway */ - if (!apply_default_configuration_from_file (manager, GDK_CURRENT_TIME)) - apply_default_boot_configuration (manager, GDK_CURRENT_TIME); - - log_msg ("State of screen after initial configuration:\n"); - log_screen (manager->priv->rw_screen); - - gdk_window_add_filter (gdk_get_default_root_window(), - (GdkFilterFunc)event_filter, - manager); - - start_or_stop_icon (manager); - - log_close (); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_xrandr_manager_stop (MsdXrandrManager *manager) -{ - g_debug ("Stopping xrandr manager"); - - manager->priv->running = FALSE; - - if (manager->priv->switch_video_mode_keycode) { - gdk_error_trap_push (); - - XUngrabKey (gdk_x11_get_default_xdisplay(), - manager->priv->switch_video_mode_keycode, AnyModifier, - gdk_x11_get_default_root_xwindow()); - - gdk_error_trap_pop (); - } - - if (manager->priv->rotate_windows_keycode) { - gdk_error_trap_push (); - - XUngrabKey (gdk_x11_get_default_xdisplay(), - manager->priv->rotate_windows_keycode, AnyModifier, - gdk_x11_get_default_root_xwindow()); - - gdk_error_trap_pop (); - } - - gdk_window_remove_filter (gdk_get_default_root_window (), - (GdkFilterFunc) event_filter, - manager); - - if (manager->priv->notify_id != 0) { - mateconf_client_remove_dir (manager->priv->client, - CONF_DIR, NULL); - mateconf_client_notify_remove (manager->priv->client, - manager->priv->notify_id); - manager->priv->notify_id = 0; - } - - if (manager->priv->client != NULL) { - g_object_unref (manager->priv->client); - manager->priv->client = NULL; - } - - if (manager->priv->rw_screen != NULL) { - mate_rr_screen_destroy (manager->priv->rw_screen); - manager->priv->rw_screen = NULL; - } - - if (manager->priv->dbus_connection != NULL) { - dbus_g_connection_unref (manager->priv->dbus_connection); - manager->priv->dbus_connection = NULL; - } - - status_icon_stop (manager); - - log_open (); - log_msg ("STOPPING XRANDR PLUGIN\n------------------------------------------------------------\n"); - log_close (); -} - -static void -msd_xrandr_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdXrandrManager *self; - - self = MSD_XRANDR_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_xrandr_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdXrandrManager *self; - - self = MSD_XRANDR_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_xrandr_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdXrandrManager *xrandr_manager; - MsdXrandrManagerClass *klass; - - klass = MSD_XRANDR_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_XRANDR_MANAGER)); - - xrandr_manager = MSD_XRANDR_MANAGER (G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (xrandr_manager); -} - -static void -msd_xrandr_manager_dispose (GObject *object) -{ - MsdXrandrManager *xrandr_manager; - - xrandr_manager = MSD_XRANDR_MANAGER (object); - - G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->dispose (object); -} - -static void -msd_xrandr_manager_class_init (MsdXrandrManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_xrandr_manager_get_property; - object_class->set_property = msd_xrandr_manager_set_property; - object_class->constructor = msd_xrandr_manager_constructor; - object_class->dispose = msd_xrandr_manager_dispose; - object_class->finalize = msd_xrandr_manager_finalize; - - dbus_g_object_type_install_info (MSD_TYPE_XRANDR_MANAGER, &dbus_glib_msd_xrandr_manager_object_info); - - g_type_class_add_private (klass, sizeof (MsdXrandrManagerPrivate)); -} - -static guint -get_keycode_for_keysym_name (const char *name) -{ - Display *dpy; - guint keyval; - - dpy = gdk_x11_get_default_xdisplay (); - - keyval = gdk_keyval_from_name (name); - return XKeysymToKeycode (dpy, keyval); -} - -static void -msd_xrandr_manager_init (MsdXrandrManager *manager) -{ - manager->priv = MSD_XRANDR_MANAGER_GET_PRIVATE (manager); - - manager->priv->switch_video_mode_keycode = get_keycode_for_keysym_name (VIDEO_KEYSYM); - manager->priv->rotate_windows_keycode = get_keycode_for_keysym_name (ROTATE_KEYSYM); - - manager->priv->current_fn_f7_config = -1; - manager->priv->fn_f7_configs = NULL; -} - -static void -msd_xrandr_manager_finalize (GObject *object) -{ - MsdXrandrManager *xrandr_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_XRANDR_MANAGER (object)); - - xrandr_manager = MSD_XRANDR_MANAGER (object); - - g_return_if_fail (xrandr_manager->priv != NULL); - - G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->finalize (object); -} - -static gboolean -register_manager_dbus (MsdXrandrManager *manager) -{ - GError *error = NULL; - - manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (manager->priv->dbus_connection == NULL) { - if (error != NULL) { - g_warning ("Error getting session bus: %s", error->message); - g_error_free (error); - } - return FALSE; - } - - /* Hmm, should we do this in msd_xrandr_manager_start()? */ - dbus_g_connection_register_g_object (manager->priv->dbus_connection, MSD_XRANDR_DBUS_PATH, G_OBJECT (manager)); - - return TRUE; -} - -MsdXrandrManager * -msd_xrandr_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_XRANDR_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - - if (!register_manager_dbus (manager_object)) { - g_object_unref (manager_object); - return NULL; - } - } - - return MSD_XRANDR_MANAGER (manager_object); -} diff --git a/plugins/xrandr/gsd-xrandr-manager.h b/plugins/xrandr/gsd-xrandr-manager.h deleted file mode 100644 index dbb5dff..0000000 --- a/plugins/xrandr/gsd-xrandr-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_XRANDR_MANAGER_H -#define __MSD_XRANDR_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_XRANDR_MANAGER (msd_xrandr_manager_get_type ()) -#define MSD_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManager)) -#define MSD_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerClass)) -#define MSD_IS_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRANDR_MANAGER)) -#define MSD_IS_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRANDR_MANAGER)) -#define MSD_XRANDR_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerClass)) - -typedef struct MsdXrandrManagerPrivate MsdXrandrManagerPrivate; - -typedef struct -{ - GObject parent; - MsdXrandrManagerPrivate *priv; -} MsdXrandrManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdXrandrManagerClass; - -GType msd_xrandr_manager_get_type (void); - -MsdXrandrManager * msd_xrandr_manager_new (void); -gboolean msd_xrandr_manager_start (MsdXrandrManager *manager, - GError **error); -void msd_xrandr_manager_stop (MsdXrandrManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_XRANDR_MANAGER_H */ diff --git a/plugins/xrandr/gsd-xrandr-manager.xml b/plugins/xrandr/gsd-xrandr-manager.xml deleted file mode 100644 index c82a594..0000000 --- a/plugins/xrandr/gsd-xrandr-manager.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/xrandr/gsd-xrandr-plugin.c b/plugins/xrandr/gsd-xrandr-plugin.c deleted file mode 100644 index 9e78124..0000000 --- a/plugins/xrandr/gsd-xrandr-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-xrandr-plugin.h" -#include "msd-xrandr-manager.h" - -struct MsdXrandrPluginPrivate { - MsdXrandrManager *manager; -}; - -#define MSD_XRANDR_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdXrandrPlugin, msd_xrandr_plugin) - -static void -msd_xrandr_plugin_init (MsdXrandrPlugin *plugin) -{ - plugin->priv = MSD_XRANDR_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdXrandrPlugin initializing"); - - plugin->priv->manager = msd_xrandr_manager_new (); -} - -static void -msd_xrandr_plugin_finalize (GObject *object) -{ - MsdXrandrPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_XRANDR_PLUGIN (object)); - - g_debug ("MsdXrandrPlugin finalizing"); - - plugin = MSD_XRANDR_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_xrandr_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating xrandr plugin"); - - error = NULL; - res = msd_xrandr_manager_start (MSD_XRANDR_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start xrandr manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating xrandr plugin"); - msd_xrandr_manager_stop (MSD_XRANDR_PLUGIN (plugin)->priv->manager); -} - -static void -msd_xrandr_plugin_class_init (MsdXrandrPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_xrandr_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdXrandrPluginPrivate)); -} diff --git a/plugins/xrandr/gsd-xrandr-plugin.h b/plugins/xrandr/gsd-xrandr-plugin.h deleted file mode 100644 index 62e742e..0000000 --- a/plugins/xrandr/gsd-xrandr-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_XRANDR_PLUGIN_H__ -#define __MSD_XRANDR_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_XRANDR_PLUGIN (msd_xrandr_plugin_get_type ()) -#define MSD_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPlugin)) -#define MSD_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginClass)) -#define MSD_IS_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRANDR_PLUGIN)) -#define MSD_IS_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRANDR_PLUGIN)) -#define MSD_XRANDR_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginClass)) - -typedef struct MsdXrandrPluginPrivate MsdXrandrPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdXrandrPluginPrivate *priv; -} MsdXrandrPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdXrandrPluginClass; - -GType msd_xrandr_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_XRANDR_PLUGIN_H__ */ diff --git a/plugins/xrandr/gsd-xrandr.svg b/plugins/xrandr/gsd-xrandr.svg deleted file mode 100644 index 0679b6b..0000000 --- a/plugins/xrandr/gsd-xrandr.svg +++ /dev/null @@ -1,470 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - Change Resolution - - - Jakub Steiner - - - - - - display - resolution - video - - - - - Andreas Nilsson -Luca Ferretti <elle.uca@libero.it> - - - - http://www.gnome.org - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/xrandr/msd-xrandr-16.png b/plugins/xrandr/msd-xrandr-16.png new file mode 100644 index 0000000..f996ddf Binary files /dev/null and b/plugins/xrandr/msd-xrandr-16.png differ diff --git a/plugins/xrandr/msd-xrandr-22.png b/plugins/xrandr/msd-xrandr-22.png new file mode 100644 index 0000000..cc47eec Binary files /dev/null and b/plugins/xrandr/msd-xrandr-22.png differ diff --git a/plugins/xrandr/msd-xrandr-24.png b/plugins/xrandr/msd-xrandr-24.png new file mode 100644 index 0000000..49b4e12 Binary files /dev/null and b/plugins/xrandr/msd-xrandr-24.png differ diff --git a/plugins/xrandr/msd-xrandr-32.png b/plugins/xrandr/msd-xrandr-32.png new file mode 100644 index 0000000..95de3ea Binary files /dev/null and b/plugins/xrandr/msd-xrandr-32.png differ diff --git a/plugins/xrandr/msd-xrandr-manager.c b/plugins/xrandr/msd-xrandr-manager.c new file mode 100644 index 0000000..dc00be1 --- /dev/null +++ b/plugins/xrandr/msd-xrandr-manager.c @@ -0,0 +1,2584 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * Copyright (C) 2007, 2008 Red Hat, Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define MATE_DESKTOP_USE_UNSTABLE_API + +#include +#include +#include + +#ifdef HAVE_LIBMATENOTIFY +#include +#endif + +#include "mate-settings-profile.h" +#include "msd-xrandr-manager.h" + +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX 255 +#endif + +#define MSD_XRANDR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerPrivate)) + +#define CONF_DIR "/apps/mate_settings_daemon/xrandr" +#define CONF_KEY_SHOW_NOTIFICATION_ICON (CONF_DIR "/show_notification_icon") +#define CONF_KEY_TURN_ON_EXTERNAL_MONITORS_AT_STARTUP (CONF_DIR "/turn_on_external_monitors_at_startup") +#define CONF_KEY_TURN_ON_LAPTOP_MONITOR_AT_STARTUP (CONF_DIR "/turn_on_laptop_monitor_at_startup") +#define CONF_KEY_DEFAULT_CONFIGURATION_FILE (CONF_DIR "/default_configuration_file") + +#define VIDEO_KEYSYM "XF86Display" +#define ROTATE_KEYSYM "XF86RotateWindows" + +/* Number of seconds that the confirmation dialog will last before it resets the + * RANDR configuration to its old state. + */ +#define CONFIRMATION_DIALOG_SECONDS 30 + +/* name of the icon files (msd-xrandr.svg, etc.) */ +#define MSD_XRANDR_ICON_NAME "msd-xrandr" + +/* executable of the control center's display configuration capplet */ +#define MSD_XRANDR_DISPLAY_CAPPLET "mate-control-center display" + +#define MSD_DBUS_PATH "/org/mate/SettingsDaemon" +#define MSD_DBUS_NAME "org.mate.SettingsDaemon" +#define MSD_XRANDR_DBUS_PATH MSD_DBUS_PATH "/XRANDR" +#define MSD_XRANDR_DBUS_NAME MSD_DBUS_NAME ".XRANDR" + +struct MsdXrandrManagerPrivate +{ + DBusGConnection *dbus_connection; + + /* Key code of the XF86Display key (Fn-F7 on Thinkpads, Fn-F4 on HP machines, etc.) */ + guint switch_video_mode_keycode; + + /* Key code of the XF86RotateWindows key (present on some tablets) */ + guint rotate_windows_keycode; + + MateRRScreen *rw_screen; + gboolean running; + + GtkStatusIcon *status_icon; + GtkWidget *popup_menu; + MateRRConfig *configuration; + MateRRLabeler *labeler; + MateConfClient *client; + int notify_id; + + /* fn-F7 status */ + int current_fn_f7_config; /* -1 if no configs */ + MateRRConfig **fn_f7_configs; /* NULL terminated, NULL if there are no configs */ + + /* Last time at which we got a "screen got reconfigured" event; see on_randr_event() */ + guint32 last_config_timestamp; +}; + +static const MateRRRotation possible_rotations[] = { + MATE_RR_ROTATION_0, + MATE_RR_ROTATION_90, + MATE_RR_ROTATION_180, + MATE_RR_ROTATION_270 + /* We don't allow REFLECT_X or REFLECT_Y for now, as mate-display-properties doesn't allow them, either */ +}; + +static void msd_xrandr_manager_class_init (MsdXrandrManagerClass *klass); +static void msd_xrandr_manager_init (MsdXrandrManager *xrandr_manager); +static void msd_xrandr_manager_finalize (GObject *object); + +static void error_message (MsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text); + +static void status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timestamp); +static void run_display_capplet (GtkWidget *widget); +static void get_allowed_rotations_for_output (MateRRConfig *config, + MateRRScreen *rr_screen, + MateOutputInfo *output, + int *out_num_rotations, + MateRRRotation *out_rotations); + +G_DEFINE_TYPE (MsdXrandrManager, msd_xrandr_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +static FILE *log_file; + +static void +log_open (void) +{ + char *toggle_filename; + char *log_filename; + struct stat st; + + if (log_file) + return; + + toggle_filename = g_build_filename (g_get_home_dir (), "msd-debug-randr", NULL); + log_filename = g_build_filename (g_get_home_dir (), "msd-debug-randr.log", NULL); + + if (stat (toggle_filename, &st) != 0) + goto out; + + log_file = fopen (log_filename, "a"); + + if (log_file && ftell (log_file) == 0) + fprintf (log_file, "To keep this log from being created, please rm ~/msd-debug-randr\n"); + +out: + g_free (toggle_filename); + g_free (log_filename); +} + +static void +log_close (void) +{ + if (log_file) { + fclose (log_file); + log_file = NULL; + } +} + +static void +log_msg (const char *format, ...) +{ + if (log_file) { + va_list args; + + va_start (args, format); + vfprintf (log_file, format, args); + va_end (args); + } +} + +static void +log_output (MateOutputInfo *output) +{ + log_msg (" %s: ", output->name ? output->name : "unknown"); + + if (output->connected) { + if (output->on) { + log_msg ("%dx%d@%d +%d+%d", + output->width, + output->height, + output->rate, + output->x, + output->y); + } else + log_msg ("off"); + } else + log_msg ("disconnected"); + + if (output->display_name) + log_msg (" (%s)", output->display_name); + + if (output->primary) + log_msg (" (primary output)"); + + log_msg ("\n"); +} + +static void +log_configuration (MateRRConfig *config) +{ + int i; + + log_msg (" cloned: %s\n", config->clone ? "yes" : "no"); + + for (i = 0; config->outputs[i] != NULL; i++) + log_output (config->outputs[i]); + + if (i == 0) + log_msg (" no outputs!\n"); +} + +static char +timestamp_relationship (guint32 a, guint32 b) +{ + if (a < b) + return '<'; + else if (a > b) + return '>'; + else + return '='; +} + +static void +log_screen (MateRRScreen *screen) +{ + MateRRConfig *config; + int min_w, min_h, max_w, max_h; + guint32 change_timestamp, config_timestamp; + + if (!log_file) + return; + + config = mate_rr_config_new_current (screen); + + mate_rr_screen_get_ranges (screen, &min_w, &max_w, &min_h, &max_h); + mate_rr_screen_get_timestamps (screen, &change_timestamp, &config_timestamp); + + log_msg (" Screen min(%d, %d), max(%d, %d), change=%u %c config=%u\n", + min_w, min_h, + max_w, max_h, + change_timestamp, + timestamp_relationship (change_timestamp, config_timestamp), + config_timestamp); + + log_configuration (config); + mate_rr_config_free (config); +} + +static void +log_configurations (MateRRConfig **configs) +{ + int i; + + if (!configs) { + log_msg (" No configurations\n"); + return; + } + + for (i = 0; configs[i]; i++) { + log_msg (" Configuration %d\n", i); + log_configuration (configs[i]); + } +} + +static void +show_timestamps_dialog (MsdXrandrManager *manager, const char *msg) +{ +#if 1 + return; +#else + struct MsdXrandrManagerPrivate *priv = manager->priv; + GtkWidget *dialog; + guint32 change_timestamp, config_timestamp; + static int serial; + + mate_rr_screen_get_timestamps (priv->rw_screen, &change_timestamp, &config_timestamp); + + dialog = gtk_message_dialog_new (NULL, + 0, + GTK_MESSAGE_INFO, + GTK_BUTTONS_CLOSE, + "RANDR timestamps (%d):\n%s\nchange: %u\nconfig: %u", + serial++, + msg, + change_timestamp, + config_timestamp); + g_signal_connect (dialog, "response", + G_CALLBACK (gtk_widget_destroy), NULL); + gtk_widget_show (dialog); +#endif +} + +/* This function centralizes the use of mate_rr_config_apply_from_filename_with_time(). + * + * Optionally filters out MATE_RR_ERROR_NO_MATCHING_CONFIG from + * mate_rr_config_apply_from_filename_with_time(), since that is not usually an error. + */ +static gboolean +apply_configuration_from_filename (MsdXrandrManager *manager, + const char *filename, + gboolean no_matching_config_is_an_error, + guint32 timestamp, + GError **error) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + GError *my_error; + gboolean success; + char *str; + + str = g_strdup_printf ("Applying %s with timestamp %d", filename, timestamp); + show_timestamps_dialog (manager, str); + g_free (str); + + my_error = NULL; + success = mate_rr_config_apply_from_filename_with_time (priv->rw_screen, filename, timestamp, &my_error); + if (success) + return TRUE; + + if (g_error_matches (my_error, MATE_RR_ERROR, MATE_RR_ERROR_NO_MATCHING_CONFIG)) { + if (no_matching_config_is_an_error) + goto fail; + + /* This is not an error; the user probably changed his monitors + * and so they don't match any of the stored configurations. + */ + g_error_free (my_error); + return TRUE; + } + +fail: + g_propagate_error (error, my_error); + return FALSE; +} + +/* This function centralizes the use of mate_rr_config_apply_with_time(). + * + * Applies a configuration and displays an error message if an error happens. + * We just return whether setting the configuration succeeded. + */ +static gboolean +apply_configuration_and_display_error (MsdXrandrManager *manager, MateRRConfig *config, guint32 timestamp) +{ + MsdXrandrManagerPrivate *priv = manager->priv; + GError *error; + gboolean success; + + error = NULL; + success = mate_rr_config_apply_with_time (config, priv->rw_screen, timestamp, &error); + if (!success) { + log_msg ("Could not switch to the following configuration (timestamp %u): %s\n", timestamp, error->message); + log_configuration (config); + error_message (manager, _("Could not switch the monitor configuration"), error, NULL); + g_error_free (error); + } + + return success; +} + +static void +restore_backup_configuration_without_messages (const char *backup_filename, const char *intended_filename) +{ + backup_filename = mate_rr_config_get_backup_filename (); + rename (backup_filename, intended_filename); +} + +static void +restore_backup_configuration (MsdXrandrManager *manager, const char *backup_filename, const char *intended_filename, guint32 timestamp) +{ + int saved_errno; + + if (rename (backup_filename, intended_filename) == 0) { + GError *error; + + error = NULL; + if (!apply_configuration_from_filename (manager, intended_filename, FALSE, timestamp, &error)) { + error_message (manager, _("Could not restore the display's configuration"), error, NULL); + + if (error) + g_error_free (error); + } + + return; + } + + saved_errno = errno; + + /* ENOENT means the original file didn't exist. That is *not* an error; + * the backup was not created because there wasn't even an original + * monitors.xml (such as on a first-time login). Note that *here* there + * is a "didn't work" monitors.xml, so we must delete that one. + */ + if (saved_errno == ENOENT) + unlink (intended_filename); + else { + char *msg; + + msg = g_strdup_printf ("Could not rename %s to %s: %s", + backup_filename, intended_filename, + g_strerror (saved_errno)); + error_message (manager, + _("Could not restore the display's configuration from a backup"), + NULL, + msg); + g_free (msg); + } + + unlink (backup_filename); +} + +typedef struct { + MsdXrandrManager *manager; + GtkWidget *dialog; + + int countdown; + int response_id; +} TimeoutDialog; + +static void +print_countdown_text (TimeoutDialog *timeout) +{ + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (timeout->dialog), + ngettext ("The display will be reset to its previous configuration in %d second", + "The display will be reset to its previous configuration in %d seconds", + timeout->countdown), + timeout->countdown); +} + +static gboolean +timeout_cb (gpointer data) +{ + TimeoutDialog *timeout = data; + + timeout->countdown--; + + if (timeout->countdown == 0) { + timeout->response_id = GTK_RESPONSE_CANCEL; + gtk_main_quit (); + } else { + print_countdown_text (timeout); + } + + return TRUE; +} + +static void +timeout_response_cb (GtkDialog *dialog, int response_id, gpointer data) +{ + TimeoutDialog *timeout = data; + + if (response_id == GTK_RESPONSE_DELETE_EVENT) { + /* The user closed the dialog or pressed ESC, revert */ + timeout->response_id = GTK_RESPONSE_CANCEL; + } else + timeout->response_id = response_id; + + gtk_main_quit (); +} + +static gboolean +user_says_things_are_ok (MsdXrandrManager *manager, GdkWindow *parent_window) +{ + TimeoutDialog timeout; + guint timeout_id; + + timeout.manager = manager; + + timeout.dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_MODAL, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("Does the display look OK?")); + + timeout.countdown = CONFIRMATION_DIALOG_SECONDS; + + print_countdown_text (&timeout); + + gtk_dialog_add_button (GTK_DIALOG (timeout.dialog), _("_Restore Previous Configuration"), GTK_RESPONSE_CANCEL); + gtk_dialog_add_button (GTK_DIALOG (timeout.dialog), _("_Keep This Configuration"), GTK_RESPONSE_ACCEPT); + gtk_dialog_set_default_response (GTK_DIALOG (timeout.dialog), GTK_RESPONSE_ACCEPT); /* ah, the optimism */ + + g_signal_connect (timeout.dialog, "response", + G_CALLBACK (timeout_response_cb), + &timeout); + + gtk_widget_realize (timeout.dialog); + + if (parent_window) + gdk_window_set_transient_for (gtk_widget_get_window (timeout.dialog), parent_window); + + gtk_widget_show_all (timeout.dialog); + /* We don't use g_timeout_add_seconds() since we actually care that the user sees "real" second ticks in the dialog */ + timeout_id = g_timeout_add (1000, + timeout_cb, + &timeout); + gtk_main (); + + gtk_widget_destroy (timeout.dialog); + g_source_remove (timeout_id); + + if (timeout.response_id == GTK_RESPONSE_ACCEPT) + return TRUE; + else + return FALSE; +} + +struct confirmation { + MsdXrandrManager *manager; + GdkWindow *parent_window; + guint32 timestamp; +}; + +static gboolean +confirm_with_user_idle_cb (gpointer data) +{ + struct confirmation *confirmation = data; + char *backup_filename; + char *intended_filename; + + backup_filename = mate_rr_config_get_backup_filename (); + intended_filename = mate_rr_config_get_intended_filename (); + + if (user_says_things_are_ok (confirmation->manager, confirmation->parent_window)) + unlink (backup_filename); + else + restore_backup_configuration (confirmation->manager, backup_filename, intended_filename, confirmation->timestamp); + + g_free (confirmation); + + return FALSE; +} + +static void +queue_confirmation_by_user (MsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp) +{ + struct confirmation *confirmation; + + confirmation = g_new (struct confirmation, 1); + confirmation->manager = manager; + confirmation->parent_window = parent_window; + confirmation->timestamp = timestamp; + + g_idle_add (confirm_with_user_idle_cb, confirmation); +} + +static gboolean +try_to_apply_intended_configuration (MsdXrandrManager *manager, GdkWindow *parent_window, guint32 timestamp, GError **error) +{ + char *backup_filename; + char *intended_filename; + gboolean result; + + /* Try to apply the intended configuration */ + + backup_filename = mate_rr_config_get_backup_filename (); + intended_filename = mate_rr_config_get_intended_filename (); + + result = apply_configuration_from_filename (manager, intended_filename, FALSE, timestamp, error); + if (!result) { + error_message (manager, _("The selected configuration for displays could not be applied"), error ? *error : NULL, NULL); + restore_backup_configuration_without_messages (backup_filename, intended_filename); + goto out; + } else { + /* We need to return as quickly as possible, so instead of + * confirming with the user right here, we do it in an idle + * handler. The caller only expects a status for "could you + * change the RANDR configuration?", not "is the user OK with it + * as well?". + */ + queue_confirmation_by_user (manager, parent_window, timestamp); + } + +out: + g_free (backup_filename); + g_free (intended_filename); + + return result; +} + +/* DBus method for org.mate.SettingsDaemon.XRANDR ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ +static gboolean +msd_xrandr_manager_apply_configuration (MsdXrandrManager *manager, + GError **error) +{ + return try_to_apply_intended_configuration (manager, NULL, GDK_CURRENT_TIME, error); +} + +/* DBus method for org.mate.SettingsDaemon.XRANDR_2 ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ +static gboolean +msd_xrandr_manager_2_apply_configuration (MsdXrandrManager *manager, + gint64 parent_window_id, + gint64 timestamp, + GError **error) +{ + GdkWindow *parent_window; + gboolean result; + + if (parent_window_id != 0) + parent_window = gdk_window_foreign_new_for_display (gdk_display_get_default (), (GdkNativeWindow) parent_window_id); + else + parent_window = NULL; + + result = try_to_apply_intended_configuration (manager, parent_window, (guint32) timestamp, error); + + if (parent_window) + g_object_unref (parent_window); + + return result; +} + +/* We include this after the definition of msd_xrandr_manager_apply_configuration() so the prototype will already exist */ +#include "msd-xrandr-manager-glue.h" + +static gboolean +is_laptop (MateRRScreen *screen, MateOutputInfo *output) +{ + MateRROutput *rr_output; + + rr_output = mate_rr_screen_get_output_by_name (screen, output->name); + return mate_rr_output_is_laptop (rr_output); +} + +static gboolean +get_clone_size (MateRRScreen *screen, int *width, int *height) +{ + MateRRMode **modes = mate_rr_screen_list_clone_modes (screen); + int best_w, best_h; + int i; + + best_w = 0; + best_h = 0; + + for (i = 0; modes[i] != NULL; ++i) { + MateRRMode *mode = modes[i]; + int w, h; + + w = mate_rr_mode_get_width (mode); + h = mate_rr_mode_get_height (mode); + + if (w * h > best_w * best_h) { + best_w = w; + best_h = h; + } + } + + if (best_w > 0 && best_h > 0) { + if (width) + *width = best_w; + if (height) + *height = best_h; + + return TRUE; + } + + return FALSE; +} + +static void +print_output (MateOutputInfo *info) +{ + g_print (" Output: %s attached to %s\n", info->display_name, info->name); + g_print (" status: %s\n", info->on ? "on" : "off"); + g_print (" width: %d\n", info->width); + g_print (" height: %d\n", info->height); + g_print (" rate: %d\n", info->rate); + g_print (" position: %d %d\n", info->x, info->y); +} + +static void +print_configuration (MateRRConfig *config, const char *header) +{ + int i; + + g_print ("=== %s Configuration ===\n", header); + if (!config) { + g_print (" none\n"); + return; + } + + for (i = 0; config->outputs[i] != NULL; ++i) + print_output (config->outputs[i]); +} + +static gboolean +config_is_all_off (MateRRConfig *config) +{ + int j; + + for (j = 0; config->outputs[j] != NULL; ++j) { + if (config->outputs[j]->on) { + return FALSE; + } + } + + return TRUE; +} + +static MateRRConfig * +make_clone_setup (MateRRScreen *screen) +{ + MateRRConfig *result; + int width, height; + int i; + + if (!get_clone_size (screen, &width, &height)) + return NULL; + + result = mate_rr_config_new_current (screen); + + for (i = 0; result->outputs[i] != NULL; ++i) { + MateOutputInfo *info = result->outputs[i]; + + info->on = FALSE; + if (info->connected) { + MateRROutput *output = + mate_rr_screen_get_output_by_name (screen, info->name); + MateRRMode **modes = mate_rr_output_list_modes (output); + int j; + int best_rate = 0; + + for (j = 0; modes[j] != NULL; ++j) { + MateRRMode *mode = modes[j]; + int w, h; + + w = mate_rr_mode_get_width (mode); + h = mate_rr_mode_get_height (mode); + + if (w == width && h == height) { + int r = mate_rr_mode_get_freq (mode); + if (r > best_rate) + best_rate = r; + } + } + + if (best_rate > 0) { + info->on = TRUE; + info->width = width; + info->height = height; + info->rate = best_rate; + info->rotation = MATE_RR_ROTATION_0; + info->x = 0; + info->y = 0; + } + } + } + + if (config_is_all_off (result)) { + mate_rr_config_free (result); + result = NULL; + } + + print_configuration (result, "clone setup"); + + return result; +} + +static MateRRMode * +find_best_mode (MateRROutput *output) +{ + MateRRMode *preferred; + MateRRMode **modes; + int best_size; + int best_width, best_height, best_rate; + int i; + MateRRMode *best_mode; + + preferred = mate_rr_output_get_preferred_mode (output); + if (preferred) + return preferred; + + modes = mate_rr_output_list_modes (output); + if (!modes) + return NULL; + + best_size = best_width = best_height = best_rate = 0; + best_mode = NULL; + + for (i = 0; modes[i] != NULL; i++) { + int w, h, r; + int size; + + w = mate_rr_mode_get_width (modes[i]); + h = mate_rr_mode_get_height (modes[i]); + r = mate_rr_mode_get_freq (modes[i]); + + size = w * h; + + if (size > best_size) { + best_size = size; + best_width = w; + best_height = h; + best_rate = r; + best_mode = modes[i]; + } else if (size == best_size) { + if (r > best_rate) { + best_rate = r; + best_mode = modes[i]; + } + } + } + + return best_mode; +} + +static gboolean +turn_on (MateRRScreen *screen, + MateOutputInfo *info, + int x, int y) +{ + MateRROutput *output = mate_rr_screen_get_output_by_name (screen, info->name); + MateRRMode *mode = find_best_mode (output); + + if (mode) { + info->on = TRUE; + info->x = x; + info->y = y; + info->width = mate_rr_mode_get_width (mode); + info->height = mate_rr_mode_get_height (mode); + info->rotation = MATE_RR_ROTATION_0; + info->rate = mate_rr_mode_get_freq (mode); + + return TRUE; + } + + return FALSE; +} + +static MateRRConfig * +make_laptop_setup (MateRRScreen *screen) +{ + /* Turn on the laptop, disable everything else */ + MateRRConfig *result = mate_rr_config_new_current (screen); + int i; + + for (i = 0; result->outputs[i] != NULL; ++i) { + MateOutputInfo *info = result->outputs[i]; + + if (is_laptop (screen, info)) { + if (!turn_on (screen, info, 0, 0)) { + mate_rr_config_free (result); + result = NULL; + break; + } + } + else { + info->on = FALSE; + } + } + + if (config_is_all_off (result)) { + mate_rr_config_free (result); + result = NULL; + } + + print_configuration (result, "Laptop setup"); + + /* FIXME - Maybe we should return NULL if there is more than + * one connected "laptop" screen? + */ + return result; + +} + +static int +turn_on_and_get_rightmost_offset (MateRRScreen *screen, MateOutputInfo *info, int x) +{ + if (turn_on (screen, info, x, 0)) + x += info->width; + + return x; +} + +static MateRRConfig * +make_xinerama_setup (MateRRScreen *screen) +{ + /* Turn on everything that has a preferred mode, and + * position it from left to right + */ + MateRRConfig *result = mate_rr_config_new_current (screen); + int i; + int x; + + x = 0; + for (i = 0; result->outputs[i] != NULL; ++i) { + MateOutputInfo *info = result->outputs[i]; + + if (is_laptop (screen, info)) + x = turn_on_and_get_rightmost_offset (screen, info, x); + } + + for (i = 0; result->outputs[i] != NULL; ++i) { + MateOutputInfo *info = result->outputs[i]; + + if (info->connected && !is_laptop (screen, info)) + x = turn_on_and_get_rightmost_offset (screen, info, x); + } + + if (config_is_all_off (result)) { + mate_rr_config_free (result); + result = NULL; + } + + print_configuration (result, "xinerama setup"); + + return result; +} + +static MateRRConfig * +make_other_setup (MateRRScreen *screen) +{ + /* Turn off all laptops, and make all external monitors clone + * from (0, 0) + */ + + MateRRConfig *result = mate_rr_config_new_current (screen); + int i; + + for (i = 0; result->outputs[i] != NULL; ++i) { + MateOutputInfo *info = result->outputs[i]; + + if (is_laptop (screen, info)) { + info->on = FALSE; + } + else { + if (info->connected) + turn_on (screen, info, 0, 0); + } + } + + if (config_is_all_off (result)) { + mate_rr_config_free (result); + result = NULL; + } + + print_configuration (result, "other setup"); + + return result; +} + +static GPtrArray * +sanitize (MsdXrandrManager *manager, GPtrArray *array) +{ + int i; + GPtrArray *new; + + g_debug ("before sanitizing"); + + for (i = 0; i < array->len; ++i) { + if (array->pdata[i]) { + print_configuration (array->pdata[i], "before"); + } + } + + + /* Remove configurations that are duplicates of + * configurations earlier in the cycle + */ + for (i = 0; i < array->len; i++) { + int j; + + for (j = i + 1; j < array->len; j++) { + MateRRConfig *this = array->pdata[j]; + MateRRConfig *other = array->pdata[i]; + + if (this && other && mate_rr_config_equal (this, other)) { + g_debug ("removing duplicate configuration"); + mate_rr_config_free (this); + array->pdata[j] = NULL; + break; + } + } + } + + for (i = 0; i < array->len; ++i) { + MateRRConfig *config = array->pdata[i]; + + if (config && config_is_all_off (config)) { + g_debug ("removing configuration as all outputs are off"); + mate_rr_config_free (array->pdata[i]); + array->pdata[i] = NULL; + } + } + + /* Do a final sanitization pass. This will remove configurations that + * don't fit in the framebuffer's Virtual size. + */ + + for (i = 0; i < array->len; i++) { + MateRRConfig *config = array->pdata[i]; + + if (config) { + GError *error; + + error = NULL; + if (!mate_rr_config_applicable (config, manager->priv->rw_screen, &error)) { /* NULL-GError */ + g_debug ("removing configuration which is not applicable because %s", error->message); + g_error_free (error); + + mate_rr_config_free (config); + array->pdata[i] = NULL; + } + } + } + + /* Remove NULL configurations */ + new = g_ptr_array_new (); + + for (i = 0; i < array->len; ++i) { + if (array->pdata[i]) { + g_ptr_array_add (new, array->pdata[i]); + print_configuration (array->pdata[i], "Final"); + } + } + + if (new->len > 0) { + g_ptr_array_add (new, NULL); + } else { + g_ptr_array_free (new, TRUE); + new = NULL; + } + + g_ptr_array_free (array, TRUE); + + return new; +} + +static void +generate_fn_f7_configs (MsdXrandrManager *mgr) +{ + GPtrArray *array = g_ptr_array_new (); + MateRRScreen *screen = mgr->priv->rw_screen; + + g_debug ("Generating configurations"); + + /* Free any existing list of configurations */ + if (mgr->priv->fn_f7_configs) { + int i; + + for (i = 0; mgr->priv->fn_f7_configs[i] != NULL; ++i) + mate_rr_config_free (mgr->priv->fn_f7_configs[i]); + g_free (mgr->priv->fn_f7_configs); + + mgr->priv->fn_f7_configs = NULL; + mgr->priv->current_fn_f7_config = -1; + } + + g_ptr_array_add (array, mate_rr_config_new_current (screen)); + g_ptr_array_add (array, make_clone_setup (screen)); + g_ptr_array_add (array, make_xinerama_setup (screen)); + g_ptr_array_add (array, make_laptop_setup (screen)); + g_ptr_array_add (array, make_other_setup (screen)); + + array = sanitize (mgr, array); + + if (array) { + mgr->priv->fn_f7_configs = (MateRRConfig **)g_ptr_array_free (array, FALSE); + mgr->priv->current_fn_f7_config = 0; + } +} + +static void +error_message (MsdXrandrManager *mgr, const char *primary_text, GError *error_to_display, const char *secondary_text) +{ +#ifdef HAVE_LIBMATENOTIFY + MsdXrandrManagerPrivate *priv = mgr->priv; + NotifyNotification *notification; + + g_assert (error_to_display == NULL || secondary_text == NULL); + + if (priv->status_icon) + notification = notify_notification_new_with_status_icon (primary_text, + error_to_display ? error_to_display->message : secondary_text, + MSD_XRANDR_ICON_NAME, + priv->status_icon); + else + notification = notify_notification_new (primary_text, + error_to_display ? error_to_display->message : secondary_text, + MSD_XRANDR_ICON_NAME, + NULL); + + notify_notification_show (notification, NULL); /* NULL-GError */ +#else + GtkWidget *dialog; + + dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s", primary_text); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", + error_to_display ? error_to_display->message : secondary_text); + + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +#endif /* HAVE_LIBMATENOTIFY */ +} + +static void +handle_fn_f7 (MsdXrandrManager *mgr, guint32 timestamp) +{ + MsdXrandrManagerPrivate *priv = mgr->priv; + MateRRScreen *screen = priv->rw_screen; + MateRRConfig *current; + GError *error; + + /* Theory of fn-F7 operation + * + * We maintain a datastructure "fn_f7_status", that contains + * a list of MateRRConfig's. Each of the MateRRConfigs has a + * mode (or "off") for each connected output. + * + * When the user hits fn-F7, we cycle to the next MateRRConfig + * in the data structure. If the data structure does not exist, it + * is generated. If the configs in the data structure do not match + * the current hardware reality, it is regenerated. + * + */ + g_debug ("Handling fn-f7"); + + log_open (); + log_msg ("Handling XF86Display hotkey - timestamp %u\n", timestamp); + + error = NULL; + if (!mate_rr_screen_refresh (screen, &error) && error) { + char *str; + + str = g_strdup_printf (_("Could not refresh the screen information: %s"), error->message); + g_error_free (error); + + log_msg ("%s\n", str); + error_message (mgr, str, NULL, _("Trying to switch the monitor configuration anyway.")); + g_free (str); + } + + if (!priv->fn_f7_configs) { + log_msg ("Generating stock configurations:\n"); + generate_fn_f7_configs (mgr); + log_configurations (priv->fn_f7_configs); + } + + current = mate_rr_config_new_current (screen); + + if (priv->fn_f7_configs && + (!mate_rr_config_match (current, priv->fn_f7_configs[0]) || + !mate_rr_config_equal (current, priv->fn_f7_configs[mgr->priv->current_fn_f7_config]))) { + /* Our view of the world is incorrect, so regenerate the + * configurations + */ + generate_fn_f7_configs (mgr); + log_msg ("Regenerated stock configurations:\n"); + log_configurations (priv->fn_f7_configs); + } + + mate_rr_config_free (current); + + if (priv->fn_f7_configs) { + guint32 server_timestamp; + gboolean success; + + mgr->priv->current_fn_f7_config++; + + if (priv->fn_f7_configs[mgr->priv->current_fn_f7_config] == NULL) + mgr->priv->current_fn_f7_config = 0; + + g_debug ("cycling to next configuration (%d)", mgr->priv->current_fn_f7_config); + + print_configuration (priv->fn_f7_configs[mgr->priv->current_fn_f7_config], "new config"); + + g_debug ("applying"); + + /* See https://bugzilla.gnome.org/show_bug.cgi?id=610482 + * + * Sometimes we'll get two rapid XF86Display keypress events, + * but their timestamps will be out of order with respect to the + * RANDR timestamps. This *may* be due to stupid BIOSes sending + * out display-switch keystrokes "to make Windows work". + * + * The X server will error out if the timestamp provided is + * older than a previous change configuration timestamp. We + * assume here that we do want this event to go through still, + * since kernel timestamps may be skewed wrt the X server. + */ + mate_rr_screen_get_timestamps (screen, NULL, &server_timestamp); + if (timestamp < server_timestamp) + timestamp = server_timestamp; + + success = apply_configuration_and_display_error (mgr, priv->fn_f7_configs[mgr->priv->current_fn_f7_config], timestamp); + + if (success) { + log_msg ("Successfully switched to configuration (timestamp %u):\n", timestamp); + log_configuration (priv->fn_f7_configs[mgr->priv->current_fn_f7_config]); + } + } + else { + g_debug ("no configurations generated"); + } + + log_close (); + + g_debug ("done handling fn-f7"); +} + +static MateOutputInfo * +get_laptop_output_info (MateRRScreen *screen, MateRRConfig *config) +{ + int i; + + for (i = 0; config->outputs[i] != NULL; i++) { + MateOutputInfo *info; + + info = config->outputs[i]; + if (is_laptop (screen, info)) + return info; + } + + return NULL; + +} + +static MateRRRotation +get_next_rotation (MateRRRotation allowed_rotations, MateRRRotation current_rotation) +{ + int i; + int current_index; + + /* First, find the index of the current rotation */ + + current_index = -1; + + for (i = 0; i < G_N_ELEMENTS (possible_rotations); i++) { + MateRRRotation r; + + r = possible_rotations[i]; + if (r == current_rotation) { + current_index = i; + break; + } + } + + if (current_index == -1) { + /* Huh, the current_rotation was not one of the supported rotations. Bail out. */ + return current_rotation; + } + + /* Then, find the next rotation that is allowed */ + + i = (current_index + 1) % G_N_ELEMENTS (possible_rotations); + + while (1) { + MateRRRotation r; + + r = possible_rotations[i]; + if (r == current_rotation) { + /* We wrapped around and no other rotation is suported. Bummer. */ + return current_rotation; + } else if (r & allowed_rotations) + return r; + + i = (i + 1) % G_N_ELEMENTS (possible_rotations); + } +} + +/* We use this when the XF86RotateWindows key is pressed. That key is present + * on some tablet PCs; they use it so that the user can rotate the tablet + * easily. + */ +static void +handle_rotate_windows (MsdXrandrManager *mgr, guint32 timestamp) +{ + MsdXrandrManagerPrivate *priv = mgr->priv; + MateRRScreen *screen = priv->rw_screen; + MateRRConfig *current; + MateOutputInfo *rotatable_output_info; + int num_allowed_rotations; + MateRRRotation allowed_rotations; + MateRRRotation next_rotation; + + g_debug ("Handling XF86RotateWindows"); + + /* Which output? */ + + current = mate_rr_config_new_current (screen); + + rotatable_output_info = get_laptop_output_info (screen, current); + if (rotatable_output_info == NULL) { + g_debug ("No laptop outputs found to rotate; XF86RotateWindows key will do nothing"); + goto out; + } + + /* Which rotation? */ + + get_allowed_rotations_for_output (current, priv->rw_screen, rotatable_output_info, &num_allowed_rotations, &allowed_rotations); + next_rotation = get_next_rotation (allowed_rotations, rotatable_output_info->rotation); + + if (next_rotation == rotatable_output_info->rotation) { + g_debug ("No rotations are supported other than the current one; XF86RotateWindows key will do nothing"); + goto out; + } + + /* Rotate */ + + rotatable_output_info->rotation = next_rotation; + + apply_configuration_and_display_error (mgr, current, timestamp); + +out: + mate_rr_config_free (current); +} + +static GdkFilterReturn +event_filter (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) +{ + MsdXrandrManager *manager = data; + XEvent *xev = (XEvent *) xevent; + + if (!manager->priv->running) + return GDK_FILTER_CONTINUE; + + /* verify we have a key event */ + if (xev->xany.type != KeyPress && xev->xany.type != KeyRelease) + return GDK_FILTER_CONTINUE; + + if (xev->xany.type == KeyPress) { + if (xev->xkey.keycode == manager->priv->switch_video_mode_keycode) + handle_fn_f7 (manager, xev->xkey.time); + else if (xev->xkey.keycode == manager->priv->rotate_windows_keycode) + handle_rotate_windows (manager, xev->xkey.time); + + return GDK_FILTER_CONTINUE; + } + + return GDK_FILTER_CONTINUE; +} + +static void +refresh_tray_icon_menu_if_active (MsdXrandrManager *manager, guint32 timestamp) +{ + MsdXrandrManagerPrivate *priv = manager->priv; + + if (priv->popup_menu) { + gtk_menu_shell_cancel (GTK_MENU_SHELL (priv->popup_menu)); /* status_icon_popup_menu_selection_done_cb() will free everything */ + status_icon_popup_menu (manager, 0, timestamp); + } +} + +static void +auto_configure_outputs (MsdXrandrManager *manager, guint32 timestamp) +{ + MsdXrandrManagerPrivate *priv = manager->priv; + MateRRConfig *config; + int i; + GList *just_turned_on; + GList *l; + int x; + GError *error; + gboolean applicable; + + config = mate_rr_config_new_current (priv->rw_screen); + + /* For outputs that are connected and on (i.e. they have a CRTC assigned + * to them, so they are getting a signal), we leave them as they are + * with their current modes. + * + * For other outputs, we will turn on connected-but-off outputs and turn + * off disconnected-but-on outputs. + * + * FIXME: If an output remained connected+on, it would be nice to ensure + * that the output's CRTCs still has a reasonable mode (think of + * changing one monitor for another with different capabilities). + */ + + just_turned_on = NULL; + + for (i = 0; config->outputs[i] != NULL; i++) { + MateOutputInfo *output = config->outputs[i]; + + if (output->connected && !output->on) { + output->on = TRUE; + output->rotation = MATE_RR_ROTATION_0; + just_turned_on = g_list_prepend (just_turned_on, GINT_TO_POINTER (i)); + } else if (!output->connected && output->on) + output->on = FALSE; + } + + /* Now, lay out the outputs from left to right. Put first the outputs + * which remained on; put last the outputs that were newly turned on. + */ + + x = 0; + + /* First, outputs that remained on */ + + for (i = 0; config->outputs[i] != NULL; i++) { + MateOutputInfo *output = config->outputs[i]; + + if (g_list_find (just_turned_on, GINT_TO_POINTER (i))) + continue; + + if (output->on) { + g_assert (output->connected); + + output->x = x; + output->y = 0; + + x += output->width; + } + } + + /* Second, outputs that were newly-turned on */ + + for (l = just_turned_on; l; l = l->next) { + MateOutputInfo *output; + + i = GPOINTER_TO_INT (l->data); + output = config->outputs[i]; + + g_assert (output->on && output->connected); + + output->x = x; + output->y = 0; + + /* since the output was off, use its preferred width/height (it doesn't have a real width/height yet) */ + output->width = output->pref_width; + output->height = output->pref_height; + + x += output->width; + } + + /* Check if we have a large enough framebuffer size. If not, turn off + * outputs from right to left until we reach a usable size. + */ + + just_turned_on = g_list_reverse (just_turned_on); /* now the outputs here are from right to left */ + + l = just_turned_on; + while (1) { + MateOutputInfo *output; + gboolean is_bounds_error; + + error = NULL; + applicable = mate_rr_config_applicable (config, priv->rw_screen, &error); + + if (applicable) + break; + + is_bounds_error = g_error_matches (error, MATE_RR_ERROR, MATE_RR_ERROR_BOUNDS_ERROR); + g_error_free (error); + + if (!is_bounds_error) + break; + + if (l) { + i = GPOINTER_TO_INT (l->data); + l = l->next; + + output = config->outputs[i]; + output->on = FALSE; + } else + break; + } + + /* Apply the configuration! */ + + if (applicable) + apply_configuration_and_display_error (manager, config, timestamp); + + g_list_free (just_turned_on); + mate_rr_config_free (config); + + /* Finally, even though we did a best-effort job in sanitizing the + * outputs, we don't know the physical layout of the monitors. We'll + * start the display capplet so that the user can tweak things to his + * liking. + */ + +#if 0 + /* FIXME: This is disabled for now. The capplet is not a single-instance application. + * If you do this: + * + * 1. Start the display capplet + * + * 2. Plug an extra monitor + * + * 3. Hit the "Detect displays" button + * + * Then we will get a RANDR event because X re-probes the outputs. We don't want to + * start up a second display capplet right there! + */ + + run_display_capplet (NULL); +#endif +} + +static void +apply_color_profiles (void) +{ + gboolean ret; + GError *error = NULL; + + /* run the mate-color-manager apply program */ + ret = g_spawn_command_line_async (BINDIR "/gcm-apply", &error); + if (!ret) { + /* only print the warning if the binary is installed */ + if (error->code != G_SPAWN_ERROR_NOENT) { + g_warning ("failed to apply color profiles: %s", error->message); + } + g_error_free (error); + } +} + +static void +on_randr_event (MateRRScreen *screen, gpointer data) +{ + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + MsdXrandrManagerPrivate *priv = manager->priv; + guint32 change_timestamp, config_timestamp; + + if (!priv->running) + return; + + mate_rr_screen_get_timestamps (screen, &change_timestamp, &config_timestamp); + + log_open (); + log_msg ("Got RANDR event with timestamps change=%u %c config=%u\n", + change_timestamp, + timestamp_relationship (change_timestamp, config_timestamp), + config_timestamp); + + if (change_timestamp >= config_timestamp) { + /* The event is due to an explicit configuration change. + * + * If the change was performed by us, then we need to do nothing. + * + * If the change was done by some other X client, we don't need + * to do anything, either; the screen is already configured. + */ + show_timestamps_dialog (manager, "ignoring since change > config"); + log_msg (" Ignoring event since change >= config\n"); + } else { + /* Here, config_timestamp > change_timestamp. This means that + * the screen got reconfigured because of hotplug/unplug; the X + * server is just notifying us, and we need to configure the + * outputs in a sane way. + */ + + char *intended_filename; + GError *error; + gboolean success; + + show_timestamps_dialog (manager, "need to deal with reconfiguration, as config > change"); + + intended_filename = mate_rr_config_get_intended_filename (); + + error = NULL; + success = apply_configuration_from_filename (manager, intended_filename, TRUE, config_timestamp, &error); + g_free (intended_filename); + + if (!success) { + /* We don't bother checking the error type. + * + * Both G_FILE_ERROR_NOENT and + * MATE_RR_ERROR_NO_MATCHING_CONFIG would mean, "there + * was no configuration to apply, or none that matched + * the current outputs", and in that case we need to run + * our fallback. + * + * Any other error means "we couldn't do the smart thing + * of using a previously- saved configuration, anyway, + * for some other reason. In that case, we also need to + * run our fallback to avoid leaving the user with a + * bogus configuration. + */ + + if (error) + g_error_free (error); + + if (config_timestamp != priv->last_config_timestamp) { + priv->last_config_timestamp = config_timestamp; + auto_configure_outputs (manager, config_timestamp); + log_msg (" Automatically configured outputs to deal with event\n"); + } else + log_msg (" Ignored event as old and new config timestamps are the same\n"); + } else + log_msg ("Applied stored configuration to deal with event\n"); + } + + /* poke mate-color-manager */ + apply_color_profiles (); + + refresh_tray_icon_menu_if_active (manager, MAX (change_timestamp, config_timestamp)); + + log_close (); +} + +static void +run_display_capplet (GtkWidget *widget) +{ + GdkScreen *screen; + GError *error; + + if (widget) + screen = gtk_widget_get_screen (widget); + else + screen = gdk_screen_get_default (); + + error = NULL; + if (!gdk_spawn_command_line_on_screen (screen, MSD_XRANDR_DISPLAY_CAPPLET, &error)) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "" + "Display configuration could not be run" + "\n\n" + "%s", error->message); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + g_error_free (error); + } +} + +static void +popup_menu_configure_display_cb (GtkMenuItem *item, gpointer data) +{ + run_display_capplet (GTK_WIDGET (item)); +} + +static void +status_icon_popup_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer data) +{ + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + struct MsdXrandrManagerPrivate *priv = manager->priv; + + gtk_widget_destroy (priv->popup_menu); + priv->popup_menu = NULL; + + mate_rr_labeler_hide (priv->labeler); + g_object_unref (priv->labeler); + priv->labeler = NULL; + + mate_rr_config_free (priv->configuration); + priv->configuration = NULL; +} + +#define OUTPUT_TITLE_ITEM_BORDER 2 +#define OUTPUT_TITLE_ITEM_PADDING 4 + +/* This is an expose-event hander for the title label for each MateRROutput. + * We want each title to have a colored background, so we paint that background, then + * return FALSE to let GtkLabel expose itself (i.e. paint the label's text), and then + * we have a signal_connect_after handler as well. See the comments below + * to see why that "after" handler is needed. + */ +static gboolean +output_title_label_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + struct MsdXrandrManagerPrivate *priv = manager->priv; + MateOutputInfo *output; + GdkColor color; + cairo_t *cr; + GtkAllocation allocation; + + g_assert (GTK_IS_LABEL (widget)); + + output = g_object_get_data (G_OBJECT (widget), "output"); + g_assert (output != NULL); + + g_assert (priv->labeler != NULL); + + /* Draw a black rectangular border, filled with the color that corresponds to this output */ + + mate_rr_labeler_get_color_for_output (priv->labeler, output, &color); + + cr = gdk_cairo_create (gtk_widget_get_window (widget)); + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_set_line_width (cr, OUTPUT_TITLE_ITEM_BORDER); + gtk_widget_get_allocation (widget, &allocation); + cairo_rectangle (cr, + allocation.x + OUTPUT_TITLE_ITEM_BORDER / 2.0, + allocation.y + OUTPUT_TITLE_ITEM_BORDER / 2.0, + allocation.width - OUTPUT_TITLE_ITEM_BORDER, + allocation.height - OUTPUT_TITLE_ITEM_BORDER); + cairo_stroke (cr); + + gdk_cairo_set_source_color (cr, &color); + cairo_rectangle (cr, + allocation.x + OUTPUT_TITLE_ITEM_BORDER, + allocation.y + OUTPUT_TITLE_ITEM_BORDER, + allocation.width - 2 * OUTPUT_TITLE_ITEM_BORDER, + allocation.height - 2 * OUTPUT_TITLE_ITEM_BORDER); + + cairo_fill (cr); + + /* We want the label to always show up as if it were sensitive + * ("style->fg[GTK_STATE_NORMAL]"), even though the label is insensitive + * due to being inside an insensitive menu item. So, here we have a + * HACK in which we frob the label's state directly. GtkLabel's expose + * handler will be run after this function, so it will think that the + * label is in GTK_STATE_NORMAL. We reset the label's state back to + * insensitive in output_title_label_after_expose_event_cb(). + * + * Yay for fucking with GTK+'s internals. + */ + + gtk_widget_set_state (widget, GTK_STATE_NORMAL); + + return FALSE; +} + +/* See the comment in output_title_event_box_expose_event_cb() about this funny label widget */ +static gboolean +output_title_label_after_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + g_assert (GTK_IS_LABEL (widget)); + gtk_widget_set_state (widget, GTK_STATE_INSENSITIVE); + + return FALSE; +} + +static void +title_item_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer data) +{ + /* When GtkMenu does size_request on its items, it asks them for their "toggle size", + * which will be non-zero when there are check/radio items. GtkMenu remembers + * the largest of those sizes. During the size_allocate pass, GtkMenu calls + * gtk_menu_item_toggle_size_allocate() with that value, to tell the menu item + * that it should later paint its child a bit to the right of its edge. + * + * However, we want the "title" menu items for each RANDR output to span the *whole* + * allocation of the menu item, not just the "allocation minus toggle" area. + * + * So, we let the menu item size_allocate itself as usual, but this + * callback gets run afterward. Here we hack a toggle size of 0 into + * the menu item, and size_allocate it by hand *again*. We also need to + * avoid recursing into this function. + */ + + g_assert (GTK_IS_MENU_ITEM (widget)); + + gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (widget), 0); + + g_signal_handlers_block_by_func (widget, title_item_size_allocate_cb, NULL); + + /* Sigh. There is no way to turn on GTK_ALLOC_NEEDED outside of GTK+ + * itself; also, since calling size_allocate on a widget with the same + * allcation is a no-op, we need to allocate with a "different" size + * first. + */ + + allocation->width++; + gtk_widget_size_allocate (widget, allocation); + + allocation->width--; + gtk_widget_size_allocate (widget, allocation); + + g_signal_handlers_unblock_by_func (widget, title_item_size_allocate_cb, NULL); +} + +static GtkWidget * +make_menu_item_for_output_title (MsdXrandrManager *manager, MateOutputInfo *output) +{ + GtkWidget *item; + GtkWidget *label; + char *str; + GdkColor black = { 0, 0, 0, 0 }; + + item = gtk_menu_item_new (); + + g_signal_connect (item, "size-allocate", + G_CALLBACK (title_item_size_allocate_cb), NULL); + + str = g_markup_printf_escaped ("%s", output->display_name); + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), str); + g_free (str); + + /* Make the label explicitly black. We don't want it to follow the + * theme's colors, since the label is always shown against a light + * pastel background. See bgo#556050 + */ + gtk_widget_modify_fg (label, gtk_widget_get_state (label), &black); + + /* Add padding around the label to fit the box that we'll draw for color-coding */ + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_misc_set_padding (GTK_MISC (label), + OUTPUT_TITLE_ITEM_BORDER + OUTPUT_TITLE_ITEM_PADDING, + OUTPUT_TITLE_ITEM_BORDER + OUTPUT_TITLE_ITEM_PADDING); + + gtk_container_add (GTK_CONTAINER (item), label); + + /* We want to paint a colored box as the background of the label, so we connect + * to its expose-event signal. See the comment in *** to see why need to connect + * to the label both 'before' and 'after'. + */ + g_signal_connect (label, "expose-event", + G_CALLBACK (output_title_label_expose_event_cb), manager); + g_signal_connect_after (label, "expose-event", + G_CALLBACK (output_title_label_after_expose_event_cb), manager); + + g_object_set_data (G_OBJECT (label), "output", output); + + gtk_widget_set_sensitive (item, FALSE); /* the title is not selectable */ + gtk_widget_show_all (item); + + return item; +} + +static void +get_allowed_rotations_for_output (MateRRConfig *config, + MateRRScreen *rr_screen, + MateOutputInfo *output, + int *out_num_rotations, + MateRRRotation *out_rotations) +{ + MateRRRotation current_rotation; + int i; + + *out_num_rotations = 0; + *out_rotations = 0; + + current_rotation = output->rotation; + + /* Yay for brute force */ + + for (i = 0; i < G_N_ELEMENTS (possible_rotations); i++) { + MateRRRotation rotation_to_test; + + rotation_to_test = possible_rotations[i]; + + output->rotation = rotation_to_test; + + if (mate_rr_config_applicable (config, rr_screen, NULL)) { /* NULL-GError */ + (*out_num_rotations)++; + (*out_rotations) |= rotation_to_test; + } + } + + output->rotation = current_rotation; + + if (*out_num_rotations == 0 || *out_rotations == 0) { + g_warning ("Huh, output %p says it doesn't support any rotations, and yet it has a current rotation?", output); + *out_num_rotations = 1; + *out_rotations = output->rotation; + } +} + +static void +add_unsupported_rotation_item (MsdXrandrManager *manager) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + GtkWidget *item; + GtkWidget *label; + gchar *markup; + + item = gtk_menu_item_new (); + + label = gtk_label_new (NULL); + markup = g_strdup_printf ("%s", _("Rotation not supported")); + gtk_label_set_markup (GTK_LABEL (label), markup); + g_free (markup); + gtk_container_add (GTK_CONTAINER (item), label); + + gtk_widget_show_all (item); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); +} + +static void +ensure_current_configuration_is_saved (void) +{ + MateRRScreen *rr_screen; + MateRRConfig *rr_config; + + /* Normally, mate_rr_config_save() creates a backup file based on the + * old monitors.xml. However, if *that* file didn't exist, there is + * nothing from which to create a backup. So, here we'll save the + * current/unchanged configuration and then let our caller call + * mate_rr_config_save() again with the new/changed configuration, so + * that there *will* be a backup file in the end. + */ + + rr_screen = mate_rr_screen_new (gdk_screen_get_default (), NULL, NULL, NULL); /* NULL-GError */ + if (!rr_screen) + return; + + rr_config = mate_rr_config_new_current (rr_screen); + mate_rr_config_save (rr_config, NULL); /* NULL-GError */ + + mate_rr_config_free (rr_config); + mate_rr_screen_destroy (rr_screen); +} + +static void +output_rotation_item_activate_cb (GtkCheckMenuItem *item, gpointer data) +{ + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + struct MsdXrandrManagerPrivate *priv = manager->priv; + MateOutputInfo *output; + MateRRRotation rotation; + GError *error; + + /* Not interested in deselected items */ + if (!gtk_check_menu_item_get_active (item)) + return; + + ensure_current_configuration_is_saved (); + + output = g_object_get_data (G_OBJECT (item), "output"); + rotation = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "rotation")); + + output->rotation = rotation; + + error = NULL; + if (!mate_rr_config_save (priv->configuration, &error)) { + error_message (manager, _("Could not save monitor configuration"), error, NULL); + if (error) + g_error_free (error); + + return; + } + + try_to_apply_intended_configuration (manager, NULL, gtk_get_current_event_time (), NULL); /* NULL-GError */ +} + +static void +add_items_for_rotations (MsdXrandrManager *manager, MateOutputInfo *output, MateRRRotation allowed_rotations) +{ + typedef struct { + MateRRRotation rotation; + const char * name; + } RotationInfo; + static const RotationInfo rotations[] = { + { MATE_RR_ROTATION_0, N_("Normal") }, + { MATE_RR_ROTATION_90, N_("Left") }, + { MATE_RR_ROTATION_270, N_("Right") }, + { MATE_RR_ROTATION_180, N_("Upside Down") }, + /* We don't allow REFLECT_X or REFLECT_Y for now, as mate-display-properties doesn't allow them, either */ + }; + + struct MsdXrandrManagerPrivate *priv = manager->priv; + int i; + GSList *group; + GtkWidget *active_item; + gulong active_item_activate_id; + + group = NULL; + active_item = NULL; + active_item_activate_id = 0; + + for (i = 0; i < G_N_ELEMENTS (rotations); i++) { + MateRRRotation rot; + GtkWidget *item; + gulong activate_id; + + rot = rotations[i].rotation; + + if ((allowed_rotations & rot) == 0) { + /* don't display items for rotations which are + * unavailable. Their availability is not under the + * user's control, anyway. + */ + continue; + } + + item = gtk_radio_menu_item_new_with_label (group, _(rotations[i].name)); + gtk_widget_show_all (item); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); + + g_object_set_data (G_OBJECT (item), "output", output); + g_object_set_data (G_OBJECT (item), "rotation", GINT_TO_POINTER (rot)); + + activate_id = g_signal_connect (item, "activate", + G_CALLBACK (output_rotation_item_activate_cb), manager); + + group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item)); + + if (rot == output->rotation) { + active_item = item; + active_item_activate_id = activate_id; + } + } + + if (active_item) { + /* Block the signal temporarily so our callback won't be called; + * we are just setting up the UI. + */ + g_signal_handler_block (active_item, active_item_activate_id); + + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (active_item), TRUE); + + g_signal_handler_unblock (active_item, active_item_activate_id); + } + +} + +static void +add_rotation_items_for_output (MsdXrandrManager *manager, MateOutputInfo *output) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + int num_rotations; + MateRRRotation rotations; + + get_allowed_rotations_for_output (priv->configuration, priv->rw_screen, output, &num_rotations, &rotations); + + if (num_rotations == 1) + add_unsupported_rotation_item (manager); + else + add_items_for_rotations (manager, output, rotations); +} + +static void +add_menu_items_for_output (MsdXrandrManager *manager, MateOutputInfo *output) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + GtkWidget *item; + + item = make_menu_item_for_output_title (manager, output); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); + + add_rotation_items_for_output (manager, output); +} + +static void +add_menu_items_for_outputs (MsdXrandrManager *manager) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + int i; + + for (i = 0; priv->configuration->outputs[i] != NULL; i++) { + if (priv->configuration->outputs[i]->connected) + add_menu_items_for_output (manager, priv->configuration->outputs[i]); + } +} + +static void +status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timestamp) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + GtkWidget *item; + + g_assert (priv->configuration == NULL); + priv->configuration = mate_rr_config_new_current (priv->rw_screen); + + g_assert (priv->labeler == NULL); + priv->labeler = mate_rr_labeler_new (priv->configuration); + + g_assert (priv->popup_menu == NULL); + priv->popup_menu = gtk_menu_new (); + + add_menu_items_for_outputs (manager); + + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); + + item = gtk_menu_item_new_with_mnemonic (_("_Configure Display Settings…")); + g_signal_connect (item, "activate", + G_CALLBACK (popup_menu_configure_display_cb), manager); + gtk_widget_show (item); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); + + g_signal_connect (priv->popup_menu, "selection-done", + G_CALLBACK (status_icon_popup_menu_selection_done_cb), manager); + + gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL, + gtk_status_icon_position_menu, + priv->status_icon, button, timestamp); +} + +static void +status_icon_activate_cb (GtkStatusIcon *status_icon, gpointer data) +{ + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + + /* Suck; we don't get a proper button/timestamp */ + status_icon_popup_menu (manager, 0, gtk_get_current_event_time ()); +} + +static void +status_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 timestamp, gpointer data) +{ + MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data); + + status_icon_popup_menu (manager, button, timestamp); +} + +static void +status_icon_start (MsdXrandrManager *manager) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + + /* Ideally, we should detect if we are on a tablet and only display + * the icon in that case. + */ + if (!priv->status_icon) { + priv->status_icon = gtk_status_icon_new_from_icon_name (MSD_XRANDR_ICON_NAME); + gtk_status_icon_set_tooltip_text (priv->status_icon, _("Configure display settings")); + + g_signal_connect (priv->status_icon, "activate", + G_CALLBACK (status_icon_activate_cb), manager); + g_signal_connect (priv->status_icon, "popup-menu", + G_CALLBACK (status_icon_popup_menu_cb), manager); + } +} + +static void +status_icon_stop (MsdXrandrManager *manager) +{ + struct MsdXrandrManagerPrivate *priv = manager->priv; + + if (priv->status_icon) { + g_signal_handlers_disconnect_by_func ( + priv->status_icon, G_CALLBACK (status_icon_activate_cb), manager); + g_signal_handlers_disconnect_by_func ( + priv->status_icon, G_CALLBACK (status_icon_popup_menu_cb), manager); + + /* hide the icon before unreffing it; otherwise we will leak + whitespace in the notification area due to a bug in there */ + gtk_status_icon_set_visible (priv->status_icon, FALSE); + g_object_unref (priv->status_icon); + priv->status_icon = NULL; + } +} + +static void +start_or_stop_icon (MsdXrandrManager *manager) +{ + if (mateconf_client_get_bool (manager->priv->client, CONF_KEY_SHOW_NOTIFICATION_ICON, NULL)) { + status_icon_start (manager); + } + else { + status_icon_stop (manager); + } +} + +static void +on_config_changed (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MsdXrandrManager *manager) +{ + if (strcmp (entry->key, CONF_KEY_SHOW_NOTIFICATION_ICON) == 0) + start_or_stop_icon (manager); +} + +static gboolean +apply_intended_configuration (MsdXrandrManager *manager, const char *intended_filename, guint32 timestamp) +{ + GError *my_error; + gboolean result; + + my_error = NULL; + result = apply_configuration_from_filename (manager, intended_filename, FALSE, timestamp, &my_error); + if (!result) { + if (my_error) { + if (!g_error_matches (my_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) + error_message (manager, _("Could not apply the stored configuration for monitors"), my_error, NULL); + + g_error_free (my_error); + } + } + + return result; +} + +static void +apply_default_boot_configuration (MsdXrandrManager *mgr, guint32 timestamp) +{ + MsdXrandrManagerPrivate *priv = mgr->priv; + MateRRScreen *screen = priv->rw_screen; + MateRRConfig *config; + gboolean turn_on_external, turn_on_laptop; + + turn_on_external = + mateconf_client_get_bool (mgr->priv->client, CONF_KEY_TURN_ON_EXTERNAL_MONITORS_AT_STARTUP, NULL); + turn_on_laptop = + mateconf_client_get_bool (mgr->priv->client, CONF_KEY_TURN_ON_LAPTOP_MONITOR_AT_STARTUP, NULL); + + if (turn_on_external && turn_on_laptop) + config = make_clone_setup (screen); + else if (!turn_on_external && turn_on_laptop) + config = make_laptop_setup (screen); + else if (turn_on_external && !turn_on_laptop) + config = make_other_setup (screen); + else + config = make_laptop_setup (screen); + + if (config) { + apply_configuration_and_display_error (mgr, config, timestamp); + mate_rr_config_free (config); + } +} + +static gboolean +apply_stored_configuration_at_startup (MsdXrandrManager *manager, guint32 timestamp) +{ + GError *my_error; + gboolean success; + char *backup_filename; + char *intended_filename; + + backup_filename = mate_rr_config_get_backup_filename (); + intended_filename = mate_rr_config_get_intended_filename (); + + /* 1. See if there was a "saved" configuration. If there is one, it means + * that the user had selected to change the display configuration, but the + * machine crashed. In that case, we'll apply *that* configuration and save it on top of the + * "intended" one. + */ + + my_error = NULL; + + success = apply_configuration_from_filename (manager, backup_filename, FALSE, timestamp, &my_error); + if (success) { + /* The backup configuration existed, and could be applied + * successfully, so we must restore it on top of the + * failed/intended one. + */ + restore_backup_configuration (manager, backup_filename, intended_filename, timestamp); + goto out; + } + + if (!g_error_matches (my_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + /* Epic fail: there (probably) was a backup configuration, but + * we could not apply it. The only thing we can do is delete + * the backup configuration. Let's hope that the user doesn't + * get left with an unusable display... + */ + + unlink (backup_filename); + goto out; + } + + /* 2. There was no backup configuration! This means we are + * good. Apply the intended configuration instead. + */ + + success = apply_intended_configuration (manager, intended_filename, timestamp); + +out: + + if (my_error) + g_error_free (my_error); + + g_free (backup_filename); + g_free (intended_filename); + + return success; +} + +static gboolean +apply_default_configuration_from_file (MsdXrandrManager *manager, guint32 timestamp) +{ + MsdXrandrManagerPrivate *priv = manager->priv; + char *default_config_filename; + gboolean result; + + default_config_filename = mateconf_client_get_string (priv->client, CONF_KEY_DEFAULT_CONFIGURATION_FILE, NULL); + if (!default_config_filename) + return FALSE; + + result = apply_configuration_from_filename (manager, default_config_filename, TRUE, timestamp, NULL); + + g_free (default_config_filename); + return result; +} + +gboolean +msd_xrandr_manager_start (MsdXrandrManager *manager, + GError **error) +{ + g_debug ("Starting xrandr manager"); + mate_settings_profile_start (NULL); + + log_open (); + log_msg ("------------------------------------------------------------\nSTARTING XRANDR PLUGIN\n"); + + manager->priv->rw_screen = mate_rr_screen_new ( + gdk_screen_get_default (), on_randr_event, manager, error); + + if (manager->priv->rw_screen == NULL) { + log_msg ("Could not initialize the RANDR plugin%s%s\n", + (error && *error) ? ": " : "", + (error && *error) ? (*error)->message : ""); + log_close (); + return FALSE; + } + + log_msg ("State of screen at startup:\n"); + log_screen (manager->priv->rw_screen); + + manager->priv->running = TRUE; + manager->priv->client = mateconf_client_get_default (); + + g_assert (manager->priv->notify_id == 0); + + mateconf_client_add_dir (manager->priv->client, CONF_DIR, + MATECONF_CLIENT_PRELOAD_ONELEVEL, + NULL); + + manager->priv->notify_id = + mateconf_client_notify_add ( + manager->priv->client, CONF_DIR, + (MateConfClientNotifyFunc)on_config_changed, + manager, NULL, NULL); + + if (manager->priv->switch_video_mode_keycode) { + gdk_error_trap_push (); + + XGrabKey (gdk_x11_get_default_xdisplay(), + manager->priv->switch_video_mode_keycode, AnyModifier, + gdk_x11_get_default_root_xwindow(), + True, GrabModeAsync, GrabModeAsync); + + gdk_flush (); + gdk_error_trap_pop (); + } + + if (manager->priv->rotate_windows_keycode) { + gdk_error_trap_push (); + + XGrabKey (gdk_x11_get_default_xdisplay(), + manager->priv->rotate_windows_keycode, AnyModifier, + gdk_x11_get_default_root_xwindow(), + True, GrabModeAsync, GrabModeAsync); + + gdk_flush (); + gdk_error_trap_pop (); + } + + show_timestamps_dialog (manager, "Startup"); + if (!apply_stored_configuration_at_startup (manager, GDK_CURRENT_TIME)) /* we don't have a real timestamp at startup anyway */ + if (!apply_default_configuration_from_file (manager, GDK_CURRENT_TIME)) + apply_default_boot_configuration (manager, GDK_CURRENT_TIME); + + log_msg ("State of screen after initial configuration:\n"); + log_screen (manager->priv->rw_screen); + + gdk_window_add_filter (gdk_get_default_root_window(), + (GdkFilterFunc)event_filter, + manager); + + start_or_stop_icon (manager); + + log_close (); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_xrandr_manager_stop (MsdXrandrManager *manager) +{ + g_debug ("Stopping xrandr manager"); + + manager->priv->running = FALSE; + + if (manager->priv->switch_video_mode_keycode) { + gdk_error_trap_push (); + + XUngrabKey (gdk_x11_get_default_xdisplay(), + manager->priv->switch_video_mode_keycode, AnyModifier, + gdk_x11_get_default_root_xwindow()); + + gdk_error_trap_pop (); + } + + if (manager->priv->rotate_windows_keycode) { + gdk_error_trap_push (); + + XUngrabKey (gdk_x11_get_default_xdisplay(), + manager->priv->rotate_windows_keycode, AnyModifier, + gdk_x11_get_default_root_xwindow()); + + gdk_error_trap_pop (); + } + + gdk_window_remove_filter (gdk_get_default_root_window (), + (GdkFilterFunc) event_filter, + manager); + + if (manager->priv->notify_id != 0) { + mateconf_client_remove_dir (manager->priv->client, + CONF_DIR, NULL); + mateconf_client_notify_remove (manager->priv->client, + manager->priv->notify_id); + manager->priv->notify_id = 0; + } + + if (manager->priv->client != NULL) { + g_object_unref (manager->priv->client); + manager->priv->client = NULL; + } + + if (manager->priv->rw_screen != NULL) { + mate_rr_screen_destroy (manager->priv->rw_screen); + manager->priv->rw_screen = NULL; + } + + if (manager->priv->dbus_connection != NULL) { + dbus_g_connection_unref (manager->priv->dbus_connection); + manager->priv->dbus_connection = NULL; + } + + status_icon_stop (manager); + + log_open (); + log_msg ("STOPPING XRANDR PLUGIN\n------------------------------------------------------------\n"); + log_close (); +} + +static void +msd_xrandr_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdXrandrManager *self; + + self = MSD_XRANDR_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_xrandr_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdXrandrManager *self; + + self = MSD_XRANDR_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_xrandr_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdXrandrManager *xrandr_manager; + MsdXrandrManagerClass *klass; + + klass = MSD_XRANDR_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_XRANDR_MANAGER)); + + xrandr_manager = MSD_XRANDR_MANAGER (G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (xrandr_manager); +} + +static void +msd_xrandr_manager_dispose (GObject *object) +{ + MsdXrandrManager *xrandr_manager; + + xrandr_manager = MSD_XRANDR_MANAGER (object); + + G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->dispose (object); +} + +static void +msd_xrandr_manager_class_init (MsdXrandrManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_xrandr_manager_get_property; + object_class->set_property = msd_xrandr_manager_set_property; + object_class->constructor = msd_xrandr_manager_constructor; + object_class->dispose = msd_xrandr_manager_dispose; + object_class->finalize = msd_xrandr_manager_finalize; + + dbus_g_object_type_install_info (MSD_TYPE_XRANDR_MANAGER, &dbus_glib_msd_xrandr_manager_object_info); + + g_type_class_add_private (klass, sizeof (MsdXrandrManagerPrivate)); +} + +static guint +get_keycode_for_keysym_name (const char *name) +{ + Display *dpy; + guint keyval; + + dpy = gdk_x11_get_default_xdisplay (); + + keyval = gdk_keyval_from_name (name); + return XKeysymToKeycode (dpy, keyval); +} + +static void +msd_xrandr_manager_init (MsdXrandrManager *manager) +{ + manager->priv = MSD_XRANDR_MANAGER_GET_PRIVATE (manager); + + manager->priv->switch_video_mode_keycode = get_keycode_for_keysym_name (VIDEO_KEYSYM); + manager->priv->rotate_windows_keycode = get_keycode_for_keysym_name (ROTATE_KEYSYM); + + manager->priv->current_fn_f7_config = -1; + manager->priv->fn_f7_configs = NULL; +} + +static void +msd_xrandr_manager_finalize (GObject *object) +{ + MsdXrandrManager *xrandr_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_XRANDR_MANAGER (object)); + + xrandr_manager = MSD_XRANDR_MANAGER (object); + + g_return_if_fail (xrandr_manager->priv != NULL); + + G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->finalize (object); +} + +static gboolean +register_manager_dbus (MsdXrandrManager *manager) +{ + GError *error = NULL; + + manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (manager->priv->dbus_connection == NULL) { + if (error != NULL) { + g_warning ("Error getting session bus: %s", error->message); + g_error_free (error); + } + return FALSE; + } + + /* Hmm, should we do this in msd_xrandr_manager_start()? */ + dbus_g_connection_register_g_object (manager->priv->dbus_connection, MSD_XRANDR_DBUS_PATH, G_OBJECT (manager)); + + return TRUE; +} + +MsdXrandrManager * +msd_xrandr_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_XRANDR_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + + if (!register_manager_dbus (manager_object)) { + g_object_unref (manager_object); + return NULL; + } + } + + return MSD_XRANDR_MANAGER (manager_object); +} diff --git a/plugins/xrandr/msd-xrandr-manager.h b/plugins/xrandr/msd-xrandr-manager.h new file mode 100644 index 0000000..dbb5dff --- /dev/null +++ b/plugins/xrandr/msd-xrandr-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_XRANDR_MANAGER_H +#define __MSD_XRANDR_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_XRANDR_MANAGER (msd_xrandr_manager_get_type ()) +#define MSD_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManager)) +#define MSD_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerClass)) +#define MSD_IS_XRANDR_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRANDR_MANAGER)) +#define MSD_IS_XRANDR_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRANDR_MANAGER)) +#define MSD_XRANDR_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRANDR_MANAGER, MsdXrandrManagerClass)) + +typedef struct MsdXrandrManagerPrivate MsdXrandrManagerPrivate; + +typedef struct +{ + GObject parent; + MsdXrandrManagerPrivate *priv; +} MsdXrandrManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdXrandrManagerClass; + +GType msd_xrandr_manager_get_type (void); + +MsdXrandrManager * msd_xrandr_manager_new (void); +gboolean msd_xrandr_manager_start (MsdXrandrManager *manager, + GError **error); +void msd_xrandr_manager_stop (MsdXrandrManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_XRANDR_MANAGER_H */ diff --git a/plugins/xrandr/msd-xrandr-manager.xml b/plugins/xrandr/msd-xrandr-manager.xml new file mode 100644 index 0000000..c82a594 --- /dev/null +++ b/plugins/xrandr/msd-xrandr-manager.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/xrandr/msd-xrandr-plugin.c b/plugins/xrandr/msd-xrandr-plugin.c new file mode 100644 index 0000000..9e78124 --- /dev/null +++ b/plugins/xrandr/msd-xrandr-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-xrandr-plugin.h" +#include "msd-xrandr-manager.h" + +struct MsdXrandrPluginPrivate { + MsdXrandrManager *manager; +}; + +#define MSD_XRANDR_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdXrandrPlugin, msd_xrandr_plugin) + +static void +msd_xrandr_plugin_init (MsdXrandrPlugin *plugin) +{ + plugin->priv = MSD_XRANDR_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdXrandrPlugin initializing"); + + plugin->priv->manager = msd_xrandr_manager_new (); +} + +static void +msd_xrandr_plugin_finalize (GObject *object) +{ + MsdXrandrPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_XRANDR_PLUGIN (object)); + + g_debug ("MsdXrandrPlugin finalizing"); + + plugin = MSD_XRANDR_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_xrandr_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating xrandr plugin"); + + error = NULL; + res = msd_xrandr_manager_start (MSD_XRANDR_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start xrandr manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating xrandr plugin"); + msd_xrandr_manager_stop (MSD_XRANDR_PLUGIN (plugin)->priv->manager); +} + +static void +msd_xrandr_plugin_class_init (MsdXrandrPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_xrandr_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdXrandrPluginPrivate)); +} diff --git a/plugins/xrandr/msd-xrandr-plugin.h b/plugins/xrandr/msd-xrandr-plugin.h new file mode 100644 index 0000000..62e742e --- /dev/null +++ b/plugins/xrandr/msd-xrandr-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_XRANDR_PLUGIN_H__ +#define __MSD_XRANDR_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_XRANDR_PLUGIN (msd_xrandr_plugin_get_type ()) +#define MSD_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPlugin)) +#define MSD_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginClass)) +#define MSD_IS_XRANDR_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRANDR_PLUGIN)) +#define MSD_IS_XRANDR_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRANDR_PLUGIN)) +#define MSD_XRANDR_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRANDR_PLUGIN, MsdXrandrPluginClass)) + +typedef struct MsdXrandrPluginPrivate MsdXrandrPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdXrandrPluginPrivate *priv; +} MsdXrandrPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdXrandrPluginClass; + +GType msd_xrandr_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_XRANDR_PLUGIN_H__ */ diff --git a/plugins/xrandr/msd-xrandr.svg b/plugins/xrandr/msd-xrandr.svg new file mode 100644 index 0000000..0679b6b --- /dev/null +++ b/plugins/xrandr/msd-xrandr.svg @@ -0,0 +1,470 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Change Resolution + + + Jakub Steiner + + + + + + display + resolution + video + + + + + Andreas Nilsson +Luca Ferretti <elle.uca@libero.it> + + + + http://www.gnome.org + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/xrdb/gsd-xrdb-manager.c b/plugins/xrdb/gsd-xrdb-manager.c deleted file mode 100644 index 776d1e7..0000000 --- a/plugins/xrdb/gsd-xrdb-manager.c +++ /dev/null @@ -1,637 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2003 Ross Burton - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "mate-settings-profile.h" -#include "msd-xrdb-manager.h" - -#define MSD_XRDB_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerPrivate)) - -#define SYSTEM_AD_DIR DATADIR "/xrdb" -#define GENERAL_AD SYSTEM_AD_DIR "/General.ad" -#define USER_AD_DIR ".config/mate/xrdb" -#define USER_X_RESOURCES ".Xresources" -#define USER_X_DEFAULTS ".Xdefaults" - -#define GTK_THEME_KEY "/desktop/mate/interface/gtk_theme" - -struct MsdXrdbManagerPrivate { - GtkWidget* widget; -}; - -static void msd_xrdb_manager_class_init (MsdXrdbManagerClass *klass); -static void msd_xrdb_manager_init (MsdXrdbManager *xrdb_manager); -static void msd_xrdb_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MsdXrdbManager, msd_xrdb_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; -static void - -append_color_define (GString *string, - const char *name, - const GdkColor *color) -{ - g_return_if_fail (string != NULL); - g_return_if_fail (name != NULL); - g_return_if_fail (color != NULL); - - g_string_append_printf (string, - "#define %s #%2.2hx%2.2hx%2.2hx\n", - name, - color->red>>8, - color->green>>8, - color->blue>>8); -} - -static GdkColor* -color_shade (GdkColor *a, - gdouble shade, - GdkColor *b) -{ - guint16 red, green, blue; - - red = CLAMP ((a->red) * shade, 0, 0xFFFF); - green = CLAMP ((a->green) * shade, 0, 0xFFFF); - blue = CLAMP ((a->blue) * shade, 0, 0xFFFF); - - b->red = red; - b->green = green; - b->blue = blue; - - return b; -} - -static void -append_theme_colors (GtkStyle *style, - GString *string) -{ - GdkColor tmp; - - g_return_if_fail (style != NULL); - g_return_if_fail (string != NULL); - - append_color_define (string, - "BACKGROUND", - &style->bg[GTK_STATE_NORMAL]); - append_color_define (string, - "FOREGROUND", - &style->fg[GTK_STATE_NORMAL]); - append_color_define (string, - "SELECT_BACKGROUND", - &style->bg[GTK_STATE_SELECTED]); - append_color_define (string, - "SELECT_FOREGROUND", - &style->text[GTK_STATE_SELECTED]); - append_color_define (string, - "WINDOW_BACKGROUND", - &style->base[GTK_STATE_NORMAL]); - append_color_define (string, - "WINDOW_FOREGROUND", - &style->text[GTK_STATE_NORMAL]); - append_color_define (string, - "INACTIVE_BACKGROUND", - &style->bg[GTK_STATE_INSENSITIVE]); - append_color_define (string, - "INACTIVE_FOREGROUND", - &style->text[GTK_STATE_INSENSITIVE]); - append_color_define (string, - "ACTIVE_BACKGROUND", - &style->bg[GTK_STATE_SELECTED]); - append_color_define (string, - "ACTIVE_FOREGROUND", - &style->text[GTK_STATE_SELECTED]); - - append_color_define (string, - "HIGHLIGHT", - color_shade (&style->bg[GTK_STATE_NORMAL], 1.2, &tmp)); - append_color_define (string, - "LOWLIGHT", - color_shade (&style->bg[GTK_STATE_NORMAL], 2.0/3.0, &tmp)); - return; -} - -/** - * Scan a single directory for .ad files, and return them all in a - * GSList* - */ -static GSList* -scan_ad_directory (const char *path, - GError **error) -{ - GSList *list; - GDir *dir; - const char *entry; - GError *local_error; - - list = NULL; - - g_return_val_if_fail (path != NULL, NULL); - - local_error = NULL; - dir = g_dir_open (path, 0, &local_error); - if (local_error != NULL) { - g_propagate_error (error, local_error); - return NULL; - } - - while ((entry = g_dir_read_name (dir)) != NULL) { - if (g_str_has_suffix (entry, ".ad")) { - list = g_slist_prepend (list, g_strdup_printf ("%s/%s", path, entry)); - } - } - - g_dir_close (dir); - - /* TODO: sort still? */ - return g_slist_sort (list, (GCompareFunc)strcmp); -} - -/** - * Compare two file names on their base names. - */ -static gint -compare_basenames (gconstpointer a, - gconstpointer b) -{ - char *base_a; - char *base_b; - int res; - - base_a = g_path_get_basename (a); - base_b = g_path_get_basename (b); - res = strcmp (base_a, base_b); - g_free (base_a); - g_free (base_b); - - return res; -} - -/** - * Scan the user and system paths, and return a list of strings in the - * right order for processing. - */ -static GSList* -scan_for_files (MsdXrdbManager *manager, - GError **error) -{ - const char *home_dir; - GSList *user_list; - GSList *system_list; - GSList *list; - GSList *p; - GError *local_error; - - list = NULL; - user_list = NULL; - system_list = NULL; - - local_error = NULL; - system_list = scan_ad_directory (SYSTEM_AD_DIR, &local_error); - if (local_error != NULL) { - g_propagate_error (error, local_error); - return NULL; - } - - home_dir = g_get_home_dir (); - if (home_dir != NULL) { - char *user_ad; - - user_ad = g_build_filename (home_dir, USER_AD_DIR, NULL); - - if (g_file_test (user_ad, G_FILE_TEST_IS_DIR)) { - - local_error = NULL; - user_list = scan_ad_directory (user_ad, &local_error); - if (local_error != NULL) { - g_propagate_error (error, local_error); - - g_slist_foreach (system_list, (GFunc)g_free, NULL); - g_slist_free (system_list); - g_free (user_ad); - return NULL; - } - } - - g_free (user_ad); - - } else { - g_warning (_("Cannot determine user's home directory")); - } - - /* An alternative approach would be to strdup() the strings - and free the entire contents of these lists, but that is a - little inefficient for my liking - RB */ - for (p = system_list; p != NULL; p = g_slist_next (p)) { - if (strcmp (p->data, GENERAL_AD) == 0) { - /* We ignore this, free the data now */ - g_free (p->data); - continue; - } - if (g_slist_find_custom (user_list, p->data, compare_basenames)) { - /* Ditto */ - g_free (p->data); - continue; - } - list = g_slist_prepend (list, p->data); - } - g_slist_free (system_list); - - for (p = user_list; p != NULL; p = g_slist_next (p)) { - list = g_slist_prepend (list, p->data); - } - g_slist_free (user_list); - - /* Reverse the order so it is the correct way */ - list = g_slist_reverse (list); - - /* Add the initial file */ - list = g_slist_prepend (list, g_strdup (GENERAL_AD)); - - return list; -} - -/** - * Append the contents of a file onto the end of a GString - */ -static void -append_file (const char *file, - GString *string, - GError **error) -{ - char *contents; - - g_return_if_fail (string != NULL); - g_return_if_fail (file != NULL); - - if (g_file_get_contents (file, &contents, NULL, error)) { - g_string_append (string, contents); - g_free (contents); - } -} - -/** - * Append an X resources file, such as .Xresources, or .Xdefaults - */ -static void -append_xresource_file (const char *filename, - GString *string, - GError **error) -{ - const char *home_path; - char *xresources; - - g_return_if_fail (string != NULL); - - home_path = g_get_home_dir (); - if (home_path == NULL) { - g_warning (_("Cannot determine user's home directory")); - return; - } - - xresources = g_build_filename (home_path, filename, NULL); - if (g_file_test (xresources, G_FILE_TEST_EXISTS)) { - GError *local_error; - - local_error = NULL; - - append_file (xresources, string, &local_error); - if (local_error != NULL) { - g_warning ("%s", local_error->message); - g_propagate_error (error, local_error); - } - } - g_free (xresources); -} - -static gboolean -write_all (int fd, - const char *buf, - gsize to_write) -{ - while (to_write > 0) { - gssize count = write (fd, buf, to_write); - if (count < 0) { - if (errno != EINTR) - return FALSE; - } else { - to_write -= count; - buf += count; - } - } - - return TRUE; -} - -static void -child_watch_cb (GPid pid, - int status, - gpointer user_data) -{ - char *command = user_data; - - if (!WIFEXITED (status) || WEXITSTATUS (status)) { - g_warning ("Command %s failed", command); - } -} - -static void -spawn_with_input (const char *command, - const char *input) -{ - char **argv; - int child_pid; - int inpipe; - GError *error; - gboolean res; - - argv = NULL; - res = g_shell_parse_argv (command, NULL, &argv, NULL); - if (! res) { - g_warning ("Unable to parse command: %s", command); - return; - } - - error = NULL; - res = g_spawn_async_with_pipes (NULL, - argv, - NULL, - G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, - NULL, - NULL, - &child_pid, - &inpipe, - NULL, - NULL, - &error); - g_strfreev (argv); - - if (! res) { - g_warning ("Could not execute %s: %s", command, error->message); - g_error_free (error); - - return; - } - - if (input != NULL) { - if (! write_all (inpipe, input, strlen (input))) { - g_warning ("Could not write input to %s", command); - } - - close (inpipe); - } - - g_child_watch_add (child_pid, (GChildWatchFunc) child_watch_cb, (gpointer)command); -} - -static void -apply_settings (MsdXrdbManager *manager, - GtkStyle *style) -{ - const char *command; - GString *string; - GSList *list; - GSList *p; - GError *error; - - mate_settings_profile_start (NULL); - - command = "xrdb -merge -quiet"; - - string = g_string_sized_new (256); - append_theme_colors (style, string); - - error = NULL; - list = scan_for_files (manager, &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } - - for (p = list; p != NULL; p = p->next) { - error = NULL; - append_file (p->data, string, &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } - } - - g_slist_foreach (list, (GFunc)g_free, NULL); - g_slist_free (list); - - error = NULL; - append_xresource_file (USER_X_RESOURCES, string, &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } - - error = NULL; - append_xresource_file (USER_X_DEFAULTS, string, &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } - - spawn_with_input (command, string->str); - g_string_free (string, TRUE); - - mate_settings_profile_end (NULL); - - return; -} - -static void -theme_changed (GtkSettings *settings, - GParamSpec *pspec, - MsdXrdbManager *manager) -{ - apply_settings (manager, gtk_widget_get_style (manager->priv->widget)); -} - -gboolean -msd_xrdb_manager_start (MsdXrdbManager *manager, - GError **error) -{ - mate_settings_profile_start (NULL); - - /* the initialization is done here otherwise - mate_settings_xsettings_load would generate - false hit as gtk-theme-name is set to Default in - mate_settings_xsettings_init */ - g_signal_connect (gtk_settings_get_default (), - "notify::gtk-theme-name", - G_CALLBACK (theme_changed), - manager); - - manager->priv->widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_widget_ensure_style (manager->priv->widget); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_xrdb_manager_stop (MsdXrdbManager *manager) -{ - MsdXrdbManagerPrivate *p = manager->priv; - - g_debug ("Stopping xrdb manager"); - - g_signal_handlers_disconnect_by_func (gtk_settings_get_default (), - theme_changed, - manager); - - if (p->widget != NULL) { - gtk_widget_destroy (p->widget); - p->widget = NULL; - } -} - -static void -msd_xrdb_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdXrdbManager *self; - - self = MSD_XRDB_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_xrdb_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdXrdbManager *self; - - self = MSD_XRDB_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_xrdb_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdXrdbManager *xrdb_manager; - MsdXrdbManagerClass *klass; - - klass = MSD_XRDB_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_XRDB_MANAGER)); - - xrdb_manager = MSD_XRDB_MANAGER (G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (xrdb_manager); -} - -static void -msd_xrdb_manager_dispose (GObject *object) -{ - MsdXrdbManager *xrdb_manager; - - xrdb_manager = MSD_XRDB_MANAGER (object); - - G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->dispose (object); -} - -static void -msd_xrdb_manager_class_init (MsdXrdbManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_xrdb_manager_get_property; - object_class->set_property = msd_xrdb_manager_set_property; - object_class->constructor = msd_xrdb_manager_constructor; - object_class->dispose = msd_xrdb_manager_dispose; - object_class->finalize = msd_xrdb_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdXrdbManagerPrivate)); -} - -static void -msd_xrdb_manager_init (MsdXrdbManager *manager) -{ - manager->priv = MSD_XRDB_MANAGER_GET_PRIVATE (manager); - -} - -static void -msd_xrdb_manager_finalize (GObject *object) -{ - MsdXrdbManager *xrdb_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_XRDB_MANAGER (object)); - - xrdb_manager = MSD_XRDB_MANAGER (object); - - g_return_if_fail (xrdb_manager->priv != NULL); - - G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->finalize (object); -} - -MsdXrdbManager * -msd_xrdb_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_XRDB_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_XRDB_MANAGER (manager_object); -} diff --git a/plugins/xrdb/gsd-xrdb-manager.h b/plugins/xrdb/gsd-xrdb-manager.h deleted file mode 100644 index cb83d24..0000000 --- a/plugins/xrdb/gsd-xrdb-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_XRDB_MANAGER_H -#define __MSD_XRDB_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_XRDB_MANAGER (msd_xrdb_manager_get_type ()) -#define MSD_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManager)) -#define MSD_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerClass)) -#define MSD_IS_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRDB_MANAGER)) -#define MSD_IS_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRDB_MANAGER)) -#define MSD_XRDB_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerClass)) - -typedef struct MsdXrdbManagerPrivate MsdXrdbManagerPrivate; - -typedef struct -{ - GObject parent; - MsdXrdbManagerPrivate *priv; -} MsdXrdbManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdXrdbManagerClass; - -GType msd_xrdb_manager_get_type (void); - -MsdXrdbManager * msd_xrdb_manager_new (void); -gboolean msd_xrdb_manager_start (MsdXrdbManager *manager, - GError **error); -void msd_xrdb_manager_stop (MsdXrdbManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_XRDB_MANAGER_H */ diff --git a/plugins/xrdb/gsd-xrdb-plugin.c b/plugins/xrdb/gsd-xrdb-plugin.c deleted file mode 100644 index 1efe570..0000000 --- a/plugins/xrdb/gsd-xrdb-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-xrdb-plugin.h" -#include "msd-xrdb-manager.h" - -struct MsdXrdbPluginPrivate { - MsdXrdbManager *manager; -}; - -#define MSD_XRDB_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdXrdbPlugin, msd_xrdb_plugin) - -static void -msd_xrdb_plugin_init (MsdXrdbPlugin *plugin) -{ - plugin->priv = MSD_XRDB_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdXrdbPlugin initializing"); - - plugin->priv->manager = msd_xrdb_manager_new (); -} - -static void -msd_xrdb_plugin_finalize (GObject *object) -{ - MsdXrdbPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_XRDB_PLUGIN (object)); - - g_debug ("MsdXrdbPlugin finalizing"); - - plugin = MSD_XRDB_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_xrdb_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating xrdb plugin"); - - error = NULL; - res = msd_xrdb_manager_start (MSD_XRDB_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start xrdb manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating xrdb plugin"); - msd_xrdb_manager_stop (MSD_XRDB_PLUGIN (plugin)->priv->manager); -} - -static void -msd_xrdb_plugin_class_init (MsdXrdbPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_xrdb_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdXrdbPluginPrivate)); -} diff --git a/plugins/xrdb/gsd-xrdb-plugin.h b/plugins/xrdb/gsd-xrdb-plugin.h deleted file mode 100644 index 893835b..0000000 --- a/plugins/xrdb/gsd-xrdb-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_XRDB_PLUGIN_H__ -#define __MSD_XRDB_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_XRDB_PLUGIN (msd_xrdb_plugin_get_type ()) -#define MSD_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPlugin)) -#define MSD_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginClass)) -#define MSD_IS_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRDB_PLUGIN)) -#define MSD_IS_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRDB_PLUGIN)) -#define MSD_XRDB_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginClass)) - -typedef struct MsdXrdbPluginPrivate MsdXrdbPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdXrdbPluginPrivate *priv; -} MsdXrdbPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdXrdbPluginClass; - -GType msd_xrdb_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_XRDB_PLUGIN_H__ */ diff --git a/plugins/xrdb/msd-xrdb-manager.c b/plugins/xrdb/msd-xrdb-manager.c new file mode 100644 index 0000000..776d1e7 --- /dev/null +++ b/plugins/xrdb/msd-xrdb-manager.c @@ -0,0 +1,637 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2003 Ross Burton + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "mate-settings-profile.h" +#include "msd-xrdb-manager.h" + +#define MSD_XRDB_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerPrivate)) + +#define SYSTEM_AD_DIR DATADIR "/xrdb" +#define GENERAL_AD SYSTEM_AD_DIR "/General.ad" +#define USER_AD_DIR ".config/mate/xrdb" +#define USER_X_RESOURCES ".Xresources" +#define USER_X_DEFAULTS ".Xdefaults" + +#define GTK_THEME_KEY "/desktop/mate/interface/gtk_theme" + +struct MsdXrdbManagerPrivate { + GtkWidget* widget; +}; + +static void msd_xrdb_manager_class_init (MsdXrdbManagerClass *klass); +static void msd_xrdb_manager_init (MsdXrdbManager *xrdb_manager); +static void msd_xrdb_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MsdXrdbManager, msd_xrdb_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; +static void + +append_color_define (GString *string, + const char *name, + const GdkColor *color) +{ + g_return_if_fail (string != NULL); + g_return_if_fail (name != NULL); + g_return_if_fail (color != NULL); + + g_string_append_printf (string, + "#define %s #%2.2hx%2.2hx%2.2hx\n", + name, + color->red>>8, + color->green>>8, + color->blue>>8); +} + +static GdkColor* +color_shade (GdkColor *a, + gdouble shade, + GdkColor *b) +{ + guint16 red, green, blue; + + red = CLAMP ((a->red) * shade, 0, 0xFFFF); + green = CLAMP ((a->green) * shade, 0, 0xFFFF); + blue = CLAMP ((a->blue) * shade, 0, 0xFFFF); + + b->red = red; + b->green = green; + b->blue = blue; + + return b; +} + +static void +append_theme_colors (GtkStyle *style, + GString *string) +{ + GdkColor tmp; + + g_return_if_fail (style != NULL); + g_return_if_fail (string != NULL); + + append_color_define (string, + "BACKGROUND", + &style->bg[GTK_STATE_NORMAL]); + append_color_define (string, + "FOREGROUND", + &style->fg[GTK_STATE_NORMAL]); + append_color_define (string, + "SELECT_BACKGROUND", + &style->bg[GTK_STATE_SELECTED]); + append_color_define (string, + "SELECT_FOREGROUND", + &style->text[GTK_STATE_SELECTED]); + append_color_define (string, + "WINDOW_BACKGROUND", + &style->base[GTK_STATE_NORMAL]); + append_color_define (string, + "WINDOW_FOREGROUND", + &style->text[GTK_STATE_NORMAL]); + append_color_define (string, + "INACTIVE_BACKGROUND", + &style->bg[GTK_STATE_INSENSITIVE]); + append_color_define (string, + "INACTIVE_FOREGROUND", + &style->text[GTK_STATE_INSENSITIVE]); + append_color_define (string, + "ACTIVE_BACKGROUND", + &style->bg[GTK_STATE_SELECTED]); + append_color_define (string, + "ACTIVE_FOREGROUND", + &style->text[GTK_STATE_SELECTED]); + + append_color_define (string, + "HIGHLIGHT", + color_shade (&style->bg[GTK_STATE_NORMAL], 1.2, &tmp)); + append_color_define (string, + "LOWLIGHT", + color_shade (&style->bg[GTK_STATE_NORMAL], 2.0/3.0, &tmp)); + return; +} + +/** + * Scan a single directory for .ad files, and return them all in a + * GSList* + */ +static GSList* +scan_ad_directory (const char *path, + GError **error) +{ + GSList *list; + GDir *dir; + const char *entry; + GError *local_error; + + list = NULL; + + g_return_val_if_fail (path != NULL, NULL); + + local_error = NULL; + dir = g_dir_open (path, 0, &local_error); + if (local_error != NULL) { + g_propagate_error (error, local_error); + return NULL; + } + + while ((entry = g_dir_read_name (dir)) != NULL) { + if (g_str_has_suffix (entry, ".ad")) { + list = g_slist_prepend (list, g_strdup_printf ("%s/%s", path, entry)); + } + } + + g_dir_close (dir); + + /* TODO: sort still? */ + return g_slist_sort (list, (GCompareFunc)strcmp); +} + +/** + * Compare two file names on their base names. + */ +static gint +compare_basenames (gconstpointer a, + gconstpointer b) +{ + char *base_a; + char *base_b; + int res; + + base_a = g_path_get_basename (a); + base_b = g_path_get_basename (b); + res = strcmp (base_a, base_b); + g_free (base_a); + g_free (base_b); + + return res; +} + +/** + * Scan the user and system paths, and return a list of strings in the + * right order for processing. + */ +static GSList* +scan_for_files (MsdXrdbManager *manager, + GError **error) +{ + const char *home_dir; + GSList *user_list; + GSList *system_list; + GSList *list; + GSList *p; + GError *local_error; + + list = NULL; + user_list = NULL; + system_list = NULL; + + local_error = NULL; + system_list = scan_ad_directory (SYSTEM_AD_DIR, &local_error); + if (local_error != NULL) { + g_propagate_error (error, local_error); + return NULL; + } + + home_dir = g_get_home_dir (); + if (home_dir != NULL) { + char *user_ad; + + user_ad = g_build_filename (home_dir, USER_AD_DIR, NULL); + + if (g_file_test (user_ad, G_FILE_TEST_IS_DIR)) { + + local_error = NULL; + user_list = scan_ad_directory (user_ad, &local_error); + if (local_error != NULL) { + g_propagate_error (error, local_error); + + g_slist_foreach (system_list, (GFunc)g_free, NULL); + g_slist_free (system_list); + g_free (user_ad); + return NULL; + } + } + + g_free (user_ad); + + } else { + g_warning (_("Cannot determine user's home directory")); + } + + /* An alternative approach would be to strdup() the strings + and free the entire contents of these lists, but that is a + little inefficient for my liking - RB */ + for (p = system_list; p != NULL; p = g_slist_next (p)) { + if (strcmp (p->data, GENERAL_AD) == 0) { + /* We ignore this, free the data now */ + g_free (p->data); + continue; + } + if (g_slist_find_custom (user_list, p->data, compare_basenames)) { + /* Ditto */ + g_free (p->data); + continue; + } + list = g_slist_prepend (list, p->data); + } + g_slist_free (system_list); + + for (p = user_list; p != NULL; p = g_slist_next (p)) { + list = g_slist_prepend (list, p->data); + } + g_slist_free (user_list); + + /* Reverse the order so it is the correct way */ + list = g_slist_reverse (list); + + /* Add the initial file */ + list = g_slist_prepend (list, g_strdup (GENERAL_AD)); + + return list; +} + +/** + * Append the contents of a file onto the end of a GString + */ +static void +append_file (const char *file, + GString *string, + GError **error) +{ + char *contents; + + g_return_if_fail (string != NULL); + g_return_if_fail (file != NULL); + + if (g_file_get_contents (file, &contents, NULL, error)) { + g_string_append (string, contents); + g_free (contents); + } +} + +/** + * Append an X resources file, such as .Xresources, or .Xdefaults + */ +static void +append_xresource_file (const char *filename, + GString *string, + GError **error) +{ + const char *home_path; + char *xresources; + + g_return_if_fail (string != NULL); + + home_path = g_get_home_dir (); + if (home_path == NULL) { + g_warning (_("Cannot determine user's home directory")); + return; + } + + xresources = g_build_filename (home_path, filename, NULL); + if (g_file_test (xresources, G_FILE_TEST_EXISTS)) { + GError *local_error; + + local_error = NULL; + + append_file (xresources, string, &local_error); + if (local_error != NULL) { + g_warning ("%s", local_error->message); + g_propagate_error (error, local_error); + } + } + g_free (xresources); +} + +static gboolean +write_all (int fd, + const char *buf, + gsize to_write) +{ + while (to_write > 0) { + gssize count = write (fd, buf, to_write); + if (count < 0) { + if (errno != EINTR) + return FALSE; + } else { + to_write -= count; + buf += count; + } + } + + return TRUE; +} + +static void +child_watch_cb (GPid pid, + int status, + gpointer user_data) +{ + char *command = user_data; + + if (!WIFEXITED (status) || WEXITSTATUS (status)) { + g_warning ("Command %s failed", command); + } +} + +static void +spawn_with_input (const char *command, + const char *input) +{ + char **argv; + int child_pid; + int inpipe; + GError *error; + gboolean res; + + argv = NULL; + res = g_shell_parse_argv (command, NULL, &argv, NULL); + if (! res) { + g_warning ("Unable to parse command: %s", command); + return; + } + + error = NULL; + res = g_spawn_async_with_pipes (NULL, + argv, + NULL, + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, + NULL, + &child_pid, + &inpipe, + NULL, + NULL, + &error); + g_strfreev (argv); + + if (! res) { + g_warning ("Could not execute %s: %s", command, error->message); + g_error_free (error); + + return; + } + + if (input != NULL) { + if (! write_all (inpipe, input, strlen (input))) { + g_warning ("Could not write input to %s", command); + } + + close (inpipe); + } + + g_child_watch_add (child_pid, (GChildWatchFunc) child_watch_cb, (gpointer)command); +} + +static void +apply_settings (MsdXrdbManager *manager, + GtkStyle *style) +{ + const char *command; + GString *string; + GSList *list; + GSList *p; + GError *error; + + mate_settings_profile_start (NULL); + + command = "xrdb -merge -quiet"; + + string = g_string_sized_new (256); + append_theme_colors (style, string); + + error = NULL; + list = scan_for_files (manager, &error); + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + + for (p = list; p != NULL; p = p->next) { + error = NULL; + append_file (p->data, string, &error); + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + } + + g_slist_foreach (list, (GFunc)g_free, NULL); + g_slist_free (list); + + error = NULL; + append_xresource_file (USER_X_RESOURCES, string, &error); + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + + error = NULL; + append_xresource_file (USER_X_DEFAULTS, string, &error); + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + + spawn_with_input (command, string->str); + g_string_free (string, TRUE); + + mate_settings_profile_end (NULL); + + return; +} + +static void +theme_changed (GtkSettings *settings, + GParamSpec *pspec, + MsdXrdbManager *manager) +{ + apply_settings (manager, gtk_widget_get_style (manager->priv->widget)); +} + +gboolean +msd_xrdb_manager_start (MsdXrdbManager *manager, + GError **error) +{ + mate_settings_profile_start (NULL); + + /* the initialization is done here otherwise + mate_settings_xsettings_load would generate + false hit as gtk-theme-name is set to Default in + mate_settings_xsettings_init */ + g_signal_connect (gtk_settings_get_default (), + "notify::gtk-theme-name", + G_CALLBACK (theme_changed), + manager); + + manager->priv->widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_ensure_style (manager->priv->widget); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_xrdb_manager_stop (MsdXrdbManager *manager) +{ + MsdXrdbManagerPrivate *p = manager->priv; + + g_debug ("Stopping xrdb manager"); + + g_signal_handlers_disconnect_by_func (gtk_settings_get_default (), + theme_changed, + manager); + + if (p->widget != NULL) { + gtk_widget_destroy (p->widget); + p->widget = NULL; + } +} + +static void +msd_xrdb_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdXrdbManager *self; + + self = MSD_XRDB_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_xrdb_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdXrdbManager *self; + + self = MSD_XRDB_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_xrdb_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdXrdbManager *xrdb_manager; + MsdXrdbManagerClass *klass; + + klass = MSD_XRDB_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_XRDB_MANAGER)); + + xrdb_manager = MSD_XRDB_MANAGER (G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (xrdb_manager); +} + +static void +msd_xrdb_manager_dispose (GObject *object) +{ + MsdXrdbManager *xrdb_manager; + + xrdb_manager = MSD_XRDB_MANAGER (object); + + G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->dispose (object); +} + +static void +msd_xrdb_manager_class_init (MsdXrdbManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_xrdb_manager_get_property; + object_class->set_property = msd_xrdb_manager_set_property; + object_class->constructor = msd_xrdb_manager_constructor; + object_class->dispose = msd_xrdb_manager_dispose; + object_class->finalize = msd_xrdb_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdXrdbManagerPrivate)); +} + +static void +msd_xrdb_manager_init (MsdXrdbManager *manager) +{ + manager->priv = MSD_XRDB_MANAGER_GET_PRIVATE (manager); + +} + +static void +msd_xrdb_manager_finalize (GObject *object) +{ + MsdXrdbManager *xrdb_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_XRDB_MANAGER (object)); + + xrdb_manager = MSD_XRDB_MANAGER (object); + + g_return_if_fail (xrdb_manager->priv != NULL); + + G_OBJECT_CLASS (msd_xrdb_manager_parent_class)->finalize (object); +} + +MsdXrdbManager * +msd_xrdb_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_XRDB_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_XRDB_MANAGER (manager_object); +} diff --git a/plugins/xrdb/msd-xrdb-manager.h b/plugins/xrdb/msd-xrdb-manager.h new file mode 100644 index 0000000..cb83d24 --- /dev/null +++ b/plugins/xrdb/msd-xrdb-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_XRDB_MANAGER_H +#define __MSD_XRDB_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_XRDB_MANAGER (msd_xrdb_manager_get_type ()) +#define MSD_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManager)) +#define MSD_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerClass)) +#define MSD_IS_XRDB_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRDB_MANAGER)) +#define MSD_IS_XRDB_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRDB_MANAGER)) +#define MSD_XRDB_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRDB_MANAGER, MsdXrdbManagerClass)) + +typedef struct MsdXrdbManagerPrivate MsdXrdbManagerPrivate; + +typedef struct +{ + GObject parent; + MsdXrdbManagerPrivate *priv; +} MsdXrdbManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdXrdbManagerClass; + +GType msd_xrdb_manager_get_type (void); + +MsdXrdbManager * msd_xrdb_manager_new (void); +gboolean msd_xrdb_manager_start (MsdXrdbManager *manager, + GError **error); +void msd_xrdb_manager_stop (MsdXrdbManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_XRDB_MANAGER_H */ diff --git a/plugins/xrdb/msd-xrdb-plugin.c b/plugins/xrdb/msd-xrdb-plugin.c new file mode 100644 index 0000000..1efe570 --- /dev/null +++ b/plugins/xrdb/msd-xrdb-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-xrdb-plugin.h" +#include "msd-xrdb-manager.h" + +struct MsdXrdbPluginPrivate { + MsdXrdbManager *manager; +}; + +#define MSD_XRDB_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdXrdbPlugin, msd_xrdb_plugin) + +static void +msd_xrdb_plugin_init (MsdXrdbPlugin *plugin) +{ + plugin->priv = MSD_XRDB_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdXrdbPlugin initializing"); + + plugin->priv->manager = msd_xrdb_manager_new (); +} + +static void +msd_xrdb_plugin_finalize (GObject *object) +{ + MsdXrdbPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_XRDB_PLUGIN (object)); + + g_debug ("MsdXrdbPlugin finalizing"); + + plugin = MSD_XRDB_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_xrdb_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating xrdb plugin"); + + error = NULL; + res = msd_xrdb_manager_start (MSD_XRDB_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start xrdb manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating xrdb plugin"); + msd_xrdb_manager_stop (MSD_XRDB_PLUGIN (plugin)->priv->manager); +} + +static void +msd_xrdb_plugin_class_init (MsdXrdbPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_xrdb_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdXrdbPluginPrivate)); +} diff --git a/plugins/xrdb/msd-xrdb-plugin.h b/plugins/xrdb/msd-xrdb-plugin.h new file mode 100644 index 0000000..893835b --- /dev/null +++ b/plugins/xrdb/msd-xrdb-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_XRDB_PLUGIN_H__ +#define __MSD_XRDB_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_XRDB_PLUGIN (msd_xrdb_plugin_get_type ()) +#define MSD_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPlugin)) +#define MSD_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginClass)) +#define MSD_IS_XRDB_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_XRDB_PLUGIN)) +#define MSD_IS_XRDB_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_XRDB_PLUGIN)) +#define MSD_XRDB_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_XRDB_PLUGIN, MsdXrdbPluginClass)) + +typedef struct MsdXrdbPluginPrivate MsdXrdbPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdXrdbPluginPrivate *priv; +} MsdXrdbPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdXrdbPluginClass; + +GType msd_xrdb_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_XRDB_PLUGIN_H__ */ diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c deleted file mode 100644 index 9df8f61..0000000 --- a/plugins/xsettings/gsd-xsettings-manager.c +++ /dev/null @@ -1,1040 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 Rodrigo Moya - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "mate-settings-profile.h" -#include "msd-xsettings-manager.h" -#include "xsettings-manager.h" -#ifdef HAVE_FONTCONFIG -#include "fontconfig-monitor.h" -#endif /* HAVE_FONTCONFIG */ - -#define MATE_XSETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManagerPrivate)) - -#define MOUSE_SETTINGS_DIR "/desktop/mate/peripherals/mouse" -#define GTK_SETTINGS_DIR "/desktop/gtk" -#define INTERFACE_SETTINGS_DIR "/desktop/mate/interface" -#define SOUND_SETTINGS_DIR "/desktop/mate/sound" -#define GTK_MODULES_DIR "/apps/mate_settings_daemon/gtk-modules" - -#ifdef HAVE_FONTCONFIG -#define FONT_RENDER_DIR "/desktop/mate/font_rendering" -#define FONT_ANTIALIASING_KEY FONT_RENDER_DIR "/antialiasing" -#define FONT_HINTING_KEY FONT_RENDER_DIR "/hinting" -#define FONT_RGBA_ORDER_KEY FONT_RENDER_DIR "/rgba_order" -#define FONT_DPI_KEY FONT_RENDER_DIR "/dpi" - -/* X servers sometimes lie about the screen's physical dimensions, so we cannot - * compute an accurate DPI value. When this happens, the user gets fonts that - * are too huge or too tiny. So, we see what the server returns: if it reports - * something outside of the range [DPI_LOW_REASONABLE_VALUE, - * DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use - * DPI_FALLBACK instead. - * - * See get_dpi_from_mateconf_or_server() below, and also - * https://bugzilla.novell.com/show_bug.cgi?id=217790 - */ -#define DPI_FALLBACK 96 -#define DPI_LOW_REASONABLE_VALUE 50 -#define DPI_HIGH_REASONABLE_VALUE 500 - -#endif /* HAVE_FONTCONFIG */ - -typedef struct _TranslationEntry TranslationEntry; -typedef void (* TranslationFunc) (MateXSettingsManager *manager, - TranslationEntry *trans, - MateConfValue *value); - -struct _TranslationEntry { - const char *mateconf_key; - const char *xsetting_name; - - MateConfValueType mateconf_type; - TranslationFunc translate; -}; - -struct MateXSettingsManagerPrivate -{ - XSettingsManager **managers; - guint notify[6]; -#ifdef HAVE_FONTCONFIG - fontconfig_monitor_handle_t *fontconfig_handle; -#endif /* HAVE_FONTCONFIG */ -}; - -#define MSD_XSETTINGS_ERROR msd_xsettings_error_quark () - -enum { - MSD_XSETTINGS_ERROR_INIT -}; - -static void mate_xsettings_manager_class_init (MateXSettingsManagerClass *klass); -static void mate_xsettings_manager_init (MateXSettingsManager *xsettings_manager); -static void mate_xsettings_manager_finalize (GObject *object); - -G_DEFINE_TYPE (MateXSettingsManager, mate_xsettings_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -static GQuark -msd_xsettings_error_quark (void) -{ - return g_quark_from_static_string ("msd-xsettings-error-quark"); -} - -static void -translate_bool_int (MateXSettingsManager *manager, - TranslationEntry *trans, - MateConfValue *value) -{ - int i; - - g_assert (value->type == trans->mateconf_type); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_set_int (manager->priv->managers [i], trans->xsetting_name, - mateconf_value_get_bool (value)); - } -} - -static void -translate_int_int (MateXSettingsManager *manager, - TranslationEntry *trans, - MateConfValue *value) -{ - int i; - - g_assert (value->type == trans->mateconf_type); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_set_int (manager->priv->managers [i], trans->xsetting_name, - mateconf_value_get_int (value)); - } -} - -static void -translate_string_string (MateXSettingsManager *manager, - TranslationEntry *trans, - MateConfValue *value) -{ - int i; - - g_assert (value->type == trans->mateconf_type); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_set_string (manager->priv->managers [i], - trans->xsetting_name, - mateconf_value_get_string (value)); - } -} - -static void -translate_string_string_toolbar (MateXSettingsManager *manager, - TranslationEntry *trans, - MateConfValue *value) -{ - int i; - const char *tmp; - - g_assert (value->type == trans->mateconf_type); - - /* This is kind of a workaround since MATE expects the key value to be - * "both_horiz" and gtk+ wants the XSetting to be "both-horiz". - */ - tmp = mateconf_value_get_string (value); - if (tmp && strcmp (tmp, "both_horiz") == 0) { - tmp = "both-horiz"; - } - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_set_string (manager->priv->managers [i], - trans->xsetting_name, - tmp); - } -} - -static TranslationEntry translations [] = { - { "/desktop/mate/peripherals/mouse/double_click", "Net/DoubleClickTime", MATECONF_VALUE_INT, translate_int_int }, - { "/desktop/mate/peripherals/mouse/drag_threshold", "Net/DndDragThreshold", MATECONF_VALUE_INT, translate_int_int }, - { "/desktop/mate/gtk-color-palette", "Gtk/ColorPalette", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/font_name", "Gtk/FontName", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/gtk_key_theme", "Gtk/KeyThemeName", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/toolbar_style", "Gtk/ToolbarStyle", MATECONF_VALUE_STRING, translate_string_string_toolbar }, - { "/desktop/mate/interface/toolbar_icons_size", "Gtk/ToolbarIconSize", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/can_change_accels", "Gtk/CanChangeAccels", MATECONF_VALUE_BOOL, translate_bool_int }, - { "/desktop/mate/interface/cursor_blink", "Net/CursorBlink", MATECONF_VALUE_BOOL, translate_bool_int }, - { "/desktop/mate/interface/cursor_blink_time", "Net/CursorBlinkTime", MATECONF_VALUE_INT, translate_int_int }, - { "/desktop/mate/interface/gtk_theme", "Net/ThemeName", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/gtk_color_scheme", "Gtk/ColorScheme", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/gtk-im-preedit-style", "Gtk/IMPreeditStyle", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/gtk-im-status-style", "Gtk/IMStatusStyle", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/gtk-im-module", "Gtk/IMModule", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/icon_theme", "Net/IconThemeName", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/file_chooser_backend", "Gtk/FileChooserBackend", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/interface/menus_have_icons", "Gtk/MenuImages", MATECONF_VALUE_BOOL, translate_bool_int }, - { "/desktop/mate/interface/buttons_have_icons", "Gtk/ButtonImages", MATECONF_VALUE_BOOL, translate_bool_int }, - { "/desktop/mate/interface/menubar_accel", "Gtk/MenuBarAccel", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/peripherals/mouse/cursor_theme", "Gtk/CursorThemeName", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/peripherals/mouse/cursor_size", "Gtk/CursorThemeSize", MATECONF_VALUE_INT, translate_int_int }, - { "/desktop/mate/interface/show_input_method_menu", "Gtk/ShowInputMethodMenu", MATECONF_VALUE_BOOL, translate_bool_int }, - { "/desktop/mate/interface/show_unicode_menu", "Gtk/ShowUnicodeMenu", MATECONF_VALUE_BOOL, translate_bool_int }, - { "/desktop/mate/sound/theme_name", "Net/SoundThemeName", MATECONF_VALUE_STRING, translate_string_string }, - { "/desktop/mate/sound/event_sounds", "Net/EnableEventSounds" , MATECONF_VALUE_BOOL, translate_bool_int }, - { "/desktop/mate/sound/input_feedback_sounds", "Net/EnableInputFeedbackSounds", MATECONF_VALUE_BOOL, translate_bool_int } -}; - -#ifdef HAVE_FONTCONFIG -static double -dpi_from_pixels_and_mm (int pixels, - int mm) -{ - double dpi; - - if (mm >= 1) - dpi = pixels / (mm / 25.4); - else - dpi = 0; - - return dpi; -} - -static double -get_dpi_from_x_server (void) -{ - GdkScreen *screen; - double dpi; - - screen = gdk_screen_get_default (); - if (screen != NULL) { - double width_dpi, height_dpi; - - width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen), gdk_screen_get_width_mm (screen)); - height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen), gdk_screen_get_height_mm (screen)); - - if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE - || height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE) { - dpi = DPI_FALLBACK; - } else { - dpi = (width_dpi + height_dpi) / 2.0; - } - } else { - /* Huh!? No screen? */ - - dpi = DPI_FALLBACK; - } - - return dpi; -} - -static double -get_dpi_from_mateconf_or_x_server (MateConfClient *client) -{ - MateConfValue *value; - double dpi; - - value = mateconf_client_get_without_default (client, FONT_DPI_KEY, NULL); - - /* If the user has ever set the DPI preference in MateConf, we use that. - * Otherwise, we see if the X server reports a reasonable DPI value: some X - * servers report completely bogus values, and the user gets huge or tiny - * fonts which are unusable. - */ - - if (value != NULL) { - dpi = mateconf_value_get_float (value); - mateconf_value_free (value); - } else { - dpi = get_dpi_from_x_server (); - } - - return dpi; -} - -typedef struct -{ - gboolean antialias; - gboolean hinting; - int dpi; - const char *rgba; - const char *hintstyle; -} MateXftSettings; - -static const char *rgba_types[] = { "rgb", "bgr", "vbgr", "vrgb" }; - -/* Read MateConf settings and determine the appropriate Xft settings based on them - * This probably could be done a bit more cleanly with mateconf_string_to_enum - */ -static void -xft_settings_get (MateConfClient *client, - MateXftSettings *settings) -{ - char *antialiasing; - char *hinting; - char *rgba_order; - double dpi; - - antialiasing = mateconf_client_get_string (client, FONT_ANTIALIASING_KEY, NULL); - hinting = mateconf_client_get_string (client, FONT_HINTING_KEY, NULL); - rgba_order = mateconf_client_get_string (client, FONT_RGBA_ORDER_KEY, NULL); - dpi = get_dpi_from_mateconf_or_x_server (client); - - settings->antialias = TRUE; - settings->hinting = TRUE; - settings->hintstyle = "hintfull"; - settings->dpi = dpi * 1024; /* Xft wants 1/1024ths of an inch */ - settings->rgba = "rgb"; - - if (rgba_order) { - int i; - gboolean found = FALSE; - - for (i = 0; i < G_N_ELEMENTS (rgba_types) && !found; i++) { - if (strcmp (rgba_order, rgba_types[i]) == 0) { - settings->rgba = rgba_types[i]; - found = TRUE; - } - } - - if (!found) { - g_warning ("Invalid value for " FONT_RGBA_ORDER_KEY ": '%s'", - rgba_order); - } - } - - if (hinting) { - if (strcmp (hinting, "none") == 0) { - settings->hinting = 0; - settings->hintstyle = "hintnone"; - } else if (strcmp (hinting, "slight") == 0) { - settings->hinting = 1; - settings->hintstyle = "hintslight"; - } else if (strcmp (hinting, "medium") == 0) { - settings->hinting = 1; - settings->hintstyle = "hintmedium"; - } else if (strcmp (hinting, "full") == 0) { - settings->hinting = 1; - settings->hintstyle = "hintfull"; - } else { - g_warning ("Invalid value for " FONT_HINTING_KEY ": '%s'", - hinting); - } - } - - if (antialiasing) { - gboolean use_rgba = FALSE; - - if (strcmp (antialiasing, "none") == 0) { - settings->antialias = 0; - } else if (strcmp (antialiasing, "grayscale") == 0) { - settings->antialias = 1; - } else if (strcmp (antialiasing, "rgba") == 0) { - settings->antialias = 1; - use_rgba = TRUE; - } else { - g_warning ("Invalid value for " FONT_ANTIALIASING_KEY " : '%s'", - antialiasing); - } - - if (!use_rgba) { - settings->rgba = "none"; - } - } - - g_free (rgba_order); - g_free (hinting); - g_free (antialiasing); -} - -static void -xft_settings_set_xsettings (MateXSettingsManager *manager, - MateXftSettings *settings) -{ - int i; - - mate_settings_profile_start (NULL); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_set_int (manager->priv->managers [i], "Xft/Antialias", settings->antialias); - xsettings_manager_set_int (manager->priv->managers [i], "Xft/Hinting", settings->hinting); - xsettings_manager_set_string (manager->priv->managers [i], "Xft/HintStyle", settings->hintstyle); - xsettings_manager_set_int (manager->priv->managers [i], "Xft/DPI", settings->dpi); - xsettings_manager_set_string (manager->priv->managers [i], "Xft/RGBA", settings->rgba); - } - mate_settings_profile_end (NULL); -} - -static void -update_property (GString *props, const gchar* key, const gchar* value) -{ - gchar* needle; - size_t needle_len; - gchar* found = NULL; - - /* update an existing property */ - needle = g_strconcat (key, ":", NULL); - needle_len = strlen (needle); - if (g_str_has_prefix (props->str, needle)) - found = props->str; - else - found = strstr (props->str, needle); - - if (found) { - size_t value_index; - gchar* end; - - end = strchr (found, '\n'); - value_index = (found - props->str) + needle_len + 1; - g_string_erase (props, value_index, end ? (end - found - needle_len) : -1); - g_string_insert (props, value_index, "\n"); - g_string_insert (props, value_index, value); - } else { - g_string_append_printf (props, "%s:\t%s\n", key, value); - } -} - -static void -xft_settings_set_xresources (MateXftSettings *settings) -{ - GString *add_string; - char dpibuf[G_ASCII_DTOSTR_BUF_SIZE]; - Display *dpy; - - mate_settings_profile_start (NULL); - - /* get existing properties */ - dpy = XOpenDisplay (NULL); - g_return_if_fail (dpy != NULL); - add_string = g_string_new (XResourceManagerString (dpy)); - - g_debug("xft_settings_set_xresources: orig res '%s'", add_string->str); - - update_property (add_string, "Xft.dpi", - g_ascii_dtostr (dpibuf, sizeof (dpibuf), (double) settings->dpi / 1024.0)); - update_property (add_string, "Xft.antialias", - settings->antialias ? "1" : "0"); - update_property (add_string, "Xft.hinting", - settings->hinting ? "1" : "0"); - update_property (add_string, "Xft.hintstyle", - settings->hintstyle); - update_property (add_string, "Xft.rgba", - settings->rgba); - - g_debug("xft_settings_set_xresources: new res '%s'", add_string->str); - - /* Set the new X property */ - XChangeProperty(dpy, RootWindow (dpy, 0), - XA_RESOURCE_MANAGER, XA_STRING, 8, PropModeReplace, add_string->str, add_string->len); - XCloseDisplay (dpy); - - g_string_free (add_string, TRUE); - - mate_settings_profile_end (NULL); -} - -/* We mirror the Xft properties both through XSETTINGS and through - * X resources - */ -static void -update_xft_settings (MateXSettingsManager *manager, - MateConfClient *client) -{ - MateXftSettings settings; - - mate_settings_profile_start (NULL); - - xft_settings_get (client, &settings); - xft_settings_set_xsettings (manager, &settings); - xft_settings_set_xresources (&settings); - - mate_settings_profile_end (NULL); -} - -static void -xft_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MateXSettingsManager *manager) -{ - int i; - - update_xft_settings (manager, client); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_notify (manager->priv->managers [i]); - } -} - -static void -fontconfig_callback (fontconfig_monitor_handle_t *handle, - MateXSettingsManager *manager) -{ - int i; - int timestamp = time (NULL); - - mate_settings_profile_start (NULL); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_set_int (manager->priv->managers [i], "Fontconfig/Timestamp", timestamp); - xsettings_manager_notify (manager->priv->managers [i]); - } - mate_settings_profile_end (NULL); -} - -static gboolean -start_fontconfig_monitor_idle_cb (MateXSettingsManager *manager) -{ - mate_settings_profile_start (NULL); - - manager->priv->fontconfig_handle = fontconfig_monitor_start ((GFunc) fontconfig_callback, manager); - - mate_settings_profile_end (NULL); - - return FALSE; -} - -static void -start_fontconfig_monitor (MateXSettingsManager *manager) -{ - mate_settings_profile_start (NULL); - - fontconfig_cache_init (); - - g_idle_add ((GSourceFunc) start_fontconfig_monitor_idle_cb, manager); - - mate_settings_profile_end (NULL); -} - -static void -stop_fontconfig_monitor (MateXSettingsManager *manager) -{ - if (manager->priv->fontconfig_handle) { - fontconfig_monitor_stop (manager->priv->fontconfig_handle); - manager->priv->fontconfig_handle = NULL; - } -} -#endif /* HAVE_FONTCONFIG */ - -static const char * -type_to_string (MateConfValueType type) -{ - switch (type) { - case MATECONF_VALUE_INT: - return "int"; - case MATECONF_VALUE_STRING: - return "string"; - case MATECONF_VALUE_FLOAT: - return "float"; - case MATECONF_VALUE_BOOL: - return "bool"; - case MATECONF_VALUE_SCHEMA: - return "schema"; - case MATECONF_VALUE_LIST: - return "list"; - case MATECONF_VALUE_PAIR: - return "pair"; - case MATECONF_VALUE_INVALID: - return "*invalid*"; - default: - g_assert_not_reached(); - return NULL; /* for warnings */ - } -} - -static void -process_value (MateXSettingsManager *manager, - TranslationEntry *trans, - MateConfValue *val) -{ - if (val == NULL) { - int i; - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_delete_setting (manager->priv->managers [i], trans->xsetting_name); - } - } else { - if (val->type == trans->mateconf_type) { - (* trans->translate) (manager, trans, val); - } else { - g_warning (_("MateConf key %s set to type %s but its expected type was %s\n"), - trans->mateconf_key, - type_to_string (val->type), - type_to_string (trans->mateconf_type)); - } - } -} - -static TranslationEntry * -find_translation_entry (const char *mateconf_key) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (translations); ++i) { - if (strcmp (translations[i].mateconf_key, mateconf_key) == 0) { - return &translations[i]; - } - } - - return NULL; -} - -static void -xsettings_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MateXSettingsManager *manager) -{ - TranslationEntry *trans; - int i; - - trans = find_translation_entry (entry->key); - if (trans == NULL) { - return; - } - - process_value (manager, trans, entry->value); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_set_string (manager->priv->managers [i], - "Net/FallbackIconTheme", - "mate"); - } - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_notify (manager->priv->managers [i]); - } -} - -static gchar * -get_gtk_modules (MateConfClient *client) -{ - GSList *entries, *l; - GString *mods = g_string_new (NULL); - - entries = mateconf_client_all_entries (client, GTK_MODULES_DIR, NULL); - - for (l = entries; l != NULL; l = g_slist_next (l)) { - MateConfEntry *e = l->data; - MateConfValue *v = mateconf_entry_get_value (e); - - if (v != NULL) { - gboolean enabled = FALSE; - const gchar *key; - - switch (v->type) { - case MATECONF_VALUE_BOOL: - /* simple enabled/disabled */ - enabled = mateconf_value_get_bool (v); - break; - - /* due to limitations in MateConf (or the client libraries, - * anyway), it is currently impossible to monitor - * arbitrary keys for changes, so these won't update at - * runtime */ - case MATECONF_VALUE_STRING: - /* linked to another MateConf key of type bool */ - key = mateconf_value_get_string (v); - if (key != NULL && mateconf_valid_key (key, NULL)) { - enabled = mateconf_client_get_bool (client, key, NULL); - } - break; - - default: - g_warning ("MateConf entry %s has invalid type %s", - mateconf_entry_get_key (e), type_to_string (v->type)); - } - - if (enabled) { - const gchar *name; - name = strrchr (mateconf_entry_get_key (e), '/') + 1; - - if (mods->len > 0) { - g_string_append_c (mods, ':'); - } - g_string_append (mods, name); - } - } - - mateconf_entry_free (e); - } - - g_slist_free (entries); - - return g_string_free (mods, mods->len == 0); -} - -static void -gtk_modules_callback (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - MateXSettingsManager *manager) -{ - gchar *modules = get_gtk_modules (client); - int i; - - if (modules == NULL) { - for (i = 0; manager->priv->managers [i]; ++i) { - xsettings_manager_delete_setting (manager->priv->managers [i], "Gtk/Modules"); - } - } else { - g_debug ("Setting GTK modules '%s'", modules); - for (i = 0; manager->priv->managers [i]; ++i) { - xsettings_manager_set_string (manager->priv->managers [i], - "Gtk/Modules", - modules); - } - g_free (modules); - } - - for (i = 0; manager->priv->managers [i]; ++i) { - xsettings_manager_notify (manager->priv->managers [i]); - } -} - -static guint -register_config_callback (MateXSettingsManager *manager, - MateConfClient *client, - const char *path, - MateConfClientNotifyFunc func) -{ - return mateconf_client_notify_add (client, path, func, manager, NULL, NULL); -} - -static void -terminate_cb (void *data) -{ - gboolean *terminated = data; - - if (*terminated) { - return; - } - - *terminated = TRUE; - - gtk_main_quit (); -} - -static gboolean -setup_xsettings_managers (MateXSettingsManager *manager) -{ - GdkDisplay *display; - int i; - int n_screens; - gboolean res; - gboolean terminated; - - display = gdk_display_get_default (); - n_screens = gdk_display_get_n_screens (display); - - res = xsettings_manager_check_running (gdk_x11_display_get_xdisplay (display), - gdk_screen_get_number (gdk_screen_get_default ())); - if (res) { - g_warning ("You can only run one xsettings manager at a time; exiting"); - return FALSE; - } - - manager->priv->managers = g_new0 (XSettingsManager *, n_screens + 1); - - terminated = FALSE; - for (i = 0; i < n_screens; i++) { - GdkScreen *screen; - - screen = gdk_display_get_screen (display, i); - - manager->priv->managers [i] = xsettings_manager_new (gdk_x11_display_get_xdisplay (display), - gdk_screen_get_number (screen), - terminate_cb, - &terminated); - if (! manager->priv->managers [i]) { - g_warning ("Could not create xsettings manager for screen %d!", i); - return FALSE; - } - } - - return TRUE; -} - -gboolean -mate_xsettings_manager_start (MateXSettingsManager *manager, - GError **error) -{ - MateConfClient *client; - int i; - - g_debug ("Starting xsettings manager"); - mate_settings_profile_start (NULL); - - if (!setup_xsettings_managers (manager)) { - g_set_error (error, MSD_XSETTINGS_ERROR, - MSD_XSETTINGS_ERROR_INIT, - "Could not initialize xsettings manager."); - return FALSE; - } - - client = mateconf_client_get_default (); - - mateconf_client_add_dir (client, MOUSE_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - mateconf_client_add_dir (client, GTK_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - mateconf_client_add_dir (client, INTERFACE_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - mateconf_client_add_dir (client, SOUND_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - mateconf_client_add_dir (client, GTK_MODULES_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - mateconf_client_add_dir (client, FONT_RENDER_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); - - for (i = 0; i < G_N_ELEMENTS (translations); i++) { - MateConfValue *val; - GError *err; - - err = NULL; - val = mateconf_client_get (client, - translations[i].mateconf_key, - &err); - - if (err != NULL) { - g_warning ("Error getting value for %s: %s", - translations[i].mateconf_key, - err->message); - g_error_free (err); - } else { - process_value (manager, &translations[i], val); - if (val != NULL) { - mateconf_value_free (val); - } - } - } - - manager->priv->notify[0] = - register_config_callback (manager, client, - MOUSE_SETTINGS_DIR, - (MateConfClientNotifyFunc) xsettings_callback); - manager->priv->notify[1] = - register_config_callback (manager, client, - GTK_SETTINGS_DIR, - (MateConfClientNotifyFunc) xsettings_callback); - manager->priv->notify[2] = - register_config_callback (manager, client, - INTERFACE_SETTINGS_DIR, - (MateConfClientNotifyFunc) xsettings_callback); - manager->priv->notify[3] = - register_config_callback (manager, client, - SOUND_SETTINGS_DIR, - (MateConfClientNotifyFunc) xsettings_callback); - - manager->priv->notify[4] = - register_config_callback (manager, client, - GTK_MODULES_DIR, - (MateConfClientNotifyFunc) gtk_modules_callback); - gtk_modules_callback (client, 0, NULL, manager); - -#ifdef HAVE_FONTCONFIG - manager->priv->notify[5] = - register_config_callback (manager, client, - FONT_RENDER_DIR, - (MateConfClientNotifyFunc) xft_callback); - update_xft_settings (manager, client); - - start_fontconfig_monitor (manager); -#endif /* HAVE_FONTCONFIG */ - - g_object_unref (client); - - for (i = 0; manager->priv->managers [i]; i++) - xsettings_manager_set_string (manager->priv->managers [i], - "Net/FallbackIconTheme", - "mate"); - - for (i = 0; manager->priv->managers [i]; i++) { - xsettings_manager_notify (manager->priv->managers [i]); - } - - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -mate_xsettings_manager_stop (MateXSettingsManager *manager) -{ - MateXSettingsManagerPrivate *p = manager->priv; - MateConfClient *client; - int i; - - g_debug ("Stopping xsettings manager"); - - if (p->managers != NULL) { - for (i = 0; p->managers [i]; ++i) - xsettings_manager_destroy (p->managers [i]); - - g_free (p->managers); - p->managers = NULL; - } - - client = mateconf_client_get_default (); - - mateconf_client_remove_dir (client, MOUSE_SETTINGS_DIR, NULL); - mateconf_client_remove_dir (client, GTK_SETTINGS_DIR, NULL); - mateconf_client_remove_dir (client, INTERFACE_SETTINGS_DIR, NULL); - mateconf_client_remove_dir (client, SOUND_SETTINGS_DIR, NULL); - mateconf_client_remove_dir (client, GTK_MODULES_DIR, NULL); -#ifdef HAVE_FONTCONFIG - mateconf_client_remove_dir (client, FONT_RENDER_DIR, NULL); - - stop_fontconfig_monitor (manager); -#endif /* HAVE_FONTCONFIG */ - - for (i = 0; i < G_N_ELEMENTS (p->notify); ++i) { - if (p->notify[i] != 0) { - mateconf_client_notify_remove (client, p->notify[i]); - p->notify[i] = 0; - } - } - - g_object_unref (client); -} - -static void -mate_xsettings_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MateXSettingsManager *self; - - self = MATE_XSETTINGS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -mate_xsettings_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MateXSettingsManager *self; - - self = MATE_XSETTINGS_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -mate_xsettings_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MateXSettingsManager *xsettings_manager; - MateXSettingsManagerClass *klass; - - klass = MATE_XSETTINGS_MANAGER_CLASS (g_type_class_peek (MATE_TYPE_XSETTINGS_MANAGER)); - - xsettings_manager = MATE_XSETTINGS_MANAGER (G_OBJECT_CLASS (mate_xsettings_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (xsettings_manager); -} - -static void -mate_xsettings_manager_dispose (GObject *object) -{ - MateXSettingsManager *xsettings_manager; - - xsettings_manager = MATE_XSETTINGS_MANAGER (object); - - G_OBJECT_CLASS (mate_xsettings_manager_parent_class)->dispose (object); -} - -static void -mate_xsettings_manager_class_init (MateXSettingsManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = mate_xsettings_manager_get_property; - object_class->set_property = mate_xsettings_manager_set_property; - object_class->constructor = mate_xsettings_manager_constructor; - object_class->dispose = mate_xsettings_manager_dispose; - object_class->finalize = mate_xsettings_manager_finalize; - - g_type_class_add_private (klass, sizeof (MateXSettingsManagerPrivate)); -} - -static void -mate_xsettings_manager_init (MateXSettingsManager *manager) -{ - manager->priv = MATE_XSETTINGS_MANAGER_GET_PRIVATE (manager); -} - -static void -mate_xsettings_manager_finalize (GObject *object) -{ - MateXSettingsManager *xsettings_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MATE_IS_XSETTINGS_MANAGER (object)); - - xsettings_manager = MATE_XSETTINGS_MANAGER (object); - - g_return_if_fail (xsettings_manager->priv != NULL); - - G_OBJECT_CLASS (mate_xsettings_manager_parent_class)->finalize (object); -} - -MateXSettingsManager * -mate_xsettings_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MATE_TYPE_XSETTINGS_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MATE_XSETTINGS_MANAGER (manager_object); -} diff --git a/plugins/xsettings/gsd-xsettings-manager.h b/plugins/xsettings/gsd-xsettings-manager.h deleted file mode 100644 index b97afbf..0000000 --- a/plugins/xsettings/gsd-xsettings-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MATE_XSETTINGS_MANAGER_H -#define __MATE_XSETTINGS_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MATE_TYPE_XSETTINGS_MANAGER (mate_xsettings_manager_get_type ()) -#define MATE_XSETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManager)) -#define MATE_XSETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManagerClass)) -#define MATE_IS_XSETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_TYPE_XSETTINGS_MANAGER)) -#define MATE_IS_XSETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MATE_TYPE_XSETTINGS_MANAGER)) -#define MATE_XSETTINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManagerClass)) - -typedef struct MateXSettingsManagerPrivate MateXSettingsManagerPrivate; - -typedef struct -{ - GObject parent; - MateXSettingsManagerPrivate *priv; -} MateXSettingsManager; - -typedef struct -{ - GObjectClass parent_class; -} MateXSettingsManagerClass; - -GType mate_xsettings_manager_get_type (void); - -MateXSettingsManager * mate_xsettings_manager_new (void); -gboolean mate_xsettings_manager_start (MateXSettingsManager *manager, - GError **error); -void mate_xsettings_manager_stop (MateXSettingsManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_XSETTINGS_MANAGER_H */ diff --git a/plugins/xsettings/gsd-xsettings-plugin.c b/plugins/xsettings/gsd-xsettings-plugin.c deleted file mode 100644 index 50af53a..0000000 --- a/plugins/xsettings/gsd-xsettings-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-xsettings-plugin.h" -#include "msd-xsettings-manager.h" - -struct MateXSettingsPluginPrivate { - MateXSettingsManager *manager; -}; - -#define MATE_XSETTINGS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MateXSettingsPlugin, mate_xsettings_plugin) - -static void -mate_xsettings_plugin_init (MateXSettingsPlugin *plugin) -{ - plugin->priv = MATE_XSETTINGS_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MateXSettingsPlugin initializing"); - - plugin->priv->manager = mate_xsettings_manager_new (); -} - -static void -mate_xsettings_plugin_finalize (GObject *object) -{ - MateXSettingsPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MATE_IS_XSETTINGS_PLUGIN (object)); - - g_debug ("MateXSettingsPlugin finalizing"); - - plugin = MATE_XSETTINGS_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (mate_xsettings_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating xsettings plugin"); - - error = NULL; - res = mate_xsettings_manager_start (MATE_XSETTINGS_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start xsettings manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating xsettings plugin"); - mate_xsettings_manager_stop (MATE_XSETTINGS_PLUGIN (plugin)->priv->manager); -} - -static void -mate_xsettings_plugin_class_init (MateXSettingsPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = mate_xsettings_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MateXSettingsPluginPrivate)); -} diff --git a/plugins/xsettings/gsd-xsettings-plugin.h b/plugins/xsettings/gsd-xsettings-plugin.h deleted file mode 100644 index 88c8331..0000000 --- a/plugins/xsettings/gsd-xsettings-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MATE_XSETTINGS_PLUGIN_H__ -#define __MATE_XSETTINGS_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MATE_TYPE_XSETTINGS_PLUGIN (mate_xsettings_plugin_get_type ()) -#define MATE_XSETTINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPlugin)) -#define MATE_XSETTINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPluginClass)) -#define MATE_IS_XSETTINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_TYPE_XSETTINGS_PLUGIN)) -#define MATE_IS_XSETTINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MATE_TYPE_XSETTINGS_PLUGIN)) -#define MATE_XSETTINGS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPluginClass)) - -typedef struct MateXSettingsPluginPrivate MateXSettingsPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MateXSettingsPluginPrivate *priv; -} MateXSettingsPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MateXSettingsPluginClass; - -GType mate_xsettings_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MATE_XSETTINGS_PLUGIN_H__ */ diff --git a/plugins/xsettings/msd-xsettings-manager.c b/plugins/xsettings/msd-xsettings-manager.c new file mode 100644 index 0000000..9df8f61 --- /dev/null +++ b/plugins/xsettings/msd-xsettings-manager.c @@ -0,0 +1,1040 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 Rodrigo Moya + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "mate-settings-profile.h" +#include "msd-xsettings-manager.h" +#include "xsettings-manager.h" +#ifdef HAVE_FONTCONFIG +#include "fontconfig-monitor.h" +#endif /* HAVE_FONTCONFIG */ + +#define MATE_XSETTINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManagerPrivate)) + +#define MOUSE_SETTINGS_DIR "/desktop/mate/peripherals/mouse" +#define GTK_SETTINGS_DIR "/desktop/gtk" +#define INTERFACE_SETTINGS_DIR "/desktop/mate/interface" +#define SOUND_SETTINGS_DIR "/desktop/mate/sound" +#define GTK_MODULES_DIR "/apps/mate_settings_daemon/gtk-modules" + +#ifdef HAVE_FONTCONFIG +#define FONT_RENDER_DIR "/desktop/mate/font_rendering" +#define FONT_ANTIALIASING_KEY FONT_RENDER_DIR "/antialiasing" +#define FONT_HINTING_KEY FONT_RENDER_DIR "/hinting" +#define FONT_RGBA_ORDER_KEY FONT_RENDER_DIR "/rgba_order" +#define FONT_DPI_KEY FONT_RENDER_DIR "/dpi" + +/* X servers sometimes lie about the screen's physical dimensions, so we cannot + * compute an accurate DPI value. When this happens, the user gets fonts that + * are too huge or too tiny. So, we see what the server returns: if it reports + * something outside of the range [DPI_LOW_REASONABLE_VALUE, + * DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use + * DPI_FALLBACK instead. + * + * See get_dpi_from_mateconf_or_server() below, and also + * https://bugzilla.novell.com/show_bug.cgi?id=217790 + */ +#define DPI_FALLBACK 96 +#define DPI_LOW_REASONABLE_VALUE 50 +#define DPI_HIGH_REASONABLE_VALUE 500 + +#endif /* HAVE_FONTCONFIG */ + +typedef struct _TranslationEntry TranslationEntry; +typedef void (* TranslationFunc) (MateXSettingsManager *manager, + TranslationEntry *trans, + MateConfValue *value); + +struct _TranslationEntry { + const char *mateconf_key; + const char *xsetting_name; + + MateConfValueType mateconf_type; + TranslationFunc translate; +}; + +struct MateXSettingsManagerPrivate +{ + XSettingsManager **managers; + guint notify[6]; +#ifdef HAVE_FONTCONFIG + fontconfig_monitor_handle_t *fontconfig_handle; +#endif /* HAVE_FONTCONFIG */ +}; + +#define MSD_XSETTINGS_ERROR msd_xsettings_error_quark () + +enum { + MSD_XSETTINGS_ERROR_INIT +}; + +static void mate_xsettings_manager_class_init (MateXSettingsManagerClass *klass); +static void mate_xsettings_manager_init (MateXSettingsManager *xsettings_manager); +static void mate_xsettings_manager_finalize (GObject *object); + +G_DEFINE_TYPE (MateXSettingsManager, mate_xsettings_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +static GQuark +msd_xsettings_error_quark (void) +{ + return g_quark_from_static_string ("msd-xsettings-error-quark"); +} + +static void +translate_bool_int (MateXSettingsManager *manager, + TranslationEntry *trans, + MateConfValue *value) +{ + int i; + + g_assert (value->type == trans->mateconf_type); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_int (manager->priv->managers [i], trans->xsetting_name, + mateconf_value_get_bool (value)); + } +} + +static void +translate_int_int (MateXSettingsManager *manager, + TranslationEntry *trans, + MateConfValue *value) +{ + int i; + + g_assert (value->type == trans->mateconf_type); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_int (manager->priv->managers [i], trans->xsetting_name, + mateconf_value_get_int (value)); + } +} + +static void +translate_string_string (MateXSettingsManager *manager, + TranslationEntry *trans, + MateConfValue *value) +{ + int i; + + g_assert (value->type == trans->mateconf_type); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_string (manager->priv->managers [i], + trans->xsetting_name, + mateconf_value_get_string (value)); + } +} + +static void +translate_string_string_toolbar (MateXSettingsManager *manager, + TranslationEntry *trans, + MateConfValue *value) +{ + int i; + const char *tmp; + + g_assert (value->type == trans->mateconf_type); + + /* This is kind of a workaround since MATE expects the key value to be + * "both_horiz" and gtk+ wants the XSetting to be "both-horiz". + */ + tmp = mateconf_value_get_string (value); + if (tmp && strcmp (tmp, "both_horiz") == 0) { + tmp = "both-horiz"; + } + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_string (manager->priv->managers [i], + trans->xsetting_name, + tmp); + } +} + +static TranslationEntry translations [] = { + { "/desktop/mate/peripherals/mouse/double_click", "Net/DoubleClickTime", MATECONF_VALUE_INT, translate_int_int }, + { "/desktop/mate/peripherals/mouse/drag_threshold", "Net/DndDragThreshold", MATECONF_VALUE_INT, translate_int_int }, + { "/desktop/mate/gtk-color-palette", "Gtk/ColorPalette", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/font_name", "Gtk/FontName", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/gtk_key_theme", "Gtk/KeyThemeName", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/toolbar_style", "Gtk/ToolbarStyle", MATECONF_VALUE_STRING, translate_string_string_toolbar }, + { "/desktop/mate/interface/toolbar_icons_size", "Gtk/ToolbarIconSize", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/can_change_accels", "Gtk/CanChangeAccels", MATECONF_VALUE_BOOL, translate_bool_int }, + { "/desktop/mate/interface/cursor_blink", "Net/CursorBlink", MATECONF_VALUE_BOOL, translate_bool_int }, + { "/desktop/mate/interface/cursor_blink_time", "Net/CursorBlinkTime", MATECONF_VALUE_INT, translate_int_int }, + { "/desktop/mate/interface/gtk_theme", "Net/ThemeName", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/gtk_color_scheme", "Gtk/ColorScheme", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/gtk-im-preedit-style", "Gtk/IMPreeditStyle", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/gtk-im-status-style", "Gtk/IMStatusStyle", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/gtk-im-module", "Gtk/IMModule", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/icon_theme", "Net/IconThemeName", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/file_chooser_backend", "Gtk/FileChooserBackend", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/interface/menus_have_icons", "Gtk/MenuImages", MATECONF_VALUE_BOOL, translate_bool_int }, + { "/desktop/mate/interface/buttons_have_icons", "Gtk/ButtonImages", MATECONF_VALUE_BOOL, translate_bool_int }, + { "/desktop/mate/interface/menubar_accel", "Gtk/MenuBarAccel", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/peripherals/mouse/cursor_theme", "Gtk/CursorThemeName", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/peripherals/mouse/cursor_size", "Gtk/CursorThemeSize", MATECONF_VALUE_INT, translate_int_int }, + { "/desktop/mate/interface/show_input_method_menu", "Gtk/ShowInputMethodMenu", MATECONF_VALUE_BOOL, translate_bool_int }, + { "/desktop/mate/interface/show_unicode_menu", "Gtk/ShowUnicodeMenu", MATECONF_VALUE_BOOL, translate_bool_int }, + { "/desktop/mate/sound/theme_name", "Net/SoundThemeName", MATECONF_VALUE_STRING, translate_string_string }, + { "/desktop/mate/sound/event_sounds", "Net/EnableEventSounds" , MATECONF_VALUE_BOOL, translate_bool_int }, + { "/desktop/mate/sound/input_feedback_sounds", "Net/EnableInputFeedbackSounds", MATECONF_VALUE_BOOL, translate_bool_int } +}; + +#ifdef HAVE_FONTCONFIG +static double +dpi_from_pixels_and_mm (int pixels, + int mm) +{ + double dpi; + + if (mm >= 1) + dpi = pixels / (mm / 25.4); + else + dpi = 0; + + return dpi; +} + +static double +get_dpi_from_x_server (void) +{ + GdkScreen *screen; + double dpi; + + screen = gdk_screen_get_default (); + if (screen != NULL) { + double width_dpi, height_dpi; + + width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen), gdk_screen_get_width_mm (screen)); + height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen), gdk_screen_get_height_mm (screen)); + + if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE + || height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE) { + dpi = DPI_FALLBACK; + } else { + dpi = (width_dpi + height_dpi) / 2.0; + } + } else { + /* Huh!? No screen? */ + + dpi = DPI_FALLBACK; + } + + return dpi; +} + +static double +get_dpi_from_mateconf_or_x_server (MateConfClient *client) +{ + MateConfValue *value; + double dpi; + + value = mateconf_client_get_without_default (client, FONT_DPI_KEY, NULL); + + /* If the user has ever set the DPI preference in MateConf, we use that. + * Otherwise, we see if the X server reports a reasonable DPI value: some X + * servers report completely bogus values, and the user gets huge or tiny + * fonts which are unusable. + */ + + if (value != NULL) { + dpi = mateconf_value_get_float (value); + mateconf_value_free (value); + } else { + dpi = get_dpi_from_x_server (); + } + + return dpi; +} + +typedef struct +{ + gboolean antialias; + gboolean hinting; + int dpi; + const char *rgba; + const char *hintstyle; +} MateXftSettings; + +static const char *rgba_types[] = { "rgb", "bgr", "vbgr", "vrgb" }; + +/* Read MateConf settings and determine the appropriate Xft settings based on them + * This probably could be done a bit more cleanly with mateconf_string_to_enum + */ +static void +xft_settings_get (MateConfClient *client, + MateXftSettings *settings) +{ + char *antialiasing; + char *hinting; + char *rgba_order; + double dpi; + + antialiasing = mateconf_client_get_string (client, FONT_ANTIALIASING_KEY, NULL); + hinting = mateconf_client_get_string (client, FONT_HINTING_KEY, NULL); + rgba_order = mateconf_client_get_string (client, FONT_RGBA_ORDER_KEY, NULL); + dpi = get_dpi_from_mateconf_or_x_server (client); + + settings->antialias = TRUE; + settings->hinting = TRUE; + settings->hintstyle = "hintfull"; + settings->dpi = dpi * 1024; /* Xft wants 1/1024ths of an inch */ + settings->rgba = "rgb"; + + if (rgba_order) { + int i; + gboolean found = FALSE; + + for (i = 0; i < G_N_ELEMENTS (rgba_types) && !found; i++) { + if (strcmp (rgba_order, rgba_types[i]) == 0) { + settings->rgba = rgba_types[i]; + found = TRUE; + } + } + + if (!found) { + g_warning ("Invalid value for " FONT_RGBA_ORDER_KEY ": '%s'", + rgba_order); + } + } + + if (hinting) { + if (strcmp (hinting, "none") == 0) { + settings->hinting = 0; + settings->hintstyle = "hintnone"; + } else if (strcmp (hinting, "slight") == 0) { + settings->hinting = 1; + settings->hintstyle = "hintslight"; + } else if (strcmp (hinting, "medium") == 0) { + settings->hinting = 1; + settings->hintstyle = "hintmedium"; + } else if (strcmp (hinting, "full") == 0) { + settings->hinting = 1; + settings->hintstyle = "hintfull"; + } else { + g_warning ("Invalid value for " FONT_HINTING_KEY ": '%s'", + hinting); + } + } + + if (antialiasing) { + gboolean use_rgba = FALSE; + + if (strcmp (antialiasing, "none") == 0) { + settings->antialias = 0; + } else if (strcmp (antialiasing, "grayscale") == 0) { + settings->antialias = 1; + } else if (strcmp (antialiasing, "rgba") == 0) { + settings->antialias = 1; + use_rgba = TRUE; + } else { + g_warning ("Invalid value for " FONT_ANTIALIASING_KEY " : '%s'", + antialiasing); + } + + if (!use_rgba) { + settings->rgba = "none"; + } + } + + g_free (rgba_order); + g_free (hinting); + g_free (antialiasing); +} + +static void +xft_settings_set_xsettings (MateXSettingsManager *manager, + MateXftSettings *settings) +{ + int i; + + mate_settings_profile_start (NULL); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_int (manager->priv->managers [i], "Xft/Antialias", settings->antialias); + xsettings_manager_set_int (manager->priv->managers [i], "Xft/Hinting", settings->hinting); + xsettings_manager_set_string (manager->priv->managers [i], "Xft/HintStyle", settings->hintstyle); + xsettings_manager_set_int (manager->priv->managers [i], "Xft/DPI", settings->dpi); + xsettings_manager_set_string (manager->priv->managers [i], "Xft/RGBA", settings->rgba); + } + mate_settings_profile_end (NULL); +} + +static void +update_property (GString *props, const gchar* key, const gchar* value) +{ + gchar* needle; + size_t needle_len; + gchar* found = NULL; + + /* update an existing property */ + needle = g_strconcat (key, ":", NULL); + needle_len = strlen (needle); + if (g_str_has_prefix (props->str, needle)) + found = props->str; + else + found = strstr (props->str, needle); + + if (found) { + size_t value_index; + gchar* end; + + end = strchr (found, '\n'); + value_index = (found - props->str) + needle_len + 1; + g_string_erase (props, value_index, end ? (end - found - needle_len) : -1); + g_string_insert (props, value_index, "\n"); + g_string_insert (props, value_index, value); + } else { + g_string_append_printf (props, "%s:\t%s\n", key, value); + } +} + +static void +xft_settings_set_xresources (MateXftSettings *settings) +{ + GString *add_string; + char dpibuf[G_ASCII_DTOSTR_BUF_SIZE]; + Display *dpy; + + mate_settings_profile_start (NULL); + + /* get existing properties */ + dpy = XOpenDisplay (NULL); + g_return_if_fail (dpy != NULL); + add_string = g_string_new (XResourceManagerString (dpy)); + + g_debug("xft_settings_set_xresources: orig res '%s'", add_string->str); + + update_property (add_string, "Xft.dpi", + g_ascii_dtostr (dpibuf, sizeof (dpibuf), (double) settings->dpi / 1024.0)); + update_property (add_string, "Xft.antialias", + settings->antialias ? "1" : "0"); + update_property (add_string, "Xft.hinting", + settings->hinting ? "1" : "0"); + update_property (add_string, "Xft.hintstyle", + settings->hintstyle); + update_property (add_string, "Xft.rgba", + settings->rgba); + + g_debug("xft_settings_set_xresources: new res '%s'", add_string->str); + + /* Set the new X property */ + XChangeProperty(dpy, RootWindow (dpy, 0), + XA_RESOURCE_MANAGER, XA_STRING, 8, PropModeReplace, add_string->str, add_string->len); + XCloseDisplay (dpy); + + g_string_free (add_string, TRUE); + + mate_settings_profile_end (NULL); +} + +/* We mirror the Xft properties both through XSETTINGS and through + * X resources + */ +static void +update_xft_settings (MateXSettingsManager *manager, + MateConfClient *client) +{ + MateXftSettings settings; + + mate_settings_profile_start (NULL); + + xft_settings_get (client, &settings); + xft_settings_set_xsettings (manager, &settings); + xft_settings_set_xresources (&settings); + + mate_settings_profile_end (NULL); +} + +static void +xft_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MateXSettingsManager *manager) +{ + int i; + + update_xft_settings (manager, client); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_notify (manager->priv->managers [i]); + } +} + +static void +fontconfig_callback (fontconfig_monitor_handle_t *handle, + MateXSettingsManager *manager) +{ + int i; + int timestamp = time (NULL); + + mate_settings_profile_start (NULL); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_int (manager->priv->managers [i], "Fontconfig/Timestamp", timestamp); + xsettings_manager_notify (manager->priv->managers [i]); + } + mate_settings_profile_end (NULL); +} + +static gboolean +start_fontconfig_monitor_idle_cb (MateXSettingsManager *manager) +{ + mate_settings_profile_start (NULL); + + manager->priv->fontconfig_handle = fontconfig_monitor_start ((GFunc) fontconfig_callback, manager); + + mate_settings_profile_end (NULL); + + return FALSE; +} + +static void +start_fontconfig_monitor (MateXSettingsManager *manager) +{ + mate_settings_profile_start (NULL); + + fontconfig_cache_init (); + + g_idle_add ((GSourceFunc) start_fontconfig_monitor_idle_cb, manager); + + mate_settings_profile_end (NULL); +} + +static void +stop_fontconfig_monitor (MateXSettingsManager *manager) +{ + if (manager->priv->fontconfig_handle) { + fontconfig_monitor_stop (manager->priv->fontconfig_handle); + manager->priv->fontconfig_handle = NULL; + } +} +#endif /* HAVE_FONTCONFIG */ + +static const char * +type_to_string (MateConfValueType type) +{ + switch (type) { + case MATECONF_VALUE_INT: + return "int"; + case MATECONF_VALUE_STRING: + return "string"; + case MATECONF_VALUE_FLOAT: + return "float"; + case MATECONF_VALUE_BOOL: + return "bool"; + case MATECONF_VALUE_SCHEMA: + return "schema"; + case MATECONF_VALUE_LIST: + return "list"; + case MATECONF_VALUE_PAIR: + return "pair"; + case MATECONF_VALUE_INVALID: + return "*invalid*"; + default: + g_assert_not_reached(); + return NULL; /* for warnings */ + } +} + +static void +process_value (MateXSettingsManager *manager, + TranslationEntry *trans, + MateConfValue *val) +{ + if (val == NULL) { + int i; + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_delete_setting (manager->priv->managers [i], trans->xsetting_name); + } + } else { + if (val->type == trans->mateconf_type) { + (* trans->translate) (manager, trans, val); + } else { + g_warning (_("MateConf key %s set to type %s but its expected type was %s\n"), + trans->mateconf_key, + type_to_string (val->type), + type_to_string (trans->mateconf_type)); + } + } +} + +static TranslationEntry * +find_translation_entry (const char *mateconf_key) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (translations); ++i) { + if (strcmp (translations[i].mateconf_key, mateconf_key) == 0) { + return &translations[i]; + } + } + + return NULL; +} + +static void +xsettings_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MateXSettingsManager *manager) +{ + TranslationEntry *trans; + int i; + + trans = find_translation_entry (entry->key); + if (trans == NULL) { + return; + } + + process_value (manager, trans, entry->value); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_set_string (manager->priv->managers [i], + "Net/FallbackIconTheme", + "mate"); + } + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_notify (manager->priv->managers [i]); + } +} + +static gchar * +get_gtk_modules (MateConfClient *client) +{ + GSList *entries, *l; + GString *mods = g_string_new (NULL); + + entries = mateconf_client_all_entries (client, GTK_MODULES_DIR, NULL); + + for (l = entries; l != NULL; l = g_slist_next (l)) { + MateConfEntry *e = l->data; + MateConfValue *v = mateconf_entry_get_value (e); + + if (v != NULL) { + gboolean enabled = FALSE; + const gchar *key; + + switch (v->type) { + case MATECONF_VALUE_BOOL: + /* simple enabled/disabled */ + enabled = mateconf_value_get_bool (v); + break; + + /* due to limitations in MateConf (or the client libraries, + * anyway), it is currently impossible to monitor + * arbitrary keys for changes, so these won't update at + * runtime */ + case MATECONF_VALUE_STRING: + /* linked to another MateConf key of type bool */ + key = mateconf_value_get_string (v); + if (key != NULL && mateconf_valid_key (key, NULL)) { + enabled = mateconf_client_get_bool (client, key, NULL); + } + break; + + default: + g_warning ("MateConf entry %s has invalid type %s", + mateconf_entry_get_key (e), type_to_string (v->type)); + } + + if (enabled) { + const gchar *name; + name = strrchr (mateconf_entry_get_key (e), '/') + 1; + + if (mods->len > 0) { + g_string_append_c (mods, ':'); + } + g_string_append (mods, name); + } + } + + mateconf_entry_free (e); + } + + g_slist_free (entries); + + return g_string_free (mods, mods->len == 0); +} + +static void +gtk_modules_callback (MateConfClient *client, + guint cnxn_id, + MateConfEntry *entry, + MateXSettingsManager *manager) +{ + gchar *modules = get_gtk_modules (client); + int i; + + if (modules == NULL) { + for (i = 0; manager->priv->managers [i]; ++i) { + xsettings_manager_delete_setting (manager->priv->managers [i], "Gtk/Modules"); + } + } else { + g_debug ("Setting GTK modules '%s'", modules); + for (i = 0; manager->priv->managers [i]; ++i) { + xsettings_manager_set_string (manager->priv->managers [i], + "Gtk/Modules", + modules); + } + g_free (modules); + } + + for (i = 0; manager->priv->managers [i]; ++i) { + xsettings_manager_notify (manager->priv->managers [i]); + } +} + +static guint +register_config_callback (MateXSettingsManager *manager, + MateConfClient *client, + const char *path, + MateConfClientNotifyFunc func) +{ + return mateconf_client_notify_add (client, path, func, manager, NULL, NULL); +} + +static void +terminate_cb (void *data) +{ + gboolean *terminated = data; + + if (*terminated) { + return; + } + + *terminated = TRUE; + + gtk_main_quit (); +} + +static gboolean +setup_xsettings_managers (MateXSettingsManager *manager) +{ + GdkDisplay *display; + int i; + int n_screens; + gboolean res; + gboolean terminated; + + display = gdk_display_get_default (); + n_screens = gdk_display_get_n_screens (display); + + res = xsettings_manager_check_running (gdk_x11_display_get_xdisplay (display), + gdk_screen_get_number (gdk_screen_get_default ())); + if (res) { + g_warning ("You can only run one xsettings manager at a time; exiting"); + return FALSE; + } + + manager->priv->managers = g_new0 (XSettingsManager *, n_screens + 1); + + terminated = FALSE; + for (i = 0; i < n_screens; i++) { + GdkScreen *screen; + + screen = gdk_display_get_screen (display, i); + + manager->priv->managers [i] = xsettings_manager_new (gdk_x11_display_get_xdisplay (display), + gdk_screen_get_number (screen), + terminate_cb, + &terminated); + if (! manager->priv->managers [i]) { + g_warning ("Could not create xsettings manager for screen %d!", i); + return FALSE; + } + } + + return TRUE; +} + +gboolean +mate_xsettings_manager_start (MateXSettingsManager *manager, + GError **error) +{ + MateConfClient *client; + int i; + + g_debug ("Starting xsettings manager"); + mate_settings_profile_start (NULL); + + if (!setup_xsettings_managers (manager)) { + g_set_error (error, MSD_XSETTINGS_ERROR, + MSD_XSETTINGS_ERROR_INIT, + "Could not initialize xsettings manager."); + return FALSE; + } + + client = mateconf_client_get_default (); + + mateconf_client_add_dir (client, MOUSE_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + mateconf_client_add_dir (client, GTK_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + mateconf_client_add_dir (client, INTERFACE_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + mateconf_client_add_dir (client, SOUND_SETTINGS_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + mateconf_client_add_dir (client, GTK_MODULES_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + mateconf_client_add_dir (client, FONT_RENDER_DIR, MATECONF_CLIENT_PRELOAD_ONELEVEL, NULL); + + for (i = 0; i < G_N_ELEMENTS (translations); i++) { + MateConfValue *val; + GError *err; + + err = NULL; + val = mateconf_client_get (client, + translations[i].mateconf_key, + &err); + + if (err != NULL) { + g_warning ("Error getting value for %s: %s", + translations[i].mateconf_key, + err->message); + g_error_free (err); + } else { + process_value (manager, &translations[i], val); + if (val != NULL) { + mateconf_value_free (val); + } + } + } + + manager->priv->notify[0] = + register_config_callback (manager, client, + MOUSE_SETTINGS_DIR, + (MateConfClientNotifyFunc) xsettings_callback); + manager->priv->notify[1] = + register_config_callback (manager, client, + GTK_SETTINGS_DIR, + (MateConfClientNotifyFunc) xsettings_callback); + manager->priv->notify[2] = + register_config_callback (manager, client, + INTERFACE_SETTINGS_DIR, + (MateConfClientNotifyFunc) xsettings_callback); + manager->priv->notify[3] = + register_config_callback (manager, client, + SOUND_SETTINGS_DIR, + (MateConfClientNotifyFunc) xsettings_callback); + + manager->priv->notify[4] = + register_config_callback (manager, client, + GTK_MODULES_DIR, + (MateConfClientNotifyFunc) gtk_modules_callback); + gtk_modules_callback (client, 0, NULL, manager); + +#ifdef HAVE_FONTCONFIG + manager->priv->notify[5] = + register_config_callback (manager, client, + FONT_RENDER_DIR, + (MateConfClientNotifyFunc) xft_callback); + update_xft_settings (manager, client); + + start_fontconfig_monitor (manager); +#endif /* HAVE_FONTCONFIG */ + + g_object_unref (client); + + for (i = 0; manager->priv->managers [i]; i++) + xsettings_manager_set_string (manager->priv->managers [i], + "Net/FallbackIconTheme", + "mate"); + + for (i = 0; manager->priv->managers [i]; i++) { + xsettings_manager_notify (manager->priv->managers [i]); + } + + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +mate_xsettings_manager_stop (MateXSettingsManager *manager) +{ + MateXSettingsManagerPrivate *p = manager->priv; + MateConfClient *client; + int i; + + g_debug ("Stopping xsettings manager"); + + if (p->managers != NULL) { + for (i = 0; p->managers [i]; ++i) + xsettings_manager_destroy (p->managers [i]); + + g_free (p->managers); + p->managers = NULL; + } + + client = mateconf_client_get_default (); + + mateconf_client_remove_dir (client, MOUSE_SETTINGS_DIR, NULL); + mateconf_client_remove_dir (client, GTK_SETTINGS_DIR, NULL); + mateconf_client_remove_dir (client, INTERFACE_SETTINGS_DIR, NULL); + mateconf_client_remove_dir (client, SOUND_SETTINGS_DIR, NULL); + mateconf_client_remove_dir (client, GTK_MODULES_DIR, NULL); +#ifdef HAVE_FONTCONFIG + mateconf_client_remove_dir (client, FONT_RENDER_DIR, NULL); + + stop_fontconfig_monitor (manager); +#endif /* HAVE_FONTCONFIG */ + + for (i = 0; i < G_N_ELEMENTS (p->notify); ++i) { + if (p->notify[i] != 0) { + mateconf_client_notify_remove (client, p->notify[i]); + p->notify[i] = 0; + } + } + + g_object_unref (client); +} + +static void +mate_xsettings_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MateXSettingsManager *self; + + self = MATE_XSETTINGS_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +mate_xsettings_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MateXSettingsManager *self; + + self = MATE_XSETTINGS_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +mate_xsettings_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MateXSettingsManager *xsettings_manager; + MateXSettingsManagerClass *klass; + + klass = MATE_XSETTINGS_MANAGER_CLASS (g_type_class_peek (MATE_TYPE_XSETTINGS_MANAGER)); + + xsettings_manager = MATE_XSETTINGS_MANAGER (G_OBJECT_CLASS (mate_xsettings_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (xsettings_manager); +} + +static void +mate_xsettings_manager_dispose (GObject *object) +{ + MateXSettingsManager *xsettings_manager; + + xsettings_manager = MATE_XSETTINGS_MANAGER (object); + + G_OBJECT_CLASS (mate_xsettings_manager_parent_class)->dispose (object); +} + +static void +mate_xsettings_manager_class_init (MateXSettingsManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = mate_xsettings_manager_get_property; + object_class->set_property = mate_xsettings_manager_set_property; + object_class->constructor = mate_xsettings_manager_constructor; + object_class->dispose = mate_xsettings_manager_dispose; + object_class->finalize = mate_xsettings_manager_finalize; + + g_type_class_add_private (klass, sizeof (MateXSettingsManagerPrivate)); +} + +static void +mate_xsettings_manager_init (MateXSettingsManager *manager) +{ + manager->priv = MATE_XSETTINGS_MANAGER_GET_PRIVATE (manager); +} + +static void +mate_xsettings_manager_finalize (GObject *object) +{ + MateXSettingsManager *xsettings_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MATE_IS_XSETTINGS_MANAGER (object)); + + xsettings_manager = MATE_XSETTINGS_MANAGER (object); + + g_return_if_fail (xsettings_manager->priv != NULL); + + G_OBJECT_CLASS (mate_xsettings_manager_parent_class)->finalize (object); +} + +MateXSettingsManager * +mate_xsettings_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MATE_TYPE_XSETTINGS_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MATE_XSETTINGS_MANAGER (manager_object); +} diff --git a/plugins/xsettings/msd-xsettings-manager.h b/plugins/xsettings/msd-xsettings-manager.h new file mode 100644 index 0000000..b97afbf --- /dev/null +++ b/plugins/xsettings/msd-xsettings-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MATE_XSETTINGS_MANAGER_H +#define __MATE_XSETTINGS_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MATE_TYPE_XSETTINGS_MANAGER (mate_xsettings_manager_get_type ()) +#define MATE_XSETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManager)) +#define MATE_XSETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManagerClass)) +#define MATE_IS_XSETTINGS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_TYPE_XSETTINGS_MANAGER)) +#define MATE_IS_XSETTINGS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MATE_TYPE_XSETTINGS_MANAGER)) +#define MATE_XSETTINGS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_TYPE_XSETTINGS_MANAGER, MateXSettingsManagerClass)) + +typedef struct MateXSettingsManagerPrivate MateXSettingsManagerPrivate; + +typedef struct +{ + GObject parent; + MateXSettingsManagerPrivate *priv; +} MateXSettingsManager; + +typedef struct +{ + GObjectClass parent_class; +} MateXSettingsManagerClass; + +GType mate_xsettings_manager_get_type (void); + +MateXSettingsManager * mate_xsettings_manager_new (void); +gboolean mate_xsettings_manager_start (MateXSettingsManager *manager, + GError **error); +void mate_xsettings_manager_stop (MateXSettingsManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MATE_XSETTINGS_MANAGER_H */ diff --git a/plugins/xsettings/msd-xsettings-plugin.c b/plugins/xsettings/msd-xsettings-plugin.c new file mode 100644 index 0000000..50af53a --- /dev/null +++ b/plugins/xsettings/msd-xsettings-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-xsettings-plugin.h" +#include "msd-xsettings-manager.h" + +struct MateXSettingsPluginPrivate { + MateXSettingsManager *manager; +}; + +#define MATE_XSETTINGS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MateXSettingsPlugin, mate_xsettings_plugin) + +static void +mate_xsettings_plugin_init (MateXSettingsPlugin *plugin) +{ + plugin->priv = MATE_XSETTINGS_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MateXSettingsPlugin initializing"); + + plugin->priv->manager = mate_xsettings_manager_new (); +} + +static void +mate_xsettings_plugin_finalize (GObject *object) +{ + MateXSettingsPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MATE_IS_XSETTINGS_PLUGIN (object)); + + g_debug ("MateXSettingsPlugin finalizing"); + + plugin = MATE_XSETTINGS_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (mate_xsettings_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating xsettings plugin"); + + error = NULL; + res = mate_xsettings_manager_start (MATE_XSETTINGS_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start xsettings manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating xsettings plugin"); + mate_xsettings_manager_stop (MATE_XSETTINGS_PLUGIN (plugin)->priv->manager); +} + +static void +mate_xsettings_plugin_class_init (MateXSettingsPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = mate_xsettings_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MateXSettingsPluginPrivate)); +} diff --git a/plugins/xsettings/msd-xsettings-plugin.h b/plugins/xsettings/msd-xsettings-plugin.h new file mode 100644 index 0000000..88c8331 --- /dev/null +++ b/plugins/xsettings/msd-xsettings-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MATE_XSETTINGS_PLUGIN_H__ +#define __MATE_XSETTINGS_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MATE_TYPE_XSETTINGS_PLUGIN (mate_xsettings_plugin_get_type ()) +#define MATE_XSETTINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPlugin)) +#define MATE_XSETTINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPluginClass)) +#define MATE_IS_XSETTINGS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MATE_TYPE_XSETTINGS_PLUGIN)) +#define MATE_IS_XSETTINGS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MATE_TYPE_XSETTINGS_PLUGIN)) +#define MATE_XSETTINGS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MATE_TYPE_XSETTINGS_PLUGIN, MateXSettingsPluginClass)) + +typedef struct MateXSettingsPluginPrivate MateXSettingsPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MateXSettingsPluginPrivate *priv; +} MateXSettingsPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MateXSettingsPluginClass; + +GType mate_xsettings_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MATE_XSETTINGS_PLUGIN_H__ */ -- cgit v1.2.1