new desktop management code

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6057 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2004-01-13 00:56:36 +00:00
parent 67e7217c89
commit 158c46331a
14 changed files with 1387 additions and 1290 deletions
+112 -133
View File
@@ -38,7 +38,6 @@
#include <Message.h> #include <Message.h>
#include "AppServer.h" #include "AppServer.h"
#include "ColorSet.h" #include "ColorSet.h"
#include "Desktop.h"
#include "DisplayDriver.h" #include "DisplayDriver.h"
#include "ServerApp.h" #include "ServerApp.h"
#include "ServerCursor.h" #include "ServerCursor.h"
@@ -50,6 +49,7 @@
#include "CursorManager.h" #include "CursorManager.h"
#include "Utils.h" #include "Utils.h"
#include "FontServer.h" #include "FontServer.h"
#include "Desktop.h"
//#define DEBUG_KEYHANDLING //#define DEBUG_KEYHANDLING
#ifdef DEBUG_KEYHANDLING #ifdef DEBUG_KEYHANDLING
@@ -60,6 +60,8 @@
#endif #endif
// Globals // Globals
Desktop* desktop;
//! Used to access the app_server from new_decorator //! Used to access the app_server from new_decorator
AppServer *app_server=NULL; AppServer *app_server=NULL;
@@ -81,14 +83,14 @@ AppServer::AppServer(void) : BApplication (SERVER_SIGNATURE)
AppServer::AppServer(void) AppServer::AppServer(void)
#endif #endif
{ {
_mouseport=create_port(200,SERVER_INPUT_PORT); _mouseport = create_port(200,SERVER_INPUT_PORT);
_messageport=create_port(200,SERVER_PORT_NAME); _messageport = create_port(200,SERVER_PORT_NAME);
_applist=new BList(0); _applist = new BList(0);
_quitting_server=false; _quitting_server= false;
_exit_poller=false; _exit_poller = false;
_ssindex=1; _ssindex = 1;
make_decorator=NULL; make_decorator = NULL;
// Create the font server and scan the proper directories. // Create the font server and scan the proper directories.
fontserver=new FontServer; fontserver=new FontServer;
@@ -123,29 +125,27 @@ AppServer::AppServer(void)
InitDecorators(); InitDecorators();
// Set up the Desktop // Set up the Desktop
desktop=new Desktop(); desktop = new Desktop();
desktop->Init();
// Create the cursor manager. Object declared in CursorManager.cpp // Create the cursor manager. Object declared in CursorManager.cpp
cursormanager=new CursorManager(); cursormanager = new CursorManager();
cursormanager->SetCursor(B_CURSOR_DEFAULT); cursormanager->SetCursor(B_CURSOR_DEFAULT);
// Create the bitmap allocator. Object declared in BitmapManager.cpp // Create the bitmap allocator. Object declared in BitmapManager.cpp
bitmapmanager=new BitmapManager(); bitmapmanager = new BitmapManager();
// This is necessary to mediate access between the Poller and app_server threads // This is necessary to mediate access between the Poller and app_server threads
_active_lock=create_sem(1,"app_server_active_sem"); _active_lock = create_sem(1,"app_server_active_sem");
// This locker is for app_server and Picasso to vy for control of the ServerApp list // This locker is for app_server and Picasso to vy for control of the ServerApp list
_applist_lock=create_sem(1,"app_server_applist_sem"); _applist_lock = create_sem(1,"app_server_applist_sem");
// This locker is to mediate access to the make_decorator pointer // This locker is to mediate access to the make_decorator pointer
_decor_lock=create_sem(1,"app_server_decor_sem"); _decor_lock = create_sem(1,"app_server_decor_sem");
// Get the driver first - Poller thread utilizes the thing
_driver=desktop->GetGfxDriver();
// Spawn our input-polling thread // Spawn our input-polling thread
_poller_id=spawn_thread(PollerThread, "Poller", B_NORMAL_PRIORITY, this); _poller_id = spawn_thread(PollerThread, "Poller", B_NORMAL_PRIORITY, this);
if (_poller_id >= 0) if (_poller_id >= 0)
resume_thread(_poller_id); resume_thread(_poller_id);
@@ -154,9 +154,7 @@ AppServer::AppServer(void)
if (_picasso_id >= 0) if (_picasso_id >= 0)
resume_thread(_picasso_id); resume_thread(_picasso_id);
_active_app=-1; decorator_name = "Default";
_p_active_app=NULL;
decorator_name="Default";
} }
/*! /*!
@@ -183,6 +181,8 @@ AppServer::~AppServer(void)
delete bitmapmanager; delete bitmapmanager;
delete cursormanager; delete cursormanager;
delete desktop;
// If these threads are still running, kill them - after this, if exit_poller // If these threads are still running, kill them - after this, if exit_poller
// is deleted, who knows what will happen... These things will just return an // is deleted, who knows what will happen... These things will just return an
// error and fail if the threads have already exited. // error and fail if the threads have already exited.
@@ -192,8 +192,6 @@ AppServer::~AppServer(void)
delete fontserver; delete fontserver;
make_decorator=NULL; make_decorator=NULL;
delete desktop;
desktop=NULL;
} }
/*! /*!
@@ -204,7 +202,7 @@ AppServer::~AppServer(void)
int32 AppServer::PollerThread(void *data) int32 AppServer::PollerThread(void *data)
{ {
// This thread handles nothing but input messages for mouse and keyboard // This thread handles nothing but input messages for mouse and keyboard
AppServer *appserver=(AppServer*)data; AppServer *appserver = (AppServer*)data;
PortQueue mousequeue(appserver->_mouseport); PortQueue mousequeue(appserver->_mouseport);
PortMessage *msg; PortMessage *msg;
@@ -215,7 +213,7 @@ int32 AppServer::PollerThread(void *data)
else else
mousequeue.GetMessagesFromPort(false); mousequeue.GetMessagesFromPort(false);
msg=mousequeue.GetMessageFromQueue(); msg = mousequeue.GetMessageFromQueue();
if(!msg) if(!msg)
continue; continue;
@@ -227,44 +225,18 @@ int32 AppServer::PollerThread(void *data)
case B_MOUSE_DOWN: case B_MOUSE_DOWN:
case B_MOUSE_UP: case B_MOUSE_UP:
case B_MOUSE_WHEEL_CHANGED: case B_MOUSE_WHEEL_CHANGED:
{
if(!msg->Buffer())
break;
ServerWindow::HandleMouseEvent(msg);
break;
}
// Process the cursor and then pass it on
case B_MOUSE_MOVED: case B_MOUSE_MOVED:
{ desktop->MouseEventHandler(msg);
// Attached data:
// 1) int64 - time of mouse click
// 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click
// 4) int32 - buttons down
int64 dummy;
float tempx=0,tempy=0;
msg->Read<int64>(&dummy);
msg->Read<float>(&tempx);
msg->Read<float>(&tempy);
msg->Rewind();
if(appserver->_driver)
{
appserver->_driver->MoveCursorTo(tempx,tempy);
ServerWindow::HandleMouseEvent(msg);
}
break; break;
}
case B_KEY_DOWN: case B_KEY_DOWN:
case B_KEY_UP: case B_KEY_UP:
case B_UNMAPPED_KEY_DOWN: case B_UNMAPPED_KEY_DOWN:
case B_UNMAPPED_KEY_UP: case B_UNMAPPED_KEY_UP:
case B_MODIFIERS_CHANGED: case B_MODIFIERS_CHANGED:
appserver->HandleKeyMessage(msg->Code(),(int8*)msg->Buffer()); desktop->KeyboardEventHandler(msg);
break; break;
default: default:
printf("Server::Poller received unexpected code %lx\n",msg->Code()); printf("Server::Poller received unexpected code %lx\n",msg->Code());
break; break;
@@ -286,14 +258,14 @@ int32 AppServer::PollerThread(void *data)
int32 AppServer::PicassoThread(void *data) int32 AppServer::PicassoThread(void *data)
{ {
int32 i; int32 i;
AppServer *appserver=(AppServer*)data; AppServer *appserver = (AppServer*)data;
ServerApp *app; ServerApp *app;
for(;;) for(;;)
{ {
acquire_sem(appserver->_applist_lock); acquire_sem(appserver->_applist_lock);
for(i=0;i<appserver->_applist->CountItems(); i++) for(i = 0; i < appserver->_applist->CountItems(); i++)
{ {
app=(ServerApp*)appserver->_applist->ItemAt(i); app = (ServerApp*)appserver->_applist->ItemAt(i);
if(!app) if(!app)
{ {
printf("PANIC: NULL app in app list\n"); printf("PANIC: NULL app in app list\n");
@@ -332,9 +304,9 @@ void AppServer::MainLoop(void)
for(;;) for(;;)
{ {
if(pmsg.ReadFromPort(_messageport)==B_OK) if(pmsg.ReadFromPort(_messageport) == B_OK)
{ {
if(pmsg.Protocol()==B_QUIT_REQUESTED) if(pmsg.Protocol() == B_QUIT_REQUESTED)
pmsg.SetCode(B_QUIT_REQUESTED); pmsg.SetCode(B_QUIT_REQUESTED);
switch(pmsg.Code()) switch(pmsg.Code())
@@ -364,13 +336,10 @@ void AppServer::MainLoop(void)
if(pmsg.Code()==AS_DELETE_APP || (pmsg.Protocol()==B_QUIT_REQUESTED && DISPLAYDRIVER!=HWDRIVER)) if(pmsg.Code()==AS_DELETE_APP || (pmsg.Protocol()==B_QUIT_REQUESTED && DISPLAYDRIVER!=HWDRIVER))
{ {
if(_quitting_server==true && _applist->CountItems()==0) if(_quitting_server == true && _applist->CountItems() == 0)
break; break;
} }
} }
// Make sure our polling thread has exited
if(find_thread("Poller")!=B_NAME_NOT_FOUND)
kill_thread(_poller_id);
} }
/*! /*!
@@ -392,16 +361,16 @@ bool AppServer::LoadDecorator(const char *path)
// internal one // internal one
if(!path) if(!path)
{ {
make_decorator=NULL; make_decorator = NULL;
return true; return true;
} }
create_decorator *pcreatefunc=NULL; create_decorator *pcreatefunc = NULL;
status_t stat; status_t stat;
image_id addon; image_id addon;
addon=load_add_on(path); addon = load_add_on(path);
if(addon<0) if(addon < 0)
return false; return false;
// As of now, we do nothing with decorator versions, but the possibility exists // As of now, we do nothing with decorator versions, but the possibility exists
@@ -410,19 +379,18 @@ bool AppServer::LoadDecorator(const char *path)
// go here. // go here.
// Get the instantiation function // Get the instantiation function
stat=get_image_symbol(addon, "instantiate_decorator", B_SYMBOL_TYPE_TEXT, (void**)&pcreatefunc); 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); unload_add_on(addon);
return false; return false;
} }
BPath temppath(path); BPath temppath(path);
decorator_name=temppath.Leaf(); decorator_name = temppath.Leaf();
acquire_sem(_decor_lock); acquire_sem(_decor_lock);
make_decorator=pcreatefunc; make_decorator = pcreatefunc;
_decorator_id=addon; _decorator_id = addon;
release_sem(_decor_lock); release_sem(_decor_lock);
return true; return true;
} }
@@ -477,17 +445,23 @@ void AppServer::DispatchMessage(PortMessage *msg)
// Attached data: // Attached data:
// 1) port_id - receiver port of a regular app // 1) port_id - receiver port of a regular app
// 2) int32 - handler token of the regular app // 2) port_id - client looper port - for send messages to the client
// 2) char * - signature of the regular app // 2) team_id - app's team ID
// 3) port_id - port to reply to // 3) int32 - handler token of the regular app
// 4) char * - signature of the regular app
// 5) port_id - port to reply to
// Find the necessary data // Find the necessary data
team_id clientTeamID;
port_id clientLooperPort;
port_id reply_port; port_id reply_port;
port_id app_port; port_id app_port;
int32 htoken; int32 htoken;
char *app_signature; char* app_signature;
msg->Read<int32>(&app_port); msg->Read<port_id>(&app_port);
msg->Read<port_id>(&clientLooperPort);
msg->Read<team_id>(&clientTeamID);
msg->Read<int32>(&htoken); msg->Read<int32>(&htoken);
msg->ReadString(&app_signature); msg->ReadString(&app_signature);
msg->Read<int32>(&reply_port); msg->Read<int32>(&reply_port);
@@ -495,22 +469,21 @@ void AppServer::DispatchMessage(PortMessage *msg)
// Create the ServerApp subthread for this app // Create the ServerApp subthread for this app
acquire_sem(_applist_lock); acquire_sem(_applist_lock);
port_id r=create_port(DEFAULT_MONITOR_PORT_SIZE,app_signature); port_id r = create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature);
if(r==B_NO_MORE_PORTS || r==B_BAD_VALUE) if(r == B_NO_MORE_PORTS || r == B_BAD_VALUE)
{ {
release_sem(_applist_lock); release_sem(_applist_lock);
printf("No more ports left. Time to crash. Have a nice day! :)\n"); printf("No more ports left. Time to crash. Have a nice day! :)\n");
break; break;
} }
ServerApp *newapp=new ServerApp(app_port,r,htoken,app_signature); ServerApp *newapp;
newapp = new ServerApp(app_port, r, clientLooperPort, clientTeamID, htoken, app_signature);
// add the new ServerApp to the known list of ServerApps
_applist->AddItem(newapp); _applist->AddItem(newapp);
release_sem(_applist_lock); release_sem(_applist_lock);
acquire_sem(_active_lock);
_p_active_app=newapp;
_active_app=_applist->CountItems()-1;
PortLink replylink(reply_port); PortLink replylink(reply_port);
replylink.SetOpCode(AS_SET_SERVER_PORT); replylink.SetOpCode(AS_SET_SERVER_PORT);
replylink.Attach<int32>(newapp->_receiver); replylink.Attach<int32>(newapp->_receiver);
@@ -519,9 +492,6 @@ void AppServer::DispatchMessage(PortMessage *msg)
// This is necessary because PortLink::ReadString allocates memory // This is necessary because PortLink::ReadString allocates memory
delete app_signature; delete app_signature;
release_sem(_active_lock);
newapp->Run();
break; break;
} }
case AS_DELETE_APP: case AS_DELETE_APP:
@@ -532,47 +502,32 @@ void AppServer::DispatchMessage(PortMessage *msg)
// Attached Data: // Attached Data:
// 1) thread_id - thread ID of the ServerApp to be deleted // 1) thread_id - thread ID of the ServerApp to be deleted
int32 i, appnum=_applist->CountItems(); int32 i,
appnum = _applist->CountItems();
ServerApp *srvapp; ServerApp *srvapp;
thread_id srvapp_id; thread_id srvapp_id;
msg->Read<thread_id>(&srvapp_id); msg->Read<thread_id>(&srvapp_id);
// Run through the list of apps and nuke the proper one
for(i=0;i<appnum;i++)
{
srvapp=(ServerApp *)_applist->ItemAt(i);
if(srvapp!=NULL && srvapp->_monitor_thread==srvapp_id)
{
acquire_sem(_applist_lock); acquire_sem(_applist_lock);
srvapp=(ServerApp *)_applist->RemoveItem(i);
if(srvapp)
{
delete srvapp;
srvapp=NULL;
}
release_sem(_applist_lock);
acquire_sem(_active_lock);
if(_applist->CountItems()==0) // Run through the list of apps and nuke the proper one
for(i = 0; i < appnum; i++)
{ {
// active==-1 signifies that no other apps are running - NOT good srvapp = (ServerApp *)_applist->ItemAt(i);
_active_app=-1;
} if(srvapp != NULL && srvapp->_monitor_thread == srvapp_id)
else
{ {
// we actually still have apps running, so make a new one active srvapp = (ServerApp *)_applist->RemoveItem(i);
if(_active_app>0) if(srvapp){
_active_app--; delete srvapp;
else srvapp = NULL;
_active_app=0;
} }
_p_active_app=(_active_app>-1)?(ServerApp*)_applist->ItemAt(_active_app):NULL;
release_sem(_active_lock);
break; // jump out of our for() loop break; // jump out of our for() loop
} }
} }
release_sem(_applist_lock);
break; break;
} }
case AS_UPDATED_CLIENT_FONTLIST: case AS_UPDATED_CLIENT_FONTLIST:
@@ -723,14 +678,34 @@ void AppServer::DispatchMessage(PortMessage *msg)
// We've been asked to quit, so (for now) broadcast to all // We've been asked to quit, so (for now) broadcast to all
// test apps to quit. This situation will occur only when the server // test apps to quit. This situation will occur only when the server
// is compiled as a regular Be application. // is compiled as a regular Be application.
if(DISPLAYDRIVER==HWDRIVER) if(DISPLAYDRIVER == HWDRIVER)
break; break;
Broadcast(AS_QUIT_APP); Broadcast(AS_QUIT_APP);
// So when we delete the last ServerApp, we can exit the server // we have to wait until *all* threads have finished!
_quitting_server=true; ServerApp *app = NULL;
_exit_poller=true; status_t rv;
acquire_sem(_applist_lock);
for(int32 i = 0; i < _applist->CountItems(); i++)
{
app = (ServerApp*)_applist->ItemAt(i);
if(!app)
{ printf("PANIC in AppServer::Broadcast()\n"); continue; }
wait_for_thread(app->_monitor_thread, &rv);
}
release_sem(_applist_lock);
// When we delete the last ServerApp, we can exit the server
_quitting_server = true;
_exit_poller = true;
// also wait for picasso thread
wait_for_thread(_picasso_id, &rv);
// poller thread is stuck reading messages from its input port
// so, there is no cleaner way to make it quit, other than killing it!
kill_thread(_poller_id);
// we are now clear to exit
break; break;
} }
case AS_SET_SYSCURSOR_DEFAULTS: case AS_SET_SYSCURSOR_DEFAULTS:
@@ -752,15 +727,14 @@ void AppServer::DispatchMessage(PortMessage *msg)
*/ */
void AppServer::Broadcast(int32 code) void AppServer::Broadcast(int32 code)
{ {
int32 i; ServerApp *app = NULL;
ServerApp *app;
acquire_sem(_applist_lock); acquire_sem(_applist_lock);
for(i=0;i<_applist->CountItems(); i++) for(int32 i = 0; i < _applist->CountItems(); i++)
{ {
app=(ServerApp*)_applist->ItemAt(i); app = (ServerApp*)_applist->ItemAt(i);
if(!app) if(!app)
continue; { printf("PANIC in AppServer::Broadcast()\n"); continue; }
app->PostMessage(code, sizeof(int32), (int8*)&code); app->PostMessage(code, sizeof(int32), (int8*)&code);
} }
release_sem(_applist_lock); release_sem(_applist_lock);
@@ -824,7 +798,7 @@ void AppServer::HandleKeyMessage(int32 code, int8 *buffer)
if(modifiers & B_CONTROL_KEY) if(modifiers & B_CONTROL_KEY)
{ {
STRACE(("Set Workspace %ld\n",scancode-1)); STRACE(("Set Workspace %ld\n",scancode-1));
desktop->SetWorkspace(scancode-2); //TODO: change SetWorkspace(scancode-2);
break; break;
} }
@@ -878,7 +852,7 @@ void AppServer::HandleKeyMessage(int32 code, int8 *buffer)
if(modifiers & (B_LEFT_SHIFT_KEY | B_LEFT_CONTROL_KEY)) if(modifiers & (B_LEFT_SHIFT_KEY | B_LEFT_CONTROL_KEY))
{ {
STRACE(("Set Workspace %ld\n",scancode-1)); STRACE(("Set Workspace %ld\n",scancode-1));
desktop->SetWorkspace(scancode-2); //TODO: resolve SetWorkspace(scancode-2);
break; break;
} }
} }
@@ -1080,11 +1054,13 @@ Decorator *new_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel
int32 wflags, DisplayDriver *ddriver) int32 wflags, DisplayDriver *ddriver)
{ {
Decorator *dec=NULL; Decorator *dec=NULL;
if(!app_server->make_decorator) // Temporary solution!
dec=new DefaultDecorator(rect,wlook,wfeel,wflags);
/* if(!app_server->make_decorator)
dec=new DefaultDecorator(rect,wlook,wfeel,wflags); dec=new DefaultDecorator(rect,wlook,wfeel,wflags);
else else
dec=app_server->make_decorator(rect,wlook,wfeel,wflags); dec=app_server->make_decorator(rect,wlook,wfeel,wflags);
*/
gui_colorset.Lock(); gui_colorset.Lock();
dec->SetDriver(ddriver); dec->SetDriver(ddriver);
dec->SetColors(gui_colorset); dec->SetColors(gui_colorset);
@@ -1101,15 +1077,18 @@ Decorator *new_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel
\param argv String array of the command-line arguments \param argv String array of the command-line arguments
\return -1 if the app_server is already running, 0 if everything's OK. \return -1 if the app_server is already running, 0 if everything's OK.
*/ */
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
// There can be only one.... // There can be only one....
if(find_port(SERVER_PORT_NAME)!=B_NAME_NOT_FOUND) if(find_port(SERVER_PORT_NAME)!=B_NAME_NOT_FOUND)
return -1; return -1;
app_server=new AppServer(); // why on the heap?
/* app_server=new AppServer();
app_server->Run(); app_server->Run();
delete app_server; delete app_server;
*/
AppServer app_server;
app_server.Run();
return 0; return 0;
} }
+27 -12
View File
@@ -36,34 +36,49 @@ class AppServer : public BApplication
public: public:
AppServer(void); AppServer(void);
~AppServer(void); ~AppServer(void);
static int32 PollerThread(void *data); static int32 PollerThread(void *data);
static int32 PicassoThread(void *data); static int32 PicassoThread(void *data);
thread_id Run(void); thread_id Run(void);
void MainLoop(void); void MainLoop(void);
bool LoadDecorator(const char *path); bool LoadDecorator(const char *path);
void InitDecorators(void); void InitDecorators(void);
void DispatchMessage(PortMessage *msg); void DispatchMessage(PortMessage *msg);
void Broadcast(int32 code); void Broadcast(int32 code);
// TODO: remove shortly!
void HandleKeyMessage(int32 code, int8 *buffer); void HandleKeyMessage(int32 code, int8 *buffer);
ServerApp *FindApp(const char *sig);
ServerApp* FindApp(const char *sig);
private: private:
friend Decorator *new_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel, friend Decorator* new_decorator(BRect rect, const char *title,
int32 wlook, int32 wfeel,
int32 wflags, DisplayDriver *ddriver); int32 wflags, DisplayDriver *ddriver);
create_decorator *make_decorator; // global function pointer create_decorator *make_decorator; // global function pointer
port_id _messageport,_mouseport; port_id _messageport,
image_id _decorator_id; _mouseport;
BString decorator_name;
bool _quitting_server; image_id _decorator_id;
BList *_applist;
int32 _active_app; BString decorator_name;
ServerApp *_p_active_app;
thread_id _poller_id, _picasso_id; bool _quitting_server,
_exit_poller;
BList *_applist;
thread_id _poller_id,
_picasso_id;
sem_id _active_lock,
_applist_lock,
_decor_lock;
sem_id _active_lock, _applist_lock, _decor_lock;
bool _exit_poller;
DisplayDriver *_driver; DisplayDriver *_driver;
int32 _ssindex; int32 _ssindex;
}; };
+228 -187
View File
@@ -1,8 +1,10 @@
#include "Desktop.h" #include <stdio.h>
#include <Region.h>
#include <Message.h> #include <Message.h>
#include "Desktop.h"
#include "RootLayer.h" #include "RootLayer.h"
#include "ServerScreen.h" #include "Screen.h"
#include "Layer.h" #include "Layer.h"
#include "PortMessage.h" #include "PortMessage.h"
#include "DisplayDriver.h" #include "DisplayDriver.h"
@@ -12,72 +14,66 @@
#include "Workspace.h" #include "Workspace.h"
#include "Globals.h" #include "Globals.h"
#include "ServerWindow.h" #include "ServerWindow.h"
#include "ServerConfig.h"
#include <Region.h> //#define REAL_MODE
#include <stdio.h>
Desktop *desktop=NULL; Desktop::Desktop(void){
// desktop = this;
Desktop::Desktop(void)
{
fDragMessage = NULL; fDragMessage = NULL;
fActiveRootLayer = NULL; fActiveRootLayer = NULL;
fFrontWinBorder = NULL; fFrontWinBorder = NULL;
fFocusWinBorder = NULL; fFocusWinBorder = NULL;
fActiveScreen = NULL; fCursorScreen = NULL;
Init();
} }
//---------------------------------------------------------------------------
Desktop::~Desktop(void) Desktop::~Desktop(void){
{ //printf("~Desktop()\n");
if (fDragMessage) if (fDragMessage)
delete fDragMessage; delete fDragMessage;
void *ptr; void *ptr;
for(int32 i=0; (ptr=fRootLayerList.ItemAt(i)); i++) for(int32 i=0; (ptr=fRootLayerList.ItemAt(i)); i++){
delete (RootLayer*)ptr; delete (RootLayer*)ptr;
}
for(int32 i=0; (ptr=fScreenList.ItemAt(i)); i++) for(int32 i=0; (ptr=fScreenList.ItemAt(i)); i++){
delete (Screen*)ptr; delete (Screen*)ptr;
}
for(int32 i=0; (ptr=fWinBorderList.ItemAt(i)); i++) for(int32 i=0; (ptr=fWinBorderList.ItemAt(i)); i++){
delete (WinBorder*)ptr; delete (WinBorder*)ptr;
}
} }
//---------------------------------------------------------------------------
void Desktop::Init(void) void Desktop::Init(void){
{
DisplayDriver *driver = NULL; DisplayDriver *driver = NULL;
int32 driverCount = 0; int32 driverCount = 0;
bool initDrivers = true; bool initDrivers = true;
while(initDrivers) while(initDrivers){
{
#ifdef TEST_MODE
driver = new ViewDriver();
#else
#ifdef REAL_MODE
// If we're using the AccelerantDriver for rendering, eventually we will loop through // 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, // drivers until one can't initialize in order to support multiple monitors. For now,
// we'll just load one and be done with it. // we'll just load one and be done with it.
driver = new AccelerantDriver(); driver = new AccelerantDriver();
#endif #else
driver = new ViewDriver();
#endif
if(driver->Initialize()) if(driver->Initialize()){
{
driverCount++; driverCount++;
Screen *sc = new Screen(driver, BPoint(640, 480), B_RGB32, 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); fScreenList.AddItem(sc);
// TODO: remove this when you have a real Driver. // TODO: remove this when you have a real Driver.
if (driverCount == 2) if (driverCount == 1)//2)
initDrivers = false; initDrivers = false;
} }
else else{
{
driver->Shutdown(); driver->Shutdown();
delete driver; delete driver;
driver = NULL; driver = NULL;
@@ -85,24 +81,24 @@ void Desktop::Init(void)
} }
} }
if (driverCount < 1) if (driverCount < 1){
delete this; delete this;
}
InitMode(); InitMode();
SetActiveRootLayerByIndex(0); SetActiveRootLayerByIndex(0);
} }
//---------------------------------------------------------------------------
void Desktop::InitMode(void) void Desktop::InitMode(void){
{
// this is init mode for n-SS. // this is init mode for n-SS.
for (int32 i=0; i<fScreenList.CountItems(); i++) fCursorScreen = fScreenList.ItemAt(0)? (Screen*)fScreenList.ItemAt(0): NULL;
{ for (int32 i=0; i<fScreenList.CountItems(); i++){
char name[32]; char name[32];
sprintf(name, "RootLayer %ld", i+1); sprintf(name, "RootLayer %ld", i+1);
Screen *screens[1]; Screen *screens[1];
screens[0]= (Screen*)fScreenList.ItemAt(i); screens[0] = (Screen*)fScreenList.ItemAt(i);
RootLayer *rl = new RootLayer(name, 4, this); RootLayer *rl = new RootLayer(name, 4, this);
rl->SetScreens(screens, 1, 1); rl->SetScreens(screens, 1, 1);
@@ -111,41 +107,31 @@ void Desktop::InitMode(void)
} }
} }
// Methods for multiple monitors. // Methods for multiple monitors.
Screen* Desktop::ScreenAt(int32 index) const //---------------------------------------------------------------------------
{ Screen* Desktop::ScreenAt(int32 index) const{
Screen *sc; Screen *sc;
sc = static_cast<Screen*>(fScreenList.ItemAt(index)); sc = static_cast<Screen*>(fScreenList.ItemAt(index));
return sc; return sc;
} }
//---------------------------------------------------------------------------
int32 Desktop::ScreenCount(void) const int32 Desktop::ScreenCount() const{
{
return fScreenList.CountItems(); return fScreenList.CountItems();
} }
//---------------------------------------------------------------------------
void Desktop::SetActiveScreen(int32 index) Screen* Desktop::CursorScreen() const{
{ return fCursorScreen;
if(index<0 || index>fScreenList.CountItems()-1)
return;
// TODO: Once we get multiple monitor support going officially, we'll likely
// need to do something with the cursor here.
fActiveScreen=(Screen*)fScreenList.ItemAt(index);
} }
//---------------------------------------------------------------------------
void Desktop::SetActiveRootLayerByIndex(int32 listIndex) void Desktop::SetActiveRootLayerByIndex(int32 listIndex){
{
RootLayer *rl; RootLayer *rl;
rl = RootLayerAt(listIndex); rl = RootLayerAt(listIndex);
if (rl) if (rl)
SetActiveRootLayer(rl); SetActiveRootLayer(rl);
} }
//---------------------------------------------------------------------------
void Desktop::SetActiveRootLayer(RootLayer* rl) void Desktop::SetActiveRootLayer(RootLayer* rl){
{
if (fActiveRootLayer == rl) if (fActiveRootLayer == rl)
return; return;
@@ -155,19 +141,17 @@ void Desktop::SetActiveRootLayer(RootLayer* rl)
SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer()); SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer());
SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer()); SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer());
// TODO: other tasks required when this happens. I don't know them now. // TODO: other tasks required when this happens. I don't know them now.
// Rebuild & Invalidate // Rebuild & Invalidate
// hide the mouse in the old ActiveRootLayer // hide the mouse in the old ActiveRootLayer
// show the mouse in new ActiveRootLayer // show the mouse in new ActiveRootLayer
} }
//---------------------------------------------------------------------------
RootLayer* Desktop::ActiveRootLayer(void) const RootLayer* Desktop::ActiveRootLayer() const{
{
return fActiveRootLayer; return fActiveRootLayer;
} }
//---------------------------------------------------------------------------
int32 Desktop::ActiveRootLayerIndex(void) const int32 Desktop::ActiveRootLayerIndex() const{
{
int32 rootLayerCount = CountRootLayers(); int32 rootLayerCount = CountRootLayers();
for(int32 i=0; i<rootLayerCount; i++){ for(int32 i=0; i<rootLayerCount; i++){
if(fActiveRootLayer == (RootLayer*)(fRootLayerList.ItemAt(i))) if(fActiveRootLayer == (RootLayer*)(fRootLayerList.ItemAt(i)))
@@ -175,106 +159,189 @@ int32 Desktop::ActiveRootLayerIndex(void) const
} }
return -1; return -1;
} }
//---------------------------------------------------------------------------
RootLayer* Desktop::RootLayerAt(int32 index) RootLayer* Desktop::RootLayerAt(int32 index){
{
RootLayer *rl; RootLayer *rl;
rl = static_cast<RootLayer*>(fRootLayerList.ItemAt(index)); rl = static_cast<RootLayer*>(fRootLayerList.ItemAt(index));
return rl; return rl;
} }
//---------------------------------------------------------------------------
int32 Desktop::CountRootLayers(void) const{ int32 Desktop::CountRootLayers() const{
return fRootLayerList.CountItems(); return fRootLayerList.CountItems();
} }
// Methods for layer(WinBorder) manipulation. DisplayDriver* Desktop::GetDisplayDriver() const{
return ScreenAt(0)->DDriver();
void Desktop::AddWinBorder(WinBorder* winBorder) }
{ // Methods for layer(WinBorder) manipulation.
//---------------------------------------------------------------------------
void Desktop::AddWinBorder(WinBorder* winBorder){
if(fWinBorderList.HasItem(winBorder)) if(fWinBorderList.HasItem(winBorder))
return; return;
// special case for Tracker background window. // special case for Tracker background window.
if (winBorder->GetServerFeel() == B_SYSTEM_LAST) if (winBorder->_level == B_SYSTEM_LAST){
{
// it's added in all RottLayers // it's added in all RottLayers
for(int32 i=0; i<fRootLayerList.CountItems(); i++) for(int32 i=0; i<fRootLayerList.CountItems(); i++){
{
((RootLayer*)fRootLayerList.ItemAt(i))->AddWinBorder(winBorder); ((RootLayer*)fRootLayerList.ItemAt(i))->AddWinBorder(winBorder);
} }
} }
else
{
// other windows are added to the current RootLayer only. // other windows are added to the current RootLayer only.
else
ActiveRootLayer()->AddWinBorder(winBorder); 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); fWinBorderList.AddItem(winBorder);
fLayerLock.Unlock();
SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer()); SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer());
SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer()); SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer());
} }
//---------------------------------------------------------------------------
void Desktop::RemoveWinBorder(WinBorder* winBorder) void Desktop::RemoveWinBorder(WinBorder* winBorder){
{ if(winBorder->_level == B_SYSTEM_LAST){
if(winBorder->GetServerFeel() == B_SYSTEM_LAST)
for(int32 i=0; i<fRootLayerList.CountItems(); i++) for(int32 i=0; i<fRootLayerList.CountItems(); i++)
((RootLayer*)fRootLayerList.ItemAt(i))->RemoveWinBorder(winBorder); ((RootLayer*)fRootLayerList.ItemAt(i))->RemoveWinBorder(winBorder);
else }
else{
winBorder->GetRootLayer()->RemoveWinBorder(winBorder); winBorder->GetRootLayer()->RemoveWinBorder(winBorder);
}
if (winBorder == fFrontWinBorder) if (winBorder == fFrontWinBorder)
SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer()); SetFrontWinBorder(fActiveRootLayer->ActiveWorkspace()->FrontLayer());
if (winBorder == fFocusWinBorder) if (winBorder == fFocusWinBorder)
SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer()); SetFocusWinBorder(fActiveRootLayer->ActiveWorkspace()->FocusLayer());
fLayerLock.Lock();
fWinBorderList.RemoveItem(winBorder); fWinBorderList.RemoveItem(winBorder);
fLayerLock.Unlock();
} }
//---------------------------------------------------------------------------
bool Desktop::HasWinBorder(WinBorder* winBorder) bool Desktop::HasWinBorder(WinBorder* winBorder){
{
return fWinBorderList.HasItem(winBorder); return fWinBorderList.HasItem(winBorder);
} }
//---------------------------------------------------------------------------
void Desktop::SetFrontWinBorder(WinBorder* winBorder) void Desktop::SetFrontWinBorder(WinBorder* winBorder){
{
// TODO: implement
fFrontWinBorder = winBorder; fFrontWinBorder = winBorder;
// TODO: implement
} }
//---------------------------------------------------------------------------
void Desktop::SetFocusWinBorder(WinBorder* winBorder){
if (fFocusWinBorder == winBorder && (winBorder && !winBorder->IsHidden()))
return;
void Desktop::SetFocusWinBorder(WinBorder* winBorder) // NOTE: we assume both, the old and new focus layer are in the active workspace
{ WinBorder *newFocus = NULL;
// TODO: implement
fFocusWinBorder = winBorder; if(fFocusWinBorder){
fFocusWinBorder->SetFocus(false);
}
if(winBorder){
newFocus = winBorder->GetRootLayer()->ActiveWorkspace()->SetFocusLayer(winBorder);
newFocus->SetFocus(true);
}
fFocusWinBorder = newFocus;
} }
//---------------------------------------------------------------------------
WinBorder* Desktop::FrontWinBorder(void) const WinBorder* Desktop::FrontWinBorder(void) const{
{
return fActiveRootLayer->ActiveWorkspace()->FrontLayer(); return fActiveRootLayer->ActiveWorkspace()->FrontLayer();
// return fFrontWinBorder;
}
//---------------------------------------------------------------------------
WinBorder* Desktop::FocusWinBorder(void) const{
// return fActiveRootLayer->ActiveWorkspace()->FocusLayer();
return fFocusWinBorder;
} }
WinBorder* Desktop::FocusWinBorder(void) const // Input related methods
{ //---------------------------------------------------------------------------
return fActiveRootLayer->ActiveWorkspace()->FocusLayer(); 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
// 3) float - y coordinate of mouse click
// 4) int32 - modifier keys down
// 5) int32 - buttons down
// 6) int32 - clicks
BPoint pt;
int64 dummy;
msg->Read<int64>(&dummy);
msg->Read<float>(&pt.x);
msg->Read<float>(&pt.y);
printf("MOUSE DOWN: at (%f, %f)\n", pt.x, pt.y);
WinBorder *target;
RootLayer *rl;
Workspace *ws;
rl = ActiveRootLayer();
ws = rl->ActiveWorkspace();
target = ws->SearchLayerUnderPoint(pt);
if (target){
printf("\t '%s' was selected.\n", target->GetName());
fGeneralLock.Lock();
rl->fMainLock.Lock();
ws->SetFrontLayer(target);
SetFocusWinBorder(target);
// TODO: improve!
rl->Invalidate(rl->Bounds());
rl->fMainLock.Unlock();
fGeneralLock.Unlock();
}
break;
}
case B_MOUSE_UP:{
// 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
BPoint pt;
int64 dummy;
msg->Read<int64>(&dummy);
msg->Read<float>(&pt.x);
msg->Read<float>(&pt.y);
printf("MOUSE UP: at (%f, %f)\n", pt.x, pt.y);
break;
}
case B_MOUSE_MOVED:{
// Attached data:
// 1) int64 - time of mouse click
// 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click
// 4) int32 - buttons down
break;
}
case B_MOUSE_WHEEL_CHANGED:{
break;
}
default:{
printf("\nDesktop::MouseEventHandler(): WARNING: unknown message\n\n");
}
}
} }
//---------------------------------------------------------------------------
// Input related methods void Desktop::KeyboardEventHandler(PortMessage *msg){
void Desktop::MouseEventHandler(PortMessage *msg)
{
} }
//---------------------------------------------------------------------------
void Desktop::KeyboardEventHandler(PortMessage *msg) void Desktop::SetDragMessage(BMessage* msg){
{ if (fDragMessage){
}
void Desktop::SetDragMessage(BMessage* msg)
{
if (fDragMessage)
{
delete fDragMessage; delete fDragMessage;
fDragMessage = NULL; fDragMessage = NULL;
} }
@@ -282,86 +349,71 @@ void Desktop::SetDragMessage(BMessage* msg)
if (msg) if (msg)
fDragMessage = new BMessage(*msg); fDragMessage = new BMessage(*msg);
} }
//---------------------------------------------------------------------------
BMessage* Desktop::DragMessage(void) const BMessage* Desktop::DragMessage(void) const{
{
return fDragMessage; return fDragMessage;
} }
// Methods for various desktop stuff handled by the server // Methods for various desktop stuff handled by the server
void Desktop::SetScrollBarInfo(const scroll_bar_info &info) //---------------------------------------------------------------------------
{ void Desktop::SetScrollBarInfo(const scroll_bar_info &info){
fScrollBarInfo = info; fScrollBarInfo = info;
} }
//---------------------------------------------------------------------------
scroll_bar_info Desktop::ScrollBarInfo(void) const scroll_bar_info Desktop::ScrollBarInfo(void) const{
{
return fScrollBarInfo; return fScrollBarInfo;
} }
//---------------------------------------------------------------------------
void Desktop::SetMenuInfo(const menu_info &info) void Desktop::SetMenuInfo(const menu_info &info){
{
fMenuInfo = info; fMenuInfo = info;
} }
//---------------------------------------------------------------------------
menu_info Desktop::MenuInfo(void) const menu_info Desktop::MenuInfo(void) const{
{
return fMenuInfo; return fMenuInfo;
} }
//---------------------------------------------------------------------------
void Desktop::UseFFMouse(const bool &useffm) void Desktop::UseFFMouse(const bool &useffm){
{
fFFMouseMode = useffm; fFFMouseMode = useffm;
} }
//---------------------------------------------------------------------------
bool Desktop::FFMouseInUse(void) const bool Desktop::FFMouseInUse(void) const{
{
return fFFMouseMode; return fFFMouseMode;
} }
//---------------------------------------------------------------------------
void Desktop::SetFFMouseMode(const mode_mouse &value) void Desktop::SetFFMouseMode(const mode_mouse &value){
{
fMouseMode = value; fMouseMode = value;
} }
//---------------------------------------------------------------------------
mode_mouse Desktop::FFMouseMode(void) const mode_mouse Desktop::FFMouseMode(void) const{
{
return fMouseMode; return fMouseMode;
} }
//---------------------------------------------------------------------------
bool Desktop::ReadWorkspaceData(void) bool Desktop::ReadWorkspaceData(void){
{ // TODO: implement
// TODO: implement
return true; return true;
} }
//---------------------------------------------------------------------------
void Desktop::SaveWorkspaceData(void) void Desktop::SaveWorkspaceData(void){
{ // TODO: implement
// TODO: implement
} }
//---------------------------------------------------------------------------
void Desktop::RemoveSubsetWindow(WinBorder* wb) void Desktop::RemoveSubsetWindow(WinBorder* wb){
{
WinBorder *winBorder = NULL; WinBorder *winBorder = NULL;
int32 count = fWinBorderList.CountItems(); int32 count = fWinBorderList.CountItems();
for(int32 i=0; i < count; i++){
for(int32 i=0; i < count; i++)
{
winBorder = static_cast<WinBorder*>(fWinBorderList.ItemAt(i)); winBorder = static_cast<WinBorder*>(fWinBorderList.ItemAt(i));
if (winBorder->GetServerFeel() == B_NORMAL_FEEL) if (winBorder->_level == B_NORMAL_FEEL)
winBorder->Window()->GetFMWList()->RemoveItem(wb); winBorder->Window()->fWinFMWList.RemoveItem(wb);
} }
RootLayer *rl = winBorder->GetRootLayer(); RootLayer *rl = winBorder->GetRootLayer();
int32 countWKs = rl->WorkspaceCount(); int32 countWKs = rl->WorkspaceCount();
for (int32 i=0; i < countWKs; i++) for (int32 i=0; i < countWKs; i++){
{
rl->WorkspaceAt(i+1)->RemoveLayerPtr(wb); rl->WorkspaceAt(i+1)->RemoveLayerPtr(wb);
} }
} }
//---------------------------------------------------------------------------
void Desktop::PrintToStream(void) void Desktop::PrintToStream(){
{
printf("RootLayer List:\n=======\n"); printf("RootLayer List:\n=======\n");
for(int32 i=0; i<fRootLayerList.CountItems(); i++){ for(int32 i=0; i<fRootLayerList.CountItems(); i++){
printf("\t%s\n", ((RootLayer*)fRootLayerList.ItemAt(i))->GetName()); printf("\t%s\n", ((RootLayer*)fRootLayerList.ItemAt(i))->GetName());
@@ -369,7 +421,7 @@ void Desktop::PrintToStream(void)
printf("-------\n"); printf("-------\n");
} }
printf("=======\nActive RootLayer: %s\n", fActiveRootLayer? fActiveRootLayer->GetName(): "NULL"); printf("=======\nActive RootLayer: %s\n", fActiveRootLayer? fActiveRootLayer->GetName(): "NULL");
// printf("Active WinBorder: %s\n", fActiveWinBorder? fActiveWinBorder->Name(void): "NULL"); // printf("Active WinBorder: %s\n", fActiveWinBorder? fActiveWinBorder->Name(): "NULL");
printf("Screen List:\n"); printf("Screen List:\n");
for(int32 i=0; i<fScreenList.CountItems(); i++){ for(int32 i=0; i<fScreenList.CountItems(); i++){
@@ -377,9 +429,8 @@ void Desktop::PrintToStream(void)
} }
} }
//---------------------------------------------------------------------------
void Desktop::PrintVisibleInRootLayerNo(int32 no) void Desktop::PrintVisibleInRootLayerNo(int32 no){
{
if (no<0 || no>=fRootLayerList.CountItems()) if (no<0 || no>=fRootLayerList.CountItems())
return; return;
@@ -392,13 +443,3 @@ void Desktop::PrintVisibleInRootLayerNo(int32 no)
wb->PrintToStream(); wb->PrintToStream();
} }
} }
DisplayDriver *Desktop::GetGfxDriver(void)
{
return fActiveScreen->GetDriver();
}
void Desktop::SetWorkspace(int32 index)
{
fActiveRootLayer->SetActiveWorkspaceByIndex(index);
}
+18 -22
View File
@@ -6,13 +6,13 @@
#include <Menu.h> #include <Menu.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
class DisplayDriver;
class RootLayer; class RootLayer;
class Screen; class Screen;
class Layer; class Layer;
class BMessage; class BMessage;
class PortMessage; class PortMessage;
class WinBorder; class WinBorder;
class DisplayDriver;
class Desktop class Desktop
{ {
@@ -21,26 +21,20 @@ public:
Desktop(void); Desktop(void);
~Desktop(void); ~Desktop(void);
void Init(void); void Init(void);
void InitMode(void); // 1-BigScreen or n-SmallScreens
// 1-BigScreen or n-SmallScreens
void InitMode(void);
// Methods for multiple monitors. // Methods for multiple monitors.
Screen *ScreenAt(int32 index) const; Screen* ScreenAt(int32 index) const;
int32 ScreenCount(void) const; int32 ScreenCount() const;
Screen *ActiveScreen(void) const { return fActiveScreen; } Screen* CursorScreen() const;
void SetActiveScreen(int32 index);
void SetActiveRootLayerByIndex(int32 listIndex); void SetActiveRootLayerByIndex(int32 listIndex);
void SetActiveRootLayer(RootLayer* rl); void SetActiveRootLayer(RootLayer* rl);
RootLayer* RootLayerAt(int32 index); RootLayer* RootLayerAt(int32 index);
RootLayer* ActiveRootLayer(void) const; RootLayer* ActiveRootLayer() const;
int32 ActiveRootLayerIndex(void) const; int32 ActiveRootLayerIndex() const;
int32 CountRootLayers(void) const; int32 CountRootLayers() const;
DisplayDriver* GetDisplayDriver() const;
// Stuff for easy access
DisplayDriver *GetGfxDriver(void);
void SetWorkspace(int32 index);
// Methods for layer(WinBorder) manipulation. // Methods for layer(WinBorder) manipulation.
void AddWinBorder(WinBorder* winBorder); void AddWinBorder(WinBorder* winBorder);
@@ -74,17 +68,18 @@ public:
bool ReadWorkspaceData(void); bool ReadWorkspaceData(void);
void SaveWorkspaceData(void); void SaveWorkspaceData(void);
// Debugging methods // Debugging methods
void PrintToStream(void); void PrintToStream();
void PrintVisibleInRootLayerNo(int32 no); void PrintVisibleInRootLayerNo(int32 no);
// "Private" to app_server :-) - means they should not be used very much // "Private" to app_server :-) - means they should not be used very much
void RemoveSubsetWindow(WinBorder* wb); void RemoveSubsetWindow(WinBorder* wb);
BLocker fGeneralLock;
private:
BLocker fLayerLock; BLocker fLayerLock;
BList fWinBorderList; BList fWinBorderList;
private:
BMessage *fDragMessage; BMessage *fDragMessage;
BList fRootLayerList; BList fRootLayerList;
@@ -93,14 +88,15 @@ private:
WinBorder* fFocusWinBorder; WinBorder* fFocusWinBorder;
BList fScreenList; BList fScreenList;
int32 fScreenMode; // '1' or 'n' Screen(s). Not sure it's needed though.
Screen* fCursorScreen;
scroll_bar_info fScrollBarInfo; scroll_bar_info fScrollBarInfo;
menu_info fMenuInfo; menu_info fMenuInfo;
mode_mouse fMouseMode; mode_mouse fMouseMode;
bool fFFMouseMode; bool fFFMouseMode;
Screen *fActiveScreen;
}; };
extern Desktop* desktop; extern Desktop* desktop;
#endif // _DESKTOP_H_ #endif _DESKTOP_H_
+58 -103
View File
@@ -29,6 +29,7 @@
#include <View.h> #include <View.h>
#include <Message.h> #include <Message.h>
#include <AppDefs.h> #include <AppDefs.h>
#include <Region.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "Layer.h" #include "Layer.h"
@@ -39,7 +40,6 @@
#include "ServerCursor.h" #include "ServerCursor.h"
#include "CursorManager.h" #include "CursorManager.h"
#include "TokenHandler.h" #include "TokenHandler.h"
#include "RectUtils.h"
#include "RootLayer.h" #include "RootLayer.h"
#include "DisplayDriver.h" #include "DisplayDriver.h"
#include "Desktop.h" #include "Desktop.h"
@@ -81,6 +81,7 @@ Layer::Layer(BRect frame, const char *name, int32 token, uint32 resize,
_lowersibling = NULL; _lowersibling = NULL;
_topchild = NULL; _topchild = NULL;
_bottomchild = NULL; _bottomchild = NULL;
fRootLayer = NULL;
/* NOW all regions (_visible, _fullVisible, _full) are empty */ /* NOW all regions (_visible, _fullVisible, _full) are empty */
@@ -95,9 +96,8 @@ Layer::Layer(BRect frame, const char *name, int32 token, uint32 resize,
_serverwin = win; _serverwin = win;
_cursor = NULL; _cursor = NULL;
clipToPicture = NULL; clipToPicture = NULL;
// TODO: modify!
//TODO: Fix fDriver = desktop->GetDisplayDriver();
// fDriver = GetGfxDriver(ActiveScreen());
} }
//! Destructor frees all allocated heap space //! Destructor frees all allocated heap space
@@ -127,13 +127,20 @@ Layer::~Layer(void)
\param before Add the child in front of this layer \param before Add the child in front of this layer
\param rebuild Flag to fully rebuild all visibility regions \param rebuild Flag to fully rebuild all visibility regions
*/ */
void Layer::AddChild(Layer *layer, Layer *before) void Layer::AddChild(Layer *layer, RootLayer *rootLayer)
{ {
if( layer->_parent != NULL ) { if( layer->_parent != NULL ) {
printf("ERROR: AddChild(): Layer already has a _parent\n"); printf("ERROR: AddChild(): Layer already has a _parent\n");
return; return;
} }
if (layer->GetRootLayer()){
printf("Error: Layer already belongs to a RootLayer!\n");
return;
}
layer->fRootLayer = rootLayer;
// attach layer to the tree structure // attach layer to the tree structure
layer->_parent = this; layer->_parent = this;
if( _bottomchild ){ if( _bottomchild ){
@@ -164,24 +171,6 @@ void Layer::AddChild(Layer *layer, Layer *before)
} }
} }
/*!
\brief Used in the new Desktop Management code
*/
void Layer::AddChild(Layer *layer, RootLayer *rootLayer)
{
// TODO: Document
if (layer->GetRootLayer())
{
printf("Error: Layer already belongs to a RootLayer!\n");
return;
}
layer->fRootLayer = rootLayer;
fLayerList.AddItem(layer);
}
/*! /*!
\brief Removes a layer from the child stack \brief Removes a layer from the child stack
\param layer The layer to remove \param layer The layer to remove
@@ -193,13 +182,13 @@ void Layer::RemoveChild(Layer *layer)
printf("ERROR: RemoveChild(): Layer doesn't have a _parent\n"); printf("ERROR: RemoveChild(): Layer doesn't have a _parent\n");
return; return;
} }
if( layer->_parent != this ){
if (!(fLayerList.HasItem(layer))) printf("ERROR: RemoveChild(): Layer is not a child of this layer\n");
{
printf("Error: Layer is not a child of this RootLayer!\n");
return; return;
} }
fRootLayer = NULL;
// cache some things. The rebuilding/redrawing process will need those. // cache some things. The rebuilding/redrawing process will need those.
Layer* cachedUpperSibling = layer->_uppersibling; Layer* cachedUpperSibling = layer->_uppersibling;
@@ -236,9 +225,6 @@ void Layer::RemoveChild(Layer *layer)
DoInvalidate( BRegion(invalidRect), cachedUpperSibling ); DoInvalidate( BRegion(invalidRect), cachedUpperSibling );
} }
} }
fRootLayer = NULL;
fLayerList.RemoveItem(layer);
} }
/*! /*!
@@ -255,35 +241,23 @@ void Layer::RemoveSelf()
_parent->RemoveChild(this); _parent->RemoveChild(this);
} }
/*! bool Layer::HasChild(Layer* layer) const{
\brief Used in the new Desktop Management code for(Layer *lay = VirtualTopChild(); lay; lay = lay->VirtualLowerSibling()){
*/ if(lay == layer)
bool Layer::HasChild(Layer* layer) const return true;
{ }
return fLayerList.HasItem(layer); return false;
}
/*!
\brief Used in the new Desktop Management code
*/
void Layer::SetRootLayer(RootLayer* rl)
{
fRootLayer = rl;
} }
/*! /*!
\brief Finds the first child at a given point. \brief Finds the first child at a given point.
\param pt Point to look for a child \param pt Point to look for a child
\param recursive Flag to look for the bottom-most child
\return non-NULL if found, NULL if not \return non-NULL if found, NULL if not
Find out which child gets hit if we click at a certain spot. Returns NULL Find out which child gets hit if we click at a certain spot. Returns NULL
if there are no _visible children or if the click does not hit a child layer if there are no _visible children or if the click does not hit a child layer
If recursive==true, then it will continue to call until it reaches a layer
which has no children, i.e. a layer that is at the top of its 'branch' in
the layer tree
*/ */
Layer* Layer::GetLayerAt(const BPoint &pt) Layer* Layer::LayerAt(const BPoint &pt)
{ {
if (_visible.Contains(pt)){ if (_visible.Contains(pt)){
return this; return this;
@@ -292,7 +266,7 @@ Layer* Layer::GetLayerAt(const BPoint &pt)
if (_fullVisible.Contains(pt)){ if (_fullVisible.Contains(pt)){
Layer *lay = NULL; Layer *lay = NULL;
for ( Layer* child = _bottomchild; child != NULL; child = child->_uppersibling ){ for ( Layer* child = _bottomchild; child != NULL; child = child->_uppersibling ){
if ( (lay = child->GetLayerAt( pt )) ) if ( (lay = child->LayerAt( pt )) )
return lay; return lay;
} }
} }
@@ -421,7 +395,15 @@ void Layer::MouseTransit(uint32 transit)
void Layer::DoInvalidate(const BRegion &reg, Layer *start){ void Layer::DoInvalidate(const BRegion &reg, Layer *start){
//TODO: REMOVE this! For Test purposes only! //TODO: REMOVE this! For Test purposes only!
printf("**********Layer::DoInvalidate()\n");
if (GetRootLayer())
GetRootLayer()->Draw(GetRootLayer()->Bounds());
else{
if(dynamic_cast<RootLayer*>(this))
Draw(Bounds());
}
return; return;
//----------------
if (_hidden || !(_fullVisible.Intersects(reg.Frame())) ){ if (_hidden || !(_fullVisible.Intersects(reg.Frame())) ){
printf("SERVER: WARNING: Layer(%s)::DoInvalidate() 1 \n\n", _name->String()); printf("SERVER: WARNING: Layer(%s)::DoInvalidate() 1 \n\n", _name->String());
@@ -586,6 +568,12 @@ void Layer::Show(void)
_hidden = false; _hidden = false;
//TODO: *****!*!*!*!*!*!*!**!***REMOVE this! For Test purposes only!
printf("**********Layer::Show()\n");
DoInvalidate(BRegion(Bounds()), NULL);
return;
//----------------
// rebuild layer visible region based on its parent's and those supplied by user // rebuild layer visible region based on its parent's and those supplied by user
if (_parent){ if (_parent){
_parent->RebuildChildRegions( _full.Frame(), this ); _parent->RebuildChildRegions( _full.Frame(), this );
@@ -608,6 +596,12 @@ void Layer::Hide(void)
_hidden = true; _hidden = true;
//TODO: *****!*!*!*!*!*!*!**!***REMOVE this! For Test purposes only!
printf("**********Layer::Hide()\n");
DoInvalidate(BRegion(Bounds()), NULL);
return;
//----------------
if (_fullVisible.CountRects() > 0){ if (_fullVisible.CountRects() > 0){
BRegion cachedFullVisible = _fullVisible; BRegion cachedFullVisible = _fullVisible;
@@ -1034,7 +1028,12 @@ void Layer::RebuildRegions( const BRect& r )
} }
void Layer::RebuildFullRegion( ){ void Layer::RebuildFullRegion( ){
// TODO: temporary patch?
if (_parent && dynamic_cast<RootLayer*>(_parent) ){
}
else{
_full.Set( ConvertToTop( _frame ) ); _full.Set( ConvertToTop( _frame ) );
}
LayerData *ld; LayerData *ld;
@@ -1255,59 +1254,15 @@ BRect Layer::ConvertFromTop(BRect rect)
return(rect); return(rect);
} }
/*! RootLayer* Layer::GetRootLayer() const{
\brief Makes the layer the backmost layer belonging to its parent return fRootLayer;
This function will do nothing if the Layer has no parent or no siblings. Region
rebuilding is not performed.
*/
void Layer::MakeTopChild(void)
{
// Handle redundant and pointless cases
if(!_parent || (!_uppersibling && !_lowersibling) || _parent->_topchild==this)
return;
// Pull ourselves out of the layer tree
if(_uppersibling)
_uppersibling->_lowersibling=_lowersibling;
if(_lowersibling)
_lowersibling->_uppersibling=_uppersibling;
// Set this layer's upper/lower sib pointers to appropriate values
_uppersibling=NULL;
_lowersibling=_parent->_topchild;
// move former top child down a layer
_lowersibling->_uppersibling=this;
_parent->_topchild=this;
} }
/*! void Layer::SetRootLayer(RootLayer* rl){
\brief Makes the layer the frontmost layer belonging to its parent fRootLayer = rl;
This function will do nothing if the Layer has no parent or no siblings. Region
rebuilding is not performed.
*/
void Layer::MakeBottomChild(void)
{
// Handle redundant and pointless cases
if(!_parent || (!_uppersibling && !_lowersibling) || _parent->_bottomchild==this)
return;
// Pull ourselves out of the layer tree
if(_uppersibling)
_uppersibling->_lowersibling=_lowersibling;
if(_lowersibling)
_lowersibling->_uppersibling=_uppersibling;
// Set this layer's upper/lower sib pointers to appropriate values
_uppersibling=_parent->_bottomchild;
_lowersibling=NULL;
// move former bottom child up a layer
_uppersibling->_lowersibling=this;
_parent->_bottomchild=this;
} }
/*
@log
*/
+32 -16
View File
@@ -44,6 +44,8 @@ class WinBorder;
class Screen; class Screen;
class ServerCursor; class ServerCursor;
class DisplayDriver; class DisplayDriver;
class Desktop;
class Workspace;
/*! /*!
\class Layer Layer.h \class Layer Layer.h
@@ -56,29 +58,36 @@ class DisplayDriver;
class Layer class Layer
{ {
public: public:
Layer(BRect frame, const char *name, int32 token, uint32 resize, uint32 flags, ServerWindow *win); Layer(BRect frame, const char *name, int32 token, uint32 resize,
uint32 flags, ServerWindow *win);
virtual ~Layer(void); virtual ~Layer(void);
void AddChild(Layer *child, Layer *before=NULL); void AddChild(Layer *child, RootLayer *rootLayer);
void AddChild(Layer *layer, RootLayer *rootLayer);
void RemoveChild(Layer *child); void RemoveChild(Layer *child);
void RemoveSelf(); void RemoveSelf();
bool HasChild(Layer* layer) const; bool HasChild(Layer* layer) const;
RootLayer* GetRootLayer() const;
uint32 CountChildren(void) const; uint32 CountChildren(void) const;
void MakeTopChild(void);
void MakeBottomChild(void);
Layer* FindLayer(const int32 token); Layer* FindLayer(const int32 token);
Layer* GetLayerAt(const BPoint &pt); Layer* LayerAt(const BPoint &pt);
Layer* GetUpperSibling() const { return _uppersibling; }
Layer* GetLowerSibling() const { return _lowersibling; } virtual Layer* TopLayer() const { return _topchild; }
RootLayer *GetRootLayer() const { return fRootLayer; } virtual Layer* LowerSibling() const { return _lowersibling; }
void SetRootLayer(RootLayer* rl); virtual Layer* UpperSibling() const { return _uppersibling; }
virtual Layer* BottomLayer() const { return _bottomchild; }
virtual Layer* VirtualTopChild() const{ return _topchild; }
virtual Layer* VirtualLowerSibling() const{ return _lowersibling; }
virtual Layer* VirtualUpperSibling() const{ return _uppersibling; }
virtual Layer* VirtualBottomChild() const{ return _bottomchild; }
const char* GetName(void) const { return (_name)?_name->String():NULL; } const char* GetName(void) const { return (_name)?_name->String():NULL; }
LayerData* GetLayerData(void) const { return _layerdata; } LayerData* GetLayerData(void) const { return _layerdata; }
void SetLayerCursor(ServerCursor *csr); void SetLayerCursor(ServerCursor *csr);
ServerCursor *GetLayerCursor(void) const; ServerCursor* GetLayerCursor(void) const;
virtual void MouseTransit(uint32 transit); virtual void MouseTransit(uint32 transit);
void Invalidate(const BRect &rect); void Invalidate(const BRect &rect);
@@ -95,8 +104,8 @@ public:
void RequestDraw(const BRect &r); void RequestDraw(const BRect &r);
virtual void Draw(const BRect &r); virtual void Draw(const BRect &r);
void Show(void); virtual void Show(void);
void Hide(void); virtual void Hide(void);
bool IsHidden(void) const; bool IsHidden(void) const;
BRect Bounds(void) const; BRect Bounds(void) const;
@@ -120,11 +129,15 @@ public:
void PrintNode(void); void PrintNode(void);
void PrintTree(); void PrintTree();
// server "private" - should not be used
void SetRootLayer(RootLayer* rl);
protected: protected:
friend class RootLayer; friend class RootLayer;
friend class WinBorder; friend class WinBorder;
friend class Screen; friend class Screen;
friend class ServerWindow; friend class ServerWindow;
friend class Desktop;
friend class Workspace;
BRect _frame; BRect _frame;
BPoint _boundsLeftTop; BPoint _boundsLeftTop;
@@ -151,10 +164,13 @@ protected:
bool _is_updating; bool _is_updating;
LayerData *_layerdata; LayerData *_layerdata;
ServerCursor *_cursor; ServerCursor *_cursor;
DisplayDriver *fDriver; DisplayDriver* fDriver;
RootLayer* fRootLayer; RootLayer* fRootLayer;
BList fLayerList;
}; };
#endif #endif
/*
@log
* added a new member, BPoint _boundsLeftTop. Beside other uses, (DW don't forget!)it will be needed in redraw code.
* _flags is now declared as uint32
*/
+107 -21
View File
@@ -3,16 +3,19 @@
#include <Window.h> #include <Window.h>
#include <List.h> #include <List.h>
#include "ServerApp.h"
#include "Globals.h" #include "Globals.h"
#include "RootLayer.h" #include "RootLayer.h"
#include "Layer.h" #include "Layer.h"
#include "Workspace.h" #include "Workspace.h"
#include "ServerScreen.h" #include "Screen.h"
#include "WinBorder.h" #include "WinBorder.h"
#include "ServerWindow.h" #include "ServerWindow.h"
#include "ServerApp.h"
#include "Desktop.h" #include "Desktop.h"
#include "FMWList.h" #include "FMWList.h"
#include "DisplayDriver.h"
//#define DISPLAYDRIVER_TEST_HACK
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
RootLayer::RootLayer(const char *layername, int32 workspaceCount, Desktop *desktop) RootLayer::RootLayer(const char *layername, int32 workspaceCount, Desktop *desktop)
@@ -34,7 +37,6 @@ RootLayer::RootLayer(const char *layername, int32 workspaceCount, Desktop *deskt
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
RootLayer::~RootLayer(){ RootLayer::~RootLayer(){
//printf("~RootLayer( %s )\n", Name());
// RootLayer object just uses Screen objects, it is not allowed to delete them. // RootLayer object just uses Screen objects, it is not allowed to delete them.
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -42,8 +44,29 @@ void RootLayer::Draw(const BRect &r){
/* THIS method is here because of DisplayDriver testing! /* THIS method is here because of DisplayDriver testing!
* It SHOULD BE REMOVED as soon as testing is done!!!! * It SHOULD BE REMOVED as soon as testing is done!!!!
*/ */
/* printf("*RootLayer(%s)::Draw(r)\n", GetName());
// NOTE: (!!!) fMainLock MUST be locked when this method is called!!!
if (!fMainLock.IsLocked())
printf("\n\n\tWARNING: fMainLock MUST be locked!!!\n\n");
// NOTE: (!!!) desktop->fGeneralLock MUST be locked when this method is called!!!
if (!desktop->fGeneralLock.IsLocked())
printf("\n\n\tWARNING: desktop->fGeneralLock MUST be locked!!!\n\n");
RGBColor c(51,102,152);
fDriver->FillRect(Bounds(), c);
Workspace *as = ActiveWorkspace();
WinBorder *wb = NULL;
for (wb = as->GoToTopItem(); wb; wb = as->GoToLowerItem()){
printf("requesting draw? %s from %s\n", wb->IsHidden()?"NO":"YES", wb->GetName());
if (!(wb->IsHidden()))
wb->Draw(wb->Bounds());
}
printf("#RootLayer(%s)::Draw(r) END\n", GetName());
//--------REMOVE ABOVE--------------
#ifdef DISPLAYDRIVER_TEST_HACK #ifdef DISPLAYDRIVER_TEST_HACK
DisplayDriver *_driver = fDriver;
int8 pattern[8]; int8 pattern[8];
int8 pattern2[8]; int8 pattern2[8];
memset(pattern,255,8); memset(pattern,255,8);
@@ -104,7 +127,7 @@ void RootLayer::Draw(const BRect &r){
_driver->FillPolygon(polygon,6,polygonRect,_layerdata,pattern); _driver->FillPolygon(polygon,6,polygonRect,_layerdata,pattern);
// _driver->FillTriangle(triangle,triangleRect,_layerdata,pattern); // _driver->FillTriangle(triangle,triangleRect,_layerdata,pattern);
#endif #endif
*/
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void RootLayer::MoveBy(float x, float y){ void RootLayer::MoveBy(float x, float y){
@@ -146,11 +169,15 @@ void RootLayer::AddWinBorderToWorkspaces(WinBorder* winBorder, uint32 wks){
*/ */
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void RootLayer::AddWinBorder(WinBorder* winBorder){ void RootLayer::AddWinBorder(WinBorder* winBorder){
printf("*RootLayer::AddWinBorder(%s)\n", winBorder->GetName());
desktop->fGeneralLock.Lock();
printf("*RootLayer::AddWinBorder(%s) - General lock acquired\n", winBorder->GetName());
fMainLock.Lock();
printf("*RootLayer::AddWinBorder(%s) - Main lock acquired\n", winBorder->GetName());
// add winBorder to the known list of WinBorders so we can keep track of it. // add winBorder to the known list of WinBorders so we can keep track of it.
AddChild(winBorder, this); AddChild(winBorder, this);
// add winBorder to the desired workspaces // add winBorder to the desired workspaces
switch(winBorder->Window()->GetFeel()){ switch(winBorder->Window()->Feel()){
case B_MODAL_SUBSET_WINDOW_FEEL:{ case B_MODAL_SUBSET_WINDOW_FEEL:{
/* this kind of window isn't added anywhere. It *will* be added /* this kind of window isn't added anywhere. It *will* be added
to main window's subset when winBorder::AddToSubsetOf(main) to main window's subset when winBorder::AddToSubsetOf(main)
@@ -160,7 +187,7 @@ void RootLayer::AddWinBorder(WinBorder* winBorder){
case B_MODAL_APP_WINDOW_FEEL:{ case B_MODAL_APP_WINDOW_FEEL:{
// add to ***app's*** list of Floating/Modal Windows. // add to ***app's*** list of Floating/Modal Windows.
winBorder->Window()->GetApp()->GetFMWList()->AddItem(winBorder); winBorder->Window()->App()->fAppFMWList.AddItem(winBorder);
// determine in witch workspaces to add this winBorder. // determine in witch workspaces to add this winBorder.
uint32 wks = 0; uint32 wks = 0;
@@ -169,9 +196,9 @@ void RootLayer::AddWinBorder(WinBorder* winBorder){
Workspace *ws = WorkspaceAt(i+1); Workspace *ws = WorkspaceAt(i+1);
for (WinBorder *wb = ws->GoToBottomItem(); wb!=NULL; wb = ws->GoToUpperItem()){ for (WinBorder *wb = ws->GoToBottomItem(); wb!=NULL; wb = ws->GoToUpperItem()){
if ( !(wb->IsHidden()) && if ( !(wb->IsHidden()) &&
winBorder->Window()->GetClientTeamID() == wb->Window()->GetClientTeamID()) winBorder->Window()->ClientTeamID() == wb->Window()->ClientTeamID())
{ {
wks = wks | winBorder->Window()->GetWorkspaces(); wks = wks | winBorder->Window()->Workspaces();
break; break;
} }
} }
@@ -200,13 +227,13 @@ void RootLayer::AddWinBorder(WinBorder* winBorder){
case B_FLOATING_APP_WINDOW_FEEL:{ case B_FLOATING_APP_WINDOW_FEEL:{
// add to ***app's*** list of Floating/Modal Windows. // add to ***app's*** list of Floating/Modal Windows.
winBorder->Window()->GetApp()->GetFMWList()->AddItem(winBorder); winBorder->Window()->App()->fAppFMWList.AddItem(winBorder);
for (int32 i=0; i<WorkspaceCount(); i++){ for (int32 i=0; i<WorkspaceCount(); i++){
Workspace *ws = WorkspaceAt(i+1); Workspace *ws = WorkspaceAt(i+1);
WinBorder *wb = ws->FrontLayer(); WinBorder *wb = ws->FrontLayer();
if(wb && wb->Window()->GetClientTeamID() == winBorder->Window()->GetClientTeamID() if(wb && wb->Window()->ClientTeamID() == winBorder->Window()->ClientTeamID()
&& wb->Window()->GetFeel() == B_NORMAL_WINDOW_FEEL) && wb->Window()->Feel() == B_NORMAL_WINDOW_FEEL)
{ {
ws->AddLayerPtr(winBorder); ws->AddLayerPtr(winBorder);
} }
@@ -225,7 +252,7 @@ void RootLayer::AddWinBorder(WinBorder* winBorder){
case B_NORMAL_WINDOW_FEEL:{ case B_NORMAL_WINDOW_FEEL:{
// add this winBorder to the specified workspaces // add this winBorder to the specified workspaces
AddWinBorderToWorkspaces(winBorder, winBorder->Window()->GetWorkspaces()); AddWinBorderToWorkspaces(winBorder, winBorder->Window()->Workspaces());
break; break;
} }
@@ -238,6 +265,11 @@ void RootLayer::AddWinBorder(WinBorder* winBorder){
default: default:
break; break;
} }
fMainLock.Unlock();
printf("*RootLayer::AddWinBorder(%s) - Main lock released\n", winBorder->GetName());
desktop->fGeneralLock.Unlock();
printf("*RootLayer::AddWinBorder(%s) - General lock released\n", winBorder->GetName());
printf("#RootLayer::AddWinBorder(%s)\n", winBorder->GetName());
} }
/* This method does 3 things: /* This method does 3 things:
* 1) Removes MODAL/SUBSET windows from system/app/window subset list. * 1) Removes MODAL/SUBSET windows from system/app/window subset list.
@@ -246,8 +278,9 @@ void RootLayer::AddWinBorder(WinBorder* winBorder){
*/ */
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void RootLayer::RemoveWinBorder(WinBorder* winBorder){ void RootLayer::RemoveWinBorder(WinBorder* winBorder){
desktop->fGeneralLock.Lock();
int32 feel = winBorder->Window()->GetFeel(); fMainLock.Lock();
int32 feel = winBorder->Window()->Feel();
if(feel == B_MODAL_SUBSET_WINDOW_FEEL || feel == B_FLOATING_SUBSET_WINDOW_FEEL){ if(feel == B_MODAL_SUBSET_WINDOW_FEEL || feel == B_FLOATING_SUBSET_WINDOW_FEEL){
desktop->RemoveSubsetWindow(winBorder); desktop->RemoveSubsetWindow(winBorder);
} }
@@ -265,14 +298,17 @@ void RootLayer::RemoveWinBorder(WinBorder* winBorder){
WorkspaceAt(i+1)->RemoveLayerPtr(winBorder); WorkspaceAt(i+1)->RemoveLayerPtr(winBorder);
} }
else{ // for B_NORMAL_WINDOW_FEEL else{ // for B_NORMAL_WINDOW_FEEL
uint32 workspaces = winBorder->Window()->GetWorkspaces(); uint32 workspaces = winBorder->Window()->Workspaces();
int32 count = WorkspaceCount(); int32 count = WorkspaceCount();
for( int32 i=0; i < 32 && i < count; i++) for( int32 i=0; i < 32 && i < count; i++)
if( workspaces & (0x00000001 << i)) if( workspaces & (0x00000001UL << i)){
WorkspaceAt(i+1)->RemoveLayerPtr(winBorder); WorkspaceAt(i+1)->RemoveLayerPtr(winBorder);
} }
}
RemoveChild(winBorder); RemoveChild(winBorder);
fMainLock.Unlock();
desktop->fGeneralLock.Unlock();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void RootLayer::ChangeWorkspacesFor(WinBorder* winBorder, uint32 newWorkspaces){ void RootLayer::ChangeWorkspacesFor(WinBorder* winBorder, uint32 newWorkspaces){
@@ -280,7 +316,7 @@ void RootLayer::ChangeWorkspacesFor(WinBorder* winBorder, uint32 newWorkspaces){
if(!winBorder->_level != B_NORMAL_FEEL) if(!winBorder->_level != B_NORMAL_FEEL)
return; return;
uint32 oldWorkspaces = winBorder->Window()->GetWorkspaces(); uint32 oldWorkspaces = winBorder->Window()->Workspaces();
for(int32 i=0; i < WorkspaceCount(); i++){ for(int32 i=0; i < WorkspaceCount(); i++){
if ((oldWorkspaces & (0x00000001 << i)) && (newWorkspaces & (0x00000001 << i))){ if ((oldWorkspaces & (0x00000001 << i)) && (newWorkspaces & (0x00000001 << i))){
// do nothing. // do nothing.
@@ -294,6 +330,49 @@ void RootLayer::ChangeWorkspacesFor(WinBorder* winBorder, uint32 newWorkspaces){
} }
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool RootLayer::SetFrontWinBorder(WinBorder* winBorder){
// TODO: watch out for a NULL value
printf("*RootLayer::SetFrontWinBorder(%s)\n", winBorder? winBorder->GetName():"NULL");
fMainLock.Lock();
printf("*RootLayer::SetFrontWinBorder(%s) - main lock acquired\n", winBorder? winBorder->GetName():"NULL");
if (!winBorder){
ActiveWorkspace()->SetFrontLayer(NULL);
return true;
}
uint32 workspaces = winBorder->Window()->Workspaces();
int32 count = WorkspaceCount();
int32 newWorkspace= 0;
if (workspaces & (0x00000001UL << (ActiveWorkspaceIndex()-1)) ){
newWorkspace = ActiveWorkspaceIndex();
}
else{
int32 i;
for( i = 0; i < 32 && i < count; i++)
if( workspaces & (0x00000001UL << i)){
newWorkspace = i+1;
break;
}
if (i == count || i == 32)
newWorkspace = ActiveWorkspaceIndex();
}
if(newWorkspace != ActiveWorkspaceIndex()){
WorkspaceAt(newWorkspace)->SetFrontLayer(winBorder);
SetActiveWorkspaceByIndex(newWorkspace);
}
else{
ActiveWorkspace()->SetFrontLayer(winBorder);
}
fMainLock.Unlock();
printf("*RootLayer::SetFrontWinBorder(%s) - main lock released\n", winBorder? winBorder->GetName():"NULL");
printf("#RootLayer::SetFrontWinBorder(%s)\n", winBorder? winBorder->GetName():"NULL");
return true;
}
//---------------------------------------------------------------------------
void RootLayer::SetScreens(Screen *screen[], int32 rows, int32 columns){ void RootLayer::SetScreens(Screen *screen[], int32 rows, int32 columns){
// NOTE: *All* Screens *MUST* have the same resolution. // NOTE: *All* Screens *MUST* have the same resolution.
fScreenPtrList.MakeEmpty(); fScreenPtrList.MakeEmpty();
@@ -359,6 +438,7 @@ bool RootLayer::SetScreenResolution(int32 width, int32 height, uint32 colorspace
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void RootLayer::SetWorkspaceCount(const int32 count){ void RootLayer::SetWorkspaceCount(const int32 count){
printf("*RootLayer::SetWorkspaceCount(%ld)\n", count);
if ((count < 1 && count > 32) || count == WorkspaceCount()) if ((count < 1 && count > 32) || count == WorkspaceCount())
return; return;
@@ -367,6 +447,8 @@ void RootLayer::SetWorkspaceCount(const int32 count){
BList newWSPtrList; BList newWSPtrList;
void *workspacePtr; void *workspacePtr;
fMainLock.Lock();
printf("*RootLayer::SetWorkspaceCount(%ld) - main lock acquired\n", count);
for(int i=0; i < count; i++){ for(int i=0; i < count; i++){
workspacePtr = fWSPtrList.ItemAt(i); workspacePtr = fWSPtrList.ItemAt(i);
if (workspacePtr){ if (workspacePtr){
@@ -374,7 +456,7 @@ void RootLayer::SetWorkspaceCount(const int32 count){
} }
else{ else{
Workspace *ws; Workspace *ws;
ws = new Workspace(fColorSpace, i+1, BGColor()); ws = new Workspace(fColorSpace, i+1, BGColor(), this);
newWSPtrList.AddItem(ws); newWSPtrList.AddItem(ws);
} }
} }
@@ -393,12 +475,16 @@ void RootLayer::SetWorkspaceCount(const int32 count){
} }
fWSPtrList = newWSPtrList; fWSPtrList = newWSPtrList;
fMainLock.Unlock();
printf("*RootLayer::SetWorkspaceCount(%ld) - main lock released\n", count);
if (exActiveWorkspaceIndex > count) if (exActiveWorkspaceIndex > count)
SetActiveWorkspaceByIndex(count); SetActiveWorkspaceByIndex(count);
// if true, this is the first time this method is called. // if true, this is the first time this method is called.
if (exActiveWorkspaceIndex == -1) if (exActiveWorkspaceIndex == -1)
SetActiveWorkspaceByIndex(1); SetActiveWorkspaceByIndex(1);
printf("#RootLayer::SetWorkspaceCount(%ld)\n", count);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
int32 RootLayer::WorkspaceCount() const{ int32 RootLayer::WorkspaceCount() const{
@@ -453,7 +539,7 @@ RGBColor RootLayer::BGColor(void) const{
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void RootLayer::RemoveAppWindow(WinBorder *wb){ void RootLayer::RemoveAppWindow(WinBorder *wb){
wb->Window()->GetApp()->GetFMWList()->RemoveItem(wb); wb->Window()->App()->fAppFMWList.RemoveItem(wb);
int32 count = WorkspaceCount(); int32 count = WorkspaceCount();
for(int32 i=0; i < count; i++){ for(int32 i=0; i < count; i++){
+9 -5
View File
@@ -29,6 +29,7 @@
#define _ROOTLAYER_H_ #define _ROOTLAYER_H_
#include <List.h> #include <List.h>
#include <Locker.h>
#include "Layer.h" #include "Layer.h"
#include "FMWList.h" #include "FMWList.h"
@@ -50,7 +51,8 @@ class Desktop;
class RootLayer : public Layer class RootLayer : public Layer
{ {
public: public:
RootLayer(const char *layername, int32 workspaceCount, Desktop *desktop); RootLayer(const char *layername,
int32 workspaceCount, Desktop *desktop);
virtual ~RootLayer(); virtual ~RootLayer();
virtual void Draw(const BRect &r); virtual void Draw(const BRect &r);
@@ -65,6 +67,7 @@ public:
void AddWinBorder(WinBorder* winBorder); void AddWinBorder(WinBorder* winBorder);
void RemoveWinBorder(WinBorder* winBorder); void RemoveWinBorder(WinBorder* winBorder);
void ChangeWorkspacesFor(WinBorder* winBorder, uint32 newWorkspaces); void ChangeWorkspacesFor(WinBorder* winBorder, uint32 newWorkspaces);
bool SetFrontWinBorder(WinBorder* winBorder);
void SetScreens(Screen *screen[], int32 rows, int32 columns); void SetScreens(Screen *screen[], int32 rows, int32 columns);
Screen** Screens(); Screen** Screens();
@@ -83,15 +86,16 @@ public:
void SetBGColor(const RGBColor &col); void SetBGColor(const RGBColor &col);
RGBColor BGColor(void) const; RGBColor BGColor(void) const;
void AddWinBorderToWorkspaces(WinBorder* winBorder, uint32 wks); void AddWinBorderToWorkspaces(WinBorder* winBorder,
uint32 wks);
// ------- debugging methods ------- // ------- debugging methods -------
void PrintToStream(); void PrintToStream();
// "Private" to app_server :-) - they should not be used
// "Private" to app_server :-) - they should not be used
void RemoveAppWindow(WinBorder *wb); void RemoveAppWindow(WinBorder *wb);
FMWList fMainFMWList; FMWList fMainFMWList;
BLocker fMainLock;
private: private:
Desktop *fDesktop; Desktop *fDesktop;
+114 -86
View File
@@ -54,7 +54,7 @@
#include "LayerData.h" #include "LayerData.h"
#include "Utils.h" #include "Utils.h"
//#define DEBUG_SERVERAPP #define DEBUG_SERVERAPP
#ifdef DEBUG_SERVERAPP #ifdef DEBUG_SERVERAPP
# include <stdio.h> # include <stdio.h>
@@ -70,8 +70,14 @@
\param _signature NULL-terminated string which contains the BApplication's \param _signature NULL-terminated string which contains the BApplication's
MIME _signature. MIME _signature.
*/ */
ServerApp::ServerApp(port_id sendport, port_id rcvport, int32 handlerID, char *signature) ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort,
team_id clientTeamID, int32 handlerID, char *signature)
{ {
// it will be of *very* musch use in correct window order
fClientTeamID = clientTeamID;
// what to send a message to the client? Write a BMessage to this port.
fClientLooperPort = clientLooperPort;
// need to copy the _signature because the message buffer // need to copy the _signature because the message buffer
// owns the copy which we are passed as a parameter. // owns the copy which we are passed as a parameter.
_signature=(signature)?signature:"application/x-vnd.unregistered-application"; _signature=(signature)?signature:"application/x-vnd.unregistered-application";
@@ -85,9 +91,7 @@ ServerApp::ServerApp(port_id sendport, port_id rcvport, int32 handlerID, char *s
_applink->SetPort(_sender); _applink->SetPort(_sender);
// Gotta get the team ID so we can ping the application // Gotta get the team ID so we can ping the application
port_info pinfo; _target_id = clientTeamID;
get_port_info(_sender,&pinfo);
_target_id=pinfo.team;
// _receiver is the port we receive messages from our BApplication // _receiver is the port we receive messages from our BApplication
_receiver=rcvport; _receiver=rcvport;
@@ -102,11 +106,12 @@ ServerApp::ServerApp(port_id sendport, port_id rcvport, int32 handlerID, char *s
_appcursor=(defaultc)?new ServerCursor(defaultc):NULL; _appcursor=(defaultc)?new ServerCursor(defaultc):NULL;
_lock=create_sem(1,"ServerApp sem"); _lock=create_sem(1,"ServerApp sem");
// TODO: Fix //TODO: resolve
// _driver=GetGfxDriver(ActiveScreen()); // _driver=GetGfxDriver(ActiveScreen());
_cursorhidden=false; _cursorhidden=false;
Run();
STRACE(("ServerApp %s:\n",_signature.String())); STRACE(("ServerApp %s:\n",_signature.String()));
STRACE(("\tBApp port: %ld\n",_sender)); STRACE(("\tBApp port: %ld\n",_sender));
STRACE(("\tReceiver port: %ld\n",_receiver)); STRACE(("\tReceiver port: %ld\n",_receiver));
@@ -115,9 +120,35 @@ ServerApp::ServerApp(port_id sendport, port_id rcvport, int32 handlerID, char *s
//! Does all necessary teardown for application //! Does all necessary teardown for application
ServerApp::~ServerApp(void) ServerApp::~ServerApp(void)
{ {
STRACE(("ServerApp %s:~ServerApp()\n",_signature.String())); STRACE(("*ServerApp %s:~ServerApp()\n",_signature.String()));
int32 i; int32 i;
// wait for our ServerWindow threads
bool ready = true;
desktop->fLayerLock.Lock();
do{
ready = true;
int32 count = desktop->fWinBorderList.CountItems();
for( int32 i = 0; i < count; i++){
ServerWindow *sw = ((WinBorder*)desktop->fWinBorderList.ItemAt(i))->Window();
if (ClientTeamID() == sw->ClientTeamID()){
thread_id tid = sw->ThreadID();
status_t temp;
desktop->fLayerLock.Unlock();
printf("waiting for thread %s\n", sw->Title());
wait_for_thread(tid, &temp);
desktop->fLayerLock.Lock();
ready = false;
break;
}
}
}while(!ready);
desktop->fLayerLock.Unlock();
/*
ServerWindow *tempwin; ServerWindow *tempwin;
for(i=0;i<_winlist->CountItems();i++) for(i=0;i<_winlist->CountItems();i++)
{ {
@@ -127,7 +158,7 @@ ServerApp::~ServerApp(void)
} }
_winlist->MakeEmpty(); _winlist->MakeEmpty();
delete _winlist; delete _winlist;
*/
ServerBitmap *tempbmp; ServerBitmap *tempbmp;
for(i=0;i<_bmplist->CountItems();i++) for(i=0;i<_bmplist->CountItems();i++)
{ {
@@ -153,13 +184,17 @@ ServerApp::~ServerApp(void)
if(_appcursor) if(_appcursor)
delete _appcursor; delete _appcursor;
cursormanager->RemoveAppCursors(_signature.String());
delete_sem(_lock);
STRACE(("#ServerApp %s:~ServerApp()\n",_signature.String()));
// Kill the monitor thread if it exists // Kill the monitor thread if it exists
thread_info info; thread_info info;
if(get_thread_info(_monitor_thread,&info)==B_OK) if(get_thread_info(_monitor_thread,&info)==B_OK)
kill_thread(_monitor_thread); kill_thread(_monitor_thread);
cursormanager->RemoveAppCursors(_signature.String());
delete_sem(_lock);
} }
/*! /*!
@@ -220,6 +255,21 @@ void ServerApp::PostMessage(int32 code, size_t size, int8 *buffer)
write_port(_receiver,code, buffer, size); write_port(_receiver,code, buffer, size);
} }
void ServerApp::SendMessageToClient(const BMessage* msg) const{
ssize_t size;
char *buffer;
size = msg->FlattenedSize();
buffer = new char[size];
if (msg->Flatten(buffer, size) == B_OK){
write_port(fClientLooperPort, msg->what, buffer, size);
}
else
printf("PANIC: ServerApp: '%s': can't flatten message in 'SendMessageToClient()'\n", _signature.String());
delete buffer;
}
/*! /*!
\brief Sets the ServerApp's active status \brief Sets the ServerApp's active status
\param value The new status of the ServerApp. \param value The new status of the ServerApp.
@@ -247,22 +297,23 @@ void ServerApp::SetAppCursor(void)
\param data Pointer to the thread's ServerApp object \param data Pointer to the thread's ServerApp object
\return Throwaway value - always 0 \return Throwaway value - always 0
*/ */
int32 ServerApp::MonitorApp(void *data) int32 ServerApp::MonitorApp(void *data)
{ {
// Message-dispatching loop for the ServerApp // Message-dispatching loop for the ServerApp
ServerApp *app=(ServerApp *)data; ServerApp *app = (ServerApp *)data;
PortQueue msgqueue(app->_receiver); PortQueue msgqueue(app->_receiver);
PortMessage *msg; PortMessage *msg;
bool quiting = false;
for(;;) for( ; !quiting; )
{ {
if(!msgqueue.MessagesWaiting()) if(!msgqueue.MessagesWaiting())
msgqueue.GetMessagesFromPort(true); msgqueue.GetMessagesFromPort(true);
else else
msgqueue.GetMessagesFromPort(false); msgqueue.GetMessagesFromPort(false);
msg=msgqueue.GetMessageFromQueue(); msg = msgqueue.GetMessageFromQueue();
if(!msg) if(!msg)
continue; continue;
@@ -271,6 +322,7 @@ int32 ServerApp::MonitorApp(void *data)
case AS_QUIT_APP: case AS_QUIT_APP:
{ {
STRACE(("ServerApp %s:Server shutdown notification received\n",app->_signature.String())); STRACE(("ServerApp %s:Server shutdown notification received\n",app->_signature.String()));
/*
// If we are using the real, accelerated version of the // If we are using the real, accelerated version of the
// DisplayDriver, we do NOT want the user to be able shut down // DisplayDriver, we do NOT want the user to be able shut down
// the server. The results would NOT be pretty // the server. The results would NOT be pretty
@@ -281,18 +333,13 @@ int32 ServerApp::MonitorApp(void *data)
// ask all apps to quit. This is NOT the same as system // ask all apps to quit. This is NOT the same as system
// shutdown and will happen only in testing // shutdown and will happen only in testing
// For now, it seems that we can't seem to try to play nice and tell BMessage pleaseQuit(_QUIT_);
// an application to quit, so we'll just have to go postal. XD app->SendMessageToClient(&pleaseQuit);
// BMessage *shutdown=new BMessage(_QUIT_);
// SendMessage(app->_sender,shutdown);
// DIE! DIE! DIE! :P
port_info pi;
get_port_info(app->_sender,&pi);
kill_team(pi.team);
app->PostMessage(B_QUIT_REQUESTED);
} }
* Adi: I do not agree here! I think this is a reminiscence(?) since the "old" days...
*/
BMessage pleaseQuit(_QUIT_);
app->SendMessageToClient(&pleaseQuit);
break; break;
} }
@@ -300,15 +347,19 @@ int32 ServerApp::MonitorApp(void *data)
{ {
// Our BApplication sent us this message when it quit. // Our BApplication sent us this message when it quit.
// We need to ask the app_server to delete our monitor // We need to ask the app_server to delete our monitor
port_id serverport=find_port(SERVER_PORT_NAME); // ADI: No! This is a bad solution. A thead should continue its
if(serverport==B_NAME_NOT_FOUND) // execution until its exit point, and this can *very* easily be done
{ quiting = true;
// see... no need to ask the main thread to kill us.
// still... it will delete this ServerApp object.
port_id serverport = find_port(SERVER_PORT_NAME);
if(serverport == B_NAME_NOT_FOUND){
printf("PANIC: ServerApp %s could not find the app_server port!\n",app->_signature.String()); printf("PANIC: ServerApp %s could not find the app_server port!\n",app->_signature.String());
break; break;
} }
app->_applink->SetPort(serverport); app->_applink->SetPort(serverport);
app->_applink->SetOpCode(AS_DELETE_APP); app->_applink->SetOpCode(AS_DELETE_APP);
app->_applink->Attach(&app->_monitor_thread,sizeof(thread_id)); app->_applink->Attach(&app->_monitor_thread, sizeof(thread_id));
app->_applink->Flush(); app->_applink->Flush();
break; break;
} }
@@ -321,10 +372,8 @@ int32 ServerApp::MonitorApp(void *data)
} }
delete msg; delete msg;
} // end for } // end for
// clean exit.
exit_thread(0);
return 0; return 0;
} }
@@ -353,9 +402,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
} }
case AS_UPDATE_COLORS: case AS_UPDATE_COLORS:
{ {
// TODO: move message def to ServerProtocol.h to allow for ServerWindow *win;
// complete build compatibility under R5
/* ServerWindow *win;
BMessage msg(_COLORS_UPDATED); BMessage msg(_COLORS_UPDATED);
for(int32 i=0; i<_winlist->CountItems(); i++) for(int32 i=0; i<_winlist->CountItems(); i++)
@@ -366,14 +413,11 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
win->SendMessageToClient(&msg); win->SendMessageToClient(&msg);
win->Unlock(); win->Unlock();
} }
*/ break; break;
} }
case AS_UPDATE_FONTS: case AS_UPDATE_FONTS:
{ {
// TODO: move message def to ServerProtocol.h to allow for ServerWindow *win;
// complete build compatibility under R5
/* ServerWindow *win;
BMessage msg(_FONTS_UPDATED); BMessage msg(_FONTS_UPDATED);
for(int32 i=0; i<_winlist->CountItems(); i++) for(int32 i=0; i<_winlist->CountItems(); i++)
@@ -384,13 +428,11 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
win->SendMessageToClient(&msg); win->SendMessageToClient(&msg);
win->Unlock(); win->Unlock();
} }
*/ break; break;
} }
case AS_UPDATE_DECORATOR: case AS_UPDATE_DECORATOR:
{ {
// TODO: move message def to ServerProtocol.h to allow for ServerWindow *win;
// complete build compatibility under R5
/* ServerWindow *win;
for(int32 i=0; i<_winlist->CountItems(); i++) for(int32 i=0; i<_winlist->CountItems(); i++)
{ {
@@ -399,7 +441,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
win->_winborder->UpdateDecorator(); win->_winborder->UpdateDecorator();
win->Unlock(); win->Unlock();
} }
*/ break; break;
} }
case AS_CREATE_WINDOW: case AS_CREATE_WINDOW:
{ {
@@ -441,41 +483,18 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
_signature.String())); _signature.String()));
// ServerWindow constructor will reply with port_id of a newly created port // ServerWindow constructor will reply with port_id of a newly created port
ServerWindow *newwin = new ServerWindow(frame, title, new ServerWindow(frame, title, look, feel, flags, this,
look, feel, flags, this, sendPort, looperPort, replyport, wkspaces, token); sendPort, looperPort, replyport, wkspaces, token);
// ServerWindow constructor has added 'newwin' to the Desktop.
// We don't have to do anything here...
_winlist->AddItem(newwin); STRACE(("\nServerApp %s: New Window %s (%.1f,%.1f,%.1f,%.1f)\n",
STRACE(("ServerApp %s: New Window %s (%.1f,%.1f,%.1f,%.1f)\n",
_signature.String(),title,frame.left,frame.top,frame.right,frame.bottom)); _signature.String(),title,frame.left,frame.top,frame.right,frame.bottom));
delete title; delete title;
break; break;
} }
case AS_DELETE_WINDOW:
{
// Received from a ServerWindow when its window quits
// Attached data:
// 1) uint32 ServerWindow ID token
ServerWindow *w;
uint32 winid;
msg->Read<uint32>(&winid);
for(int32 i=0;i<_winlist->CountItems();i++)
{
w=(ServerWindow*)_winlist->ItemAt(i);
if(w->_token==winid)
{
STRACE(("ServerApp %s: Deleting window %s\n",_signature.String(),w->GetTitle()));
_winlist->RemoveItem(w);
delete w;
break;
}
}
break;
}
case AS_CREATE_BITMAP: case AS_CREATE_BITMAP:
{ {
// Allocate a bitmap for an application // Allocate a bitmap for an application
@@ -601,8 +620,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
msg->Read<int32>(&workspace); msg->Read<int32>(&workspace);
msg->Read<uint32>(&mode); msg->Read<uint32>(&mode);
msg->Read<bool>(&stick); msg->Read<bool>(&stick);
//TODO: Resolve
// TODO: Fix
// SetSpace(workspace,mode,ActiveScreen(),stick); // SetSpace(workspace,mode,ActiveScreen(),stick);
break; break;
@@ -615,8 +633,7 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
// Error-checking is done in ActivateWorkspace, so this is a safe call // Error-checking is done in ActivateWorkspace, so this is a safe call
int32 workspace; int32 workspace;
msg->Read<int32>(&workspace); msg->Read<int32>(&workspace);
//TODO: Resolve
// TODO: Fix
// SetWorkspace(workspace); // SetWorkspace(workspace);
break; break;
} }
@@ -735,13 +752,15 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
{ {
// Attached data: // Attached data:
// 1) port_id reply port - synchronous message // 1) port_id reply port - synchronous message
scroll_bar_info sbi=desktop->ScrollBarInfo(); //TODO: resolve
// scroll_bar_info sbi=GetScrollBarInfo();
port_id replyport; port_id replyport;
msg->Read<int32>(&replyport); msg->Read<int32>(&replyport);
PortLink link(replyport); PortLink link(replyport);
link.Attach<scroll_bar_info>(sbi); //TODO: resolve
// link.Attach<scroll_bar_info>(sbi);
link.Flush(); link.Flush();
break; break;
} }
@@ -751,7 +770,8 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
// 1) scroll_bar_info scroll bar info structure // 1) scroll_bar_info scroll bar info structure
scroll_bar_info sbi; scroll_bar_info sbi;
msg->Read<scroll_bar_info>(&sbi); msg->Read<scroll_bar_info>(&sbi);
desktop->SetScrollBarInfo(sbi); //TODO: resolve
// SetScrollBarInfo(sbi);
break; break;
} }
case AS_FOCUS_FOLLOWS_MOUSE: case AS_FOCUS_FOLLOWS_MOUSE:
@@ -763,7 +783,8 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
msg->Read<int32>(&replyport); msg->Read<int32>(&replyport);
PortLink link(replyport); PortLink link(replyport);
link.Attach<bool>(desktop->FFMouseInUse()); //TODO: resolve
// link.Attach<bool>(GetFFMouse());
link.Flush(); link.Flush();
break; break;
} }
@@ -773,7 +794,8 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
// 1) scroll_bar_info scroll bar info structure // 1) scroll_bar_info scroll bar info structure
scroll_bar_info sbi; scroll_bar_info sbi;
msg->Read<scroll_bar_info>(&sbi); msg->Read<scroll_bar_info>(&sbi);
desktop->SetScrollBarInfo(sbi); //TODO: resolve
// SetScrollBarInfo(sbi);
break; break;
} }
case AS_SET_MOUSE_MODE: case AS_SET_MOUSE_MODE:
@@ -782,20 +804,23 @@ void ServerApp::_DispatchMessage(PortMessage *msg)
// 1) enum mode_mouse FFM mouse mode // 1) enum mode_mouse FFM mouse mode
mode_mouse mmode; mode_mouse mmode;
msg->Read<mode_mouse>(&mmode); msg->Read<mode_mouse>(&mmode);
desktop->SetFFMouseMode(mmode); //TODO: resolve
// SetFFMouseMode(mmode);
break; break;
} }
case AS_GET_MOUSE_MODE: case AS_GET_MOUSE_MODE:
{ {
// Attached data: // Attached data:
// 1) port_id reply port - synchronous message // 1) port_id reply port - synchronous message
mode_mouse mmode=desktop->FFMouseMode(); //TODO: resolve
// mode_mouse mmode=GetFFMouseMode();
port_id replyport; port_id replyport;
msg->Read<int32>(&replyport); msg->Read<int32>(&replyport);
PortLink link(replyport); PortLink link(replyport);
link.Attach<mode_mouse>(mmode); //TODO: resolve
// link.Attach<mode_mouse>(mmode);
link.Flush(); link.Flush();
break; break;
} }
@@ -831,3 +856,6 @@ ServerBitmap *ServerApp::_FindBitmap(int32 token)
return NULL; return NULL;
} }
team_id ServerApp::ClientTeamID(){
return fClientTeamID;
}
+24 -29
View File
@@ -29,7 +29,6 @@
#include <OS.h> #include <OS.h>
#include <String.h> #include <String.h>
#include <ServerBitmap.h>
#include "FMWList.h" #include "FMWList.h"
class AppServer; class AppServer;
@@ -40,22 +39,6 @@ class BList;
class DisplayDriver; class DisplayDriver;
class ServerCursor; class ServerCursor;
/*
class ServerApp{
public:
ServerApp(team_id clientTeamID){
fClientTeamID = clientTeamID;
}
virtual ~ServerApp(){ }
team_id ClientTeamID(){ return fClientTeamID; }
FMWList fAppFMWList;
private:
team_id fClientTeamID;
};
*/
/*! /*!
\class ServerApp ServerApp.h \class ServerApp ServerApp.h
\brief Counterpart to BApplication within the app_server \brief Counterpart to BApplication within the app_server
@@ -63,8 +46,9 @@ private:
class ServerApp class ServerApp
{ {
public: public:
ServerApp(port_id sendport, port_id rcvport, int32 handlerID, char *signature); ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort,
~ServerApp(void); team_id clientTeamID, int32 handlerID, char *signature);
virtual ~ServerApp(void);
bool Run(void); bool Run(void);
static int32 MonitorApp(void *data); static int32 MonitorApp(void *data);
@@ -81,30 +65,41 @@ public:
void Activate(bool value); void Activate(bool value);
bool PingTarget(void); bool PingTarget(void);
void PostMessage(int32 code, size_t size=0, int8 *buffer=NULL); void PostMessage(int32 code, size_t size=0,
int8 *buffer=NULL);
void SendMessageToClient( const BMessage* msg ) const;
void SetAppCursor(void); void SetAppCursor(void);
FMWList *GetFMWList(void) { return &fAppFMWList; }
team_id ClientTeamID();
FMWList fAppFMWList;
protected: protected:
friend class AppServer; friend class AppServer;
friend class ServerWindow; friend class ServerWindow;
void _DispatchMessage(PortMessage *msg);
ServerBitmap *_FindBitmap(int32 token);
port_id _sender,_receiver; void _DispatchMessage(PortMessage *msg);
ServerBitmap* _FindBitmap(int32 token);
port_id _sender,
_receiver,
fClientLooperPort;
BString _signature; BString _signature;
thread_id _monitor_thread; thread_id _monitor_thread;
team_id fClientTeamID;
team_id _target_id; team_id _target_id;
PortLink *_applink; PortLink* _applink;
BList *_winlist, *_bmplist, *_piclist; BList *_winlist,
DisplayDriver *_driver; *_bmplist,
ServerCursor *_appcursor; *_piclist;
ServerCursor* _appcursor;
sem_id _lock; sem_id _lock;
bool _cursorhidden; bool _cursorhidden;
bool _isactive; bool _isactive;
int32 _handlertoken; int32 _handlertoken;
FMWList fAppFMWList;
}; };
#endif #endif
File diff suppressed because it is too large Load Diff
+39 -33
View File
@@ -65,31 +65,17 @@ class Layer;
class ServerWindow class ServerWindow
{ {
public: public:
ServerWindow(BRect rect, const char *string, uint32 wlook, uint32 wfeel, ServerWindow(BRect rect, const char *string,
uint32 wflags, ServerApp *winapp, port_id winport, uint32 wlook, uint32 wfeel, uint32 wflags,
port_id looperPort, port_id replyport, uint32 index,int32 handlerID); ServerApp *winapp, port_id winport,
port_id looperPort, port_id replyport, uint32 index,
int32 handlerID);
~ServerWindow(void); ~ServerWindow(void);
void ReplaceDecorator(void); void ReplaceDecorator(void);
void Quit(void); void Quit(void);
const char* GetTitle(void);
const char *GetTitle(void); ServerApp* GetApp(void);
ServerApp *GetApp(void);
int32 GetLook(void) const { return _look; }
int32 GetFeel(void) const { return _feel; }
int32 GetFlags(void) const { return _flags; }
int32 GetHandlerID(void) const { return _handlertoken; }
//! Returns the index of the workspaces to which it belongs
uint32 GetWorkspaces(void) const { return _workspaces; }
team_id GetClientTeamID(void) const { return fClientTeamID; }
FMWList *GetFMWList(void) { return &fWinFMWList; }
void SetLook(int32 look);
void SetFeel(int32 feel);
void SetFlags(int32 flags);
void SetWorkspaces(int32 workspaces);
void Show(void); void Show(void);
void Hide(void); void Hide(void);
bool IsHidden(void); bool IsHidden(void);
@@ -111,23 +97,40 @@ public:
status_t Lock(void); status_t Lock(void);
void Unlock(void); void Unlock(void);
bool IsLocked(void); bool IsLocked(void);
thread_id ThreadID() const { return _monitorthread;}
void DispatchMessage(PortMessage msg); void DispatchMessage(int32 code);
void DispatchGraphicsMessage(int32 msgsize, int8 *msgbuffer); void DispatchGraphicsMessage(int32 msgsize, int8 *msgbuffer);
static int32 MonitorWin(void *data); static int32 MonitorWin(void *data);
static void HandleMouseEvent(PortMessage *msg); static void HandleMouseEvent(PortMessage *msg);
static void HandleKeyEvent(int32 code, int8 *buffer); static void HandleKeyEvent(int32 code, int8 *buffer);
// Workspace* GetWorkspace(void); //! Returns the index of the workspaces to which it belongs
int32 GetWorkspaceIndex(void) { return fWorkspaces; }
Workspace* GetWorkspace(void);
void SetWorkspace(Workspace *wkspc); void SetWorkspace(Workspace *wkspc);
//! Returns the window's title //! Returns the window's title
const char *Title(void) { return _title->String(); } const char* Title(void) { return _title->String(); }
Layer* FindLayer(const Layer* start, int32 token) const; Layer* FindLayer(const Layer* start, int32 token) const;
void SendMessageToClient( const BMessage* msg ) const; void SendMessageToClient( const BMessage* msg ) const;
int32 Look() const { return _look; }
int32 Feel() const { return _feel; }
uint32 Flags() const { return _flags; }
team_id ClientTeamID() const { return fClientTeamID; }
ServerApp* App() const { return _app; }
uint32 Workspaces() const { return fWorkspaces; }
WinBorder* GetWinBorder() const { return _winborder; }
// server "private" - try not to use
void QuietlySetWorkspaces(uint32 wks)
{ fWorkspaces = wks; }
void QuietlySetFeel(int32 feel)
{ _feel = feel; }
FMWList fWinFMWList;
protected: protected:
friend class ServerApp; friend class ServerApp;
friend class WinBorder; friend class WinBorder;
@@ -138,34 +141,37 @@ protected:
int32 _look, int32 _look,
_feel, _feel,
_flags; _flags;
uint32 _workspaces; uint32 fWorkspaces;
Workspace *_workspace; Workspace *_workspace;
bool _active; bool _active;
ServerApp *_app; ServerApp *_app;
WinBorder *_winborder; WinBorder *_winborder;
team_id fClientTeamID;
thread_id _monitorthread; thread_id _monitorthread;
port_id _receiver; // Messages from window port_id _receiver; // Messages from window
port_id _sender; // Messages to window port_id _sender; // Messages to window
PortLink *_winlink;
PortLink *_winlink,
*_applink;
BLocker _locker; BLocker _locker;
BRect _frame; BRect _frame;
uint32 _token; uint32 _token;
int32 _handlertoken; int32 _handlertoken;
BSession *ses;
port_id winLooperPort; port_id winLooperPort;
Layer *top_layer; Layer *top_layer;
Layer *currentlayer; Layer *cl; // short for currentLayer. We'll use it a lot, that's why it's short :-)
FMWList fWinFMWList;
team_id fClientTeamID;
}; };
void ActivateWindow(ServerWindow *oldwin,ServerWindow *newwin); void ActivateWindow(ServerWindow *oldwin,ServerWindow *newwin);
#endif #endif
/*
@log
* added Layer as a friend.
* added a new member: port_id winLooperPort; We'll use it to send flattened BMessages(like _UPDATE_ / B_VIEW_RESIZED(MOVED)) to our BWindow counterpart.
* SendMessageToClient( BMessage ) sends that message BWindow's looper port.
*/
+1 -42
View File
@@ -27,10 +27,8 @@
#include <Region.h> #include <Region.h>
#include <String.h> #include <String.h>
#include <Locker.h> #include <Locker.h>
#include <Region.h>
#include <Debug.h> #include <Debug.h>
#include <TokenSpace.h> #include <TokenSpace.h>
#include "Globals.h"
#include "View.h" // for mouse button defines #include "View.h" // for mouse button defines
#include "ServerWindow.h" #include "ServerWindow.h"
#include "Decorator.h" #include "Decorator.h"
@@ -342,48 +340,9 @@ void WinBorder::SetFocus(const bool &active)
_decorator->SetFocus(active); _decorator->SetFocus(active);
} }
void WinBorder::SetServerFeel(int32 feel)
{
switch(_win->GetFeel())
{
case B_NORMAL_WINDOW_FEEL:
_serverfeel = B_NORMAL_FEEL;
break;
case B_FLOATING_SUBSET_WINDOW_FEEL:
_serverfeel = B_FLOATING_SUBSET_FEEL;
break;
case B_FLOATING_APP_WINDOW_FEEL:
_serverfeel = B_FLOATING_APP_FEEL;
break;
case B_FLOATING_ALL_WINDOW_FEEL:
_serverfeel = B_FLOATING_ALL_FEEL;
break;
case B_MODAL_SUBSET_WINDOW_FEEL:
_serverfeel = B_MODAL_SUBSET_FEEL;
break;
case B_MODAL_APP_WINDOW_FEEL:
_serverfeel = B_MODAL_APP_FEEL;
break;
case B_MODAL_ALL_WINDOW_FEEL:
_serverfeel = B_MODAL_ALL_FEEL;
break;
case B_SYSTEM_LAST:
case B_SYSTEM_FIRST:
// if(_win->ServerTeamID() != _win->ClientTeamID())
// _win->QuietlySetFeel(B_NORMAL_WINDOW_FEEL);
// else
// _serverfeel = _win->GetFeel();
break;
default:
_win->SetFeel(B_NORMAL_WINDOW_FEEL);
_serverfeel = B_NORMAL_FEEL;
break;
}
}
void WinBorder::RebuildRegions( const BRect& r ){ void WinBorder::RebuildRegions( const BRect& r ){
/* WinBorder is a little bit special. It doesn't have a visible region /* WinBorder is a little bit special. It doesn't have a visible region
in witch to do its drawings. Instead the hole visible region is split in which to do its drawings. Instead the whole visible region is split
between decorator and top_layer. between decorator and top_layer.
*/ */
+1 -2
View File
@@ -80,7 +80,6 @@ public:
void SetMainWinBorder(WinBorder *newMain); void SetMainWinBorder(WinBorder *newMain);
protected: protected:
ServerWindow *_win; ServerWindow *_win;
//BString *_title; //BString *_title;
Decorator *_decorator; Decorator *_decorator;
@@ -110,7 +109,7 @@ void set_is_moving_window(bool state);
bool is_resizing_window(void); bool is_resizing_window(void);
void set_is_resizing_window(bool state); void set_is_resizing_window(bool state);
void set_active_winborder(WinBorder *win); void set_active_winborder(WinBorder *win);
WinBorder *get_active_winborder(void); WinBorder* get_active_winborder(void);
void set_is_resizing_window(bool state); void set_is_resizing_window(bool state);
void set_is_sliding_tab(bool state); void set_is_sliding_tab(bool state);
bool is_sliding_tab(void); bool is_sliding_tab(void);