Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "Tiling window manager with a twist",
"url": "https://github.com/paperwm/PaperWM",
"settings-schema": "org.gnome.shell.extensions.paperwm",
"shell-version": [ "45", "46", "47", "48" ],
"shell-version": [ "45", "46", "47", "48", "49" ],
"version-name": "48.0.3"
}
72 changes: 47 additions & 25 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,7 @@ export class Space extends Array {

let f = mw.get_frame_rect();

let resizable = !mw.fullscreen &&
mw.get_maximized() !== Meta.MaximizeFlags.BOTH;
let resizable = !mw.fullscreen && !isMaximized(mw);

if (mw.preferredWidth) {
let prop = mw.preferredWidth;
Expand Down Expand Up @@ -869,7 +868,7 @@ export class Space extends Array {
return false;
} else {
// Fullscreen windows are only placeable on the monitor origin
if ((metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH && x !== min) ||
if ((isMaximized(metaWindow) && x !== min) ||
(metaWindow.fullscreen && x !== 0)) {
return false;
}
Expand Down Expand Up @@ -1394,8 +1393,7 @@ export class Space extends Array {
if (Easer.isEasing(w.clone))
return;

let unMovable = w.fullscreen ||
w.get_maximized() === Meta.MaximizeFlags.BOTH;
let unMovable = w.fullscreen || isMaximized(w);
if (unMovable)
return;

Expand Down Expand Up @@ -3417,6 +3415,33 @@ export function isScratch(metaWindow) {
return Scratch.isScratchWindow(metaWindow);
}

export function isMaximized(metaWindow) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ (Just a comment, nothing to change here)

👍 I think these wrappers around gnome-shell functionality are great. The less one needs to know about gnome-shell internals in order to contribute high-level functionality to PaperWM, the better.

In the future, we should talk about organizing all the stuff that's currently in tiling.js.

  • Currently I don't see any clear logic for when to create a top level function, a method on Space, or a method on Spaces.
  • There's not a clear separation of space-local operations and global ones (that work based on the current focused monitor/workspace/window).
  • We don't have any public/private separation, which means that renaming anything might break someone's customizations (e.g. stuff in examples/).

Today though, I don't have a good enough understanding of all the stuff that exists to know how to organize it, so here is fine for now. Since they're not exported, we can always move them later.

if (!metaWindow) {
return false;
}
if (typeof metaWindow.is_maximized === 'function') // GNOME >= 49
return metaWindow.is_maximized();
return metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH;
}

function isMaximizedHorizontal(metaWindow) {
if (!metaWindow) {
return false;
}
if (typeof metaWindow.get_maximize_flags === 'function') // GNOME >= 49
return metaWindow.get_maximize_flags() === Meta.MaximizeFlags.Horizontal;
return metaWindow.get_maximized() === Meta.MaximizeFlags.Horizontal;
}

function unmaximize(metaWindow, flags) {
if (!metaWindow) {
return false;
}
if (typeof metaWindow.set_unmaximize_flags === 'function') // GNOME >= 49
return metaWindow.set_unmaximize_flags(flags);
return metaWindow.unmaximize(flags);
}

export function is_override_redirect(metaWindow) {
// Note: is_overrride_redirect() seem to be false for all wayland windows
const windowType = metaWindow.windowType;
Expand Down Expand Up @@ -3491,10 +3516,8 @@ export function registerWindow(metaWindow) {
});

signals.connect(metaWindow, 'notify::maximized-horizontally', metaWindow => {
if (
Settings.prefs.maximize_within_tiling &&
metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
if (Settings.prefs.maximize_within_tiling && isMaximized(metaWindow)) {
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);

// restore last layout frame
if (metaWindow._last_layout_frame) {
Expand Down Expand Up @@ -3725,8 +3748,7 @@ export function resizeHandler(metaWindow) {
x -= space.monitor.x;

// for non-maximised windows, enforce horizontal margin in restore position
if (metaWindow.get_maximized() !== Meta.MaximizeFlags.BOTH &&
metaWindow.get_maximized() !== Meta.MaximizeFlags.Horizontal) {
if (!isMaximized(metaWindow) && !isMaximizedHorizontal(metaWindow)) {
x = Math.max(x, Settings.prefs.horizontal_margin);
}

Expand Down Expand Up @@ -4138,8 +4160,8 @@ Opening "${metaWindow?.title}" on current space.`);
return;

metaWindow.unmake_above();
if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
if (isMaximized(metaWindow)) {
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);
toggleMaximizeHorizontally(metaWindow);
}

Expand Down Expand Up @@ -4776,9 +4798,9 @@ export function isWindowAnimating(metaWindow) {
export function toggleMaximizeHorizontally(metaWindow) {
metaWindow = metaWindow || display.focus_window;

if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
if (isMaximized(metaWindow)) {
// ASSUMPTION: MaximizeFlags.HORIZONTALLY is not used
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);
metaWindow.unmaximizedRect = null;
return;
}
Expand Down Expand Up @@ -4823,8 +4845,8 @@ export function resizeHInc(metaWindow) {
let targetHeight = Math.min(currentHeight + step, maxHeight);
let targetY = frame.y;

if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
if (isMaximized(metaWindow)) {
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);
}

// Space.layout will ensure the window is moved if necessary
Expand All @@ -4844,8 +4866,8 @@ export function resizeHDec(metaWindow) {
let targetHeight = Math.max(currentHeight - step, minHeight);
let targetY = frame.y;

if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
if (isMaximized(metaWindow)) {
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);
}

// Space.layout will ensure the window is moved if necessary
Expand All @@ -4864,8 +4886,8 @@ export function resizeWInc(metaWindow) {
let targetWidth = Math.min(currentWidth + step, maxWidth);
let targetX = frame.x;

if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
if (isMaximized(metaWindow)) {
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);
}

// Space.layout will ensure the window is moved if necessary
Expand All @@ -4885,8 +4907,8 @@ export function resizeWDec(metaWindow) {
let targetWidth = Math.max(currentWidth - step, minWidth);
let targetX = frame.x;

if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
if (isMaximized(metaWindow)) {
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);
}

// Space.layout will ensure the window is moved if necessary
Expand Down Expand Up @@ -4939,8 +4961,8 @@ export function cycleWindowWidthDirection(metaWindow, direction) {
}
}

if (metaWindow.get_maximized() === Meta.MaximizeFlags.BOTH) {
metaWindow.unmaximize(Meta.MaximizeFlags.BOTH);
if (isMaximized(metaWindow)) {
unmaximize(metaWindow, Meta.MaximizeFlags.BOTH);
}

// Space.layout will ensure the window is moved if necessary
Expand Down