[glade/csd: 2/3] GladeWindowEditor: Added custom control for client side decorations



commit 6d4364cc2353f3366031156e4a1ab3a778feeb7b
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Oct 17 08:02:17 2014 -0400

    GladeWindowEditor: Added custom control for client side decorations
    
    This is needed so that when the command is issued, it can also
    include the child deletion as a part of the command group.
    
    When a window is using CSD, mark the title, decoration and
    hide-when-maximized editors as insensitive, since they affect
    non-CSD decorations.

 plugins/gtk+/glade-window-editor.c  |   92 +++++++++++++++++++++++++++
 plugins/gtk+/glade-window-editor.ui |  119 ++++++++++++++++++++---------------
 plugins/gtk+/gtk+.xml.in            |    2 +-
 3 files changed, 162 insertions(+), 51 deletions(-)
---
diff --git a/plugins/gtk+/glade-window-editor.c b/plugins/gtk+/glade-window-editor.c
index 62a6451..4c24f7e 100644
--- a/plugins/gtk+/glade-window-editor.c
+++ b/plugins/gtk+/glade-window-editor.c
@@ -31,6 +31,7 @@ static void glade_window_editor_grab_focus (GtkWidget * widget);
 /* Callbacks */
 static void icon_name_toggled    (GtkWidget *widget, GladeWindowEditor * window_editor);
 static void icon_file_toggled    (GtkWidget *widget, GladeWindowEditor * window_editor);
+static void use_csd_toggled      (GtkWidget *widget, GladeWindowEditor * window_editor);
 
 struct _GladeWindowEditorPrivate {
   GtkWidget *embed;
@@ -38,6 +39,10 @@ struct _GladeWindowEditorPrivate {
   GtkWidget *extension_port;
   GtkWidget *icon_name_radio;
   GtkWidget *icon_file_radio;
+  GtkWidget *use_csd_check;
+  GtkWidget *title_editor;
+  GtkWidget *decorated_editor;
+  GtkWidget *hide_titlebar_editor;
 };
 
 static GladeEditableIface *parent_editable_iface;
@@ -59,9 +64,14 @@ glade_window_editor_class_init (GladeWindowEditorClass * klass)
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, embed);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, icon_name_radio);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, icon_file_radio);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, use_csd_check);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, title_editor);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, decorated_editor);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, hide_titlebar_editor);
 
   gtk_widget_class_bind_template_callback (widget_class, icon_name_toggled);
   gtk_widget_class_bind_template_callback (widget_class, icon_file_toggled);
+  gtk_widget_class_bind_template_callback (widget_class, use_csd_toggled);
 }
 
 static void
@@ -94,13 +104,17 @@ glade_window_editor_load (GladeEditable *editable,
   if (gwidget)
     {
       gboolean icon_name;
+      gboolean use_csd;
 
       glade_widget_property_get (gwidget, "glade-window-icon-name", &icon_name);
+      glade_widget_property_get (gwidget, "use-csd", &use_csd);
 
       if (icon_name)
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->icon_name_radio), TRUE);
       else
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->icon_file_radio), TRUE);
+
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_csd_check), use_csd);
     }
 }
 
@@ -180,6 +194,84 @@ icon_file_toggled (GtkWidget         *widget,
   glade_editable_load (GLADE_EDITABLE (window_editor), gwidget);
 }
 
+#if !GTK_CHECK_VERSION (3,15,0)
+/* Hack to find the titlebar */
+static void check_titlebar (GtkWidget *widget, gpointer data)
+{
+  GtkWidget **titlebar = data;
+  if (gtk_style_context_has_class (gtk_widget_get_style_context (widget), "titlebar"))
+    *titlebar = widget;
+}
+
+static GtkWidget *
+gtk_window_get_titlebar (GtkWindow *window)
+{
+  GtkWidget *titlebar = NULL;
+  gtk_container_forall (GTK_CONTAINER (window), check_titlebar, &titlebar);
+  return titlebar;
+}
+#endif
+
+static void
+use_csd_toggled (GtkWidget         *widget,
+                GladeWindowEditor *window_editor)
+{
+  GladeWindowEditorPrivate *priv = window_editor->priv;
+  GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (window_editor));
+  GladeWidget   *gtitlebar = NULL;
+  GtkWidget     *window;
+  GtkWidget     *titlebar;
+  GladeProperty *property;
+  gboolean       use_csd;
+
+  if (glade_editable_loading (GLADE_EDITABLE (window_editor)) || !gwidget)
+    return;
+
+  /* Get new desired property state */
+  use_csd = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_csd_check));
+
+  gtk_widget_set_sensitive (priv->title_editor, !use_csd);
+  gtk_widget_set_sensitive (priv->decorated_editor, !use_csd);
+  gtk_widget_set_sensitive (priv->hide_titlebar_editor, !use_csd);
+
+  /* Get any existing titlebar widget */
+  window = (GtkWidget *)glade_widget_get_object (gwidget);
+  titlebar = gtk_window_get_titlebar (GTK_WINDOW (window));
+
+  if (titlebar && !GLADE_IS_PLACEHOLDER (titlebar))
+    gtitlebar = glade_widget_get_from_gobject (titlebar);
+
+  glade_editable_block (GLADE_EDITABLE (window_editor));
+
+  if (use_csd)
+    glade_command_push_group (_("Setting %s to use a custom titlebar"),
+                             glade_widget_get_name (gwidget));
+  else
+    glade_command_push_group (_("Setting %s to use a system provided titlebar"),
+                             glade_widget_get_name (gwidget));
+
+  /* If a project widget exists when were disabling CSD, it needs
+   * to be removed first as a part of the issuing GladeCommand group
+   */
+  if (gtitlebar)
+    {
+      GList list;
+      list.prev = list.next = NULL;
+      list.data = gtitlebar;
+      glade_command_delete (&list);
+    }
+
+  property = glade_widget_get_property (gwidget, "use-csd");
+  glade_command_set_property (property, use_csd);
+
+  glade_command_pop_group ();
+
+  glade_editable_unblock (GLADE_EDITABLE (window_editor));
+
+  /* reload buttons and sensitivity and stuff... */
+  glade_editable_load (GLADE_EDITABLE (window_editor), gwidget);
+}
+
 /*************************************
  *                API                *
  *************************************/
diff --git a/plugins/gtk+/glade-window-editor.ui b/plugins/gtk+/glade-window-editor.ui
index 2aefa84..6a57586 100644
--- a/plugins/gtk+/glade-window-editor.ui
+++ b/plugins/gtk+/glade-window-editor.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.1 
+<!-- Generated with glade 3.18.2
 
 libgladegtk - Glade UI Designer Gtk+ support plugin
 Copyright (C) 2013 Tristan Van Berkom <tvb gnome org>
@@ -217,34 +217,6 @@ Author: Tristan Van Berkom <tvb gnome org>
           </packing>
         </child>
         <child>
-          <object class="GladePropertyLabel" id="title_label">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_left">12</property>
-            <property name="hexpand">False</property>
-            <property name="property_name">title</property>
-            <property name="custom_text" translatable="yes">Title:</property>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">10</property>
-            <property name="width">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GladePropertyShell" id="title_editor">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="hexpand">False</property>
-            <property name="property_name">title</property>
-          </object>
-          <packing>
-            <property name="left_attach">2</property>
-            <property name="top_attach">10</property>
-            <property name="width">4</property>
-          </packing>
-        </child>
-        <child>
           <object class="GtkRadioButton" id="icon_file_radio">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
@@ -266,7 +238,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">13</property>
+            <property name="top_attach">14</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -293,7 +265,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">12</property>
+            <property name="top_attach">13</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -306,7 +278,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">12</property>
+            <property name="top_attach">13</property>
             <property name="width">4</property>
           </packing>
         </child>
@@ -319,7 +291,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">13</property>
+            <property name="top_attach">14</property>
             <property name="width">4</property>
           </packing>
         </child>
@@ -333,7 +305,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">14</property>
+            <property name="top_attach">15</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -347,7 +319,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">15</property>
+            <property name="top_attach">16</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -360,7 +332,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">14</property>
+            <property name="top_attach">15</property>
             <property name="width">4</property>
           </packing>
         </child>
@@ -373,7 +345,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">15</property>
+            <property name="top_attach">16</property>
             <property name="width">4</property>
           </packing>
         </child>
@@ -390,7 +362,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">16</property>
+            <property name="top_attach">17</property>
             <property name="width">6</property>
           </packing>
         </child>
@@ -404,7 +376,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">11</property>
+            <property name="top_attach">12</property>
             <property name="width">4</property>
           </packing>
         </child>
@@ -419,7 +391,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">11</property>
+            <property name="top_attach">12</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -434,7 +406,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">17</property>
+            <property name="top_attach">18</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -448,7 +420,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">17</property>
+            <property name="top_attach">18</property>
           </packing>
         </child>
         <child>
@@ -462,7 +434,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">18</property>
+            <property name="top_attach">19</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -477,7 +449,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">19</property>
+            <property name="top_attach">20</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -491,7 +463,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">18</property>
+            <property name="top_attach">19</property>
           </packing>
         </child>
         <child>
@@ -504,7 +476,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">3</property>
-            <property name="top_attach">17</property>
+            <property name="top_attach">18</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -518,7 +490,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">19</property>
+            <property name="top_attach">20</property>
           </packing>
         </child>
         <child>
@@ -532,7 +504,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">20</property>
+            <property name="top_attach">21</property>
             <property name="width">2</property>
           </packing>
         </child>
@@ -546,7 +518,7 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">20</property>
+            <property name="top_attach">21</property>
           </packing>
         </child>
         <child>
@@ -689,7 +661,54 @@ Author: Tristan Van Berkom <tvb gnome org>
           </object>
           <packing>
             <property name="left_attach">3</property>
-            <property name="top_attach">18</property>
+            <property name="top_attach">19</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyLabel" id="title_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">title</property>
+            <property name="sensitive" bind-source="title_editor" bind-property="sensitive"/>
+            <property name="custom_text" translatable="yes">Title:</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">11</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GladePropertyShell" id="title_editor">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">title</property>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">11</property>
+            <property name="width">4</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="use_csd_check">
+            <property name="label" translatable="yes">Client side window decorations</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="tooltip_text" translatable="yes">Whether this window should include a custom 
titlebar.</property>
+            <property name="margin_left">12</property>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
+            <signal name="toggled" handler="use_csd_toggled" swapped="no"/>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">10</property>
+            <property name="width">6</property>
           </packing>
         </child>
         <child>
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 4608f88..c302d82 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -706,7 +706,7 @@
             <_tooltip>A list of accel groups to be added to this window</_tooltip>
           </property>
           <!-- Virtual csd mode property -->
-          <property id="use-csd" name="CSD" visible="True" save="False">
+          <property id="use-csd" name="CSD" save="False" custom-layout="True">
             <parameter-spec>
               <type>GParamBoolean</type>
             </parameter-spec>


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