[gnome-flashback] add gnome-flashback-init



commit 24495c83d25e3a4df530835cd8996a64d545f358
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Oct 16 18:21:45 2014 +0300

    add gnome-flashback-init
    
    Add new gnome-flashback-init application that will be autostarted
    in Initialization phase. This will allow as to set some session
    environment variables.
    
    Currently it will be only used to set XDG_MENU_PREFIX.

 Makefile.am                                        |    1 +
 configure.ac                                       |    5 +
 gnome-flashback-init/Makefile.am                   |   28 +++++
 .../gnome-flashback-init.desktop.in                |    9 ++
 gnome-flashback-init/main.c                        |  117 ++++++++++++++++++++
 po/POTFILES.in                                     |    1 +
 sessions/gnome-flashback-compiz.session.in         |    2 +-
 sessions/gnome-flashback-metacity.session.in       |    2 +-
 8 files changed, 163 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 6b9a03d..c81c2ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,6 @@
 SUBDIRS = \
        gnome-flashback \
+       gnome-flashback-init \
        po \
        sessions
 
diff --git a/configure.ac b/configure.ac
index 2bbca9e..a1807af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,6 +36,10 @@ PKG_CHECK_MODULES(GNOME_FLASHBACK, gtk+-3.0 >= $GTK_REQUIRED)
 AC_SUBST(GNOME_FLASHBACK_CFLAGS)
 AC_SUBST(GNOME_FLASHBACK_LIBS)
 
+PKG_CHECK_MODULES(GNOME_FLASHBACK_INIT, gtk+-3.0 >= $GTK_REQUIRED)
+AC_SUBST(GNOME_FLASHBACK_INIT_CFLAGS)
+AC_SUBST(GNOME_FLASHBACK_INIT_LIBS)
+
 PKG_CHECK_MODULES(END_SESSION_DIALOG, gtk+-3.0 >= $GTK_REQUIRED)
 AC_SUBST(END_SESSION_DIALOG_CFLAGS)
 AC_SUBST(END_SESSION_DIALOG_LIBS)
@@ -68,6 +72,7 @@ gnome-flashback/libend-session-dialog/Makefile
 gnome-flashback/libidle-monitor/Makefile
 gnome-flashback/libsound-applet/Makefile
 gnome-flashback/libsound-applet/gvc/Makefile
+gnome-flashback-init/Makefile
 po/Makefile.in
 sessions/Makefile
 ])
diff --git a/gnome-flashback-init/Makefile.am b/gnome-flashback-init/Makefile.am
new file mode 100644
index 0000000..f5c30a4
--- /dev/null
+++ b/gnome-flashback-init/Makefile.am
@@ -0,0 +1,28 @@
+bin_PROGRAMS = \
+       gnome-flashback-init
+
+AM_CPPFLAGS = \
+       $(GNOME_FLASHBACK_INIT_CFLAGS) \
+       -I$(top_builddir)/gnome-flashback-init
+
+gnome_flashback_init_SOURCES = \
+       main.c
+
+gnome_flashback_init_LDADD = \
+       $(GNOME_FLASHBACK_INIT_LIBS)
+
+desktopdir       = $(datadir)/applications
+desktop_in_files = gnome-flashback-init.desktop.in
+desktop_DATA     = $(desktop_in_files:.desktop.in=.desktop)
+
+%.desktop: %.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d 
-u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< $@
+
+ INTLTOOL_XML_NOMERGE_RULE@
+
+EXTRA_DIST = \
+       $(desktop_in_files)
+
+CLEANFILES = \
+       $(desktop_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/gnome-flashback-init/gnome-flashback-init.desktop.in 
b/gnome-flashback-init/gnome-flashback-init.desktop.in
new file mode 100644
index 0000000..c3e11d2
--- /dev/null
+++ b/gnome-flashback-init/gnome-flashback-init.desktop.in
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Type=Application
+_Name=GNOME Flashback Initialization
+Exec=gnome-flashback-init
+OnlyShowIn=GNOME;
+NoDisplay=true
+X-GNOME-Autostart-Phase=Initialization
+X-GNOME-Autostart-Notify=true
+X-GNOME-AutoRestart=true
diff --git a/gnome-flashback-init/main.c b/gnome-flashback-init/main.c
new file mode 100644
index 0000000..c2aba3f
--- /dev/null
+++ b/gnome-flashback-init/main.c
@@ -0,0 +1,117 @@
+/* 
+ * Copyright (C) 2014 Alberts Muktupāvels
+ *
+ * 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 3 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 <gtk/gtk.h>
+
+static void
+set_session_env (GDBusProxy  *proxy,
+                 const gchar *name,
+                 const gchar *value)
+{
+       GError *error;
+       GVariant *parameters;
+       GVariant *res;
+
+       error = NULL;
+       parameters = g_variant_new ("(ss)", name, value);
+       res = g_dbus_proxy_call_sync (proxy,
+                                     "Setenv",
+                                     parameters,
+                                     G_DBUS_CALL_FLAGS_NONE,
+                                     -1,
+                                     NULL,
+                                     &error);
+
+       if (error) {
+               g_debug ("Failed to set the environment: %s", error->message);
+               g_error_free (error);
+               return;
+       }
+
+       g_variant_unref (res);
+}
+
+int
+main (int argc, char *argv[])
+{
+       GError *error;
+       GDBusConnection *connection;
+       GDBusProxy *proxy;
+       const gchar *app_id;
+       const gchar *client_startup_id;
+       GVariant *parameters;
+       GVariant *res;
+
+       error = NULL;
+       connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+       if (!connection) {
+               g_warning ("Cannot connect to session bus: %s", error->message);
+               g_error_free (error);
+               return 1;
+       }
+
+       g_warning ("Connecting to session manager");
+
+       proxy = g_dbus_proxy_new_sync (connection,
+                                      G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+                                      G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+                                      NULL,
+                                      "org.gnome.SessionManager",
+                                      "/org/gnome/SessionManager",
+                                      "org.gnome.SessionManager",
+                                      NULL,
+                                      &error);
+
+       if (error) {
+               g_warning ("Failed to get a session proxy: %s", error->message);
+               g_error_free (error);
+               g_object_unref (connection);
+               return 1;
+       }
+
+       set_session_env (proxy, "XDG_MENU_PREFIX", "gnome-flashback-");
+
+       app_id = "gnome-flashback-init";
+       client_startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+
+       g_warning ("Registering client '%s' '%s'", app_id, client_startup_id);
+
+       parameters = g_variant_new ("(ss)",app_id, client_startup_id ? client_startup_id : "");
+       res = g_dbus_proxy_call_sync (proxy,
+                                     "RegisterClient",
+                                     parameters,
+                                     G_DBUS_CALL_FLAGS_NONE,
+                                     -1,
+                                     NULL,
+                                     &error);
+
+       if (error) {
+               g_warning ("Failed to register client: %s", error->message);
+               g_error_free (error);
+               g_object_unref (proxy);
+               g_object_unref (connection);
+               return 1;
+       }
+
+       g_variant_unref (res);
+       g_object_unref (proxy);
+       g_object_unref (connection);
+
+       return 0;
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ea39d52..e6b7883 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,6 +9,7 @@ gnome-flashback/libsound-applet/gvc-channel-bar.c
 gnome-flashback/libsound-applet/gvc-stream-status-icon.c
 gnome-flashback/libsound-applet/gvc/gvc-mixer-control.c
 gnome-flashback/org.gnome.gnome-flashback.gschema.xml.in.in
+gnome-flashback-init/gnome-flashback-init.desktop.in
 sessions/gnome-flashback-compiz.desktop.in.in
 sessions/gnome-flashback-compiz.session.in
 sessions/gnome-flashback-metacity.desktop.in.in
diff --git a/sessions/gnome-flashback-compiz.session.in b/sessions/gnome-flashback-compiz.session.in
index 307aa36..ff84a4a 100644
--- a/sessions/gnome-flashback-compiz.session.in
+++ b/sessions/gnome-flashback-compiz.session.in
@@ -1,3 +1,3 @@
 [GNOME Session]
 _Name=GNOME Flashback (Compiz)
-RequiredComponents=gnome-flashback;gnome-panel;compiz;gnome-settings-daemon;
+RequiredComponents=gnome-flashback-init;gnome-flashback;gnome-panel;compiz;gnome-settings-daemon;
diff --git a/sessions/gnome-flashback-metacity.session.in b/sessions/gnome-flashback-metacity.session.in
index 8e562fb..d591bba 100644
--- a/sessions/gnome-flashback-metacity.session.in
+++ b/sessions/gnome-flashback-metacity.session.in
@@ -1,3 +1,3 @@
 [GNOME Session]
 _Name=GNOME Flashback (Metacity)
-RequiredComponents=gnome-flashback;gnome-panel;metacity;gnome-settings-daemon;
+RequiredComponents=gnome-flashback-init;gnome-flashback;gnome-panel;metacity;gnome-settings-daemon;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]