summaryrefslogtreecommitdiff
path: root/src/kernel/window.c
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/window.c
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/window.c')
-rw-r--r--src/kernel/window.c57
1 files changed, 47 insertions, 10 deletions
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