util: Remove shell_util_get_transformed_allocation

This helper function could be replaced with the new
clutter_actor_get_transformed_extents, that does the same.

See https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1386

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1380
This commit is contained in:
Daniel García Moreno 2020-07-29 12:50:47 +02:00
parent 95436a08b5
commit 71d37bffdf
5 changed files with 27 additions and 89 deletions

View File

@ -2335,13 +2335,8 @@ var AppFolderDialog = GObject.registerClass({
} }
_withinDialog(x, y) { _withinDialog(x, y) {
const childAllocation = const childExtents = this.child.get_transformed_extents();
Shell.util_get_transformed_allocation(this.child); return childExtents.contains_point(new Graphene.Point({ x, y }));
return x > childAllocation.x1 &&
x < childAllocation.x2 &&
y > childAllocation.y1 &&
y < childAllocation.y2;
} }
_setupDragMonitor() { _setupDragMonitor() {

View File

@ -1,7 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported BoxPointer */ /* exported BoxPointer */
const { Clutter, GObject, Shell, St } = imports.gi; const { Clutter, GObject, St } = imports.gi;
const Main = imports.ui.main; const Main = imports.ui.main;
@ -453,15 +453,16 @@ var BoxPointer = GObject.registerClass({
let alignment = this._arrowAlignment; let alignment = this._arrowAlignment;
let monitorIndex = Main.layoutManager.findIndexForActor(sourceActor); let monitorIndex = Main.layoutManager.findIndexForActor(sourceActor);
this._sourceAllocation = Shell.util_get_transformed_allocation(sourceActor); this._sourceExtents = sourceActor.get_transformed_extents();
this._workArea = Main.layoutManager.getWorkAreaForMonitor(monitorIndex); this._workArea = Main.layoutManager.getWorkAreaForMonitor(monitorIndex);
// Position correctly relative to the sourceActor // Position correctly relative to the sourceActor
let sourceNode = sourceActor.get_theme_node(); let sourceNode = sourceActor.get_theme_node();
let sourceContentBox = sourceNode.get_content_box(sourceActor.get_allocation_box()); let sourceContentBox = sourceNode.get_content_box(sourceActor.get_allocation_box());
let sourceAllocation = this._sourceAllocation; let sourceTopLeft = this._sourceExtents.get_top_left();
let sourceCenterX = sourceAllocation.x1 + sourceContentBox.x1 + (sourceContentBox.x2 - sourceContentBox.x1) * this._sourceAlignment; let sourceBottomRight = this._sourceExtents.get_bottom_right();
let sourceCenterY = sourceAllocation.y1 + sourceContentBox.y1 + (sourceContentBox.y2 - sourceContentBox.y1) * this._sourceAlignment; let sourceCenterX = sourceTopLeft.x + sourceContentBox.x1 + (sourceContentBox.x2 - sourceContentBox.x1) * this._sourceAlignment;
let sourceCenterY = sourceTopLeft.y + sourceContentBox.y1 + (sourceContentBox.y2 - sourceContentBox.y1) * this._sourceAlignment;
let [, , natWidth, natHeight] = this.get_preferred_size(); let [, , natWidth, natHeight] = this.get_preferred_size();
// We also want to keep it onscreen, and separated from the // We also want to keep it onscreen, and separated from the
@ -481,16 +482,16 @@ var BoxPointer = GObject.registerClass({
switch (this._arrowSide) { switch (this._arrowSide) {
case St.Side.TOP: case St.Side.TOP:
resY = sourceAllocation.y2 + gap; resY = sourceBottomRight.y + gap;
break; break;
case St.Side.BOTTOM: case St.Side.BOTTOM:
resY = sourceAllocation.y1 - natHeight - gap; resY = sourceTopLeft.y - natHeight - gap;
break; break;
case St.Side.LEFT: case St.Side.LEFT:
resX = sourceAllocation.x2 + gap; resX = sourceBottomRight.x + gap;
break; break;
case St.Side.RIGHT: case St.Side.RIGHT:
resX = sourceAllocation.x1 - natWidth - gap; resX = sourceTopLeft.x - natWidth - gap;
break; break;
} }
@ -586,29 +587,30 @@ var BoxPointer = GObject.registerClass({
} }
_calculateArrowSide(arrowSide) { _calculateArrowSide(arrowSide) {
let sourceAllocation = this._sourceAllocation; let sourceTopLeft = this._sourceExtents.get_top_left();
let sourceBottomRight = this._sourceExtents.get_bottom_right();
let [, , boxWidth, boxHeight] = this.get_preferred_size(); let [, , boxWidth, boxHeight] = this.get_preferred_size();
let workarea = this._workArea; let workarea = this._workArea;
switch (arrowSide) { switch (arrowSide) {
case St.Side.TOP: case St.Side.TOP:
if (sourceAllocation.y2 + boxHeight > workarea.y + workarea.height && if (sourceBottomRight.y + boxHeight > workarea.y + workarea.height &&
boxHeight < sourceAllocation.y1 - workarea.y) boxHeight < sourceTopLeft.y - workarea.y)
return St.Side.BOTTOM; return St.Side.BOTTOM;
break; break;
case St.Side.BOTTOM: case St.Side.BOTTOM:
if (sourceAllocation.y1 - boxHeight < workarea.y && if (sourceTopLeft.y - boxHeight < workarea.y &&
boxHeight < workarea.y + workarea.height - sourceAllocation.y2) boxHeight < workarea.y + workarea.height - sourceBottomRight.y)
return St.Side.TOP; return St.Side.TOP;
break; break;
case St.Side.LEFT: case St.Side.LEFT:
if (sourceAllocation.x2 + boxWidth > workarea.x + workarea.width && if (sourceBottomRight.x + boxWidth > workarea.x + workarea.width &&
boxWidth < sourceAllocation.x1 - workarea.x) boxWidth < sourceTopLeft.x - workarea.x)
return St.Side.RIGHT; return St.Side.RIGHT;
break; break;
case St.Side.RIGHT: case St.Side.RIGHT:
if (sourceAllocation.x1 - boxWidth < workarea.x && if (sourceTopLeft.x - boxWidth < workarea.x &&
boxWidth < workarea.x + workarea.width - sourceAllocation.x2) boxWidth < workarea.x + workarea.width - sourceBottomRight.x)
return St.Side.LEFT; return St.Side.LEFT;
break; break;
} }

View File

@ -388,17 +388,16 @@ var _Draggable = class _Draggable {
const [, newAllocatedWidth] = this._dragActor.get_preferred_width(-1); const [, newAllocatedWidth] = this._dragActor.get_preferred_width(-1);
const [, newAllocatedHeight] = this._dragActor.get_preferred_height(-1); const [, newAllocatedHeight] = this._dragActor.get_preferred_height(-1);
const transformedAllocation = const transformedExtents = this._dragActor.get_transformed_extents();
Shell.util_get_transformed_allocation(this._dragActor);
// Set the actor's scale such that it will keep the same // Set the actor's scale such that it will keep the same
// transformed size when it's reparented to the uiGroup // transformed size when it's reparented to the uiGroup
this._dragActor.set_scale( this._dragActor.set_scale(
transformedAllocation.get_width() / newAllocatedWidth, transformedExtents.get_width() / newAllocatedWidth,
transformedAllocation.get_height() / newAllocatedHeight); transformedExtents.get_height() / newAllocatedHeight);
this._dragOffsetX = transformedAllocation.x1 - this._dragStartX; this._dragOffsetX = transformedExtents.origin.x - this._dragStartX;
this._dragOffsetY = transformedAllocation.y1 - this._dragStartY; this._dragOffsetY = transformedExtents.origin.y - this._dragStartY;
this._dragOrigParent.remove_actor(this._dragActor); this._dragOrigParent.remove_actor(this._dragActor);
Main.uiGroup.add_child(this._dragActor); Main.uiGroup.add_child(this._dragActor);

View File

@ -77,61 +77,6 @@ shell_util_set_hidden_from_pick (ClutterActor *actor,
} }
} }
/**
* shell_util_get_transformed_allocation:
* @actor: a #ClutterActor
* @box: (out): location to store returned box in stage coordinates
*
* This function is similar to a combination of clutter_actor_get_transformed_position(),
* and clutter_actor_get_transformed_size(), but unlike
* clutter_actor_get_transformed_size(), it always returns a transform
* of the current allocation, while clutter_actor_get_transformed_size() returns
* bad values (the transform of the requested size) if a relayout has been
* queued.
*
* This function is more convenient to use than
* clutter_actor_get_abs_allocation_vertices() if no transformation is in effect
* and also works around limitations in the GJS binding of arrays.
*/
void
shell_util_get_transformed_allocation (ClutterActor *actor,
ClutterActorBox *box)
{
/* Code adapted from clutter-actor.c:
* Copyright 2006, 2007, 2008 OpenedHand Ltd
*/
graphene_point3d_t v[4];
gfloat x_min, x_max, y_min, y_max;
guint i;
g_return_if_fail (CLUTTER_IS_ACTOR (actor));
clutter_actor_get_abs_allocation_vertices (actor, v);
x_min = x_max = v[0].x;
y_min = y_max = v[0].y;
for (i = 1; i < G_N_ELEMENTS (v); ++i)
{
if (v[i].x < x_min)
x_min = v[i].x;
if (v[i].x > x_max)
x_max = v[i].x;
if (v[i].y < y_min)
y_min = v[i].y;
if (v[i].y > y_max)
y_max = v[i].y;
}
box->x1 = x_min;
box->y1 = y_min;
box->x2 = x_max;
box->y2 = y_max;
}
/** /**
* shell_util_get_week_start: * shell_util_get_week_start:
* *

View File

@ -14,9 +14,6 @@ G_BEGIN_DECLS
void shell_util_set_hidden_from_pick (ClutterActor *actor, void shell_util_set_hidden_from_pick (ClutterActor *actor,
gboolean hidden); gboolean hidden);
void shell_util_get_transformed_allocation (ClutterActor *actor,
ClutterActorBox *box);
int shell_util_get_week_start (void); int shell_util_get_week_start (void);
const char *shell_util_translate_time_string (const char *str); const char *shell_util_translate_time_string (const char *str);