Skip to content

Commit 78f2c7d

Browse files
committed
proper multi-GNOME version support, updates from fork, bugfixes, co-exist with Ubuntu tiler extension
1 parent 82a07a8 commit 78f2c7d

File tree

10 files changed

+234
-112
lines changed

10 files changed

+234
-112
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
1+
build/*
22
node_modules/
33
package-lock.json
44
package.json
5+
dist

build.sh

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,77 @@
11
#!/bin/bash
22

3-
3+
G45() {
4+
local FILE="${1}"
5+
IN_NON_G45=0
6+
IN_G45=0
7+
while IFS= read -r LINE; do
8+
if [[ "${LINE}" = *"/* END NON-G45 */"* ]]; then
9+
IN_NON_G45=0
10+
elif [[ "${LINE}" = *"/* END G45 */"* ]]; then
11+
IN_G45=0
12+
fi
13+
if (( IN_G45 == 1 )); then
14+
echo "${LINE}" | sed -E 's|^(\s+)?// |\1|'
15+
elif (( IN_NON_G45 == 1 )) && ! [[ ${LINE} =~ ^[[:space:]]*// ]]; then
16+
echo "${LINE}" | sed -E 's|^(\s+)?|\1// |'
17+
else
18+
echo "${LINE}"
19+
fi
20+
if [[ "${LINE}" = *"/* BEGIN NON-G45 */"* ]]; then
21+
IN_NON_G45=1
22+
elif [[ "${LINE}" = *"/* BEGIN G45 */"* ]]; then
23+
IN_G45=1
24+
fi
25+
done < "${FILE}"
26+
}
27+
28+
NON_G45() {
29+
local FILE="${1}"
30+
IN_NON_G45=0
31+
IN_G45=0
32+
while IFS= read -r LINE; do
33+
if [[ "${LINE}" = *"/* END NON-G45 */"* ]]; then
34+
IN_NON_G45=0
35+
elif [[ "${LINE}" = *"/* END G45 */"* ]]; then
36+
IN_G45=0
37+
fi
38+
if (( IN_G45 == 1 )) && ! [[ ${LINE} =~ ^[[:space:]]*// ]]; then
39+
echo "${LINE}" | sed -E 's|^(\s+)?|\1// |'
40+
elif (( IN_NON_G45 == 1 )); then
41+
echo "${LINE}" | sed -E 's|^(\s+)?// |\1|'
42+
else
43+
echo "${LINE}"
44+
fi
45+
if [[ "${LINE}" = *"/* BEGIN NON-G45 */"* ]]; then
46+
IN_NON_G45=1
47+
elif [[ "${LINE}" = *"/* BEGIN G45 */"* ]]; then
48+
IN_G45=1
49+
fi
50+
done < "${FILE}"
51+
}
52+
53+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
54+
cd "${SCRIPT_DIR}"
55+
56+
rm -rf dist
57+
mkdir -p dist/G43/build
58+
mkdir -p dist/G45/build
59+
460
glib-compile-schemas schemas/
61+
62+
FILES="extension.js keybindings.js prefs.js"
63+
for FILE in ${FILES}; do
64+
NON_G45 ${FILE} > dist/G43/build/${FILE}
65+
G45 ${FILE} > dist/G45/build/${FILE}
66+
done
67+
cp -a settings.ui schemas dist/G43/build/
68+
cp -a settings.ui schemas dist/G45/build/
69+
cp -a metadata.json dist/G43/build/metadata.json
70+
cp -a metadata-45.json dist/G45/build/metadata.json
71+
72+
cd dist/G43/build
73+
zip -r9 [email protected] extension.js keybindings.js metadata.json prefs.js settings.ui schemas
74+
75+
cd ../../G45/build
576
zip -r9 [email protected] extension.js keybindings.js metadata.json prefs.js settings.ui schemas
77+

build/.gitkeep

Whitespace-only changes.

extension.js

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
/* global global */
22

3+
34
/* BEGIN NON-G45 */
4-
// const Meta = imports.gi.Meta;
5-
// const Main = imports.ui.main;
6-
// const Gio = imports.gi.Gio;
7-
// const GLib = imports.gi.GLib;
8-
// const ExtensionUtils = imports.misc.extensionUtils;
9-
// const Clutter = imports.gi.Clutter;
10-
// const St = imports.gi.St;
11-
// const Config = imports.misc.config;
12-
// const SHELL_VERSION = parseFloat(Config.PACKAGE_VERSION);
5+
const Meta = imports.gi.Meta;
6+
const Main = imports.ui.main;
7+
const Gio = imports.gi.Gio;
8+
const GLib = imports.gi.GLib;
9+
const Extension = imports.misc.extensionUtils.getCurrentExtension();
10+
const Clutter = imports.gi.Clutter;
11+
const St = imports.gi.St;
12+
const Config = imports.misc.config;
13+
const ExtensionUtils = imports.misc.extensionUtils;
14+
const Me = ExtensionUtils.getCurrentExtension();
15+
const KeyBindingsManager = Me.imports.keybindings.KeyBindingsManager;
16+
const SHELL_VERSION = parseFloat(Config.PACKAGE_VERSION);
1317
/* END NON-G45 */
1418

1519
/* BEGIN G45 */
16-
import Meta from 'gi://Meta';
17-
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
18-
import Gio from 'gi://Gio';
19-
import GLib from 'gi://GLib';
20-
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
21-
import Clutter from 'gi://Clutter';
22-
import St from 'gi://St';
23-
import {PACKAGE_VERSION} from 'resource:///org/gnome/shell/misc/config.js';
24-
import KeyBindingsManager from './keybindings.js';
25-
const SHELL_VERSION = parseFloat(PACKAGE_VERSION);
20+
// import Meta from 'gi://Meta';
21+
// import * as Main from 'resource:///org/gnome/shell/ui/main.js';
22+
// import Gio from 'gi://Gio';
23+
// import GLib from 'gi://GLib';
24+
// import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
25+
// import Clutter from 'gi://Clutter';
26+
// import St from 'gi://St';
27+
// import {PACKAGE_VERSION} from 'resource:///org/gnome/shell/misc/config.js';
28+
// import KeyBindingsManager from './keybindings.js';
29+
// const SHELL_VERSION = parseFloat(PACKAGE_VERSION);
2630
/* END G45 */
2731

2832
let onWindowGrabBegin, onWindowGrabEnd;
@@ -42,7 +46,7 @@ journalctl -qf | grep -i -e Wintile -e 'js error'
4246
*/
4347
function _log(message) {
4448
if (config.debug)
45-
log('[WinTile]', message);
49+
console.log('[Wintile]', message);
4650
}
4751

4852
let config = {
@@ -83,16 +87,6 @@ function updateSettings() {
8387
_log(JSON.stringify(config));
8488
}
8589

86-
/* BEGIN NON-G45 */
87-
// const wintile = {
88-
// extdatadir: imports.misc.extensionUtils.getCurrentExtension().path,
89-
// shell_version: parseInt(Config.PACKAGE_VERSION.split('.')[1], 10),
90-
// };
91-
// imports.searchPath.unshift(wintile.extdatadir);
92-
93-
// const KeyBindings = imports.keybindings;
94-
/* END NON-G45 */
95-
9690
let keyManager = null;
9791
var oldbindings = {
9892
unmaximize: [],
@@ -329,6 +323,10 @@ function sendMove(direction, ctrlPressed = false) {
329323
_log('---');
330324
_log(`sendMove) ${direction} ctrl: ${ctrlPressed}`);
331325
var app = global.display.focus_window;
326+
if (!app) {
327+
_log('no window selected');
328+
return;
329+
}
332330
var monitorIndex = app.get_monitor();
333331
var curMonitor = getMonitorInfo(monitorIndex);
334332

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

10761075
/* BEGIN NON-G45 */
1077-
// class WintileExtension {
1076+
var WintileExtension = class WintileExtension {
10781077
/* END NON-G45 */
10791078

10801079
/* BEGIN G45 */
1081-
export default class WintileExtension extends Extension {
1080+
// export default class WintileExtension extends Extension {
10821081
/* END G45 */
1082+
10831083
enable() {
10841084
_log('enable) Keymanager is being defined');
10851085

1086+
/* BEGIN NON-G45 */
1087+
keyManager = new KeyBindingsManager(`${Me.path}/schemas`);
1088+
/* END NON-G45 */
1089+
10861090
/* BEGIN G45 */
1087-
keyManager = new KeyBindingsManager();
1091+
// keyManager = new KeyBindingsManager();
10881092
/* END G45 */
10891093

1090-
/* BEGIN NON-G45 */
1091-
// keyManager = new KeyBindings.Manager();
1092-
/* END NON-G45 */
10931094
let desktopSettings = new Gio.Settings({schema_id: 'org.gnome.desktop.wm.keybindings'});
10941095
let mutterKeybindingSettings = new Gio.Settings({schema_id: 'org.gnome.mutter.keybindings'});
10951096
let mutterSettings = new Gio.Settings({schema_id: 'org.gnome.mutter'});
@@ -1108,6 +1109,19 @@ export default class WintileExtension extends Extension {
11081109
changeBinding(mutterKeybindingSettings, 'toggle-tiled-left', '<Super>Left', '<Control><Shift><Super>Left');
11091110
changeBinding(mutterKeybindingSettings, 'toggle-tiled-right', '<Super>Right', '<Control><Shift><Super>Right');
11101111
mutterSettings.set_boolean('edge-tiling', false);
1112+
try {
1113+
let tilingAssistantSettings = new Gio.Settings({schema_id: 'org.gnome.shell.extensions.tiling-assistant'});
1114+
oldbindings['restore-window'] = tilingAssistantSettings.get_strv('restore-window');
1115+
oldbindings['tile-left-half'] = tilingAssistantSettings.get_strv('tile-left-half');
1116+
oldbindings['tile-maximize'] = tilingAssistantSettings.get_strv('tile-maximize');
1117+
oldbindings['tile-right-half'] = tilingAssistantSettings.get_strv('tile-right-half');
1118+
changeBinding(tilingAssistantSettings, 'restore-window', '<Super>Down', '<Alt><Shift><Super>Down');
1119+
changeBinding(tilingAssistantSettings, 'tile-left-half', '<Super>Left', '<Alt><Shift><Super>Left');
1120+
changeBinding(tilingAssistantSettings, 'tile-maximize', '<Super>Up', '<Alt><Shift><Super>Up');
1121+
changeBinding(tilingAssistantSettings, 'tile-right-half', '<Super>Right', '<Alt><Shift><Super>Right');
1122+
} catch (error) {
1123+
_log('enable) org.gnome.shell.extensions.tiling-assistant does not exist');
1124+
}
11111125
keyManagerTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 3000, () => {
11121126
keyManager.add('<Super><Control>left', () => {
11131127
requestMove('left', true);
@@ -1135,35 +1149,31 @@ export default class WintileExtension extends Extension {
11351149
});
11361150
});
11371151

1138-
// Since GNOME 40 the metaDisplay argument isn't passed anymore to these callbacks.
1139-
// We "translate" the parameters here so that things work on both GNOME 3 and 40.
1140-
onWindowGrabBegin = global.display.connect('grab-op-begin', (metaDisplay, metaScreen, metaWindow, metaGrabOp, _gpointer) => {
1141-
if (SHELL_VERSION >= 40)
1142-
windowGrabBegin(metaScreen, metaWindow);
1143-
else
1144-
windowGrabBegin(metaWindow, metaGrabOp);
1152+
onWindowGrabBegin = global.display.connect('grab-op-begin', (metaDisplay, metaScreen, metaWindow, _metaGrabOp, _gpointer) => {
1153+
windowGrabBegin(metaScreen, metaWindow);
11451154
});
1146-
onWindowGrabEnd = global.display.connect('grab-op-end', (metaDisplay, metaScreen, metaWindow, metaGrabOp, _gpointer) => {
1147-
if (SHELL_VERSION >= 40)
1148-
windowGrabEnd(metaScreen, metaWindow);
1149-
else
1150-
windowGrabEnd(metaWindow, metaGrabOp);
1155+
onWindowGrabEnd = global.display.connect('grab-op-end', (metaDisplay, metaScreen, metaWindow, _metaGrabOp, _gpointer) => {
1156+
windowGrabEnd(metaScreen, metaWindow);
11511157
});
11521158

11531159
// Create a new gsettings object
11541160
preview = new St.BoxLayout({
11551161
style_class: 'tile-preview',
11561162
visible: false,
11571163
});
1158-
Main.uiGroup.add_actor(preview);
1164+
if (SHELL_VERSION < 46.0)
1165+
Main.uiGroup.add_actor(preview);
1166+
else
1167+
Main.uiGroup.add_child(preview);
1168+
1169+
/* BEGIN NON-G45 */
1170+
gsettings = ExtensionUtils.getSettings();
1171+
/* END NON-G45 */
11591172

11601173
/* BEGIN G45 */
1161-
gsettings = this.getSettings();
1174+
// gsettings = this.getSettings();
11621175
/* END G45 */
11631176

1164-
/* BEGIN NON-G45 */
1165-
// gsettings = ExtensionUtils.getSettings();
1166-
/* END NON-G45 */
11671177
updateSettings();
11681178

11691179
// Watch the gsettings for changes
@@ -1195,6 +1205,16 @@ export default class WintileExtension extends Extension {
11951205
mutterKeybindingSettings = null;
11961206
mutterSettings.reset('edge-tiling');
11971207
mutterSettings = null;
1208+
try {
1209+
let tilingAssistantSettings = new Gio.Settings({schema_id: 'org.gnome.shell.extensions.tiling-assistant'});
1210+
tilingAssistantSettings.reset('restore-window');
1211+
tilingAssistantSettings.reset('tile-left-half');
1212+
tilingAssistantSettings.reset('tile-maximize');
1213+
tilingAssistantSettings.reset('tile-right-half');
1214+
tilingAssistantSettings = null;
1215+
} catch (error) {
1216+
_log('disable) org.gnome.shell.extensions.tiling-assistant does not exist');
1217+
}
11981218
global.display.disconnect(onWindowGrabBegin);
11991219
global.display.disconnect(onWindowGrabEnd);
12001220
onWindowGrabBegin = null;
@@ -1212,11 +1232,7 @@ export default class WintileExtension extends Extension {
12121232
}
12131233

12141234
/* BEGIN NON-G45 */
1215-
// /**
1216-
// *
1217-
// * @param {object} _meta = standard meta object
1218-
// */
1219-
// function init(_meta) {
1220-
// return new WintileExtension();
1221-
// }
1235+
function init() {
1236+
return new WintileExtension();
1237+
}
12221238
/* END NON-G45 */

keybindings.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
/* global global */
33

44
/* BEGIN NON-G45 */
5-
// const Main = imports.ui.main;
6-
// const Meta = imports.gi.Meta;
7-
// const Shell = imports.gi.Shell;
5+
const Main = imports.ui.main;
6+
const Meta = imports.gi.Meta;
7+
const Shell = imports.gi.Shell;
88
/* END NON-G45 */
99

1010
/* BEGIN G45 */
11-
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
12-
import Meta from 'gi://Meta';
13-
import Shell from 'gi://Shell';
11+
// import * as Main from 'resource:///org/gnome/shell/ui/main.js';
12+
// import Meta from 'gi://Meta';
13+
// import Shell from 'gi://Shell';
1414
/* END G45 */
1515

1616
/**
@@ -29,10 +29,10 @@ import Shell from 'gi://Shell';
2929
* https://gitlab.gnome.org/GNOME/gnome-shell/blob/master/js/ui/windowManager.js#L1093-1112
3030
*/
3131
/* BEGIN NON-G45 */
32-
// var Manager = class Manager {
32+
var KeyBindingsManager = class KeyBindingsManager {
3333
/* END NON-G45 */
3434
/* BEGIN G45 */
35-
export default class KeyBindingsManager {
35+
// export default class KeyBindingsManager {
3636
/* END G45 */
3737
constructor() {
3838
this._keybindings = new Map();

metadata-45.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "WinTile",
3+
"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",
4+
"uuid": "[email protected]",
5+
"url": "https://nowsci.com/wintile/",
6+
"settings-schema":"org.gnome.shell.extensions.wintile",
7+
"shell-version": [
8+
"45",
9+
"46",
10+
"47"
11+
],
12+
"version": 19
13+
}

metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "WinTile",
3-
"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",
3+
"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",
44
"uuid": "[email protected]",
5-
"url": "https://github.com/fmstrat/wintile",
5+
"url": "https://nowsci.com/wintile/",
66
"settings-schema":"org.gnome.shell.extensions.wintile",
77
"shell-version": [
8-
"45"
8+
"43"
99
],
10-
"version": 17
10+
"version": 18
1111
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wintile",
3-
"version": "11.0.0",
3+
"version": "19.0.0",
44
"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>`.",
55
"main": "extension.js",
66
"scripts": {
@@ -15,9 +15,9 @@
1515
"bugs": {
1616
"url": "https://github.com/Fmstrat/wintile/issues"
1717
},
18-
"homepage": "https://github.com/Fmstrat/wintile#readme",
18+
"homepage": "https://nowsci.com/wintile/",
1919
"devDependencies": {
20-
"eslint": "^8.44.0",
20+
"eslint": "^8.57.0",
2121
"eslint-plugin-jsdoc": "^45.0.0"
2222
}
2323
}

0 commit comments

Comments
 (0)