[libadwaita/wip/exalm/deprecations] Fix GtkStyleContext deprecations
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/deprecations] Fix GtkStyleContext deprecations
- Date: Sat, 15 Oct 2022 13:54:55 +0000 (UTC)
commit 426e3649709f48e69a749eca9978ee802eff1954
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Oct 14 22:54:02 2022 +0400
Fix GtkStyleContext deprecations
src/adw-carousel-indicator-dots.c | 15 ++------------
src/adw-carousel-indicator-lines.c | 17 +++-------------
src/adw-flap.c | 14 +++++--------
src/adw-tab-box.c | 20 ++++--------------
src/adw-tab-grid.c | 20 ++++--------------
src/adw-tab-overview.c | 38 ++++++++++-------------------------
src/adw-tab-thumbnail.c | 8 +++-----
src/adw-tab-view.c | 13 +++++-------
src/adw-widget-utils-private.h | 7 +++++++
src/adw-widget-utils.c | 26 ++++++++++++++++++++++++
src/stylesheet/widgets/_tab-view.scss | 5 -----
11 files changed, 70 insertions(+), 113 deletions(-)
---
diff --git a/src/adw-carousel-indicator-dots.c b/src/adw-carousel-indicator-dots.c
index 42cbf609..5cf167b4 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -12,6 +12,7 @@
#include "adw-macros-private.h"
#include "adw-swipeable.h"
#include "adw-timed-animation.h"
+#include "adw-widget-utils-private.h"
#include <math.h>
@@ -72,18 +73,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 +87,7 @@ snapshot_dots (GtkWidget *widget,
double current_position, remaining_progress;
graphene_rect_t rect;
- color = get_color (widget);
+ adw_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..719ab96b 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -11,6 +11,7 @@
#include "adw-macros-private.h"
#include "adw-swipeable.h"
#include "adw-timed-animation.h"
+#include "adw-widget-utils-private.h"
#include <math.h>
@@ -70,18 +71,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 +84,7 @@ snapshot_lines (GtkWidget *widget,
double indicator_length, full_size, line_size;
double x = 0, y = 0, pos;
- color = get_color (widget);
+ adw_widget_get_style_color (widget, &color);
color.alpha *= LINE_OPACITY;
line_size = LINE_LENGTH + LINE_SPACING;
@@ -143,7 +132,7 @@ snapshot_lines (GtkWidget *widget,
pos += (LINE_LENGTH + LINE_SPACING) * sizes[i];
}
- color = get_color (widget);
+ adw_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-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..49c569e1 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;
}
@@ -1184,8 +1171,7 @@ adw_tab_overview_snapshot (GtkWidget *widget,
gtk_widget_snapshot_child (widget, self->overview, snapshot);
/* Draw dim layer */
- if (!gtk_style_context_lookup_color (gtk_widget_get_style_context (widget),
- "shade_color", &rgba))
+ if (!adw_widget_lookup_color (widget, "shade_color", &rgba))
rgba.alpha = 0;
rgba.alpha *= 1 - self->progress;
@@ -1207,9 +1193,8 @@ adw_tab_overview_snapshot (GtkWidget *widget,
gtk_widget_snapshot_child (widget, self->child_bin, snapshot);
if (self->transition_pinned) {
- GtkStyleContext *context = gtk_widget_get_style_context (self->transition_picture);
-
- if (!gtk_style_context_lookup_color (context, "thumbnail_bg_color", &rgba))
+ if (!adw_widget_lookup_color (self->transition_picture,
+ "thumbnail_bg_color", &rgba))
rgba.red = rgba.green = rgba.blue = rgba.alpha = 1;
gtk_snapshot_pop (snapshot);
@@ -1224,8 +1209,7 @@ adw_tab_overview_snapshot (GtkWidget *widget,
rgba.red = rgba.green = rgba.blue = 0;
rgba.alpha = 0.5;
} else {
- if (!gtk_style_context_lookup_color (gtk_widget_get_style_context (widget),
- "shade_color", &rgba))
+ if (!adw_widget_lookup_color (widget, "shade_color", &rgba))
rgba.alpha = 0;
}
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..3910f52b 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -862,9 +862,8 @@ get_background_color (AdwTabPaintable *self,
GdkRGBA *rgba)
{
GtkWidget *child = adw_tab_page_get_child (self->page);
- GtkStyleContext *context = gtk_widget_get_style_context (child);
- if (gtk_style_context_lookup_color (context, "thumbnail_bg_color", rgba))
+ if (adw_widget_lookup_color (child, "thumbnail_bg_color", rgba))
return;
rgba->red = 1;
@@ -950,7 +949,6 @@ snapshot_default_icon (GtkSnapshot *snapshot,
GtkIconTheme *icon_theme;
GIcon *default_icon;
GtkIconPaintable *icon;
- GtkStyleContext *context;
GdkRGBA colors[4];
double x, y;
double view_width, view_height;
@@ -990,11 +988,10 @@ snapshot_default_icon (GtkSnapshot *snapshot,
gtk_widget_get_direction (view),
GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
- context = gtk_widget_get_style_context (view);
- gtk_style_context_get_color (context, &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]);
+ adw_widget_get_style_color (view, &colors[GTK_SYMBOLIC_COLOR_FOREGROUND]);
+ adw_widget_lookup_color (view, "error-color", &colors[GTK_SYMBOLIC_COLOR_ERROR]);
+ adw_widget_lookup_color (view, "warning-color", &colors[GTK_SYMBOLIC_COLOR_WARNING]);
+ adw_widget_lookup_color (view, "success-color", &colors[GTK_SYMBOLIC_COLOR_SUCCESS]);
hc = adw_style_manager_get_high_contrast (adw_style_manager_get_for_display (display));
diff --git a/src/adw-widget-utils-private.h b/src/adw-widget-utils-private.h
index 3f6f027d..adfdcc3d 100644
--- a/src/adw-widget-utils-private.h
+++ b/src/adw-widget-utils-private.h
@@ -41,4 +41,11 @@ void adw_widget_compute_expand_horizontal_only (GtkWidget *widget,
GtkSizeRequestMode adw_widget_get_request_mode (GtkWidget *widget);
+void adw_widget_get_style_color (GtkWidget *widget,
+ GdkRGBA *rgba);
+
+gboolean adw_widget_lookup_color (GtkWidget *widget,
+ const char *name,
+ GdkRGBA *rgba);
+
G_END_DECLS
diff --git a/src/adw-widget-utils.c b/src/adw-widget-utils.c
index 9541fb89..1b4b57d5 100644
--- a/src/adw-widget-utils.c
+++ b/src/adw-widget-utils.c
@@ -543,3 +543,29 @@ adw_widget_get_request_mode (GtkWidget *widget)
GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
+
+void
+adw_widget_get_style_color (GtkWidget *widget,
+ GdkRGBA *rgba)
+{
+#if GTK_CHECK_VERSION (4, 9, 1)
+ gtk_widget_get_style_color (widget, rgba);
+#else
+ GtkStyleContext *context = gtk_widget_get_style_context (widget);
+
+ gtk_style_context_get_color (context, rgba);
+#endif
+}
+
+/* FIXME: Replace this with public color API and make public */
+gboolean
+adw_widget_lookup_color (GtkWidget *widget,
+ const char *name,
+ GdkRGBA *rgba)
+{
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ GtkStyleContext *context = gtk_widget_get_style_context (widget);
+
+ return gtk_style_context_lookup_color (context, name, rgba);
+G_GNUC_END_IGNORE_DEPRECATIONS
+}
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]