2005-06-17 23:10:15 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001-2005, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT license.
|
|
|
|
*
|
2005-06-23 21:40:35 +04:00
|
|
|
* Authors:
|
|
|
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
2005-06-17 23:10:15 +04:00
|
|
|
*/
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2005-10-29 20:27:43 +04:00
|
|
|
#include <unistd.h>
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2004-01-27 03:38:14 +03:00
|
|
|
#include <Accelerant.h>
|
2005-05-15 04:22:55 +04:00
|
|
|
#include <AppDefs.h>
|
|
|
|
#include <Directory.h>
|
2003-03-30 04:17:50 +04:00
|
|
|
#include <Entry.h>
|
2005-05-15 04:22:55 +04:00
|
|
|
#include <File.h>
|
|
|
|
#include <Message.h>
|
2003-10-09 03:18:30 +04:00
|
|
|
#include <Path.h>
|
2003-07-12 02:30:55 +04:00
|
|
|
#include <PortLink.h>
|
2005-05-15 04:22:55 +04:00
|
|
|
#include <StopWatch.h>
|
2005-06-17 02:30:50 +04:00
|
|
|
#include <RosterPrivate.h>
|
2005-07-01 14:09:11 +04:00
|
|
|
#include <Autolock.h>
|
2003-08-31 21:38:34 +04:00
|
|
|
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "BitmapManager.h"
|
2003-03-31 01:09:39 +04:00
|
|
|
#include "ColorSet.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "CursorManager.h"
|
2005-06-17 23:10:15 +04:00
|
|
|
#include "DecorManager.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "DefaultDecorator.h"
|
|
|
|
#include "Desktop.h"
|
|
|
|
#include "FontServer.h"
|
2005-06-24 03:46:17 +04:00
|
|
|
#include "HWInterface.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "RegistrarDefs.h"
|
|
|
|
#include "RGBColor.h"
|
2005-10-30 23:05:18 +03:00
|
|
|
#include "Layer.h"
|
|
|
|
#include "WinBorder.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
#include "RootLayer.h"
|
2005-07-15 16:45:23 +04:00
|
|
|
#include "ScreenManager.h"
|
2003-01-27 22:43:15 +03:00
|
|
|
#include "ServerApp.h"
|
2005-07-29 03:48:46 +04:00
|
|
|
#include "ServerConfig.h"
|
2003-02-20 23:14:57 +03:00
|
|
|
#include "ServerCursor.h"
|
2003-01-27 22:43:15 +03:00
|
|
|
#include "ServerProtocol.h"
|
2003-02-07 15:53:57 +03:00
|
|
|
#include "ServerWindow.h"
|
2005-06-08 01:32:24 +04:00
|
|
|
#include "SystemPalette.h"
|
2003-03-30 04:17:50 +04:00
|
|
|
#include "Utils.h"
|
2005-05-15 04:22:55 +04:00
|
|
|
|
|
|
|
#include "AppServer.h"
|
|
|
|
|
2003-03-30 04:17:50 +04:00
|
|
|
//#define DEBUG_KEYHANDLING
|
2004-09-05 04:52:45 +04:00
|
|
|
//#define DEBUG_SERVER
|
2004-07-30 19:16:59 +04:00
|
|
|
|
2003-09-09 01:08:27 +04:00
|
|
|
#ifdef DEBUG_KEYHANDLING
|
|
|
|
# include <stdio.h>
|
2004-07-30 19:16:59 +04:00
|
|
|
# define KBTRACE(x) printf x
|
|
|
|
#else
|
|
|
|
# define KBTRACE(x) ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_SERVER
|
|
|
|
# include <stdio.h>
|
2003-09-09 01:08:27 +04:00
|
|
|
# define STRACE(x) printf x
|
|
|
|
#else
|
|
|
|
# define STRACE(x) ;
|
|
|
|
#endif
|
2004-01-20 01:18:37 +03:00
|
|
|
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2003-02-15 18:28:22 +03:00
|
|
|
// Globals
|
2005-05-28 17:43:13 +04:00
|
|
|
Desktop *gDesktop;
|
2004-01-13 03:56:36 +03:00
|
|
|
|
2005-05-27 17:36:05 +04:00
|
|
|
port_id gAppServerPort;
|
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
static AppServer *sAppServer;
|
2003-01-20 23:38:49 +03:00
|
|
|
|
2003-03-31 01:09:39 +04:00
|
|
|
//! System-wide GUI color object
|
2005-06-24 07:31:41 +04:00
|
|
|
ColorSet gGUIColorSet;
|
2003-03-31 01:09:39 +04:00
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Constructor
|
|
|
|
|
|
|
|
This loads the default fonts, allocates all the major global variables, spawns the main housekeeping
|
|
|
|
threads, loads user preferences for the UI and decorator, and allocates various locks.
|
|
|
|
*/
|
2005-07-26 01:53:48 +04:00
|
|
|
AppServer::AppServer()
|
|
|
|
: MessageLooper("app_server"),
|
2005-04-20 00:44:09 +04:00
|
|
|
fCursorSem(-1),
|
2005-07-26 01:08:34 +04:00
|
|
|
fCursorArea(-1)
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
2005-07-26 01:53:48 +04:00
|
|
|
fMessagePort = create_port(DEFAULT_MONITOR_PORT_SIZE, SERVER_PORT_NAME);
|
|
|
|
if (fMessagePort < B_OK)
|
2005-04-17 16:26:16 +04:00
|
|
|
debugger("app_server could not create message port");
|
2005-05-27 17:36:05 +04:00
|
|
|
|
2005-07-26 01:53:48 +04:00
|
|
|
fLink.SetReceiverPort(fMessagePort);
|
2005-05-27 17:36:05 +04:00
|
|
|
gAppServerPort = fMessagePort;
|
|
|
|
|
2005-04-17 16:26:16 +04:00
|
|
|
// Create the input port. The input_server will send it's messages here.
|
|
|
|
// TODO: If we want multiple user support we would need an individual
|
|
|
|
// port for each user and do the following for each RootLayer.
|
|
|
|
fServerInputPort = create_port(200, SERVER_INPUT_PORT);
|
2005-07-26 01:53:48 +04:00
|
|
|
if (fServerInputPort < B_OK)
|
2005-04-17 16:26:16 +04:00
|
|
|
debugger("app_server could not create input port");
|
2005-05-27 17:36:05 +04:00
|
|
|
|
2005-05-28 17:43:13 +04:00
|
|
|
sAppServer = this;
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
// Create the font server and scan the proper directories.
|
2005-06-24 07:31:41 +04:00
|
|
|
gFontServer = new FontServer;
|
|
|
|
gFontServer->Lock();
|
2005-08-12 18:55:46 +04:00
|
|
|
gFontServer->ScanSystemFolders();
|
2005-06-24 07:31:41 +04:00
|
|
|
gFontServer->SaveList();
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
if (!gFontServer->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
DEFAULT_PLAIN_FONT_STYLE,
|
|
|
|
DEFAULT_PLAIN_FONT_SIZE) &&
|
2005-06-24 07:31:41 +04:00
|
|
|
!gFontServer->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
DEFAULT_PLAIN_FONT_STYLE,
|
|
|
|
DEFAULT_PLAIN_FONT_SIZE)) {
|
|
|
|
printf("Couldn't set plain to %s (fallback: %s), %s %d pt\n",
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_PLAIN_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
FALLBACK_PLAIN_FONT_FAMILY,
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_PLAIN_FONT_STYLE,
|
|
|
|
DEFAULT_PLAIN_FONT_SIZE);
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
if (!gFontServer->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
DEFAULT_BOLD_FONT_STYLE,
|
|
|
|
DEFAULT_BOLD_FONT_SIZE) &&
|
2005-06-24 07:31:41 +04:00
|
|
|
!gFontServer->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
DEFAULT_BOLD_FONT_STYLE,
|
|
|
|
DEFAULT_BOLD_FONT_SIZE)) {
|
|
|
|
printf("Couldn't set bold to %s (fallback: %s), %s %d pt\n",
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_BOLD_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
FALLBACK_BOLD_FONT_FAMILY,
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_BOLD_FONT_STYLE,
|
|
|
|
DEFAULT_BOLD_FONT_SIZE);
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
if (!gFontServer->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
DEFAULT_FIXED_FONT_STYLE,
|
|
|
|
DEFAULT_FIXED_FONT_SIZE) &&
|
2005-06-24 07:31:41 +04:00
|
|
|
!gFontServer->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
DEFAULT_FIXED_FONT_STYLE,
|
|
|
|
DEFAULT_FIXED_FONT_SIZE)) {
|
|
|
|
printf("Couldn't set fixed to %s (fallback: %s), %s %d pt\n",
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_FIXED_FONT_FAMILY,
|
2005-04-14 04:11:33 +04:00
|
|
|
FALLBACK_FIXED_FONT_FAMILY,
|
2005-04-12 17:15:38 +04:00
|
|
|
DEFAULT_FIXED_FONT_STYLE,
|
|
|
|
DEFAULT_FIXED_FONT_SIZE);
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
gFontServer->Unlock();
|
2005-05-27 17:36:05 +04:00
|
|
|
|
2003-07-05 21:40:42 +04:00
|
|
|
// Load the GUI colors here and set the global set to the values contained therein. If this
|
|
|
|
// is not possible, set colors to the defaults
|
2005-06-24 07:31:41 +04:00
|
|
|
if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME, &gGUIColorSet) != B_OK)
|
|
|
|
gGUIColorSet.SetToDefaults();
|
2003-07-12 02:30:55 +04:00
|
|
|
|
2005-07-15 16:45:23 +04:00
|
|
|
gScreenManager = new ScreenManager();
|
2005-07-26 01:08:34 +04:00
|
|
|
gScreenManager->Run();
|
2005-07-15 16:45:23 +04:00
|
|
|
|
2005-07-24 22:32:05 +04:00
|
|
|
// the system palette needs to be initialized before the desktop,
|
|
|
|
// since it is used there already
|
2005-06-08 01:32:24 +04:00
|
|
|
InitializeColorMap();
|
|
|
|
|
2003-02-20 23:14:57 +03:00
|
|
|
// Create the bitmap allocator. Object declared in BitmapManager.cpp
|
2005-06-24 07:31:41 +04:00
|
|
|
gBitmapManager = new BitmapManager();
|
2005-07-24 22:32:05 +04:00
|
|
|
|
|
|
|
// Set up the Desktop
|
|
|
|
gDesktop = new Desktop();
|
|
|
|
gDesktop->Init();
|
|
|
|
gDesktop->Run();
|
2003-02-20 23:14:57 +03:00
|
|
|
|
2005-04-17 16:26:16 +04:00
|
|
|
#if 0
|
2005-04-20 00:44:09 +04:00
|
|
|
LaunchCursorThread();
|
2005-04-17 16:26:16 +04:00
|
|
|
#endif
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Destructor
|
2005-07-26 01:53:48 +04:00
|
|
|
Reached only when the server is asked to shut down in Test mode.
|
2003-01-27 22:43:15 +03:00
|
|
|
*/
|
2005-06-24 07:31:41 +04:00
|
|
|
AppServer::~AppServer()
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
2005-06-24 07:31:41 +04:00
|
|
|
delete gBitmapManager;
|
2003-02-20 23:14:57 +03:00
|
|
|
|
2005-07-26 01:53:48 +04:00
|
|
|
gScreenManager->Lock();
|
|
|
|
gScreenManager->Quit();
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
delete gFontServer;
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Starts Input Server
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AppServer::LaunchInputServer()
|
|
|
|
{
|
|
|
|
// We are supposed to start the input_server, but it's a BApplication
|
|
|
|
// that depends on the registrar running, which is started after app_server
|
|
|
|
// so we wait on roster thread to launch the input server
|
|
|
|
|
|
|
|
fISThreadID = B_ERROR;
|
|
|
|
|
2005-06-23 21:40:35 +04:00
|
|
|
while (!BRoster::Private().IsMessengerValid(false) && !fQuitting) {
|
2005-04-20 00:44:09 +04:00
|
|
|
snooze(250000);
|
2005-06-17 02:30:50 +04:00
|
|
|
BRoster::Private::DeleteBeRoster();
|
|
|
|
BRoster::Private::InitBeRoster();
|
2005-04-20 00:44:09 +04:00
|
|
|
}
|
|
|
|
|
2005-06-23 21:40:35 +04:00
|
|
|
if (fQuitting)
|
2005-04-20 00:44:09 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// we use an area for cursor data communication with input_server
|
|
|
|
// area id and sem id are sent to the input_server
|
|
|
|
|
|
|
|
if (fCursorArea < B_OK)
|
|
|
|
fCursorArea = create_area("isCursor", (void**) &fCursorAddr, B_ANY_ADDRESS, B_PAGE_SIZE, B_FULL_LOCK, B_READ_AREA | B_WRITE_AREA);
|
|
|
|
if (fCursorSem < B_OK)
|
2005-05-15 04:22:55 +04:00
|
|
|
fCursorSem = create_sem(0, "isSem");
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
int32 arg_c = 1;
|
|
|
|
char **arg_v = (char **)malloc(sizeof(char *) * (arg_c + 1));
|
2005-04-28 14:10:52 +04:00
|
|
|
#if TEST_MODE
|
|
|
|
arg_v[0] = strdup("/boot/home/svnhaiku/trunk/distro/x86.R1/beos/system/servers/input_server");
|
|
|
|
#else
|
|
|
|
arg_v[0] = strdup("/system/servers/input_server");
|
|
|
|
#endif
|
2005-04-20 00:44:09 +04:00
|
|
|
arg_v[1] = NULL;
|
|
|
|
fISThreadID = load_image(arg_c, (const char**)arg_v, (const char **)environ);
|
|
|
|
free(arg_v[0]);
|
|
|
|
|
|
|
|
int32 tmpbuf[2] = {fCursorSem, fCursorArea};
|
2005-05-15 04:22:55 +04:00
|
|
|
int32 code = 0;
|
|
|
|
send_data(fISThreadID, code, (void *)tmpbuf, sizeof(tmpbuf));
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
resume_thread(fISThreadID);
|
|
|
|
setpgid(fISThreadID, 0);
|
|
|
|
|
|
|
|
// we receive
|
|
|
|
|
|
|
|
thread_id sender;
|
2005-05-15 04:22:55 +04:00
|
|
|
code = receive_data(&sender, (void *)tmpbuf, sizeof(tmpbuf));
|
|
|
|
fISASPort = tmpbuf[0];
|
|
|
|
fISPort = tmpbuf[1];
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
// if at any time, one of these ports is error prone, it might mean input_server is gone
|
|
|
|
// then relaunch input_server
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Starts the Cursor Thread
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AppServer::LaunchCursorThread()
|
|
|
|
{
|
|
|
|
// Spawn our cursor thread
|
2005-05-15 04:22:55 +04:00
|
|
|
fCursorThreadID = spawn_thread(CursorThread, "CursorThreadOfTheDeath", B_REAL_TIME_DISPLAY_PRIORITY - 1, this);
|
2005-04-20 00:44:09 +04:00
|
|
|
if (fCursorThreadID >= 0)
|
2005-05-15 04:22:55 +04:00
|
|
|
resume_thread(fCursorThreadID);
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief The Cursor Thread task
|
|
|
|
*/
|
|
|
|
int32
|
|
|
|
AppServer::CursorThread(void* data)
|
|
|
|
{
|
2005-06-23 21:40:35 +04:00
|
|
|
AppServer *server = (AppServer *)data;
|
2005-04-20 00:44:09 +04:00
|
|
|
|
2005-06-23 21:40:35 +04:00
|
|
|
server->LaunchInputServer();
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
do {
|
2005-06-23 21:40:35 +04:00
|
|
|
while (acquire_sem(server->fCursorSem) == B_OK) {
|
|
|
|
BPoint p;
|
|
|
|
p.y = *server->fCursorAddr & 0x7fff;
|
|
|
|
p.x = *server->fCursorAddr >> 15 & 0x7fff;
|
2005-04-20 00:44:09 +04:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
gDesktop->GetHWInterface()->MoveCursorTo(p.x, p.y);
|
2005-04-30 19:00:10 +04:00
|
|
|
STRACE(("CursorThread : %f, %f\n", p.x, p.y));
|
2005-04-20 00:44:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
snooze(100000);
|
2005-07-26 01:53:48 +04:00
|
|
|
} while (!server->IsQuitting());
|
2005-04-20 00:44:09 +04:00
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 18:28:22 +03:00
|
|
|
/*!
|
|
|
|
\brief The call that starts it all...
|
|
|
|
*/
|
2005-05-27 14:57:25 +04:00
|
|
|
void
|
2005-07-26 01:53:48 +04:00
|
|
|
AppServer::RunLooper()
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
2005-07-26 01:53:48 +04:00
|
|
|
rename_thread(find_thread(NULL), "picasso");
|
|
|
|
_message_thread((void *)this);
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2005-07-26 01:53:48 +04:00
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Message handling function for all messages sent to the app_server
|
|
|
|
\param code ID of the message sent
|
2004-07-30 19:16:59 +04:00
|
|
|
\param buffer Attachment buffer for the message.
|
2003-01-27 22:43:15 +03:00
|
|
|
|
|
|
|
*/
|
2005-05-26 19:06:31 +04:00
|
|
|
void
|
2005-07-26 01:53:48 +04:00
|
|
|
AppServer::_DispatchMessage(int32 code, BPrivate::LinkReceiver& msg)
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
2005-05-26 19:06:31 +04:00
|
|
|
switch (code) {
|
2005-07-26 01:08:34 +04:00
|
|
|
case AS_GET_DESKTOP:
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
2005-07-26 01:08:34 +04:00
|
|
|
port_id replyPort;
|
|
|
|
if (msg.Read<port_id>(&replyPort) < B_OK)
|
2005-06-08 08:01:59 +04:00
|
|
|
break;
|
2005-05-26 19:06:31 +04:00
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
int32 userID;
|
|
|
|
msg.Read<int32>(&userID);
|
2003-01-27 22:43:15 +03:00
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
BPrivate::LinkSender reply(replyPort);
|
|
|
|
reply.StartMessage(B_OK);
|
|
|
|
reply.Attach<port_id>(gDesktop->MessagePort());
|
|
|
|
reply.Flush();
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2003-02-24 18:47:06 +03:00
|
|
|
case AS_QUERY_FONTS_CHANGED:
|
2003-01-27 22:43:15 +03:00
|
|
|
{
|
|
|
|
// Client application is asking if the font list has changed since
|
|
|
|
// the last client-side refresh
|
|
|
|
|
|
|
|
// Attached data:
|
|
|
|
// 1) port_id reply port
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
gFontServer->Lock();
|
|
|
|
bool needsUpdate = gFontServer->FontsNeedUpdated();
|
|
|
|
gFontServer->Unlock();
|
|
|
|
|
2004-07-30 19:16:59 +04:00
|
|
|
// Seeing how the client merely wants an answer, we'll skip the BPortLink
|
2003-10-04 04:56:43 +04:00
|
|
|
// and all its overhead and just write the code to port.
|
2005-07-26 01:53:48 +04:00
|
|
|
port_id replyPort;
|
|
|
|
if (msg.Read<port_id>(&replyPort) < B_OK)
|
2004-07-30 19:16:59 +04:00
|
|
|
break;
|
2005-07-26 01:53:48 +04:00
|
|
|
|
|
|
|
BPrivate::PortLink reply(replyPort);
|
|
|
|
reply.StartMessage(needsUpdate ? SERVER_TRUE : SERVER_FALSE);
|
|
|
|
reply.Flush();
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2005-04-14 04:11:33 +04:00
|
|
|
#if TEST_MODE
|
2005-06-23 21:40:35 +04:00
|
|
|
case B_QUIT_REQUESTED:
|
2005-07-26 01:08:34 +04:00
|
|
|
{
|
2005-07-26 01:53:48 +04:00
|
|
|
thread_id thread = gDesktop->Thread();
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
// 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.
|
2005-03-08 00:52:41 +03:00
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
gDesktop->PostMessage(B_QUIT_REQUESTED);
|
2005-06-23 21:40:35 +04:00
|
|
|
fQuitting = true;
|
2005-07-05 05:02:32 +04:00
|
|
|
|
2005-07-26 01:08:34 +04:00
|
|
|
// we just wait for the desktop to kill itself
|
|
|
|
status_t status;
|
2005-07-26 01:53:48 +04:00
|
|
|
wait_for_thread(thread, &status);
|
2005-03-04 02:21:36 +03:00
|
|
|
|
2005-07-26 01:53:48 +04:00
|
|
|
kill_thread(fCursorThreadID);
|
|
|
|
delete this;
|
2004-01-17 21:37:57 +03:00
|
|
|
|
|
|
|
// we are now clear to exit
|
2005-07-06 08:57:57 +04:00
|
|
|
exit(0);
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
2005-07-06 08:57:57 +04:00
|
|
|
}
|
2005-06-23 21:40:35 +04:00
|
|
|
#endif
|
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
case AS_SET_SYSCURSOR_DEFAULTS:
|
|
|
|
{
|
2005-08-21 14:28:40 +04:00
|
|
|
gDesktop->GetCursorManager().SetDefaults();
|
2003-07-24 23:38:24 +04:00
|
|
|
break;
|
|
|
|
}
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2005-07-25 01:10:33 +04: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 error = B_OK;
|
|
|
|
|
|
|
|
// get the parameters
|
|
|
|
port_id replyPort;
|
|
|
|
team_id team;
|
|
|
|
if (msg.Read(&replyPort) < B_OK
|
|
|
|
|| msg.Read(&team) < B_OK) {
|
|
|
|
error = B_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// activate one of the app's windows.
|
|
|
|
if (error == B_OK) {
|
|
|
|
error = B_BAD_TEAM_ID;
|
2005-10-31 01:30:29 +03:00
|
|
|
if (gDesktop->Lock()) {
|
2005-10-30 23:05:18 +03:00
|
|
|
// search for an unhidden window to give focus to
|
|
|
|
int32 windowCount = gDesktop->WindowList().CountItems();
|
|
|
|
Layer *layer;
|
|
|
|
for (int32 i = 0; i < windowCount; ++i)
|
|
|
|
// is this layer in fact a WinBorder?
|
|
|
|
if ((layer = static_cast<Layer*>(gDesktop->WindowList().ItemAtFast(i)))) {
|
|
|
|
WinBorder *winBorder = dynamic_cast<WinBorder*>(layer);
|
|
|
|
// if winBorder is valid and not hidden, then we've found our target
|
|
|
|
if (winBorder && !winBorder->IsHidden()
|
|
|
|
&& winBorder->App()->ClientTeam() == team) {
|
|
|
|
if (gDesktop->ActiveRootLayer()
|
2005-10-31 01:30:29 +03:00
|
|
|
&& gDesktop->ActiveRootLayer()->Lock()) {
|
2005-10-30 23:05:18 +03:00
|
|
|
gDesktop->ActiveRootLayer()->SetActive(winBorder);
|
|
|
|
gDesktop->ActiveRootLayer()->Unlock();
|
|
|
|
|
|
|
|
if (gDesktop->ActiveRootLayer()->Active() == winBorder)
|
|
|
|
error = B_OK;
|
|
|
|
else
|
|
|
|
error = B_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gDesktop->Unlock();
|
|
|
|
}
|
2005-07-25 01:10:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// send the reply
|
|
|
|
BPrivate::PortLink replyLink(replyPort);
|
|
|
|
replyLink.StartMessage(error);
|
|
|
|
replyLink.Flush();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
default:
|
2005-06-23 21:40:35 +04:00
|
|
|
STRACE(("Server::MainLoop received unexpected code %ld (offset %ld)\n",
|
|
|
|
code, code - SERVER_TRUE));
|
2003-01-27 22:43:15 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-01-20 23:38:49 +03:00
|
|
|
}
|
|
|
|
|
2005-06-23 21:40:35 +04:00
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
2003-01-27 22:43:15 +03:00
|
|
|
/*!
|
|
|
|
\brief Entry function to run the entire server
|
|
|
|
\param argc Number of command-line arguments present
|
|
|
|
\param argv String array of the command-line arguments
|
|
|
|
\return -1 if the app_server is already running, 0 if everything's OK.
|
|
|
|
*/
|
2005-05-27 14:57:25 +04:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2003-01-20 23:38:49 +03:00
|
|
|
{
|
|
|
|
// There can be only one....
|
2005-05-27 17:36:05 +04:00
|
|
|
if (find_port(SERVER_PORT_NAME) >= B_OK)
|
2003-01-20 23:38:49 +03:00
|
|
|
return -1;
|
|
|
|
|
2005-03-13 20:07:40 +03:00
|
|
|
srand(real_time_clock_usecs());
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2005-07-26 01:53:48 +04:00
|
|
|
AppServer* server = new AppServer;
|
|
|
|
server->RunLooper();
|
2005-06-23 21:40:35 +04:00
|
|
|
|
2003-01-20 23:38:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|