From 7ccbf059c1a9d8e045f27153dbae08d970f59e29 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Sun, 10 Jul 2022 20:29:45 +0200 Subject: [PATCH] Extend --geometry flag to also accept display offsets --- CHANGELOG.md | 1 + command_line.c | 37 +++++++++++++++++++++---------------- command_line.h | 4 ++++ main.c | 6 ++++-- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8cad61..c4b6f7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/command_line.c b/command_line.c index 872717c..d1325fe 100644 --- a/command_line.c +++ b/command_line.c @@ -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': diff --git a/command_line.h b/command_line.h index 5a98923..b65483a 100644 --- a/command_line.h +++ b/command_line.h @@ -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. */ diff --git a/main.c b/main.c index 886676f..8ffec77 100644 --- a/main.c +++ b/main.c @@ -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);