Skip to content

Commit

Permalink
Merge branch 'fixes-gnome-44-support' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jtaala committed May 19, 2023
2 parents 154fbb3 + 18db715 commit 6b50846
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 56 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
PaperWM is an experimental [Gnome Shell](https://wiki.gnome.org/Projects/GnomeShell) extension providing scrollable tiling of windows and per monitor workspaces. It's inspired by paper notebooks and tiling window managers.

Supports Gnome Shell from 3.28 to 43 on X11 and wayland.
Supports Gnome Shell from 3.28 to 44 on X11 and wayland.

>**Note:** while PaperWM can be installed on a wide range of Gnome versions, new features aren't generally backported to prevous Gnome Shell versions. Fixes may be backported on request (please submit a [new issue](https://github.com/paperwm/PaperWM/issues/new/choose) if you've identified a recent fix that should be backported and you can help with testing).
While technically an [extension](https://wiki.gnome.org/Projects/GnomeShell/Extensions) it's to a large extent built on top of the Gnome desktop rather than merely extending it.

Expand All @@ -16,8 +18,8 @@ We hang out on [zulip](https://paperwm.zulipchat.com).

Clone the repo and check out the branch supporting the Gnome Shell version you're running.

- 44 (experimental, not officially supported yet, please report bugs): https://github.com/paperwm/PaperWM/tree/develop
- 43 (experimental, please report bugs): https://github.com/paperwm/PaperWM/tree/develop
- 44 (targeted for current support): https://github.com/paperwm/PaperWM/tree/develop
- 43: https://github.com/paperwm/PaperWM/tree/gnome-43
- 42: https://github.com/paperwm/PaperWM/tree/gnome-42
- 40: https://github.com/paperwm/PaperWM/tree/gnome-40
- 3.28-3.38: https://github.com/paperwm/PaperWM/tree/gnome-3.38
Expand Down Expand Up @@ -432,6 +434,8 @@ There's a few Gnome Shell settings which works poorly with PaperWM. Namely
spanning all monitors
- `edge-tiling`: We don't support the native half tiled windows
- `attach-modal-dialogs`: Attached modal dialogs can cause visual glitching
- `toggle-tiled-left`: Default GNOME keyboard shortcut `super+left` collides with a default PaperWM shortcut. We disable the GNOME shortcut
- `toggle-tiled-right`: Default GNOME keyboard shortcut `super+right` collides with a default PaperWM shortcut. We disable the GNOME shortcut

To use the recommended settings run
[`set-recommended-gnome-shell-settings.sh`](https://github.com/paperwm/PaperWM/blob/master/set-recommended-gnome-shell-settings.sh). A "restore previous settings" script is generated so the original settings is not lost.
Expand Down
54 changes: 49 additions & 5 deletions grab.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ var Utils = Extension.imports.utils;
var Tweener = Utils.tweener;
var Navigator = Extension.imports.navigator;

var virtualPointer;

function isInRect(x, y, r) {
return r.x <= x && x < r.x + r.width &&
r.y <= y && y < r.y + r.height;
}


function monitorAtPoint(gx, gy) {
for (let monitor of Main.layoutManager.monitors) {
if (isInRect(gx, gy, monitor))
Expand All @@ -33,6 +33,22 @@ function monitorAtPoint(gx, gy) {
return null;
}

/**
* Returns a virtual pointer (i.e. mouse) device that can be used to
* "clickout" of a drag operation when `grab_end_op` is unavailable
* (i.e. as of Gnome 44 where `grab_end_op` was removed).
* @returns Clutter.VirtualInputDevice
*/
function getVirtualPointer() {
if (!virtualPointer) {
virtualPointer = Clutter.get_default_backend()
.get_default_seat()
.create_virtual_device(Clutter.InputDeviceType.POINTER_DEVICE);
}

return virtualPointer;
}

var MoveGrab = class MoveGrab {
constructor(metaWindow, type, space) {
this.window = metaWindow;
Expand All @@ -42,6 +58,10 @@ var MoveGrab = class MoveGrab {

this.initialSpace = space || Tiling.spaces.spaceOfWindow(metaWindow);
this.zoneActors = new Set();

// save whether this was tiled window at start of grab
this.wasTiled = !(this.initialSpace.isFloating(metaWindow) ||
Scratch.isScratchWindow(metaWindow));
}

begin({center} = {}) {
Expand All @@ -50,8 +70,11 @@ var MoveGrab = class MoveGrab {
this.center = center;
if (this.grabbed)
return;

this.grabbed = true
global.display?.end_grab_op(global.get_current_time());

global.display.end_grab_op?.(global.get_current_time());

global.display.set_cursor(Meta.Cursor.MOVE_OR_RESIZE_WINDOW);
this.dispatcher = new Navigator.getActionDispatcher(Clutter.GrabState.POINTER)
this.actor = this.dispatcher.actor
Expand Down Expand Up @@ -370,7 +393,7 @@ var MoveGrab = class MoveGrab {
time: prefs.animation_time,
scale_x: 1,
scale_y: 1,
opacity: clone.__oldOpacity || 255
opacity: clone?.__oldOpacity ?? 255,
};

if (this.dnd) {
Expand Down Expand Up @@ -456,10 +479,9 @@ var MoveGrab = class MoveGrab {
// and layout will work correctly etc.
this.window = null;


this.initialSpace.layout();
// ensure window is properly activated after layout/ensureViewport tweens
Mainloop.timeout_add(0, () => {
Meta.later_add(Meta.LaterType.IDLE, () => {
Main.activateWindow(metaWindow);
});

Expand All @@ -473,6 +495,28 @@ var MoveGrab = class MoveGrab {
}

global.display.set_cursor(Meta.Cursor.DEFAULT);

/**
* Gnome 44 removed the ability to manually end_grab_op.
* Previously we would end the grab_op before doing
* PaperWM grabs. In 44, we can't do this so the grab op
* may still be in progress, which is okay, but won't be ended
* until we "click out". We do this here if needed.
*/
Meta.later_add(Meta.LaterType.IDLE, () => {
if (!global.display.end_grab_op && this.wasTiled) {
// move to current cursort position
let [x, y, _mods] = global.get_pointer();
getVirtualPointer().notify_absolute_motion(
Clutter.get_current_event_time(),
x, y);

getVirtualPointer().notify_button(Clutter.get_current_event_time(),
Clutter.BUTTON_PRIMARY, Clutter.ButtonState.PRESSED);
getVirtualPointer().notify_button(Clutter.get_current_event_time(),
Clutter.BUTTON_PRIMARY, Clutter.ButtonState.RELEASED);
}
});
}

activateDndTarget(zone, first) {
Expand Down
8 changes: 4 additions & 4 deletions keybindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var Gdk = imports.gi.Gdk;
var Gtk = imports.gi.Gtk;
var Gio = imports.gi.Gio;
var Meta = imports.gi.Meta;
var GLib = imports.gi.GLib;

var Utils = Extension.imports.utils;
var Main = imports.ui.main;
Expand Down Expand Up @@ -568,7 +569,7 @@ function getActionId(mutterName) {
function overrideAction(mutterName, action) {
let id = getActionId(mutterName);
Main.wm.setCustomKeybindingHandler(mutterName, Shell.ActionMode.NORMAL,
action.keyHandler);
action.keyHandler);
if (id === Meta.KeyBindingAction.NONE)
return;
actionIdMap[id] = action;
Expand Down Expand Up @@ -600,8 +601,7 @@ function resetConflicts() {
) {
Main.wm.setCustomKeybindingHandler(
name,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
Main.wm._showWorkspaceSwitcher.bind(Main.wm));
continue;
}
Expand Down Expand Up @@ -663,7 +663,7 @@ function resetConflicts() {
break;
case 'toggle-application-view':
// overview._controls: Backward compatibility for 3.34 and below:
const viewSelector = (Main.overview._overview._controls || Main.overview.viewSelector || Main.overview._controls.viewSelector);
const viewSelector = (Main.overview._overview._controls || Main.overview.viewSelector || Main.overview._controls.viewSelector);

Main.wm.setCustomKeybindingHandler(
name,
Expand Down
33 changes: 22 additions & 11 deletions kludges.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,25 @@ function overrideHotCorners() {
}
}

// polyfill for 3.28 (`get_monitor_scale` first appeared in 3.31.92).
if (!global.display.get_monitor_scale) {
// `get_monitor_scale` first appeared in 3.31.92. Polyfill a fallback for 3.28
global.display.constructor.prototype.get_monitor_scale = () => 1.0;
}

// polyfill for 3.28 (`get_monitor_neighbor_index`)
if (!global.display.get_monitor_neighbor_index) {
// `get_monitor_neighbor_index` polyfill a fallback for 3.28
global.display.constructor.prototype.get_monitor_neighbor_index = function(...args) {
return global.screen.get_monitor_neighbor_index(...args);
}
}

if (!global.display.set_cursor) {
global.display.constructor.prototype.set_cursor = global.screen.set_cursor.bind(global.screen);
}

// polyfill for 3.28
if (!Meta.DisplayDirection && Meta.ScreenDirection) {
Meta.DisplayDirection = Meta.ScreenDirection;
}

// polyfill for 3.28
if (!St.Settings) {
// `St.Settings` doesn't exist in 3.28 - polyfill:
let Gtk = imports.gi.Gtk;
let gtkSettings = Gtk.Settings.get_default();
let polyfillSettings = new (class PolyfillStSettings {
Expand All @@ -82,14 +78,14 @@ if (!St.Settings) {
};
}

// polyfill for 3.28
if (!Clutter.Actor.prototype.set) {
// `set` doesn't exist in 3.28 - polyfill:
Clutter.Actor.prototype.set = function(params) {
Object.assign(this, params);
}
}

// Polyfill gnome-3.34 transition API, taken from gnome-shell/js/ui/environment.js
// polyfill 3.34 transition API, taken from gnome-shell/js/ui/environment.js
if (version[0] >= 3 && version[1] < 34) {
function _makeEaseCallback(params, cleanup) {
let onComplete = params.onComplete;
Expand Down Expand Up @@ -179,7 +175,12 @@ if (version[0] >= 3 && version[1] < 34) {
};
}

// Polyfill
// polyfill
if (!global.display.set_cursor) {
global.display.constructor.prototype.set_cursor = global.screen.set_cursor.bind(global.screen);
}

// polyfill
if (!Clutter.Actor.prototype.raise) {
Clutter.Actor.prototype.raise = function raise(above) {
const parent = this.get_parent();
Expand All @@ -189,12 +190,14 @@ if (!Clutter.Actor.prototype.raise) {
}
}

// polyfill
if (!Clutter.Actor.prototype.raise_top) {
Clutter.Actor.prototype.raise_top = function raise_top() {
this.raise(null);
}
}

// polyfill
if (!Clutter.Actor.prototype.reparent) {
Clutter.Actor.prototype.reparent = function reparent(newParent) {
const parent = this.get_parent();
Expand All @@ -205,11 +208,19 @@ if (!Clutter.Actor.prototype.reparent) {
}
}

if (! Clutter.Vertex) {
// polyfill
if (!Clutter.Vertex) {
const {Graphene} = imports.gi;
Clutter.Vertex = Graphene.Point3D;
}

// polyfill for 44
if (!Meta.later_add && global.compositor?.get_laters()) {
Meta.later_add = function(...args) {
global.compositor.get_laters().add(...args);
}
}

// Workspace.Workspace._realRecalculateWindowPositions
// Sort tiled windows in the correct order
function _realRecalculateWindowPositions(flags) {
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"url": "https://github.com/paperwm/PaperWM",
"settings-schema": "org.gnome.Shell.Extensions.PaperWM",
"shell-version": [ "42", "43", "44" ],
"version": "43.0",
"version": "44.0",
"session-modes": [ "unlock-dialog", "user" ]
}
1 change: 0 additions & 1 deletion navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ function getModLock(mods) {
grab = Main.pushModal(this.actor)
// We expect at least a keyboard grab here
if ((grab.get_seat_state() & Clutter.GrabState.KEYBOARD) === 0) {
Main.popModal(grabHandle);
log("Failed to grab modal");
throw new Error('Could not grab modal')
}
Expand Down
2 changes: 0 additions & 2 deletions set-recommended-gnome-shell-settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,5 @@ set-with-backup org.gnome.shell.overrides edge-tiling false
# Attached modal dialogs isn't handled very well
set-with-backup org.gnome.shell.overrides attach-modal-dialogs false



echo
echo "Run $RESTORE_SETTINGS_SCRIPT to revert changes"
2 changes: 1 addition & 1 deletion settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function keystrToKeycombo(keystr) {
keystr = keystr.replace('Above_Tab', 'A');
aboveTab = true;
}
let [key, mask] = Gtk.accelerator_parse(keystr);
let [ok, key, mask] = Gtk.accelerator_parse(keystr);

if (aboveTab)
key = META_KEY_ABOVE_TAB;
Expand Down
Loading

0 comments on commit 6b50846

Please sign in to comment.