* The app_server no longer uses workspace counts internally, but only columns,

and rows.
* set_workspace_count() now uses the logic formerly found in
  WorkspacesView::_GetGrid() to determine the layout.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31958 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-07-30 00:52:21 +00:00
parent 8ccfaa66bb
commit 69f9a367bc
10 changed files with 139 additions and 98 deletions
+1 -1
View File
@@ -178,9 +178,9 @@ enum {
AS_GET_DECORATOR_NAME,
AS_COUNT_WORKSPACES,
AS_SET_WORKSPACE_COUNT,
AS_CURRENT_WORKSPACE,
AS_ACTIVATE_WORKSPACE,
AS_SET_WORKSPACE_LAYOUT,
AS_GET_WORKSPACE_LAYOUT,
AS_GET_SCROLLBAR_INFO,
AS_SET_SCROLLBAR_INFO,
+21 -7
View File
@@ -717,25 +717,39 @@ keyboard_navigation_color()
int32
count_workspaces()
{
int32 count = 1;
int32 columns = 1;
int32 rows = 1;
BPrivate::AppServerLink link;
link.StartMessage(AS_COUNT_WORKSPACES);
link.StartMessage(AS_GET_WORKSPACE_LAYOUT);
status_t status;
if (link.FlushWithReply(status) == B_OK && status == B_OK)
link.Read<int32>(&count);
if (link.FlushWithReply(status) == B_OK && status == B_OK) {
link.Read<int32>(&columns);
link.Read<int32>(&rows);
}
return count;
return columns * rows;
}
void
set_workspace_count(int32 count)
{
int32 squareRoot = (int32)sqrt(count);
int32 rows = 1;
for (int32 i = 2; i <= squareRoot; i++) {
if (count % i == 0)
rows = i;
}
int32 columns = count / rows;
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_WORKSPACE_COUNT);
link.Attach<int32>(count);
link.StartMessage(AS_SET_WORKSPACE_LAYOUT);
link.Attach<int32>(columns);
link.Attach<int32>(rows);
link.Flush();
}
+6 -7
View File
@@ -147,7 +147,7 @@ KeyboardFilter::Filter(BMessage* message, EventTarget** _target,
&& message->FindInt32("key", &key) == B_OK
&& message->FindInt32("modifiers", &modifiers) == B_OK) {
// Check for safe video mode (cmd + ctrl + escape)
if (key == 0x01 && (modifiers & B_COMMAND_KEY) != 0
if (key == 0x01 && (modifiers & B_COMMAND_KEY) != 0
&& (modifiers & B_CONTROL_KEY) != 0) {
system("screenmode --fall-back &");
return B_SKIP_MESSAGE;
@@ -844,15 +844,16 @@ Desktop::StoreWorkspaceConfiguration(int32 index)
status_t
Desktop::SetWorkspacesCount(int32 newCount)
Desktop::SetWorkspacesLayout(int32 newColumns, int32 newRows)
{
int32 newCount = newColumns * newRows;
if (newCount < 1 || newCount > kMaxWorkspaces)
return B_BAD_VALUE;
if (!LockAllWindows())
return B_ERROR;
fSettings->SetWorkspacesCount(newCount);
fSettings->SetWorkspacesLayout(newColumns, newRows);
// either update the workspaces window, or switch to
// the last available workspace - which will update
@@ -895,8 +896,7 @@ Desktop::WorkspaceFrame(int32 index) const
}
/*!
Changes the current workspace to the one specified by \a index.
/*! Changes the current workspace to the one specified by \a index.
*/
void
Desktop::SetWorkspaceAsync(int32 index)
@@ -908,8 +908,7 @@ Desktop::SetWorkspaceAsync(int32 index)
}
/*!
Changes the current workspace to the one specified by \a index.
/*! Changes the current workspace to the one specified by \a index.
You must not hold any window lock when calling this method.
*/
void
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2008, Haiku.
* Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -111,7 +111,7 @@ class Desktop : public MessageLooper, public ScreenOwner {
{ return fCurrentWorkspace; }
Workspace::Private& WorkspaceAt(int32 index)
{ return fWorkspaces[index]; }
status_t SetWorkspacesCount(int32 newCount);
status_t SetWorkspacesLayout(int32 columns, int32 rows);
BRect WorkspaceFrame(int32 index) const;
// Window methods
+66 -17
View File
@@ -70,9 +70,11 @@ DesktopSettingsPrivate::_SetDefaults()
fMenuInfo.click_to_open = true; // always true
fMenuInfo.triggers_always_shown = false;
fWorkspacesCount = 4;
fWorkspacesColumns = 2;
fWorkspacesRows = 2;
memcpy(fShared.colors, BPrivate::kDefaultColors, sizeof(rgb_color) * kNumColors);
memcpy(fShared.colors, BPrivate::kDefaultColors,
sizeof(rgb_color) * kNumColors);
gSubpixelAntialiasing = false;
gDefaultHintingMode = HINTING_MODE_ON;
@@ -117,16 +119,18 @@ DesktopSettingsPrivate::_Load()
BMessage settings;
status = settings.Unflatten(&file);
if (status == B_OK) {
int32 count;
if (settings.FindInt32("count", &count) == B_OK) {
fWorkspacesCount = count;
if (fWorkspacesCount < 1 || fWorkspacesCount > 32)
fWorkspacesCount = 4;
int32 columns;
int32 rows;
if (settings.FindInt32("columns", &columns) == B_OK
&& settings.FindInt32("rows", &rows) == B_OK) {
_ValidateWorkspacesLayout(columns, rows);
fWorkspacesColumns = columns;
fWorkspacesRows = rows;
}
int32 i = 0;
while (i < kMaxWorkspaces
&& settings.FindMessage("workspace", i, &fWorkspaceMessages[i]) == B_OK) {
while (i < kMaxWorkspaces && settings.FindMessage("workspace",
i, &fWorkspaceMessages[i]) == B_OK) {
i++;
}
}
@@ -293,7 +297,8 @@ DesktopSettingsPrivate::Save(uint32 mask)
BPath path(basePath);
if (path.Append("workspaces") == B_OK) {
BMessage settings('asws');
settings.AddInt32("count", fWorkspacesCount);
settings.AddInt32("columns", fWorkspacesColumns);
settings.AddInt32("rows", fWorkspacesRows);
for (int32 i = 0; i < kMaxWorkspaces; i++) {
settings.AddMessage("workspace", &fWorkspaceMessages[i]);
@@ -519,14 +524,12 @@ DesktopSettingsPrivate::ShowAllDraggers() const
void
DesktopSettingsPrivate::SetWorkspacesCount(int32 number)
DesktopSettingsPrivate::SetWorkspacesLayout(int32 columns, int32 rows)
{
if (number < 1)
number = 1;
else if (number > kMaxWorkspaces)
number = kMaxWorkspaces;
_ValidateWorkspacesLayout(columns, rows);
fWorkspacesColumns = columns;
fWorkspacesRows = rows;
fWorkspacesCount = number;
Save(kWorkspacesSettings);
}
@@ -534,7 +537,21 @@ DesktopSettingsPrivate::SetWorkspacesCount(int32 number)
int32
DesktopSettingsPrivate::WorkspacesCount() const
{
return fWorkspacesCount;
return fWorkspacesColumns * fWorkspacesRows;
}
int32
DesktopSettingsPrivate::WorkspacesColumns() const
{
return fWorkspacesColumns;
}
int32
DesktopSettingsPrivate::WorkspacesRows() const
{
return fWorkspacesRows;
}
@@ -644,6 +661,24 @@ DesktopSettingsPrivate::IsSubpixelOrderingRegular() const
return gSubpixelOrderingRGB;
}
void
DesktopSettingsPrivate::_ValidateWorkspacesLayout(int32& columns,
int32& rows) const
{
if (columns < 1)
columns = 1;
if (rows < 1)
rows = 1;
if (columns * rows > kMaxWorkspaces) {
// Revert to defaults in case of invalid settings
columns = 2;
rows = 2;
}
}
// #pragma mark - read access
@@ -722,6 +757,20 @@ DesktopSettings::WorkspacesCount() const
}
int32
DesktopSettings::WorkspacesColumns() const
{
return fSettings->WorkspacesColumns();
}
int32
DesktopSettings::WorkspacesRows() const
{
return fSettings->WorkspacesRows();
}
const BMessage*
DesktopSettings::WorkspacesMessage(int32 index) const
{
+2
View File
@@ -49,6 +49,8 @@ class DesktopSettings {
bool ShowAllDraggers() const;
int32 WorkspacesCount() const;
int32 WorkspacesColumns() const;
int32 WorkspacesRows() const;
const BMessage* WorkspacesMessage(int32 index) const;
rgb_color UIColor(color_which which) const;
+8 -3
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2008, Haiku.
* Copyright 2005-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -48,8 +48,10 @@ public:
void SetShowAllDraggers(bool show);
bool ShowAllDraggers() const;
void SetWorkspacesCount(int32 number);
void SetWorkspacesLayout(int32 columns, int32 rows);
int32 WorkspacesCount() const;
int32 WorkspacesColumns() const;
int32 WorkspacesRows() const;
void SetWorkspacesMessage(int32 index,
BMessage& message);
@@ -73,6 +75,8 @@ private:
void _SetDefaults();
status_t _Load();
status_t _GetPath(BPath& path);
void _ValidateWorkspacesLayout(int32& columns,
int32& rows) const;
ServerFont fPlainFont;
ServerFont fBoldFont;
@@ -82,7 +86,8 @@ private:
menu_info fMenuInfo;
mode_mouse fMouseMode;
bool fShowAllDraggers;
int32 fWorkspacesCount;
int32 fWorkspacesColumns;
int32 fWorkspacesRows;
BMessage fWorkspaceMessages[kMaxWorkspaces];
server_read_only_memory& fShared;
+9 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2007-2008, Haiku Inc. All rights reserved.
* Copyright 2007-2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -18,9 +18,12 @@ string_for_message_code(uint32 code, BString& string)
string = "";
switch (code) {
case AS_GET_DESKTOP: string = "AS_GET_DESKTOP"; break;
case AS_REGISTER_INPUT_SERVER: string = "AS_REGISTER_INPUT_SERVER"; break;
case AS_EVENT_STREAM_CLOSED: string = "AS_EVENT_STREAM_CLOSED"; break;
// Return the exact name for each constant
#define CODE(x) case x: string = #x; break
CODE(AS_GET_DESKTOP);
CODE(AS_REGISTER_INPUT_SERVER);
CODE(AS_EVENT_STREAM_CLOSED);
// Desktop definitions (through the ServerApp, though)
case AS_GET_WINDOW_LIST: string = "AS_GET_WINDOW_LIST"; break;
@@ -160,8 +163,8 @@ string_for_message_code(uint32 code, BString& string)
case AS_COUNT_DECORATORS: string = "AS_COUNT_DECORATORS"; break;
case AS_GET_DECORATOR_NAME: string = "AS_GET_DECORATOR_NAME"; break;
case AS_COUNT_WORKSPACES: string = "AS_COUNT_WORKSPACES"; break;
case AS_SET_WORKSPACE_COUNT: string = "AS_SET_WORKSPACE_COUNT"; break;
CODE(AS_SET_WORKSPACE_LAYOUT);
CODE(AS_GET_WORKSPACE_LAYOUT);
case AS_CURRENT_WORKSPACE: string = "AS_CURRENT_WORKSPACE"; break;
case AS_ACTIVATE_WORKSPACE: string = "AS_ACTIVATE_WORKSPACE"; break;
case AS_GET_SCROLLBAR_INFO: string = "AS_GET_SCROLLBAR_INFO"; break;
+18 -38
View File
@@ -797,29 +797,6 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
break;
}
case AS_COUNT_WORKSPACES:
{
if (fDesktop->LockSingleWindow()) {
DesktopSettings settings(fDesktop);
fLink.StartMessage(B_OK);
fLink.Attach<int32>(settings.WorkspacesCount());
fDesktop->UnlockSingleWindow();
} else
fLink.StartMessage(B_ERROR);
fLink.Flush();
break;
}
case AS_SET_WORKSPACE_COUNT:
{
int32 newCount;
if (link.Read<int32>(&newCount) == B_OK)
fDesktop->SetWorkspacesCount(newCount);
break;
}
case AS_CURRENT_WORKSPACE:
STRACE(("ServerApp %s: get current workspace\n", Signature()));
@@ -845,26 +822,29 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
break;
}
case AS_SET_WORKSPACE_LAYOUT:
{
int32 newColumns;
int32 newRows;
if (link.Read<int32>(&newColumns) == B_OK
&& link.Read<int32>(&newRows) == B_OK)
fDesktop->SetWorkspacesLayout(newColumns, newRows);
break;
}
case AS_GET_WORKSPACE_LAYOUT:
{
// TODO: this is taken from WorkspacesView::_GetGrid() - this is
// only a temporary solution
DesktopSettings settings(fDesktop);
if (fDesktop->LockSingleWindow()) {
DesktopSettings settings(fDesktop);
int32 count = settings.WorkspacesCount();
int32 squareRoot = (int32)sqrt(count);
fLink.StartMessage(B_OK);
fLink.Attach<int32>(settings.WorkspacesColumns());
fLink.Attach<int32>(settings.WorkspacesRows());
int32 rows = 1;
for (int32 i = 2; i <= squareRoot; i++) {
if (count % i == 0)
rows = i;
}
fDesktop->UnlockSingleWindow();
} else
fLink.StartMessage(B_ERROR);
int32 columns = count / rows;
fLink.StartMessage(B_OK);
fLink.Attach<int32>(columns);
fLink.Attach<int32>(rows);
fLink.Flush();
break;
}
+6 -17
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2008, Haiku Inc.
* Copyright 2005-2009, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -62,21 +62,12 @@ WorkspacesView::_GetGrid(int32& columns, int32& rows)
{
DesktopSettings settings(Window()->Desktop());
int32 count = settings.WorkspacesCount();
int32 squareRoot = (int32)sqrt(count);
rows = 1;
for (int32 i = 2; i <= squareRoot; i++) {
if (count % i == 0)
rows = i;
}
columns = count / rows;
columns = settings.WorkspacesColumns();
rows = settings.WorkspacesRows();
}
/*!
\brief Returns the frame of the screen for the specified workspace.
/*! \brief Returns the frame of the screen for the specified workspace.
*/
BRect
WorkspacesView::_ScreenFrame(int32 i)
@@ -85,8 +76,7 @@ WorkspacesView::_ScreenFrame(int32 i)
}
/*!
\brief Returns the frame of the specified workspace within the
/*! \brief Returns the frame of the specified workspace within the
workspaces view.
*/
BRect
@@ -119,8 +109,7 @@ WorkspacesView::_WorkspaceAt(int32 i)
}
/*!
\brief Returns the workspace frame and index of the workspace
/*! \brief Returns the workspace frame and index of the workspace
under \a where.
If, for some reason, there is no workspace located under \where,