-
Notifications
You must be signed in to change notification settings - Fork 17
/
windowdelegate.m
56 lines (45 loc) · 1.54 KB
/
windowdelegate.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
#import "windowdelegate.h"
#include "_cgo_export.h"
const int DID_RESIZE_EVENT = 0;
const int DID_MOVE_EVENT = 1;
const int DID_MINIATURIZE_EVENT = 2;
const int DID_DEMINIATURIZE_EVENT = 3;
@implementation WindowDelegate
- (void)dealloc
{
[super dealloc];
}
- (void)windowDidResize:(NSNotification *)notification
{
NSWindow *movedWindow = notification.object;
triggerEvent([self goWindowID], movedWindow, @"windowDidResize", DID_RESIZE_EVENT);
}
- (void)windowDidMove:(NSNotification *)notification
{
NSWindow *movedWindow = notification.object;
triggerEvent([self goWindowID], movedWindow, @"windowDidMove", DID_MOVE_EVENT);
}
- (void)windowDidMiniaturize:(NSNotification *)notification
{
NSWindow *movedWindow = notification.object;
triggerEvent([self goWindowID], movedWindow, @"windowDidMiniaturize", DID_MINIATURIZE_EVENT);
}
- (void)windowDidDeminiaturize:(NSNotification *)notification
{
NSWindow *movedWindow = notification.object;
triggerEvent([self goWindowID], movedWindow, @"windowDidDeminiaturize", DID_DEMINIATURIZE_EVENT);
}
@end
void triggerEvent(int goWindowID, NSWindow *movedWindow, NSString *eventTitle, const int eventId)
{
if ([movedWindow isKeyWindow])
{
NSRect rect = movedWindow.frame;
int x = (int)(rect.origin.x);
int y = (int)(rect.origin.y);
int w = (int)(rect.size.width);
int h = (int)(rect.size.height);
NSLog(@"%@ %@", eventTitle, movedWindow);
onWindowEvent(goWindowID, eventId, x, y, w, h);
}
}