/mobiled3/test/xlinetest.cc

https://github.com/benadler/taser_genrob · C++ · 160 lines · 84 code · 49 blank · 27 comment · 4 complexity · 1a06510d171216a0341ed35fee9a3bfe MD5 · raw file

  1. //
  2. //
  3. //
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <sys/time.h>
  7. #include <X11/Xlib.h>
  8. #include <X11/Xutil.h> // XSizeHints
  9. int main (void)
  10. {
  11. //
  12. //
  13. //
  14. Display *display = XOpenDisplay (NULL);
  15. if (!display)
  16. {
  17. fprintf (stderr, "can't connect to xserver\n");
  18. abort ();
  19. }
  20. //
  21. //
  22. //
  23. Window win = XCreateSimpleWindow (display,
  24. RootWindow (display, DefaultScreen (display)),
  25. 0, 0,
  26. 800, 600,
  27. 0,
  28. BlackPixel (display, DefaultScreen (display)),
  29. WhitePixel (display, DefaultScreen (display)));
  30. XSizeHints hints;
  31. hints.flags = PPosition | PSize | PMinSize | PMaxSize;
  32. hints.x = 0;
  33. hints.y = 0;
  34. hints.width = hints.min_width = hints.max_width = 800;
  35. hints.height = hints.min_height = hints.max_height = 600;
  36. XSetNormalHints (display, win, &hints);
  37. XStoreName (display, win, "<no title>");
  38. XSelectInput (display, win,
  39. ButtonPressMask | KeyPressMask | ExposureMask);
  40. XGCValues xgcvalues;
  41. GC gc = XCreateGC (display, win, 0, &xgcvalues);
  42. XSetFont (display, gc, XLoadQueryFont (display, "9x15")->fid);
  43. XSetForeground (display, gc, BlackPixel (display, DefaultScreen (display)));
  44. XSetLineAttributes (display, gc, 0, LineSolid, CapRound, JoinRound);
  45. XSetFunction (display, gc, GXcopy);
  46. #if 0
  47. // set backing store
  48. XSetWindowAttributes winattr;
  49. winattr.backing_store = Always;
  50. XChangeWindowAttributes (display, win, CWBackingStore, &winattr);
  51. #endif
  52. XEvent ev;
  53. XMapWindow (display, win);
  54. XNextEvent (display, &ev); // pop the map event
  55. //
  56. //
  57. //
  58. int lines = 0;
  59. struct timeval start;
  60. gettimeofday (&start, 0x0);
  61. while (42)
  62. {
  63. struct timeval now;
  64. gettimeofday (&now, 0x0);
  65. int ms =
  66. (now.tv_sec - start.tv_sec) * 1000 +
  67. (now.tv_usec - start.tv_usec) / 1000;
  68. if (ms >= 1000)
  69. {
  70. start = now;
  71. printf ("************* %i lines/s\n", lines);
  72. fflush (stdout);
  73. lines = 0;
  74. }
  75. lines += 800;
  76. //
  77. //
  78. //
  79. XSetForeground (display,
  80. gc,
  81. WhitePixel (display, DefaultScreen (display)));
  82. // XSetFillStyle (display, gc, FillSolid);
  83. XSetFunction (display,
  84. gc,
  85. GXcopy);
  86. XFillRectangle (display, win, gc, 0, 0, 799, 599);
  87. //
  88. //
  89. //
  90. XSetForeground (display,
  91. gc,
  92. BlackPixel (display, DefaultScreen (display)));
  93. XSetFunction (display, gc, GXcopy);
  94. for (int x=0; x<=799; x++)
  95. {
  96. XDrawLine (display, win, gc, x, 0, 799-x, 599);
  97. }
  98. XFlush (display);
  99. //
  100. //
  101. //
  102. //sleep (1);
  103. }
  104. //
  105. //
  106. //
  107. XUnmapWindow (display, win); // raises no event?
  108. XDestroyWindow (display, win);
  109. XFlush (display);
  110. return 0;
  111. }