summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-02-27 16:20:25 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-02-27 16:20:25 +0100
commitfc46e771cdd5b90d33fc7f895886fc43dea351c7 (patch)
tree966449959d3b12c873fd60d8b34dd640fe54b89a
parent746cbf861a5a441695b2fc653ed8327a9b409035 (diff)
Improve prioritization of event handlers added at open display time
-rw-r--r--FL/Fl.H4
-rw-r--r--src/Fl.cxx28
-rw-r--r--src/Fl_Screen_Driver.cxx16
3 files changed, 40 insertions, 8 deletions
diff --git a/FL/Fl.H b/FL/Fl.H
index 95d08c9db..f229e5344 100644
--- a/FL/Fl.H
+++ b/FL/Fl.H
@@ -851,7 +851,9 @@ public:
/** Gets the current Fl::focus() widget. \sa Fl::focus(Fl_Widget*) */
static Fl_Widget* focus() {return focus_;}
static void focus(Fl_Widget*);
- static void add_handler(Fl_Event_Handler h);
+ static void add_handler(Fl_Event_Handler ha);
+ static void add_handler(Fl_Event_Handler ha, Fl_Event_Handler before);
+ static Fl_Event_Handler last_handler();
static void remove_handler(Fl_Event_Handler h);
static void add_system_handler(Fl_System_Handler h, void *data);
static void remove_system_handler(Fl_System_Handler h);
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);
}
}