mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
html 2.0 compliance update browser
This commit is contained in:
parent
b708ad7e45
commit
41d1e3960b
13 changed files with 600 additions and 316 deletions
5
Makefile
5
Makefile
|
|
@ -165,8 +165,9 @@ clean:
|
|||
|
||||
run: $(ISO_IMAGE)
|
||||
qemu-system-x86_64 -m 2G -serial stdio -cdrom $< -boot d \
|
||||
-m 4G \
|
||||
-smp 4 -m 4G \
|
||||
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0 \
|
||||
-netdev user,id=net0,hostfwd=udp::12346-:12345 -device e1000,netdev=net0 \
|
||||
-vga std -global VGA.xres=1920 -global VGA.yres=1080 \
|
||||
-drive file=disk.img,format=raw,file.locking=off
|
||||
-drive file=disk.img,format=raw,file.locking=off \
|
||||
-cpu max
|
||||
BIN
boredos.iso
BIN
boredos.iso
Binary file not shown.
BIN
build/cmd.o
BIN
build/cmd.o
Binary file not shown.
BIN
build/explorer.o
BIN
build/explorer.o
Binary file not shown.
BIN
build/ps2.o
BIN
build/ps2.o
Binary file not shown.
|
|
@ -67,7 +67,8 @@ typedef struct {
|
|||
unsigned char *bitmap;
|
||||
} font_cache_entry_t;
|
||||
|
||||
static font_cache_entry_t g_font_cache[FONT_CACHE_SIZE];
|
||||
// Cache is disabled for now due to race conditions and collisions
|
||||
// static font_cache_entry_t g_font_cache[FONT_CACHE_SIZE];
|
||||
|
||||
bool font_manager_init(void) {
|
||||
// We'll load a default font later if available
|
||||
|
|
@ -141,34 +142,15 @@ void font_manager_render_char_scaled(ttf_font_t *font, int x, int y, char c, uin
|
|||
|
||||
stbtt_fontinfo *info = (stbtt_fontinfo *)font->info;
|
||||
|
||||
int cache_idx = ((unsigned char)c * 31 + (int)(scale * 17.0f)) % FONT_CACHE_SIZE;
|
||||
font_cache_entry_t *entry = &g_font_cache[cache_idx];
|
||||
|
||||
unsigned char *bitmap = NULL;
|
||||
int w, h, xoff, yoff;
|
||||
|
||||
if (entry->bitmap && entry->c == c && entry->pixel_height == scale) {
|
||||
bitmap = entry->bitmap;
|
||||
w = entry->w;
|
||||
h = entry->h;
|
||||
xoff = entry->xoff;
|
||||
yoff = entry->yoff;
|
||||
} else {
|
||||
float real_scale = stbtt_ScaleForPixelHeight(info, scale); // Convert pixel size back to stbtt scale
|
||||
bitmap = stbtt_GetCodepointBitmap(info, 0, real_scale, c, &w, &h, &xoff, &yoff);
|
||||
|
||||
if (entry->bitmap) {
|
||||
stbtt_FreeBitmap(entry->bitmap, NULL);
|
||||
}
|
||||
|
||||
entry->c = c;
|
||||
entry->pixel_height = scale;
|
||||
entry->w = w;
|
||||
entry->h = h;
|
||||
entry->xoff = xoff;
|
||||
entry->yoff = yoff;
|
||||
entry->bitmap = bitmap;
|
||||
}
|
||||
float real_scale = stbtt_ScaleForPixelHeight(info, scale); // Convert pixel size back to stbtt scale
|
||||
|
||||
int codepoint = (unsigned char)c;
|
||||
if (codepoint == 128) codepoint = 0x2014; // Unicode emdash
|
||||
|
||||
bitmap = stbtt_GetCodepointBitmap(info, 0, real_scale, codepoint, &w, &h, &xoff, &yoff);
|
||||
|
||||
if (bitmap) {
|
||||
for (int row = 0; row < h; row++) {
|
||||
|
|
@ -182,6 +164,7 @@ void font_manager_render_char_scaled(ttf_font_t *font, int x, int y, char c, uin
|
|||
}
|
||||
}
|
||||
}
|
||||
stbtt_FreeBitmap(bitmap, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +204,9 @@ int font_manager_get_string_width_scaled(ttf_font_t *font, const char *s, float
|
|||
int width = 0;
|
||||
while (*s) {
|
||||
int advance, lsb;
|
||||
stbtt_GetCodepointHMetrics(info, *s, &advance, &lsb);
|
||||
int codepoint = (unsigned char)*s;
|
||||
if (codepoint == 128) codepoint = 0x2014; // Unicode emdash
|
||||
stbtt_GetCodepointHMetrics(info, codepoint, &advance, &lsb);
|
||||
// Round per-character to match draw_string's accumulation
|
||||
width += (int)(advance * real_scale + 0.5f);
|
||||
s++;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#define GUI_CMD_DRAW_IMAGE 7
|
||||
#define GUI_CMD_GET_STRING_WIDTH 8
|
||||
#define GUI_CMD_GET_FONT_HEIGHT 9
|
||||
#define GUI_CMD_WINDOW_SET_RESIZABLE 14
|
||||
|
||||
#define GUI_EVENT_NONE 0
|
||||
#define GUI_EVENT_PAINT 1
|
||||
|
|
@ -24,6 +25,7 @@
|
|||
#define GUI_EVENT_MOUSE_UP 7
|
||||
#define GUI_EVENT_MOUSE_MOVE 8
|
||||
#define GUI_EVENT_KEYUP 10
|
||||
#define GUI_EVENT_RESIZE 11
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
|
|
|
|||
|
|
@ -132,6 +132,26 @@ static void user_window_key(Window *win, char c, bool pressed) {
|
|||
process_push_gui_event(proc, &ev);
|
||||
}
|
||||
|
||||
static void user_window_resize(Window *win, int w, int h) {
|
||||
if (!win) return;
|
||||
if (w <= 0 || h <= 0) return;
|
||||
|
||||
extern void* kmalloc(size_t size);
|
||||
extern void kfree(void* ptr);
|
||||
extern void serial_write(const char *str);
|
||||
|
||||
|
||||
if (win->pixels) kfree(win->pixels);
|
||||
if (win->comp_pixels) kfree(win->comp_pixels);
|
||||
|
||||
win->pixels = (uint32_t *)kmalloc(w * h * sizeof(uint32_t));
|
||||
win->comp_pixels = (uint32_t *)kmalloc(w * h * sizeof(uint32_t));
|
||||
|
||||
if (win->pixels) {
|
||||
for (int i = 0; i < w * h; i++) win->pixels[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) {
|
||||
extern void cmd_write(const char *str);
|
||||
|
|
@ -244,8 +264,8 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6
|
|||
win->handle_right_click = user_window_right_click;
|
||||
win->handle_close = user_window_close;
|
||||
win->handle_key = user_window_key;
|
||||
win->handle_resize = NULL;
|
||||
win->resizable = false;
|
||||
win->handle_resize = user_window_resize;
|
||||
win->resizable = false; // Default to false, can be enabled via syscall
|
||||
|
||||
proc->ui_window = win;
|
||||
wm_add_window(win);
|
||||
|
|
@ -523,11 +543,44 @@ static uint64_t syscall_handler_inner(uint64_t syscall_num, uint64_t arg1, uint6
|
|||
} else if (cmd == GUI_CMD_GET_FONT_HEIGHT) {
|
||||
extern int graphics_get_font_height(void);
|
||||
return (uint64_t)graphics_get_font_height();
|
||||
|
||||
} else if (cmd == 14) { // GUI_CMD_WINDOW_SET_RESIZABLE
|
||||
Window *win = (Window *)arg2;
|
||||
if (win) {
|
||||
extern void serial_write(const char *str);
|
||||
serial_write("Kernel: Setting window resizable to ");
|
||||
serial_write(arg3 ? "true\n" : "false\n");
|
||||
win->resizable = (arg3 != 0);
|
||||
}
|
||||
return 0;
|
||||
} else if (cmd == 13) { // GUI_CMD_GET_FONT_HEIGHT_SCALED
|
||||
uint32_t scale_bits = (uint32_t)arg2;
|
||||
float scale = *(float*)&scale_bits;
|
||||
extern int graphics_get_font_height_scaled(float scale);
|
||||
return (uint64_t)graphics_get_font_height_scaled(scale);
|
||||
} else if (cmd == 15) { // GUI_CMD_WINDOW_SET_TITLE
|
||||
Window *win = (Window *)arg2;
|
||||
const char *user_title = (const char *)arg3;
|
||||
if (win && user_title) {
|
||||
int title_len = 0;
|
||||
while (user_title[title_len] && title_len < 255) title_len++;
|
||||
|
||||
char *kernel_title = kmalloc(title_len + 1);
|
||||
if (kernel_title) {
|
||||
for (int i = 0; i < title_len; i++) {
|
||||
kernel_title[i] = user_title[i];
|
||||
}
|
||||
kernel_title[title_len] = '\0';
|
||||
|
||||
if (win->title && win->title != (char*)"Unknown") {
|
||||
kfree(win->title);
|
||||
}
|
||||
win->title = kernel_title;
|
||||
wm_mark_dirty(win->x, win->y - 20, win->w, 20); // Mark title bar dirty
|
||||
wm_refresh();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} else if (syscall_num == SYS_FS) {
|
||||
int cmd = (int)arg1;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -75,3 +75,11 @@ uint32_t ui_get_font_height_scaled(float scale) {
|
|||
uint32_t scale_bits = *(uint32_t*)&scale;
|
||||
return (uint32_t)syscall3(SYS_GUI, GUI_CMD_GET_FONT_HEIGHT_SCALED, (uint64_t)scale_bits, 0);
|
||||
}
|
||||
|
||||
void ui_window_set_title(ui_window_t win, const char *title) {
|
||||
syscall3(SYS_GUI, GUI_CMD_WINDOW_SET_TITLE, (uint64_t)win, (uint64_t)title);
|
||||
}
|
||||
|
||||
void ui_window_set_resizable(ui_window_t win, bool resizable) {
|
||||
syscall3(SYS_GUI, GUI_CMD_WINDOW_SET_RESIZABLE, (uint64_t)win, resizable ? 1 : 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,12 @@
|
|||
#define GUI_CMD_DRAW_IMAGE 7
|
||||
#define GUI_CMD_GET_STRING_WIDTH 8
|
||||
#define GUI_CMD_GET_FONT_HEIGHT 9
|
||||
#define GUI_CMD_WINDOW_SET_RESIZABLE 14
|
||||
#define GUI_CMD_DRAW_STRING_BITMAP 10
|
||||
#define GUI_CMD_DRAW_STRING_SCALED 11
|
||||
#define GUI_CMD_GET_STRING_WIDTH_SCALED 12
|
||||
#define GUI_CMD_GET_FONT_HEIGHT_SCALED 13
|
||||
#define GUI_CMD_WINDOW_SET_TITLE 15
|
||||
|
||||
// Event Types
|
||||
#define GUI_EVENT_NONE 0
|
||||
|
|
@ -32,6 +34,7 @@
|
|||
#define GUI_EVENT_MOUSE_UP 7
|
||||
#define GUI_EVENT_MOUSE_MOVE 8
|
||||
#define GUI_EVENT_MOUSE_WHEEL 9
|
||||
#define GUI_EVENT_RESIZE 11
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
|
|
@ -59,5 +62,7 @@ void ui_draw_string_bitmap(ui_window_t win, int x, int y, const char *str, uint3
|
|||
void ui_draw_string_scaled(ui_window_t win, int x, int y, const char *str, uint32_t color, float scale);
|
||||
uint32_t ui_get_string_width_scaled(const char *str, float scale);
|
||||
uint32_t ui_get_font_height_scaled(float scale);
|
||||
void ui_window_set_title(ui_window_t win, const char *title);
|
||||
void ui_window_set_resizable(ui_window_t win, bool resizable);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -55,25 +55,17 @@ void *malloc(size_t size) {
|
|||
|
||||
size = ALIGN8(size);
|
||||
|
||||
// Best-fit search
|
||||
BlockMeta *best = NULL;
|
||||
// First-fit search (faster than best-fit for large heaps)
|
||||
BlockMeta *current = heap_head;
|
||||
while (current) {
|
||||
if (current->free && current->size >= size) {
|
||||
if (!best || current->size < best->size) {
|
||||
best = current;
|
||||
if (best->size == size) break; // Perfect fit
|
||||
}
|
||||
split_block(current, size);
|
||||
current->free = 0;
|
||||
return (current + 1);
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
if (best) {
|
||||
split_block(best, size);
|
||||
best->free = 0;
|
||||
return (best + 1);
|
||||
}
|
||||
|
||||
// No suitable block found, request more space
|
||||
BlockMeta *block = request_space(size);
|
||||
if (!block) return NULL;
|
||||
|
|
|
|||
|
|
@ -1894,6 +1894,18 @@ void wm_handle_right_click(int x, int y) {
|
|||
if (drag_window->handle_resize) {
|
||||
drag_window->handle_resize(drag_window, new_w, new_h);
|
||||
}
|
||||
|
||||
// Push resize event to userland process if it has one
|
||||
process_t *proc = process_get_by_ui_window(drag_window);
|
||||
if (proc) {
|
||||
gui_event_t ev;
|
||||
ev.type = 11; // GUI_EVENT_RESIZE
|
||||
ev.arg1 = new_w;
|
||||
ev.arg2 = new_h;
|
||||
ev.arg3 = 0;
|
||||
process_push_gui_event(proc, &ev);
|
||||
}
|
||||
|
||||
force_redraw = true;
|
||||
}
|
||||
} else if (left && !is_dragging && !is_resizing && !is_dragging_file && (dx != 0 || dy != 0)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue