diff --git a/src/servers/app/server/AppServer.cpp b/src/servers/app/server/AppServer.cpp index e27ea64ae8..41da5e2564 100644 --- a/src/servers/app/server/AppServer.cpp +++ b/src/servers/app/server/AppServer.cpp @@ -26,15 +26,11 @@ //------------------------------------------------------------------------------ #include #include -#include #include #include #include -#include #include -#include - #include #include #include "AppServer.h" @@ -53,8 +49,17 @@ #include "Desktop.h" //#define DEBUG_KEYHANDLING +//#define DEBUG_SERVER + #ifdef DEBUG_KEYHANDLING # include +# define KBTRACE(x) printf x +#else +# define KBTRACE(x) ; +#endif + +#ifdef DEBUG_SERVER +# include # define STRACE(x) printf x #else # define STRACE(x) ; @@ -86,7 +91,7 @@ AppServer::AppServer(void) #endif { fMousePort= create_port(200,SERVER_INPUT_PORT); - _fMessagePort= create_port(200,SERVER_PORT_NAME); + fMessagePort= create_port(200,SERVER_PORT_NAME); fAppList= new BList(0); fQuittingServer= false; @@ -206,22 +211,23 @@ AppServer::~AppServer(void) int32 AppServer::PollerThread(void *data) { // This thread handles nothing but input messages for mouse and keyboard - AppServer *appserver=(AppServer*)data; - PortQueue mousequeue(appserver->fMousePort); - PortMessage *msg; - + AppServer *appserver=(AppServer*)data; + BPortLink mousequeue(-1,appserver->fMousePort); + int32 code=0; + status_t err=B_OK; + for(;;) { - if(!mousequeue.MessagesWaiting()) - mousequeue.GetMessagesFromPort(true); - else - mousequeue.GetMessagesFromPort(false); - - msg= mousequeue.GetMessageFromQueue(); - if(!msg) + STRACE(("info: AppServer::PollerThread listening on port %ld.\n", appserver->fMousePort)); + err=mousequeue.GetNextReply(&code); + + if(errCode()) + } + + 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 @@ -230,7 +236,7 @@ int32 AppServer::PollerThread(void *data) case B_MOUSE_UP: case B_MOUSE_WHEEL_CHANGED: case B_MOUSE_MOVED: - desktop->MouseEventHandler(msg); + desktop->MouseEventHandler(code,mousequeue); break; case B_KEY_DOWN: @@ -238,20 +244,18 @@ int32 AppServer::PollerThread(void *data) case B_UNMAPPED_KEY_DOWN: case B_UNMAPPED_KEY_UP: case B_MODIFIERS_CHANGED: - desktop->KeyboardEventHandler(msg); + desktop->KeyboardEventHandler(code,mousequeue); break; default: - printf("Server::Poller received unexpected code %lx\n",msg->Code()); + STRACE(("AppServer::Poller received unexpected code %lx\n",code)); break; } - delete msg; - if(appserver->fExitPoller) break; } - return 0; + return err; } /*! @@ -304,41 +308,45 @@ thread_id AppServer::Run(void) //! Main message-monitoring loop for the regular message port - no input messages! void AppServer::MainLoop(void) { - PortMessage pmsg; + BPortLink pmsg(-1,fMessagePort); + int32 code=0; + status_t err=B_OK; while(1) { - if(pmsg.ReadFromPort(_fMessagePort)== B_OK) - { - if(pmsg.Protocol()== B_QUIT_REQUESTED) - pmsg.SetCode(B_QUIT_REQUESTED); - - switch(pmsg.Code()) - { - case B_QUIT_REQUESTED: - case AS_CREATE_APP: - case AS_DELETE_APP: - case AS_GET_SCREEN_MODE: - case AS_UPDATED_CLIENT_FONTLIST: - case AS_QUERY_FONTS_CHANGED: - case AS_SET_UI_COLORS: - case AS_GET_UI_COLOR: - case AS_SET_DECORATOR: - case AS_GET_DECORATOR: - case AS_R5_SET_DECORATOR: - DispatchMessage(&pmsg); - break; - default: - { - printf("Server::MainLoop received unexpected code %ld(offset %ld)\n", - pmsg.Code(),pmsg.Code()-SERVER_TRUE); - break; - } - } + STRACE(("info: AppServer::MainLoop listening on port %ld.\n", fMessagePort)); + err=pmsg.GetNextReply(&code); + if(errCountItems()== 0) break; @@ -384,13 +392,14 @@ bool AppServer::LoadDecorator(const char *path) // Get the instantiation function stat= get_image_symbol(addon, "instantiate_decorator", B_SYMBOL_TYPE_TEXT, (void**)&pcreatefunc); - if(stat != B_OK){ + if(stat != B_OK) + { unload_add_on(addon); return false; } - BPath temppath(path); - fDecoratorName= temppath.Leaf(); + BPath temppath(path); + fDecoratorName=temppath.Leaf(); acquire_sem(fDecoratorLock); make_decorator=pcreatefunc; @@ -436,12 +445,12 @@ void AppServer::InitDecorators(void) /*! \brief Message handling function for all messages sent to the app_server \param code ID of the message sent - \param buffer Attachement buffer for the message. + \param buffer Attachment buffer for the message. */ -void AppServer::DispatchMessage(PortMessage *msg) +void AppServer::DispatchMessage(int32 code, BPortLink &msg) { - switch(msg->Code()) + switch(code) { case AS_CREATE_APP: { @@ -456,45 +465,47 @@ void AppServer::DispatchMessage(PortMessage *msg) // 5) port_id - port to reply to // Find the necessary data - team_id clientTeamID; - port_id clientLooperPort; - port_id reply_port; - port_id app_port; - int32 htoken; - char* app_signature; + team_id clientTeamID=-1; + port_id clientLooperPort=-1; + port_id reply_port=-1; // TODO: deprecated + port_id app_port=-1; + int32 htoken=B_NULL_TOKEN; + char *app_signature=NULL; - msg->Read(&app_port); - msg->Read(&clientLooperPort); - msg->Read(&clientTeamID); - msg->Read(&htoken); - msg->ReadString(&app_signature); - msg->Read(&reply_port); + msg.Read(&app_port); + msg.Read(&clientLooperPort); + msg.Read(&clientTeamID); + msg.Read(&htoken); + msg.ReadString(&app_signature); + msg.Read(&reply_port); // Create the ServerApp subthread for this app acquire_sem(fAppListLock); - port_id r= create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature); - if(r== B_NO_MORE_PORTS || r== B_BAD_VALUE) + port_id server_listen=create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature); + if(server_listenAddItem(newapp); release_sem(fAppListLock); - PortLink replylink(reply_port); - replylink.SetOpCode(AS_SET_SERVER_PORT); + BPortLink replylink(reply_port); + replylink.StartMessage(AS_SET_SERVER_PORT); replylink.Attach(newapp->fMessagePort); replylink.Flush(); - // This is necessary because PortLink::ReadString allocates memory - delete app_signature; + // This is necessary because BPortLink::ReadString allocates memory + if(app_signature) + free(app_signature); break; } @@ -506,12 +517,14 @@ void AppServer::DispatchMessage(PortMessage *msg) // Attached Data: // 1) thread_id - thread ID of the ServerApp to be deleted - int32 i, - appnum= fAppList->CountItems(); - ServerApp *srvapp; + int32 i=0, + appnum=fAppList->CountItems(); + + ServerApp *srvapp=NULL; + thread_id srvapp_id=-1; - thread_id srvapp_id; - msg->Read(&srvapp_id); + if(msg.Read(&srvapp_id)fMonitorThreadID== srvapp_id) { srvapp=(ServerApp *)fAppList->RemoveItem(i); - if(srvapp){ + if(srvapp) + { status_t temp; wait_for_thread(srvapp_id, &temp); delete srvapp; @@ -557,12 +571,15 @@ void AppServer::DispatchMessage(PortMessage *msg) bool needs_update=fontserver->FontsNeedUpdated(); fontserver->Unlock(); - // Seeing how the client merely wants an answer, we'll skip the PortLink + // Seeing how the client merely wants an answer, we'll skip the BPortLink // and all its overhead and just write the code to port. port_id replyport; - msg->Read(&replyport); + if (msg.Read(&replyport) < B_OK) + break; + BPortLink replylink(replyport); + replylink.StartMessage(needs_update ? SERVER_TRUE : SERVER_FALSE); + replylink.Flush(); - write_port(replyport, (needs_update)?SERVER_TRUE:SERVER_FALSE, NULL,0); break; } case AS_SET_UI_COLORS: @@ -574,7 +591,7 @@ void AppServer::DispatchMessage(PortMessage *msg) // 1) ColorSet new colors to use gui_colorset.Lock(); - msg->Read(&gui_colorset); + msg.Read(&gui_colorset); gui_colorset.Unlock(); Broadcast(AS_UPDATE_COLORS); break; @@ -587,8 +604,8 @@ void AppServer::DispatchMessage(PortMessage *msg) // Attached Data: // char * name of the decorator in the decorators path to use - char *decname; - msg->ReadString(&decname); + char *decname=NULL; + msg.ReadString(&decname); if(decname) { if(strcmp(decname,"Default")!=0) @@ -605,7 +622,7 @@ void AppServer::DispatchMessage(PortMessage *msg) Broadcast(AS_UPDATE_DECORATOR); } } - delete decname; + free(decname); break; } @@ -614,10 +631,12 @@ void AppServer::DispatchMessage(PortMessage *msg) // Attached Data: // 1) port_id reply port - port_id replyport; - msg->Read(&replyport); - PortLink replylink(replyport); - replylink.SetOpCode(AS_GET_DECORATOR); + port_id replyport=-1; + if(msg.Read(&replyport)Read(&decindex); + int32 decindex=0; + if(msg.Read(&decindex)GetMode(&dmode); - port_id replyport; - msg->Read(&replyport); + port_id replyport=-1; + if(msg.Read(&replyport)(dmode); replylink.Flush(); break; diff --git a/src/servers/app/server/AppServer.h b/src/servers/app/server/AppServer.h index eb377bb504..7c3df3205e 100644 --- a/src/servers/app/server/AppServer.h +++ b/src/servers/app/server/AppServer.h @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "Decorator.h" #include "ServerConfig.h" @@ -17,7 +16,6 @@ class ServerApp; class DisplayDriver; class CursorManager; class BitmapManager; -class PortMessage; /*! \class AppServer AppServer.h @@ -45,7 +43,7 @@ public: bool LoadDecorator(const char *path); void InitDecorators(void); - void DispatchMessage(PortMessage *msg); + void DispatchMessage(int32 code, BPortLink &link); void Broadcast(int32 code); ServerApp* FindApp(const char *sig); @@ -57,7 +55,7 @@ private: // global function pointer create_decorator *make_decorator; - port_id _fMessagePort, + port_id fMessagePort, fMousePort; image_id fDecoratorID; diff --git a/src/servers/app/server/Desktop.cpp b/src/servers/app/server/Desktop.cpp index 3a42d4607d..70cffd0de6 100644 --- a/src/servers/app/server/Desktop.cpp +++ b/src/servers/app/server/Desktop.cpp @@ -35,7 +35,6 @@ #include "DisplayDriver.h" #include "Globals.h" #include "Layer.h" -#include "PortMessage.h" #include "RootLayer.h" #include "ServerConfig.h" #include "ServerScreen.h" @@ -259,14 +258,6 @@ void Desktop::AddWinBorder(WinBorder* winBorder) // other windows are added to the current RootLayer only. ActiveRootLayer()->AddWinBorder(winBorder); - // TODO: try to unify this code with that for B_MOUSE_DOWN - winBorder->Window()->Lock(); - BRegion invalidRegion; - invalidRegion.Include(&(winBorder->fFull)); - invalidRegion.Include(&(winBorder->fTopLayer->fFull)); - winBorder->fParent->RebuildAndForceRedraw(invalidRegion, winBorder); - winBorder->Window()->Unlock(); - // add that pointer to user winboder list so that we can keep track of them. fLayerLock.Lock(); fWinBorderList.AddItem(winBorder); @@ -302,10 +293,10 @@ bool Desktop::HasWinBorder(WinBorder* winBorder) //--------------------------------------------------------------------------- // Input related methods //--------------------------------------------------------------------------- -void Desktop::MouseEventHandler(PortMessage *msg) +void Desktop::MouseEventHandler(int32 code, BPortLink& msg) { // TODO: locking mechanism needs SERIOUS rethought - switch(msg->Code()) + switch(code) { case B_MOUSE_DOWN: { @@ -317,24 +308,24 @@ void Desktop::MouseEventHandler(PortMessage *msg) // 5) int32 - buttons down // 6) int32 - clicks - BPoint pt; - int64 dummy; + 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); - msg->Read(&dummy); - msg->Read(&pt.x); - msg->Read(&pt.y); + // printf("MOUSE DOWN: at (%f, %f)\n", evt.where.x, evt.where.y); - // After we read the data, we need to reset it for MouseDown() - msg->Rewind(); - - // printf("MOUSE DOWN: at (%f, %f)\n", pt.x, pt.y); - - WinBorder *target; - RootLayer *rl; - Workspace *ws; + WinBorder *target=NULL; + RootLayer *rl=NULL; + Workspace *ws=NULL + ; rl = ActiveRootLayer(); ws = rl->ActiveWorkspace(); - target = rl->WinBorderAt(pt); + target = rl->WinBorderAt(evt.where); if (target) { fGeneralLock.Lock(); @@ -346,8 +337,8 @@ printf("Focus: %s\n", ws->FocusLayer()->GetName()); #endif if (target != ws->FrontLayer()) { - WinBorder *previousFocus; - WinBorder *activeFocus; + WinBorder *previousFocus=NULL; + WinBorder *activeFocus=NULL; BRegion invalidRegion; ws->BringToFrontANormalWindow(target); @@ -359,12 +350,13 @@ printf("Focus: %s\n", ws->FocusLayer()->GetName()); activeFocus->Window()->Lock(); if (target == activeFocus && target->Window()->Flags() & B_WILL_ACCEPT_FIRST_CLICK) - target->MouseDown(msg, true); + target->MouseDown(evt, true); else - target->MouseDown(msg, false); + target->MouseDown(evt, false); // may be or may be empty. -// TODO: what if modal of floating windows are in front of us? + + // TODO: what if modal of floating windows are in front of us? invalidRegion.Include(&(activeFocus->fFull)); invalidRegion.Include(&(activeFocus->fTopLayer->fFull)); activeFocus->fParent->RebuildAndForceRedraw(invalidRegion, activeFocus); @@ -394,7 +386,7 @@ printf("2Focus: %s\n", ws->FocusLayer()->GetName()); if (target == ws->FocusLayer()) { target->Window()->Lock(); - target->MouseDown(msg, true); + target->MouseDown(evt, true); target->Window()->Unlock(); } } @@ -415,37 +407,32 @@ printf("2Focus: %s\n", ws->FocusLayer()->GetName()); // 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); + if (fMouseTarget) { fMouseTarget->Window()->Lock(); - fMouseTarget->MouseUp(msg); + fMouseTarget->MouseUp(evt); fMouseTarget->Window()->Unlock(); fMouseTarget = NULL; } else { - BPoint pt; - int64 dummy; - int32 mod; - - msg->Read(&dummy); - msg->Read(&pt.x); - msg->Read(&pt.y); - msg->Read(&mod); - - // After we read the data, we need to reset it for MouseUp() - msg->Rewind(); - - WinBorder *target = ActiveRootLayer()->WinBorderAt(pt); + WinBorder *target = ActiveRootLayer()->WinBorderAt(evt.where); if(target){ target->Window()->Lock(); - target->MouseUp(msg); + target->MouseUp(evt); target->Window()->Unlock(); } } - // printf("MOUSE UP: at (%f, %f)\n", pt.x, pt.y); + STRACE(("MOUSE UP: at (%f, %f)\n", evt.where.x, evt.where.y)); break; } @@ -456,45 +443,50 @@ printf("2Focus: %s\n", ws->FocusLayer()->GetName()); // 2) float - x coordinate of mouse click // 3) float - y coordinate of mouse click // 4) int32 - buttons down - int64 dummy; - float x,y; - int32 buttons; - msg->Read(&dummy); - msg->Read(&x); - msg->Read(&y); - msg->Read(&buttons); - - // After we read the data, we need to reset it for MouseDown() - msg->Rewind(); + 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); if (fMouseTarget) { fActiveScreen->DDriver()->HideCursor(); - fActiveScreen->DDriver()->MoveCursorTo(x,y); + fActiveScreen->DDriver()->MoveCursorTo(evt.where.x, evt.where.y); fMouseTarget->Window()->Lock(); - fMouseTarget->MouseMoved(msg); + fMouseTarget->MouseMoved(evt); fMouseTarget->Window()->Unlock(); fActiveScreen->DDriver()->ShowCursor(); } else { - WinBorder *target = ActiveRootLayer()->WinBorderAt(BPoint(x,y)); + WinBorder *target = ActiveRootLayer()->WinBorderAt(BPoint(evt.where.x, evt.where.y)); if(target){ target->Window()->Lock(); - target->MouseMoved(msg); + target->MouseMoved(evt); target->Window()->Unlock(); } - fActiveScreen->DDriver()->MoveCursorTo(x,y); + fActiveScreen->DDriver()->MoveCursorTo(evt.where.x, evt.where.y); } break; } case B_MOUSE_WHEEL_CHANGED: { + PointerEvent evt; + evt.code = B_MOUSE_WHEEL_CHANGED; + msg.Read(&evt.when); + msg.Read(&evt.where.x); + msg.Read(&evt.where.y); + msg.Read(&evt.wheel_delta_x); + msg.Read(&evt.wheel_delta_y); + msg.Read(&evt.modifiers); + // TODO: Pass this on to the client ServerWindow break; } @@ -506,11 +498,10 @@ printf("2Focus: %s\n", ws->FocusLayer()->GetName()); } } -void Desktop::KeyboardEventHandler(PortMessage *msg) +void Desktop::KeyboardEventHandler(int32 code, BPortLink& msg) { - int8 *index=(int8*)msg->Buffer(); - - switch(msg->Code()) + + switch(code) { case B_KEY_DOWN: { @@ -525,13 +516,22 @@ void Desktop::KeyboardEventHandler(PortMessage *msg) // generated string // 8) Character string generated by the keystroke // 9) int8[16] state of all keys - - // Obtain only what data which we'll need - STRACE(("Key Down: 0x%lx\n",scancode)); - index+=sizeof(int64); - int32 scancode=*((int32*)index); index+=sizeof(int32) * 3; - int32 modifiers=*((int32*)index); index+=sizeof(int32) + (sizeof(int8) * 3); - int8 stringlength=*index; index+=stringlength; + + bigtime_t time; + int32 scancode, modifiers; + int8 utf[3]; + char *string = NULL; + int32 keystate; + + msg.Read(&time); + msg.Read(&scancode); + msg.Read(&modifiers); + msg.Read(utf, sizeof(utf)); + msg.ReadString(&string); + msg.Read(&keystate); + if (string) + free(string); + if(DISPLAYDRIVER==HWDRIVER) { // Check for workspace change or safe video mode @@ -669,11 +669,26 @@ void Desktop::KeyboardEventHandler(PortMessage *msg) // 7) Character string generated by the keystroke // 8) int8[16] state of all keys - // Obtain only what data which we'll need - index+=sizeof(int64); - int32 scancode=*((int32*)index); index+=sizeof(int32) * 3; - int32 modifiers=*((int32*)index); index+=sizeof(int8) * 3; - int8 stringlength=*index; index+=stringlength + sizeof(int8); + bigtime_t time; + int32 scancode; + int32 ascii; + int32 modifiers; + int8 utf[3]; + int8 bytes; + char *string; + int8 keystate[16]; + + msg.Read(&time); + msg.Read(&scancode); + msg.Read(&ascii); + msg.Read(&modifiers); + msg.Read(utf, sizeof(utf)); + msg.Read(&bytes); + msg.ReadString(&string); + msg.Read(keystate, sizeof(keystate)); + if (string) + free(string); + STRACE(("Key Up: 0x%lx\n",scancode)); if(DISPLAYDRIVER==HWDRIVER) @@ -717,9 +732,20 @@ void Desktop::KeyboardEventHandler(PortMessage *msg) // 4) int32 number of elements in the key state array to follow // 5) int8 state of all keys + bigtime_t time; + int32 scancode; + int32 modifiers; + int32 elements; + //int8 keystate[16]; + + msg.Read(&time); + msg.Read(&scancode); + msg.Read(&modifiers); + msg.Read(&elements); + //msg.Read(keystate, elements); + #ifdef DEBUG_KEYHANDLING - index+=sizeof(bigtime_t); - printf("Unmapped Key Down: 0x%lx\n",*((int32*)index)); + printf("Unmapped Key Down: 0x%lx\n", scancode); #endif // TODO: Pass on to client window with the focus break; @@ -733,9 +759,20 @@ void Desktop::KeyboardEventHandler(PortMessage *msg) // 4) int32 number of elements in the key state array to follow // 5) int8 state of all keys + bigtime_t time; + int32 scancode; + int32 modifiers; + int32 elements; + //int8 keystate[16]; + + msg.Read(&time); + msg.Read(&scancode); + msg.Read(&modifiers); + msg.Read(&elements); + //msg.Read(keystate, elements); + #ifdef DEBUG_KEYHANDLING - index+=sizeof(bigtime_t); - printf("Unmapped Key Up: 0x%lx\n",*((int32*)index)); + printf("Unmapped Key Up: 0x%lx\n", scancode); #endif // TODO: Pass on to client window with the focus @@ -750,8 +787,19 @@ void Desktop::KeyboardEventHandler(PortMessage *msg) // 4) int32 number of elements in the key state array to follow // 5) int8 state of all keys + bigtime_t time; + int32 scancode; + int32 modifiers; + int32 elements; + //int8 keystate[16]; + + msg.Read(&time); + msg.Read(&scancode); + msg.Read(&modifiers); + msg.Read(&elements); + //msg.Read(keystate, elements); + #ifdef DEBUG_KEYHANDLING - index+=sizeof(bigtime_t); printf("Modifiers Changed\n"); #endif diff --git a/src/servers/app/server/Desktop.h b/src/servers/app/server/Desktop.h index 4a7365e92e..29c9b818cb 100644 --- a/src/servers/app/server/Desktop.h +++ b/src/servers/app/server/Desktop.h @@ -36,9 +36,9 @@ class RootLayer; class Screen; class Layer; class BMessage; -class PortMessage; class WinBorder; class DisplayDriver; +class BPortLink; class Desktop { @@ -70,8 +70,8 @@ public: bool HasWinBorder(WinBorder *winBorder); // Input related methods - void MouseEventHandler(PortMessage *msg); - void KeyboardEventHandler(PortMessage *msg); + void MouseEventHandler(int32 code, BPortLink& link); + void KeyboardEventHandler(int32 code, BPortLink& link); void SetDragMessage(BMessage *msg); BMessage *DragMessage(void) const; diff --git a/src/servers/app/server/DirectDriver.cpp b/src/servers/app/server/DirectDriver.cpp index e666669659..66b03f1b51 100644 --- a/src/servers/app/server/DirectDriver.cpp +++ b/src/servers/app/server/DirectDriver.cpp @@ -798,7 +798,7 @@ DDView::DDView(BRect bounds) SetViewColor(B_TRANSPARENT_32_BIT); #ifdef ENABLE_INPUT_SERVER_EMULATION - serverlink.SetPort(find_port(SERVER_INPUT_PORT)); + serverlink.SetSendPort(find_port(SERVER_INPUT_PORT)); #endif } @@ -827,7 +827,7 @@ void DDView::MouseDown(BPoint pt) GetMouse(&p,&buttons); - serverlink.SetOpCode(B_MOUSE_DOWN); + serverlink.StartMessage(B_MOUSE_DOWN); serverlink.Attach(&time, sizeof(int64)); serverlink.Attach(&pt.x,sizeof(float)); serverlink.Attach(&pt.y,sizeof(float)); @@ -850,7 +850,7 @@ void DDView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg) uint32 buttons; int64 time=(int64)real_time_clock(); - serverlink.SetOpCode(B_MOUSE_MOVED); + serverlink.StartMessage(B_MOUSE_MOVED); serverlink.Attach(&time,sizeof(int64)); serverlink.Attach(&pt.x,sizeof(float)); serverlink.Attach(&pt.y,sizeof(float)); @@ -877,7 +877,7 @@ void DDView::MouseUp(BPoint pt) GetMouse(&p,&buttons); - serverlink.SetOpCode(B_MOUSE_UP); + serverlink.StartMessage(B_MOUSE_UP); serverlink.Attach(&time, sizeof(int64)); serverlink.Attach(&pt.x,sizeof(float)); serverlink.Attach(&pt.y,sizeof(float)); @@ -897,7 +897,7 @@ void DDView::MessageReceived(BMessage *msg) msg->FindFloat("be:wheel_delta_x",&x); msg->FindFloat("be:wheel_delta_y",&y); int64 time=real_time_clock(); - serverlink.SetOpCode(B_MOUSE_WHEEL_CHANGED); + serverlink.StartMessage(B_MOUSE_WHEEL_CHANGED); serverlink.Attach(&time,sizeof(int64)); serverlink.Attach(x); serverlink.Attach(y); diff --git a/src/servers/app/server/DirectDriver.h b/src/servers/app/server/DirectDriver.h index 3e02f97ab6..b5723bf7ca 100644 --- a/src/servers/app/server/DirectDriver.h +++ b/src/servers/app/server/DirectDriver.h @@ -73,7 +73,7 @@ public: void MouseUp(BPoint pt); void MessageReceived(BMessage *msg); - PortLink serverlink; + BPortLink serverlink; }; class DDWindow : public BDirectWindow @@ -162,7 +162,7 @@ protected: rgb_color GetBlitColor(rgb_color src, rgb_color dest,DrawData *d, bool use_high=true); - PortLink *serverlink; + BPortLink *serverlink; DDWindow *screenwin; BView *drawview; }; diff --git a/src/servers/app/server/Jamfile b/src/servers/app/server/Jamfile index ca0fd59b6a..66245148e9 100644 --- a/src/servers/app/server/Jamfile +++ b/src/servers/app/server/Jamfile @@ -40,7 +40,6 @@ Server app_server : FMWList.cpp PicturePlayer.cpp PNGDump.cpp - SessionStreamReader.cpp Utils.cpp # Manager Classes diff --git a/src/servers/app/server/Layer.cpp b/src/servers/app/server/Layer.cpp index 3f99b0ce56..5eb1884b2a 100644 --- a/src/servers/app/server/Layer.cpp +++ b/src/servers/app/server/Layer.cpp @@ -44,7 +44,7 @@ Layer::Layer(BRect frame, const char *name, int32 token, uint32 resize, fBoundsLeftTop.Set( 0.0f, 0.0f ); - fName = new BString(name); + fName = new BString(name ? name : B_EMPTY_STRING); fLayerData = new LayerData(); // driver init @@ -65,7 +65,6 @@ Layer::Layer(BRect frame, const char *name, int32 token, uint32 resize, fFlags = flags; fAdFlags = 0; fClassID = AS_LAYER_CLASS; - fFrameAction = B_LAYER_NONE; fResizeMode = resize; fHidden = false; @@ -446,15 +445,7 @@ void Layer::RequestDraw(const BRegion ®, Layer *startFrom) int redraw = false; if (startFrom == NULL) redraw = true; -/* -srand(real_time_clock_usecs()); -RGBColor c(rand()/256,34,56); -BRegion reg1 = reg; -fDriver->ConstrainClippingRegion(®1); -fDriver->FillRect(reg.Frame(), c); -fDriver->ConstrainClippingRegion(NULL); -snooze(1000000); -*/ + if (fVisible.CountRects() > 0) { // client side drawing. Send only one UPDATE message! @@ -465,7 +456,7 @@ snooze(1000000); // calculate the minimum region/rectangle to be updated with // a single message to the client. fUpdateReg = fFullVisible; - if (fFlags & B_FULL_UPDATE_ON_RESIZE && fFrameAction == B_LAYER_RESIZE){ } + if (fFlags & B_FULL_UPDATE_ON_RESIZE){ } else { fUpdateReg.IntersectWith(®); } if (fUpdateReg.CountRects() > 0) @@ -479,7 +470,7 @@ snooze(1000000); // calculate the update region, then... fUpdateReg = fVisible; - if (fFlags & B_FULL_UPDATE_ON_RESIZE && fFrameAction == B_LAYER_RESIZE){ } + if (fFlags & B_FULL_UPDATE_ON_RESIZE){ } else { fUpdateReg.IntersectWith(®); } if (fUpdateReg.CountRects() > 0) @@ -495,7 +486,7 @@ snooze(1000000); else { fUpdateReg = fVisible; - if (fFlags & B_FULL_UPDATE_ON_RESIZE && fFrameAction == B_LAYER_RESIZE){ } + if (fFlags & B_FULL_UPDATE_ON_RESIZE){ } else { fUpdateReg.IntersectWith(®); } if (fUpdateReg.CountRects() > 0) @@ -534,6 +525,7 @@ snooze(1000000); void Layer::Draw(const BRect &r) { // TODO/NOTE: this should be an empty method! the next lines are for testing only + #ifdef DEBUG_LAYER printf("Layer::Draw: "); r.PrintToStream(); @@ -1022,9 +1014,7 @@ void Layer::MoveBy(float x, float y) debugger("ERROR: in Layer::MoveBy()! - No parent!\n"); return; } - - fFrameAction = B_LAYER_MOVE; - + BPoint pt(x,y); BRect rect(fFull.Frame().OffsetByCopy(pt)); @@ -1034,8 +1024,6 @@ void Layer::MoveBy(float x, float y) EmptyGlobals(); - fFrameAction = B_LAYER_NONE; - STRACE(("Layer(%s)::MoveBy() END\n", GetName())); } @@ -1127,9 +1115,7 @@ void Layer::ResizeBy(float x, float y) printf("ERROR: in Layer::MoveBy()! - No parent!\n"); return; } - - fFrameAction = B_LAYER_RESIZE; - + BPoint pt(x,y); BRect rect(fFull.Frame()); rect.right += x; @@ -1141,9 +1127,7 @@ void Layer::ResizeBy(float x, float y) fParent->Redraw(gRedrawReg, this); EmptyGlobals(); - - fFrameAction = B_LAYER_NONE; - + STRACE(("Layer(%s)::ResizeBy() END\n", GetName())); } @@ -1174,7 +1158,7 @@ void Layer::PrintToStream(void) printf("Frame: (%f, %f, %f, %f)", fFrame.left, fFrame.top, fFrame.right, fFrame.bottom); printf("Token: %ld\n",fViewToken); - printf("Hidden - direct: %s\n", IsHidden()?"true":"false"); + printf("Hidden - direct: %s\n", fHidden?"true":"false"); printf("Hidden - indirect: %s\n", IsHidden()?"true":"false"); printf("ResizingMode: %lx\n", fResizeMode); printf("Flags: %lx\n", fFlags); diff --git a/src/servers/app/server/ScreenDriver.h b/src/servers/app/server/ScreenDriver.h index b0464e3546..671305521e 100644 --- a/src/servers/app/server/ScreenDriver.h +++ b/src/servers/app/server/ScreenDriver.h @@ -43,7 +43,7 @@ #include "PatternHandler.h" class BBitmap; -class PortLink; +class BPortLink; class SDWindow; class LayerData; class ScreenDriver; @@ -65,7 +65,7 @@ protected: friend class ScreenDriver; bool is_connected; - PortLink *serverlink; + BPortLink *serverlink; BPoint mousepos; uint32 buttons; thread_id monitor_thread,copy_thread; @@ -89,7 +89,7 @@ public: void MessageReceived(BMessage *msg); BBitmap *viewbmp; - PortLink *serverlink; + BPortLink *serverlink; int hide_cursor; BBitmap *cursor; @@ -192,7 +192,7 @@ protected: BBitmap *framebuffer; BView *drawview; BRegion laregion; - PortLink *serverlink; + BPortLink *serverlink; rgb_color highcolor,lowcolor; bool is_initialized; diff --git a/src/servers/app/server/ServerApp.cpp b/src/servers/app/server/ServerApp.cpp index 5269b9d088..5fa921abee 100644 --- a/src/servers/app/server/ServerApp.cpp +++ b/src/servers/app/server/ServerApp.cpp @@ -28,12 +28,7 @@ #include #include #include -#include -#include #include - -#include - #include #include #include @@ -91,11 +86,12 @@ ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort // fClientAppPort is the our BApplication's event port fClientAppPort=sendport; - fAppLink=new PortLink(fClientAppPort); // fMessagePort is the port we receive messages from our BApplication fMessagePort=rcvport; + fAppLink = new BPortLink(fClientAppPort, fMessagePort); + fSWindowList=new BList(0); fBitmapList=new BList(0); fPictureList=new BList(0); @@ -246,8 +242,8 @@ bool ServerApp::PingTarget(void) printf("PANIC: ServerApp %s could not find the app_server port in PingTarget()!\n",fSignature.String()); return false; } - fAppLink->SetPort(serverport); - fAppLink->SetOpCode(AS_DELETE_APP); + fAppLink->SetSendPort(serverport); + fAppLink->StartMessage(AS_DELETE_APP); fAppLink->Attach(&fMonitorThreadID,sizeof(thread_id)); fAppLink->Flush(); return false; @@ -336,22 +332,19 @@ int32 ServerApp::MonitorApp(void *data) // Message-dispatching loop for the ServerApp ServerApp *app = (ServerApp *)data; - PortQueue msgqueue(app->fMessagePort); - PortMessage *msg; + BPortLink msgqueue(-1, app->fMessagePort); bool quitting = false; + int32 code; + status_t err = B_OK; - for( ; !quitting; ) + while(!quitting) { - if(!msgqueue.MessagesWaiting()) - msgqueue.GetMessagesFromPort(true); - else - msgqueue.GetMessagesFromPort(false); + STRACE(("info: ServerApp::MonitorApp listening on port %ld.\n", app->fMessagePort)); + err = msgqueue.GetNextReply(&code); + if (err < B_OK) + break; - msg = msgqueue.GetMessageFromQueue(); - if(!msg) - continue; - - switch(msg->Code()) + switch(code) { case AS_QUIT_APP: { @@ -400,8 +393,8 @@ int32 ServerApp::MonitorApp(void *data) printf("PANIC: ServerApp %s could not find the app_server port!\n",app->fSignature.String()); break; } - app->fAppLink->SetPort(serverport); - app->fAppLink->SetOpCode(AS_DELETE_APP); + app->fAppLink->SetSendPort(serverport); + app->fAppLink->StartMessage(AS_DELETE_APP); app->fAppLink->Attach(&app->fMonitorThreadID, sizeof(thread_id)); app->fAppLink->Flush(); break; @@ -409,12 +402,11 @@ int32 ServerApp::MonitorApp(void *data) default: { STRACE(("ServerApp %s: Got a Message to dispatch\n",app->fSignature.String())); - app->_DispatchMessage(msg); + app->_DispatchMessage(code, msgqueue); break; } } - delete msg; } // end for // clean exit. @@ -430,10 +422,10 @@ int32 ServerApp::MonitorApp(void *data) All attachments are placed in the buffer via a PortLink, so it will be a matter of casting and incrementing an index variable to access them. */ -void ServerApp::_DispatchMessage(PortMessage *msg) +void ServerApp::_DispatchMessage(int32 code, BPortLink& msg) { LayerData ld; - switch(msg->Code()) + switch(code) { case AS_UPDATED_CLIENT_FONTLIST: { @@ -460,7 +452,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg) win=(ServerWindow*)fSWindowList->ItemAt(i); win->Lock(); win->fWinBorder->UpdateColors(); - win->SendMessageToClient(&msg); + win->SendMessageToClient(AS_UPDATE_COLORS, msg); win->Unlock(); } */ break; @@ -479,7 +471,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg) win=(ServerWindow*)fSWindowList->ItemAt(i); win->Lock(); win->fWinBorder->UpdateFont(); - win->SendMessageToClient(&msg); + win->SendMessageToClient(AS_UPDATE_FONTS, msg); win->Unlock(); } */ break; @@ -518,22 +510,24 @@ void ServerApp::_DispatchMessage(PortMessage *msg) uint32 feel; uint32 flags; uint32 wkspaces; - int32 token; - port_id sendPort; - port_id looperPort; - port_id replyport; - char *title; + int32 token = B_NULL_TOKEN; + port_id sendPort = -1; + port_id looperPort = -1; + char *title = NULL; + port_id replyport = -1; - msg->Read(&frame); - msg->Read((int32*)&look); - msg->Read((int32*)&feel); - msg->Read((int32*)&flags); - msg->Read((int32*)&wkspaces); - msg->Read(&token); - msg->Read(&sendPort); - msg->Read(&looperPort); - msg->ReadString(&title); - msg->Read(&replyport); + msg.Read(&frame); + msg.Read((int32*)&look); + msg.Read((int32*)&feel); + msg.Read((int32*)&flags); + msg.Read((int32*)&wkspaces); + msg.Read(&token); + msg.Read(&sendPort); + msg.Read(&looperPort); + msg.ReadString(&title); + + //TODO: deprecate - just use sendPort + msg.Read(&replyport); STRACE(("ServerApp %s: Got 'New Window' message, trying to do smething...\n",fSignature.String())); @@ -546,7 +540,8 @@ void ServerApp::_DispatchMessage(PortMessage *msg) STRACE(("\nServerApp %s: New Window %s (%.1f,%.1f,%.1f,%.1f)\n", fSignature.String(),title,frame.left,frame.top,frame.right,frame.bottom)); - delete [] title; + if (title) + free(title); break; } @@ -570,40 +565,39 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // 3) int32 area pointer offset used to calculate fBasePtr // First, let's attempt to allocate the bitmap - port_id replyport; + port_id replyport = -1; BRect r; color_space cs; int32 f,bpr; screen_id s; - msg->Read(&r); - msg->Read(&cs); - msg->Read(&f); - msg->Read(&bpr); - msg->Read(&s); - msg->Read(&replyport); + msg.Read(&r); + msg.Read(&cs); + msg.Read(&f); + msg.Read(&bpr); + msg.Read(&s); + msg.Read(&replyport); ServerBitmap *sbmp=bitmapmanager->CreateBitmap(r,cs,f,bpr,s); STRACE(("ServerApp %s: Create Bitmap (%.1f,%.1f,%.1f,%.1f)\n", fSignature.String(),r.left,r.top,r.right,r.bottom)); + BPortLink replylink(replyport); if(sbmp) { fBitmapList->AddItem(sbmp); - PortLink replylink(replyport); - replylink.SetOpCode(SERVER_TRUE); + replylink.StartMessage(SERVER_TRUE); replylink.Attach(sbmp->Token()); replylink.Attach(sbmp->Area()); replylink.Attach(sbmp->AreaOffset()); - replylink.Flush(); } else { // alternatively, if something went wrong, we reply with SERVER_FALSE - int32 code=SERVER_FALSE; - write_port(replyport,SERVER_FALSE,&code,sizeof(int32)); + replylink.StartMessage(SERVER_FALSE); } + replylink.Flush(); break; } @@ -618,24 +612,25 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // Reply Code: SERVER_TRUE if successful, // SERVER_FALSE if the buffer was already deleted or was not found - port_id replyport; + port_id replyport = -1; int32 bmp_id; - msg->Read(&bmp_id); - msg->Read(&replyport); + msg.Read(&bmp_id); + msg.Read(&replyport); ServerBitmap *sbmp=FindBitmap(bmp_id); + BPortLink replylink(replyport); if(sbmp) { STRACE(("ServerApp %s: Deleting Bitmap %ld\n",fSignature.String(),bmp_id)); fBitmapList->RemoveItem(sbmp); bitmapmanager->DeleteBitmap(sbmp); - write_port(replyport,SERVER_TRUE,NULL,0); + replylink.StartMessage(SERVER_TRUE); } else - write_port(replyport,SERVER_FALSE,NULL,0); - + replylink.StartMessage(SERVER_TRUE); + replylink.Flush(); break; } case AS_CREATE_PICTURE: @@ -677,9 +672,9 @@ void ServerApp::_DispatchMessage(PortMessage *msg) int32 workspace; uint32 mode; bool stick; - msg->Read(&workspace); - msg->Read(&mode); - msg->Read(&stick); + msg.Read(&workspace); + msg.Read(&mode); + msg.Read(&stick); //TODO: Resolve //SetSpace(workspace,mode,ActiveScreen(),stick); @@ -694,7 +689,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // Error-checking is done in ActivateWorkspace, so this is a safe call int32 workspace; - msg->Read(&workspace); + msg.Read(&workspace); //TODO: Resolve //SetWorkspace(workspace); @@ -729,9 +724,11 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // Attached data // 1) int32 port to reply to int32 replyport; - msg->Read(&replyport); + msg.Read(&replyport); - write_port(replyport,(fCursorHidden)?SERVER_TRUE:SERVER_FALSE,NULL,0); + BPortLink replylink(replyport); + replylink.StartMessage(fCursorHidden ? SERVER_TRUE : SERVER_FALSE); + replylink.Flush(); break; } case AS_SET_CURSOR_DATA: @@ -740,7 +737,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // Attached data: 68 bytes of fAppCursor data int8 cdata[68]; - msg->Read(cdata,68); + msg.Read(cdata,68); // Because we don't want an overaccumulation of these particular // cursors, we will delete them if there is an existing one. It would @@ -763,13 +760,13 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // 2) int32 token ID of the cursor to set // 3) port_id port to receive a reply. Only exists if the sync flag is true. bool sync; - int32 ctoken; - port_id replyport; + int32 ctoken = B_NULL_TOKEN; + port_id replyport = -1; - msg->Read(&sync); - msg->Read(&ctoken); + msg.Read(&sync); + msg.Read(&ctoken); if(sync) - msg->Read(&replyport); + msg.Read(&replyport); cursormanager->SetCursor(ctoken); @@ -777,8 +774,9 @@ void ServerApp::_DispatchMessage(PortMessage *msg) { // the application is expecting a reply, but plans to do literally nothing // with the data, so we'll just reuse the cursor token variable - ctoken=AS_SET_CURSOR_BCURSOR; - write_port(replyport,ctoken, &ctoken, sizeof(int32)); + BPortLink replylink(replyport); + replylink.StartMessage(SERVER_TRUE); + replylink.Flush(); } break; } @@ -789,20 +787,21 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // 1) 68 bytes of fAppCursor data // 2) port_id reply port - port_id replyport; + port_id replyport = -1; int8 cdata[68]; - msg->Read(cdata,68); - msg->Read(&replyport); + msg.Read(cdata,68); + msg.Read(&replyport); fAppCursor=new ServerCursor(cdata); fAppCursor->SetAppSignature(fSignature.String()); cursormanager->AddCursor(fAppCursor); // Synchronous message - BApplication is waiting on the cursor's ID - PortLink link(replyport); - link.Attach(fAppCursor->ID()); - link.Flush(); + BPortLink replylink(replyport); + replylink.StartMessage(SERVER_TRUE); + replylink.Attach(fAppCursor->ID()); + replylink.Flush(); break; } case AS_DELETE_BCURSOR: @@ -810,8 +809,8 @@ void ServerApp::_DispatchMessage(PortMessage *msg) STRACE(("ServerApp %s: Delete BCursor\n",fSignature.String())); // Attached data: // 1) int32 token ID of the cursor to delete - int32 ctoken; - msg->Read(&ctoken); + int32 ctoken = B_NULL_TOKEN; + msg.Read(&ctoken); if(fAppCursor && fAppCursor->ID()==ctoken) fAppCursor=NULL; @@ -828,12 +827,12 @@ void ServerApp::_DispatchMessage(PortMessage *msg) scroll_bar_info sbi=desktop->ScrollBarInfo(); port_id replyport; - msg->Read(&replyport); + msg.Read(&replyport); - PortLink link(replyport); - - link.Attach(sbi); - link.Flush(); + BPortLink replylink(replyport); + replylink.StartMessage(SERVER_TRUE); + replylink.Attach(sbi); + replylink.Flush(); break; } case AS_SET_SCROLLBAR_INFO: @@ -842,7 +841,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // Attached Data: // 1) scroll_bar_info scroll bar info structure scroll_bar_info sbi; - msg->Read(&sbi); + msg.Read(&sbi); desktop->SetScrollBarInfo(sbi); break; @@ -854,23 +853,23 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // 1) port_id reply port - synchronous message port_id replyport; - msg->Read(&replyport); + msg.Read(&replyport); - PortLink link(replyport); - - link.Attach(desktop->FFMouseInUse()); - link.Flush(); + BPortLink replylink(replyport); + replylink.StartMessage(SERVER_TRUE); + replylink.Attach(desktop->FFMouseInUse()); + replylink.Flush(); break; } case AS_SET_FOCUS_FOLLOWS_MOUSE: { STRACE(("ServerApp %s: Set Focus Follows Mouse in use\n",fSignature.String())); - // Attached Data: +/* // Attached Data: // 1) scroll_bar_info scroll bar info structure scroll_bar_info sbi; - msg->Read(&sbi); + msg.Read(&sbi); - desktop->SetScrollBarInfo(sbi); + desktop->SetScrollBarInfo(sbi);*/ break; } case AS_SET_MOUSE_MODE: @@ -879,7 +878,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg) // Attached Data: // 1) enum mode_mouse FFM mouse mode mode_mouse mmode; - msg->Read(&mmode); + msg.Read(&mmode); desktop->SetFFMouseMode(mmode); break; @@ -892,13 +891,13 @@ void ServerApp::_DispatchMessage(PortMessage *msg) mode_mouse mmode=desktop->FFMouseMode(); - port_id replyport; - msg->Read(&replyport); + port_id replyport = -1; + msg.Read(&replyport); - PortLink link(replyport); - - link.Attach(mmode); - link.Flush(); + BPortLink replylink(replyport); + replylink.StartMessage(SERVER_TRUE); + replylink.Attach(mmode); + replylink.Flush(); break; } case AS_GET_UI_COLOR: @@ -907,17 +906,17 @@ void ServerApp::_DispatchMessage(PortMessage *msg) RGBColor color; int32 whichcolor; - port_id replyport; + port_id replyport = -1; - msg->Read(&whichcolor); - msg->Read(&replyport); + msg.Read(&whichcolor); + msg.Read(&replyport); gui_colorset.Lock(); color=gui_colorset.AttributeToColor(whichcolor); gui_colorset.Unlock(); - PortLink replylink(replyport); - replylink.SetOpCode(SERVER_TRUE); + BPortLink replylink(replyport); + replylink.StartMessage(SERVER_TRUE); replylink.Attach(color.GetColor32()); replylink.Flush(); break; @@ -925,7 +924,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg) default: { STRACE(("ServerApp %s received unhandled message code offset %s\n",fSignature.String(), - MsgCodeToBString(msg->Code()).String())); + MsgCodeToBString(code).String())); break; } @@ -953,3 +952,4 @@ team_id ServerApp::ClientTeamID() { return fClientTeamID; } + diff --git a/src/servers/app/server/ServerApp.h b/src/servers/app/server/ServerApp.h index e80160b83f..eaa2ad386f 100644 --- a/src/servers/app/server/ServerApp.h +++ b/src/servers/app/server/ServerApp.h @@ -34,8 +34,7 @@ class AppServer; class BMessage; -class PortLink; -class PortMessage; +class BPortLink; class BList; class DisplayDriver; class ServerCursor; @@ -82,7 +81,7 @@ protected: friend class AppServer; friend class ServerWindow; - void _DispatchMessage(PortMessage *msg); + void _DispatchMessage(int32 code, BPortLink& link); ServerBitmap* _FindBitmap(int32 token); port_id fClientAppPort, @@ -94,7 +93,7 @@ protected: team_id fClientTeamID; - PortLink *fAppLink; + BPortLink *fAppLink; BList *fSWindowList, *fBitmapList, *fPictureList; diff --git a/src/servers/app/server/ServerWindow.cpp b/src/servers/app/server/ServerWindow.cpp index 2e72b30676..a33513083e 100644 --- a/src/servers/app/server/ServerWindow.cpp +++ b/src/servers/app/server/ServerWindow.cpp @@ -124,6 +124,8 @@ ServerWindow::ServerWindow(BRect rect, const char *string, uint32 wlook, if(string) fTitle.SetTo(string); + else + fTitle.SetTo(B_EMPTY_STRING); fFrame = rect; fFlags = wflags; @@ -136,6 +138,7 @@ ServerWindow::ServerWindow(BRect rect, const char *string, uint32 wlook, fWorkspaces = index; fWinBorder = NULL; + cl = NULL; //current layer // fClientWinPort is the port to which the app awaits messages from the server fClientWinPort = winport; @@ -143,24 +146,12 @@ ServerWindow::ServerWindow(BRect rect, const char *string, uint32 wlook, // fMessagePort is the port to which the app sends messages for the server fMessagePort = create_port(30,fTitle.String()); - fSession = new BSession(fMessagePort, fClientWinPort); + fSession = new BPortLink(fClientWinPort, fMessagePort); // Send a reply to our window - it is expecting fMessagePort port. - // Temporarily use winlink to save time and memory - PortLink winLink(replyport); - winLink.SetOpCode(AS_CREATE_WINDOW); - winLink.Attach(fMessagePort); - winLink.Flush(); - - // check the next 2 messages to make sure we receive top_view's attributes. - int32 vCode; - fSession->ReadInt32(&vCode); - if(vCode != AS_LAYER_CREATE_ROOT) - debugger("SERVER ERROR: ServerWindow(xxx): NO top_view data received! - 1\n"); - - fSession->ReadInt32(&vCode); - if(vCode != AS_LAYER_CREATE) - debugger("SERVER ERROR: ServerWindow(xxx): NO top_view data received! - 2\n"); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(fMessagePort); + fSession->Flush(); STRACE(("ServerWindow %s:\n",fTitle.String())); STRACE(("\tFrame (%.1f,%.1f,%.1f,%.1f)\n",rect.left,rect.top,rect.right,rect.bottom)); @@ -174,18 +165,6 @@ void ServerWindow::Init(void) this, desktop->GetDisplayDriver()); fWinBorder->RebuildFullRegion(); - // Start receiving top_view data -- pass NULL as the parent view. - // This should be the *only* place where this happens. - fWinBorder->fTopLayer = CreateLayerTree(NULL); - fWinBorder->fTopLayer->SetAsTopLayer(true); - cl = fWinBorder->fTopLayer; - - // connect decorator and top layer. - fWinBorder->AddChild(fWinBorder->fTopLayer, NULL); - - // NOTE: this MUST be before the monitor thread is spawned! - desktop->AddWinBorder(fWinBorder); - // Spawn our message-monitoring thread fMonitorThreadID = spawn_thread(MonitorWin, fTitle.String(), B_NORMAL_PRIORITY, this); @@ -283,13 +262,17 @@ void ServerWindow::Show(void) WinBorder *previousFocus; BRegion invalidRegion; Workspace *ws; -// TODO: can you unify this method with Desktop::MouseEventHandler::B_MOUSE_DOWN + + // TODO: can you unify this method with Desktop::MouseEventHandler::B_MOUSE_DOWN + ws = rl->WorkspaceAt(i+1); ws->BringToFrontANormalWindow(fWinBorder); ws->SearchAndSetNewFront(fWinBorder); previousFocus = ws->FocusLayer(); ws->SearchAndSetNewFocus(fWinBorder); -// TODO: only do this in for the active workspace! + + // TODO: only do this in for the active workspace! + // first redraw previous window's decorator. It has lost focus state. if (previousFocus) if (previousFocus->fDecorator) @@ -358,7 +341,7 @@ void ServerWindow::Hide(void) if (ws->FocusLayer() == fWinBorder) ws->SearchAndSetNewFocus(fWinBorder); else{ -// TODO: RootLayer class should take care of this. (or Desktop) + // TODO: RootLayer class should take care of this. (or Desktop) // ws->Invalidate(); } } @@ -531,13 +514,12 @@ void ServerWindow::SetLayerFontState(Layer *layer) // NOTE: no need to check for a lock. This is a private method. uint16 mask; - fSession->ReadUInt16(&mask); + fSession->Read(&mask); if (mask & B_FONT_FAMILY_AND_STYLE) { uint32 fontID; - fSession->ReadInt32((int32*)&fontID); - + fSession->Read((int32*)&fontID); // TODO: implement later. Currently there is no SetFamAndStyle(uint32) // in ServerFont class. DW, could you add one? //layer->fLayerData->font-> @@ -546,49 +528,49 @@ void ServerWindow::SetLayerFontState(Layer *layer) if (mask & B_FONT_SIZE) { float size; - fSession->ReadFloat(&size); + fSession->Read(&size); layer->fLayerData->font.SetSize(size); } if (mask & B_FONT_SHEAR) { float shear; - fSession->ReadFloat(&shear); + fSession->Read(&shear); layer->fLayerData->font.SetShear(shear); } if (mask & B_FONT_ROTATION) { float rotation; - fSession->ReadFloat(&rotation); + fSession->Read(&rotation); layer->fLayerData->font.SetRotation(rotation); } if (mask & B_FONT_SPACING) { uint8 spacing; - fSession->ReadUInt8(&spacing); + fSession->Read(&spacing); layer->fLayerData->font.SetSpacing(spacing); } if (mask & B_FONT_ENCODING) { uint8 encoding; - fSession->ReadUInt8((uint8*)&encoding); + fSession->Read((uint8*)&encoding); layer->fLayerData->font.SetEncoding(encoding); } if (mask & B_FONT_FACE) { uint16 face; - fSession->ReadUInt16(&face); + fSession->Read(&face); layer->fLayerData->font.SetFace(face); } if (mask & B_FONT_FLAGS) { uint32 flags; - fSession->ReadUInt32(&flags); + fSession->Read(&flags); layer->fLayerData->font.SetFlags(flags); } STRACE(("DONE: ServerWindow %s: Message AS_LAYER_SET_FONT_STATE: Layer: %s\n", @@ -599,25 +581,25 @@ void ServerWindow::SetLayerState(Layer *layer) { // NOTE: no need to check for a lock. This is a private method. rgb_color highColor, lowColor, viewColor; - pattern patt; + pattern patt; int32 clipRegRects; - fSession->ReadPoint( &(layer->fLayerData->penlocation)); - fSession->ReadFloat( &(layer->fLayerData->pensize)); - fSession->ReadData( &highColor, sizeof(rgb_color)); - fSession->ReadData( &lowColor, sizeof(rgb_color)); - fSession->ReadData( &viewColor, sizeof(rgb_color)); - fSession->ReadData( &patt, sizeof(pattern)); - fSession->ReadInt8((int8*) &(layer->fLayerData->draw_mode)); - fSession->ReadPoint( &(layer->fLayerData->coordOrigin)); - fSession->ReadInt8((int8*) &(layer->fLayerData->lineJoin)); - fSession->ReadInt8((int8*) &(layer->fLayerData->lineCap)); - fSession->ReadFloat( &(layer->fLayerData->miterLimit)); - fSession->ReadInt8((int8*) &(layer->fLayerData->alphaSrcMode)); - fSession->ReadInt8((int8*) &(layer->fLayerData->alphaFncMode)); - fSession->ReadFloat( &(layer->fLayerData->scale)); - fSession->ReadBool( &(layer->fLayerData->fontAliasing)); - fSession->ReadInt32( &clipRegRects); + fSession->Read( &(layer->fLayerData->penlocation)); + fSession->Read( &(layer->fLayerData->pensize)); + fSession->Read( &highColor, sizeof(rgb_color)); + fSession->Read( &lowColor, sizeof(rgb_color)); + fSession->Read( &viewColor, sizeof(rgb_color)); + fSession->Read( &patt, sizeof(pattern)); + fSession->Read((int8*) &(layer->fLayerData->draw_mode)); + fSession->Read( &(layer->fLayerData->coordOrigin)); + fSession->Read((int8*) &(layer->fLayerData->lineJoin)); + fSession->Read((int8*) &(layer->fLayerData->lineCap)); + fSession->Read( &(layer->fLayerData->miterLimit)); + fSession->Read((int8*) &(layer->fLayerData->alphaSrcMode)); + fSession->Read((int8*) &(layer->fLayerData->alphaFncMode)); + fSession->Read( &(layer->fLayerData->scale)); + fSession->Read( &(layer->fLayerData->fontAliasing)); + fSession->Read( &clipRegRects); layer->fLayerData->patt.Set(*((uint64*)&patt)); layer->fLayerData->highcolor.SetColor(highColor); @@ -635,7 +617,7 @@ void ServerWindow::SetLayerState(Layer *layer) for(int32 i = 0; i < clipRegRects; i++) { - fSession->ReadRect(&rect); + fSession->Read(&rect); layer->fLayerData->clipReg->Include(rect); } } @@ -662,61 +644,43 @@ Layer * ServerWindow::CreateLayerTree(Layer *localRoot) uint32 flags; bool hidden; int32 childCount; - char *name; + char *name = NULL; - fSession->ReadInt32(&token); - name = fSession->ReadString(); - fSession->ReadRect(&frame); - fSession->ReadUInt32(&resizeMask); - fSession->ReadUInt32(&flags); - fSession->ReadBool(&hidden); - fSession->ReadInt32(&childCount); + fSession->Read(&token); + fSession->ReadString(&name); + fSession->Read(&frame); + fSession->Read(&resizeMask); + fSession->Read(&flags); + fSession->Read(&hidden); + fSession->Read(&childCount); Layer *newLayer; - newLayer = new Layer(frame.OffsetToCopy(0.0, 0.0), name, token, resizeMask, + newLayer = new Layer(frame, name, token, resizeMask, flags, desktop->GetDisplayDriver()); - delete name; + if (name) + free(name); // there is no way of setting this, other than manually :-) newLayer->fHidden = hidden; - int32 dummyMsg; - - // next comes BView's font state - fSession->ReadInt32(&dummyMsg); - if (dummyMsg == AS_LAYER_SET_FONT_STATE) - SetLayerFontState(newLayer); - else - debugger("ServerWindow(%s) - AS_LAYER_SET_FONT_STATE Expected!\n"); - - // lastly, the BView's graphic state - fSession->ReadInt32(&dummyMsg); - if (dummyMsg == AS_LAYER_SET_STATE) - SetLayerState(newLayer); - else - debugger("ServerWindow(%s) - AS_LAYER_SET_STATE Expected!\n"); - // add the new Layer to the tree structure. if(localRoot) localRoot->AddChild(newLayer, NULL); - - // attach newLayer's children... - for(int i = 0; i < childCount; i++) - { - fSession->ReadInt32(&dummyMsg); - if (dummyMsg == AS_LAYER_CREATE) - CreateLayerTree(newLayer); - else - debugger("ServerWindow(%s) - AS_LAYER_CREATE Expected!\n"); - } - STRACE(("DONE: ServerWindow %s: Message AS_CREATE_LAYER: Parent: %s, Child: %s\n", fTitle.String(), + + STRACE(("DONE: ServerWindow %s: Message AS_LAYER_CREATE: Parent: %s, Child: %s\n", fTitle.String(), localRoot? localRoot->fName->String(): "NULL", newLayer->fName->String())); - + return newLayer; } //------------------------------------------------------------------------------ void ServerWindow::DispatchMessage(int32 code) { + if (cl == NULL && code != AS_LAYER_CREATE_ROOT) + { + printf("ServerWindow %s received unexpected code - message offset %lx before top_view attached.\n",fTitle.String(), code - SERVER_TRUE); + return; + } + switch(code) { //--------- BView Messages ----------------- @@ -725,8 +689,8 @@ void ServerWindow::DispatchMessage(int32 code) int32 bitmapToken; BPoint point; - fSession->ReadInt32(&bitmapToken); - fSession->ReadPoint(&point); + fSession->Read(&bitmapToken); + fSession->Read(&point); ServerBitmap *sbmp = fServerApp->FindBitmap(bitmapToken); if(sbmp) @@ -750,8 +714,8 @@ void ServerWindow::DispatchMessage(int32 code) int32 bitmapToken; BPoint point; - fSession->ReadInt32(&bitmapToken); - fSession->ReadPoint(&point); + fSession->Read(&bitmapToken); + fSession->Read(&point); ServerBitmap *sbmp = fServerApp->FindBitmap(bitmapToken); if(sbmp) @@ -773,9 +737,9 @@ void ServerWindow::DispatchMessage(int32 code) int32 bitmapToken; BRect srcRect, dstRect; - fSession->ReadInt32(&bitmapToken); - fSession->ReadRect(&dstRect); - fSession->ReadRect(&srcRect); + fSession->Read(&bitmapToken); + fSession->Read(&dstRect); + fSession->Read(&srcRect); ServerBitmap *sbmp = fServerApp->FindBitmap(bitmapToken); if(sbmp) @@ -797,9 +761,9 @@ void ServerWindow::DispatchMessage(int32 code) int32 bitmapToken; BRect srcRect, dstRect; - fSession->ReadInt32(&bitmapToken); - fSession->ReadRect(&dstRect); - fSession->ReadRect(&srcRect); + fSession->Read(&bitmapToken); + fSession->Read(&dstRect); + fSession->Read(&srcRect); ServerBitmap *sbmp = fServerApp->FindBitmap(bitmapToken); if(sbmp) @@ -819,20 +783,42 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_SET_CURRENT_LAYER: Layer name: %s\n", fTitle.String(), cl->fName->String())); int32 token; - fSession->ReadInt32(&token); + fSession->Read(&token); Layer *current = FindLayer(fWinBorder->fTopLayer, token); - + if (current) cl=current; else // hope this NEVER happens! :-) debugger("Server PANIC: window cannot find Layer with ID\n"); break; } + + case AS_LAYER_CREATE_ROOT: + { + // Start receiving top_view data -- pass NULL as the parent view. + // This should be the *only* place where this happens. + if (cl != NULL) + break; + + fWinBorder->fTopLayer = CreateLayerTree(NULL); + fWinBorder->fTopLayer->SetAsTopLayer(true); + cl = fWinBorder->fTopLayer; + + // connect decorator and top layer. + fWinBorder->AddChild(fWinBorder->fTopLayer, NULL); + desktop->AddWinBorder(fWinBorder); + + break; + } + case AS_LAYER_CREATE: { STRACE(("ServerWindow %s: Message AS_LAYER_CREATE: Layer name: %s\n", fTitle.String(), cl->fName->String())); Layer *newLayer; + + if (cl == NULL) + break; newLayer = CreateLayerTree(NULL); cl->AddChild(newLayer, this); @@ -898,46 +884,49 @@ void ServerWindow::DispatchMessage(int32 code) vc = ld->viewcolor.GetColor32(); patt = ld->patt.GetInt64(); - // TODO: DW implement such a method in ServerFont class - // fSession->WriteUInt32(ld->font.GetFamAndStyle()); - fSession->WriteUInt32(0UL); - fSession->WriteFloat(ld->font.Size()); - fSession->WriteFloat(ld->font.Shear()); - fSession->WriteFloat(ld->font.Rotation()); - fSession->WriteUInt8(ld->font.Spacing()); - fSession->WriteUInt8(ld->font.Encoding()); - fSession->WriteUInt16(ld->font.Face()); - fSession->WriteUInt32(ld->font.Flags()); + // TODO: DW implement such a method in ServerFont class! + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(0UL /*uint32 ld->font.GetFamAndStyle()*/); + fSession->Attach(ld->font.Size()); + fSession->Attach(ld->font.Shear()); + fSession->Attach(ld->font.Rotation()); + fSession->Attach(ld->font.Spacing()); + fSession->Attach(ld->font.Encoding()); + fSession->Attach(ld->font.Face()); + fSession->Attach(ld->font.Flags()); - fSession->WritePoint(ld->penlocation); - fSession->WriteFloat(ld->pensize); - fSession->WriteData(&hc, sizeof(rgb_color)); - fSession->WriteData(&lc, sizeof(rgb_color)); - fSession->WriteData(&vc, sizeof(rgb_color)); - fSession->WriteData(&patt,sizeof(pattern)); - fSession->WritePoint(ld->coordOrigin); - fSession->WriteUInt8((uint8)(ld->draw_mode)); - fSession->WriteUInt8((uint8)(ld->lineCap)); - fSession->WriteUInt8((uint8)(ld->lineJoin)); - fSession->WriteFloat(ld->miterLimit); - fSession->WriteUInt8((uint8)(ld->alphaSrcMode)); - fSession->WriteUInt8((uint8)(ld->alphaFncMode)); - fSession->WriteFloat(ld->scale); - fSession->WriteFloat(ld->fontAliasing); + fSession->Attach(ld->penlocation); + fSession->Attach(ld->pensize); + fSession->Attach(&hc, sizeof(rgb_color)); + fSession->Attach(&lc, sizeof(rgb_color)); + fSession->Attach(&vc, sizeof(rgb_color)); + + // TODO: fix this to use the templatized version + fSession->Attach(&patt,sizeof(pattern)); + fSession->Attach(ld->coordOrigin); + fSession->Attach((uint8)(ld->draw_mode)); + fSession->Attach((uint8)(ld->lineCap)); + fSession->Attach((uint8)(ld->lineJoin)); + fSession->Attach(ld->miterLimit); + fSession->Attach((uint8)(ld->alphaSrcMode)); + fSession->Attach((uint8)(ld->alphaFncMode)); + fSession->Attach(ld->scale); + fSession->Attach(ld->fontAliasing); int32 noOfRects = 0; if (ld->clipReg) noOfRects = ld->clipReg->CountRects(); - fSession->WriteInt32(noOfRects); + fSession->Attach(noOfRects); for(int i = 0; i < noOfRects; i++) - fSession->WriteRect(ld->clipReg->RectAt(i)); + fSession->Attach(ld->clipReg->RectAt(i)); - fSession->WriteFloat(cl->fFrame.left); - fSession->WriteFloat(cl->fFrame.top); - fSession->WriteRect(cl->fFrame.OffsetToCopy(cl->fBoundsLeftTop)); - fSession->Sync(); + fSession->Attach(cl->fFrame.left); + fSession->Attach(cl->fFrame.top); + fSession->Attach(cl->fFrame.OffsetToCopy(cl->fBoundsLeftTop)); + fSession->Flush(); + break; } case AS_LAYER_MOVETO: @@ -945,8 +934,8 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_MOVETO: Layer name: %s\n", fTitle.String(), cl->fName->String())); float x, y; - fSession->ReadFloat(&x); - fSession->ReadFloat(&y); + fSession->Read(&x); + fSession->Read(&y); cl->MoveBy(x, y); @@ -957,8 +946,8 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_RESIZETO: Layer name: %s\n", fTitle.String(), cl->fName->String())); float newWidth, newHeight; - fSession->ReadFloat(&newWidth); - fSession->ReadFloat(&newHeight); + fSession->Read(&newWidth); + fSession->Read(&newHeight); // TODO: check for minimum alowed. WinBorder should provide such // a method, based on its decorator. @@ -970,10 +959,12 @@ void ServerWindow::DispatchMessage(int32 code) case AS_LAYER_GET_COORD: { STRACE(("ServerWindow %s: Message AS_LAYER_GET_COORD: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->WriteFloat(cl->fFrame.left); - fSession->WriteFloat(cl->fFrame.top); - fSession->WriteRect(cl->fFrame.OffsetToCopy(cl->fBoundsLeftTop)); - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(cl->fFrame.left); + fSession->Attach(cl->fFrame.top); + fSession->Attach(cl->fFrame.OffsetToCopy(cl->fBoundsLeftTop)); + fSession->Flush(); + break; } case AS_LAYER_SET_ORIGIN: @@ -981,8 +972,8 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_SET_ORIGIN: Layer: %s\n",fTitle.String(), cl->fName->String())); float x, y; - fSession->ReadFloat(&x); - fSession->ReadFloat(&y); + fSession->Read(&x); + fSession->Read(&y); cl->fLayerData->coordOrigin.Set(x, y); @@ -991,15 +982,16 @@ void ServerWindow::DispatchMessage(int32 code) case AS_LAYER_GET_ORIGIN: { STRACE(("ServerWindow %s: Message AS_LAYER_GET_ORIGIN: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->WritePoint(cl->fLayerData->coordOrigin); - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(cl->fLayerData->coordOrigin); + fSession->Flush(); break; } case AS_LAYER_RESIZE_MODE: { STRACE(("ServerWindow %s: Message AS_LAYER_RESIZE_MODE: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->ReadUInt32(&(cl->fResizeMode)); + fSession->Read(&(cl->fResizeMode)); break; } @@ -1008,7 +1000,7 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_CURSOR: Layer: %s\n",fTitle.String(), cl->fName->String())); int32 token; - fSession->ReadInt32(&token); + fSession->Read(&token); cursormanager->SetCursor(token); @@ -1016,7 +1008,7 @@ void ServerWindow::DispatchMessage(int32 code) } case AS_LAYER_SET_FLAGS: { - fSession->ReadUInt32(&(cl->fFlags)); + fSession->Read(&(cl->fFlags)); STRACE(("ServerWindow %s: Message AS_LAYER_SET_FLAGS: Layer: %s\n",fTitle.String(), cl->fName->String())); break; @@ -1043,9 +1035,9 @@ void ServerWindow::DispatchMessage(int32 code) // it was called. e.g.: different lineCap or lineJoin. Strange results // would appear. - fSession->ReadInt8(&lineCap); - fSession->ReadInt8(&lineJoin); - fSession->ReadFloat(&(cl->fLayerData->miterLimit)); + fSession->Read(&lineCap); + fSession->Read(&lineJoin); + fSession->Read(&(cl->fLayerData->miterLimit)); cl->fLayerData->lineCap = (cap_mode)lineCap; cl->fLayerData->lineJoin = (join_mode)lineJoin; @@ -1055,10 +1047,11 @@ void ServerWindow::DispatchMessage(int32 code) case AS_LAYER_GET_LINE_MODE: { STRACE(("ServerWindow %s: Message AS_LAYER_GET_LINE_MODE: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->WriteInt8((int8)(cl->fLayerData->lineCap)); - fSession->WriteInt8((int8)(cl->fLayerData->lineJoin)); - fSession->WriteFloat(cl->fLayerData->miterLimit); - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach((int8)(cl->fLayerData->lineCap)); + fSession->Attach((int8)(cl->fLayerData->lineJoin)); + fSession->Attach(cl->fLayerData->miterLimit); + fSession->Flush(); break; } @@ -1092,9 +1085,8 @@ void ServerWindow::DispatchMessage(int32 code) } case AS_LAYER_SET_SCALE: { - STRACE(("ServerWindow %s: Message AS_LAYER_SET_SCALE: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->ReadFloat(&(cl->fLayerData->scale)); - + STRACE(("ServerWindow %s: Message AS_LAYER_SET_SCALE: Layer: %s\n",fTitle.String(), cl->_name->String())); + fSession->Read(&(cl->fLayerData->scale)); break; } case AS_LAYER_GET_SCALE: @@ -1107,9 +1099,10 @@ void ServerWindow::DispatchMessage(int32 code) while((ld = ld->prevState)) scale *= ld->scale; - fSession->WriteFloat(scale); - fSession->Sync(); - + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(scale); + fSession->Flush(); + break; } case AS_LAYER_SET_PEN_LOC: @@ -1117,34 +1110,36 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_SET_PEN_LOC: Layer: %s\n",fTitle.String(), cl->fName->String())); float x, y; - fSession->ReadFloat(&x); - fSession->ReadFloat(&y); - + fSession->Read(&x); + fSession->Read(&y); + cl->fLayerData->penlocation.Set(x, y); - + break; } case AS_LAYER_GET_PEN_LOC: { - STRACE(("ServerWindow %s: Message AS_LAYER_GET_PEN_LOC: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->WritePoint(cl->fLayerData->penlocation); - - fSession->Sync(); - + STRACE(("ServerWindow %s: Message AS_LAYER_GET_PEN_LOC: Layer: %s\n",fTitle.String(), cl->_name->String())); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(cl->fLayerData->penlocation); + fSession->Flush(); + break; } case AS_LAYER_SET_PEN_SIZE: { - STRACE(("ServerWindow %s: Message AS_LAYER_SET_PEN_SIZE: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->ReadFloat(&(cl->fLayerData->pensize)); - + STRACE(("ServerWindow %s: Message AS_LAYER_SET_PEN_SIZE: Layer: %s\n",fTitle.String(), cl->_name->String())); + fSession->Read(&(cl->fLayerData->pensize)); + break; } case AS_LAYER_GET_PEN_SIZE: { - STRACE(("ServerWindow %s: Message AS_LAYER_GET_PEN_SIZE: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->WriteFloat(cl->fLayerData->pensize); - fSession->Sync(); + STRACE(("ServerWindow %s: Message AS_LAYER_GET_PEN_SIZE: Layer: %s\n",fTitle.String(), cl->_name->String())); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(cl->fLayerData->pensize); + fSession->Flush(); + break; } case AS_LAYER_SET_HIGH_COLOR: @@ -1152,10 +1147,10 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_SET_HIGH_COLOR: Layer: %s\n",fTitle.String(), cl->fName->String())); rgb_color c; - fSession->ReadData(&c, sizeof(rgb_color)); + fSession->Read(&c, sizeof(rgb_color)); cl->fLayerData->highcolor.SetColor(c); - + break; } case AS_LAYER_SET_LOW_COLOR: @@ -1163,7 +1158,7 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_SET_LOW_COLOR: Layer: %s\n",fTitle.String(), cl->fName->String())); rgb_color c; - fSession->ReadData(&c, sizeof(rgb_color)); + fSession->Read(&c, sizeof(rgb_color)); cl->fLayerData->lowcolor.SetColor(c); @@ -1174,7 +1169,7 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_SET_VIEW_COLOR: Layer: %s\n",fTitle.String(), cl->fName->String())); rgb_color c; - fSession->ReadData(&c, sizeof(rgb_color)); + fSession->Read(&c, sizeof(rgb_color)); cl->fLayerData->viewcolor.SetColor(c); @@ -1191,10 +1186,11 @@ void ServerWindow::DispatchMessage(int32 code) lowColor = cl->fLayerData->lowcolor.GetColor32(); viewColor = cl->fLayerData->viewcolor.GetColor32(); - fSession->WriteData(&highColor, sizeof(rgb_color)); - fSession->WriteData(&lowColor, sizeof(rgb_color)); - fSession->WriteData(&viewColor, sizeof(rgb_color)); - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(&highColor, sizeof(rgb_color)); + fSession->Attach(&lowColor, sizeof(rgb_color)); + fSession->Attach(&viewColor, sizeof(rgb_color)); + fSession->Flush(); break; } @@ -1203,21 +1199,21 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_SET_BLEND_MODE: Layer: %s\n",fTitle.String(), cl->fName->String())); int8 srcAlpha, alphaFunc; - fSession->ReadInt8(&srcAlpha); - fSession->ReadInt8(&alphaFunc); + fSession->Read(&srcAlpha); + fSession->Read(&alphaFunc); cl->fLayerData->alphaSrcMode = (source_alpha)srcAlpha; cl->fLayerData->alphaFncMode = (alpha_function)alphaFunc; - + break; } case AS_LAYER_GET_BLEND_MODE: { STRACE(("ServerWindow %s: Message AS_LAYER_GET_BLEND_MODE: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->WriteInt8((int8)(cl->fLayerData->alphaSrcMode)); - fSession->WriteInt8((int8)(cl->fLayerData->alphaFncMode)); - - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach((int8)(cl->fLayerData->alphaSrcMode)); + fSession->Attach((int8)(cl->fLayerData->alphaFncMode)); + fSession->Flush(); break; } @@ -1226,7 +1222,7 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_SET_DRAW_MODE: Layer: %s\n",fTitle.String(), cl->fName->String())); int8 drawingMode; - fSession->ReadInt8(&drawingMode); + fSession->Read(&drawingMode); cl->fLayerData->draw_mode = (drawing_mode)drawingMode; @@ -1235,27 +1231,29 @@ void ServerWindow::DispatchMessage(int32 code) case AS_LAYER_GET_DRAW_MODE: { STRACE(("ServerWindow %s: Message AS_LAYER_GET_DRAW_MODE: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->WriteInt8((int8)(cl->fLayerData->draw_mode)); - fSession->Sync(); - + fSession->StartMessage(SERVER_TRUE); + fSession->Attach((int8)(cl->fLayerData->draw_mode)); + fSession->Flush(); + break; } case AS_LAYER_PRINT_ALIASING: { STRACE(("ServerWindow %s: Message AS_LAYER_PRINT_ALIASING: Layer: %s\n",fTitle.String(), cl->fName->String())); - fSession->ReadBool(&(cl->fLayerData->fontAliasing)); + fSession->Read(&(cl->fLayerData->fontAliasing)); break; } case AS_LAYER_CLIP_TO_PICTURE: { STRACE(("ServerWindow %s: Message AS_LAYER_CLIP_TO_PICTURE: Layer: %s\n",fTitle.String(), cl->fName->String())); + // TODO: watch out for the coordinate system int32 pictureToken; BPoint where; - fSession->ReadInt32(&pictureToken); - fSession->ReadPoint(&where); + fSession->Read(&pictureToken); + fSession->Read(&where); BRegion reg; @@ -1324,12 +1322,13 @@ void ServerWindow::DispatchMessage(int32 code) case AS_LAYER_CLIP_TO_INVERSE_PICTURE: { STRACE(("ServerWindow %s: Message AS_LAYER_CLIP_TO_INVERSE_PICTURE: Layer: %s\n",fTitle.String(), cl->fName->String())); + // TODO: watch out for the coordinate system int32 pictureToken; BPoint where; - fSession->ReadInt32(&pictureToken); - fSession->ReadPoint(&where); + fSession->Read(&pictureToken); + fSession->Read(&where); ServerPicture *sp = NULL; int32 i = 0; @@ -1365,8 +1364,9 @@ void ServerWindow::DispatchMessage(int32 code) STRACE(("ServerWindow %s: Message AS_LAYER_GET_CLIP_REGION: Layer: %s\n",fTitle.String(), cl->fName->String())); // if this Layer is hidden, it is clear that its visible region is void. if (cl->IsHidden()){ - fSession->WriteInt32(0L); - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(0L); + fSession->Flush(); } else{ // TODO: watch out for the coordinate system @@ -1387,10 +1387,11 @@ void ServerWindow::DispatchMessage(int32 code) } noOfRects = reg.CountRects(); - fSession->WriteInt32(noOfRects); + fSession->StartMessage(SERVER_TRUE); + fSession->Attach(noOfRects); for(int i = 0; i < noOfRects; i++) - fSession->WriteRect(reg.RectAt(i)); + fSession->Attach(reg.RectAt(i)); } break; } @@ -1406,11 +1407,11 @@ void ServerWindow::DispatchMessage(int32 code) else cl->fLayerData->clipReg = new BRegion(); - fSession->ReadInt32(&noOfRects); + fSession->Read(&noOfRects); for(int i = 0; i < noOfRects; i++) { - fSession->ReadRect(&r); + fSession->Read(&r); cl->fLayerData->clipReg->Include(r); } @@ -1431,7 +1432,7 @@ void ServerWindow::DispatchMessage(int32 code) // TODO: watch out for the coordinate system BRect invalRect; - fSession->ReadRect(&invalRect); + fSession->Read(&invalRect); cl->Invalidate(invalRect); @@ -1445,11 +1446,11 @@ void ServerWindow::DispatchMessage(int32 code) int32 noOfRects; BRect rect; - fSession->ReadInt32(&noOfRects); + fSession->Read(&noOfRects); for(int i = 0; i < noOfRects; i++) { - fSession->ReadRect(&rect); + fSession->Read(&rect); invalReg.Include(rect); } @@ -1527,21 +1528,21 @@ void ServerWindow::DispatchMessage(int32 code) int32 mainToken; team_id teamID; - fSession->ReadInt32(&mainToken); - fSession->ReadData(&teamID, sizeof(team_id)); + fSession->Read(&mainToken); + fSession->Read(&teamID, sizeof(team_id)); wb = desktop->FindWinBorderByServerWindowTokenAndTeamID(mainToken, teamID); if(wb) { - fSession->WriteInt32(SERVER_TRUE); - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Flush(); fWinBorder->AddToSubsetOf(wb); } else { - fSession->WriteInt32(SERVER_FALSE); - fSession->Sync(); + fSession->StartMessage(SERVER_FALSE); + fSession->Flush(); } break; } @@ -1551,21 +1552,21 @@ void ServerWindow::DispatchMessage(int32 code) int32 mainToken; team_id teamID; - fSession->ReadInt32(&mainToken); - fSession->ReadData(&teamID, sizeof(team_id)); + fSession->Read(&mainToken); + fSession->Read(&teamID, sizeof(team_id)); wb = desktop->FindWinBorderByServerWindowTokenAndTeamID(mainToken, teamID); if(wb) { - fSession->WriteInt32(SERVER_TRUE); - fSession->Sync(); + fSession->StartMessage(SERVER_TRUE); + fSession->Flush(); fWinBorder->RemoveFromSubsetOf(wb); } else { - fSession->WriteInt32(SERVER_FALSE); - fSession->Sync(); + fSession->StartMessage(SERVER_FALSE); + fSession->Flush(); } break; } @@ -1616,8 +1617,8 @@ void ServerWindow::DispatchMessage(int32 code) float xResizeBy; float yResizeBy; - fSession->ReadFloat(&xResizeBy); - fSession->ReadFloat(&yResizeBy); + fSession->Read(&xResizeBy); + fSession->Read(&yResizeBy); fWinBorder->ResizeBy(xResizeBy, yResizeBy); @@ -1628,8 +1629,8 @@ void ServerWindow::DispatchMessage(int32 code) float xMoveBy; float yMoveBy; - fSession->ReadFloat(&xMoveBy); - fSession->ReadFloat(&yMoveBy); + fSession->Read(&xMoveBy); + fSession->Read(&yMoveBy); fWinBorder->MoveBy(xMoveBy, yMoveBy); @@ -2216,14 +2217,18 @@ void ServerWindow::DispatchGraphicsMessage(int32 msgsize, int8 *msgbuffer) int32 ServerWindow::MonitorWin(void *data) { ServerWindow *win = (ServerWindow *)data; - BSession *ses = win->fSession; + BPortLink *ses = win->fSession; bool quitting = false; int32 code; + status_t err = B_OK; while(!quitting) { + printf("info: ServerWindow::MonitorWin listening on port %ld.\n", win->fMessagePort); code = AS_CLIENT_DEAD; - ses->ReadInt32(&code); + err = ses->GetNextReply(&code); + if (err < B_OK) + return err; win->Lock(); @@ -2255,7 +2260,7 @@ int32 ServerWindow::MonitorWin(void *data) win->Unlock(); } - return 0; + return err; } //------------------------------------------------------------------------------ Layer* ServerWindow::FindLayer(const Layer* start, int32 token) const diff --git a/src/servers/app/server/ServerWindow.h b/src/servers/app/server/ServerWindow.h index 7dfee09c8b..f88f3dd4e3 100644 --- a/src/servers/app/server/ServerWindow.h +++ b/src/servers/app/server/ServerWindow.h @@ -34,7 +34,6 @@ #include #include #include -#include #include "FMWList.h" class BString; @@ -43,10 +42,9 @@ class BPoint; class BMessage; class ServerApp; class Decorator; -class PortLink; +class BPortLink; class WinBorder; class Workspace; -class BSession; class Layer; #define AS_UPDATE_DECORATOR 'asud' @@ -159,7 +157,7 @@ protected: uint32 fToken; int32 fHandlerToken; - BSession *fSession; + BPortLink *fSession; // cl is short for currentLayer. We'll use it a lot, that's why it's short :-) Layer *cl; diff --git a/src/servers/app/server/SysCursor.cpp b/src/servers/app/server/SysCursor.cpp index 818531152b..272d32e937 100644 --- a/src/servers/app/server/SysCursor.cpp +++ b/src/servers/app/server/SysCursor.cpp @@ -25,7 +25,7 @@ // //------------------------------------------------------------------------------ #include -#include +#include #include #include #include @@ -43,8 +43,8 @@ void set_syscursor(cursor_which which, const BCursor *cursor) port_id server=find_port(SERVER_PORT_NAME); if(server!=B_NAME_NOT_FOUND) { - PortLink link(server); - link.SetOpCode(AS_SET_SYSCURSOR_BCURSOR); + BPortLink link(server); + link.StartMessage(AS_SET_SYSCURSOR_BCURSOR); link.Attach(which); // The easy (and clean) way for us to access the cursor's token @@ -69,8 +69,8 @@ void set_syscursor(cursor_which which, const BBitmap *bitmap) port_id server=find_port(SERVER_PORT_NAME); if(server!=B_NAME_NOT_FOUND) { - PortLink link(server); - link.SetOpCode(AS_SET_SYSCURSOR_BBITMAP); + BPortLink link(server); + link.StartMessage(AS_SET_SYSCURSOR_BBITMAP); link.Attach(which); // Just like the BCursor version, we will use a hack until R1. @@ -89,17 +89,19 @@ void set_syscursor(cursor_which which, const BBitmap *bitmap) cursor_which get_syscursor(void) { port_id server=find_port(SERVER_PORT_NAME); - if(server!=B_NAME_NOT_FOUND) + if(server >= 0) { - PortMessage pmsg; - - PortLink link(server); - link.SetOpCode(AS_GET_SYSCURSOR); - link.FlushWithReply(&pmsg); - + int32 code = SERVER_FALSE; + BPrivate::BAppServerLink link; cursor_which which; - pmsg.Read(&which); - return which; + + link.SetSendPort(server); + link.StartMessage(AS_GET_SYSCURSOR); + link.FlushWithReply(&code); + + if (code == SERVER_TRUE) + if (link.Read(&which) == B_OK) + return which; } return B_CURSOR_INVALID; } @@ -111,10 +113,10 @@ cursor_which get_syscursor(void) void setcursor(cursor_which which) { port_id server=find_port(SERVER_PORT_NAME); - if(server!=B_NAME_NOT_FOUND) + if(server >= 0) { - PortLink link(server); - link.SetOpCode(AS_SET_CURSOR_SYSTEM); + BPortLink link(server); + link.StartMessage(AS_SET_CURSOR_SYSTEM); link.Flush(); } } @@ -270,7 +272,7 @@ status_t CursorSet::FindCursor(cursor_which which, BBitmap **cursor, BPoint *hot return B_NAME_NOT_FOUND; const void *buffer; - BString tempstr; + const char *tempstr; int32 bufferLength; BBitmap *bmp; BPoint hotpt; @@ -282,7 +284,7 @@ status_t CursorSet::FindCursor(cursor_which which, BBitmap **cursor, BPoint *hot return B_ERROR; - if(tempstr.Compare("cursor")==0) + if(strcmp(tempstr, "cursor")==0) { bmp=new BBitmap( msg.FindRect("_frame"), (color_space) msg.FindInt32("_cspace"),true ); @@ -316,7 +318,7 @@ status_t CursorSet::FindCursor(cursor_which which, ServerCursor **cursor) return B_NAME_NOT_FOUND; const void *buffer; - BString tempstr; + const char *tempstr; int32 bufferLength; ServerCursor *csr; BPoint hotpt; @@ -327,7 +329,7 @@ status_t CursorSet::FindCursor(cursor_which which, ServerCursor **cursor) if(msg.FindPoint("hotspot",&hotpt)!=B_OK) return B_ERROR; - if(tempstr.Compare("cursor")==0) + if(strcmp(tempstr, "cursor")==0) { csr=new ServerCursor(msg.FindRect("_frame"),(color_space) msg.FindInt32("_cspace"),0, hotpt); msg.FindData("_data",B_RAW_TYPE,(const void **)&buffer, (ssize_t*)&bufferLength); @@ -345,8 +347,8 @@ status_t CursorSet::FindCursor(cursor_which which, ServerCursor **cursor) */ const char *CursorSet::GetName(void) { - const char *name = NULL; - if (FindString("name", &name) == B_OK) + const char *name; + if(FindString("name",&name)==B_OK) return name; return NULL; } diff --git a/src/servers/app/server/ViewDriver.cpp b/src/servers/app/server/ViewDriver.cpp index 7e15818dbf..da53bd9c52 100644 --- a/src/servers/app/server/ViewDriver.cpp +++ b/src/servers/app/server/ViewDriver.cpp @@ -83,7 +83,7 @@ VDView::VDView(BRect bounds) // This link for sending mouse messages to the OBAppServer. // This is only to take the place of the Input Server. - serverlink=new PortLink(find_port(SERVER_INPUT_PORT)); + serverlink = new BPortLink(find_port(SERVER_INPUT_PORT)); // Create a cursor which isn't just a box cursor=new BBitmap(BRect(0,0,20,20),B_RGBA32,true); @@ -159,7 +159,7 @@ void VDView::MouseDown(BPoint pt) GetMouse(&p,&buttons); - serverlink->SetOpCode(B_MOUSE_DOWN); + serverlink->StartMessage(B_MOUSE_DOWN); serverlink->Attach(&time, sizeof(int64)); serverlink->Attach(&pt.x,sizeof(float)); serverlink->Attach(&pt.y,sizeof(float)); @@ -182,7 +182,7 @@ void VDView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg) uint32 buttons; int64 time=(int64)real_time_clock(); - serverlink->SetOpCode(B_MOUSE_MOVED); + serverlink->StartMessage(B_MOUSE_MOVED); serverlink->Attach(&time,sizeof(int64)); serverlink->Attach(&pt.x,sizeof(float)); serverlink->Attach(&pt.y,sizeof(float)); @@ -209,7 +209,7 @@ void VDView::MouseUp(BPoint pt) GetMouse(&p,&buttons); - serverlink->SetOpCode(B_MOUSE_UP); + serverlink->StartMessage(B_MOUSE_UP); serverlink->Attach(&time, sizeof(int64)); serverlink->Attach(&pt.x,sizeof(float)); serverlink->Attach(&pt.y,sizeof(float)); @@ -229,7 +229,7 @@ void VDView::MessageReceived(BMessage *msg) msg->FindFloat("be:wheel_delta_x",&x); msg->FindFloat("be:wheel_delta_y",&y); int64 time=real_time_clock(); - serverlink->SetOpCode(B_MOUSE_WHEEL_CHANGED); + serverlink->StartMessage(B_MOUSE_WHEEL_CHANGED); serverlink->Attach(&time,sizeof(int64)); serverlink->Attach(x); serverlink->Attach(y); @@ -289,7 +289,7 @@ void VDWindow::MessageReceived(BMessage *msg) msg->FindString("bytes",&string); for(int8 i=0;i<15;i++) msg->FindInt8("states",i,&keyarray[i]); - view->serverlink->SetOpCode(B_KEY_DOWN); + view->serverlink->StartMessage(B_KEY_DOWN); view->serverlink->Attach(&systime,sizeof(bigtime_t)); view->serverlink->Attach(scancode); view->serverlink->Attach(asciicode); @@ -330,7 +330,7 @@ void VDWindow::MessageReceived(BMessage *msg) msg->FindString("bytes",&string); for(int8 i=0;i<15;i++) msg->FindInt8("states",i,&keyarray[i]); - view->serverlink->SetOpCode(B_KEY_UP); + view->serverlink->StartMessage(B_KEY_UP); view->serverlink->Attach(&systime,sizeof(bigtime_t)); view->serverlink->Attach(scancode); view->serverlink->Attach(asciicode); @@ -358,7 +358,7 @@ void VDWindow::MessageReceived(BMessage *msg) msg->FindInt32("modifiers",&modifiers); for(int8 i=0;i<15;i++) msg->FindInt8("states",i,&keyarray[i]); - view->serverlink->SetOpCode(B_UNMAPPED_KEY_DOWN); + view->serverlink->StartMessage(B_UNMAPPED_KEY_DOWN); view->serverlink->Attach(&systime,sizeof(bigtime_t)); view->serverlink->Attach(scancode); view->serverlink->Attach(modifiers); @@ -382,7 +382,7 @@ void VDWindow::MessageReceived(BMessage *msg) msg->FindInt32("modifiers",&modifiers); for(int8 i=0;i<15;i++) msg->FindInt8("states",i,&keyarray[i]); - view->serverlink->SetOpCode(B_UNMAPPED_KEY_UP); + view->serverlink->StartMessage(B_UNMAPPED_KEY_UP); view->serverlink->Attach(&systime,sizeof(bigtime_t)); view->serverlink->Attach(scancode); view->serverlink->Attach(modifiers); @@ -407,7 +407,7 @@ void VDWindow::MessageReceived(BMessage *msg) msg->FindInt32("be:old_modifiers",&oldmodifiers); for(int8 i=0;i<15;i++) msg->FindInt8("states",i,&keyarray[i]); - view->serverlink->SetOpCode(B_MODIFIERS_CHANGED); + view->serverlink->StartMessage(B_MODIFIERS_CHANGED); view->serverlink->Attach(&systime,sizeof(bigtime_t)); view->serverlink->Attach(scancode); view->serverlink->Attach(modifiers); diff --git a/src/servers/app/server/ViewDriver.h b/src/servers/app/server/ViewDriver.h index 2ef02aabd7..05c4fe430f 100644 --- a/src/servers/app/server/ViewDriver.h +++ b/src/servers/app/server/ViewDriver.h @@ -40,7 +40,7 @@ #include "FontServer.h" class BBitmap; -class PortLink; +class BPortLink; class VDWindow; class DrawData; @@ -57,7 +57,7 @@ public: void MessageReceived(BMessage *msg); BBitmap *viewbmp; - PortLink *serverlink; + BPortLink *serverlink; int hide_cursor; BBitmap *cursor; @@ -160,7 +160,7 @@ protected: BView *drawview; BRegion laregion; - PortLink *serverlink; + BPortLink *serverlink; // drawing_mode drawmode; rgb_color highcolor,lowcolor; diff --git a/src/servers/app/server/WinBorder.cpp b/src/servers/app/server/WinBorder.cpp index b8edb77a5a..26297306c8 100644 --- a/src/servers/app/server/WinBorder.cpp +++ b/src/servers/app/server/WinBorder.cpp @@ -30,7 +30,7 @@ #include #include #include -#include "PortMessage.h" +#include "PortLink.h" #include "View.h" // for mouse button defines #include "ServerWindow.h" #include "Decorator.h" @@ -90,7 +90,6 @@ WinBorder::WinBorder(const BRect &r, const char *name, const int32 look, const i fMouseButtons = 0; fKeyModifiers = 0; - fServerHidden = false; fMainWinBorder = NULL; fDecorator = NULL; fTopLayer = NULL; @@ -140,7 +139,7 @@ void WinBorder::RebuildFullRegion(void) fDecorator->GetFootprint(&fFull); } -void WinBorder::MouseDown(PortMessage *msg, bool sendMessage) +void WinBorder::MouseDown(PointerEvent& evt, bool sendMessage) { if (!(Window()->IsLocked())) debugger("you must lock the attached ServerWindow object\n\t before calling WinBorder::MouseDown()\n"); @@ -150,34 +149,13 @@ void WinBorder::MouseDown(PortMessage *msg, bool sendMessage) // user clicked on WinBorder's visible region, which is in fact decorator's. // so, if true, we find out if the user clicked the decorator. - // 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 - - int64 time; - BPoint pt; - int32 modifierkeys; - int32 buttons; - int32 clicks; - - msg->Read(&time); - msg->Read(&pt.x); - msg->Read(&pt.y); - msg->Read(&modifierkeys); - msg->Read(&buttons); - msg->Read(&clicks); - - Layer *target = LayerAt(pt); + Layer *target = LayerAt(evt.where); if (target == this) { click_type action; // find out where user clicked in Decorator - action = fDecorator->Clicked(pt, buttons, modifierkeys); + action = fDecorator->Clicked(evt.where, evt.buttons, evt.modifiers); switch(action) { case DEC_CLOSE: @@ -236,42 +214,29 @@ void WinBorder::MouseDown(PortMessage *msg, bool sendMessage) else if (sendMessage){ BMessage msg; msg.what= B_MOUSE_DOWN; - msg.AddInt64("when", time); - msg.AddPoint("where", pt); - msg.AddInt32("modifiers", modifierkeys); - msg.AddInt32("buttons", buttons); - msg.AddInt32("clicks", clicks); + 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); // TODO: figure out how to specify the target // msg.AddInt32("token", token); Window()->SendMessageToClient(&msg); } - // Just to clean up any mess we've made. :) - msg->Rewind(); - - fLastMousePosition = pt; + fLastMousePosition = evt.where; } -void WinBorder::MouseMoved(PortMessage *msg) +void WinBorder::MouseMoved(PointerEvent& evt) { if (!(Window()->IsLocked())) debugger("you must lock the attached ServerWindow object\n\t before calling WinBorder::MouseMoved()\n"); - BPoint pt; - int64 dummy; - int32 buttons; - - msg->Read(&dummy); - msg->Read(&pt.x); - msg->Read(&pt.y); - msg->Read(&buttons); - msg->Rewind(); - if (fIsMoving) { STRACE_CLICK(("===> Moving...\n")); - BPoint offset = pt; + BPoint offset = evt.where; offset -= fLastMousePosition; MoveBy(offset.x, offset.y); } @@ -279,14 +244,14 @@ void WinBorder::MouseMoved(PortMessage *msg) if (fIsResizing) { STRACE_CLICK(("===> Resizing...\n")); - BPoint offset = pt; + BPoint offset = evt.where; offset -= fLastMousePosition; ResizeBy(offset.x, offset.y); } else { // Do a click test only if we have to, which would be now. :) - click_type location=fDecorator->Clicked(pt,buttons,fKeyModifiers); + click_type location=fDecorator->Clicked(evt.where, evt.buttons,fKeyModifiers); if (fIsZooming && location!=DEC_ZOOM) { @@ -306,10 +271,10 @@ void WinBorder::MouseMoved(PortMessage *msg) fDecorator->DrawMinimize(); } } - fLastMousePosition = pt; + fLastMousePosition = evt.where; } -void WinBorder::MouseUp(PortMessage *msg) +void WinBorder::MouseUp(PointerEvent& evt) { if (!(Window()->IsLocked())) debugger("you must lock the attached ServerWindow object\n\t before calling WinBorder::MouseUp()\n"); @@ -411,22 +376,7 @@ void WinBorder::ResizeBy(float x, float y) Layer::ResizeBy(x,y); } -bool WinBorder::IsHidden() const{ - if (fServerHidden) - return true; - - return Layer::IsHidden(); -} - -void WinBorder::ServerHide(){ - fServerHidden = true; -} - -void WinBorder::ServerUnhide(){ - fServerHidden = false; -} - -bool WinBorder::HasPoint(const BPoint& pt) const +bool WinBorder::HasPoint(BPoint pt) const { return fFullVisible.Contains(pt); } @@ -495,7 +445,7 @@ void WinBorder::AddToSubsetOf(WinBorder* main) { // if the main window is hidden also hide this one. if(main->IsHidden()) - Hide();//fHidden = true; + fHidden = true; // add to main window's subset main->Window()->fWinFMWList.AddItem(this); @@ -603,7 +553,7 @@ void WinBorder::PrintToStream() if (fLevel == B_NORMAL_FEEL) printf("\t%s", "B_NORMAL_WINDOW_FEEL"); - printf("\t%s\n", IsHidden()?"hidden" : "not hidden"); + printf("\t%s\n", fHidden?"hidden" : "not hidden"); } void WinBorder::UpdateColors(void) diff --git a/src/servers/app/server/WinBorder.h b/src/servers/app/server/WinBorder.h index d92e0cf502..cc064a9625 100644 --- a/src/servers/app/server/WinBorder.h +++ b/src/servers/app/server/WinBorder.h @@ -35,9 +35,23 @@ class ServerWindow; class Decorator; class DisplayDriver; -class PortMessage; class Desktop; +class PointerEvent +{ + public: + int32 code; //B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED + //B_MOUSE_WHEEL_CHANGED + bigtime_t when; + BPoint where; + float wheel_delta_x; + float wheel_delta_y; + int32 modifiers; + int32 buttons; //B_PRIMARY_MOUSE_BUTTON, B_SECONDARY_MOUSE_BUTTON + //B_TERTIARY_MOUSE_BUTTON + int32 clicks; +}; + class WinBorder : public Layer { public: @@ -52,13 +66,9 @@ public: virtual void RebuildFullRegion(void); - virtual bool IsHidden() const; - void ServerHide(); - void ServerUnhide(); - - void MouseDown(PortMessage *msg, bool sendMessage); - void MouseMoved(PortMessage *msg); - void MouseUp(PortMessage *msg); + void MouseDown(PointerEvent& evt, bool sendMessage); + void MouseMoved(PointerEvent& evt); + void MouseUp(PointerEvent& evt); void UpdateColors(void); void UpdateDecorator(void); @@ -71,7 +81,7 @@ public: void SetLevel(); void HighlightDecorator(const bool &active); - bool HasPoint(const BPoint &pt) const; + bool HasPoint(BPoint pt) const; void AddToSubsetOf(WinBorder* main); void RemoveFromSubsetOf(WinBorder* main); @@ -93,7 +103,6 @@ protected: int32 fKeyModifiers; BPoint fLastMousePosition; - bool fServerHidden; WinBorder *fMainWinBorder; bool fIsMoving; bool fIsResizing;