Ticket #8156: workspaces-deskbar-correct-width.patch

File workspaces-deskbar-correct-width.patch, 1.5 KB (added by rq, 12 years ago)

Additional patch, which implements smarter calculation of the replicant size.

  • src/apps/workspaces/Workspaces.cpp

    diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp
    index b65cfb1..8d58039 100644
    a b WorkspacesApp::ArgvReceived(int32 argc, char **argv)  
    962962
    963963BView* instantiate_deskbar_item()
    964964{
    965     return new WorkspacesView(BRect (0, 0, 75, 15), false);
     965    // Calculate the correct size of the Deskbar replicant first
     966   
     967    BScreen screen;
     968    float screenWidth = screen.Frame().Width();
     969    float screenHeight = screen.Frame().Height();
     970    float aspectRatio = screenWidth / screenHeight;
     971    uint32 columns, rows;
     972    BPrivate::get_workspaces_layout(&columns, &rows);
     973
     974    // ╔═╤═╕ A Deskbar replicant can be 16px tall and 129px wide at most.
     975    // ║ │ │ We use 1px for the top and left borders (shown as double)
     976    // ╟─┼─┤ and divide the remainder equally. However, we keep in mind
     977    // ║ │ │ that the actual width and height of each workspace is smaller
     978    // ╙─┴─┘ by 1px, because of bottom/right borders (shown as single).
     979    // When calculating workspace width, we must ensure that the assumed
     980    // actual workspace height is not negative. Zero is OK.
     981
     982    float height = 16;
     983    float rowHeight = floor((height - 1) / rows);
     984    if(rowHeight < 1)
     985        rowHeight = 1;
     986
     987    float columnWidth = floor((rowHeight - 1) * aspectRatio) + 1;
     988
     989    float width = columnWidth * columns + 1;
     990    if(width > 129)
     991        width = 129;
     992
     993    return new WorkspacesView(BRect (0, 0, width, height), false);
    966994}
    967995
    968996