Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1.  
  2. ///////////////
  3. // Shortcuts //
  4. ///////////////
  5.  
  6. const ws = workspace;
  7.  
  8. function NumberOfDesktops() { return ws.desktops; }
  9. function NumberOfScreens() { return ws.numScreens; }
  10. const numDesk = NumberOfDesktops();
  11. const numScr = NumberOfScreens();
  12.  
  13. function CurrentActivity() { return ws.currentActivity; }
  14. function CurrentDesk() { return ws.currentDesktop; }
  15. function CurrentScreen() { return ws.activeScreen; }
  16. const curAct = CurrentActivity();
  17. const curDesk = CurrentDesk();
  18. const curScr = CurrentScreen();
  19.  
  20. var qt = [];
  21.  
  22. var gap = 8;
  23.  
  24. for (var d = 1; d <= numDesk; d++) {
  25. qt[d] = [];
  26. for (var s = 0; s < numScr; s++) {
  27. qt[d][s] = new Screen(ws.clientArea(0, s, 0));
  28. }
  29. }
  30.  
  31. function CurrentClients() { return qt[curDesk][curScr].clients; }
  32. const curClients = CurrentClients();
  33.  
  34. /////////////
  35. // Signals //
  36. /////////////
  37.  
  38. function connectWorkspace() {
  39. ws.clientAdded.connect(addClient);
  40. ws.clientRemoved.connect(removeClient);
  41. }
  42.  
  43. function addClient(client) {
  44. if(curClients.length > 3) return;
  45.  
  46. client.oldgeo = client.geometry;
  47. qt[client.desktop][client.screen].push(client);
  48.  
  49. tileClients();
  50. }
  51.  
  52. function removeClient(client) {
  53. client.geometry = client.oldgeo;
  54.  
  55. curClients.splice(curClients.indexOf(client), 1)
  56.  
  57. tileClients();
  58. }
  59.  
  60. function tileClients() {
  61. for (var s = 0; s < numScr; s++) {
  62. var tiles = qt[curDesk][s].tiles();
  63. for (var c = 0; c < qt[curDesk][s].length; c++) {
  64. qt[curDesk][s].clients[c].geometry = tiles[c];
  65. }
  66. }
  67. }
  68.  
  69. /////////////
  70. // Objects //
  71. /////////////
  72.  
  73. function Screen(geometry) {
  74. this.geometry = geometry;
  75. this.orientation = (geometry.width > geometry.height) ? "horizontal" : "vertical";
  76. this.pane = { y: geometry.height / 2, x: geometry.width / 2 };
  77. this.clients = [];
  78. this.tiles = function() {
  79. var tiles = [ this.geometry, this.geometry, this.geometry, this.geometry ];
  80. tiles[0].x = this.geometry.x;
  81. tiles[0].y = this.geometry.y;
  82. tiles[0].width = this.pane.x;
  83. tiles[0].height = this.pane.y;
  84.  
  85. tiles[1].x = this.geometry.x + this.pane.x;
  86. tiles[1].y = this.geometry.y;
  87. tiles[1].width = this.geometry.width - this.pane.x;
  88. tiles[1].height = this.pane.y;
  89.  
  90. tiles[2].x = this.geometry.x + this.pane.x;
  91. tiles[2].y = this.geometry.y + this.pane.y;
  92. tiles[2].width = this.geometry.width - this.pane.x;
  93. tiles[2].height = this.geometry.height - this.pane.y;
  94.  
  95. tiles[3].x = this.geometry.x;
  96. tiles[3].y = this.geometry.y + this.pane.y;
  97. tiles[3].width = this.pane.x;
  98. tiles[3].height = this.geometry.height - this.pane.y;
  99. return tiles;
  100. }
  101. }
  102.  
  103. //////////
  104. // Init //
  105. //////////
  106.  
  107. function main() {
  108. connectWorkspace();
  109. }
  110.  
  111. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement