Skip to content

Commit 8d772e1

Browse files
authored
Monitor label cleanup (#13593)
* monitorLabeler.js: Port the MonitorLabel to GObject * layout.js: Add getWorkAreaForMonitor() convenience function * MonitorLabel: Use monitor work area to place the label This just keeps it from weirdly overlapping any top panels * monitorLabeler.js: Clean up a few function and variable names
1 parent beffc6d commit 8d772e1

2 files changed

Lines changed: 55 additions & 42 deletions

File tree

js/ui/layout.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,14 @@ var LayoutManager = GObject.registerClass({
638638
return index;
639639
}
640640

641+
getWorkAreaForMonitor(monitorIndex) {
642+
// Assume that all workspaces will have the same
643+
// struts and pick the first one.
644+
const workspaceManager = global.workspace_manager;
645+
const ws = workspaceManager.get_workspace_by_index(0);
646+
return ws.get_work_area_for_monitor(monitorIndex);
647+
}
648+
641649
/**
642650
* isTrackingChrome:
643651
* @actor (Clutter.Actor): the actor to check

js/ui/monitorLabeler.js

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const GObject = imports.gi.GObject;
12
const St = imports.gi.St;
23
const Main = imports.ui.main;
34
const Gio = imports.gi.Gio;
@@ -14,122 +15,126 @@ const common_css =
1415
text-align: center; \
1516
";
1617

17-
var MonitorLabel = class {
18-
constructor(monitor, connector, info) {
18+
var MonitorLabel = GObject.registerClass(
19+
class MonitorLabel extends St.BoxLayout {
20+
_init(monitor, connector, info) {
1921
this._monitor = monitor;
2022
this._connector = connector;
2123
this._index = info[0];
2224
this._cloned = info[1];
23-
this._display_name = info[2];
25+
this._displayName = info[2];
2426
this._color = info[3];
2527

26-
this.actor = new St.BoxLayout({ style: `${common_css} background-color: ${this._color};`,
27-
vertical: true });
28+
super._init({
29+
style: `${common_css} background-color: ${this._color};`,
30+
vertical: true,
31+
});
2832

29-
let label_text;
33+
let labelText;
3034

3135
if (this._cloned) {
3236
let str = _("Mirrored Displays");
33-
label_text = `<b>${str}</b>`;
37+
labelText = `<b>${str}</b>`;
3438
} else {
35-
label_text = `<b>${this._index} ${this._display_name}</b>\n${this._connector}`
39+
labelText = `<b>${this._index} ${this._displayName}</b>\n${this._connector}`
3640
}
3741

3842
this._label = new St.Label();
39-
this._label.clutter_text.set_markup(label_text);
40-
this.actor.add(this._label);
43+
this._label.clutter_text.set_markup(labelText);
44+
this.add_child(this._label);
4145

42-
Main.uiGroup.add_child(this.actor);
46+
Main.uiGroup.add_child(this);
4347

44-
this.actor.x = monitor.x + 6 * global.ui_scale;
45-
this.actor.y = monitor.y + 6 * global.ui_scale;
48+
const workArea = Main.layoutManager.getWorkAreaForMonitor(monitor.index);
49+
this.x = workArea.x + 6 * global.ui_scale;
50+
this.y = workArea.y + 6 * global.ui_scale;
4651
}
47-
}
52+
});
4853

4954
var MonitorLabeler = class {
5055
constructor() {
5156
this._labels = [];
52-
this._tracked_clients = new Map();
57+
this._trackedClients = new Map();
5358
this._active = false;
54-
this._monitor_manager = Meta.MonitorManager.get();
59+
this._monitorManager = Meta.MonitorManager.get();
5560

56-
this._show_idle_id = 0;
61+
this._showIdleId = 0;
5762
}
5863

5964
show(dict, sender) {
6065
this._active = true;
61-
this.watch_sender(sender);
66+
this.watchSender(sender);
6267

63-
if (this._show_idle_id != 0) {
64-
GLib.source_remove(this._show_idle_id);
65-
this._show_idle_id = 0;
68+
if (this._showIdleId != 0) {
69+
GLib.source_remove(this._showIdleId);
70+
this._showIdleId = 0;
6671
}
6772

68-
this._show_idle_id = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => this._real_show(dict));
73+
this._showIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => this._realShow(dict));
6974
}
7075

71-
_real_show(dict) {
76+
_realShow(dict) {
7277
for (let label of this._labels) {
73-
label.actor.destroy();
78+
label.destroy();
7479
}
7580

7681
this._labels = [];
7782

7883
for (let connector in dict) {
79-
let index = this._monitor_manager.get_monitor_for_connector(connector);
84+
let index = this._monitorManager.get_monitor_for_connector(connector);
8085
if (index == -1) {
8186
continue;
8287
}
8388

84-
let layout_monitor = 0;
89+
let layoutMonitor = 0;
8590

8691
try {
87-
layout_monitor = Main.layoutManager.monitors[index];
92+
layoutMonitor = Main.layoutManager.monitors[index];
8893
} catch {
8994
continue;
9095
}
9196

9297
let info = dict[connector].deep_unpack();
9398

94-
let label = new MonitorLabel(layout_monitor, connector, info);
99+
let label = new MonitorLabel(layoutMonitor, connector, info);
95100
this._labels.push(label);
96101
}
97102

98-
this._show_idle_id = 0;
103+
this._showIdleId = 0;
99104

100105
return GLib.SOURCE_REMOVE;
101106
}
102107

103108
hide(sender=null) {
104-
const watch_handle = this._tracked_clients.get(sender);
105-
if (watch_handle !== undefined) {
106-
Gio.bus_unwatch_name(watch_handle);
107-
this._tracked_clients.delete(sender)
109+
const watchHandle = this._trackedClients.get(sender);
110+
if (watchHandle !== undefined) {
111+
Gio.bus_unwatch_name(watchHandle);
112+
this._trackedClients.delete(sender)
108113
}
109114

110-
if (this._tracked_clients.size > 0) {
115+
if (this._trackedClients.size > 0) {
111116
return;
112117
}
113118

114-
if (this._show_idle_id != 0) {
115-
GLib.source_remove(this._show_idle_id);
116-
this._show_idle_id = 0;
119+
if (this._showIdleId != 0) {
120+
GLib.source_remove(this._showIdleId);
121+
this._showIdleId = 0;
117122
}
118123

119124
for (let label of this._labels) {
120-
label.actor.destroy();
125+
label.destroy();
121126
}
122127

123128
this._labels = [];
124129
this._active = false;
125130
}
126131

127-
watch_sender(sender) {
128-
if (this._tracked_clients.has(sender)) {
132+
watchSender(sender) {
133+
if (this._trackedClients.has(sender)) {
129134
return;
130135
}
131136

132-
let watch_handle = Gio.bus_watch_name(Gio.BusType.SESSION, sender, 0, null, (c, name) => this.hide(name))
133-
this._tracked_clients.set(sender, watch_handle);
137+
let watchHandle = Gio.bus_watch_name(Gio.BusType.SESSION, sender, 0, null, (c, name) => this.hide(name))
138+
this._trackedClients.set(sender, watchHandle);
134139
}
135140
};

0 commit comments

Comments
 (0)