Configuration of dwm for Mac Computers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
2.6 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #include <stdlib.h>
  3. #include <X11/Xlib.h>
  4. #include "draw.h"
  5. Draw *
  6. draw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h) {
  7. Draw *draw = (Draw *)calloc(1, sizeof(Draw));
  8. draw->dpy = dpy;
  9. draw->screen = screen;
  10. draw->win = win;
  11. draw->w = w;
  12. draw->h = h;
  13. draw->drawable = XCreatePixmap(dpy, win, w, h, DefaultDepth(dpy, screen));
  14. draw->gc = XCreateGC(dpy, win, 0, NULL);
  15. XSetLineAttributes(dpy, draw->gc, 1, LineSolid, CapButt, JoinMiter);
  16. return draw;
  17. }
  18. void
  19. draw_resize(Draw *draw, unsigned int w, unsigned int h) {
  20. if(!draw)
  21. return;
  22. draw->w = w;
  23. draw->h = h;
  24. XFreePixmap(draw->dpy, draw->drawable);
  25. draw->drawable = XCreatePixmap(draw->dpy, draw->win, w, h, DefaultDepth(draw->dpy, draw->screen));
  26. }
  27. void
  28. draw_free(Draw *draw) {
  29. XFreePixmap(draw->dpy, draw->drawable);
  30. XFreeGC(draw->dpy, draw->gc);
  31. free(draw);
  32. }
  33. DDC *
  34. dc_create(Draw *draw) {
  35. DDC *dc = (DDC *)calloc(1, sizeof(DDC));
  36. dc->draw = draw;
  37. dc->next = draw->dc;
  38. draw->dc = dc;
  39. return dc;
  40. }
  41. void
  42. dc_free(DDC *dc) {
  43. DDC **tdc;
  44. if(!dc)
  45. return;
  46. /* remove from dc list */
  47. for(tdc = &dc->draw->dc; *tdc && *tdc != dc; tdc = &(*tdc)->next);
  48. *tdc = dc->next;
  49. /* TODO: deallocate any resources of this dc, if needed */
  50. free(dc);
  51. }
  52. Fnt *
  53. font_create(const char *fontname) {
  54. Fnt *font = (Fnt *)calloc(1, sizeof(Fnt));
  55. /* TODO: allocate actual font */
  56. return font;
  57. }
  58. void
  59. font_free(Fnt *font) {
  60. if(!font)
  61. return;
  62. /* TODO: deallocate any font resources */
  63. free(font);
  64. }
  65. Col *
  66. col_create(const char *colname) {
  67. Col *col = (Col *)calloc(1, sizeof(Col));
  68. /* TODO: allocate color */
  69. return col;
  70. }
  71. void
  72. col_free(Col *col) {
  73. if(!col)
  74. return;
  75. /* TODO: deallocate any color resource */
  76. free(col);
  77. }
  78. void
  79. dc_setfont(DDC *dc, Fnt *font) {
  80. if(!dc || !font)
  81. return;
  82. dc->font = font;
  83. }
  84. void
  85. dc_setfg(DDC *dc, Col *col) {
  86. if(!dc || !col)
  87. return;
  88. dc->fg = col;
  89. }
  90. void
  91. dc_setbg(DDC *dc, Col *col) {
  92. if(!dc || !col)
  93. return;
  94. dc->bg = col;
  95. }
  96. void
  97. dc_setfill(DDC *dc, Bool fill) {
  98. if(!dc)
  99. return;
  100. dc->fill = fill;
  101. }
  102. void
  103. dc_drawrect(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
  104. if(!dc)
  105. return;
  106. /* TODO: draw the rectangle */
  107. }
  108. void
  109. dc_drawtext(DDC *dc, int x, int y, const char *text) {
  110. if(!dc)
  111. return;
  112. /* TODO: draw the text */
  113. }
  114. void
  115. dc_map(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
  116. if(!dc)
  117. return;
  118. /* TODO: map the dc contents in the region */
  119. }
  120. void
  121. dc_getextents(DDC *dc, const char *text, TextExtents *extents) {
  122. if(!dc || !extents)
  123. return;
  124. /* TODO: get extents */
  125. }