🎉 Add minitiature settings dialog
This commit is contained in:
+15
-4
@@ -34,16 +34,25 @@ class Extension {
|
|||||||
// from GNOME Tweaks, when you log in or when the screen is unlocked.
|
// from GNOME Tweaks, when you log in or when the screen is unlocked.
|
||||||
enable() {
|
enable() {
|
||||||
|
|
||||||
imports.ui.windowManager.DESTROY_WINDOW_ANIMATION_TIME = 2000;
|
|
||||||
|
|
||||||
// Store a reference to the settings object.
|
// Store a reference to the settings object.
|
||||||
// this._settings = ExtensionUtils.getSettings();
|
this._settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
// We will monkey-patch these three methods. Let's store the original ones.
|
// We will monkey-patch these three methods. Let's store the original ones.
|
||||||
this._origWindowRemoved = Workspace.prototype._windowRemoved;
|
this._origWindowRemoved = Workspace.prototype._windowRemoved;
|
||||||
this._origDoRemoveWindow = Workspace.prototype._doRemoveWindow;
|
this._origDoRemoveWindow = Workspace.prototype._doRemoveWindow;
|
||||||
this._origShouldAnimateActor = WindowManager.prototype._shouldAnimateActor;
|
this._origShouldAnimateActor = WindowManager.prototype._shouldAnimateActor;
|
||||||
|
|
||||||
|
// We may also override these animation times.
|
||||||
|
this._origDestroyTime = imports.ui.windowManager.DESTROY_WINDOW_ANIMATION_TIME;
|
||||||
|
|
||||||
|
const loadAnimationTimes = () => {
|
||||||
|
imports.ui.windowManager.DESTROY_WINDOW_ANIMATION_TIME =
|
||||||
|
this._settings.get_int('destroy-animation-time');
|
||||||
|
};
|
||||||
|
|
||||||
|
this._settings.connect('changed::destroy-animation-time', loadAnimationTimes);
|
||||||
|
loadAnimationTimes();
|
||||||
|
|
||||||
// We will use extensionThis to refer to the extension inside the patched methods of
|
// We will use extensionThis to refer to the extension inside the patched methods of
|
||||||
// the WorkspacesView.
|
// the WorkspacesView.
|
||||||
const extensionThis = this;
|
const extensionThis = this;
|
||||||
@@ -210,7 +219,9 @@ class Extension {
|
|||||||
Workspace.prototype._doRemoveWindow = this._origDoRemoveWindow;
|
Workspace.prototype._doRemoveWindow = this._origDoRemoveWindow;
|
||||||
WindowManager.prototype._shouldAnimateActor = this._origShouldAnimateActor;
|
WindowManager.prototype._shouldAnimateActor = this._origShouldAnimateActor;
|
||||||
|
|
||||||
// this._settings = null;
|
imports.ui.windowManager.DESTROY_WINDOW_ANIMATION_TIME = this._origDestroyTime;
|
||||||
|
|
||||||
|
this._settings = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- private stuff
|
// ----------------------------------------------------------------------- private stuff
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ) ( //
|
||||||
|
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
|
||||||
|
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
|
||||||
|
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
|
||||||
|
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
|
||||||
|
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
|
||||||
|
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
|
||||||
|
// |__/ //
|
||||||
|
// Copyright (c) 2021 Simon Schneegans //
|
||||||
|
// Released under the GPLv3 or later. See LICENSE file for details. //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const {Gio, Gtk} = imports.gi;
|
||||||
|
|
||||||
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
|
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
||||||
|
const utils = Me.imports.utils;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// For now, the preferences dialog of this extension is very simple. In the future, if //
|
||||||
|
// we might consider to improve its layout... //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var PreferencesDialog = class PreferencesDialog {
|
||||||
|
// ------------------------------------------------------------ constructor / destructor
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
// Load all of our resources.
|
||||||
|
this._resources = Gio.Resource.load(Me.path + '/resources/burn-my-windows.gresource');
|
||||||
|
Gio.resources_register(this._resources);
|
||||||
|
|
||||||
|
// Load the user interface file.
|
||||||
|
this._builder = new Gtk.Builder();
|
||||||
|
this._builder.add_from_resource(`/ui/settings.ui`);
|
||||||
|
|
||||||
|
// This is our top-level widget which we will return later.
|
||||||
|
this._widget = this._builder.get_object('settings-widget');
|
||||||
|
|
||||||
|
// Store a reference to the settings object.
|
||||||
|
this._settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
|
// Bind all properties.
|
||||||
|
this._bindAdjustment('destroy-animation-time');
|
||||||
|
|
||||||
|
// As we do not have something like a destructor, we just listen for the destroy
|
||||||
|
// signal of our main widget.
|
||||||
|
this._widget.connect('destroy', () => {
|
||||||
|
// Unregister our resources.
|
||||||
|
Gio.resources_unregister(this._resources);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------- public interface
|
||||||
|
|
||||||
|
// Returns the widget used for the settings of this extension.
|
||||||
|
getWidget() {
|
||||||
|
return this._widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- private stuff
|
||||||
|
|
||||||
|
// Connects a Gtk.Adjustment (or anything else which has a 'value' property) to a
|
||||||
|
// settings key. It also binds the corresponding reset button.
|
||||||
|
_bindAdjustment(settingsKey) {
|
||||||
|
this._bind(settingsKey, 'value');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connects a Gtk.Switch (or anything else which has an 'active' property) to a settings
|
||||||
|
// key. It also binds the corresponding reset button.
|
||||||
|
_bindSwitch(settingsKey) {
|
||||||
|
this._bind(settingsKey, 'active');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connects any widget's property to a settings key. The widget must have the same ID as
|
||||||
|
// the settings key. It also binds the corresponding reset button.
|
||||||
|
_bind(settingsKey, property) {
|
||||||
|
this._settings.bind(
|
||||||
|
settingsKey, this._builder.get_object(settingsKey), property,
|
||||||
|
Gio.SettingsBindFlags.DEFAULT);
|
||||||
|
|
||||||
|
const resetButton = this._builder.get_object('reset-' + settingsKey);
|
||||||
|
resetButton.connect('clicked', () => {
|
||||||
|
this._settings.reset(settingsKey);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing to do for now...
|
||||||
|
function init() {}
|
||||||
|
|
||||||
|
// This function is called when the preferences window is created to build and return a
|
||||||
|
// Gtk widget. We create a new instance of the PreferencesDialog class each time this
|
||||||
|
// method is called. This way we can actually open multiple settings windows and interact
|
||||||
|
// with all of them properly.
|
||||||
|
function buildPrefsWidget() {
|
||||||
|
var dialog = new PreferencesDialog();
|
||||||
|
return dialog.getWidget();
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface domain="desktop-cube">
|
||||||
|
<requires lib="gtk" version="4.0" />
|
||||||
|
|
||||||
|
<object class="GtkScrolledWindow" id="settings-widget">
|
||||||
|
<property name="hscrollbar-policy">never</property>
|
||||||
|
<property name="min-content-height">200</property>
|
||||||
|
<property name="hexpand">0</property>
|
||||||
|
<property name="vexpand">1</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkViewport">
|
||||||
|
<property name="scroll-to-focus">1</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="margin-start">60</property>
|
||||||
|
<property name="margin-end">60</property>
|
||||||
|
<property name="margin-top">30</property>
|
||||||
|
<property name="margin-bottom">30</property>
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="margin-top">30</property>
|
||||||
|
<property name="margin-bottom">10</property>
|
||||||
|
<property name="label">Fire Options</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
<style>
|
||||||
|
<class name="title-4" />
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame">
|
||||||
|
<child>
|
||||||
|
<object class="GtkListBox">
|
||||||
|
<property name="selection-mode">none</property>
|
||||||
|
<property name="show-separators">1</property>
|
||||||
|
<style>
|
||||||
|
<class name="rich-list" />
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<object class="GtkListBoxRow">
|
||||||
|
<property name="activatable">0</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="label" translatable="yes">Animation Time [ms]</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
<property name="halign">start</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="hexpand">1</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScale">
|
||||||
|
<property name="halign">end</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="draw-value">1</property>
|
||||||
|
<property name="digits">0</property>
|
||||||
|
<property name="value-pos">left</property>
|
||||||
|
<property name="width-request">250</property>
|
||||||
|
<property name="adjustment">
|
||||||
|
<object class="GtkAdjustment" id="destroy-animation-time">
|
||||||
|
<property name="upper">10000</property>
|
||||||
|
<property name="lower">500</property>
|
||||||
|
<property name="step-increment">10</property>
|
||||||
|
<property name="page-increment">100</property>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="reset-destroy-animation-time">
|
||||||
|
<property name="icon-name">edit-clear-symbolic</property>
|
||||||
|
<property name="tooltip-text">Reset to Default Value</property>
|
||||||
|
<style>
|
||||||
|
<class name="flat" />
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
|
||||||
|
</interface>
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<schemalist>
|
<schemalist>
|
||||||
|
|
||||||
<schema path="/org/gnome/shell/extensions/burn-my-windows/" id="org.gnome.shell.extensions.burn-my-windows"></schema>
|
<schema path="/org/gnome/shell/extensions/burn-my-windows/" id="org.gnome.shell.extensions.burn-my-windows">
|
||||||
|
|
||||||
|
<key name="destroy-animation-time" type="i">
|
||||||
|
<default>2000</default>
|
||||||
|
<summary>Destroy Animation Time</summary>
|
||||||
|
<description>The time it takes to burn the windows.</description>
|
||||||
|
</key>
|
||||||
|
|
||||||
|
</schema>
|
||||||
|
|
||||||
</schemalist>
|
</schemalist>
|
||||||
Reference in New Issue
Block a user