:: commit aaa500ba70382d84611c9490356f2cef38565314

iretq <me@iretq.dev> — 2025-12-08 08:26

parents: e6bd838bc6

lib/gterm: Support framebuffer rotation

diff --git a/CONFIG.md b/CONFIG.md
index 72fadffe..c0b93832 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -120,6 +120,8 @@ Limine interface control options:
   Limine will pick a resolution automatically. If the resolution is not
   available, Limine will pick another one automatically. Ignored if using text
   mode.
+* `interface_rotation` - Specifies the rotation of the Limine interface.
+  It can be any of the following values: `0`, `90`, `180`, `270`. Default is `0`.
 * `interface_branding` - A string that will be displayed on top of the Limine
   interface.
 * `interface_branding_colour` - A value between 0 and 7 specifying the colour
diff --git a/bootstrap b/bootstrap
index 81c910a4..000d4781 100755
--- a/bootstrap
+++ b/bootstrap
@@ -104,7 +104,7 @@ if ! test -f version; then
     clone_repo_commit \
         https://codeberg.org/Mintsuki/Flanterm.git \
         flanterm \
-        ea6a6cdecf3b830f2a8cb4ffe3e58098937224c3
+        f9d424145bdde18872714094434797e2f44ff5b4
 
     download_by_hash \
         https://github.com/nothings/stb/raw/5c205738c191bcb0abc65c4febfa9bd25ff35234/stb_image.h \
diff --git a/common/lib/gterm.c b/common/lib/gterm.c
index 5449626b..fae0612c 100644
--- a/common/lib/gterm.c
+++ b/common/lib/gterm.c
@@ -525,6 +525,18 @@ bool gterm_init(struct fb_info **_fbs, size_t *_fbs_count,
     margin = 64;
     margin_gradient = 4;
 
+    int fb_rotation = FLANTERM_FB_ROTATE_0;
+    char *rotation_str = config_get_value(config, 0, "INTERFACE_ROTATION");
+    if (rotation_str != NULL) {
+        int rotation_val = strtoui(rotation_str, NULL, 10);
+        switch (rotation_val) {
+            case 90: fb_rotation = FLANTERM_FB_ROTATE_90; break;
+            case 180: fb_rotation = FLANTERM_FB_ROTATE_180; break;
+            case 270: fb_rotation = FLANTERM_FB_ROTATE_270; break;
+        }
+        pmm_free(rotation_str, strlen(rotation_str) + 1);
+    }
+
     uint32_t ansi_colours[8];
 
     ansi_colours[0] = 0x00000000; // black
@@ -713,6 +725,12 @@ no_load_font:;
             continue;
         }
 
+        if (fb_rotation == FLANTERM_FB_ROTATE_90 || fb_rotation == FLANTERM_FB_ROTATE_270) {
+            uint64_t tmp = fb->framebuffer_width;
+            fb->framebuffer_width = fb->framebuffer_height;
+            fb->framebuffer_height = tmp;
+        }
+
         if (background != NULL) {
             char *background_layout = config_get_value(config, 0, "WALLPAPER_STYLE");
             if (background_layout != NULL && strcmp(background_layout, "centered") == 0) {
@@ -740,6 +758,12 @@ no_load_font:;
             }
         }
 
+        if (fb_rotation == FLANTERM_FB_ROTATE_90 || fb_rotation == FLANTERM_FB_ROTATE_270) {
+            uint64_t tmp = fb->framebuffer_width;
+            fb->framebuffer_width = fb->framebuffer_height;
+            fb->framebuffer_height = tmp;
+        }
+
         terms[terms_i] = flanterm_fb_init(ext_mem_alloc,
                             pmm_free,
                             (void *)(uintptr_t)fb->framebuffer_addr,
@@ -753,7 +777,7 @@ no_load_font:;
                             &default_bg_bright, &default_fg_bright,
                             font, font_width, font_height, font_spacing,
                             font_scale_x, font_scale_y,
-                            margin);
+                            margin, fb_rotation);
 
         if (terms[terms_i] != NULL) {
             terms_i++;
diff --git a/test/limine.c b/test/limine.c
index 8df7a35b..8254d5a0 100644
--- a/test/limine.c
+++ b/test/limine.c
@@ -311,7 +311,8 @@ static void limine_main(void) {
         NULL, NULL,
         NULL, 0, 0, 1,
         0, 0,
-        0
+        0,
+        FLANTERM_FB_ROTATE_0
     );
 
     uint64_t executable_slide = (uint64_t)executable_start - 0xffffffff80000000;
tab: 248 wrap: offon