From 114fb66cd38f10c14a076108eb8f77e75a107174 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 15 Nov 2024 20:24:40 +0100 Subject: [PATCH] Fixes Alt-modifier handling in Fl_Shorcut_Button on macOS --- src/Fl_Shortcut_Button.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Fl_Shortcut_Button.cxx b/src/Fl_Shortcut_Button.cxx index 9f19fa0b4..7e04183bc 100644 --- a/src/Fl_Shortcut_Button.cxx +++ b/src/Fl_Shortcut_Button.cxx @@ -19,6 +19,7 @@ #include #include #include +#include "Fl_System_Driver.H" #include "flstring.h" #include @@ -174,6 +175,7 @@ void Fl_Shortcut_Button::do_end_hot_callback() { Handle keystrokes to catch the user's shortcut. */ int Fl_Shortcut_Button::handle(int e) { + static int alt_modifier_extra_handler = Fl::system_driver()->need_test_shortcut_extra(); #if 0 bool inside_default_button = false; if (default_set_ && ( (e == FL_PUSH) || (e == FL_DRAG) || (e == FL_RELEASE) ) ) { @@ -235,6 +237,17 @@ int Fl_Shortcut_Button::handle(int e) { // type, so we don't handle them here either // Todo: use fl_utf_tolower and fl_utf_toupper int v = fl_utf8decode(Fl::event_text(), 0, 0); + if (alt_modifier_extra_handler && Fl::event_state(FL_ALT)) { + // MacOS returns special characters when the alt modifier is held down. + // FLTK handles shortcuts as ASCII keys, so let's convert the keystroke. + int c = Fl::event_key(); + if ( (c>32) && (c<128) && (isalnum(c)) ) { + v = c; + if (Fl::event_state(FL_SHIFT)) { + v = toupper(c); + } + } + } if ( (v > 32 && v < 0x7f) || (v > 0xa0 && v <= 0xff) ) { if (isupper(v)) { v = tolower(v);