diff options
author | Anton Kling <anton@kling.gg> | 2023-11-18 00:38:31 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-18 00:38:31 +0100 |
commit | 02f427a6cae9b2e9d26f7beb6fd9f1f57367044c (patch) | |
tree | 0748cfd39a0e724e57974d8eefe4f958923992be | |
parent | 01a9392ad6051878e217bffeffd6261ccf994c42 (diff) |
WindowServer: Implement window resizing.
Currently no event is sent to a client that a window is resized. This
should be added when I can bother adding that functionality to the
client applications also.
-rw-r--r-- | userland/windowserver/draw.c | 18 | ||||
-rw-r--r-- | userland/windowserver/ws.c | 14 | ||||
-rw-r--r-- | userland/windowserver/ws.h | 2 |
3 files changed, 28 insertions, 6 deletions
diff --git a/userland/windowserver/draw.c b/userland/windowserver/draw.c index 7e07305..1e02d0d 100644 --- a/userland/windowserver/draw.c +++ b/userland/windowserver/draw.c @@ -81,6 +81,8 @@ void draw_window(DISPLAY *disp, const WINDOW *w) { const int py = w->y; const int sx = w->sx; const int sy = w->sy; + const int b_sx = w->buffer_sx; + const int b_sy = w->buffer_sy; x = px; y = py; // Draw a border around the current selected window @@ -102,9 +104,19 @@ void draw_window(DISPLAY *disp, const WINDOW *w) { px * disp->bpp; if (i * sx > disp->height * disp->width) break; - uint32_t *bm = &w->bitmap_ptr[i * sx]; - for (int j = 0; j < sx; j++) { - ptr[j] = bm[j]; + if (i < b_sy) { + uint32_t *bm = &w->bitmap_ptr[i * b_sx]; + int j = 0; + for (; j < b_sx && j < sx; j++) { + ptr[j] = bm[j]; + } + for (; j < sx; j++) { + ptr[j] = 0; + } + } else { + for (int j = 0; j < sx; j++) { + ptr[j] = 0; + } } } } diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c index d04dd08..a438566 100644 --- a/userland/windowserver/ws.c +++ b/userland/windowserver/ws.c @@ -91,7 +91,7 @@ void setup(void) { main_display.width = disp_info.width; main_display.height = disp_info.height; - main_display.bpp = disp_info.bpp/8; + main_display.bpp = disp_info.bpp / 8; setup_display(&main_display, "/dev/vbe", 0xBB8000); draw_wallpaper(&main_display); @@ -169,8 +169,8 @@ void create_window(WINDOW *w, int fd, int x, int y, int sx, int sy) { w->bitmap_ptr = mmap(NULL, sx * sy * sizeof(uint32_t), 0, 0, fd, 0); w->x = x; w->y = y; - w->sx = sx; - w->sy = sy; + w->buffer_sx = w->sx = sx; + w->buffer_sy = w->sy = sy; } typedef struct { @@ -312,6 +312,7 @@ void parse_mouse_event(int fd) { int16_t xc = 0; int16_t yc = 0; int middle_button = 0; + int right_button = 0; int left_button = 0; for (;;) { struct mouse_event e[100]; @@ -324,6 +325,7 @@ void parse_mouse_event(int fd) { uint8_t xs = e[i].buttons & (1 << 4); uint8_t ys = e[i].buttons & (1 << 5); middle_button = e[i].buttons & (1 << 2); + right_button = e[i].buttons & (1 << 1); left_button = e[i].buttons & (1 << 0); int16_t x = e[i].x; int16_t y = e[i].y; @@ -352,6 +354,12 @@ void parse_mouse_event(int fd) { &main_display.active_window->y); } } + if (right_button) { + if (main_display.active_window) { + main_display.active_window->sx += xc; + main_display.active_window->sy -= yc; + } + } update_mouse(); } diff --git a/userland/windowserver/ws.h b/userland/windowserver/ws.h index 6f8eee3..477f123 100644 --- a/userland/windowserver/ws.h +++ b/userland/windowserver/ws.h @@ -14,6 +14,8 @@ typedef struct { int y; int sx; int sy; + int buffer_sx; + int buffer_sy; } WINDOW; typedef struct { |