2005-07-05 22:14:24 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2005, Haiku.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Adrian Oanca <adioanca@cotty.iren.ro>
|
|
|
|
* Stephan Aßmus <superstippi@gmx.de>
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Class used to encapsulate desktop management */
|
|
|
|
|
|
|
|
|
2004-01-13 03:56:36 +03:00
|
|
|
#include <stdio.h>
|
2005-06-24 03:46:17 +04:00
|
|
|
|
2004-01-12 01:12:55 +03:00
|
|
|
#include <Message.h>
|
2005-06-24 03:46:17 +04:00
|
|
|
#include <Region.h>
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2005-07-05 22:14:24 +04:00
|
|
|
#include <WindowInfo.h>
|
|
|
|
#include <ServerProtocol.h>
|
|
|
|
|
2004-01-22 03:32:07 +03:00
|
|
|
#include "AppServer.h"
|
2005-11-04 18:54:16 +03:00
|
|
|
#include "DrawingEngine.h"
|
2004-01-12 01:12:55 +03:00
|
|
|
#include "Layer.h"
|
2004-01-22 03:32:07 +03:00
|
|
|
#include "RootLayer.h"
|
|
|
|
#include "ServerConfig.h"
|
|
|
|
#include "ServerScreen.h"
|
2005-02-28 23:23:51 +03:00
|
|
|
#include "ServerApp.h"
|
2004-01-22 03:32:07 +03:00
|
|
|
#include "ServerWindow.h"
|
2004-01-12 01:12:55 +03:00
|
|
|
#include "WinBorder.h"
|
|
|
|
#include "Workspace.h"
|
2005-07-17 20:25:48 +04:00
|
|
|
#include "DesktopSettingsPrivate.h"
|
|
|
|
|
2003-02-12 14:24:26 +03:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
#ifdef __HAIKU__
|
2005-07-05 22:38:12 +04:00
|
|
|
# define USE_ACCELERANT 1
|
2005-06-24 03:46:17 +04:00
|
|
|
#else
|
2005-07-05 22:38:12 +04:00
|
|
|
# define USE_ACCELERANT 0
|
2005-06-24 03:46:17 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_ACCELERANT
|
2005-07-05 22:38:12 +04:00
|
|
|
# include "AccelerantHWInterface.h"
|
2005-06-24 03:46:17 +04:00
|
|
|
#else
|
2005-07-05 22:38:12 +04:00
|
|
|
# include "ViewHWInterface.h"
|
2005-06-24 03:46:17 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Desktop.h"
|
|
|
|
|
2004-01-22 03:32:07 +03:00
|
|
|
//#define DEBUG_DESKTOP
|
2003-02-12 14:24:26 +03:00
|
|
|
|
2004-01-22 03:32:07 +03:00
|
|
|
#ifdef DEBUG_DESKTOP
|
2005-07-05 22:38:12 +04:00
|
|
|
# define STRACE(a) printf(a)
|
2004-01-22 03:32:07 +03:00
|
|
|
#else
|
2005-07-05 22:38:12 +04:00
|
|
|
# define STRACE(a) /* nothing */
|
2004-01-22 03:32:07 +03:00
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
2005-10-31 22:35:46 +03:00
|
|
|
Desktop::Desktop(uid_t userID)
|
2005-07-24 21:14:17 +04:00
|
|
|
: MessageLooper("desktop"),
|
2005-10-31 22:35:46 +03:00
|
|
|
fUserID(userID),
|
2005-07-17 20:25:48 +04:00
|
|
|
fSettings(new DesktopSettings::Private()),
|
2005-07-26 01:08:34 +04:00
|
|
|
fAppListLock("application list"),
|
|
|
|
fShutdownSemaphore(-1),
|
2005-07-17 20:25:48 +04:00
|
|
|
fWinBorderList(64),
|
2005-08-21 14:28:40 +04:00
|
|
|
fActiveScreen(NULL),
|
|
|
|
fCursorManager()
|
2004-01-22 03:32:07 +03:00
|
|
|
{
|
2005-07-24 21:14:17 +04:00
|
|
|
// TODO: use user name
|
|
|
|
char name[B_OS_NAME_LENGTH];
|
|
|
|
snprintf(name, sizeof(name), "d:%s", "baron");
|
|
|
|
|
|
|
|
fMessagePort = create_port(DEFAULT_MONITOR_PORT_SIZE, name);
|
|
|
|
if (fMessagePort < B_OK)
|
|
|
|
return;
|
2005-07-26 01:08:34 +04:00
|
|
|
|
|
|
|
fLink.SetReceiverPort(fMessagePort);
|
2005-11-03 20:03:36 +03:00
|
|
|
gFontManager->AttachUser(fUserID);
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
2004-01-22 03:32:07 +03:00
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
Desktop::~Desktop()
|
2004-01-22 03:32:07 +03:00
|
|
|
{
|
2005-04-25 18:14:09 +04:00
|
|
|
for (int32 i = 0; WinBorder *border = (WinBorder *)fWinBorderList.ItemAt(i); i++)
|
|
|
|
delete border;
|
2005-01-17 00:35:02 +03:00
|
|
|
|
2005-07-15 16:45:23 +04:00
|
|
|
delete fRootLayer;
|
2005-07-17 20:25:48 +04:00
|
|
|
delete fSettings;
|
2005-07-24 21:14:17 +04:00
|
|
|
|
|
|
|
delete_port(fMessagePort);
|
2005-11-03 20:03:36 +03:00
|
|
|
gFontManager->DetachUser(fUserID);
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2005-03-29 19:39:08 +04:00
|
|
|
|
|
|
|
void
|
2005-06-24 03:46:17 +04:00
|
|
|
Desktop::Init()
|
2004-01-22 03:32:07 +03:00
|
|
|
{
|
2005-07-17 20:25:48 +04:00
|
|
|
fVirtualScreen.RestoreConfiguration(*this, fSettings->WorkspacesMessage(0));
|
2005-04-25 18:14:09 +04:00
|
|
|
|
2005-07-15 16:45:23 +04:00
|
|
|
// TODO: temporary workaround, fActiveScreen will be removed
|
|
|
|
fActiveScreen = fVirtualScreen.ScreenAt(0);
|
2005-04-25 18:14:09 +04:00
|
|
|
|
2005-07-15 16:45:23 +04:00
|
|
|
// TODO: add user identity to the name
|
|
|
|
char name[32];
|
|
|
|
sprintf(name, "RootLayer %d", 1);
|
2005-04-25 18:14:09 +04:00
|
|
|
|
2005-11-04 18:23:54 +03:00
|
|
|
fRootLayer = new RootLayer(name, 4, this, GetDrawingEngine());
|
2005-07-15 16:45:23 +04:00
|
|
|
fRootLayer->RunThread();
|
2005-07-18 04:22:08 +04:00
|
|
|
|
|
|
|
// take care of setting the default cursor
|
2005-08-21 14:28:40 +04:00
|
|
|
ServerCursor *cursor = fCursorManager.GetCursor(B_CURSOR_DEFAULT);
|
2005-07-18 04:22:08 +04:00
|
|
|
if (cursor)
|
|
|
|
fVirtualScreen.HWInterface()->SetCursor(cursor);
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
2004-01-22 03:32:07 +03:00
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
2005-07-24 21:14:17 +04:00
|
|
|
void
|
|
|
|
Desktop::_GetLooperName(char* name, size_t length)
|
|
|
|
{
|
|
|
|
snprintf(name, length, "d:%d:%s", /*id*/0, /*name*/"baron");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
void
|
|
|
|
Desktop::_PrepareQuit()
|
|
|
|
{
|
|
|
|
// let's kill all remaining applications
|
|
|
|
|
|
|
|
fAppListLock.Lock();
|
|
|
|
|
|
|
|
int32 count = fAppList.CountItems();
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
ServerApp *app = (ServerApp*)fAppList.ItemAt(i);
|
|
|
|
team_id clientTeam = app->ClientTeam();
|
|
|
|
|
|
|
|
app->Quit();
|
|
|
|
kill_team(clientTeam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for the last app to die
|
|
|
|
if (count > 0)
|
|
|
|
acquire_sem_etc(fShutdownSemaphore, fShutdownCount, B_RELATIVE_TIMEOUT, 250000);
|
|
|
|
|
|
|
|
fAppListLock.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Desktop::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case AS_CREATE_APP:
|
|
|
|
{
|
|
|
|
// Create the ServerApp to node monitor a new BApplication
|
|
|
|
|
|
|
|
// Attached data:
|
|
|
|
// 1) port_id - receiver port of a regular app
|
|
|
|
// 2) port_id - client looper port - for sending messages to the client
|
|
|
|
// 2) team_id - app's team ID
|
|
|
|
// 3) int32 - handler token of the regular app
|
|
|
|
// 4) char * - signature of the regular app
|
|
|
|
|
|
|
|
// Find the necessary data
|
|
|
|
team_id clientTeamID = -1;
|
|
|
|
port_id clientLooperPort = -1;
|
|
|
|
port_id clientReplyPort = -1;
|
|
|
|
int32 htoken = B_NULL_TOKEN;
|
|
|
|
char *appSignature = NULL;
|
|
|
|
|
|
|
|
link.Read<port_id>(&clientReplyPort);
|
|
|
|
link.Read<port_id>(&clientLooperPort);
|
|
|
|
link.Read<team_id>(&clientTeamID);
|
|
|
|
link.Read<int32>(&htoken);
|
|
|
|
if (link.ReadString(&appSignature) != B_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ServerApp *app = new ServerApp(this, clientReplyPort,
|
|
|
|
clientLooperPort, clientTeamID, htoken, appSignature);
|
|
|
|
if (app->InitCheck() == B_OK
|
|
|
|
&& app->Run()) {
|
|
|
|
// add the new ServerApp to the known list of ServerApps
|
|
|
|
fAppListLock.Lock();
|
|
|
|
fAppList.AddItem(app);
|
|
|
|
fAppListLock.Unlock();
|
|
|
|
} else {
|
|
|
|
delete app;
|
|
|
|
|
|
|
|
// if everything went well, ServerApp::Run() will notify
|
|
|
|
// the client - but since it didn't, we do it here
|
|
|
|
BPrivate::LinkSender reply(clientReplyPort);
|
|
|
|
reply.StartMessage(SERVER_FALSE);
|
|
|
|
reply.Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is necessary because BPortLink::ReadString allocates memory
|
|
|
|
free(appSignature);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AS_DELETE_APP:
|
|
|
|
{
|
|
|
|
// Delete a ServerApp. Received only from the respective ServerApp when a
|
|
|
|
// BApplication asks it to quit.
|
|
|
|
|
|
|
|
// Attached Data:
|
|
|
|
// 1) thread_id - thread ID of the ServerApp to be deleted
|
|
|
|
|
|
|
|
thread_id thread = -1;
|
|
|
|
if (link.Read<thread_id>(&thread) < B_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
fAppListLock.Lock();
|
|
|
|
|
|
|
|
// Run through the list of apps and nuke the proper one
|
|
|
|
|
|
|
|
int32 count = fAppList.CountItems();
|
|
|
|
ServerApp *removeApp = NULL;
|
|
|
|
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
ServerApp *app = (ServerApp *)fAppList.ItemAt(i);
|
|
|
|
|
|
|
|
if (app != NULL && app->Thread() == thread) {
|
|
|
|
fAppList.RemoveItem(i);
|
|
|
|
removeApp = app;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fAppListLock.Unlock();
|
|
|
|
|
|
|
|
if (removeApp != NULL)
|
|
|
|
removeApp->Quit(fShutdownSemaphore);
|
|
|
|
|
|
|
|
if (fQuitting && count <= 1) {
|
|
|
|
// wait for the last app to die
|
|
|
|
acquire_sem_etc(fShutdownSemaphore, fShutdownCount, B_RELATIVE_TIMEOUT, 500000);
|
|
|
|
PostMessage(kMsgQuitLooper);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-10-31 22:35:46 +03:00
|
|
|
case AS_ACTIVATE_APP:
|
|
|
|
{
|
|
|
|
// Someone is requesting to activation of a certain app.
|
|
|
|
|
|
|
|
// Attached data:
|
|
|
|
// 1) port_id reply port
|
|
|
|
// 2) team_id team
|
|
|
|
|
|
|
|
status_t status;
|
|
|
|
|
|
|
|
// get the parameters
|
|
|
|
port_id replyPort;
|
|
|
|
team_id team;
|
|
|
|
if (link.Read(&replyPort) == B_OK
|
|
|
|
&& link.Read(&team) == B_OK)
|
|
|
|
status = _ActivateApp(team);
|
|
|
|
else
|
|
|
|
status = B_ERROR;
|
|
|
|
|
|
|
|
// send the reply
|
|
|
|
BPrivate::PortLink replyLink(replyPort);
|
|
|
|
replyLink.StartMessage(status);
|
|
|
|
replyLink.Flush();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AS_SET_SYSCURSOR_DEFAULTS:
|
|
|
|
{
|
|
|
|
GetCursorManager().SetDefaults();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
case B_QUIT_REQUESTED:
|
|
|
|
// We've been asked to quit, so (for now) broadcast to all
|
|
|
|
// test apps to quit. This situation will occur only when the server
|
|
|
|
// is compiled as a regular Be application.
|
|
|
|
|
|
|
|
fAppListLock.Lock();
|
|
|
|
fShutdownSemaphore = create_sem(0, "desktop shutdown");
|
|
|
|
fShutdownCount = fAppList.CountItems();
|
|
|
|
fAppListLock.Unlock();
|
|
|
|
|
|
|
|
fQuitting = true;
|
|
|
|
BroadcastToAllApps(AS_QUIT_APP);
|
|
|
|
|
|
|
|
// We now need to process the remaining AS_DELETE_APP messages and
|
|
|
|
// wait for the kMsgShutdownServer message.
|
|
|
|
// If an application does not quit as asked, the picasso thread
|
|
|
|
// will send us this message in 2-3 seconds.
|
|
|
|
|
|
|
|
// if there are no apps to quit, shutdown directly
|
|
|
|
if (fShutdownCount == 0)
|
|
|
|
PostMessage(kMsgQuitLooper);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Desktop %d:%s received unexpected code %ld\n", 0, "baron", code);
|
|
|
|
|
|
|
|
if (link.NeedsReply()) {
|
|
|
|
// the client is now blocking and waiting for a reply!
|
|
|
|
fLink.StartMessage(B_ERROR);
|
|
|
|
fLink.Flush();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-31 22:35:46 +03:00
|
|
|
/*!
|
|
|
|
\brief activate one of the app's windows.
|
|
|
|
*/
|
|
|
|
status_t
|
|
|
|
Desktop::_ActivateApp(team_id team)
|
|
|
|
{
|
|
|
|
status_t status = B_BAD_TEAM_ID;
|
|
|
|
|
|
|
|
// search for an unhidden window to give focus to
|
|
|
|
int32 windowCount = WindowList().CountItems();
|
|
|
|
for (int32 i = 0; i < windowCount; ++i) {
|
|
|
|
// is this layer in fact a WinBorder?
|
|
|
|
WinBorder *winBorder = WindowList().ItemAt(i);
|
|
|
|
|
|
|
|
// if winBorder is valid and not hidden, then we've found our target
|
|
|
|
if (winBorder != NULL && !winBorder->IsHidden()
|
|
|
|
&& winBorder->App()->ClientTeam() == team) {
|
|
|
|
if (fRootLayer->Lock()) {
|
|
|
|
fRootLayer->SetActive(winBorder);
|
|
|
|
fRootLayer->Unlock();
|
|
|
|
|
|
|
|
if (fRootLayer->Active() == winBorder)
|
|
|
|
return B_OK;
|
|
|
|
|
|
|
|
status = B_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
/*!
|
|
|
|
\brief Send a quick (no attachments) message to all applications
|
|
|
|
|
|
|
|
Quite useful for notification for things like server shutdown, system
|
|
|
|
color changes, etc.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Desktop::BroadcastToAllApps(int32 code)
|
|
|
|
{
|
|
|
|
BAutolock locker(fAppListLock);
|
|
|
|
|
|
|
|
for (int32 i = 0; i < fAppList.CountItems(); i++) {
|
|
|
|
ServerApp *app = (ServerApp *)fAppList.ItemAt(i);
|
|
|
|
|
|
|
|
if (!app) {
|
|
|
|
printf("PANIC in Broadcast()\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
app->PostMessage(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-31 22:35:46 +03:00
|
|
|
// #pragma mark - Methods for WinBorder manipulation
|
2004-01-22 03:32:07 +03:00
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Desktop::AddWinBorder(WinBorder *winBorder)
|
2005-02-28 23:23:51 +03:00
|
|
|
{
|
|
|
|
if (!winBorder)
|
|
|
|
return;
|
|
|
|
|
2005-03-19 22:08:19 +03:00
|
|
|
// R2: how to determine the RootLayer to which this window should be added???
|
|
|
|
// for now, use ActiveRootLayer() because we only have one instance.
|
|
|
|
|
2005-04-16 17:30:49 +04:00
|
|
|
int32 feel = winBorder->Feel();
|
2005-02-28 23:23:51 +03:00
|
|
|
|
2005-03-19 22:08:19 +03:00
|
|
|
// we are ServerApp thread, we need to lock RootLayer here.
|
|
|
|
ActiveRootLayer()->Lock();
|
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
// we're playing with window list. lock first.
|
|
|
|
Lock();
|
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
if (fWinBorderList.HasItem(winBorder)) {
|
2005-02-28 23:23:51 +03:00
|
|
|
Unlock();
|
2005-03-31 00:06:50 +04:00
|
|
|
ActiveRootLayer()->Unlock();
|
2005-02-28 23:23:51 +03:00
|
|
|
debugger("AddWinBorder: WinBorder already in Desktop list\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we have a new window. store a record of it.
|
|
|
|
fWinBorderList.AddItem(winBorder);
|
|
|
|
|
|
|
|
// add FLOATING_APP windows to the local list of all normal windows.
|
|
|
|
// This is to keep the order all floating windows (app or subset) when we go from
|
|
|
|
// one normal window to another.
|
2005-04-25 18:14:09 +04:00
|
|
|
if (feel == B_FLOATING_APP_WINDOW_FEEL || feel == B_NORMAL_WINDOW_FEEL) {
|
|
|
|
WinBorder *wb = NULL;
|
|
|
|
int32 count = fWinBorderList.CountItems();
|
|
|
|
int32 feelToLookFor = (feel == B_NORMAL_WINDOW_FEEL ?
|
|
|
|
B_FLOATING_APP_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL);
|
|
|
|
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
wb = (WinBorder *)fWinBorderList.ItemAt(i);
|
|
|
|
|
2005-06-23 21:40:35 +04:00
|
|
|
if (wb->App()->ClientTeam() == winBorder->App()->ClientTeam()
|
2005-04-25 18:14:09 +04:00
|
|
|
&& wb->Feel() == feelToLookFor) {
|
2005-02-28 23:23:51 +03:00
|
|
|
// R2: RootLayer comparison is needed.
|
2005-03-13 22:53:44 +03:00
|
|
|
feel == B_NORMAL_WINDOW_FEEL ?
|
2005-06-17 20:34:22 +04:00
|
|
|
winBorder->fSubWindowList.AddWinBorder(wb) :
|
|
|
|
wb->fSubWindowList.AddWinBorder(winBorder);
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add application's list of modal windows.
|
2005-04-25 18:14:09 +04:00
|
|
|
if (feel == B_MODAL_APP_WINDOW_FEEL) {
|
2005-06-17 20:34:22 +04:00
|
|
|
winBorder->App()->fAppSubWindowList.AddWinBorder(winBorder);
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
|
|
|
|
2005-03-19 22:08:19 +03:00
|
|
|
// send WinBorder to be added to workspaces
|
|
|
|
ActiveRootLayer()->AddWinBorder(winBorder);
|
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
// hey, unlock!
|
|
|
|
Unlock();
|
|
|
|
|
2005-03-19 22:08:19 +03:00
|
|
|
ActiveRootLayer()->Unlock();
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Desktop::RemoveWinBorder(WinBorder *winBorder)
|
2004-01-22 03:32:07 +03:00
|
|
|
{
|
2005-02-28 23:23:51 +03:00
|
|
|
if (!winBorder)
|
|
|
|
return;
|
|
|
|
|
2005-03-19 22:08:19 +03:00
|
|
|
// we are ServerApp thread, we need to lock RootLayer here.
|
|
|
|
ActiveRootLayer()->Lock();
|
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
// we're playing with window list. lock first.
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
// remove from main WinBorder list.
|
2005-04-25 18:14:09 +04:00
|
|
|
if (fWinBorderList.RemoveItem(winBorder)) {
|
|
|
|
int32 feel = winBorder->Feel();
|
2005-02-28 23:23:51 +03:00
|
|
|
|
|
|
|
// floating app/subset and modal_subset windows require special atention because
|
|
|
|
// they are/may_be added to the list of a lot normal windows.
|
|
|
|
if (feel == B_FLOATING_SUBSET_WINDOW_FEEL
|
|
|
|
|| feel == B_MODAL_SUBSET_WINDOW_FEEL
|
|
|
|
|| feel == B_FLOATING_APP_WINDOW_FEEL)
|
|
|
|
{
|
2005-04-25 18:14:09 +04:00
|
|
|
WinBorder *wb = NULL;
|
|
|
|
int32 count = fWinBorderList.CountItems();
|
2004-06-19 17:04:50 +04:00
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
wb = (WinBorder*)fWinBorderList.ItemAt(i);
|
2005-02-28 23:23:51 +03:00
|
|
|
|
2005-04-16 17:30:49 +04:00
|
|
|
if (wb->Feel() == B_NORMAL_WINDOW_FEEL
|
2005-06-23 21:40:35 +04:00
|
|
|
&& wb->App()->ClientTeam() == winBorder->App()->ClientTeam()) {
|
2005-02-28 23:23:51 +03:00
|
|
|
// R2: RootLayer comparison is needed. We'll see.
|
2005-06-17 20:34:22 +04:00
|
|
|
wb->fSubWindowList.RemoveItem(winBorder);
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove from application's list
|
2005-04-25 18:14:09 +04:00
|
|
|
if (feel == B_MODAL_APP_WINDOW_FEEL) {
|
2005-06-17 20:34:22 +04:00
|
|
|
winBorder->App()->fAppSubWindowList.RemoveItem(winBorder);
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
2005-04-25 18:14:09 +04:00
|
|
|
} else {
|
2005-02-28 23:23:51 +03:00
|
|
|
Unlock();
|
2005-03-31 00:06:50 +04:00
|
|
|
ActiveRootLayer()->Unlock();
|
2005-02-28 23:23:51 +03:00
|
|
|
debugger("RemoveWinBorder: WinBorder not found in Desktop list\n");
|
2003-02-20 21:05:35 +03:00
|
|
|
return;
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
2003-02-20 21:05:35 +03:00
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
// Tell to winBorder's RootLayer about this.
|
|
|
|
ActiveRootLayer()->RemoveWinBorder(winBorder);
|
|
|
|
|
2005-03-18 22:00:45 +03:00
|
|
|
Unlock();
|
2005-03-19 22:08:19 +03:00
|
|
|
ActiveRootLayer()->Unlock();
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Desktop::AddWinBorderToSubset(WinBorder *winBorder, WinBorder *toWinBorder)
|
2005-02-28 23:23:51 +03:00
|
|
|
{
|
2005-03-18 22:00:45 +03:00
|
|
|
// NOTE: we can safely lock the entire method body, because this method is called from
|
|
|
|
// RootLayer's thread only.
|
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
// we're playing with window list. lock first.
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
if (!winBorder || !toWinBorder
|
2005-04-25 18:14:09 +04:00
|
|
|
|| !fWinBorderList.HasItem(winBorder)
|
|
|
|
|| !fWinBorderList.HasItem(toWinBorder)) {
|
2005-02-28 23:23:51 +03:00
|
|
|
Unlock();
|
|
|
|
debugger("AddWinBorderToSubset: NULL WinBorder or not found in Desktop list\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
if ((winBorder->Feel() == B_FLOATING_SUBSET_WINDOW_FEEL
|
2005-04-16 17:30:49 +04:00
|
|
|
|| winBorder->Feel() == B_MODAL_SUBSET_WINDOW_FEEL)
|
2005-04-25 18:14:09 +04:00
|
|
|
&& toWinBorder->Feel() == B_NORMAL_WINDOW_FEEL
|
2005-06-23 21:40:35 +04:00
|
|
|
&& toWinBorder->App()->ClientTeam() == winBorder->App()->ClientTeam()
|
2005-06-17 20:34:22 +04:00
|
|
|
&& !toWinBorder->fSubWindowList.HasItem(winBorder)) {
|
2005-02-28 23:23:51 +03:00
|
|
|
// add to normal_window's list
|
2005-06-17 20:34:22 +04:00
|
|
|
toWinBorder->fSubWindowList.AddWinBorder(winBorder);
|
2005-04-25 18:14:09 +04:00
|
|
|
} else {
|
2005-02-28 23:23:51 +03:00
|
|
|
Unlock();
|
|
|
|
debugger("AddWinBorderToSubset: you must add a subset_window to a normal_window's subset with the same team_id\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
// send WinBorder to be added to workspaces, if not already in there.
|
|
|
|
ActiveRootLayer()->AddSubsetWinBorder(winBorder, toWinBorder);
|
2005-03-18 22:00:45 +03:00
|
|
|
|
|
|
|
Unlock();
|
2004-01-12 01:12:55 +03:00
|
|
|
}
|
2004-01-22 03:32:07 +03:00
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Desktop::RemoveWinBorderFromSubset(WinBorder *winBorder, WinBorder *fromWinBorder)
|
2004-01-22 03:32:07 +03:00
|
|
|
{
|
2005-03-18 22:00:45 +03:00
|
|
|
// NOTE: we can safely lock the entire method body, because this method is called from
|
|
|
|
// RootLayer's thread only.
|
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
// we're playing with window list. lock first.
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
if (!winBorder || !fromWinBorder
|
2005-04-25 18:14:09 +04:00
|
|
|
|| !fWinBorderList.HasItem(winBorder)
|
|
|
|
|| !fWinBorderList.HasItem(fromWinBorder)) {
|
2005-02-28 23:23:51 +03:00
|
|
|
Unlock();
|
|
|
|
debugger("RemoveWinBorderFromSubset: NULL WinBorder or not found in Desktop list\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-06-19 17:04:50 +04:00
|
|
|
|
2005-03-18 22:00:45 +03:00
|
|
|
// remove WinBorder from workspace, if needed - some other windows may still have it in their subset
|
|
|
|
ActiveRootLayer()->RemoveSubsetWinBorder(winBorder, fromWinBorder);
|
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
if (fromWinBorder->Feel() == B_NORMAL_WINDOW_FEEL) {
|
2005-02-28 23:23:51 +03:00
|
|
|
//remove from this normal_window's subset.
|
2005-06-17 20:34:22 +04:00
|
|
|
fromWinBorder->fSubWindowList.RemoveItem(winBorder);
|
2005-04-25 18:14:09 +04:00
|
|
|
} else {
|
2005-02-28 23:23:51 +03:00
|
|
|
Unlock();
|
|
|
|
debugger("RemoveWinBorderFromSubset: you must remove a subset_window from a normal_window's subset\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-09-09 01:18:39 +04:00
|
|
|
|
2005-02-28 23:23:51 +03:00
|
|
|
Unlock();
|
2003-08-31 21:38:34 +04:00
|
|
|
}
|
2004-01-22 03:32:07 +03:00
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Desktop::SetWinBorderFeel(WinBorder *winBorder, uint32 feel)
|
2005-04-21 22:57:34 +04:00
|
|
|
{
|
|
|
|
// NOTE: this method is called from RootLayer thread only
|
|
|
|
|
|
|
|
// we're playing with window list. lock first.
|
|
|
|
Lock();
|
|
|
|
|
|
|
|
RemoveWinBorder(winBorder);
|
|
|
|
winBorder->QuietlySetFeel(feel);
|
|
|
|
AddWinBorder(winBorder);
|
|
|
|
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
2005-04-25 18:14:09 +04:00
|
|
|
|
|
|
|
WinBorder *
|
2005-07-05 22:14:24 +04:00
|
|
|
Desktop::FindWinBorderByClientToken(int32 token, team_id teamID)
|
2005-02-28 23:23:51 +03:00
|
|
|
{
|
2005-07-05 22:14:24 +04:00
|
|
|
BAutolock locker(this);
|
2005-02-28 23:23:51 +03:00
|
|
|
|
2005-07-05 22:14:24 +04:00
|
|
|
WinBorder *wb;
|
2005-04-25 18:14:09 +04:00
|
|
|
for (int32 i = 0; (wb = (WinBorder *)fWinBorderList.ItemAt(i)); i++) {
|
2005-02-28 23:23:51 +03:00
|
|
|
if (wb->Window()->ClientToken() == token
|
2005-06-23 21:40:35 +04:00
|
|
|
&& wb->Window()->ClientTeam() == teamID)
|
2005-07-05 22:14:24 +04:00
|
|
|
return wb;
|
2005-02-28 23:23:51 +03:00
|
|
|
}
|
2005-04-25 18:14:09 +04:00
|
|
|
|
2005-07-05 22:14:24 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-31 22:35:46 +03:00
|
|
|
const BObjectList<WinBorder> &
|
|
|
|
Desktop::WindowList() const
|
|
|
|
{
|
|
|
|
if (!IsLocked())
|
|
|
|
debugger("You must lock before getting registered windows list\n");
|
|
|
|
|
|
|
|
return fWinBorderList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-05 22:14:24 +04:00
|
|
|
void
|
|
|
|
Desktop::WriteWindowList(team_id team, BPrivate::LinkSender& sender)
|
|
|
|
{
|
|
|
|
BAutolock locker(this);
|
|
|
|
|
|
|
|
// compute the number of windows
|
|
|
|
|
|
|
|
int32 count = 0;
|
|
|
|
if (team >= B_OK) {
|
|
|
|
for (int32 i = 0; i < fWinBorderList.CountItems(); i++) {
|
2005-10-31 22:35:46 +03:00
|
|
|
WinBorder* border = fWinBorderList.ItemAt(i);
|
2005-07-05 22:14:24 +04:00
|
|
|
|
|
|
|
if (border->Window()->ClientTeam() == team)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
count = fWinBorderList.CountItems();
|
|
|
|
|
|
|
|
// write list
|
|
|
|
|
|
|
|
sender.StartMessage(SERVER_TRUE);
|
|
|
|
sender.Attach<int32>(count);
|
|
|
|
|
|
|
|
for (int32 i = 0; i < fWinBorderList.CountItems(); i++) {
|
2005-10-31 22:35:46 +03:00
|
|
|
WinBorder* border = fWinBorderList.ItemAt(i);
|
2005-07-05 22:14:24 +04:00
|
|
|
|
|
|
|
if (team >= B_OK && border->Window()->ClientTeam() != team)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sender.Attach<int32>(border->Window()->ServerToken());
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Desktop::WriteWindowInfo(int32 serverToken, BPrivate::LinkSender& sender)
|
|
|
|
{
|
|
|
|
BAutolock locker(this);
|
|
|
|
BAutolock tokenLocker(BPrivate::gDefaultTokens);
|
|
|
|
|
|
|
|
ServerWindow* window;
|
|
|
|
if (BPrivate::gDefaultTokens.GetToken(serverToken,
|
|
|
|
B_SERVER_TOKEN, (void**)&window) != B_OK) {
|
|
|
|
sender.StartMessage(B_ENTRY_NOT_FOUND);
|
|
|
|
sender.Flush();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_info info;
|
|
|
|
window->GetInfo(info);
|
|
|
|
|
|
|
|
int32 length = window->Title() ? strlen(window->Title()) : 0;
|
|
|
|
|
|
|
|
sender.StartMessage(B_OK);
|
|
|
|
sender.Attach<int32>(sizeof(window_info) + length + 1);
|
|
|
|
sender.Attach(&info, sizeof(window_info));
|
|
|
|
if (length > 0)
|
|
|
|
sender.Attach(window->Title(), length + 1);
|
|
|
|
else
|
|
|
|
sender.Attach<char>('\0');
|
|
|
|
sender.Flush();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
2004-01-22 03:32:07 +03:00
|
|
|
|