kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=2d9511d59dbb33e3be1019545493d2950c131b54

commit 2d9511d59dbb33e3be1019545493d2950c131b54
Author: Kim Woelders <[email protected]>
Date:   Wed Nov 27 17:24:46 2019 +0100

    Quit on 'q' or 'esc' key press in all imlib2_... test utilities
    
    The ...free... stuff at quit seems to be needed to silence valgrind when
    exiting by return from main and not by exit().
---
 src/bin/imlib2_bumpmap.c    | 15 ++++++++++-----
 src/bin/imlib2_colorspace.c | 22 ++++++++--------------
 src/bin/imlib2_poly.c       | 24 ++++++++++++++----------
 src/bin/imlib2_show.c       | 24 ++++++++++++++++++++----
 src/bin/imlib2_test.c       | 16 +++++++++++++---
 src/bin/imlib2_view.c       |  6 ++++--
 6 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/src/bin/imlib2_bumpmap.c b/src/bin/imlib2_bumpmap.c
index 7889276..92ccca6 100644
--- a/src/bin/imlib2_bumpmap.c
+++ b/src/bin/imlib2_bumpmap.c
@@ -1,6 +1,7 @@
 #include "config.h"
 
 #include <X11/Xlib.h>
+#include <X11/keysym.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -15,6 +16,7 @@ main(int argc, char **argv)
    int                 w, h, x, y;
    Imlib_Image         im_bg;
    XEvent              ev;
+   KeySym              keysym;
 
    /**
     * Initialization according to options
@@ -33,7 +35,7 @@ main(int argc, char **argv)
 
    win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
                              0, 0, 0);
-   XSelectInput(disp, win,
+   XSelectInput(disp, win, KeyPressMask |
                 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
                 PointerMotionMask | ExposureMask);
 
@@ -69,17 +71,19 @@ main(int argc, char **argv)
              XNextEvent(disp, &ev);
              switch (ev.type)
                {
-               case Expose:
+               case KeyPress:
+                  keysym = XLookupKeysym(&ev.xkey, 0);
+                  if (keysym == XK_q || keysym == XK_Escape)
+                     goto quit;
                   break;
                case ButtonRelease:
-                  exit(0);
-                  break;
+                  goto quit;
                case MotionNotify:
                   x = ev.xmotion.x;
                   y = ev.xmotion.y;
+                  break;
                default:
                   break;
-
                }
           }
         while (XPending(disp));
@@ -107,5 +111,6 @@ main(int argc, char **argv)
         imlib_free_image();
      }
 
+ quit:
    return 0;
 }
diff --git a/src/bin/imlib2_colorspace.c b/src/bin/imlib2_colorspace.c
index 9de74bb..bc8cb65 100644
--- a/src/bin/imlib2_colorspace.c
+++ b/src/bin/imlib2_colorspace.c
@@ -1,7 +1,7 @@
 #include "config.h"
 
 #include <X11/Xlib.h>
-#include <X11/Xutil.h>
+#include <X11/keysym.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -17,7 +17,6 @@ main(int argc, char **argv)
    Imlib_Image         im_bg = NULL;
    XEvent              ev;
    KeySym              keysym;
-   static char         kbuf[20];
    Imlib_Font          font;
    Imlib_Color_Range   range;
 
@@ -68,20 +67,13 @@ main(int argc, char **argv)
              XNextEvent(disp, &ev);
              switch (ev.type)
                {
-               case ButtonRelease:
-                  exit(0);
-                  break;
                case KeyPress:
-                  XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
-                                NULL);
-                  switch (*kbuf)
-                    {
-                    case 'q':
-                       exit(0);
-                    default:
-                       break;
-                    }
+                  keysym = XLookupKeysym(&ev.xkey, 0);
+                  if (keysym == XK_q || keysym == XK_Escape)
+                     goto quit;
                   break;
+               case ButtonRelease:
+                  goto quit;
                default:
                   break;
 
@@ -133,5 +125,7 @@ main(int argc, char **argv)
 
         imlib_render_image_on_drawable(0, 0);
      }
+
+ quit:
    return 0;
 }
diff --git a/src/bin/imlib2_poly.c b/src/bin/imlib2_poly.c
index a433595..4ca37b6 100644
--- a/src/bin/imlib2_poly.c
+++ b/src/bin/imlib2_poly.c
@@ -1,7 +1,7 @@
 #include "config.h"
 
 #include <X11/Xlib.h>
-#include <X11/Xutil.h>
+#include <X11/keysym.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -17,7 +17,6 @@ main(int argc, char **argv)
    Imlib_Image         im_bg = NULL;
    XEvent              ev;
    KeySym              keysym;
-   static char         kbuf[20];
    ImlibPolygon        poly, poly1, poly2;
 
    /**
@@ -81,13 +80,9 @@ main(int argc, char **argv)
              XNextEvent(disp, &ev);
              switch (ev.type)
                {
-               case ButtonRelease:
-                  exit(0);
-                  break;
                case KeyPress:
-                  XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
-                                NULL);
-                  switch (*kbuf)
+                  keysym = XLookupKeysym(&ev.xkey, 0);
+                  switch (keysym)
                     {
                     case ' ':
                        imlib_context_set_anti_alias
@@ -95,12 +90,15 @@ main(int argc, char **argv)
                        printf("AA is %s\n",
                               imlib_context_get_anti_alias()? "on" : "off");
                        break;
-                    case 'q':
-                       exit(0);
+                    case XK_q:
+                    case XK_Escape:
+                       goto quit;
                     default:
                        break;
                     }
                   break;
+               case ButtonRelease:
+                  goto quit;
                default:
                   break;
 
@@ -117,5 +115,11 @@ main(int argc, char **argv)
         imlib_image_fill_polygon(poly2);
         imlib_render_image_on_drawable(0, 0);
      }
+
+ quit:
+   imlib_polygon_free(poly);
+   imlib_polygon_free(poly1);
+   imlib_polygon_free(poly2);
+
    return 0;
 }
diff --git a/src/bin/imlib2_show.c b/src/bin/imlib2_show.c
index 4e586d0..0a9003e 100644
--- a/src/bin/imlib2_show.c
+++ b/src/bin/imlib2_show.c
@@ -1,7 +1,7 @@
 #include "config.h"
 
 #include <X11/Xlib.h>
-#include <X11/Xutil.h>
+#include <X11/keysym.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -274,7 +274,7 @@ main(int argc, char **argv)
              win =
                 XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10,
                                     10, 0, 0, 0);
-             XSelectInput(disp, win,
+             XSelectInput(disp, win, KeyPressMask |
                           ButtonPressMask | ButtonReleaseMask | 
ButtonMotionMask
                           | PointerMotionMask | ExposureMask);
           }
@@ -776,6 +776,7 @@ main(int argc, char **argv)
         Imlib_Updates       up = NULL;
         int                 x, y;
         XEvent              ev;
+        KeySym              keysym;
         Imlib_Font          fn = NULL;
         struct font_hdr {
            int                 type;
@@ -944,14 +945,18 @@ main(int argc, char **argv)
                                                      ev.xexpose.width,
                                                      ev.xexpose.height);
                        break;
+                    case KeyPress:
+                       keysym = XLookupKeysym(&ev.xkey, 0);
+                       if (keysym == XK_q || keysym == XK_Escape)
+                          goto quit;
+                       break;
                     case ButtonRelease:
                        if (fon)
                          {
                             imlib_context_set_font(fn);
                             imlib_free_font();
                          }
-                       exit(0);
-                       break;
+                       goto quit;
                     case MotionNotify:
                        x = ev.xmotion.x;
                        y = ev.xmotion.y;
@@ -1381,5 +1386,16 @@ main(int argc, char **argv)
    printf("%3.3f sec, %3.3f M pixels (%i)\n", sec, (double)pixels / 1000000,
           pixels);
    printf("%3.3f Mpixels / sec\n", (double)(pixels) / (sec * 1000000));
+
+ quit:
+   if (im)
+     {
+        imlib_context_set_image(im);
+        imlib_free_image();
+     }
+   imlib_polygon_free(poly);
+   imlib_polygon_free(poly2);
+   imlib_polygon_free(poly3);
+
    return 0;
 }
diff --git a/src/bin/imlib2_test.c b/src/bin/imlib2_test.c
index b34d821..21bd05b 100644
--- a/src/bin/imlib2_test.c
+++ b/src/bin/imlib2_test.c
@@ -1,6 +1,7 @@
 #include "config.h"
 
 #include <X11/Xlib.h>
+#include <X11/keysym.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -16,6 +17,7 @@ main(int argc, char **argv)
 {
    /* events we get from X */
    XEvent              ev;
+   KeySym              keysym;
 
    /* areas to update */
    Imlib_Updates       updates, current_update;
@@ -46,7 +48,7 @@ main(int argc, char **argv)
    win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
                              0, 0, 640, 480, 0, 0, 0);
    /* tell X what events we are interested in */
-   XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
+   XSelectInput(disp, win, KeyPressMask | ButtonPressMask | ButtonReleaseMask |
                 PointerMotionMask | ExposureMask);
    /* show the window */
    XMapWindow(disp, win);
@@ -93,10 +95,14 @@ main(int argc, char **argv)
                                                      ev.xexpose.width,
                                                      ev.xexpose.height);
                   break;
+               case KeyPress:
+                  keysym = XLookupKeysym(&ev.xkey, 0);
+                  if (keysym == XK_q || keysym == XK_Escape)
+                     goto quit;
+                  break;
                case ButtonPress:
                   /* if we click anywhere in the window, exit */
-                  exit(0);
-                  break;
+                  goto quit;
                case MotionNotify:
                   /* if the mouse moves - note it */
                   /* add a rectangle update for the new mouse position */
@@ -271,5 +277,9 @@ main(int argc, char **argv)
            imlib_updates_free(updates);
         /* loop again waiting for events */
      }
+
+ quit:
+   imlib_updates_free(updates);
+
    return 0;
 }
diff --git a/src/bin/imlib2_view.c b/src/bin/imlib2_view.c
index 26f5dec..3d108d2 100644
--- a/src/bin/imlib2_view.c
+++ b/src/bin/imlib2_view.c
@@ -218,12 +218,12 @@ main(int argc, char **argv)
           case ClientMessage:
              if (ev.xclient.message_type == ATOM_WM_PROTOCOLS &&
                  (Atom) ev.xclient.data.l[0] == ATOM_WM_DELETE_WINDOW)
-                return 0;
+                goto quit;
              break;
           case KeyPress:
              key = XLookupKeysym(&ev.xkey, 0);
              if (key == XK_q || key == XK_Escape)
-                return 0;
+                goto quit;
              if (key == XK_Right)
                 goto show_next;
              if (key == XK_Left)
@@ -408,5 +408,7 @@ main(int argc, char **argv)
                }
           }
      }
+
+ quit:
    return 0;
 }

-- 


Reply via email to