-
Notifications
You must be signed in to change notification settings - Fork 2
/
Area.m
executable file
·125 lines (104 loc) · 3.18 KB
/
Area.m
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
75
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* This file is part of the Tile project.
*
* Copyright 2009-2013 Crazor <crazor@gmail.com>
*
* Tile 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 3 of the License, or
* (at your option) any later version.
*
* Tile 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 Tile. If not, see <http://www.gnu.org/licenses/>.
*/
#import "Area.h"
#import "Window.h"
@implementation Area
static NSWindow *overlay;
// TODO: Especially the ToplevelArea should really really acquire its rect and
// origin dynamically from NSScreen, since they are subject to changes, e.g.
// when the Dock is switched from/to autohide.
- (id)initWithRect:(NSRect)r
{
if ((self = [super init]))
{
_children = [[NSMutableArray alloc] init];
_rect = r;
}
return self;
}
- (int)width
{
return self.rect.size.width;
}
- (int)height
{
return self.rect.size.height;
}
- (void)drawOverlay
{
NSRect contentRect = [NSWindow contentRectForFrameRect:_rect styleMask:NSBorderlessWindowMask];
overlay = [[NSWindow alloc] initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
overlay.backgroundColor = NSColor.lightGrayColor;
overlay.opaque = NO;
overlay.level = NSMainMenuWindowLevel + 1; //Alternative: NSFloatingWindowLevel
overlay.alphaValue = 0.4;
overlay.hasShadow = NO;
overlay.ignoresMouseEvents = YES;
[overlay makeKeyAndOrderFront:overlay];
}
- (void)addChild:(Window *)w
{
[self.children addObject:w];
w.area = self;
[self resizeChildren];
}
- (void)removeChild:(Window *)w
{
[self.children removeObject:w];
[self resizeChildren];
}
- (void)resizeChildren
{
if (self.children.count == 0)
return;
if (self.verticallySplit)
{
int heightPerWindow = self.height / self.children.count;
int i = 0;
for (Window *w in self.children)
{
NSRect newRect;
newRect.size.width = self.width;
newRect.size.height = heightPerWindow;
NSPoint newOrigin = self.rect.origin;
newOrigin.y += i++ * heightPerWindow;
newRect.origin = newOrigin;
w.rect = newRect;
}
}
else
{
int widthPerWindow = self.width / self.children.count;
int i = 0;
for (Window *w in self.children)
{
NSRect newRect;
newRect.size.width = widthPerWindow;
newRect.size.height = self.height;
NSPoint newOrigin = self.rect.origin;
newOrigin.x += i++ * widthPerWindow;
newRect.origin = newOrigin;
w.rect = newRect;
}
}
}
@end