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() {
|
|
|
|
this.label_1 = null
|
|
|
|
this.label_2 = null
|
2021-10-31 20:36:34 +08:00
|
|
|
this.loaded = 0
|
|
|
|
this.settings = null
|
2021-11-01 14:36:10 +08:00
|
|
|
this.handler_id = null
|
2021-10-29 20:12:14 +08:00
|
|
|
}
|
|
|
|
|
2021-10-31 20:36:34 +08:00
|
|
|
update() {
|
|
|
|
if (this.label_1 && this.label_2) {
|
2021-11-01 14:36:10 +08:00
|
|
|
let settings = this.settings
|
|
|
|
let text1 = settings.get_string('text-l1') || settings.get_default_value('text-l1').get_string()
|
|
|
|
let text2 = settings.get_string('text-l2') || settings.get_default_value('text-l2').get_string()
|
|
|
|
let vl2 = settings.get_double('l2-vertical') || settings.get_default_value('l2-vertical').get_double()
|
|
|
|
let hl2 = settings.get_double('l2-horizontal') || settings.get_default_value('l2-horizontal').get_double()
|
|
|
|
this.label_1.text = text1
|
|
|
|
this.label_2.text = text2
|
2021-10-31 20:36:34 +08:00
|
|
|
let monitor = Main.layoutManager.primaryMonitor
|
|
|
|
let h = Math.floor(monitor.height * vl2 - this.label_2.height)
|
|
|
|
let w = Math.floor(monitor.width * hl2 - this.label_2.width)
|
|
|
|
this.label_2.set_position(w, h)
|
|
|
|
this.label_1.set_position(w, h - this.label_1.height)
|
2021-10-31 21:40:24 +08:00
|
|
|
if (this.loaded < 4) {
|
|
|
|
this.loaded++
|
|
|
|
Mainloop.timeout_add(1000, () => this.update())
|
|
|
|
}
|
2021-10-31 20:36:34 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-01 14:36:10 +08:00
|
|
|
|
2021-10-29 20:12:14 +08:00
|
|
|
enable() {
|
2021-11-01 14:36:10 +08:00
|
|
|
this.settings = ExtensionUtils.getSettings(Me.metadata['settings-schema'])
|
|
|
|
this.handler_id = this.settings.connect('changed', () => this.update())
|
|
|
|
this.label_2 = new St.Label({ style_class: 'label-2', text: '' })
|
|
|
|
this.label_1 = new St.Label({ style_class: 'label-1', text: '' })
|
2021-10-29 20:12:14 +08:00
|
|
|
Main.layoutManager.addTopChrome(this.label_2, {"trackFullscreen": false})
|
|
|
|
Main.layoutManager.addTopChrome(this.label_1, {"trackFullscreen": false})
|
2021-10-31 20:36:34 +08:00
|
|
|
this.update()
|
2021-10-29 20:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
|
|
|
Main.layoutManager.removeChrome(this.label_1)
|
|
|
|
Main.layoutManager.removeChrome(this.label_2)
|
|
|
|
this.label_1.destroy()
|
|
|
|
this.label_2.destroy()
|
|
|
|
this.label_1 = null
|
|
|
|
this.label_2 = null
|
2021-11-01 14:36:10 +08:00
|
|
|
this.settings.disconnect(this.handler_id)
|
2021-10-31 20:36:34 +08:00
|
|
|
this.settings = null
|
2021-11-01 14:36:10 +08:00
|
|
|
this.handler_id = 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()
|
|
|
|
}
|