[haiku-3rdparty-dev] Re: Dispatch messages

  • From: Zenja Solaja <solaja@xxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Sun, 13 Nov 2022 22:56:42 +0100

Hi Carlo.

I understand your issue, and wont bother discussing the merrits of
blocking. The easy way is to use the B_MODAL_WINDOW creation flag. See
BAlert source as an example.

A harder way is to override the BWindow (derived from BHandler)
MessageReceived function. While the modal window is open, trap messages
(also dont forward to base class BWindow::MessageReceived). You may
encounter a world of hurt with FrameResized, QuitRequested and friends.

Alternatively, from the BLooper eliminate pending messages from the queue.
I’ve seen input handlers filter messages (see input handler filters). The
BeAPI actually allows you to filter messages to handlers.


The Window creation flag gets you to where you want to be.   Its a hack
since BeOS apps should have multithreaded windows, however its better to
have a app vs no app.



On Sun, 13 Nov 2022 at 21:17, Carlo Lanzotti <clanzotti@xxxxxxxxxxxxx>
wrote:

Hi all,

I’m the developer of a multiplatform system/GUI toolkit. I’ve ported my
engine to haiku years ago, but now I’m facing a problem that maybe some of
you can help me figure out how to solve it.

The system rely only on one OS main window that simply intercepts events
and send it to my own event handler.

In my system I’ve implemented a way to run modal windows that can be
called and block until a return value is returned, e.g.:

Int val = run_modal_window();

(waiting for the function to return, like when the user clicked an Ok
button or something)

When the function get called I start running a local loop that will block
the function from returning and inside this loop I call the OS’s specific
message dispatching allowing the OS to continue handling events for it’s
window and send them to my event handler (and avoid ui lock). For example,
in Windows I use the usual way to do it:

    while(PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
    {
        if(GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

As well as on the other OS (Linux, iOS, macOS etc… with their counterpart).

The problem is that in Haiku I can’t find a way to do the same due to the
different (and multi threaded) way things are done, or at least I didn’t
find something that satisfy my need. Is there a way to tell the system to
continue intercept/send events to a windows/view (app?) like things are
done in other OSs?

Thanks in advance.

P.S. I already sent this mail to the haiku developer list due to a mistake
caused by the corrector, sorry.

Best Regards,

Carlo Lanzotti


Other related posts: