This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository legacy-imlib2.
View the commit online.
commit 0c687ee837dffdc7a715d7bce5dfe8a4d9ccf0df
Author: Kim Woelders <[email protected]>
AuthorDate: Sat Aug 27 17:42:25 2022 +0200
Unify basic X11 functionality in test programs
---
src/bin/Makefile.am | 16 +++++-----
src/bin/imlib2_bumpmap.c | 29 +++++-------------
src/bin/imlib2_colorspace.c | 30 +++++--------------
src/bin/imlib2_grab.c | 17 ++---------
src/bin/imlib2_poly.c | 30 +++++--------------
src/bin/imlib2_show.c | 42 +++++++-------------------
src/bin/imlib2_test.c | 41 ++++++++++---------------
src/bin/imlib2_view.c | 27 +++--------------
src/bin/prog_x11.c | 73 +++++++++++++++++++++++++++++++++++++++++++++
src/bin/prog_x11.h | 12 ++++++++
src/bin/props.c | 25 ----------------
src/bin/props.h | 16 ----------
12 files changed, 151 insertions(+), 207 deletions(-)
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 6768acd..1a64e30 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -16,29 +16,31 @@ imlib2_conv \
imlib2_load \
$(X_BASED_PROGS)
+SRCS_COMMON_X11 = prog_x11.c prog_x11.h
+
imlib2_conv_SOURCES = imlib2_conv.c
imlib2_conv_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_load_SOURCES = imlib2_load.c
imlib2_load_LDADD = $(top_builddir)/src/lib/libImlib2.la $(CLOCK_LIBS)
-imlib2_show_SOURCES = imlib2_show.c
+imlib2_show_SOURCES = imlib2_show.c $(SRCS_COMMON_X11)
imlib2_show_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11 -lm
-imlib2_test_SOURCES = imlib2_test.c
+imlib2_test_SOURCES = imlib2_test.c $(SRCS_COMMON_X11)
imlib2_test_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11
-imlib2_bumpmap_SOURCES = imlib2_bumpmap.c
+imlib2_bumpmap_SOURCES = imlib2_bumpmap.c $(SRCS_COMMON_X11)
imlib2_bumpmap_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11
-imlib2_poly_SOURCES = imlib2_poly.c
+imlib2_poly_SOURCES = imlib2_poly.c $(SRCS_COMMON_X11)
imlib2_poly_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11
-imlib2_colorspace_SOURCES = imlib2_colorspace.c
+imlib2_colorspace_SOURCES = imlib2_colorspace.c $(SRCS_COMMON_X11)
imlib2_colorspace_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11
-imlib2_view_SOURCES = imlib2_view.c props.c props.h
+imlib2_view_SOURCES = imlib2_view.c $(SRCS_COMMON_X11)
imlib2_view_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11
-imlib2_grab_SOURCES = imlib2_grab.c
+imlib2_grab_SOURCES = imlib2_grab.c $(SRCS_COMMON_X11)
imlib2_grab_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11
diff --git a/src/bin/imlib2_bumpmap.c b/src/bin/imlib2_bumpmap.c
index 690ace0..4aefe10 100644
--- a/src/bin/imlib2_bumpmap.c
+++ b/src/bin/imlib2_bumpmap.c
@@ -6,7 +6,8 @@
#include <stdio.h>
#include <stdlib.h>
-Display *disp;
+#include "prog_x11.h"
+
Window win;
int
@@ -22,29 +23,13 @@ main(int argc, char **argv)
*/
printf("Initialising\n");
- /**
- * First tests to determine which rendering task to perform
- */
- disp = XOpenDisplay(NULL);
- if (!disp)
- {
- fprintf(stderr, "Cannot open display\n");
- return 1;
- }
-
- win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
- 0, 0, 0);
- XSelectInput(disp, win, KeyPressMask |
- ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
- PointerMotionMask | ExposureMask);
+ prog_x11_init();
+ win = prog_x11_create_window("imlib2_bumpmap", 100, 100);
/**
* Start rendering
*/
printf("Rendering\n");
- imlib_context_set_display(disp);
- imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
- imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
imlib_context_set_drawable(win);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
@@ -70,6 +55,10 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
+ default:
+ if (prog_x11_event(&ev))
+ goto quit;
+ break;
case KeyPress:
keysym = XLookupKeysym(&ev.xkey, 0);
if (keysym == XK_q || keysym == XK_Escape)
@@ -81,8 +70,6 @@ main(int argc, char **argv)
x = ev.xmotion.x;
y = ev.xmotion.y;
break;
- default:
- break;
}
}
while (XPending(disp));
diff --git a/src/bin/imlib2_colorspace.c b/src/bin/imlib2_colorspace.c
index a9e6ca9..853e257 100644
--- a/src/bin/imlib2_colorspace.c
+++ b/src/bin/imlib2_colorspace.c
@@ -6,12 +6,12 @@
#include <stdio.h>
#include <stdlib.h>
-Display *disp;
-Window win;
+#include "prog_x11.h"
int
main(int argc, char **argv)
{
+ Window win;
int w, h;
Imlib_Image im_bg = NULL;
XEvent ev;
@@ -23,21 +23,9 @@ main(int argc, char **argv)
int tw, th;
#endif
- /**
- * First tests to determine which rendering task to perform
- */
- disp = XOpenDisplay(NULL);
- if (!disp)
- {
- fprintf(stderr, "Cannot open display\n");
- return 1;
- }
+ prog_x11_init();
- win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
- 0, 0, 0);
- XSelectInput(disp, win,
- ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
- PointerMotionMask | ExposureMask | KeyPressMask);
+ win = prog_x11_create_window("imlib2_colorspace", 100, 100);
/**
* Start rendering
@@ -46,9 +34,6 @@ main(int argc, char **argv)
imlib_set_font_cache_size(512 * 1024);
imlib_add_path_to_font_path(PACKAGE_DATA_DIR "/data/fonts");
#endif
- imlib_context_set_display(disp);
- imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
- imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
imlib_context_set_drawable(win);
imlib_context_set_blend(0);
imlib_context_set_color_modifier(NULL);
@@ -72,6 +57,10 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
+ default:
+ if (prog_x11_event(&ev))
+ goto quit;
+ break;
case KeyPress:
keysym = XLookupKeysym(&ev.xkey, 0);
if (keysym == XK_q || keysym == XK_Escape)
@@ -79,9 +68,6 @@ main(int argc, char **argv)
break;
case ButtonRelease:
goto quit;
- default:
- break;
-
}
}
while (XPending(disp));
diff --git a/src/bin/imlib2_grab.c b/src/bin/imlib2_grab.c
index 8d14eeb..28b3cee 100644
--- a/src/bin/imlib2_grab.c
+++ b/src/bin/imlib2_grab.c
@@ -6,8 +6,7 @@
#include <string.h>
#include <stdlib.h>
-Display *disp;
-int image_width = 0, image_height = 0;
+#include "prog_x11.h"
static void
usage(void)
@@ -24,7 +23,6 @@ main(int argc, char **argv)
char *file = NULL;
int verbose;
int get_alpha;
- const char *display_name = getenv("DISPLAY");
Drawable draw;
int x, y;
unsigned int w, h, bw;
@@ -93,18 +91,7 @@ main(int argc, char **argv)
file = argv[0];
- if (!display_name)
- display_name = ":0";
- disp = XOpenDisplay(display_name);
- if (!disp)
- {
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
- }
-
- imlib_context_set_display(disp);
- imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
- imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
+ prog_x11_init();
if (draw == None)
draw = DefaultRootWindow(disp);
diff --git a/src/bin/imlib2_poly.c b/src/bin/imlib2_poly.c
index f3153e6..8c55692 100644
--- a/src/bin/imlib2_poly.c
+++ b/src/bin/imlib2_poly.c
@@ -6,40 +6,25 @@
#include <stdio.h>
#include <stdlib.h>
-Display *disp;
-Window win;
+#include "prog_x11.h"
int
main(int argc, char **argv)
{
+ Window win;
int w, h;
Imlib_Image im_bg = NULL;
XEvent ev;
KeySym keysym;
ImlibPolygon poly, poly1, poly2;
- /**
- * First tests to determine which rendering task to perform
- */
- disp = XOpenDisplay(NULL);
- if (!disp)
- {
- fprintf(stderr, "Cannot open display\n");
- return 1;
- }
+ prog_x11_init();
- win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
- 0, 0, 0);
- XSelectInput(disp, win,
- ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
- PointerMotionMask | ExposureMask | KeyPressMask);
+ win = prog_x11_create_window("imlib2_poly", 100, 100);
/**
* Start rendering
*/
- imlib_context_set_display(disp);
- imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
- imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
imlib_context_set_drawable(win);
imlib_context_set_blend(0);
imlib_context_set_color_modifier(NULL);
@@ -79,6 +64,10 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
+ default:
+ if (prog_x11_event(&ev))
+ goto quit;
+ break;
case KeyPress:
keysym = XLookupKeysym(&ev.xkey, 0);
switch (keysym)
@@ -98,9 +87,6 @@ main(int argc, char **argv)
break;
case ButtonRelease:
goto quit;
- default:
- break;
-
}
}
while (XPending(disp));
diff --git a/src/bin/imlib2_show.c b/src/bin/imlib2_show.c
index 740fb45..60dd7f6 100644
--- a/src/bin/imlib2_show.c
+++ b/src/bin/imlib2_show.c
@@ -11,8 +11,9 @@
#include <math.h>
#include <locale.h>
-Display *disp;
-Window win;
+#include "prog_x11.h"
+
+static Window win;
void progress(Imlib_Image * im, char percent, int update_x,
int update_y, int update_w, int update_h);
@@ -21,7 +22,6 @@ void
progress(Imlib_Image * im, char percent,
int update_x, int update_y, int update_w, int update_h)
{
- imlib_context_set_display(disp);
imlib_context_set_drawable(win);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
@@ -267,16 +267,7 @@ main(int argc, char **argv)
*/
if (!blendtest)
{
- const char *display_name = getenv("DISPLAY");
-
- if (!display_name)
- display_name = ":0";
- disp = XOpenDisplay(display_name);
- if (!disp)
- {
- fprintf(stderr, "Can't open display %s\n", display_name);
- return 1;
- }
+ prog_x11_init();
#if 0
/* nasty - using imlib internal function.. but it makes benchmarks fair */
if (!interactive)
@@ -285,14 +276,9 @@ main(int argc, char **argv)
if (root)
win = DefaultRootWindow(disp);
else
- {
- win =
- XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10,
- 10, 0, 0, 0);
- XSelectInput(disp, win, KeyPressMask |
- ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
- | PointerMotionMask | ExposureMask);
- }
+ win = prog_x11_create_window("imlib2_show", 100, 100);
+
+ imlib_context_set_drawable(win);
}
if (!interactive)
@@ -338,13 +324,6 @@ main(int argc, char **argv)
*/
printf("rend\n");
- if (!blendtest)
- {
- imlib_context_set_display(disp);
- imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
- imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
- imlib_context_set_drawable(win);
- }
imlib_context_set_anti_alias(aa);
imlib_context_set_dither(dith);
imlib_context_set_blend(blend);
@@ -957,6 +936,10 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
+ default:
+ if (prog_x11_event(&ev))
+ goto quit;
+ break;
case Expose:
up = imlib_update_append_rect(up,
ev.xexpose.x,
@@ -981,9 +964,6 @@ main(int argc, char **argv)
case MotionNotify:
x = ev.xmotion.x;
y = ev.xmotion.y;
- default:
- break;
-
}
}
while (XPending(disp));
diff --git a/src/bin/imlib2_test.c b/src/bin/imlib2_test.c
index ad8d4aa..cbdfefb 100644
--- a/src/bin/imlib2_test.c
+++ b/src/bin/imlib2_test.c
@@ -6,14 +6,13 @@
#include <stdio.h>
#include <stdlib.h>
-/* some globals for our window & X display */
-Display *disp;
-Window win;
+#include "prog_x11.h"
-/* the program... */
int
main(int argc, char **argv)
{
+ Window win;
+
/* events we get from X */
XEvent ev;
KeySym keysym;
@@ -30,27 +29,18 @@ main(int argc, char **argv)
/* our mouse x, y coordinates */
int mouse_x = 0, mouse_y = 0;
- /* connect to X */
- disp = XOpenDisplay(NULL);
- if (!disp)
- {
- fprintf(stderr, "Cannot open display\n");
- return 1;
- }
+ prog_x11_init();
- /* get default visual , colormap etc. you could ask imlib2 for what it */
- /* thinks is the best, but this example is intended to be simple */
/* create a window 640x480 */
- win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
- 0, 0, 640, 480, 0, 0, 0);
- /* tell X what events we are interested in */
- XSelectInput(disp, win, KeyPressMask | ButtonPressMask | ButtonReleaseMask |
- PointerMotionMask | ExposureMask);
+ win = prog_x11_create_window("imlib2_test", 640, 480);
+
/* show the window */
XMapWindow(disp, win);
+
/* set our cache to 2 Mb so it doesn't have to go hit the disk as long as */
/* the images we use use less than 2Mb of RAM (that is uncompressed) */
imlib_set_cache_size(2048 * 1024);
+
#if ENABLE_TEXT
/* set the font cache to 512Kb - again to avoid re-loading */
imlib_set_font_cache_size(512 * 1024);
@@ -58,14 +48,14 @@ main(int argc, char **argv)
/* in that dir for the text to display */
imlib_add_path_to_font_path(PACKAGE_DATA_DIR "/data/fonts");
#endif
+
/* set the maximum number of colors to allocate for 8bpp and less to 128 */
imlib_set_color_usage(128);
+
/* dither for depths < 24bpp */
imlib_context_set_dither(1);
- /* set the display , visual, colormap and drawable we are using */
- imlib_context_set_display(disp);
- imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
- imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
+
+ /* set the drawable we are using */
imlib_context_set_drawable(win);
/* infinite event loop */
@@ -91,6 +81,10 @@ main(int argc, char **argv)
XNextEvent(disp, &ev);
switch (ev.type)
{
+ default:
+ if (prog_x11_event(&ev))
+ goto quit;
+ break;
case Expose:
/* window rectangle was exposed - add it to the list of */
/* rectangles we need to re-render */
@@ -160,9 +154,6 @@ main(int argc, char **argv)
}
#endif /* ENABLE_TEXT */
break;
- default:
- /* any other events - do nothing */
- break;
}
}
while (XPending(disp));
diff --git a/src/bin/imlib2_view.c b/src/bin/imlib2_view.c
index 9f6af27..6366512 100644
--- a/src/bin/imlib2_view.c
+++ b/src/bin/imlib2_view.c
@@ -9,13 +9,11 @@
#include <stdbool.h>
#include <unistd.h>
-#include "props.h"
+#include "prog_x11.h"
#define MIN(a, b) ((a < b) ? a : b)
#define MAX(a, b) ((a > b) ? a : b)
-Display *disp;
-
typedef struct {
int x, y; /* Origin */
int w, h; /* Size */
@@ -599,23 +597,9 @@ main(int argc, char **argv)
return 1;
}
- disp = XOpenDisplay(NULL);
- if (!disp)
- {
- fprintf(stderr, "Cannot open display\n");
- return 1;
- }
-
- win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10, 10,
- 0, 0, 0);
- XSelectInput(disp, win, KeyPressMask | ButtonPressMask | ButtonReleaseMask |
- ButtonMotionMask | PointerMotionMask);
-
- props_win_set_proto_quit(win);
+ prog_x11_init();
- imlib_context_set_display(disp);
- imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
- imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
+ win = prog_x11_create_window("imlib2_view", 10, 10);
if (opt_progr)
{
@@ -678,10 +662,7 @@ main(int argc, char **argv)
switch (ev.type)
{
default:
- break;
-
- case ClientMessage:
- if (props_clientmsg_check_quit(&ev.xclient))
+ if (prog_x11_event(&ev))
goto quit;
break;
case KeyPress:
diff --git a/src/bin/prog_x11.c b/src/bin/prog_x11.c
new file mode 100644
index 0000000..8807b88
--- /dev/null
+++ b/src/bin/prog_x11.c
@@ -0,0 +1,73 @@
+/*
+ * Common program functionality
+ */
+#include "config.h"
+#include <Imlib2.h>
+
+#include <stdio.h>
+#include <X11/Xlib.h>
+
+#include "prog_x11.h"
+
+Display *disp = NULL;
+
+static Atom ATOM_WM_DELETE_WINDOW = None;
+static Atom ATOM_WM_PROTOCOLS = None;
+
+int
+prog_x11_init(void)
+{
+ disp = XOpenDisplay(NULL);
+ if (!disp)
+ {
+ fprintf(stderr, "Cannot open display\n");
+ return 1;
+ }
+
+ imlib_context_set_display(disp);
+ imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
+ imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
+
+ return 0;
+}
+
+Window
+prog_x11_create_window(const char *name, int w, int h)
+{
+ Window win;
+ int x, y;
+
+ x = y = 0;
+
+ win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
+ x, y, w, h, 0, 0, 0);
+
+ XSelectInput(disp, win, KeyPressMask |
+ ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
+ PointerMotionMask | ExposureMask);
+
+ XStoreName(disp, win, name);
+
+ ATOM_WM_PROTOCOLS = XInternAtom(disp, "WM_PROTOCOLS", False);
+ ATOM_WM_DELETE_WINDOW = XInternAtom(disp, "WM_DELETE_WINDOW", False);
+ XSetWMProtocols(disp, win, &ATOM_WM_DELETE_WINDOW, 1);
+
+ return win;
+}
+
+int
+prog_x11_event(XEvent * ev)
+{
+ switch (ev->type)
+ {
+ default:
+ break;
+ case ClientMessage:
+ if (ev->xclient.message_type == ATOM_WM_PROTOCOLS &&
+ ev->xclient.data.l[0] == (long)ATOM_WM_DELETE_WINDOW)
+ return 1;
+ break;
+ }
+
+ return 0;
+}
diff --git a/src/bin/prog_x11.h b/src/bin/prog_x11.h
new file mode 100644
index 0000000..271c582
--- /dev/null
+++ b/src/bin/prog_x11.h
@@ -0,0 +1,12 @@
+#ifndef PROG_X11_H
+#define PROG_X11_H
+
+#include <X11/Xlib.h>
+
+extern Display *disp;
+
+int prog_x11_init(void);
+Window prog_x11_create_window(const char *name, int w, int h);
+int prog_x11_event(XEvent * ev);
+
+#endif /* PROG_X11_H */
diff --git a/src/bin/props.c b/src/bin/props.c
deleted file mode 100644
index e5e8681..0000000
--- a/src/bin/props.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Property handling
- */
-#include <X11/Xatom.h>
-#include <X11/Xlib.h>
-
-#include "props.h"
-
-static Atom ATOM_WM_DELETE_WINDOW = None;
-static Atom ATOM_WM_PROTOCOLS = None;
-
-void
-props_win_set_proto_quit(Window win)
-{
- ATOM_WM_PROTOCOLS = XInternAtom(disp, "WM_PROTOCOLS", False);
- ATOM_WM_DELETE_WINDOW = XInternAtom(disp, "WM_DELETE_WINDOW", False);
- XSetWMProtocols(disp, win, &ATOM_WM_DELETE_WINDOW, 1);
-}
-
-int
-props_clientmsg_check_quit(const XClientMessageEvent * ev)
-{
- return ev->message_type == ATOM_WM_PROTOCOLS &&
- (Atom) ev->data.l[0] == ATOM_WM_DELETE_WINDOW;
-}
diff --git a/src/bin/props.h b/src/bin/props.h
deleted file mode 100644
index aeecbf1..0000000
--- a/src/bin/props.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Property handling
- */
-#ifndef PROPS_H
-#define PROPS_H
-
-#include <X11/Xatom.h>
-#include <X11/Xlib.h>
-
-extern Display *disp;
-
-void props_win_set_proto_quit(Window win);
-
-int props_clientmsg_check_quit(const XClientMessageEvent * ev);
-
-#endif /* PROPS_H */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.