Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xos.h>
- #include <X11/Xatom.h>
- int main(int argc, char *argv[])
- {
- Display *dpy;
- int screen;
- Window win;
- Window childWin;
- XEvent event;
- /* Text declaration vars */
- Font fid;
- XFontStruct *font;
- XTextItem ti[1];
- dpy = XOpenDisplay(NULL);
- if(dpy == NULL)
- {
- fprintf(stderr, "Cannot open display\n");
- exit(1);
- }
- screen = DefaultScreen(dpy);
- /* parent window */
- win = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
- 100, 100, 500, 300,
- 1, BlackPixel(dpy, screen), WhitePixel(dpy, screen));
- XSelectInput(dpy, win, ExposureMask | KeyPressMask);
- XMapWindow(dpy, win);
- /* child window */
- childWin = XCreateSimpleWindow(dpy, win,
- 20, 20, 200, 100,
- 1, BlackPixel(dpy, screen), WhitePixel(dpy, screen));
- XSelectInput(dpy, childWin, ExposureMask | KeyPressMask);
- XMapWindow(dpy, childWin);
- while(1)
- {
- XNextEvent(dpy, &event);
- if(event.xany.window == childWin){
- if(event.type == Expose)
- {
- XDrawLine(dpy, childWin, DefaultGC(dpy,
- screen), 10, 10, 60, 60);
- font = XLoadQueryFont(dpy, "-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*");
- ti[0].chars = "Press Me!";
- ti[0].nchars = 9;
- ti[0].delta = 0;
- ti[0].font = font->fid;
- XDrawText(dpy, childWin, DefaultGC(dpy, screen),
- (200 - XTextWidth(font, ti[0].chars, ti[0].nchars))/2,
- (100 - (font->ascent+font->descent))/2+font->ascent,
- ti, 1);
- XUnloadFont(dpy, font->fid);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement