From e33bdffc7d1e3cb85a672ec6cd77c2b5a57dd909 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Fri, 22 Mar 2024 17:55:59 -0600 Subject: [PATCH] Fixing issue where keyUp events aren't sent for keys that become modified by the command key --- code/custom/4coder_command_map.cpp | 8 +++++--- code/platform_mac/mac_4ed.mm | 18 ++++++++++++------ code/platform_mac/mac_4ed_metal.mm | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/code/custom/4coder_command_map.cpp b/code/custom/4coder_command_map.cpp index f3c15979..2d3ba16a 100644 --- a/code/custom/4coder_command_map.cpp +++ b/code/custom/4coder_command_map.cpp @@ -216,9 +216,11 @@ map_loose_match(Input_Modifier_Set *binding_mod_set, Input_Modifier_Set *event_m i32 binding_mod_count = binding_mod_set->count; Key_Code *binding_mods = binding_mod_set->mods; for (i32 i = 0; i < binding_mod_count; i += 1){ - if (has_modifier(event_mod_set, binding_mods[i])){ - result += 1; + if (!has_modifier(event_mod_set, binding_mods[i])){ + result = 0; + break; } + result += 1; } return(result); } @@ -274,7 +276,7 @@ map_get_binding_non_recursive(Command_Map *map, Input_Event *event, Binding_Matc result = map->text_input_command; } else{ - Map_Event_Breakdown breakdown = map_get_event_breakdown(event); + Map_Event_Breakdown breakdown = map_get_event_breakdown(event); Table_Lookup lookup = table_lookup(&map->event_code_to_binding_list, breakdown.key); if (lookup.found_match){ u64 val = 0; diff --git a/code/platform_mac/mac_4ed.mm b/code/platform_mac/mac_4ed.mm index e316dfa7..0bca9547 100644 --- a/code/platform_mac/mac_4ed.mm +++ b/code/platform_mac/mac_4ed.mm @@ -348,7 +348,7 @@ os_popup_error(char *title, char *message){ #if defined(FRED_INTERNAL) function inline void mac_profile(char *name, u64 begin, u64 end){ - printf("%s Time: %fs\n", name, ((end - begin) / 1000000.0f)); + //printf("%s Time: %fs\n", name, ((end - begin) / 1000000.0f)); } #define MacProfileScope(name) for (u64 glue(_i_, __LINE__) = 0, glue(_begin_, __LINE__) = system_now_time();\ @@ -909,7 +909,7 @@ mac_toggle_fullscreen(void){ mac_profile("Frame", prev_timer_start, mac_vars.timer_start); #if FRED_INTERNAL - printf("\n"); + //printf("\n"); #endif } @@ -946,7 +946,7 @@ mac_toggle_fullscreen(void){ - (void)keyDown:(NSEvent*)event{ // NOTE(yuval): Process keyboard event [self process_keyboard_event:event down:true]; - [self interpretKeyEvents:[NSArray arrayWithObject:event]]; + [self interpretKeyEvents:[NSArray arrayWithObject:event]]; // TODO(allen): Deduplicate with insertText version // NOTE(allen): We need to manually send text for '\n' and '\t' @@ -961,9 +961,9 @@ mac_toggle_fullscreen(void){ } if ((c == '\t') || (c == '\n')){ u8 *str = push_array(&mac_vars.frame_arena, u8, 1); - str[0] = (u8)c; + str[0] = (u8)c; -Input_Event *event = push_input_event(&mac_vars.frame_arena, &mac_vars.input_chunk.trans.event_list); + Input_Event *event = push_input_event(&mac_vars.frame_arena, &mac_vars.input_chunk.trans.event_list); event->kind = InputEventKind_TextInsert; event->text.string = SCu8(str, 1); event->text.next_text = 0; @@ -1206,11 +1206,17 @@ Input_Event *event = push_input_event(&mac_vars.frame_arena, &mac_vars.input_chu system_signal_step(0); } - } else{ + } 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; diff --git a/code/platform_mac/mac_4ed_metal.mm b/code/platform_mac/mac_4ed_metal.mm index f18369da..94fc7c87 100644 --- a/code/platform_mac/mac_4ed_metal.mm +++ b/code/platform_mac/mac_4ed_metal.mm @@ -16,7 +16,7 @@ struct Mac_Metal{ function mac_render_sig(mac_metal__render){ #if defined(FRED_INTERNAL) - printf("Redering using Metal!\n"); + //printf("Redering using Metal!\n"); #endif Mac_Metal *metal = (Mac_Metal*)renderer;