[libadwaita/wip/exalm/deprecations: 2/2] Fix GtkStyleContext deprecations




commit 623ebbb98628b60c2ff3c6a18e6b7d7e00a65f49
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Oct 14 22:54:02 2022 +0400

    Fix GtkStyleContext deprecations

 src/adw-carousel-indicator-dots.c     | 14 +-------------
 src/adw-carousel-indicator-lines.c    | 16 ++--------------
 src/adw-flap.c                        | 14 +++++---------
 src/adw-swipe-tracker.c               |  2 +-
 src/adw-tab-box.c                     | 20 ++++----------------
 src/adw-tab-grid.c                    | 20 ++++----------------
 src/adw-tab-overview.c                | 27 +++++++--------------------
 src/adw-tab-thumbnail.c               |  8 +++-----
 src/adw-tab-view.c                    |  2 +-
 src/stylesheet/widgets/_tab-view.scss |  5 -----
 10 files changed, 28 insertions(+), 100 deletions(-)
---
diff --git a/src/adw-carousel-indicator-dots.c b/src/adw-carousel-indicator-dots.c
index 42cbf609..d096d5d6 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -72,18 +72,6 @@ enum {
 
 static GParamSpec *props[LAST_PROP];
 
-static GdkRGBA
-get_color (GtkWidget *widget)
-{
-  GtkStyleContext *context;
-  GdkRGBA color;
-
-  context = gtk_widget_get_style_context (widget);
-  gtk_style_context_get_color (context, &color);
-
-  return color;
-}
-
 static void
 snapshot_dots (GtkWidget      *widget,
                GtkSnapshot    *snapshot,
@@ -98,7 +86,7 @@ snapshot_dots (GtkWidget      *widget,
   double current_position, remaining_progress;
   graphene_rect_t rect;
 
-  color = get_color (widget);
+  gtk_widget_get_style_color (widget, &color);
   dot_size = 2 * DOTS_RADIUS_SELECTED + DOTS_SPACING;
 
   indicator_length = -DOTS_SPACING;
diff --git a/src/adw-carousel-indicator-lines.c b/src/adw-carousel-indicator-lines.c
index 0d25d337..59f09d8d 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -70,18 +70,6 @@ enum {
 
 static GParamSpec *props[LAST_PROP];
 
-static GdkRGBA
-get_color (GtkWidget *widget)
-{
-  GtkStyleContext *context;
-  GdkRGBA color;
-
-  context = gtk_widget_get_style_context (widget);
-  gtk_style_context_get_color (context, &color);
-
-  return color;
-}
-
 static void
 snapshot_lines (GtkWidget      *widget,
                 GtkSnapshot    *snapshot,
@@ -95,7 +83,7 @@ snapshot_lines (GtkWidget      *widget,
   double indicator_length, full_size, line_size;
   double x = 0, y = 0, pos;
 
-  color = get_color (widget);
+  gtk_widget_get_style_color (widget, &color);
   color.alpha *= LINE_OPACITY;
 
   line_size = LINE_LENGTH + LINE_SPACING;
@@ -143,7 +131,7 @@ snapshot_lines (GtkWidget      *widget,
     pos += (LINE_LENGTH + LINE_SPACING) * sizes[i];
   }
 
-  color = get_color (widget);
+  gtk_widget_get_style_color (widget, &color);
   color.alpha *= LINE_OPACITY_ACTIVE;
 
   pos = position * (LINE_LENGTH + LINE_SPACING);
diff --git a/src/adw-flap.c b/src/adw-flap.c
index aab2c897..6e47f431 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -363,8 +363,6 @@ static void
 set_folded (AdwFlap  *self,
             gboolean  folded)
 {
-  GtkStyleContext *context;
-
   folded = !!folded;
 
   if (self->folded == folded)
@@ -386,13 +384,12 @@ set_folded (AdwFlap  *self,
   if (!self->locked)
     set_reveal_flap (self, !self->folded, 0);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (self));
   if (folded) {
-    gtk_style_context_add_class (context, "folded");
-    gtk_style_context_remove_class (context, "unfolded");
+    gtk_widget_add_css_class (GTK_WIDGET (self), "folded");
+    gtk_widget_remove_css_class (GTK_WIDGET (self), "unfolded");
   } else {
-    gtk_style_context_remove_class (context, "folded");
-    gtk_style_context_add_class (context, "unfolded");
+    gtk_widget_remove_css_class (GTK_WIDGET (self), "folded");
+    gtk_widget_add_css_class (GTK_WIDGET (self), "unfolded");
   }
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FOLDED]);
@@ -1532,7 +1529,6 @@ flap_close_cb (AdwFlap *self)
 static void
 adw_flap_init (AdwFlap *self)
 {
-  GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (self));
   GtkEventController *gesture;
   GtkShortcut *shortcut;
   AdwAnimationTarget *target;
@@ -1582,7 +1578,7 @@ adw_flap_init (AdwFlap *self)
 
   gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
 
-  gtk_style_context_add_class (context, "unfolded");
+  gtk_widget_add_css_class (GTK_WIDGET (self), "unfolded");
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
                                               fold_animation_value_cb,
diff --git a/src/adw-swipe-tracker.c b/src/adw-swipe-tracker.c
index a76c360b..35217a02 100644
--- a/src/adw-swipe-tracker.c
+++ b/src/adw-swipe-tracker.c
@@ -733,7 +733,7 @@ handle_scroll_event (AdwSwipeTracker *self,
     } else {
       append_to_history (self, delta, time);
 
-      gesture_update (self, delta / distance * SCROLL_MULTIPLIER, time);
+      gesture_update (self, delta / distance, time);
       return GDK_EVENT_STOP;
     }
   }
diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index 1c2ca064..62045046 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -50,7 +50,6 @@ typedef struct {
   GdkDrag *drag;
 
   AdwTab *tab;
-  GtkBorder tab_margin;
 
   int hotspot_x;
   int hotspot_y;
@@ -2455,15 +2454,11 @@ icon_resize_animation_value_cb (double    value,
 
   icon->width = (int) round (value);
 
-  gtk_widget_set_size_request (GTK_WIDGET (icon->tab),
-                               icon->width + icon->tab_margin.left + icon->tab_margin.right,
-                               -1);
+  gtk_widget_set_size_request (GTK_WIDGET (icon->tab),  icon->width, -1);
 
   icon->hotspot_x = (int) round (icon->width * relative_pos);
 
-  gdk_drag_set_hotspot (icon->drag,
-                        icon->hotspot_x + icon->tab_margin.left,
-                        icon->hotspot_y + icon->tab_margin.top);
+  gdk_drag_set_hotspot (icon->drag, icon->hotspot_x, icon->hotspot_y);
 
   gtk_widget_queue_resize (GTK_WIDGET (icon->tab));
 }
@@ -2491,19 +2486,12 @@ create_drag_icon (AdwTabBox *self,
   gtk_drag_icon_set_child (GTK_DRAG_ICON (gtk_drag_icon_get_for_drag (drag)),
                            GTK_WIDGET (icon->tab));
 
-  gtk_style_context_get_margin (gtk_widget_get_style_context (GTK_WIDGET (icon->tab)),
-                                &icon->tab_margin);
-
-  gtk_widget_set_size_request (GTK_WIDGET (icon->tab),
-                               icon->width + icon->tab_margin.left + icon->tab_margin.right,
-                               -1);
+  gtk_widget_set_size_request (GTK_WIDGET (icon->tab), icon->width, -1);
 
   icon->hotspot_x = (int) self->drag_offset_x;
   icon->hotspot_y = (int) self->drag_offset_y;
 
-  gdk_drag_set_hotspot (drag,
-                        icon->hotspot_x + icon->tab_margin.left,
-                        icon->hotspot_y + icon->tab_margin.top);
+  gdk_drag_set_hotspot (drag, icon->hotspot_x, icon->hotspot_y);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
                                               icon_resize_animation_value_cb,
diff --git a/src/adw-tab-grid.c b/src/adw-tab-grid.c
index e459a91a..3631aeb8 100644
--- a/src/adw-tab-grid.c
+++ b/src/adw-tab-grid.c
@@ -60,7 +60,6 @@ typedef struct {
   GdkDrag *drag;
 
   AdwTabThumbnail *tab;
-  GtkBorder tab_margin;
 
   int hotspot_x;
   int hotspot_y;
@@ -2439,16 +2438,12 @@ icon_resize_animation_value_cb (double    value,
   icon->width = (int) round (adw_lerp (icon->initial_width, icon->target_width, value));
   icon->height = (int) round (adw_lerp (icon->initial_height, icon->target_height, value));
 
-  gtk_widget_set_size_request (GTK_WIDGET (icon->tab),
-                               icon->width + icon->tab_margin.left + icon->tab_margin.right,
-                               icon->height + icon->tab_margin.top + icon->tab_margin.bottom);
+  gtk_widget_set_size_request (GTK_WIDGET (icon->tab), icon->width, icon->height);
 
   icon->hotspot_x = (int) round (icon->width * relative_x);
   icon->hotspot_y = (int) round (icon->height * relative_y);
 
-  gdk_drag_set_hotspot (icon->drag,
-                        icon->hotspot_x + icon->tab_margin.left,
-                        icon->hotspot_y + icon->tab_margin.top);
+  gdk_drag_set_hotspot (icon->drag, icon->hotspot_x, icon->hotspot_y);
 
   gtk_widget_queue_resize (GTK_WIDGET (icon->tab));
 }
@@ -2480,19 +2475,12 @@ create_drag_icon (AdwTabGrid *self,
   gtk_drag_icon_set_child (GTK_DRAG_ICON (gtk_drag_icon_get_for_drag (drag)),
                            GTK_WIDGET (icon->tab));
 
-  gtk_style_context_get_margin (gtk_widget_get_style_context (GTK_WIDGET (icon->tab)),
-                                &icon->tab_margin);
-
-  gtk_widget_set_size_request (GTK_WIDGET (icon->tab),
-                               icon->width + icon->tab_margin.left + icon->tab_margin.right,
-                               icon->height + icon->tab_margin.top + icon->tab_margin.bottom);
+  gtk_widget_set_size_request (GTK_WIDGET (icon->tab), icon->width, icon->height);
 
   icon->hotspot_x = (int) self->drag_offset_x;
   icon->hotspot_y = (int) self->drag_offset_y;
 
-  gdk_drag_set_hotspot (drag,
-                        icon->hotspot_x + icon->tab_margin.left,
-                        icon->hotspot_y + icon->tab_margin.top);
+  gdk_drag_set_hotspot (drag, icon->hotspot_x, icon->hotspot_y);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
                                               icon_resize_animation_value_cb,
diff --git a/src/adw-tab-overview.c b/src/adw-tab-overview.c
index 238deabc..46757fab 100644
--- a/src/adw-tab-overview.c
+++ b/src/adw-tab-overview.c
@@ -1047,9 +1047,7 @@ should_round_corners (AdwTabOverview *self,
                       gboolean       *round_bottom_right)
 {
   GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (self));
-  GtkBorder border, padding, window_border, window_padding;
   graphene_rect_t bounds;
-  GtkStyleContext *context;
   GdkSurface *surface;
   GdkToplevelState state;
   gboolean top_left = TRUE;
@@ -1077,40 +1075,29 @@ should_round_corners (AdwTabOverview *self,
                 GDK_TOPLEVEL_STATE_LEFT_TILED)) > 0)
     return;
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (root));
-
-  if (!gtk_style_context_has_class (context, "csd") ||
-      gtk_style_context_has_class (context, "solid-csd"))
+  if (!gtk_widget_has_css_class (GTK_WIDGET (root), "csd") ||
+      gtk_widget_has_css_class (GTK_WIDGET (root), "solid-csd"))
     return;
 
-  gtk_style_context_get_border (context, &window_border);
-  gtk_style_context_get_padding (context, &window_padding);
-
-  context = gtk_widget_get_style_context (GTK_WIDGET (self));
-  gtk_style_context_get_border (context, &border);
-  gtk_style_context_get_padding (context, &padding);
-
-  if (!gtk_widget_compute_bounds (GTK_WIDGET (self), GTK_WIDGET (root), &bounds))
+  if (!gtk_widget_compute_bounds (GTK_WIDGET (self->child_bin), GTK_WIDGET (root), &bounds))
     return;
 
-  if (border.left + padding.left + window_border.left + window_padding.left + bounds.origin.x > 0) {
+  if (bounds.origin.x > 0) {
     top_left = FALSE;
     bottom_left = FALSE;
   }
 
-  if (border.right + padding.right + window_border.right + window_padding.right > 0 ||
-      bounds.origin.x + bounds.size.width < gtk_widget_get_width (GTK_WIDGET (root))) {
+  if (bounds.origin.x + bounds.size.width < gtk_widget_get_width (GTK_WIDGET (root))) {
     top_right = FALSE;
     bottom_right = FALSE;
   }
 
-  if (border.top + padding.top + window_border.top + window_padding.top + bounds.origin.y > 0) {
+  if (bounds.origin.y > 0) {
     top_left = FALSE;
     top_right = FALSE;
   }
 
-  if (border.bottom + padding.bottom + window_border.bottom + window_padding.bottom > 0 ||
-      bounds.origin.y + bounds.size.height < gtk_widget_get_height (GTK_WIDGET (root))) {
+  if (bounds.origin.y + bounds.size.height < gtk_widget_get_height (GTK_WIDGET (root))) {
     bottom_left = FALSE;
     bottom_right = FALSE;
   }
diff --git a/src/adw-tab-thumbnail.c b/src/adw-tab-thumbnail.c
index d4a43036..833764df 100644
--- a/src/adw-tab-thumbnail.c
+++ b/src/adw-tab-thumbnail.c
@@ -16,6 +16,7 @@
 #include "adw-timed-animation.h"
 
 #define FADE_TRANSITION_DURATION 250
+#define PINNED_MARGIN 10
 
 struct _AdwTabThumbnail
 {
@@ -292,7 +293,6 @@ allocate_pinned_tab (AdwGizmo *gizmo,
   int left_margin = 0, right_margin = 0;
   int box_pos, box_width;
   gboolean is_rtl;
-  GtkBorder margin;
 
   if (gtk_widget_should_layout (self->unpin_icon))
     gtk_widget_measure (self->unpin_icon, GTK_ORIENTATION_HORIZONTAL, -1,
@@ -304,8 +304,6 @@ allocate_pinned_tab (AdwGizmo *gizmo,
   gtk_widget_measure (self->icon_title_box, GTK_ORIENTATION_HORIZONTAL, -1,
                       NULL, &box_width, NULL, NULL);
 
-  gtk_style_context_get_margin (gtk_widget_get_style_context (GTK_WIDGET (gizmo)), &margin);
-
   is_rtl = gtk_widget_get_direction (GTK_WIDGET (gizmo)) == GTK_TEXT_DIR_RTL;
 
   if (is_rtl != self->inverted) {
@@ -314,8 +312,8 @@ allocate_pinned_tab (AdwGizmo *gizmo,
     right_margin = tmp;
   }
 
-  left_margin = MAX (left_margin - margin.left, 0);
-  right_margin = MAX (right_margin - margin.right, 0);
+  left_margin = MAX (left_margin, PINNED_MARGIN);
+  right_margin = MAX (right_margin, PINNED_MARGIN);
 
   box_width = MIN (width - right_margin - left_margin, box_width);
   box_pos = (width - box_width) / 2;
diff --git a/src/adw-tab-view.c b/src/adw-tab-view.c
index ccabd2e8..3e2e5216 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -991,7 +991,7 @@ snapshot_default_icon (GtkSnapshot *snapshot,
                                          GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
 
   context = gtk_widget_get_style_context (view);
-  gtk_style_context_get_color (context, &colors[GTK_SYMBOLIC_COLOR_FOREGROUND]);
+  gtk_widget_get_style_color (view, &colors[GTK_SYMBOLIC_COLOR_FOREGROUND]);
   gtk_style_context_lookup_color (context, "error-color", &colors[GTK_SYMBOLIC_COLOR_ERROR]);
   gtk_style_context_lookup_color (context, "warning-color", &colors[GTK_SYMBOLIC_COLOR_WARNING]);
   gtk_style_context_lookup_color (context, "success-color", &colors[GTK_SYMBOLIC_COLOR_SUCCESS]);
diff --git a/src/stylesheet/widgets/_tab-view.scss b/src/stylesheet/widgets/_tab-view.scss
index a8549813..f2ccfdd6 100644
--- a/src/stylesheet/widgets/_tab-view.scss
+++ b/src/stylesheet/widgets/_tab-view.scss
@@ -198,11 +198,6 @@ tabthumbnail {
     }
   }
 
-  .pinned-box {
-    margin-left: 10px;
-    margin-right: 10px;
-  }
-
   .icon-title-box {
     border-spacing: 6px;
   }


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