|
| 1 | +/* |
| 2 | +KWin Script Always Open on Focused Screen |
| 3 | +(C) 2021 Natalie Clarius <[email protected]> |
| 4 | +GNU General Public License v3.0 |
| 5 | +*/ |
| 6 | + |
| 7 | +// when a client is activated |
| 8 | +focusedScreen = workspace.activeScreen; |
| 9 | +workspace.clientActivated.connect(function(client) { |
| 10 | + // update focused screen to screen client is on |
| 11 | + if (client == null || client.specialWindow) return; |
| 12 | + focusedScreen = client.screen; |
| 13 | +}); |
| 14 | + |
| 15 | +// when a client is added |
| 16 | +workspace.clientAdded.connect(function(client) { |
| 17 | + // move client to focused screen |
| 18 | + if (client == null || client.desktopWindow || client.dock) return; |
| 19 | + if (client.screen == focusedScreen) return; |
| 20 | + console.debug("sending client", client.caption, "to focused screen", focusedScreen); |
| 21 | + workspace.sendClientToScreen(client, focusedScreen); |
| 22 | + |
| 23 | + // clip and move client into bounds of screen dimensions |
| 24 | + if (!(client.moveable && client.resizeable)) return; |
| 25 | + area = workspace.clientArea(KWin.MaximizeArea, client); |
| 26 | + // window width/height maximally screen width/height |
| 27 | + client.geometry.width = Math.min(client.width, area.width); |
| 28 | + client.geometry.height = Math.min(client.height, area.height); |
| 29 | + // left/top window edge between left and right/top and bottom screen edges |
| 30 | + client.geometry.x = Math.max(area.x, Math.min(area.x + area.width - client.width, client.x)); |
| 31 | + client.geometry.y = Math.max(area.y, Math.min(area.y + area.height - client.height, client.y)); |
| 32 | +}); |
0 commit comments