Skip to content

Commit

Permalink
Avoid to use Gdk constants when Clutter should be used
Browse files Browse the repository at this point in the history
Also avoid to use Gdk.Display when we have already everything from Mutter.
  • Loading branch information
tintou committed Mar 29, 2023
1 parent e9d5370 commit da21971
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 131 deletions.
24 changes: 12 additions & 12 deletions lib/DragDropAction.vala
Expand Up @@ -187,13 +187,13 @@ namespace Gala {

public override bool handle_event (Event event) {
if (!(DragDropActionType.SOURCE in drag_type)) {
return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

switch (event.get_type ()) {
case EventType.BUTTON_PRESS:
if (grabbed_actor != null) {
return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

grab_actor (actor, event.get_device ());
Expand All @@ -205,7 +205,7 @@ namespace Gala {
last_x = x;
last_y = y;

return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;

case EventType.BUTTON_RELEASE:
if (!dragging) {
Expand All @@ -221,15 +221,15 @@ namespace Gala {
ungrab_actor ();
clicked = false;
dragging = false;
return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
} else if (dragging) {
if (hovered != null) {
finish ();
} else {
cancel ();
}

return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
}
break;

Expand Down Expand Up @@ -273,7 +273,7 @@ namespace Gala {
if (grabbed_device != null &&
device != grabbed_device &&
device.get_device_type () != InputDeviceType.KEYBOARD_DEVICE) {
return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

switch (event.get_type ()) {
Expand All @@ -293,7 +293,7 @@ namespace Gala {
if (handle == null) {
ungrab_actor ();
critical ("No handle has been returned by the started signal, aborting drag.");
return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

clicked = false;
Expand All @@ -317,7 +317,7 @@ namespace Gala {
}
}
}
return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
} else if (dragging) {
handle.x -= last_x - x;
handle.y -= last_y - y;
Expand All @@ -337,7 +337,7 @@ namespace Gala {

// didn't change, no need to do anything
if (actor == hovered)
return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;

if (action == null) {
// apparently we left ours if we had one before
Expand All @@ -346,7 +346,7 @@ namespace Gala {
hovered = null;
}

return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
}

// signal the previous one that we left it
Expand All @@ -358,15 +358,15 @@ namespace Gala {
hovered = actor;
emit_crossed (hovered, true);

return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
}

break;
default:
break;
}

return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

/**
Expand Down
32 changes: 15 additions & 17 deletions plugins/pip/PopupWindow.vala
Expand Up @@ -55,10 +55,6 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
|| window_type == Meta.WindowType.MODAL_DIALOG;
}

private static void get_current_cursor_position (out int x, out int y) {
Gdk.Display.get_default ().get_default_seat ().get_pointer ().get_position (null, out x, out y);
}

public PopupWindow (Gala.WindowManager wm, Meta.WindowActor window_actor) {
Object (wm: wm, window_actor: window_actor);
}
Expand Down Expand Up @@ -180,7 +176,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
resize_button.opacity = 255;
resize_button.restore_easing_state ();

return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

public override bool leave_event (Clutter.CrossingEvent event) {
Expand All @@ -196,7 +192,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
resize_button.opacity = 0;
resize_button.restore_easing_state ();

return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

public void set_container_clip (Graphene.Rect? container_clip) {
Expand All @@ -217,40 +213,42 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {

private bool on_resize_button_press (Clutter.ButtonEvent event) {
if (resizing || event.button != 1) {
return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
}

resizing = true;

get_current_cursor_position (out resize_start_x, out resize_start_y);

Graphene.Point coords;
Clutter.ModifierType mods;
resize_start_x = event.x;
resize_start_x = event.y;

begin_resize_width = width;
begin_resize_height = height;

grab = resize_button.get_stage ().grab (resize_button);
resize_button.event.connect (on_resize_event);

return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

private bool on_resize_event (Clutter.Event event) {
if (!resizing) {
return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
}

switch (event.get_type ()) {
case Clutter.EventType.MOTION:
unowned var motion_event = (Clutter.MotionEvent) event;
var mods = event.get_state ();
if (!(Clutter.ModifierType.BUTTON1_MASK in mods)) {
stop_resizing ();
break;
}

int motion_x, motion_y;
get_current_cursor_position (out motion_x, out motion_y);

float diff_x = motion_x - resize_start_x;
float diff_y = motion_y - resize_start_y;
float diff_x = motion_event.x - resize_start_x;
float diff_y = motion_event.y - resize_start_y;

width = begin_resize_width + diff_x;
height = begin_resize_height + diff_y;
Expand All @@ -268,12 +266,12 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
break;
case Clutter.EventType.LEAVE:
case Clutter.EventType.ENTER:
return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
default:
break;
}

return Gdk.EVENT_STOP;
return Clutter.EVENT_STOP;
}

private void stop_resizing () {
Expand Down
2 changes: 1 addition & 1 deletion src/Background/BackgroundContainer.vala
Expand Up @@ -31,7 +31,7 @@ namespace Gala {

reactive = true;
button_release_event.connect ((event) => {
if (event.button == Gdk.BUTTON_SECONDARY) {
if (event.button == Clutter.Button.SECONDARY) {
show_background_menu ((int)event.x, (int)event.y);
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/Gestures/Gesture.vala
Expand Up @@ -35,9 +35,9 @@ namespace Gala {
}

public class Gesture {
public Gdk.EventType type;
public Clutter.EventType type;
public GestureDirection direction;
public int fingers;
public Gdk.InputSource performed_on_device_type;
public Clutter.InputDeviceType performed_on_device_type;
}
}
4 changes: 2 additions & 2 deletions src/Gestures/GestureSettings.vala
Expand Up @@ -28,8 +28,8 @@ public class Gala.GestureSettings : Object {
touchpad_settings = new GLib.Settings ("org.gnome.desktop.peripherals.touchpad");
}

public bool is_natural_scroll_enabled (Gdk.InputSource device_type) {
return (device_type == Gdk.InputSource.TOUCHSCREEN)
public bool is_natural_scroll_enabled (Clutter.InputDeviceType device_type) {
return (device_type == Clutter.InputDeviceType.TOUCHSCREEN_DEVICE)
? true
: touchpad_settings.get_boolean ("natural-scroll");
}
Expand Down
6 changes: 3 additions & 3 deletions src/Gestures/ScrollBackend.vala
Expand Up @@ -65,7 +65,7 @@ public class Gala.ScrollBackend : Object {
// Scroll events apply the natural scroll preferences out of the box
// Standardize them so the direction matches the physical direction of the gesture and the
// GestureTracker user can decide if it wants to follow natural scroll settings or not
bool natural_scroll = settings.is_natural_scroll_enabled (Gdk.InputSource.TOUCHPAD);
bool natural_scroll = settings.is_natural_scroll_enabled (Clutter.InputDeviceType.TOUCHPAD_DEVICE);
if (natural_scroll) {
x *= -1;
y *= -1;
Expand Down Expand Up @@ -115,10 +115,10 @@ public class Gala.ScrollBackend : Object {
}

return new Gesture () {
type = Gdk.EventType.SCROLL,
type = Clutter.EventType.SCROLL,
direction = direction,
fingers = 2,
performed_on_device_type = Gdk.InputSource.TOUCHPAD
performed_on_device_type = Clutter.InputDeviceType.TOUCHPAD_DEVICE
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/Gestures/ToucheggBackend.vala
Expand Up @@ -225,25 +225,25 @@ public class Gala.ToucheggBackend : Object {
}

private static Gesture? make_gesture (GestureType type, GestureDirection direction, int fingers, DeviceType performed_on_device_type) {
Gdk.EventType event_type;
Clutter.EventType event_type;
switch (type) {
case GestureType.SWIPE:
event_type = Gdk.EventType.TOUCHPAD_SWIPE;
event_type = Clutter.EventType.TOUCHPAD_SWIPE;
break;
case GestureType.PINCH:
event_type = Gdk.EventType.TOUCHPAD_PINCH;
event_type = Clutter.EventType.TOUCHPAD_PINCH;
break;
default:
return null;
}

Gdk.InputSource input_source;
Clutter.InputDeviceType input_source;
switch (performed_on_device_type) {
case DeviceType.TOUCHPAD:
input_source = Gdk.InputSource.TOUCHPAD;
input_source = Clutter.InputDeviceType.TOUCHPAD_DEVICE;
break;
case DeviceType.TOUCHSCREEN:
input_source = Gdk.InputSource.TOUCHSCREEN;
input_source = Clutter.InputDeviceType.TOUCHSCREEN_DEVICE;
break;
default:
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/InternalUtils.vala
Expand Up @@ -192,7 +192,7 @@ namespace Gala {

public struct TilableWindow {
Meta.Rectangle rect;
void *id;
unowned WindowClone id;
}

public static List<TilableWindow?> calculate_grid_placement (Meta.Rectangle area, List<TilableWindow?> windows) {
Expand Down
17 changes: 12 additions & 5 deletions src/ScreenshotManager.vala
Expand Up @@ -175,7 +175,11 @@ namespace Gala {
}

yield wait_stage_repaint ();
selection_area.get_selection_rectangle (out x, out y, out width, out height);
var rect = selection_area.get_selection_rectangle ();
x = (int) GLib.Math.roundf (rect.origin.x);
y = (int) GLib.Math.roundf (rect.origin.y);
width = (int) GLib.Math.roundf (rect.size.width);
height = (int) GLib.Math.roundf (rect.size.height);
}

private void unconceal_text () {
Expand Down Expand Up @@ -223,10 +227,13 @@ namespace Gala {
throw new GLib.IOError.CANCELLED ("Operation was cancelled");
}

int x = 0, y = 0;
pixel_picker.get_point (out x, out y);

var image = take_screenshot (x, y, 1, 1, false);
var picker_point = pixel_picker.point;
var image = take_screenshot (
(int) GLib.Math.roundf (picker_point.x),
(int) GLib.Math.roundf (picker_point.y),
1, 1,
false
);

assert (image.get_format () == Cairo.Format.ARGB32);

Expand Down
6 changes: 3 additions & 3 deletions src/Widgets/IconGroup.vala
Expand Up @@ -111,7 +111,7 @@ namespace Gala {

// block propagation of button presses on the close button, otherwise
// the click action on the icon group will act weirdly
close_button.button_release_event.connect (() => { return Gdk.EVENT_STOP; });
close_button.button_release_event.connect (() => { return Clutter.EVENT_STOP; });

add_child (close_button);

Expand All @@ -129,15 +129,15 @@ namespace Gala {
public override bool enter_event (Clutter.CrossingEvent event) {
toggle_close_button (true);

return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

public override bool leave_event (Clutter.CrossingEvent event) {
if (!contains (event.related)) {
toggle_close_button (false);
}

return Gdk.EVENT_PROPAGATE;
return Clutter.EVENT_PROPAGATE;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Widgets/MultitaskingView.vala
Expand Up @@ -235,7 +235,7 @@ namespace Gala {
}

private void on_multitasking_gesture_detected (Gesture gesture) {
if (gesture.type != Gdk.EventType.TOUCHPAD_SWIPE ||
if (gesture.type != Clutter.EventType.TOUCHPAD_SWIPE ||
(gesture.fingers == 3 && GestureSettings.get_string ("three-finger-swipe-up") != "multitasking-view") ||
(gesture.fingers == 4 && GestureSettings.get_string ("four-finger-swipe-up") != "multitasking-view")
) {
Expand All @@ -254,13 +254,13 @@ namespace Gala {
return;
}

var can_handle_swipe = gesture.type == Gdk.EventType.TOUCHPAD_SWIPE &&
var can_handle_swipe = gesture.type == Clutter.EventType.TOUCHPAD_SWIPE &&
(gesture.direction == GestureDirection.LEFT || gesture.direction == GestureDirection.RIGHT);

var fingers = (gesture.fingers == 3 && Gala.GestureSettings.get_string ("three-finger-swipe-horizontal") == "switch-to-workspace") ||
(gesture.fingers == 4 && Gala.GestureSettings.get_string ("four-finger-swipe-horizontal") == "switch-to-workspace");

if (gesture.type == Gdk.EventType.SCROLL || (can_handle_swipe && fingers)) {
if (gesture.type == Clutter.EventType.SCROLL || (can_handle_swipe && fingers)) {
var direction = workspace_gesture_tracker.settings.get_natural_scroll_direction (gesture);
switch_workspace_with_gesture (direction);
}
Expand Down

0 comments on commit da21971

Please sign in to comment.