Files
.gitlab
.gitlab-ci
.settings
data
docs
js
dbusServices
extensions
gdm
misc
portalHelper
ui
components
status
accessDialog.js
altTab.js
animation.js
appDisplay.js
appFavorites.js
appMenu.js
audioDeviceSelection.js
background.js
backgroundMenu.js
barLevel.js
boxpointer.js
calendar.js
checkBox.js
closeDialog.js
components.js
ctrlAltTab.js
dash.js
dateMenu.js
dialog.js
dnd.js
edgeDragAction.js
endSessionDialog.js
environment.js
extensionDownloader.js
extensionSystem.js
focusCaretTracker.js
grabHelper.js
ibusCandidatePopup.js
iconGrid.js
inhibitShortcutsDialog.js
init.js
kbdA11yDialog.js
keyboard.js
layout.js
lightbox.js
listModes.js
locatePointer.js
lookingGlass.js
magnifier.js
main.js
messageList.js
messageTray.js
modalDialog.js
mpris.js
notificationDaemon.js
osdMonitorLabeler.js
osdWindow.js
overview.js
overviewControls.js
padOsd.js
pageIndicators.js
panel.js
panelMenu.js
pointerA11yTimeout.js
pointerWatcher.js
popupMenu.js
quickSettings.js
remoteSearch.js
ripples.js
runDialog.js
screenShield.js
screenshot.js
scripting.js
search.js
searchController.js
sessionMode.js
shellDBus.js
shellEntry.js
shellMountOperation.js
slider.js
swipeTracker.js
switchMonitor.js
switcherPopup.js
unlockDialog.js
userWidget.js
welcomeDialog.js
windowAttentionHandler.js
windowManager.js
windowMenu.js
windowPreview.js
workspace.js
workspaceAnimation.js
workspaceSwitcherPopup.js
workspaceThumbnail.js
workspacesView.js
xdndHandler.js
js-resources.gresource.xml
meson.build
portal-resources.gresource.xml
lint
man
meson
po
src
subprojects
tests
tools
.eslintrc.yml
.gitignore
.gitlab-ci.yml
.gitmodules
.jscheckignore
COPYING
HACKING.md
NEWS
README.md
config.h.meson
gnome-shell.doap
meson.build
meson_options.txt
gnome-shell/js/ui/osdMonitorLabeler.js
Florian Müllner a42f7c2384 cleanup: Use type-safe comparisons
We have been using type-safe comparisons in new code for quite a while
now, however old code has only been adapted slowly.

Change all the remaining bits to get rid of another legacy style
difference.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2866>
2023-08-09 15:10:38 +00:00

123 lines
3.3 KiB
JavaScript

// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
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';
import * as Main from './main.js';
const OsdMonitorLabel = GObject.registerClass(
class OsdMonitorLabel extends St.Widget {
_init(monitor, label) {
super._init({x_expand: true, y_expand: true});
this._monitor = monitor;
this._box = new St.BoxLayout({
vertical: true,
});
this.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);
Main.uiGroup.set_child_above_sibling(this, null);
this._position();
Meta.disable_unredirect_for_display(global.display);
this.connect('destroy', () => {
Meta.enable_unredirect_for_display(global.display);
});
}
_position() {
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;
}
});
export class OsdMonitorLabeler {
constructor() {
this._monitorManager = global.backend.get_monitor_manager();
this._client = null;
this._clientWatchId = 0;
this._osdLabels = [];
this._monitorLabels = null;
Main.layoutManager.connect('monitors-changed',
this._reset.bind(this));
this._reset();
}
_reset() {
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, []);
}
_trackClient(client) {
if (this._client)
return this._client === client;
this._client = client;
this._clientWatchId = Gio.bus_watch_name(Gio.BusType.SESSION,
client, 0, null,
(c, name) => {
this.hide(name);
});
return true;
}
_untrackClient(client) {
if (!this._client || this._client !== client)
return false;
Gio.bus_unwatch_name(this._clientWatchId);
this._clientWatchId = 0;
this._client = null;
return true;
}
show(client, params) {
if (!this._trackClient(client))
return;
this._reset();
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].deepUnpack());
}
for (let [monitor, labels] of this._monitorLabels.entries()) {
labels.sort();
this._osdLabels.push(new OsdMonitorLabel(monitor, labels.join(' ')));
}
}
hide(client) {
if (!this._untrackClient(client))
return;
this._reset();
}
}