From fc46e771cdd5b90d33fc7f895886fc43dea351c7 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:20:25 +0100 Subject: Improve prioritization of event handlers added at open display time --- src/Fl.cxx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/Fl.cxx') diff --git a/src/Fl.cxx b/src/Fl.cxx index 013d4dee1..c9a2972d2 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -827,6 +827,34 @@ void Fl::add_handler(Fl_Event_Handler ha) { } +/** Returns the last function installed by a call to Fl::add_handler() */ +Fl_Event_Handler Fl::last_handler() { + return handlers ? handlers->handle : NULL; +} + + +/** Install a function to parse unrecognized events with less priority than another function. + Install function \p ha to handle unrecognized events + giving it the priority just lower than that of function \p before + which was previously installed. + \see Fl::add_handler(Fl_Event_Handler) + \see Fl::last_handler() + */ +void Fl::add_handler(Fl_Event_Handler ha, Fl_Event_Handler before) { + if (!before) return Fl::add_handler(ha); + handler_link *l = handlers; + while (l) { + if (l->handle == before) { + handler_link *p = l->next, *q = new handler_link; + q->handle = ha; + q->next = p; + l->next = q; + return; + } + l = l->next; + } +} + /** Removes a previously added event handler. \see Fl::handle(int, Fl_Window*) -- cgit v1.2.3