Skip to content

Commit

Permalink
Replace public MetaFrameGeometry with MetaFrameBorders
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vkareh committed Jun 5, 2019
1 parent 707eb40 commit c66b326
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 358 deletions.
105 changes: 51 additions & 54 deletions src/core/constraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ typedef struct
{
MetaRectangle orig;
MetaRectangle current;
MetaFrameGeometry *fgeom;
MetaFrameBorders *borders;
ActionType action_type;
gboolean is_user_action;

Expand Down Expand Up @@ -189,7 +189,7 @@ static gboolean constrain_partially_onscreen (MetaWindow *window,

static void setup_constraint_info (ConstraintInfo *info,
MetaWindow *window,
MetaFrameGeometry *orig_fgeom,
MetaFrameBorders *orig_borders,
MetaMoveResizeFlags flags,
int resize_gravity,
const MetaRectangle *orig,
Expand All @@ -200,12 +200,12 @@ static void update_onscreen_requirements (MetaWindow *window,
ConstraintInfo *info);
static void extend_by_frame (MetaWindow *window,
MetaRectangle *rect,
const MetaFrameGeometry *fgeom);
const MetaFrameBorders *borders);
static void unextend_by_frame (MetaWindow *window,
MetaRectangle *rect,
const MetaFrameGeometry *fgeom);
const MetaFrameBorders *borders);
static inline void get_size_limits (const MetaWindow *window,
const MetaFrameGeometry *fgeom,
const MetaFrameBorders *borders,
gboolean include_frame,
MetaRectangle *min_size,
MetaRectangle *max_size);
Expand Down Expand Up @@ -281,7 +281,7 @@ do_all_constraints (MetaWindow *window,

void
meta_window_constrain (MetaWindow *window,
MetaFrameGeometry *orig_fgeom,
MetaFrameBorders *orig_borders,
MetaMoveResizeFlags flags,
int resize_gravity,
const MetaRectangle *orig,
Expand All @@ -304,7 +304,7 @@ meta_window_constrain (MetaWindow *window,

setup_constraint_info (&info,
window,
orig_fgeom,
orig_borders,
flags,
resize_gravity,
orig,
Expand Down Expand Up @@ -339,14 +339,14 @@ meta_window_constrain (MetaWindow *window,
* not gobject-style--gobject would be more pain than it's worth) or
* smart pointers would be so much nicer here. *shrug*
*/
if (!orig_fgeom)
g_free (info.fgeom);
if (!orig_borders)
g_free (info.borders);
}

static void
setup_constraint_info (ConstraintInfo *info,
MetaWindow *window,
MetaFrameGeometry *orig_fgeom,
MetaFrameBorders *orig_borders,
MetaMoveResizeFlags flags,
int resize_gravity,
const MetaRectangle *orig,
Expand All @@ -359,10 +359,10 @@ setup_constraint_info (ConstraintInfo *info,
info->current = *new;

/* Create a fake frame geometry if none really exists */
if (orig_fgeom && !window->fullscreen)
info->fgeom = orig_fgeom;
if (orig_borders && !window->fullscreen)
info->borders = orig_borders;
else
info->fgeom = g_new0 (MetaFrameGeometry, 1);
info->borders = g_new0 (MetaFrameBorders, 1);

if (flags & META_IS_MOVE_ACTION && flags & META_IS_RESIZE_ACTION)
info->action_type = ACTION_MOVE_AND_RESIZE;
Expand Down Expand Up @@ -469,7 +469,6 @@ setup_constraint_info (ConstraintInfo *info,
"Setting up constraint info:\n"
" orig: %d,%d +%d,%d\n"
" new : %d,%d +%d,%d\n"
" fgeom: %d,%d,%d,%d\n"
" action_type : %s\n"
" is_user_action : %s\n"
" resize_gravity : %s\n"
Expand All @@ -479,8 +478,6 @@ setup_constraint_info (ConstraintInfo *info,
info->orig.x, info->orig.y, info->orig.width, info->orig.height,
info->current.x, info->current.y,
info->current.width, info->current.height,
info->fgeom->left_width, info->fgeom->right_width,
info->fgeom->top_height, info->fgeom->bottom_height,
(info->action_type == ACTION_MOVE) ? "Move" :
(info->action_type == ACTION_RESIZE) ? "Resize" :
(info->action_type == ACTION_MOVE_AND_RESIZE) ? "Move&Resize" :
Expand Down Expand Up @@ -521,7 +518,7 @@ place_window_if_needed(MetaWindow *window,
MetaWorkspace *cur_workspace;
const MetaXineramaScreenInfo *xinerama_info;

meta_window_place (window, info->fgeom, info->orig.x, info->orig.y,
meta_window_place (window, info->borders, info->orig.x, info->orig.y,
&placed_rect.x, &placed_rect.y);
did_placement = TRUE;

Expand Down Expand Up @@ -581,7 +578,7 @@ place_window_if_needed(MetaWindow *window,

/* maximization may have changed frame geometry */
if (window->frame && !window->fullscreen)
meta_frame_calc_geometry (window->frame, info->fgeom);
meta_frame_calc_borders (window->frame, info->borders);

if (window->fullscreen_after_placement)
{
Expand Down Expand Up @@ -639,7 +636,7 @@ update_onscreen_requirements (MetaWindow *window,
/* The require onscreen/on-single-xinerama and titlebar_visible
* stuff is relative to the outer window, not the inner
*/
extend_by_frame (window, &info->current, info->fgeom);
extend_by_frame (window, &info->current, info->borders);

/* Update whether we want future constraint runs to require the
* window to be on fully onscreen.
Expand Down Expand Up @@ -675,7 +672,7 @@ update_onscreen_requirements (MetaWindow *window,
MetaRectangle titlebar_rect;

titlebar_rect = info->current;
titlebar_rect.height = info->fgeom->top_height;
titlebar_rect.height = info->borders->visible.top;
old = window->require_titlebar_visible;
window->require_titlebar_visible =
meta_rectangle_overlaps_with_region (info->usable_screen_region,
Expand All @@ -688,20 +685,20 @@ update_onscreen_requirements (MetaWindow *window,
}

/* Don't forget to restore the position of the window */
unextend_by_frame (window, &info->current, info->fgeom);
unextend_by_frame (window, &info->current, info->borders);
}

static void
extend_by_frame (MetaWindow *window,
MetaRectangle *rect,
const MetaFrameGeometry *fgeom)
const MetaFrameBorders *borders)
{
if (window->frame)
{
rect->x -= fgeom->left_width;
rect->y -= fgeom->top_height;
rect->width += fgeom->left_width + fgeom->right_width;
rect->height += fgeom->top_height + fgeom->bottom_height;
rect->x -= borders->visible.left;
rect->y -= borders->visible.top;
rect->width += borders->visible.left + borders->visible.right;
rect->height += borders->visible.top + borders->visible.bottom;
}
else
{
Expand All @@ -715,14 +712,14 @@ extend_by_frame (MetaWindow *window,
static void
unextend_by_frame (MetaWindow *window,
MetaRectangle *rect,
const MetaFrameGeometry *fgeom)
const MetaFrameBorders *borders)
{
if (window->frame)
{
rect->x += fgeom->left_width;
rect->y += fgeom->top_height;
rect->width -= fgeom->left_width + fgeom->right_width;
rect->height -= fgeom->top_height + fgeom->bottom_height;
rect->x += borders->visible.left;
rect->y += borders->visible.top;
rect->width -= borders->visible.left + borders->visible.right;
rect->height -= borders->visible.top + borders->visible.bottom;
}
else
{
Expand All @@ -735,7 +732,7 @@ unextend_by_frame (MetaWindow *window,

static inline void
get_size_limits (const MetaWindow *window,
const MetaFrameGeometry *fgeom,
const MetaFrameBorders *borders,
gboolean include_frame,
MetaRectangle *min_size,
MetaRectangle *max_size)
Expand All @@ -755,8 +752,8 @@ get_size_limits (const MetaWindow *window,

if (window->frame)
{
fw = fgeom->left_width + fgeom->right_width;
fh = fgeom->top_height + fgeom->bottom_height;
fw = borders->visible.left + borders->visible.right;
fh = borders->visible.top + borders->visible.bottom;

min_size->width += fw;
min_size->height += fh;
Expand Down Expand Up @@ -807,18 +804,18 @@ constrain_modal_dialog (MetaWindow *window,
y = 0;
if (parent->frame)
{
MetaFrameGeometry fgeom;
MetaFrameBorders borders;

x += parent->frame->rect.x;
y += parent->frame->rect.y;

meta_frame_calc_geometry (parent->frame, &fgeom);
y += fgeom.top_height;
meta_frame_calc_borders (parent->frame, &borders);
y += borders.visible.top;

y += info->fgeom->top_height;
y += info->borders->visible.top;
}
else
y = parent->rect.y + info->fgeom->top_height;
y = parent->rect.y + info->borders->visible.top;

constraint_already_satisfied = (x == info->current.x) && (y == info->current.y);

Expand Down Expand Up @@ -874,19 +871,19 @@ constrain_maximization (MetaWindow *window,
active_workspace_struts = window->screen->active_workspace->all_struts;

target_size = info->current;
extend_by_frame (window, &target_size, info->fgeom);
extend_by_frame (window, &target_size, info->borders);
meta_rectangle_expand_to_avoiding_struts (&target_size,
&info->entire_xinerama,
direction,
active_workspace_struts);
}
/* Now make target_size = maximized size of client window */
unextend_by_frame (window, &target_size, info->fgeom);
unextend_by_frame (window, &target_size, info->borders);

/* Check min size constraints; max size constraints are ignored for maximized
* windows, as per bug 327543.
*/
get_size_limits (window, info->fgeom, FALSE, &min_size, &max_size);
get_size_limits (window, info->borders, FALSE, &min_size, &max_size);
hminbad = target_size.width < min_size.width && window->maximized_horizontally;
vminbad = target_size.height < min_size.height && window->maximized_vertically;
if (hminbad || vminbad)
Expand Down Expand Up @@ -942,12 +939,12 @@ constrain_tiling (MetaWindow *window,
* use an external function for the actual calculation
*/
meta_window_get_current_tile_area (window, &target_size);
unextend_by_frame (window, &target_size, info->fgeom);
unextend_by_frame (window, &target_size, info->borders);

/* Check min size constraints; max size constraints are ignored as for
* maximized windows.
*/
get_size_limits (window, info->fgeom, FALSE, &min_size, &max_size);
get_size_limits (window, info->borders, FALSE, &min_size, &max_size);
hminbad = target_size.width < min_size.width;
vminbad = target_size.height < min_size.height;
if (hminbad || vminbad)
Expand Down Expand Up @@ -1095,7 +1092,7 @@ constrain_fullscreen (MetaWindow *window,

xinerama = info->entire_xinerama;

get_size_limits (window, info->fgeom, FALSE, &min_size, &max_size);
get_size_limits (window, info->borders, FALSE, &min_size, &max_size);
too_big = !meta_rectangle_could_fit_rect (&xinerama, &min_size);
too_small = !meta_rectangle_could_fit_rect (&max_size, &xinerama);
if (too_big || too_small)
Expand Down Expand Up @@ -1203,7 +1200,7 @@ constrain_size_limits (MetaWindow *window,
return TRUE;

/* Determine whether constraint is already satisfied; exit if it is */
get_size_limits (window, info->fgeom, FALSE, &min_size, &max_size);
get_size_limits (window, info->borders, FALSE, &min_size, &max_size);
/* We ignore max-size limits for maximized windows; see #327543 */
if (window->maximized_horizontally)
max_size.width = MAX (max_size.width, info->current.width);
Expand Down Expand Up @@ -1394,8 +1391,8 @@ do_screen_and_xinerama_relative_constraints (

/* Determine whether constraint applies; exit if it doesn't */
how_far_it_can_be_smushed = info->current;
get_size_limits (window, info->fgeom, TRUE, &min_size, &max_size);
extend_by_frame (window, &info->current, info->fgeom);
get_size_limits (window, info->borders, TRUE, &min_size, &max_size);
extend_by_frame (window, &info->current, info->borders);

if (info->action_type != ACTION_MOVE)
{
Expand All @@ -1415,7 +1412,7 @@ do_screen_and_xinerama_relative_constraints (
&info->current);
if (exit_early || constraint_satisfied || check_only)
{
unextend_by_frame (window, &info->current, info->fgeom);
unextend_by_frame (window, &info->current, info->borders);
return constraint_satisfied;
}

Expand All @@ -1439,7 +1436,7 @@ do_screen_and_xinerama_relative_constraints (
info->fixed_directions,
&info->current);

unextend_by_frame (window, &info->current, info->fgeom);
unextend_by_frame (window, &info->current, info->borders);
return TRUE;
}

Expand Down Expand Up @@ -1551,8 +1548,8 @@ constrain_titlebar_visible (MetaWindow *window,
*/
if (window->frame)
{
bottom_amount = info->current.height + info->fgeom->bottom_height;
vert_amount_onscreen = info->fgeom->top_height;
bottom_amount = info->current.height + info->borders->visible.bottom;
vert_amount_onscreen = info->borders->visible.top;
}
else
bottom_amount = vert_amount_offscreen;
Expand Down Expand Up @@ -1626,8 +1623,8 @@ constrain_partially_onscreen (MetaWindow *window,
*/
if (window->frame)
{
bottom_amount = info->current.height + info->fgeom->bottom_height;
vert_amount_onscreen = info->fgeom->top_height;
bottom_amount = info->current.height + info->borders->visible.bottom;
vert_amount_onscreen = info->borders->visible.top;
}
else
bottom_amount = vert_amount_offscreen;
Expand Down
2 changes: 1 addition & 1 deletion src/core/constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef enum
} MetaMoveResizeFlags;

void meta_window_constrain (MetaWindow *window,
MetaFrameGeometry *orig_fgeom,
MetaFrameBorders *orig_borders,
MetaMoveResizeFlags flags,
int resize_gravity,
const MetaRectangle *orig,
Expand Down
21 changes: 7 additions & 14 deletions src/core/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -4470,11 +4470,7 @@ process_request_frame_extents (MetaDisplay *display,
&hints);
if ((hints_set && hints->decorations) || !hints_set)
{
int top = 0;
int bottom = 0;
int left = 0;
int right = 0;

MetaFrameBorders borders;
MetaScreen *screen;

screen = meta_display_screen_for_xwindow (display,
Expand All @@ -4492,15 +4488,12 @@ process_request_frame_extents (MetaDisplay *display,
meta_ui_theme_get_frame_borders (screen->ui,
META_FRAME_TYPE_NORMAL,
0,
&top,
&bottom,
&left,
&right);

data[0] = left;
data[1] = right;
data[2] = top;
data[3] = bottom;
&borders);

data[0] = borders.visible.left;
data[1] = borders.visible.right;
data[2] = borders.visible.top;
data[3] = borders.visible.bottom;
}

meta_topic (META_DEBUG_GEOMETRY,
Expand Down

0 comments on commit c66b326

Please sign in to comment.