[gnome-control-center/single-window-shell] [display] add a --socket option



commit e94adcf7e9d99b24ab9e8c82d1e2bba66dd6414d
Author: Thomas Wood <thomas wood intel com>
Date:   Tue Jan 12 12:08:29 2010 +0000

    [display] add a --socket option
    
    Allow embedding in another application by adding a --socket option to
    specify the ID of an window.

 capplets/display/display-capplet.ui |    8 ++--
 capplets/display/xrandr-capplet.c   |   77 ++++++++++++++++++++++------------
 2 files changed, 54 insertions(+), 31 deletions(-)
---
diff --git a/capplets/display/display-capplet.ui b/capplets/display/display-capplet.ui
index 5e0a5d0..6eae1ab 100644
--- a/capplets/display/display-capplet.ui
+++ b/capplets/display/display-capplet.ui
@@ -343,7 +343,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="apply_button">
+              <object class="GtkButton" id="apply-button">
                 <property name="label">gtk-apply</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -358,7 +358,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="button2">
+              <object class="GtkButton" id="close-button">
                 <property name="label">gtk-close</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -383,8 +383,8 @@
     </child>
     <action-widgets>
       <action-widget response="-11">helpbutton1</action-widget>
-      <action-widget response="-10">apply_button</action-widget>
-      <action-widget response="-7">button2</action-widget>
+      <action-widget response="-10">apply-button</action-widget>
+      <action-widget response="-7">close-button</action-widget>
     </action-widgets>
   </object>
   <object class="GtkListStore" id="liststore1">
diff --git a/capplets/display/xrandr-capplet.c b/capplets/display/xrandr-capplet.c
index 1d4d12c..fbcf590 100644
--- a/capplets/display/xrandr-capplet.c
+++ b/capplets/display/xrandr-capplet.c
@@ -35,6 +35,8 @@
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-bindings.h>
 
+#include "capplet-util.h"
+
 typedef struct App App;
 typedef struct GrabInfo GrabInfo;
 
@@ -45,6 +47,7 @@ struct App
     GnomeRRLabeler *labeler;
     GnomeOutputInfo         *current_output;
 
+    guint32         socket_id;
     GtkWidget	   *dialog;
     GtkWidget      *current_monitor_event_box;
     GtkWidget      *current_monitor_label;
@@ -2255,6 +2258,8 @@ apply_button_clicked_cb (GtkButton *button, gpointer data)
      */
 
     app->apply_button_clicked_timestamp = gtk_get_current_event_time ();
+
+    apply (app);
 }
 
 static GtkWidget*
@@ -2375,39 +2380,40 @@ run_application (App *app)
     /* Until we have help to show, we'll just hide the Help button */
     hide_help_button (app);
 
-    app->apply_button = _gtk_builder_get_widget (builder, "apply_button");
+    app->apply_button = _gtk_builder_get_widget (builder, "apply-button");
     g_signal_connect (app->apply_button, "clicked",
 		      G_CALLBACK (apply_button_clicked_cb), app);
 
-    on_screen_changed (app->screen, app);
+    g_signal_connect (_gtk_builder_get_widget (builder, "close-button"),
+                      "clicked", G_CALLBACK (gtk_main_quit), NULL);
 
-    g_object_unref (builder);
+    on_screen_changed (app->screen, app);
 
-restart:
-    switch (gtk_dialog_run (GTK_DIALOG (app->dialog)))
+    if (app->socket_id)
     {
-    default:
-	/* Fall Through */
-    case GTK_RESPONSE_DELETE_EVENT:
-    case GTK_RESPONSE_CLOSE:
-#if 0
-	g_debug ("Close");
-#endif
-	break;
+      GtkWidget *content, *plug;
 
-    case GTK_RESPONSE_HELP:
-#if 0
-	g_debug ("Help");
-#endif
-	goto restart;
-	break;
+      /* re-parent contents */
+      content = _gtk_builder_get_widget (builder, "dialog-vbox1");
+
+      plug = gtk_plug_new (app->socket_id);
+      gtk_widget_reparent (content, plug);
+      g_signal_connect (plug, "destroy", G_CALLBACK (gtk_main_quit), NULL);
 
-    case GTK_RESPONSE_APPLY:
-	apply (app);
-	goto restart;
-	break;
+      gtk_widget_show_all (plug);
+
+      gtk_widget_hide (_gtk_builder_get_widget (builder, "close-button"));
+      gtk_container_set_border_width (GTK_CONTAINER (content), 12);
+    }
+    else
+    {
+      gtk_widget_show (GTK_WIDGET (app->dialog));
     }
 
+    g_object_unref (builder);
+
+    gtk_main ();
+
     gtk_widget_destroy (app->dialog);
     gnome_rr_screen_destroy (app->screen);
     g_object_unref (app->client);
@@ -2417,14 +2423,31 @@ int
 main (int argc, char **argv)
 {
     App *app;
+    static guint32 socket_id = 0;
+
+    GOptionContext *context;
+    static GOptionEntry cap_options[] = {
+          { "socket",
+            's',
+            G_OPTION_FLAG_IN_MAIN,
+            G_OPTION_ARG_INT,
+            &socket_id,
+            /* TRANSLATORS: don't translate the terms in brackets */
+            N_("ID of the socket to embed in"),
+            N_("socket") },
+
+          { NULL }
+    };
+
 
-    bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
-    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-    textdomain (GETTEXT_PACKAGE);
+    context = g_option_context_new (_("- GNOME Display Preferences"));
+    g_option_context_add_main_entries (context, cap_options,
+                                       GETTEXT_PACKAGE);
 
-    gtk_init (&argc, &argv);
+    capplet_init (context, &argc, &argv);
 
     app = g_new0 (App, 1);
+    app->socket_id = socket_id;
 
     run_application (app);
 



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