Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <X11/Xlib.h>
  4. #include <X11/Xutil.h>
  5. #include <X11/Xos.h>
  6. #include <X11/Xatom.h>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10.     Display *dpy;
  11.     int screen;
  12.     Window win;
  13.     Window childWin;
  14.     XEvent event;
  15.  
  16.     /* Text declaration vars */
  17.     Font fid;
  18.  
  19.     XFontStruct *font;
  20.     XTextItem ti[1];
  21.  
  22.     dpy = XOpenDisplay(NULL);
  23.  
  24.     if(dpy == NULL)
  25.     {
  26.         fprintf(stderr, "Cannot open display\n");
  27.         exit(1);
  28.     }
  29.  
  30.     screen = DefaultScreen(dpy);
  31.  
  32.     /* parent window */
  33.     win = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
  34.             100, 100, 500, 300,
  35.             1, BlackPixel(dpy, screen), WhitePixel(dpy, screen));
  36.  
  37.     XSelectInput(dpy, win, ExposureMask | KeyPressMask);
  38.     XMapWindow(dpy, win);
  39.  
  40.     /* child window */
  41.     childWin = XCreateSimpleWindow(dpy, win,
  42.             20, 20, 200, 100,
  43.             1, BlackPixel(dpy, screen), WhitePixel(dpy, screen));
  44.  
  45.     XSelectInput(dpy, childWin, ExposureMask | KeyPressMask);
  46.     XMapWindow(dpy, childWin);
  47.  
  48.     while(1)
  49.     {
  50.         XNextEvent(dpy, &event);
  51.         if(event.xany.window == childWin){
  52.            
  53.             if(event.type == Expose)
  54.             {
  55.                 XDrawLine(dpy, childWin, DefaultGC(dpy,
  56.                             screen), 10, 10, 60, 60);
  57.                
  58.                 font = XLoadQueryFont(dpy, "-*-helvetica-*-r-*-*-14-*-*-*-*-*-*-*");
  59.                 ti[0].chars = "Press Me!";
  60.                 ti[0].nchars = 9;
  61.                 ti[0].delta = 0;
  62.                 ti[0].font = font->fid;
  63.                 XDrawText(dpy, childWin, DefaultGC(dpy, screen),
  64.                         (200 - XTextWidth(font, ti[0].chars, ti[0].nchars))/2,
  65.                         (100 - (font->ascent+font->descent))/2+font->ascent,
  66.                         ti, 1);
  67.                 XUnloadFont(dpy, font->fid);
  68.  
  69.  
  70.             }
  71.  
  72.         }
  73.     }
  74.  
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement