2003-01-24 18:19:27 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// 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: Desktop.cpp
|
|
|
|
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
// Description: Functions used to work with workspaces and general desktop stuff
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#include "DisplayDriver.h"
|
|
|
|
#include "Desktop.h"
|
2003-02-14 14:04:01 +03:00
|
|
|
#include "DesktopClasses.h"
|
2003-02-15 18:28:22 +03:00
|
|
|
#include "ServerConfig.h"
|
2003-01-29 02:58:06 +03:00
|
|
|
|
|
|
|
#include "ViewDriver.h"
|
2003-02-12 14:24:26 +03:00
|
|
|
|
|
|
|
#if DISPLAYDRIVER == SCREENDRIVER
|
2003-01-29 02:58:06 +03:00
|
|
|
#include "ScreenDriver.h"
|
|
|
|
#endif
|
2003-02-12 14:24:26 +03:00
|
|
|
|
|
|
|
#if DISPLAYDRIVER == HWDRIVER
|
2003-01-29 02:58:06 +03:00
|
|
|
#include "AccelerantDriver.h"
|
|
|
|
#endif
|
|
|
|
|
2003-02-12 14:24:26 +03:00
|
|
|
#include "ServerWindow.h"
|
2003-01-24 18:19:27 +03:00
|
|
|
|
2003-04-05 05:51:35 +04:00
|
|
|
//#define DEBUG_DESKTOP
|
|
|
|
|
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-06 23:48:17 +04:00
|
|
|
bool ReadOBOSWorkspaceData(void);
|
|
|
|
bool ReadR5WorkspaceData(void);
|
|
|
|
void SaveWorkspaceData(void);
|
|
|
|
|
2003-02-12 14:24:26 +03:00
|
|
|
//! This namespace encapsulates all globals specifically for the desktop
|
2003-01-24 18:19:27 +03:00
|
|
|
namespace desktop_private {
|
2003-02-14 14:04:01 +03:00
|
|
|
int8 *dragmessage=NULL;
|
|
|
|
int32 dragmessagesize=0;
|
2003-02-14 04:53:53 +03:00
|
|
|
BLocker draglock,
|
2003-02-12 14:24:26 +03:00
|
|
|
layerlock,
|
2003-07-06 23:48:17 +04:00
|
|
|
workspacelock,
|
|
|
|
optlock;
|
2003-02-20 16:13:01 +03:00
|
|
|
BList *screenlist=NULL;
|
2003-02-14 14:04:01 +03:00
|
|
|
Screen *activescreen=NULL;
|
2003-07-06 23:48:17 +04:00
|
|
|
scroll_bar_info scrollbarinfo;
|
|
|
|
menu_info menuinfo;
|
2003-07-10 21:48:04 +04:00
|
|
|
mode_mouse ffm_mode;
|
|
|
|
bool ffm;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
//! locks layer access
|
2003-02-14 04:53:53 +03:00
|
|
|
void lock_layers(void) { desktop_private::layerlock.Lock(); }
|
2003-02-14 14:04:01 +03:00
|
|
|
//! unlocks layer access
|
2003-02-14 04:53:53 +03:00
|
|
|
void unlock_layers(void) { desktop_private::layerlock.Unlock(); }
|
2003-02-14 14:04:01 +03:00
|
|
|
//! locks access to drag and drop data
|
2003-02-14 04:53:53 +03:00
|
|
|
void lock_dragdata(void) { desktop_private::draglock.Lock(); }
|
2003-02-14 14:04:01 +03:00
|
|
|
//! unlocks access to drag and drop data
|
2003-02-14 04:53:53 +03:00
|
|
|
void unlock_dragdata(void) { desktop_private::draglock.Unlock(); }
|
2003-02-14 14:04:01 +03:00
|
|
|
//! locks access to the workspace list
|
2003-02-14 04:53:53 +03:00
|
|
|
void lock_workspaces(void) { desktop_private::workspacelock.Lock(); }
|
2003-02-14 14:04:01 +03:00
|
|
|
//! unlocks access to the workspace list
|
2003-02-14 04:53:53 +03:00
|
|
|
void unlock_workspaces(void) { desktop_private::workspacelock.Unlock(); }
|
|
|
|
|
2003-02-12 14:24:26 +03:00
|
|
|
/*!
|
|
|
|
\brief Initializes the desktop for use.
|
|
|
|
|
|
|
|
InitDesktop creates all workspaces, starts up the appropriate DisplayDriver, and
|
|
|
|
generally gets everything ready for the server to use.
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
void InitDesktop(void)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: InitWorkspace\n");
|
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
desktop_private::screenlist=new BList(0);
|
|
|
|
DisplayDriver *tdriver;
|
|
|
|
Screen *s=NULL;
|
2003-02-12 14:24:26 +03:00
|
|
|
|
2003-03-30 04:17:50 +04:00
|
|
|
#ifndef TEST_MODE
|
2003-02-14 14:04:01 +03:00
|
|
|
// If we're using the AccelerantDriver for rendering, eventually we will loop through
|
|
|
|
// drivers until one can't initialize in order to support multiple monitors. For now,
|
|
|
|
// we'll just load one and be done with it.
|
|
|
|
tdriver=new AccelerantDriver;
|
|
|
|
|
|
|
|
if(tdriver->Initialize())
|
|
|
|
{
|
|
|
|
// TODO: figure out how to load the workspace data and do it here.
|
|
|
|
// For now, we'll just use 3 workspaces.
|
|
|
|
|
|
|
|
s=new Screen(tdriver,3);
|
|
|
|
desktop_private::screenlist->AddItem(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Uh-oh. We don't have a video card. This would be a *bad* thing. Seeing how
|
|
|
|
// we can't see anything, we can't do anything, either. It's time to crash now. ;)
|
|
|
|
tdriver->Shutdown();
|
|
|
|
delete tdriver;
|
|
|
|
tdriver=NULL;
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("\t NULL display driver. OK. We crash now. :P\n");
|
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
}
|
2003-07-06 23:48:17 +04:00
|
|
|
#else // end if not TEST_MODE
|
2003-02-14 14:04:01 +03:00
|
|
|
|
|
|
|
#if DISPLAYDRIVER == SCREENDRIVER
|
|
|
|
tdriver=new ScreenDriver;
|
|
|
|
#else
|
|
|
|
tdriver=new ViewDriver;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(tdriver->Initialize())
|
|
|
|
{
|
|
|
|
// TODO: figure out how to load the workspace data and do it here.
|
|
|
|
// For now, we'll just use 3 workspaces.
|
|
|
|
|
2003-02-15 18:28:22 +03:00
|
|
|
s=new Screen(tdriver,3);
|
2003-02-14 14:04:01 +03:00
|
|
|
desktop_private::screenlist->AddItem(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Uh-oh. We don't have a video card. This would be a *bad* thing. Seeing how
|
|
|
|
// we can't see anything, we can't do anything, either. It's time to crash now. ;)
|
|
|
|
tdriver->Shutdown();
|
|
|
|
delete tdriver;
|
|
|
|
tdriver=NULL;
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("\t NULL display driver. OK. We crash now. :P\n");
|
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
}
|
2003-02-18 01:23:52 +03:00
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
|
|
|
|
// Once we utilize multiple monitors, we'll make Screen 0 the active one.
|
|
|
|
if(tdriver)
|
|
|
|
{
|
|
|
|
s->Activate();
|
|
|
|
desktop_private::activescreen=s;
|
2003-02-24 18:47:06 +03:00
|
|
|
s->SetSpace(0,B_32_BIT_640x480,true);
|
2003-02-14 14:04:01 +03:00
|
|
|
}
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
else
|
|
|
|
printf("ERROR: NULL display driver\n");
|
|
|
|
#endif
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
//! Shuts down the graphics subsystem
|
2003-01-24 18:19:27 +03:00
|
|
|
void ShutdownDesktop(void)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: ShutdownDesktop\n");
|
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
Screen *s;
|
|
|
|
|
|
|
|
for(int32 i=0;i<desktop_private::screenlist->CountItems();i++)
|
|
|
|
{
|
|
|
|
s=(Screen*)desktop_private::screenlist->ItemAt(i);
|
|
|
|
if(s)
|
|
|
|
delete s;
|
|
|
|
}
|
|
|
|
if(!desktop_private::dragmessage)
|
|
|
|
{
|
|
|
|
delete desktop_private::dragmessage;
|
|
|
|
desktop_private::dragmessage=NULL;
|
|
|
|
desktop_private::dragmessagesize=0;
|
|
|
|
}
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Add a workspace to the desktop
|
|
|
|
\param index Place in the workspace list to add the new one.
|
|
|
|
|
|
|
|
The default location to add a workspace is at the end of the list. If index
|
|
|
|
is less than 0 or greater than the current workspace count, AddWorkspace will place
|
|
|
|
the workspace at the list's end. Note that it is possible to insert a workspace
|
|
|
|
in the list simply by specifying an index.
|
|
|
|
*/
|
2003-06-23 06:54:52 +04:00
|
|
|
void AddWorkspace(int32 index)
|
2003-01-24 18:19:27 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: AddWorkspace(%ld)\n",index+1);
|
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
lock_workspaces();
|
|
|
|
lock_layers();
|
|
|
|
|
|
|
|
Screen *s;
|
|
|
|
|
|
|
|
for(int32 i=0;i<desktop_private::screenlist->CountItems();i++)
|
|
|
|
{
|
|
|
|
s=(Screen*)desktop_private::screenlist->ItemAt(i);
|
|
|
|
if(s)
|
|
|
|
s->AddWorkspace(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock_layers();
|
|
|
|
unlock_workspaces();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Deletes a workspace
|
|
|
|
\param index The index to delete
|
|
|
|
|
|
|
|
If the workspace specified by index does not refer to a valid workspace, this function
|
|
|
|
will fail. Should the workspace to be deleted be the active one, the previous
|
|
|
|
workspace in the list will be chosen or workspace 0 if workspace 0 is being deleted.
|
|
|
|
This function will fail if there is only 1 workspace used.
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
void DeleteWorkspace(int32 index)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: DeleteWorkspace(%ld)\n",index+1);
|
|
|
|
#endif
|
2003-02-14 14:04:01 +03:00
|
|
|
lock_workspaces();
|
|
|
|
lock_layers();
|
|
|
|
|
|
|
|
Screen *s;
|
|
|
|
|
|
|
|
for(int32 i=0;i<desktop_private::screenlist->CountItems();i++)
|
|
|
|
{
|
|
|
|
s=(Screen*)desktop_private::screenlist->ItemAt(i);
|
|
|
|
if(s)
|
|
|
|
s->DeleteWorkspace(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock_layers();
|
|
|
|
unlock_workspaces();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the number of workspaces available
|
|
|
|
\return the number of workspaces available
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
int32 CountWorkspaces(void)
|
|
|
|
{
|
2003-02-14 14:04:01 +03:00
|
|
|
lock_workspaces();
|
|
|
|
lock_layers();
|
|
|
|
|
|
|
|
int32 count=desktop_private::activescreen->CountWorkspaces();
|
|
|
|
|
|
|
|
unlock_layers();
|
|
|
|
unlock_workspaces();
|
|
|
|
|
|
|
|
return count;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Sets the number of workspaces available
|
|
|
|
\param count The new number of available workspaces
|
|
|
|
|
|
|
|
This function will fail if count is less than 1 or greater than 32. The limit of 32 was
|
|
|
|
set by BeOS. Making the limit higher will cause unreachable workspaces because of the
|
|
|
|
API interface used to access them. Were this to change, the only limiting factor for
|
|
|
|
workspace count would be the hardware itself.
|
2003-03-01 23:25:08 +03:00
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
void SetWorkspaceCount(int32 count)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: SetWorkspaceCount(%ld)\n",count);
|
|
|
|
#endif
|
2003-03-01 23:25:08 +03:00
|
|
|
if(count<1 || count>32)
|
|
|
|
return;
|
|
|
|
lock_workspaces();
|
|
|
|
Screen *scr;
|
|
|
|
for(int32 i=0;i<desktop_private::screenlist->CountItems();i++)
|
|
|
|
{
|
|
|
|
scr=(Screen*)desktop_private::screenlist->ItemAt(i);
|
|
|
|
if(!scr)
|
|
|
|
continue;
|
|
|
|
scr->SetWorkspaceCount(count);
|
|
|
|
}
|
|
|
|
unlock_workspaces();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the index of the active workspace
|
2003-03-01 23:25:08 +03:00
|
|
|
\return the index of the active workspace or -1 if an internal error occurred.
|
2003-02-14 14:04:01 +03:00
|
|
|
*/
|
|
|
|
int32 CurrentWorkspace(void)
|
2003-01-24 18:19:27 +03:00
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_workspaces();
|
|
|
|
int32 id=-1;
|
|
|
|
|
|
|
|
if(desktop_private::activescreen)
|
|
|
|
id=desktop_private::activescreen->CurrentWorkspace();
|
|
|
|
unlock_workspaces();
|
|
|
|
|
|
|
|
return id;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-24 18:47:06 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the workspace object for the active screen at the given index
|
|
|
|
*/
|
|
|
|
Workspace *WorkspaceAt(int32 index)
|
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_workspaces();
|
|
|
|
Workspace *w=NULL;
|
2003-02-24 18:47:06 +03:00
|
|
|
if(desktop_private::activescreen)
|
2003-03-01 23:25:08 +03:00
|
|
|
w=desktop_private::activescreen->GetWorkspace(index);
|
|
|
|
unlock_workspaces();
|
|
|
|
return w;
|
2003-02-24 18:47:06 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Sets the active workspace
|
|
|
|
\param workspace Index of the workspace to activate
|
|
|
|
|
|
|
|
This function will do nothing if passed an index which does not refer to a valid
|
|
|
|
workspace.
|
|
|
|
*/
|
|
|
|
void SetWorkspace(int32 workspace)
|
2003-01-24 18:19:27 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: SetWorkspace(%ld)\n",workspace+1);
|
|
|
|
#endif
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_workspaces();
|
|
|
|
if(workspace<0 || workspace>(CountWorkspaces()-1))
|
|
|
|
{
|
|
|
|
unlock_workspaces();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Screen *scr;
|
|
|
|
for(int32 i=0;i<desktop_private::screenlist->CountItems();i++)
|
|
|
|
{
|
|
|
|
scr=(Screen*)desktop_private::screenlist->ItemAt(i);
|
|
|
|
if(!scr)
|
|
|
|
continue;
|
|
|
|
scr->SetWorkspace(workspace);
|
|
|
|
}
|
|
|
|
unlock_workspaces();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Sets the active screen. Currently unused.
|
|
|
|
\param id ID of the screen to activate.
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
void SetScreen(screen_id id)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: SetScreen(%ld)\n",id.id);
|
|
|
|
#endif
|
2003-03-01 23:25:08 +03:00
|
|
|
Screen *scr;
|
|
|
|
for(int32 i=0;i<desktop_private::screenlist->CountItems();i++)
|
|
|
|
{
|
|
|
|
scr=(Screen*)desktop_private::screenlist->ItemAt(i);
|
|
|
|
if(!scr)
|
|
|
|
continue;
|
|
|
|
if(scr->GetID().id==id.id)
|
|
|
|
{
|
|
|
|
desktop_private::activescreen->Activate(false);
|
|
|
|
desktop_private::activescreen=scr;
|
|
|
|
desktop_private::activescreen->Activate(true);
|
|
|
|
}
|
|
|
|
}
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the number of screens available. Currently unused.
|
|
|
|
\return the number of screens available.
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
int32 CountScreens(void)
|
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
return desktop_private::screenlist->CountItems();;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the index of the active screen. Currently unused.
|
|
|
|
\return the index of the active screen
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
screen_id ActiveScreen(void)
|
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
return desktop_private::activescreen->GetID();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-07-06 23:48:17 +04:00
|
|
|
/*!
|
|
|
|
\brief Returns the active screen.
|
|
|
|
\return The currently active screen
|
|
|
|
*/
|
|
|
|
Screen *GetActiveScreen(void)
|
|
|
|
{
|
|
|
|
return desktop_private::activescreen;
|
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Obtains the DisplayDriver object used for the specified screen.
|
|
|
|
\param screen ID of the screen to get the DisplayDriver for.
|
|
|
|
\return The DisplayDriver or NULL if not available for that screen ID
|
|
|
|
|
|
|
|
Like the other multiscreen functions, this is unused. Because multiple screens are
|
|
|
|
not utilized, specifying an ID other than B_MAIN_SCREEN_ID will return NULL
|
|
|
|
*/
|
2003-04-05 05:51:35 +04:00
|
|
|
DisplayDriver *GetGfxDriver(screen_id screen)
|
2003-01-24 18:19:27 +03:00
|
|
|
{
|
2003-02-15 18:28:22 +03:00
|
|
|
return (desktop_private::activescreen)?desktop_private::activescreen->GetGfxDriver():NULL;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Sets the video parameters of the specified workspace
|
|
|
|
\param index The workspace to change
|
|
|
|
\param res Resolution constant from GraphicsDefs.h
|
|
|
|
\param stick If false, resolution will revert to its old value on next boot
|
2003-02-20 21:05:35 +03:00
|
|
|
\param screen ID of the screen to change. Currently unused.
|
2003-02-14 14:04:01 +03:00
|
|
|
\return B_OK if successful, B_ERROR if not.
|
|
|
|
|
|
|
|
Because of the lack of outside multimonitor support, the screen ID is ignored for now.
|
|
|
|
*/
|
2003-06-23 06:54:52 +04:00
|
|
|
status_t SetSpace(int32 index, int32 res, screen_id screen, bool stick)
|
2003-01-24 18:19:27 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: SetSpace(%ld,%ld,%s,%ld)\n",index+1,res,
|
|
|
|
stick?"stick":"non-stick",screen.id);
|
|
|
|
#endif
|
2003-02-20 21:05:35 +03:00
|
|
|
desktop_private::workspacelock.Lock();
|
|
|
|
status_t stat=desktop_private::activescreen->SetSpace(index,res,stick);
|
|
|
|
desktop_private::workspacelock.Unlock();
|
|
|
|
return stat;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-20 21:05:35 +03:00
|
|
|
/*!
|
|
|
|
\brief Adds a window to the desktop so that it will be displayed
|
|
|
|
\param win Window to add
|
|
|
|
\param workspace index of the workspace to add the window to
|
|
|
|
\param screen Optional screen specifier. Currently unused.
|
|
|
|
*/
|
2003-04-05 05:51:35 +04:00
|
|
|
void AddWindowToDesktop(ServerWindow *win, int32 workspace, screen_id screen)
|
2003-01-24 18:19:27 +03:00
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: AddWindowToDesktop(%s,%ld,%ld)\n",win?win->GetTitle():"NULL",
|
|
|
|
workspace+1,screen.id);
|
|
|
|
#endif
|
2003-02-20 21:05:35 +03:00
|
|
|
// Workspace() will be non-NULL if it has already been added to the desktop
|
|
|
|
if(!win || win->GetWorkspace())
|
|
|
|
return;
|
|
|
|
|
|
|
|
desktop_private::workspacelock.Lock();
|
|
|
|
desktop_private::layerlock.Lock();
|
|
|
|
|
|
|
|
Workspace *w=desktop_private::activescreen->GetActiveWorkspace();
|
|
|
|
win->SetWorkspace(w);
|
2003-03-23 23:52:37 +03:00
|
|
|
desktop_private::activescreen->AddWindow(win,workspace);
|
2003-02-20 21:05:35 +03:00
|
|
|
|
|
|
|
desktop_private::layerlock.Unlock();
|
|
|
|
desktop_private::workspacelock.Unlock();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-08-31 21:38:34 +04:00
|
|
|
WinBorder* WindowContainsPoint( BPoint pt ){
|
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: WindowContainsPoint(%s,%f,%f)\n",win?win->GetTitle():"NULL",
|
|
|
|
pt.x, pt.y);
|
|
|
|
#endif
|
|
|
|
WinBorder *wb;
|
|
|
|
|
|
|
|
desktop_private::workspacelock.Lock();
|
|
|
|
desktop_private::layerlock.Lock();
|
|
|
|
|
|
|
|
wb = desktop_private::activescreen->GetWindowAt( pt );
|
|
|
|
|
|
|
|
desktop_private::layerlock.Unlock();
|
|
|
|
desktop_private::workspacelock.Unlock();
|
|
|
|
|
|
|
|
return wb;
|
|
|
|
}
|
2003-02-20 21:05:35 +03:00
|
|
|
/*!
|
|
|
|
\brief Removes a window from the desktop
|
|
|
|
\param win Window to remove
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
void RemoveWindowFromDesktop(ServerWindow *win)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: RemoveWindowFromDesktop(%s)\n",win?win->GetTitle():"NULL");
|
|
|
|
#endif
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_workspaces();
|
|
|
|
lock_layers();
|
2003-02-20 21:05:35 +03:00
|
|
|
|
|
|
|
win->SetWorkspace(NULL);
|
2003-03-23 23:52:37 +03:00
|
|
|
desktop_private::activescreen->RemoveWindow(win);
|
2003-02-20 21:05:35 +03:00
|
|
|
|
2003-03-01 23:25:08 +03:00
|
|
|
unlock_layers();
|
|
|
|
unlock_workspaces();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-20 16:13:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the active window in the current workspace of the active screen
|
|
|
|
\return The active window in the current workspace of the active screen
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
ServerWindow *GetActiveWindow(void)
|
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_workspaces();
|
2003-02-20 16:13:01 +03:00
|
|
|
ServerWindow *w=desktop_private::activescreen->ActiveWindow();
|
2003-03-01 23:25:08 +03:00
|
|
|
unlock_workspaces();
|
2003-02-20 16:13:01 +03:00
|
|
|
|
|
|
|
return w;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-20 16:13:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Sets the active window in the current workspace of the active screen
|
|
|
|
\param win The window to activate
|
|
|
|
|
|
|
|
If the window is not in the current workspace of the active screen, this call fails
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
void SetActiveWindow(ServerWindow *win)
|
|
|
|
{
|
2003-04-05 05:51:35 +04:00
|
|
|
#ifdef DEBUG_DESKTOP
|
|
|
|
printf("Desktop: SetActiveWindow(%s)\n",win?win->GetTitle():"NULL");
|
|
|
|
#endif
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_workspaces();
|
2003-02-20 16:13:01 +03:00
|
|
|
Workspace *w=desktop_private::activescreen->GetActiveWorkspace();
|
2003-07-06 23:48:17 +04:00
|
|
|
if(win && win->GetWorkspace()!=w)
|
2003-02-20 16:13:01 +03:00
|
|
|
{
|
|
|
|
desktop_private::workspacelock.Unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerWindow *oldwin=desktop_private::activescreen->ActiveWindow();
|
|
|
|
ActivateWindow(oldwin,win);
|
|
|
|
|
2003-03-01 23:25:08 +03:00
|
|
|
unlock_workspaces();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Returns the root layer for the specified workspace
|
|
|
|
\param workspace Index of the workspace to use
|
2003-02-20 16:13:01 +03:00
|
|
|
\param screen Index of the screen to use. Currently ignored.
|
2003-02-14 14:04:01 +03:00
|
|
|
\return The root layer or NULL if there was an invalid parameter.
|
|
|
|
*/
|
2003-04-05 05:51:35 +04:00
|
|
|
Layer *GetRootLayer(int32 workspace, screen_id screen)
|
2003-01-24 18:19:27 +03:00
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_workspaces();
|
|
|
|
lock_layers();
|
2003-02-20 16:13:01 +03:00
|
|
|
Layer *r=desktop_private::activescreen->GetRootLayer();
|
2003-03-01 23:25:08 +03:00
|
|
|
unlock_layers();
|
|
|
|
unlock_workspaces();
|
2003-02-20 16:13:01 +03:00
|
|
|
|
|
|
|
return r;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Assigns a flattened BMessage to the global drag data.
|
|
|
|
\param size Size of the data buffer
|
|
|
|
\param flattened Flattened BMessage data buffer
|
|
|
|
|
|
|
|
This assigns a BMessage in its flattened state to the internal storage. Only
|
|
|
|
one message can be stored at a time. Once an assignment is made, another cannot
|
|
|
|
be made until the current one is emptied. If additional calls are made while
|
|
|
|
there is a drag message assigned, the function will fail and the new assignment
|
|
|
|
will not be made. Note that this merely passes a pointer around. No copies are
|
|
|
|
made and the caller is responsible for freeing any allocated objects from the heap.
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
void set_drag_message(int32 size, int8 *flattened)
|
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_dragdata();
|
2003-02-20 16:13:01 +03:00
|
|
|
|
|
|
|
if(desktop_private::dragmessage)
|
|
|
|
{
|
|
|
|
desktop_private::draglock.Unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
desktop_private::dragmessage=flattened;
|
|
|
|
desktop_private::dragmessagesize=size;
|
|
|
|
|
2003-03-01 23:25:08 +03:00
|
|
|
unlock_dragdata();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Gets the current drag data
|
|
|
|
\param size Receives the size of the drag data buffer
|
|
|
|
\return the drag data buffer or NULL if size is NULL
|
|
|
|
|
|
|
|
Retrieve the current drag message in use. This function will fail if a NULL pointer
|
|
|
|
is passed to it. Note that this does not free the current drag message from use.
|
|
|
|
The size of the flattened message is stored in the size parameter. Also, note that if
|
|
|
|
there is no message in use, it will return NULL and set size to 0.
|
|
|
|
*/
|
2003-01-24 18:19:27 +03:00
|
|
|
int8 *get_drag_message(int32 *size)
|
|
|
|
{
|
2003-02-20 16:13:01 +03:00
|
|
|
int8 *ptr=NULL;
|
|
|
|
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_dragdata();
|
2003-02-20 16:13:01 +03:00
|
|
|
|
|
|
|
if(desktop_private::dragmessage)
|
|
|
|
{
|
|
|
|
ptr=desktop_private::dragmessage;
|
|
|
|
*size=desktop_private::dragmessagesize;
|
|
|
|
}
|
2003-03-01 23:25:08 +03:00
|
|
|
unlock_dragdata();
|
2003-02-20 16:13:01 +03:00
|
|
|
return ptr;
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-02-14 14:04:01 +03:00
|
|
|
//! Empties current drag data and allows for new data to be assigned
|
2003-01-24 18:19:27 +03:00
|
|
|
void empty_drag_message(void)
|
|
|
|
{
|
2003-03-01 23:25:08 +03:00
|
|
|
lock_dragdata();
|
2003-02-20 16:13:01 +03:00
|
|
|
|
|
|
|
if(desktop_private::dragmessage)
|
|
|
|
delete desktop_private::dragmessage;
|
|
|
|
desktop_private::dragmessage=NULL;
|
|
|
|
desktop_private::dragmessagesize=0;
|
|
|
|
|
2003-03-01 23:25:08 +03:00
|
|
|
unlock_dragdata();
|
2003-01-24 18:19:27 +03:00
|
|
|
}
|
|
|
|
|
2003-07-06 23:48:17 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Thread-safe way of obtaining the current scrollbar behavior info
|
|
|
|
\return Current scroll behavior data
|
|
|
|
*/
|
|
|
|
scroll_bar_info GetScrollBarInfo(void)
|
|
|
|
{
|
|
|
|
scroll_bar_info sbi;
|
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
sbi=desktop_private::scrollbarinfo;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
return sbi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Thread-safe way of setting the current scrollbar behavior info
|
|
|
|
\param info Behavior data structure
|
|
|
|
*/
|
|
|
|
void SetScrollBarInfo(const scroll_bar_info &info)
|
|
|
|
{
|
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
desktop_private::scrollbarinfo=info;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Thread-safe way of obtaining the current menu behavior info
|
|
|
|
\return Current menu behavior data
|
|
|
|
*/
|
|
|
|
menu_info GetMenuInfo(void)
|
|
|
|
{
|
|
|
|
menu_info mi;
|
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
mi=desktop_private::menuinfo;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
return mi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Thread-safe way of setting the current menu behavior info
|
|
|
|
\param info Behavior data structure
|
|
|
|
*/
|
|
|
|
void SetMenuInfo(const menu_info &info)
|
|
|
|
{
|
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
desktop_private::menuinfo=info;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2003-07-10 21:48:04 +04:00
|
|
|
\brief See if the the system is in focus-follows-mouse mode
|
|
|
|
\return True if enabled, false if disabled
|
2003-07-06 23:48:17 +04:00
|
|
|
*/
|
2003-07-10 21:48:04 +04:00
|
|
|
bool GetFFMouse(void)
|
2003-07-06 23:48:17 +04:00
|
|
|
{
|
2003-07-10 21:48:04 +04:00
|
|
|
bool value;
|
2003-07-06 23:48:17 +04:00
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
value=desktop_private::ffm;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2003-07-10 21:48:04 +04:00
|
|
|
\brief Enable or disable focus-follows-mouse for system
|
|
|
|
\param info Enable/Disable flag
|
2003-07-06 23:48:17 +04:00
|
|
|
*/
|
2003-07-10 21:48:04 +04:00
|
|
|
void SetFFMouse(const bool &value)
|
2003-07-06 23:48:17 +04:00
|
|
|
{
|
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
desktop_private::ffm=value;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
}
|
|
|
|
|
2003-07-10 21:48:04 +04:00
|
|
|
/*!
|
|
|
|
\brief Obtain the current focus-follows-mouse behavior
|
|
|
|
\return Current menu behavior data
|
|
|
|
*/
|
|
|
|
mode_mouse GetFFMouseMode(void)
|
|
|
|
{
|
|
|
|
mode_mouse value;
|
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
value=desktop_private::ffm_mode;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Set the focus-follows-mouse behavior
|
|
|
|
\param info Behavior data structure
|
|
|
|
*/
|
|
|
|
void SetFFMouseMode(const mode_mouse &value)
|
|
|
|
{
|
|
|
|
desktop_private::optlock.Lock();
|
|
|
|
desktop_private::ffm_mode=value;
|
|
|
|
desktop_private::optlock.Unlock();
|
|
|
|
}
|
|
|
|
|
2003-07-06 23:48:17 +04:00
|
|
|
/*!
|
|
|
|
\brief Read in settings from R5's workspace settings file in ~/config/settings
|
|
|
|
\return True if successful, false unable to read and parse file.
|
|
|
|
*/
|
|
|
|
bool ReadR5WorkspaceData(void)
|
|
|
|
{
|
|
|
|
//TODO: Add read checks for fscsnf calls
|
|
|
|
|
|
|
|
// Should there be multiple graphics devices, I assume that we'd probably need to loop through
|
|
|
|
// each device and read the workspace data for each. For now, we just assume that there is
|
|
|
|
// just one.
|
|
|
|
|
|
|
|
FILE *file=fopen("/boot/home/config/settings/app_server_settings",B_READ_ONLY);
|
|
|
|
if(!file)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char devicepath[B_PATH_NAME_LENGTH];
|
|
|
|
as_workspace_data wdata;
|
|
|
|
int workspace_count=3;
|
|
|
|
|
|
|
|
Screen *active=GetActiveScreen();
|
|
|
|
|
|
|
|
// read in device
|
|
|
|
// Device <devpath>
|
|
|
|
fscanf(file,"Device %s",devicepath);
|
|
|
|
|
|
|
|
// read workspace count
|
|
|
|
// Workspaces # {
|
|
|
|
fscanf(file,"Workspaces %d {",&workspace_count);
|
|
|
|
|
|
|
|
// read workspace config for all 32 (0-31)
|
|
|
|
|
|
|
|
for(int i=0; i<32;i++)
|
|
|
|
{
|
|
|
|
// Workspace # {
|
|
|
|
fscanf(file,"Workspace %d {",&wdata.index);
|
|
|
|
|
|
|
|
// timing: display_timing struct in Accelerant.h
|
|
|
|
fscanf(file,"timing %lu %u %u %u %u %u %u %u %u %lu",&wdata.timing.pixel_clock,
|
|
|
|
(unsigned int*)&(wdata.timing.h_display),(unsigned int*)&(wdata.timing.h_sync_start),
|
|
|
|
(unsigned int*)&(wdata.timing.h_sync_end),(unsigned int*)&(wdata.timing.h_total),
|
|
|
|
(unsigned int*)&(wdata.timing.v_display),(unsigned int*)&(wdata.timing.v_sync_start),
|
|
|
|
(unsigned int*)&(wdata.timing.v_sync_end),(unsigned int*)&(wdata.timing.v_total),
|
|
|
|
&wdata.timing.flags);
|
|
|
|
|
|
|
|
// colorspace: member of color_space struct, like RGB15, RGB32, etc.
|
|
|
|
fscanf(file,"colorspace %lx",(long*)&wdata.space);
|
|
|
|
|
|
|
|
// virtual width height
|
|
|
|
fscanf(file,"virtual %d %d",&wdata.res_w, &wdata.res_h);
|
|
|
|
|
|
|
|
// flags:
|
|
|
|
fscanf(file,"flags %lx",&wdata.flags);
|
|
|
|
|
|
|
|
// color: RGB hexcode
|
|
|
|
fscanf(file,"color %lx",&wdata.bgcolor);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Create a workspace and add it to the active screen.
|
|
|
|
Workspace *w=new Workspace(&wdata,active);
|
|
|
|
active->AddWorkspace(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
scroll_bar_info sbi;
|
|
|
|
|
|
|
|
// read interface block
|
|
|
|
// Interface {
|
|
|
|
// read scrollbars block
|
|
|
|
// Scrollbars {
|
|
|
|
int bflag;
|
|
|
|
|
|
|
|
// get the four scrollbar values
|
|
|
|
// proportional 1
|
|
|
|
fscanf(file,"proportional %d",&bflag);
|
|
|
|
sbi.proportional=(bflag==1)?true:false;
|
|
|
|
|
|
|
|
// arrows 2
|
|
|
|
fscanf(file,"arrows %d",&bflag);
|
|
|
|
sbi.double_arrows=(bflag==2)?true:false;
|
|
|
|
|
|
|
|
// knobtype 0
|
|
|
|
fscanf(file,"knobtype %ld",&sbi.knob);
|
|
|
|
|
|
|
|
// knobsize 15
|
|
|
|
fscanf(file,"knobsize %ld",&sbi.min_knob_size);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// read options block
|
|
|
|
// Options {
|
|
|
|
|
|
|
|
// get focus-follows-mouse block
|
|
|
|
// ffm #
|
|
|
|
// FFM values:
|
|
|
|
// 0: Disabled
|
|
|
|
// 1: Enabled
|
|
|
|
// 2: Warping
|
|
|
|
// 3: Instant Warping
|
|
|
|
int ffm;
|
|
|
|
fscanf(file,"ffm %d",&ffm);
|
|
|
|
SetFFMouse(ffm);
|
|
|
|
|
|
|
|
// skip decor listing
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Reads in workspace config data using the regular system file
|
|
|
|
\return True if settings were successfully loaded. False if not
|
|
|
|
|
|
|
|
The file's location is defined in ServerConfig.h - SERVER_SETTINGS_DIR/WORKSPACE_SETTINGS_NAME.
|
|
|
|
*/
|
|
|
|
bool ReadOBOSWorkspaceData(void)
|
|
|
|
{
|
|
|
|
//TODO: Implement
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Saves workspace config to SERVER_SETTINGS_DIR/WORKSPACE_SETTINGS_NAME as defined in ServerConfig.h
|
|
|
|
void SaveWorkspaceData(void)
|
|
|
|
{
|
|
|
|
//TODO: Implement
|
|
|
|
}
|