c++cursorfltk

Changing the cursor of a FLTK window


I am trying to change the cursor inside a FLTK window: the following code

#include "FL/Fl.H"
#include "FL/Fl_Double_Window.H"

Fl_Cursor CUR_DEF = FL_CURSOR_HAND;

int main(){
    Fl_Double_Window* W = new Fl_Double_Window(200,200,"test");
    W -> cursor(CUR_DEF);
    W -> show();
    return Fl::run();
}

does not work, and it does not work even using default_cursor(CUR_DEF). But as soon as I move W -> cursor(CUR_DEF); after W -> show(), the hand cursor appears if I firstly move the cursor on the window's title bar (in this case, "test") or if I firstly move the window across the screen. Why the right cursor is not appearing when the program is launched?

Moreover, when the cursor leaves the window and enter again, the cursor returns to be the system one, and becomes the "hand" only if it passes over the title bar.

I am using FLTK 1.3.5, clang version 14.0.0, on a MacBook pro.


Solution

  • FLTK 1.3.5 is more than 5 years old (March 2019), you should really use a newer version. Current stable release is 1.3.9, and 1.4.0 is the development version (git only).

    In FLTK 1.4.0 it is documented behavior that "the window must be show()'n for this function to have any effect". This answers the main part of your question. Unfortunately this bit of information is missing in the 1.3 documentation but it applies to this version as well.

    I tested your program after moving the cursor assignment below the show() statement, using FLTK 1.3 (release 1.3.9 and git branch-1.3) and FLTK 1.4.0 (git master) and I can confirm your report only partially. In my test on macOS I found that the cursor is assigned immediately when the pointer enters the window from any side (left, right, bottom) except from the top (crossing the title bar). I did NOT test FLTK 1.3.5.

    I'm going to open a bug report (GitHub Issue) for FLTK 1.4.0. Note that there are similar issues on the new Wayland platform (1.4 only). I'll let you and others know the issue number and a link shortly. I will also post a slightly modified version of your test program to the issue.

    Side note: you should also change the #include statements to use <...> rather than double quotes (the exact reason why this is useful would be OT here).