On Mon, 8 Dec 2025 22:03:07 +0100 ichthyo <[email protected]> wrote:WidgetPDial.cpp, line 195 cairo_surface_t* Xsurface = cairo_xlib_surface_create (fl_display, fl_window, fl_visual->visual, Fl_Window::current()->w() * scale, Fl_Window::current()->h() * scale); This *can* not work under Wayland.
On 09/12/2025 15:05, ichthyo wrote:
Cairo is in widespread use in modern UI toolkits, and thus we can assume that it has adopted support for Wayland since a long time. We just have to figure out (for the yoshimi project) how to achieve that step. A quick internet search I did yesterday turned up the following: https://jan.newmarch.name/Wayland/Cairo/ A good introduction into Cairo concepts and usage is here https://www.cairographics.org/tutorial/ But what we need to research and figure out now is the question: "how is that achieved properly *under FLTK*"....
Hi Yoshimi-devs, while I hadn't time to look into any details, I poked around a bit more yesterday, and found some further possible starting points First, as we all know, "Internet Search" is no longer what it used to be, in the good old days. It is now optimised for "ordinary people" and on top of that comes that there are far less blogs and hompages "out there" with quality content. To some degree, the AI bots compensate for that sad situation. Personally, I often use the "Stackoverflow AI", since that bot formost links to Stackoverflow content. https://stackoverflow.ai/ I have asked the Bot, but it just proposes the workaround we have figured out ourselves, which is to render a bitmap with Cairo. Notably the bot did not find any Stackoverflow post for this topic. Here is the Code proposed by the Bot: // inside draw() int w = Fl_Window::current()->w() * scale; int h = Fl_Window::current()->h() * scale; if (getenv("WAYLAND_DISPLAY") == nullptr) { // X11 path cairo_surface_t* surf = cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, w, h); cairo_t* cr = cairo_create(surf); // ... your Cairo drawing here ... cairo_destroy(cr); cairo_surface_destroy(surf); } else { // Wayland / fallback: draw to image surface then blit cairo_surface_t* surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); cairo_t* cr = cairo_create(surf); // ... your Cairo drawing here ... unsigned char* data = cairo_image_surface_get_data(surf); int stride = cairo_image_surface_get_stride(surf); cairo_surface_flush(surf); // Present to FLTK: create an Fl_RGB_Image (expects interleaved bytes) // Note: FLTK may expect premultiplied alpha / byte ordering — you might // need to convert ARGB32 to the pixel format FLTK expects. Fl_RGB_Image img((const unsigned char*)data, w, h, 4, /*copy=*/1); img.draw(0, 0, w/scale, h/scale); cairo_destroy(cr); cairo_surface_destroy(surf); } So that might be a plan B, but is not satisfactory, from an engineering POV. For that reason, I also opened a Stackoverflow Question: https://stackoverflow.com/questions/79844438/fltk-custom-widget-with-cairo-under-wayland Let's see if someone has already encountered a similar problem... Furthermore, I have looked into the FLTK source code a bit. FLTK is obviously using Cairo itself. The FL_Dial just draws with the internal drawing functions (do those delegate to Cairo?). But there is a class Fl_Cairo_Window, which overloads the draw() function to provide a ready-made cairo context. As said, I didn't have the time to look in more detail, but this might be a lead, since this seems to provide that context / surface which is used by FLTK itself. https://github.com/fltk/fltk/blob/branch-1.4/FL/Fl_Cairo_Window.H#L99 After digging around through some further forum posts, I came across the following documentation link (which that damn search engines did not turn out!!) https://www.fltk.org/doc-1.4/wayland-devel.html This seems to be a comprehensive introduction to the topic Wayland in FLTK, and it mentions Cairo. -- Hermann _______________________________________________ Yoshimi-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/yoshimi-devel
