mirror of
https://github.com/elementary/gala.git
synced 2024-09-11 15:15:39 +03:00
pip: Add multi-monitor support to off screen window
Avoid placing the window off screen when it is actually in a different monitor.
This commit is contained in:
parent
89e13c03d9
commit
143eb26d20
@ -430,13 +430,15 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
|
||||
var off_screen_x_threshold = width * OFF_SCREEN_PERCENT;
|
||||
|
||||
var off_screen_x = (x - monitor_x) < -off_screen_x_threshold;
|
||||
if (off_screen_x) {
|
||||
if (off_screen_x
|
||||
&& !coord_is_in_other_monitor (x, Clutter.Orientation.HORIZONTAL)) {
|
||||
off_screen = true;
|
||||
x = monitor_x - width + OFF_SCREEN_VISIBLE_PIXELS;
|
||||
}
|
||||
|
||||
var off_screen_w = (x + width) > (monitor_x + monitor_width + off_screen_x_threshold);
|
||||
if (off_screen_w) {
|
||||
if (off_screen_w
|
||||
&& !coord_is_in_other_monitor (x + width, Clutter.Orientation.HORIZONTAL)) {
|
||||
off_screen = true;
|
||||
x = monitor_x + monitor_width - OFF_SCREEN_VISIBLE_PIXELS;
|
||||
}
|
||||
@ -445,13 +447,15 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
|
||||
var off_screen_y_threshold = height * OFF_SCREEN_PERCENT;
|
||||
|
||||
var off_screen_y = (y - monitor_y) < -off_screen_y_threshold;
|
||||
if (off_screen_y) {
|
||||
if (off_screen_y
|
||||
&& !coord_is_in_other_monitor (y, Clutter.Orientation.VERTICAL)) {
|
||||
off_screen = true;
|
||||
y = monitor_y - height + OFF_SCREEN_VISIBLE_PIXELS;
|
||||
}
|
||||
|
||||
var off_screen_h = (y + height) > (monitor_y + monitor_height + off_screen_y_threshold);
|
||||
if (off_screen_h) {
|
||||
if (off_screen_h
|
||||
&& !coord_is_in_other_monitor (y + height, Clutter.Orientation.VERTICAL)) {
|
||||
off_screen = true;
|
||||
y = monitor_y + monitor_height - OFF_SCREEN_VISIBLE_PIXELS;
|
||||
}
|
||||
@ -461,6 +465,35 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
|
||||
return off_screen;
|
||||
}
|
||||
|
||||
private bool coord_is_in_other_monitor (float coord, Clutter.Orientation axis) {
|
||||
var display = wm.get_display ();
|
||||
int n_monitors = display.get_n_monitors ();
|
||||
|
||||
if (n_monitors == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int current = display.get_current_monitor ();
|
||||
for (int i = 0; i < n_monitors; i++) {
|
||||
if (i != current) {
|
||||
var monitor_rect = display.get_monitor_geometry (i);
|
||||
bool in_monitor = false;
|
||||
|
||||
if (axis == Clutter.Orientation.HORIZONTAL) {
|
||||
in_monitor = (coord >= monitor_rect.x) && (coord <= monitor_rect.x + monitor_rect.width);
|
||||
} else {
|
||||
in_monitor = (coord >= monitor_rect.y) && (coord <= monitor_rect.y + monitor_rect.height);
|
||||
}
|
||||
|
||||
if (in_monitor) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void reposition_resize_button () {
|
||||
resize_button.set_position (width - button_size, height - button_size);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user