From d3ec1b609b53dfba8c5a6fc09b1de9ecd8062e02 Mon Sep 17 00:00:00 2001 From: speedie Date: Wed, 8 Mar 2023 18:20:15 +0100 Subject: [PATCH] don't allow the image to be scaled up beyond menu width --- libs/img.c | 4 ++-- spmenu.c | 52 +++++----------------------------------------------- 2 files changed, 7 insertions(+), 49 deletions(-) diff --git a/libs/img.c b/libs/img.c index 09f7813..a46aba2 100644 --- a/libs/img.c +++ b/libs/img.c @@ -8,8 +8,8 @@ setimagesize(int width, int height) int oih = 0; int oiw = 0; - /* this makes sure we cannot scale down the image too much */ - if ((!image && height < imageheight) || (!image && width < imagewidth) || hideimage) return; + /* this makes sure we cannot scale the image up or down too much */ + if ((!image && height < imageheight) || (!image && width < imagewidth) || width > mw || hideimage) return; cleanupimage(); diff --git a/spmenu.c b/spmenu.c index 7f4a41b..899fc9e 100644 --- a/spmenu.c +++ b/spmenu.c @@ -191,7 +191,6 @@ static size_t nextrune(int inc); static void drawmenu(void); static void calcoffsets(void); -static void run(void); static void readstdin(void); static void recalculatenumbers(void); static void usage(void); @@ -200,6 +199,8 @@ static void movewordedge(int dir); static void insert(const char *str, ssize_t n); static void cleanup(void); static void navigatehistfile(int dir); +static void grabfocus(void); +static void pastesel(void); static int max_textw(void); /* user configuration */ @@ -223,6 +224,8 @@ static int longestedge = 0; /* longest edge */ #include "libs/rtl.h" #include "libs/rtl.c" #endif +#include "libs/event.h" +#include "libs/event.c" #include "libs/key.c" #include "libs/mouse.c" #include "libs/draw.c" @@ -804,51 +807,6 @@ readstdin(void) lines = MIN(lines, i); } -void -run(void) -{ - XEvent ev; - - while (!XNextEvent(dpy, &ev)) { - if (XFilterEvent(&ev, win)) - continue; - switch(ev.type) { - case DestroyNotify: - if (ev.xdestroywindow.window != win) - break; - cleanup(); - exit(1); - case ButtonPress: - buttonpress(&ev); - break; - case Expose: - if (ev.xexpose.count == 0) - drw_map(drw, win, 0, 0, mw, mh); - break; - case FocusIn: - /* regrab focus from parent window */ - if (ev.xfocus.window != win) - grabfocus(); - break; - case KeyPress: - keypress(&ev); - break; - case SelectionNotify: - if (ev.xselection.property == utf8) - pastesel(); - break; - case VisibilityNotify: - if (ev.xvisibility.state != VisibilityUnobscured) - XRaiseWindow(dpy, win); - break; - } - - #if USEIMAGE - drawimage(); - #endif - } -} - void setup(void) { @@ -1068,7 +1026,7 @@ main(int argc, char *argv[]) } setup(); - run(); + eventloop(); return 1; /* unreachable */ }