diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-17 17:49:05 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-17 17:49:05 +0200 |
| commit | 9a52082f2c08589476a539d4c55ad268ae13ac0f (patch) | |
| tree | cbb06bc8133a35e64ed347679a909f9735f17315 /swt.c | |
| parent | 74e9d116d6a40b54db4ec66101f6de5c6cc3f783 (diff) | |
fix crash on cursor sel y overflow
Diffstat (limited to 'swt.c')
| -rw-r--r-- | swt.c | 47 |
1 files changed, 31 insertions, 16 deletions
@@ -29,7 +29,7 @@ char *argv0; #define TRUEBLUE(x) (((x) & 0xff)) #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) #define FONTMODE(mode) (mode & ATTR_ITALIC ? (mode & ATTR_BOLD ? FONT_BOLD_ITALIC : FONT_ITALIC) : (mode & ATTR_BOLD ? FONT_BOLD : FONT_NORMAL)) -#define wintotty(scale, type) (scale < 2 * borderpx ? 0 : (scale - 2 * borderpx) / win.fontcache->box.type) +#define wintotty(scale, type) (((int)scale < (int)(2 * borderpx)) ? 0 : (scale - 2 * borderpx) / win.fontcache->box.type) #define match_then_bind(obj, inter, ver) \ if (strcmp(interface, inter.name) == 0) { \ obj = wl_registry_bind(registry, name, &inter, ver); @@ -51,6 +51,10 @@ typedef struct { FontCache *fontcache; int mode; int cursor; + struct { + unsigned width; + unsigned height; + } tty; } Window; @@ -399,7 +403,6 @@ void surface_configure(void *data, struct xdg_surface *surface, uint32_t serial) { int first_configure = win.canvas == 0; - int ttywidth, ttyheight; xdg_surface_ack_configure(surface, serial); if (first_configure) @@ -410,7 +413,6 @@ surface_configure(void *data, struct xdg_surface *surface, uint32_t serial) void toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int32_t height, struct wl_array *clients) { - int ttywidth, ttyheight; if (win.canvas == 0 || width != win.width || height != win.height) { if (width == 0 || height == 0) { win.width = 800; @@ -426,12 +428,12 @@ toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int win.canvas = create_drw(client.shm, win.width, win.height); draw_frame(); - ttywidth = (win.width - 2 * borderpx) / win.fontcache->box.width; - ttyheight = (win.height - 2 * borderpx) / win.fontcache->box.height; - ttywidth = MAX(ttywidth, 1); - ttyheight = MAX(ttyheight, 1); - tresize(ttywidth, ttyheight); - ttyresize(ttywidth, ttyheight); + win.tty.width = (win.width - 2 * borderpx) / win.fontcache->box.width; + win.tty.height = (win.height - 2 * borderpx) / win.fontcache->box.height; + win.tty.width = MAX(win.tty.width, 1); + win.tty.height = MAX(win.tty.height, 1); + tresize(win.tty.width, win.tty.height); + ttyresize(win.tty.width, win.tty.height); } } @@ -641,6 +643,12 @@ pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl void pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface) { + selextend( + wintotty(client.pointer.position.x, width), + wintotty(client.pointer.position.y, height), + SEL_REGULAR, + 1 + ); } @@ -651,12 +659,14 @@ pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t client.pointer.position.y = wl_fixed_to_int(y); if (client.pointer.buttons.button & BTN_LEFT) { + fprintf(stderr, "y: %i\n", wintotty(client.pointer.position.y, height)); selextend( - wintotty(client.pointer.position.x, width), - wintotty(client.pointer.position.y, height), + MIN(wintotty(client.pointer.position.x, width), win.tty.width - 1), + MIN(wintotty(client.pointer.position.y, height), win.tty.height - 1), SEL_REGULAR, 0 ); + fprintf(stderr, "HERE\n"); draw(); } } @@ -684,15 +694,20 @@ pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t client.pointer.buttons.tclick = time; ++client.pointer.buttons.click_combo; - selstart(wintotty(client.pointer.position.x, width), wintotty(client.pointer.position.y, height), snap); + selstart( + MIN(wintotty(client.pointer.position.x, width), win.tty.width - 1), + MIN(wintotty(client.pointer.position.y, height), win.tty.height - 1), + snap + ); draw(); fprintf(stderr, "redraw: %i\n", snap); } else if (button == BTN_LEFT && !state) { + client.pointer.buttons.button &= ~BTN_LEFT; selextend( - wintotty(client.pointer.position.x, width), - wintotty(client.pointer.position.y, height), - SEL_REGULAR, - 1 + MIN(wintotty(client.pointer.position.x, width), win.tty.width - 1), + MIN(wintotty(client.pointer.position.y, height), win.tty.height - 1), + SEL_REGULAR, + 1 ); } } |