Skip to content

Commit 7e548bb

Browse files
committed
feat(utils): Remove MacOS includes from header because Mac is quirky
1 parent 2c9b81d commit 7e548bb

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/macos.mm

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,40 @@
1010
#import <Geode/cocos/platform/mac/EAGLView.h>
1111
#import <objc/runtime.h>
1212

13+
#include "BetterTextInputNode.hpp"
14+
1315
#include "types/TouchMessageType.hpp"
16+
#include "utils.hpp"
17+
18+
namespace BI::platform
19+
{
20+
inline bool keyDown(PlatformKey key, NSEvent* event)
21+
{
22+
switch (key)
23+
{
24+
case BI::PlatformKey::LEFT_CONTROL:
25+
return ([event modifierFlags] & NSCommandKeyMask);
26+
case BI::PlatformKey::LEFT_SHIFT:
27+
return ([event modifierFlags] & NSShiftKeyMask);
28+
}
29+
30+
return false;
31+
}
32+
}
1433

1534
#define HOOK_OBJC_METHOD(klass, cleanFuncName, funcName) \
1635
auto cleanFuncName ## Method = class_getInstanceMethod(objc_getClass(#klass), @selector(funcName)); \
1736
cleanFuncName ## OIMP = method_getImplementation(cleanFuncName ## Method); \
1837
method_setImplementation(cleanFuncName ## Method, (EventType<klass>)&funcName);
1938

20-
#define CALL_OIMP(funcName) reinterpret_cast<decltype(&funcName)>(funcName ## OIMP)(self, sel, event)
21-
2239
template <typename T>
2340
using EventType = void(*)(T*, SEL, NSEvent*);
2441

2542

2643
static EventType<EAGLView> keyDownExecOIMP;
2744
void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) {
2845
if (!g_selectedInput)
29-
CALL_OIMP(keyDownExec);
46+
keyDownExecOIMP(self, sel, event);
3047

3148
// on click, can be held
3249
if (
@@ -140,37 +157,37 @@ void keyDownExec(EAGLView* self, SEL sel, NSEvent* event) {
140157
!BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL, event) &&
141158
[event keyCode] == kVK_Return
142159
) {
143-
CALL_OIMP(keyDownExec);
160+
keyDownExec(self, sel, event);
144161
}
145162
}
146163
}
147164

148165
static EventType<EAGLView> keyUpExecOIMP;
149166
void keyUpExec(EAGLView* self, SEL sel, NSEvent* event) {
150167
if (!g_selectedInput)
151-
CALL_OIMP(keyUpExec);
168+
keyUpExec(self, sel, event);
152169
}
153170

154171

155172
// TODO: move to hooking mouseDownExec
156173
// handles mouse clicks
157-
struct BetterTouchDispatcher : Modify<BetterTouchDispatcher, CCTouchDispatcher>
174+
struct BetterTouchDispatcher : geode::Modify<BetterTouchDispatcher, cocos2d::CCTouchDispatcher>
158175
{
159176
// https://github.com/ninXout/Crystal-Client/blob/7df5a8336ccb852bc984e55dd29ca27bb1741443/src/ImGui/ImGui.cpp#L96
160177
void touches(cocos2d::CCSet* touches, cocos2d::CCEvent* event, unsigned int type)
161178
{
162179
if (!g_selectedInput)
163-
return CCTouchDispatcher::touches(touches, event, type);
180+
return cocos2d::CCTouchDispatcher::touches(touches, event, type);
164181

165-
auto* touch = static_cast<CCTouch*>(touches->anyObject());
182+
auto* touch = static_cast<cocos2d::CCTouch*>(touches->anyObject());
166183
const auto touchPos = touch->getLocation();
167184

168185
if (type == TouchMessageType::Began)
169186
{
170-
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
187+
CCSize winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
171188

172189
// the touch event's origin is bottom left
173-
CCTouch touch{};
190+
cocos2d::CCTouch touch{};
174191
touch.setTouchInfo(0, touchPos.x, winSize.height - touchPos.y);
175192

176193
g_selectedInput->useUpdateBlinkPos(true);

src/utils.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
#include <Geode/cocos/robtop/glfw/glfw3.h>
66

77
#include <WinUser.h> // virtual keys
8-
#elif defined(GEODE_IS_MACOS)
9-
#define CommentType CommentTypeDummy
10-
#import <Cocoa/Cocoa.h>
11-
#include <AppKit/NSEvent.h>
12-
#undef CommentType
138
#endif
149

1510
#include <Geode/cocos/cocoa/CCGeometry.h>
@@ -153,19 +148,6 @@ namespace BI
153148
return GetKeyState(VK_SHIFT) & 0x8000;
154149
}
155150

156-
return false;
157-
}
158-
#elif defined(GEODE_IS_MACOS)
159-
inline bool keyDown(PlatformKey key, NSEvent* event)
160-
{
161-
switch (key)
162-
{
163-
case BI::PlatformKey::LEFT_CONTROL:
164-
return ([event modifierFlags] & NSCommandKeyMask);
165-
case BI::PlatformKey::LEFT_SHIFT:
166-
return ([event modifierFlags] & NSShiftKeyMask);
167-
}
168-
169151
return false;
170152
}
171153
#endif

0 commit comments

Comments
 (0)