2013-03-02 10:48:25 +01:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2023-07-10 02:53:00 -07:00
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
import Meta from 'gi://Meta';
|
|
|
|
import St from 'gi://St';
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2023-07-10 02:53:00 -07:00
|
|
|
import * as BarLevel from './barLevel.js';
|
|
|
|
import * as Layout from './layout.js';
|
|
|
|
import * as Main from './main.js';
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2023-07-10 02:53:00 -07:00
|
|
|
const HIDE_TIMEOUT = 1500;
|
|
|
|
const FADE_TIME = 100;
|
|
|
|
const LEVEL_ANIMATION_TIME = 100;
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2023-07-10 02:53:00 -07:00
|
|
|
export const OsdWindow = GObject.registerClass(
|
2022-01-25 20:31:07 +01:00
|
|
|
class OsdWindow extends Clutter.Actor {
|
2019-07-16 11:24:13 +02:00
|
|
|
_init(monitorIndex) {
|
|
|
|
super._init({
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
2022-01-25 23:15:52 +01:00
|
|
|
y_align: Clutter.ActorAlign.END,
|
2019-07-16 11:24:13 +02:00
|
|
|
});
|
2014-04-17 10:23:30 +02:00
|
|
|
|
|
|
|
this._monitorIndex = monitorIndex;
|
|
|
|
let constraint = new Layout.MonitorConstraint({ index: monitorIndex });
|
2019-07-16 11:24:13 +02:00
|
|
|
this.add_constraint(constraint);
|
2014-04-17 10:23:30 +02:00
|
|
|
|
2022-01-25 23:15:52 +01:00
|
|
|
this._hbox = new St.BoxLayout({
|
|
|
|
style_class: 'osd-window',
|
|
|
|
});
|
|
|
|
this.add_actor(this._hbox);
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2019-10-21 20:44:00 +02:00
|
|
|
this._icon = new St.Icon({ y_expand: true });
|
2022-01-25 23:15:52 +01:00
|
|
|
this._hbox.add_child(this._icon);
|
|
|
|
|
|
|
|
this._vbox = new St.BoxLayout({
|
|
|
|
vertical: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
|
|
|
this._hbox.add_child(this._vbox);
|
2013-03-02 10:48:25 +01:00
|
|
|
|
|
|
|
this._label = new St.Label();
|
2022-01-25 23:15:52 +01:00
|
|
|
this._vbox.add_child(this._label);
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2019-07-25 18:53:00 +02:00
|
|
|
this._level = new BarLevel.BarLevel({
|
|
|
|
style_class: 'level',
|
2019-08-20 23:43:54 +02:00
|
|
|
value: 0,
|
2019-07-25 18:53:00 +02:00
|
|
|
});
|
2022-01-25 23:15:52 +01:00
|
|
|
this._vbox.add_child(this._level);
|
2013-03-02 10:48:25 +01:00
|
|
|
|
|
|
|
this._hideTimeoutId = 0;
|
|
|
|
this._reset();
|
2019-07-16 11:24:13 +02:00
|
|
|
Main.uiGroup.add_child(this);
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2022-01-25 23:15:52 +01:00
|
|
|
_updateBoxVisibility() {
|
|
|
|
this._vbox.visible = [...this._vbox].some(c => c.visible);
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2018-09-23 03:06:21 +02:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
setIcon(icon) {
|
2013-03-02 10:48:25 +01:00
|
|
|
this._icon.gicon = icon;
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
setLabel(label) {
|
2019-08-19 21:38:51 +02:00
|
|
|
this._label.visible = label != undefined;
|
2013-03-02 10:48:25 +01:00
|
|
|
if (label)
|
|
|
|
this._label.text = label;
|
2022-01-25 23:15:52 +01:00
|
|
|
this._updateBoxVisibility();
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2019-02-02 17:58:47 +01:00
|
|
|
setLevel(value) {
|
2019-08-19 21:38:51 +02:00
|
|
|
this._level.visible = value != undefined;
|
2019-02-02 17:58:47 +01:00
|
|
|
if (value != undefined) {
|
2019-08-20 02:51:42 +02:00
|
|
|
if (this.visible) {
|
2019-07-25 02:06:05 +02:00
|
|
|
this._level.ease_property('value', value, {
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2019-08-20 23:43:54 +02:00
|
|
|
duration: LEVEL_ANIMATION_TIME,
|
2019-07-25 02:06:05 +02:00
|
|
|
});
|
2019-08-20 02:51:42 +02:00
|
|
|
} else {
|
2019-02-02 17:58:47 +01:00
|
|
|
this._level.value = value;
|
2019-08-20 02:51:42 +02:00
|
|
|
}
|
2013-04-14 11:32:21 -04:00
|
|
|
}
|
2022-01-25 23:15:52 +01:00
|
|
|
this._updateBoxVisibility();
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2019-02-02 17:50:04 +01:00
|
|
|
setMaxLevel(maxLevel = 1) {
|
2019-02-02 17:58:47 +01:00
|
|
|
this._level.maximum_value = maxLevel;
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2018-07-31 16:47:05 +02:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
show() {
|
2013-03-02 10:48:25 +01:00
|
|
|
if (!this._icon.gicon)
|
|
|
|
return;
|
|
|
|
|
2019-07-16 11:24:13 +02:00
|
|
|
if (!this.visible) {
|
2018-01-03 15:55:38 +08:00
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
2019-07-16 11:24:13 +02:00
|
|
|
super.show();
|
|
|
|
this.opacity = 0;
|
|
|
|
this.get_parent().set_child_above_sibling(this, null);
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2019-07-16 11:24:13 +02:00
|
|
|
this.ease({
|
2018-07-20 21:46:19 +02:00
|
|
|
opacity: 255,
|
|
|
|
duration: FADE_TIME,
|
2019-08-20 23:43:54 +02:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2018-07-20 21:46:19 +02:00
|
|
|
});
|
2013-03-02 10:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this._hideTimeoutId)
|
2019-08-19 20:50:33 +02:00
|
|
|
GLib.source_remove(this._hideTimeoutId);
|
|
|
|
this._hideTimeoutId = GLib.timeout_add(
|
|
|
|
GLib.PRIORITY_DEFAULT, HIDE_TIMEOUT, this._hide.bind(this));
|
2014-04-10 19:26:52 +02:00
|
|
|
GLib.Source.set_name_by_id(this._hideTimeoutId, '[gnome-shell] this._hide');
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
cancel() {
|
2013-03-02 19:56:37 +01:00
|
|
|
if (!this._hideTimeoutId)
|
|
|
|
return;
|
|
|
|
|
2019-08-19 20:50:33 +02:00
|
|
|
GLib.source_remove(this._hideTimeoutId);
|
2013-03-02 19:56:37 +01:00
|
|
|
this._hide();
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-03-02 19:56:37 +01:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
_hide() {
|
2013-06-24 17:15:33 -04:00
|
|
|
this._hideTimeoutId = 0;
|
2019-07-16 11:24:13 +02:00
|
|
|
this.ease({
|
2018-07-20 21:46:19 +02:00
|
|
|
opacity: 0,
|
|
|
|
duration: FADE_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
onComplete: () => {
|
|
|
|
this._reset();
|
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
2019-08-20 23:43:54 +02:00
|
|
|
},
|
2018-07-20 21:46:19 +02:00
|
|
|
});
|
2013-11-29 01:45:39 +01:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-03-02 10:48:25 +01:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
_reset() {
|
2019-07-16 11:24:13 +02:00
|
|
|
super.hide();
|
2013-03-02 10:48:25 +01:00
|
|
|
this.setLabel(null);
|
2018-07-31 16:47:05 +02:00
|
|
|
this.setMaxLevel(null);
|
2018-10-18 17:26:03 +02:00
|
|
|
this.setLevel(null);
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2019-07-16 11:24:13 +02:00
|
|
|
});
|
2014-04-17 10:23:30 +02:00
|
|
|
|
2023-07-10 02:53:00 -07:00
|
|
|
export class OsdWindowManager {
|
2017-10-31 02:19:44 +01:00
|
|
|
constructor() {
|
2014-04-17 10:23:30 +02:00
|
|
|
this._osdWindows = [];
|
|
|
|
Main.layoutManager.connect('monitors-changed',
|
2019-01-29 20:36:54 +01:00
|
|
|
this._monitorsChanged.bind(this));
|
2014-04-17 10:23:30 +02:00
|
|
|
this._monitorsChanged();
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-11-18 13:48:19 +01:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
_monitorsChanged() {
|
2014-04-17 10:23:30 +02:00
|
|
|
for (let i = 0; i < Main.layoutManager.monitors.length; i++) {
|
|
|
|
if (this._osdWindows[i] == undefined)
|
|
|
|
this._osdWindows[i] = new OsdWindow(i);
|
|
|
|
}
|
2013-11-18 13:48:19 +01:00
|
|
|
|
2014-04-17 10:23:30 +02:00
|
|
|
for (let i = Main.layoutManager.monitors.length; i < this._osdWindows.length; i++) {
|
2019-07-16 11:24:13 +02:00
|
|
|
this._osdWindows[i].destroy();
|
2014-04-17 10:23:30 +02:00
|
|
|
this._osdWindows[i] = null;
|
|
|
|
}
|
2013-11-18 13:48:19 +01:00
|
|
|
|
2014-04-17 10:23:30 +02:00
|
|
|
this._osdWindows.length = Main.layoutManager.monitors.length;
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2013-11-18 13:48:19 +01:00
|
|
|
|
2018-07-31 16:47:05 +02:00
|
|
|
_showOsdWindow(monitorIndex, icon, label, level, maxLevel) {
|
2014-04-17 10:23:30 +02:00
|
|
|
this._osdWindows[monitorIndex].setIcon(icon);
|
|
|
|
this._osdWindows[monitorIndex].setLabel(label);
|
2018-07-31 16:47:05 +02:00
|
|
|
this._osdWindows[monitorIndex].setMaxLevel(maxLevel);
|
2018-10-18 17:26:03 +02:00
|
|
|
this._osdWindows[monitorIndex].setLevel(level);
|
2014-04-17 10:23:30 +02:00
|
|
|
this._osdWindows[monitorIndex].show();
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2014-04-17 10:23:30 +02:00
|
|
|
|
2018-07-31 16:47:05 +02:00
|
|
|
show(monitorIndex, icon, label, level, maxLevel) {
|
2014-04-17 10:23:30 +02:00
|
|
|
if (monitorIndex != -1) {
|
|
|
|
for (let i = 0; i < this._osdWindows.length; i++) {
|
|
|
|
if (i == monitorIndex)
|
2018-07-31 16:47:05 +02:00
|
|
|
this._showOsdWindow(i, icon, label, level, maxLevel);
|
2014-04-17 10:23:30 +02:00
|
|
|
else
|
|
|
|
this._osdWindows[i].cancel();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (let i = 0; i < this._osdWindows.length; i++)
|
2018-07-31 16:47:05 +02:00
|
|
|
this._showOsdWindow(i, icon, label, level, maxLevel);
|
2014-04-17 10:23:30 +02:00
|
|
|
}
|
2017-10-31 02:19:44 +01:00
|
|
|
}
|
2014-04-17 10:23:30 +02:00
|
|
|
|
2017-10-31 01:03:21 +01:00
|
|
|
hideAll() {
|
2014-04-17 10:23:30 +02:00
|
|
|
for (let i = 0; i < this._osdWindows.length; i++)
|
|
|
|
this._osdWindows[i].cancel();
|
2013-03-02 10:48:25 +01:00
|
|
|
}
|
2023-07-10 02:53:00 -07:00
|
|
|
}
|