Initial commit.
[hondza-y36pr2.git] / xtma / xtma.c
blobc44410a0a3d4f84a42c72b83aa25b7d6504cc359
1 /******************************************************************************
2 * xtma.c
3 *****************************************************************************/
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <unistd.h>
10 #include <X11/Xlib.h>
11 #include <X11/keysym.h>
14 int main(int argc, char ** argv)
16 Display *dpy;
17 int screen;
18 int dispw;
19 int disph;
20 Window win;
21 int run = 1;
22 XEvent xev;
23 Atom wm_state, fs;
24 Pixmap bm_no;
25 Colormap cmap;
26 Cursor no_ptr;
27 XColor black, dummy;
28 static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
30 close(0); close(1); close(2);
32 while(1)
34 dpy = XOpenDisplay("");
35 if(NULL != dpy) break;
36 sleep(1);
39 screen = DefaultScreen(dpy);
40 dispw = XDisplayWidth(dpy, screen);
41 disph = XDisplayHeight(dpy, screen);
43 win = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 0, 0, 1, 1, 0, WhitePixel(dpy, screen), BlackPixel(dpy, screen));
45 /* disable the cursor: http://www.linuxforums.org/forum/linux-programming-scripting/59012-xlib-hide-mouse-pointer.html */
46 cmap = DefaultColormap(dpy, screen);
47 XAllocNamedColor(dpy, cmap, "black", &black, &dummy);
48 bm_no = XCreateBitmapFromData(dpy, win, bm_no_data, 8, 8);
49 no_ptr = XCreatePixmapCursor(dpy, bm_no, bm_no, &black, &black, 0, 0);
50 XDefineCursor(dpy, win, no_ptr);
52 /* name */
53 XStoreName(dpy, win, "xtma");
55 /* show the window */
56 XMapRaised(dpy, win);
58 /* listen for mouse and kbd */
59 XSelectInput(dpy, win, KeyPressMask | ButtonPressMask);
61 /* fullscreen */
62 wm_state = XInternAtom(dpy, "_NET_WM_STATE", True);
63 fs = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", True);
64 memset(&xev, 0, sizeof(xev));
65 xev.type = ClientMessage;
66 xev.xclient.serial = 0;
67 xev.xclient.send_event=True;
68 xev.xclient.window = win;
69 xev.xclient.message_type = wm_state;
70 xev.xclient.format = 32;
71 xev.xclient.data.l[0] = 1;
72 xev.xclient.data.l[1] = fs;
73 xev.xclient.data.l[2] = 0;
74 XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
75 XFlush(dpy);
78 while(run)
80 XNextEvent(dpy, &xev);
81 if(ButtonPress == xev.type || (KeyPress == xev.type && XK_Escape == (XLookupKeysym((XKeyEvent *)&xev, 0)))) run = 0;
85 XCloseDisplay(dpy);
87 return 0;
88 } /* main() */