-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "entirely remove Carbon, get all events directly through the e…
…vent mach port" This reverts commit 207c4d7. .. ..
- Loading branch information
1 parent
893ed8c
commit 0e4ccc1
Showing
7 changed files
with
73 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,68 @@ | ||
#include <Carbon/Carbon.h> | ||
#include "mouse.h" | ||
|
||
bool mouse_handle_event(CGEventType type, CGEventRef cg_event) { | ||
if (type == kCGEventOtherMouseUp | ||
|| type == kCGEventLeftMouseUp | ||
|| type == kCGEventRightMouseUp) { | ||
struct event event = { (void *) cg_event, MOUSE_UP }; | ||
event_post(&event); | ||
} else if (type == kCGEventLeftMouseDragged) { | ||
struct event event = { (void *) cg_event, MOUSE_DRAGGED }; | ||
event_post(&event); | ||
} else if (type == 0x8) { | ||
struct event event = { (void *) cg_event, MOUSE_ENTERED }; | ||
event_post(&event); | ||
} else if (type == 0x9) { | ||
struct event event = { (void *) cg_event, MOUSE_EXITED }; | ||
event_post(&event); | ||
} else if (type == kCGEventScrollWheel) { | ||
struct event event = { (void *) cg_event, MOUSE_SCROLLED }; | ||
event_post(&event); | ||
} else return false; | ||
return true; | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
#pragma once | ||
#include "event.h" | ||
|
||
static const CGEventMask g_mouse_events | ||
= CGEventMaskBit(kCGEventLeftMouseUp) | ||
| CGEventMaskBit(kCGEventRightMouseUp) | ||
| CGEventMaskBit(kCGEventOtherMouseUp) | ||
| CGEventMaskBit(kCGEventLeftMouseDragged) | ||
| CGEventMaskBit(kCGEventScrollWheel); | ||
|
||
bool mouse_handle_event(CGEventType type, CGEventRef cg_event); | ||
void mouse_begin(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters