Last active
November 1, 2015 01:41
-
-
Save bFraley/11f60f20c42211bbdf70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| This should compile using: | |
| gcc X11_testAPI.c-o X11_test -I /usr/include/X11 -L /usr/X11/lib -lX11 | |
| */ | |
| // X11 header files. | |
| #include <X11/Xlib.h> | |
| #include <X11/Xutil.h> | |
| #include <X11/Xos.h> | |
| // Declare X11 globals | |
| Display *display; /* X11 display type */ | |
| int screen; /* X11 - client screen */ | |
| Window win; /* X11 Window type */ | |
| GC gc; /* X11 GC (graphic context) type */ | |
| /** | |
| Function declarations. | |
| */ | |
| void window_init(); | |
| void close_window(); | |
| void redraw(); | |
| /** | |
| Main | |
| */ | |
| int main() | |
| { | |
| window_init(); | |
| // Basic setup for events and keypress keys | |
| XEvent event; /* XEvent declaration. */ | |
| KeySym key; /* KeyPress event key */ | |
| char text[255]; /* Buffer for KeyPress events */ | |
| _Bool run = 1; | |
| while(run) | |
| { | |
| XNextEvent(display, &event); | |
| if (event.type==Expose && event.xexpose.count==0) | |
| { | |
| /* The window was exposed, redraw it */ | |
| redraw(); | |
| } | |
| XSetForeground(display, gc, 100); // 100 is a color | |
| XFillRectangle(display, win, gc, 30, 30, 200, 200); | |
| } | |
| } /* END MAIN */ | |
| /** | |
| Function definitions. | |
| */ | |
| /* window_init creates and manages a window and it's structures.*/ | |
| void window_init() | |
| { | |
| unsigned long black, white; | |
| display=XOpenDisplay((char *)0); | |
| screen=DefaultScreen(display); | |
| black=BlackPixel(display, screen), | |
| white=WhitePixel(display, screen); | |
| win=XCreateSimpleWindow(display,DefaultRootWindow(display), | |
| 50, 50, 500, 500, 5, black, white); | |
| XSetStandardProperties(display, win, "zeta","zeta", None, NULL, 0, NULL); | |
| // NOTE: At minimum, we have to select the ExposureMask in order for draw | |
| // functions to produce output (draw) to the window. | |
| XSelectInput(display, win, ExposureMask|ButtonPressMask|KeyPressMask); | |
| gc=XCreateGC(display, win, 0, 0); | |
| XSetBackground(display, gc, white); | |
| XSetForeground(display, gc, black); | |
| XClearWindow(display, win); | |
| XMapRaised(display, win); | |
| }; | |
| void close_window() | |
| { | |
| XFreeGC(display, gc); | |
| XDestroyWindow(display, win); | |
| XCloseDisplay(display); | |
| }; | |
| void redraw() | |
| { | |
| XClearWindow(display, win); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment