From 47d9ed62d33e873f57fb672e288d0dde706ce354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 27 Jul 2009 17:22:11 +0000 Subject: [PATCH] * Added AS_GET_WORKSPACE_LAYOUT to get the number of columns/rows of the workspaces. * Added shortcuts Ctrl-Alt-{Left|Right|Up|Down} to switch to adjacent workspaces. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31824 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/ServerProtocol.h | 3 +- src/kits/interface/Window.cpp | 61 +++++++++++++++++++++++++++- src/servers/app/ServerApp.cpp | 26 +++++++++++- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index 28edc04838..f1a3b9a81b 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -181,6 +181,7 @@ enum { AS_SET_WORKSPACE_COUNT, AS_CURRENT_WORKSPACE, AS_ACTIVATE_WORKSPACE, + AS_GET_WORKSPACE_LAYOUT, AS_GET_SCROLLBAR_INFO, AS_SET_SCROLLBAR_INFO, AS_GET_MENU_INFO, diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 4848ec7c08..a916a1c3ce 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -61,7 +61,8 @@ // if we ever move this to a public namespace, we should also move the // handling of this message into BApplication -#define _MINIMIZE_ '_WMZ' +#define _MINIMIZE_ '_WMZ' +#define _SWITCH_WORKSPACE_ '_SWS' void do_minimize_team(BRect zoomRect, team_id team, bool zoom); @@ -861,6 +862,47 @@ BWindow::DispatchMessage(BMessage* msg, BHandler* target) break; } + case _SWITCH_WORKSPACE_: + { + int32 deltaX = 0; + msg->FindInt32("delta_x", &deltaX); + int32 deltaY = 0; + msg->FindInt32("delta_y", &deltaY); + + if (deltaX == 0 && deltaY == 0) + break; + + BPrivate::AppServerLink link; + link.StartMessage(AS_GET_WORKSPACE_LAYOUT); + + status_t status; + int32 columns; + int32 rows; + if (link.FlushWithReply(status) != B_OK || status != B_OK) + break; + + link.Read(&columns); + link.Read(&rows); + + int32 current = current_workspace(); + + int32 nextColumn = current % columns + deltaX; + int32 nextRow = current / columns + deltaY; + if (nextColumn >= columns) + nextColumn = columns - 1; + else if (nextColumn < 0) + nextColumn = 0; + if (nextRow >= rows) + nextRow = rows - 1; + else if (nextRow < 0) + nextRow = 0; + + int32 next = nextColumn + nextRow * columns; + if (next != current) + activate_workspace(next); + break; + } + case B_MINIMIZE: { bool minimize; @@ -2575,6 +2617,23 @@ BWindow::_InitData(BRect frame, const char* title, window_look look, AddShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY, new BMessage(B_HIDE_APPLICATION), NULL); + // Workspace modifier keys + BMessage* message = new BMessage(_SWITCH_WORKSPACE_); + message->AddInt32("delta_x", -1); + AddShortcut(B_LEFT_ARROW, B_COMMAND_KEY | B_CONTROL_KEY, message, NULL); + + message = new BMessage(_SWITCH_WORKSPACE_); + message->AddInt32("delta_x", 1); + AddShortcut(B_RIGHT_ARROW, B_COMMAND_KEY | B_CONTROL_KEY, message, NULL); + + message = new BMessage(_SWITCH_WORKSPACE_); + message->AddInt32("delta_y", -1); + AddShortcut(B_UP_ARROW, B_COMMAND_KEY | B_CONTROL_KEY, message, NULL); + + message = new BMessage(_SWITCH_WORKSPACE_); + message->AddInt32("delta_y", 1); + AddShortcut(B_DOWN_ARROW, B_COMMAND_KEY | B_CONTROL_KEY, message, NULL); + // We set the default pulse rate, but we don't start the pulse fPulseRate = 500000; fPulseRunner = NULL; diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index c3bf5e12fd..9ffba9a5e6 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008, Haiku. + * Copyright 2001-2009, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -845,6 +845,30 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) break; } + case AS_GET_WORKSPACE_LAYOUT: + { + // TODO: this is taken from WorkspacesView::_GetGrid() - this is + // only a temporary solution + DesktopSettings settings(fDesktop); + + int32 count = settings.WorkspacesCount(); + 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; + + fLink.StartMessage(B_OK); + fLink.Attach(columns); + fLink.Attach(rows); + fLink.Flush(); + break; + } + case AS_IDLE_TIME: STRACE(("ServerApp %s: idle time\n", Signature()));