(metaWindow, horizontal = true, vertical = false)
| 5053 | * Centers the currently selected window. |
| 5054 | */ |
| 5055 | export 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. |
no test coverage detected