1
/**************************************************************/
4
#include <X11/Xlib.h> /* the X library */
5
#include <X11/Xutil.h> /* the X library */
7
/* a few arbitary constants */
10
#define WINDOW_WIDTH 225
11
#define WINDOW_HEIGHT 400
12
#define BORDER_WIDTH 1
13
#define KEY_STR_LENGTH 20
15
Display *the_display; /* the display that will be used */
16
int the_screen; /* the screen that will be used */
17
Window root_window; /* the root window on the screen */
18
XSizeHints size_hints; /* size hints for the window manager */
19
XEvent the_event; /* the structure for the input event */
20
XSetWindowAttributes attributes;/* the windows attributes */
23
the_clear_GC; /* the graphics contexts */
25
XGCValues the_solid_GC_values,
29
XFontStruct *the_fontstruct; /* the font info to be used */
33
Window the_window; /* the window that will be opened */
36
/* Set the display to be the default display (ie, your
37
display as given in the environment variable DISPLAY). */
39
if ((the_display = XOpenDisplay("")) == NULL)
41
printf("can't open display\n");
45
/* A few useful values. */
47
the_screen = DefaultScreen(the_display);
48
root_window = RootWindow(the_display,the_screen);
50
/* Set the size hints for the window manager. */
52
size_hints.x = START_X;
53
size_hints.y = START_Y;
54
size_hints.width = WINDOW_WIDTH;
55
size_hints.height = WINDOW_HEIGHT;
56
size_hints.flags = PSize|PPosition;
58
/* Create a window of fixed size, origin, and borderwidth.
59
The window will have a black border and white background. */
61
the_window = XCreateSimpleWindow(the_display,root_window,
62
size_hints.x,size_hints.y,size_hints.width,
63
size_hints.height,BORDER_WIDTH,
64
BlackPixel(the_display,the_screen),
65
WhitePixel(the_display,the_screen));
67
XSetStandardProperties(the_display,the_window,"My Window","My Icon",
68
None,NULL,NULL,&size_hints);
70
cmap = DefaultColormap(the_display, the_screen);
72
the_solid_GC = XCreateGC(the_display, the_window, None, &the_solid_GC_values);
73
the_clear_GC = XCreateGC(the_display, the_window, None, &the_clear_GC_values);
76
XSetBackground(the_display, the_solid_GC, BlackPixel(the_display,the_screen));
77
XSetForeground(the_display, the_solid_GC, BlackPixel(the_display,the_screen));
79
XSetBackground(the_display, the_clear_GC, WhitePixel(the_display,the_screen));
80
XSetForeground(the_display, the_clear_GC, WhitePixel(the_display,the_screen));
82
if ((the_fontstruct = XLoadQueryFont(the_display,"8x13")) == NULL)
84
printf("could not open font\n");
87
/* Put the font into the graphics context for draw operations. */
88
XSetFont(the_display, the_solid_GC, the_fontstruct->fid);
89
XSetFont(the_display, the_clear_GC, the_fontstruct->fid);
91
/* Tell the server to make the window visible. */
93
XMapWindow(the_display,the_window);
95
attributes.bit_gravity = NorthWestGravity;
96
XChangeWindowAttributes(the_display, the_window, CWBitGravity, &attributes);
101
int close_window(the_window)
104
XDestroyWindow(the_display, the_window);
109
int draw_line(the_window, x1, y1, x2, y2)
113
XDrawLine(the_display, the_window, the_solid_GC, x1, y1, x2, y2);
118
int draw_arc(the_window, x, y, width, height, angle1, angle2)
120
int x, y, width, height, angle1, angle2;
122
XDrawArc(the_display, the_window, the_solid_GC,
123
x, y, width, height, angle1, angle2);
128
int fill_arc(the_window, x, y, width, height, angle1, angle2)
130
int x, y, width, height, angle1, angle2;
132
XFillArc(the_display, the_window, the_solid_GC,
133
x, y, width, height, angle1, angle2);
138
int clear_arc(the_window, x, y, width, height, angle1, angle2)
140
int x, y, width, height, angle1, angle2;
142
XFillArc(the_display, the_window, the_clear_GC,
143
x, y, width, height, angle1, angle2);
148
int set_arc_mode (pie_or_chord)
150
if (pie_or_chord == 0) {
151
XSetArcMode(the_display, the_solid_GC, ArcChord);
152
XSetArcMode(the_display, the_clear_GC, ArcChord);
155
XSetArcMode(the_display, the_solid_GC, ArcPieSlice);
156
XSetArcMode(the_display, the_clear_GC, ArcPieSlice);
161
int erase_line(the_window, x1, y1, x2, y2)
165
XDrawLine(the_display, the_window, the_clear_GC, x1, y1, x2, y2);
170
int draw_text(the_window, string, x, y)
175
XDrawString(the_display, the_window, the_solid_GC, x, y,
176
string, strlen(string));
181
int erase_text(the_window, string, x, y)
186
XDrawString(the_display, the_window, the_clear_GC, x, y,
187
string, strlen(string));
192
int clear_window(the_window)
195
XClearWindow(the_display, the_window);
200
int resize_window(the_window, width, height)
204
XResizeWindow(the_display, the_window, width, height);
209
int raise_window(the_window)
212
XRaiseWindow(the_display, the_window);
217
int use_font (font_name)
220
if ((the_fontstruct = XLoadQueryFont(the_display, font_name)) == NULL)
223
/* Put the font into the graphics context for draw operations. */
224
XSetFont(the_display, the_solid_GC, the_fontstruct->fid);
225
XSetFont(the_display, the_clear_GC, the_fontstruct->fid);
232
int set_background (the_window, color_string)
239
if (result = XParseColor(the_display, cmap, color_string, &color)) {
240
if (result = XAllocColor(the_display, cmap, &color)) {
241
XSetWindowBackground(the_display, the_window, color.pixel);
242
XSetBackground(the_display, the_clear_GC, color.pixel);
243
XSetForeground(the_display, the_clear_GC, color.pixel);
250
int set_foreground (color_string)
256
if (result = XParseColor(the_display, cmap, color_string, &color)) {
257
if (result = XAllocColor(the_display, cmap, &color)) {
258
XSetForeground(the_display, the_solid_GC, color.pixel);
259
XSetBackground(the_display, the_solid_GC, color.pixel);