Skip to content

Commit

Permalink
proper multi-GNOME version support, updates from fork, bugfixes, co-e…
Browse files Browse the repository at this point in the history
…xist with Ubuntu tiler extension
  • Loading branch information
Fmstrat committed Nov 22, 2024
1 parent 82a07a8 commit 78f2c7d
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
wintile@nowsci.com.zip
build/*
node_modules/
package-lock.json
package.json
dist
74 changes: 73 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
#!/bin/bash

rm wintile@nowsci.com.zip
G45() {
local FILE="${1}"
IN_NON_G45=0
IN_G45=0
while IFS= read -r LINE; do
if [[ "${LINE}" = *"/* END NON-G45 */"* ]]; then
IN_NON_G45=0
elif [[ "${LINE}" = *"/* END G45 */"* ]]; then
IN_G45=0
fi
if (( IN_G45 == 1 )); then
echo "${LINE}" | sed -E 's|^(\s+)?// |\1|'
elif (( IN_NON_G45 == 1 )) && ! [[ ${LINE} =~ ^[[:space:]]*// ]]; then
echo "${LINE}" | sed -E 's|^(\s+)?|\1// |'
else
echo "${LINE}"
fi
if [[ "${LINE}" = *"/* BEGIN NON-G45 */"* ]]; then
IN_NON_G45=1
elif [[ "${LINE}" = *"/* BEGIN G45 */"* ]]; then
IN_G45=1
fi
done < "${FILE}"
}

NON_G45() {
local FILE="${1}"
IN_NON_G45=0
IN_G45=0
while IFS= read -r LINE; do
if [[ "${LINE}" = *"/* END NON-G45 */"* ]]; then
IN_NON_G45=0
elif [[ "${LINE}" = *"/* END G45 */"* ]]; then
IN_G45=0
fi
if (( IN_G45 == 1 )) && ! [[ ${LINE} =~ ^[[:space:]]*// ]]; then
echo "${LINE}" | sed -E 's|^(\s+)?|\1// |'
elif (( IN_NON_G45 == 1 )); then
echo "${LINE}" | sed -E 's|^(\s+)?// |\1|'
else
echo "${LINE}"
fi
if [[ "${LINE}" = *"/* BEGIN NON-G45 */"* ]]; then
IN_NON_G45=1
elif [[ "${LINE}" = *"/* BEGIN G45 */"* ]]; then
IN_G45=1
fi
done < "${FILE}"
}

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "${SCRIPT_DIR}"

rm -rf dist
mkdir -p dist/G43/build
mkdir -p dist/G45/build

glib-compile-schemas schemas/

FILES="extension.js keybindings.js prefs.js"
for FILE in ${FILES}; do
NON_G45 ${FILE} > dist/G43/build/${FILE}
G45 ${FILE} > dist/G45/build/${FILE}
done
cp -a settings.ui schemas dist/G43/build/
cp -a settings.ui schemas dist/G45/build/
cp -a metadata.json dist/G43/build/metadata.json
cp -a metadata-45.json dist/G45/build/metadata.json

cd dist/G43/build
zip -r9 wintile@nowsci.com.zip extension.js keybindings.js metadata.json prefs.js settings.ui schemas
mv wintile@nowsci.com.zip ..
cd ../../G45/build
zip -r9 wintile@nowsci.com.zip extension.js keybindings.js metadata.json prefs.js settings.ui schemas
mv wintile@nowsci.com.zip ..
Empty file added build/.gitkeep
Empty file.
136 changes: 76 additions & 60 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
/* 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 = imports.gi.Clutter;
// const St = imports.gi.St;
// const Config = imports.misc.config;
// const SHELL_VERSION = parseFloat(Config.PACKAGE_VERSION);
const Meta = imports.gi.Meta;
const Main = imports.ui.main;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Extension = imports.misc.extensionUtils.getCurrentExtension();
const Clutter = imports.gi.Clutter;
const St = imports.gi.St;
const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const KeyBindingsManager = Me.imports.keybindings.KeyBindingsManager;
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 {PACKAGE_VERSION} from 'resource:///org/gnome/shell/misc/config.js';
import KeyBindingsManager from './keybindings.js';
const SHELL_VERSION = parseFloat(PACKAGE_VERSION);
// 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 {PACKAGE_VERSION} from 'resource:///org/gnome/shell/misc/config.js';
// import KeyBindingsManager from './keybindings.js';
// const SHELL_VERSION = parseFloat(PACKAGE_VERSION);
/* END G45 */

let onWindowGrabBegin, onWindowGrabEnd;
Expand All @@ -42,7 +46,7 @@ journalctl -qf | grep -i -e Wintile -e 'js error'
*/
function _log(message) {
if (config.debug)
log('[WinTile]', message);
console.log('[Wintile]', message);
}

let config = {
Expand Down Expand Up @@ -83,16 +87,6 @@ function updateSettings() {
_log(JSON.stringify(config));
}

/* BEGIN NON-G45 */
// const wintile = {
// extdatadir: imports.misc.extensionUtils.getCurrentExtension().path,
// shell_version: parseInt(Config.PACKAGE_VERSION.split('.')[1], 10),
// };
// imports.searchPath.unshift(wintile.extdatadir);

// const KeyBindings = imports.keybindings;
/* END NON-G45 */

let keyManager = null;
var oldbindings = {
unmaximize: [],
Expand Down Expand Up @@ -329,6 +323,10 @@ function sendMove(direction, ctrlPressed = false) {
_log('---');
_log(`sendMove) ${direction} ctrl: ${ctrlPressed}`);
var app = global.display.focus_window;
if (!app) {
_log('no window selected');
return;
}
var monitorIndex = app.get_monitor();
var curMonitor = getMonitorInfo(monitorIndex);

Expand Down Expand Up @@ -712,6 +710,7 @@ function windowGrabEnd(metaWindow, metaGrabOp) {
*/
function changeBinding(settingsObject, key, oldBinding, newBinding) {
var binding = oldbindings[key.replace(/-/g, '_')];
if (!binding) binding = oldbindings[key];
var _newbindings = [];
for (var i = 0; i < binding.length; i++) {
let currentbinding = binding[i];
Expand Down Expand Up @@ -1074,22 +1073,24 @@ function getMonitorInfo(monitorIndex) {
*/

/* BEGIN NON-G45 */
// class WintileExtension {
var WintileExtension = class WintileExtension {
/* END NON-G45 */

/* BEGIN G45 */
export default class WintileExtension extends Extension {
// export default class WintileExtension extends Extension {
/* END G45 */

enable() {
_log('enable) Keymanager is being defined');

/* BEGIN NON-G45 */
keyManager = new KeyBindingsManager(`${Me.path}/schemas`);
/* END NON-G45 */

/* BEGIN G45 */
keyManager = new KeyBindingsManager();
// keyManager = new KeyBindingsManager();
/* END G45 */

/* BEGIN NON-G45 */
// keyManager = new KeyBindings.Manager();
/* END NON-G45 */
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'});
Expand All @@ -1108,6 +1109,19 @@ export default class WintileExtension extends Extension {
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);
try {
let tilingAssistantSettings = new Gio.Settings({schema_id: 'org.gnome.shell.extensions.tiling-assistant'});
oldbindings['restore-window'] = tilingAssistantSettings.get_strv('restore-window');
oldbindings['tile-left-half'] = tilingAssistantSettings.get_strv('tile-left-half');
oldbindings['tile-maximize'] = tilingAssistantSettings.get_strv('tile-maximize');
oldbindings['tile-right-half'] = tilingAssistantSettings.get_strv('tile-right-half');
changeBinding(tilingAssistantSettings, 'restore-window', '<Super>Down', '<Alt><Shift><Super>Down');
changeBinding(tilingAssistantSettings, 'tile-left-half', '<Super>Left', '<Alt><Shift><Super>Left');
changeBinding(tilingAssistantSettings, 'tile-maximize', '<Super>Up', '<Alt><Shift><Super>Up');
changeBinding(tilingAssistantSettings, 'tile-right-half', '<Super>Right', '<Alt><Shift><Super>Right');
} catch (error) {
_log('enable) org.gnome.shell.extensions.tiling-assistant does not exist');
}
keyManagerTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 3000, () => {
keyManager.add('<Super><Control>left', () => {
requestMove('left', true);
Expand Down Expand Up @@ -1135,35 +1149,31 @@ export default class WintileExtension extends Extension {
});
});

// 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);
onWindowGrabBegin = global.display.connect('grab-op-begin', (metaDisplay, metaScreen, metaWindow, _metaGrabOp, _gpointer) => {
windowGrabBegin(metaScreen, metaWindow);
});
onWindowGrabEnd = global.display.connect('grab-op-end', (metaDisplay, metaScreen, metaWindow, metaGrabOp, _gpointer) => {
if (SHELL_VERSION >= 40)
windowGrabEnd(metaScreen, metaWindow);
else
windowGrabEnd(metaWindow, metaGrabOp);
onWindowGrabEnd = global.display.connect('grab-op-end', (metaDisplay, metaScreen, metaWindow, _metaGrabOp, _gpointer) => {
windowGrabEnd(metaScreen, metaWindow);
});

// Create a new gsettings object
preview = new St.BoxLayout({
style_class: 'tile-preview',
visible: false,
});
Main.uiGroup.add_actor(preview);
if (SHELL_VERSION < 46.0)
Main.uiGroup.add_actor(preview);
else
Main.uiGroup.add_child(preview);

/* BEGIN NON-G45 */
gsettings = ExtensionUtils.getSettings();
/* END NON-G45 */

/* BEGIN G45 */
gsettings = this.getSettings();
// gsettings = this.getSettings();
/* END G45 */

/* BEGIN NON-G45 */
// gsettings = ExtensionUtils.getSettings();
/* END NON-G45 */
updateSettings();

// Watch the gsettings for changes
Expand Down Expand Up @@ -1195,6 +1205,16 @@ export default class WintileExtension extends Extension {
mutterKeybindingSettings = null;
mutterSettings.reset('edge-tiling');
mutterSettings = null;
try {
let tilingAssistantSettings = new Gio.Settings({schema_id: 'org.gnome.shell.extensions.tiling-assistant'});
tilingAssistantSettings.reset('restore-window');
tilingAssistantSettings.reset('tile-left-half');
tilingAssistantSettings.reset('tile-maximize');
tilingAssistantSettings.reset('tile-right-half');
tilingAssistantSettings = null;
} catch (error) {
_log('disable) org.gnome.shell.extensions.tiling-assistant does not exist');
}
global.display.disconnect(onWindowGrabBegin);
global.display.disconnect(onWindowGrabEnd);
onWindowGrabBegin = null;
Expand All @@ -1212,11 +1232,7 @@ export default class WintileExtension extends Extension {
}

/* BEGIN NON-G45 */
// /**
// *
// * @param {object} _meta = standard meta object
// */
// function init(_meta) {
// return new WintileExtension();
// }
function init() {
return new WintileExtension();
}
/* END NON-G45 */
16 changes: 8 additions & 8 deletions keybindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
/* global global */

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

/* BEGIN G45 */
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
// import * as Main from 'resource:///org/gnome/shell/ui/main.js';
// import Meta from 'gi://Meta';
// import Shell from 'gi://Shell';
/* END G45 */

/**
Expand All @@ -29,10 +29,10 @@ import Shell from 'gi://Shell';
* https://gitlab.gnome.org/GNOME/gnome-shell/blob/master/js/ui/windowManager.js#L1093-1112
*/
/* BEGIN NON-G45 */
// var Manager = class Manager {
var KeyBindingsManager = class KeyBindingsManager {
/* END NON-G45 */
/* BEGIN G45 */
export default class KeyBindingsManager {
// export default class KeyBindingsManager {
/* END G45 */
constructor() {
this._keybindings = new Map();
Expand Down
13 changes: 13 additions & 0 deletions metadata-45.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "WinTile",
"description": "WinTile is a hotkey driven window tiling system for GNOME that imitates the standard Win-Arrow keys of Windows 10, allowing you to maximize, maximize to sides, or 1/4 sized to corner across a single or multiple monitors using just Super+Arrow.\n\nWinTile also supports:\n- 1-5 columns and 1-5 rows for standard or ultrawide monitors\n- Top/bottom half support\n- Mouse preview and snapping for placing windows\n- 'Maximize' mode, which adds/removes GNOME animations\n- 'Ultrawide-only' mode, to allow standard screens to have different cols/row than ultrawides\n- Portrait screens will automatically swap columns and rows\n- Add gaps around tiles to avoid the 'crowded elevator' feeling'\n- Ctrl+Super+Arrow to grow a tile in that direction if space is available\n- Ctrl+drag to drop a tile in a specific spot\n- Ctrl+Super+drag to draw a grid for the new tile",
"uuid": "wintile@nowsci.com",
"url": "https://nowsci.com/wintile/",
"settings-schema":"org.gnome.shell.extensions.wintile",
"shell-version": [
"45",
"46",
"47"
],
"version": 19
}
8 changes: 4 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "WinTile",
"description": "WinTile is a hotkey driven window tiling system for GNOME that imitates the standard Win-Arrow keys of Windows 10, allowing you to maximize, maximize to sides, or 1/4 sized to corner across a single or multiple monitors using just Super+Arrow.\n\nAs of v17, WinTile also supports:\n- 1-5 columns and 1-5 rows for standard or ultrawide monitors\n- Top/bottom half support\n- Mouse preview and snapping for placing windows\n- 'Maximize' mode, which adds/removes GNOME animations\n- 'Ultrawide-only' mode, to allow standard screens to have different cols/row than ultrawides\n- Portrait screens will automatically swap columns and rows\n- Add gaps around tiles to avoid the 'crowded elevator' feeling'\n- Ctrl+Super+Arrow to grow a tile in that direction if space is available\n- Ctrl+drag to drop a tile in a specific spot\n- Ctrl+Super+drag to draw a grid for the new tile",
"description": "WinTile is a hotkey driven window tiling system for GNOME that imitates the standard Win-Arrow keys of Windows 10, allowing you to maximize, maximize to sides, or 1/4 sized to corner across a single or multiple monitors using just Super+Arrow.\n\nWinTile also supports:\n- 1-5 columns and 1-5 rows for standard or ultrawide monitors\n- Top/bottom half support\n- Mouse preview and snapping for placing windows\n- 'Maximize' mode, which adds/removes GNOME animations\n- 'Ultrawide-only' mode, to allow standard screens to have different cols/row than ultrawides\n- Portrait screens will automatically swap columns and rows\n- Add gaps around tiles to avoid the 'crowded elevator' feeling'\n- Ctrl+Super+Arrow to grow a tile in that direction if space is available\n- Ctrl+drag to drop a tile in a specific spot\n- Ctrl+Super+drag to draw a grid for the new tile",
"uuid": "wintile@nowsci.com",
"url": "https://github.com/fmstrat/wintile",
"url": "https://nowsci.com/wintile/",
"settings-schema":"org.gnome.shell.extensions.wintile",
"shell-version": [
"45"
"43"
],
"version": 17
"version": 18
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wintile",
"version": "11.0.0",
"version": "19.0.0",
"description": "WinTile: Windows 10 window tiling for GNOME =========================================== WinTile is a hotkey driven window tiling system for GNOME that imitates the standard `Win-Arrow` keys of Windows 10, allowing you to maximize, maximize to sides, or 1/4 sized to corner a window using just `<Super>`+`<Arrows>`.",
"main": "extension.js",
"scripts": {
Expand All @@ -15,9 +15,9 @@
"bugs": {
"url": "https://github.com/Fmstrat/wintile/issues"
},
"homepage": "https://github.com/Fmstrat/wintile#readme",
"homepage": "https://nowsci.com/wintile/",
"devDependencies": {
"eslint": "^8.44.0",
"eslint": "^8.57.0",
"eslint-plugin-jsdoc": "^45.0.0"
}
}
Loading

0 comments on commit 78f2c7d

Please sign in to comment.