Skip to content

Commit

Permalink
Support Gnome 45 and 46.
Browse files Browse the repository at this point in the history
The switch from GJS custom imports to standard JavaScript modules in
Gnome 45 means this is not a backwards compatible change.
  • Loading branch information
rickybrent committed Apr 2, 2024
1 parent 9a0ad0f commit 8194b79
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 72 deletions.
100 changes: 51 additions & 49 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
// Forked from sunwxg/gnome-shell-extension-undecorate
// Apps preferences handling borrowed from https://github.com/eonpatapon/gnome-shell-extension-
const Lang = imports.lang;
const { Shell, GLib, Meta } = imports.gi;
const PopupMenu = imports.ui.popupMenu;
const WindowMenu = imports.ui.windowMenu.WindowMenu;
const ExtensionUtils = imports.misc.extensionUtils;
import GLib from 'gi://GLib';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as WindowMenu from 'resource:///org/gnome/shell/ui/windowMenu.js';
import { Extension, InjectionManager, gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js';

let old_buildMenu;
let windowCreatedId;

function init() {
// Cache the incoming `_buildMenu` class, to hook into.
old_buildMenu = WindowMenu.prototype._buildMenu;
}

// Overwrite the buildMenu method to hook our menu item into.
function enable() {
WindowMenu.prototype._buildMenu = newBuildMenu;

windowCreatedId = global.display.connect('window-created', (_, window) => {
// Automatically set this window up
const settings = ExtensionUtils.getSettings();

// Set defaults
let done = false;
const appSystem = Shell.AppSystem.get_default();

settings.get_strv('inhibit-apps').forEach(appId => {
//const window = global.display.focus_window;
if (done) {
return;
}
let windowCreatedId;

const app = appSystem.lookup_app(appId);
export default class UndecorateExtension extends Extension {
enable() {
// Overwrite the buildMenu method to hook our menu item into.
this._injectionManager = new InjectionManager();
this._injectionManager.overrideMethod(WindowMenu.WindowMenu.prototype, '_buildMenu',
old_buildMenu => {
return function (...args) {
old_buildMenu.call(this, ...args);
newBuildMenu.call(this, ...args)
}
})

const settings = this.getSettings();
windowCreatedId = global.display.connect('window-created', (_, window) => {
// Automatically set this window up
// Set defaults
let done = false;
const appSystem = Shell.AppSystem.get_default();

settings.get_strv('inhibit-apps').forEach(appId => {
//const window = global.display.focus_window;
if (done) {
return;
}

const app = appSystem.lookup_app(appId);

if (app.get_windows().includes(window)) {
undecorate(window);
windowGetFocus(window);
done = true;
}
});
});
}

if (app.get_windows().includes(window)) {
undecorate(window);
windowGetFocus(window);
done = true;
}
});
});
disable() {
this._injectionManager.clear();
this._injectionManager = null;
global.display.disconnect(windowCreatedId);
}
}

// Return to the original class method.
function disable() {
WindowMenu.prototype._buildMenu = old_buildMenu;

global.display.disconnect(windowCreatedId);
}

function undecorate(window) {
try {
Expand Down Expand Up @@ -92,22 +97,19 @@ function windowGetFocus(window) {
// Cannot use an arrow function here, as the function will be treated as a
// class method when invoked and we rely on `this`.
function newBuildMenu(window) {
let old = Lang.bind(this, old_buildMenu);
old(window);

this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

let item = {};
if (window.decorated) {
item = this.addAction(_('Undecorate'), Lang.bind(this, event => {
item = this.addAction(_('Undecorate'), event => {
undecorate(window);
windowGetFocus(window);
}));
});
} else {
item = this.addAction(_('Decorate'), Lang.bind(this, event => {
item = this.addAction(_('Decorate'), event => {
decorate(window);
windowGetFocus(window);
}));
});
}
if (window.get_window_type() == Meta.WindowType.DESKTOP) {
item.setSensitive(false);
Expand Down
10 changes: 2 additions & 8 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@
"[email protected]"
],
"shell-version": [
"3.20",
"3.22",
"3.24",
"40",
"41",
"42",
"43",
"44"
"45",
"46"
],
"settings-schema": "org.gnome.shell.extensions.undecorate",
"gettext-domain": "gnome-shell-extension-undecorate",
Expand Down
32 changes: 17 additions & 15 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

// loosely based on https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/blob/master/extensions/auto-move-windows/prefs.js

const { Gio, GLib, GObject, Gtk, Pango } = imports.gi;
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import Pango from 'gi://Pango';

const Gettext = imports.gettext.domain('gnome-shell-extension-undecorated');
const _ = Gettext.gettext;

const ExtensionUtils = imports.misc.extensionUtils;
import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';

var _settings;
const SettingsKey = {
INHIBIT_APPS: 'inhibit-apps',
};
Expand Down Expand Up @@ -41,7 +43,7 @@ const SettingListBoxRow = GObject.registerClass({
class SettingListBoxRow extends Gtk.ListBoxRow {
_init(label, description, settingsKey, type, options) {
this.rowType = type;
this._settings = ExtensionUtils.getSettings();
this._settings = _settings;

const _hbox = new Gtk.Box({
spacing: 12,
Expand Down Expand Up @@ -109,6 +111,7 @@ const AppsPane = GObject.registerClass(
super._init({
hscrollbar_policy: Gtk.PolicyType.NEVER,
});
this.set_min_content_height(450);

const box = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
Expand Down Expand Up @@ -137,7 +140,7 @@ const AppsPane = GObject.registerClass(
const context = this._list.get_style_context();
const cssProvider = new Gtk.CssProvider();
cssProvider.load_from_string(
'list { min-width: 30em; }');
'list { min-width: 25em; }');

context.add_provider(cssProvider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
Expand Down Expand Up @@ -168,7 +171,7 @@ const AppsPane = GObject.registerClass(
this._actionGroup.add_action(action);
this._updateAction = action;

this._settings = ExtensionUtils.getSettings();
this._settings = _settings;
this._changedId = this._settings.connect('changed',
this._sync.bind(this));
this._sync();
Expand Down Expand Up @@ -306,7 +309,7 @@ const NewAppDialog = GObject.registerClass(
modal: true,
});

this._settings = ExtensionUtils.getSettings();
this._settings = _settings;

this.get_widget().set({
show_all: true,
Expand Down Expand Up @@ -337,10 +340,9 @@ const UndecoratedSettingsWidget = GObject.registerClass(
}
);

function init() {
ExtensionUtils.initTranslations();
}

function buildPrefsWidget() {
return new UndecoratedSettingsWidget();
export default class UndecoratePrefs extends ExtensionPreferences {
getPreferencesWidget() {
_settings = this.getSettings();
return new UndecoratedSettingsWidget();
}
}
Binary file added [email protected]/schemas/gschemas.compiled
Binary file not shown.

0 comments on commit 8194b79

Please sign in to comment.