-
Notifications
You must be signed in to change notification settings - Fork 0
/
PuckRunLoop.m
83 lines (71 loc) · 1.99 KB
/
PuckRunLoop.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
//
// PuckRunLoop
// Puck
//
// Created by slex on 30/05/21.
#import "PuckRunLoop.h"
#import "PuckEventHandlerFactory.h"
@implementation PuckRunLoop
@synthesize uiHandler;
- (id)initWithUIHandler:(PuckUIHandler*)anUiHandler
{
self = [super init];
if (self == nil)
{
NSLog(@"Unable to init...");
return nil;
}
uiHandler = anUiHandler;
return self;
}
- (void)startEventHandlerLoop
{
xcb_generic_event_t *e;
XCBConnection *connection = [uiHandler connection];
PuckEventHandlerFactory *eventHandler = [[PuckEventHandlerFactory alloc] initWithConnection:connection andUiHandler:uiHandler];
while ((e = xcb_wait_for_event([connection connection])))
{
switch (e->response_type & ~0x80)
{
case XCB_MAP_NOTIFY:
{
xcb_map_notify_event_t *mapNotify = (xcb_map_notify_event_t*) e;
NSLog(@"Window %u mapped", mapNotify->window);
[eventHandler handleMapNotify:mapNotify];
[connection flush];
break;
}
case XCB_PROPERTY_NOTIFY:
{
xcb_property_notify_event_t *propEvent = (xcb_property_notify_event_t *) e;
[eventHandler handlePropertyNotify:propEvent];
[connection flush];
break;
}
case XCB_MOTION_NOTIFY:
{
break;
}
case XCB_DESTROY_NOTIFY:
{
xcb_destroy_notify_event_t *destroyNotify = (xcb_destroy_notify_event_t *) e;
NSLog(@"Destroy EVENT for window: %u", destroyNotify->window);
[eventHandler handleDestroyNotify:destroyNotify];
[connection flush];
break;
}
default:
{
//NSLog(@"Default");
break;
}
}
}
eventHandler = nil;
connection = nil;
}
- (void) dealloc
{
uiHandler = nil;
}
@end