MCPcopy
hub / github.com/paperwm/PaperWM / centerWindow

Function centerWindow

tiling.js:5055–5071  ·  view source on GitHub ↗
(metaWindow, horizontal = true, vertical = false)

Source from the content-addressed store, hash-verified

5053 * Centers the currently selected window.
5054 */
5055export function centerWindow(metaWindow, horizontal = true, vertical = false) {
5056 const frame = metaWindow.get_frame_rect();
5057 const space = spaces.spaceOfWindow(metaWindow);
5058 const monitor = space.monitor;
5059 const workArea = space.workArea();
5060
5061 const targetX = horizontal ? workArea.x + Math.round((workArea.width - frame.width) / 2) : frame.x;
5062 let targetY = vertical ? workArea.y + Math.round((workArea.height - frame.height) / 2) : frame.y;
5063 targetY = Math.max(targetY, workArea.y);
5064 if (space.indexOf(metaWindow) === -1) {
5065 Scratch.easeScratch(metaWindow, targetX + monitor.x, targetY + monitor.y);
5066 } else {
5067 move_to(space, metaWindow, {
5068 x: targetX,
5069 });
5070 }
5071}
5072
5073/**
5074 * Activates the window under the mouse cursor, if any.

Callers 3

layoutMethod · 0.85
resizeHandlerFunction · 0.85
setFocusModeFunction · 0.85

Calls 4

move_toFunction · 0.85
spaceOfWindowMethod · 0.80
workAreaMethod · 0.80
indexOfMethod · 0.80

Tested by

no test coverage detected