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 <pulkomandy@gmail.com>
This commit is contained in:
Adrien Destugues 2020-07-18 19:55:06 +02:00 committed by Adrien Destugues
parent f6d0ea5cad
commit 8b2b301059
6 changed files with 47 additions and 6 deletions

View File

@ -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 status_t
Desktop::LockDirectScreen(team_id team) Desktop::LockDirectScreen(team_id team)
{ {
@ -2676,14 +2692,13 @@ Desktop::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
fQuitting = true; fQuitting = true;
BroadcastToAllApps(AS_QUIT_APP); BroadcastToAllApps(AS_QUIT_APP);
// We now need to process the remaining AS_DELETE_APP messages and // We now need to process the remaining AS_DELETE_APP messages.
// wait for the kMsgShutdownServer message. // We quit the looper when the last app is deleted.
// If an application does not quit as asked, the picasso thread
// will send us this message in 2-3 seconds.
// if there are no apps to quit, shutdown directly // if there are no apps to quit, shutdown directly
if (fShutdownCount == 0) if (fShutdownCount == 0)
PostMessage(kMsgQuitLooper); PostMessage(kMsgQuitLooper);
break; break;
case AS_ACTIVATE_WORKSPACE: case AS_ACTIVATE_WORKSPACE:

View File

@ -125,6 +125,8 @@ public:
BRect& frame); BRect& frame);
void RevertScreenModes(uint32 workspaces); void RevertScreenModes(uint32 workspaces);
status_t SetBrightness(int32 id, float brightness);
MultiLocker& ScreenLocker() { return fScreenLock; } MultiLocker& ScreenLocker() { return fScreenLock; }
status_t LockDirectScreen(team_id team); status_t LockDirectScreen(team_id team);

View File

@ -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 void
ScreenConfigurations::Remove(screen_configuration* configuration) ScreenConfigurations::Remove(screen_configuration* configuration)
{ {
@ -184,6 +194,7 @@ ScreenConfigurations::Store(BMessage& settings) const
screenSettings.AddRect("frame", configuration->frame); screenSettings.AddRect("frame", configuration->frame);
screenSettings.AddData("mode", B_RAW_TYPE, &configuration->mode, screenSettings.AddData("mode", B_RAW_TYPE, &configuration->mode,
sizeof(display_mode)); sizeof(display_mode));
screenSettings.AddFloat("brightness", configuration->brightness);
settings.AddMessage("screen", &screenSettings); settings.AddMessage("screen", &screenSettings);
} }
@ -230,7 +241,8 @@ ScreenConfigurations::Restore(const BMessage& settings)
// create monitor info // create monitor info
strlcpy(configuration->info.vendor, vendor, strlcpy(configuration->info.vendor, vendor,
sizeof(configuration->info.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, strlcpy(configuration->info.serial_number, serial,
sizeof(configuration->info.serial_number)); sizeof(configuration->info.serial_number));
configuration->info.product_id = productID; configuration->info.product_id = productID;
@ -243,6 +255,9 @@ ScreenConfigurations::Restore(const BMessage& settings)
stored.FindRect("frame", &configuration->frame); stored.FindRect("frame", &configuration->frame);
memcpy(&configuration->mode, mode, sizeof(display_mode)); memcpy(&configuration->mode, mode, sizeof(display_mode));
if (stored.FindFloat("brightness", &configuration->brightness) != B_OK)
configuration->brightness = 1.0f;
fConfigurations.AddItem(configuration); fConfigurations.AddItem(configuration);
} }

View File

@ -20,6 +20,7 @@ struct screen_configuration {
monitor_info info; monitor_info info;
BRect frame; BRect frame;
display_mode mode; display_mode mode;
float brightness;
bool has_info; bool has_info;
bool is_current; bool is_current;
}; };
@ -37,6 +38,7 @@ public:
status_t Set(int32 id, const monitor_info* info, status_t Set(int32 id, const monitor_info* info,
const BRect& frame, const BRect& frame,
const display_mode& mode); const display_mode& mode);
void SetBrightness(int32 id, float brightness);
void Remove(screen_configuration* configuration); void Remove(screen_configuration* configuration);
status_t Store(BMessage& settings) const; status_t Store(BMessage& settings) const;

View File

@ -3110,7 +3110,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
float brightness; float brightness;
link.Read<float>(&brightness); link.Read<float>(&brightness);
status_t status = fDesktop->HWInterface()->SetBrightness(brightness); status_t status = fDesktop->SetBrightness(id, brightness);
fLink.StartMessage(status); fLink.StartMessage(status);
fLink.Flush(); fLink.Flush();

View File

@ -142,6 +142,13 @@ VirtualScreen::AddScreen(Screen* screen, ScreenConfigurations& configurations)
fFrame = screen->Frame(); fFrame = screen->Frame();
item->frame = fFrame; 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); fScreenList.AddItem(item);
return B_OK; return B_OK;