summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2014-06-20 14:19:41 +0100
committerJon TURNEY <jon.turney@dronecode.org.uk>2014-06-20 14:19:41 +0100
commit781080903f7687a62bcfe4e3eba43afde9fd08ed (patch)
tree424ca6ce8f42beb7e85dec73bec45b75a322c0e5
parent23af93f4f59befee887624ad9a0e0c574393439c (diff)
Add multithread_quick_window, wm_normal_hints tests
-rw-r--r--[-rwxr-xr-x]gtk_window_maximize.c0
-rw-r--r--multithread_quick_window.c71
-rw-r--r--[-rwxr-xr-x]qt4_clip.cpp0
-rw-r--r--wm_normal_hints.c62
4 files changed, 133 insertions, 0 deletions
diff --git a/gtk_window_maximize.c b/gtk_window_maximize.c
index 6f1f378..6f1f378 100755..100644
--- a/gtk_window_maximize.c
+++ b/gtk_window_maximize.c
diff --git a/multithread_quick_window.c b/multithread_quick_window.c
new file mode 100644
index 0000000..a2a0491
--- /dev/null
+++ b/multithread_quick_window.c
@@ -0,0 +1,71 @@
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+//
+// gcc -g -Wall -o multithread_quick_window multithread_quick_window.c -lX11
+//
+// test case for a window which only exists briefly causing a X server segfault
+//
+
+static void *
+worker(void *ignored)
+{
+ // Open the display
+ Display *dpy = XOpenDisplay(NULL);
+ assert(dpy);
+
+ // Get some colors
+ int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
+
+ while (1)
+ {
+ XSizeHints sh;
+ int t;
+
+ // Create the window
+ Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, blackColor, blackColor);
+
+ sh.width = 200;
+ sh.height = 100;
+ sh.x = 0;
+ sh.y = 0;
+// sh.flags = (rand() % 2 == 1) ? (PPosition | USPosition) : 0;
+ sh.flags = (PPosition | USPosition);
+ XSetWMNormalHints(dpy, w, &sh);
+
+ // Map the window
+ XMapWindow(dpy, w);
+ XFlush(dpy);
+
+ t = rand() % 500000;
+ usleep(t);
+
+ XDestroyWindow(dpy, w);
+ XFlush(dpy);
+
+ t = rand() % 500000;
+ usleep(t);
+ }
+
+ return 0;
+}
+
+int main()
+{
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ pthread_t thread;
+ pthread_create(&thread, NULL, worker, NULL);
+ }
+
+ worker(NULL);
+
+ return 0;
+}
diff --git a/qt4_clip.cpp b/qt4_clip.cpp
index c489e0b..c489e0b 100755..100644
--- a/qt4_clip.cpp
+++ b/qt4_clip.cpp
diff --git a/wm_normal_hints.c b/wm_normal_hints.c
new file mode 100644
index 0000000..18a2122
--- /dev/null
+++ b/wm_normal_hints.c
@@ -0,0 +1,62 @@
+// gcc -o wm_normal_hints wm_normal_hints.c -lX11
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include <stdio.h>
+
+Display *display;
+int screen_num;
+Window root;
+
+Window create_window(char * name, Window parent, int x, int y, int width, int height)
+{
+ XSizeHints sh;
+ Window win = XCreateSimpleWindow(display, parent, x, y, width, height,
+ 2, // border width
+ BlackPixel(display, screen_num),
+ WhitePixel(display, screen_num));
+
+ sh.width = width;
+ sh.height = height;
+ sh.x = x;
+ sh.y = y;
+ sh.flags = PPosition;
+ XSetWMNormalHints(display, win, &sh);
+
+ return win;
+}
+
+int main(int argc, char **argv)
+{
+ Window window, win;
+ XEvent ev;
+
+ char *display_name = NULL;
+ if ((display = XOpenDisplay(display_name)) == NULL)
+ {
+ fprintf(stderr, "Couldn't open %s\n", XDisplayName(display_name));
+ return -1;
+ }
+ screen_num = DefaultScreen(display);
+ root = RootWindow(display, screen_num);
+
+ window = create_window("TestFrame", root, 1, 0, 200, 100);
+
+ XFlush(display);
+ XSync(display, False);
+
+ XMapWindow(display, window);
+
+ XFlush(display);
+ XSync(display, False);
+
+ while (1)
+ {
+ XNextEvent(display, &ev);
+
+ fprintf(stderr, "event on frame %i: ", ev.xany.window);
+ fprintf(stderr, "%d\n", ev.xany.type);
+ }
+ return 0;
+}