add always minimize feature

This commit is contained in:
martindmtrv
2022-04-13 22:03:22 +02:00
committed by Marcin Jakubowski
parent cddb0cd863
commit 5561cff12a
6 changed files with 36 additions and 2 deletions
+3
View File
@@ -1,2 +1,5 @@
# notification-position-reloaded # notification-position-reloaded
Gnome Shell extension allowing customization of notification banner position and animation properties Gnome Shell extension allowing customization of notification banner position and animation properties
# recompile schema if adding additional options
```glib-compile-schemas schemas```
+15 -1
View File
@@ -32,6 +32,7 @@ let ANCHOR_VERTICAL = 0;
let ANCHOR_HORIZONTAL = 2; let ANCHOR_HORIZONTAL = 2;
let PADDING_VERTICAL = 0; let PADDING_VERTICAL = 0;
let PADDING_HORIZONTAL = 0; let PADDING_HORIZONTAL = 0;
let ALWAYS_MINIMIZE = 0;
function patcher(obj, method, original, patch) { function patcher(obj, method, original, patch) {
const body = eval(`${obj}.prototype.${method}.toString()`); 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 { class Extension {
constructor() { constructor() {
this._previous_y_align = BannerBin.get_y_align(); this._previous_y_align = BannerBin.get_y_align();
@@ -160,6 +168,7 @@ class Extension {
PADDING_HORIZONTAL = this._settings.get_int(Utils.PrefFields.PADDING_HORIZONTAL); PADDING_HORIZONTAL = this._settings.get_int(Utils.PrefFields.PADDING_HORIZONTAL);
ANIMATION_DIRECTION = this._settings.get_int(Utils.PrefFields.ANIMATION_DIRECTION); ANIMATION_DIRECTION = this._settings.get_int(Utils.PrefFields.ANIMATION_DIRECTION);
ANIMATION_TIME = this._settings.get_int(Utils.PrefFields.ANIMATION_TIME); ANIMATION_TIME = this._settings.get_int(Utils.PrefFields.ANIMATION_TIME);
ALWAYS_MINIMIZE = this._settings.get_int(Utils.PrefFields.ALWAYS_MINIMIZE);
} }
_onSettingsChange() { _onSettingsChange() {
@@ -178,10 +187,15 @@ class Extension {
let y_align = Clutter.ActorAlign.START; let y_align = Clutter.ActorAlign.START;
BannerBin.set_x_align(x_align); BannerBin.set_x_align(x_align);
BannerBin.set_y_align(y_align); BannerBin.set_y_align(y_align);
this.restore() this.restore();
for (const { obj, method, original, patch } of patches) { for (const { obj, method, original, patch } of patches) {
patcher(obj, method, original, patch) patcher(obj, method, original, patch)
} }
if (ALWAYS_MINIMIZE) {
const { obj, method, original, patch } = always_minimize_patch;
patcher(obj, method, original, patch);
}
} }
disable() { disable() {
+11 -1
View File
@@ -90,9 +90,12 @@ class Preferences {
this.animationDirection = new Gtk.ComboBox({ this.animationDirection = new Gtk.ComboBox({
model: this._create_options([ _('Slide from Left'), _('Slide from Right'), _('Slide from Top'), _('Slide from Bottom')]) 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(); 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.pack_start(rendererText, false);
widget.add_attribute(rendererText, "text", 0); widget.add_attribute(rendererText, "text", 0);
} }
@@ -127,6 +130,11 @@ class Preferences {
hexpand: true, hexpand: true,
halign: Gtk.Align.START halign: Gtk.Align.START
}); });
let alwaysMinimizeLabel = new Gtk.Label({
label: _("Always Minimize"),
hexpand: true,
halign: Gtk.Align.START
});
const addRow = ((main) => { const addRow = ((main) => {
let row = 0; let row = 0;
@@ -156,6 +164,7 @@ class Preferences {
addRow(paddingVerticalLabel, this.paddingVertical); addRow(paddingVerticalLabel, this.paddingVertical);
addRow(animationDirectionLabel, this.animationDirection); addRow(animationDirectionLabel, this.animationDirection);
addRow(animationTimeLabel, this.animationTime); addRow(animationTimeLabel, this.animationTime);
addRow(alwaysMinimizeLabel, this.alwaysMinimize);
const settings = ExtensionUtils.getSettings(); const settings = ExtensionUtils.getSettings();
settings.bind(Utils.PrefFields.ANCHOR_HORIZONTAL, this.anchorHorizontal, 'active', Gio.SettingsBindFlags.DEFAULT); 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.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_DIRECTION, this.animationDirection, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind(Utils.PrefFields.ANIMATION_TIME, this.animationTime, 'value', 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) { _create_options(opts) {
Binary file not shown.
@@ -43,5 +43,11 @@
<description></description> <description></description>
<range min="0" max="3"/> <range min="0" max="3"/>
</key> </key>
<key type="i" name="always-minimized">
<default>0</default>
<summary>Always minimized notifications by default (ignores urgency of notification)</summary>
<description></description>
<range min="0" max="1"/>
</key>
</schema> </schema>
</schemalist> </schemalist>
+1
View File
@@ -5,4 +5,5 @@ var PrefFields = {
PADDING_HORIZONTAL : 'padding-horizontal', PADDING_HORIZONTAL : 'padding-horizontal',
ANIMATION_TIME : 'animation-time', ANIMATION_TIME : 'animation-time',
ANIMATION_DIRECTION : 'animation-direction', ANIMATION_DIRECTION : 'animation-direction',
ALWAYS_MINIMIZE : 'always-minimized',
}; };