FLTK logo

[branch-1.4] dd04178 - Cont'd "New Wayland subwindow code creates issues with resizes of opengl windows…" (#1311)

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

[branch-1.4] dd04178 - Cont'd "New Wayland subwindow code creates issues with resizes of opengl windows…" (#1311) "ManoloFLTK" Oct 27, 2025  
 
commit dd0417885e6b8e4881f7e9f02914d6d3f5b3202f
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Mon Oct 27 09:55:13 2025 +0100
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Mon Oct 27 09:55:13 2025 +0100

    Cont'd "New Wayland subwindow code creates issues with resizes of opengl windowsâ?¦" (#1311)

 src/Fl_Gl_Window.cxx                               |  1 -
 src/Fl_Gl_Window_Driver.H                          |  1 -
 src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.H  |  3 +-
 .../Wayland/Fl_Wayland_Gl_Window_Driver.cxx        | 42 +++++++++++++++-------
 src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx   |  1 +
 5 files changed, 33 insertions(+), 15 deletions(-)

diff --git src/Fl_Gl_Window.cxx src/Fl_Gl_Window.cxx
index 30451ef..3e87a88 100644
--- src/Fl_Gl_Window.cxx
+++ src/Fl_Gl_Window.cxx
@@ -299,7 +299,6 @@ void Fl_Gl_Window::resize(int X,int Y,int W,int H) {
   if (is_a_resize) valid(0);
   pGlWindowDriver->resize(is_a_resize, W, H);
   Fl_Window::resize(X,Y,W,H);
-  if (is_a_resize) pGlWindowDriver->after_resize();
 }
 
 /**
diff --git src/Fl_Gl_Window_Driver.H src/Fl_Gl_Window_Driver.H
index aed986d..d40cbf8 100644
--- src/Fl_Gl_Window_Driver.H
+++ src/Fl_Gl_Window_Driver.H
@@ -67,7 +67,6 @@ public:
   virtual void make_current_after() {}
   virtual void swap_buffers() {}
   virtual void resize(int /*is_a_resize*/, int /*w*/, int /*h*/) {}
-  virtual void after_resize() {}
   virtual char swap_type();
   virtual void swap_interval(int) { }
   virtual int swap_interval() const { return -1; }
diff --git src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.H src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.H
index 0fac148..a7622fc 100644
--- src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.H
+++ src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.H
@@ -32,13 +32,13 @@ private:
   static EGLDisplay egl_display;
   struct wl_egl_window *egl_window;
   EGLSurface egl_surface;
+  bool need_swap;
   Fl_Wayland_Gl_Window_Driver(Fl_Gl_Window *win);
   float pixels_per_unit() FL_OVERRIDE;
   void make_current_before() FL_OVERRIDE;
   int mode_(int m, const int *a) FL_OVERRIDE;
   void swap_buffers() FL_OVERRIDE;
   void resize(int is_a_resize, int w, int h) FL_OVERRIDE;
-  void after_resize() FL_OVERRIDE;
   char swap_type() FL_OVERRIDE;
   void swap_interval(int) FL_OVERRIDE;
   int swap_interval() const FL_OVERRIDE;
@@ -52,6 +52,7 @@ private:
   void gl_visual(Fl_Gl_Choice *c) FL_OVERRIDE;
   void init();
 public:
+  static void surface_frame_done(void *data, struct wl_callback *cb, uint32_t time);
   //virtual bool need_scissor() { return true; } // CONTROL_LEAKING_SUB_GL_WINDOWS
   //void apply_scissor(); // CONTROL_LEAKING_SUB_GL_WINDOWS
 };
diff --git src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.cxx src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.cxx
index bd3a891..0dd3150 100644
--- src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.cxx
+++ src/drivers/Wayland/Fl_Wayland_Gl_Window_Driver.cxx
@@ -76,6 +76,7 @@ Fl_Wayland_Gl_Window_Driver::Fl_Wayland_Gl_Window_Driver(Fl_Gl_Window *win) :
   if (egl_display == EGL_NO_DISPLAY) init();
   egl_window = NULL;
   egl_surface = NULL;
+  need_swap = false;
 }
 
 
@@ -300,6 +301,23 @@ int Fl_Wayland_Gl_Window_Driver::mode_(int m, const int *a) {
 }
 
 
+void Fl_Wayland_Gl_Window_Driver::surface_frame_done(void *data, struct wl_callback *cb, uint32_t time) {
+  Fl_Wayland_Gl_Window_Driver *gl_dr = (Fl_Wayland_Gl_Window_Driver *)data;
+  wl_callback_destroy(cb);
+  struct wld_window *window = fl_wl_xid(gl_dr->pWindow);
+  window->frame_cb = NULL;
+  if (gl_dr->need_swap) {
+    eglSwapBuffers(Fl_Wayland_Gl_Window_Driver::egl_display, gl_dr->egl_surface);
+    gl_dr->need_swap = false;
+  }
+}
+
+
+static const struct wl_callback_listener surface_frame_listener = {
+  .done = Fl_Wayland_Gl_Window_Driver::surface_frame_done,
+};
+
+
 void Fl_Wayland_Gl_Window_Driver::swap_buffers() {
   if (overlay()) {
     static bool overlay_buffer = true;
@@ -333,14 +351,21 @@ void Fl_Wayland_Gl_Window_Driver::swap_buffers() {
   }
 
   if (egl_surface) {
-    if (pWindow->parent()) { // issue #967
+    Fl_Window *parent = pWindow->parent() ? pWindow->window() : NULL;
+    struct wld_window *parent_xid = parent ? fl_wl_xid(parent) : NULL;
+    if (parent_xid) { // issue #967
       struct wld_window *xid = fl_wl_xid(pWindow);
-      if (xid->frame_cb) return;
-      xid->frame_cb = wl_surface_frame(xid->wl_surface);
-      wl_callback_add_listener(xid->frame_cb, Fl_Wayland_Graphics_Driver::p_surface_frame_listener,
-                               xid);
+      if (xid->frame_cb) {
+        need_swap = true;
+        return;
+      }
+      if (!parent_xid->frame_cb) {
+        xid->frame_cb = wl_surface_frame(xid->wl_surface);
+        wl_callback_add_listener(xid->frame_cb, &surface_frame_listener, this);
+      }
     }
     eglSwapBuffers(Fl_Wayland_Gl_Window_Driver::egl_display, egl_surface);
+    need_swap = false;
   }
 }
 
@@ -405,13 +430,6 @@ void Fl_Wayland_Gl_Window_Driver::resize(int is_a_resize, int W, int H) {
   }*/
 }
 
-void Fl_Wayland_Gl_Window_Driver::after_resize() {
-  Fl_Window *parent = (pWindow->parent() ? pWindow->window() : NULL);
-  struct wld_window *xid = (parent ? fl_wl_xid(parent) : NULL);
-  if (xid && !xid->frame_cb) {
-    eglSwapBuffers(Fl_Wayland_Gl_Window_Driver::egl_display, egl_surface);
-  }
-}
 
 char Fl_Wayland_Gl_Window_Driver::swap_type() {
   return copy;
diff --git src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx
index 0b6b357..044997b 100644
--- src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx
+++ src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx
@@ -1911,6 +1911,7 @@ void Fl_Wayland_Window_Driver::resize(int X, int Y, int W, int H) {
       if (fl_win->subsurface) wl_subsurface_set_position(fl_win->subsurface, X * f, Y * f);
       if (!parent_xid->buffer->wl_buffer || parent_xid->buffer->draw_buffer_needs_commit) {
         if (!parent_xid->frame_cb) Fl_Wayland_Graphics_Driver::buffer_commit(parent_xid);
+        else wl_surface_commit(parent_xid->wl_surface);
       } else {
         if (!parent_xid->frame_cb) {
           // Use the frame callback mechanism applied to the object's parent window
[ Direct Link to Message ]
 
     
[ Previous Message ] [ Next Message ]
 
 

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