diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 530d4c3785..e74c53125d 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -1172,19 +1172,20 @@ BView::GetMouse(BPoint *location, uint32 *buttons, bool checkMessageQueue) { do_owner_check(); - // ToDo: We should check if we are calling this from the BWindow's thread or not. - // But why exactly do we have to do this? If the looper is locked, it - // shouldn't do too much harm, besides, who would do this, anyway :) -- axeld. - if (checkMessageQueue) { - BMessageQueue *queue = Window()->MessageQueue(); - BMessage *msg; + if (find_thread(NULL) == Window()->Thread()) { + // If the event loop is not running right now (we're blocking it), + // we need to retrieve all messages that are pending on the port. + Window()->DequeueAll(); + } + BMessageQueue *queue = Window()->MessageQueue(); queue->Lock(); // First process and remove all _UPDATE_ messages // ToDo: it would be great to join them together to one big update message! + BMessage *msg; for (int32 i = 0; (msg = queue->FindMessage(i)) != NULL; ) { if (msg->what == _UPDATE_) { Window()->BWindow::DispatchMessage(msg, Window()); diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index c5b7435407..51f380fa13 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -2316,7 +2316,23 @@ void BWindow::InitData( BRect frame, const char* title, window_look look, BuildTopView(); } -//------------------------------------------------------------------------------ + +/** Reads all pending messages from the window port and put them into the queue. + */ + +void +BWindow::DequeueAll() +{ + // Get message count from port + int32 count = port_count(fMsgPort); + + for (int32 i = 0; i < count; i++) { + BMessage *message = MessageFromPort(0); + if (message != NULL) + fQueue->AddMessage(message); + } +} + // TODO: This here is a nearly full code duplication to BLooper::task_loop // but with one little difference: It uses the determine_target function