edge-resistance: Replace booleans with flags parameter

Multiple boolean parameters don't make for great API, so before we
add another one, replace them with a single flag parameter.

https://bugzilla.gnome.org/show_bug.cgi?id=679609
This commit is contained in:
Florian Müllner 2020-05-24 03:07:51 +02:00 committed by verdre
parent 64ced1632e
commit f9edb6bad3
8 changed files with 120 additions and 97 deletions

View File

@ -192,7 +192,7 @@ struct _MetaDisplay
gboolean grab_threshold_movement_reached; /* raise_on_click == FALSE. */ gboolean grab_threshold_movement_reached; /* raise_on_click == FALSE. */
int64_t grab_last_moveresize_time; int64_t grab_last_moveresize_time;
MetaEdgeResistanceData *grab_edge_resistance_data; MetaEdgeResistanceData *grab_edge_resistance_data;
unsigned int grab_last_user_action_was_snap; unsigned int grab_last_edge_resistance_flags;
int grab_resize_timeout_id; int grab_resize_timeout_id;

View File

@ -1903,7 +1903,7 @@ meta_display_begin_grab_op (MetaDisplay *display,
display->grab_latest_motion_x = root_x; display->grab_latest_motion_x = root_x;
display->grab_latest_motion_y = root_y; display->grab_latest_motion_y = root_y;
display->grab_last_moveresize_time = 0; display->grab_last_moveresize_time = 0;
display->grab_last_user_action_was_snap = FALSE; display->grab_last_edge_resistance_flags = META_EDGE_RESISTANCE_DEFAULT;
display->grab_frame_action = frame_action; display->grab_frame_action = frame_action;
meta_display_update_cursor (display); meta_display_update_cursor (display);

View File

@ -542,14 +542,17 @@ apply_edge_resistance_to_each_side (MetaDisplay *display,
const MetaRectangle *old_outer, const MetaRectangle *old_outer,
MetaRectangle *new_outer, MetaRectangle *new_outer,
GSourceFunc timeout_func, GSourceFunc timeout_func,
gboolean auto_snap, MetaEdgeResistanceFlags flags,
gboolean keyboard_op,
gboolean is_resize) gboolean is_resize)
{ {
MetaEdgeResistanceData *edge_data; 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;
gboolean auto_snap, keyboard_op;
auto_snap = flags & META_EDGE_RESISTANCE_SNAP;
keyboard_op = flags & META_EDGE_RESISTANCE_KEYBOARD_OP;
if (display->grab_edge_resistance_data == NULL) if (display->grab_edge_resistance_data == NULL)
compute_resistance_and_snapping_edges (display); compute_resistance_and_snapping_edges (display);
@ -1178,11 +1181,11 @@ meta_window_edge_resistance_for_move (MetaWindow *window,
int *new_x, int *new_x,
int *new_y, int *new_y,
GSourceFunc timeout_func, GSourceFunc timeout_func,
gboolean snap, MetaEdgeResistanceFlags flags)
gboolean is_keyboard_op)
{ {
MetaRectangle old_outer, proposed_outer, new_outer; MetaRectangle old_outer, proposed_outer, new_outer;
gboolean is_resize; MetaEdgeResistanceFlags saved_flags;
gboolean is_resize, is_keyboard_op, snap;
meta_window_get_frame_rect (window, &old_outer); meta_window_get_frame_rect (window, &old_outer);
@ -1191,15 +1194,18 @@ meta_window_edge_resistance_for_move (MetaWindow *window,
proposed_outer.y = *new_y; proposed_outer.y = *new_y;
new_outer = proposed_outer; new_outer = proposed_outer;
window->display->grab_last_user_action_was_snap = snap; snap = flags & META_EDGE_RESISTANCE_SNAP;
is_keyboard_op = flags & META_EDGE_RESISTANCE_KEYBOARD_OP;
saved_flags = flags & ~META_EDGE_RESISTANCE_KEYBOARD_OP;
window->display->grab_last_edge_resistance_flags = saved_flags;
is_resize = FALSE; is_resize = FALSE;
if (apply_edge_resistance_to_each_side (window->display, if (apply_edge_resistance_to_each_side (window->display,
window, window,
&old_outer, &old_outer,
&new_outer, &new_outer,
timeout_func, timeout_func,
snap, flags,
is_keyboard_op,
is_resize)) is_resize))
{ {
/* apply_edge_resistance_to_each_side independently applies /* apply_edge_resistance_to_each_side independently applies
@ -1257,10 +1263,10 @@ meta_window_edge_resistance_for_resize (MetaWindow *window,
int *new_height, int *new_height,
MetaGravity gravity, MetaGravity gravity,
GSourceFunc timeout_func, GSourceFunc timeout_func,
gboolean snap, MetaEdgeResistanceFlags flags)
gboolean is_keyboard_op)
{ {
MetaRectangle old_outer, new_outer; MetaRectangle old_outer, new_outer;
MetaEdgeResistanceFlags saved_flags;
int proposed_outer_width, proposed_outer_height; int proposed_outer_width, proposed_outer_height;
meta_window_get_frame_rect (window, &old_outer); meta_window_get_frame_rect (window, &old_outer);
@ -1272,14 +1278,15 @@ meta_window_edge_resistance_for_resize (MetaWindow *window,
proposed_outer_width, proposed_outer_width,
proposed_outer_height); proposed_outer_height);
window->display->grab_last_user_action_was_snap = snap; saved_flags = flags & ~META_EDGE_RESISTANCE_KEYBOARD_OP;
window->display->grab_last_edge_resistance_flags = saved_flags;
if (apply_edge_resistance_to_each_side (window->display, if (apply_edge_resistance_to_each_side (window->display,
window, window,
&old_outer, &old_outer,
&new_outer, &new_outer,
timeout_func, timeout_func,
snap, flags,
is_keyboard_op,
TRUE)) TRUE))
{ {
*new_width = new_outer.width; *new_width = new_outer.width;

View File

@ -28,15 +28,13 @@ void meta_window_edge_resistance_for_move (MetaWindow *window,
int *new_x, int *new_x,
int *new_y, int *new_y,
GSourceFunc timeout_func, GSourceFunc timeout_func,
gboolean snap, MetaEdgeResistanceFlags flags);
gboolean is_keyboard_op);
void meta_window_edge_resistance_for_resize (MetaWindow *window, void meta_window_edge_resistance_for_resize (MetaWindow *window,
int *new_width, int *new_width,
int *new_height, int *new_height,
MetaGravity gravity, MetaGravity gravity,
GSourceFunc timeout_func, GSourceFunc timeout_func,
gboolean snap, MetaEdgeResistanceFlags flags);
gboolean is_keyboard_op);
#endif /* META_EDGE_RESISTANCE_H */ #endif /* META_EDGE_RESISTANCE_H */

View File

@ -2400,11 +2400,11 @@ process_keyboard_move_grab (MetaDisplay *display,
MetaWindow *window, MetaWindow *window,
ClutterKeyEvent *event) ClutterKeyEvent *event)
{ {
MetaEdgeResistanceFlags flags;
gboolean handled; gboolean handled;
MetaRectangle frame_rect; MetaRectangle frame_rect;
int x, y; int x, y;
int incr; int incr;
gboolean smart_snap;
handled = FALSE; handled = FALSE;
@ -2420,12 +2420,15 @@ process_keyboard_move_grab (MetaDisplay *display,
x = frame_rect.x; x = frame_rect.x;
y = frame_rect.y; y = frame_rect.y;
smart_snap = (event->modifier_state & CLUTTER_SHIFT_MASK) != 0; flags = META_EDGE_RESISTANCE_KEYBOARD_OP;
if ((event->modifier_state & CLUTTER_SHIFT_MASK) != 0)
flags |= META_EDGE_RESISTANCE_SNAP;
#define SMALL_INCREMENT 1 #define SMALL_INCREMENT 1
#define NORMAL_INCREMENT 10 #define NORMAL_INCREMENT 10
if (smart_snap) if (flags & META_EDGE_RESISTANCE_SNAP)
incr = 1; incr = 1;
else if (event->modifier_state & CLUTTER_CONTROL_MASK) else if (event->modifier_state & CLUTTER_CONTROL_MASK)
incr = SMALL_INCREMENT; incr = SMALL_INCREMENT;
@ -2501,8 +2504,7 @@ process_keyboard_move_grab (MetaDisplay *display,
&x, &x,
&y, &y,
NULL, NULL,
smart_snap, flags);
TRUE);
meta_window_move_frame (window, TRUE, x, y); meta_window_move_frame (window, TRUE, x, y);
meta_window_update_keyboard_move (window); meta_window_update_keyboard_move (window);
@ -2641,7 +2643,7 @@ process_keyboard_resize_grab (MetaDisplay *display,
int height_inc; int height_inc;
int width_inc; int width_inc;
int width, height; int width, height;
gboolean smart_snap; MetaEdgeResistanceFlags flags;
MetaGravity gravity; MetaGravity gravity;
handled = FALSE; handled = FALSE;
@ -2679,12 +2681,15 @@ process_keyboard_resize_grab (MetaDisplay *display,
gravity = meta_resize_gravity_from_grab_op (display->grab_op); gravity = meta_resize_gravity_from_grab_op (display->grab_op);
smart_snap = (event->modifier_state & CLUTTER_SHIFT_MASK) != 0; flags = META_EDGE_RESISTANCE_KEYBOARD_OP;
if ((event->modifier_state & CLUTTER_SHIFT_MASK) != 0)
flags |= META_EDGE_RESISTANCE_SNAP;
#define SMALL_INCREMENT 1 #define SMALL_INCREMENT 1
#define NORMAL_INCREMENT 10 #define NORMAL_INCREMENT 10
if (smart_snap) if (flags & META_EDGE_RESISTANCE_SNAP)
{ {
height_inc = 1; height_inc = 1;
width_inc = 1; width_inc = 1;
@ -2853,8 +2858,7 @@ process_keyboard_resize_grab (MetaDisplay *display,
&height, &height,
gravity, gravity,
NULL, NULL,
smart_snap, flags);
TRUE);
meta_window_resize_frame_with_gravity (window, meta_window_resize_frame_with_gravity (window,
TRUE, TRUE,

View File

@ -157,6 +157,13 @@ typedef enum
META_EDGE_CONSTRAINT_MONITOR = 2, META_EDGE_CONSTRAINT_MONITOR = 2,
} MetaEdgeConstraint; } MetaEdgeConstraint;
typedef enum
{
META_EDGE_RESISTANCE_DEFAULT = 0,
META_EDGE_RESISTANCE_SNAP = 1 << 0,
META_EDGE_RESISTANCE_KEYBOARD_OP = 1 << 1,
} MetaEdgeResistanceFlags;
struct _MetaWindow struct _MetaWindow
{ {
GObject parent_instance; GObject parent_instance;
@ -843,7 +850,7 @@ void meta_window_set_urgent (MetaWindow *window,
gboolean urgent); gboolean urgent);
void meta_window_update_resize (MetaWindow *window, void meta_window_update_resize (MetaWindow *window,
gboolean snap, MetaEdgeResistanceFlags flags,
int x, int y, int x, int y,
gboolean force); gboolean force);

View File

@ -132,12 +132,12 @@ static void meta_window_move_resize_now (MetaWindow *window);
static void meta_window_unqueue (MetaWindow *window, guint queuebits); static void meta_window_unqueue (MetaWindow *window, guint queuebits);
static void update_move (MetaWindow *window, static void update_move (MetaWindow *window,
gboolean snap, MetaEdgeResistanceFlags flags,
int x, int x,
int y); int y);
static gboolean update_move_timeout (gpointer data); static gboolean update_move_timeout (gpointer data);
static void update_resize (MetaWindow *window, static void update_resize (MetaWindow *window,
gboolean snap, MetaEdgeResistanceFlags flags,
int x, int x,
int y, int y,
gboolean force); gboolean force);
@ -5980,7 +5980,7 @@ update_move_timeout (gpointer data)
MetaWindow *window = data; MetaWindow *window = data;
update_move (window, update_move (window,
window->display->grab_last_user_action_was_snap, window->display->grab_last_edge_resistance_flags,
window->display->grab_latest_motion_x, window->display->grab_latest_motion_x,
window->display->grab_latest_motion_y); window->display->grab_latest_motion_y);
@ -6044,7 +6044,7 @@ update_move_maybe_tile (MetaWindow *window,
static void static void
update_move (MetaWindow *window, update_move (MetaWindow *window,
gboolean snap, MetaEdgeResistanceFlags flags,
int x, int x,
int y) int y)
{ {
@ -6086,7 +6086,7 @@ update_move (MetaWindow *window,
shake_threshold = meta_prefs_get_drag_threshold () * shake_threshold = meta_prefs_get_drag_threshold () *
DRAG_THRESHOLD_TO_SHAKE_THRESHOLD_FACTOR; DRAG_THRESHOLD_TO_SHAKE_THRESHOLD_FACTOR;
if (snap) if (flags & META_EDGE_RESISTANCE_SNAP)
{ {
/* We don't want to tile while snapping. Also, clear any previous tile /* We don't want to tile while snapping. Also, clear any previous tile
request. */ request. */
@ -6222,8 +6222,7 @@ update_move (MetaWindow *window,
&new_x, &new_x,
&new_y, &new_y,
update_move_timeout, update_move_timeout,
snap, flags);
FALSE);
meta_window_move_frame (window, TRUE, new_x, new_y); meta_window_move_frame (window, TRUE, new_x, new_y);
} }
@ -6234,7 +6233,7 @@ update_resize_timeout (gpointer data)
MetaWindow *window = data; MetaWindow *window = data;
update_resize (window, update_resize (window,
window->display->grab_last_user_action_was_snap, window->display->grab_last_edge_resistance_flags,
window->display->grab_latest_motion_x, window->display->grab_latest_motion_x,
window->display->grab_latest_motion_y, window->display->grab_latest_motion_y,
TRUE); TRUE);
@ -6243,8 +6242,9 @@ update_resize_timeout (gpointer data)
static void static void
update_resize (MetaWindow *window, update_resize (MetaWindow *window,
gboolean snap, MetaEdgeResistanceFlags flags,
int x, int y, int x,
int y,
gboolean force) gboolean force)
{ {
int dx, dy; int dx, dy;
@ -6359,8 +6359,7 @@ update_resize (MetaWindow *window,
&new_h, &new_h,
gravity, gravity,
update_resize_timeout, update_resize_timeout,
snap, flags);
FALSE);
meta_window_resize_frame_with_gravity (window, TRUE, new_w, new_h, gravity); meta_window_resize_frame_with_gravity (window, TRUE, new_w, new_h, gravity);
@ -6389,11 +6388,11 @@ maybe_maximize_tiled_window (MetaWindow *window)
void void
meta_window_update_resize (MetaWindow *window, meta_window_update_resize (MetaWindow *window,
gboolean snap, MetaEdgeResistanceFlags flags,
int x, int y, int x, int y,
gboolean force) gboolean force)
{ {
update_resize (window, snap, x, y, force); update_resize (window, flags, x, y, force);
} }
static void static void
@ -6401,6 +6400,7 @@ end_grab_op (MetaWindow *window,
const ClutterEvent *event) const ClutterEvent *event)
{ {
ClutterModifierType modifiers; ClutterModifierType modifiers;
MetaEdgeResistanceFlags last_flags;
gfloat x, y; gfloat x, y;
clutter_event_get_coords (event, &x, &y); clutter_event_get_coords (event, &x, &y);
@ -6413,23 +6413,27 @@ end_grab_op (MetaWindow *window,
* not want a non-snapped movement to occur from the button * not want a non-snapped movement to occur from the button
* release. * release.
*/ */
if (!window->display->grab_last_user_action_was_snap) last_flags = window->display->grab_last_edge_resistance_flags;
if ((last_flags & META_EDGE_RESISTANCE_SNAP) == 0)
{ {
MetaEdgeResistanceFlags flags = META_EDGE_RESISTANCE_DEFAULT;
if (modifiers & CLUTTER_SHIFT_MASK)
flags |= META_EDGE_RESISTANCE_SNAP;
if (meta_grab_op_is_moving (window->display->grab_op)) if (meta_grab_op_is_moving (window->display->grab_op))
{ {
if (window->display->preview_tile_mode != META_TILE_NONE) if (window->display->preview_tile_mode != META_TILE_NONE)
meta_window_tile (window, window->display->preview_tile_mode); meta_window_tile (window, window->display->preview_tile_mode);
else else
update_move (window, update_move (window, flags, x, y);
modifiers & CLUTTER_SHIFT_MASK,
x, y);
} }
else if (meta_grab_op_is_resizing (window->display->grab_op)) else if (meta_grab_op_is_resizing (window->display->grab_op))
{ {
update_resize (window, if (window->tile_match != NULL)
modifiers & CLUTTER_SHIFT_MASK || window->tile_match != NULL, flags |= META_EDGE_RESISTANCE_SNAP;
x, y,
TRUE); update_resize (window, flags, x, y, TRUE);
maybe_maximize_tiled_window (window); maybe_maximize_tiled_window (window);
} }
} }
@ -6443,6 +6447,7 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
{ {
ClutterEventSequence *sequence = clutter_event_get_event_sequence (event); ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
ClutterModifierType modifier_state; ClutterModifierType modifier_state;
MetaEdgeResistanceFlags flags;
gfloat x, y; gfloat x, y;
switch (event->type) switch (event->type)
@ -6493,20 +6498,22 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
case CLUTTER_MOTION: case CLUTTER_MOTION:
modifier_state = clutter_event_get_state (event); modifier_state = clutter_event_get_state (event);
clutter_event_get_coords (event, &x, &y); clutter_event_get_coords (event, &x, &y);
flags = META_EDGE_RESISTANCE_DEFAULT;
if (modifier_state & CLUTTER_SHIFT_MASK)
flags |= META_EDGE_RESISTANCE_SNAP;
meta_display_check_threshold_reached (window->display, x, y); meta_display_check_threshold_reached (window->display, x, y);
if (meta_grab_op_is_moving (window->display->grab_op)) if (meta_grab_op_is_moving (window->display->grab_op))
{ {
update_move (window, update_move (window, flags, x, y);
modifier_state & CLUTTER_SHIFT_MASK,
x, y);
} }
else if (meta_grab_op_is_resizing (window->display->grab_op)) else if (meta_grab_op_is_resizing (window->display->grab_op))
{ {
update_resize (window, if (window->tile_match != NULL)
modifier_state & CLUTTER_SHIFT_MASK || window->tile_match != NULL, flags |= META_EDGE_RESISTANCE_SNAP;
x, y,
FALSE); update_resize (window, flags, x, y, FALSE);
} }
return TRUE; return TRUE;

View File

@ -1226,7 +1226,7 @@ sync_request_timeout (gpointer data)
meta_grab_op_is_resizing (window->display->grab_op)) meta_grab_op_is_resizing (window->display->grab_op))
{ {
meta_window_update_resize (window, meta_window_update_resize (window,
window->display->grab_last_user_action_was_snap, window->display->grab_last_edge_resistance_flags,
window->display->grab_latest_motion_x, window->display->grab_latest_motion_x,
window->display->grab_latest_motion_y, window->display->grab_latest_motion_y,
TRUE); TRUE);
@ -4028,7 +4028,7 @@ meta_window_x11_update_sync_request_counter (MetaWindow *window,
/* This means we are ready for another configure; /* This means we are ready for another configure;
* no pointer round trip here, to keep in sync */ * no pointer round trip here, to keep in sync */
meta_window_update_resize (window, meta_window_update_resize (window,
window->display->grab_last_user_action_was_snap, window->display->grab_last_edge_resistance_flags,
window->display->grab_latest_motion_x, window->display->grab_latest_motion_x,
window->display->grab_latest_motion_y, window->display->grab_latest_motion_y,
TRUE); TRUE);