moving active window with SHIFT+ARROW

This commit is contained in:
uosfz 2026-02-13 15:30:38 +01:00
parent 4f4ec8076f
commit e534f6a63f
Signed by: uosfz
SSH key fingerprint: SHA256:FlktuluyhTQg3jHZNLKwxOOC5hbfrUXM0tz3IA3lGJo

View file

@ -92,6 +92,9 @@ void app_draw_pixel(void *self, struct color col, int x, int y) {
void app_draw_rect(void *self, struct color col, const struct rect *rect) {
struct app_instance *ins = app_find(self);
ASSERT(ins != NULL);
// draw into private fb
tex_fill_region(&ins->framebuf, col, rect);
// draw on public fb
struct tex fb_tex = fb_as_tex();
struct tex my_view = tex_view(&fb_tex, &ins->pos);
tex_fill_region(&my_view, col, rect);
@ -101,9 +104,12 @@ void app_draw_rect(void *self, struct color col, const struct rect *rect) {
void app_draw_texture(void *self, const struct tex *tex, int x, int y) {
struct app_instance *ins = app_find(self);
ASSERT(ins != NULL);
struct rect src_rect = RECT_XYWH(x, y, tex->width, tex->height);
// draw into private fb
tex_blit(&ins->framebuf, tex, NULL, &src_rect);
// draw on public fb
struct tex fb_tex = fb_as_tex();
struct tex my_view = tex_view(&fb_tex, &ins->pos);
struct rect src_rect = RECT_XYWH(x, y, tex->width, tex->height);
tex_blit(&my_view, tex, NULL, &src_rect);
fb_damage_in_rect(&src_rect, &ins->pos);
}
@ -159,11 +165,52 @@ void app_pop(void) {
app_stack_size--;
}
void app_translate(size_t app_idx, int dx, int dy) {
// TODO could optimize the uncovered
ASSERT(app_idx < app_stack_size);
struct app_instance *ins = &app_stack[app_idx];
struct rect uncovered = ins->pos;
rect_translate(&ins->pos, dx, dy);
struct tex fb_tex = fb_as_tex();
struct tex my_view = tex_view(&fb_tex, &ins->pos);
// TODO correct uncover order
tex_blit(&fb_tex, &app_background, &uncovered, &uncovered);
fb_damage(uncovered);
tex_blit(&my_view, &ins->framebuf, NULL, NULL);
fb_damage(ins->pos);
}
void app_key_event_listener(struct key_event event) {
if (app_stack_size == 0) {
return;
}
struct app_instance *ins = app_top();
if (event.code == KEY_ARROW_LEFT && (event.mod & KEY_MOD_SHIFT)) {
if (event.pressed) {
app_translate(app_stack_size - 1, -10, 0);
}
return;
}
if (event.code == KEY_ARROW_RIGHT && (event.mod & KEY_MOD_SHIFT)) {
if (event.pressed) {
app_translate(app_stack_size - 1, 10, 0);
}
return;
}
if (event.code == KEY_ARROW_UP && (event.mod & KEY_MOD_SHIFT)) {
if (event.pressed) {
app_translate(app_stack_size - 1, 0, -10);
}
return;
}
if (event.code == KEY_ARROW_DOWN && (event.mod & KEY_MOD_SHIFT)) {
if (event.pressed) {
app_translate(app_stack_size - 1, 0, 10);
}
return;
}
if (ins->template->event_keyboard) {
ins->template->event_keyboard(ins->app, event);
}