version 3, add changed signal for settings and change opacity

This commit is contained in:
JerryXiao 2021-11-01 14:36:10 +08:00
parent 2d04d3fdba
commit 3b8e8a16d7
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
8 changed files with 26 additions and 18 deletions

5
Makefile Normal file
View file

@ -0,0 +1,5 @@
schemdir = ./activate_gnome@isjerryxiao/schemas
$(schemdir)/gschemas.compiled: $(schemdir)/org.gnome.shell.extensions.activate_gnome.gschema.xml
glib-compile-schemas $(schemdir)/
clean:
rm $(schemdir)/gschemas.compiled

View file

@ -6,7 +6,7 @@ A gnome-shell extension to show 'Activate Gnome' watermark.
## Installation ## Installation
``` ```
git clone https://github.com/isjerryxiao/gnome-shell-extension-activate-gnome activate_gnome git clone https://github.com/isjerryxiao/gnome-shell-extension-activate-gnome activate_gnome
make -C activate_gnome/activate_gnome@isjerryxiao make -C activate_gnome
ln -s $(realpath activate_gnome/activate_gnome@isjerryxiao) ~/.local/share/gnome-shell/extensions/ ln -s $(realpath activate_gnome/activate_gnome@isjerryxiao) ~/.local/share/gnome-shell/extensions/
``` ```

View file

@ -1,2 +0,0 @@
./schemas/gschemas.compiled: ./schemas/org.gnome.shell.extensions.activate_gnome.gschema.xml
glib-compile-schemas ./schemas/

View file

@ -28,11 +28,18 @@ class Extension {
this.label_2 = null this.label_2 = null
this.loaded = 0 this.loaded = 0
this.settings = null this.settings = null
this.handler_id = null
} }
update() { update() {
if (this.label_1 && this.label_2) { if (this.label_1 && this.label_2) {
let [text1, text2, vl2, hl2] = this.settings 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
let monitor = Main.layoutManager.primaryMonitor let monitor = Main.layoutManager.primaryMonitor
let h = Math.floor(monitor.height * vl2 - this.label_2.height) let h = Math.floor(monitor.height * vl2 - this.label_2.height)
let w = Math.floor(monitor.width * hl2 - this.label_2.width) let w = Math.floor(monitor.width * hl2 - this.label_2.width)
@ -44,15 +51,12 @@ class Extension {
} }
} }
} }
enable() { enable() {
let settings = ExtensionUtils.getSettings(Me.metadata['settings-schema']) this.settings = ExtensionUtils.getSettings(Me.metadata['settings-schema'])
let text1 = settings.get_string('text-l1') || settings.get_default_value('text-l1').get_string() this.handler_id = this.settings.connect('changed', () => this.update())
let text2 = settings.get_string('text-l2') || settings.get_default_value('text-l2').get_string() this.label_2 = new St.Label({ style_class: 'label-2', text: '' })
let vl2 = settings.get_double('l2-vertical') || settings.get_default_value('l2-vertical').get_double() this.label_1 = new St.Label({ style_class: 'label-1', text: '' })
let hl2 = settings.get_double('l2-horizontal') || settings.get_default_value('l2-horizontal').get_double()
this.settings = [text1, text2, vl2, hl2]
this.label_2 = new St.Label({ style_class: 'label-2', text: text2 })
this.label_1 = new St.Label({ style_class: 'label-1', text: text1 })
Main.layoutManager.addTopChrome(this.label_2, {"trackFullscreen": false}) Main.layoutManager.addTopChrome(this.label_2, {"trackFullscreen": false})
Main.layoutManager.addTopChrome(this.label_1, {"trackFullscreen": false}) Main.layoutManager.addTopChrome(this.label_1, {"trackFullscreen": false})
this.update() this.update()
@ -65,7 +69,9 @@ class Extension {
this.label_2.destroy() this.label_2.destroy()
this.label_1 = null this.label_1 = null
this.label_2 = null this.label_2 = null
this.settings.disconnect(this.handler_id)
this.settings = null this.settings = null
this.handler_id = null
} }
} }

View file

@ -1,5 +1,5 @@
{ {
"name": "activate_gnome", "name": "Activate Gnome",
"description": "Shows Activate Gnome watermark on your screen.", "description": "Shows Activate Gnome watermark on your screen.",
"uuid": "activate_gnome@isjerryxiao", "uuid": "activate_gnome@isjerryxiao",
"settings-schema": "org.gnome.shell.extensions.activate_gnome", "settings-schema": "org.gnome.shell.extensions.activate_gnome",
@ -7,6 +7,6 @@
"40", "40",
"41" "41"
], ],
"version": 2, "version": 3,
"url": "https://github.com/isjerryxiao/gnome-shell-extension-activate-gnome" "url": "https://github.com/isjerryxiao/gnome-shell-extension-activate-gnome"
} }

View file

@ -4,7 +4,6 @@ const Gtk = imports.gi.Gtk
const ExtensionUtils = imports.misc.extensionUtils const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension() const Me = ExtensionUtils.getCurrentExtension()
function init() { function init() {
} }

View file

@ -15,7 +15,7 @@
<summary>Vertical position of line 2</summary> <summary>Vertical position of line 2</summary>
</key> </key>
<key name="l2-horizontal" type="d"> <key name="l2-horizontal" type="d">
<default>0.9</default> <default>0.92</default>
<summary>Horizontal position of line 2</summary> <summary>Horizontal position of line 2</summary>
</key> </key>
</schema> </schema>

View file

@ -2,14 +2,14 @@
.label-1 { .label-1 {
font-size: 36px; font-size: 36px;
font-weight: normal; font-weight: normal;
color: rgba(255, 255, 255, 0.3); color: rgba(255, 255, 255, 0.4);
background-color: rgba(10, 10, 10, 0); background-color: rgba(10, 10, 10, 0);
border-radius: 5px; border-radius: 5px;
} }
.label-2 { .label-2 {
font-size: 26px; font-size: 26px;
font-weight: normal; font-weight: normal;
color: rgba(255, 255, 255, 0.3); color: rgba(255, 255, 255, 0.4);
background-color: rgba(10, 10, 10, 0); background-color: rgba(10, 10, 10, 0);
border-radius: 5px; border-radius: 5px;
} }