2015-01-26 09:52:10 -05:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported OsdMonitorLabeler */
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, Gio, Meta, St } = imports.gi;
|
2015-01-26 09:52:10 -05:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var OsdMonitorLabel = class {
|
|
|
|
constructor(monitor, label) {
|
2015-06-27 01:05:58 -04:00
|
|
|
this._actor = new St.Widget({ x_expand: true,
|
2015-01-26 09:52:10 -05:00
|
|
|
y_expand: true });
|
|
|
|
|
|
|
|
this._monitor = monitor;
|
|
|
|
|
|
|
|
this._box = new St.BoxLayout({ style_class: 'osd-window',
|
|
|
|
vertical: true });
|
|
|
|
this._actor.add_actor(this._box);
|
|
|
|
|
|
|
|
this._label = new St.Label({ style_class: 'osd-monitor-label',
|
|
|
|
text: label });
|
|
|
|
this._box.add(this._label);
|
|
|
|
|
|
|
|
Main.uiGroup.add_child(this._actor);
|
|
|
|
Main.uiGroup.set_child_above_sibling(this._actor, null);
|
|
|
|
this._position();
|
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_position() {
|
2015-01-26 09:52:10 -05:00
|
|
|
let workArea = Main.layoutManager.getWorkAreaForMonitor(this._monitor);
|
|
|
|
|
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
|
|
|
|
this._box.x = workArea.x + (workArea.width - this._box.width);
|
|
|
|
else
|
|
|
|
this._box.x = workArea.x;
|
|
|
|
|
|
|
|
this._box.y = workArea.y;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2015-06-27 01:05:58 -04:00
|
|
|
this._actor.destroy();
|
2018-01-03 02:55:38 -05:00
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
2015-01-26 09:52:10 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var OsdMonitorLabeler = class {
|
|
|
|
constructor() {
|
2015-01-26 09:52:10 -05:00
|
|
|
this._monitorManager = Meta.MonitorManager.get();
|
|
|
|
this._client = null;
|
|
|
|
this._clientWatchId = 0;
|
|
|
|
this._osdLabels = [];
|
|
|
|
this._monitorLabels = null;
|
|
|
|
Main.layoutManager.connect('monitors-changed',
|
2019-01-29 14:36:54 -05:00
|
|
|
this._reset.bind(this));
|
2015-01-26 09:52:10 -05:00
|
|
|
this._reset();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reset() {
|
2015-01-26 09:52:10 -05:00
|
|
|
for (let i in this._osdLabels)
|
|
|
|
this._osdLabels[i].destroy();
|
|
|
|
this._osdLabels = [];
|
|
|
|
this._monitorLabels = new Map();
|
|
|
|
let monitors = Main.layoutManager.monitors;
|
|
|
|
for (let i in monitors)
|
|
|
|
this._monitorLabels.set(monitors[i].index, []);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_trackClient(client) {
|
2015-01-26 09:52:10 -05:00
|
|
|
if (this._client)
|
|
|
|
return (this._client == client);
|
|
|
|
|
|
|
|
this._client = client;
|
|
|
|
this._clientWatchId = Gio.bus_watch_name(Gio.BusType.SESSION, client, 0, null,
|
2017-10-30 20:38:18 -04:00
|
|
|
(c, name) => {
|
2015-01-26 09:52:10 -05:00
|
|
|
this.hide(name);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2015-01-26 09:52:10 -05:00
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_untrackClient(client) {
|
2015-01-26 09:52:10 -05:00
|
|
|
if (!this._client || this._client != client)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Gio.bus_unwatch_name(this._clientWatchId);
|
|
|
|
this._clientWatchId = 0;
|
|
|
|
this._client = null;
|
|
|
|
return true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2015-01-26 09:52:10 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
show(client, params) {
|
2015-01-26 09:52:10 -05:00
|
|
|
if (!this._trackClient(client))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reset();
|
|
|
|
|
2017-04-06 01:18:39 -04:00
|
|
|
for (let connector in params) {
|
|
|
|
let monitor = this._monitorManager.get_monitor_for_connector(connector);
|
|
|
|
if (monitor == -1)
|
|
|
|
continue;
|
|
|
|
this._monitorLabels.get(monitor).push(params[connector].deep_unpack());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let [monitor, labels] of this._monitorLabels.entries()) {
|
|
|
|
labels.sort();
|
|
|
|
this._osdLabels.push(new OsdMonitorLabel(monitor, labels.join(' ')));
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-04-06 01:18:39 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
hide(client) {
|
2015-01-26 09:52:10 -05:00
|
|
|
if (!this._untrackClient(client))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reset();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|