1 [+ autogen5 template +]
2 [+INCLUDE (string-append "licenses/" (get "License") ".tpl") \+]
3 [+INCLUDE (string-append "indent.tpl") \+]
4 /* [+INVOKE EMACS-MODELINE MODE="C" \+] */
5 [+INVOKE START-INDENT\+]
6 /*
7 * main.c
8 * Copyright (C) [+(shell "date +%Y")+] [+Author+][+IF (get "Email")+] <[+Email+]>[+ENDIF+]
9 *
10 [+INVOKE LICENSE-DESCRIPTION PFX=" * " PROGRAM=(get "Name") OWNER=(get "Author") \+]
11 */
12
13 /*Program closes with a mouse click or keypress */
14
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <X11/Xlib.h>
21
main(int argc,char * argv[])22 int main (int argc, char *argv[])
23 {
24 Display *dpy;
25 Visual *visual;
26 int depth;
27 XSetWindowAttributes attributes;
28 Window win;
29 XFontStruct *fontinfo;
30 XColor color, dummy;
31 XGCValues gr_values;
32 GC gc;
33 XKeyEvent event;
34
35 dpy = XOpenDisplay(NULL);
36 visual = DefaultVisual(dpy, 0);
37 depth = DefaultDepth(dpy, 0);
38 attributes.background_pixel = XWhitePixel(dpy, 0);
39 /* create the application window */
40 win = XCreateWindow(dpy, XRootWindow(dpy, 0),
41 50, 50, 400, 400, 5, depth,
42 InputOutput, visual, CWBackPixel,
43 &attributes);
44 XSelectInput(dpy, win, ExposureMask | KeyPressMask |
45 ButtonPressMask | StructureNotifyMask);
46
47 fontinfo = XLoadQueryFont(dpy, "6x10");
48 XAllocNamedColor(dpy, DefaultColormap(dpy, 0),
49 "green", &color, &dummy);
50 gr_values.font = fontinfo->fid;
51 gr_values.foreground = color.pixel;
52 gc = XCreateGC(dpy, win, GCFont+GCForeground, &gr_values);
53 XMapWindow(dpy, win);
54
55 /* run till key press */
56 while(1){
57 XNextEvent(dpy, (XEvent *)&event);
58 switch(event.type) {
59 case Expose:
60 XDrawLine(dpy, win, gc, 0, 0, 100, 100);
61 XDrawRectangle(dpy, win, gc, 140, 140, 50, 50);
62 XDrawString(dpy, win, gc, 100, 100, "hello X world", 13);
63 break;
64 case ButtonPress:
65 case KeyPress:
66 XUnloadFont(dpy, fontinfo->fid);
67 XFreeGC(dpy, gc);
68 XCloseDisplay(dpy);
69 exit(0);
70 break;
71 case ConfigureNotify:
72 /* reconfigure size of window here */
73 break;
74 default:
75 break;
76 }
77 }
78 return(0);
79 }
80 [+INVOKE END-INDENT\+]
81