Skip to content

Commit

Permalink
Merge branch 'master' into pip-mask
Browse files Browse the repository at this point in the history
  • Loading branch information
cassidyjames authored Aug 25, 2021
2 parents 468d4ea + bb79f62 commit 0ca2f56
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 71 deletions.
12 changes: 12 additions & 0 deletions data/gala.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
<p>A window &amp; compositing manager based on libmutter and designed by elementary for use with Pantheon.</p>
</description>
<releases>
<release version="6.2.0" date="2020-08-24" urgency="medium">
<description>
<p>New features:</p>
<ul>
<li>Stash the picture-in-picture window by pushing it off screen</li>
</ul>
<p>Improvements:</p>
<ul>
<li>Updated translations</li>
</ul>
</description>
</release>
<release version="6.0.1" date="2020-08-11" urgency="medium">
<description>
<p>Improvements:</p>
Expand Down
100 changes: 98 additions & 2 deletions plugins/pip/PopupWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
private const float MINIMUM_SCALE = 0.1f;
private const float MAXIMUM_SCALE = 1.0f;
private const int SCREEN_MARGIN = 0;
private const float OFF_SCREEN_PERCENT = 0.5f;
private const int OFF_SCREEN_VISIBLE_PIXELS = 80;

public signal void closed ();

Expand All @@ -44,6 +46,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
private float resize_start_y = 0.0f;

private bool resizing = false;
private bool off_screen = false;

static unowned Meta.Window? previous_focus = null;

Expand Down Expand Up @@ -379,6 +382,14 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
}

private void update_screen_position () {
if (!place_window_off_screen ()) {
place_window_in_screen ();
}
}

private void place_window_in_screen () {
off_screen = false;

Meta.Rectangle monitor_rect;
get_current_monitor_rect (out monitor_rect);

Expand All @@ -404,6 +415,87 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
set_easing_duration (0);
}

private bool place_window_off_screen () {
off_screen = false;
set_easing_duration (300);
set_easing_mode (Clutter.AnimationMode.EASE_OUT_BACK);

Meta.Rectangle monitor_rect;
get_current_monitor_rect (out monitor_rect);

int monitor_x = monitor_rect.x;
int monitor_y = monitor_rect.y;
int monitor_width = monitor_rect.width;
int monitor_height = monitor_rect.height;

// X axis off screen
var off_screen_x_threshold = width * OFF_SCREEN_PERCENT;

var off_screen_x = (x - monitor_x) < -off_screen_x_threshold;
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
&& !coord_is_in_other_monitor (x + width, Clutter.Orientation.HORIZONTAL)) {
off_screen = true;
x = monitor_x + monitor_width - OFF_SCREEN_VISIBLE_PIXELS;
}

// Y axis off screen
var off_screen_y_threshold = height * OFF_SCREEN_PERCENT;

var off_screen_y = (y - monitor_y) < -off_screen_y_threshold;
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
&& !coord_is_in_other_monitor (y + height, Clutter.Orientation.VERTICAL)) {
off_screen = true;
y = monitor_y + monitor_height - OFF_SCREEN_VISIBLE_PIXELS;
}

set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
set_easing_duration (0);
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);
}
Expand All @@ -425,7 +517,11 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
}

private void activate () {
var window = window_actor.get_meta_window ();
window.activate (Clutter.get_current_event_time ());
if (off_screen) {
place_window_in_screen ();
} else {
var window = window_actor.get_meta_window ();
window.activate (Clutter.get_current_event_time ());
}
}
}
Loading

0 comments on commit 0ca2f56

Please sign in to comment.