[gnome-control-center] Use libunique in the shell to have a single-instance shell
- From: Vincent Untz <vuntz src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-control-center] Use libunique in the shell to have a single-instance shell
- Date: Tue, 11 Aug 2009 09:33:46 +0000 (UTC)
commit 915b55e3fb01dc6f74024b8ac510b1985ba30d52
Author: Vincent Untz <vuntz gnome org>
Date: Sat Aug 8 15:07:16 2009 +0200
Use libunique in the shell to have a single-instance shell
This requires a slight API meaning change in libslab:
create_main_window() doesn't run gtk_main() anymore. This wasn't a good
thing anyway.
configure.in | 2 +-
libslab/app-shell.c | 1 -
shell/control-center.c | 65 ++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 61 insertions(+), 7 deletions(-)
---
diff --git a/configure.in b/configure.in
index 08cc7ab..a0ed56a 100644
--- a/configure.in
+++ b/configure.in
@@ -95,7 +95,7 @@ COMMON_MODULES="gtk+-2.0 >= 2.15.0 dnl
gnome-desktop-2.0 >= 2.25.1"
PKG_CHECK_MODULES(CAPPLET, $COMMON_MODULES)
PKG_CHECK_MODULES(GNOMECC, $COMMON_MODULES libgnome-menu >= 2.10.1)
-PKG_CHECK_MODULES(GNOMECC_SHELL, $COMMON_MODULES libgnome-menu)
+PKG_CHECK_MODULES(GNOMECC_SHELL, $COMMON_MODULES libgnome-menu unique-1.0)
PKG_CHECK_MODULES(DBUS, dbus-1 dbus-glib-1)
PKG_CHECK_MODULES(GNOME_DESKTOP, gnome-desktop-2.0)
PKG_CHECK_MODULES(DEFAULT_APPLICATIONS_CAPPLET, libxml-2.0)
diff --git a/libslab/app-shell.c b/libslab/app-shell.c
index 2cf8e02..ad7293d 100644
--- a/libslab/app-shell.c
+++ b/libslab/app-shell.c
@@ -138,7 +138,6 @@ create_main_window (AppShellData * app_data, const gchar * app_name, const gchar
gtk_window_set_position (GTK_WINDOW (app_data->main_app), GTK_WIN_POS_CENTER);
if (!hidden)
show_shell (app_data);
- gtk_main ();
return TRUE;
}
diff --git a/shell/control-center.c b/shell/control-center.c
index ac0ab9f..c4c154d 100644
--- a/shell/control-center.c
+++ b/shell/control-center.c
@@ -20,15 +20,12 @@
#include "config.h"
-#include <string.h>
-
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libgnome/gnome-desktop-item.h>
-#include <dirent.h>
+#include <unique/unique.h>
-#include "app-shell.h"
-#include "slab-gnome-util.h"
+#include <libslab/slab.h>
void handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data);
static GSList *get_actions_list ();
@@ -101,10 +98,44 @@ handle_static_action_clicked (Tile * tile, TileEvent * event, gpointer data)
g_free (temp);
}
+static UniqueResponse
+message_received_cb (UniqueApp *app,
+ UniqueCommand command,
+ UniqueMessageData *message,
+ guint time,
+ gpointer user_data)
+{
+ UniqueResponse res;
+ AppShellData *app_data = user_data;
+
+ switch (command) {
+ case UNIQUE_ACTIVATE:
+ /* move the main window to the screen that sent us the command */
+ gtk_window_set_screen (GTK_WINDOW (app_data->main_app),
+ unique_message_data_get_screen (message));
+ if (!app_data->main_app_window_shown_once)
+ show_shell (app_data);
+
+ gtk_window_present_with_time (GTK_WINDOW (app_data->main_app),
+ time);
+
+ gtk_widget_grab_focus (SLAB_SECTION (app_data->filter_section)->contents);
+
+ res = UNIQUE_RESPONSE_OK;
+ break;
+ default:
+ res = UNIQUE_RESPONSE_PASSTHROUGH;
+ break;
+ }
+
+ return res;
+}
+
int
main (int argc, char *argv[])
{
gboolean hidden = FALSE;
+ UniqueApp *unique_app;
AppShellData *app_data;
GSList *actions;
GError *error;
@@ -127,6 +158,22 @@ main (int argc, char *argv[])
return 1;
}
+ unique_app = unique_app_new ("org.opensuse.yast-control-center-gnome", NULL);
+ if (unique_app_is_running (unique_app)) {
+ int retval = 0;
+
+ if (!hidden) {
+ UniqueResponse response;
+ response = unique_app_send_message (unique_app,
+ UNIQUE_ACTIVATE,
+ NULL);
+ retval = (response != UNIQUE_RESPONSE_OK);
+ }
+
+ g_object_unref (unique_app);
+ return retval;
+ }
+
app_data = appshelldata_new ("gnomecc.menu", NULL, CONTROL_CENTER_PREFIX,
GTK_ICON_SIZE_DND, FALSE, TRUE);
generate_categories (app_data);
@@ -138,5 +185,13 @@ main (int argc, char *argv[])
create_main_window (app_data, "MyControlCenter", _("Control Center"),
"gnome-control-center", 975, 600, hidden);
+ unique_app_watch_window (unique_app, GTK_WINDOW (app_data->main_app));
+ g_signal_connect (unique_app, "message-received",
+ G_CALLBACK (message_received_cb), app_data);
+
+ gtk_main ();
+
+ g_object_unref (unique_app);
+
return 0;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]