Skip to content

Commit

Permalink
WindowSwitcher: Improve mouse handling (#1836)
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 authored Jan 28, 2024
1 parent 6e50184 commit c25770e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
45 changes: 14 additions & 31 deletions src/Widgets/WindowSwitcher/WindowSwitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public class Gala.WindowSwitcher : Clutter.Actor {
};

container.button_release_event.connect (container_mouse_release);
container.motion_event.connect (container_motion_event);

var caption_color = "#2e2e31";

Expand Down Expand Up @@ -292,7 +291,7 @@ public class Gala.WindowSwitcher : Clutter.Actor {
current_icon = icon;
}

container.add_child (icon);
add_icon (icon);
}

return true;
Expand Down Expand Up @@ -322,13 +321,25 @@ public class Gala.WindowSwitcher : Clutter.Actor {
current_icon = icon;
}

container.add_child (icon);
add_icon (icon);
}
}

return true;
}

private void add_icon (WindowSwitcherIcon icon) {
container.add_child (icon);

icon.motion_event.connect (() => {
if (current_icon != icon && !handling_gesture) {
current_icon = icon;
}

return Clutter.EVENT_PROPAGATE;
});
}

private void open_switcher () {
if (container.get_n_children () == 0) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
Expand Down Expand Up @@ -484,34 +495,6 @@ public class Gala.WindowSwitcher : Clutter.Actor {
}
}

#if HAS_MUTTER45
private bool container_motion_event (Clutter.Event event) {
#else
private bool container_motion_event (Clutter.MotionEvent event) {
#endif
if (handling_gesture) {
return Clutter.EVENT_STOP;
}

float x, y;
event.get_coords (out x, out y);
var actor = container.get_stage ().get_actor_at_pos (Clutter.PickMode.ALL, (int)x, (int)y);
if (actor == null) {
return Clutter.EVENT_STOP;
}

var selected = actor as WindowSwitcherIcon;
if (selected == null) {
return Clutter.EVENT_STOP;
}

if (current_icon != selected) {
current_icon = selected;
}

return true;
}

#if HAS_MUTTER45
private bool container_mouse_release (Clutter.Event event) {
#else
Expand Down
2 changes: 2 additions & 0 deletions src/Widgets/WindowSwitcher/WindowSwitcherIcon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class Gala.WindowSwitcherIcon : Clutter.Actor {
canvas.draw.connect (draw_background);
set_content (canvas);

reactive = true;

this.scale_factor = scale_factor;
}

Expand Down

0 comments on commit c25770e

Please sign in to comment.