diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2014-03-14 20:17:34 +0000 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2014-03-16 18:57:29 +0000 |
commit | 5014e38500e12ac9bf3c207b72ebfbce3f1f6ae5 (patch) | |
tree | 81e621fd64de5a5b072e0286a3fd63246081a334 | |
parent | 04475105a6a9cc1f78e51d3d782d1dd7c080d431 (diff) |
more testcases
-rw-r--r-- | README | 3 | ||||
-rwxr-xr-x | TypeInSwing.java | 16 | ||||
-rwxr-xr-x | gtk_window_maximize.c | 28 | ||||
-rw-r--r-- | iconized.c | 87 | ||||
-rw-r--r-- | makecurrenttest.c | 29 | ||||
-rw-r--r-- | test-invalid-net-wm-icon.c | 12 | ||||
-rw-r--r-- | test-wm-class.c | 48 | ||||
-rw-r--r-- | wm_take_focus.c | 98 |
8 files changed, 304 insertions, 17 deletions
@@ -3,5 +3,6 @@ A collection of small X programs for testing, mainly for window manager behaviou Also, don't forget about: metacity-window-demo -qt4-qtdemo +qtdemo-qt4 +gtk-demo measdemos diff --git a/TypeInSwing.java b/TypeInSwing.java new file mode 100755 index 0000000..4f5a623 --- /dev/null +++ b/TypeInSwing.java @@ -0,0 +1,16 @@ + +import javax.swing.JFrame; +import javax.swing.JTextField; + +public class TypeInSwing { + public static void main(String[] args) { + JFrame frame = new JFrame("HelloWorldSwing"); + final JTextField field = new JTextField("type here"); + + frame.getContentPane().add(field); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.pack(); + frame.setVisible(true); + } +} diff --git a/gtk_window_maximize.c b/gtk_window_maximize.c new file mode 100755 index 0000000..6f1f378 --- /dev/null +++ b/gtk_window_maximize.c @@ -0,0 +1,28 @@ +
+#include <gtk/gtk.h>
+
+// gcc -o gtk_window_maximize gtk_window_maximize.c `pkg-config --libs --cflags gtk+-2.0`
+
+//pygtk:
+// win = gtk.Window()
+// win.maximize()
+// win.show()
+
+int main(int argc, char *argv[]){
+ /**
+ doesn't work under cygwin
+ */
+ GtkWidget *window;
+
+ gtk_init(&argc, &argv);
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ g_signal_connect(window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+ gtk_window_maximize(GTK_WINDOW(window));
+ gtk_widget_show(window);
+
+ gtk_main();
+
+ return 0;
+}
+
diff --git a/iconized.c b/iconized.c new file mode 100644 index 0000000..e31339e --- /dev/null +++ b/iconized.c @@ -0,0 +1,87 @@ +/* Compile with "gcc -o iconized -Wall iconized.c -lX11" */ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Xatom.h> + +/* This exercises some window state transitions per ICCCM 4.1.4 */ + +/* Run as ./initially_iconized [0|1] to select initial state */ +/* Click middle mouse button on window to toggle */ + +int main(int argc, char** argv) +{ + if (argc != 2 || strcmp(argv[1], "-h") == 0) + { + fprintf(stderr, "Usage: %s [iconized]\n", argv[0]); + return 1; + } + + Display* display = XOpenDisplay(NULL); + if (!display) { + fprintf(stderr, "Couldn't open display\n"); + return 1; + } + int screen = DefaultScreen(display); + + const int width = 300, height = 200; + + unsigned long black = BlackPixel(display, screen); + unsigned long white = WhitePixel(display, screen); + + Window win = XCreateSimpleWindow(display, + RootWindow(display, screen), + 0, /* x */ + 0, /* y */ + width, + height, + 0, /* border_width */ + black, /* border */ + white); /* background */ + + Bool toggle = (strcmp(argv[1], "0") != 0); + + fprintf(stderr, "Setting WM_HINT to %s\n", (toggle ? "iconized" : "normal")); + + XWMHints *hints = XAllocWMHints(); + hints->flags = StateHint; + hints->initial_state = toggle ? IconicState : NormalState; + XSetWMHints(display, win, hints); + XFree(hints); + + XSelectInput(display, win, ButtonPressMask); + XMapWindow(display, win); + + while (1) { + XEvent event; + XNextEvent(display, &event); + + if (event.type == ButtonPress) { + XButtonEvent be = event.xbutton; + if (be.button == 2) { + fprintf(stderr, "XIconifyWindow()\n"); + XIconifyWindow(display, win, screen); + XFlush(display); + + { + int i; + fprintf(stderr, "I'll be back!\n"); + for (i = 10; i > 0; i--) + { + sleep(1); + printf("%d...\n", i); + } + } + + fprintf(stderr, "XMapWindow()\n"); + XMapWindow(display, win); + XFlush(display); + } + } + } + + return 0; +} diff --git a/makecurrenttest.c b/makecurrenttest.c index cb28458..0d6098c 100644 --- a/makecurrenttest.c +++ b/makecurrenttest.c @@ -10,9 +10,6 @@ // // gcc -g -Wall -o makecurrenttest makecurrenttest.c -lX11 -lGL // -// test case for a window which only exists briefly -// causing a X server segfault -// static Window make_rgb_db_window( Display *dpy, XVisualInfo *visinfo, unsigned int width, unsigned int height ) @@ -43,6 +40,8 @@ static Window make_rgb_db_window( Display *dpy, XVisualInfo *visinfo, int main() { + int i; + // Open the display Display *dpy = XOpenDisplay(NULL); assert(dpy); @@ -67,19 +66,25 @@ int main() // Map the window XMapWindow(dpy, w); - GLXContext ctx = glXCreateContext(dpy, visinfo, NULL, True ); - if (!ctx) { - printf("Error: glXCreateContext failed\n"); - assert(0); - } + XFlush(dpy); - glXMakeCurrent(dpy, w, ctx); + for (i=0; i < 2; i++) + { + // Create context + GLXContext ctx = glXCreateContext(dpy, visinfo, NULL, True ); + if (!ctx) { + printf("Error: glXCreateContext failed\n"); + assert(0); + } - XDestroyWindow(dpy, w); + // Make current + glXMakeCurrent(dpy, w, ctx); - glXMakeCurrent(dpy, None, NULL); + // Destroy context + glXDestroyContext(dpy, ctx); - XFlush(dpy); + XFlush(dpy); + } return 0; } diff --git a/test-invalid-net-wm-icon.c b/test-invalid-net-wm-icon.c index 7ce9829..f3c926b 100644 --- a/test-invalid-net-wm-icon.c +++ b/test-invalid-net-wm-icon.c @@ -1,4 +1,4 @@ -/* gcc test-invalid-net-wm-icon.c -o test-invalid-net-wm-icon.exe -lX11 */ +/* gcc test-invalid-net-wm-icon.c -o test-invalid-net-wm-icon -lX11 */ #include <stdlib.h> #include <stdio.h> @@ -23,7 +23,7 @@ void test(unsigned int *buffer, unsigned int buffer_length) int main(int argc, char **argv) { - /* Invalid _NET_WM_ICO icons */ + /* Invalid _NET_WM_ICON icons */ d = XOpenDisplay(0); int s = DefaultScreen(d); net_wm_icon = XInternAtom(d, "_NET_WM_ICON", False); @@ -40,6 +40,10 @@ int main(int argc, char **argv) unsigned int buffer[] = {-1, -1, 0xFFFFFFFF, 0xFFFFFFFF}; test(buffer, sizeof(buffer)); + // sizes are still just absurd + unsigned int buffer1[] = {0x80000001, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFF}; + test(buffer1, sizeof(buffer1)); + // property should be 256K, but is only 64K int propsize = 0x10000; unsigned int *buffer2 = malloc(propsize); @@ -51,8 +55,8 @@ int main(int argc, char **argv) propsize = 0x100000; unsigned int *buffer3 = malloc(propsize); assert(buffer3); - buffer2[0] = 0x3000; - buffer2[1] = 0x3000; + buffer3[0] = 0x3000; + buffer3[1] = 0x3000; test(buffer3, propsize); while(1) XNextEvent(d, &e); diff --git a/test-wm-class.c b/test-wm-class.c new file mode 100644 index 0000000..119434a --- /dev/null +++ b/test-wm-class.c @@ -0,0 +1,48 @@ +/* gcc test-wm-class.c -o test-wm-class -lX11 */ + +/* Normally you'd use XSetClassHint() to set WM_CLASS, which ensures +that it consists of 2 null terminated strings, but some applications don't +and we must handle malformed WM_CLASS safely */ + +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> + +#include <X11/Xlib.h> +#include <X11/Xatom.h> + +Display *d; + + +void test(unsigned char *buffer, unsigned int buffer_length) +{ + Window w; + + w = XCreateWindow(d, RootWindow(d, DefaultScreen(d)), 0, 0, 200, 200, 0, + CopyFromParent, InputOutput, CopyFromParent, 0, 0); + + Atom wm_class = XInternAtom(d, "WM_CLASS", False); + + XChangeProperty(d, w, wm_class, XA_STRING, 8, PropModeReplace, buffer, buffer_length); + + XMapWindow(d, w); + XFlush(d); + sleep(1); +} + +int main(int argc, char **argv) +{ + d = XOpenDisplay(0); + + test("", 0); + test("\0", 1); + test("\0\0", 2); + + test("foo", 3); + test("foo\0", 4); + test("foo\0b", 5); + test("foo\0bar", 7); + test("foo\0bar\0", 8); + + while(1) sleep(1); +} diff --git a/wm_take_focus.c b/wm_take_focus.c new file mode 100644 index 0000000..345e2cd --- /dev/null +++ b/wm_take_focus.c @@ -0,0 +1,98 @@ +// gcc -o wm_take_focus wm_take_focus.c -lX11 + +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +#include <stdio.h> + +Display *display; +int screen_num; +Window root; +Atom XA_WM_TAKE_FOCUS; + +Window create_window(char * name, Window parent, int x, int y, int width, int height) +{ + XSizeHints sh; + XWMHints wmh; + Window win = XCreateSimpleWindow(display, parent, x, y, width, height, + 2, // border width + BlackPixel(display, screen_num), + WhitePixel(display, screen_num)); + XStoreName(display, win, name); + XSelectInput(display, win, FocusChangeMask | ButtonPressMask | ButtonReleaseMask ); + + sh.width = width; + sh.height = height; + sh.x = x; + sh.y = y; + sh.flags = USPosition | USSize; + XSetWMNormalHints(display, win, &sh); + + wmh.input = False; + wmh.flags = InputHint; + XSetWMHints(display, win, &wmh); + + Atom protocols[1]; + protocols[0] = XA_WM_TAKE_FOCUS = XInternAtom (display, "WM_TAKE_FOCUS", True); + XSetWMProtocols (display, win, protocols, 1); + + 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, 100, 100, 200, 100); + + XMapWindow(display, window); + + XFlush(display); + XSync(display, False); + + while (1) + { + XNextEvent(display, &ev); + + int i = 0; + for (i = 0; i < 2; i++) { + + win = ev.xany.window; + if (win == window) { + + fprintf(stderr, "event on frame %i: ", i); + + switch(ev.xany.type) { + + case ClientMessage: + fprintf(stderr, "ClientMessage\n"); + if (ev.xclient.data.l[0] == XA_WM_TAKE_FOCUS) { + fprintf(stderr, " WM_TAKE_FOCUS\n"); + XSetInputFocus(display, win, RevertToPointerRoot, CurrentTime); + } + break; + case FocusIn: + fprintf(stderr, "FocusIn\n"); + break; + case FocusOut: + fprintf(stderr, "FocusOut\n"); + break; + default: + fprintf(stderr, "%d\n", ev.xany.type); + } + } + } + } + return 0; +} + |