RootLayer thread receives BMessages only. Changed ViewHWInterface to send BMessages for input events

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14520 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca 2005-10-25 18:42:10 +00:00
parent ef7bac18bb
commit 28d42d6e75
7 changed files with 233 additions and 393 deletions

View File

@ -1111,98 +1111,74 @@ Layer::ScrollBy(float x, float y)
} }
void void
Layer::MouseDown(const PointerEvent& evt) Layer::MouseDown(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
BMessage msg; Window()->SendMessageToClient(msg, fViewToken, false);
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);
} }
} }
void void
Layer::MouseUp(const PointerEvent& evt) Layer::MouseUp(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
BMessage upmsg(B_MOUSE_UP); Window()->SendMessageToClient(msg, fViewToken, false);
upmsg.AddInt64("when",evt.when);
upmsg.AddPoint("where",evt.where);
upmsg.AddInt32("modifiers",evt.modifiers);
Window()->SendMessageToClient(&upmsg, fViewToken, false);
} }
} }
void void
Layer::MouseMoved(const PointerEvent& evt, uint32 transit) Layer::MouseMoved(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
BMessage movemsg(B_MOUSE_MOVED); Window()->SendMessageToClient(msg, fViewToken, false);
movemsg.AddInt64("when", evt.when);
movemsg.AddPoint("where", evt.where);
movemsg.AddInt32("buttons", evt.buttons);
movemsg.AddInt32("transit", transit);
Window()->SendMessageToClient(&movemsg, fViewToken, false);
} }
} }
void void
Layer::MouseWheelChanged(const PointerEvent& evt) Layer::MouseWheelChanged(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
BMessage wheelmsg(B_MOUSE_WHEEL_CHANGED); Window()->SendMessageToClient(msg, fViewToken, false);
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);
} }
} }
void void
Layer::KeyDown(const BMessage& msg) Layer::KeyDown(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); Window()->SendMessageToClient(msg, B_NULL_TOKEN, true);
} }
} }
void void
Layer::KeyUp(const BMessage& msg) Layer::KeyUp(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); Window()->SendMessageToClient(msg, B_NULL_TOKEN, true);
} }
} }
void void
Layer::UnmappedKeyDown(const BMessage& msg) Layer::UnmappedKeyDown(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); Window()->SendMessageToClient(msg, B_NULL_TOKEN, true);
} }
} }
void void
Layer::UnmappedKeyUp(const BMessage& msg) Layer::UnmappedKeyUp(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); Window()->SendMessageToClient(msg, B_NULL_TOKEN, true);
} }
} }
void void
Layer::ModifiersChanged(const BMessage& msg) Layer::ModifiersChanged(const BMessage *msg)
{ {
if (Window() && !IsTopLayer()) { if (Window() && !IsTopLayer()) {
Window()->SendMessageToClient(&msg, B_NULL_TOKEN, true); Window()->SendMessageToClient(msg, B_NULL_TOKEN, true);
} }
} }

View File

@ -158,16 +158,16 @@ class Layer {
virtual void ResizeBy(float x, float y); virtual void ResizeBy(float x, float y);
virtual void ScrollBy(float x, float y); virtual void ScrollBy(float x, float y);
virtual void MouseDown(const PointerEvent& evt); virtual void MouseDown(const BMessage *msg);
virtual void MouseUp(const PointerEvent& evt); virtual void MouseUp(const BMessage *msg);
virtual void MouseMoved(const PointerEvent& evt, uint32 transit); virtual void MouseMoved(const BMessage *msg);
virtual void MouseWheelChanged(const PointerEvent& evt); virtual void MouseWheelChanged(const BMessage *msg);
virtual void KeyDown(const BMessage& msg); virtual void KeyDown(const BMessage *msg);
virtual void KeyUp(const BMessage& msg); virtual void KeyUp(const BMessage *msg);
virtual void UnmappedKeyDown(const BMessage& msg); virtual void UnmappedKeyDown(const BMessage *msg);
virtual void UnmappedKeyUp(const BMessage& msg); virtual void UnmappedKeyUp(const BMessage *msg);
virtual void ModifiersChanged(const BMessage& msg); virtual void ModifiersChanged(const BMessage *msg);
virtual void WorkspaceActivated(int32 index, bool active); virtual void WorkspaceActivated(int32 index, bool active);
virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces);

View File

@ -159,10 +159,12 @@ RootLayer::~RootLayer()
{ {
fQuiting = true; fQuiting = true;
BPrivate::PortLink msg(fListenPort, -1); // BMessage quitMsg(B_QUIT_REQUESTED);
msg.StartMessage(B_QUIT_REQUESTED);
msg.EndMessage(); // BPrivate::PortLink msg(fListenPort, -1);
msg.Flush(); // msg.StartMessage(B_QUIT_REQUESTED);
// msg.EndMessage();
// msg.Flush();
status_t dummy; status_t dummy;
wait_for_thread(fThreadID, &dummy); wait_for_thread(fThreadID, &dummy);
@ -198,10 +200,7 @@ RootLayer::RunThread()
int32 int32
RootLayer::WorkingThread(void *data) RootLayer::WorkingThread(void *data)
{ {
int32 code = 0;
status_t err = B_OK;
RootLayer *oneRootLayer = (RootLayer*)data; RootLayer *oneRootLayer = (RootLayer*)data;
BPrivate::PortLink messageQueue(-1, oneRootLayer->fListenPort);
// first make sure we are actualy visible // first make sure we are actualy visible
oneRootLayer->Lock(); oneRootLayer->Lock();
@ -220,48 +219,69 @@ RootLayer::WorkingThread(void *data)
oneRootLayer->Unlock(); oneRootLayer->Unlock();
STRACE(("info: RootLayer(%s)::WorkingThread listening on port %ld.\n", oneRootLayer->Name(), oneRootLayer->fListenPort)); STRACE(("info: RootLayer(%s)::WorkingThread listening on port %ld.\n", oneRootLayer->Name(), oneRootLayer->fListenPort));
for (;;) { while(!oneRootLayer->fQuiting) {
err = messageQueue.GetNextMessage(code);
if (err < B_OK) { BMessage *msg = oneRootLayer->ReadMessageFromPort(B_INFINITE_TIMEOUT);
STRACE(("WorkingThread: messageQueue.GetNextMessage() failed: %s\n", strerror(err)));
continue; 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) { oneRootLayer->Lock();
// 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;
case B_KEY_DOWN: switch (currentMessage->what) {
case B_KEY_UP: // We don't need to do anything with these two, so just pass them
case B_UNMAPPED_KEY_DOWN: // onto the active application. Eventually, we will end up passing
case B_UNMAPPED_KEY_UP: // them onto the window which is currently under the cursor.
case B_MODIFIERS_CHANGED: case B_MOUSE_DOWN:
oneRootLayer->KeyboardEventHandler(code, messageQueue); case B_MOUSE_UP:
break; case B_MOUSE_MOVED:
case B_MOUSE_WHEEL_CHANGED:
oneRootLayer->MouseEventHandler(currentMessage);
break;
case B_QUIT_REQUESTED: case B_KEY_DOWN:
exit_thread(0); case B_KEY_UP:
break; case B_UNMAPPED_KEY_DOWN:
case B_UNMAPPED_KEY_UP:
case B_MODIFIERS_CHANGED:
oneRootLayer->KeyboardEventHandler(currentMessage);
break;
default: case B_QUIT_REQUESTED:
printf("RootLayer(%s)::WorkingThread received unexpected code %lx\n", oneRootLayer->Name(), code); exit_thread(0);
break; 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; return 0;
} }
@ -937,9 +957,12 @@ RootLayer::SetActive(WinBorder* newActive)
// Input related methods // Input related methods
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void 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) { if (target == NULL) {
CRITICAL("RootLayer::_ProcessMouseMovedEvent() 'target' can't be null.\n"); CRITICAL("RootLayer::_ProcessMouseMovedEvent() 'target' can't be null.\n");
return; return;
@ -984,7 +1007,8 @@ RootLayer::_ProcessMouseMovedEvent(PointerEvent &evt)
else else
viewAction = B_OUTSIDE_VIEW; 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); fMouseNotificationList.RemoveItem(target);
fLastLayerUnderMouse = target; fLastLayerUnderMouse = target;
fLastMousePosition = evt.where; fLastMousePosition = where;
} }
void void
RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg) RootLayer::MouseEventHandler(BMessage *msg)
{ {
switch (code) { switch (msg->what) {
case B_MOUSE_DOWN: { case B_MOUSE_DOWN: {
//printf("RootLayer::MouseEventHandler(B_MOUSE_DOWN)\n"); //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; BPoint where(0,0);
evt.code = B_MOUSE_DOWN;
msg.Read<int64>(&evt.when);
msg.Read<float>(&evt.where.x);
msg.Read<float>(&evt.where.y);
msg.Read<int32>(&evt.modifiers);
msg.Read<int32>(&evt.buttons);
msg.Read<int32>(&evt.clicks);
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 // 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) { if (fLastLayerUnderMouse == NULL) {
CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_DOWN) fLastLayerUnderMouse is null!\n"); CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_DOWN) fLastLayerUnderMouse is null!\n");
break; break;
@ -1046,37 +1070,43 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg)
if (lay) if (lay)
// NOTE: testing under R5 shows that it doesn't matter if a window is created // 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. // 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 // get the pointer for one of the first RootLayer's descendants
Layer *primaryTarget = LayerAt(evt.where, false); Layer *primaryTarget = LayerAt(where, false);
primaryTarget->MouseDown(evt); primaryTarget->MouseDown(msg);
break; break;
} }
case B_MOUSE_UP: { case B_MOUSE_UP: {
//printf("RootLayer::MouseEventHandler(B_MOUSE_UP)\n"); //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; BPoint where(0,0);
evt.code = B_MOUSE_UP;
msg.Read<int64>(&evt.when);
msg.Read<float>(&evt.where.x);
msg.Read<float>(&evt.where.y);
msg.Read<int32>(&evt.modifiers);
evt.where.ConstrainTo(fFrame); msg->FindPoint("where", &where);
if (fLastMousePosition != evt.where) { where.ConstrainTo(fFrame);
if (fLastMousePosition != where) {
// move cursor on screen // 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) { if (fLastLayerUnderMouse == NULL) {
@ -1090,12 +1120,12 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg)
for (int32 i = 0; i <= count; i++) { for (int32 i = 0; i <= count; i++) {
lay = static_cast<Layer*>(fMouseNotificationList.ItemAt(i)); lay = static_cast<Layer*>(fMouseNotificationList.ItemAt(i));
if (lay) if (lay)
lay->MouseUp(evt); lay->MouseUp(msg);
} }
ClearNotifyLayer(); ClearNotifyLayer();
if (!foundCurrent) if (!foundCurrent)
fLastLayerUnderMouse->MouseUp(evt); fLastLayerUnderMouse->MouseUp(msg);
// TODO: This is a quick fix to avoid the endless loop with windows created // 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. // 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 // 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click // 3) float - y coordinate of mouse click
// 4) int32 - buttons down // 4) int32 - buttons down
PointerEvent evt;
evt.code = B_MOUSE_MOVED;
msg.Read<int64>(&evt.when);
msg.Read<float>(&evt.where.x);
msg.Read<float>(&evt.where.y);
msg.Read<int32>(&evt.buttons);
evt.where.ConstrainTo(fFrame); BPoint where(0,0);
msg->FindPoint("where", &where);
where.ConstrainTo(fFrame);
// move cursor on screen // move cursor on screen
GetHWInterface()->MoveCursorTo(evt.where.x, evt.where.y); GetHWInterface()->MoveCursorTo(where.x, where.y);
_ProcessMouseMovedEvent(evt); _ProcessMouseMovedEvent(msg);
break; 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 // under the cursor. It's pretty stupid to send it to the active window unless a particular
// view has locked focus via SetMouseEventMask // view has locked focus via SetMouseEventMask
PointerEvent evt;
evt.code = B_MOUSE_WHEEL_CHANGED;
msg.Read<int64>(&evt.when);
msg.Read<float>(&evt.wheel_delta_x);
msg.Read<float>(&evt.wheel_delta_y);
if (fLastLayerUnderMouse == NULL) { if (fLastLayerUnderMouse == NULL) {
CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_DOWN) fLastLayerUnderMouse is null!\n"); CRITICAL("RootLayer::MouseEventHandler(B_MOUSE_DOWN) fLastLayerUnderMouse is null!\n");
break; break;
} }
fLastLayerUnderMouse->MouseWheelChanged(evt); fLastLayerUnderMouse->MouseWheelChanged(msg);
break; break;
} }
default: default:
@ -1156,39 +1177,16 @@ RootLayer::MouseEventHandler(int32 code, BPrivate::PortLink& msg)
void void
RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg) RootLayer::KeyboardEventHandler(BMessage *msg)
{ {
switch (code) { switch (msg->what) {
case B_KEY_DOWN: case B_KEY_DOWN:
{ {
// Attached Data: int32 scancode = 0;
// 1) int64 bigtime_t object of when the message was sent int32 modifiers = 0;
// 2) int32 raw key code (scancode)
// 3) int32 modifier-independent ASCII code for the character msg->FindInt32("key", &scancode);
// 4) int32 repeat count msg->FindInt32("modifiers", &modifiers);
// 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<bigtime_t>(&time);
msg.Read<int32>(&scancode);
msg.Read<int32>(&raw_char);
msg.Read<int32>(&repeatcount);
msg.Read<int32>(&modifiers);
msg.Read(utf, sizeof(utf));
msg.ReadString(&string);
msg.Read(keystates, sizeof(keystates));
STRACE(("Key Down: 0x%lx\n",scancode));
// F1-F12 // F1-F12
if (scancode > 0x01 && scancode < 0x0e) { 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) // TODO: Set to Safe Mode in KeyboardEventHandler:B_KEY_DOWN. (DisplayDriver API change)
STRACE(("Safe Video Mode invoked - code unimplemented\n")); STRACE(("Safe Video Mode invoked - code unimplemented\n"));
free(string);
break; break;
} }
@ -1224,7 +1221,6 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg)
fDriver->ConstrainClippingRegion(NULL); fDriver->ConstrainClippingRegion(NULL);
#endif #endif
#endif #endif
free(string);
break; break;
} }
} }
@ -1242,7 +1238,6 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg)
//{ //{
// TODO: implement; // TODO: implement;
printf("Send Twitcher message key to Deskbar - unimplmemented\n"); printf("Send Twitcher message key to Deskbar - unimplmemented\n");
free(string);
break; break;
//} //}
} }
@ -1267,7 +1262,6 @@ RootLayer::KeyboardEventHandler(int32 code, BPrivate::PortLink& msg)
GetDisplayDriver()->DumpToFile(filename); GetDisplayDriver()->DumpToFile(filename);
free(string);
break; 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 // We got this far, so apparently it's safe to pass to the active
// window. // window.
if (Focus()) { if (Focus())
BMessage keymsg(B_KEY_DOWN); Focus()->KeyDown(msg);
keymsg.AddInt64("when", time);
keymsg.AddInt32("key", scancode);
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; break;
} }
case B_KEY_UP: case B_KEY_UP:
{ {
// Attached Data: int32 scancode = 0;
// 1) int64 bigtime_t object of when the message was sent int32 modifiers = 0;
// 2) int32 raw key code (scancode)
// 3) int32 modifier-independent ASCII code for the character msg->FindInt32("key", &scancode);
// 4) int32 modifiers msg->FindInt32("modifiers", &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<bigtime_t>(&time);
msg.Read<int32>(&scancode);
msg.Read<int32>(&raw_char);
msg.Read<int32>(&modifiers);
msg.Read(utf, sizeof(utf));
msg.ReadString(&string);
msg.Read(keystates, sizeof(keystates));
STRACE(("Key Up: 0x%lx\n", scancode));
#if !TEST_MODE #if !TEST_MODE
// Tab key // 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 // We got this far, so apparently it's safe to pass to the active
// window. // window.
if (Focus()) { if (Focus())
BMessage keymsg(B_KEY_UP); Focus()->KeyUp(msg);
keymsg.AddInt64("when", time);
keymsg.AddInt32("key", scancode);
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()->KeyUp(keymsg);
}
free(string);
break; break;
} }
case B_UNMAPPED_KEY_DOWN: case B_UNMAPPED_KEY_DOWN:
{ {
// Attached Data: if(Focus())
// 1) int64 bigtime_t object of when the message was sent Focus()->UnmappedKeyDown(msg);
// 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<bigtime_t>(&time);
msg.Read<int32>(&scancode);
msg.Read<int32>(&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);
}
break; break;
} }
case B_UNMAPPED_KEY_UP: case B_UNMAPPED_KEY_UP:
{ {
// Attached Data: if(Focus())
// 1) int64 bigtime_t object of when the message was sent Focus()->UnmappedKeyUp(msg);
// 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<bigtime_t>(&time);
msg.Read<int32>(&scancode);
msg.Read<int32>(&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);
}
break; break;
} }
case B_MODIFIERS_CHANGED: case B_MODIFIERS_CHANGED:
{ {
// Attached Data: if(Focus())
// 1) int64 bigtime_t object of when the message was sent Focus()->ModifiersChanged(msg);
// 2) int32 modifiers
// 3) int32 old modifiers
// 4) int8 state of all keys
bigtime_t time;
int32 modifiers,oldmodifiers;
int8 keystates[16];
msg.Read<bigtime_t>(&time);
msg.Read<int32>(&modifiers);
msg.Read<int32>(&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);
}
break; break;
} }
@ -1828,6 +1700,8 @@ RootLayer::ConvertToMessage(void* raw, int32 code)
if (raw != NULL) { if (raw != NULL) {
if (bmsg->Unflatten((const char*)raw) != B_OK) { 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; delete bmsg;
bmsg = NULL; bmsg = NULL;
} }

View File

@ -31,6 +31,7 @@
#include <List.h> #include <List.h>
#include <Locker.h> #include <Locker.h>
#include <MessageQueue.h>
#include "DebugInfoManager.h" #include "DebugInfoManager.h"
#include "Desktop.h" #include "Desktop.h"
@ -161,10 +162,10 @@ friend class WinBorder; // temporarily, I need invalidate_layer()
void empty_visible_regions(Layer *layer); void empty_visible_regions(Layer *layer);
#endif #endif
// Input related methods // Input related methods
void MouseEventHandler(int32 code, BPrivate::PortLink& link); void MouseEventHandler(BMessage *msg);
void KeyboardEventHandler(int32 code, BPrivate::PortLink& link); void KeyboardEventHandler(BMessage *msg);
void _ProcessMouseMovedEvent(PointerEvent &evt); void _ProcessMouseMovedEvent(BMessage *msg);
inline HWInterface* GetHWInterface() const inline HWInterface* GetHWInterface() const
{ return fDesktop->GetHWInterface(); } { return fDesktop->GetHWInterface(); }
@ -187,6 +188,7 @@ friend class WinBorder; // temporarily, I need invalidate_layer()
thread_id fThreadID; thread_id fThreadID;
port_id fListenPort; port_id fListenPort;
BMessageQueue fQueue;
int32 fButtons; int32 fButtons;
BPoint fLastMousePosition; BPoint fLastMousePosition;

View File

@ -74,7 +74,6 @@ WinBorder::WinBorder(const BRect &frame,
fInUpdateRegion(), fInUpdateRegion(),
fMouseButtons(0), fMouseButtons(0),
fKeyModifiers(0),
fLastMousePosition(-1.0, -1.0), fLastMousePosition(-1.0, -1.0),
fIsClosing(false), fIsClosing(false),
@ -444,23 +443,26 @@ WinBorder::GetSizeLimits(float* minWidth, float* maxWidth,
} }
void void
WinBorder::MouseDown(const PointerEvent& evt) WinBorder::MouseDown(const BMessage *msg)
{ {
DesktopSettings desktopSettings(gDesktop); DesktopSettings desktopSettings(gDesktop);
BPoint where(0,0);
msg->FindPoint("where", &where);
// not in FFM mode? // not in FFM mode?
if (desktopSettings.MouseMode() == B_NORMAL_MOUSE) { if (desktopSettings.MouseMode() == B_NORMAL_MOUSE) {
// default action is to drag the WinBorder // default action is to drag the WinBorder
click_type action = DEC_DRAG; click_type action = DEC_DRAG;
Layer *target = LayerAt(evt.where); Layer *target = LayerAt(where);
// clicking a simple Layer. // clicking a simple Layer.
if (target != this) { if (target != this) {
if (GetRootLayer()->ActiveWorkspace()->Active() == this) { if (GetRootLayer()->ActiveWorkspace()->Active() == this) {
target->MouseDown(evt); target->MouseDown(msg);
} }
else { else {
if (WindowFlags() & B_WILL_ACCEPT_FIRST_CLICK) if (WindowFlags() & B_WILL_ACCEPT_FIRST_CLICK)
target->MouseDown(evt); target->MouseDown(msg);
else else
goto activateWindow; goto activateWindow;
} }
@ -470,7 +472,7 @@ WinBorder::MouseDown(const PointerEvent& evt)
winBorderAreaHandle: winBorderAreaHandle:
if (fDecorator) if (fDecorator)
action = _ActionFor(evt); action = _ActionFor(msg);
// deactivate border buttons on first click(select) // deactivate border buttons on first click(select)
if (GetRootLayer()->Focus() != this && action != DEC_MOVETOBACK if (GetRootLayer()->Focus() != this && action != DEC_MOVETOBACK
@ -499,19 +501,19 @@ WinBorder::MouseDown(const PointerEvent& evt)
case DEC_DRAG: case DEC_DRAG:
fIsDragging = true; fIsDragging = true;
fLastMousePosition = evt.where; fLastMousePosition = where;
STRACE_CLICK(("===> DEC_DRAG\n")); STRACE_CLICK(("===> DEC_DRAG\n"));
break; break;
case DEC_RESIZE: case DEC_RESIZE:
fIsResizing = true; fIsResizing = true;
fLastMousePosition = evt.where; fLastMousePosition = where;
STRACE_CLICK(("===> DEC_RESIZE\n")); STRACE_CLICK(("===> DEC_RESIZE\n"));
break; break;
case DEC_SLIDETAB: case DEC_SLIDETAB:
fIsSlidingTab = true; fIsSlidingTab = true;
fLastMousePosition = evt.where; fLastMousePosition = where;
STRACE_CLICK(("===> DEC_SLIDETAB\n")); STRACE_CLICK(("===> DEC_SLIDETAB\n"));
break; break;
@ -538,10 +540,10 @@ WinBorder::MouseDown(const PointerEvent& evt)
} }
// in FFM mode // in FFM mode
else { else {
Layer *target = LayerAt(evt.where); Layer *target = LayerAt(where);
// clicking a simple Layer; forward event. // clicking a simple Layer; forward event.
if (target != this) if (target != this)
target->MouseDown(evt); target->MouseDown(msg);
// clicking inside our visible area. // clicking inside our visible area.
else else
goto winBorderAreaHandle; goto winBorderAreaHandle;
@ -549,11 +551,11 @@ WinBorder::MouseDown(const PointerEvent& evt)
} }
void void
WinBorder::MouseUp(const PointerEvent& event) WinBorder::MouseUp(const BMessage *msg)
{ {
bool invalidate = false; bool invalidate = false;
if (fDecorator) { if (fDecorator) {
click_type action = _ActionFor(event); click_type action = _ActionFor(msg);
// TODO: present behavior is not fine! // TODO: present behavior is not fine!
// Decorator's Set*() methods _actualy draw_! on screen, not // Decorator's Set*() methods _actualy draw_! on screen, not
// taking into account if that region is visible or not! // taking into account if that region is visible or not!
@ -590,8 +592,12 @@ WinBorder::MouseUp(const PointerEvent& event)
} }
void void
WinBorder::MouseMoved(const PointerEvent& event, uint32 transit) WinBorder::MouseMoved(const BMessage *msg)
{ {
BPoint where(0,0);
msg->FindPoint("where", &where);
if (fDecorator) { if (fDecorator) {
// TODO: present behavior is not fine! // TODO: present behavior is not fine!
// Decorator's Set*() methods _actualy draw_! on screen, not // 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 // Decorator redraw code should follow the same path as Layer's
// one! // one!
if (fIsZooming) { if (fIsZooming) {
fDecorator->SetZoom(_ActionFor(event) == DEC_ZOOM); fDecorator->SetZoom(_ActionFor(msg) == DEC_ZOOM);
} else if (fIsClosing) { } else if (fIsClosing) {
fDecorator->SetClose(_ActionFor(event) == DEC_CLOSE); fDecorator->SetClose(_ActionFor(msg) == DEC_CLOSE);
} else if (fIsMinimizing) { } else if (fIsMinimizing) {
fDecorator->SetMinimize(_ActionFor(event) == DEC_MINIMIZE); fDecorator->SetMinimize(_ActionFor(msg) == DEC_MINIMIZE);
} }
} }
if (fIsDragging) { if (fIsDragging) {
BPoint delta = event.where - fLastMousePosition; BPoint delta = where - fLastMousePosition;
#ifndef NEW_CLIPPING #ifndef NEW_CLIPPING
MoveBy(delta.x, delta.y); MoveBy(delta.x, delta.y);
#else #else
@ -616,7 +622,7 @@ WinBorder::MouseMoved(const PointerEvent& event, uint32 transit)
#endif #endif
} }
if (fIsResizing) { if (fIsResizing) {
BPoint delta = event.where - fLastMousePosition; BPoint delta = where - fLastMousePosition;
#ifndef NEW_CLIPPING #ifndef NEW_CLIPPING
ResizeBy(delta.x, delta.y); ResizeBy(delta.x, delta.y);
#else #else
@ -627,7 +633,7 @@ WinBorder::MouseMoved(const PointerEvent& event, uint32 transit)
// TODO: implement // TODO: implement
} }
fLastMousePosition = event.where; fLastMousePosition = where;
} }
void void
@ -777,21 +783,29 @@ WinBorder::QuietlySetFeel(int32 feel)
// _ActionFor // _ActionFor
click_type 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_INPUT_HANDING
#ifndef NEW_CLIPPING #ifndef NEW_CLIPPING
if (fTopLayer->fFullVisible.Contains(event.where)) if (fTopLayer->fFullVisible.Contains(where))
return DEC_NONE; return DEC_NONE;
else else
#else #else
if (fTopLayer->fFullVisible2.Contains(event.where)) if (fTopLayer->fFullVisible2.Contains(where))
return DEC_NONE; return DEC_NONE;
else else
#endif #endif
#endif #endif
if (fDecorator) if (fDecorator)
return fDecorator->Clicked(event.where, event.buttons, event.modifiers); return fDecorator->Clicked(where, buttons, modifiers);
else else
return DEC_NONE; return DEC_NONE;
} }

View File

@ -81,11 +81,13 @@ class WinBorder : public Layer {
float* minHeight, float* minHeight,
float* maxHeight) const; float* maxHeight) const;
virtual void MouseDown(const PointerEvent& evt); virtual void MouseDown(const BMessage *msg);
virtual void MouseUp(const PointerEvent& evt); virtual void MouseUp(const BMessage *msg);
virtual void MouseMoved(const PointerEvent& evt, uint32 transit); virtual void MouseMoved(const BMessage *msg);
click_type ActionFor(const PointerEvent& evt)
{ return _ActionFor(evt); } // click_type ActionFor(const BMessage *msg)
// { return _ActionFor(evt); }
virtual void WorkspaceActivated(int32 index, bool active); virtual void WorkspaceActivated(int32 index, bool active);
virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces);
@ -138,7 +140,7 @@ class WinBorder : public Layer {
friend class Layer; friend class Layer;
friend class RootLayer; friend class RootLayer;
click_type _ActionFor(const PointerEvent& evt) const; click_type _ActionFor(const BMessage *msg) const;
bool _ResizeBy(float x, float y); bool _ResizeBy(float x, float y);
Decorator* fDecorator; Decorator* fDecorator;
@ -148,7 +150,6 @@ class WinBorder : public Layer {
BRegion fInUpdateRegion; BRegion fInUpdateRegion;
int32 fMouseButtons; int32 fMouseButtons;
int32 fKeyModifiers;
BPoint fLastMousePosition; BPoint fLastMousePosition;
BPoint fResizingClickOffset; BPoint fResizingClickOffset;

View File

@ -26,8 +26,6 @@
#include <View.h> #include <View.h>
#include <Window.h> #include <Window.h>
#include "fake_input_server.h"
#include "BBitmapBuffer.h" #include "BBitmapBuffer.h"
#include "PortLink.h" #include "PortLink.h"
#include "ServerConfig.h" #include "ServerConfig.h"
@ -123,14 +121,10 @@ class CardView : public BView {
// CardView // CardView
void SetBitmap(const BBitmap* bimtap); void SetBitmap(const BBitmap* bimtap);
inline BPrivate::PortLink* ServerLink() const
{ return fServerLink; }
void ForwardMessage(); void ForwardMessage();
private: private:
port_id fInputPort; port_id fInputPort;
BPrivate::PortLink* fServerLink;
const BBitmap* fBitmap; const BBitmap* fBitmap;
}; };
@ -158,16 +152,12 @@ class CardWindow : public BWindow {
CardView::CardView(BRect bounds) CardView::CardView(BRect bounds)
: BView(bounds, "graphics card view", B_FOLLOW_ALL, B_WILL_DRAW), : BView(bounds, "graphics card view", B_FOLLOW_ALL, B_WILL_DRAW),
fServerLink(NULL),
fBitmap(NULL) fBitmap(NULL)
{ {
SetViewColor(B_TRANSPARENT_32_BIT); SetViewColor(B_TRANSPARENT_32_BIT);
#ifndef INPUTSERVER_TEST_MODE #ifndef INPUTSERVER_TEST_MODE
// This link for sending mouse messages to the Haiku app_server. fInputPort = find_port(SERVER_INPUT_PORT);
// 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);
#else #else
fInputPort = create_port(100, "ViewInputDevice"); fInputPort = create_port(100, "ViewInputDevice");
#endif #endif
@ -176,7 +166,6 @@ CardView::CardView(BRect bounds)
CardView::~CardView() CardView::~CardView()
{ {
delete fServerLink;
} }
// AttachedToWindow // AttachedToWindow
@ -216,12 +205,8 @@ void
CardView::MouseDown(BPoint pt) CardView::MouseDown(BPoint pt)
{ {
#ifdef ENABLE_INPUT_SERVER_EMULATION #ifdef ENABLE_INPUT_SERVER_EMULATION
#ifndef INPUTSERVER_TEST_MODE
send_mouse_down(fServerLink, pt, Window()->CurrentMessage());
#else
ForwardMessage(); ForwardMessage();
#endif #endif
#endif
} }
// MouseMoved // MouseMoved
@ -237,12 +222,8 @@ CardView::MouseMoved(BPoint pt, uint32 transit, const BMessage* dragMessage)
SetViewCursor(&cursor, true); SetViewCursor(&cursor, true);
#ifdef ENABLE_INPUT_SERVER_EMULATION #ifdef ENABLE_INPUT_SERVER_EMULATION
#ifndef INPUTSERVER_TEST_MODE
send_mouse_moved(fServerLink, pt, Window()->CurrentMessage());
#else
ForwardMessage(); ForwardMessage();
#endif #endif
#endif
} }
// MouseUp // MouseUp
@ -250,12 +231,8 @@ void
CardView::MouseUp(BPoint pt) CardView::MouseUp(BPoint pt)
{ {
#ifdef ENABLE_INPUT_SERVER_EMULATION #ifdef ENABLE_INPUT_SERVER_EMULATION
#ifndef INPUTSERVER_TEST_MODE
send_mouse_up(fServerLink, pt, Window()->CurrentMessage());
#else
ForwardMessage(); ForwardMessage();
#endif #endif
#endif
} }
// MessageReceived // MessageReceived
@ -324,11 +301,7 @@ STRACE("MSG_UPDATE\n");
break; break;
default: default:
#ifdef ENABLE_INPUT_SERVER_EMULATION #ifdef ENABLE_INPUT_SERVER_EMULATION
#ifndef INPUTSERVER_TEST_MODE
if (!handle_message(fView->ServerLink(), msg))
#else
fView->ForwardMessage(); fView->ForwardMessage();
#endif
#endif #endif
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
@ -348,7 +321,7 @@ CardWindow::QuitRequested()
link.Flush(); link.Flush();
} else } else
printf("ERROR: couldn't find the app_server's main port!"); printf("ERROR: couldn't find the app_server's main port!");
// we don't quit on ourself, we let us be Quit()! // we don't quit on ourself, we let us be Quit()!
return false; return false;
} }