@@ -104,6 +104,7 @@ struct params {
104104 bool percentage ;
105105 bool save ;
106106 bool restore ;
107+ bool frac ;
107108 float exponent ;
108109};
109110
@@ -123,6 +124,7 @@ static const struct option options[] = {
123124 {"restore" , no_argument , NULL , 'r' },
124125 {"save" , no_argument , NULL , 's' },
125126 {"version" , no_argument , NULL , 'V' },
127+ {"frac" , no_argument , NULL , 0 },
126128 {NULL ,}
127129};
128130
@@ -192,6 +194,9 @@ int main(int argc, char **argv) {
192194 printf ("%s\n" , VERSION );
193195 exit (0 );
194196 break ;
197+ case 0 :
198+ p .frac = true;
199+ break ;
195200 default :
196201 phelp ++ ;
197202 }
@@ -286,7 +291,7 @@ int apply_operation(struct device *dev, enum operation operation, struct value *
286291 return 0 ;
287292 case GET :
288293 if (p .percentage )
289- fprintf (stdout , "%d \n" , ( int ) val_to_percent (dev -> curr_brightness , dev , true ));
294+ fprintf (stdout , "%.4g \n" , val_to_percent (dev -> curr_brightness , dev , ! p . frac ));
290295 else
291296 fprintf (stdout , "%u\n" , dev -> curr_brightness );
292297 return 0 ;
@@ -381,12 +386,12 @@ unsigned long percent_to_val(float percent, struct device *d) {
381386}
382387
383388void print_device (struct device * dev ) {
384- char * format = p .mach ? "%s,%s,%d,%d %%,%d\n" :
385- "Device '%s' of class '%s':\n\tCurrent brightness: %d (%d %%)\n\tMax brightness: %d\n\n" ;
389+ char * format = p .mach ? "%s,%s,%d,%.4g %%,%d\n" :
390+ "Device '%s' of class '%s':\n\tCurrent brightness: %d (%.4g %%)\n\tMax brightness: %d\n\n" ;
386391 fprintf (stdout , format ,
387392 dev -> id , dev -> class ,
388393 dev -> curr_brightness ,
389- ( int ) val_to_percent (dev -> curr_brightness , dev , true ),
394+ val_to_percent (dev -> curr_brightness , dev , ! p . frac ),
390395 dev -> max_brightness );
391396}
392397
@@ -738,6 +743,7 @@ Options:\n\
738743 -d, --device=DEVICE \tspecify device name (can be a wildcard).\n\
739744 -c, --class=CLASS \tspecify device class.\n\
740745 -V, --version \tprint version and exit.\n\
746+ --frac \tenable fractional percentage output.\n\
741747\n\
742748Operations:\n\
743749 i, info \tget device info.\n\
0 commit comments