Author: jannis
Date: 2008-09-14 18:22:51 +0000 (Sun, 14 Sep 2008)
New Revision: 27865

Modified:
   xfce4-settings/trunk/TODO
   xfce4-settings/trunk/xfce4-settings-manager/main.c
   xfce4-settings/trunk/xfce4-settings-manager/xfce-settings-manager-dialog.c
Log:
Use 2/3 of the screen width and height for the main settings dialog or
fall back to a pre-defined minimum size of that's considered to small.
This works better on my machine and should be ok for all resolutions
starting at 800x600.

Add support for embedding settings dialogs into xfce4-settings-manager.
Update TODO with a few things that still need to be done.

Modified: xfce4-settings/trunk/TODO
===================================================================
--- xfce4-settings/trunk/TODO   2008-09-14 14:53:35 UTC (rev 27864)
+++ xfce4-settings/trunk/TODO   2008-09-14 18:22:51 UTC (rev 27865)
@@ -7,11 +7,8 @@
     The maximum values also seem to be a bit high.
   * IMPORTANT (for the final release): Update the property-changed 
     handler so that they it adds a new row for new properties
-  * IMPORTANT (for the final release): Don't display Mod2-Mod5. Instead 
-    figure out which modifiers are mapped to them and unmask the modifier
-    bits before calling gtk_accelerator_name(). Update 
-    xfce4-settings-helper according to this as well (just the other way
-    around).
+  * IMPORTANT (for the final release): Improve the libfrap code for
+    shortcuts. It could be less complicated.
   * IMPORTANT (for the final release): Hard-coded default shortcuts and
     an option to reset them to defaults (see xfwm4).
 
@@ -29,6 +26,21 @@
     a pid file, but I'm not sure that's a good solution...
 
 
+Settings Manager
+------------------------------------------------------------------------
+
+  * Add embed support to all dialogs (not only those in xfce4-settings).
+  * Figure out a way to avoid the black glitches that happen when 
+    embedding dialogs into the main dialog sometimes.
+  * Consider adding an X-Xfce-Embed=true key to the .desktop files of
+    settings dialogs so that the main dialog can check if they support
+    the embed feature or not.
+  * Come up with a solution for help buttons (maybe using an additonal
+    .desktop file key with a help URL for each settings dialog?).
+  * Maybe make addding dialog-specific buttons to the button bar of the
+    main dialog possible, dunno.
+
+
 Display Settings (Nick)
 ------------------------------------------------------------------------
 

Modified: xfce4-settings/trunk/xfce4-settings-manager/main.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-manager/main.c  2008-09-14 14:53:35 UTC 
(rev 27864)
+++ xfce4-settings/trunk/xfce4-settings-manager/main.c  2008-09-14 18:22:51 UTC 
(rev 27865)
@@ -3,6 +3,7 @@
  *  xfce4-settings-manager
  *
  *  Copyright (c) 2008 Brian Tarricone <[EMAIL PROTECTED]>
+ *                     Jannis Pohlmann <[EMAIL PROTECTED]>
  *
  *  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
@@ -37,8 +38,10 @@
 
 /* somewhat arbitrary; should really do something complicated by
  * looking at font height/avg width, pixbuf height, etc. */
-#define WINDOW_MAX_WIDTH   800
-#define WINDOW_MAX_HEIGHT  600
+/* These values should be ok from anything starting from a
+ * 800x600 resolution */
+#define WINDOW_MIN_WIDTH   640
+#define WINDOW_MIN_HEIGHT  480
 
 static gboolean opt_version = FALSE;
 
@@ -62,9 +65,11 @@
 
     gdk_screen_get_monitor_geometry(screen, monitor, &geom);
 
+    /* Use 2/3 of the screen width and height and fall back to the pre-defined
+     * minimum size if that's considered too small */
     gtk_window_set_default_size(GTK_WINDOW(dialog),
-                                MIN(geom.width * 2.0 / 3, WINDOW_MAX_WIDTH),
-                                MIN(geom.height *2.0 / 3, WINDOW_MAX_HEIGHT));
+                                MAX(geom.width * 2.0 / 3, WINDOW_MIN_WIDTH),
+                                MAX(geom.height * 2.0 / 3, WINDOW_MIN_HEIGHT));
 }
 
 int

Modified: 
xfce4-settings/trunk/xfce4-settings-manager/xfce-settings-manager-dialog.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-manager/xfce-settings-manager-dialog.c  
2008-09-14 14:53:35 UTC (rev 27864)
+++ xfce4-settings/trunk/xfce4-settings-manager/xfce-settings-manager-dialog.c  
2008-09-14 18:22:51 UTC (rev 27865)
@@ -2,6 +2,7 @@
  *  xfce4-settings-manager
  *
  *  Copyright (c) 2008 Brian Tarricone <[EMAIL PROTECTED]>
+ *                     Jannis Pohlmann <[EMAIL PROTECTED]>
  *
  *  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
@@ -29,6 +30,8 @@
 #include <string.h>
 #endif
 
+#include <signal.h>
+
 #include <gtk/gtk.h>
 
 #include <libxfce4util/libxfce4util.h>
@@ -44,6 +47,22 @@
     XfceTitledDialog parent;
 
     GtkListStore *ls;
+
+    GtkWidget *content_frame;
+
+    GtkWidget *scrollwin;
+
+    GtkWidget *client_frame;
+    GtkWidget *socket_viewport;
+    GtkWidget *socket;
+
+    GtkWidget *back_button;
+
+    const gchar *default_title;
+    const gchar *default_subtitle;
+    const gchar *default_icon;
+
+    GPid last_pid;
 };
 
 typedef struct _XfceSettingsManagerDialogClass
@@ -65,10 +84,21 @@
 static void xfce_settings_manager_dialog_init(XfceSettingsManagerDialog 
*dialog);
 static void xfce_settings_manager_dialog_finalize(GObject *obj);
 
+static void xfce_settings_manager_dialog_reset_view(XfceSettingsManagerDialog 
*dialog,
+                                                    gboolean overview);
 static void 
xfce_settings_manager_dialog_create_liststore(XfceSettingsManagerDialog 
*dialog);
 static void xfce_settings_manager_dialog_item_activated(GtkIconView *iconview,
                                                         GtkTreePath *path,
                                                         gpointer user_data);
+static void xfce_settings_manager_dialog_back_button_clicked(GtkWidget *button,
+                                                             
XfceSettingsManagerDialog *dialog);
+static void xfce_settings_manager_dialog_response(GtkDialog *dialog,
+                                                  gint response);
+static void xfce_settings_manager_dialog_plug_added(GtkSocket *socket,
+                                                    XfceSettingsManagerDialog 
*dialog);
+static gboolean xfce_settings_manager_dialog_plug_removed(GtkSocket *socket,
+                                                          
XfceSettingsManagerDialog *dialog);
+static void 
xfce_settings_manager_dialog_destroy_client(XfceSettingsManagerDialog *dialog);
 #if GTK_CHECK_VERSION(2, 12, 0)
 static gboolean xfce_settings_manager_dialog_query_tooltip(GtkWidget *widget,
                                                            gint x,
@@ -93,22 +123,39 @@
 static void
 xfce_settings_manager_dialog_init(XfceSettingsManagerDialog *dialog)
 {
-    GtkWidget *sw, *iconview;
+    GtkWidget *iconview, *vbox, *scrollwin, *hbox, *back_button;
     GtkCellRenderer *render;
 
+    dialog->socket = NULL;
+    dialog->last_pid = -1;
+
+    dialog->default_title = _("Xfce Settings Manager");
+    dialog->default_subtitle = _("Customize your Xfce desktop");
+    dialog->default_icon = "preferences-desktop";
+
     xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(dialog),
                                     _("Customize your Xfce desktop"));
     gtk_window_set_title(GTK_WINDOW(dialog), _("Xfce Settings Manager"));
     gtk_window_set_icon_name(GTK_WINDOW(dialog), "preferences-desktop");
     gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
 
-    sw = gtk_scrolled_window_new(NULL, NULL);
-    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), 
GTK_SHADOW_IN);
-    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
+    dialog->content_frame = gtk_vbox_new(FALSE, 0);
+#if 0
+    dialog->content_frame = gtk_frame_new(NULL);
+    gtk_frame_set_shadow_type(GTK_FRAME(dialog->content_frame), 
GTK_SHADOW_NONE);
+#endif
+    gtk_widget_show(dialog->content_frame);
+    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 
+                      dialog->content_frame);
+
+    dialog->scrollwin = gtk_scrolled_window_new(NULL, NULL);
+    
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(dialog->scrollwin), 
+                                        GTK_SHADOW_IN);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dialog->scrollwin),
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-    gtk_container_set_border_width(GTK_CONTAINER(sw), 6);
-    gtk_widget_show(sw);
-    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0);
+    gtk_container_set_border_width(GTK_CONTAINER(dialog->scrollwin), 6);
+    gtk_widget_show(dialog->scrollwin);
+    gtk_container_add(GTK_CONTAINER(dialog->content_frame), dialog->scrollwin);
 
     xfce_settings_manager_dialog_create_liststore(dialog);
     iconview = exo_icon_view_new_with_model(GTK_TREE_MODEL(dialog->ls));
@@ -121,7 +168,7 @@
     exo_icon_view_set_selection_mode(EXO_ICON_VIEW(iconview),
                                      GTK_SELECTION_NONE);
     gtk_widget_show(iconview);
-    gtk_container_add(GTK_CONTAINER(sw), iconview);
+    gtk_container_add(GTK_CONTAINER(dialog->scrollwin), iconview);
     g_signal_connect(G_OBJECT(iconview), "item-activated",
                      G_CALLBACK(xfce_settings_manager_dialog_item_activated),
                      dialog);
@@ -142,9 +189,65 @@
     gtk_cell_layout_pack_end(GTK_CELL_LAYOUT(iconview), render, TRUE);
     gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(iconview), render,
                                   "text", COL_NAME);
+
+    /* Create client frame to contain the socket scroll window */
+    dialog->client_frame = gtk_frame_new (NULL);
+    gtk_frame_set_shadow_type(GTK_FRAME(dialog->client_frame), 
+                              GTK_SHADOW_NONE);
+    gtk_widget_hide(dialog->client_frame);
+    gtk_container_add(GTK_CONTAINER(dialog->content_frame), 
dialog->client_frame);
+
+    /* Create scroll window to contain the socket viewport */
+    scrollwin = gtk_scrolled_window_new(NULL, NULL);
+    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin), 
+                                        GTK_SHADOW_NONE);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), 
+                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+    gtk_widget_show(scrollwin);
+    gtk_container_add(GTK_CONTAINER(dialog->client_frame), scrollwin);
+
+    /* Create socket viewport */
+    dialog->socket_viewport = gtk_viewport_new(NULL, NULL);
+    gtk_viewport_set_shadow_type(GTK_VIEWPORT(dialog->socket_viewport), 
+                                 GTK_SHADOW_NONE);
+    gtk_widget_show(dialog->socket_viewport);
+    gtk_container_add(GTK_CONTAINER(scrollwin), dialog->socket_viewport);
+
+    /* Create socket */
+    dialog->socket = gtk_socket_new();
+    gtk_widget_show(dialog->socket);
+    gtk_container_add(GTK_CONTAINER(dialog->socket_viewport), dialog->socket);
     
+    /* Handle newly added plugs in a callback */
+    g_signal_connect(dialog->socket, "plug-added", 
+                     G_CALLBACK(xfce_settings_manager_dialog_plug_added),
+                     dialog);
+
+    /* Add plug-removed callback to be able to re-use the socket when plugs
+     * are removed */
+    g_signal_connect(dialog->socket, "plug-removed", 
+                     G_CALLBACK(xfce_settings_manager_dialog_plug_removed),
+                     dialog);
+
+    /* Connect to response signal because maybe we need to kill the settings
+     * dialog spawned last before closing the dialog */
+    g_signal_connect(dialog, "response",
+                     G_CALLBACK(xfce_settings_manager_dialog_response), NULL);
+
+    /* Create back button which takes the user back to the overview */
+    dialog->back_button = gtk_button_new_from_stock(GTK_STOCK_GO_BACK);
+    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 
+                      dialog->back_button);
+    gtk_widget_hide(dialog->back_button);
+
+    g_signal_connect(dialog->back_button, "clicked", 
+                     
G_CALLBACK(xfce_settings_manager_dialog_back_button_clicked),
+                     dialog);
+
     gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE,
                           GTK_RESPONSE_ACCEPT);
+
+    xfce_settings_manager_dialog_reset_view(dialog, TRUE);
 }
 
 static void
@@ -152,13 +255,50 @@
 {
     XfceSettingsManagerDialog *dialog = XFCE_SETTINGS_MANAGER_DIALOG(obj);
 
-    g_object_unref(G_OBJECT(dialog->ls));
+    g_object_unref(dialog->ls);
 
     G_OBJECT_CLASS(xfce_settings_manager_dialog_parent_class)->finalize(obj);
 }
 
+static void
+xfce_settings_manager_dialog_reset_view(XfceSettingsManagerDialog *dialog,
+                                        gboolean overview)
+{
+    if(overview) {
+        /* Reset dialog title and icon */
+        gtk_window_set_title(GTK_WINDOW(dialog), dialog->default_title);
+        gtk_window_set_icon_name(GTK_WINDOW(dialog), dialog->default_icon);
+        xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(dialog),
+                                        dialog->default_subtitle);
 
+        /* Hide the socket view and display the overview */
+        gtk_widget_hide(dialog->client_frame);
+        gtk_widget_show(dialog->scrollwin);
 
+        /* Display the close button on the right */
+        
gtk_button_box_set_layout(GTK_BUTTON_BOX(GTK_DIALOG(dialog)->action_area),
+                                  GTK_BUTTONBOX_END);
+
+        /* Hide the back button in the overview */
+        gtk_widget_hide(dialog->back_button);
+    } else {
+        /* Hide overview and (just to be sure) the socket view. The latter is
+         * to made visible once a plug has been added to the socket */
+        gtk_widget_hide(dialog->scrollwin);
+        gtk_widget_hide(dialog->client_frame);
+
+        /* Realize the socket (just to make sure embedding will succeed) */
+        gtk_widget_realize(dialog->socket);
+
+        /* Display back button on the left, close button on the right */
+        
gtk_button_box_set_layout(GTK_BUTTON_BOX(GTK_DIALOG(dialog)->action_area),
+                                  GTK_BUTTONBOX_EDGE);
+
+        /* Display the back button */
+        gtk_widget_show(dialog->back_button);
+    }
+}
+
 static gint
 xfce_settings_manager_dialog_sort_icons(GtkTreeModel *model,
                                         GtkTreeIter *a,
@@ -305,22 +445,49 @@
 {
     XfceSettingsManagerDialog *dialog = user_data;
     GtkTreeIter iter;
-    gchar *exec = NULL;
+    gchar *exec = NULL, *name, *comment, *icon_name, *primary;
     gboolean snotify = FALSE;
+    gchar *argv[2];
     GError *error = NULL;
 
     if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->ls), &iter, path))
         return;
 
     gtk_tree_model_get(GTK_TREE_MODEL(dialog->ls), &iter,
+                       COL_NAME, &name,
+                       COL_COMMENT, &comment,
                        COL_EXEC, &exec,
+                       COL_ICON_NAME, &icon_name,
                        COL_SNOTIFY, &snotify,
                        -1);
 
-    if(!xfce_exec_on_screen(gtk_widget_get_screen(GTK_WIDGET(iconview)),
-                            exec, FALSE, snotify, &error))
+    /* Kill the previously spawned dialog (if there is any) */
+    xfce_settings_manager_dialog_destroy_client(dialog);
+
+    /* Update dialog title and icon */
+    gtk_window_set_title(GTK_WINDOW(dialog), name);
+    gtk_window_set_icon_name(GTK_WINDOW(dialog), icon_name);
+    xfce_titled_dialog_set_subtitle(XFCE_TITLED_DIALOG(dialog), comment);
+
+    /* Switch to the socket view (but don't display it yet) */
+    xfce_settings_manager_dialog_reset_view(dialog, FALSE);
+
+    /* Build the dialog command */
+    argv[0] = exec;
+    argv[1] = g_strdup_printf("--socket-id=%d", 
+                              gtk_socket_get_id(GTK_SOCKET(dialog->socket)));
+
+    /* Try to spawn the dialog */
+    if(!gdk_spawn_on_screen(gtk_widget_get_screen(GTK_WIDGET(iconview)), NULL, 
+                            argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, 
+                            &dialog->last_pid, &error))
     {
-        gchar *primary = g_strdup_printf(_("Unable to start \"%s\""), exec);
+        /* Spawning failed, go back to the overview */
+        xfce_settings_manager_dialog_destroy_client(dialog);
+        xfce_settings_manager_dialog_reset_view(dialog, TRUE);
+
+        /* Notify the user that there has been a problem */
+        primary = g_strdup_printf(_("Unable to start \"%s\""), exec);
         xfce_message_dialog(GTK_WINDOW(dialog), _("Xfce Settings Manager"),
                             GTK_STOCK_DIALOG_ERROR, primary, error->message,
                             GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
@@ -328,9 +495,57 @@
         g_error_free(error);
     }
 
-    g_free(exec);
+    g_free(argv[0]);
+    g_free(argv[1]);
 }
 
+static void
+xfce_settings_manager_dialog_back_button_clicked(GtkWidget *button,
+                                                 XfceSettingsManagerDialog 
*dialog)
+{
+    /* Kill the currently embedded dialog and go back to the overview */
+    xfce_settings_manager_dialog_destroy_client(dialog);
+    xfce_settings_manager_dialog_reset_view(dialog, TRUE);
+}
+
+static void
+xfce_settings_manager_dialog_response(GtkDialog *dialog,
+                                      gint response)
+{
+    XfceSettingsManagerDialog *sm_dialog = 
XFCE_SETTINGS_MANAGER_DIALOG(dialog);
+
+    /* Make sure the currently embedded dialog is killed before exiting */
+    xfce_settings_manager_dialog_destroy_client(sm_dialog);
+}
+
+static void
+xfce_settings_manager_dialog_plug_added(GtkSocket *socket,
+                                        XfceSettingsManagerDialog *dialog)
+{
+    /* TODO: Handle black glitches here, either using a timeout handler to 
+     * display the client frame or by doing something more clever */
+    gtk_widget_show(dialog->client_frame);
+}
+
+static gboolean
+xfce_settings_manager_dialog_plug_removed(GtkSocket *socket,
+                                          XfceSettingsManagerDialog *dialog)
+{
+    /* Return true to be able to re-use the socket for another plug */
+    return TRUE;
+}
+
+static void
+xfce_settings_manager_dialog_destroy_client(XfceSettingsManagerDialog *dialog)
+{
+    /* Veeery simple way to make the embedded dialog application quit */
+    if(dialog->last_pid != -1) {
+        g_spawn_close_pid(dialog->last_pid);
+        kill(dialog->last_pid, SIGQUIT);
+        dialog->last_pid = -1;
+    }
+}
+
 #if GTK_CHECK_VERSION(2, 12, 0)
 static gboolean
 xfce_settings_manager_dialog_query_tooltip(GtkWidget *widget,

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to