Skip to content

Commit 6cfa36b

Browse files
committed
Use more built-in Mtk.Rectangle methods
1 parent 57cf275 commit 6cfa36b

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

plugins/pip/Main.vala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
8+
public const int MIN_SELECTION_SIZE = 100;
9+
810
private Gee.ArrayList<PopupWindow> windows = new Gee.ArrayList<PopupWindow> ();
911
private WindowManager wm;
1012
private SelectionArea? selection_area;
@@ -33,7 +35,7 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
3335
}
3436

3537
var target_frame = target_window.get_frame_rect ();
36-
if (target_frame.width < SelectionArea.MIN_SELECTION || target_frame.height < SelectionArea.MIN_SELECTION) {
38+
if (target_frame.width < MIN_SELECTION_SIZE || target_frame.height < MIN_SELECTION_SIZE) {
3739
return;
3840
}
3941

@@ -52,7 +54,7 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
5254
selection_area.start_selection ();
5355
}
5456

55-
private void on_selection_actor_captured (int x, int y, int width, int height) {
57+
private void on_selection_actor_captured (Mtk.Rectangle selection) {
5658
var popup_window = new PopupWindow (wm.get_display (), selection_area.target_actor);
5759
windows.add (popup_window);
5860
wm.ui_group.add_child (popup_window);
@@ -73,11 +75,12 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
7375
var frame = selection_area.target_actor.meta_window.get_frame_rect ();
7476

7577
// Don't clip if the entire window was selected
76-
if (frame.x != x || frame.y != y || frame.width != width || frame.height != height) {
77-
var point_x = x - frame.x;
78-
var point_y = y - frame.y;
78+
if (!frame.equal (selection)) {
79+
selection.x -= frame.x;
80+
selection.x -= frame.y;
7981

80-
popup_window.set_container_clip ({ { point_x, point_y }, { width, height } });
82+
// FIXME: Mtk.Rectangle.to_graphene_rect is broken in Vala
83+
popup_window.set_container_clip ({ { selection.x, selection.y }, { selection.width, selection.height } });
8184
}
8285

8386
clear_selection_area ();

plugins/pip/SelectionArea.vala

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
*/
77

88
public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
9-
public const int MIN_SELECTION = 100;
10-
119
private const int HANDLER_RADIUS = 6;
1210
private const int BORDER_WIDTH = 2;
1311
private const int RESIZE_THRESHOLD = 10;
1412
private const int CONFIRM_BUTTON_SIZE = 60;
1513

16-
public signal void captured (int x, int y, int width, int height);
14+
public signal void captured (Mtk.Rectangle selection);
1715
public signal void closed ();
1816

1917
public Gala.WindowManager wm { get; construct; }
@@ -34,11 +32,11 @@ public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
3432
/**
3533
* If the user is resizing the selection area and the resize handler used.
3634
*/
37-
private bool resizing = false;
38-
private bool resizing_top = false;
39-
private bool resizing_bottom = false;
40-
private bool resizing_left = false;
41-
private bool resizing_right = false;
35+
private bool resizing = false;
36+
private bool resizing_top = false;
37+
private bool resizing_bottom = false;
38+
private bool resizing_left = false;
39+
private bool resizing_right = false;
4240

4341
/**
4442
* If the user is dragging the selection area and the starting point.
@@ -133,7 +131,7 @@ public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
133131

134132
private void capture_selected_area () {
135133
close ();
136-
captured (selection.x, selection.y, selection.width, selection.height);
134+
captured (selection);
137135
}
138136

139137
public override bool button_press_event (Clutter.Event event) {
@@ -158,7 +156,11 @@ public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
158156
return Clutter.EVENT_STOP;
159157
}
160158

161-
dragging = selection.contains_rect ({ (int) event_x, (int) event_y, 1, 1 });
159+
#if HAS_MUTTER48
160+
dragging = selection.contains_pointf (event_x, event_y);
161+
#else
162+
dragging = selection.contains_rect ({ (int) event_x, (int) event_y, 0, 0 });
163+
#endif
162164
if (dragging) {
163165
drag_x = event_x - selection.x;
164166
drag_y = event_y - selection.y;
@@ -172,9 +174,6 @@ public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
172174
return Clutter.EVENT_STOP;
173175
}
174176

175-
selection.x = (int) event_x;
176-
selection.y = (int) event_y;
177-
178177
return Clutter.EVENT_STOP;
179178
}
180179

@@ -191,7 +190,11 @@ public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
191190
float event_x, event_y;
192191
event.get_coords (out event_x, out event_y);
193192

193+
#if HAS_MUTTER48
194+
if (!resizing && !dragging && !selection.contains_pointf (event_x, event_y)) {
195+
#else
194196
if (!resizing && !dragging && !selection.contains_rect ({ (int) event_x, (int) event_y, 0, 0 })) {
197+
#endif
195198
close ();
196199
closed ();
197200
return true;
@@ -232,25 +235,25 @@ public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
232235
var end_y = selection.y + selection.height;
233236

234237
if (resizing_top) {
235-
start_y = (int) event_y.clamp (max_size.y, end_y - MIN_SELECTION);
238+
start_y = (int) event_y.clamp (max_size.y, end_y - Plugin.MIN_SELECTION_SIZE);
236239
} else if (resizing_bottom) {
237-
end_y = (int) event_y.clamp (start_y + MIN_SELECTION, max_size.y + max_size.height);
240+
end_y = (int) event_y.clamp (start_y + Plugin.MIN_SELECTION_SIZE, max_size.y + max_size.height);
238241
}
239242

240243
if (resizing_left) {
241-
start_x = (int) event_x.clamp (max_size.x, end_x - MIN_SELECTION);
244+
start_x = (int) event_x.clamp (max_size.x, end_x - Plugin.MIN_SELECTION_SIZE);
242245
} else if (resizing_right) {
243-
end_x = (int) event_x.clamp (start_x + MIN_SELECTION, max_size.x + max_size.width);
246+
end_x = (int) event_x.clamp (start_x + Plugin.MIN_SELECTION_SIZE, max_size.x + max_size.width);
244247
}
245248

246249
selection = { start_x, start_y, end_x - start_x, end_y - start_y };
247250

248251
update_confirm_button_position ();
249252
}
250253

251-
private void drag_selection_area (Clutter.Event e) {
254+
private void drag_selection_area (Clutter.Event event) {
252255
float event_x, event_y;
253-
e.get_coords (out event_x, out event_y);
256+
event.get_coords (out event_x, out event_y);
254257

255258
selection.x = (int) (event_x - drag_x).clamp (max_size.x, max_size.x + max_size.width - selection.width);
256259
selection.y = (int) (event_y - drag_y).clamp (max_size.y, max_size.y + max_size.height - selection.height);
@@ -265,13 +268,13 @@ public class Gala.Plugins.PIP.SelectionArea : CanvasActor {
265268
);
266269
}
267270

268-
private void set_mouse_cursor_on_motion (Clutter.Event e) {
271+
private void set_mouse_cursor_on_motion (Clutter.Event event) {
269272
if (resizing || dragging) {
270273
return;
271274
}
272275

273276
float event_x, event_y;
274-
e.get_coords (out event_x, out event_y);
277+
event.get_coords (out event_x, out event_y);
275278

276279
var top = is_close_to_coord (event_y, selection.y, RESIZE_THRESHOLD);
277280
var bottom = is_close_to_coord (event_y, selection.y + selection.height, RESIZE_THRESHOLD);

0 commit comments

Comments
 (0)