[haiku-commits] haiku: hrev43430 - src/apps/workspaces

  • From: revol@xxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 7 Dec 2011 01:26:14 +0100 (CET)

hrev43430 adds 1 changeset to branch 'master'
old head: 97680106f0ecd95f5f8ca7e1aeb33992fba42ccb
new head: cee4855acbc8402e0ac54f390ec1d4335e32439d

----------------------------------------------------------------------------

cee4855: Better calculation of the Deskbar replicant size
  
  Patch by RQ from ticket #8156 that accounts for the workspaces layout.

                                          [ François Revol <revol@xxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev43430
Commit:      cee4855acbc8402e0ac54f390ec1d4335e32439d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=cee4855
Author:      François Revol <revol@xxxxxxx>
Date:        Wed Dec  7 00:24:09 2011 UTC

Ticket:      https://dev.haiku-os.org/ticket/8156

----------------------------------------------------------------------------

1 files changed, 29 insertions(+), 1 deletions(-)
src/apps/workspaces/Workspaces.cpp |   30 +++++++++++++++++++++++++++++-

----------------------------------------------------------------------------

diff --git a/src/apps/workspaces/Workspaces.cpp 
b/src/apps/workspaces/Workspaces.cpp
index 043fd18..72ed59f 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);
 }
 
 


Other related posts: