FLTK logo

[master] 61c0f79 - Fix "FLTK on NetBSD very slow on X11 with Unicode locale" (#935)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 61c0f79 - Fix "FLTK on NetBSD very slow on X11 with Unicode locale" (#935) "ManoloFLTK" 06:17 Mar 18  
 
commit 61c0f79397f6d074d51364b840a2642861f5396e
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Mon Mar 18 14:05:48 2024 +0100
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Mon Mar 18 14:05:48 2024 +0100

     Fix "FLTK on NetBSD very slow on X11 with Unicode locale" (#935)

 src/Fl_x.cxx | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git src/Fl_x.cxx src/Fl_x.cxx
index 9f22b08..c3355ca 100644
--- src/Fl_x.cxx
+++ src/Fl_x.cxx
@@ -1232,15 +1232,52 @@ static void after_display_rescale(float *p_current_xft_dpi) {
 }
 #endif // USE_XFT
 
+
+static Window *xid_vector = NULL; // list of FLTK-created xid's (see issue #935)
+static int xid_vector_size = 0;
+static int xid_vector_count = 0;
+
+static void add_xid_vector(Window xid) {
+  if (xid_vector_count >= xid_vector_size) {
+    xid_vector_size += 10;
+    xid_vector = (Window*)realloc(xid_vector, xid_vector_size * sizeof(Window));
+  }
+  xid_vector[xid_vector_count++] = xid;
+}
+
+static bool remove_xid_vector(Window xid) {
+  for (int pos = xid_vector_count - 1; pos >= 0; pos--) {
+    if (xid_vector[pos] == xid) {
+      if (pos != --xid_vector_count) xid_vector[pos] = xid_vector[xid_vector_count];
+      return true;
+    }
+  }
+  return false;
+}
+
 int fl_handle(const XEvent& thisevent)
 {
   XEvent xevent = thisevent;
   fl_xevent = &thisevent;
   Window xid = xevent.xany.window;
+  
+  // For each DestroyNotify event, determine whether an FLTK-created window
+  // is being destroyed (see issue #935).
+  bool xid_is_from_fltk_win = false;
+  if (xevent.type == DestroyNotify) {
+    xid_is_from_fltk_win = remove_xid_vector(xid);
+  }
 
+  // The following if statement is limited to cases when event DestroyNotify
+  // concerns a non-FLTK window. Thus, the possibly slow call to XOpenIM()
+  // is not performed when an FLTK-created window is closed. This fixes issue #935.
   if (Fl_X11_Screen_Driver::xim_ic && xevent.type == DestroyNotify &&
-        xid != Fl_X11_Screen_Driver::xim_win && !fl_find(xid))
+        xid != Fl_X11_Screen_Driver::xim_win && !fl_find(xid) && !xid_is_from_fltk_win)
   {
+// When using menus or tooltips: xid is a just hidden top-level FLTK win, xim_win is non-FLTK;
+// after XIM crash: xid is non-FLTK.
+// Trigger XIM crash under Debian: kill process containing "ibus-daemon"
+// Restart XIM after triggered crash: "ibus-daemon --panel disable --xim &"
     XIM xim_im;
     xim_im = XOpenIM(fl_display, NULL, NULL, NULL);
     if (!xim_im) {
@@ -2372,6 +2409,7 @@ void Fl_X11_Window_Driver::un_maximize() {
 void fl_fix_focus(); // in Fl.cxx
 
 Fl_X* Fl_X::set_xid(Fl_Window* win, Window winxid) {
+  if (!win->parent()) add_xid_vector(winxid); // store xid's of top-level FLTK windows
   Fl_X *xp = new Fl_X;
   xp->xid = winxid;
   Fl_Window_Driver::driver(win)->other_xid = 0;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.