Skip to content

Commit

Permalink
add class structure
Browse files Browse the repository at this point in the history
Gnome 40-44 allows for a class structure.
Gnome 45 REQUIRES it. So this is an easy transition.
  • Loading branch information
GrylledCheez committed Oct 31, 2023
1 parent 37f8af3 commit 5820ad7
Showing 1 changed file with 133 additions and 108 deletions.
241 changes: 133 additions & 108 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
/* global global */

/* BEGIN NON-G45 */
const Meta = imports.gi.Meta;
const Main = imports.ui.main;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;

const ExtensionUtils = imports.misc.extensionUtils;

const {Clutter, St} = imports.gi;

const Clutter = imports.gi.Clutter;
const St = imports.gi.St;
const Config = imports.misc.config;
const SHELL_VERSION = parseFloat(Config.PACKAGE_VERSION);
/* END NON-G45 */

/* BEGIN G45 */
// import Meta from 'gi://Meta';
// import * as Main from 'resource:///org/gnome/shell/ui/main.js';
// import Gio from 'gi://Gio';
// import GLib from 'gi://GLib';
// import Extension from 'resource:///org/gnome/shell/extensions/extension.js';
// import Clutter from 'gi://Clutter';
// import St from 'gi://St';
// import Config from imports.misc.config;
// const SHELL_VERSION = parseFloat(Config.PACKAGE_VERSION);
/* END G45 */

let onWindowGrabBegin, onWindowGrabEnd;
let requestMoveTimer, checkForMoveTimer, windowGrabBeginTimer, windowGrabEndTimer, checkIfNearGridTimer, keyManagerTimer;
Expand All @@ -20,7 +32,10 @@ let dragStart = null;
let gsettings;


// View logs with `journalctl -qf |grep -i -e Wintile -e 'js error' `
/* View logs with
journalctl -qf | grep -i -e Wintile -e 'js error'
*/

/**
* @param {string} message - the actual log to be logged
*/
Expand Down Expand Up @@ -1053,119 +1068,129 @@ function getMonitorInfo(monitorIndex) {
/**
*
*/
function enable() {
_log('enable) Keymanager is being defined');
keyManager = new KeyBindings.Manager();
let desktopSettings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.keybindings'});
let mutterKeybindingSettings = new Gio.Settings({schema_id: 'org.gnome.mutter.keybindings'});
let mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'});
try {
let shellSettings = new Gio.Settings({schema_id: 'org.gnome.shell.overrides'});
shellSettings.set_boolean('edge-tiling', false);
} catch (error) {
_log('enable) org.gnome.shell.overrides does not exist');
}
oldbindings['unmaximize'] = desktopSettings.get_strv('unmaximize');
oldbindings['maximize'] = desktopSettings.get_strv('maximize');
oldbindings['toggle_tiled_left'] = mutterKeybindingSettings.get_strv('toggle-tiled-left');
oldbindings['toggle_tiled_right'] = mutterKeybindingSettings.get_strv('toggle-tiled-right');
changeBinding(desktopSettings, 'unmaximize', '<Super>Down', '<Control><Shift><Super>Down');
changeBinding(desktopSettings, 'maximize', '<Super>Up', '<Control><Shift><Super>Up');
changeBinding(mutterKeybindingSettings, 'toggle-tiled-left', '<Super>Left', '<Control><Shift><Super>Left');
changeBinding(mutterKeybindingSettings, 'toggle-tiled-right', '<Super>Right', '<Control><Shift><Super>Right');
mutterSettings.set_boolean('edge-tiling', false);
keyManagerTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 3000, () => {
keyManager.add('<Super><Control>left', () => {
requestMove('left', true);
});
keyManager.add('<Super><Control>right', () => {
requestMove('right', true);
});
keyManager.add('<Super><Control>up', () => {
requestMove('up', true);
});
keyManager.add('<Super><Control>down', () => {
requestMove('down', true);
});
keyManager.add('<Super>left', () => {
requestMove('left');
});
keyManager.add('<Super>right', () => {
requestMove('right');
class WintileExtension {
enable() {
_log('enable) Keymanager is being defined');
keyManager = new KeyBindings.Manager();
let desktopSettings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.keybindings'});
let mutterKeybindingSettings = new Gio.Settings({schema_id: 'org.gnome.mutter.keybindings'});
let mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'});
try {
let shellSettings = new Gio.Settings({schema_id: 'org.gnome.shell.overrides'});
shellSettings.set_boolean('edge-tiling', false);
} catch (error) {
_log('enable) org.gnome.shell.overrides does not exist');
}
oldbindings['unmaximize'] = desktopSettings.get_strv('unmaximize');
oldbindings['maximize'] = desktopSettings.get_strv('maximize');
oldbindings['toggle_tiled_left'] = mutterKeybindingSettings.get_strv('toggle-tiled-left');
oldbindings['toggle_tiled_right'] = mutterKeybindingSettings.get_strv('toggle-tiled-right');
changeBinding(desktopSettings, 'unmaximize', '<Super>Down', '<Control><Shift><Super>Down');
changeBinding(desktopSettings, 'maximize', '<Super>Up', '<Control><Shift><Super>Up');
changeBinding(mutterKeybindingSettings, 'toggle-tiled-left', '<Super>Left', '<Control><Shift><Super>Left');
changeBinding(mutterKeybindingSettings, 'toggle-tiled-right', '<Super>Right', '<Control><Shift><Super>Right');
mutterSettings.set_boolean('edge-tiling', false);
keyManagerTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 3000, () => {
keyManager.add('<Super><Control>left', () => {
requestMove('left', true);
});
keyManager.add('<Super><Control>right', () => {
requestMove('right', true);
});
keyManager.add('<Super><Control>up', () => {
requestMove('up', true);
});
keyManager.add('<Super><Control>down', () => {
requestMove('down', true);
});
keyManager.add('<Super>left', () => {
requestMove('left');
});
keyManager.add('<Super>right', () => {
requestMove('right');
});
keyManager.add('<Super>up', () => {
requestMove('up');
});
keyManager.add('<Super>down', () => {
requestMove('down');
});
});
keyManager.add('<Super>up', () => {
requestMove('up');

// Since GNOME 40 the metaDisplay argument isn't passed anymore to these callbacks.
// We "translate" the parameters here so that things work on both GNOME 3 and 40.
onWindowGrabBegin = global.display.connect('grab-op-begin', (metaDisplay, metaScreen, metaWindow, metaGrabOp, _gpointer) => {
if (SHELL_VERSION >= 40)
windowGrabBegin(metaScreen, metaWindow);
else
windowGrabBegin(metaWindow, metaGrabOp);
});
keyManager.add('<Super>down', () => {
requestMove('down');
onWindowGrabEnd = global.display.connect('grab-op-end', (metaDisplay, metaScreen, metaWindow, metaGrabOp, _gpointer) => {
if (SHELL_VERSION >= 40)
windowGrabEnd(metaScreen, metaWindow);
else
windowGrabEnd(metaWindow, metaGrabOp);
});
});

// Since GNOME 40 the metaDisplay argument isn't passed anymore to these callbacks.
// We "translate" the parameters here so that things work on both GNOME 3 and 40.
onWindowGrabBegin = global.display.connect('grab-op-begin', (metaDisplay, metaScreen, metaWindow, metaGrabOp, _gpointer) => {
if (SHELL_VERSION >= 40)
windowGrabBegin(metaScreen, metaWindow);
else
windowGrabBegin(metaWindow, metaGrabOp);
});
onWindowGrabEnd = global.display.connect('grab-op-end', (metaDisplay, metaScreen, metaWindow, metaGrabOp, _gpointer) => {
if (SHELL_VERSION >= 40)
windowGrabEnd(metaScreen, metaWindow);
else
windowGrabEnd(metaWindow, metaGrabOp);
});
// Create a new gsettings object
preview = new St.BoxLayout({
style_class: 'tile-preview',
visible: false,
});
Main.uiGroup.add_actor(preview);

// Create a new gsettings object
preview = new St.BoxLayout({
style_class: 'tile-preview',
visible: false,
});
Main.uiGroup.add_actor(preview);
gsettings = ExtensionUtils.getSettings();
updateSettings();

gsettings = ExtensionUtils.getSettings();
updateSettings();
// Watch the gsettings for changes
gsettings.connect('changed', updateSettings.bind());
}

// Watch the gsettings for changes
gsettings.connect('changed', updateSettings.bind());
/**
*
*/
disable() {
_log('disable) Keymanager is being removed');
keyManager.removeAll();
keyManager.destroy();
keyManager = null;
let desktopSettings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.keybindings'});
let mutterKeybindingSettings = new Gio.Settings({schema_id: 'org.gnome.mutter.keybindings'});
let mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'});
try {
let shellSettings = new Gio.Settings({schema_id: 'org.gnome.shell.overrides'});
shellSettings.reset('edge-tiling');
} catch (error) {
_log('disable) org.gnome.shell.overrides does not exist');
}
desktopSettings.reset('unmaximize');
desktopSettings.reset('maximize');
desktopSettings = null;
mutterKeybindingSettings.reset('toggle-tiled-left');
mutterKeybindingSettings.reset('toggle-tiled-right');
mutterKeybindingSettings = null;
mutterSettings.reset('edge-tiling');
mutterSettings = null;
global.display.disconnect(onWindowGrabBegin);
global.display.disconnect(onWindowGrabEnd);
onWindowGrabBegin = null;
onWindowGrabEnd = null;
GLib.source_remove(requestMoveTimer);
GLib.source_remove(checkForMoveTimer);
GLib.source_remove(windowGrabBeginTimer);
GLib.source_remove(windowGrabEndTimer);
GLib.source_remove(checkIfNearGridTimer);
GLib.source_remove(keyManagerTimer);
gsettings = null;
preview = null;
dragStart = null;
}
}

/**
*
* @param {object} _meta = standard meta object
*/
function disable() {
_log('disable) Keymanager is being removed');
keyManager.removeAll();
keyManager.destroy();
keyManager = null;
let desktopSettings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.keybindings'});
let mutterKeybindingSettings = new Gio.Settings({schema_id: 'org.gnome.mutter.keybindings'});
let mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'});
try {
let shellSettings = new Gio.Settings({schema_id: 'org.gnome.shell.overrides'});
shellSettings.reset('edge-tiling');
} catch (error) {
_log('disable) org.gnome.shell.overrides does not exist');
}
desktopSettings.reset('unmaximize');
desktopSettings.reset('maximize');
desktopSettings = null;
mutterKeybindingSettings.reset('toggle-tiled-left');
mutterKeybindingSettings.reset('toggle-tiled-right');
mutterKeybindingSettings = null;
mutterSettings.reset('edge-tiling');
mutterSettings = null;
global.display.disconnect(onWindowGrabBegin);
global.display.disconnect(onWindowGrabEnd);
onWindowGrabBegin = null;
onWindowGrabEnd = null;
GLib.source_remove(requestMoveTimer);
GLib.source_remove(checkForMoveTimer);
GLib.source_remove(windowGrabBeginTimer);
GLib.source_remove(windowGrabEndTimer);
GLib.source_remove(checkIfNearGridTimer);
GLib.source_remove(keyManagerTimer);
gsettings = null;
preview = null;
dragStart = null;
function init(_meta) {
return new WintileExtension();
}

0 comments on commit 5820ad7

Please sign in to comment.