1a10cf76eSAxel Dörfler /* 2a10cf76eSAxel Dörfler * Copyright 2001-2005, Haiku. 3a10cf76eSAxel Dörfler * Distributed under the terms of the MIT License. 4a10cf76eSAxel Dörfler * 5a10cf76eSAxel Dörfler * Authors: 6a10cf76eSAxel Dörfler * Rafael Romo 7a10cf76eSAxel Dörfler * Stefano Ceccherini (burton666@libero.it) 8a10cf76eSAxel Dörfler * Andrew Bachmann 9a10cf76eSAxel Dörfler * Thomas Kurschel 10a10cf76eSAxel Dörfler * Axel Dörfler, axeld@pinc-software.de 11a10cf76eSAxel Dörfler */ 12a10cf76eSAxel Dörfler 13a10cf76eSAxel Dörfler 14a10cf76eSAxel Dörfler #include <Alert.h> 15a10cf76eSAxel Dörfler #include <Application.h> 16a10cf76eSAxel Dörfler #include <Box.h> 17a10cf76eSAxel Dörfler #include <Button.h> 18a10cf76eSAxel Dörfler #include <InterfaceDefs.h> 19a10cf76eSAxel Dörfler #include <MenuItem.h> 20a10cf76eSAxel Dörfler #include <MenuField.h> 21a10cf76eSAxel Dörfler #include <Messenger.h> 22a10cf76eSAxel Dörfler #include <PopUpMenu.h> 23a10cf76eSAxel Dörfler #include <Screen.h> 24a10cf76eSAxel Dörfler #include <String.h> 25a10cf76eSAxel Dörfler #include <Window.h> 26a10cf76eSAxel Dörfler 27a10cf76eSAxel Dörfler #include <cstdio> 28a10cf76eSAxel Dörfler #include <cstdlib> 29a10cf76eSAxel Dörfler #include <cstring> 30a10cf76eSAxel Dörfler 31a10cf76eSAxel Dörfler #include "AlertWindow.h" 32a10cf76eSAxel Dörfler #include "Constants.h" 33a10cf76eSAxel Dörfler #include "RefreshWindow.h" 34a10cf76eSAxel Dörfler #include "MonitorView.h" 35a10cf76eSAxel Dörfler #include "ScreenSettings.h" 36a10cf76eSAxel Dörfler #include "ScreenWindow.h" 37a10cf76eSAxel Dörfler #include "Utility.h" 38a10cf76eSAxel Dörfler 39a10cf76eSAxel Dörfler /* Note, this headers defines a *private* interface to the Radeon accelerant. 40a10cf76eSAxel Dörfler * It's a solution that works with the current BeOS interface that Haiku 41a10cf76eSAxel Dörfler * adopted. 42a10cf76eSAxel Dörfler * However, it's not a nice and clean solution. Don't use this header in any 43a10cf76eSAxel Dörfler * application if you can avoid it. No other driver is using this, or should 44a10cf76eSAxel Dörfler * be using this. 45a10cf76eSAxel Dörfler * It will be replaced as soon as we introduce an updated accelerant interface 46a10cf76eSAxel Dörfler * which may even happen before R1 hits the streets. 47a10cf76eSAxel Dörfler */ 48a10cf76eSAxel Dörfler 49a10cf76eSAxel Dörfler #include "multimon.h" // the usual: DANGER WILL, ROBINSON! 50a10cf76eSAxel Dörfler 51a10cf76eSAxel Dörfler 52a10cf76eSAxel Dörfler #define USE_FIXED_REFRESH 53a10cf76eSAxel Dörfler // define to use fixed standard refresh rates 54a10cf76eSAxel Dörfler // undefine to get standard refresh rates from driver 55a10cf76eSAxel Dörfler 56a10cf76eSAxel Dörfler 57a10cf76eSAxel Dörfler // list of officially supported colour spaces 58a10cf76eSAxel Dörfler static const struct { 59a10cf76eSAxel Dörfler color_space space; 60a10cf76eSAxel Dörfler int32 bits_per_pixel; 61a10cf76eSAxel Dörfler const char* label; 62a10cf76eSAxel Dörfler } kColorSpaces[] = { 63a10cf76eSAxel Dörfler { B_CMAP8, 8, "8 Bits/Pixel, 256 Colors" }, 64a10cf76eSAxel Dörfler { B_RGB15, 15, "15 Bits/Pixel, 32768 Colors" }, 65a10cf76eSAxel Dörfler { B_RGB16, 16, "16 Bits/Pixel, 65536 Colors" }, 66a10cf76eSAxel Dörfler { B_RGB32, 32, "32 Bits/Pixel, 16 Million Colors" } 67a10cf76eSAxel Dörfler }; 68a10cf76eSAxel Dörfler static const int32 kColorSpaceCount = sizeof(kColorSpaces) / sizeof(kColorSpaces[0]); 69a10cf76eSAxel Dörfler 70a10cf76eSAxel Dörfler // list of standard refresh rates 71a10cf76eSAxel Dörfler static const int32 kRefreshRates[] = {56, 60, 70, 72, 75}; 72a10cf76eSAxel Dörfler static const int32 kRefreshRateCount = sizeof(kRefreshRates) / sizeof(kRefreshRates[0]); 73a10cf76eSAxel Dörfler 74a10cf76eSAxel Dörfler 75a10cf76eSAxel Dörfler // list of combine modes 76a10cf76eSAxel Dörfler static const struct { 77a10cf76eSAxel Dörfler combine_mode mode; 78a10cf76eSAxel Dörfler const char *name; 79a10cf76eSAxel Dörfler } kCombineModes[] = { 80a10cf76eSAxel Dörfler { kCombineDisable, "disable" }, 81a10cf76eSAxel Dörfler { kCombineHorizontally, "horizontally" }, 82a10cf76eSAxel Dörfler { kCombineVertically, "vertically" } 83a10cf76eSAxel Dörfler }; 84a10cf76eSAxel Dörfler static const int32 kCombineModeCount = sizeof(kCombineModes) / sizeof(kCombineModes[0]); 85a10cf76eSAxel Dörfler 86a10cf76eSAxel Dörfler 87a10cf76eSAxel Dörfler static BString 88a10cf76eSAxel Dörfler tv_standard_to_string(uint32 mode) 89a10cf76eSAxel Dörfler { 90a10cf76eSAxel Dörfler switch (mode) { 91a10cf76eSAxel Dörfler case 0: return "disabled"; 92a10cf76eSAxel Dörfler case 1: return "NTSC"; 93a10cf76eSAxel Dörfler case 2: return "NTSC Japan"; 94a10cf76eSAxel Dörfler case 3: return "PAL BDGHI"; 95a10cf76eSAxel Dörfler case 4: return "PAL M"; 96a10cf76eSAxel Dörfler case 5: return "PAL N"; 97a10cf76eSAxel Dörfler case 6: return "SECAM"; 98a10cf76eSAxel Dörfler case 101: return "NTSC 443"; 99a10cf76eSAxel Dörfler case 102: return "PAL 60"; 100a10cf76eSAxel Dörfler case 103: return "PAL NC"; 101a10cf76eSAxel Dörfler default: 102a10cf76eSAxel Dörfler { 103a10cf76eSAxel Dörfler BString name; 104a10cf76eSAxel Dörfler name << "??? (" << mode << ")"; 105a10cf76eSAxel Dörfler 106a10cf76eSAxel Dörfler return name; 107a10cf76eSAxel Dörfler } 108a10cf76eSAxel Dörfler } 109a10cf76eSAxel Dörfler } 110a10cf76eSAxel Dörfler 111a10cf76eSAxel Dörfler 112a10cf76eSAxel Dörfler static void 113a10cf76eSAxel Dörfler resolution_to_string(screen_mode& mode, BString &string) 114a10cf76eSAxel Dörfler { 115a10cf76eSAxel Dörfler string << mode.width << " x " << mode.height; 116a10cf76eSAxel Dörfler } 117a10cf76eSAxel Dörfler 118a10cf76eSAxel Dörfler 119a10cf76eSAxel Dörfler static void 120a10cf76eSAxel Dörfler refresh_rate_to_string(float refresh, BString &string, 121a10cf76eSAxel Dörfler bool appendUnit = true, bool alwaysWithFraction = false) 122a10cf76eSAxel Dörfler { 123a10cf76eSAxel Dörfler snprintf(string.LockBuffer(32), 32, "%.*g", refresh >= 100.0 ? 4 : 3, refresh); 124a10cf76eSAxel Dörfler string.UnlockBuffer(); 125a10cf76eSAxel Dörfler 126a10cf76eSAxel Dörfler if (appendUnit) 127a10cf76eSAxel Dörfler string << " Hz"; 128a10cf76eSAxel Dörfler } 129a10cf76eSAxel Dörfler 130a10cf76eSAxel Dörfler 13107184a9eSAxel Dörfler static const char* 13207184a9eSAxel Dörfler screen_errors(status_t status) 13307184a9eSAxel Dörfler { 13407184a9eSAxel Dörfler switch (status) { 13507184a9eSAxel Dörfler case B_ENTRY_NOT_FOUND: 13607184a9eSAxel Dörfler return "Unknown Mode"; 13707184a9eSAxel Dörfler // TODO: add more? 13807184a9eSAxel Dörfler 13907184a9eSAxel Dörfler default: 14007184a9eSAxel Dörfler return strerror(status); 14107184a9eSAxel Dörfler } 14207184a9eSAxel Dörfler } 14307184a9eSAxel Dörfler 14407184a9eSAxel Dörfler 145a10cf76eSAxel Dörfler // #pragma mark - 146a10cf76eSAxel Dörfler 147a10cf76eSAxel Dörfler 148a10cf76eSAxel Dörfler ScreenWindow::ScreenWindow(ScreenSettings *Settings) 149a10cf76eSAxel Dörfler : BWindow(Settings->WindowFrame(), "Screen", B_TITLED_WINDOW, 150a10cf76eSAxel Dörfler B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES), 151a10cf76eSAxel Dörfler fScreenMode(this), 152a10cf76eSAxel Dörfler fChangingAllWorkspaces(false) 153a10cf76eSAxel Dörfler { 154a10cf76eSAxel Dörfler BScreen screen(this); 155a10cf76eSAxel Dörfler BRect frame(Bounds()); 156a10cf76eSAxel Dörfler 157a10cf76eSAxel Dörfler fScreenMode.Get(fOriginal); 158a10cf76eSAxel Dörfler fActive = fSelected = fOriginal; 159a10cf76eSAxel Dörfler 160a10cf76eSAxel Dörfler BView *view = new BView(frame, "ScreenView", B_FOLLOW_ALL, B_WILL_DRAW); 161a10cf76eSAxel Dörfler view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 162a10cf76eSAxel Dörfler AddChild(view); 163a10cf76eSAxel Dörfler 164a10cf76eSAxel Dörfler fSettings = Settings; 165a10cf76eSAxel Dörfler 166a10cf76eSAxel Dörfler // box on the left with workspace count and monitor view 167a10cf76eSAxel Dörfler 168a10cf76eSAxel Dörfler BRect screenBoxRect(11.0, 18.0, 153.0, 155.0); 169a10cf76eSAxel Dörfler BBox *screenBox = new BBox(screenBoxRect, "left box"); 170a10cf76eSAxel Dörfler 171a10cf76eSAxel Dörfler fMonitorView = new MonitorView(BRect(20.0, 16.0, 122.0, 93.0), "monitor", 172a10cf76eSAxel Dörfler screen.Frame().Width() + 1, screen.Frame().Height() + 1); 173a10cf76eSAxel Dörfler screenBox->AddChild(fMonitorView); 174a10cf76eSAxel Dörfler 175a10cf76eSAxel Dörfler BPopUpMenu *popUpMenu = new BPopUpMenu("", true, true); 176a10cf76eSAxel Dörfler BMenuField *menuField = new BMenuField(BRect(7.0, 107.0, 135.0, 127.0), 177a10cf76eSAxel Dörfler "WorkspaceCountMenu", "Workspace count:", popUpMenu, true); 178a10cf76eSAxel Dörfler screenBox->AddChild(menuField); 179a10cf76eSAxel Dörfler 180a10cf76eSAxel Dörfler for (int32 count = 1; count <= 32; count++) { 181a10cf76eSAxel Dörfler BString workspaceCount; 182a10cf76eSAxel Dörfler workspaceCount << count; 183a10cf76eSAxel Dörfler 184a10cf76eSAxel Dörfler BMessage *message = new BMessage(POP_WORKSPACE_CHANGED_MSG); 185a10cf76eSAxel Dörfler message->AddInt32("workspace count", count); 186a10cf76eSAxel Dörfler 187a10cf76eSAxel Dörfler popUpMenu->AddItem(new BMenuItem(workspaceCount.String(), 188a10cf76eSAxel Dörfler message)); 189a10cf76eSAxel Dörfler } 190a10cf76eSAxel Dörfler 191a10cf76eSAxel Dörfler BMenuItem *item = popUpMenu->ItemAt(count_workspaces() - 1); 192a10cf76eSAxel Dörfler if (item != NULL) 193a10cf76eSAxel Dörfler item->SetMarked(true); 194a10cf76eSAxel Dörfler 195a10cf76eSAxel Dörfler menuField->SetDivider(91.0); 196a10cf76eSAxel Dörfler view->AddChild(screenBox); 197a10cf76eSAxel Dörfler 198a10cf76eSAxel Dörfler // box on the right with screen resolution, etc. 199a10cf76eSAxel Dörfler 200a10cf76eSAxel Dörfler popUpMenu = new BPopUpMenu("Current Workspace", true, true); 201a10cf76eSAxel Dörfler fAllWorkspacesItem = new BMenuItem("All Workspaces", new BMessage(WORKSPACE_CHECK_MSG)); 202a10cf76eSAxel Dörfler popUpMenu->AddItem(fAllWorkspacesItem); 203a10cf76eSAxel Dörfler item = new BMenuItem("Current Workspace", new BMessage(WORKSPACE_CHECK_MSG)); 204a10cf76eSAxel Dörfler item->SetMarked(true); 205a10cf76eSAxel Dörfler popUpMenu->AddItem(item); 206a10cf76eSAxel Dörfler 207a10cf76eSAxel Dörfler BRect rect(0.0, 0.0, 132.0, 18.0); 208a10cf76eSAxel Dörfler menuField = new BMenuField(rect, "WorkspaceMenu", NULL, popUpMenu, true); 209a10cf76eSAxel Dörfler 210a10cf76eSAxel Dörfler rect.Set(164.0, 7.0, 345.0, 155.0); 211a10cf76eSAxel Dörfler BBox* controlsBox = new BBox(rect); 212a10cf76eSAxel Dörfler controlsBox->SetLabel(menuField); 213a10cf76eSAxel Dörfler 214a10cf76eSAxel Dörfler rect.Set(88.0, 114.0, 200.0, 150.0); 215a10cf76eSAxel Dörfler fApplyButton = new BButton(rect, "ApplyButton", "Apply", 216a10cf76eSAxel Dörfler new BMessage(BUTTON_APPLY_MSG)); 217a10cf76eSAxel Dörfler fApplyButton->ResizeToPreferred(); 218a10cf76eSAxel Dörfler fApplyButton->SetEnabled(false); 219a10cf76eSAxel Dörfler 220a10cf76eSAxel Dörfler controlsBox->AddChild(fApplyButton); 221a10cf76eSAxel Dörfler 222a10cf76eSAxel Dörfler fResolutionMenu = new BPopUpMenu("resolution", true, true); 223a10cf76eSAxel Dörfler 224a10cf76eSAxel Dörfler uint16 previousWidth = 0, previousHeight = 0; 225a10cf76eSAxel Dörfler for (int32 i = 0; i < fScreenMode.CountModes(); i++) { 226a10cf76eSAxel Dörfler screen_mode mode = fScreenMode.ModeAt(i); 227a10cf76eSAxel Dörfler 228a10cf76eSAxel Dörfler if (mode.width == previousWidth && mode.height == previousHeight) 229a10cf76eSAxel Dörfler continue; 230a10cf76eSAxel Dörfler 231a10cf76eSAxel Dörfler previousWidth = mode.width; 232a10cf76eSAxel Dörfler previousHeight = mode.height; 233a10cf76eSAxel Dörfler 234a10cf76eSAxel Dörfler BMessage *message = new BMessage(POP_RESOLUTION_MSG); 235a10cf76eSAxel Dörfler message->AddInt32("width", mode.width); 236a10cf76eSAxel Dörfler message->AddInt32("height", mode.height); 237a10cf76eSAxel Dörfler 238a10cf76eSAxel Dörfler BString name; 239a10cf76eSAxel Dörfler name << mode.width << " x " << mode.height; 240a10cf76eSAxel Dörfler 241a10cf76eSAxel Dörfler fResolutionMenu->AddItem(new BMenuItem(name.String(), message)); 242a10cf76eSAxel Dörfler } 243a10cf76eSAxel Dörfler 244a10cf76eSAxel Dörfler rect.Set(33.0, 30.0, 171.0, 48.0); 245a10cf76eSAxel Dörfler fResolutionField = new BMenuField(rect, "ResolutionMenu", "Resolution:", 246a10cf76eSAxel Dörfler fResolutionMenu, true); 247a10cf76eSAxel Dörfler fResolutionField->SetDivider(55.0); 248a10cf76eSAxel Dörfler controlsBox->AddChild(fResolutionField); 249a10cf76eSAxel Dörfler 250a10cf76eSAxel Dörfler fColorsMenu = new BPopUpMenu("colors", true, true); 251a10cf76eSAxel Dörfler 252a10cf76eSAxel Dörfler for (int32 i = 0; i < kColorSpaceCount; i++) { 253a10cf76eSAxel Dörfler BMessage *message = new BMessage(POP_COLORS_MSG); 254a10cf76eSAxel Dörfler message->AddInt32("bits_per_pixel", kColorSpaces[i].bits_per_pixel); 255a10cf76eSAxel Dörfler message->AddInt32("space", kColorSpaces[i].space); 256a10cf76eSAxel Dörfler 257a10cf76eSAxel Dörfler fColorsMenu->AddItem(new BMenuItem(kColorSpaces[i].label, message)); 258a10cf76eSAxel Dörfler } 259a10cf76eSAxel Dörfler 260a10cf76eSAxel Dörfler rect.Set(50.0, 58.0, 171.0, 76.0); 261a10cf76eSAxel Dörfler fColorsField = new BMenuField(rect, "ColorsMenu", "Colors:", fColorsMenu, true); 262a10cf76eSAxel Dörfler fColorsField->SetDivider(38.0); 263a10cf76eSAxel Dörfler controlsBox->AddChild(fColorsField); 264a10cf76eSAxel Dörfler 265a10cf76eSAxel Dörfler fRefreshMenu = new BPopUpMenu("refresh rate", true, true); 266a10cf76eSAxel Dörfler 267a10cf76eSAxel Dörfler #ifdef USE_FIXED_REFRESH 268a10cf76eSAxel Dörfler for (int32 i = 0; i < kRefreshRateCount; ++i) { 269a10cf76eSAxel Dörfler BString name; 270a10cf76eSAxel Dörfler name << kRefreshRates[i] << " Hz"; 271a10cf76eSAxel Dörfler 272a10cf76eSAxel Dörfler BMessage *message = new BMessage(POP_REFRESH_MSG); 273a10cf76eSAxel Dörfler message->AddFloat("refresh", kRefreshRates[i]); 274a10cf76eSAxel Dörfler 275a10cf76eSAxel Dörfler fRefreshMenu->AddItem(new BMenuItem(name.String(), message)); 276a10cf76eSAxel Dörfler } 277a10cf76eSAxel Dörfler #endif 278a10cf76eSAxel Dörfler 279a10cf76eSAxel Dörfler BMessage *message = new BMessage(POP_OTHER_REFRESH_MSG); 280a10cf76eSAxel Dörfler 281a10cf76eSAxel Dörfler fOtherRefresh = new BMenuItem("Other" B_UTF8_ELLIPSIS, message); 282a10cf76eSAxel Dörfler fRefreshMenu->AddItem(fOtherRefresh); 283a10cf76eSAxel Dörfler 284a10cf76eSAxel Dörfler rect.Set(19.0, 86.0, 171.0, 104.0); 285a10cf76eSAxel Dörfler fRefreshField = new BMenuField(rect, "RefreshMenu", "Refresh Rate:", fRefreshMenu, true); 286a10cf76eSAxel Dörfler fRefreshField->SetDivider(69.0); 287a10cf76eSAxel Dörfler controlsBox->AddChild(fRefreshField); 288a10cf76eSAxel Dörfler 289a10cf76eSAxel Dörfler view->AddChild(controlsBox); 290a10cf76eSAxel Dörfler 291a10cf76eSAxel Dörfler // enlarged area for multi-monitor settings 292a10cf76eSAxel Dörfler { 293a10cf76eSAxel Dörfler bool dummy; 294a10cf76eSAxel Dörfler uint32 dummy32; 295a10cf76eSAxel Dörfler bool multiMonSupport; 296a10cf76eSAxel Dörfler bool useLaptopPanelSupport; 297a10cf76eSAxel Dörfler bool tvStandardSupport; 298a10cf76eSAxel Dörfler 299a10cf76eSAxel Dörfler multiMonSupport = TestMultiMonSupport(&screen) == B_OK; 300a10cf76eSAxel Dörfler useLaptopPanelSupport = GetUseLaptopPanel(&screen, &dummy) == B_OK; 301a10cf76eSAxel Dörfler tvStandardSupport = GetTVStandard(&screen, &dummy32) == B_OK; 302a10cf76eSAxel Dörfler 303a10cf76eSAxel Dörfler // even if there is no support, we still create all controls 304a10cf76eSAxel Dörfler // to make sure we don't access NULL pointers later on 305a10cf76eSAxel Dörfler if (multiMonSupport) { 306a10cf76eSAxel Dörfler fApplyButton->MoveTo(275, 114); 307a10cf76eSAxel Dörfler controlsBox->ResizeTo(366, 148); 308a10cf76eSAxel Dörfler ResizeTo(556, 202); 309a10cf76eSAxel Dörfler } 310a10cf76eSAxel Dörfler 311a10cf76eSAxel Dörfler fCombineMenu = new BPopUpMenu("CombineDisplays", true, true); 312a10cf76eSAxel Dörfler 313a10cf76eSAxel Dörfler for (int32 i = 0; i < kCombineModeCount; i++) { 314a10cf76eSAxel Dörfler message = new BMessage(POP_COMBINE_DISPLAYS_MSG); 315a10cf76eSAxel Dörfler message->AddInt32("mode", kCombineModes[i].mode); 316a10cf76eSAxel Dörfler 317a10cf76eSAxel Dörfler fCombineMenu->AddItem(new BMenuItem(kCombineModes[i].name, message)); 318a10cf76eSAxel Dörfler } 319a10cf76eSAxel Dörfler 320a10cf76eSAxel Dörfler rect.Set(185, 30, 356, 48); 321a10cf76eSAxel Dörfler BMenuField* menuField = new BMenuField(rect, "CombineMenu", 322a10cf76eSAxel Dörfler "Combine Displays:", fCombineMenu, true); 323a10cf76eSAxel Dörfler menuField->SetDivider(90); 324a10cf76eSAxel Dörfler controlsBox->AddChild(menuField); 325a10cf76eSAxel Dörfler 326a10cf76eSAxel Dörfler if (!multiMonSupport) 327a10cf76eSAxel Dörfler menuField->Hide(); 328a10cf76eSAxel Dörfler 329a10cf76eSAxel Dörfler fSwapDisplaysMenu = new BPopUpMenu("SwapDisplays", true, true); 330a10cf76eSAxel Dörfler 331a10cf76eSAxel Dörfler // !order is important - we rely that boolean value == idx 332a10cf76eSAxel Dörfler message = new BMessage(POP_SWAP_DISPLAYS_MSG); 333a10cf76eSAxel Dörfler message->AddBool("swap", false); 334a10cf76eSAxel Dörfler fSwapDisplaysMenu->AddItem(new BMenuItem("no", message)); 335a10cf76eSAxel Dörfler 336a10cf76eSAxel Dörfler message = new BMessage(POP_SWAP_DISPLAYS_MSG); 337a10cf76eSAxel Dörfler message->AddBool("swap", true); 338a10cf76eSAxel Dörfler fSwapDisplaysMenu->AddItem(new BMenuItem("yes", message)); 339a10cf76eSAxel Dörfler 340a10cf76eSAxel Dörfler rect.Set(199, 58, 356, 76); 341a10cf76eSAxel Dörfler menuField = new BMenuField(rect, "SwapMenu", "Swap Displays:", 342a10cf76eSAxel Dörfler fSwapDisplaysMenu, true); 343a10cf76eSAxel Dörfler menuField->SetDivider(76); 344a10cf76eSAxel Dörfler 345a10cf76eSAxel Dörfler controlsBox->AddChild(menuField); 346a10cf76eSAxel Dörfler if (!multiMonSupport) 347a10cf76eSAxel Dörfler menuField->Hide(); 348a10cf76eSAxel Dörfler 349a10cf76eSAxel Dörfler fUseLaptopPanelMenu = new BPopUpMenu("UseLaptopPanel", true, true); 350a10cf76eSAxel Dörfler 351a10cf76eSAxel Dörfler // !order is important - we rely that boolean value == idx 352a10cf76eSAxel Dörfler message = new BMessage(POP_USE_LAPTOP_PANEL_MSG); 353a10cf76eSAxel Dörfler message->AddBool("use", false); 354a10cf76eSAxel Dörfler fUseLaptopPanelMenu->AddItem(new BMenuItem("if needed", message)); 355a10cf76eSAxel Dörfler 356a10cf76eSAxel Dörfler message = new BMessage(POP_USE_LAPTOP_PANEL_MSG); 357a10cf76eSAxel Dörfler message->AddBool("use", true); 358a10cf76eSAxel Dörfler fUseLaptopPanelMenu->AddItem(new BMenuItem("always", message)); 359a10cf76eSAxel Dörfler 360a10cf76eSAxel Dörfler rect.Set(184, 86, 356, 104); 361a10cf76eSAxel Dörfler menuField = new BMenuField(rect, "UseLaptopPanel", "Use Laptop Panel:", 362a10cf76eSAxel Dörfler fUseLaptopPanelMenu, true); 363a10cf76eSAxel Dörfler menuField->SetDivider(91); 364a10cf76eSAxel Dörfler 365a10cf76eSAxel Dörfler controlsBox->AddChild(menuField); 366a10cf76eSAxel Dörfler if (!useLaptopPanelSupport) 367a10cf76eSAxel Dörfler menuField->Hide(); 368a10cf76eSAxel Dörfler 369a10cf76eSAxel Dörfler fTVStandardMenu = new BPopUpMenu("TVStandard", true, true); 370a10cf76eSAxel Dörfler 371a10cf76eSAxel Dörfler // arbitrary limit 372a10cf76eSAxel Dörfler uint32 i; 373a10cf76eSAxel Dörfler for (i = 0; i < 100; ++i) { 374a10cf76eSAxel Dörfler uint32 mode; 375a10cf76eSAxel Dörfler 376a10cf76eSAxel Dörfler if (GetNthSupportedTVStandard(&screen, i, &mode) != B_OK) 377a10cf76eSAxel Dörfler break; 378a10cf76eSAxel Dörfler 379a10cf76eSAxel Dörfler BString name = tv_standard_to_string(mode); 380a10cf76eSAxel Dörfler 381a10cf76eSAxel Dörfler message = new BMessage(POP_TV_STANDARD_MSG); 382a10cf76eSAxel Dörfler message->AddInt32("tv_standard", mode); 383a10cf76eSAxel Dörfler 384a10cf76eSAxel Dörfler fTVStandardMenu->AddItem(new BMenuItem(name.String(), message)); 385a10cf76eSAxel Dörfler } 386a10cf76eSAxel Dörfler 387a10cf76eSAxel Dörfler rect.Set(15, 114, 171, 132); 388a10cf76eSAxel Dörfler menuField = new BMenuField(rect, "tv standard", "Video Format:", 389a10cf76eSAxel Dörfler fTVStandardMenu, true); 390a10cf76eSAxel Dörfler menuField->SetDivider(73); 391a10cf76eSAxel Dörfler 392a10cf76eSAxel Dörfler if (!tvStandardSupport || i == 0) 393a10cf76eSAxel Dörfler menuField->Hide(); 394a10cf76eSAxel Dörfler 395a10cf76eSAxel Dörfler controlsBox->AddChild(menuField); 396a10cf76eSAxel Dörfler } 397a10cf76eSAxel Dörfler 398a10cf76eSAxel Dörfler rect.Set(10.0, 167, 100.0, 200.0); 399a10cf76eSAxel Dörfler fDefaultsButton = new BButton(rect, "DefaultsButton", "Defaults", 400a10cf76eSAxel Dörfler new BMessage(BUTTON_DEFAULTS_MSG)); 401a10cf76eSAxel Dörfler fDefaultsButton->ResizeToPreferred(); 402a10cf76eSAxel Dörfler view->AddChild(fDefaultsButton); 403a10cf76eSAxel Dörfler 404a10cf76eSAxel Dörfler rect.Set(95.0, 167, 160.0, 200.0); 405a10cf76eSAxel Dörfler fRevertButton = new BButton(rect, "RevertButton", "Revert", 406a10cf76eSAxel Dörfler new BMessage(BUTTON_REVERT_MSG)); 407a10cf76eSAxel Dörfler fRevertButton->ResizeToPreferred(); 408a10cf76eSAxel Dörfler fRevertButton->SetEnabled(false); 409a10cf76eSAxel Dörfler view->AddChild(fRevertButton); 410a10cf76eSAxel Dörfler 411a10cf76eSAxel Dörfler UpdateControls(); 412a10cf76eSAxel Dörfler } 413a10cf76eSAxel Dörfler 414a10cf76eSAxel Dörfler 415a10cf76eSAxel Dörfler ScreenWindow::~ScreenWindow() 416a10cf76eSAxel Dörfler { 417a10cf76eSAxel Dörfler delete fSettings; 418a10cf76eSAxel Dörfler } 419a10cf76eSAxel Dörfler 420a10cf76eSAxel Dörfler 421a10cf76eSAxel Dörfler bool 422a10cf76eSAxel Dörfler ScreenWindow::QuitRequested() 423a10cf76eSAxel Dörfler { 424a10cf76eSAxel Dörfler fSettings->SetWindowFrame(Frame()); 425a10cf76eSAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED); 426a10cf76eSAxel Dörfler 427a10cf76eSAxel Dörfler return BWindow::QuitRequested(); 428a10cf76eSAxel Dörfler } 429a10cf76eSAxel Dörfler 430a10cf76eSAxel Dörfler 431a10cf76eSAxel Dörfler /** update resolution list according to combine mode 432a10cf76eSAxel Dörfler * (some resolution may not be combinable due to memory restrictions) 433a10cf76eSAxel Dörfler */ 434a10cf76eSAxel Dörfler 435a10cf76eSAxel Dörfler void 436a10cf76eSAxel Dörfler ScreenWindow::CheckResolutionMenu() 437a10cf76eSAxel Dörfler { 438a10cf76eSAxel Dörfler for (int32 i = 0; i < fResolutionMenu->CountItems(); i++) 439a10cf76eSAxel Dörfler fResolutionMenu->ItemAt(i)->SetEnabled(false); 440a10cf76eSAxel Dörfler 441a10cf76eSAxel Dörfler for (int32 i = 0; i < fScreenMode.CountModes(); i++) { 442a10cf76eSAxel Dörfler screen_mode mode = fScreenMode.ModeAt(i); 443a10cf76eSAxel Dörfler if (mode.combine != fSelected.combine) 444a10cf76eSAxel Dörfler continue; 445a10cf76eSAxel Dörfler 446a10cf76eSAxel Dörfler BString name; 447a10cf76eSAxel Dörfler name << mode.width << " x " << mode.height; 448a10cf76eSAxel Dörfler 449a10cf76eSAxel Dörfler BMenuItem *item = fResolutionMenu->FindItem(name.String()); 450a10cf76eSAxel Dörfler if (item != NULL) 451a10cf76eSAxel Dörfler item->SetEnabled(true); 452a10cf76eSAxel Dörfler } 453a10cf76eSAxel Dörfler } 454a10cf76eSAxel Dörfler 455a10cf76eSAxel Dörfler 456a10cf76eSAxel Dörfler /** update color and refresh options according to current mode 457a10cf76eSAxel Dörfler * (a color space is made active if there is any mode with 458a10cf76eSAxel Dörfler * given resolution and this colour space; same applies for 459a10cf76eSAxel Dörfler * refresh rate, though "Other…" is always possible) 460a10cf76eSAxel Dörfler */ 461a10cf76eSAxel Dörfler 462a10cf76eSAxel Dörfler void 463a10cf76eSAxel Dörfler ScreenWindow::CheckColorMenu() 464a10cf76eSAxel Dörfler { 465a10cf76eSAxel Dörfler for (int32 i = 0; i < kColorSpaceCount; i++) { 466a10cf76eSAxel Dörfler bool supported = false; 467a10cf76eSAxel Dörfler 468a10cf76eSAxel Dörfler for (int32 j = 0; j < fScreenMode.CountModes(); j++) { 469a10cf76eSAxel Dörfler screen_mode mode = fScreenMode.ModeAt(j); 470a10cf76eSAxel Dörfler 471a10cf76eSAxel Dörfler if (fSelected.width == mode.width 472a10cf76eSAxel Dörfler && fSelected.height == mode.height 473a10cf76eSAxel Dörfler && kColorSpaces[i].space == mode.space 474a10cf76eSAxel Dörfler && fSelected.combine == mode.combine) { 475a10cf76eSAxel Dörfler supported = true; 476a10cf76eSAxel Dörfler break; 477a10cf76eSAxel Dörfler } 478a10cf76eSAxel Dörfler } 479a10cf76eSAxel Dörfler 480a10cf76eSAxel Dörfler BMenuItem* item = fColorsMenu->ItemAt(i); 481a10cf76eSAxel Dörfler if (item) 482a10cf76eSAxel Dörfler item->SetEnabled(supported); 483a10cf76eSAxel Dörfler } 484a10cf76eSAxel Dörfler } 485a10cf76eSAxel Dörfler 486a10cf76eSAxel Dörfler 487a10cf76eSAxel Dörfler /** Enable/disable refresh options according to current mode. 488a10cf76eSAxel Dörfler * Only needed when USE_FIXED_REFRESH is not defined. 489a10cf76eSAxel Dörfler */ 490a10cf76eSAxel Dörfler 491a10cf76eSAxel Dörfler void 492a10cf76eSAxel Dörfler ScreenWindow::CheckRefreshMenu() 493a10cf76eSAxel Dörfler { 494a10cf76eSAxel Dörfler #ifndef USE_FIXED_REFRESH 495a10cf76eSAxel Dörfler // ToDo: does currently not compile! 496a10cf76eSAxel Dörfler for (int32 i = fRefreshMenu->CountItems() - 2; i >= 0; --i) { 497a10cf76eSAxel Dörfler delete fRefreshMenu->RemoveItem(i); 498a10cf76eSAxel Dörfler } 499a10cf76eSAxel Dörfler 500a10cf76eSAxel Dörfler for (int32 i = 0; i < fModeListCount; ++i) { 501a10cf76eSAxel Dörfler if (virtualWidth == fModeList[i].virtual_width 502a10cf76eSAxel Dörfler && virtualHeight == fModeList[i].virtual_height 503a10cf76eSAxel Dörfler && combine == get_combine_mode(&fModeList[i])) { 504a10cf76eSAxel Dörfler BString name; 505a10cf76eSAxel Dörfler BMenuItem *item; 506a10cf76eSAxel Dörfler 507a10cf76eSAxel Dörfler int32 refresh10 = get_refresh10(fModeList[i]); 508a10cf76eSAxel Dörfler refresh10_to_string(name, refresh10); 509a10cf76eSAxel Dörfler 510a10cf76eSAxel Dörfler item = fRefreshMenu->FindItem(name.String()); 511a10cf76eSAxel Dörfler if (item == NULL) { 512a10cf76eSAxel Dörfler BMessage *msg = new BMessage(POP_REFRESH_MSG); 513a10cf76eSAxel Dörfler msg->AddFloat("refresh", refresh); 514a10cf76eSAxel Dörfler 515a10cf76eSAxel Dörfler fRefreshMenu->AddItem(new BMenuItem(name.String(), msg), 516a10cf76eSAxel Dörfler fRefreshMenu->CountItems() - 1); 517a10cf76eSAxel Dörfler } 518a10cf76eSAxel Dörfler } 519a10cf76eSAxel Dörfler } 520a10cf76eSAxel Dörfler #endif 521a10cf76eSAxel Dörfler 522a10cf76eSAxel Dörfler // TBD: some drivers lack many refresh rates; still, they 523a10cf76eSAxel Dörfler // can be used by generating the mode manually 524a10cf76eSAxel Dörfler /* 525a10cf76eSAxel Dörfler for( i = 0; i < sizeof( refresh_list ) / sizeof( refresh_list[0] ); ++i ) { 526a10cf76eSAxel Dörfler BMenuItem *item; 527a10cf76eSAxel Dörfler bool supported = false; 528a10cf76eSAxel Dörfler 529a10cf76eSAxel Dörfler for( j = 0; j < fModeListCount; ++j ) { 530a10cf76eSAxel Dörfler if( width == fModeList[j].virtual_width && 531a10cf76eSAxel Dörfler height == fModeList[j].virtual_height && 532a10cf76eSAxel Dörfler refresh_list[i].refresh * 10 == getModeRefresh10( &fModeList[j] )) 533a10cf76eSAxel Dörfler { 534a10cf76eSAxel Dörfler supported = true; 535a10cf76eSAxel Dörfler break; 536a10cf76eSAxel Dörfler } 537a10cf76eSAxel Dörfler } 538a10cf76eSAxel Dörfler 539a10cf76eSAxel Dörfler item = fRefreshMenu->ItemAt( i ); 540a10cf76eSAxel Dörfler if( item ) 541a10cf76eSAxel Dörfler item->SetEnabled( supported ); 542a10cf76eSAxel Dörfler } 543a10cf76eSAxel Dörfler */ 544a10cf76eSAxel Dörfler } 545a10cf76eSAxel Dörfler 546a10cf76eSAxel Dörfler 547a10cf76eSAxel Dörfler /** activate appropriate menu item according to selected refresh rate */ 548a10cf76eSAxel Dörfler 549a10cf76eSAxel Dörfler void 550a10cf76eSAxel Dörfler ScreenWindow::UpdateRefreshControl() 551a10cf76eSAxel Dörfler { 552a10cf76eSAxel Dörfler BString string; 553a10cf76eSAxel Dörfler refresh_rate_to_string(fSelected.refresh, string); 554a10cf76eSAxel Dörfler 555a10cf76eSAxel Dörfler BMenuItem* item = fRefreshMenu->FindItem(string.String()); 556a10cf76eSAxel Dörfler if (item) { 557a10cf76eSAxel Dörfler if (!item->IsMarked()) 558a10cf76eSAxel Dörfler item->SetMarked(true); 559a10cf76eSAxel Dörfler // "Other…" items only contains a refresh rate when active 560a10cf76eSAxel Dörfler fOtherRefresh->SetLabel("Other…"); 561a10cf76eSAxel Dörfler return; 562a10cf76eSAxel Dörfler } 563a10cf76eSAxel Dörfler 564a10cf76eSAxel Dörfler // this is a non-standard refresh rate 565a10cf76eSAxel Dörfler 566a10cf76eSAxel Dörfler fOtherRefresh->Message()->ReplaceFloat("refresh", fSelected.refresh); 567a10cf76eSAxel Dörfler fOtherRefresh->SetMarked(true); 568a10cf76eSAxel Dörfler 569a10cf76eSAxel Dörfler fRefreshMenu->Superitem()->SetLabel(string.String()); 570a10cf76eSAxel Dörfler 571a10cf76eSAxel Dörfler string.Append("/Other" B_UTF8_ELLIPSIS); 572a10cf76eSAxel Dörfler fOtherRefresh->SetLabel(string.String()); 573a10cf76eSAxel Dörfler } 574a10cf76eSAxel Dörfler 575a10cf76eSAxel Dörfler 576a10cf76eSAxel Dörfler void 577a10cf76eSAxel Dörfler ScreenWindow::UpdateMonitorView() 578a10cf76eSAxel Dörfler { 579a10cf76eSAxel Dörfler BMessage updateMessage(UPDATE_DESKTOP_MSG); 580a10cf76eSAxel Dörfler updateMessage.AddInt32("width", fSelected.width); 581a10cf76eSAxel Dörfler updateMessage.AddInt32("height", fSelected.height); 582a10cf76eSAxel Dörfler 583a10cf76eSAxel Dörfler PostMessage(&updateMessage, fMonitorView); 584a10cf76eSAxel Dörfler } 585a10cf76eSAxel Dörfler 586a10cf76eSAxel Dörfler 587a10cf76eSAxel Dörfler void 588a10cf76eSAxel Dörfler ScreenWindow::UpdateControls() 589a10cf76eSAxel Dörfler { 590a10cf76eSAxel Dörfler BMenuItem* item = fSwapDisplaysMenu->ItemAt((int32)fSelected.swap_displays); 591a10cf76eSAxel Dörfler if (item && !item->IsMarked()) 592a10cf76eSAxel Dörfler item->SetMarked(true); 593a10cf76eSAxel Dörfler 594a10cf76eSAxel Dörfler item = fUseLaptopPanelMenu->ItemAt((int32)fSelected.use_laptop_panel); 595a10cf76eSAxel Dörfler if (item && !item->IsMarked()) 596a10cf76eSAxel Dörfler item->SetMarked(true); 597a10cf76eSAxel Dörfler 598a10cf76eSAxel Dörfler for (int32 i = 0; i < fTVStandardMenu->CountItems(); i++) { 599a10cf76eSAxel Dörfler item = fTVStandardMenu->ItemAt(i); 600a10cf76eSAxel Dörfler 601a10cf76eSAxel Dörfler uint32 tvStandard; 602a10cf76eSAxel Dörfler item->Message()->FindInt32("tv_standard", (int32 *)&tvStandard); 603a10cf76eSAxel Dörfler if (tvStandard == fSelected.tv_standard) { 604a10cf76eSAxel Dörfler if (!item->IsMarked()) 605a10cf76eSAxel Dörfler item->SetMarked(true); 606a10cf76eSAxel Dörfler break; 607a10cf76eSAxel Dörfler } 608a10cf76eSAxel Dörfler } 609a10cf76eSAxel Dörfler 610a10cf76eSAxel Dörfler CheckResolutionMenu(); 611a10cf76eSAxel Dörfler CheckColorMenu(); 612a10cf76eSAxel Dörfler CheckRefreshMenu(); 613a10cf76eSAxel Dörfler 614a10cf76eSAxel Dörfler BString string; 615a10cf76eSAxel Dörfler resolution_to_string(fSelected, string); 616a10cf76eSAxel Dörfler item = fResolutionMenu->FindItem(string.String()); 617a10cf76eSAxel Dörfler 618a10cf76eSAxel Dörfler if (item != NULL) { 619a10cf76eSAxel Dörfler if (!item->IsMarked()) 620a10cf76eSAxel Dörfler item->SetMarked(true); 621a10cf76eSAxel Dörfler } else { 622a10cf76eSAxel Dörfler // this is bad luck - if mode has been set via screen references, 623a10cf76eSAxel Dörfler // this case cannot occur; there are three possible solutions: 624a10cf76eSAxel Dörfler // 1. add a new resolution to list 625a10cf76eSAxel Dörfler // - we had to remove it as soon as a "valid" one is selected 626a10cf76eSAxel Dörfler // - we don't know which frequencies/bit depths are supported 627a10cf76eSAxel Dörfler // - as long as we haven't the GMT formula to create 628a10cf76eSAxel Dörfler // parameters for any resolution given, we cannot 629a10cf76eSAxel Dörfler // really set current mode - it's just not in the list 630a10cf76eSAxel Dörfler // 2. choose nearest resolution 631a10cf76eSAxel Dörfler // - probably a good idea, but implies coding and testing 632a10cf76eSAxel Dörfler // 3. choose lowest resolution 633a10cf76eSAxel Dörfler // - do you really think we are so lazy? yes, we are 634a10cf76eSAxel Dörfler item = fResolutionMenu->ItemAt(0); 635a10cf76eSAxel Dörfler if (item) 636a10cf76eSAxel Dörfler item->SetMarked(true); 637a10cf76eSAxel Dörfler 638a10cf76eSAxel Dörfler // okay - at least we set menu label to active resolution 639a10cf76eSAxel Dörfler fResolutionMenu->Superitem()->SetLabel(string.String()); 640a10cf76eSAxel Dörfler } 641a10cf76eSAxel Dörfler 642a10cf76eSAxel Dörfler // mark active combine mode 643a10cf76eSAxel Dörfler for (int32 i = 0; i < kCombineModeCount; i++) { 644a10cf76eSAxel Dörfler if (kCombineModes[i].mode == fSelected.combine) { 645a10cf76eSAxel Dörfler item = fCombineMenu->ItemAt(i); 646a10cf76eSAxel Dörfler if (item && !item->IsMarked()) 647a10cf76eSAxel Dörfler item->SetMarked(true); 648a10cf76eSAxel Dörfler break; 649a10cf76eSAxel Dörfler } 650a10cf76eSAxel Dörfler } 651a10cf76eSAxel Dörfler 652a10cf76eSAxel Dörfler item = fColorsMenu->ItemAt(0); 653a10cf76eSAxel Dörfler 654a10cf76eSAxel Dörfler for (int32 i = kColorSpaceCount; i-- > 0;) { 655a10cf76eSAxel Dörfler if (kColorSpaces[i].space == fSelected.space) { 656a10cf76eSAxel Dörfler item = fColorsMenu->ItemAt(i); 657a10cf76eSAxel Dörfler break; 658a10cf76eSAxel Dörfler } 659a10cf76eSAxel Dörfler } 660a10cf76eSAxel Dörfler 661a10cf76eSAxel Dörfler if (item && !item->IsMarked()) 662a10cf76eSAxel Dörfler item->SetMarked(true); 663a10cf76eSAxel Dörfler 664a10cf76eSAxel Dörfler string.Truncate(0); 665a10cf76eSAxel Dörfler string << fSelected.BitsPerPixel() << " Bits/Pixel"; 666a10cf76eSAxel Dörfler if (string != fColorsMenu->Superitem()->Label()) 667a10cf76eSAxel Dörfler fColorsMenu->Superitem()->SetLabel(string.String()); 668a10cf76eSAxel Dörfler 669a10cf76eSAxel Dörfler UpdateMonitorView(); 670a10cf76eSAxel Dörfler UpdateRefreshControl(); 671a10cf76eSAxel Dörfler 672a10cf76eSAxel Dörfler CheckApplyEnabled(); 673a10cf76eSAxel Dörfler } 674a10cf76eSAxel Dörfler 675a10cf76eSAxel Dörfler 676a10cf76eSAxel Dörfler /** reflect active mode in chosen settings */ 677a10cf76eSAxel Dörfler 678a10cf76eSAxel Dörfler void 679a10cf76eSAxel Dörfler ScreenWindow::UpdateActiveMode() 680a10cf76eSAxel Dörfler { 681a10cf76eSAxel Dörfler // usually, this function gets called after a mode 682a10cf76eSAxel Dörfler // has been set manually; still, as the graphics driver 683a10cf76eSAxel Dörfler // is free to fiddle with mode passed, we better ask 684a10cf76eSAxel Dörfler // what kind of mode we actually got 685a10cf76eSAxel Dörfler fScreenMode.Get(fActive); 686a10cf76eSAxel Dörfler fSelected = fActive; 687a10cf76eSAxel Dörfler 688a10cf76eSAxel Dörfler UpdateControls(); 689a10cf76eSAxel Dörfler } 690a10cf76eSAxel Dörfler 691a10cf76eSAxel Dörfler 692a10cf76eSAxel Dörfler void 693a10cf76eSAxel Dörfler ScreenWindow::ScreenChanged(BRect frame, color_space mode) 694a10cf76eSAxel Dörfler { 695a10cf76eSAxel Dörfler // move window on screen, if necessary 696a10cf76eSAxel Dörfler if (frame.right <= Frame().right 697a10cf76eSAxel Dörfler && frame.bottom <= Frame().bottom) { 698a10cf76eSAxel Dörfler MoveTo((frame.Width() - Frame().Width()) / 2, 699a10cf76eSAxel Dörfler (frame.Height() - Frame().Height()) / 2); 700a10cf76eSAxel Dörfler } 701a10cf76eSAxel Dörfler } 702a10cf76eSAxel Dörfler 703a10cf76eSAxel Dörfler 704a10cf76eSAxel Dörfler void 705a10cf76eSAxel Dörfler ScreenWindow::WorkspaceActivated(int32 workspace, bool state) 706a10cf76eSAxel Dörfler { 707a10cf76eSAxel Dörfler if (fChangingAllWorkspaces) { 708a10cf76eSAxel Dörfler // we're currently changing all workspaces, so there is no need 709a10cf76eSAxel Dörfler // to update the interface 710a10cf76eSAxel Dörfler return; 711a10cf76eSAxel Dörfler } 712a10cf76eSAxel Dörfler 713a10cf76eSAxel Dörfler fScreenMode.Get(fOriginal); 714a10cf76eSAxel Dörfler fScreenMode.UpdateOriginalMode(); 715a10cf76eSAxel Dörfler 716a10cf76eSAxel Dörfler // only override current settings if they have not been changed yet 717a10cf76eSAxel Dörfler if (fSelected == fActive) 718a10cf76eSAxel Dörfler UpdateActiveMode(); 719a10cf76eSAxel Dörfler 720*6edaa0f6SStefano Ceccherini BMessage message(UPDATE_DESKTOP_COLOR_MSG); 721*6edaa0f6SStefano Ceccherini PostMessage(&message, fMonitorView); 722a10cf76eSAxel Dörfler } 723a10cf76eSAxel Dörfler 724a10cf76eSAxel Dörfler 725a10cf76eSAxel Dörfler void 726a10cf76eSAxel Dörfler ScreenWindow::MessageReceived(BMessage* message) 727a10cf76eSAxel Dörfler { 728a10cf76eSAxel Dörfler switch (message->what) { 729a10cf76eSAxel Dörfler case WORKSPACE_CHECK_MSG: 730a10cf76eSAxel Dörfler CheckApplyEnabled(); 731a10cf76eSAxel Dörfler break; 732a10cf76eSAxel Dörfler 733a10cf76eSAxel Dörfler case POP_WORKSPACE_CHANGED_MSG: 734a10cf76eSAxel Dörfler { 735a10cf76eSAxel Dörfler int32 index; 736a10cf76eSAxel Dörfler if (message->FindInt32("index", &index) == B_OK) 737a10cf76eSAxel Dörfler set_workspace_count(index + 1); 738a10cf76eSAxel Dörfler break; 739a10cf76eSAxel Dörfler } 740a10cf76eSAxel Dörfler 741a10cf76eSAxel Dörfler case POP_RESOLUTION_MSG: 742a10cf76eSAxel Dörfler { 743a10cf76eSAxel Dörfler message->FindInt32("width", &fSelected.width); 744a10cf76eSAxel Dörfler message->FindInt32("height", &fSelected.height); 745a10cf76eSAxel Dörfler 746a10cf76eSAxel Dörfler CheckColorMenu(); 747a10cf76eSAxel Dörfler CheckRefreshMenu(); 748a10cf76eSAxel Dörfler 749a10cf76eSAxel Dörfler UpdateMonitorView(); 750a10cf76eSAxel Dörfler UpdateRefreshControl(); 751a10cf76eSAxel Dörfler 752a10cf76eSAxel Dörfler CheckApplyEnabled(); 753a10cf76eSAxel Dörfler break; 754a10cf76eSAxel Dörfler } 755a10cf76eSAxel Dörfler 756a10cf76eSAxel Dörfler case POP_COLORS_MSG: 757a10cf76eSAxel Dörfler { 758a10cf76eSAxel Dörfler message->FindInt32("space", (int32 *)&fSelected.space); 759a10cf76eSAxel Dörfler 760a10cf76eSAxel Dörfler BString string; 761a10cf76eSAxel Dörfler string << fSelected.BitsPerPixel() << " Bits/Pixel"; 762a10cf76eSAxel Dörfler fColorsMenu->Superitem()->SetLabel(string.String()); 763a10cf76eSAxel Dörfler 764a10cf76eSAxel Dörfler CheckApplyEnabled(); 765a10cf76eSAxel Dörfler break; 766a10cf76eSAxel Dörfler } 767a10cf76eSAxel Dörfler 768a10cf76eSAxel Dörfler case POP_REFRESH_MSG: 769a10cf76eSAxel Dörfler message->FindFloat("refresh", &fSelected.refresh); 770a10cf76eSAxel Dörfler fOtherRefresh->SetLabel("Other" B_UTF8_ELLIPSIS); 771a10cf76eSAxel Dörfler // revert "Other…" label - it might have had a refresh rate prefix 772a10cf76eSAxel Dörfler 773a10cf76eSAxel Dörfler CheckApplyEnabled(); 774a10cf76eSAxel Dörfler break; 775a10cf76eSAxel Dörfler 776a10cf76eSAxel Dörfler case POP_OTHER_REFRESH_MSG: 777a10cf76eSAxel Dörfler { 778a10cf76eSAxel Dörfler // make sure menu shows something usefull 779a10cf76eSAxel Dörfler UpdateRefreshControl(); 780a10cf76eSAxel Dörfler 781a10cf76eSAxel Dörfler BRect frame(Frame()); 782a10cf76eSAxel Dörfler RefreshWindow *fRefreshWindow = new RefreshWindow(BRect(frame.left + 201.0, 783a10cf76eSAxel Dörfler frame.top + 34.0, frame.left + 509.0, frame.top + 169.0), 784a10cf76eSAxel Dörfler int32(fSelected.refresh * 10)); 785a10cf76eSAxel Dörfler fRefreshWindow->Show(); 786a10cf76eSAxel Dörfler break; 787a10cf76eSAxel Dörfler } 788a10cf76eSAxel Dörfler 789a10cf76eSAxel Dörfler case SET_CUSTOM_REFRESH_MSG: 790a10cf76eSAxel Dörfler { 791a10cf76eSAxel Dörfler // user pressed "done" in "Other…" refresh dialog; 792a10cf76eSAxel Dörfler // select the refresh rate chosen 793a10cf76eSAxel Dörfler message->FindFloat("refresh", &fSelected.refresh); 794a10cf76eSAxel Dörfler 795a10cf76eSAxel Dörfler UpdateRefreshControl(); 796a10cf76eSAxel Dörfler CheckApplyEnabled(); 797a10cf76eSAxel Dörfler break; 798a10cf76eSAxel Dörfler } 799a10cf76eSAxel Dörfler 800a10cf76eSAxel Dörfler case POP_COMBINE_DISPLAYS_MSG: 801a10cf76eSAxel Dörfler { 802a10cf76eSAxel Dörfler // new combine mode has bee chosen 803a10cf76eSAxel Dörfler int32 mode; 804a10cf76eSAxel Dörfler if (message->FindInt32("mode", &mode) == B_OK) 805a10cf76eSAxel Dörfler fSelected.combine = (combine_mode)mode; 806a10cf76eSAxel Dörfler 807a10cf76eSAxel Dörfler CheckResolutionMenu(); 808a10cf76eSAxel Dörfler CheckApplyEnabled(); 809a10cf76eSAxel Dörfler break; 810a10cf76eSAxel Dörfler } 811a10cf76eSAxel Dörfler 812a10cf76eSAxel Dörfler case POP_SWAP_DISPLAYS_MSG: 813a10cf76eSAxel Dörfler message->FindBool("swap", &fSelected.swap_displays); 814a10cf76eSAxel Dörfler CheckApplyEnabled(); 815a10cf76eSAxel Dörfler break; 816a10cf76eSAxel Dörfler 817a10cf76eSAxel Dörfler case POP_USE_LAPTOP_PANEL_MSG: 818a10cf76eSAxel Dörfler message->FindBool("use", &fSelected.use_laptop_panel); 819a10cf76eSAxel Dörfler CheckApplyEnabled(); 820a10cf76eSAxel Dörfler break; 821a10cf76eSAxel Dörfler 822a10cf76eSAxel Dörfler case POP_TV_STANDARD_MSG: 823a10cf76eSAxel Dörfler message->FindInt32("tv_standard", (int32 *)&fSelected.tv_standard); 824a10cf76eSAxel Dörfler CheckApplyEnabled(); 825a10cf76eSAxel Dörfler break; 826a10cf76eSAxel Dörfler 827a10cf76eSAxel Dörfler case BUTTON_DEFAULTS_MSG: 828a10cf76eSAxel Dörfler { 829a10cf76eSAxel Dörfler fSelected.width = 640; 830a10cf76eSAxel Dörfler fSelected.height = 480; 831a10cf76eSAxel Dörfler fSelected.space = B_CMAP8; 832a10cf76eSAxel Dörfler fSelected.refresh = 60.0; 833a10cf76eSAxel Dörfler fSelected.combine = kCombineDisable; 834a10cf76eSAxel Dörfler fSelected.swap_displays = false; 835a10cf76eSAxel Dörfler fSelected.use_laptop_panel = false; 836a10cf76eSAxel Dörfler fSelected.tv_standard = 0; 837a10cf76eSAxel Dörfler 838a10cf76eSAxel Dörfler UpdateControls(); 839a10cf76eSAxel Dörfler break; 840a10cf76eSAxel Dörfler } 841a10cf76eSAxel Dörfler 842a10cf76eSAxel Dörfler case BUTTON_REVERT_MSG: 843a10cf76eSAxel Dörfler case SET_INITIAL_MODE_MSG: 844a10cf76eSAxel Dörfler fScreenMode.Revert(); 845a10cf76eSAxel Dörfler UpdateActiveMode(); 846a10cf76eSAxel Dörfler break; 847a10cf76eSAxel Dörfler 848a10cf76eSAxel Dörfler case BUTTON_APPLY_MSG: 849a10cf76eSAxel Dörfler Apply(); 850a10cf76eSAxel Dörfler break; 851a10cf76eSAxel Dörfler 852a10cf76eSAxel Dörfler case MAKE_INITIAL_MSG: { 853a10cf76eSAxel Dörfler // user pressed "keep" in confirmation box; 854a10cf76eSAxel Dörfler // select this mode in dialog and mark it as 855a10cf76eSAxel Dörfler // previous mode; if "all workspaces" is selected, 856a10cf76eSAxel Dörfler // distribute mode to all workspaces 857a10cf76eSAxel Dörfler 858a10cf76eSAxel Dörfler // use the mode that has eventually been set and 859a10cf76eSAxel Dörfler // thus we know to be working; it can differ from 860a10cf76eSAxel Dörfler // the mode selected by user due to hardware limitation 861a10cf76eSAxel Dörfler display_mode newMode; 862a10cf76eSAxel Dörfler BScreen screen(this); 863a10cf76eSAxel Dörfler screen.GetMode(&newMode); 864a10cf76eSAxel Dörfler 865a10cf76eSAxel Dörfler if (fAllWorkspacesItem->IsMarked()) { 866a10cf76eSAxel Dörfler int32 originatingWorkspace; 867a10cf76eSAxel Dörfler 868a10cf76eSAxel Dörfler // the original panel activates each workspace in turn; 869a10cf76eSAxel Dörfler // this is disguisting and there is a SetMode 870a10cf76eSAxel Dörfler // variant that accepts a workspace id, so let's take 871a10cf76eSAxel Dörfler // this one 872a10cf76eSAxel Dörfler originatingWorkspace = current_workspace(); 873a10cf76eSAxel Dörfler 874a10cf76eSAxel Dörfler // well, this "cannot be reverted" message is not 875a10cf76eSAxel Dörfler // entirely true - at least, you can revert it 876a10cf76eSAxel Dörfler // for current workspace; to not overwrite original 877a10cf76eSAxel Dörfler // mode during workspace switch, we use this flag 878a10cf76eSAxel Dörfler fChangingAllWorkspaces = true; 879a10cf76eSAxel Dörfler 880a10cf76eSAxel Dörfler for (int32 i = 0; i < count_workspaces(); i++) { 881a10cf76eSAxel Dörfler if (i != originatingWorkspace) 882a10cf76eSAxel Dörfler screen.SetMode(i, &newMode, true); 883a10cf76eSAxel Dörfler } 884a10cf76eSAxel Dörfler 885a10cf76eSAxel Dörfler fChangingAllWorkspaces = false; 886a10cf76eSAxel Dörfler } 887a10cf76eSAxel Dörfler 888a10cf76eSAxel Dörfler UpdateActiveMode(); 889a10cf76eSAxel Dörfler break; 890a10cf76eSAxel Dörfler } 891a10cf76eSAxel Dörfler 892a10cf76eSAxel Dörfler default: 893a10cf76eSAxel Dörfler BWindow::MessageReceived(message); 894a10cf76eSAxel Dörfler break; 895a10cf76eSAxel Dörfler } 896a10cf76eSAxel Dörfler } 897a10cf76eSAxel Dörfler 898a10cf76eSAxel Dörfler 899a10cf76eSAxel Dörfler bool 900a10cf76eSAxel Dörfler ScreenWindow::CanApply() const 901a10cf76eSAxel Dörfler { 902a10cf76eSAxel Dörfler if (fAllWorkspacesItem->IsMarked()) 903a10cf76eSAxel Dörfler return true; 904a10cf76eSAxel Dörfler 905a10cf76eSAxel Dörfler return fSelected != fActive; 906a10cf76eSAxel Dörfler } 907a10cf76eSAxel Dörfler 908a10cf76eSAxel Dörfler 909a10cf76eSAxel Dörfler bool 910a10cf76eSAxel Dörfler ScreenWindow::CanRevert() const 911a10cf76eSAxel Dörfler { 912a10cf76eSAxel Dörfler if (fActive != fOriginal) 913a10cf76eSAxel Dörfler return true; 914a10cf76eSAxel Dörfler 915a10cf76eSAxel Dörfler return CanApply(); 916a10cf76eSAxel Dörfler } 917a10cf76eSAxel Dörfler 918a10cf76eSAxel Dörfler 919a10cf76eSAxel Dörfler void 920a10cf76eSAxel Dörfler ScreenWindow::CheckApplyEnabled() 921a10cf76eSAxel Dörfler { 922a10cf76eSAxel Dörfler fApplyButton->SetEnabled(CanApply()); 923a10cf76eSAxel Dörfler fRevertButton->SetEnabled(CanRevert()); 924a10cf76eSAxel Dörfler } 925a10cf76eSAxel Dörfler 926a10cf76eSAxel Dörfler 927a10cf76eSAxel Dörfler void 928a10cf76eSAxel Dörfler ScreenWindow::Apply() 929a10cf76eSAxel Dörfler { 930a10cf76eSAxel Dörfler if (fAllWorkspacesItem->IsMarked()) { 931a10cf76eSAxel Dörfler BAlert *workspacesAlert = new BAlert("WorkspacesAlert", 932a10cf76eSAxel Dörfler "Change all workspaces? This action cannot be reverted.", "Okay", "Cancel", 933a10cf76eSAxel Dörfler NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); 934a10cf76eSAxel Dörfler 935a10cf76eSAxel Dörfler if (workspacesAlert->Go() == 1) 936a10cf76eSAxel Dörfler return; 937a10cf76eSAxel Dörfler } 938a10cf76eSAxel Dörfler 93907184a9eSAxel Dörfler status_t status = fScreenMode.Set(fSelected); 94007184a9eSAxel Dörfler if (status == B_OK) { 941a10cf76eSAxel Dörfler fActive = fSelected; 942a10cf76eSAxel Dörfler 943a10cf76eSAxel Dörfler // ToDo: only show alert when this is an unknown mode 944a10cf76eSAxel Dörfler BWindow* window = new AlertWindow(this); 945a10cf76eSAxel Dörfler window->Show(); 94607184a9eSAxel Dörfler } else { 94707184a9eSAxel Dörfler char message[256]; 94807184a9eSAxel Dörfler snprintf(message, sizeof(message), 94907184a9eSAxel Dörfler "The screen mode could not be set:\n\t%s\n", screen_errors(status)); 95007184a9eSAxel Dörfler BAlert* alert = new BAlert("Screen Alert", message, "Okay", NULL, NULL, 95107184a9eSAxel Dörfler B_WIDTH_AS_USUAL, B_WARNING_ALERT); 95207184a9eSAxel Dörfler alert->Go(); 953a10cf76eSAxel Dörfler } 95407184a9eSAxel Dörfler } 95507184a9eSAxel Dörfler 956