Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MacOS] Fullscreen fix #121

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/unix/apple/macosx/app.m
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ static void window_pen_event(struct window *ctx, NSEvent *event, bool pressed)

static void window_mouse_button_event(struct window *ctx, NSUInteger index, bool pressed)
{
if (!ctx)
return;

NSPoint p = {0};
struct window *cur = window_find_mouse(ctx, &p);
if (!cur)
Expand Down Expand Up @@ -638,6 +641,9 @@ static void window_mouse_button_event(struct window *ctx, NSUInteger index, bool

static void window_button_event(struct window *ctx, NSEvent *event, NSUInteger index, bool pressed)
{
if (!ctx)
return;

// An index of zero indicates a pen event
bool is_pen_press = event.buttonMask & NSEventButtonMaskPenTip || index == 0;

Expand Down Expand Up @@ -736,6 +742,9 @@ static void window_mouse_motion_event(struct window *ctx, NSEvent *event, bool p

static void window_motion_event(struct window *ctx, NSEvent *event)
{
if (!ctx)
return;

bool pen_in_range = event.subtype == NSEventSubtypeTabletPoint;

if (ctx->app->pen_enabled && pen_in_range) {
Expand Down Expand Up @@ -834,6 +843,8 @@ static BOOL window_canBecomeMainWindow(NSWindow *self, SEL _cmd)
static NSRect window_windowWillUseStandardFrame_defaultFrame(NSWindow *self, SEL _cmd, NSWindow *window, NSRect newFrame)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return newFrame;

if (!NSEqualRects(window.frame, newFrame))
ctx->normal_frame = window.frame;
Expand All @@ -844,13 +855,17 @@ static NSRect window_windowWillUseStandardFrame_defaultFrame(NSWindow *self, SEL
static BOOL window_performKeyEquivalent(NSWindow *self, SEL _cmd, NSEvent *event)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return NO;

return ctx->app->grab_kb;
}

static BOOL window_windowShouldClose(NSWindow *self, SEL _cmd, NSWindow *sender)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return NO;

MTY_Event evt = {
.type = MTY_EVENT_CLOSE,
Expand All @@ -870,6 +885,8 @@ static void window_windowWillClose(NSWindow *self, SEL _cmd, NSNotification *not
static void window_windowDidResignKey(NSWindow *self, SEL _cmd, NSNotification *notification)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

MTY_Event evt = {
.type = MTY_EVENT_FOCUS,
Expand All @@ -895,6 +912,8 @@ static void window_windowDidResignKey(NSWindow *self, SEL _cmd, NSNotification *
static void window_windowDidBecomeKey(NSWindow *self, SEL _cmd, NSNotification *notification)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

MTY_Event evt = {
.type = MTY_EVENT_FOCUS,
Expand All @@ -911,6 +930,8 @@ static void window_windowDidBecomeKey(NSWindow *self, SEL _cmd, NSNotification *
static void window_windowDidChangeScreen(NSWindow *self, SEL _cmd, NSNotification *notification)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

// This event fires at the right time to re-apply the window level above the dock
if (ctx->top && self.isKeyWindow && (self.styleMask & NSWindowStyleMaskFullScreen)) {
Expand All @@ -922,6 +943,8 @@ static void window_windowDidChangeScreen(NSWindow *self, SEL _cmd, NSNotificatio
static void window_windowDidResize(NSWindow *self, SEL _cmd, NSNotification *notification)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

MTY_Event evt = {
.type = MTY_EVENT_SIZE,
Expand All @@ -937,6 +960,8 @@ static void window_windowDidResize(NSWindow *self, SEL _cmd, NSNotification *not
static void window_windowDidMove(NSWindow *self, SEL _cmd, NSNotification *notification)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

MTY_Event evt = {
.type = MTY_EVENT_MOVE,
Expand All @@ -949,13 +974,17 @@ static void window_windowDidMove(NSWindow *self, SEL _cmd, NSNotification *notif
static void window_keyUp(NSWindow *self, SEL _cmd, NSEvent *event)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

window_keyboard_event(ctx, event.keyCode, event.modifierFlags, false, false);
}

static void window_keyDown(NSWindow *self, SEL _cmd, NSEvent *event)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

window_text_event(ctx, [event.characters UTF8String]);
window_keyboard_event(ctx, event.keyCode, event.modifierFlags, true, event.isARepeat);
Expand All @@ -964,6 +993,8 @@ static void window_keyDown(NSWindow *self, SEL _cmd, NSEvent *event)
static void window_flagsChanged(NSWindow *self, SEL _cmd, NSEvent *event)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

bool pressed = window_flags_changed(event.keyCode, event.modifierFlags);
window_keyboard_event(ctx, event.keyCode, event.modifierFlags, pressed, false);
Expand Down Expand Up @@ -1024,6 +1055,8 @@ static void window_otherMouseDragged(NSWindow *self, SEL _cmd, NSEvent *event)
static void window_mouseEntered(NSWindow *self, SEL _cmd, NSEvent *event)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

ctx->app->cursor_outside = false;
app_apply_cursor(ctx->app);
Expand All @@ -1032,6 +1065,8 @@ static void window_mouseEntered(NSWindow *self, SEL _cmd, NSEvent *event)
static void window_mouseExited(NSWindow *self, SEL _cmd, NSEvent *event)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

ctx->app->cursor_outside = true;
app_apply_cursor(ctx->app);
Expand All @@ -1045,6 +1080,8 @@ static void window_scrollWheel(NSWindow *self, SEL _cmd, NSEvent *event)
static void window_tabletProximity(NSWindow *self, SEL _cmd, NSEvent *event)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

ctx->app->eraser = event.pointingDeviceType == NSPointingDeviceTypeEraser;
ctx->app->pen_left = !event.enteringProximity;
Expand All @@ -1055,6 +1092,8 @@ static NSApplicationPresentationOptions window_window_willUseFullScreenPresentat
NSWindow *window, NSApplicationPresentationOptions proposedOptions)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return proposedOptions;

if (![self isZoomed]) {
ctx->normal_frame = window.frame;
Expand All @@ -1071,6 +1110,8 @@ static NSApplicationPresentationOptions window_window_willUseFullScreenPresentat
static void window_windowDidEnterFullScreen(NSWindow *self, SEL _cmd, NSNotification *notification)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

if (ctx->top)
[self setLevel:NSMainMenuWindowLevel - 1];
Expand All @@ -1079,6 +1120,8 @@ static void window_windowDidEnterFullScreen(NSWindow *self, SEL _cmd, NSNotifica
static void window_windowWillExitFullScreen(NSWindow *self, SEL _cmd, NSNotification *notification)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

ctx->top = false;
[self setLevel:NSNormalWindowLevel];
Expand All @@ -1087,6 +1130,8 @@ static void window_windowWillExitFullScreen(NSWindow *self, SEL _cmd, NSNotifica
static void window_toggleFullScreen(NSWindow *self, SEL _cmd, id sender)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

if (window_is_fullscreen(self, true)) {
if (self.isKeyWindow)
Expand Down Expand Up @@ -1187,6 +1232,8 @@ static BOOL view_acceptsFirstMouse(NSView *self, SEL _cmd, NSEvent *event)
static void view_updateTrackingAreas(NSView *self, SEL _cmd)
{
struct window *ctx = OBJC_CTX();
if (!ctx)
return;

if (ctx->area)
[self removeTrackingArea:ctx->area];
Expand Down Expand Up @@ -1727,6 +1774,7 @@ MTY_Window MTY_WindowCreate(MTY_App *app, const char *title, const MTY_Frame *fr
[ctx->nsw setDelegate:ctx->nsw];
[ctx->nsw setAcceptsMouseMovedEvents:YES];
[ctx->nsw setReleasedWhenClosed:NO];
[ctx->nsw setTabbingMode:NSWindowTabbingModeDisallowed];

NSUInteger cb = alt_fs ? NSWindowCollectionBehaviorFullScreenNone |
NSWindowCollectionBehaviorFullScreenDisallowsTiling : NSWindowCollectionBehaviorFullScreenPrimary;
Expand Down Expand Up @@ -1765,6 +1813,9 @@ void MTY_WindowDestroy(MTY_App *app, MTY_Window window)

ctx->app->windows[window] = NULL;

OBJC_CTX_CLEAR(ctx->nsw.contentView);
OBJC_CTX_CLEAR(ctx->nsw);

[ctx->nsw close];

// XXX Make sure this is freed after the window is closed, events
Expand Down
3 changes: 3 additions & 0 deletions src/unix/apple/objc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#define OBJC_CTX() \
(*((void **) object_getIndexedIvars(self)))

#define OBJC_CTX_CLEAR(obj) \
*((void **) object_getIndexedIvars(obj)) = nil;

#define OBJC_ALLOCATE(super, name) \
objc_allocateClassPair(objc_getClass(super), name, sizeof(void *))

Expand Down