From 8b2b30105941e16ea895873a7248914888d12b12 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 18 Jul 2020 19:55:06 +0200 Subject: [PATCH] app_server: save/restore screen brightness settings The brightness is saved in the screen configurations of the first workspace. For now, all screens get the same brightness (I can't get screen IDs to work today). Since we only support setting the brightness for laptop displays for now, this shouldn't matter. It can be fixed when app_server gets actual multiple display support. Fixes #14254 Change-Id: Ib33aa65a73407a65bd469d0efa8542210fec02d4 Reviewed-on: https://review.haiku-os.org/c/haiku/+/362 Reviewed-by: Adrien Destugues --- src/servers/app/Desktop.cpp | 23 +++++++++++++++++++---- src/servers/app/Desktop.h | 2 ++ src/servers/app/ScreenConfigurations.cpp | 17 ++++++++++++++++- src/servers/app/ScreenConfigurations.h | 2 ++ src/servers/app/ServerApp.cpp | 2 +- src/servers/app/VirtualScreen.cpp | 7 +++++++ 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index c2d48084c8..cccd2c579f 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -887,6 +887,22 @@ Desktop::RevertScreenModes(uint32 workspaces) } +status_t +Desktop::SetBrightness(int32 id, float brightness) +{ + status_t result = HWInterface()->SetBrightness(brightness); + + if (result == B_OK) { + fWorkspaces[0].StoredScreenConfiguration().SetBrightness(id, + brightness); + // Save brightness for next boot + StoreWorkspaceConfiguration(0); + } + + return result; +} + + status_t Desktop::LockDirectScreen(team_id team) { @@ -2676,14 +2692,13 @@ Desktop::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) fQuitting = true; BroadcastToAllApps(AS_QUIT_APP); - // We now need to process the remaining AS_DELETE_APP messages and - // wait for the kMsgShutdownServer message. - // If an application does not quit as asked, the picasso thread - // will send us this message in 2-3 seconds. + // We now need to process the remaining AS_DELETE_APP messages. + // We quit the looper when the last app is deleted. // if there are no apps to quit, shutdown directly if (fShutdownCount == 0) PostMessage(kMsgQuitLooper); + break; case AS_ACTIVATE_WORKSPACE: diff --git a/src/servers/app/Desktop.h b/src/servers/app/Desktop.h index dc7b92c53d..f0dae9b0e6 100644 --- a/src/servers/app/Desktop.h +++ b/src/servers/app/Desktop.h @@ -125,6 +125,8 @@ public: BRect& frame); void RevertScreenModes(uint32 workspaces); + status_t SetBrightness(int32 id, float brightness); + MultiLocker& ScreenLocker() { return fScreenLock; } status_t LockDirectScreen(team_id team); diff --git a/src/servers/app/ScreenConfigurations.cpp b/src/servers/app/ScreenConfigurations.cpp index 9c2a7628f9..d326250956 100644 --- a/src/servers/app/ScreenConfigurations.cpp +++ b/src/servers/app/ScreenConfigurations.cpp @@ -143,6 +143,16 @@ ScreenConfigurations::Set(int32 id, const monitor_info* info, } +void +ScreenConfigurations::SetBrightness(int32 id, float brightness) +{ + for (int32 i = fConfigurations.CountItems(); i-- > 0;) { + screen_configuration* configuration = fConfigurations.ItemAt(i); + configuration->brightness = brightness; + } +} + + void ScreenConfigurations::Remove(screen_configuration* configuration) { @@ -184,6 +194,7 @@ ScreenConfigurations::Store(BMessage& settings) const screenSettings.AddRect("frame", configuration->frame); screenSettings.AddData("mode", B_RAW_TYPE, &configuration->mode, sizeof(display_mode)); + screenSettings.AddFloat("brightness", configuration->brightness); settings.AddMessage("screen", &screenSettings); } @@ -230,7 +241,8 @@ ScreenConfigurations::Restore(const BMessage& settings) // create monitor info strlcpy(configuration->info.vendor, vendor, sizeof(configuration->info.vendor)); - strlcpy(configuration->info.name, name, sizeof(configuration->info.name)); + strlcpy(configuration->info.name, name, + sizeof(configuration->info.name)); strlcpy(configuration->info.serial_number, serial, sizeof(configuration->info.serial_number)); configuration->info.product_id = productID; @@ -243,6 +255,9 @@ ScreenConfigurations::Restore(const BMessage& settings) stored.FindRect("frame", &configuration->frame); memcpy(&configuration->mode, mode, sizeof(display_mode)); + if (stored.FindFloat("brightness", &configuration->brightness) != B_OK) + configuration->brightness = 1.0f; + fConfigurations.AddItem(configuration); } diff --git a/src/servers/app/ScreenConfigurations.h b/src/servers/app/ScreenConfigurations.h index 2a9d4523b9..7eb9fc51b0 100644 --- a/src/servers/app/ScreenConfigurations.h +++ b/src/servers/app/ScreenConfigurations.h @@ -20,6 +20,7 @@ struct screen_configuration { monitor_info info; BRect frame; display_mode mode; + float brightness; bool has_info; bool is_current; }; @@ -37,6 +38,7 @@ public: status_t Set(int32 id, const monitor_info* info, const BRect& frame, const display_mode& mode); + void SetBrightness(int32 id, float brightness); void Remove(screen_configuration* configuration); status_t Store(BMessage& settings) const; diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index ec6fdecd14..6f30c98246 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -3110,7 +3110,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) float brightness; link.Read(&brightness); - status_t status = fDesktop->HWInterface()->SetBrightness(brightness); + status_t status = fDesktop->SetBrightness(id, brightness); fLink.StartMessage(status); fLink.Flush(); diff --git a/src/servers/app/VirtualScreen.cpp b/src/servers/app/VirtualScreen.cpp index 94a9e1e1f2..1f6c37cdb4 100644 --- a/src/servers/app/VirtualScreen.cpp +++ b/src/servers/app/VirtualScreen.cpp @@ -142,6 +142,13 @@ VirtualScreen::AddScreen(Screen* screen, ScreenConfigurations& configurations) fFrame = screen->Frame(); item->frame = fFrame; + screen_configuration* config = configurations.CurrentByID(screen->ID()); + if (config) { + float brightness = config->brightness; + if (brightness > 0) + fHWInterface->SetBrightness(brightness); + } + fScreenList.AddItem(item); return B_OK;