Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. ///////////////
  2. // Shortcuts //
  3. ///////////////
  4.  
  5. const Ws = workspace;
  6.  
  7. function NumberOfDesktops() { return Ws.desktops; }
  8. function NumberOfScreens() { return Ws.numScreens; }
  9. const NumDesks = NumberOfDesktops();
  10. const NumScrs = NumberOfScreens();
  11.  
  12. function CurrentActivity() { return Ws.currentActivity; }
  13. function CurrentDesk() { return Ws.currentDesktop; }
  14. function CurrentScreen() { return Ws.activeScreen; }
  15. const CurAct = CurrentActivity();
  16. const CurDesk = CurrentDesk();
  17. const CurScr = CurrentScreen();
  18.  
  19. function ScreenGeo(scr) { return Ws.clientArea(0, scr, 0); }
  20.  
  21.  
  22.  
  23.  
  24. /////////////
  25. // Globals //
  26. /////////////
  27.  
  28. WM = [];
  29.  
  30. // Initiate the desktops and screens
  31. for (var desk = 1; desk <= NumDesks; desk++) {
  32. WM[desk] = [];
  33. for (var scr = 0; scr < NumScrs; scr++) {
  34. WM[desk][scr] = new Screen(ScreenGeo(scr));
  35. }
  36. }
  37.  
  38. var Gap = 8;
  39.  
  40.  
  41. /////////////
  42. // Signals //
  43. /////////////
  44.  
  45. function connectWorkspace() {
  46. Ws.clientAdded.connect(addClient);
  47. Ws.clientRemoved.connect(removeClient);
  48. }
  49.  
  50. function addClient(client) {
  51. if (WM[client.desktop][client.screen].clients.length > 3) return;
  52.  
  53. client.index = WM[client.desktop][client.screen].clients.length;
  54. client.startGeo = client.geometry;
  55. client.oldGeo = client.geometry;
  56.  
  57. client.clientStartUserMovedResized.connect(startMove);
  58. client.clientStepUserMovedResized.connect(stepMove);
  59. client.clientFinishUserMovedResized.connect(endMove);
  60.  
  61. WM[client.desktop][client.screen].clients.push(client);
  62.  
  63. tileClients();
  64. }
  65.  
  66. function removeClient(client) {
  67. client.index = null;
  68. client.startGeo = null;
  69. client.oldGeo = null;
  70.  
  71. client.clientStartUserMovedResized.disconnect(startMove);
  72. client.clientStepUserMovedResized.disconnect(stepMove);
  73. client.clientFinishUserMovedResized.disconnect(endMove);
  74.  
  75. WM[client.desktop][client.screen].clients.splice(WM[client.desktop][client.screen].clients.indexOf(client), 1);
  76.  
  77. tileClients();
  78. }
  79.  
  80. function floatClient(client) {
  81. client.geometry = client.oldGeo;
  82.  
  83. removeClient(client);
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. function startMove(client) {
  92. client.startGeo = client.geometry;
  93. client.index = WM[client.desktop][client.screen].clients.indexOf(client);
  94. }
  95.  
  96. function stepMove(client) {
  97. // Remove a client if it's moved
  98. if (client.geometry.width === client.oldGeo.width && client.geometry.height === client.oldGeo.height) {
  99. if (client.geometry.x !== client.oldGeo.x || client.geometry.y !== client.oldGeo.y) {
  100. floatClient(client);
  101. }
  102. }
  103. }
  104.  
  105. function endMove(client) {
  106. if (client.geometry === client.startGeo) return;
  107.  
  108. WM[client.desktop][client.screen].pane.x += (client.index === 0 || client.index === 3) ? client.geometry.width - client.startGeo.width : client.startGeo.width - client.geometry.width;
  109. WM[client.desktop][client.screen].pane.y += (client.index === 0 || client.index === 1) ? client.geometry.height - client.startGeo.height : client.startGeo.height - client.geometry.height;
  110.  
  111. tileClients();
  112. }
  113.  
  114.  
  115.  
  116. function tileClients() {
  117. for (var scr = 0; scr < NumScrs; scr++) {
  118. WM[CurDesk][scr].tile();
  119. for (var c = 0; c < WM[CurDesk][scr].clients.length; c++) {
  120. WM[CurDesk][scr].clients[c].geometry = WM[CurDesk][scr].tiles[c];
  121. }
  122. }
  123. }
  124.  
  125.  
  126.  
  127. /////////////
  128. // Objects //
  129. /////////////
  130.  
  131. function Desktop() {
  132.  
  133. }
  134.  
  135. function Screen(geometry) {
  136. this.geometry = geometry;
  137. this.orientation = (geometry.width > geometry.height) ? "horizontal" : "vertical";
  138. this.pane = { x: geometry.width / 2, y: geometry.height / 2 };
  139. this.clients = [];
  140. this.tiles = [ {}, {}, {}, {} ];
  141. this.tile = function() {
  142. for (var t = 0; t < this.tiles.length; t++) {
  143. this.tiles[t].x = (t === 0 || t === 3) ? this.geometry.x : this.geometry.x + this.pane.x;
  144. this.tiles[t].y = (t === 0 || t === 1) ? this.geometry.y : this.geometry.y + this.pane.y;
  145. this.tiles[t].width = (t === 0 || t === 3) ? this.pane.x : this.geometry.width - this.pane.x;
  146. this.tiles[t].height = (t === 0 || t === 1) ? this.pane.y : this.geometry.height - this.pane.y;
  147. }
  148. }
  149. }
  150.  
  151.  
  152.  
  153.  
  154. //////////
  155. // Init //
  156. //////////
  157.  
  158. function main() {
  159. connectWorkspace();
  160. }
  161.  
  162. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement