[gnome] Add new extensions

This commit is contained in:
2026-02-11 16:14:31 -05:00
parent 5b86d17bab
commit 2c2be21fef
25 changed files with 4047 additions and 0 deletions

View File

@ -0,0 +1,245 @@
/* extension.js
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import Clutter from 'gi://Clutter';
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import { MessageTray } from 'resource:///org/gnome/shell/ui/messageTray.js';
import * as Utils from './utils.js';
const BannerBin = Main.messageTray._bannerBin;
/* Imports necessary by the code pulled in from messageTray.js */
import { State, Urgency } from 'resource:///org/gnome/shell/ui/messageTray.js';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import St from 'gi://St';
import * as Calendar from 'resource:///org/gnome/shell/ui/calendar.js'
import * as MessageList from 'resource:///org/gnome/shell/ui/messageList.js'
const NOTIFICATION_TIMEOUT = 4000;
const HIDE_TIMEOUT = 200;
const LONGER_HIDE_TIMEOUT = 600;
const IDLE_TIME = 1000;
let ANIMATION_TIME = 200;
let ANIMATION_DIRECTION = 2;
let ANCHOR_VERTICAL = 0;
let ANCHOR_HORIZONTAL = 2;
let PADDING_VERTICAL = 0;
let PADDING_HORIZONTAL = 0;
let ALWAYS_MINIMIZE = 0;
function patcher(obj, live, method, original, patch) {
const body = eval(`${obj}.prototype.${method}.toString()`);
const newBody = body.replace(original, patch).replace(method + "(", "function(")
eval(`${obj}.prototype.${method} = ${newBody}`);
eval(`${live}.${method} = ${newBody}`);
}
const getMessageTraySize = () => {
const { width, height } = Main.layoutManager.getWorkAreaForMonitor(global.display.get_primary_monitor());
return {width, height};
}
const originalShow = MessageTray.prototype._showNotification;
const originalHide = MessageTray.prototype._hideNotification;
const originalUpdateShowing = MessageTray.prototype._updateShowingNotification;
function calcTarget(self) {
let x = 0, y = 0;
switch (ANCHOR_HORIZONTAL) {
case 0: // left
x = 0 + PADDING_HORIZONTAL;
break;
case 1: // right
x = getMessageTraySize().width - self._banner.width - PADDING_HORIZONTAL;
break;
case 2: // center
x = (getMessageTraySize().width - self._banner.width) / 2.0;
break;
}
switch (ANCHOR_VERTICAL) {
case 0: // top
y = 0 + PADDING_VERTICAL;
break;
case 1: // bottom
y = getMessageTraySize().height - self._banner.height - PADDING_VERTICAL;
break;
case 2: // center
y = (getMessageTraySize().height - self._banner.height) / 2.0;
break;
}
return { x, y }
}
function calcHide(self) {
let { x, y } = calcTarget(self)
switch (ANIMATION_DIRECTION) {
case 0: // from left
x = -self._banner.width;
break;
case 1: // from right
x = getMessageTraySize().width;
break;
case 2: // from top
y = -self._banner.height
break;
case 3: // from bottom
y = getMessageTraySize().height
break;
}
return { x, y }
}
function calcStart(self) {
const { x, y } = calcHide(self);
self._bannerBin.x = x;
self._bannerBin.y = y;
// if banner is not expanded and anchored to the bottom
// it won't have enough vertical space to expand
// in such case, move it up enough to fit the expanded banner
if (!self._banner.expanded && ANCHOR_VERTICAL == 1) {
const unexpandedHeight = self._banner.height
// expand without animation to measure height
self._banner.expand(false);
const expandedDifference = self._banner.height - unexpandedHeight;
// go back to unexpanded
self._banner.unexpand(false);
// move up when needed
self._banner.connect('expanded', () => {
self._bannerBin.ease({
y: self._bannerBin.y - expandedDifference,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
});
});
}
}
// each of the methods has hardcoded values for showing banners
// at the top. instead of rewriting whole functions, just patch the
// relevant lines
const patches = [
{
"obj": "MessageTray", "method": "_updateShowingNotification",
"live": "Main.messageTray",
"original": 'y: 0',
"patch": '...calcTarget(this)'
},
{
"obj": "MessageTray", "method": "_showNotification",
"live": "Main.messageTray",
"original": 'this._bannerBin.y = -this._banner.height',
"patch": 'calcStart(this)'
},
{
"obj": "MessageTray", "method": "_hideNotification",
"live": "Main.messageTray",
"original": 'y: -this._bannerBin.height',
"patch": '...calcHide(this)'
}
];
const always_minimize_patch = {
obj: "MessageTray",
live: "Main.messageTray",
method: "_updateShowingNotification",
original: "this._expandBanner(true)",
patch: "// always minimized setting enabled by notification-banner-reloaded ... this._expandBanner(true)",
};
export default class NotificationExtension extends Extension {
constructor(metadata) {
super(metadata);
this._previous_y_align = BannerBin.get_y_align();
this._previous_x_align = BannerBin.get_x_align();
}
_loadSettings() {
this._settings = this.getSettings();
this._settingsChangedId = this._settings.connect('changed', this._onSettingsChange.bind(this));
this._fetchSettings();
}
_fetchSettings() {
ANCHOR_VERTICAL = this._settings.get_int(Utils.PrefFields.ANCHOR_VERTICAL);
ANCHOR_HORIZONTAL = this._settings.get_int(Utils.PrefFields.ANCHOR_HORIZONTAL);
PADDING_VERTICAL = this._settings.get_int(Utils.PrefFields.PADDING_VERTICAL);
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() {
this._fetchSettings();
this.enable();
}
enable() {
this._loadSettings();
// generally alignment can be controller with START/CENTER/END
// but CENTER and END are problematic to implement animations with
// (especially x -> END and animations from left/right)
// all positions will then be calculated in relation to the top-left
// corner (START/START).
let x_align = Clutter.ActorAlign.START;
let y_align = Clutter.ActorAlign.START;
BannerBin.set_x_align(x_align);
BannerBin.set_y_align(y_align);
this.restore();
for (const { obj, live, method, original, patch } of patches) {
patcher(obj, live, method, original, patch)
}
if (ALWAYS_MINIMIZE) {
const { obj, live, method, original, patch } = always_minimize_patch;
patcher(obj, live, method, original, patch);
}
}
disable() {
BannerBin.set_x_align(this._previous_x_align);
BannerBin.set_y_align(this._previous_y_align);
BannerBin.x = 0
BannerBin.y = 0
this.restore()
if (this._settingsChangedId) {
this._settings.disconnect(this._settingsChangedId);
this._settingsChangedId = null;
}
this._settings = null;
}
restore() {
MessageTray.prototype._hideNotification = originalHide;
MessageTray.prototype._showNotification = originalShow;
MessageTray.prototype._updateShowingNotification = originalUpdateShowing;
}
}

View File

@ -0,0 +1,16 @@
{
"_generated": "Generated by SweetTooth, do not edit",
"description": "Configure notification banner position and animation to your liking.\nVersion 9: Gnome 45 changes by mannjani@github\nVersion 10: mannjani@github added a test button inside prefs",
"name": "Notification Banner Reloaded",
"settings-schema": "org.gnome.shell.extensions.notification-banner-reloaded",
"shell-version": [
"45",
"46",
"47",
"48",
"49"
],
"url": "https://github.com/marcinjakubowski/notification-position-reloaded",
"uuid": "notification-banner-reloaded@marcinjakubowski.github.com",
"version": 17
}

View File

@ -0,0 +1,248 @@
/* extension.js
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/*
Swaths of pref related code borrowed from Clipboard Indicator, an amazing extension
https://github.com/Tudmotu/gnome-shell-extension-clipboard-indicator
https://extensions.gnome.org/extension/779/clipboard-indicator/
*/
import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import * as Utils from './utils.js';
import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
export default class NotificationExtensionPreferences extends ExtensionPreferences {
constructor(metadata) {
super(metadata);
}
getPreferencesWidget() {
let frame = new Gtk.Box();
let widget = new Preferences(this.getSettings());
frame.append(widget.main);
if (frame.show_all)
frame.show_all();
return frame;
}
}
class Preferences{
constructor(settings) {
this.settings = settings
this.main = new Gtk.Grid({
margin_top: 10,
margin_bottom: 10,
margin_start: 10,
margin_end: 10,
row_spacing: 12,
column_spacing: 18,
column_homogeneous: false,
row_homogeneous: false
});
this.paddingHorizontal = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 1000,
step_increment: 1
})
});
this.paddingVertical = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 1000,
step_increment: 1
})
});
this.animationTime = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 100,
upper: 5000,
step_increment: 100
})
});
this.anchorHorizontal = new Gtk.ComboBox({
model: this._create_options([ _('Left'), _('Right'), _('Center') ])
});
this.anchorVertical = new Gtk.ComboBox({
model: this._create_options([ _('Top'), _('Bottom'), _('Center') ])
});
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')])
});
this.testButton = new Gtk.Button({ label: _("Test") });
this.testButton.connect('clicked', () => {
const notification = new GLib.Variant('(susssasa{sv}i)', [
'Notification Banner Reloaded',
0,
'dialog-information-symbolic',
'Notification Banner Reloaded',
'Test',
[],
{},
-1,
]);
Gio.DBus.session.call(
'org.freedesktop.Notifications',
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
'Notify',
notification,
null,
Gio.DBusCallFlags.NONE,
-1,
null,
null);
});
let rendererText = new Gtk.CellRendererText();
for (const widget of [this.anchorHorizontal, this.anchorVertical, this.animationDirection, this.alwaysMinimize]) {
widget.pack_start(rendererText, false);
widget.add_attribute(rendererText, "text", 0);
}
let anchorHorizontalLabel = new Gtk.Label({
label: _("Horizontal Position"),
hexpand: true,
halign: Gtk.Align.START
});
let anchorVerticalLabel = new Gtk.Label({
label: _("Vertical Position"),
hexpand: true,
halign: Gtk.Align.START
});
let paddingHorizontalLabel = new Gtk.Label({
label: _("Horizontal Padding"),
hexpand: true,
halign: Gtk.Align.START
});
let paddingVerticalLabel = new Gtk.Label({
label: _("Vertical Padding"),
hexpand: true,
halign: Gtk.Align.START
});
let animationDirectionLabel = new Gtk.Label({
label: _("Animation Direction"),
hexpand: true,
halign: Gtk.Align.START
});
let animationTimeLabel = new Gtk.Label({
label: _("Animation Time (ms)"),
hexpand: true,
halign: Gtk.Align.START
});
let alwaysMinimizeLabel = new Gtk.Label({
label: _("Always Minimize"),
hexpand: true,
halign: Gtk.Align.START
});
const testButtonLabel = new Gtk.Label({
label: _("Send Test Notification"),
hexpand: true,
halign: Gtk.Align.START
});
const addRow = ((main) => {
let row = 0;
return (label, input) => {
let inputWidget = input;
if (input instanceof Gtk.Switch) {
inputWidget = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL,});
addBox(inputWidget, input);
}
if (label) {
main.attach(label, 0, row, 1, 1);
main.attach(inputWidget, 1, row, 1, 1);
}
else {
main.attach(inputWidget, 0, row, 2, 1);
}
row++;
};
})(this.main);
addRow(anchorHorizontalLabel, this.anchorHorizontal);
addRow(anchorVerticalLabel, this.anchorVertical);
addRow(paddingHorizontalLabel, this.paddingHorizontal);
addRow(paddingVerticalLabel, this.paddingVertical);
addRow(animationDirectionLabel, this.animationDirection);
addRow(animationTimeLabel, this.animationTime);
addRow(alwaysMinimizeLabel, this.alwaysMinimize);
addRow(testButtonLabel, this.testButton);
settings.bind(Utils.PrefFields.ANCHOR_HORIZONTAL, this.anchorHorizontal, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind(Utils.PrefFields.ANCHOR_VERTICAL, this.anchorVertical, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind(Utils.PrefFields.ANIMATION_DIRECTION, this.animationDirection, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind(Utils.PrefFields.ALWAYS_MINIMIZE, this.alwaysMinimize, 'active', Gio.SettingsBindFlags.DEFAULT);
this._bindSpinWithThrottle(this.paddingHorizontal, Utils.PrefFields.PADDING_HORIZONTAL);
this._bindSpinWithThrottle(this.paddingVertical, Utils.PrefFields.PADDING_VERTICAL);
this._bindSpinWithThrottle(this.animationTime, Utils.PrefFields.ANIMATION_TIME);
}
_bindSpinWithThrottle(spinButton, key) {
/*- Load value from settings -*/
spinButton.value = this.settings.get_int(key);
let timeoutId = 0;
const updateSettings = () => {
const newVal = Math.round(spinButton.value);
if (this.settings.get_int(key) !== newVal) {
this.settings.set_int(key, newVal);
}
timeoutId = 0;
return GLib.SOURCE_REMOVE;
};
spinButton.connect('value-changed', () => {
if (timeoutId) {
GLib.source_remove(timeoutId);
}
timeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, updateSettings);
});
/*- If the user update elsewhere, we update spin value -*/
this.settings.connect(`changed::${key}`, () => {
const val = this.settings.get_int(key);
if (Math.round(spinButton.value) !== val) {
spinButton.value = val;
}
});
}
_create_options(opts) {
let options = opts.map(function (v) { return { name: v }});
let liststore = new Gtk.ListStore();
liststore.set_column_types([GObject.TYPE_STRING])
for (let i = 0; i < options.length; i++ ) {
let option = options[i];
let iter = liststore.append();
liststore.set (iter, [0], [option.name]);
}
return liststore;
}
};

View File

@ -0,0 +1,53 @@
<schemalist gettext-domain="gnome-shell-extensions">
<schema id="org.gnome.shell.extensions.notification-banner-reloaded"
path="/org/gnome/shell/extensions/notification-banner-reloaded/">
<key type="i" name="animation-time">
<default>200</default>
<summary>Duration of the show/hide animation</summary>
<description>Duration of the show/hide animation, in milliseconds</description>
<range min="100" max="5000"/>
</key>
<key type="i" name="anchor-vertical">
<default>0</default>
<summary>Vertical position of the banner</summary>
<description></description>
<range min="0" max="2"/>
</key>
<key type="i" name="anchor-horizontal">
<default>2</default>
<summary>Horizontal position of the banner</summary>
<description></description>
<range min="0" max="2"/>
</key>
<key type="i" name="padding-vertical">
<default>0</default>
<summary>Vertical padding of the banner</summary>
<description></description>
<range min="0" max="1000"/>
</key>
<key type="i" name="padding-horizontal">
<default>0</default>
<summary>Horizontal padding of the banner</summary>
<description></description>
<range min="0" max="1000"/>
</key>
<key type="i" name="animation-direction">
<default>2</default>
<summary>Animation direction</summary>
<description></description>
<range min="0" max="3"/>
</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>
</schemalist>

View File

@ -0,0 +1,9 @@
export const PrefFields = {
ANCHOR_VERTICAL : 'anchor-vertical',
ANCHOR_HORIZONTAL : 'anchor-horizontal',
PADDING_VERTICAL : 'padding-vertical',
PADDING_HORIZONTAL : 'padding-horizontal',
ANIMATION_TIME : 'animation-time',
ANIMATION_DIRECTION : 'animation-direction',
ALWAYS_MINIMIZE : 'always-minimized',
};