2021-10-29 20:12:14 +08:00
|
|
|
/* extension.js
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2021-10-31 20:36:34 +08:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2021-10-29 20:12:14 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-10-31 20:36:34 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2021-10-29 20:12:14 +08:00
|
|
|
*
|
2021-10-31 20:36:34 +08:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
* /
|
2021-10-29 20:12:14 +08:00
|
|
|
/* exported init */
|
2021-10-31 21:40:24 +08:00
|
|
|
const St = imports.gi.St
|
|
|
|
const Main = imports.ui.main
|
|
|
|
const Mainloop = imports.mainloop
|
2021-10-29 20:12:14 +08:00
|
|
|
const ExtensionUtils = imports.misc.extensionUtils
|
|
|
|
const Me = ExtensionUtils.getCurrentExtension()
|
|
|
|
|
|
|
|
class Extension {
|
|
|
|
constructor() {
|
2022-03-14 14:39:56 +08:00
|
|
|
this.labels = []
|
2021-10-31 20:36:34 +08:00
|
|
|
this.settings = null
|
2022-03-19 22:28:36 +08:00
|
|
|
this.handlers = []
|
2022-03-20 18:13:49 +08:00
|
|
|
this.settings_get = (method, key) => this.settings[method](key) || this.settings.get_default_value(key)[method]()
|
2021-10-29 20:12:14 +08:00
|
|
|
}
|
|
|
|
|
2021-10-31 20:36:34 +08:00
|
|
|
update() {
|
2022-03-20 18:13:49 +08:00
|
|
|
let text1 = this.settings_get('get_string', 'text-l1')
|
|
|
|
let text2 = this.settings_get('get_string', 'text-l2')
|
|
|
|
let vl2 = this.settings_get('get_double', 'l2-vertical')
|
|
|
|
let hl2 = this.settings_get('get_double', 'l2-horizontal')
|
|
|
|
let opacity = this.settings_get('get_double', 'opacity')
|
2022-03-14 14:39:56 +08:00
|
|
|
|
|
|
|
this.cleanup()
|
|
|
|
for (let monitor of Main.layoutManager.monitors) {
|
2022-03-19 22:28:36 +08:00
|
|
|
let label_1 = new St.Label({style_class: 'label-1', text: text1, opacity})
|
|
|
|
let label_2 = new St.Label({style_class: 'label-2', text: text2, opacity})
|
2022-06-07 18:13:53 +08:00
|
|
|
Main.layoutManager.uiGroup.add_actor(label_2, {"trackFullscreen": false})
|
|
|
|
Main.layoutManager.uiGroup.add_actor(label_1, {"trackFullscreen": false})
|
2022-03-14 14:39:56 +08:00
|
|
|
this.labels.push(label_1)
|
|
|
|
this.labels.push(label_2)
|
|
|
|
let h = Math.max(0, Math.floor(monitor.height * vl2 - label_2.height))
|
|
|
|
let w = Math.max(0, Math.floor(monitor.width * hl2 - label_2.width))
|
|
|
|
label_2.set_position(monitor.x + w, monitor.y + h)
|
2022-03-19 15:45:05 +08:00
|
|
|
label_1.set_position(Math.min(monitor.x + w, monitor.x + monitor.width - label_1.width), monitor.y + h - label_1.height)
|
2021-10-31 20:36:34 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-01 14:36:10 +08:00
|
|
|
|
2022-03-14 14:39:56 +08:00
|
|
|
cleanup() {
|
|
|
|
for (let label of this.labels) {
|
2022-06-07 18:13:53 +08:00
|
|
|
Main.layoutManager.uiGroup.remove_actor(label)
|
2022-03-14 14:39:56 +08:00
|
|
|
label.destroy()
|
|
|
|
}
|
|
|
|
this.labels = []
|
|
|
|
}
|
|
|
|
|
2022-03-19 22:28:36 +08:00
|
|
|
enable() {
|
|
|
|
this.settings = ExtensionUtils.getSettings(Me.metadata['settings-schema'])
|
|
|
|
this.handlers.push({
|
|
|
|
owner: this.settings,
|
|
|
|
id: this.settings.connect('changed', () => this.update())
|
|
|
|
})
|
|
|
|
this.handlers.push({
|
|
|
|
owner: Main.layoutManager,
|
|
|
|
id: Main.layoutManager.connect('monitors-changed', () => this.update())
|
|
|
|
})
|
|
|
|
this.handlers.push({
|
|
|
|
owner: Main.layoutManager,
|
|
|
|
id: Main.layoutManager.connect('startup-complete', () => this.update())
|
|
|
|
})
|
2022-03-20 18:13:49 +08:00
|
|
|
if (!Main.layoutManager._startingUp) this.update()
|
2022-03-19 22:28:36 +08:00
|
|
|
}
|
|
|
|
|
2021-10-29 20:12:14 +08:00
|
|
|
disable() {
|
2022-03-14 14:39:56 +08:00
|
|
|
this.cleanup()
|
2022-03-19 22:28:36 +08:00
|
|
|
for (let handler of this.handlers) {
|
|
|
|
handler.owner.disconnect(handler.id)
|
|
|
|
}
|
|
|
|
this.handlers = []
|
2021-10-31 20:36:34 +08:00
|
|
|
this.settings = null
|
2021-10-29 20:12:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
2021-10-31 21:40:24 +08:00
|
|
|
log(`initializing ${Me.metadata.name}`)
|
2021-10-29 20:12:14 +08:00
|
|
|
return new Extension()
|
|
|
|
}
|