From cee4855acbc8402e0ac54f390ec1d4335e32439d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 7 Dec 2011 01:24:09 +0100 Subject: [PATCH] Better calculation of the Deskbar replicant size Patch by RQ from ticket #8156 that accounts for the workspaces layout. --- src/apps/workspaces/Workspaces.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp index 043fd18e3e..72ed59fe4a 100644 --- a/src/apps/workspaces/Workspaces.cpp +++ b/src/apps/workspaces/Workspaces.cpp @@ -962,7 +962,35 @@ WorkspacesApp::ArgvReceived(int32 argc, char **argv) BView* instantiate_deskbar_item() { - return new WorkspacesView(BRect (0, 0, 75, 15), false); + // Calculate the correct size of the Deskbar replicant first + + BScreen screen; + float screenWidth = screen.Frame().Width(); + float screenHeight = screen.Frame().Height(); + float aspectRatio = screenWidth / screenHeight; + uint32 columns, rows; + BPrivate::get_workspaces_layout(&columns, &rows); + + // ╔═╤═╕ A Deskbar replicant can be 16px tall and 129px wide at most. + // ║ │ │ We use 1px for the top and left borders (shown as double) + // ╟─┼─┤ and divide the remainder equally. However, we keep in mind + // ║ │ │ that the actual width and height of each workspace is smaller + // ╙─┴─┘ by 1px, because of bottom/right borders (shown as single). + // When calculating workspace width, we must ensure that the assumed + // actual workspace height is not negative. Zero is OK. + + float height = 16; + float rowHeight = floor((height - 1) / rows); + if(rowHeight < 1) + rowHeight = 1; + + float columnWidth = floor((rowHeight - 1) * aspectRatio) + 1; + + float width = columnWidth * columns + 1; + if(width > 129) + width = 129; + + return new WorkspacesView(BRect (0, 0, width, height), false); }