diff --git a/CHANGELOG.md b/CHANGELOG.md index 25de4d3..7fabded 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ If a change only affects particular applications, they are listed in parentheses - fix: Use usleep to release CPU when possible (!31, thanks @uninsane) - feat(buffyboard): Add a buffyboard.service systemd service (!34, @uninsane) - fix(unl0kr): Select an available DRM device instead of a hard-coded one (!35, thanks @Sorcus) +- feat(unl0kr): Enable software rotation (!32, thanks @xs5871 & @craftyguy) ## 3.2.0 (2024-06-03) diff --git a/man/unl0kr.1.scd b/man/unl0kr.1.scd index 28e76f7..7aa9ed5 100644 --- a/man/unl0kr.1.scd +++ b/man/unl0kr.1.scd @@ -34,6 +34,14 @@ password is printed to STDOUT. All other output happens on STDERR. horizontally by X pixels and vertically by Y pixels. *-d --dpi=N* Override the display's DPI value. +*-r, --rotate=[0-3]* + Rotate the UI to the given orientation. The + values match the ones provided by the kernel in + /sys/class/graphics/fbcon/rotate. + * 0 - normal orientation (0 degree) + * 1 - clockwise orientation (90 degrees) + * 2 - upside down orientation (180 degrees) + * 3 - counterclockwise orientation (270 degrees) *-h, --help* Print this message and exit. *-v, --verbose* diff --git a/unl0kr/README.md b/unl0kr/README.md index 09eaae7..c0338d2 100644 --- a/unl0kr/README.md +++ b/unl0kr/README.md @@ -61,6 +61,13 @@ Mandatory arguments to long options are mandatory for short options too. vertical pixels, offset horizontally by X pixels and vertically by Y pixels -d --dpi=N Override the display's DPI value + -r, --rotate=[0-3] Rotate the UI to the given orientation. The + values match the ones provided by the kernel in + /sys/class/graphics/fbcon/rotate. + * 0 - normal orientation (0 degree) + * 1 - clockwise orientation (90 degrees) + * 2 - upside down orientation (180 degrees) + * 3 - counterclockwise orientation (270 degrees) -h, --help Print this message and exit -v, --verbose Enable more detailed logging output on STDERR -V, --version Print the unl0kr version and exit diff --git a/unl0kr/command_line.c b/unl0kr/command_line.c index 1f245c6..9d8f4c5 100644 --- a/unl0kr/command_line.c +++ b/unl0kr/command_line.c @@ -44,6 +44,7 @@ static void init_opts(ul_cli_opts *opts) { opts->x_offset = 0; opts->y_offset = 0; opts->dpi = 0; + opts->rotation = LV_DISPLAY_ROTATION_0; opts->verbose = false; } @@ -68,6 +69,13 @@ static void print_usage() { " vertical pixels, offset horizontally by X\n" " pixels and vertically by Y pixels\n" " -d --dpi=N Override the display's DPI value\n" + " -r, --rotate=[0-3] Rotate the UI to the given orientation. The\n" + " values match the ones provided by the kernel in\n" + " /sys/class/graphics/fbcon/rotate.\n" + " * 0 - normal orientation (0 degree)\n" + " * 1 - clockwise orientation (90 degrees)\n" + " * 2 - upside down orientation (180 degrees)\n" + " * 3 - counterclockwise orientation (270 degrees)\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"); @@ -86,6 +94,7 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) { { "config-override", required_argument, NULL, 'C' }, { "geometry", required_argument, NULL, 'g' }, { "dpi", required_argument, NULL, 'd' }, + { "rotate", required_argument, NULL, 'r' }, { "help", no_argument, NULL, 'h' }, { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, @@ -94,7 +103,7 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) { int opt, index = 0; - while ((opt = getopt_long(argc, argv, "C:g:d:hvV", long_opts, &index)) != -1) { + while ((opt = getopt_long(argc, argv, "C:g:d:r:hvV", long_opts, &index)) != -1) { switch (opt) { case 'C': opts->config_files = realloc(opts->config_files, (opts->num_config_files + 1) * sizeof(char *)); @@ -119,6 +128,28 @@ void ul_cli_parse_opts(int argc, char *argv[], ul_cli_opts *opts) { exit(EXIT_FAILURE); } break; + case 'r': { + int orientation; + if (sscanf(optarg, "%i", &orientation) != 1 || orientation < 0 || orientation > 3) { + fprintf(stderr, "Invalid orientation argument \"%s\"\n", optarg); + exit(EXIT_FAILURE); + } + switch (orientation) { + case 0: + opts->rotation = LV_DISPLAY_ROTATION_0; + break; + case 1: + opts->rotation = LV_DISPLAY_ROTATION_270; + break; + case 2: + opts->rotation = LV_DISPLAY_ROTATION_180; + break; + case 3: + opts->rotation = LV_DISPLAY_ROTATION_90; + break; + } + break; + } case 'h': print_usage(); exit(EXIT_SUCCESS); diff --git a/unl0kr/command_line.h b/unl0kr/command_line.h index 39cce8f..b9cea7e 100644 --- a/unl0kr/command_line.h +++ b/unl0kr/command_line.h @@ -8,6 +8,7 @@ #define UL_COMMAND_LINE_H #include +#include "lvgl/lvgl.h" /** * Options parsed from command line arguments @@ -27,6 +28,8 @@ typedef struct { int y_offset; /* DPI */ int dpi; + /* Display rotation */ + lv_display_rotation_t rotation; /* Verbose mode. If true, provide more detailed logging output on STDERR. */ bool verbose; } ul_cli_opts; diff --git a/unl0kr/lv_conf.h b/unl0kr/lv_conf.h index 438fddd..d2597e2 100644 --- a/unl0kr/lv_conf.h +++ b/unl0kr/lv_conf.h @@ -509,7 +509,7 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/ #define LV_USE_LINUX_FBDEV 1 #if LV_USE_LINUX_FBDEV #define LV_LINUX_FBDEV_BSD 0 - #define LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_DIRECT + #define LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_PARTIAL #define LV_LINUX_FBDEV_BUFFER_COUNT 0 #define LV_LINUX_FBDEV_BUFFER_SIZE 60 #endif diff --git a/unl0kr/main.c b/unl0kr/main.c index 42d6d6e..5e337e1 100644 --- a/unl0kr/main.c +++ b/unl0kr/main.c @@ -455,6 +455,9 @@ int main(int argc, char *argv[]) { lv_display_set_dpi(disp, cli_opts.dpi); } + /* Set up display rotation */ + lv_display_set_rotation(disp, cli_opts.rotation); + /* Store final display resolution for convenient later access */ const uint32_t hor_res = lv_disp_get_hor_res(disp); const uint32_t ver_res = lv_disp_get_ver_res(disp);