extracted the fake input_server communication into an extra file used by ViewDriver and ViewHWInterface

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12085 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2005-03-28 11:04:00 +00:00
parent 53115c9920
commit 022badfd34
4 changed files with 353 additions and 501 deletions

View File

@ -39,6 +39,8 @@
#include <Screen.h>
#include <TranslatorRoster.h>
#include "fake_input_server.h"
#include "PortLink.h"
#include "RectUtils.h"
#include "ServerProtocol.h"
@ -147,31 +149,7 @@ void VDView::Draw(BRect rect)
void VDView::MouseDown(BPoint pt)
{
#ifdef ENABLE_INPUT_SERVER_EMULATION
// Attach 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
uint32 buttons, mod, clicks=1;
int64 time=(int64)real_time_clock();
BMessage *msg=Window()->CurrentMessage();
msg->FindPoint("where",&pt);
msg->FindInt32("modifiers",(int32*)&mod);
msg->FindInt32("buttons",(int32*)&buttons);
msg->FindInt32("clicks",(int32*)&clicks);
serverlink->StartMessage(B_MOUSE_DOWN);
serverlink->Attach(&time, sizeof(int64));
serverlink->Attach(&pt.x,sizeof(float));
serverlink->Attach(&pt.y,sizeof(float));
serverlink->Attach(&mod, sizeof(uint32));
serverlink->Attach(&buttons, sizeof(uint32));
serverlink->Attach(&clicks, sizeof(uint32));
serverlink->Flush();
send_mouse_down(serverlink, pt, Window()->CurrentMessage());
#endif
}
@ -180,48 +158,14 @@ void VDView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg)
if (!(transit == B_ENTERED_VIEW || transit == B_INSIDE_VIEW))
return;
#ifdef ENABLE_INPUT_SERVER_EMULATION
// Attach data:
// 1) int64 - time of mouse click
// 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click
// 4) int32 - buttons down
BPoint p;
uint32 buttons;
int64 time=(int64)real_time_clock();
serverlink->StartMessage(B_MOUSE_MOVED);
serverlink->Attach(&time,sizeof(int64));
serverlink->Attach(&pt.x,sizeof(float));
serverlink->Attach(&pt.y,sizeof(float));
GetMouse(&p,&buttons);
serverlink->Attach(&buttons,sizeof(int32));
serverlink->Flush();
send_mouse_moved(serverlink, pt, Window()->CurrentMessage());
#endif
}
void VDView::MouseUp(BPoint pt)
{
#ifdef ENABLE_INPUT_SERVER_EMULATION
// Attach 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
BPoint p;
uint32 buttons,
mod=modifiers();
int64 time=(int64)real_time_clock();
GetMouse(&p,&buttons);
serverlink->StartMessage(B_MOUSE_UP);
serverlink->Attach(&time, sizeof(int64));
serverlink->Attach(&pt.x,sizeof(float));
serverlink->Attach(&pt.y,sizeof(float));
serverlink->Attach(&mod, sizeof(uint32));
serverlink->Flush();
send_mouse_up(serverlink, pt, Window()->CurrentMessage());
#endif
}
@ -249,196 +193,10 @@ VDWindow::~VDWindow()
void VDWindow::MessageReceived(BMessage *msg)
{
switch(msg->what)
{
#ifdef ENABLE_INPUT_SERVER_EMULATION
case B_MOUSE_WHEEL_CHANGED:
{
float x,y;
msg->FindFloat("be:wheel_delta_x",&x);
msg->FindFloat("be:wheel_delta_y",&y);
int64 time=real_time_clock();
view->serverlink->StartMessage(B_MOUSE_WHEEL_CHANGED);
view->serverlink->Attach(&time,sizeof(int64));
view->serverlink->Attach(x);
view->serverlink->Attach(y);
view->serverlink->Flush();
break;
}
if (!handle_message(view->serverlink, msg))
#endif
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) int8 number of bytes to follow containing the
// generated string
// 8) Character string generated by the keystroke
// 10) int8[16] state of all keys
bigtime_t systime;
int32 scancode, asciicode,repeatcount,modifiers;
int8 utf8data[4];
BString string;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
if(msg->FindInt32("be:key_repeat",&repeatcount)!=B_OK)
{
// TODO: see if repeatcount should be 0 or 1 when not repeating in ViewDriver
repeatcount=1;
}
msg->FindInt32("modifiers",&modifiers);
msg->FindInt32("raw_char",&asciicode);
msg->FindInt8("byte",0,utf8data);
if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)
utf8data[1]=0;
if(msg->FindInt8("byte",2,utf8data+2)!=B_OK)
utf8data[2]=0;
if(msg->FindInt8("byte",3,utf8data+3)!=B_OK)
utf8data[3]=0;
msg->FindString("bytes",&string);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
view->serverlink->StartMessage(B_KEY_DOWN);
view->serverlink->Attach(&systime,sizeof(bigtime_t));
view->serverlink->Attach(scancode);
view->serverlink->Attach(asciicode);
view->serverlink->Attach(repeatcount);
view->serverlink->Attach(modifiers);
view->serverlink->Attach(utf8data,sizeof(int8)*3);
view->serverlink->AttachString(string.String());
view->serverlink->Attach(keyarray,sizeof(int8)*16);
view->serverlink->Flush();
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) int8 number of bytes to follow containing the
// generated string
// 7) Character string generated by the keystroke
// 8) int8[16] state of all keys
bigtime_t systime;
int32 scancode, asciicode,modifiers;
int8 utf8data[3];
BString string;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("raw_char",&asciicode);
msg->FindInt32("modifiers",&modifiers);
msg->FindInt8("byte",0,utf8data);
if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)
utf8data[1]=0;
if(msg->FindInt8("byte",1,utf8data+2)!=B_OK)
utf8data[2]=0;
if(msg->FindInt8("byte",1,utf8data+3)!=B_OK)
utf8data[3]=0;
msg->FindString("bytes",&string);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
view->serverlink->StartMessage(B_KEY_UP);
view->serverlink->Attach(&systime,sizeof(bigtime_t));
view->serverlink->Attach(scancode);
view->serverlink->Attach(asciicode);
view->serverlink->Attach(modifiers);
view->serverlink->Attach(utf8data,sizeof(int8)*3);
view->serverlink->AttachString(string.String());
view->serverlink->Attach(keyarray,sizeof(int8)*16);
view->serverlink->Flush();
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[16] state of all keys
bigtime_t systime;
int32 scancode,modifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
view->serverlink->StartMessage(B_UNMAPPED_KEY_DOWN);
view->serverlink->Attach(&systime,sizeof(bigtime_t));
view->serverlink->Attach(scancode);
view->serverlink->Attach(modifiers);
view->serverlink->Attach(keyarray,sizeof(int8)*16);
view->serverlink->Flush();
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[16] state of all keys
bigtime_t systime;
int32 scancode,modifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
view->serverlink->StartMessage(B_UNMAPPED_KEY_UP);
view->serverlink->Attach(&systime,sizeof(bigtime_t));
view->serverlink->Attach(scancode);
view->serverlink->Attach(modifiers);
view->serverlink->Attach(keyarray,sizeof(int8)*16);
view->serverlink->Flush();
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 systime;
int32 scancode,modifiers,oldmodifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
msg->FindInt32("be:old_modifiers",&oldmodifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
view->serverlink->StartMessage(B_MODIFIERS_CHANGED);
view->serverlink->Attach(&systime,sizeof(bigtime_t));
view->serverlink->Attach(scancode);
view->serverlink->Attach(modifiers);
view->serverlink->Attach(oldmodifiers);
view->serverlink->Attach(keyarray,sizeof(int8)*16);
view->serverlink->Flush();
break;
}
default:
BWindow::MessageReceived(msg);
break;
}
BWindow::MessageReceived(msg);
}
bool VDWindow::QuitRequested()

View File

@ -24,6 +24,8 @@
#include <View.h>
#include <Window.h>
#include "fake_input_server.h"
#include "BitmapBuffer.h"
#include "PortLink.h"
#include "ServerConfig.h"
@ -177,33 +179,7 @@ void
CardView::MouseDown(BPoint pt)
{
#ifdef ENABLE_INPUT_SERVER_EMULATION
// Attach 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
if (BMessage* message = Window()->CurrentMessage()) {
uint32 buttons, mod, clicks = 1;
int64 time=(int64)real_time_clock();
message->FindPoint("where", &pt);
message->FindInt32("modifiers", (int32*)&mod);
message->FindInt32("buttons", (int32*)&buttons);
message->FindInt32("clicks", (int32*)&clicks);
fServerLink->StartMessage(B_MOUSE_DOWN);
fServerLink->Attach(&time, sizeof(int64));
fServerLink->Attach(&pt.x, sizeof(float));
fServerLink->Attach(&pt.y, sizeof(float));
fServerLink->Attach(&mod, sizeof(uint32));
fServerLink->Attach(&buttons, sizeof(uint32));
fServerLink->Attach(&clicks, sizeof(uint32));
fServerLink->Flush();
}
send_mouse_down(fServerLink, pt, Window()->CurrentMessage());
#endif
}
@ -221,24 +197,7 @@ CardView::MouseMoved(BPoint pt, uint32 transit, const BMessage* dragMessage)
// SetViewCursor(&cursor, true);
#ifdef ENABLE_INPUT_SERVER_EMULATION
// Attach data:
// 1) int64 - time of mouse click
// 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click
// 4) int32 - buttons down
if (BMessage* message = Window()->CurrentMessage()) {
uint32 buttons;
int64 time=(int64)real_time_clock();
message->FindInt32("buttons",(int32*)&buttons);
fServerLink->StartMessage(B_MOUSE_MOVED);
fServerLink->Attach(&time, sizeof(int64));
fServerLink->Attach(&pt.x, sizeof(float));
fServerLink->Attach(&pt.y, sizeof(float));
fServerLink->Attach(&buttons, sizeof(int32));
fServerLink->Flush();
}
send_mouse_moved(fServerLink, pt, Window()->CurrentMessage());
#endif
}
@ -247,21 +206,7 @@ void
CardView::MouseUp(BPoint pt)
{
#ifdef ENABLE_INPUT_SERVER_EMULATION
// Attach 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
int64 time=(int64)real_time_clock();
uint32 mod = modifiers();
fServerLink->StartMessage(B_MOUSE_UP);
fServerLink->Attach(&time, sizeof(int64));
fServerLink->Attach(&pt.x, sizeof(float));
fServerLink->Attach(&pt.y, sizeof(float));
fServerLink->Attach(&mod, sizeof(uint32));
fServerLink->Flush();
send_mouse_up(fServerLink, pt, Window()->CurrentMessage());
#endif
}
@ -308,10 +253,10 @@ CardWindow::~CardWindow()
void CardWindow::MessageReceived(BMessage *msg)
{
BPortLink* serverLink = fView->ServerLink();
switch(msg->what)
{
STRACE("CardWindow::MessageReceived()\n");
switch (msg->what) {
case MSG_UPDATE:
STRACE("MSG_UPDATE\n");
// invalidate all areas in the view that need redrawing
if (fUpdateLock.LockWithTimeout(0LL) >= B_OK) {
/* int32 count = fUpdateRegion.CountRects();
@ -321,201 +266,21 @@ void CardWindow::MessageReceived(BMessage *msg)
BRect frame = fUpdateRegion.Frame();
if (frame.IsValid()) {
fView->Invalidate(frame);
fUpdateRegion.MakeEmpty();
}
fUpdateRegion.MakeEmpty();
fUpdateLock.Unlock();
} else {
// see you next time
}
break;
#ifdef ENABLE_INPUT_SERVER_EMULATION
case B_MOUSE_WHEEL_CHANGED:
{
float x,y;
msg->FindFloat("be:wheel_delta_x",&x);
msg->FindFloat("be:wheel_delta_y",&y);
int64 time=real_time_clock();
serverLink->StartMessage(B_MOUSE_WHEEL_CHANGED);
serverLink->Attach(&time,sizeof(int64));
serverLink->Attach(x);
serverLink->Attach(y);
serverLink->Flush();
break;
}
#endif
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) int8 number of bytes to follow containing the
// generated string
// 8) Character string generated by the keystroke
// 10) int8[16] state of all keys
bigtime_t systime;
int32 scancode, asciicode,repeatcount,modifiers;
int8 utf8data[4];
BString string;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
if(msg->FindInt32("be:key_repeat",&repeatcount)!=B_OK)
{
// TODO: see if repeatcount should be 0 or 1 when not repeating in ViewDriver
repeatcount=1;
}
msg->FindInt32("modifiers",&modifiers);
msg->FindInt32("raw_char",&asciicode);
msg->FindInt8("byte",0,utf8data);
if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)
utf8data[1]=0;
if(msg->FindInt8("byte",2,utf8data+2)!=B_OK)
utf8data[2]=0;
if(msg->FindInt8("byte",3,utf8data+3)!=B_OK)
utf8data[3]=0;
msg->FindString("bytes",&string);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_KEY_DOWN);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(asciicode);
serverLink->Attach(repeatcount);
serverLink->Attach(modifiers);
serverLink->Attach(utf8data,sizeof(int8)*3);
serverLink->AttachString(string.String());
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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) int8 number of bytes to follow containing the
// generated string
// 7) Character string generated by the keystroke
// 8) int8[16] state of all keys
bigtime_t systime;
int32 scancode, asciicode,modifiers;
int8 utf8data[3];
BString string;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("raw_char",&asciicode);
msg->FindInt32("modifiers",&modifiers);
msg->FindInt8("byte",0,utf8data);
if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)
utf8data[1]=0;
if(msg->FindInt8("byte",1,utf8data+2)!=B_OK)
utf8data[2]=0;
if(msg->FindInt8("byte",1,utf8data+3)!=B_OK)
utf8data[3]=0;
msg->FindString("bytes",&string);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_KEY_UP);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(asciicode);
serverLink->Attach(modifiers);
serverLink->Attach(utf8data,sizeof(int8)*3);
serverLink->AttachString(string.String());
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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[16] state of all keys
bigtime_t systime;
int32 scancode,modifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_UNMAPPED_KEY_DOWN);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(modifiers);
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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[16] state of all keys
bigtime_t systime;
int32 scancode,modifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_UNMAPPED_KEY_UP);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(modifiers);
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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 systime;
int32 scancode,modifiers,oldmodifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
msg->FindInt32("be:old_modifiers",&oldmodifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_MODIFIERS_CHANGED);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(modifiers);
serverLink->Attach(oldmodifiers);
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
break;
}
default:
BWindow::MessageReceived(msg);
#ifdef ENABLE_INPUT_SERVER_EMULATION
if (!handle_message(fView->ServerLink(), msg))
#endif
BWindow::MessageReceived(msg);
break;
}
STRACE("CardWindow::MessageReceived() - exit\n");
}
// QuitRequested
@ -535,7 +300,7 @@ CardWindow::QuitRequested()
return false;
}
// MessageReceived
// SetBitmap
void
CardWindow::SetBitmap(const BBitmap* bitmap)
{
@ -908,9 +673,9 @@ ViewHWInterface::CopyBackToFront(const BRect& frame)
src += srcBPR;
}
}
// update the region on screen
fWindow->Invalidate(area);
}
// update the region on screen
fWindow->Invalidate(area);
return B_OK;
}

View File

@ -0,0 +1,295 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
// Distributed under the terms of the MIT license.
//
// File Name: fake_input_server_comm.cpp
// Authors: DarkWyrm <bpmagic@columbus.rr.com>
// Stephan Aßmus <superstippi@gmx.de>
// Description: implementing the fake input_server communication
// at a central place to avoid code duplication
//
//------------------------------------------------------------------------------
#include <InterfaceDefs.h>
#include <Message.h>
#include <OS.h>
#include <String.h>
#include "PortLink.h"
// These functions emulate the Input Server by sending the *exact* same kind of messages
// to the server's port.
// send_mouse_down
void
send_mouse_down(BPortLink* serverLink, BPoint pt,
BMessage* currentMessage)
{
// Attach 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
uint32 buttons, mod, clicks=1;
int64 time=(int64)real_time_clock();
currentMessage->FindPoint("where",&pt);
currentMessage->FindInt32("modifiers",(int32*)&mod);
currentMessage->FindInt32("buttons",(int32*)&buttons);
currentMessage->FindInt32("clicks",(int32*)&clicks);
serverLink->StartMessage(B_MOUSE_DOWN);
serverLink->Attach(&time, sizeof(int64));
serverLink->Attach(&pt.x,sizeof(float));
serverLink->Attach(&pt.y,sizeof(float));
serverLink->Attach(&mod, sizeof(uint32));
serverLink->Attach(&buttons, sizeof(uint32));
serverLink->Attach(&clicks, sizeof(uint32));
serverLink->Flush();
}
// send_mouse_moved
void
send_mouse_moved(BPortLink* serverLink, BPoint pt,
BMessage* currentMessage)
{
// Attach data:
// 1) int64 - time of mouse click
// 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click
// 4) int32 - buttons down
uint32 buttons;
int64 time=(int64)real_time_clock();
currentMessage->FindInt32("buttons", (int32*)&buttons);
serverLink->StartMessage(B_MOUSE_MOVED);
serverLink->Attach(&time,sizeof(int64));
serverLink->Attach(&pt.x,sizeof(float));
serverLink->Attach(&pt.y,sizeof(float));
serverLink->Attach(&buttons,sizeof(int32));
serverLink->Flush();
}
// send_mouse_moved
void
send_mouse_up(BPortLink* serverLink, BPoint pt,
BMessage* currentMessage)
{
// Attach 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
uint32 buttons, mod = modifiers();
int64 time=(int64)real_time_clock();
currentMessage->FindInt32("buttons", (int32*)&buttons);
serverLink->StartMessage(B_MOUSE_UP);
serverLink->Attach(&time, sizeof(int64));
serverLink->Attach(&pt.x,sizeof(float));
serverLink->Attach(&pt.y,sizeof(float));
serverLink->Attach(&mod, sizeof(uint32));
serverLink->Flush();
}
// handle_message
bool
handle_message(BPortLink* serverLink, BMessage* msg)
{
bool handled = true;
switch (msg->what)
{
case B_MOUSE_WHEEL_CHANGED:
{
float x,y;
msg->FindFloat("be:wheel_delta_x",&x);
msg->FindFloat("be:wheel_delta_y",&y);
int64 time=real_time_clock();
serverLink->StartMessage(B_MOUSE_WHEEL_CHANGED);
serverLink->Attach(&time,sizeof(int64));
serverLink->Attach(x);
serverLink->Attach(y);
serverLink->Flush();
break;
}
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) int8 number of bytes to follow containing the
// generated string
// 8) Character string generated by the keystroke
// 10) int8[16] state of all keys
bigtime_t systime;
int32 scancode, asciicode,repeatcount,modifiers;
int8 utf8data[4];
BString string;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
if(msg->FindInt32("be:key_repeat",&repeatcount)!=B_OK)
{
// TODO: see if repeatcount should be 0 or 1 when not repeating
repeatcount=1;
}
msg->FindInt32("modifiers",&modifiers);
msg->FindInt32("raw_char",&asciicode);
msg->FindInt8("byte",0,utf8data);
if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)
utf8data[1]=0;
if(msg->FindInt8("byte",2,utf8data+2)!=B_OK)
utf8data[2]=0;
if(msg->FindInt8("byte",3,utf8data+3)!=B_OK)
utf8data[3]=0;
msg->FindString("bytes",&string);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_KEY_DOWN);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(asciicode);
serverLink->Attach(repeatcount);
serverLink->Attach(modifiers);
serverLink->Attach(utf8data,sizeof(int8)*3);
serverLink->AttachString(string.String());
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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) int8 number of bytes to follow containing the
// generated string
// 7) Character string generated by the keystroke
// 8) int8[16] state of all keys
bigtime_t systime;
int32 scancode, asciicode,modifiers;
int8 utf8data[3];
BString string;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("raw_char",&asciicode);
msg->FindInt32("modifiers",&modifiers);
msg->FindInt8("byte",0,utf8data);
if(msg->FindInt8("byte",1,utf8data+1)!=B_OK)
utf8data[1]=0;
if(msg->FindInt8("byte",1,utf8data+2)!=B_OK)
utf8data[2]=0;
if(msg->FindInt8("byte",1,utf8data+3)!=B_OK)
utf8data[3]=0;
msg->FindString("bytes",&string);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_KEY_UP);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(asciicode);
serverLink->Attach(modifiers);
serverLink->Attach(utf8data,sizeof(int8)*3);
serverLink->AttachString(string.String());
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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[16] state of all keys
bigtime_t systime;
int32 scancode,modifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_UNMAPPED_KEY_DOWN);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(modifiers);
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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[16] state of all keys
bigtime_t systime;
int32 scancode,modifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_UNMAPPED_KEY_UP);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(modifiers);
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
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 systime;
int32 scancode,modifiers,oldmodifiers;
int8 keyarray[16];
systime=(int64)real_time_clock();
msg->FindInt32("key",&scancode);
msg->FindInt32("modifiers",&modifiers);
msg->FindInt32("be:old_modifiers",&oldmodifiers);
for(int8 i=0;i<15;i++)
msg->FindInt8("states",i,&keyarray[i]);
serverLink->StartMessage(B_MODIFIERS_CHANGED);
serverLink->Attach(&systime,sizeof(bigtime_t));
serverLink->Attach(scancode);
serverLink->Attach(modifiers);
serverLink->Attach(oldmodifiers);
serverLink->Attach(keyarray,sizeof(int8)*16);
serverLink->Flush();
break;
}
default:
handled = false;;
break;
}
return handled;
}

View File

@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// Copyright (c) 2005, Haiku, Inc.
// Distributed under the terms of the MIT license.
//
// File Name: fake_input_server.h
// Authors: Stephan Aßmus <superstippi@gmx.de>
// Description: prototypes for the fake input_server communication
//
//------------------------------------------------------------------------------
#ifndef FAKE_INPUT_SERVER_H
#define FAKE_INPUT_SERVER_H
#include <Point.h>
class BPortLink;
class BMessage;
void
send_mouse_down(BPortLink* serverLink, BPoint pt,
BMessage* currentMessage);
void
send_mouse_moved(BPortLink* serverLink, BPoint pt,
BMessage* currentMessage);
void
send_mouse_up(BPortLink* serverLink, BPoint pt,
BMessage* currentMessage);
bool
handle_message(BPortLink* serverLink, BMessage* msg);
#endif // FAKE_INPUT_SERVER_H