summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-03-03 23:47:26 -0500
committerBenji Dial <benji6283@gmail.com>2021-03-03 23:47:26 -0500
commit2fc768319887945c5c6beafcd21d29d9884cd48a (patch)
tree9dadaf32069588c23e755228099669557449304f /src/kernel
parent81df4702c424f91cca5570ab2554d1d4cbae534d (diff)
downloadportland-os-2fc768319887945c5c6beafcd21d29d9884cd48a.tar.gz
moving windows with mouse, changing some old panics into syslogs, small bugfix in knob files, "send to back" wm keybinding
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/elf.c25
-rw-r--r--src/kernel/task.c9
-rw-r--r--src/kernel/task.h3
-rw-r--r--src/kernel/window.c57
4 files changed, 67 insertions, 27 deletions
diff --git a/src/kernel/elf.c b/src/kernel/elf.c
index f601654..fdb13aa 100644
--- a/src/kernel/elf.c
+++ b/src/kernel/elf.c
@@ -76,6 +76,10 @@ struct ph_entry {
} __attribute__ ((packed));
uint32_t try_elf_run(const struct drive *d, const char *path, const char *pass_old_vma, uint32_t io_handle) {
+ struct task_state *tstate = new_task();
+ if (!tstate)
+ return 0;
+
file_id_t h = d->get_file(d, path);
if (!h)
return 0;
@@ -126,18 +130,17 @@ uint32_t try_elf_run(const struct drive *d, const char *path, const char *pass_o
memcpy(pass_pma, pass, pass_l);
- struct task_state tstate;
- tstate.page_directory = pd;
- tstate.ret_addr = ehead.entry_vma;
- tstate.stack_bottom = 0;
+ tstate->page_directory = pd;
+ tstate->ret_addr = ehead.entry_vma;
+ tstate->stack_bottom = 0;
//logf(LOG_INFO, " tasks: 0x%h", tasks);
//logf(LOG_INFO, "active_task: 0x%h", active_task);
//logf(LOG_INFO, " new edi: 0x%hb", active_task - tasks + 1);
- tstate.edx = (uint32_t)pass_vma;
- tstate.esi = io_handle;
- tstate.edi = active_task - tasks + 1;
- tstate.esp = 0;
+ tstate->edx = (uint32_t)pass_vma;
+ tstate->esi = io_handle;
+ tstate->edi = active_task - tasks + 1;
+ tstate->esp = 0;
const char *path_end_start = path;
for (const char *i = path; *i; ++i)
@@ -148,9 +151,9 @@ uint32_t try_elf_run(const struct drive *d, const char *path, const char *pass_o
for (i = 0; i < TASK_NAME_LEN; ++i) {
if (!path_end_start[i])
break;
- tstate.name[i] = path_end_start[i];
+ tstate->name[i] = path_end_start[i];
}
- tstate.name[i] = '\0';
+ tstate->name[i] = '\0';
- return new_task(tstate);
+ return (tstate - tasks) + 1;
}
diff --git a/src/kernel/task.c b/src/kernel/task.c
index 077eea6..b301217 100644
--- a/src/kernel/task.c
+++ b/src/kernel/task.c
@@ -46,18 +46,17 @@ struct tss {
struct task_state tasks[MAX_TASKS];
struct task_state *active_task;
-//puts the handle into ecx
-uint32_t new_task(struct task_state state) {
+struct task_state *new_task() {
for (uint8_t n = 0; n < MAX_TASKS; ++n)
if (!tasks[n].page_directory) {
- tasks[n] = state;
tasks[n].ecx = n + 1;
tasks[n].waiting = false;
for (uint8_t i = 0; i < MAX_WAITS; ++i)
tasks[n].waits[i].mode = NONE;
- return n + 1;
+ return tasks + n;
}
- PANIC("Maximum number of tasks reached.");
+ logf(LOG_ERROR, "Reached %d tasks, refusing to create any more.", MAX_TASKS);
+ return 0;
}
static void tmp_halt() {
diff --git a/src/kernel/task.h b/src/kernel/task.h
index 643c88e..ca8e2b7 100644
--- a/src/kernel/task.h
+++ b/src/kernel/task.h
@@ -52,7 +52,8 @@ extern struct task_state *active_task;
void init_tasks();
//puts the handle into ecx
-uint32_t new_task(struct task_state state);
+//returns null on full
+struct task_state *new_task();
void advance_active_task();
void delete_task(struct task_state *state);
diff --git a/src/kernel/window.c b/src/kernel/window.c
index bc36578..28f7010 100644
--- a/src/kernel/window.c
+++ b/src/kernel/window.c
@@ -392,6 +392,7 @@ enum wm_action {
WM_MOVE_UP,
WM_MOVE_DOWN,
WM_RUN_COMMAND,
+ WM_SEND_BOTTOM,
N_WM_ACTIONS
};
@@ -401,7 +402,8 @@ static struct key_packet keybinds[] = {
{.key_id = KEY_RIGHT_ARROW, .modifiers = WINS},
{.key_id = KEY_UP_ARROW, .modifiers = WINS},
{.key_id = KEY_DOWN_ARROW, .modifiers = WINS},
- {.key_id = KEY_SPACE, .modifiers = WINS}
+ {.key_id = KEY_SPACE, .modifiers = WINS},
+ {.key_id = KEY_PAGE_DOWN, .modifiers = WINS}
};
static inline bool fuzzy_key_match(struct key_packet t, struct key_packet a) {
@@ -496,7 +498,20 @@ void on_action(struct window_action packet) {
break;
case WM_RUN_COMMAND:
if (!try_elf_run(drives, run_command, run_command_pass, 0))
- PANIC("Couldn't run program listed in " RUN_COMMAND_FILE ".");
+ logf(LOG_ERROR, "Couldn't run program listed in " RUN_COMMAND_FILE ".");
+ break;
+ case WM_SEND_BOTTOM:
+ if (top_window && (top_window != bottom_window)) {
+ struct window *const top = top_window;
+ struct window *const bot = bottom_window;
+ top->above = bot;
+ bot->below = top;
+ top_window = top->below;
+ bottom_window = top;
+ top_window->above = 0;
+ bottom_window->below = 0;
+ paint_and_above(bot);
+ }
}
switch_to_task_cr3();
return;
@@ -506,14 +521,27 @@ void on_action(struct window_action packet) {
send_action(top_window, packet);
}
+struct window *being_moved = 0;
+int16_t winpos_rel_y;
+int16_t winpos_rel_x;
+
void move_mouse_by(int16_t y, int16_t x) {
//logf(LOG_INFO, "old mouse coords: (%d, %d)", mouse_x, mouse_y);
switch_to_kernel_cr3();
- blit(mouse_x, mouse_x + MOUSE_WIDTH > VBE_MODE_INFO->width ? VBE_MODE_INFO->width : mouse_x + MOUSE_WIDTH,
- mouse_y, mouse_y + MOUSE_HEIGHT > VBE_MODE_INFO->height ? VBE_MODE_INFO->height : mouse_y + MOUSE_HEIGHT);
+ const uint16_t old_y = mouse_y;
+ const uint16_t old_x = mouse_x;
mouse_y = (-y > mouse_y) ? 0 : (y + mouse_y + MOUSE_HEIGHT > VBE_MODE_INFO->height) ? VBE_MODE_INFO->height - MOUSE_HEIGHT : y + mouse_y;
mouse_x = (-x > mouse_x) ? 0 : (x + mouse_x + MOUSE_WIDTH > VBE_MODE_INFO->width) ? VBE_MODE_INFO->width - MOUSE_WIDTH : x + mouse_x;
- blit_mouse();
+ if (being_moved) {
+ being_moved->ypos = winpos_rel_y + mouse_y;
+ being_moved->xpos = winpos_rel_x + mouse_x;
+ paint_all();
+ }
+ else {
+ blit(old_x, old_x + MOUSE_WIDTH > VBE_MODE_INFO->width ? VBE_MODE_INFO->width : old_x + MOUSE_WIDTH,
+ old_y, old_y + MOUSE_HEIGHT > VBE_MODE_INFO->height ? VBE_MODE_INFO->height : old_y + MOUSE_HEIGHT);
+ blit_mouse();
+ }
switch_to_task_cr3();
//logf(LOG_INFO, "new mouse coords: (%d, %d)", mouse_x, mouse_y);
}
@@ -542,10 +570,19 @@ void mouse_button(enum mouse_button which, bool up) {
if (!clicked_on)
return;
- if (clicked_on != top_window) {
- focus(clicked_on);
- paint_and_above(clicked_on);
+ if ((mouse_y >= clicked_on->ypos) && (mouse_y < clicked_on->ypos + clicked_on->height) &&
+ (mouse_x >= clicked_on->xpos) && (mouse_x < clicked_on->xpos + clicked_on->width)) {
+ if (clicked_on != top_window) {
+ focus(clicked_on);
+ paint_and_above(clicked_on);
+ }
+ send_action(clicked_on, (struct window_action){.action_type = up ? MOUSE_UP : MOUSE_DOWN, .as_mouse = {.y = mouse_y - clicked_on->ypos, .x = mouse_x - clicked_on->xpos, .which = which}});
}
-
- send_action(clicked_on, (struct window_action){.action_type = up ? MOUSE_UP : MOUSE_DOWN, .as_mouse = {.y = mouse_y - clicked_on->ypos, .x = mouse_x - clicked_on->xpos, .which = which}});
+ else if (!up && !being_moved) {
+ being_moved = clicked_on;
+ winpos_rel_y = clicked_on->ypos - mouse_y;
+ winpos_rel_x = clicked_on->xpos - mouse_x;
+ }
+ else if (up)
+ being_moved = 0;
} \ No newline at end of file