Skip to content

Commit

Permalink
Last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmhewitt authored and tintou committed Mar 29, 2023
1 parent 02183ff commit 4eafd31
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/Gestures/GestureTracker.vala
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ public class Gala.GestureTracker : Object {
* values not divisible by physical pixels.
* @returns The linear animation value at the specified percentage.
*/
public static float animation_value (float initial_value, float target_value, double percentage, bool rounded = false) {
public static float animation_value (float initial_value, float target_value, double percentage, float scale, bool rounded = false) {
float value = ((target_value - initial_value) * (float) percentage) + initial_value;

if (rounded) {
value = (float) InternalUtils.pixel_align (value);
value = (float) InternalUtils.pixel_align (value, scale);
}

return value;
Expand Down
6 changes: 3 additions & 3 deletions src/InternalUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ namespace Gala {
break;
case InputArea.NONE:
default:
unowned Meta.X11Display x11display = display.get_x11_display ();
x11display.clear_stage_input_region ();
return;
X.Xrectangle rect = {0, 0, 0, 0};
rects = {rect};
break;
}

unowned Meta.X11Display x11display = display.get_x11_display ();
Expand Down
10 changes: 7 additions & 3 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ namespace Gala {
debug ("Target X: %f", target_x);

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage, true);
var x = GestureTracker.animation_value (initial_x, target_x, percentage, scale, true);

if (is_nudge_animation) {
x = x.clamp (initial_x - nudge_gap, initial_x + nudge_gap);
Expand Down Expand Up @@ -704,6 +704,7 @@ namespace Gala {
continue;

var monitor_geom = display.get_monitor_geometry (monitor);
var monitor_scale = display.get_monitor_scale (monitor);

var window_geom = window.get_frame_rect ();
var top = monitor_geom.y + MAX_OFFSET > window_geom.y;
Expand All @@ -726,7 +727,7 @@ namespace Gala {
};

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var y = GestureTracker.animation_value (initial_y, target_y, percentage);
var y = GestureTracker.animation_value (initial_y, target_y, percentage, monitor_scale);
clone.y = y;
};

Expand Down Expand Up @@ -757,12 +758,15 @@ namespace Gala {
var initial_y = dock.y;
var target_y = dock.source.y;

var monitor = ((SafeWindowClone)dock).window.get_monitor ();
var monitor_scale = display.get_monitor_scale (monitor);

GestureTracker.OnBegin on_animation_begin = () => {
dock.set_easing_duration (0);
};

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var y = GestureTracker.animation_value (initial_y, target_y, percentage);
var y = GestureTracker.animation_value (initial_y, target_y, percentage, monitor_scale);
dock.y = y;
};

Expand Down
20 changes: 10 additions & 10 deletions src/Widgets/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ public class Gala.WindowClone : Clutter.Actor {
place_widgets (outer_rect.width, outer_rect.height, scale);

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage);
var y = GestureTracker.animation_value (initial_y, target_y, percentage);
var width = GestureTracker.animation_value (initial_width, outer_rect.width, percentage);
var height = GestureTracker.animation_value (initial_height, outer_rect.height, percentage);
var opacity = GestureTracker.animation_value (255f, 0f, percentage);
var x = GestureTracker.animation_value (initial_x, target_x, percentage, scale);
var y = GestureTracker.animation_value (initial_y, target_y, percentage, scale);
var width = GestureTracker.animation_value (initial_width, outer_rect.width, percentage, scale);
var height = GestureTracker.animation_value (initial_height, outer_rect.height, percentage, scale);
var opacity = GestureTracker.animation_value (255f, 0f, percentage, scale);

set_size (width, height);
set_position (x, y);
Expand Down Expand Up @@ -357,11 +357,11 @@ public class Gala.WindowClone : Clutter.Actor {
place_widgets (rect.width, rect.height, scale);

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, rect.x, percentage);
var y = GestureTracker.animation_value (initial_y, rect.y, percentage);
var width = GestureTracker.animation_value (initial_width, rect.width, percentage);
var height = GestureTracker.animation_value (initial_height, rect.height, percentage);
var opacity = GestureTracker.animation_value (0f, 255f, percentage);
var x = GestureTracker.animation_value (initial_x, rect.x, percentage, scale);
var y = GestureTracker.animation_value (initial_y, rect.y, percentage, scale);
var width = GestureTracker.animation_value (initial_width, rect.width, percentage, scale);
var height = GestureTracker.animation_value (initial_height, rect.height, percentage, scale);
var opacity = GestureTracker.animation_value (0f, 255f, percentage, scale);

set_size (width, height);
set_position (x, y);
Expand Down
5 changes: 4 additions & 1 deletion src/Widgets/WindowCloneContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,13 @@ namespace Gala {

var window_positions = InternalUtils.calculate_grid_placement (area, windows);

unowned var display = wm.get_display ();
var scale = display.get_monitor_scale (display.get_primary_monitor ());

foreach (var tilable in window_positions) {
unowned var clone = (WindowClone) tilable.id;
clone.take_slot (tilable.rect, with_gesture, is_cancel_animation);
clone.place_widgets (tilable.rect.width, tilable.rect.height);
clone.place_widgets (tilable.rect.width, tilable.rect.height, scale);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Widgets/WindowIconActor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace Gala {
public class WindowIconActor : Clutter.Actor {
public Meta.Window window { get; construct; }

private int icon_scale;
private float cur_icon_scale = 1.0f;
private float desired_icon_scale = 1.0f;

Expand Down
15 changes: 9 additions & 6 deletions src/Widgets/WorkspaceClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ namespace Gala {

window_container.restack_windows ();
var display = workspace.get_display ();

var scale_factor = display.get_monitor_scale (display.get_primary_monitor ());

var monitor = display.get_monitor_geometry (display.get_primary_monitor ());
Expand All @@ -358,10 +357,10 @@ namespace Gala {
};

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage);
var x = GestureTracker.animation_value (initial_x, target_x, percentage, scale_factor);
set_x (x);

double update_scale = (double) GestureTracker.animation_value (1.0f, (float)scale, percentage);
double update_scale = (double) GestureTracker.animation_value (1.0f, (float)scale, percentage, scale_factor);
background.set_scale (update_scale, update_scale);
};

Expand Down Expand Up @@ -428,12 +427,16 @@ namespace Gala {
double initial_scale_x, initial_scale_y;
background.get_scale (out initial_scale_x, out initial_scale_y);


var display = workspace.get_display ();
var scale_factor = display.get_monitor_scale (display.get_primary_monitor ());

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage);
var x = GestureTracker.animation_value (initial_x, target_x, percentage, scale_factor);
set_x (x);

double scale_x = (double) GestureTracker.animation_value ((float) initial_scale_x, 1.0f, percentage);
double scale_y = (double) GestureTracker.animation_value ((float) initial_scale_y, 1.0f, percentage);
double scale_x = (double) GestureTracker.animation_value ((float) initial_scale_x, 1.0f, percentage, scale_factor);
double scale_y = (double) GestureTracker.animation_value ((float) initial_scale_y, 1.0f, percentage, scale_factor);
background.set_scale (scale_x, scale_y);
};

Expand Down
23 changes: 12 additions & 11 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ namespace Gala {
}

animating_switch_workspace = true;
var nudge_gap = NUDGE_GAP * InternalUtils.get_ui_scaling_factor ();
var scale = get_display ().get_monitor_scale (get_display ().get_primary_monitor ());
var nudge_gap = InternalUtils.scale_to_int ((int)NUDGE_GAP, scale);

float dest = 0;
if (!switch_workspace_with_gesture) {
Expand All @@ -548,7 +549,7 @@ namespace Gala {
}

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (0.0f, dest, percentage, true);
var x = GestureTracker.animation_value (0.0f, dest, percentage, scale, true);
ui_group.x = x.clamp (-nudge_gap, nudge_gap);
};

Expand Down Expand Up @@ -731,7 +732,6 @@ namespace Gala {

unowned Meta.Display display = get_display ();

update_input_area ();
proxy.grab = stage.grab (actor);

if (modal_stack.size == 1) {
Expand Down Expand Up @@ -1144,11 +1144,11 @@ namespace Gala {
Meta.Rectangle icon = {};
if (actor.get_meta_window ().get_icon_geometry (out icon)) {
// Fix icon position and size according to ui scaling factor.
int ui_scale = InternalUtils.get_ui_scaling_factor ();
icon.x *= ui_scale;
icon.y *= ui_scale;
icon.width *= ui_scale;
icon.height *= ui_scale;
float ui_scale = get_display ().get_monitor_scale (get_display ().get_monitor_index_for_rect (icon));
icon.x = InternalUtils.scale_to_int (icon.x, ui_scale);
icon.y = InternalUtils.scale_to_int (icon.y, ui_scale);
icon.width = InternalUtils.scale_to_int (icon.width, ui_scale);
icon.height = InternalUtils.scale_to_int (icon.height, ui_scale);

float scale_x = (float)icon.width / actor.width;
float scale_y = (float)icon.height / actor.height;
Expand Down Expand Up @@ -1921,8 +1921,9 @@ namespace Gala {
main_container.width = move_primary_only ? monitor_geom.width : screen_width;
main_container.height = move_primary_only ? monitor_geom.height : screen_height;

var monitor_scale = display.get_monitor_scale (primary);
var x2 = move_primary_only ? monitor_geom.width : screen_width;
x2 += WORKSPACE_GAP * InternalUtils.get_ui_scaling_factor ();
x2 += WORKSPACE_GAP * monitor_scale;
if (direction == Meta.MotionDirection.RIGHT)
x2 = -x2;

Expand All @@ -1949,8 +1950,8 @@ namespace Gala {
var animation_mode = Clutter.AnimationMode.EASE_OUT_CUBIC;

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x_out = GestureTracker.animation_value (0.0f, x2, percentage, true);
var x_in = GestureTracker.animation_value (-x2, 0.0f, percentage, true);
var x_out = GestureTracker.animation_value (0.0f, x2, percentage, monitor_scale, true);
var x_in = GestureTracker.animation_value (-x2, 0.0f, percentage, monitor_scale, true);

out_group.x = x_out;
in_group.x = x_in;
Expand Down
5 changes: 4 additions & 1 deletion src/Zoom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ public class Gala.Zoom : Object {
}

private void zoom_with_gesture (GestureDirection direction) {
unowned var display = wm.get_display ();
var scale = display.get_monitor_scale (display.get_current_monitor ());

var initial_zoom = current_zoom;
var target_zoom = (direction == GestureDirection.IN)
? initial_zoom - MAX_ZOOM
: initial_zoom + MAX_ZOOM;

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var zoom_level = GestureTracker.animation_value (initial_zoom, target_zoom, percentage);
var zoom_level = GestureTracker.animation_value (initial_zoom, target_zoom, percentage, scale);
var delta = zoom_level - current_zoom;

if (!wm.enable_animations) {
Expand Down
2 changes: 2 additions & 0 deletions vapi/libmutter.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,9 @@ namespace Meta {
public sealed class X11Display : GLib.Object {
[CCode (has_construct_function = false)]
protected X11Display ();
#if !HAS_MUTTER44
public void clear_stage_input_region ();
#endif
[CCode (cheader_filename = "meta/meta-x11-errors.h", cname = "meta_x11_error_trap_pop")]
public void error_trap_pop ();
[CCode (cheader_filename = "meta/meta-x11-errors.h", cname = "meta_x11_error_trap_pop_with_return")]
Expand Down

0 comments on commit 4eafd31

Please sign in to comment.