From 91cc66a52a8a04d63ce3c89ab2348f5de5710c0e Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Thu, 24 Apr 2025 16:45:45 -0700 Subject: [PATCH] Fixing no keyup events while command is pressed on mac --- code/platform_mac/mac_4ed.mm | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/code/platform_mac/mac_4ed.mm b/code/platform_mac/mac_4ed.mm index cdc898ec..0fdee594 100644 --- a/code/platform_mac/mac_4ed.mm +++ b/code/platform_mac/mac_4ed.mm @@ -701,7 +701,14 @@ mac_toggle_fullscreen(void){ [super dealloc]; } -- (void)viewDidChangeBackingProperties{ +- (void)viewDidChangBackingProperties{ + NSWindow* window = self.window; + f32 max_dpi = [window screen].backingScaleFactor; + mac_vars.screen_scale_factor = max_dpi; + + // TODO(PS): we want to call try_modify_face here for all active faces + // try_modify_face(app, face_id, &description); + // TODO(yuval): If the screen scale factor changed, modify the current face to use the new screen scale factor. mac_resize(mac_vars.window); } @@ -1209,22 +1216,6 @@ mac_toggle_fullscreen(void){ } else { mac_vars.active_key_stroke = 0; mac_vars.active_text_input = 0; - - if (key != 0){ - // NOTE(PS): when releasing the command key, assume all keys being pressed - // are released - if (key == KeyCode_Command) { - mods->count = 0; - } - - Input_Event *event = push_input_event(&mac_vars.frame_arena, &mac_vars.input_chunk.trans.event_list); - event->kind = InputEventKind_KeyRelease; - event->key.code = key; - event->key.modifiers = copy_modifier_set(&mac_vars.frame_arena, mods); - - remove_modifier(mods, key); - } - system_signal_step(0); } } @@ -1261,6 +1252,15 @@ main(int arg_count, char **args){ FCoder_App_Delegate *app_delegate = [[FCoder_App_Delegate alloc] init]; [NSApp setDelegate:app_delegate]; + // workaround for "no key-up sent while Cmd is pressed" taken from GLFW: + NSEvent* (^keyup_monitor)(NSEvent*) = ^NSEvent* (NSEvent* event) { + if ([event modifierFlags] & NSEventModifierFlagCommand) { + [[NSApp keyWindow] sendEvent:event]; + } + return event; + }; + id keyup_monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyUp handler:keyup_monitor]; + mac_init_recursive_mutex(&memory_tracker_mutex); // NOTE(yuval): Context setup