Extend --geometry flag to also accept display offsets

This commit is contained in:
Johannes Marbach 2022-07-10 20:29:45 +02:00
parent 51380c7654
commit 7ccbf059c1
4 changed files with 30 additions and 18 deletions

View file

@ -6,6 +6,7 @@
- fix: Use actual screen DPI value to compute sizes and spaces
- feat: Allow shutting down the device on inactivity
- fix: Disable terminal keyboard while unl0kr is running
- feat: Extend --geometry flag to also accept display offsets
## 0.2.0 (2022-05-27)

View file

@ -61,6 +61,8 @@ static void init_opts(ul_cli_opts *opts) {
opts->hor_res = -1;
opts->ver_res = -1;
opts->x_offset = 0;
opts->y_offset = 0;
opts->verbose = false;
}
@ -73,19 +75,20 @@ static void print_usage() {
"password is printed to STDOUT. All other output happens on STDERR.\n"
"\n"
"Mandatory arguments to long options are mandatory for short options too.\n"
" -c, --config=PATH Locaton of the main config file. Defaults to\n"
" /etc/unl0kr.conf.\n"
" -C, --config-override Location of the config override file. Values in\n"
" this file override values for the same keys in the\n"
" main config file. If specified multiple times, the\n"
" values from consecutive files will be merged in\n"
" order.\n"
" -g, --geometry=NxM Force a display size of N horizontal times M\n"
" vertical pixels\n"
" -d --dpi=N Overrides the DPI\n"
" -h, --help Print this message and exit\n"
" -v, --verbose Enable more detailed logging output on STDERR\n"
" -V, --version Print the unl0kr version and exit\n");
" -c, --config=PATH Locaton of the main config file. Defaults to\n"
" /etc/unl0kr.conf.\n"
" -C, --config-override Location of the config override file. Values in\n"
" this file override values for the same keys in\n"
" the main config file. If specified multiple\n"
" times, the values from consecutive files will be\n"
" merged in order.\n"
" -g, --geometry=NxM[@X,Y] Force a display size of N horizontal times M\n"
" vertical pixels, offset horizontally by X\n"
" pixels and vertically by Y pixels"
" -d --dpi=N Override the display's DPI value\n"
" -h, --help Print this message and exit\n"
" -v, --verbose Enable more detailed logging output on STDERR\n"
" -V, --version Print the unl0kr version and exit\n");
/*-------------------------------- 78 CHARS --------------------------------*/
}
@ -125,9 +128,11 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) {
opts->num_config_files++;
break;
case 'g':
if (sscanf(optarg, "%ix%i", &(opts->hor_res), &(opts->ver_res)) != 2) {
ul_log(UL_LOG_LEVEL_ERROR, "Invalid geometry argument \"%s\"\n", optarg);
exit(EXIT_FAILURE);
if (sscanf(optarg, "%ix%i@%i,%i", &(opts->hor_res), &(opts->ver_res), &(opts->x_offset), &(opts->y_offset)) != 4) {
if (sscanf(optarg, "%ix%i", &(opts->hor_res), &(opts->ver_res)) != 2) {
ul_log(UL_LOG_LEVEL_ERROR, "Invalid geometry argument \"%s\"\n", optarg);
exit(EXIT_FAILURE);
}
}
break;
case 'd':

View file

@ -35,6 +35,10 @@ typedef struct {
int hor_res;
/* Vertical display resolution */
int ver_res;
/* Horizontal display offset */
int x_offset;
/* Vertical display offset */
int y_offset;
/* DPI */
int dpi;
/* Verbose mode. If true, provide more detailed logging output on STDERR. */

6
main.c
View file

@ -391,10 +391,10 @@ int main(int argc, char *argv[]) {
/* Override display parameters with command line options if necessary */
if (cli_opts.hor_res > 0) {
hor_res = LV_MIN(hor_res, (uint32_t)cli_opts.hor_res);
hor_res = cli_opts.hor_res;
}
if (cli_opts.ver_res > 0) {
ver_res = LV_MIN(ver_res, (uint32_t)cli_opts.ver_res);
ver_res = cli_opts.ver_res;
}
if (cli_opts.dpi > 0) {
dpi = cli_opts.dpi;
@ -411,6 +411,8 @@ int main(int argc, char *argv[]) {
disp_drv.draw_buf = &disp_buf;
disp_drv.hor_res = hor_res;
disp_drv.ver_res = ver_res;
disp_drv.offset_x = cli_opts.x_offset;
disp_drv.offset_y = cli_opts.y_offset;
disp_drv.dpi = dpi;
lv_disp_drv_register(&disp_drv);