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