LayoutManager: add a ClutterConstraint for tracking monitor sizes
Instead of connecting manually to LayoutManager, or using ShellGenericContainer, make a ClutterConstraint subclass that can track automatically a specific monitor index, or the primary monitor. https://bugzilla.gnome.org/show_bug.cgi?id=681743
This commit is contained in:
parent
1dbbb4f91c
commit
3e94f6bc3c
@ -1,6 +1,7 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
|
|
||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
|
const GObject = imports.gi.GObject;
|
||||||
const Lang = imports.lang;
|
const Lang = imports.lang;
|
||||||
const Mainloop = imports.mainloop;
|
const Mainloop = imports.mainloop;
|
||||||
const Meta = imports.gi.Meta;
|
const Meta = imports.gi.Meta;
|
||||||
@ -17,6 +18,79 @@ const HOT_CORNER_ACTIVATION_TIMEOUT = 0.5;
|
|||||||
const STARTUP_ANIMATION_TIME = 0.2;
|
const STARTUP_ANIMATION_TIME = 0.2;
|
||||||
const KEYBOARD_ANIMATION_TIME = 0.5;
|
const KEYBOARD_ANIMATION_TIME = 0.5;
|
||||||
|
|
||||||
|
const MonitorConstraint = new Lang.Class({
|
||||||
|
Name: 'MonitorConstraint',
|
||||||
|
Extends: Clutter.Constraint,
|
||||||
|
Properties: {'primary': GObject.ParamSpec.boolean('primary',
|
||||||
|
'Primary', 'Track primary monitor',
|
||||||
|
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
|
||||||
|
false),
|
||||||
|
'index': GObject.ParamSpec.int('index',
|
||||||
|
'Monitor index', 'Track specific monitor',
|
||||||
|
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
|
||||||
|
-1, 64, -1)},
|
||||||
|
|
||||||
|
_init: function(props) {
|
||||||
|
this._primary = false;
|
||||||
|
this._index = -1;
|
||||||
|
|
||||||
|
this.parent(props);
|
||||||
|
},
|
||||||
|
|
||||||
|
get primary() {
|
||||||
|
return this._primary;
|
||||||
|
},
|
||||||
|
|
||||||
|
set primary(v) {
|
||||||
|
this._primary = v;
|
||||||
|
if (this.actor)
|
||||||
|
this.actor.queue_relayout();
|
||||||
|
this.notify('primary');
|
||||||
|
},
|
||||||
|
|
||||||
|
get index() {
|
||||||
|
return this._index;
|
||||||
|
},
|
||||||
|
|
||||||
|
set index(v) {
|
||||||
|
this._index = v;
|
||||||
|
if (this.actor)
|
||||||
|
this.actor.queue_relayout();
|
||||||
|
this.notify('index');
|
||||||
|
},
|
||||||
|
|
||||||
|
vfunc_set_actor: function(actor) {
|
||||||
|
if (actor) {
|
||||||
|
if (!this._monitorsChangedId) {
|
||||||
|
this._monitorsChangedId = Main.layoutManager.connect('monitors-changed', Lang.bind(this, function() {
|
||||||
|
this.actor.queue_relayout();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this._monitorsChangedId)
|
||||||
|
Main.layoutManager.disconnect(this._monitorsChangedId);
|
||||||
|
this._monitorsChangedId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.parent(actor);
|
||||||
|
},
|
||||||
|
|
||||||
|
vfunc_update_allocation: function(actor, actorBox) {
|
||||||
|
if (!this._primary && this._index < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let monitor;
|
||||||
|
if (this._primary) {
|
||||||
|
monitor = Main.layoutManager.primaryMonitor;
|
||||||
|
} else {
|
||||||
|
let index = Math.max(this._index, Main.layoutManager.monitors.length);
|
||||||
|
monitor = Main.layoutManager.monitors[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
actorBox.init_rect(monitor.x, monitor.y, monitor.width, monitor.height);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const LayoutManager = new Lang.Class({
|
const LayoutManager = new Lang.Class({
|
||||||
Name: 'LayoutManager',
|
Name: 'LayoutManager',
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user