From cfd49bdf68ef48fcd53a084c74626372fc169688 Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Fri, 12 Apr 2019 07:58:30 -0400 Subject: Replace public MetaFrameGeometry with MetaFrameBorders There were actually *two* MetaFrameGeometry structs: one in theme-private.h, one in frame.h. The latter public struct was populated by a mix of (void*) casting and int pointers, usually pulling directly from the data in the private struct. Remove the public struct, replace it with MetaFrameBorders and scrap all the pointer hacks to populate it, instead relying on both structs being used in common code. This commit should be relatively straightforward, and it should not do any tricky logic at all, just a sophisticated find and replace. https://bugzilla.gnome.org/show_bug.cgi?id=644930 upstream commit: https://gitlab.gnome.org/GNOME/metacity/commit/72224a165 NOTE: Patch copied from metacity and adapted for marco. --- src/ui/frames.c | 35 ++++++++++++--------- src/ui/frames.h | 7 ++--- src/ui/preview-widget.c | 47 +++++++++++++--------------- src/ui/preview-widget.h | 6 +--- src/ui/theme-viewer.c | 11 +++---- src/ui/theme.c | 83 ++++++++++++++++++------------------------------- src/ui/theme.h | 10 ++---- src/ui/ui.c | 30 ++++++++---------- 8 files changed, 96 insertions(+), 133 deletions(-) (limited to 'src/ui') diff --git a/src/ui/frames.c b/src/ui/frames.c index 8e6eefd3..264e2373 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -668,10 +668,9 @@ meta_frames_lookup_window (MetaFrames *frames, } void -meta_frames_get_geometry (MetaFrames *frames, - Window xwindow, - int *top_height, int *bottom_height, - int *left_width, int *right_width) +meta_frames_get_borders (MetaFrames *frames, + Window xwindow, + MetaFrameBorders *borders) { MetaFrameFlags flags; MetaUIFrame *frame; @@ -702,14 +701,13 @@ meta_frames_get_geometry (MetaFrames *frames, type, frame->text_height, flags, - top_height, bottom_height, - left_width, right_width); + borders); /* Scale frame geometry to ensure proper frame position */ - *top_height *= scale; - *bottom_height *= scale; - *left_width *= scale; - *right_width *= scale; + borders->visible.top *= scale; + borders->visible.bottom *= scale; + borders->visible.left *= scale; + borders->visible.right *= scale; } #ifdef HAVE_SHAPE @@ -2062,6 +2060,7 @@ populate_cache (MetaFrames *frames, MetaUIFrame *frame) { int top, bottom, left, right; + MetaFrameBorders borders; int width, height; int frame_width, frame_height, screen_width, screen_height; gint scale; @@ -2092,7 +2091,12 @@ populate_cache (MetaFrames *frames, frame_type, frame->text_height, frame_flags, - &top, &bottom, &left, &right); + &borders); + + top = borders.visible.top; + left = borders.visible.left; + right = borders.visible.right; + bottom = borders.visible.bottom; pixels = get_cache (frames, frame); scale = gdk_window_get_scale_factor (frame->window); @@ -2197,6 +2201,7 @@ subtract_client_area (cairo_region_t *region, MetaUIFrame *frame) GdkRectangle area; MetaFrameFlags flags; MetaFrameType type; + MetaFrameBorders borders; cairo_region_t *tmp_region; Display *display; gint scale; @@ -2212,13 +2217,13 @@ subtract_client_area (cairo_region_t *region, MetaUIFrame *frame) META_CORE_GET_END); meta_theme_get_frame_borders (meta_theme_get_current (), - type, frame->text_height, flags, - &area.x, NULL, &area.y, NULL); + type, frame->text_height, flags, + &borders); area.width /= scale; area.height /= scale; - area.x /= scale; - area.y /= scale; + area.x = borders.visible.left / scale; + area.y = borders.visible.top / scale; tmp_region = cairo_region_create_rectangle (&area); cairo_region_subtract (region, tmp_region); diff --git a/src/ui/frames.h b/src/ui/frames.h index 736c37ca..1262f148 100644 --- a/src/ui/frames.h +++ b/src/ui/frames.h @@ -127,10 +127,9 @@ void meta_frames_set_title (MetaFrames *frames, void meta_frames_repaint_frame (MetaFrames *frames, Window xwindow); -void meta_frames_get_geometry (MetaFrames *frames, - Window xwindow, - int *top_height, int *bottom_height, - int *left_width, int *right_width); +void meta_frames_get_borders (MetaFrames *frames, + Window xwindow, + MetaFrameBorders *borders); void meta_frames_apply_shapes (MetaFrames *frames, Window xwindow, diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c index 6dc4691c..1db34950 100644 --- a/src/ui/preview-widget.c +++ b/src/ui/preview-widget.c @@ -98,10 +98,10 @@ meta_preview_init (MetaPreview *preview) META_FRAME_ALLOWS_SHADE | META_FRAME_ALLOWS_MOVE; - preview->left_width = -1; - preview->right_width = -1; - preview->top_height = -1; - preview->bottom_height = -1; + preview->borders.visible.left = -1; + preview->borders.visible.right = -1; + preview->borders.visible.top = -1; + preview->borders.visible.bottom = -1; } GtkWidget* @@ -172,7 +172,7 @@ ensure_info (MetaPreview *preview) pango_font_description_free (font_desc); } - if (preview->top_height < 0) + if (preview->borders.visible.top < 0) { if (preview->theme) { @@ -180,17 +180,14 @@ ensure_info (MetaPreview *preview) preview->type, preview->text_height, preview->flags, - &preview->top_height, - &preview->bottom_height, - &preview->left_width, - &preview->right_width); + &preview->borders); } else { - preview->top_height = 0; - preview->bottom_height = 0; - preview->left_width = 0; - preview->right_width = 0; + preview->borders.visible.top = 0; + preview->borders.visible.bottom = 0; + preview->borders.visible.left = 0; + preview->borders.visible.right = 0; } } } @@ -223,8 +220,8 @@ meta_preview_draw (GtkWidget *widget, border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); gtk_widget_get_allocation (widget, &allocation); - client_width = allocation.width - preview->left_width - preview->right_width - border_width * 2; - client_height = allocation.height - preview->top_height - preview->bottom_height - border_width * 2; + client_width = allocation.width - preview->borders.visible.left - preview->borders.visible.right - border_width * 2; + client_height = allocation.height - preview->borders.visible.top - preview->borders.visible.bottom - border_width * 2; if (client_width < 0) client_width = 1; @@ -268,7 +265,7 @@ meta_preview_get_preferred_width (GtkWidget *widget, ensure_info (preview); - *minimum = *natural = preview->left_width + preview->right_width; + *minimum = *natural = preview->borders.visible.left + preview->borders.visible.right; child = gtk_bin_get_child (GTK_BIN (preview)); if (child && gtk_widget_get_visible (child)) @@ -304,7 +301,7 @@ meta_preview_get_preferred_height (GtkWidget *widget, ensure_info (preview); - *minimum = *natural = preview->top_height + preview->bottom_height; + *minimum = *natural = preview->borders.visible.top + preview->borders.visible.bottom; child = gtk_bin_get_child (GTK_BIN (preview)); if (child && gtk_widget_get_visible (child)) @@ -349,11 +346,11 @@ meta_preview_size_allocate (GtkWidget *widget, gtk_widget_get_visible (child)) { gtk_widget_get_allocation (widget, &widget_allocation); - child_allocation.x = widget_allocation.x + border_width + preview->left_width; - child_allocation.y = widget_allocation.y + border_width + preview->top_height; + child_allocation.x = widget_allocation.x + border_width + preview->borders.visible.left; + child_allocation.y = widget_allocation.y + border_width + preview->borders.visible.top; - child_allocation.width = MAX (1, widget_allocation.width - border_width * 2 - preview->left_width - preview->right_width); - child_allocation.height = MAX (1, widget_allocation.height - border_width * 2 - preview->top_height - preview->bottom_height); + child_allocation.width = MAX (1, widget_allocation.width - border_width * 2 - preview->borders.visible.left - preview->borders.visible.right); + child_allocation.height = MAX (1, widget_allocation.height - border_width * 2 - preview->borders.visible.top - preview->borders.visible.bottom); gtk_widget_size_allocate (gtk_bin_get_child (GTK_BIN (widget)), &child_allocation); } } @@ -367,10 +364,10 @@ clear_cache (MetaPreview *preview) preview->layout = NULL; } - preview->left_width = -1; - preview->right_width = -1; - preview->top_height = -1; - preview->bottom_height = -1; + preview->borders.visible.left = -1; + preview->borders.visible.right = -1; + preview->borders.visible.top = -1; + preview->borders.visible.bottom = -1; } void diff --git a/src/ui/preview-widget.h b/src/ui/preview-widget.h index 1bbd97e7..11818588 100644 --- a/src/ui/preview-widget.h +++ b/src/ui/preview-widget.h @@ -50,11 +50,7 @@ struct _MetaPreview PangoLayout *layout; int text_height; - int left_width; - int right_width; - int top_height; - int bottom_height; - + MetaFrameBorders borders; MetaButtonLayout button_layout; }; diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c index 65df34fa..f88df0b0 100644 --- a/src/ui/theme-viewer.c +++ b/src/ui/theme-viewer.c @@ -1000,7 +1000,7 @@ run_theme_benchmark (void) GtkWidget* widget; cairo_surface_t *pixmap; cairo_t *cr; - int top_height, bottom_height, left_width, right_width; + MetaFrameBorders borders; MetaButtonState button_states[META_BUTTON_TYPE_LAST] = { META_BUTTON_STATE_NORMAL, @@ -1026,10 +1026,7 @@ run_theme_benchmark (void) META_FRAME_TYPE_NORMAL, get_text_height (widget), get_flags (widget), - &top_height, - &bottom_height, - &left_width, - &right_width); + &borders); layout = create_title_layout (widget); @@ -1064,8 +1061,8 @@ run_theme_benchmark (void) */ pixmap = gdk_window_create_similar_surface (gtk_widget_get_window (widget), CAIRO_CONTENT_COLOR, - client_width + left_width + right_width, - client_height + top_height + bottom_height); + client_width + borders.visible.left + borders.visible.right, + client_height + borders.visible.top + borders.visible.bottom); cr = cairo_create (pixmap); meta_theme_draw_frame (global_theme, diff --git a/src/ui/theme.c b/src/ui/theme.c index a7368c92..20cf6913 100644 --- a/src/ui/theme.c +++ b/src/ui/theme.c @@ -405,10 +405,7 @@ void meta_frame_layout_get_borders (const MetaFrameLayout *layout, int text_height, MetaFrameFlags flags, - int *top_height, - int *bottom_height, - int *left_width, - int *right_width) + MetaFrameBorders *borders) { int buttons_height, title_height; @@ -423,34 +420,20 @@ meta_frame_layout_get_borders (const MetaFrameLayout *layout, layout->title_vertical_pad + layout->title_border.top + layout->title_border.bottom; - if (top_height) - { - *top_height = MAX (buttons_height, title_height); - } - - if (left_width) - *left_width = layout->left_width; - if (right_width) - *right_width = layout->right_width; - - if (bottom_height) - { - if (flags & META_FRAME_SHADED) - *bottom_height = 0; - else - *bottom_height = layout->bottom_height; - } + borders->visible.top = MAX (buttons_height, title_height); + borders->visible.left = layout->left_width; + borders->visible.right = layout->right_width; + if (flags & META_FRAME_SHADED) + borders->visible.bottom = 0; + else + borders->visible.bottom = layout->bottom_height; if (flags & META_FRAME_FULLSCREEN) { - if (top_height) - *top_height = 0; - if (bottom_height) - *bottom_height = 0; - if (left_width) - *left_width = 0; - if (right_width) - *right_width = 0; + borders->visible.top = 0; + borders->visible.bottom = 0; + borders->visible.left = 0; + borders->visible.right = 0; } } @@ -647,12 +630,16 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout, GdkRectangle *right_bg_rects[MAX_BUTTONS_PER_CORNER]; gboolean right_buttons_has_spacer[MAX_BUTTONS_PER_CORNER]; + MetaFrameBorders borders; + meta_frame_layout_get_borders (layout, text_height, flags, - &fgeom->top_height, - &fgeom->bottom_height, - &fgeom->left_width, - &fgeom->right_width); + &borders); + + fgeom->left_width = borders.visible.left; + fgeom->right_width = borders.visible.right; + fgeom->top_height = borders.visible.top; + fgeom->bottom_height = borders.visible.bottom; width = client_width + fgeom->left_width + fgeom->right_width; @@ -5659,30 +5646,23 @@ meta_theme_draw_frame_by_name (MetaTheme *theme, } void -meta_theme_get_frame_borders (MetaTheme *theme, - MetaFrameType type, - int text_height, - MetaFrameFlags flags, - int *top_height, - int *bottom_height, - int *left_width, - int *right_width) +meta_theme_get_frame_borders (MetaTheme *theme, + MetaFrameType type, + int text_height, + MetaFrameFlags flags, + MetaFrameBorders *borders) { MetaFrameStyle *style; g_return_if_fail (type < META_FRAME_TYPE_LAST); - if (top_height) - *top_height = 0; - if (bottom_height) - *bottom_height = 0; - if (left_width) - *left_width = 0; - if (right_width) - *right_width = 0; - style = theme_get_style (theme, type, flags); + borders->visible.top = 0; + borders->visible.left = 0; + borders->visible.right = 0; + borders->visible.bottom = 0; + /* Parser is not supposed to allow this currently */ if (style == NULL) return; @@ -5690,8 +5670,7 @@ meta_theme_get_frame_borders (MetaTheme *theme, meta_frame_layout_get_borders (style->layout, text_height, flags, - top_height, bottom_height, - left_width, right_width); + borders); } void diff --git a/src/ui/theme.h b/src/ui/theme.h index ef6af363..2e4a425c 100644 --- a/src/ui/theme.h +++ b/src/ui/theme.h @@ -877,10 +877,7 @@ void meta_frame_layout_unref (MetaFrameLayout *layout) void meta_frame_layout_get_borders (const MetaFrameLayout *layout, int text_height, MetaFrameFlags flags, - int *top_height, - int *bottom_height, - int *left_width, - int *right_width); + MetaFrameBorders *borders); void meta_frame_layout_calc_geometry (const MetaFrameLayout *layout, int text_height, MetaFrameFlags flags, @@ -1080,10 +1077,7 @@ void meta_theme_get_frame_borders (MetaTheme *theme, MetaFrameType type, int text_height, MetaFrameFlags flags, - int *top_height, - int *bottom_height, - int *left_width, - int *right_width); + MetaFrameBorders *borders); void meta_theme_calc_geometry (MetaTheme *theme, MetaFrameType type, int text_height, diff --git a/src/ui/ui.c b/src/ui/ui.c index 00c1176a..fdb9733a 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -295,14 +295,11 @@ meta_ui_free (MetaUI *ui) } void -meta_ui_get_frame_geometry (MetaUI *ui, - Window frame_xwindow, - int *top_height, int *bottom_height, - int *left_width, int *right_width) +meta_ui_get_frame_borders (MetaUI *ui, + Window frame_xwindow, + MetaFrameBorders *borders) { - meta_frames_get_geometry (ui->frames, frame_xwindow, - top_height, bottom_height, - left_width, right_width); + meta_frames_get_borders (ui->frames, frame_xwindow, borders); } static void @@ -634,13 +631,10 @@ meta_ui_window_should_not_cause_focus (Display *xdisplay, } void -meta_ui_theme_get_frame_borders (MetaUI *ui, - MetaFrameType type, - MetaFrameFlags flags, - int *top_height, - int *bottom_height, - int *left_width, - int *right_width) +meta_ui_theme_get_frame_borders (MetaUI *ui, + MetaFrameType type, + MetaFrameFlags flags, + MetaFrameBorders *borders) { int text_height; GtkStyleContext *style = NULL; @@ -681,15 +675,17 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, meta_theme_get_frame_borders (meta_theme_get_current (), type, text_height, flags, - top_height, bottom_height, - left_width, right_width); + borders); if (free_font_desc) pango_font_description_free (free_font_desc); } else { - *top_height = *bottom_height = *left_width = *right_width = 0; + borders->visible.top = 0; + borders->visible.bottom = 0; + borders->visible.left = 0; + borders->visible.right = 0; } if (style != NULL) -- cgit v1.2.1