layout: Add MonitorConstraint:work-area property

Occasionally it makes sense to constrain to a monitor's work-area
rather than the entire monitor, so implement that behavior and add
a property to turn it on.

https://bugzilla.gnome.org/show_bug.cgi?id=744850
This commit is contained in:
Florian Müllner 2015-02-06 19:27:02 +01:00
parent d903e831f3
commit faf00036e2

View File

@ -45,11 +45,16 @@ const MonitorConstraint = new Lang.Class({
'index': GObject.ParamSpec.int('index', 'index': GObject.ParamSpec.int('index',
'Monitor index', 'Track specific monitor', 'Monitor index', 'Track specific monitor',
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE, GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
-1, 64, -1)}, -1, 64, -1),
'work-area': GObject.ParamSpec.boolean('work-area',
'Work-area', 'Track monitor\'s work-area',
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
false)},
_init: function(props) { _init: function(props) {
this._primary = false; this._primary = false;
this._index = -1; this._index = -1;
this._workArea = false;
this.parent(props); this.parent(props);
}, },
@ -79,6 +84,19 @@ const MonitorConstraint = new Lang.Class({
this.notify('index'); this.notify('index');
}, },
get work_area() {
return this._workArea;
},
set work_area(v) {
if (v == this._workArea)
return;
this._workArea = v;
if (this.actor)
this.actor.queue_relayout();
this.notify('work-area');
},
vfunc_set_actor: function(actor) { vfunc_set_actor: function(actor) {
if (actor) { if (actor) {
if (!this._monitorsChangedId) { if (!this._monitorsChangedId) {
@ -86,10 +104,21 @@ const MonitorConstraint = new Lang.Class({
this.actor.queue_relayout(); this.actor.queue_relayout();
})); }));
} }
if (!this._workareasChangedId) {
this._workareasChangedId = global.screen.connect('workareas-changed', Lang.bind(this, function() {
if (this._workArea)
this.actor.queue_relayout();
}));
}
} else { } else {
if (this._monitorsChangedId) if (this._monitorsChangedId)
Main.layoutManager.disconnect(this._monitorsChangedId); Main.layoutManager.disconnect(this._monitorsChangedId);
this._monitorsChangedId = 0; this._monitorsChangedId = 0;
if (this._workareasChangedId)
global.screen.disconnect(this._workareasChangedId);
this._workareasChangedId = 0;
} }
this.parent(actor); this.parent(actor);
@ -99,15 +128,21 @@ const MonitorConstraint = new Lang.Class({
if (!this._primary && this._index < 0) if (!this._primary && this._index < 0)
return; return;
let monitor; let index;
if (this._primary) { if (this._primary)
monitor = Main.layoutManager.primaryMonitor; index = Main.layoutManager.primaryIndex;
else
index = Math.min(this._index, Main.layoutManager.monitors.length - 1);
let rect;
if (this._workArea) {
let ws = global.screen.get_workspace_by_index(0);
rect = ws.get_work_area_for_monitor(index);
} else { } else {
let index = Math.min(this._index, Main.layoutManager.monitors.length - 1); rect = Main.layoutManager.monitors[index];
monitor = Main.layoutManager.monitors[index];
} }
actorBox.init_rect(monitor.x, monitor.y, monitor.width, monitor.height); actorBox.init_rect(rect.x, rect.y, rect.width, rect.height);
} }
}); });