Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2013 Fabian Homborg <FHomborg@gmail.com>
based on spirallayout.js by Matthias Gottschlag
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
// FIXME: Crash on moving client to another desktop
/**
* Class which arranges the windows in a spiral with the largest window filling
* the left half of the screen.
*/
function BladeLayout(screenRectangle) {
print("Creating BladeLayout");
Layout.call(this, screenRectangle);
// TODO
}
BladeLayout.name = "Blade";
// TODO: Add an image for the layout switcher
BladeLayout.image = null;
BladeLayout.prototype = new Layout();
BladeLayout.prototype.constructor = BladeLayout;
BladeLayout.prototype.resetTileSizes = function() {
// Simply erase all tiles and recreate them to recompute the initial sizes
var tileCount = this.tiles.length;
this.tiles.length = 0;
for (var i = 0; i < tileCount; i++) {
this.addTile();
}
}
BladeLayout.prototype.addTile = function() {
if (this.tiles.length == 0) {
// The first tile fills the whole screen
var rect = Qt.rect(this.screenRectangle.x,
this.screenRectangle.y,
this.screenRectangle.width,
this.screenRectangle.height);
this._createTile(rect);
return;
} else {
// Divide the screen width evenly between full-height tiles
// FIXME: Screenrectangle for struts is weird
var lastRect = this.tiles[0].rectangle;
var newRect = Qt.rect(this.screenRectangle.x,
lastRect.y,
Math.floor((this.screenRectangle.width + this.screenRectangle.x) / (this.tiles.length + 1)),
this.screenRectangle.height);
// FIXME: Try to keep ratio
for (i = 0; i < this.tiles.length; i++) {
var rect = this.tiles[i].rectangle;
rect.x = newRect.x + newRect.width * i;
rect.width = newRect.width;
this.tiles[i].rectangle = rect;
}
// Adjust tile's width for rounding errors
newRect.x = newRect.x + newRect.width * this.tiles.length;
newRect.width = (this.screenRectangle.width + this.screenRectangle.x) - newRect.x;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// TODO: Move this before setting ratio to simplify
this._createTile(newRect);
}
}
BladeLayout.prototype.removeTile = function(tileIndex) {
// Remove the array entry
var oldrect = this.tiles[tileIndex].rectangle;
this.tiles.splice(tileIndex, 1);
// Update the other tiles
if (this.tiles.length == 1) {
this.tiles[0].rectangle = this.screenRectangle;
this.tiles[0].hasDirectNeighbour[Direction.Left] = false;
this.tiles[0].hasDirectNeighbour[Direction.Right] = false;
}
if (this.tiles.length > 1) {
var tileCount = this.tiles.length;
var lastRect = this.tiles[0].rectangle;
var newRect = Qt.rect(this.screenRectangle.x,
this.screenRectangle.y,
Math.floor(this.screenRectangle.width / tileCount),
this.screenRectangle.height);
var lowest = 1;
for (i = 0; i < this.tiles.length; i++) {
var rect = this.tiles[i].rectangle;
rect.x = newRect.x + newRect.width * i;
rect.width = newRect.width;
this.tiles[i].rectangle = rect;
this.tiles[i].hasDirectNeighbour[Direction.Left] = (i > 0);
this.tiles[i].hasDirectNeighbour[Direction.Right] = (i < this.tiles.length - 1);
this.tiles[i].neighbours[Direction.Left] = i - 1;
this.tiles[i].neighbours[Direction.Right] = i + 1;
}
// Adjust rightmost tile's height for rounding errors
this.tiles[this.tiles.length - 1].rectangle.width = (this.screenRectangle.width + this.screenRectangle.x) - this.tiles[this.tiles.length - 1].rectangle.x;
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
}
}
BladeLayout.prototype.resizeTile = function(tileIndex, rectangle) {
// TODO: Mark tile as resized so it can keep its size on tileadd/remove
if (tileIndex < 0 || tileIndex > this.tiles.length) {
print("Tileindex invalid", tileIndex, "/", this.tiles.length);
return;
}
var tile = this.tiles[tileIndex];
if (tile == null) {
print("No tile");
return;
}
if (rectangle == null){
print("No rect");
return;
}
// Cap rectangle at screenedges
if (rectangle.x < this.screenRectangle.x) {
rectangle.x = this.screenRectangle.x;
}
if (rectangle.y < this.screenRectangle.y) {
rectangle.y = this.screenRectangle.y;
}
if (rectangle.y + rectangle.height > this.screenRectangle.y + this.screenRectangle.height) {
rectangle.height = this.screenRectangle.y + this.screenRectangle.height - rectangle.y;
}
if (rectangle.x + rectangle.width > this.screenRectangle.x + this.screenRectangle.width) {
rectangle.width = this.screenRectangle.x + this.screenRectangle.width - rectangle.x;
}
var newRect = Qt.Rect(this.screenRectangle.x,
this.screenRectangle.y,
Math.floor(rectangle.x / tileIndex),
this.screenRectangle.height);
for(i = 0; i < tileIndex; i++) {
var rect = this.tiles[i].rectangle;
rect.x = newRect.x + newRect.width * i;
rect.width = newRect.width;
this.tiles[i].rectangle = rect;
}
newRect.width = Math.floor((this.screenRectangle.width - rectangle.x) / (this.tiles.length - tileIndex - 1));
for(i = tileIndex + 1; i < this.tiles.length; i++){
var rect = this.tiles[i].rectangle;
rect.x = newRect.x + newRect.width * i;
rect.width = newRect.width;
this.tiles[i].rectangle = rect;
}
rectangle.y = this.screenRectangle.y;
rectangle.height = this.screenRectangle.height;
this.tiles[tileIndex].rectangle = rectangle;
}
BladeLayout.prototype._createTile = function(rect) {
// Update the last tile in the list
if (this.tiles.length > 1) {
var lastTile = this.tiles[this.tiles.length - 1];
lastTile.neighbours[Direction.Down] = this.tiles.length;
lastTile.hasDirectNeighbour[Direction.Down] = true;
}
if (this.tiles.length == 1) {
var lastTile2 = this.tiles[0];
lastTile2.neighbours[Direction.Right] = 1;
lastTile2.hasDirectNeighbour[Direction.Right] = true;
}
// Create a new tile and add it to the list
var tile = {};
tile.rectangle = rect;
tile.neighbours = [];
tile.hasDirectNeighbour = [];
tile.neighbours[Direction.Left] = 0;
tile.hasDirectNeighbour[Direction.Left] = (this.tiles.length > 0);
tile.neighbours[Direction.Right] = - 1;
tile.hasDirectNeighbour[Direction.Right] = false;
if (this.tiles.length > 1) {
tile.hasDirectNeighbour[Direction.Up] = true;
tile.neighbours[Direction.Up] = this.tiles.length - 1;
} else {
tile.hasDirectNeighbour[Direction.Up] = false;
tile.neighbours[Direction.Up] = - 1;
}
tile.neighbours[Direction.Down] = - 1;
tile.hasDirectNeighbour[Direction.Down] = false;
tile.index = this.tiles.length;
this.tiles.push(tile);
}