summaryrefslogtreecommitdiff
path: root/src/kernel/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/window.c')
-rw-r--r--src/kernel/window.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/src/kernel/window.c b/src/kernel/window.c
index d50e454..9487211 100644
--- a/src/kernel/window.c
+++ b/src/kernel/window.c
@@ -7,6 +7,7 @@
#include "util.h"
#include "pmap.h"
#include "elf.h"
+#include "kbd.h"
#include "log.h"
#include "vbe.h"
@@ -402,7 +403,6 @@ enum wm_action {
WM_MOVE_UP,
WM_MOVE_DOWN,
WM_RUN_COMMAND,
- WM_SEND_BOTTOM,
N_WM_ACTIONS
};
@@ -412,8 +412,7 @@ 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_PAGE_DOWN, .modifiers = WINS}
+ {.key_id = KEY_SPACE, .modifiers = WINS}
};
static inline bool fuzzy_key_match(struct key_packet t, struct key_packet a) {
@@ -510,18 +509,6 @@ void on_action(struct window_action packet) {
if (!try_elf_run(drives, run_command, run_command_pass, 0))
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;
@@ -572,6 +559,32 @@ static void focus(struct window *w) {
send_action(w, (struct window_action){.action_type = FOCUS_ENTER});
}
+static void send_bottom(struct window *w) {
+ if (w == bottom_window)
+ return;
+ if (w == top_window) {
+ send_action(w, (struct window_action){.action_type = FOCUS_LEAVE});
+ top_window = w->below;
+ top_window->above = 0;
+ w->above = bottom_window;
+ w->below = 0;
+ bottom_window->below = w;
+ bottom_window = w;
+ send_action(top_window, (struct window_action){.action_type = FOCUS_ENTER});
+ }
+ else {
+ w->above->below = w->below;
+ w->below->above = w->above;
+ bottom_window->below = w;
+ w->above = bottom_window;
+ w->below = 0;
+ bottom_window = w;
+ }
+ paint_and_above(w->above);
+}
+
+bool skip_up_right = false;
+
void mouse_button(enum mouse_button which, bool up) {
if (!top_window)
return;
@@ -580,19 +593,33 @@ void mouse_button(enum mouse_button which, bool up) {
if (!clicked_on)
return;
- 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 ((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))
+ //TODO: resizing
+ return;
+
+ if (up && being_moved && (which == LEFT))
+ being_moved = 0;
+
+ else if (!up && !being_moved && (keymods & ALTS) && (which == LEFT)) {
+ being_moved = clicked_on;
+ winpos_rel_y = clicked_on->ypos - mouse_y;
+ winpos_rel_x = clicked_on->xpos - mouse_x;
+ }
+
+ else if (!up && (keymods & ALTS) && (which == RIGHT)) {
+ send_bottom(clicked_on);
+ skip_up_right = true;
+ }
+
+ else if (up && skip_up_right && (which == RIGHT))
+ skip_up_right = false;
+
+ else {
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}});
}
- 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