add back settings && update readme

This commit is contained in:
JerryXiao 2021-10-31 20:36:34 +08:00
parent c76ee0036f
commit 335c5765c1
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
7 changed files with 176 additions and 22 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
activate_gnome@isjerryxiao/schemas/gschemas.compiled

View file

@ -3,5 +3,12 @@
A gnome-shell extension to show 'Activate Gnome' watermark.
## Installation
```
git clone https://github.com/isjerryxiao/gnome-shell-extension-activate-gnome activate_gnome
make -C activate_gnome/activate_gnome@isjerryxiao
ln -s $(realpath activate_gnome/activate_gnome@isjerryxiao) ~/.local/share/gnome-shell/extensions/
```
## Contributing
* Copyright © 2021 JerryXiao

View file

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

View file

@ -2,7 +2,7 @@
*
* 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
* the Free Software Foundation, either version 2 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@ -11,14 +11,14 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
* SPDX-License-Identifier: GPL-3.0-or-later
* /
/* exported init */
const St = imports.gi.St;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;
const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()
@ -26,20 +26,33 @@ class Extension {
constructor() {
this.label_1 = null
this.label_2 = null
this.loaded = 0
this.settings = null
}
update() {
if (this.label_1 && this.label_2) {
let [text1, text2, vl2, hl2] = this.settings
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)
if (this.loaded++ < 4) Mainloop.timeout_add(1000, () => this.update())
}
}
enable() {
let text1 = "Activate Gnome";
let text2 = "Go to Settings to activate Gnome."
this.label_1 = new St.Label({ style_class: 'label-1', text: text1 })
let settings = ExtensionUtils.getSettings(Me.metadata['settings-schema'])
let text1 = settings.get_string('text-l1') || settings.get_default().get_string('text-l1')
let text2 = settings.get_string('text-l2') || settings.get_default().get_string('text-l2')
let vl2 = settings.get_double('l2-vertical') || settings.get_default().get_double('l2-vertical')
let hl2 = settings.get_double('l2-horizontal') || settings.get_default().get_double('l2-horizontal')
this.settings = [text1, text2, vl2, hl2]
this.label_2 = new St.Label({ style_class: 'label-2', text: text2 })
let monitor = Main.layoutManager.primaryMonitor
this.label_1 = new St.Label({ style_class: 'label-1', text: text1 })
Main.layoutManager.addTopChrome(this.label_2, {"trackFullscreen": false})
let h = Math.floor(monitor.height / 18 * 17 - this.label_2.height)
let w = Math.floor(monitor.width / 10 * 9 - this.label_2.width)
this.label_2.set_position(w, h)
Main.layoutManager.addTopChrome(this.label_1, {"trackFullscreen": false})
this.label_1.set_position(w, h - this.label_1.height)
this.update()
}
disable() {
@ -49,9 +62,11 @@ class Extension {
this.label_2.destroy()
this.label_1 = null
this.label_2 = null
this.settings = null
}
}
function init() {
log(`initializing ${Me.metadata.name}`);
return new Extension()
}

View file

@ -1,11 +1,12 @@
{
"name": "activate_gnome",
"description": "Shows Activate Gnome watermark on your screen.",
"uuid": "activate_gnome@isjerryxiao",
"shell-version": [
"40",
"41"
],
"version": 1,
"url": "https://github.com/isjerryxiao/activate_gnome"
"name": "activate_gnome",
"description": "Shows Activate Gnome watermark on your screen.",
"uuid": "activate_gnome@isjerryxiao",
"settings-schema": "org.gnome.shell.extensions.activate_gnome",
"shell-version": [
"40",
"41"
],
"version": 1,
"url": "https://github.com/isjerryxiao/activate_gnome"
}

View file

@ -0,0 +1,106 @@
const Gio = imports.gi.Gio
const Gtk = imports.gi.Gtk
const ExtensionUtils = imports.misc.extensionUtils
const Me = ExtensionUtils.getCurrentExtension()
function init() {
}
function buildPrefsWidget() {
this.settings = ExtensionUtils.getSettings(Me.metadata['settings-schema'])
let prefsWidget = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
halign: Gtk.Align.CENTER,
spacing: 6,
margin_top: 12,
margin_bottom: 12,
margin_start: 6,
margin_end: 6,
})
// line 1
let l1label = new Gtk.Label({
label: '<b>Line 1</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(l1label)
let l1entry = new Gtk.Entry({
margin_top: 6,
hexpand: true,
})
l1entry.set_width_chars(30)
prefsWidget.append(l1entry)
// line 2
let l2label = new Gtk.Label({
label: '<b>Line 2</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(l2label)
let l2entry = new Gtk.Entry({
margin_top: 6,
hexpand: true,
})
l2entry.set_width_chars(30)
prefsWidget.append(l2entry)
// l2-vertical
let vlabel = new Gtk.Label({
label: '<b>Vertical Position</b>',
margin_top: 12,
use_markup: true,
})
prefsWidget.append(vlabel)
let ventry = new Gtk.SpinButton({
margin_top: 6,
numeric: true,
digits: 4,
})
ventry.set_range(0.0, 1.0)
ventry.set_increments(0.01, 0.1)
prefsWidget.append(ventry)
// l2-horizontal
let hlabel = new Gtk.Label({
label: '<b>Horizontal Position</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(hlabel)
let hentry = new Gtk.SpinButton({
margin_top: 6,
numeric: true,
digits: 4,
})
hentry.set_range(0.0, 1.0)
hentry.set_increments(0.01, 0.1)
prefsWidget.append(hentry)
let resetbtn = new Gtk.Button({
label: 'reset',
margin_top: 12,
})
resetbtn.connect('clicked', () => {
this.settings.reset('text-l1')
this.settings.reset('text-l2')
this.settings.reset('l2-vertical')
this.settings.reset('l2-horizontal')
})
prefsWidget.append(resetbtn)
this.settings.bind('text-l1', l1entry, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('text-l2', l2entry, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-vertical', ventry, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-horizontal', hentry, 'value', Gio.SettingsBindFlags.DEFAULT)
return prefsWidget
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="activate_gnome">
<schema id="org.gnome.shell.extensions.activate_gnome" path="/org/gnome/shell/extensions/activate_gnome/">
<!-- See also: https://developer.gnome.org/glib/stable/gvariant-format-strings.html -->
<key name="text-l1" type="s">
<default>'Activate Gnome'</default>
<summary>Text to display on line 1</summary>
</key>
<key name="text-l2" type="s">
<default>'Go to Settings to activate Gnome.'</default>
<summary>Text to display on line 2</summary>
</key>
<key name="l2-vertical" type="d">
<default>0.9444444444444444</default>
<summary>Vertical position of line 2</summary>
</key>
<key name="l2-horizontal" type="d">
<default>0.9</default>
<summary>Horizontal position of line 2</summary>
</key>
</schema>
</schemalist>