diff options
author | Marvin Borner | 2020-11-27 12:46:45 +0100 |
---|---|---|
committer | Marvin Borner | 2020-11-27 12:46:45 +0100 |
commit | a1dbc858d40b2394e23511aa111ec6590b5fb8c7 (patch) | |
tree | 7ad9a63a67a0fca0b879cb7053eb702407a64174 | |
parent | 3288fc6ad2119828c028846ebfdd9cdc8c94af83 (diff) |
Started window resize support
-rw-r--r-- | apps/wm.c | 27 | ||||
-rw-r--r-- | libgui/gui.c | 23 | ||||
-rw-r--r-- | libgui/inc/gui.h | 6 |
3 files changed, 43 insertions, 13 deletions
@@ -51,6 +51,17 @@ static struct context *new_context(struct context *ctx, u32 pid, int x, int y, u return ctx; } +static void remove_context(struct context *ctx) +{ + assert(list_remove(contexts, list_first_data(contexts, ctx))); + free(ctx->fb); + ctx->fb = NULL; + free(ctx); + ctx = NULL; + free(ctx); + ctx = NULL; +} + static struct context *context_at(int x, int y) { if (!contexts->head || !contexts->head->data) @@ -186,14 +197,24 @@ static void handle_mouse(struct event_mouse *event) focused->width = mouse_x - focused->x; if (mouse_y - focused->y > 0) { focused->height = mouse_y - focused->y; - focused->pitch = focused->height * (focused->bpp >> 3); } - redraw_all(); // TODO: Function to redraw one context + /* redraw_all(); // TODO: Function to redraw one context */ } mouse_pressed[1] = 1; } else if (mod_pressed && mouse_pressed[1]) { mouse_pressed[1] = 0; - redraw_all(); + if (focused) { + struct context *resized = malloc(sizeof(*resized)); + new_context(resized, focused->pid, focused->x, focused->y, focused->width, + focused->height, focused->flags); + remove_context(focused); + list_add(contexts, resized); + focused = resized; + struct gui_event_resize *msg = malloc(sizeof(*msg)); + msg->new_ctx = resized; + msg_send(resized->pid, GUI_RESIZE, msg); + redraw_all(); + } } cursor.x = mouse_x; diff --git a/libgui/gui.c b/libgui/gui.c index 943c5d7..4b28114 100644 --- a/libgui/gui.c +++ b/libgui/gui.c @@ -406,14 +406,10 @@ void gui_event_loop(struct element *container) continue; s[l] = event->ch; s[l + 1] = '\0'; - gui_sync_text_input(focused); - merge_elements(get_root(focused->window_id)); - gfx_redraw_focused(); + gui_sync(get_root(focused->window_id), focused); } else if (event->scancode == KEY_BACKSPACE && l > 0) { s[l - 1] = '\0'; - gui_sync_text_input(focused); - merge_elements(get_root(focused->window_id)); - gfx_redraw_focused(); + gui_sync(get_root(focused->window_id), focused); } } @@ -423,9 +419,7 @@ void gui_event_loop(struct element *container) // Clear! char *t = ((struct element_text_input *)focused->data)->text; memset(t, 0, strlen(t)); - gui_sync_text_input(focused); - merge_elements(get_root(focused->window_id)); - gfx_redraw_focused(); + gui_sync(get_root(focused->window_id), focused); } if (focused && focused->event.on_key && event->press && event->ch) @@ -433,6 +427,17 @@ void gui_event_loop(struct element *container) break; } + case GUI_RESIZE: { + struct gui_event_resize *event = msg->data; + struct element *root = get_root(container->window_id); + printf("RESIZE: %d->%d %d->%d\n", root->ctx->width, event->new_ctx->width, + root->ctx->height, event->new_ctx->height); + root->ctx = event->new_ctx; + gui_sync_container(root); + merge_elements(root); + gfx_redraw_focused(); + break; + } } } } diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h index 8e925d6..cf0020d 100644 --- a/libgui/inc/gui.h +++ b/libgui/inc/gui.h @@ -13,7 +13,7 @@ #define MAX_INPUT_LENGTH 100 // TODO: Improve event types (maybe as struct header) -enum window_event_type { GUI_KEYBOARD = GFX_MAX + 1, GUI_MOUSE, GUI_MAX }; +enum window_event_type { GUI_KEYBOARD = GFX_MAX + 1, GUI_MOUSE, GUI_RESIZE, GUI_MAX }; enum element_type { GUI_TYPE_ROOT, GUI_TYPE_CONTAINER, @@ -101,6 +101,10 @@ struct gui_event_mouse { int but3; }; +struct gui_event_resize { + struct context *new_ctx; +}; + struct element *gui_init(const char *title, u32 width, u32 height, u32 color_bg); void gui_event_loop(struct element *container); struct element *gui_add_button(struct element *container, int x, int y, enum font_type font_type, |