diff options
Diffstat (limited to 'plugins/common')
-rw-r--r-- | plugins/common/daemon-skeleton-gtk.h | 292 | ||||
-rw-r--r-- | plugins/common/daemon-skeleton.h | 264 | ||||
-rw-r--r-- | plugins/common/gsd-input-helper.c | 79 | ||||
-rw-r--r-- | plugins/common/gsd-input-helper.h | 33 | ||||
-rw-r--r-- | plugins/common/gsd-settings-migrate.c | 74 | ||||
-rw-r--r-- | plugins/common/gsd-settings-migrate.h | 43 | ||||
-rw-r--r-- | plugins/common/gsd-shell-helper.c | 66 | ||||
-rw-r--r-- | plugins/common/gsd-shell-helper.h | 42 | ||||
-rw-r--r-- | plugins/common/gsd.gresources.xml | 6 | ||||
-rw-r--r-- | plugins/common/gtk.css | 0 | ||||
-rw-r--r-- | plugins/common/meson.build | 43 |
11 files changed, 942 insertions, 0 deletions
diff --git a/plugins/common/daemon-skeleton-gtk.h b/plugins/common/daemon-skeleton-gtk.h new file mode 100644 index 0000000..596281d --- /dev/null +++ b/plugins/common/daemon-skeleton-gtk.h @@ -0,0 +1,292 @@ +/** + * Create a gnome-settings-daemon helper easily + * + * #define NEW gsd_media_keys_manager_new + * #define START gsd_media_keys_manager_start + * #define MANAGER GsdMediaKeysManager + * #include "gsd-media-keys-manager.h" + * + * #include "daemon-skeleton-gtk.h" + */ + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> +#include <locale.h> + +#include <glib-unix.h> +#include <glib/gi18n.h> +#include <gtk/gtk.h> + +#include "gnome-settings-bus.h" + +#ifndef PLUGIN_NAME +#error Include PLUGIN_CFLAGS in the daemon s CFLAGS +#endif /* !PLUGIN_NAME */ + +#define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" +#define GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate" + +static MANAGER *manager = NULL; +static int timeout = -1; +static char *dummy_name = NULL; +static gboolean verbose = FALSE; + +static GOptionEntry entries[] = { + { "exit-time", 0, 0, G_OPTION_ARG_INT, &timeout, "Exit after n seconds time", NULL }, + { "dummy-name", 0, 0, G_OPTION_ARG_STRING, &dummy_name, "Name when using the dummy daemon", NULL }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose", NULL }, + {NULL} +}; + +static void +respond_to_end_session (GDBusProxy *proxy) +{ + /* we must answer with "EndSessionResponse" */ + g_dbus_proxy_call (proxy, "EndSessionResponse", + g_variant_new ("(bs)", TRUE, ""), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); +} + +static void +do_stop (void) +{ + gtk_main_quit (); +} + +static void +client_proxy_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + if (g_strcmp0 (signal_name, "QueryEndSession") == 0) { + g_debug ("Got QueryEndSession signal"); + respond_to_end_session (proxy); + } else if (g_strcmp0 (signal_name, "EndSession") == 0) { + g_debug ("Got EndSession signal"); + respond_to_end_session (proxy); + } else if (g_strcmp0 (signal_name, "Stop") == 0) { + g_debug ("Got Stop signal"); + do_stop (); + } +} + +static void +on_client_registered (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GVariant *variant; + GDBusProxy *client_proxy; + GError *error = NULL; + gchar *object_path = NULL; + + variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); + if (!variant) { + g_warning ("Unable to register client: %s", error->message); + g_error_free (error); + return; + } + + g_variant_get (variant, "(o)", &object_path); + + g_debug ("Registered client at path %s", object_path); + + client_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, 0, NULL, + GNOME_SESSION_DBUS_NAME, + object_path, + GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE, + NULL, + &error); + if (!client_proxy) { + g_warning ("Unable to get the session client proxy: %s", error->message); + g_error_free (error); + return; + } + + g_signal_connect (client_proxy, "g-signal", + G_CALLBACK (client_proxy_signal_cb), NULL); + + g_free (object_path); + g_variant_unref (variant); +} + +static void +register_with_gnome_session (void) +{ + GDBusProxy *proxy; + const char *startup_id; + + proxy = G_DBUS_PROXY (gnome_settings_bus_get_session_proxy ()); + startup_id = g_getenv ("DESKTOP_AUTOSTART_ID"); + g_dbus_proxy_call (proxy, + "RegisterClient", + g_variant_new ("(ss)", dummy_name ? dummy_name : PLUGIN_NAME, startup_id ? startup_id : ""), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + (GAsyncReadyCallback) on_client_registered, + NULL); + + /* DESKTOP_AUTOSTART_ID must not leak into child processes, because + * it can't be reused. Child processes will not know whether this is + * a genuine value or erroneous already-used value. */ + g_unsetenv ("DESKTOP_AUTOSTART_ID"); +} + +static void +set_empty_gtk_theme (gboolean set) +{ + static char *old_gtk_theme = NULL; + + if (set) { + /* Override GTK_THEME to reduce overhead of CSS engine. By using + * GTK_THEME environment variable, GtkSettings is not allowed to + * initially parse the Adwaita theme. + * + * https://bugzilla.gnome.org/show_bug.cgi?id=780555 */ + old_gtk_theme = g_strdup (g_getenv ("GTK_THEME")); + g_setenv ("GTK_THEME", "Disabled", TRUE); + } else { + /* GtkSettings has loaded, so we can drop GTK_THEME used to initialize + * our internal theme. Only the main thread accesses the GTK_THEME + * environment variable, so this is safe to release. */ + if (old_gtk_theme != NULL) + g_setenv ("GTK_THEME", old_gtk_theme, TRUE); + else + g_unsetenv ("GTK_THEME"); + } +} + +static gboolean +handle_sigterm (gpointer user_data) +{ + g_debug ("Got SIGTERM; shutting down ..."); + + if (gtk_main_level () > 0) + gtk_main_quit (); + + return G_SOURCE_REMOVE; +} + +static void +install_signal_handler (void) +{ + g_autoptr(GSource) source = NULL; + + source = g_unix_signal_source_new (SIGTERM); + + g_source_set_callback (source, handle_sigterm, NULL, NULL); + g_source_attach (source, NULL); +} + +static void +bus_acquired_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data G_GNUC_UNUSED) +{ + g_debug ("%s: acquired bus %p for name %s", G_STRFUNC, connection, name); +} + +static void +name_acquired_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data G_GNUC_UNUSED) +{ + g_debug ("%s: acquired name %s on bus %p", G_STRFUNC, name, connection); +} + +static void +name_lost_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data G_GNUC_UNUSED) +{ + g_debug ("%s: lost name %s on bus %p", G_STRFUNC, name, connection); +} + +int +main (int argc, char **argv) +{ + GError *error = NULL; + guint name_own_id; + + bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + setlocale (LC_ALL, ""); + + set_empty_gtk_theme (TRUE); + +#ifdef GDK_BACKEND + { + const gchar *setup_display = getenv ("GNOME_SETUP_DISPLAY"); + if (setup_display && *setup_display != '\0') + g_setenv ("DISPLAY", setup_display, TRUE); + } + + gdk_set_allowed_backends (GDK_BACKEND); +#endif + + error = NULL; + if (! gtk_init_with_args (&argc, &argv, PLUGIN_NAME, entries, NULL, &error)) { + if (error != NULL) { + fprintf (stderr, "%s\n", error->message); + g_error_free (error); + } + exit (1); + } + + set_empty_gtk_theme (FALSE); + + if (verbose) { + g_setenv ("G_MESSAGES_DEBUG", "all", TRUE); + /* Work around GLib not flushing the output for us by explicitly + * setting buffering to a sane behaviour. This is important + * during testing when the output is not going to a TTY and + * we are reading messages from g_debug on stdout. + * + * See also + * https://bugzilla.gnome.org/show_bug.cgi?id=792432 + */ + setlinebuf (stdout); + } + + if (timeout > 0) { + guint id; + id = g_timeout_add_seconds (timeout, (GSourceFunc) gtk_main_quit, NULL); + g_source_set_name_by_id (id, "[gnome-settings-daemon] gtk_main_quit"); + } + + install_signal_handler (); + + manager = NEW (); + register_with_gnome_session (); + + if (!START (manager, &error)) { + fprintf (stderr, "Failed to start: %s\n", error->message); + g_error_free (error); + exit (1); + } + + name_own_id = g_bus_own_name (G_BUS_TYPE_SESSION, + PLUGIN_DBUS_NAME, + G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE, + bus_acquired_cb, + name_acquired_cb, + name_lost_cb, + NULL, /* user_data */ + NULL /* user_data_free_func */); + + gtk_main (); + + STOP (manager); + + g_object_unref (manager); + g_bus_unown_name (name_own_id); + + return 0; +} diff --git a/plugins/common/daemon-skeleton.h b/plugins/common/daemon-skeleton.h new file mode 100644 index 0000000..40b7f14 --- /dev/null +++ b/plugins/common/daemon-skeleton.h @@ -0,0 +1,264 @@ +/** + * Create a gnome-settings-daemon helper easily + * + * #define NEW gsd_media_keys_manager_new + * #define START gsd_media_keys_manager_start + * #define MANAGER GsdMediaKeysManager + * #include "gsd-media-keys-manager.h" + * + * #include "daemon-skeleton.h" + */ + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> +#include <locale.h> + +#include <glib-unix.h> +#include <glib/gi18n.h> + +#include "gnome-settings-bus.h" + +#ifndef PLUGIN_NAME +#error Include PLUGIN_CFLAGS in the daemon s CFLAGS +#endif /* !PLUGIN_NAME */ + +#ifndef PLUGIN_DBUS_NAME +#error Include PLUGIN_DBUS_NAME in the daemon s CFLAGS +#endif /* !PLUGIN_DBUS_NAME */ + +#define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" +#define GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate" + +static MANAGER *manager = NULL; +static int timeout = -1; +static char *dummy_name = NULL; +static gboolean verbose = FALSE; + +static GOptionEntry entries[] = { + { "exit-time", 0, 0, G_OPTION_ARG_INT, &timeout, "Exit after n seconds time", NULL }, + { "dummy-name", 0, 0, G_OPTION_ARG_STRING, &dummy_name, "Name when using the dummy daemon", NULL }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose", NULL }, + {NULL} +}; + +static void +respond_to_end_session (GDBusProxy *proxy) +{ + /* we must answer with "EndSessionResponse" */ + g_dbus_proxy_call (proxy, "EndSessionResponse", + g_variant_new ("(bs)", TRUE, ""), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL, NULL); +} + +static void +do_stop (GMainLoop *loop) +{ + g_main_loop_quit (loop); +} + +static void +client_proxy_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + if (g_strcmp0 (signal_name, "QueryEndSession") == 0) { + g_debug ("Got QueryEndSession signal"); + respond_to_end_session (proxy); + } else if (g_strcmp0 (signal_name, "EndSession") == 0) { + g_debug ("Got EndSession signal"); + respond_to_end_session (proxy); + } else if (g_strcmp0 (signal_name, "Stop") == 0) { + g_debug ("Got Stop signal"); + do_stop (user_data); + } +} + +static void +on_client_registered (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GVariant *variant; + GMainLoop *loop = user_data; + GDBusProxy *client_proxy; + GError *error = NULL; + gchar *object_path = NULL; + + variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); + if (!variant) { + g_warning ("Unable to register client: %s", error->message); + g_error_free (error); + return; + } + + g_variant_get (variant, "(o)", &object_path); + + g_debug ("Registered client at path %s", object_path); + + client_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, 0, NULL, + GNOME_SESSION_DBUS_NAME, + object_path, + GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE, + NULL, + &error); + if (!client_proxy) { + g_warning ("Unable to get the session client proxy: %s", error->message); + g_error_free (error); + return; + } + + g_signal_connect (client_proxy, "g-signal", + G_CALLBACK (client_proxy_signal_cb), loop); + + g_free (object_path); + g_variant_unref (variant); +} + +static void +register_with_gnome_session (GMainLoop *loop) +{ + GDBusProxy *proxy; + const char *startup_id; + + proxy = G_DBUS_PROXY (gnome_settings_bus_get_session_proxy ()); + startup_id = g_getenv ("DESKTOP_AUTOSTART_ID"); + g_dbus_proxy_call (proxy, + "RegisterClient", + g_variant_new ("(ss)", dummy_name ? dummy_name : PLUGIN_NAME, startup_id ? startup_id : ""), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + (GAsyncReadyCallback) on_client_registered, + loop); + + /* DESKTOP_AUTOSTART_ID must not leak into child processes, because + * it can't be reused. Child processes will not know whether this is + * a genuine value or erroneous already-used value. */ + g_unsetenv ("DESKTOP_AUTOSTART_ID"); +} + +static gboolean +handle_sigterm (gpointer user_data) +{ + GMainLoop *main_loop = user_data; + + g_debug ("Got SIGTERM; shutting down ..."); + + if (g_main_loop_is_running (main_loop)) + g_main_loop_quit (main_loop); + + return G_SOURCE_REMOVE; +} + +static void +install_signal_handler (GMainLoop *loop) +{ + g_autoptr(GSource) source = NULL; + + source = g_unix_signal_source_new (SIGTERM); + + g_source_set_callback (source, handle_sigterm, loop, NULL); + g_source_attach (source, NULL); +} + +static void +bus_acquired_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data G_GNUC_UNUSED) +{ + g_debug ("%s: acquired bus %p for name %s", G_STRFUNC, connection, name); +} + +static void +name_acquired_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data G_GNUC_UNUSED) +{ + g_debug ("%s: acquired name %s on bus %p", G_STRFUNC, name, connection); +} + +static void +name_lost_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data G_GNUC_UNUSED) +{ + g_debug ("%s: lost name %s on bus %p", G_STRFUNC, name, connection); +} + +int +main (int argc, char **argv) +{ + GError *error = NULL; + GOptionContext *context; + GMainLoop *loop; + guint name_own_id; + + bindtextdomain (GETTEXT_PACKAGE, GNOME_SETTINGS_LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + setlocale (LC_ALL, ""); + + context = g_option_context_new (NULL); + g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); + if (!g_option_context_parse (context, &argc, &argv, &error)) { + fprintf (stderr, "%s\n", error->message); + g_error_free (error); + exit (1); + } + g_option_context_free (context); + + loop = g_main_loop_new (NULL, FALSE); + + if (verbose) { + g_setenv ("G_MESSAGES_DEBUG", "all", TRUE); + /* Work around GLib not flushing the output for us by explicitly + * setting buffering to a sane behaviour. This is important + * during testing when the output is not going to a TTY and + * we are reading messages from g_debug on stdout. + * + * See also + * https://bugzilla.gnome.org/show_bug.cgi?id=792432 + */ + setlinebuf (stdout); + } + + if (timeout > 0) { + guint id; + id = g_timeout_add_seconds (timeout, (GSourceFunc) g_main_loop_quit, loop); + g_source_set_name_by_id (id, "[gnome-settings-daemon] g_main_loop_quit"); + } + + install_signal_handler (loop); + + manager = NEW (); + register_with_gnome_session (loop); + + if (!START (manager, &error)) { + fprintf (stderr, "Failed to start: %s\n", error->message); + g_error_free (error); + exit (1); + } + + name_own_id = g_bus_own_name (G_BUS_TYPE_SESSION, + PLUGIN_DBUS_NAME, + G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE, + bus_acquired_cb, + name_acquired_cb, + name_lost_cb, + NULL, /* user_data */ + NULL /* user_data_free_func */); + + g_main_loop_run (loop); + + STOP (manager); + + g_object_unref (manager); + g_bus_unown_name (name_own_id); + + return 0; +} diff --git a/plugins/common/gsd-input-helper.c b/plugins/common/gsd-input-helper.c new file mode 100644 index 0000000..d806ccf --- /dev/null +++ b/plugins/common/gsd-input-helper.c @@ -0,0 +1,79 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2010 Bastien Nocera <hadess@hadess.net> + * + * 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, see <http://www.gnu.org/licenses/>. + * + */ + +#include "config.h" + +#include <string.h> + +#include <gdk/gdk.h> +#include <gdk/gdkx.h> + +#include <sys/types.h> +#include <X11/Xatom.h> +#include <X11/extensions/XInput2.h> + +#include "gsd-input-helper.h" + +char * +xdevice_get_device_node (int deviceid) +{ + Atom prop; + Atom act_type; + int act_format; + unsigned long nitems, bytes_after; + unsigned char *data; + char *ret; + + gdk_display_sync (gdk_display_get_default ()); + + prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Node", False); + if (!prop) + return NULL; + + gdk_x11_display_error_trap_push (gdk_display_get_default ()); + + if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), + deviceid, prop, 0, 1000, False, + AnyPropertyType, &act_type, &act_format, + &nitems, &bytes_after, &data) == Success) { + gdk_x11_display_error_trap_pop_ignored (gdk_display_get_default ()); + return NULL; + } + if (gdk_x11_display_error_trap_pop (gdk_display_get_default ())) + goto out; + + if (nitems == 0) + goto out; + + if (act_type != XA_STRING) + goto out; + + /* Unknown string format */ + if (act_format != 8) + goto out; + + ret = g_strdup ((char *) data); + + XFree (data); + return ret; + +out: + XFree (data); + return NULL; +} diff --git a/plugins/common/gsd-input-helper.h b/plugins/common/gsd-input-helper.h new file mode 100644 index 0000000..ae0d3ab --- /dev/null +++ b/plugins/common/gsd-input-helper.h @@ -0,0 +1,33 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2010 Bastien Nocera <hadess@hadess.net> + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __GSD_INPUT_HELPER_H +#define __GSD_INPUT_HELPER_H + +G_BEGIN_DECLS + +#include <glib.h> + +#include <X11/extensions/XInput.h> +#include <X11/extensions/XIproto.h> + +char * xdevice_get_device_node (int deviceid); + +G_END_DECLS + +#endif /* __GSD_INPUT_HELPER_H */ diff --git a/plugins/common/gsd-settings-migrate.c b/plugins/common/gsd-settings-migrate.c new file mode 100644 index 0000000..a0e5cb8 --- /dev/null +++ b/plugins/common/gsd-settings-migrate.c @@ -0,0 +1,74 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2015 Red Hat + * + * 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. + * + * Author: Carlos Garnacho <carlosg@gnome.org> + */ + +#include "config.h" + +#include <gio/gio.h> + +#include "gsd-settings-migrate.h" + +void +gsd_settings_migrate_check (const gchar *origin_schema, + const gchar *origin_path, + const gchar *dest_schema, + const gchar *dest_path, + GsdSettingsMigrateEntry entries[], + guint n_entries) +{ + GSettings *origin_settings, *dest_settings; + guint i; + + origin_settings = g_settings_new_with_path (origin_schema, origin_path); + dest_settings = g_settings_new_with_path (dest_schema, dest_path); + + for (i = 0; i < n_entries; i++) { + g_autoptr(GVariant) variant = NULL; + + variant = g_settings_get_user_value (origin_settings, entries[i].origin_key); + + if (!variant) + continue; + + g_settings_reset (origin_settings, entries[i].origin_key); + + if (entries[i].dest_key) { + if (entries[i].func) { + g_autoptr(GVariant) old_default = NULL; + g_autoptr(GVariant) new_default = NULL; + GVariant *modified; + + old_default = g_settings_get_default_value (origin_settings, entries[i].origin_key); + new_default = g_settings_get_default_value (dest_settings, entries[i].dest_key); + + modified = entries[i].func (variant, old_default, new_default); + g_clear_pointer (&variant, g_variant_unref); + if (modified) + variant = g_variant_ref_sink (modified); + } + + if (variant) + g_settings_set_value (dest_settings, entries[i].dest_key, variant); + } + } + + g_object_unref (origin_settings); + g_object_unref (dest_settings); +} diff --git a/plugins/common/gsd-settings-migrate.h b/plugins/common/gsd-settings-migrate.h new file mode 100644 index 0000000..b8d2259 --- /dev/null +++ b/plugins/common/gsd-settings-migrate.h @@ -0,0 +1,43 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2015 Red Hat + * + * 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. + * + * Author: Carlos Garnacho <carlosg@gnome.org> + */ + +#ifndef __GSD_SETTINGS_MIGRATE_H__ +#define __GSD_SETTINGS_MIGRATE_H__ + +typedef struct _GsdSettingsMigrateEntry GsdSettingsMigrateEntry; + +typedef GVariant * (* GsdSettingsMigrateFunc) (GVariant *variant, GVariant *old_default, GVariant *new_default); + +struct _GsdSettingsMigrateEntry +{ + const gchar *origin_key; + const gchar *dest_key; + GsdSettingsMigrateFunc func; +}; + +void gsd_settings_migrate_check (const gchar *origin_schema, + const gchar *origin_path, + const gchar *dest_schema, + const gchar *dest_path, + GsdSettingsMigrateEntry entries[], + guint n_entries); + +#endif /* __GSD_SETTINGS_MIGRATE_H__ */ diff --git a/plugins/common/gsd-shell-helper.c b/plugins/common/gsd-shell-helper.c new file mode 100644 index 0000000..e4a2f23 --- /dev/null +++ b/plugins/common/gsd-shell-helper.c @@ -0,0 +1,66 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Carlos Garnacho <carlosg@gnome.org> + * + * 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, see <http://www.gnu.org/licenses/>. + * + */ + +#include "config.h" +#include "gsd-shell-helper.h" + +void +shell_show_osd (GsdShell *shell, + const gchar *icon_name, + const gchar *label, + double level, + const gchar *connector) +{ + shell_show_osd_with_max_level (shell, icon_name, label, level, -1, connector); +} + +void +shell_show_osd_with_max_level (GsdShell *shell, + const gchar *icon_name, + const gchar *label, + double level, + double max_level, + const gchar *connector) +{ + GVariantBuilder builder; + + g_return_if_fail (GSD_IS_SHELL (shell)); + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + + if (icon_name) + g_variant_builder_add (&builder, "{sv}", + "icon", g_variant_new_string (icon_name)); + if (label) + g_variant_builder_add (&builder, "{sv}", + "label", g_variant_new_string (label)); + if (level >= 0.0) + g_variant_builder_add (&builder, "{sv}", + "level", g_variant_new_double (level)); + if (max_level > 1.0) + g_variant_builder_add (&builder, "{sv}", + "max_level", g_variant_new_double (max_level)); + if (connector) + g_variant_builder_add (&builder, "{sv}", + "connector", g_variant_new_string (connector)); + + gsd_shell_call_show_osd (shell, + g_variant_builder_end (&builder), + NULL, NULL, NULL); +} diff --git a/plugins/common/gsd-shell-helper.h b/plugins/common/gsd-shell-helper.h new file mode 100644 index 0000000..16a694b --- /dev/null +++ b/plugins/common/gsd-shell-helper.h @@ -0,0 +1,42 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Carlos Garnacho <carlosg@gnome.org> + * + * 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, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __GSD_SHELL_HELPER_H__ +#define __GSD_SHELL_HELPER_H__ + +#include "gsd-shell-glue.h" + +G_BEGIN_DECLS + +void shell_show_osd (GsdShell *shell, + const gchar *icon_name, + const gchar *label, + double level, + const gchar *connector); + +void shell_show_osd_with_max_level (GsdShell *shell, + const gchar *icon_name, + const gchar *label, + double level, + double max_level, + const gchar *connector); + +G_END_DECLS + +#endif /* __GSD_SHELL_HELPER_H__ */ diff --git a/plugins/common/gsd.gresources.xml b/plugins/common/gsd.gresources.xml new file mode 100644 index 0000000..e4ac1cd --- /dev/null +++ b/plugins/common/gsd.gresources.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gtk/libgtk/theme/Disabled"> + <file>gtk.css</file> + </gresource> +</gresources> diff --git a/plugins/common/gtk.css b/plugins/common/gtk.css new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/common/gtk.css diff --git a/plugins/common/meson.build b/plugins/common/meson.build new file mode 100644 index 0000000..2f18c2c --- /dev/null +++ b/plugins/common/meson.build @@ -0,0 +1,43 @@ +common_inc = include_directories('.') + +sources = files( + 'gsd-input-helper.c', + 'gsd-settings-migrate.c', + 'gsd-shell-helper.c' +) + +resource_data = files('gtk.css') + +sources += gnome.compile_resources( + 'gsd-resources', + 'gsd.gresources.xml', + c_name: 'gsd', + dependencies: resource_data +) + +deps = plugins_deps + [ + gnome_desktop_dep, + gtk_x11_dep, + x11_dep, + dependency('kbproto'), + dependency('xi') +] + +ldflags = [] +if host_is_darwin + ldflags += ['-Wl,-bundle_loader,@0@'.format(join_paths(), meson.build_root(), meson.project_name(), meson.project_name())] +endif + +libcommon = static_library( + plugin_name, + sources: sources, + include_directories: [top_inc, data_inc], + dependencies: deps, + c_args: cflags, + link_args: ldflags +) + +libcommon_dep = declare_dependency( + include_directories: common_inc, + link_with: libcommon +) |