Turns out the whole "active app" mechanism in the registrar wasn't used at all; the

Switcher now works as expected.
* Renamed TRoster::ActivateApp() to UpdateActiveApp(), as the app is already activated
  at that point (the registrar only keeps track of it).
* BWindow::DispatchMessage() now calls the new BRoster::Private::UpdateActiveApp()
  method when it receives a B_WINDOW_ACTIVATED message.
* Added BRoster::_UpdateActiveApp() which calls the new B_REG_UPDATE_ACTIVE_APP.
* Removed now unused B_REG_ACTIVATE_APP.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19857 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-01-18 17:45:08 +00:00
parent badbad99a9
commit c2f641f2e5
8 changed files with 121 additions and 104 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2006, Haiku.
* Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -146,7 +146,7 @@ class BRoster {
const BList *messageList, int argc,
const char *const *args,
team_id *appTeam) const;
bool _UpdateActiveApp(team_id team) const;
status_t _UpdateActiveApp(team_id team) const;
void _SetAppFlags(team_id team, uint32 flags) const;
void _DumpRoster() const;
status_t _ResolveApp(const char *inType, entry_ref *ref, entry_ref *appRef,

View File

@ -1,35 +1,20 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: RegistrarDefs.h
// Author(s): Ingo Weinhold (bonefish@users.sf.net)
// Description: API classes - registrar interface.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold, bonefish@users.sf.net
*/
#ifndef REGISTRAR_DEFS_H
#define REGISTRAR_DEFS_H
//! API classes - registrar interface.
#include <Errors.h>
#include <Roster.h>
namespace BPrivate {
// names
@ -62,7 +47,7 @@ enum {
B_REG_SET_SIGNATURE = 'rgss',
B_REG_GET_APP_INFO = 'rgai',
B_REG_GET_APP_LIST = 'rgal',
B_REG_ACTIVATE_APP = 'rgac',
B_REG_UPDATE_ACTIVE_APP = 'rgua',
B_REG_BROADCAST = 'rgbc',
B_REG_START_WATCHING = 'rgwa',
B_REG_STOP_WATCHING = 'rgsw',

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2006, Haiku.
* Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -75,6 +75,9 @@ class BRoster::Private {
void ApplicationCrashed(team_id team) const
{ fRoster->_ApplicationCrashed(team); }
void UpdateActiveApp(team_id team) const
{ fRoster->_UpdateActiveApp(team); }
static void InitBeRoster();
static void DeleteBeRoster();

View File

@ -1,9 +1,10 @@
/*
* Copyright 2001-2006, Haiku.
* Copyright 2001-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold (bonefish@users.sf.net)
* Axel Dörfler, axeld@pinc-software.de
*/
/*! BRoster class lets you launch apps and keeps track of apps
@ -510,13 +511,14 @@ BRoster::GetRunningAppInfo(team_id team, app_info *info) const
status_t
BRoster::GetActiveAppInfo(app_info *info) const
{
status_t error = (info ? B_OK : B_BAD_VALUE);
if (info == NULL)
return B_BAD_VALUE;
// compose the request message
BMessage request(B_REG_GET_APP_INFO);
// send the request
BMessage reply;
if (error == B_OK)
error = fMessenger.SendMessage(&request, &reply);
status_t error = fMessenger.SendMessage(&request, &reply);
// evaluate the reply
if (error == B_OK) {
if (reply.what == B_REG_SUCCESS)
@ -1732,7 +1734,34 @@ BRoster::_ApplicationCrashed(team_id team)
}
// _LaunchApp
/*!
Tells the registrar which application is currently active.
It's called from within BWindow on B_WINDOW_ACTIVATED messages.
*/
status_t
BRoster::_UpdateActiveApp(team_id team) const
{
if (team < B_OK)
return B_BAD_TEAM_ID;
// compose the request message
BMessage request(B_REG_UPDATE_ACTIVE_APP);
status_t status = request.AddInt32("team", team);
// send the request
BMessage reply;
if (status == B_OK)
status = fMessenger.SendMessage(&request, &reply);
// evaluate the reply
if (status == B_OK && reply.what != B_REG_SUCCESS
&& reply.FindInt32("error", &status) != B_OK)
status = B_ERROR;
return status;
}
/*! \brief Launches the application associated with the supplied MIME type or
the entry referred to by the supplied entry_ref.

View File

@ -29,6 +29,7 @@
#include <MenuPrivate.h>
#include <MessagePrivate.h>
#include <PortLink.h>
#include <RosterPrivate.h>
#include <ServerProtocol.h>
#include <TokenSpace.h>
#include <tracker_private.h>
@ -905,12 +906,18 @@ FrameMoved(origin);
if (msg->FindBool("active", &active) == B_OK
&& active != fActive) {
fActive = active;
if (active) {
// notify registrar about the active app
BRoster::Private roster;
roster.UpdateActiveApp(be_app->Team());
}
WindowActivated(active);
// call hook function 'WindowActivated(bool)' for all
// views attached to this window.
fTopView->_Activate(active);
// we notify the input server if we are gaining or losing focus
// from a view which has the B_INPUT_METHOD_AWARE on a window
// (de)activation

View File

@ -1,16 +1,14 @@
// Registrar.cpp
/*
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold, bonefish@users.sf.net
*/
#include "Debug.h"
#include <stdio.h>
#include <string.h>
#include <Application.h>
#include <Message.h>
#include <OS.h>
#include <RegistrarDefs.h>
#include <RosterPrivate.h>
#include "ClipboardHandler.h"
#include "EventQueue.h"
#include "MessageDeliverer.h"
@ -22,6 +20,16 @@
#include "ShutdownProcess.h"
#include "TRoster.h"
#include <Application.h>
#include <Message.h>
#include <OS.h>
#include <RegistrarDefs.h>
#include <RosterPrivate.h>
#include <stdio.h>
#include <string.h>
/*!
\class Registrar
\brief The application class of the registrar.
@ -38,20 +46,20 @@ static const char *kEventQueueName = "timer_thread";
//! Time interval between two roster sanity checks (1 s).
static const bigtime_t kRosterSanityEventInterval = 1000000LL;
// constructor
/*! \brief Creates the registrar application class.
\param error Passed to the BApplication constructor for returning an
error code.
*/
Registrar::Registrar(status_t *error)
: BServer(kRegistrarSignature, false, error),
fRoster(NULL),
fClipboardHandler(NULL),
fMIMEManager(NULL),
fEventQueue(NULL),
fMessageRunnerManager(NULL),
fSanityEvent(NULL),
fShutdownProcess(NULL)
: BServer(kRegistrarSignature, false, error),
fRoster(NULL),
fClipboardHandler(NULL),
fMIMEManager(NULL),
fEventQueue(NULL),
fMessageRunnerManager(NULL),
fSanityEvent(NULL),
fShutdownProcess(NULL)
{
FUNCTION_START();
}
@ -147,8 +155,8 @@ Registrar::MessageReceived(BMessage *message)
case B_REG_GET_APP_LIST:
fRoster->HandleGetAppList(message);
break;
case B_REG_ACTIVATE_APP:
fRoster->HandleActivateApp(message);
case B_REG_UPDATE_ACTIVE_APP:
fRoster->HandleUpdateActiveApp(message);
break;
case B_REG_BROADCAST:
fRoster->HandleBroadcast(message);
@ -347,7 +355,10 @@ Registrar::_HandleShutDown(BMessage *request)
ShutdownProcess::SendReply(request, error);
}
// main
// #pragma mark -
/*! \brief Creates and runs the registrar application.
The main thread is renamed.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2006, Ingo Weinhold, bonefish@users.sf.net.
* Copyright 2001-2007, Ingo Weinhold, bonefish@users.sf.net.
* Distributed under the terms of the MIT License.
*/
@ -718,20 +718,22 @@ TRoster::HandleGetAppList(BMessage *request)
FUNCTION_END();
}
// HandleActivateApp
/*! \brief Handles a ActivateApp() request.
/*! \brief Handles a _UpdateActiveApp() request.
This is sent from a BWindow when it receives a B_WINDOW_ACTIVATED message.
\param request The request message
*/
void
TRoster::HandleActivateApp(BMessage *request)
TRoster::HandleUpdateActiveApp(BMessage *request)
{
FUNCTION_START();
BAutolock _(fLock);
status_t error = B_OK;
// get the parameters
status_t error = B_OK;
team_id team;
if (request->FindInt32("team", &team) != B_OK)
error = B_BAD_VALUE;
@ -739,7 +741,7 @@ TRoster::HandleActivateApp(BMessage *request)
// activate the app
if (error == B_OK) {
if (RosterAppInfo *info = fRegisteredApps.InfoFor(team))
ActivateApp(info);
UpdateActiveApp(info);
else
error = B_BAD_TEAM_ID;
}
@ -1223,7 +1225,7 @@ TRoster::RemoveApp(RosterAppInfo *info)
}
}
// ActivateApp
/*! \brief Activates the application identified by \a info.
The currently active application is deactivated and the one whose
@ -1233,7 +1235,7 @@ TRoster::RemoveApp(RosterAppInfo *info)
\param info The info of the app to be activated
*/
void
TRoster::ActivateApp(RosterAppInfo *info)
TRoster::UpdateActiveApp(RosterAppInfo *info)
{
BAutolock _(fLock);
@ -1243,6 +1245,7 @@ TRoster::ActivateApp(RosterAppInfo *info)
fActiveApp = NULL;
if (oldActiveApp)
_AppDeactivated(oldActiveApp);
// activate the new app
if (info) {
fActiveApp = info;
@ -1449,7 +1452,7 @@ TRoster::_AppRemoved(RosterAppInfo *info)
if (info) {
// deactivate the app, if it was the active one
if (info == fActiveApp)
ActivateApp(NULL);
UpdateActiveApp(NULL);
// notify the watchers
BMessage message(B_SOME_APP_QUIT);
_AddMessageWatchingInfo(&message, info);

View File

@ -1,45 +1,24 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: TRoster.h
// Author: Ingo Weinhold (bonefish@users.sf.net)
// Description: TRoster is the incarnation of The Roster. It manages the
// running applications.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2007, Ingo Weinhold, bonefish@users.sf.net.
* Distributed under the terms of the MIT License.
*/
#ifndef T_ROSTER_H
#define T_ROSTER_H
#include <hash_set>
#include <map>
#include <Locker.h>
#include <MessageQueue.h>
#include <SupportDefs.h>
#include "AppInfoList.h"
#include "RecentApps.h"
#include "RecentEntries.h"
#include "WatchingService.h"
#include <Locker.h>
#include <MessageQueue.h>
#include <SupportDefs.h>
#include <hash_set>
#include <map>
#if __GNUC__ >= 4
using __gnu_cxx::hash_set;
#endif
@ -65,7 +44,7 @@ public:
void HandleSetSignature(BMessage *request);
void HandleGetAppInfo(BMessage *request);
void HandleGetAppList(BMessage *request);
void HandleActivateApp(BMessage *request);
void HandleUpdateActiveApp(BMessage *request);
void HandleBroadcast(BMessage *request);
void HandleStartWatching(BMessage *request);
void HandleStopWatching(BMessage *request);
@ -86,7 +65,7 @@ public:
status_t AddApp(RosterAppInfo *info);
void RemoveApp(RosterAppInfo *info);
void ActivateApp(RosterAppInfo *info);
void UpdateActiveApp(RosterAppInfo *info);
void CheckSanity();