PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/xlib/third.c

https://github.com/koushik2506/exp
C | 133 lines | 86 code | 46 blank | 1 comment | 7 complexity | 9446686862125e6ed8b28e81f8719a1f MD5 | raw file
  1. #include <X11/Xlib.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. Window create_simple_window(Display *display,int width,int height,int x,int y) {
  6. int screen_num = DefaultScreen(display);
  7. int win_border_width = 2;
  8. Window win;
  9. win = XCreateSimpleWindow(display,RootWindow(display,screen_num),x,y,width,height,win_border_width,
  10. WhitePixel(display,screen_num),WhitePixel(display,screen_num));
  11. XSelectInput(display,win,StructureNotifyMask);
  12. XMapWindow(display,win);
  13. XFlush(display);
  14. return win;
  15. }
  16. GC create_gc(Display *display,Window win,int reverse_video) {
  17. GC gc;
  18. unsigned long valuemask = 0;
  19. XGCValues values;
  20. unsigned int line_width = 2;
  21. int line_style = LineSolid;
  22. int cap_style = CapButt;
  23. int join_style = JoinBevel;
  24. int screen_num = DefaultScreen(display);
  25. gc = XCreateGC(display,win,valuemask,&values);
  26. if (reverse_video) {
  27. XSetForeground(display,gc,WhitePixel(display,screen_num));
  28. XSetBackground(display,gc,BlackPixel(display,screen_num));
  29. } else {
  30. XSetForeground(display,gc,BlackPixel(display,screen_num));
  31. XSetBackground(display,gc,WhitePixel(display,screen_num));
  32. }
  33. //XSetForeground(display,gc,WhitePixel(display,screen_num));
  34. XSetLineAttributes(display,gc,line_width,line_style,cap_style,join_style);
  35. XSetFillStyle(display,gc,FillSolid);
  36. return gc;
  37. }
  38. int main(int argc,char **argv) {
  39. Display *display;
  40. int screen_num;
  41. Window win;
  42. unsigned int display_width,display_height;
  43. unsigned int width,height;
  44. char *display_name = getenv("DISPLAY");
  45. GC gc;
  46. display = XOpenDisplay(display_name);
  47. if(display == NULL ){
  48. fprintf(stderr,"%s couldn't connect to '%s'\n",argv[0],display_name);
  49. exit(1);
  50. }
  51. screen_num = DefaultScreen(display);
  52. display_width = DisplayWidth(display,screen_num);
  53. display_height = DisplayHeight(display,screen_num);
  54. width = display_width/3;
  55. height = display_height/3;
  56. win = create_simple_window(display,width,height,0,0);
  57. gc = create_gc(display,win,0);
  58. XSync(display,False);
  59. for(;;) {
  60. XEvent e;
  61. XNextEvent(display,&e);
  62. if(e.type == MapNotify) break;
  63. }
  64. XDrawPoint(display,win,gc,5,5);
  65. XDrawPoint(display,win,gc,5,height-5);
  66. XDrawPoint(display,win,gc,width-5,5);
  67. XDrawPoint(display,win,gc,width-5,height-5);
  68. XDrawLine(display,win,gc,50,0,50,200);
  69. XDrawLine(display,win,gc,0,100,200,100);
  70. XDrawArc(display,win,gc,50-(30/2),100-(30/2),30,30,0,360*64);
  71. {
  72. XPoint points[] = {
  73. {0,0},
  74. {15,15},
  75. {0,15},
  76. {0,0}
  77. };
  78. int npoints = sizeof(points)/sizeof(XPoint);
  79. XDrawLines(display,win,gc,points,npoints,CoordModeOrigin);
  80. }
  81. XDrawRectangle(display,win,gc,120,150,50,60);
  82. XFillRectangle(display,win,gc,60,150,50,60);
  83. XFlush(display);
  84. XSync(display,False);
  85. sleep(30);
  86. return 0;
  87. }