Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xos.h>
- #include <unistd.h>
- void start_x(){
- Display *dis;
- Window win;
- GC gc;
- };
- void init_x(){
- //colors black and white
- unsigned log black,white;
- //display, X connection
- dis=XOpenDisplay((char *)0);
- screen=DefaultScreen(dis);
- black=BlackPixel(dis,screen); //get black color
- white=WhitePixel(dis,screen); //get white color
- //create window
- printf("Window, height & width: ");
- int height,width;
- scanf("%d %d",&height,&width);
- win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,height,width,5,white,black);
- //Window Title
- XSetStandardProperties(dis,win,"X11 lib Template","Sup!",None,NULL,0,NULL);
- XSelectInput(dis,win,ExposureMake|ButtonPressMask|KeyPressMask);
- //create the Graphics Context
- gc=XCreateGC(dis,win,0,0);
- //Foreground Background
- XSetBackground(dis,gc,white);
- XSetForeground(dis,gc,black);
- //Clear window
- XClearWindow(dis,win);
- XMapRaised(dis,win);
- };
- void close_x(){
- XFreeGC(dis,gc);
- XDestroyWindow(dis,win);
- XCloseDisplay(dis);
- exit(1);
- };
- void redraw() {
- XClearWindow(dis, win);
- };
- int main(){
- init_x();
- while(1) {
- /* get the next event and stuff it into our event variable.
- Note: only events we set the mask for are detected!
- */
- XNextEvent(dis, &event);
- if (event.type==Expose && event.xexpose.count==0) {
- /* the window was exposed redraw it! */
- redraw();
- }
- if (event.type==KeyPress&&
- XLookupString(&event.xkey,text,255,&key,0)==1) {
- /* use the XLookupString routine to convert the invent
- KeyPress data into regular text. Weird but necessary...
- */
- if (text[0]=='q') {
- close_x();
- }
- printf("You pressed the %c key!\n",text[0]);
- }
- if (event.type==ButtonPress) {
- /* tell where the mouse Button was Pressed */
- int x=event.xbutton.x,
- y=event.xbutton.y;
- }
- }
- sleep(4);
- close_x();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment