mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
fix: slow code from llucioc >:(
This commit is contained in:
parent
f1cee25e62
commit
4ed39f6a0c
2 changed files with 55 additions and 95 deletions
|
|
@ -201,13 +201,10 @@ typedef struct {
|
||||||
char name[64];
|
char name[64];
|
||||||
uint32_t thumb[WALLPAPER_THUMB_W * WALLPAPER_THUMB_H];
|
uint32_t thumb[WALLPAPER_THUMB_W * WALLPAPER_THUMB_H];
|
||||||
_Bool valid;
|
_Bool valid;
|
||||||
_Bool thumb_loaded;
|
|
||||||
} wallpaper_entry_t;
|
} wallpaper_entry_t;
|
||||||
|
|
||||||
static wallpaper_entry_t wallpapers[MAX_WALLPAPERS];
|
static wallpaper_entry_t wallpapers[MAX_WALLPAPERS];
|
||||||
static int wallpaper_count = 0;
|
static int wallpaper_count = 0;
|
||||||
static _Bool wallpapers_scanned = 0;
|
|
||||||
static int next_wallpaper_thumb = 0;
|
|
||||||
|
|
||||||
static _Bool desktop_snap_to_grid = 1;
|
static _Bool desktop_snap_to_grid = 1;
|
||||||
static _Bool desktop_auto_align = 1;
|
static _Bool desktop_auto_align = 1;
|
||||||
|
|
@ -410,15 +407,9 @@ static void load_settings_icons(void) {
|
||||||
static void decode_wallpapers_task(void *arg) {
|
static void decode_wallpapers_task(void *arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
wallpaper_count = 0;
|
wallpaper_count = 0;
|
||||||
next_wallpaper_thumb = 0;
|
|
||||||
wallpapers_scanned = 0;
|
|
||||||
|
|
||||||
FAT32_FileInfo info[MAX_WALLPAPERS];
|
FAT32_FileInfo info[MAX_WALLPAPERS];
|
||||||
int count = sys_list("/Library/images/Wallpapers", info, MAX_WALLPAPERS);
|
int count = sys_list("/Library/images/Wallpapers", info, MAX_WALLPAPERS);
|
||||||
if (count < 0) {
|
if (count < 0) return;
|
||||||
wallpapers_scanned = 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < count && wallpaper_count < MAX_WALLPAPERS; i++) {
|
for (int i = 0; i < count && wallpaper_count < MAX_WALLPAPERS; i++) {
|
||||||
if (info[i].is_directory) continue; // Skip directories
|
if (info[i].is_directory) continue; // Skip directories
|
||||||
|
|
@ -432,9 +423,6 @@ static void decode_wallpapers_task(void *arg) {
|
||||||
if (c1 != 'g' || c2 != 'p' || c3 != 'j') continue;
|
if (c1 != 'g' || c2 != 'p' || c3 != 'j') continue;
|
||||||
|
|
||||||
wallpaper_entry_t *wp = &wallpapers[wallpaper_count];
|
wallpaper_entry_t *wp = &wallpapers[wallpaper_count];
|
||||||
wp->valid = 0;
|
|
||||||
wp->thumb_loaded = 0;
|
|
||||||
|
|
||||||
// Set path
|
// Set path
|
||||||
char *pref = "/Library/images/Wallpapers/";
|
char *pref = "/Library/images/Wallpapers/";
|
||||||
int pl = 0; while (pref[pl]) { wp->path[pl] = pref[pl]; pl++; }
|
int pl = 0; while (pref[pl]) { wp->path[pl] = pref[pl]; pl++; }
|
||||||
|
|
@ -445,54 +433,23 @@ static void decode_wallpapers_task(void *arg) {
|
||||||
for (int j = 0; j < nl - 4 && j < 63; j++) wp->name[j] = info[i].name[j];
|
for (int j = 0; j < nl - 4 && j < 63; j++) wp->name[j] = info[i].name[j];
|
||||||
wp->name[(nl-4 < 63) ? nl-4 : 63] = 0;
|
wp->name[(nl-4 < 63) ? nl-4 : 63] = 0;
|
||||||
|
|
||||||
int tx = (wallpaper_count % 3) * (WALLPAPER_THUMB_W + 15);
|
|
||||||
int ty = (wallpaper_count / 3) * (WALLPAPER_THUMB_H + 30);
|
|
||||||
widget_button_init(&btn_wp_thumbs[wallpaper_count], 8 + tx, 306 + ty, WALLPAPER_THUMB_W + 8, WALLPAPER_THUMB_H + 26, "");
|
|
||||||
wallpaper_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
wallpapers_scanned = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void load_wallpapers(void) {
|
|
||||||
void *job_args[1] = { NULL };
|
|
||||||
sys_parallel_run(decode_wallpapers_task, job_args, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool load_next_wallpaper_thumb(void) {
|
|
||||||
if (!wallpapers_scanned) return false;
|
|
||||||
|
|
||||||
while (next_wallpaper_thumb < wallpaper_count) {
|
|
||||||
wallpaper_entry_t *wp = &wallpapers[next_wallpaper_thumb];
|
|
||||||
next_wallpaper_thumb++;
|
|
||||||
|
|
||||||
if (wp->thumb_loaded) continue;
|
|
||||||
wp->thumb_loaded = 1;
|
|
||||||
|
|
||||||
char cache_path[256];
|
char cache_path[256];
|
||||||
int cp = 0;
|
int cp = 0;
|
||||||
char *cpref = "/Library/Caches/Thumbnails/";
|
char *cpref = "/Library/Caches/Thumbnails/";
|
||||||
while (cpref[cp]) { cache_path[cp] = cpref[cp]; cp++; }
|
while (cpref[cp]) { cache_path[cp] = cpref[cp]; cp++; }
|
||||||
|
|
||||||
int prefix_len = 0;
|
|
||||||
char *pref = "/Library/images/Wallpapers/";
|
|
||||||
while (pref[prefix_len] && wp->path[prefix_len] == pref[prefix_len]) prefix_len++;
|
|
||||||
|
|
||||||
int cn = 0;
|
int cn = 0;
|
||||||
while (wp->path[prefix_len + cn]) { cache_path[cp + cn] = wp->path[prefix_len + cn]; cn++; }
|
while (info[i].name[cn]) { cache_path[cp+cn] = info[i].name[cn]; cn++; }
|
||||||
char *csuf = ".bin";
|
char *csuf = ".bin";
|
||||||
int cs = 0;
|
int cs = 0;
|
||||||
while (csuf[cs]) { cache_path[cp + cn + cs] = csuf[cs]; cs++; }
|
while (csuf[cs]) { cache_path[cp+cn+cs] = csuf[cs]; cs++; }
|
||||||
cache_path[cp + cn + cs] = 0;
|
cache_path[cp+cn+cs] = 0;
|
||||||
|
|
||||||
int cfd = sys_open(cache_path, "r");
|
int cfd = sys_open(cache_path, "r");
|
||||||
if (cfd >= 0) {
|
if (cfd >= 0) {
|
||||||
sys_read(cfd, wp->thumb, WALLPAPER_THUMB_W * WALLPAPER_THUMB_H * 4);
|
sys_read(cfd, wp->thumb, WALLPAPER_THUMB_W * WALLPAPER_THUMB_H * 4);
|
||||||
sys_close(cfd);
|
sys_close(cfd);
|
||||||
wp->valid = 1;
|
wp->valid = 1;
|
||||||
return true;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
int fd = sys_open(wp->path, "r");
|
int fd = sys_open(wp->path, "r");
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
int size = sys_seek(fd, 0, 2); // SEEK_END
|
int size = sys_seek(fd, 0, 2); // SEEK_END
|
||||||
|
|
@ -506,6 +463,7 @@ static bool load_next_wallpaper_thumb(void) {
|
||||||
if (img && img_w > 0 && img_h > 0) {
|
if (img && img_w > 0 && img_h > 0) {
|
||||||
scale_rgba_to_argb(img, img_w, img_h, wp->thumb, WALLPAPER_THUMB_W, WALLPAPER_THUMB_H);
|
scale_rgba_to_argb(img, img_w, img_h, wp->thumb, WALLPAPER_THUMB_W, WALLPAPER_THUMB_H);
|
||||||
wp->valid = 1;
|
wp->valid = 1;
|
||||||
|
stbi_image_free(img);
|
||||||
|
|
||||||
sys_mkdir("/Library/Caches");
|
sys_mkdir("/Library/Caches");
|
||||||
sys_mkdir("/Library/Caches/Thumbnails");
|
sys_mkdir("/Library/Caches/Thumbnails");
|
||||||
|
|
@ -515,17 +473,26 @@ static bool load_next_wallpaper_thumb(void) {
|
||||||
sys_close(swfd);
|
sys_close(swfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (img) stbi_image_free(img);
|
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sys_close(fd);
|
sys_close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
wallpaper_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void load_wallpapers(void) {
|
||||||
|
void *job_args[1] = { NULL };
|
||||||
|
sys_parallel_run(decode_wallpapers_task, job_args, 1);
|
||||||
|
|
||||||
|
for (int i = 0; i < wallpaper_count; i++) {
|
||||||
|
int tx = (i % 3) * (WALLPAPER_THUMB_W + 15);
|
||||||
|
int ty = (i / 3) * (WALLPAPER_THUMB_H + 30);
|
||||||
|
widget_button_init(&btn_wp_thumbs[i], 8 + tx, 306 + ty, WALLPAPER_THUMB_W + 8, WALLPAPER_THUMB_H + 20, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t parse_rgb_separate(const char *r, const char *g, const char *b) {
|
static uint32_t parse_rgb_separate(const char *r, const char *g, const char *b) {
|
||||||
|
|
@ -1242,12 +1209,7 @@ static void control_panel_handle_mouse(int x, int y, bool is_down, bool is_click
|
||||||
|
|
||||||
if (current_view == VIEW_MAIN) {
|
if (current_view == VIEW_MAIN) {
|
||||||
if (widget_button_handle_mouse(&btn_main_wallpaper, x, y, is_down, is_click, NULL)) {
|
if (widget_button_handle_mouse(&btn_main_wallpaper, x, y, is_down, is_click, NULL)) {
|
||||||
if (is_click) {
|
if (is_click) { current_view = VIEW_WALLPAPER; focused_field = -1; btn_main_wallpaper.pressed = false; }
|
||||||
current_view = VIEW_WALLPAPER;
|
|
||||||
focused_field = -1;
|
|
||||||
btn_main_wallpaper.pressed = false;
|
|
||||||
load_wallpapers();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (widget_button_handle_mouse(&btn_main_network, x, y, is_down, is_click, NULL)) {
|
if (widget_button_handle_mouse(&btn_main_network, x, y, is_down, is_click, NULL)) {
|
||||||
|
|
@ -1464,6 +1426,8 @@ int main(int argc, char **argv) {
|
||||||
control_panel_paint(win);
|
control_panel_paint(win);
|
||||||
ui_mark_dirty(win, 0, 0, 350, 500);
|
ui_mark_dirty(win, 0, 0, 350, 500);
|
||||||
|
|
||||||
|
load_wallpapers(); // load after first paint to avoid startup delay
|
||||||
|
|
||||||
gui_event_t ev;
|
gui_event_t ev;
|
||||||
while (1) {
|
while (1) {
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
|
|
@ -1473,11 +1437,12 @@ int main(int argc, char **argv) {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
|
||||||
} else if (ev.type == GUI_EVENT_CLICK ||
|
} else if (ev.type == GUI_EVENT_CLICK ||
|
||||||
|
ev.type == GUI_EVENT_MOUSE_DOWN ||
|
||||||
ev.type == GUI_EVENT_MOUSE_MOVE ||
|
ev.type == GUI_EVENT_MOUSE_MOVE ||
|
||||||
ev.type == GUI_EVENT_MOUSE_UP) {
|
ev.type == GUI_EVENT_MOUSE_UP) {
|
||||||
bool down = false;
|
bool down = false;
|
||||||
|
|
||||||
if (ev.type == GUI_EVENT_CLICK) {
|
if (ev.type == GUI_EVENT_MOUSE_DOWN || ev.type == GUI_EVENT_CLICK) {
|
||||||
down = true;
|
down = true;
|
||||||
} else if (ev.type == GUI_EVENT_MOUSE_MOVE) {
|
} else if (ev.type == GUI_EVENT_MOUSE_MOVE) {
|
||||||
down = (ev.arg3 & 1);
|
down = (ev.arg3 & 1);
|
||||||
|
|
@ -1485,7 +1450,6 @@ int main(int argc, char **argv) {
|
||||||
down = false;
|
down = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.type != GUI_EVENT_MOUSE_MOVE || down) {
|
|
||||||
control_panel_handle_mouse(
|
control_panel_handle_mouse(
|
||||||
ev.arg1,
|
ev.arg1,
|
||||||
ev.arg2,
|
ev.arg2,
|
||||||
|
|
@ -1493,7 +1457,6 @@ int main(int argc, char **argv) {
|
||||||
ev.type == GUI_EVENT_CLICK
|
ev.type == GUI_EVENT_CLICK
|
||||||
);
|
);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
|
||||||
|
|
||||||
} else if (ev.type == GUI_EVENT_MOUSE_WHEEL) {
|
} else if (ev.type == GUI_EVENT_MOUSE_WHEEL) {
|
||||||
if (current_view == VIEW_FONTS) {
|
if (current_view == VIEW_FONTS) {
|
||||||
|
|
@ -1526,15 +1489,10 @@ int main(int argc, char **argv) {
|
||||||
control_panel_paint(win);
|
control_panel_paint(win);
|
||||||
ui_mark_dirty(win, 0, 0, 350, 500);
|
ui_mark_dirty(win, 0, 0, 350, 500);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (current_view == VIEW_WALLPAPER && load_next_wallpaper_thumb()) {
|
|
||||||
control_panel_paint(win);
|
|
||||||
ui_mark_dirty(win, 0, 0, 350, 500);
|
|
||||||
} else {
|
} else {
|
||||||
sleep(10);
|
sleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,8 @@
|
||||||
#define SYSTEM_CMD_NETWORK_GET_NIC_NAME 48
|
#define SYSTEM_CMD_NETWORK_GET_NIC_NAME 48
|
||||||
#define SYSTEM_CMD_SET_KEYBOARD_LAYOUT 49
|
#define SYSTEM_CMD_SET_KEYBOARD_LAYOUT 49
|
||||||
#define SYSTEM_CMD_GET_KEYBOARD_LAYOUT 51
|
#define SYSTEM_CMD_GET_KEYBOARD_LAYOUT 51
|
||||||
|
#define SYSTEM_CMD_SET_MOUSE_CURSOR_SCALE 52
|
||||||
|
#define SYSTEM_CMD_GET_MOUSE_CURSOR_SCALE 53
|
||||||
#define SYSTEM_CMD_SET_TEXT_COLOR 29
|
#define SYSTEM_CMD_SET_TEXT_COLOR 29
|
||||||
#define SYSTEM_CMD_SET_WALLPAPER_PATH 31
|
#define SYSTEM_CMD_SET_WALLPAPER_PATH 31
|
||||||
#define SYSTEM_CMD_RTC_SET 32
|
#define SYSTEM_CMD_RTC_SET 32
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue