Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
jtaala committed Jul 29, 2024
2 parents 4fafae3 + 4ed92ec commit 1fef23a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 19 deletions.
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://github.com/paperwm/PaperWM",
"settings-schema": "org.gnome.shell.extensions.paperwm",
"shell-version": [ "45", "46" ],
"version-name": "46.13.7",
"version-name": "46.13.8",
"donations": {
"buymeacoffee": "jaytaala",
"patreon": "valpackett"
Expand Down
63 changes: 45 additions & 18 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ let gsettings, backgroundSettings, interfaceSettings;
let displayConfig;
let saveState;
let startupTimeoutId, timerId, fullscreenStartTimeout, stackSlurpTimeout, workspaceChangeTimeouts;
let monitorChangeTimeout;
let workspaceSettings;
export let inGrab;
export function enable(extension) {
Expand Down Expand Up @@ -214,6 +215,8 @@ export function disable() {
stackSlurpTimeout = null;
workspaceChangeTimeouts?.forEach(t => Utils.timeout_remove(t));
workspaceChangeTimeouts = null;
Utils.timeout_remove(monitorChangeTimeout);
monitorChangeTimeout = null;

grabSignals.destroy();
grabSignals = null;
Expand Down Expand Up @@ -2249,6 +2252,26 @@ export const Spaces = class Spaces extends Map {
let mru = this.mru();

let primary = Main.layoutManager.primaryMonitor;
if (!primary) {
// setup periodic timout to call layout on all spaces 5 times (1 second apart)
monitorChangeTimeout = Utils.periodic_timeout({
count: 5,
init: () => {
Utils.timeout_remove(monitorChangeTimeout);
},
callback: () => {
this?.forEach(s => s.layout());
},
onContinue: called => {
console.warn(`MONITORS_CHANGED: no primary monitor - 'layout' on spaces call ${called}`);
},
onComplete: () => {
monitorChangeTimeout = null;
},
});
return;
}

// get monitors but ensure primary monitor is first
let monitors = Main.layoutManager.monitors.filter(m => m !== primary);
monitors.unshift(primary);
Expand Down Expand Up @@ -3476,25 +3499,29 @@ export function registerWindow(metaWindow) {
return;
}

let tries = 0;
const timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
if (tries >= 10) {
done(timeout);
return false;
}
tries++;
// console.log(`try ${tries} height check on ${metaWindow.title}`);
const f = metaWindow.get_frame_rect();
if (metaWindow._targetHeight !== f.height) {
if (!isNaN(metaWindow._targetHeight)) {
metaWindow.move_resize_frame(true, f.x, f.y, f.width, metaWindow._targetHeight);
}
return true;
const timeout = Utils.periodic_timeout(
{
period_ms: 100,
count: 10,
callback: () => {
const f = metaWindow.get_frame_rect();
if (metaWindow._targetHeight !== f.height) {
if (!isNaN(metaWindow._targetHeight)) {
metaWindow.move_resize_frame(
true,
f.x,
f.y,
f.width,
metaWindow._targetHeight
);
}
}
},
onComplete: () => {
done(timeout);
},
}

done(timeout);
return false;
});
);
workspaceChangeTimeouts.push(timeout);
});

Expand Down
44 changes: 44 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,50 @@ export function timeout_remove(...timeouts) {
});
}

/**
* Calls a period timeout (GLib.timeout_add) that calls a callback function.
* Also contains parameters for init (call for initialisation), onContinue (callback when continuing),
* onComplete (callback when completed last callback).
* @param {Object} options
* @param {Number} options.period_ms
* @param {Number} options.count
* @param {Function} options.init
* @param {Function} options.callback
* @param {Function} options.onContinue
* @param {Function} options.onComplete
* @returns GLib timeout id
*/
export function periodic_timeout(options = { }) {
const operiod = options?.period_ms ?? 1000;
const ocount = options?.count ?? 1;
const oinit = options?.init ?? function() {};
const ocallback = options?.callback ?? function() {};
const ocontinue = options?.onContinue ?? function() {};
const ocomplete = options?.onComplete ?? function() {};

oinit();
let called = 0;
return GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
operiod,
() => {
// check for early exit (if callback returns false)
if (ocallback() === false) {
ocomplete();
return false;
}

if (called < ocount) {
called++;
ocontinue(called);
return true;
}

ocomplete();
return false; // on return false destroys timeout
});
}

export class Signals extends Map {
static get [Symbol.species]() { return Map; }

Expand Down

0 comments on commit 1fef23a

Please sign in to comment.