fix: various bug fixes in desktop components
This commit is contained in:
@@ -61,8 +61,13 @@ void desktop_scan_apps(DesktopState* ds) {
|
||||
if (sz == 0 || sz > 4096) { montauk::close(fh); continue; }
|
||||
|
||||
char* text = (char*)montauk::malloc(sz + 1);
|
||||
montauk::read(fh, (uint8_t*)text, 0, sz);
|
||||
if (!text) { montauk::close(fh); continue; }
|
||||
int bytes_read = montauk::read(fh, (uint8_t*)text, 0, sz);
|
||||
montauk::close(fh);
|
||||
if (bytes_read != (int)sz) {
|
||||
montauk::mfree(text);
|
||||
continue;
|
||||
}
|
||||
text[sz] = '\0';
|
||||
|
||||
auto doc = montauk::toml::parse(text);
|
||||
@@ -77,6 +82,10 @@ void desktop_scan_apps(DesktopState* ds) {
|
||||
const char* category = doc.get_string("menu.category", "Applications");
|
||||
bool visible = doc.get_bool("menu.visible", true);
|
||||
bool launch_with_home = doc.get_bool("launch.pass_home_dir", true);
|
||||
if (binary[0] == '\0') {
|
||||
doc.destroy();
|
||||
continue;
|
||||
}
|
||||
|
||||
montauk::strncpy(app->name, name, sizeof(app->name));
|
||||
montauk::strncpy(app->category, category, sizeof(app->category));
|
||||
@@ -154,6 +163,9 @@ void desktop_build_menu(DesktopState* ds) {
|
||||
void gui::desktop_init(DesktopState* ds) {
|
||||
ds->screen_w = ds->fb.width();
|
||||
ds->screen_h = ds->fb.height();
|
||||
ds->background_cache = nullptr;
|
||||
ds->background_cache_pitch = ds->fb.pitch();
|
||||
ds->background_cache_dirty = true;
|
||||
|
||||
// Immediately clear the screen to hide flanterm boot text
|
||||
ds->fb.clear(colors::DESKTOP_BG);
|
||||
@@ -355,9 +367,41 @@ static void desktop_clear_window_dirty(DesktopState* ds) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool desktop_panel_refresh_due(const DesktopState* ds, uint64_t now) {
|
||||
static bool desktop_netcfg_equal(const Montauk::NetCfg& a, const Montauk::NetCfg& b) {
|
||||
if (a.ipAddress != b.ipAddress || a.subnetMask != b.subnetMask ||
|
||||
a.gateway != b.gateway || a.dnsServer != b.dnsServer) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (a.macAddress[i] != b.macAddress[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool desktop_refresh_panel_state(DesktopState* ds, uint64_t now) {
|
||||
if (ds->screen_locked) return false;
|
||||
return (now - ds->net_cfg_last_poll > 5000) || (now - ds->vol_last_poll > 5000);
|
||||
|
||||
bool changed = false;
|
||||
if (now - ds->net_cfg_last_poll > 5000) {
|
||||
Montauk::NetCfg next;
|
||||
montauk::get_netcfg(&next);
|
||||
if (!desktop_netcfg_equal(next, ds->cached_net_cfg)) {
|
||||
ds->cached_net_cfg = next;
|
||||
changed = true;
|
||||
}
|
||||
ds->net_cfg_last_poll = now;
|
||||
}
|
||||
|
||||
if (now - ds->vol_last_poll > 5000) {
|
||||
int v = montauk::audio_get_volume(0);
|
||||
if (v >= 0 && !ds->vol_muted && v != ds->vol_level) {
|
||||
ds->vol_level = v;
|
||||
changed = true;
|
||||
}
|
||||
ds->vol_last_poll = now;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
@@ -386,7 +430,12 @@ bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
montauk::strncpy(ds->windows[i].title, extWins[e].title, MAX_TITLE_LEN);
|
||||
if (!montauk::streq(ds->windows[i].title, extWins[e].title)) {
|
||||
montauk::strncpy(ds->windows[i].title, extWins[e].title, MAX_TITLE_LEN);
|
||||
if (ds->windows[i].state != WIN_MINIMIZED && ds->windows[i].state != WIN_CLOSED) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
// Update dirty flag and cursor
|
||||
if (extWins[e].dirty) {
|
||||
ds->windows[i].dirty = true;
|
||||
@@ -405,9 +454,8 @@ bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
currentVa = 0;
|
||||
}
|
||||
|
||||
uint64_t va = montauk::win_map(extId);
|
||||
if (!remapRequested && va != 0 && va != currentVa) {
|
||||
montauk::win_unmap(extId);
|
||||
uint64_t va = currentVa;
|
||||
if (remapRequested || currentVa == 0) {
|
||||
va = montauk::win_map(extId);
|
||||
}
|
||||
|
||||
@@ -416,7 +464,6 @@ bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
ds->windows[i].content_w = extWins[e].width;
|
||||
ds->windows[i].content_h = extWins[e].height;
|
||||
ds->windows[i].dirty = true;
|
||||
montauk::strncpy(ds->windows[i].title, extWins[e].title, MAX_TITLE_LEN);
|
||||
changed = true;
|
||||
// Clear from closing list if the slot was reused
|
||||
for (int c = 0; c < ds->closing_ext_count; c++) {
|
||||
@@ -532,6 +579,7 @@ bool desktop_poll_external_windows(DesktopState* ds) {
|
||||
|
||||
void gui::desktop_run(DesktopState* ds) {
|
||||
uint64_t lastClockToken = 0;
|
||||
uint64_t nextClockPollMs = 0;
|
||||
uint64_t lastLauncherBlinkToken = ~0ull;
|
||||
uint64_t inputSerial = montauk::input_wait(0, 0);
|
||||
bool firstFrame = true;
|
||||
@@ -588,7 +636,7 @@ void gui::desktop_run(DesktopState* ds) {
|
||||
}
|
||||
|
||||
uint64_t now = montauk::get_milliseconds();
|
||||
sceneChanged |= desktop_panel_refresh_due(ds, now);
|
||||
sceneChanged |= desktop_refresh_panel_state(ds, now);
|
||||
|
||||
uint64_t launcherBlinkToken = desktop_launcher_blink_token(ds, now);
|
||||
if (launcherBlinkToken != lastLauncherBlinkToken) {
|
||||
@@ -596,10 +644,13 @@ void gui::desktop_run(DesktopState* ds) {
|
||||
sceneChanged = true;
|
||||
}
|
||||
|
||||
uint64_t clockToken = desktop_clock_token();
|
||||
if (clockToken != lastClockToken) {
|
||||
lastClockToken = clockToken;
|
||||
sceneChanged = true;
|
||||
if (now >= nextClockPollMs) {
|
||||
nextClockPollMs = now + 1000;
|
||||
uint64_t clockToken = desktop_clock_token();
|
||||
if (clockToken != lastClockToken) {
|
||||
lastClockToken = clockToken;
|
||||
sceneChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
sceneChanged |= desktop_has_visible_dirty_window(ds);
|
||||
|
||||
Reference in New Issue
Block a user