mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
BFIX: Fix gpf's in .elf applications
This commit is contained in:
parent
b7020152c1
commit
70cd296d19
3 changed files with 42 additions and 28 deletions
|
|
@ -589,6 +589,8 @@ uint64_t process_terminate_current(void) {
|
||||||
// Mark slot as free
|
// Mark slot as free
|
||||||
to_delete->pid = 0xFFFFFFFF;
|
to_delete->pid = 0xFFFFFFFF;
|
||||||
to_delete->cpu_affinity = 0xFFFFFFFF;
|
to_delete->cpu_affinity = 0xFFFFFFFF;
|
||||||
|
to_delete->ui_window = NULL;
|
||||||
|
to_delete->is_terminal_proc = false;
|
||||||
|
|
||||||
// 4. Load context for the NEXT process
|
// 4. Load context for the NEXT process
|
||||||
if (current_process[my_cpu]->is_user && current_process[my_cpu]->kernel_stack) {
|
if (current_process[my_cpu]->is_user && current_process[my_cpu]->kernel_stack) {
|
||||||
|
|
|
||||||
|
|
@ -40,49 +40,49 @@ void syscall_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_close(Window *win) {
|
static void user_window_close(Window *win) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = GUI_EVENT_CLOSE };
|
gui_event_t ev = { .type = GUI_EVENT_CLOSE };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_paint(Window *win) {
|
static void user_window_paint(Window *win) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = GUI_EVENT_PAINT };
|
gui_event_t ev = { .type = GUI_EVENT_PAINT };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_click(Window *win, int x, int y) {
|
static void user_window_click(Window *win, int x, int y) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = GUI_EVENT_CLICK, .arg1 = x, .arg2 = y };
|
gui_event_t ev = { .type = GUI_EVENT_CLICK, .arg1 = x, .arg2 = y };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_right_click(Window *win, int x, int y) {
|
static void user_window_right_click(Window *win, int x, int y) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = GUI_EVENT_RIGHT_CLICK, .arg1 = x, .arg2 = y };
|
gui_event_t ev = { .type = GUI_EVENT_RIGHT_CLICK, .arg1 = x, .arg2 = y };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_mouse_down(Window *win, int x, int y) {
|
static void user_window_mouse_down(Window *win, int x, int y) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = GUI_EVENT_MOUSE_DOWN, .arg1 = x, .arg2 = y };
|
gui_event_t ev = { .type = GUI_EVENT_MOUSE_DOWN, .arg1 = x, .arg2 = y };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_mouse_up(Window *win, int x, int y) {
|
static void user_window_mouse_up(Window *win, int x, int y) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = GUI_EVENT_MOUSE_UP, .arg1 = x, .arg2 = y };
|
gui_event_t ev = { .type = GUI_EVENT_MOUSE_UP, .arg1 = x, .arg2 = y };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_mouse_move(Window *win, int x, int y, uint8_t buttons) {
|
static void user_window_mouse_move(Window *win, int x, int y, uint8_t buttons) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = GUI_EVENT_MOUSE_MOVE, .arg1 = x, .arg2 = y, .arg3 = buttons };
|
gui_event_t ev = { .type = GUI_EVENT_MOUSE_MOVE, .arg1 = x, .arg2 = y, .arg3 = buttons };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
|
|
@ -90,22 +90,22 @@ static void user_window_mouse_move(Window *win, int x, int y, uint8_t buttons) {
|
||||||
|
|
||||||
// Helper function for WM to send mouse events
|
// Helper function for WM to send mouse events
|
||||||
void syscall_send_mouse_move_event(Window *win, int x, int y, uint8_t buttons) {
|
void syscall_send_mouse_move_event(Window *win, int x, int y, uint8_t buttons) {
|
||||||
if (!win || !win->data) return;
|
if (!win) return;
|
||||||
user_window_mouse_move(win, x, y, buttons);
|
user_window_mouse_move(win, x, y, buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syscall_send_mouse_down_event(Window *win, int x, int y) {
|
void syscall_send_mouse_down_event(Window *win, int x, int y) {
|
||||||
if (!win || !win->data) return;
|
if (!win) return;
|
||||||
user_window_mouse_down(win, x, y);
|
user_window_mouse_down(win, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syscall_send_mouse_up_event(Window *win, int x, int y) {
|
void syscall_send_mouse_up_event(Window *win, int x, int y) {
|
||||||
if (!win || !win->data) return;
|
if (!win) return;
|
||||||
user_window_mouse_up(win, x, y);
|
user_window_mouse_up(win, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void user_window_key(Window *win, char c, bool pressed) {
|
static void user_window_key(Window *win, char c, bool pressed) {
|
||||||
process_t *proc = (process_t *)win->data;
|
process_t *proc = process_get_by_ui_window(win);
|
||||||
if (!proc) return;
|
if (!proc) return;
|
||||||
gui_event_t ev = { .type = pressed ? GUI_EVENT_KEY : GUI_EVENT_KEYUP, .arg1 = (int)c };
|
gui_event_t ev = { .type = pressed ? GUI_EVENT_KEY : GUI_EVENT_KEYUP, .arg1 = (int)c };
|
||||||
process_push_gui_event(proc, &ev);
|
process_push_gui_event(proc, &ev);
|
||||||
|
|
|
||||||
46
src/wm/wm.c
46
src/wm/wm.c
|
|
@ -1576,20 +1576,24 @@ void wm_add_window(Window *win) {
|
||||||
wm_lock_release(rflags);
|
wm_lock_release(rflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window* wm_find_window_by_title(const char *title) {
|
Window* wm_find_window_by_title_locked(const char *title) {
|
||||||
if (!title) return NULL;
|
if (!title) return NULL;
|
||||||
uint64_t rflags;
|
|
||||||
rflags = wm_lock_acquire();
|
|
||||||
for (int i = 0; i < window_count; i++) {
|
for (int i = 0; i < window_count; i++) {
|
||||||
if (all_windows[i] && all_windows[i]->title && str_eq(all_windows[i]->title, title)) {
|
if (all_windows[i] && all_windows[i]->title && str_eq(all_windows[i]->title, title)) {
|
||||||
wm_lock_release(rflags);
|
|
||||||
return all_windows[i];
|
return all_windows[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wm_lock_release(rflags);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Window* wm_find_window_by_title(const char *title) {
|
||||||
|
if (!title) return NULL;
|
||||||
|
uint64_t rflags = wm_lock_acquire();
|
||||||
|
Window *win = wm_find_window_by_title_locked(title);
|
||||||
|
wm_lock_release(rflags);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
void wm_remove_window(Window *win) {
|
void wm_remove_window(Window *win) {
|
||||||
if (!win) return;
|
if (!win) return;
|
||||||
|
|
||||||
|
|
@ -1811,7 +1815,7 @@ void wm_handle_click(int x, int y) {
|
||||||
if (item == 0) { // About
|
if (item == 0) { // About
|
||||||
process_create_elf("/bin/about.elf", NULL);
|
process_create_elf("/bin/about.elf", NULL);
|
||||||
} else if (item == 1) { // Settings
|
} else if (item == 1) { // Settings
|
||||||
Window *existing = wm_find_window_by_title("Settings");
|
Window *existing = wm_find_window_by_title_locked("Settings");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/settings.elf", NULL);
|
else process_create_elf("/bin/settings.elf", NULL);
|
||||||
} else if (item == 2) { // Shutdown
|
} else if (item == 2) { // Shutdown
|
||||||
|
|
@ -1946,7 +1950,9 @@ void wm_handle_right_click(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
force_redraw = true;
|
force_redraw = true;
|
||||||
}void wm_handle_mouse(int dx, int dy, uint8_t buttons, int dz) {
|
}
|
||||||
|
|
||||||
|
static void wm_handle_mouse_internal(int dx, int dy, uint8_t buttons, int dz) {
|
||||||
int sw = get_screen_width();
|
int sw = get_screen_width();
|
||||||
int sh = get_screen_height();
|
int sh = get_screen_height();
|
||||||
|
|
||||||
|
|
@ -2153,53 +2159,53 @@ void wm_handle_right_click(int x, int y) {
|
||||||
if (str_starts_with(start_menu_pending_app, "Files")) {
|
if (str_starts_with(start_menu_pending_app, "Files")) {
|
||||||
explorer_open_directory("/");
|
explorer_open_directory("/");
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Notepad")) {
|
} else if (str_starts_with(start_menu_pending_app, "Notepad")) {
|
||||||
Window *existing = wm_find_window_by_title("Notepad");
|
Window *existing = wm_find_window_by_title_locked("Notepad");
|
||||||
if (existing) {
|
if (existing) {
|
||||||
wm_bring_to_front_locked(existing);
|
wm_bring_to_front_locked(existing);
|
||||||
} else {
|
} else {
|
||||||
process_create_elf("/bin/notepad.elf", NULL);
|
process_create_elf("/bin/notepad.elf", NULL);
|
||||||
}
|
}
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Editor")) {
|
} else if (str_starts_with(start_menu_pending_app, "Editor")) {
|
||||||
Window *existing = wm_find_window_by_title("Txtedit");
|
Window *existing = wm_find_window_by_title_locked("Txtedit");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/txtedit.elf", NULL);
|
else process_create_elf("/bin/txtedit.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Word Processor")) {
|
} else if (str_starts_with(start_menu_pending_app, "Word Processor")) {
|
||||||
Window *existing = wm_find_window_by_title("Word Processor");
|
Window *existing = wm_find_window_by_title_locked("Word Processor");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/boredword.elf", NULL);
|
else process_create_elf("/bin/boredword.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Terminal")) {
|
} else if (str_starts_with(start_menu_pending_app, "Terminal")) {
|
||||||
cmd_reset(); wm_bring_to_front_locked(&win_cmd);
|
cmd_reset(); wm_bring_to_front_locked(&win_cmd);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Calculator")) {
|
} else if (str_starts_with(start_menu_pending_app, "Calculator")) {
|
||||||
Window *existing = wm_find_window_by_title("Calculator");
|
Window *existing = wm_find_window_by_title_locked("Calculator");
|
||||||
if (existing) {
|
if (existing) {
|
||||||
wm_bring_to_front_locked(existing);
|
wm_bring_to_front_locked(existing);
|
||||||
} else {
|
} else {
|
||||||
process_create_elf("/bin/calculator.elf", NULL);
|
process_create_elf("/bin/calculator.elf", NULL);
|
||||||
}
|
}
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Minesweeper")) {
|
} else if (str_starts_with(start_menu_pending_app, "Minesweeper")) {
|
||||||
Window *existing = wm_find_window_by_title("Minesweeper");
|
Window *existing = wm_find_window_by_title_locked("Minesweeper");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/minesweeper.elf", NULL);
|
else process_create_elf("/bin/minesweeper.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Settings")) {
|
} else if (str_starts_with(start_menu_pending_app, "Settings")) {
|
||||||
Window *existing = wm_find_window_by_title("Settings");
|
Window *existing = wm_find_window_by_title_locked("Settings");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/settings.elf", NULL);
|
else process_create_elf("/bin/settings.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Paint")) {
|
} else if (str_starts_with(start_menu_pending_app, "Paint")) {
|
||||||
Window *existing = wm_find_window_by_title("Paint");
|
Window *existing = wm_find_window_by_title_locked("Paint");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/paint.elf", NULL);
|
else process_create_elf("/bin/paint.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Clock")) {
|
} else if (str_starts_with(start_menu_pending_app, "Clock")) {
|
||||||
Window *existing = wm_find_window_by_title("Clock");
|
Window *existing = wm_find_window_by_title_locked("Clock");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/clock.elf", NULL);
|
else process_create_elf("/bin/clock.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Browser")) {
|
} else if (str_starts_with(start_menu_pending_app, "Browser")) {
|
||||||
Window *existing = wm_find_window_by_title("Web Browser");
|
Window *existing = wm_find_window_by_title_locked("Web Browser");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/browser.elf", NULL);
|
else process_create_elf("/bin/browser.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "About")) {
|
} else if (str_starts_with(start_menu_pending_app, "About")) {
|
||||||
process_create_elf("/bin/about.elf", NULL);
|
process_create_elf("/bin/about.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Task Manager")) {
|
} else if (str_starts_with(start_menu_pending_app, "Task Manager")) {
|
||||||
Window *existing = wm_find_window_by_title("Task Manager");
|
Window *existing = wm_find_window_by_title_locked("Task Manager");
|
||||||
if (existing) wm_bring_to_front_locked(existing);
|
if (existing) wm_bring_to_front_locked(existing);
|
||||||
else process_create_elf("/bin/taskman.elf", NULL);
|
else process_create_elf("/bin/taskman.elf", NULL);
|
||||||
} else if (str_starts_with(start_menu_pending_app, "Shutdown")) {
|
} else if (str_starts_with(start_menu_pending_app, "Shutdown")) {
|
||||||
|
|
@ -2575,6 +2581,12 @@ void wm_handle_right_click(int x, int y) {
|
||||||
prev_left = left;
|
prev_left = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wm_handle_mouse(int dx, int dy, uint8_t buttons, int dz) {
|
||||||
|
uint64_t rflags = wm_lock_acquire();
|
||||||
|
wm_handle_mouse_internal(dx, dy, buttons, dz);
|
||||||
|
wm_lock_release(rflags);
|
||||||
|
}
|
||||||
|
|
||||||
// Input Queue
|
// Input Queue
|
||||||
#define INPUT_QUEUE_SIZE 128
|
#define INPUT_QUEUE_SIZE 128
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue