2015-01-26 14:52:10 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported OsdMonitorLabeler */
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2023-06-08 04:52:46 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const St = imports.gi.St;
|
2015-01-26 14:52:10 +00:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
var OsdMonitorLabel = GObject.registerClass(
|
|
|
|
class OsdMonitorLabel extends St.Widget {
|
|
|
|
_init(monitor, label) {
|
|
|
|
super._init({ x_expand: true, y_expand: true });
|
2015-01-26 14:52:10 +00:00
|
|
|
|
|
|
|
this._monitor = monitor;
|
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
this._box = new St.BoxLayout({
|
|
|
|
vertical: true,
|
|
|
|
});
|
2019-07-16 09:24:13 +00:00
|
|
|
this.add_actor(this._box);
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
this._label = new St.Label({
|
|
|
|
style_class: 'osd-monitor-label',
|
|
|
|
text: label,
|
|
|
|
});
|
2015-01-26 14:52:10 +00:00
|
|
|
this._box.add(this._label);
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
Main.uiGroup.add_child(this);
|
|
|
|
Main.uiGroup.set_child_above_sibling(this, null);
|
2015-01-26 14:52:10 +00:00
|
|
|
this._position();
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
2019-07-16 09:24:13 +00:00
|
|
|
this.connect('destroy', () => {
|
|
|
|
Meta.enable_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
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|
2015-01-26 14:52:10 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var OsdMonitorLabeler = class {
|
|
|
|
constructor() {
|
2022-09-07 18:24:44 +00:00
|
|
|
this._monitorManager = global.backend.get_monitor_manager();
|
2015-01-26 14:52:10 +00:00
|
|
|
this._client = null;
|
|
|
|
this._clientWatchId = 0;
|
|
|
|
this._osdLabels = [];
|
|
|
|
this._monitorLabels = null;
|
|
|
|
Main.layoutManager.connect('monitors-changed',
|
2019-01-29 19:36:54 +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)
|
2019-08-19 19:38:51 +00:00
|
|
|
return this._client == client;
|
2015-01-26 14:52:10 +00:00
|
|
|
|
|
|
|
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;
|
2022-08-10 09:56:14 +00:00
|
|
|
this._monitorLabels.get(monitor).push(params[connector].deepUnpack());
|
2017-04-06 05:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
};
|