2015-01-26 14:52:10 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Clutter, Gio, Meta, St } = imports.gi;
|
2015-01-26 14:52:10 +00:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var OsdMonitorLabel = class {
|
|
|
|
constructor(monitor, label) {
|
2015-06-27 05:05:58 +00:00
|
|
|
this._actor = new St.Widget({ x_expand: true,
|
2015-01-26 14:52:10 +00: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 07:55:38 +00:00
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_position() {
|
2015-01-26 14:52:10 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2015-06-27 05:05:58 +00:00
|
|
|
this._actor.destroy();
|
2018-01-03 07:55:38 +00:00
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
2015-01-26 14:52:10 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var OsdMonitorLabeler = class {
|
|
|
|
constructor() {
|
2015-01-26 14:52:10 +00:00
|
|
|
this._monitorManager = Meta.MonitorManager.get();
|
|
|
|
this._client = null;
|
|
|
|
this._clientWatchId = 0;
|
|
|
|
this._osdLabels = [];
|
|
|
|
this._monitorLabels = null;
|
|
|
|
Main.layoutManager.connect('monitors-changed',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._reset.bind(this));
|
2015-01-26 14:52:10 +00:00
|
|
|
this._reset();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_reset() {
|
2015-01-26 14:52:10 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_trackClient(client) {
|
2015-01-26 14:52:10 +00: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-31 00:38:18 +00:00
|
|
|
(c, name) => {
|
2015-01-26 14:52:10 +00:00
|
|
|
this.hide(name);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2015-01-26 14:52:10 +00:00
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_untrackClient(client) {
|
2015-01-26 14:52:10 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
show(client, params) {
|
2015-01-26 14:52:10 +00:00
|
|
|
if (!this._trackClient(client))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reset();
|
|
|
|
|
2017-04-06 05:18:39 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2017-04-06 05:18:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
hide(client) {
|
2015-01-26 14:52:10 +00:00
|
|
|
if (!this._untrackClient(client))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reset();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|