diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-02-27 16:20:25 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-02-27 16:20:25 +0100 |
| commit | fc46e771cdd5b90d33fc7f895886fc43dea351c7 (patch) | |
| tree | 966449959d3b12c873fd60d8b34dd640fe54b89a /src | |
| parent | 746cbf861a5a441695b2fc653ed8327a9b409035 (diff) | |
Improve prioritization of event handlers added at open display time
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl.cxx | 28 | ||||
| -rw-r--r-- | src/Fl_Screen_Driver.cxx | 16 |
2 files changed, 37 insertions, 7 deletions
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*) diff --git a/src/Fl_Screen_Driver.cxx b/src/Fl_Screen_Driver.cxx index d127b6b1e..112f376d3 100644 --- a/src/Fl_Screen_Driver.cxx +++ b/src/Fl_Screen_Driver.cxx @@ -571,21 +571,23 @@ void Fl_Screen_Driver::use_startup_scale_factor() void Fl_Screen_Driver::open_display() { static bool been_here = false; - // Add scale_handler first so it has least priority of all handlers - if (!been_here) Fl::add_handler(Fl_Screen_Driver::scale_handler); - open_display_platform(); if (!been_here) { been_here = true; - bool keep_scale_handler = false; + open_display_platform(); + // Memorize the most recently added handler. It may have been + // added by open_display_platform() + Fl_Event_Handler last_added = Fl::last_handler(); if (rescalable()) { use_startup_scale_factor(); - if (keyboard_screen_scaling && rescalable()) - keep_scale_handler = true; + if (keyboard_screen_scaling && rescalable()) { + // Add scale_handler after memorized one in linked list + // so it has less priority + Fl::add_handler(Fl_Screen_Driver::scale_handler, last_added); + } int mx, my; int ns = Fl::screen_driver()->get_mouse(mx, my); Fl_Graphics_Driver::default_driver().scale(scale(ns)); } - if (!keep_scale_handler) Fl::remove_handler(Fl_Screen_Driver::scale_handler); } } |
