fix: various bug fixes in desktop components

This commit is contained in:
2026-05-07 20:00:17 +02:00
parent d04d7194b9
commit 60ee905552
12 changed files with 311 additions and 85 deletions
+45 -7
View File
@@ -149,26 +149,24 @@ void desktop_draw_lock_screen(DesktopState* ds) {
// Desktop Composition
// ============================================================================
void gui::desktop_compose(DesktopState* ds) {
Framebuffer& fb = ds->fb;
void desktop_mark_background_dirty(DesktopState* ds) {
if (ds) ds->background_cache_dirty = true;
}
// Desktop background gradient
static void desktop_render_background_to(uint32_t* buf, int pitch, DesktopState* ds) {
int sw = ds->screen_w;
int sh = ds->screen_h;
int grad_start = PANEL_HEIGHT;
int grad_range = sh - grad_start;
if (grad_range < 1) grad_range = 1;
uint32_t* buf = fb.buffer();
int pitch = fb.pitch();
for (int y = 0; y < sh; y++) {
uint32_t* row = (uint32_t*)((uint8_t*)buf + y * pitch);
if (ds->settings.bg_image && ds->settings.bg_wallpaper) {
// Wallpaper covers the entire screen; panel draws on top
uint32_t* wp = ds->settings.bg_wallpaper + y * ds->settings.bg_wallpaper_w;
int cw = sw < ds->settings.bg_wallpaper_w ? sw : ds->settings.bg_wallpaper_w;
for (int x = 0; x < cw; x++) row[x] = wp[x];
montauk::memcpy(row, wp, (uint64_t)cw * sizeof(uint32_t));
} else if (y < grad_start) {
// Panel area - will be overwritten by panel drawing
uint32_t px = ds->settings.panel_color.to_pixel();
@@ -187,6 +185,46 @@ void gui::desktop_compose(DesktopState* ds) {
for (int x = 0; x < sw; x++) row[x] = px;
}
}
}
static bool desktop_prepare_background_cache(DesktopState* ds) {
if (!ds) return false;
int pitch = ds->fb.pitch();
uint64_t bytes = (uint64_t)ds->screen_h * (uint64_t)pitch;
if (!ds->background_cache) {
ds->background_cache = (uint32_t*)montauk::alloc(bytes);
if (!ds->background_cache) return false;
ds->background_cache_pitch = pitch;
ds->background_cache_dirty = true;
}
if (ds->background_cache_pitch != pitch) {
montauk::free(ds->background_cache);
ds->background_cache = (uint32_t*)montauk::alloc(bytes);
if (!ds->background_cache) return false;
ds->background_cache_pitch = pitch;
ds->background_cache_dirty = true;
}
if (ds->background_cache_dirty) {
desktop_render_background_to(ds->background_cache, ds->background_cache_pitch, ds);
ds->background_cache_dirty = false;
}
return true;
}
void gui::desktop_compose(DesktopState* ds) {
Framebuffer& fb = ds->fb;
int sw = ds->screen_w;
int sh = ds->screen_h;
if (desktop_prepare_background_cache(ds))
fb.copy_from(ds->background_cache, ds->background_cache_pitch);
else
desktop_render_background_to(fb.buffer(), fb.pitch(), ds);
// Lock screen: draw overlay and card, then cursor, and return early
if (ds->screen_locked) {