From 5561cff12a8c9e6f5c8665c2627efa41cde96bc9 Mon Sep 17 00:00:00 2001 From: martindmtrv Date: Wed, 30 Mar 2022 21:58:42 -0400 Subject: [PATCH] add always minimize feature --- README.md | 3 +++ extension.js | 16 +++++++++++++++- prefs.js | 12 +++++++++++- schemas/gschemas.compiled | Bin 760 -> 836 bytes ...ons.notification-banner-reloaded.gschema.xml | 6 ++++++ utils.js | 1 + 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5f9751..b7252b8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # notification-position-reloaded Gnome Shell extension allowing customization of notification banner position and animation properties + +# recompile schema if adding additional options +```glib-compile-schemas schemas``` diff --git a/extension.js b/extension.js index d51ce7c..944e925 100644 --- a/extension.js +++ b/extension.js @@ -32,6 +32,7 @@ let ANCHOR_VERTICAL = 0; let ANCHOR_HORIZONTAL = 2; let PADDING_VERTICAL = 0; let PADDING_HORIZONTAL = 0; +let ALWAYS_MINIMIZE = 0; function patcher(obj, method, original, patch) { const body = eval(`${obj}.prototype.${method}.toString()`); @@ -141,6 +142,13 @@ const patches = [ } ]; +const always_minimize_patch = { + obj: "MessageTray", + method: "_updateShowingNotification", + original: "this._expandBanner(true)", + patch: "// always minimized setting enabled by notification-banner-reloaded ... this._expandBanner(true)", +}; + class Extension { constructor() { this._previous_y_align = BannerBin.get_y_align(); @@ -160,6 +168,7 @@ class Extension { PADDING_HORIZONTAL = this._settings.get_int(Utils.PrefFields.PADDING_HORIZONTAL); ANIMATION_DIRECTION = this._settings.get_int(Utils.PrefFields.ANIMATION_DIRECTION); ANIMATION_TIME = this._settings.get_int(Utils.PrefFields.ANIMATION_TIME); + ALWAYS_MINIMIZE = this._settings.get_int(Utils.PrefFields.ALWAYS_MINIMIZE); } _onSettingsChange() { @@ -178,10 +187,15 @@ class Extension { let y_align = Clutter.ActorAlign.START; BannerBin.set_x_align(x_align); BannerBin.set_y_align(y_align); - this.restore() + this.restore(); for (const { obj, method, original, patch } of patches) { patcher(obj, method, original, patch) } + + if (ALWAYS_MINIMIZE) { + const { obj, method, original, patch } = always_minimize_patch; + patcher(obj, method, original, patch); + } } disable() { diff --git a/prefs.js b/prefs.js index 59d37a8..f0101cd 100644 --- a/prefs.js +++ b/prefs.js @@ -90,9 +90,12 @@ class Preferences { this.animationDirection = new Gtk.ComboBox({ model: this._create_options([ _('Slide from Left'), _('Slide from Right'), _('Slide from Top'), _('Slide from Bottom')]) }); + this.alwaysMinimize = new Gtk.ComboBox({ + model: this._create_options([ _('false'), _('true')]) + }); let rendererText = new Gtk.CellRendererText(); - for (const widget of [this.anchorHorizontal, this.anchorVertical, this.animationDirection]) { + for (const widget of [this.anchorHorizontal, this.anchorVertical, this.animationDirection, this.alwaysMinimize]) { widget.pack_start(rendererText, false); widget.add_attribute(rendererText, "text", 0); } @@ -127,6 +130,11 @@ class Preferences { hexpand: true, halign: Gtk.Align.START }); + let alwaysMinimizeLabel = new Gtk.Label({ + label: _("Always Minimize"), + hexpand: true, + halign: Gtk.Align.START + }); const addRow = ((main) => { let row = 0; @@ -156,6 +164,7 @@ class Preferences { addRow(paddingVerticalLabel, this.paddingVertical); addRow(animationDirectionLabel, this.animationDirection); addRow(animationTimeLabel, this.animationTime); + addRow(alwaysMinimizeLabel, this.alwaysMinimize); const settings = ExtensionUtils.getSettings(); settings.bind(Utils.PrefFields.ANCHOR_HORIZONTAL, this.anchorHorizontal, 'active', Gio.SettingsBindFlags.DEFAULT); @@ -164,6 +173,7 @@ class Preferences { settings.bind(Utils.PrefFields.PADDING_VERTICAL, this.paddingVertical, 'value', Gio.SettingsBindFlags.DEFAULT); settings.bind(Utils.PrefFields.ANIMATION_DIRECTION, this.animationDirection, 'active', Gio.SettingsBindFlags.DEFAULT); settings.bind(Utils.PrefFields.ANIMATION_TIME, this.animationTime, 'value', Gio.SettingsBindFlags.DEFAULT); + settings.bind(Utils.PrefFields.ALWAYS_MINIMIZE, this.alwaysMinimize, 'active', Gio.SettingsBindFlags.DEFAULT); } _create_options(opts) { diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index 03cbd83cdf14adac776ff678d4eedac0e324f1c7..53f6b1d407c0d96109001d948f27ee73ca46611e 100644 GIT binary patch literal 836 zcmaJLBT~F1^oez3jPSe zrGt}$I0}L~IOz}2bCT4C7JP7WPEIcO-FtJ_Hf5lti9~u9z}tzo`ctnDytDhXxHST19n+#NuEF=f-O=$FYogAynL+ca1y9-Q(TdKc09l;9n6ntHl5S literal 760 zcmaJ;Jxjw-6unieg5XDsRqzj_LlVKEKS9CHD!TY=p6!G5rKF+M`hhOu=->}w(l&<>{)Wy+CcNf(Y1XJai6NxO!M+o%@X-h49e~VW&anHO;iy;TmAg}HvItaoT4HC diff --git a/schemas/org.gnome.shell.extensions.notification-banner-reloaded.gschema.xml b/schemas/org.gnome.shell.extensions.notification-banner-reloaded.gschema.xml index d7e50e0..48097e1 100644 --- a/schemas/org.gnome.shell.extensions.notification-banner-reloaded.gschema.xml +++ b/schemas/org.gnome.shell.extensions.notification-banner-reloaded.gschema.xml @@ -43,5 +43,11 @@ + + 0 + Always minimized notifications by default (ignores urgency of notification) + + + diff --git a/utils.js b/utils.js index fc788c6..f96c1a9 100644 --- a/utils.js +++ b/utils.js @@ -5,4 +5,5 @@ var PrefFields = { PADDING_HORIZONTAL : 'padding-horizontal', ANIMATION_TIME : 'animation-time', ANIMATION_DIRECTION : 'animation-direction', + ALWAYS_MINIMIZE : 'always-minimized', };