1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| #include <unistd.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
#include <cairo.h>
#include <cairo-xlib.h>
#define SIZEX 200
#define SIZEY 200
/* méthode 100% pompée sur fdclock */
Visual *find_argb_visual (Display *dpy, int scr) {
XVisualInfo *xvi;
XVisualInfo tmplate;
int nvi;
int i;
XRenderPictFormat *format;
Visual *visual;
tmplate.screen = scr;
tmplate.depth = 32;
tmplate.class = TrueColor;
xvi = XGetVisualInfo (dpy,
VisualScreenMask |
VisualDepthMask |
VisualClassMask,
&tmplate,
&nvi);
if (!xvi)
return 0;
visual = 0;
for (i = 0; i < nvi; i++)
{
format = XRenderFindVisualFormat (dpy, xvi[i].visual);
if (format->type == PictTypeDirect && format->direct.alphaMask)
{
visual = xvi[i].visual;
break;
}
}
XFree (xvi);
return visual;
}
int main (int argc, char *argv[])
{
Display *dpy;
XEvent e;
Window rootwin;
Window win;
int scr;
XSetWindowAttributes attributs;
unsigned long masque_valeur;
if(!(dpy=XOpenDisplay(NULL))) {
fprintf(stderr, "ERROR: Could not open display\n");
exit(1);
}
scr=DefaultScreen(dpy);
rootwin=RootWindow(dpy, scr);
attributs.background_pixel = 0;
attributs.border_pixel = 0;
int depth = 32;
Visual *visual = find_argb_visual (dpy, scr);
attributs.colormap = XCreateColormap (dpy, rootwin, visual, AllocNone);
masque_valeur = CWBackPixel | CWBorderPixel | CWColormap;
attributs.override_redirect = True;
masque_valeur |= CWOverrideRedirect;
win = XCreateWindow (dpy, rootwin, 0, 0, SIZEX, SIZEX, 0, depth, InputOutput, visual, masque_valeur, &attributs);
XStoreName(dpy, win, "hello");
XSelectInput(dpy, win, ButtonPressMask);
XMapWindow(dpy, win);
while(1) {
XNextEvent(dpy, &e);
if(e.type==ButtonPress) break;
}
XCloseDisplay(dpy);
return 0;
} |
Partager