diff options
author | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-11-07 21:12:44 +0000 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-11-07 22:00:40 +0000 |
commit | c97341d77ef876068b0f4f4838e10a1b167896ba (patch) | |
tree | f4783ea6c386a3dc78a6b2fe9c6c93318a820913 | |
parent | 45f7e04bb0f53223a5d05d93aa42b3faa6a97d76 (diff) |
More testcases
-rw-r--r-- | skip_taskbar.c | 80 | ||||
-rw-r--r-- | test_glXCreateWindow.c | 88 | ||||
-rw-r--r-- | windowexiststest.c | 54 | ||||
-rw-r--r-- | xhole.c | 78 | ||||
-rw-r--r-- | xscreensaversuspendtest.c | 39 |
5 files changed, 339 insertions, 0 deletions
diff --git a/skip_taskbar.c b/skip_taskbar.c new file mode 100644 index 0000000..139921f --- /dev/null +++ b/skip_taskbar.c @@ -0,0 +1,80 @@ +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Xatom.h> + +/* Compile with "gcc -o skip_taskbar -Wall skip_taskbar.c -lX11" */ + +/* Run as ./skip_taskbar [0|1] to select initial state */ +/* Click middle mouse button on window to toggle */ + +/* Set window state hint to skip taskbar or not */ +static void SetSkipTaskbarHint(Display* display, Window win, Bool toggle) +{ + fprintf(stderr, "Setting hint to %s on taskbar 0x%x\n", (toggle ? "hide" : "show"), (unsigned int)win); + + Atom skip_taskbar = XInternAtom(display, "_NET_WM_STATE_SKIP_TASKBAR",False); + Atom net_wm_state = XInternAtom(display, "_NET_WM_STATE",False); + + if (toggle) + { + XChangeProperty(display, win, net_wm_state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&skip_taskbar, 1); + } + else + { + XDeleteProperty(display, win, net_wm_state); + } +} + +int main(int argc, char** argv) +{ + if (argc != 2 || strcmp(argv[1], "-h") == 0) + { + fprintf(stderr, "Usage: %s [show_on_taskbar]\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); + SetSkipTaskbarHint(display, win, toggle); + + 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) { + toggle = !toggle; + SetSkipTaskbarHint(display, win, toggle); + } + } + } + + return 0; +} diff --git a/test_glXCreateWindow.c b/test_glXCreateWindow.c new file mode 100644 index 0000000..8ee1898 --- /dev/null +++ b/test_glXCreateWindow.c @@ -0,0 +1,88 @@ +/* This case is to test the glXCreateWindow() support. + * compile: + * gcc -o test_glXCreateWindow test_glXCreateWindow.c -lGL + * run: + * LIBGL_ALWAYS_SOFTWARE=yes ./test_glXCreateWindow + * + * Result: + * The case should have no any output suppose the API works well. + * Right now the mesa will report: + * failed to create drawable + */ +#include<stdio.h> +#include<stdlib.h> +#include<X11/X.h> +#include<X11/Xlib.h> +#include<GL/gl.h> +#include<GL/glx.h> + +static const int attributes[] = { + GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DOUBLEBUFFER, GL_TRUE, + None +}; + +int main(void) +{ + GLXFBConfig config = NULL; + GLXFBConfig *configs = NULL; + + Window dummy_xwin; + XVisualInfo *xvisinfo; + int major; + int minor; + int n_configs, i; + GLXDrawable dummy_drawable; + GLXWindow dummy_glxwin; + + Display *xdisplay = XOpenDisplay(NULL); + int xscreen_num = DefaultScreen (xdisplay); + Window root_xwin = DefaultRootWindow (xdisplay); + + configs = glXChooseFBConfig (xdisplay, + xscreen_num, + attributes, + &n_configs); + if (configs) + { + config = configs[0]; + XFree (configs); + } + else + { + fprintf (stderr, "Unable to find config!\n"); + return; + } + + xvisinfo = glXGetVisualFromFBConfig (xdisplay, config); + if (xvisinfo == None) + { + fprintf (stderr, "Unable to retrieve the X11 visual!\n"); + return; + } + + dummy_xwin = XCreateWindow (xdisplay, root_xwin, + 100, 100, 200, 200, + 0, + xvisinfo->depth, + CopyFromParent, + xvisinfo->visual, + None, + None); + + if (glXQueryVersion (xdisplay, &major, &minor) && + major == 1 && minor >= 3) + { + dummy_glxwin = glXCreateWindow (xdisplay, + config, + dummy_xwin, + NULL); + } + else + { + fprintf (stderr, "The test cannot be performed in current GLX version : %d.%d\n", major, minor); + } + + return; +} diff --git a/windowexiststest.c b/windowexiststest.c new file mode 100644 index 0000000..b8e36c8 --- /dev/null +++ b/windowexiststest.c @@ -0,0 +1,54 @@ + +#include <X11/X.h> +#include <X11/Xlib.h> +#include <assert.h> + +// +// gcc -g -Wall -o testcase testcase.c -lX11 +// + +static int WindowExistsFlag; + +static int window_exists_err_handler( Display* dpy, XErrorEvent* xerr ) +{ + (void) dpy; + if (xerr->error_code == BadWindow) + { + WindowExistsFlag = 0; + } + return 0; +} + +static int window_exists( Display *dpy, Window win ) +{ + XWindowAttributes wa; + int (*old_handler)(Display*, XErrorEvent*); + + WindowExistsFlag = 1; + old_handler = XSetErrorHandler(window_exists_err_handler); + XGetWindowAttributes( dpy, win, &wa ); /* dummy request */ + XSetErrorHandler(old_handler); + + return WindowExistsFlag; +} + +int main() +{ + int i; + Display *dpy = XOpenDisplay(NULL); + assert(dpy); + + int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); + + for (i = 0; i < 2; i++) + { + Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, blackColor, blackColor); + XMapWindow(dpy, w); + XDestroyWindow(dpy, w); + XSync(dpy, 0); + window_exists(dpy, w); + XSync(dpy, 0); + } + + return 0; +} @@ -0,0 +1,78 @@ +// from http://en.wikipedia.org/wiki/Shape_extension +// gcc -o xhole xhole.c -lX11 -lXext + +/* + + xhole.c + +A sample application using the shape extension. +Creates a window with a hole in the middle. Works +with twm, fvwm, and mwm, but kde refuses to add +a title bar to it. +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <X11/Xlib.h> +#include <X11/extensions/shape.h> + +int main() { + Display *d; + int s; + Window w; + Pixmap p; + GC gw, gp; + XEvent e; + int x, y; + + /* open connection with the server */ + d=XOpenDisplay(NULL); + if(d==NULL) { + printf("Cannot open display\n"); + exit(1); + } + s=DefaultScreen(d); + gw=DefaultGC(d, s); + + /* create window, select events, map */ + w=XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 200, 1, + BlackPixel(d, s), WhitePixel(d, s)); + XSelectInput(d, w, ExposureMask | KeyPressMask | ButtonPressMask); + XStoreName(d, w, "Hole"); + XMapWindow(d, w); + + /* create the pixmap that specifies the shape */ + p=XCreatePixmap(d, w, 400, 300, 1); + gp=XCreateGC(d, p, 0, NULL); + XSetForeground(d, gp, WhitePixel(d, s)); + XFillRectangle(d, p, gp, 0, 0, 400, 300); + XSetForeground(d, gp, BlackPixel(d, s)); + XFillArc(d, p, gp, 120, 100, 100, 100, 0, 360*64); + + /* set the pixmap as the new window mask; + the pixmap is slightly larger than the window + to allow for the window border and title bar + (as added by the window manager) to be visible */ + XShapeCombineMask(d, w, ShapeBounding, -20, -50, p, ShapeSet); + + /* event polling loop */ + while(1) { + XNextEvent(d, &e); + /* draw or redraw the window */ + if(e.type==Expose) { + /* not the correct way of drawing text... */ + for(y=10; y<=210; y+=11) + for(x=0; x<300; x+=25) + XDrawString(d, w, gw, x, y, "test", 4); + } + + /* exit on button press */ + if(e.type==ButtonPress) + break; + } + + /* close connection to display */ + XCloseDisplay(d); + + return 0; +} diff --git a/xscreensaversuspendtest.c b/xscreensaversuspendtest.c new file mode 100644 index 0000000..0032289 --- /dev/null +++ b/xscreensaversuspendtest.c @@ -0,0 +1,39 @@ + +// +// XScreenSaverSuspend() test program +// +// gcc -g -Wall -o xscreensaversuspendtest xscreensaversuspendtest.c -lX11 -lXss +// + +#include <assert.h> +#include <stdio.h> +#include <stdbool.h> +#include <unistd.h> +#include <X11/extensions/scrnsaver.h> + +int +main() +{ + Display *dpy = XOpenDisplay(NULL); + assert(dpy); + + int event_base; + int error_base; + assert(XScreenSaverQueryExtension(dpy, &event_base, &error_base)); + + int major_version; + int minor_version; + assert(XScreenSaverQueryVersion(dpy, &major_version, &minor_version)); + printf("Xscreensaver version %d.%d\n", major_version, minor_version); + + XScreenSaverSuspend(dpy, true); + XFlush(dpy); + + // suspend screensaver until we are killed + while (true) + { + sleep(1); + } + + return 0; +} |