-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
mouse.c
68 lines (58 loc) · 1.83 KB
/
mouse.c
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
#include <Carbon/Carbon.h>
#include "mouse.h"
static const EventTypeSpec mouse_events [] = {
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp },
{ kEventClassMouse, kEventMouseDragged },
{ kEventClassMouse, kEventMouseEntered },
{ kEventClassMouse, kEventMouseExited },
{ kEventClassMouse, kEventMouseWheelMoved }
};
static pascal OSStatus mouse_handler(EventHandlerCallRef next, EventRef e, void *data) {
switch (GetEventKind(e)) {
case kEventMouseUp: {
CGEventRef cg_event = CopyEventCGEvent(e);
struct event event = { (void *) cg_event, MOUSE_UP };
event_post(&event);
CFRelease(cg_event);
break;
}
case kEventMouseDragged: {
CGEventRef cg_event = CopyEventCGEvent(e);
struct event event = { (void *) cg_event, MOUSE_DRAGGED };
event_post(&event);
CFRelease(cg_event);
break;
}
case kEventMouseEntered: {
CGEventRef cg_event = CopyEventCGEvent(e);
struct event event = { (void *) cg_event, MOUSE_ENTERED };
event_post(&event);
CFRelease(cg_event);
break;
}
case kEventMouseExited: {
CGEventRef cg_event = CopyEventCGEvent(e);
struct event event = { (void *) cg_event, MOUSE_EXITED };
event_post(&event);
CFRelease(cg_event);
break;
}
case kEventMouseWheelMoved: {
CGEventRef cg_event = CopyEventCGEvent(e);
struct event event = { (void *) cg_event, MOUSE_SCROLLED };
event_post(&event);
CFRelease(cg_event);
break;
}
default:
break;
}
return CallNextEventHandler(next, e);
}
void mouse_begin(void) {
InstallEventHandler(GetEventDispatcherTarget(),
NewEventHandlerUPP(mouse_handler),
GetEventTypeCount(mouse_events),
mouse_events, 0, 0);
}