Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////
- // Shortcuts //
- ///////////////
- const ws = workspace;
- function NumberOfDesktops() { return ws.desktops; }
- function NumberOfScreens() { return ws.numScreens; }
- const numDesk = NumberOfDesktops();
- const numScr = NumberOfScreens();
- function CurrentActivity() { return ws.currentActivity; }
- function CurrentDesk() { return ws.currentDesktop; }
- function CurrentScreen() { return ws.activeScreen; }
- const curAct = CurrentActivity();
- const curDesk = CurrentDesk();
- const curScr = CurrentScreen();
- var qt = [];
- var gap = 8;
- for (var d = 1; d <= numDesk; d++) {
- qt[d] = [];
- for (var s = 0; s < numScr; s++) {
- qt[d][s] = new Screen(ws.clientArea(0, s, 0));
- }
- }
- function CurrentClients() { return qt[curDesk][curScr].clients; }
- const curClients = CurrentClients();
- /////////////
- // Signals //
- /////////////
- function connectWorkspace() {
- ws.clientAdded.connect(addClient);
- ws.clientRemoved.connect(removeClient);
- }
- function addClient(client) {
- if(curClients.length > 3) return;
- client.oldgeo = client.geometry;
- qt[client.desktop][client.screen].push(client);
- tileClients();
- }
- function removeClient(client) {
- client.geometry = client.oldgeo;
- curClients.splice(curClients.indexOf(client), 1)
- tileClients();
- }
- function tileClients() {
- for (var s = 0; s < numScr; s++) {
- var tiles = qt[curDesk][s].tiles();
- for (var c = 0; c < qt[curDesk][s].length; c++) {
- qt[curDesk][s].clients[c].geometry = tiles[c];
- }
- }
- }
- /////////////
- // Objects //
- /////////////
- function Screen(geometry) {
- this.geometry = geometry;
- this.orientation = (geometry.width > geometry.height) ? "horizontal" : "vertical";
- this.pane = { y: geometry.height / 2, x: geometry.width / 2 };
- this.clients = [];
- this.tiles = function() {
- var tiles = [ this.geometry, this.geometry, this.geometry, this.geometry ];
- tiles[0].x = this.geometry.x;
- tiles[0].y = this.geometry.y;
- tiles[0].width = this.pane.x;
- tiles[0].height = this.pane.y;
- tiles[1].x = this.geometry.x + this.pane.x;
- tiles[1].y = this.geometry.y;
- tiles[1].width = this.geometry.width - this.pane.x;
- tiles[1].height = this.pane.y;
- tiles[2].x = this.geometry.x + this.pane.x;
- tiles[2].y = this.geometry.y + this.pane.y;
- tiles[2].width = this.geometry.width - this.pane.x;
- tiles[2].height = this.geometry.height - this.pane.y;
- tiles[3].x = this.geometry.x;
- tiles[3].y = this.geometry.y + this.pane.y;
- tiles[3].width = this.pane.x;
- tiles[3].height = this.geometry.height - this.pane.y;
- return tiles;
- }
- }
- //////////
- // Init //
- //////////
- function main() {
- connectWorkspace();
- }
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement