Avoiding Escape exiting my application

47 views
Skip to first unread message

Gonzalo Garramuño

unread,
Nov 22, 2023, 8:41:09 AM11/22/23
to fltkg...@googlegroups.com
Silly question, but so far I cannot get FLTK to behave.  I want to avoid
Escape from quitting my application (or make it so it respects the Quit
hotkey only set on my menu).

I was able to avoid Escape from quitting by setting a dummy callback
(just a ; on the callback), but that also prevented from exiting the
application with the standard window manager close window buttons.

I tried handling the FL_KEYBOARD, FL_KEYUP and FL_SHORTCUT and avoiding
Escape on my main window class, but it still quits on me.

--
Gonzalo Garramuño
ggar...@gmail.com

Matthias Melcher

unread,
Nov 22, 2023, 9:17:04 AM11/22/23
to fltk.general
The esc feature is handled in Fl::handle(), not in the window handle function. You can use the callback reason to find out if pressing esc caused the callback.

Fl::callback_reason() returns FL_REASON_CANCELLED if esc was pressed, and FL_REASON_CLOSED if the window manager close button was used.

Matthias Melcher

unread,
Nov 22, 2023, 9:18:06 AM11/22/23
to fltk.general
You call Fl::callback_reason() from within your own window callback.

Gonzalo Garramuño

unread,
Nov 22, 2023, 9:28:10 AM11/22/23
to 'Matthias Melcher' via fltk.general
On 22/11/23 11:18, 'Matthias Melcher' via fltk.general wrote:
You call Fl::callback_reason() from within your own window callback.

Yep.  That works.  Thanks!

-- 
Gonzalo Garramuño
ggar...@gmail.com

Ian MacArthur

unread,
Nov 22, 2023, 9:35:21 AM11/22/23
to fltk.general
On Wednesday, 22 November 2023 at 14:28:10 UTC Gonzalo wrote:
On 22/11/23 11:18, 'Matthias Melcher' via fltk.general wrote:
You call Fl::callback_reason() from within your own window callback.

Yep.  That works.  Thanks!


FWIW, I think one of the samples in the test folder demonstrates this... or something like it.
Can't remember which one though...

 

Greg Ercolano

unread,
Nov 22, 2023, 9:48:28 AM11/22/23
to fltkg...@googlegroups.com


    We have a pretty small FAQ list, and subsequently it's not referred to much,
    but this item is actually on it:  https://www.fltk.org/doc-1.4/FAQ.html#faq_escape

    It doesn't mention the 'reason' technique Matt showed, perhaps that should be added.


  

Matthias Melcher

unread,
Nov 22, 2023, 4:32:50 PM11/22/23
to fltk.general
Callback Reason is a relatively new addition. I added that to the FAQ. Maybe a native speaker wants to rephrase my wording.
Reply all
Reply to author
Forward
0 new messages