c++gtkgtkmm4

How to replace deprecated GTK3 call - Gdk::Window::process_updates() in GTK4 - so that cursor change is reflected


In GTKMM 3 I used to use Gdk::Window::process_updates() after I had set a cursor for the window so that the change to the cursor was reflected immediately and not when the event handler completes. As the above is now deprecated and I am using GTKMM 4.10 how do I perform the equivalent ? At the moment when I set a wait cursor in an event handler it does not change until the handler completes. I know that my cursor change code works as I have set the cursor to something other than the default at the end of the handler and when the handler completes it has changed as required.

The following code fragment hopefully provides further explanation. The first step is to create a wait cursor, then the '...' is the handler code, then I change the cursor back to the default one. The problem is that the cursor does not change to a wait cursor and then run the handler code as the Gdk::Window::process_updates() does not exist in GTK4.

auto wait_cursor = Gdk::Cursor::create("wait");
assert(wait_cursor);

window->set_cursor(wait_cursor);

...
...
...

window->set_cursor();

I tried using X11 calls such as XFlush() to flush the display but this did not solve the problem.

I looked for means of invalidating the display and hopefully forcing an update but this did not lead to anything.


Solution

  • To ensure that all updates for the window are processed you need to access the display for the window and then invoke the sync() member. So if you place the following code after each set_cursor() call, the cursor will be updated to reflect the change that you require:

    //
    //Now we need to fetch the display associated with the window and then
    //ensure that it is valid.
    //
    auto display = window->get_display();
    assert(display);
    
    //
    //Now we need to ensure that the display is synchronised and thus the
    //display has processed all updates.
    //
    display->sync();