From dbd08f22ac82ffd8e8bff29e7a7aafca3ec279a6 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Thu, 22 Jan 2004 00:32:07 +0000 Subject: [PATCH] Moved keyboard message handling from AppServer to Desktop class Moved style to more like OpenTracker in Deskbar class git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6221 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/server/AppServer.cpp | 269 ----------- src/servers/app/server/AppServer.h | 20 +- src/servers/app/server/Desktop.cpp | 677 ++++++++++++++++++++------- src/servers/app/server/Desktop.h | 158 ++++--- 4 files changed, 590 insertions(+), 534 deletions(-) diff --git a/src/servers/app/server/AppServer.cpp b/src/servers/app/server/AppServer.cpp index f446ea8c6e..5026c8f286 100644 --- a/src/servers/app/server/AppServer.cpp +++ b/src/servers/app/server/AppServer.cpp @@ -90,7 +90,6 @@ AppServer::AppServer(void) fAppList= new BList(0); fQuittingServer= false; fExitPoller= false; - fScreenShotIndex= 1; make_decorator= NULL; // We need this in order for new_decorator to be able to instantiate new decorators @@ -773,274 +772,6 @@ void AppServer::Broadcast(int32 code) release_sem(fAppListLock); } -/*! - \brief Handles all incoming key messages - \param code ID code of the key message - \param buffer Attachment buffer of the keyboard message. Always non-NULL. - - This function handles 5 message codes: B_KEY_UP, B_KEY_DOWN, - B_UNMAPPED_KEY_UP, B_UNMAPPED_KEY_DOWN, and B_MODIFIERS_CHANGED. It filters - out any combinations which are app_server specific: - # Left Ctrl+Alt+Shift+F12 - set to 640x480x256@60Hz - # Alt + Function Key - Change workspace - # Control+Tab - Send to Deskbar for the Twitcher -*/ -void AppServer::HandleKeyMessage(int32 code, int8 *buffer) -{ - int8 *index=buffer; - - switch(code) - { - 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 - // 9) 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(int32) + (sizeof(int8) * 3); - int8 stringlength=*index; index+=stringlength; - STRACE(("Key Down: 0x%lx\n",scancode)); - if(DISPLAYDRIVER==HWDRIVER) - { - // Check for workspace change or safe video mode - if(scancode>0x01 && scancode<0x0e) - { - if(scancode==0x0d) - { - if(modifiers & (B_LEFT_COMMAND_KEY | - B_LEFT_CONTROL_KEY | B_LEFT_SHIFT_KEY)) - { - // TODO: Set to Safe Mode here. (DisplayDriver API change) - STRACE(("Safe Video Mode invoked - code unimplemented\n")); - break; - } - } - } - - if(modifiers & B_CONTROL_KEY) - { - STRACE(("Set Workspace %ld\n",scancode-1)); - //TODO: change - //SetWorkspace(scancode-2); - break; - } - - // Tab key - if(scancode==0x26 && (modifiers & B_CONTROL_KEY)) - { - ServerApp *deskbar=FindApp("application/x-vnd.Be-TSKB"); - if(deskbar) - { - printf("Send Twitcher message key to Deskbar - unimplmemented\n"); - break; - } - } - - // PrintScreen - if(scancode==0xe) - { - if(fDriver) - { - char filename[128]; - BEntry entry; - - sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); - entry.SetTo(filename); - - while(entry.Exists()) - { - fScreenShotIndex++; - sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); - } - fScreenShotIndex++; - fDriver->DumpToFile(filename); - break; - } - } - } - else - { - // F12 - if(scancode>0x1 && scancode<0xe) - { - if(scancode==0xd) - { - if(modifiers & (B_LEFT_CONTROL_KEY | B_LEFT_SHIFT_KEY | B_LEFT_OPTION_KEY)) - { - // TODO: Set to Safe Mode here. (DisplayDriver API change) - STRACE(("Safe Video Mode invoked - code unimplemented\n")); - break; - } - } - if(modifiers & (B_LEFT_SHIFT_KEY | B_LEFT_CONTROL_KEY)) - { - STRACE(("Set Workspace %ld\n",scancode-1)); - //TODO: resolve - //SetWorkspace(scancode-2); - break; - } - } - - //Tab - if(scancode==0x26 && (modifiers & B_SHIFT_KEY)) - { - STRACE(("Twitcher\n")); - ServerApp *deskbar=FindApp("application/x-vnd.Be-TSKB"); - if(deskbar) - { - printf("Send Twitcher message key to Deskbar - unimplmemented\n"); - break; - } - } - - // Pause/Break - if(scancode==0x7f) - { - if(fDriver) - { - char filename[128]; - BEntry entry; - - sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); - entry.SetTo(filename); - - while(entry.Exists()) - { - fScreenShotIndex++; - sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); - } - fScreenShotIndex++; - - fDriver->DumpToFile(filename); - break; - } - } - } - - // We got this far, so apparently it's safe to pass to the active - // window. - ServerWindow::HandleKeyEvent(code, buffer); - 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 - - // 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); - STRACE(("Key Up: 0x%lx\n",scancode)); - - if(DISPLAYDRIVER==HWDRIVER) - { - // Tab key - if(scancode==0x26 && (modifiers & B_CONTROL_KEY)) - { - ServerApp *deskbar=FindApp("application/x-vnd.Be-TSKB"); - if(deskbar) - { - printf("Send Twitcher message key to Deskbar - unimplmemented\n"); - break; - } - } - } - else - { - if(scancode==0x26 && (modifiers & B_LEFT_SHIFT_KEY)) - { - ServerApp *deskbar=FindApp("application/x-vnd.Be-TSKB"); - if(deskbar) - { - printf("Send Twitcher message key to Deskbar - unimplmemented\n"); - break; - } - } - } - - // We got this far, so apparently it's safe to pass to the active - // window. - - // fall through to the next case - ServerWindow::HandleKeyEvent(code,buffer); - 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) int32 number of elements in the key state array to follow - // 5) int8 state of all keys - - // fall through to the next case -#ifdef DEBUG_KEYHANDLING -index+=sizeof(bigtime_t); -printf("Unmapped Key Down: 0x%lx\n",*((int32*)index)); -#endif - ServerWindow::HandleKeyEvent(code,buffer); - 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) int32 number of elements in the key state array to follow - // 5) int8 state of all keys - - // fall through to the next case -#ifdef DEBUG_KEYHANDLING -index+=sizeof(bigtime_t); -printf("Unmapped Key Up: 0x%lx\n",*((int32*)index)); -#endif - ServerWindow::HandleKeyEvent(code,buffer); - 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) int32 number of elements in the key state array to follow - // 5) int8 state of all keys - -#ifdef DEBUG_KEYHANDLING -index+=sizeof(bigtime_t); -printf("Modifiers Changed\n"); -#endif - ServerWindow::HandleKeyEvent(code,buffer); - break; - } - default: - break; - } -} - /*! \brief Finds the application with the given signature \param sig MIME signature of the application to find diff --git a/src/servers/app/server/AppServer.h b/src/servers/app/server/AppServer.h index c4ca8bb08c..eb377bb504 100644 --- a/src/servers/app/server/AppServer.h +++ b/src/servers/app/server/AppServer.h @@ -39,19 +39,16 @@ public: static int32 PollerThread(void *data); static int32 PicassoThread(void *data); - thread_id Run(void); - void MainLoop(void); + thread_id Run(void); + void MainLoop(void); - bool LoadDecorator(const char *path); - void InitDecorators(void); + bool LoadDecorator(const char *path); + void InitDecorators(void); - void DispatchMessage(PortMessage *msg); - void Broadcast(int32 code); + void DispatchMessage(PortMessage *msg); + void Broadcast(int32 code); - // TODO: remove shortly! - void HandleKeyMessage(int32 code, int8 *buffer); - - ServerApp* FindApp(const char *sig); + ServerApp* FindApp(const char *sig); private: friend Decorator* new_decorator(BRect rect, const char *title, @@ -79,8 +76,6 @@ private: fDecoratorLock; DisplayDriver *fDriver; - - int32 fScreenShotIndex; }; Decorator *new_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel, @@ -89,5 +84,6 @@ Decorator *new_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel extern CursorManager *cursormanager; extern BitmapManager *bitmapmanager; extern ColorSet gui_colorset; +extern AppServer *app_server; #endif diff --git a/src/servers/app/server/Desktop.cpp b/src/servers/app/server/Desktop.cpp index 8ce3d61e94..6362d723cc 100644 --- a/src/servers/app/server/Desktop.cpp +++ b/src/servers/app/server/Desktop.cpp @@ -25,81 +25,98 @@ // //------------------------------------------------------------------------------ #include +#include #include #include +#include "AccelerantDriver.h" +#include "AppServer.h" #include "Desktop.h" -#include "RootLayer.h" -#include "ServerScreen.h" +#include "DisplayDriver.h" +#include "Globals.h" #include "Layer.h" #include "PortMessage.h" -#include "DisplayDriver.h" -#include "AccelerantDriver.h" +#include "RootLayer.h" +#include "ServerConfig.h" +#include "ServerScreen.h" +#include "ServerWindow.h" #include "ViewDriver.h" #include "WinBorder.h" #include "Workspace.h" -#include "Globals.h" -#include "ServerWindow.h" -//#define REAL_MODE +//#define DEBUG_DESKTOP +#define DEBUG_KEYHANDLING -Desktop::Desktop(void){ -// desktop = this; +#ifdef DEBUG_DESKTOP + #define STRACE(a) printf(a) +#else + #define STRACE(a) /* nothing */ +#endif +Desktop::Desktop(void) +{ fDragMessage = NULL; fActiveRootLayer = NULL; fFrontWinBorder = NULL; fFocusWinBorder = NULL; fActiveScreen = NULL; + fScreenShotIndex = 1; } -//--------------------------------------------------------------------------- -Desktop::~Desktop(void){ -//printf("~Desktop()\n"); + +Desktop::~Desktop(void) +{ if (fDragMessage) delete fDragMessage; void *ptr; - for(int32 i=0; (ptr=fRootLayerList.ItemAt(i)); i++){ + for(int32 i=0; (ptr=fRootLayerList.ItemAt(i)); i++) delete (RootLayer*)ptr; - } - for(int32 i=0; (ptr=fScreenList.ItemAt(i)); i++){ + for(int32 i=0; (ptr=fScreenList.ItemAt(i)); i++) delete (Screen*)ptr; - } - for(int32 i=0; (ptr=fWinBorderList.ItemAt(i)); i++){ + for(int32 i=0; (ptr=fWinBorderList.ItemAt(i)); i++) delete (WinBorder*)ptr; - } } -//--------------------------------------------------------------------------- -void Desktop::Init(void){ + +void Desktop::Init(void) +{ DisplayDriver *driver = NULL; - int32 driverCount = 0; - bool initDrivers = true; + int32 driverCount = 0; + bool initDrivers = true; - while(initDrivers){ + while(initDrivers) + { -#ifdef REAL_MODE - // If we're using the AccelerantDriver for rendering, eventually we will loop through - // drivers until one can't initialize in order to support multiple monitors. For now, - // we'll just load one and be done with it. - driver = new AccelerantDriver(); -#else - driver = new ViewDriver(); -#endif + if(DISPLAYDRIVER == HWDRIVER) + { + // If we're using the AccelerantDriver for rendering, eventually we will loop through + // drivers until one can't initialize in order to support multiple monitors. For now, + // we'll just load one and be done with it. + driver = new AccelerantDriver(); + } + else + { + // Eventually, it would be nice to do away with ViewDriver and replace it with + // one which uses a double-buffered BDirectWindow as a rendering context + driver = new ViewDriver(); + } - if(driver->Initialize()){ + if(driver->Initialize()) + { driverCount++; Screen *sc = new Screen(driver, BPoint(640, 480), B_RGB32, driverCount); -// TODO: be careful, it may fail to initialize! - Monitor may not support 640x480 + + // TODO: be careful, it may fail to initialize! - Monitor may not support 640x480 fScreenList.AddItem(sc); -// TODO: remove this when you have a real Driver. - if (driverCount == 1)//2) + // TODO: remove this when you have a real Driver. + if (driverCount == 1) initDrivers = false; } - else{ + else + { driver->Shutdown(); delete driver; driver = NULL; @@ -107,19 +124,20 @@ void Desktop::Init(void){ } } - if (driverCount < 1){ + if (driverCount < 1) delete this; - } - + InitMode(); SetActiveRootLayerByIndex(0); } -//--------------------------------------------------------------------------- -void Desktop::InitMode(void){ - // this is init mode for n-SS. + +void Desktop::InitMode(void) +{ + // this is init mode for n-SS. fActiveScreen = fScreenList.ItemAt(0)? (Screen*)fScreenList.ItemAt(0): NULL; - for (int32 i=0; i(fScreenList.ItemAt(index)); +// Methods for multiple monitors. +//--------------------------------------------------------------------------- + + +Screen* Desktop::ScreenAt(int32 index) const +{ + Screen *sc= static_cast(fScreenList.ItemAt(index)); return sc; } -//--------------------------------------------------------------------------- -int32 Desktop::ScreenCount() const{ + +int32 Desktop::ScreenCount(void) const +{ return fScreenList.CountItems(); } -//--------------------------------------------------------------------------- -Screen* Desktop::ActiveScreen() const{ + +Screen* Desktop::ActiveScreen(void) const +{ return fActiveScreen; } -//--------------------------------------------------------------------------- -void Desktop::SetActiveRootLayerByIndex(int32 listIndex){ - RootLayer *rl; - rl = RootLayerAt(listIndex); + +void Desktop::SetActiveRootLayerByIndex(int32 listIndex) +{ + RootLayer *rl=RootLayerAt(listIndex); + if (rl) SetActiveRootLayer(rl); } -//--------------------------------------------------------------------------- -void Desktop::SetActiveRootLayer(RootLayer* rl){ + +void Desktop::SetActiveRootLayer(RootLayer* rl) +{ if (fActiveRootLayer == rl) return; fActiveRootLayer = rl; // TODO: fix!!!!!!!!!!!!!!!!!!!!!!!! or not? - // also set he new front and focus + // also set the new front and focus // SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer()); // SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer()); @@ -173,52 +198,62 @@ void Desktop::SetActiveRootLayer(RootLayer* rl){ // hide the mouse in the old ActiveRootLayer // show the mouse in new ActiveRootLayer } -//--------------------------------------------------------------------------- -RootLayer* Desktop::ActiveRootLayer() const{ + +RootLayer* Desktop::ActiveRootLayer(void) const +{ return fActiveRootLayer; } -//--------------------------------------------------------------------------- -int32 Desktop::ActiveRootLayerIndex() const{ + +int32 Desktop::ActiveRootLayerIndex(void) const +{ int32 rootLayerCount = CountRootLayers(); - for(int32 i=0; i(fRootLayerList.ItemAt(index)); + +RootLayer* Desktop::RootLayerAt(int32 index) +{ + RootLayer *rl=static_cast(fRootLayerList.ItemAt(index)); return rl; } -//--------------------------------------------------------------------------- -int32 Desktop::CountRootLayers() const{ + +int32 Desktop::CountRootLayers() const +{ return fRootLayerList.CountItems(); } -DisplayDriver* Desktop::GetDisplayDriver() const{ +DisplayDriver* Desktop::GetDisplayDriver() const +{ return ScreenAt(0)->DDriver(); } - // Methods for layer(WinBorder) manipulation. + //--------------------------------------------------------------------------- -void Desktop::AddWinBorder(WinBorder* winBorder){ +// Methods for layer(WinBorder) manipulation. +//--------------------------------------------------------------------------- + + +void Desktop::AddWinBorder(WinBorder* winBorder) +{ if(fWinBorderList.HasItem(winBorder)) return; - // special case for Tracker background window. - if (winBorder->_level == B_SYSTEM_LAST){ - // it's added in all RottLayers - for(int32 i=0; i_level == B_SYSTEM_LAST) + { + // it's added in all RottLayers + for(int32 i=0; iAddWinBorder(winBorder); - } } - // other windows are added to the current RootLayer only. else + // other windows are added to the current RootLayer only. ActiveRootLayer()->AddWinBorder(winBorder); - // add that pointer to user winboder list so that we can keep track of them. + // add that pointer to user winboder list so that we can keep track of them. fLayerLock.Lock(); fWinBorderList.AddItem(winBorder); fLayerLock.Unlock(); @@ -227,15 +262,16 @@ void Desktop::AddWinBorder(WinBorder* winBorder){ // SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer()); // SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer()); } -//--------------------------------------------------------------------------- -void Desktop::RemoveWinBorder(WinBorder* winBorder){ - if(winBorder->_level == B_SYSTEM_LAST){ + +void Desktop::RemoveWinBorder(WinBorder* winBorder) +{ + if(winBorder->_level == B_SYSTEM_LAST) + { for(int32 i=0; iRemoveWinBorder(winBorder); } - else{ + else winBorder->GetRootLayer()->RemoveWinBorder(winBorder); - } // TODO: remove those 4? I vote for: YES! still... have to think... // if (winBorder == fFrontWinBorder) @@ -247,18 +283,22 @@ void Desktop::RemoveWinBorder(WinBorder* winBorder){ fWinBorderList.RemoveItem(winBorder); fLayerLock.Unlock(); } -//--------------------------------------------------------------------------- -bool Desktop::HasWinBorder(WinBorder* winBorder){ + +bool Desktop::HasWinBorder(WinBorder* winBorder) +{ return fWinBorderList.HasItem(winBorder); } -//--------------------------------------------------------------------------- -void Desktop::SetFrontWinBorder(WinBorder* winBorder){ + +void Desktop::SetFrontWinBorder(WinBorder* winBorder) +{ fFrontWinBorder = winBorder; -// TODO: implement + STRACE(("Desktop::SetFrontWinBorder() unimplemented!\n")); + // TODO: implement } -//--------------------------------------------------------------------------- + // TODO: remove shortly? -void Desktop::SetFocusWinBorder(WinBorder* winBorder){ +void Desktop::SetFocusWinBorder(WinBorder* winBorder) +{ if (FocusWinBorder() == winBorder && (winBorder && !winBorder->IsHidden())) return; @@ -267,51 +307,55 @@ void Desktop::SetFocusWinBorder(WinBorder* winBorder){ // NOTE: we assume both, the old and new focus layer are in the active workspace WinBorder *newFocus = NULL; - if(fFocusWinBorder){ + if(fFocusWinBorder) fFocusWinBorder->SetFocus(false); - } - if(winBorder){ -// TODO: NO! this call is to determine the correct order! NOT to rebuild/redraw anything! -// TODO: WinBorder::SetFront... will do that - both! -// TODO: modify later -// TODO: same applies for the focus state - RootLayer::SetFocus also does redraw -// Workspace::SetFocus - Only determines the focus! Just like above! -/* - newFocus = winBorder->GetRootLayer()->ActiveWorkspace()->SetFocusLayer(winBorder); - newFocus->SetFocus(true); -*/ - Workspace *aws; + if(winBorder) + { + // TODO: NO! this call is to determine the correct order! NOT to rebuild/redraw anything! + // TODO: WinBorder::SetFront... will do that - both! + // TODO: modify later + // TODO: same applies for the focus state - RootLayer::SetFocus also does redraw + // Workspace::SetFocus - Only determines the focus! Just like above! - aws = winBorder->GetRootLayer()->ActiveWorkspace(); +// newFocus = winBorder->GetRootLayer()->ActiveWorkspace()->SetFocusLayer(winBorder); +// newFocus->SetFocus(true); + + Workspace *aws; + + aws = winBorder->GetRootLayer()->ActiveWorkspace(); aws->SearchAndSetNewFocus(winBorder); - //why do put this line? Eh... I will remove it later... - newFocus = aws->FocusLayer(); + //why do put this line? Eh... I will remove it later... + newFocus = aws->FocusLayer(); aws->FocusLayer()->SetFocus(true); aws->Invalidate(); } - fFocusWinBorder = newFocus; -} -//--------------------------------------------------------------------------- -WinBorder* Desktop::FrontWinBorder(void) const{ - return fActiveRootLayer->ActiveWorkspace()->FrontLayer(); -// return fFrontWinBorder; -} -//--------------------------------------------------------------------------- -WinBorder* Desktop::FocusWinBorder(void) const{ - return fActiveRootLayer->ActiveWorkspace()->FocusLayer(); -// return fFocusWinBorder; + fFocusWinBorder = newFocus; +} + +WinBorder* Desktop::FrontWinBorder(void) const +{ + return fActiveRootLayer->ActiveWorkspace()->FrontLayer(); +} + +WinBorder* Desktop::FocusWinBorder(void) const +{ + return fActiveRootLayer->ActiveWorkspace()->FocusLayer(); } - // Input related methods //--------------------------------------------------------------------------- -void Desktop::MouseEventHandler(PortMessage *msg){ - switch(msg->Code()){ - case B_MOUSE_DOWN:{ +// Input related methods +//--------------------------------------------------------------------------- +void Desktop::MouseEventHandler(PortMessage *msg) +{ + switch(msg->Code()) + { + case B_MOUSE_DOWN: + { // Attached data: // 1) int64 - time of mouse click // 2) float - x coordinate of mouse click @@ -353,7 +397,8 @@ void Desktop::MouseEventHandler(PortMessage *msg){ } break; } - case B_MOUSE_UP:{ + case B_MOUSE_UP: + { // Attached data: // 1) int64 - time of mouse click // 2) float - x coordinate of mouse click @@ -377,7 +422,8 @@ void Desktop::MouseEventHandler(PortMessage *msg){ break; } - case B_MOUSE_MOVED:{ + case B_MOUSE_MOVED: + { // Attached data: // 1) int64 - time of mouse click // 2) float - x coordinate of mouse click @@ -402,21 +448,280 @@ void Desktop::MouseEventHandler(PortMessage *msg){ target->MouseMoved(pt,buttons); break; } - case B_MOUSE_WHEEL_CHANGED:{ + case B_MOUSE_WHEEL_CHANGED: + { // TODO: Later on, this will need to be passed onto the client ServerWindow break; } - default:{ + default: + { printf("\nDesktop::MouseEventHandler(): WARNING: unknown message\n\n"); + break; } } } -//--------------------------------------------------------------------------- -void Desktop::KeyboardEventHandler(PortMessage *msg){ + +void Desktop::KeyboardEventHandler(PortMessage *msg) +{ + int8 *index=(int8*)msg->Buffer(); + + switch(msg->Code()) + { + 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 + // 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; + if(DISPLAYDRIVER==HWDRIVER) + { + // Check for workspace change or safe video mode + if(scancode>0x01 && scancode<0x0e) + { + if(scancode==0x0d) + { + if(modifiers & (B_LEFT_COMMAND_KEY | + B_LEFT_CONTROL_KEY | B_LEFT_SHIFT_KEY)) + { + // TODO: Set to Safe Mode here. (DisplayDriver API change) + STRACE(("Safe Video Mode invoked - code unimplemented\n")); + break; + } + } + } + + if(modifiers & B_CONTROL_KEY) + { + STRACE(("Set Workspace %ld\n",scancode-1)); + + //TODO: change + //SetWorkspace(scancode-2); + break; + } + + // Tab key + if(scancode==0x26 && (modifiers & B_CONTROL_KEY)) + { + ServerApp *deskbar=app_server->FindApp("application/x-vnd.Be-TSKB"); + if(deskbar) + { + printf("Send Twitcher message key to Deskbar - unimplmemented\n"); + break; + } + } + + // PrintScreen + if(scancode==0xe) + { + if(GetDisplayDriver()) + { + char filename[128]; + BEntry entry; + + sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); + entry.SetTo(filename); + + while(entry.Exists()) + { + fScreenShotIndex++; + sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); + } + fScreenShotIndex++; + GetDisplayDriver()->DumpToFile(filename); + break; + } + } + } + else + { + // F12 + if(scancode>0x1 && scancode<0xe) + { + if(scancode==0xd) + { + if(modifiers & (B_LEFT_CONTROL_KEY | B_LEFT_SHIFT_KEY | B_LEFT_OPTION_KEY)) + { + // TODO: Set to Safe Mode here. (DisplayDriver API change) + STRACE(("Safe Video Mode invoked - code unimplemented\n")); + break; + } + } + if(modifiers & (B_LEFT_SHIFT_KEY | B_LEFT_CONTROL_KEY)) + { + STRACE(("Set Workspace %ld\n",scancode-1)); + //TODO: resolve + //SetWorkspace(scancode-2); + break; + } + } + + //Tab + if(scancode==0x26 && (modifiers & B_SHIFT_KEY)) + { + STRACE(("Twitcher\n")); + ServerApp *deskbar=app_server->FindApp("application/x-vnd.Be-TSKB"); + if(deskbar) + { + printf("Send Twitcher message key to Deskbar - unimplmemented\n"); + break; + } + } + + // Pause/Break + if(scancode==0x7f) + { + if(GetDisplayDriver()) + { + char filename[128]; + BEntry entry; + + sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); + entry.SetTo(filename); + + while(entry.Exists()) + { + fScreenShotIndex++; + sprintf(filename,"/boot/home/screen%ld.png",fScreenShotIndex); + } + fScreenShotIndex++; + + GetDisplayDriver()->DumpToFile(filename); + break; + } + } + } + + // We got this far, so apparently it's safe to pass to the active + // window. + + // TODO: Pass on to ServerWindow? WinBorder? Client window? + 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 + + // 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); + STRACE(("Key Up: 0x%lx\n",scancode)); + + if(DISPLAYDRIVER==HWDRIVER) + { + // Tab key + if(scancode==0x26 && (modifiers & B_CONTROL_KEY)) + { + ServerApp *deskbar=app_server->FindApp("application/x-vnd.Be-TSKB"); + if(deskbar) + { + printf("Send Twitcher message key to Deskbar - unimplmemented\n"); + break; + } + } + } + else + { + if(scancode==0x26 && (modifiers & B_LEFT_SHIFT_KEY)) + { + ServerApp *deskbar=app_server->FindApp("application/x-vnd.Be-TSKB"); + if(deskbar) + { + printf("Send Twitcher message key to Deskbar - unimplmemented\n"); + break; + } + } + } + + // We got this far, so apparently it's safe to pass to the active + // window. + + // TODO: Pass on to ServerWindow? WinBorder? Client window? + 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) int32 number of elements in the key state array to follow + // 5) int8 state of all keys + + #ifdef DEBUG_KEYHANDLING + index+=sizeof(bigtime_t); + printf("Unmapped Key Down: 0x%lx\n",*((int32*)index)); + #endif + // TODO: Pass on to ServerWindow? WinBorder? Client window? + 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) int32 number of elements in the key state array to follow + // 5) int8 state of all keys + + #ifdef DEBUG_KEYHANDLING + index+=sizeof(bigtime_t); + printf("Unmapped Key Up: 0x%lx\n",*((int32*)index)); + #endif + + // TODO: Pass on to ServerWindow? WinBorder? Client window? + 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) int32 number of elements in the key state array to follow + // 5) int8 state of all keys + + #ifdef DEBUG_KEYHANDLING + index+=sizeof(bigtime_t); + printf("Modifiers Changed\n"); + #endif + + // TODO: Pass on to ServerWindow? WinBorder? Client window? + break; + } + default: + break; + } } -//--------------------------------------------------------------------------- -void Desktop::SetDragMessage(BMessage* msg){ - if (fDragMessage){ + +void Desktop::SetDragMessage(BMessage* msg) +{ + if (fDragMessage) + { delete fDragMessage; fDragMessage = NULL; } @@ -424,82 +729,100 @@ void Desktop::SetDragMessage(BMessage* msg){ if (msg) fDragMessage = new BMessage(*msg); } -//--------------------------------------------------------------------------- -BMessage* Desktop::DragMessage(void) const{ + +BMessage* Desktop::DragMessage(void) const +{ return fDragMessage; } - // Methods for various desktop stuff handled by the server //--------------------------------------------------------------------------- -void Desktop::SetScrollBarInfo(const scroll_bar_info &info){ +// Methods for various desktop stuff handled by the server +//--------------------------------------------------------------------------- +void Desktop::SetScrollBarInfo(const scroll_bar_info &info) +{ fScrollBarInfo = info; } -//--------------------------------------------------------------------------- -scroll_bar_info Desktop::ScrollBarInfo(void) const{ + +scroll_bar_info Desktop::ScrollBarInfo(void) const +{ return fScrollBarInfo; } -//--------------------------------------------------------------------------- -void Desktop::SetMenuInfo(const menu_info &info){ + +void Desktop::SetMenuInfo(const menu_info &info) +{ fMenuInfo = info; } -//--------------------------------------------------------------------------- -menu_info Desktop::MenuInfo(void) const{ + +menu_info Desktop::MenuInfo(void) const +{ return fMenuInfo; } -//--------------------------------------------------------------------------- -void Desktop::UseFFMouse(const bool &useffm){ + +void Desktop::UseFFMouse(const bool &useffm) +{ fFFMouseMode = useffm; } -//--------------------------------------------------------------------------- -bool Desktop::FFMouseInUse(void) const{ + +bool Desktop::FFMouseInUse(void) const +{ return fFFMouseMode; } -//--------------------------------------------------------------------------- -void Desktop::SetFFMouseMode(const mode_mouse &value){ + +void Desktop::SetFFMouseMode(const mode_mouse &value) +{ fMouseMode = value; } -//--------------------------------------------------------------------------- -mode_mouse Desktop::FFMouseMode(void) const{ + +mode_mouse Desktop::FFMouseMode(void) const +{ return fMouseMode; } -//--------------------------------------------------------------------------- -bool Desktop::ReadWorkspaceData(void){ -// TODO: implement + +bool Desktop::ReadWorkspaceData(void) +{ + // TODO: implement + STRACE(("Desktop::ReadWorkspaceData unimplemented\n")); return true; } -//--------------------------------------------------------------------------- -void Desktop::SaveWorkspaceData(void){ -// TODO: implement + +void Desktop::SaveWorkspaceData(void) +{ + // TODO: implement + STRACE(("Desktop::ReadWorkspaceData unimplemented\n")); } -//--------------------------------------------------------------------------- -void Desktop::RemoveSubsetWindow(WinBorder* wb){ + +void Desktop::RemoveSubsetWindow(WinBorder* wb) +{ WinBorder *winBorder = NULL; fLayerLock.Lock(); int32 count = fWinBorderList.CountItems(); - for(int32 i=0; i < count; i++){ + for(int32 i=0; i < count; i++) + { winBorder = static_cast(fWinBorderList.ItemAt(i)); if (winBorder->_level == B_NORMAL_FEEL) winBorder->Window()->fWinFMWList.RemoveItem(wb); } fLayerLock.Unlock(); - RootLayer *rl = winBorder->GetRootLayer(); + RootLayer *rl = winBorder->GetRootLayer(); if (!fGeneralLock.IsLocked()) debugger("Desktop::RemoveWinBorder() - fGeneralLock must be locked!\n"); if (!(rl->fMainLock.IsLocked())) debugger("Desktop::RemoveWinBorder() - fMainLock must be locked!\n"); - int32 countWKs = rl->WorkspaceCount(); - for (int32 i=0; i < countWKs; i++){ + int32 countWKs = rl->WorkspaceCount(); + for (int32 i=0; i < countWKs; i++) rl->WorkspaceAt(i+1)->RemoveLayerPtr(wb); - } + } -//--------------------------------------------------------------------------- -void Desktop::PrintToStream(){ + +void Desktop::PrintToStream(void) +{ printf("RootLayer List:\n=======\n"); - for(int32 i=0; iGetName()); ((RootLayer*)fRootLayerList.ItemAt(i))->PrintToStream(); printf("-------\n"); @@ -508,16 +831,16 @@ void Desktop::PrintToStream(){ // printf("Active WinBorder: %s\n", fActiveWinBorder? fActiveWinBorder->Name(): "NULL"); printf("Screen List:\n"); - for(int32 i=0; iScreenNumber()); - } - } -//--------------------------------------------------------------------------- -WinBorder* Desktop::FindWinBorderByServerWindowTokenAndTeamID(int32 token, team_id teamID){ + +WinBorder* Desktop::FindWinBorderByServerWindowTokenAndTeamID(int32 token, team_id teamID) +{ WinBorder* wb; fLayerLock.Lock(); - for (int32 i = 0; (wb = (WinBorder*)fWinBorderList.ItemAt(i)); i++){ + for (int32 i = 0; (wb = (WinBorder*)fWinBorderList.ItemAt(i)); i++) + { if (wb->Window()->ClientToken() == token && wb->Window()->ClientTeamID() == teamID) break; @@ -526,16 +849,18 @@ WinBorder* Desktop::FindWinBorderByServerWindowTokenAndTeamID(int32 token, team_ return wb; } -//--------------------------------------------------------------------------- -void Desktop::PrintVisibleInRootLayerNo(int32 no){ + +void Desktop::PrintVisibleInRootLayerNo(int32 no) +{ if (no<0 || no>=fRootLayerList.CountItems()) return; printf("Visible windows in RootLayer %ld, Workspace %ld\n", ActiveRootLayerIndex(), ActiveRootLayer()->ActiveWorkspaceIndex()); - WinBorder *wb = NULL; - Workspace *ws = ActiveRootLayer()->ActiveWorkspace(); - for(wb = (WinBorder*)ws->GoToTopItem(); wb != NULL; wb = (WinBorder*)ws->GoToLowerItem()){ + WinBorder *wb = NULL; + Workspace *ws = ActiveRootLayer()->ActiveWorkspace(); + for(wb = (WinBorder*)ws->GoToTopItem(); wb != NULL; wb = (WinBorder*)ws->GoToLowerItem()) + { if (!wb->IsHidden()) wb->PrintToStream(); } diff --git a/src/servers/app/server/Desktop.h b/src/servers/app/server/Desktop.h index e63879c44c..6d6fc2120f 100644 --- a/src/servers/app/server/Desktop.h +++ b/src/servers/app/server/Desktop.h @@ -43,86 +43,90 @@ class DisplayDriver; class Desktop { public: - // startup methods - Desktop(void); - ~Desktop(void); - void Init(void); - void InitMode(void); // 1-BigScreen or n-SmallScreens - - // Methods for multiple monitors. - Screen* ScreenAt(int32 index) const; - int32 ScreenCount() const; - Screen* ActiveScreen() const; - - void SetActiveRootLayerByIndex(int32 listIndex); - void SetActiveRootLayer(RootLayer* rl); - RootLayer* RootLayerAt(int32 index); - RootLayer* ActiveRootLayer() const; - int32 ActiveRootLayerIndex() const; - int32 CountRootLayers() const; - DisplayDriver* GetDisplayDriver() const; - - // Methods for layer(WinBorder) manipulation. - void AddWinBorder(WinBorder* winBorder); - void RemoveWinBorder(WinBorder* winBorder); - bool HasWinBorder(WinBorder* winBorder); - void SetFrontWinBorder(WinBorder* winBorder); - void SetFocusWinBorder(WinBorder* winBorder); - WinBorder* FrontWinBorder(void) const; - WinBorder* FocusWinBorder(void) const; - - // Input related methods - void MouseEventHandler(PortMessage *msg); - void KeyboardEventHandler(PortMessage *msg); - - void SetDragMessage(BMessage* msg); - BMessage* DragMessage(void) const; - - // Methods for various desktop stuff handled by the server - void SetScrollBarInfo(const scroll_bar_info &info); - scroll_bar_info ScrollBarInfo(void) const; - - void SetMenuInfo(const menu_info &info); - menu_info MenuInfo(void) const; - - - void UseFFMouse(const bool &useffm); - bool FFMouseInUse(void) const; - void SetFFMouseMode(const mode_mouse &value); - mode_mouse FFMouseMode(void) const; - - bool ReadWorkspaceData(void); - void SaveWorkspaceData(void); - -// Debugging methods - void PrintToStream(); - void PrintVisibleInRootLayerNo(int32 no); - -// "Private" to app_server :-) - means they should not be used very much - void RemoveSubsetWindow(WinBorder* wb); - WinBorder* FindWinBorderByServerWindowTokenAndTeamID(int32 token, team_id teamID); - - BLocker fGeneralLock; - BLocker fLayerLock; - BList fWinBorderList; + // startup methods + Desktop(void); + ~Desktop(void); + void Init(void); + // 1-BigScreen or n-SmallScreens + void InitMode(void); + + // Methods for multiple monitors. + Screen *ScreenAt(int32 index) const; + int32 ScreenCount(void) const; + Screen* ActiveScreen(void) const; + + void SetActiveRootLayerByIndex(int32 listIndex); + void SetActiveRootLayer(RootLayer* rl); + RootLayer* RootLayerAt(int32 index); + RootLayer* ActiveRootLayer(void) const; + int32 ActiveRootLayerIndex(void) const; + int32 CountRootLayers(void) const; + DisplayDriver* GetDisplayDriver(void) const; + + // Methods for layer(WinBorder) manipulation. + void AddWinBorder(WinBorder* winBorder); + void RemoveWinBorder(WinBorder* winBorder); + bool HasWinBorder(WinBorder* winBorder); + void SetFrontWinBorder(WinBorder* winBorder); + void SetFocusWinBorder(WinBorder* winBorder); + WinBorder* FrontWinBorder(void) const; + WinBorder* FocusWinBorder(void) const; + + // Input related methods + void MouseEventHandler(PortMessage *msg); + void KeyboardEventHandler(PortMessage *msg); + + void SetDragMessage(BMessage* msg); + BMessage* DragMessage(void) const; + + // Methods for various desktop stuff handled by the server + void SetScrollBarInfo(const scroll_bar_info &info); + scroll_bar_info ScrollBarInfo(void) const; + + void SetMenuInfo(const menu_info &info); + menu_info MenuInfo(void) const; + + + void UseFFMouse(const bool &useffm); + bool FFMouseInUse(void) const; + void SetFFMouseMode(const mode_mouse &value); + mode_mouse FFMouseMode(void) const; + + bool ReadWorkspaceData(void); + void SaveWorkspaceData(void); + + // Debugging methods + void PrintToStream(void); + void PrintVisibleInRootLayerNo(int32 no); + + // "Private" to app_server :-) - means they should not be used very much + void RemoveSubsetWindow(WinBorder* wb); + WinBorder* FindWinBorderByServerWindowTokenAndTeamID(int32 token, team_id teamID); + + BLocker fGeneralLock; + BLocker fLayerLock; + BList fWinBorderList; + private: + BMessage *fDragMessage; + + BList fRootLayerList; + RootLayer* fActiveRootLayer; + WinBorder* fFrontWinBorder; + WinBorder* fFocusWinBorder; + + BList fScreenList; - BMessage *fDragMessage; - - BList fRootLayerList; - RootLayer* fActiveRootLayer; - WinBorder* fFrontWinBorder; - WinBorder* fFocusWinBorder; - - BList fScreenList; - int32 fScreenMode; // '1' or 'n' Screen(s). Not sure it's needed though. - Screen* fActiveScreen; - - scroll_bar_info fScrollBarInfo; - menu_info fMenuInfo; - mode_mouse fMouseMode; - bool fFFMouseMode; + // '1' or 'n' Screen(s). Not sure it's needed though. + int32 fScreenMode; + Screen* fActiveScreen; + + scroll_bar_info fScrollBarInfo; + menu_info fMenuInfo; + mode_mouse fMouseMode; + bool fFFMouseMode; + int32 fScreenShotIndex; }; extern Desktop* desktop;