[gtk/wip/baedert/single-node-window: 7/8] window: Remove decoration node



commit adf8d63013d3772d9aa6c2e15eca4c1b9415dab9
Author: Timm Bäder <mail baedert org>
Date:   Sat May 2 10:25:12 2020 +0200

    window: Remove decoration node

 gtk/gtkwindow.c                | 155 +++++++++++++++++------------------------
 gtk/theme/Adwaita/_common.scss |   5 +-
 2 files changed, 68 insertions(+), 92 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 4f630f1082..86bf03c990 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -255,8 +255,6 @@ typedef struct
   GtkEventController *key_controller;
   GtkEventController *application_shortcut_controller;
 
-  GtkCssNode *decoration_node;
-
   GdkSurface  *surface;
   GskRenderer *renderer;
 
@@ -414,8 +412,6 @@ static void gtk_window_real_activate_focus   (GtkWindow         *window);
 static void gtk_window_keys_changed          (GtkWindow         *window);
 static gboolean gtk_window_enable_debugging  (GtkWindow         *window,
                                               gboolean           toggle);
-static void gtk_window_snapshot                    (GtkWidget   *widget,
-                                                    GtkSnapshot *snapshot);
 static void gtk_window_unset_transient_for         (GtkWindow  *window);
 static void gtk_window_transient_parent_realized   (GtkWidget  *parent,
                                                    GtkWidget  *window);
@@ -491,8 +487,6 @@ static void        gtk_window_do_popup                  (GtkWindow      *window,
                                                          GdkEvent       *event);
 static void        gtk_window_css_changed               (GtkWidget      *widget,
                                                          GtkCssStyleChange *change);
-static void gtk_window_state_flags_changed (GtkWidget     *widget,
-                                            GtkStateFlags  previous_state);
 static void _gtk_window_set_is_active (GtkWindow *window,
                                       gboolean   is_active);
 static void gtk_window_present_toplevel (GtkWindow *window);
@@ -753,13 +747,12 @@ gtk_window_class_init (GtkWindowClass *klass)
   widget_class->realize = gtk_window_realize;
   widget_class->unrealize = gtk_window_unrealize;
   widget_class->size_allocate = gtk_window_size_allocate;
-  widget_class->measure = gtk_window_measure;
   widget_class->compute_expand = gtk_window_compute_expand;
   widget_class->get_request_mode = gtk_window_get_request_mode;
   widget_class->focus = gtk_window_focus;
   widget_class->grab_focus = gtk_widget_grab_focus_none;
   widget_class->move_focus = gtk_window_move_focus;
-  widget_class->state_flags_changed = gtk_window_state_flags_changed;
+  widget_class->measure = gtk_window_measure;
   widget_class->css_changed = gtk_window_css_changed;
 
   klass->activate_default = gtk_window_real_activate_default;
@@ -1480,17 +1473,6 @@ drag_gesture_update_cb (GtkGestureDrag *gesture,
     }
 }
 
-static void
-node_style_changed_cb (GtkCssNode        *node,
-                       GtkCssStyleChange *change,
-                       GtkWidget         *widget)
-{
-  if (gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SIZE))
-    gtk_widget_queue_resize (widget);
-  else
-    gtk_widget_queue_draw (widget);
-}
-
 static void
 device_removed_cb (GdkSeat   *seat,
                    GdkDevice *device,
@@ -1576,7 +1558,7 @@ edge_under_coordinates (GtkWindow     *window,
 
   gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
   context = _gtk_widget_get_style_context (GTK_WIDGET (window));
-  gtk_style_context_save_to_node (context, priv->decoration_node);
+  /*gtk_style_context_save_to_node (context, priv->decoration_node);*/
 
   if (priv->use_client_shadow)
     {
@@ -1591,7 +1573,7 @@ edge_under_coordinates (GtkWindow     *window,
       gtk_style_context_get_padding (context, &border);
     }
 
-  gtk_style_context_restore (context);
+  /*gtk_style_context_restore (context);*/
 
   /* Check whether the click falls outside the handle area */
   if (x >= allocation.x + border.left &&
@@ -1786,13 +1768,6 @@ gtk_window_init (GtkWindow *window)
 #endif
 
   widget_node = gtk_widget_get_css_node (GTK_WIDGET (window));
-  priv->decoration_node = gtk_css_node_new ();
-  gtk_css_node_set_name (priv->decoration_node, g_quark_from_static_string ("decoration"));
-  gtk_css_node_set_parent (priv->decoration_node, widget_node);
-  gtk_css_node_set_state (priv->decoration_node, gtk_css_node_get_state (widget_node));
-  g_signal_connect_object (priv->decoration_node, "style-changed", G_CALLBACK (node_style_changed_cb), 
window, 0);
-  g_object_unref (priv->decoration_node);
-
   gtk_css_node_add_class (widget_node, g_quark_from_static_string (GTK_STYLE_CLASS_BACKGROUND));
 
   priv->scale = gtk_widget_get_scale_factor (widget);
@@ -2177,14 +2152,12 @@ gtk_window_native_get_surface_transform (GtkNative *native,
                                          int       *x,
                                          int       *y)
 {
-  const graphene_rect_t *margin_rect;
-  GtkCssBoxes boxes;
+  GtkBorder shadow;
 
-  gtk_css_boxes_init (&boxes, GTK_WIDGET (native));
-  margin_rect = gtk_css_boxes_get_margin_rect (&boxes);
+  get_shadow_width (GTK_WINDOW (native), &shadow);
 
-  *x = - margin_rect->origin.x;
-  *y = - margin_rect->origin.y;
+  *x = shadow.left;
+  *y = shadow.right;
 }
 
 static void
@@ -4556,8 +4529,6 @@ get_shadow_width (GtkWindow *window,
 
   context = _gtk_widget_get_style_context (GTK_WIDGET (window));
 
-  gtk_style_context_save_to_node (context, priv->decoration_node);
-
   /* Always sum border + padding */
   gtk_style_context_get_border (context, &border);
   gtk_style_context_get_padding (context, &d);
@@ -4573,8 +4544,6 @@ get_shadow_width (GtkWindow *window,
 
   sum_borders (&d, &border);
   *shadow_width = d;
-
-  gtk_style_context_restore (context);
 }
 
 static void
@@ -4592,13 +4561,13 @@ update_csd_shape (GtkWindow *window)
 
   context = _gtk_widget_get_style_context (widget);
 
-  gtk_style_context_save_to_node (context, priv->decoration_node);
+  /*gtk_style_context_save_to_node (context, priv->decoration_node);*/
   gtk_style_context_get_margin (context, &border);
   gtk_style_context_get_border (context, &tmp);
   sum_borders (&border, &tmp);
   gtk_style_context_get_padding (context, &tmp);
   sum_borders (&border, &tmp);
-  gtk_style_context_restore (context);
+  /*gtk_style_context_restore (context);*/
   get_shadow_width (window, &window_border);
 
   /* update the input shape, which makes it so that clicks
@@ -4658,7 +4627,7 @@ subtract_decoration_corners_from_region (cairo_region_t        *region,
       priv->maximized)
     return;
 
-  gtk_style_context_save_to_node (context, priv->decoration_node);
+  /*gtk_style_context_save_to_node (context, priv->decoration_node);*/
 
   corner_rect (&rect, _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS));
   rect.x = extents->x;
@@ -4680,7 +4649,7 @@ subtract_decoration_corners_from_region (cairo_region_t        *region,
   rect.y = extents->y + extents->height - rect.height;
   cairo_region_subtract_rectangle (region, &rect);
 
-  gtk_style_context_restore (context);
+  /*gtk_style_context_restore (context);*/
 }
 
 static void
@@ -4753,11 +4722,13 @@ gtk_window_realize (GtkWidget *widget)
   GtkAllocation allocation;
   GtkAllocation child_allocation;
   GdkSurface *surface;
-  GtkBorder window_border;
+  GtkBorder shadow;
 
   if (!priv->client_decorated && gtk_window_should_use_csd (window))
     create_decoration (widget);
 
+  get_shadow_width (window, &shadow);
+
   /* ensure widget tree is properly size allocated */
   if (_gtk_widget_get_alloc_needed (widget))
     {
@@ -4765,10 +4736,10 @@ gtk_window_realize (GtkWidget *widget)
 
       gtk_window_compute_configure_request (window, &request, NULL, NULL);
 
-      allocation.x = 0;
-      allocation.y = 0;
-      allocation.width = request.width;
-      allocation.height = request.height;
+      allocation.x = shadow.left;
+      allocation.y = shadow.top;
+      allocation.width = request.width - shadow.left - shadow.right;
+      allocation.height = request.height - shadow.top - shadow.bottom;
       gtk_widget_size_allocate (widget, &allocation, -1);
 
       gtk_widget_queue_resize (widget);
@@ -4779,8 +4750,8 @@ gtk_window_realize (GtkWidget *widget)
   gtk_widget_get_allocation (widget, &allocation);
 
   surface = gdk_surface_new_toplevel (gtk_widget_get_display (widget),
-                                      MAX (1, allocation.width),
-                                      MAX (1, allocation.height));
+                                      MAX (1, allocation.width + shadow.left + shadow.right),
+                                      MAX (1, allocation.height + shadow.top + shadow.bottom));
   priv->surface = surface;
   gdk_surface_set_widget (surface, widget);
 
@@ -4843,9 +4814,8 @@ gtk_window_realize (GtkWidget *widget)
   child_allocation.width = allocation.width;
   child_allocation.height = allocation.height;
 
-  get_shadow_width (window, &window_border);
 
-  update_realized_window_properties (window, &child_allocation, &window_border);
+  update_realized_window_properties (window, &child_allocation, &shadow);
 
   if (priv->application)
     gtk_application_handle_window_realize (priv->application, window);
@@ -5659,20 +5629,6 @@ gtk_window_set_focus (GtkWindow *window,
     gtk_window_root_set_focus (GTK_ROOT (window), NULL);
 }
 
-static void
-gtk_window_state_flags_changed (GtkWidget     *widget,
-                                GtkStateFlags  previous_state)
-{
-  GtkWindow *window = GTK_WINDOW (widget);
-  GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
-  GtkStateFlags state;
-
-  state = gtk_widget_get_state_flags (widget);
-  gtk_css_node_set_state (priv->decoration_node, state);
-
-  GTK_WIDGET_CLASS (gtk_window_parent_class)->state_flags_changed (widget, previous_state);
-}
-
 static void
 gtk_window_css_changed (GtkWidget         *widget,
                         GtkCssStyleChange *change)
@@ -5996,7 +5952,6 @@ gtk_window_compute_configure_request_size (GtkWindow   *window,
   /* Preconditions:
    *  - we've done a size request
    */
-  
   info = gtk_window_get_geometry_info (window, FALSE);
 
   if (priv->need_default_size)
@@ -6023,6 +5978,12 @@ gtk_window_compute_configure_request_size (GtkWindow   *window,
           if (info->default_height > 0)
             *height = default_height_csd;
         }
+
+      GtkBorder shadow = {0, };
+      get_shadow_width (window, &shadow);
+
+      *width = *width + shadow.left + shadow.right;
+      *height = *height + shadow.top + shadow.bottom;
     }
   else
     {
@@ -6036,19 +5997,20 @@ gtk_window_compute_configure_request_size (GtkWindow   *window,
       /* Unless we are maximized or fullscreen */
       gtk_window_get_remembered_size (window, width, height);
     }
-  else if (info)
-    {
-      gint resize_width_csd = info->resize_width;
-      gint resize_height_csd = info->resize_height;
-      gtk_window_update_csd_size (window,
-                                  &resize_width_csd, &resize_height_csd,
-                                  INCLUDE_CSD_SIZE);
 
-      if (info->resize_width > 0)
-        *width = resize_width_csd;
-      if (info->resize_height > 0)
-        *height = resize_height_csd;
-    }
+  /*else if (info)*/
+    /*{*/
+      /*gint resize_width_csd = info->resize_width;*/
+      /*gint resize_height_csd = info->resize_height;*/
+      /*gtk_window_update_csd_size (window,*/
+                                  /*&resize_width_csd, &resize_height_csd,*/
+                                  /*INCLUDE_CSD_SIZE);*/
+
+      /*if (info->resize_width > 0)*/
+        /**width = resize_width_csd;*/
+      /*if (info->resize_height > 0)*/
+        /**height = resize_height_csd;*/
+    /*}*/
 
   /* Don't ever request zero width or height, it's not supported by
      gdk. The size allocation code will round it to 1 anyway but if
@@ -6056,6 +6018,7 @@ gtk_window_compute_configure_request_size (GtkWindow   *window,
      not comparable to the size allocation read from the GtkWindow. */
   *width = MAX (*width, 1);
   *height = MAX (*height, 1);
+
 }
 
 static void
@@ -6094,10 +6057,14 @@ gtk_window_compute_configure_request (GtkWindow    *window,
       y = 0;
     }
 
+  GtkBorder shadow = {0, };
+
+  /*get_shadow_width (window, &shadow);*/
+
   request->x = x;
   request->y = y;
-  request->width = w;
-  request->height = h;
+  request->width = w + shadow.left + shadow.right;
+  request->height = h + shadow.top + shadow.bottom;
 
   if (geometry)
     *geometry = new_geometry;
@@ -6165,7 +6132,6 @@ gtk_window_move_resize (GtkWindow *window)
   g_clear_pointer (&priv->layout, gdk_toplevel_layout_unref);
   priv->layout = gtk_window_compute_layout (window, new_geometry.min_width, new_geometry.min_height);
 
-
   /* This check implies the invariant that we never set info->last
    * without setting the hints and sending off a configure request.
    *
@@ -6253,6 +6219,7 @@ gtk_window_move_resize (GtkWindow *window)
   if (priv->configure_notify_received)
     {
       GtkAllocation allocation;
+      GtkBorder shadow;
       int min;
 
       /* If we have received a configure event since
@@ -6268,8 +6235,10 @@ gtk_window_move_resize (GtkWindow *window)
        */
       priv->configure_notify_received = FALSE;
 
-      allocation.x = 0;
-      allocation.y = 0;
+      get_shadow_width (window, &shadow);
+
+      allocation.x = shadow.left;
+      allocation.y = shadow.top;
 
       gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL, -1,
                           &min, NULL, NULL, NULL);
@@ -6370,31 +6339,37 @@ gtk_window_move_resize (GtkWindow *window)
         g_warning ("configure request position changed. This should not happen. Ignoring the position");
 
       gdk_toplevel_present (GDK_TOPLEVEL (priv->surface),
-                           new_request.width, new_request.height,
+                            new_request.width, new_request.height,
                             priv->layout);
     }
   else
     {
       GtkAllocation allocation;
+      GtkBorder shadow;
       int min_width, min_height;
 
+      get_shadow_width (window, &shadow);
+
+      allocation.x = shadow.left;
+      allocation.y = shadow.top;
+
       /* Handle any position changes.
        */
       if (configure_request_pos_changed)
         g_warning ("configure request position changed. This should not happen. Ignoring the position");
 
-      gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL, current_height,
+      gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL, current_height - shadow.top - shadow.bottom,
                           &min_width, NULL, NULL, NULL);
-      gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL, current_width,
+      gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL, current_width - shadow.left - shadow.right,
                           &min_height, NULL, NULL, NULL);
 
       /* Our configure request didn't change size, but maybe some of
        * our child widgets have. Run a size allocate with our current
        * size to make sure that we re-layout our child widgets. */
-      allocation.x = 0;
-      allocation.y = 0;
-      allocation.width = MAX (current_width, min_width);
-      allocation.height = MAX (current_height, min_height);
+      allocation.x = shadow.left;
+      allocation.y = shadow.top;
+      allocation.width = MAX (current_width - shadow.left - shadow.right, min_width);
+      allocation.height = MAX (current_height - shadow.top - shadow.bottom, min_height);
 
       gtk_widget_size_allocate (widget, &allocation, -1);
     }
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index 829cd31390..14663a65dc 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -4052,7 +4052,8 @@ colorchooser .popover.osd { border-radius: 5px; }
 /**********************
  * Window Decorations *
  *********************/
-decoration {
+decoration,
+window {
   border-radius: $window_radius $window_radius 0 0;
   // lamefun trick to get rounded borders regardless of CSD use
   border-width: 0px;
@@ -4068,7 +4069,7 @@ decoration {
   // FIXME rationalize shadows
 
   // this is used for the resize cursor area
-  margin: 10px;
+  //margin: 10px;
 
   &:backdrop {
     // the transparent shadow here is to enforce that the shadow extents don't


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