Skip to content

Commit a28d3eb

Browse files
authored
PiP: restrict selection area to window frame rect (#2432)
1 parent 441c1a6 commit a28d3eb

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

plugins/pip/Main.vala

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,38 @@ public class Gala.Plugins.PIP.Plugin : Gala.Plugin {
7171
private void on_selection_actor_captured (int x, int y, int width, int height) {
7272
clear_selection_area ();
7373

74-
if (width < MIN_SELECTION_SIZE || height < MIN_SELECTION_SIZE) {
74+
var active = get_active_window_actor ();
75+
if (active == null) {
76+
return;
77+
}
78+
79+
var window = active.meta_window;
80+
var buffer_rect = window.get_buffer_rect ();
81+
var frame_rect = window.get_frame_rect ();
82+
83+
Mtk.Rectangle mtk_rect = {x, y, width, height};
84+
Mtk.Rectangle intersection;
85+
mtk_rect.intersect (frame_rect, out intersection);
86+
87+
// Compensate for server-side window decorations
88+
var x_offset = buffer_rect.x - frame_rect.x;
89+
var y_offset = buffer_rect.y - frame_rect.y;
90+
91+
Graphene.Rect rect = {
92+
{intersection.x - buffer_rect.x + x_offset, intersection.y - buffer_rect.y + y_offset},
93+
{intersection.width, intersection.height}
94+
};
95+
96+
if (rect.get_width () < MIN_SELECTION_SIZE || rect.get_height () < MIN_SELECTION_SIZE) {
7597
select_window_at (x, y);
76-
} else {
77-
var active = get_active_window_actor ();
78-
if (active != null) {
79-
int point_x = x - (int)active.x;
80-
int point_y = y - (int)active.y;
81-
82-
// Compensate for server-side window decorations
83-
var input_rect = active.get_meta_window ().get_buffer_rect ();
84-
var outer_rect = active.get_meta_window ().get_frame_rect ();
85-
point_x -= outer_rect.x - input_rect.x;
86-
point_y -= outer_rect.y - input_rect.y;
87-
88-
var rect = Graphene.Rect.alloc ();
89-
rect.init (point_x, point_y, width, height);
90-
91-
var popup_window = new PopupWindow (wm.get_display (), active);
92-
popup_window.set_container_clip (rect);
93-
popup_window.show.connect (on_popup_window_show);
94-
popup_window.hide.connect (on_popup_window_hide);
95-
add_window (popup_window);
96-
}
98+
return;
9799
}
100+
101+
var popup_window = new PopupWindow (wm.get_display (), active);
102+
popup_window.set_container_clip (rect);
103+
popup_window.show.connect (on_popup_window_show);
104+
popup_window.hide.connect (on_popup_window_hide);
105+
add_window (popup_window);
98106
}
99107

100108
private void on_popup_window_show (Clutter.Actor popup_window) {

0 commit comments

Comments
 (0)