mirror of
https://github.com/elementary/gala.git
synced 2024-08-16 18:40:27 +03:00
Fix barriers (#1908)
This commit is contained in:
parent
fe650bfa80
commit
29da53aedc
@ -6,7 +6,7 @@
|
||||
/**
|
||||
* A pointer barrier supporting pressured activation.
|
||||
*/
|
||||
public class Gala.Barrier : Meta.Barrier {
|
||||
public class Gala.Barrier : Object {
|
||||
public signal void trigger ();
|
||||
|
||||
public bool triggered { get; set; default = false; }
|
||||
@ -16,6 +16,8 @@ public class Gala.Barrier : Meta.Barrier {
|
||||
public int retrigger_pressure_threshold { get; construct; }
|
||||
public int retrigger_delay { get; construct; }
|
||||
|
||||
private Meta.Barrier barrier;
|
||||
|
||||
private uint32 triggered_time;
|
||||
private double pressure;
|
||||
|
||||
@ -26,6 +28,7 @@ public class Gala.Barrier : Meta.Barrier {
|
||||
* the barrier to trigger again. Set to int.MAX to disallow retrigger.
|
||||
*/
|
||||
public Barrier (
|
||||
Meta.Backend backend,
|
||||
int x1,
|
||||
int y1,
|
||||
int x2,
|
||||
@ -37,25 +40,27 @@ public class Gala.Barrier : Meta.Barrier {
|
||||
int retrigger_delay
|
||||
) {
|
||||
Object (
|
||||
x1: x1,
|
||||
y1: y1,
|
||||
x2: x2,
|
||||
y2: y2,
|
||||
directions: directions,
|
||||
trigger_pressure_threshold: trigger_pressure_threshold,
|
||||
release_pressure_threshold: release_pressure_threshold,
|
||||
retrigger_pressure_threshold: retrigger_pressure_threshold,
|
||||
retrigger_delay: retrigger_delay
|
||||
);
|
||||
|
||||
try {
|
||||
barrier = new Meta.Barrier (backend, x1, y1, x2, y2, directions, Meta.BarrierFlags.NONE);
|
||||
barrier.hit.connect (on_hit);
|
||||
barrier.left.connect (on_left);
|
||||
} catch (Error e) {
|
||||
warning ("Failed to create Meta Barrier");
|
||||
}
|
||||
}
|
||||
|
||||
construct {
|
||||
hit.connect (on_hit);
|
||||
left.connect (on_left);
|
||||
~Barrier () {
|
||||
barrier.destroy ();
|
||||
}
|
||||
|
||||
private void on_hit (Meta.BarrierEvent event) {
|
||||
if (POSITIVE_X in directions || NEGATIVE_X in directions) {
|
||||
if (POSITIVE_X in barrier.directions || NEGATIVE_X in barrier.directions) {
|
||||
pressure += event.dx.abs ();
|
||||
} else {
|
||||
pressure += event.dy.abs ();
|
||||
@ -66,7 +71,7 @@ public class Gala.Barrier : Meta.Barrier {
|
||||
}
|
||||
|
||||
if (!triggered && pressure > release_pressure_threshold) {
|
||||
release (event);
|
||||
barrier.release (event);
|
||||
}
|
||||
|
||||
if (triggered && pressure.abs () > retrigger_pressure_threshold && event.time > retrigger_delay + triggered_time) {
|
||||
|
@ -48,27 +48,23 @@ public class Gala.HotCorner : Object {
|
||||
private Gala.Barrier? vertical_barrier = null;
|
||||
private Gala.Barrier? horizontal_barrier = null;
|
||||
|
||||
public HotCorner (Meta.Display display, float x, float y, float scale, string hot_corner_position) {
|
||||
add_barriers (display, x, y, scale, hot_corner_position);
|
||||
public HotCorner (Meta.Backend backend, float x, float y, float scale, string hot_corner_position) {
|
||||
add_barriers (backend, x, y, scale, hot_corner_position);
|
||||
}
|
||||
|
||||
public void destroy_barriers () {
|
||||
if (vertical_barrier != null) {
|
||||
vertical_barrier.destroy ();
|
||||
}
|
||||
|
||||
if (horizontal_barrier != null) {
|
||||
horizontal_barrier.destroy ();
|
||||
}
|
||||
vertical_barrier = null;
|
||||
horizontal_barrier = null;
|
||||
}
|
||||
|
||||
private void add_barriers (Meta.Display display, float x, float y, float scale, string hot_corner_position) {
|
||||
private void add_barriers (Meta.Backend backend, float x, float y, float scale, string hot_corner_position) {
|
||||
var vrect = get_barrier_rect (x, y, scale, hot_corner_position, Clutter.Orientation.VERTICAL);
|
||||
var hrect = get_barrier_rect (x, y, scale, hot_corner_position, Clutter.Orientation.HORIZONTAL);
|
||||
var vdir = get_barrier_direction (hot_corner_position, Clutter.Orientation.VERTICAL);
|
||||
var hdir = get_barrier_direction (hot_corner_position, Clutter.Orientation.HORIZONTAL);
|
||||
|
||||
vertical_barrier = new Gala.Barrier (
|
||||
backend,
|
||||
vrect.x, vrect.y, vrect.x + vrect.width, vrect.y + vrect.height, vdir,
|
||||
TRIGGER_PRESSURE_THRESHOLD,
|
||||
RELEASE_PRESSURE_THRESHOLD,
|
||||
@ -77,6 +73,7 @@ public class Gala.HotCorner : Object {
|
||||
);
|
||||
|
||||
horizontal_barrier = new Gala.Barrier (
|
||||
backend,
|
||||
hrect.x, hrect.y, hrect.x + hrect.width, hrect.y + hrect.height, hdir,
|
||||
TRIGGER_PRESSURE_THRESHOLD,
|
||||
RELEASE_PRESSURE_THRESHOLD,
|
||||
|
@ -69,7 +69,7 @@ public class Gala.HotCornerManager : Object {
|
||||
}
|
||||
|
||||
unowned Meta.Display display = wm.get_display ();
|
||||
var hot_corner = new HotCorner (display, (int) x, (int) y, scale, hot_corner_position);
|
||||
var hot_corner = new HotCorner (display.get_context ().get_backend (), (int) x, (int) y, scale, hot_corner_position);
|
||||
|
||||
hot_corner.trigger.connect (() => {
|
||||
if (
|
||||
|
@ -171,7 +171,13 @@ public class Gala.HideTracker : Object {
|
||||
}
|
||||
|
||||
private void toggle_display (bool should_hide) {
|
||||
if (should_hide) {
|
||||
#if HAS_MUTTER45
|
||||
hovered = panel.window.has_pointer ();
|
||||
#else
|
||||
hovered = window_has_pointer ();
|
||||
#endif
|
||||
|
||||
if (should_hide && !hovered) {
|
||||
// Don't hide if we have transients, e.g. an open popover, dialog, etc.
|
||||
var has_transients = false;
|
||||
panel.window.foreach_transient (() => {
|
||||
@ -179,7 +185,7 @@ public class Gala.HideTracker : Object {
|
||||
return false;
|
||||
});
|
||||
|
||||
if (hovered || has_transients) {
|
||||
if (has_transients) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -184,10 +184,7 @@ public class Gala.PanelWindow : Object {
|
||||
}
|
||||
|
||||
private void destroy_barrier () {
|
||||
if (barrier != null) {
|
||||
barrier.destroy ();
|
||||
barrier = null;
|
||||
}
|
||||
barrier = null;
|
||||
}
|
||||
|
||||
private void setup_barrier () {
|
||||
@ -217,6 +214,7 @@ public class Gala.PanelWindow : Object {
|
||||
private void setup_barrier_top (Meta.Rectangle monitor_geom, int offset) {
|
||||
#endif
|
||||
barrier = new Barrier (
|
||||
wm.get_display ().get_context ().get_backend (),
|
||||
monitor_geom.x + offset,
|
||||
monitor_geom.y,
|
||||
monitor_geom.x + monitor_geom.width - offset,
|
||||
@ -237,6 +235,7 @@ public class Gala.PanelWindow : Object {
|
||||
private void setup_barrier_bottom (Meta.Rectangle monitor_geom, int offset) {
|
||||
#endif
|
||||
barrier = new Barrier (
|
||||
wm.get_display ().get_context ().get_backend (),
|
||||
monitor_geom.x + offset,
|
||||
monitor_geom.y + monitor_geom.height,
|
||||
monitor_geom.x + monitor_geom.width - offset,
|
||||
|
Loading…
Reference in New Issue
Block a user