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. */
int64_t grab_last_moveresize_time;
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;

View File

@ -1903,7 +1903,7 @@ meta_display_begin_grab_op (MetaDisplay *display,
display->grab_latest_motion_x = root_x;
display->grab_latest_motion_y = root_y;
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;
meta_display_update_cursor (display);

View File

@ -542,14 +542,17 @@ apply_edge_resistance_to_each_side (MetaDisplay *display,
const MetaRectangle *old_outer,
MetaRectangle *new_outer,
GSourceFunc timeout_func,
gboolean auto_snap,
gboolean keyboard_op,
MetaEdgeResistanceFlags flags,
gboolean is_resize)
{
MetaEdgeResistanceData *edge_data;
MetaRectangle modified_rect;
gboolean modified;
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)
compute_resistance_and_snapping_edges (display);
@ -1178,11 +1181,11 @@ meta_window_edge_resistance_for_move (MetaWindow *window,
int *new_x,
int *new_y,
GSourceFunc timeout_func,
gboolean snap,
gboolean is_keyboard_op)
MetaEdgeResistanceFlags flags)
{
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);
@ -1191,15 +1194,18 @@ meta_window_edge_resistance_for_move (MetaWindow *window,
proposed_outer.y = *new_y;
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;
if (apply_edge_resistance_to_each_side (window->display,
window,
&old_outer,
&new_outer,
timeout_func,
snap,
is_keyboard_op,
flags,
is_resize))
{
/* apply_edge_resistance_to_each_side independently applies
@ -1257,10 +1263,10 @@ meta_window_edge_resistance_for_resize (MetaWindow *window,
int *new_height,
MetaGravity gravity,
GSourceFunc timeout_func,
gboolean snap,
gboolean is_keyboard_op)
MetaEdgeResistanceFlags flags)
{
MetaRectangle old_outer, new_outer;
MetaEdgeResistanceFlags saved_flags;
int proposed_outer_width, proposed_outer_height;
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_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,
window,
&old_outer,
&new_outer,
timeout_func,
snap,
is_keyboard_op,
flags,
TRUE))
{
*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_y,
GSourceFunc timeout_func,
gboolean snap,
gboolean is_keyboard_op);
MetaEdgeResistanceFlags flags);
void meta_window_edge_resistance_for_resize (MetaWindow *window,
int *new_width,
int *new_height,
MetaGravity gravity,
GSourceFunc timeout_func,
gboolean snap,
gboolean is_keyboard_op);
MetaEdgeResistanceFlags flags);
#endif /* META_EDGE_RESISTANCE_H */

View File

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

View File

@ -157,6 +157,13 @@ typedef enum
META_EDGE_CONSTRAINT_MONITOR = 2,
} MetaEdgeConstraint;
typedef enum
{
META_EDGE_RESISTANCE_DEFAULT = 0,
META_EDGE_RESISTANCE_SNAP = 1 << 0,
META_EDGE_RESISTANCE_KEYBOARD_OP = 1 << 1,
} MetaEdgeResistanceFlags;
struct _MetaWindow
{
GObject parent_instance;
@ -843,7 +850,7 @@ void meta_window_set_urgent (MetaWindow *window,
gboolean urgent);
void meta_window_update_resize (MetaWindow *window,
gboolean snap,
MetaEdgeResistanceFlags flags,
int x, int y,
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 update_move (MetaWindow *window,
gboolean snap,
MetaEdgeResistanceFlags flags,
int x,
int y);
static gboolean update_move_timeout (gpointer data);
static void update_resize (MetaWindow *window,
gboolean snap,
MetaEdgeResistanceFlags flags,
int x,
int y,
gboolean force);
@ -5980,7 +5980,7 @@ update_move_timeout (gpointer data)
MetaWindow *window = data;
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_y);
@ -6044,7 +6044,7 @@ update_move_maybe_tile (MetaWindow *window,
static void
update_move (MetaWindow *window,
gboolean snap,
MetaEdgeResistanceFlags flags,
int x,
int y)
{
@ -6086,7 +6086,7 @@ update_move (MetaWindow *window,
shake_threshold = meta_prefs_get_drag_threshold () *
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
request. */
@ -6222,8 +6222,7 @@ update_move (MetaWindow *window,
&new_x,
&new_y,
update_move_timeout,
snap,
FALSE);
flags);
meta_window_move_frame (window, TRUE, new_x, new_y);
}
@ -6234,7 +6233,7 @@ update_resize_timeout (gpointer data)
MetaWindow *window = data;
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_y,
TRUE);
@ -6243,8 +6242,9 @@ update_resize_timeout (gpointer data)
static void
update_resize (MetaWindow *window,
gboolean snap,
int x, int y,
MetaEdgeResistanceFlags flags,
int x,
int y,
gboolean force)
{
int dx, dy;
@ -6359,8 +6359,7 @@ update_resize (MetaWindow *window,
&new_h,
gravity,
update_resize_timeout,
snap,
FALSE);
flags);
meta_window_resize_frame_with_gravity (window, TRUE, new_w, new_h, gravity);
@ -6389,11 +6388,11 @@ maybe_maximize_tiled_window (MetaWindow *window)
void
meta_window_update_resize (MetaWindow *window,
gboolean snap,
MetaEdgeResistanceFlags flags,
int x, int y,
gboolean force)
{
update_resize (window, snap, x, y, force);
update_resize (window, flags, x, y, force);
}
static void
@ -6401,6 +6400,7 @@ end_grab_op (MetaWindow *window,
const ClutterEvent *event)
{
ClutterModifierType modifiers;
MetaEdgeResistanceFlags last_flags;
gfloat 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
* 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 (window->display->preview_tile_mode != META_TILE_NONE)
meta_window_tile (window, window->display->preview_tile_mode);
else
update_move (window,
modifiers & CLUTTER_SHIFT_MASK,
x, y);
update_move (window, flags, x, y);
}
else if (meta_grab_op_is_resizing (window->display->grab_op))
{
update_resize (window,
modifiers & CLUTTER_SHIFT_MASK || window->tile_match != NULL,
x, y,
TRUE);
if (window->tile_match != NULL)
flags |= META_EDGE_RESISTANCE_SNAP;
update_resize (window, flags, x, y, TRUE);
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);
ClutterModifierType modifier_state;
MetaEdgeResistanceFlags flags;
gfloat x, y;
switch (event->type)
@ -6493,20 +6498,22 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
case CLUTTER_MOTION:
modifier_state = clutter_event_get_state (event);
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);
if (meta_grab_op_is_moving (window->display->grab_op))
{
update_move (window,
modifier_state & CLUTTER_SHIFT_MASK,
x, y);
update_move (window, flags, x, y);
}
else if (meta_grab_op_is_resizing (window->display->grab_op))
{
update_resize (window,
modifier_state & CLUTTER_SHIFT_MASK || window->tile_match != NULL,
x, y,
FALSE);
if (window->tile_match != NULL)
flags |= META_EDGE_RESISTANCE_SNAP;
update_resize (window, flags, x, y, FALSE);
}
return TRUE;

View File

@ -1226,7 +1226,7 @@ sync_request_timeout (gpointer data)
meta_grab_op_is_resizing (window->display->grab_op))
{
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_y,
TRUE);
@ -4028,7 +4028,7 @@ meta_window_x11_update_sync_request_counter (MetaWindow *window,
/* This means we are ready for another configure;
* no pointer round trip here, to keep in sync */
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_y,
TRUE);