From 0e02469e9c4fadd8468454e3e194c549b16c442c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Tue, 17 Nov 2009 02:49:43 +0000 Subject: [PATCH] Made Workspaces' initial size and shape depend on screen size, screen proportions and the current layout of one's workspaces. Adjusted Zoom() to be proportional. Also added proportional resizing, which is optional currently, pressing shift while resizing. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34082 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/workspaces/Workspaces.cpp | 76 ++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp index 88f78d7e67..8bd9721a7f 100644 --- a/src/apps/workspaces/Workspaces.cpp +++ b/src/apps/workspaces/Workspaces.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -208,10 +209,34 @@ WorkspacesSettings::WorkspacesSettings() && screen.Frame().left - 5 <= fWindowFrame.left && screen.Frame().top - 5 <= fWindowFrame.top)) { // set to some usable defaults + float screenWidth = screen.Frame().Width(); + float screenHeight = screen.Frame().Height(); + float aspectRatio = screenWidth / screenHeight; + + uint32 columns, rows; + BPrivate::get_workspaces_layout(&columns, &rows); + + // default size of ~1/10 of screen width + float workspaceWidth = screenWidth / 10; + float workspaceHeight = workspaceWidth / aspectRatio; + + float width = floor(workspaceWidth * columns); + float height = floor(workspaceHeight * rows); + + float tabHeight = 20; + // TODO: find tabHeight without being a window + + // shrink to fit more + while (width + 2 * kScreenBorderOffset > screenWidth + || height + 2 * kScreenBorderOffset + tabHeight > screenHeight) { + width = floor(0.95 * width); + height = floor(0.95 * height); + } + fWindowFrame = fScreenFrame; fWindowFrame.OffsetBy(-kScreenBorderOffset, -kScreenBorderOffset); - fWindowFrame.left = fWindowFrame.right - 160; - fWindowFrame.top = fWindowFrame.bottom - 140; + fWindowFrame.left = fWindowFrame.right - width; + fWindowFrame.top = fWindowFrame.bottom - height; } } @@ -602,6 +627,26 @@ WorkspacesWindow::FrameMoved(BPoint origin) void WorkspacesWindow::FrameResized(float width, float height) { + if (!modifiers() & B_SHIFT_KEY) { + BWindow::FrameResized(width, height); + return; + } + + uint32 columns, rows; + BPrivate::get_workspaces_layout(&columns, &rows); + + BScreen screen; + float screenWidth = screen.Frame().Width(); + float screenHeight = screen.Frame().Height(); + + float windowAspectRatio + = (columns * screenWidth) / (rows * screenHeight); + + float newHeight = width / windowAspectRatio; + + if (height != newHeight) + ResizeTo(width, newHeight); + fSettings->SetWindowFrame(Frame()); } @@ -610,9 +655,32 @@ void WorkspacesWindow::Zoom(BPoint origin, float width, float height) { 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); + + float workspaceWidth = screenWidth / 10; + float workspaceHeight = workspaceWidth / aspectRatio; + + width = floor(workspaceWidth * columns); + height = floor(workspaceHeight * rows); + + float tabHeight = Frame().top - DecoratorFrame().top; + + while (width + 2 * kScreenBorderOffset > screenWidth + || height + 2 * kScreenBorderOffset + tabHeight > screenHeight) { + width = floor(0.95 * width); + height = floor(0.95 * height); + } + + ResizeTo(width, height); + origin = screen.Frame().RightBottom(); - origin.x -= kScreenBorderOffset + fSettings->WindowFrame().Width(); - origin.y -= kScreenBorderOffset + fSettings->WindowFrame().Height(); + origin.x -= kScreenBorderOffset + width; + origin.y -= kScreenBorderOffset + height; MoveTo(origin); }