From c81316bfe988b4e599c6c7f43c313cb26d208d0c Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sat, 8 Jan 2022 21:30:12 +0100 Subject: [PATCH] :hammer: Split prefs in separate classes --- prefs.js | 231 ++---------------- resources/ui/gtk3/{fire.ui => firePage.ui} | 72 +++++- resources/ui/gtk3/generalPage.ui | 129 ++++++++++ resources/ui/gtk3/prefs.ui | 195 +-------------- resources/ui/gtk3/{tv.ui => tvPage.ui} | 56 +++++ resources/ui/gtk4/{fire.ui => firePage.ui} | 58 ++++- resources/ui/gtk4/generalPage.ui | 115 +++++++++ .../ui/gtk4/{matrix.ui => matrixPage.ui} | 46 ++++ resources/ui/gtk4/prefs.ui | 181 +------------- resources/ui/gtk4/{trex.ui => trexPage.ui} | 46 ++++ resources/ui/gtk4/tv.ui | 63 ----- resources/ui/gtk4/tvPage.ui | 109 +++++++++ ...ell.extensions.burn-my-windows.gschema.xml | 102 +++++--- src/prefs/FirePage.js | 165 +++++++++++++ src/prefs/GeneralPage.js | 43 ++++ src/prefs/MatrixPage.js | 56 +++++ src/prefs/PrefsPage.js | 102 ++++++++ src/prefs/TRexPage.js | 56 +++++ src/prefs/TVEffectPage.js | 54 ++++ 19 files changed, 1187 insertions(+), 692 deletions(-) rename resources/ui/gtk3/{fire.ui => firePage.ui} (81%) create mode 100644 resources/ui/gtk3/generalPage.ui rename resources/ui/gtk3/{tv.ui => tvPage.ui} (50%) rename resources/ui/gtk4/{fire.ui => firePage.ui} (80%) create mode 100644 resources/ui/gtk4/generalPage.ui rename resources/ui/gtk4/{matrix.ui => matrixPage.ui} (78%) rename resources/ui/gtk4/{trex.ui => trexPage.ui} (79%) delete mode 100644 resources/ui/gtk4/tv.ui create mode 100644 resources/ui/gtk4/tvPage.ui create mode 100644 src/prefs/FirePage.js create mode 100644 src/prefs/GeneralPage.js create mode 100644 src/prefs/MatrixPage.js create mode 100644 src/prefs/PrefsPage.js create mode 100644 src/prefs/TRexPage.js create mode 100644 src/prefs/TVEffectPage.js diff --git a/prefs.js b/prefs.js index d74b6ce..87273f3 100644 --- a/prefs.js +++ b/prefs.js @@ -19,12 +19,19 @@ const ExtensionUtils = imports.misc.extensionUtils; const Me = imports.misc.extensionUtils.getCurrentExtension(); const utils = Me.imports.src.common.utils; +const FirePage = Me.imports.src.prefs.FirePage.FirePage; +const MatrixPage = Me.imports.src.prefs.MatrixPage.MatrixPage; +const TVEffectPage = Me.imports.src.prefs.TVEffectPage.TVEffectPage; +const TRexPage = Me.imports.src.prefs.TRexPage.TRexPage; +const GeneralPage = Me.imports.src.prefs.GeneralPage.GeneralPage; + ////////////////////////////////////////////////////////////////////////////////////////// // 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() { @@ -39,54 +46,16 @@ var PreferencesDialog = class PreferencesDialog { this._builder = new Gtk.Builder(); this._builder.add_from_resource(`/ui/common/main-menu.ui`); this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/prefs.ui`); - this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/fire.ui`); - this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/matrix.ui`); - this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/tv.ui`); - this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/trex.ui`); + + this._generalPage = new GeneralPage(this._settings, this._builder); + this._firePage = new FirePage(this._settings, this._builder); + this._matrixPage = new MatrixPage(this._settings, this._builder); + this._tvEffectPage = new TVEffectPage(this._settings, this._builder); + this._trexPage = new TRexPage(this._settings, this._builder); // This is our top-level widget which we will return later. this._widget = this._builder.get_object('settings-widget'); - const stack = this._builder.get_object('main-stack'); - stack.add_titled(this._builder.get_object('fire-prefs'), 'fire', 'Fire'); - stack.add_titled(this._builder.get_object('matrix-prefs'), 'matrix', 'Matrix'); - stack.add_titled(this._builder.get_object('trex-prefs'), 'trex', 'T-Rex Attack'); - stack.add_titled(this._builder.get_object('tv-prefs'), 'tv', 'TV Effect'); - - // Bind all properties. - this._bindCombobox('close-animation'); - this._bindAdjustment('destroy-animation-time'); - this._bindSwitch('destroy-dialogs'); - this._bindAdjustment('flame-movement-speed'); - this._bindAdjustment('flame-scale'); - this._bindSwitch('flame-3d-noise'); - this._bindColorButton('fire-color-1'); - this._bindColorButton('fire-color-2'); - this._bindColorButton('fire-color-3'); - this._bindColorButton('fire-color-4'); - this._bindColorButton('fire-color-5'); - this._bindAdjustment('matrix-scale'); - this._bindAdjustment('matrix-randomness'); - this._bindColorButton('matrix-trail-color'); - this._bindColorButton('matrix-tip-color'); - this._bindColorButton('tv-effect-color'); - this._bindColorButton('claw-scratch-color'); - this._bindAdjustment('claw-scratch-scale'); - this._bindAdjustment('claw-scratch-count'); - this._bindAdjustment('claw-scratch-warp'); - - // The fire-gradient-reset button needs to be bound explicitly. - this._builder.get_object('reset-fire-colors').connect('clicked', () => { - this._settings.reset('fire-color-1'); - this._settings.reset('fire-color-2'); - this._settings.reset('fire-color-3'); - this._settings.reset('fire-color-4'); - this._settings.reset('fire-color-5'); - }); - - // Initialize the fire-preset dropdown. - this._createFirePresets(); - // Add a menu to the title bar of the preferences dialog. this._widget.connect('realize', (widget) => { const window = utils.isGTK4() ? widget.get_root() : widget.get_toplevel(); @@ -107,15 +76,13 @@ var PreferencesDialog = class PreferencesDialog { group.add_action(action); }; - addAction('homepage', 'https://github.com/Schneegans/Burn-My-Windows'); - addAction( - 'changelog', - 'https://github.com/Schneegans/Burn-My-Windows/blob/main/docs/changelog.md'); - addAction('bugs', 'https://github.com/Schneegans/Burn-My-Windows/issues'); - addAction( - 'donate-paypal', - 'https://www.paypal.com/donate/?hosted_button_id=3F7UFL8KLVPXE'); + // clang-format off + addAction('homepage', 'https://github.com/Schneegans/Burn-My-Windows'); + addAction('changelog', 'https://github.com/Schneegans/Burn-My-Windows/blob/main/docs/changelog.md'); + addAction('bugs', 'https://github.com/Schneegans/Burn-My-Windows/issues'); + addAction('donate-paypal', 'https://www.paypal.com/donate/?hosted_button_id=3F7UFL8KLVPXE'); addAction('donate-github', 'https://github.com/sponsors/Schneegans'); + // clang-format on window.insert_action_group('prefs', group); }); @@ -139,166 +106,6 @@ var PreferencesDialog = class PreferencesDialog { getWidget() { return this._widget; } - - // ----------------------------------------------------------------------- private stuff - - // Connects a Gtk.ComboBox (or anything else which has an 'active-id' property) to a - // settings key. It also binds the corresponding reset button. - _bindCombobox(settingsKey) { - this._bind(settingsKey, 'active-id'); - } - - // 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'); - } - - // Colors are stored as strings like 'rgb(1, 0.5, 0)'. As Gio.Settings.bind_with_mapping - // is not available yet, we need to do the color conversion manually. It also binds the - // corresponding reset button. - _bindColorButton(settingsKey) { - - const button = this._builder.get_object(settingsKey); - - if (button) { - - // Update the settings when the color is modified. - button.connect('color-set', () => { - this._settings.set_string(settingsKey, button.get_rgba().to_string()); - }); - - // Update the button state when the settings change. - const settingSignalHandler = () => { - const rgba = new Gdk.RGBA(); - rgba.parse(this._settings.get_string(settingsKey)); - button.rgba = rgba; - }; - - this._settings.connect('changed::' + settingsKey, settingSignalHandler); - - // Initialize the button with the state in the settings. - settingSignalHandler(); - } - - this._bindResetButton(settingsKey); - } - - // 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) { - const object = this._builder.get_object(settingsKey); - - if (object) { - this._settings.bind(settingsKey, object, property, Gio.SettingsBindFlags.DEFAULT); - } - - this._bindResetButton(settingsKey); - } - - // Searches for a reset button for the given settings key and make it reset the settings - // key when clicked. - _bindResetButton(settingsKey) { - const resetButton = this._builder.get_object('reset-' + settingsKey); - if (resetButton) { - resetButton.connect('clicked', () => { - this._settings.reset(settingsKey); - }); - } - } - - // This populates the preset dropdown menu for the fire options. - _createFirePresets() { - this._widget.connect('realize', (widget) => { - const presets = [ - { - name: 'Default Fire', - scale: 1.0, - speed: 0.5, - color1: 'rgba(76, 51, 25, 0.0)', - color2: 'rgba(180, 55, 30, 0.7)', - color3: 'rgba(255, 76, 38, 0.9)', - color4: 'rgba(255, 166, 25, 1)', - color5: 'rgba(255, 255, 255, 1)' - }, - { - name: 'Hell Fire', - scale: 1.5, - speed: 0.2, - color1: 'rgba(0,0,0,0)', - color2: 'rgba(103,7,80,0.5)', - color3: 'rgba(150,0,24,0.9)', - color4: 'rgb(255,200,0)', - color5: 'rgba(255, 255, 255, 1)' - }, - { - name: 'Dark and Smutty', - scale: 1.0, - speed: 0.5, - color1: 'rgba(0,0,0,0)', - color2: 'rgba(36,3,0,0.5)', - color3: 'rgba(150,0,24,0.9)', - color4: 'rgb(255,177,21)', - color5: 'rgb(255,238,166)' - }, - { - name: 'Cold Breeze', - scale: 1.5, - speed: -0.1, - color1: 'rgba(0,110,255,0)', - color2: 'rgba(30,111,180,0.24)', - color3: 'rgba(38,181,255,0.54)', - color4: 'rgba(34,162,255,0.84)', - color5: 'rgb(97,189,255)' - }, - { - name: 'Santa is Coming', - scale: 0.4, - speed: -0.5, - color1: 'rgba(0,110,255,0)', - color2: 'rgba(208,233,255,0.24)', - color3: 'rgba(207,235,255,0.84)', - color4: 'rgb(208,243,255)', - color5: 'rgb(255,255,255)' - } - ]; - - const menu = Gio.Menu.new(); - const group = Gio.SimpleActionGroup.new(); - const groupName = 'presets'; - - // Add all presets. - presets.forEach((preset, i) => { - const actionName = 'fire' + i; - menu.append(preset.name, groupName + '.' + actionName); - let action = Gio.SimpleAction.new(actionName, null); - - // Load the preset on activation. - action.connect('activate', () => { - this._settings.set_double('flame-movement-speed', preset.speed); - this._settings.set_double('flame-scale', preset.scale); - this._settings.set_string('fire-color-1', preset.color1); - this._settings.set_string('fire-color-2', preset.color2); - this._settings.set_string('fire-color-3', preset.color3); - this._settings.set_string('fire-color-4', preset.color4); - this._settings.set_string('fire-color-5', preset.color5); - }); - - group.add_action(action); - }); - - this._builder.get_object('fire-preset-button').set_menu_model(menu); - - const root = utils.isGTK4() ? widget.get_root() : widget.get_toplevel(); - root.insert_action_group(groupName, group); - }); - } } // Nothing to do for now... diff --git a/resources/ui/gtk3/fire.ui b/resources/ui/gtk3/firePage.ui similarity index 81% rename from resources/ui/gtk3/fire.ui rename to resources/ui/gtk3/firePage.ui index 93a3e61..3455fd8 100644 --- a/resources/ui/gtk3/fire.ui +++ b/resources/ui/gtk3/firePage.ui @@ -1,14 +1,21 @@ - + + 10000 + 500 + 10 + 100 + + + 3 0.1 0.01 0.1 - + 2.0 -2.0 0.01 @@ -89,6 +96,55 @@ + + + 10 + 10 + 10 + 10 + 0 + + + 8 + + + Animation Time [ms] + 0 + start + center + 1 + + + + + end + center + 1 + 0 + left + 300 + fire-animation-time + + + + + + + edit-clear-symbolic + 1 + + + Reset to Default Value + + + + + + + + 10 @@ -115,11 +171,11 @@ 2 left 300 - flame-scale + fire-scale - + edit-clear-symbolic @@ -163,11 +219,11 @@ 2 left 300 - flame-movement-speed + fire-movement-speed - + edit-clear-symbolic @@ -223,13 +279,13 @@ - + end center - + edit-clear-symbolic diff --git a/resources/ui/gtk3/generalPage.ui b/resources/ui/gtk3/generalPage.ui new file mode 100644 index 0000000..ddecbf9 --- /dev/null +++ b/resources/ui/gtk3/generalPage.ui @@ -0,0 +1,129 @@ + + + + + vertical + 60 + 60 + 30 + 30 + + + + + + none + + + + 10 + 10 + 10 + 10 + 0 + + + 8 + + + vertical + 3 + + + Close Window Animation + 0 + start + center + 1 + + + + + If multiple are selected, one is chosen randomly. + 0 + start + center + 1 + + + + + + + + Effects + + + + + + + edit-clear-symbolic + 1 + + + Reset to Default Value + + + + + + + + + + + 10 + 10 + 10 + 10 + 0 + + + 8 + + + Also Burn Dialogs + 0 + start + center + 1 + + + + + end + center + + + + + + + edit-clear-symbolic + 1 + + + Reset to Default Value + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/ui/gtk3/prefs.ui b/resources/ui/gtk3/prefs.ui index 6196c5c..5b79db1 100644 --- a/resources/ui/gtk3/prefs.ui +++ b/resources/ui/gtk3/prefs.ui @@ -2,23 +2,6 @@ - - - - - - - - Fire - fire - - - TV Effect - tv - - - - main-menu 1 @@ -31,13 +14,6 @@ - - 10000 - 500 - 10 - 100 - - @@ -49,177 +25,8 @@ slide-up-down 1 - + - - vertical - 60 - 60 - 30 - 30 - - - - - - none - - - - 10 - 10 - 10 - 10 - 0 - - - 8 - - - Close Window Animation - 0 - start - center - 1 - - - - - center - animation-mode-list - 1 - fire - - - - 0 - - - - - - - - - edit-clear-symbolic - 1 - - - Reset to Default Value - - - - - - - - - - - 10 - 10 - 10 - 10 - 0 - - - 8 - - - Animation Time [ms] - 0 - start - center - 1 - - - - - end - center - 1 - 0 - left - 300 - destroy-animation-time - - - - - - - edit-clear-symbolic - 1 - - - Reset to Default Value - - - - - - - - - - - 10 - 10 - 10 - 10 - 0 - - - 8 - - - Also Burn Dialogs - 0 - start - center - 1 - - - - - end - center - - - - - - - edit-clear-symbolic - 1 - - - Reset to Default Value - - - - - - - - - - - - - - - - General Options - - - diff --git a/resources/ui/gtk3/tv.ui b/resources/ui/gtk3/tvPage.ui similarity index 50% rename from resources/ui/gtk3/tv.ui rename to resources/ui/gtk3/tvPage.ui index 22d864c..b992120 100644 --- a/resources/ui/gtk3/tv.ui +++ b/resources/ui/gtk3/tvPage.ui @@ -1,6 +1,13 @@ + + 5000 + 100 + 10 + 100 + + vertical 60 @@ -17,6 +24,55 @@ + + + 10 + 10 + 10 + 10 + 0 + + + 8 + + + Animation Time [ms] + 0 + start + center + 1 + + + + + end + center + 1 + 0 + left + 300 + tv-animation-time + + + + + + + edit-clear-symbolic + 1 + + + Reset to Default Value + + + + + + + + 10 diff --git a/resources/ui/gtk4/fire.ui b/resources/ui/gtk4/firePage.ui similarity index 80% rename from resources/ui/gtk4/fire.ui rename to resources/ui/gtk4/firePage.ui index 6e28e38..9d8247c 100644 --- a/resources/ui/gtk4/fire.ui +++ b/resources/ui/gtk4/firePage.ui @@ -58,6 +58,52 @@ + + + 0 + + + + + Animation Time [ms] + 0 + start + center + 1 + + + + + end + center + 1 + 0 + left + 300 + + + 10000 + 500 + 10 + 100 + + + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + 0 @@ -81,7 +127,7 @@ left 300 - + 3 0.1 0.01 @@ -91,7 +137,7 @@ - + edit-clear-symbolic Reset to Default Value + + + + + 0 + + + + + vertical + 3 + + + Close Window Animation + 0 + start + center + 1 + + + + + If multiple are selected, one is chosen randomly. + 0 + start + center + 1 + + + + + + + + Effects + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + + + + 0 + + + + + Also Burn Dialogs + 0 + start + center + 1 + + + + + end + center + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/ui/gtk4/matrix.ui b/resources/ui/gtk4/matrixPage.ui similarity index 78% rename from resources/ui/gtk4/matrix.ui rename to resources/ui/gtk4/matrixPage.ui index d7eed91..7f5a570 100644 --- a/resources/ui/gtk4/matrix.ui +++ b/resources/ui/gtk4/matrixPage.ui @@ -18,6 +18,52 @@ + + + 0 + + + + + Animation Time [ms] + 0 + start + center + 1 + + + + + end + center + 1 + 0 + left + 300 + + + 10000 + 500 + 10 + 100 + + + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + 0 diff --git a/resources/ui/gtk4/prefs.ui b/resources/ui/gtk4/prefs.ui index d51f05f..92a5f39 100644 --- a/resources/ui/gtk4/prefs.ui +++ b/resources/ui/gtk4/prefs.ui @@ -2,31 +2,6 @@ - - - - - - - - Fire - fire - - - Matrix - matrix - - - TV Effect - tv - - - T-Rex Attack - trex - - - - main-menu open-menu-symbolic @@ -43,161 +18,7 @@ slide-up-down 1 - - - General Options - - - - vertical - 60 - 60 - 60 - 60 - - - - - - none - 1 - - - - - - 0 - - - - - Close Window Animation - 0 - start - center - 1 - - - - - center - animation-mode-list - 1 - fire - - - - 0 - - - - - - - edit-clear-symbolic - Reset to Default Value - - - - - - - - - - - 0 - - - - - Animation Time [ms] - 0 - start - center - 1 - - - - - end - center - 1 - 0 - left - 300 - - - 10000 - 500 - 10 - 100 - - - - - - - edit-clear-symbolic - Reset to Default Value - - - - - - - - - - - 0 - - - - - Also Burn Dialogs - 0 - start - center - 1 - - - - - end - center - - - - - edit-clear-symbolic - Reset to Default Value - - - - - - - - - - - - - - - - - - + diff --git a/resources/ui/gtk4/trex.ui b/resources/ui/gtk4/trexPage.ui similarity index 79% rename from resources/ui/gtk4/trex.ui rename to resources/ui/gtk4/trexPage.ui index 14d20d3..2bfe567 100644 --- a/resources/ui/gtk4/trex.ui +++ b/resources/ui/gtk4/trexPage.ui @@ -18,6 +18,52 @@ + + + 0 + + + + + Animation Time [ms] + 0 + start + center + 1 + + + + + end + center + 1 + 0 + left + 300 + + + 10000 + 500 + 10 + 100 + + + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + 0 diff --git a/resources/ui/gtk4/tv.ui b/resources/ui/gtk4/tv.ui deleted file mode 100644 index 150712e..0000000 --- a/resources/ui/gtk4/tv.ui +++ /dev/null @@ -1,63 +0,0 @@ - - - - - vertical - 60 - 60 - 60 - 60 - - - - - - none - 1 - - - - - 0 - - - - - Color - 0 - start - center - 1 - - - - - 0 - 1 - - - - - edit-clear-symbolic - Reset to Default Value - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/resources/ui/gtk4/tvPage.ui b/resources/ui/gtk4/tvPage.ui new file mode 100644 index 0000000..c64ecef --- /dev/null +++ b/resources/ui/gtk4/tvPage.ui @@ -0,0 +1,109 @@ + + + + + vertical + 60 + 60 + 60 + 60 + + + + + + none + 1 + + + + + 0 + + + + + Animation Time [ms] + 0 + start + center + 1 + + + + + end + center + 1 + 0 + left + 300 + + + 5000 + 100 + 10 + 100 + + + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + + + + 0 + + + + + Color + 0 + start + center + 1 + + + + + 0 + 1 + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml b/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml index d19bbf3..b049a78 100644 --- a/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml +++ b/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml @@ -1,27 +1,11 @@ - - - - - - - - - "fire" - Close Animation - The animation used for window closing. - - - - - 1500 - Destroy Animation Time - The time it takes to burn the windows. - + + + false @@ -29,22 +13,38 @@ Set to true to burn dialogs as well. - + + + + + + true + Fire Close Effect + Use the fire effect for window closing. + + + + 1500 + Fire Animation Time + The time the fire effect takes. + + + 0.5 - Flame Movement Speed - The speed at which the flames move. + Fire Movement Speed + The speed at which the fire moves. - + 1.0 - Flame Scale - The size of the flames. + Fire Scale + The size of the fire. - + false - Flame 3D Noise - Use a 3D noise for the flames. + Fire 3D Noise + Use a 3D noise for the fire. @@ -77,6 +77,21 @@ The fifth color of the fire gradient. + + + + + + false + Matrix Close Effect + Use the matrix effect for window closing. + + + + 2000 + Matrix Animation Time + The time the matrix effect takes. + 20 @@ -102,6 +117,21 @@ The color matrix trails. + + + + + + false + TV Close Effect + Use the tv effect for window closing. + + + + 250 + TV Animation Time + The time the tv effect takes. + "rgb(255, 255, 255)" @@ -109,6 +139,21 @@ The color of the TV effect. + + + + + + false + T-Rex Close Effect + Use the trex effect for window closing. + + + + 1500 + T-Rex Animation Time + The time the trex effect takes. + "rgb(170, 0, 0)" @@ -134,7 +179,6 @@ Number of claw scratches drawn on top of each other. - \ No newline at end of file diff --git a/src/prefs/FirePage.js b/src/prefs/FirePage.js new file mode 100644 index 0000000..a4afbe6 --- /dev/null +++ b/src/prefs/FirePage.js @@ -0,0 +1,165 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// ) ( // +// ( /( ( ( ) ( ( ( ( )\ ) ( ( // +// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( // +// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ // +// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) // +// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< // +// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ // +// |__/ // +// Copyright (c) 2021 Simon Schneegans // +// Released under the GPLv3 or later. See LICENSE file for details. // +////////////////////////////////////////////////////////////////////////////////////////// + +'use strict'; + +const {Gio} = imports.gi; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = imports.misc.extensionUtils.getCurrentExtension(); +const utils = Me.imports.src.common.utils; +const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; + +////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////// + +var FirePage = class FirePage extends PrefsPage { + + // ------------------------------------------------------------ constructor / destructor + + constructor(settings, builder) { + super(settings, builder); + + this._builder.add_from_resource( + `/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/firePage.ui`); + + // Bind all properties. + this._bindAdjustment('fire-animation-time'); + this._bindAdjustment('fire-movement-speed'); + this._bindAdjustment('fire-scale'); + this._bindSwitch('fire-3d-noise'); + this._bindColorButton('fire-color-1'); + this._bindColorButton('fire-color-2'); + this._bindColorButton('fire-color-3'); + this._bindColorButton('fire-color-4'); + this._bindColorButton('fire-color-5'); + + // The fire-gradient-reset button needs to be bound explicitly. + this._builder.get_object('reset-fire-colors').connect('clicked', () => { + this._settings.reset('fire-color-1'); + this._settings.reset('fire-color-2'); + this._settings.reset('fire-color-3'); + this._settings.reset('fire-color-4'); + this._settings.reset('fire-color-5'); + }); + + // Initialize the fire-preset dropdown. + this._createFirePresets(); + + const stack = this._builder.get_object('main-stack'); + stack.add_titled(this._builder.get_object('fire-prefs'), 'fire', 'Fire'); + } + + // ---------------------------------------------------------------------- public methods + + getMinVersion() { + return [3, 36]; + } + + getEnabledKey() { + return 'fire-close-effect'; + } + + getAnimationTime() { + return this._settings.get_int('fire-animation-time'); + } + + // ----------------------------------------------------------------------- private stuff + + // This populates the preset dropdown menu for the fire options. + _createFirePresets() { + this._builder.get_object('settings-widget').connect('realize', (widget) => { + const presets = [ + { + name: 'Default Fire', + scale: 1.0, + speed: 0.5, + color1: 'rgba(76, 51, 25, 0.0)', + color2: 'rgba(180, 55, 30, 0.7)', + color3: 'rgba(255, 76, 38, 0.9)', + color4: 'rgba(255, 166, 25, 1)', + color5: 'rgba(255, 255, 255, 1)' + }, + { + name: 'Hell Fire', + scale: 1.5, + speed: 0.2, + color1: 'rgba(0,0,0,0)', + color2: 'rgba(103,7,80,0.5)', + color3: 'rgba(150,0,24,0.9)', + color4: 'rgb(255,200,0)', + color5: 'rgba(255, 255, 255, 1)' + }, + { + name: 'Dark and Smutty', + scale: 1.0, + speed: 0.5, + color1: 'rgba(0,0,0,0)', + color2: 'rgba(36,3,0,0.5)', + color3: 'rgba(150,0,24,0.9)', + color4: 'rgb(255,177,21)', + color5: 'rgb(255,238,166)' + }, + { + name: 'Cold Breeze', + scale: 1.5, + speed: -0.1, + color1: 'rgba(0,110,255,0)', + color2: 'rgba(30,111,180,0.24)', + color3: 'rgba(38,181,255,0.54)', + color4: 'rgba(34,162,255,0.84)', + color5: 'rgb(97,189,255)' + }, + { + name: 'Santa is Coming', + scale: 0.4, + speed: -0.5, + color1: 'rgba(0,110,255,0)', + color2: 'rgba(208,233,255,0.24)', + color3: 'rgba(207,235,255,0.84)', + color4: 'rgb(208,243,255)', + color5: 'rgb(255,255,255)' + } + ]; + + const menu = Gio.Menu.new(); + const group = Gio.SimpleActionGroup.new(); + const groupName = 'presets'; + + // Add all presets. + presets.forEach((preset, i) => { + const actionName = 'fire' + i; + menu.append(preset.name, groupName + '.' + actionName); + let action = Gio.SimpleAction.new(actionName, null); + + // Load the preset on activation. + action.connect('activate', () => { + this._settings.set_double('fire-movement-speed', preset.speed); + this._settings.set_double('fire-scale', preset.scale); + this._settings.set_string('fire-color-1', preset.color1); + this._settings.set_string('fire-color-2', preset.color2); + this._settings.set_string('fire-color-3', preset.color3); + this._settings.set_string('fire-color-4', preset.color4); + this._settings.set_string('fire-color-5', preset.color5); + }); + + group.add_action(action); + }); + + this._builder.get_object('fire-preset-button').set_menu_model(menu); + + const root = utils.isGTK4() ? widget.get_root() : widget.get_toplevel(); + root.insert_action_group(groupName, group); + }); + } +} \ No newline at end of file diff --git a/src/prefs/GeneralPage.js b/src/prefs/GeneralPage.js new file mode 100644 index 0000000..a58408d --- /dev/null +++ b/src/prefs/GeneralPage.js @@ -0,0 +1,43 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// ) ( // +// ( /( ( ( ) ( ( ( ( )\ ) ( ( // +// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( // +// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ // +// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) // +// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< // +// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ // +// |__/ // +// Copyright (c) 2021 Simon Schneegans // +// Released under the GPLv3 or later. See LICENSE file for details. // +////////////////////////////////////////////////////////////////////////////////////////// + +'use strict'; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = imports.misc.extensionUtils.getCurrentExtension(); +const utils = Me.imports.src.common.utils; +const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; + +////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////// + +var GeneralPage = class GeneralPage extends PrefsPage { + + // ------------------------------------------------------------ constructor / destructor + + constructor(settings, builder) { + super(settings, builder); + + this._builder.add_from_resource( + `/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/generalPage.ui`); + + // Bind all properties. + this._bindSwitch('destroy-dialogs'); + + const stack = this._builder.get_object('main-stack'); + stack.add_titled( + this._builder.get_object('general-prefs'), 'general', 'General Options'); + } + + // ---------------------------------------------------------------------- public methods +} \ No newline at end of file diff --git a/src/prefs/MatrixPage.js b/src/prefs/MatrixPage.js new file mode 100644 index 0000000..a8404a9 --- /dev/null +++ b/src/prefs/MatrixPage.js @@ -0,0 +1,56 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// ) ( // +// ( /( ( ( ) ( ( ( ( )\ ) ( ( // +// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( // +// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ // +// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) // +// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< // +// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ // +// |__/ // +// Copyright (c) 2021 Simon Schneegans // +// Released under the GPLv3 or later. See LICENSE file for details. // +////////////////////////////////////////////////////////////////////////////////////////// + +'use strict'; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = imports.misc.extensionUtils.getCurrentExtension(); +const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; + +////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////// + +var MatrixPage = class MatrixPage extends PrefsPage { + + // ------------------------------------------------------------ constructor / destructor + + constructor(settings, builder) { + super(settings, builder); + + this._builder.add_from_resource('/ui/gtk4/matrixPage.ui'); + + // Bind all properties. + this._bindAdjustment('matrix-animation-time'); + this._bindAdjustment('matrix-scale'); + this._bindAdjustment('matrix-randomness'); + this._bindColorButton('matrix-trail-color'); + this._bindColorButton('matrix-tip-color'); + + const stack = this._builder.get_object('main-stack'); + stack.add_titled(this._builder.get_object('matrix-prefs'), 'matrix', 'Matrix'); + } + + // ---------------------------------------------------------------------- public methods + + getMinVersion() { + return [40, 0]; + } + + getEnabledKey() { + return 'matrix-close-effect'; + } + + getAnimationTime() { + return this._settings.get_int('matrix-animation-time'); + } +} \ No newline at end of file diff --git a/src/prefs/PrefsPage.js b/src/prefs/PrefsPage.js new file mode 100644 index 0000000..156607b --- /dev/null +++ b/src/prefs/PrefsPage.js @@ -0,0 +1,102 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// ) ( // +// ( /( ( ( ) ( ( ( ( )\ ) ( ( // +// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( // +// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ // +// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) // +// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< // +// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ // +// |__/ // +// Copyright (c) 2021 Simon Schneegans // +// Released under the GPLv3 or later. See LICENSE file for details. // +////////////////////////////////////////////////////////////////////////////////////////// + +'use strict'; + +const {Gdk, Gio} = imports.gi; + +////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////// + +var PrefsPage = class PrefsPage { + + // ------------------------------------------------------------ constructor / destructor + + constructor(settings, builder) { + this._settings = settings; + this._builder = builder; + } + + // ---------------------------------------------------------------------- public methods + + // Connects a Gtk.ComboBox (or anything else which has an 'active-id' property) to a + // settings key. It also binds the corresponding reset button. + _bindCombobox(settingsKey) { + this._bind(settingsKey, 'active-id'); + } + + // 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'); + } + + // Colors are stored as strings like 'rgb(1, 0.5, 0)'. As Gio.Settings.bind_with_mapping + // is not available yet, we need to do the color conversion manually. It also binds the + // corresponding reset button. + _bindColorButton(settingsKey) { + + const button = this._builder.get_object(settingsKey); + + if (button) { + + // Update the settings when the color is modified. + button.connect('color-set', () => { + this._settings.set_string(settingsKey, button.get_rgba().to_string()); + }); + + // Update the button state when the settings change. + const settingSignalHandler = () => { + const rgba = new Gdk.RGBA(); + rgba.parse(this._settings.get_string(settingsKey)); + button.rgba = rgba; + }; + + this._settings.connect('changed::' + settingsKey, settingSignalHandler); + + // Initialize the button with the state in the settings. + settingSignalHandler(); + } + + this._bindResetButton(settingsKey); + } + + // 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) { + const object = this._builder.get_object(settingsKey); + + if (object) { + this._settings.bind(settingsKey, object, property, Gio.SettingsBindFlags.DEFAULT); + } + + this._bindResetButton(settingsKey); + } + + // Searches for a reset button for the given settings key and make it reset the settings + // key when clicked. + _bindResetButton(settingsKey) { + const resetButton = this._builder.get_object('reset-' + settingsKey); + if (resetButton) { + resetButton.connect('clicked', () => { + this._settings.reset(settingsKey); + }); + } + } +} \ No newline at end of file diff --git a/src/prefs/TRexPage.js b/src/prefs/TRexPage.js new file mode 100644 index 0000000..7248b4e --- /dev/null +++ b/src/prefs/TRexPage.js @@ -0,0 +1,56 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// ) ( // +// ( /( ( ( ) ( ( ( ( )\ ) ( ( // +// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( // +// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ // +// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) // +// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< // +// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ // +// |__/ // +// Copyright (c) 2021 Simon Schneegans // +// Released under the GPLv3 or later. See LICENSE file for details. // +////////////////////////////////////////////////////////////////////////////////////////// + +'use strict'; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = imports.misc.extensionUtils.getCurrentExtension(); +const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; + +////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////// + +var TRexPage = class TRexPage extends PrefsPage { + + // ------------------------------------------------------------ constructor / destructor + + constructor(settings, builder) { + super(settings, builder); + + this._builder.add_from_resource('/ui/gtk4/trexPage.ui'); + + // Bind all properties. + this._bindAdjustment('trex-animation-time'); + this._bindColorButton('claw-scratch-color'); + this._bindAdjustment('claw-scratch-scale'); + this._bindAdjustment('claw-scratch-count'); + this._bindAdjustment('claw-scratch-warp'); + + const stack = this._builder.get_object('main-stack'); + stack.add_titled(this._builder.get_object('trex-prefs'), 'trex', 'T-Rex Attack'); + } + + // ---------------------------------------------------------------------- public methods + + getMinVersion() { + return [40, 0]; + } + + getEnabledKey() { + return 'trex-close-effect'; + } + + getAnimationTime() { + return this._settings.get_int('trex-animation-time'); + } +} \ No newline at end of file diff --git a/src/prefs/TVEffectPage.js b/src/prefs/TVEffectPage.js new file mode 100644 index 0000000..17b371a --- /dev/null +++ b/src/prefs/TVEffectPage.js @@ -0,0 +1,54 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// ) ( // +// ( /( ( ( ) ( ( ( ( )\ ) ( ( // +// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( // +// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ // +// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) // +// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< // +// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ // +// |__/ // +// Copyright (c) 2021 Simon Schneegans // +// Released under the GPLv3 or later. See LICENSE file for details. // +////////////////////////////////////////////////////////////////////////////////////////// + +'use strict'; + +const ExtensionUtils = imports.misc.extensionUtils; +const Me = imports.misc.extensionUtils.getCurrentExtension(); +const utils = Me.imports.src.common.utils; +const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; + +////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////// + +var TVEffectPage = class TVEffectPage extends PrefsPage { + + // ------------------------------------------------------------ constructor / destructor + + constructor(settings, builder) { + super(settings, builder); + + this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/tvPage.ui`); + + // Bind all properties. + this._bindAdjustment('tv-animation-time'); + this._bindColorButton('tv-effect-color'); + + const stack = this._builder.get_object('main-stack'); + stack.add_titled(this._builder.get_object('tv-prefs'), 'tv', 'TV Effect'); + } + + // ---------------------------------------------------------------------- public methods + + getMinVersion() { + return [3, 36]; + } + + getEnabledKey() { + return 'tv-close-effect'; + } + + getAnimationTime() { + return this._settings.get_int('tv-animation-time'); + } +} \ No newline at end of file