Allow to change brightness from the command line
screenmode can now set the brightness (only for intel_extreme, still). Both absolute and relative values are accepted, allowing to bind keyboard shortcuts to "increase brightness" and "decrease brightness". Change-Id: I5221532ebdfba5df1b4d4e1f3331406359f2807c Reviewed-on: https://review.haiku-os.org/655 Reviewed-by: Kacper Kasper <kacperkasper@gmail.com>
This commit is contained in:
parent
657081f3c6
commit
22e03e588e
@ -16,4 +16,5 @@ BinCommand screenmode :
|
||||
ScreenMode.cpp
|
||||
|
||||
: be [ TargetLibsupc++ ] libaccelerantscommon.a
|
||||
: screenmode.rdef
|
||||
;
|
||||
|
@ -25,6 +25,7 @@ static struct option const kLongOptions[] = {
|
||||
{"short", no_argument, 0, 's'},
|
||||
{"list", no_argument, 0, 'l'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"brightness", required_argument, 0, 'b'},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@ -96,6 +97,8 @@ usage(int status)
|
||||
"\t\t\tprinted in short form.\n"
|
||||
" -l --list\t\tdisplay a list of the available modes.\n"
|
||||
" -q --dont-confirm\tdo not confirm the mode after setting it.\n"
|
||||
" -b --brightness f\tset brightness (range 0 to 1).\n"
|
||||
" -b --brightness +/-f\tchange brightness by given amount.\n"
|
||||
" -m --modeline\taccept and print X-style modeline modes:\n"
|
||||
"\t\t\t <pclk> <h-display> <h-sync-start> <h-sync-end> <h-total>\n"
|
||||
"\t\t\t <v-disp> <v-sync-start> <v-sync-end> <v-total> [flags] "
|
||||
@ -120,13 +123,15 @@ main(int argc, char** argv)
|
||||
int height = -1;
|
||||
int depth = -1;
|
||||
float refresh = -1;
|
||||
float brightness = std::nanf("0");
|
||||
bool relativeBrightness = false;
|
||||
display_mode mode;
|
||||
|
||||
// TODO: add a possibility to set a virtual screen size in addition to
|
||||
// the display resolution!
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "shlfqm", kLongOptions, NULL)) != -1) {
|
||||
while ((c = getopt_long(argc, argv, "shlfqmb:", kLongOptions, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 0:
|
||||
break;
|
||||
@ -147,6 +152,12 @@ main(int argc, char** argv)
|
||||
case 'q':
|
||||
confirm = false;
|
||||
break;
|
||||
case 'b':
|
||||
if (optarg[0] == '+' || optarg[0] == '-')
|
||||
relativeBrightness = true;
|
||||
brightness = atof(optarg);
|
||||
printf("b %f rel %d\n", brightness, relativeBrightness);
|
||||
break;
|
||||
case 'h':
|
||||
usage(0);
|
||||
break;
|
||||
@ -234,6 +245,25 @@ main(int argc, char** argv)
|
||||
screen_mode currentMode;
|
||||
screenMode.Get(currentMode);
|
||||
|
||||
if (!isnan(brightness)) {
|
||||
BScreen screen;
|
||||
if (relativeBrightness) {
|
||||
float previousBrightness;
|
||||
screen.GetBrightness(&previousBrightness);
|
||||
brightness = previousBrightness + brightness;
|
||||
printf("new %f\n", brightness);
|
||||
|
||||
// Clamp to min/max values
|
||||
if (brightness < 0.f)
|
||||
brightness = 0.f;
|
||||
|
||||
if (brightness > 1.f)
|
||||
brightness = 1.f;
|
||||
printf("clamp %f\n", brightness);
|
||||
}
|
||||
screen.SetBrightness(brightness);
|
||||
}
|
||||
|
||||
if (listModes) {
|
||||
// List all reported modes
|
||||
if (!shortOutput)
|
||||
|
3
src/bin/screenmode/screenmode.rdef
Normal file
3
src/bin/screenmode/screenmode.rdef
Normal file
@ -0,0 +1,3 @@
|
||||
resource app_signature "application/x-vnd.haiku.screenmode";
|
||||
|
||||
resource app_flags B_MULTIPLE_LAUNCH | B_BACKGROUND_APP;
|
Loading…
Reference in New Issue
Block a user