diff --git a/src/servers/app/Layer.cpp b/src/servers/app/Layer.cpp index b1df80bbb0..2ef8b0ebf8 100644 --- a/src/servers/app/Layer.cpp +++ b/src/servers/app/Layer.cpp @@ -1111,98 +1111,74 @@ Layer::ScrollBy(float x, float y) } void -Layer::MouseDown(const PointerEvent& evt) +Layer::MouseDown(const BMessage *msg) { if (Window() && !IsTopLayer()) { - BMessage msg; - msg.what = B_MOUSE_DOWN; - msg.AddInt64("when", evt.when); - msg.AddPoint("where", evt.where); - msg.AddInt32("modifiers", evt.modifiers); - msg.AddInt32("buttons", evt.buttons); - msg.AddInt32("clicks", evt.clicks); - - Window()->SendMessageToClient(&msg, fViewToken, false); + Window()->SendMessageToClient(msg, fViewToken, false); } } void -Layer::MouseUp(const PointerEvent& evt) +Layer::MouseUp(const BMessage *msg) { if (Window() && !IsTopLayer()) { - BMessage upmsg(B_MOUSE_UP); - upmsg.AddInt64("when",evt.when); - upmsg.AddPoint("where",evt.where); - upmsg.AddInt32("modifiers",evt.modifiers); - - Window()->SendMessageToClient(&upmsg, fViewToken, false); + Window()->SendMessageToClient(msg, fViewToken, false); } } void -Layer::MouseMoved(const PointerEvent& evt, uint32 transit) +Layer::MouseMoved(const BMessage *msg) { if (Window() && !IsTopLayer()) { - BMessage movemsg(B_MOUSE_MOVED); - movemsg.AddInt64("when", evt.when); - movemsg.AddPoint("where", evt.where); - movemsg.AddInt32("buttons", evt.buttons); - movemsg.AddInt32("transit", transit); - - Window()->SendMessageToClient(&movemsg, fViewToken, false); + Window()->SendMessageToClient(msg, fViewToken, false); } } void -Layer::MouseWheelChanged(const PointerEvent& evt) +Layer::MouseWheelChanged(const BMessage *msg) { if (Window() && !IsTopLayer()) { - BMessage wheelmsg(B_MOUSE_WHEEL_CHANGED); - wheelmsg.AddInt64("when", evt.when); - wheelmsg.AddFloat("be:wheel_delta_x",evt.wheel_delta_x); - wheelmsg.AddFloat("be:wheel_delta_y",evt.wheel_delta_y); - - Window()->SendMessageToClient(&wheelmsg, fViewToken, false); + Window()->SendMessageToClient(msg, fViewToken, false); } } void -Layer::KeyDown(const BMessage& msg) +Layer::KeyDown(const BMessage *msg) { if (Window() && !IsTopLayer()) { - Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); + Window()->SendMessageToClient(msg, B_NULL_TOKEN, true); } } void -Layer::KeyUp(const BMessage& msg) +Layer::KeyUp(const BMessage *msg) { if (Window() && !IsTopLayer()) { - Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); + Window()->SendMessageToClient(msg, B_NULL_TOKEN, true); } } void -Layer::UnmappedKeyDown(const BMessage& msg) +Layer::UnmappedKeyDown(const BMessage *msg) { if (Window() && !IsTopLayer()) { - Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); + Window()->SendMessageToClient(msg, B_NULL_TOKEN, true); } } void -Layer::UnmappedKeyUp(const BMessage& msg) +Layer::UnmappedKeyUp(const BMessage *msg) { if (Window() && !IsTopLayer()) { - Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); + Window()->SendMessageToClient(msg, B_NULL_TOKEN, true); } } void -Layer::ModifiersChanged(const BMessage& msg) +Layer::ModifiersChanged(const BMessage *msg) { if (Window() && !IsTopLayer()) { - Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); + Window()->SendMessageToClient(msg, B_NULL_TOKEN, true); } } diff --git a/src/servers/app/Layer.h b/src/servers/app/Layer.h index 10f29f38de..6c0fc7e078 100644 --- a/src/servers/app/Layer.h +++ b/src/servers/app/Layer.h @@ -158,16 +158,16 @@ class Layer { virtual void ResizeBy(float x, float y); virtual void ScrollBy(float x, float y); - virtual void MouseDown(const PointerEvent& evt); - virtual void MouseUp(const PointerEvent& evt); - virtual void MouseMoved(const PointerEvent& evt, uint32 transit); - virtual void MouseWheelChanged(const PointerEvent& evt); + virtual void MouseDown(const BMessage *msg); + virtual void MouseUp(const BMessage *msg); + virtual void MouseMoved(const BMessage *msg); + virtual void MouseWheelChanged(const BMessage *msg); - virtual void KeyDown(const BMessage& msg); - virtual void KeyUp(const BMessage& msg); - virtual void UnmappedKeyDown(const BMessage& msg); - virtual void UnmappedKeyUp(const BMessage& msg); - virtual void ModifiersChanged(const BMessage& msg); + virtual void KeyDown(const BMessage *msg); + virtual void KeyUp(const BMessage *msg); + virtual void UnmappedKeyDown(const BMessage *msg); + virtual void UnmappedKeyUp(const BMessage *msg); + virtual void ModifiersChanged(const BMessage *msg); virtual void WorkspaceActivated(int32 index, bool active); virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); diff --git a/src/servers/app/RootLayer.cpp b/src/servers/app/RootLayer.cpp index 72127483fe..20127fcea9 100644 --- a/src/servers/app/RootLayer.cpp +++ b/src/servers/app/RootLayer.cpp @@ -159,10 +159,12 @@ RootLayer::~RootLayer() { fQuiting = true; - BPrivate::PortLink msg(fListenPort, -1); - msg.StartMessage(B_QUIT_REQUESTED); - msg.EndMessage(); - msg.Flush(); +// BMessage quitMsg(B_QUIT_REQUESTED); + +// BPrivate::PortLink msg(fListenPort, -1); +// msg.StartMessage(B_QUIT_REQUESTED); +// msg.EndMessage(); +// msg.Flush(); status_t dummy; wait_for_thread(fThreadID, &dummy); @@ -198,10 +200,7 @@ RootLayer::RunThread() int32 RootLayer::WorkingThread(void *data) { - int32 code = 0; - status_t err = B_OK; RootLayer *oneRootLayer = (RootLayer*)data; - BPrivate::PortLink messageQueue(-1, oneRootLayer->fListenPort); // first make sure we are actualy visible oneRootLayer->Lock(); @@ -220,48 +219,69 @@ RootLayer::WorkingThread(void *data) oneRootLayer->Unlock(); STRACE(("info: RootLayer(%s)::WorkingThread listening on port %ld.\n", oneRootLayer->Name(), oneRootLayer->fListenPort)); - for (;;) { - err = messageQueue.GetNextMessage(code); - if (err < B_OK) { - STRACE(("WorkingThread: messageQueue.GetNextMessage() failed: %s\n", strerror(err))); - continue; + while(!oneRootLayer->fQuiting) { + + BMessage *msg = oneRootLayer->ReadMessageFromPort(B_INFINITE_TIMEOUT); + + if (msg) + oneRootLayer->fQueue.AddMessage(msg); + + int32 msgCount = port_count(oneRootLayer->fListenPort); + for (int32 i = 0; i < msgCount; ++i) { + msg = oneRootLayer->ReadMessageFromPort(0); + if (msg) + oneRootLayer->fQueue.AddMessage(msg); } - oneRootLayer->Lock(); + // loop as long as there are messages in the queue and the port is empty. + bool dispatchNextMessage = true; + while(dispatchNextMessage && !oneRootLayer->fQuiting) { + BMessage *currentMessage = oneRootLayer->fQueue.NextMessage(); + + if (!currentMessage) + // no more messages + dispatchNextMessage = false; + else { - switch (code) { - // We don't need to do anything with these two, so just pass them - // onto the active application. Eventually, we will end up passing - // them onto the window which is currently under the cursor. - case B_MOUSE_DOWN: - case B_MOUSE_UP: - case B_MOUSE_MOVED: - case B_MOUSE_WHEEL_CHANGED: - oneRootLayer->MouseEventHandler(code, messageQueue); - break; + oneRootLayer->Lock(); - case B_KEY_DOWN: - case B_KEY_UP: - case B_UNMAPPED_KEY_DOWN: - case B_UNMAPPED_KEY_UP: - case B_MODIFIERS_CHANGED: - oneRootLayer->KeyboardEventHandler(code, messageQueue); - break; + switch (currentMessage->what) { + // We don't need to do anything with these two, so just pass them + // onto the active application. Eventually, we will end up passing + // them onto the window which is currently under the cursor. + case B_MOUSE_DOWN: + case B_MOUSE_UP: + case B_MOUSE_MOVED: + case B_MOUSE_WHEEL_CHANGED: + oneRootLayer->MouseEventHandler(currentMessage); + break; - case B_QUIT_REQUESTED: - exit_thread(0); - break; + case B_KEY_DOWN: + case B_KEY_UP: + case B_UNMAPPED_KEY_DOWN: + case B_UNMAPPED_KEY_UP: + case B_MODIFIERS_CHANGED: + oneRootLayer->KeyboardEventHandler(currentMessage); + break; - default: - printf("RootLayer(%s)::WorkingThread received unexpected code %lx\n", oneRootLayer->Name(), code); - break; + case B_QUIT_REQUESTED: + exit_thread(0); + break; + + default: + printf("RootLayer(%s)::WorkingThread received unexpected code %lx\n", oneRootLayer->Name(), msg->what); + break; + } + + oneRootLayer->Unlock(); + + delete currentMessage; + + // Are any messages on the port? + if (port_count(oneRootLayer->fListenPort) > 0) + dispatchNextMessage = false; + } } - - oneRootLayer->Unlock(); - - // if we still have other messages in our queue, but we really want to quit - if (oneRootLayer->fQuiting) - break; } return 0; } @@ -937,9 +957,12 @@ RootLayer::SetActive(WinBorder* newActive) // Input related methods //--------------------------------------------------------------------------- void -RootLayer::_ProcessMouseMovedEvent(PointerEvent &evt) +RootLayer::_ProcessMouseMovedEvent(BMessage *msg) { - Layer* target = LayerAt(evt.where); + BPoint where(0,0); + msg->FindPoint("where", &where); + + Layer* target = LayerAt(where); if (target == NULL) { CRITICAL("RootLayer::_ProcessMouseMovedEvent() 'target' can't be null.\n"); return; @@ -984,7 +1007,8 @@ RootLayer::_ProcessMouseMovedEvent(PointerEvent &evt) else viewAction = B_OUTSIDE_VIEW; - lay->MouseMoved(evt, viewAction); + msg->AddInt32("transit", viewAction); + lay->MouseMoved(msg); } } @@ -992,45 +1016,45 @@ RootLayer::_ProcessMouseMovedEvent(PointerEvent &evt) fMouseNotificationList.RemoveItem(target); fLastLayerUnderMouse = target; - fLastMousePosition = evt.where; + fLastMousePosition = where; } void -RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg) +RootLayer::MouseEventHandler(BMessage *msg) { - switch (code) { + switch (msg->what) { case B_MOUSE_DOWN: { //printf("RootLayer::MouseEventHandler(B_MOUSE_DOWN)\n"); - // Attached data: - // 1) int64 - time of mouse click - // 2) float - x coordinate of mouse click - // 3) float - y coordinate of mouse click - // 4) int32 - modifier keys down - // 5) int32 - buttons down - // 6) int32 - clicks - PointerEvent evt; - evt.code = B_MOUSE_DOWN; - msg.Read(&evt.when); - msg.Read(&evt.where.x); - msg.Read(&evt.where.y); - msg.Read(&evt.modifiers); - msg.Read(&evt.buttons); - msg.Read(&evt.clicks); + BPoint where(0,0); - evt.where.ConstrainTo(fFrame); + msg->FindPoint("where", &where); + // We'll need this so that GetMouse can query for which buttons are down. + msg->FindInt32("buttons", &fButtons); - if (fLastMousePosition != evt.where) { + where.ConstrainTo(Frame()); + + if (fLastMousePosition != where) { // move cursor on screen - GetHWInterface()->MoveCursorTo(evt.where.x, evt.where.y); + GetHWInterface()->MoveCursorTo(where.x, where.y); - _ProcessMouseMovedEvent(evt); + // If this happens, it's input server's fault. + // There might be additional fields an application expects in B_MOUSE_MOVED + // message, and in this way it won't get them. + int64 when = 0; + int32 buttons = 0; + + msg->FindInt64("when", &when); + msg->FindInt32("buttons", &buttons); + + BMessage mouseMovedMsg(B_MOUSE_MOVED); + mouseMovedMsg.AddInt64("when", when); + mouseMovedMsg.AddInt32("buttons", buttons); + mouseMovedMsg.AddPoint("where", where); + + _ProcessMouseMovedEvent(msg); } - // We'll need this so that GetMouse can query for which buttons - // are down. - fButtons = evt.buttons; - if (fLastLayerUnderMouse == NULL) { CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_DOWN) fLastLayerUnderMouse is null!\n"); break; @@ -1046,37 +1070,43 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg) if (lay) // NOTE: testing under R5 shows that it doesn't matter if a window is created // with B_ASYNCHRONOUS_CONTROLS flag or not. B_MOUSE_DOWN is always transmited. - lay->MouseDown(evt); + lay->MouseDown(msg); } // get the pointer for one of the first RootLayer's descendants - Layer *primaryTarget = LayerAt(evt.where, false); - primaryTarget->MouseDown(evt); + Layer *primaryTarget = LayerAt(where, false); + primaryTarget->MouseDown(msg); break; } case B_MOUSE_UP: { //printf("RootLayer::MouseEventHandler(B_MOUSE_UP)\n"); - // Attached data: - // 1) int64 - time of mouse click - // 2) float - x coordinate of mouse click - // 3) float - y coordinate of mouse click - // 4) int32 - modifier keys down - PointerEvent evt; - evt.code = B_MOUSE_UP; - msg.Read(&evt.when); - msg.Read(&evt.where.x); - msg.Read(&evt.where.y); - msg.Read(&evt.modifiers); + BPoint where(0,0); - evt.where.ConstrainTo(fFrame); + msg->FindPoint("where", &where); - if (fLastMousePosition != evt.where) { + where.ConstrainTo(fFrame); + + if (fLastMousePosition != where) { // move cursor on screen - GetHWInterface()->MoveCursorTo(evt.where.x, evt.where.y); + GetHWInterface()->MoveCursorTo(where.x, where.y); - _ProcessMouseMovedEvent(evt); + // If this happens, it's input server's fault. + // There might be additional fields an application expects in B_MOUSE_MOVED + // message, and in this way it won't get them. + int64 when = 0; + int32 buttons = 0; + + msg->FindInt64("when", &when); + msg->FindInt32("buttons", &buttons); + + BMessage mouseMovedMsg(B_MOUSE_MOVED); + mouseMovedMsg.AddInt64("when", when); + mouseMovedMsg.AddInt32("buttons", buttons); + mouseMovedMsg.AddPoint("where", where); + + _ProcessMouseMovedEvent(msg); } if (fLastLayerUnderMouse == NULL) { @@ -1090,12 +1120,12 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg) for (int32 i = 0; i <= count; i++) { lay = static_cast(fMouseNotificationList.ItemAt(i)); if (lay) - lay->MouseUp(evt); + lay->MouseUp(msg); } ClearNotifyLayer(); if (!foundCurrent) - fLastLayerUnderMouse->MouseUp(evt); + fLastLayerUnderMouse->MouseUp(msg); // TODO: This is a quick fix to avoid the endless loop with windows created // with the B_ASYNCHRONOUS_CONTROLS flag, but please someone have a look into this. @@ -1110,19 +1140,16 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg) // 2) float - x coordinate of mouse click // 3) float - y coordinate of mouse click // 4) int32 - buttons down - - PointerEvent evt; - evt.code = B_MOUSE_MOVED; - msg.Read(&evt.when); - msg.Read(&evt.where.x); - msg.Read(&evt.where.y); - msg.Read(&evt.buttons); - evt.where.ConstrainTo(fFrame); + BPoint where(0,0); + + msg->FindPoint("where", &where); + + where.ConstrainTo(fFrame); // move cursor on screen - GetHWInterface()->MoveCursorTo(evt.where.x, evt.where.y); + GetHWInterface()->MoveCursorTo(where.x, where.y); - _ProcessMouseMovedEvent(evt); + _ProcessMouseMovedEvent(msg); break; } @@ -1132,18 +1159,12 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg) // under the cursor. It's pretty stupid to send it to the active window unless a particular // view has locked focus via SetMouseEventMask - PointerEvent evt; - evt.code = B_MOUSE_WHEEL_CHANGED; - msg.Read(&evt.when); - msg.Read(&evt.wheel_delta_x); - msg.Read(&evt.wheel_delta_y); - if (fLastLayerUnderMouse == NULL) { CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_DOWN) fLastLayerUnderMouse is null!\n"); break; } - fLastLayerUnderMouse->MouseWheelChanged(evt); + fLastLayerUnderMouse->MouseWheelChanged(msg); break; } default: @@ -1156,39 +1177,16 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg) void -RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) +RootLayer::KeyboardEventHandler(BMessage *msg) { - switch (code) { + switch (msg->what) { case B_KEY_DOWN: { - // Attached Data: - // 1) int64 bigtime_t object of when the message was sent - // 2) int32 raw key code (scancode) - // 3) int32 modifier-independent ASCII code for the character - // 4) int32 repeat count - // 5) int32 modifiers - // 6) int8[3] UTF-8 data generated - // 7) Character string generated by the keystroke - // 8) int8[16] state of all keys - - bigtime_t time; - int32 scancode, modifiers; - int8 utf[3] = { 0, 0, 0 }; - char *string = NULL; - int8 keystates[16]; - int32 raw_char; - int32 repeatcount; - - msg.Read(&time); - msg.Read(&scancode); - msg.Read(&raw_char); - msg.Read(&repeatcount); - msg.Read(&modifiers); - msg.Read(utf, sizeof(utf)); - msg.ReadString(&string); - msg.Read(keystates, sizeof(keystates)); - - STRACE(("Key Down: 0x%lx\n",scancode)); + int32 scancode = 0; + int32 modifiers = 0; + + msg->FindInt32("key", &scancode); + msg->FindInt32("modifiers", &modifiers); // F1-F12 if (scancode > 0x01 && scancode < 0x0e) { @@ -1203,7 +1201,6 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) { // TODO: Set to Safe Mode in KeyboardEventHandler:B_KEY_DOWN. (DisplayDriver API change) STRACE(("Safe Video Mode invoked - code unimplemented\n")); - free(string); break; } @@ -1224,7 +1221,6 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) fDriver->ConstrainClippingRegion(NULL); #endif #endif - free(string); break; } } @@ -1242,7 +1238,6 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) //{ // TODO: implement; printf("Send Twitcher message key to Deskbar - unimplmemented\n"); - free(string); break; //} } @@ -1267,7 +1262,6 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) GetDisplayDriver()->DumpToFile(filename); - free(string); break; } } @@ -1275,57 +1269,19 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) // We got this far, so apparently it's safe to pass to the active // window. - if (Focus()) { - BMessage keymsg(B_KEY_DOWN); - keymsg.AddInt64("when", time); - keymsg.AddInt32("key", scancode); + if (Focus()) + Focus()->KeyDown(msg); - if (repeatcount > 1) - keymsg.AddInt32("be:key_repeat", repeatcount); - - keymsg.AddInt32("modifiers", modifiers); - keymsg.AddData("states", B_UINT8_TYPE, keystates, sizeof(int8) * 16); - - for (uint8 i = 0; i < 3; i++) - keymsg.AddInt8("byte", utf[i]); - - keymsg.AddString("bytes", string); - keymsg.AddInt32("raw_char", raw_char); - - Focus()->KeyDown(keymsg); - } - - free(string); break; } case B_KEY_UP: { - // Attached Data: - // 1) int64 bigtime_t object of when the message was sent - // 2) int32 raw key code (scancode) - // 3) int32 modifier-independent ASCII code for the character - // 4) int32 modifiers - // 5) int8[3] UTF-8 data generated - // 6) Character string generated by the keystroke - // 7) int8[16] state of all keys - - bigtime_t time; - int32 scancode, modifiers; - int8 utf[3] = { 0, 0, 0 }; - char *string = NULL; - int8 keystates[16]; - int32 raw_char; - - msg.Read(&time); - msg.Read(&scancode); - msg.Read(&raw_char); - msg.Read(&modifiers); - msg.Read(utf, sizeof(utf)); - msg.ReadString(&string); - msg.Read(keystates, sizeof(keystates)); - - STRACE(("Key Up: 0x%lx\n", scancode)); + int32 scancode = 0; + int32 modifiers = 0; + + msg->FindInt32("key", &scancode); + msg->FindInt32("modifiers", &modifiers); #if !TEST_MODE // Tab key @@ -1353,114 +1309,30 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) // We got this far, so apparently it's safe to pass to the active // window. - if (Focus()) { - BMessage keymsg(B_KEY_UP); - keymsg.AddInt64("when", time); - keymsg.AddInt32("key", scancode); - keymsg.AddInt32("modifiers", modifiers); - keymsg.AddData("states", B_UINT8_TYPE, keystates, sizeof(int8) * 16); + if (Focus()) + Focus()->KeyUp(msg); - for (uint8 i = 0; i < 3; i++) - keymsg.AddInt8("byte", utf[i]); - - keymsg.AddString("bytes", string); - keymsg.AddInt32("raw_char", raw_char); - - Focus()->KeyUp(keymsg); - } - - free(string); break; } case B_UNMAPPED_KEY_DOWN: { - // Attached Data: - // 1) int64 bigtime_t object of when the message was sent - // 2) int32 raw key code (scancode) - // 3) int32 modifiers - // 4) int8 state of all keys - - bigtime_t time; - int32 scancode, modifiers; - int8 keystates[16]; - - msg.Read(&time); - msg.Read(&scancode); - msg.Read(&modifiers); - msg.Read(keystates,sizeof(int8)*16); - - STRACE(("Unmapped Key Down: 0x%lx\n",scancode)); - - if(Focus()) { - BMessage keymsg(B_UNMAPPED_KEY_DOWN); - keymsg.AddInt64("when", time); - keymsg.AddInt32("key", scancode); - keymsg.AddInt32("modifiers", modifiers); - keymsg.AddData("states", B_UINT8_TYPE, keystates, sizeof(int8) * 16); - - Focus()->UnmappedKeyDown(keymsg); - } + if(Focus()) + Focus()->UnmappedKeyDown(msg); break; } case B_UNMAPPED_KEY_UP: { - // Attached Data: - // 1) int64 bigtime_t object of when the message was sent - // 2) int32 raw key code (scancode) - // 3) int32 modifiers - // 4) int8 state of all keys - - bigtime_t time; - int32 scancode, modifiers; - int8 keystates[16]; - - msg.Read(&time); - msg.Read(&scancode); - msg.Read(&modifiers); - msg.Read(keystates,sizeof(int8)*16); - - STRACE(("Unmapped Key Up: 0x%lx\n",scancode)); - - if(Focus()) { - BMessage keymsg(B_UNMAPPED_KEY_UP); - keymsg.AddInt64("when", time); - keymsg.AddInt32("key", scancode); - keymsg.AddInt32("modifiers", modifiers); - keymsg.AddData("states", B_UINT8_TYPE, keystates, sizeof(int8) * 16); - - Focus()->UnmappedKeyUp(keymsg); - } + if(Focus()) + Focus()->UnmappedKeyUp(msg); break; } case B_MODIFIERS_CHANGED: { - // Attached Data: - // 1) int64 bigtime_t object of when the message was sent - // 2) int32 modifiers - // 3) int32 old modifiers - // 4) int8 state of all keys - - bigtime_t time; - int32 modifiers,oldmodifiers; - int8 keystates[16]; - - msg.Read(&time); - msg.Read(&modifiers); - msg.Read(&oldmodifiers); - msg.Read(keystates,sizeof(int8)*16); - - if(Focus()) { - BMessage keymsg(B_MODIFIERS_CHANGED); - keymsg.AddInt64("when", time); - keymsg.AddInt32("modifiers", modifiers); - keymsg.AddInt32("be:old_modifiers", oldmodifiers); - keymsg.AddData("states", B_UINT8_TYPE, keystates, sizeof(int8) * 16); - - Focus()->ModifiersChanged(keymsg); - } + if(Focus()) + Focus()->ModifiersChanged(msg); break; } @@ -1828,6 +1700,8 @@ RootLayer::ConvertToMessage(void* raw, int32 code) if (raw != NULL) { if (bmsg->Unflatten((const char*)raw) != B_OK) { + printf("Convert To BMessage FAILED. port message code was: %ld - %c%c%c%c", + code, (int8)(code >> 24), (int8)(code >> 16), (int8)(code >> 8), (int8)code ); delete bmsg; bmsg = NULL; } diff --git a/src/servers/app/RootLayer.h b/src/servers/app/RootLayer.h index 093ed47161..92ad894e4b 100644 --- a/src/servers/app/RootLayer.h +++ b/src/servers/app/RootLayer.h @@ -31,6 +31,7 @@ #include #include +#include #include "DebugInfoManager.h" #include "Desktop.h" @@ -161,10 +162,10 @@ friend class WinBorder; // temporarily, I need invalidate_layer() void empty_visible_regions(Layer *layer); #endif // Input related methods - void MouseEventHandler(int32 code, BPrivate::PortLink& link); - void KeyboardEventHandler(int32 code, BPrivate::PortLink& link); + void MouseEventHandler(BMessage *msg); + void KeyboardEventHandler(BMessage *msg); - void _ProcessMouseMovedEvent(PointerEvent &evt); + void _ProcessMouseMovedEvent(BMessage *msg); inline HWInterface* GetHWInterface() const { return fDesktop->GetHWInterface(); } @@ -187,6 +188,7 @@ friend class WinBorder; // temporarily, I need invalidate_layer() thread_id fThreadID; port_id fListenPort; + BMessageQueue fQueue; int32 fButtons; BPoint fLastMousePosition; diff --git a/src/servers/app/WinBorder.cpp b/src/servers/app/WinBorder.cpp index 33bc9fcf5c..7124c9dc02 100644 --- a/src/servers/app/WinBorder.cpp +++ b/src/servers/app/WinBorder.cpp @@ -74,7 +74,6 @@ WinBorder::WinBorder(const BRect &frame, fInUpdateRegion(), fMouseButtons(0), - fKeyModifiers(0), fLastMousePosition(-1.0, -1.0), fIsClosing(false), @@ -444,23 +443,26 @@ WinBorder::GetSizeLimits(float* minWidth, float* maxWidth, } void -WinBorder::MouseDown(const PointerEvent& evt) +WinBorder::MouseDown(const BMessage *msg) { DesktopSettings desktopSettings(gDesktop); + BPoint where(0,0); + + msg->FindPoint("where", &where); // not in FFM mode? if (desktopSettings.MouseMode() == B_NORMAL_MOUSE) { // default action is to drag the WinBorder click_type action = DEC_DRAG; - Layer *target = LayerAt(evt.where); + Layer *target = LayerAt(where); // clicking a simple Layer. if (target != this) { if (GetRootLayer()->ActiveWorkspace()->Active() == this) { - target->MouseDown(evt); + target->MouseDown(msg); } else { if (WindowFlags() & B_WILL_ACCEPT_FIRST_CLICK) - target->MouseDown(evt); + target->MouseDown(msg); else goto activateWindow; } @@ -470,7 +472,7 @@ WinBorder::MouseDown(const PointerEvent& evt) winBorderAreaHandle: if (fDecorator) - action = _ActionFor(evt); + action = _ActionFor(msg); // deactivate border buttons on first click(select) if (GetRootLayer()->Focus() != this && action != DEC_MOVETOBACK @@ -499,19 +501,19 @@ WinBorder::MouseDown(const PointerEvent& evt) case DEC_DRAG: fIsDragging = true; - fLastMousePosition = evt.where; + fLastMousePosition = where; STRACE_CLICK(("===> DEC_DRAG\n")); break; case DEC_RESIZE: fIsResizing = true; - fLastMousePosition = evt.where; + fLastMousePosition = where; STRACE_CLICK(("===> DEC_RESIZE\n")); break; case DEC_SLIDETAB: fIsSlidingTab = true; - fLastMousePosition = evt.where; + fLastMousePosition = where; STRACE_CLICK(("===> DEC_SLIDETAB\n")); break; @@ -538,10 +540,10 @@ WinBorder::MouseDown(const PointerEvent& evt) } // in FFM mode else { - Layer *target = LayerAt(evt.where); + Layer *target = LayerAt(where); // clicking a simple Layer; forward event. if (target != this) - target->MouseDown(evt); + target->MouseDown(msg); // clicking inside our visible area. else goto winBorderAreaHandle; @@ -549,11 +551,11 @@ WinBorder::MouseDown(const PointerEvent& evt) } void -WinBorder::MouseUp(const PointerEvent& event) +WinBorder::MouseUp(const BMessage *msg) { bool invalidate = false; if (fDecorator) { - click_type action = _ActionFor(event); + click_type action = _ActionFor(msg); // TODO: present behavior is not fine! // Decorator's Set*() methods _actualy draw_! on screen, not // taking into account if that region is visible or not! @@ -590,8 +592,12 @@ WinBorder::MouseUp(const PointerEvent& event) } void -WinBorder::MouseMoved(const PointerEvent& event, uint32 transit) +WinBorder::MouseMoved(const BMessage *msg) { + BPoint where(0,0); + + msg->FindPoint("where", &where); + if (fDecorator) { // TODO: present behavior is not fine! // Decorator's Set*() methods _actualy draw_! on screen, not @@ -599,16 +605,16 @@ WinBorder::MouseMoved(const PointerEvent& event, uint32 transit) // Decorator redraw code should follow the same path as Layer's // one! if (fIsZooming) { - fDecorator->SetZoom(_ActionFor(event) == DEC_ZOOM); + fDecorator->SetZoom(_ActionFor(msg) == DEC_ZOOM); } else if (fIsClosing) { - fDecorator->SetClose(_ActionFor(event) == DEC_CLOSE); + fDecorator->SetClose(_ActionFor(msg) == DEC_CLOSE); } else if (fIsMinimizing) { - fDecorator->SetMinimize(_ActionFor(event) == DEC_MINIMIZE); + fDecorator->SetMinimize(_ActionFor(msg) == DEC_MINIMIZE); } } if (fIsDragging) { - BPoint delta = event.where - fLastMousePosition; + BPoint delta = where - fLastMousePosition; #ifndef NEW_CLIPPING MoveBy(delta.x, delta.y); #else @@ -616,7 +622,7 @@ WinBorder::MouseMoved(const PointerEvent& event, uint32 transit) #endif } if (fIsResizing) { - BPoint delta = event.where - fLastMousePosition; + BPoint delta = where - fLastMousePosition; #ifndef NEW_CLIPPING ResizeBy(delta.x, delta.y); #else @@ -627,7 +633,7 @@ WinBorder::MouseMoved(const PointerEvent& event, uint32 transit) // TODO: implement } - fLastMousePosition = event.where; + fLastMousePosition = where; } void @@ -777,21 +783,29 @@ WinBorder::QuietlySetFeel(int32 feel) // _ActionFor click_type -WinBorder::_ActionFor(const PointerEvent& event) const +WinBorder::_ActionFor(const BMessage *msg) const { + BPoint where(0,0); + int32 buttons = 0; + int32 modifiers = 0; + + msg->FindPoint("where", &where); + msg->FindInt32("buttons", &buttons); + msg->FindInt32("modifiers", &modifiers); + #ifndef NEW_INPUT_HANDING #ifndef NEW_CLIPPING - if (fTopLayer->fFullVisible.Contains(event.where)) + if (fTopLayer->fFullVisible.Contains(where)) return DEC_NONE; else #else - if (fTopLayer->fFullVisible2.Contains(event.where)) + if (fTopLayer->fFullVisible2.Contains(where)) return DEC_NONE; else #endif #endif if (fDecorator) - return fDecorator->Clicked(event.where, event.buttons, event.modifiers); + return fDecorator->Clicked(where, buttons, modifiers); else return DEC_NONE; } diff --git a/src/servers/app/WinBorder.h b/src/servers/app/WinBorder.h index 0b74e89378..76494e9ae3 100644 --- a/src/servers/app/WinBorder.h +++ b/src/servers/app/WinBorder.h @@ -81,11 +81,13 @@ class WinBorder : public Layer { float* minHeight, float* maxHeight) const; - virtual void MouseDown(const PointerEvent& evt); - virtual void MouseUp(const PointerEvent& evt); - virtual void MouseMoved(const PointerEvent& evt, uint32 transit); - click_type ActionFor(const PointerEvent& evt) - { return _ActionFor(evt); } + virtual void MouseDown(const BMessage *msg); + virtual void MouseUp(const BMessage *msg); + virtual void MouseMoved(const BMessage *msg); + +// click_type ActionFor(const BMessage *msg) +// { return _ActionFor(evt); } + virtual void WorkspaceActivated(int32 index, bool active); virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); @@ -138,7 +140,7 @@ class WinBorder : public Layer { friend class Layer; friend class RootLayer; - click_type _ActionFor(const PointerEvent& evt) const; + click_type _ActionFor(const BMessage *msg) const; bool _ResizeBy(float x, float y); Decorator* fDecorator; @@ -148,7 +150,6 @@ class WinBorder : public Layer { BRegion fInUpdateRegion; int32 fMouseButtons; - int32 fKeyModifiers; BPoint fLastMousePosition; BPoint fResizingClickOffset; diff --git a/src/servers/app/drawing/ViewHWInterface.cpp b/src/servers/app/drawing/ViewHWInterface.cpp index 6a7aaee902..ae74523fcb 100644 --- a/src/servers/app/drawing/ViewHWInterface.cpp +++ b/src/servers/app/drawing/ViewHWInterface.cpp @@ -26,8 +26,6 @@ #include #include -#include "fake_input_server.h" - #include "BBitmapBuffer.h" #include "PortLink.h" #include "ServerConfig.h" @@ -123,14 +121,10 @@ class CardView : public BView { // CardView void SetBitmap(const BBitmap* bimtap); - inline BPrivate::PortLink* ServerLink() const - { return fServerLink; } - void ForwardMessage(); private: port_id fInputPort; - BPrivate::PortLink* fServerLink; const BBitmap* fBitmap; }; @@ -158,16 +152,12 @@ class CardWindow : public BWindow { CardView::CardView(BRect bounds) : BView(bounds, "graphics card view", B_FOLLOW_ALL, B_WILL_DRAW), - fServerLink(NULL), fBitmap(NULL) { SetViewColor(B_TRANSPARENT_32_BIT); #ifndef INPUTSERVER_TEST_MODE - // This link for sending mouse messages to the Haiku app_server. - // This is only to take the place of the input_server. - port_id input_port = find_port(SERVER_INPUT_PORT); - fServerLink = new BPrivate::PortLink(input_port); + fInputPort = find_port(SERVER_INPUT_PORT); #else fInputPort = create_port(100, "ViewInputDevice"); #endif @@ -176,7 +166,6 @@ CardView::CardView(BRect bounds) CardView::~CardView() { - delete fServerLink; } // AttachedToWindow @@ -216,12 +205,8 @@ void CardView::MouseDown(BPoint pt) { #ifdef ENABLE_INPUT_SERVER_EMULATION -#ifndef INPUTSERVER_TEST_MODE - send_mouse_down(fServerLink, pt, Window()->CurrentMessage()); -#else ForwardMessage(); #endif -#endif } // MouseMoved @@ -237,12 +222,8 @@ CardView::MouseMoved(BPoint pt, uint32 transit, const BMessage* dragMessage) SetViewCursor(&cursor, true); #ifdef ENABLE_INPUT_SERVER_EMULATION -#ifndef INPUTSERVER_TEST_MODE - send_mouse_moved(fServerLink, pt, Window()->CurrentMessage()); -#else ForwardMessage(); #endif -#endif } // MouseUp @@ -250,12 +231,8 @@ void CardView::MouseUp(BPoint pt) { #ifdef ENABLE_INPUT_SERVER_EMULATION -#ifndef INPUTSERVER_TEST_MODE - send_mouse_up(fServerLink, pt, Window()->CurrentMessage()); -#else ForwardMessage(); #endif -#endif } // MessageReceived @@ -324,11 +301,7 @@ STRACE("MSG_UPDATE\n"); break; default: #ifdef ENABLE_INPUT_SERVER_EMULATION -#ifndef INPUTSERVER_TEST_MODE - if (!handle_message(fView->ServerLink(), msg)) -#else fView->ForwardMessage(); -#endif #endif BWindow::MessageReceived(msg); break; @@ -348,7 +321,7 @@ CardWindow::QuitRequested() link.Flush(); } else printf("ERROR: couldn't find the app_server's main port!"); - + // we don't quit on ourself, we let us be Quit()! return false; }