screenmode: Allow retrieving screen brightness via CLI
* Add a new flag (-B, or --get-brightness), that changes the output from screen mode to screen output * This new flag is affected by the -s (short output) option for use in scripts * The wording for -s is changed to reflect the fact that it now affects the new flag Change-Id: I81145f401952fc026673e05a5fc03d4e3352fd3c Reviewed-on: https://review.haiku-os.org/c/haiku/+/8865 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
bd2d95cf90
commit
1047530b8f
@@ -26,6 +26,7 @@ static struct option const kLongOptions[] = {
|
|||||||
{"list", no_argument, 0, 'l'},
|
{"list", no_argument, 0, 'l'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"brightness", required_argument, 0, 'b'},
|
{"brightness", required_argument, 0, 'b'},
|
||||||
|
{"get-brightness", no_argument, 0, 'B'},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,12 +94,14 @@ usage(int status)
|
|||||||
" --fall-back\tchanges to the standard fallback mode, and "
|
" --fall-back\tchanges to the standard fallback mode, and "
|
||||||
"displays a\n"
|
"displays a\n"
|
||||||
"\t\t\tnotification requester.\n"
|
"\t\t\tnotification requester.\n"
|
||||||
" -s --short\t\twhen no mode is given the current screen mode is\n"
|
" -s --short\t\twhen no mode is given the current screen mode or\n\n"
|
||||||
"\t\t\tprinted in short form.\n"
|
"\t\t\tthe screen brightness is printed in short form.\n"
|
||||||
" -l --list\t\tdisplay a list of the available modes.\n"
|
" -l --list\t\tdisplay a list of the available modes.\n"
|
||||||
" -q --dont-confirm\tdo not confirm the mode after setting it.\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\tset brightness (range 0 to 1).\n"
|
||||||
" -b --brightness +/-f\tchange brightness by given amount.\n"
|
" -b --brightness +/-f\tchange brightness by given amount.\n"
|
||||||
|
" -B --get-brightness\tprint the current brightness to stdout.\n"
|
||||||
|
"\t\t\tinstead of the screen mode\n"
|
||||||
" -m --modeline\taccept and print X-style modeline modes:\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 <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] "
|
"\t\t\t <v-disp> <v-sync-start> <v-sync-end> <v-total> [flags] "
|
||||||
@@ -118,6 +121,7 @@ main(int argc, char** argv)
|
|||||||
bool shortOutput = false;
|
bool shortOutput = false;
|
||||||
bool listModes = false;
|
bool listModes = false;
|
||||||
bool modeLine = false;
|
bool modeLine = false;
|
||||||
|
bool getBrightness = false;
|
||||||
bool confirm = true;
|
bool confirm = true;
|
||||||
int width = -1;
|
int width = -1;
|
||||||
int height = -1;
|
int height = -1;
|
||||||
@@ -131,7 +135,7 @@ main(int argc, char** argv)
|
|||||||
// the display resolution!
|
// the display resolution!
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt_long(argc, argv, "shlfqmb:", kLongOptions, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, "shlfqmb:B", kLongOptions, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
@@ -157,6 +161,9 @@ main(int argc, char** argv)
|
|||||||
relativeBrightness = true;
|
relativeBrightness = true;
|
||||||
brightness = atof(optarg);
|
brightness = atof(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'B':
|
||||||
|
getBrightness = true;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(0);
|
usage(0);
|
||||||
break;
|
break;
|
||||||
@@ -243,7 +250,6 @@ main(int argc, char** argv)
|
|||||||
ScreenMode screenMode(NULL);
|
ScreenMode screenMode(NULL);
|
||||||
screen_mode currentMode;
|
screen_mode currentMode;
|
||||||
screenMode.Get(currentMode);
|
screenMode.Get(currentMode);
|
||||||
|
|
||||||
if (!isnan(brightness)) {
|
if (!isnan(brightness)) {
|
||||||
BScreen screen;
|
BScreen screen;
|
||||||
if (relativeBrightness) {
|
if (relativeBrightness) {
|
||||||
@@ -280,7 +286,7 @@ main(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!setMode) {
|
if (!setMode && !getBrightness) {
|
||||||
// Just print the current mode
|
// Just print the current mode
|
||||||
if (modeLine) {
|
if (modeLine) {
|
||||||
display_mode mode;
|
display_mode mode;
|
||||||
@@ -294,6 +300,22 @@ main(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t status;
|
||||||
|
|
||||||
|
if (getBrightness) {
|
||||||
|
float brightnessToPrint = std::nanf("0");
|
||||||
|
BScreen screen;
|
||||||
|
status = screen.GetBrightness(&brightnessToPrint);
|
||||||
|
if (status != B_OK) {
|
||||||
|
fprintf(stderr, "Error retrieving brightness: %s\n", strerror(status));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!shortOutput)
|
||||||
|
printf("Brightness: ");
|
||||||
|
printf("%f\n", brightnessToPrint);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
screen_mode newMode = currentMode;
|
screen_mode newMode = currentMode;
|
||||||
|
|
||||||
if (fallbackMode) {
|
if (fallbackMode) {
|
||||||
@@ -327,7 +349,6 @@ main(int argc, char** argv)
|
|||||||
newMode.refresh = 60;
|
newMode.refresh = 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t status;
|
|
||||||
if (modeLine)
|
if (modeLine)
|
||||||
status = screenMode.Set(mode);
|
status = screenMode.Set(mode);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user