compositor: Move edge resistance data to MetaWindowDrag
At least indirectly, this is set as object qdata while the window drag is ongoing, and reset/reconstructed if needed. Consequently, this edge data does not need to be stored in the MetaDisplay struct anymore. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2683>
This commit is contained in:
parent
675d0df09b
commit
f04d84de65
@ -40,7 +40,9 @@
|
|||||||
window->type != META_WINDOW_MENU && \
|
window->type != META_WINDOW_MENU && \
|
||||||
window->type != META_WINDOW_SPLASHSCREEN
|
window->type != META_WINDOW_SPLASHSCREEN
|
||||||
|
|
||||||
struct MetaEdgeResistanceData
|
typedef struct _MetaEdgeResistanceData MetaEdgeResistanceData;
|
||||||
|
|
||||||
|
struct _MetaEdgeResistanceData
|
||||||
{
|
{
|
||||||
GArray *left_edges;
|
GArray *left_edges;
|
||||||
GArray *right_edges;
|
GArray *right_edges;
|
||||||
@ -48,7 +50,7 @@ struct MetaEdgeResistanceData
|
|||||||
GArray *bottom_edges;
|
GArray *bottom_edges;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void compute_resistance_and_snapping_edges (MetaDisplay *display);
|
static GQuark edge_resistance_data_quark = 0;
|
||||||
|
|
||||||
/* !WARNING!: this function can return invalid indices (namely, either -1 or
|
/* !WARNING!: this function can return invalid indices (namely, either -1 or
|
||||||
* edges->len); this is by design, but you need to remember this.
|
* edges->len); this is by design, but you need to remember this.
|
||||||
@ -456,14 +458,13 @@ apply_edge_snapping (int old_pos,
|
|||||||
* function will cause a crash.
|
* function will cause a crash.
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
apply_edge_resistance_to_each_side (MetaDisplay *display,
|
apply_edge_resistance_to_each_side (MetaEdgeResistanceData *edge_data,
|
||||||
MetaWindow *window,
|
MetaWindow *window,
|
||||||
const MetaRectangle *old_outer,
|
const MetaRectangle *old_outer,
|
||||||
MetaRectangle *new_outer,
|
MetaRectangle *new_outer,
|
||||||
MetaEdgeResistanceFlags flags,
|
MetaEdgeResistanceFlags flags,
|
||||||
gboolean is_resize)
|
gboolean is_resize)
|
||||||
{
|
{
|
||||||
MetaEdgeResistanceData *edge_data;
|
|
||||||
MetaRectangle modified_rect;
|
MetaRectangle modified_rect;
|
||||||
gboolean modified;
|
gboolean modified;
|
||||||
int new_left, new_right, new_top, new_bottom;
|
int new_left, new_right, new_top, new_bottom;
|
||||||
@ -472,11 +473,6 @@ apply_edge_resistance_to_each_side (MetaDisplay *display,
|
|||||||
auto_snap = flags & META_EDGE_RESISTANCE_SNAP;
|
auto_snap = flags & META_EDGE_RESISTANCE_SNAP;
|
||||||
keyboard_op = flags & META_EDGE_RESISTANCE_KEYBOARD_OP;
|
keyboard_op = flags & META_EDGE_RESISTANCE_KEYBOARD_OP;
|
||||||
|
|
||||||
if (display->grab_edge_resistance_data == NULL)
|
|
||||||
compute_resistance_and_snapping_edges (display);
|
|
||||||
|
|
||||||
edge_data = display->grab_edge_resistance_data;
|
|
||||||
|
|
||||||
if (auto_snap && !META_WINDOW_TILED_SIDE_BY_SIDE (window))
|
if (auto_snap && !META_WINDOW_TILED_SIDE_BY_SIDE (window))
|
||||||
{
|
{
|
||||||
/* Do the auto snapping instead of normal edge resistance; in all
|
/* Do the auto snapping instead of normal edge resistance; in all
|
||||||
@ -630,18 +626,12 @@ apply_edge_resistance_to_each_side (MetaDisplay *display,
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
meta_window_drag_edge_resistance_cleanup (MetaWindowDrag *window_drag)
|
meta_edge_resistance_data_free (MetaEdgeResistanceData *edge_data)
|
||||||
{
|
{
|
||||||
MetaWindow *window = meta_window_drag_get_window (window_drag);
|
|
||||||
MetaDisplay *display = window->display;
|
|
||||||
guint i,j;
|
guint i,j;
|
||||||
MetaEdgeResistanceData *edge_data = display->grab_edge_resistance_data;
|
|
||||||
GHashTable *edges_to_be_freed;
|
GHashTable *edges_to_be_freed;
|
||||||
|
|
||||||
if (edge_data == NULL) /* Not currently cached */
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* We first need to clean out any window edges */
|
/* We first need to clean out any window edges */
|
||||||
edges_to_be_freed = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
edges_to_be_freed = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
||||||
g_free, NULL);
|
g_free, NULL);
|
||||||
@ -700,8 +690,16 @@ meta_window_drag_edge_resistance_cleanup (MetaWindowDrag *window_drag)
|
|||||||
edge_data->top_edges = NULL;
|
edge_data->top_edges = NULL;
|
||||||
edge_data->bottom_edges = NULL;
|
edge_data->bottom_edges = NULL;
|
||||||
|
|
||||||
g_free (display->grab_edge_resistance_data);
|
g_free (edge_data);
|
||||||
display->grab_edge_resistance_data = NULL;
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
meta_window_drag_edge_resistance_cleanup (MetaWindowDrag *window_drag)
|
||||||
|
{
|
||||||
|
if (edge_resistance_data_quark == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_object_set_qdata (G_OBJECT (window_drag), edge_resistance_data_quark, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -713,7 +711,7 @@ stupid_sort_requiring_extra_pointer_dereference (gconstpointer a,
|
|||||||
return meta_rectangle_edge_cmp_ignore_type (*a_edge, *b_edge);
|
return meta_rectangle_edge_cmp_ignore_type (*a_edge, *b_edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static MetaEdgeResistanceData *
|
||||||
cache_edges (MetaDisplay *display,
|
cache_edges (MetaDisplay *display,
|
||||||
GList *window_edges,
|
GList *window_edges,
|
||||||
GList *monitor_edges,
|
GList *monitor_edges,
|
||||||
@ -798,9 +796,7 @@ cache_edges (MetaDisplay *display,
|
|||||||
/*
|
/*
|
||||||
* 2nd: Allocate the edges
|
* 2nd: Allocate the edges
|
||||||
*/
|
*/
|
||||||
g_assert (display->grab_edge_resistance_data == NULL);
|
edge_data = g_new0 (MetaEdgeResistanceData, 1);
|
||||||
display->grab_edge_resistance_data = g_new0 (MetaEdgeResistanceData, 1);
|
|
||||||
edge_data = display->grab_edge_resistance_data;
|
|
||||||
edge_data->left_edges = g_array_sized_new (FALSE,
|
edge_data->left_edges = g_array_sized_new (FALSE,
|
||||||
FALSE,
|
FALSE,
|
||||||
sizeof(MetaEdge*),
|
sizeof(MetaEdge*),
|
||||||
@ -867,19 +863,22 @@ cache_edges (MetaDisplay *display,
|
|||||||
* avoided this sort by sticking them into the array with some simple
|
* avoided this sort by sticking them into the array with some simple
|
||||||
* merging of the lists).
|
* merging of the lists).
|
||||||
*/
|
*/
|
||||||
g_array_sort (display->grab_edge_resistance_data->left_edges,
|
g_array_sort (edge_data->left_edges,
|
||||||
stupid_sort_requiring_extra_pointer_dereference);
|
stupid_sort_requiring_extra_pointer_dereference);
|
||||||
g_array_sort (display->grab_edge_resistance_data->right_edges,
|
g_array_sort (edge_data->right_edges,
|
||||||
stupid_sort_requiring_extra_pointer_dereference);
|
stupid_sort_requiring_extra_pointer_dereference);
|
||||||
g_array_sort (display->grab_edge_resistance_data->top_edges,
|
g_array_sort (edge_data->top_edges,
|
||||||
stupid_sort_requiring_extra_pointer_dereference);
|
stupid_sort_requiring_extra_pointer_dereference);
|
||||||
g_array_sort (display->grab_edge_resistance_data->bottom_edges,
|
g_array_sort (edge_data->bottom_edges,
|
||||||
stupid_sort_requiring_extra_pointer_dereference);
|
stupid_sort_requiring_extra_pointer_dereference);
|
||||||
|
|
||||||
|
return edge_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static MetaEdgeResistanceData *
|
||||||
compute_resistance_and_snapping_edges (MetaDisplay *display)
|
compute_resistance_and_snapping_edges (MetaWindowDrag *window_drag)
|
||||||
{
|
{
|
||||||
|
MetaEdgeResistanceData *edge_data;
|
||||||
GList *stacked_windows;
|
GList *stacked_windows;
|
||||||
GList *cur_window_iter;
|
GList *cur_window_iter;
|
||||||
GList *edges;
|
GList *edges;
|
||||||
@ -890,12 +889,10 @@ compute_resistance_and_snapping_edges (MetaDisplay *display)
|
|||||||
* in the layer that we are working on
|
* in the layer that we are working on
|
||||||
*/
|
*/
|
||||||
GSList *rem_windows, *rem_win_stacking;
|
GSList *rem_windows, *rem_win_stacking;
|
||||||
|
MetaWindow *window = meta_window_drag_get_window (window_drag);
|
||||||
|
MetaDisplay *display = window->display;
|
||||||
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
|
MetaWorkspaceManager *workspace_manager = display->workspace_manager;
|
||||||
MetaWindowDrag *window_drag;
|
|
||||||
|
|
||||||
window_drag = meta_compositor_get_current_window_drag (display->compositor);
|
|
||||||
|
|
||||||
g_assert (window_drag != NULL);
|
|
||||||
meta_topic (META_DEBUG_WINDOW_OPS,
|
meta_topic (META_DEBUG_WINDOW_OPS,
|
||||||
"Computing edges to resist-movement or snap-to for %s.",
|
"Computing edges to resist-movement or snap-to for %s.",
|
||||||
meta_window_drag_get_window (window_drag)->desc);
|
meta_window_drag_get_window (window_drag)->desc);
|
||||||
@ -1059,11 +1056,39 @@ compute_resistance_and_snapping_edges (MetaDisplay *display)
|
|||||||
* monitor edges in an array for quick access. Free the edges since
|
* monitor edges in an array for quick access. Free the edges since
|
||||||
* they've been cached elsewhere.
|
* they've been cached elsewhere.
|
||||||
*/
|
*/
|
||||||
cache_edges (display,
|
edge_data = cache_edges (display,
|
||||||
edges,
|
edges,
|
||||||
workspace_manager->active_workspace->monitor_edges,
|
workspace_manager->active_workspace->monitor_edges,
|
||||||
workspace_manager->active_workspace->screen_edges);
|
workspace_manager->active_workspace->screen_edges);
|
||||||
g_list_free (edges);
|
g_list_free (edges);
|
||||||
|
|
||||||
|
return edge_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MetaEdgeResistanceData *
|
||||||
|
meta_window_drag_ensure_edge_resistance_data (MetaWindowDrag *window_drag)
|
||||||
|
{
|
||||||
|
MetaEdgeResistanceData *edge_data;
|
||||||
|
|
||||||
|
if (G_UNLIKELY (edge_resistance_data_quark == 0))
|
||||||
|
{
|
||||||
|
edge_resistance_data_quark =
|
||||||
|
g_quark_from_static_string ("meta-window-drag-edge-data");
|
||||||
|
}
|
||||||
|
|
||||||
|
edge_data = g_object_get_qdata (G_OBJECT (window_drag),
|
||||||
|
edge_resistance_data_quark);
|
||||||
|
|
||||||
|
if (!edge_data)
|
||||||
|
{
|
||||||
|
edge_data = compute_resistance_and_snapping_edges (window_drag);
|
||||||
|
g_object_set_qdata_full (G_OBJECT (window_drag),
|
||||||
|
edge_resistance_data_quark,
|
||||||
|
edge_data,
|
||||||
|
(GDestroyNotify) meta_edge_resistance_data_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
return edge_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1072,6 +1097,7 @@ meta_window_drag_edge_resistance_for_move (MetaWindowDrag *window_drag,
|
|||||||
int *new_y,
|
int *new_y,
|
||||||
MetaEdgeResistanceFlags flags)
|
MetaEdgeResistanceFlags flags)
|
||||||
{
|
{
|
||||||
|
MetaEdgeResistanceData *edge_data;
|
||||||
MetaRectangle old_outer, proposed_outer, new_outer;
|
MetaRectangle old_outer, proposed_outer, new_outer;
|
||||||
gboolean is_resize, is_keyboard_op, snap;
|
gboolean is_resize, is_keyboard_op, snap;
|
||||||
MetaWindow *window;
|
MetaWindow *window;
|
||||||
@ -1088,8 +1114,10 @@ meta_window_drag_edge_resistance_for_move (MetaWindowDrag *window_drag,
|
|||||||
snap = flags & META_EDGE_RESISTANCE_SNAP;
|
snap = flags & META_EDGE_RESISTANCE_SNAP;
|
||||||
is_keyboard_op = flags & META_EDGE_RESISTANCE_KEYBOARD_OP;
|
is_keyboard_op = flags & META_EDGE_RESISTANCE_KEYBOARD_OP;
|
||||||
|
|
||||||
|
edge_data = meta_window_drag_ensure_edge_resistance_data (window_drag);
|
||||||
|
|
||||||
is_resize = FALSE;
|
is_resize = FALSE;
|
||||||
if (apply_edge_resistance_to_each_side (window->display,
|
if (apply_edge_resistance_to_each_side (edge_data,
|
||||||
window,
|
window,
|
||||||
&old_outer,
|
&old_outer,
|
||||||
&new_outer,
|
&new_outer,
|
||||||
@ -1152,6 +1180,7 @@ meta_window_drag_edge_resistance_for_resize (MetaWindowDrag *window_dra
|
|||||||
MetaGravity gravity,
|
MetaGravity gravity,
|
||||||
MetaEdgeResistanceFlags flags)
|
MetaEdgeResistanceFlags flags)
|
||||||
{
|
{
|
||||||
|
MetaEdgeResistanceData *edge_data;
|
||||||
MetaRectangle old_outer, new_outer;
|
MetaRectangle old_outer, new_outer;
|
||||||
int proposed_outer_width, proposed_outer_height;
|
int proposed_outer_width, proposed_outer_height;
|
||||||
MetaWindow *window;
|
MetaWindow *window;
|
||||||
@ -1167,7 +1196,9 @@ meta_window_drag_edge_resistance_for_resize (MetaWindowDrag *window_dra
|
|||||||
proposed_outer_width,
|
proposed_outer_width,
|
||||||
proposed_outer_height);
|
proposed_outer_height);
|
||||||
|
|
||||||
if (apply_edge_resistance_to_each_side (window->display,
|
edge_data = meta_window_drag_ensure_edge_resistance_data (window_drag);
|
||||||
|
|
||||||
|
if (apply_edge_resistance_to_each_side (edge_data,
|
||||||
window,
|
window,
|
||||||
&old_outer,
|
&old_outer,
|
||||||
&new_outer,
|
&new_outer,
|
||||||
|
@ -44,8 +44,6 @@
|
|||||||
typedef struct _MetaBell MetaBell;
|
typedef struct _MetaBell MetaBell;
|
||||||
typedef struct _MetaStack MetaStack;
|
typedef struct _MetaStack MetaStack;
|
||||||
|
|
||||||
typedef struct MetaEdgeResistanceData MetaEdgeResistanceData;
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
META_LIST_DEFAULT = 0, /* normal windows */
|
META_LIST_DEFAULT = 0, /* normal windows */
|
||||||
@ -143,8 +141,6 @@ struct _MetaDisplay
|
|||||||
guint autoraise_timeout_id;
|
guint autoraise_timeout_id;
|
||||||
MetaWindow* autoraise_window;
|
MetaWindow* autoraise_window;
|
||||||
|
|
||||||
MetaEdgeResistanceData *grab_edge_resistance_data;
|
|
||||||
|
|
||||||
MetaKeyBindingManager key_binding_manager;
|
MetaKeyBindingManager key_binding_manager;
|
||||||
|
|
||||||
/* Opening the display */
|
/* Opening the display */
|
||||||
|
Loading…
Reference in New Issue
Block a user