frame.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * frame.c
  3. * Copyright © 2008, 2009 Martin Duquesnoy <xorg62@gmail.com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of the nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "wmfs.h"
  33. /** Frame creation function, for make a
  34. * client frame, and configure it
  35. * \param c Client pointer
  36. */
  37. void
  38. frame_create(Client *c)
  39. {
  40. XSetWindowAttributes at;
  41. int i;
  42. at.background_pixel = conf.client.bordernormal;
  43. at.background_pixmap = ParentRelative;
  44. at.override_redirect = True;
  45. at.bit_gravity = StaticGravity;
  46. at.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
  47. |ExposureMask|VisibilityChangeMask
  48. |EnterWindowMask|LeaveWindowMask|FocusChangeMask
  49. |KeyMask|ButtonMask|MouseMask;
  50. /* Set property */
  51. c->frame_geo.x = c->geo.x - BORDH;
  52. c->frame_geo.y = c->geo.y - TBARH;
  53. c->frame_geo.width = FRAMEW(c->geo.width);
  54. c->frame_geo.height = FRAMEH(c->geo.height);
  55. c->colors.fg = conf.titlebar.fg_normal;
  56. c->colors.frame = conf.client.bordernormal;
  57. c->colors.resizecorner = conf.client.resizecorner_normal;
  58. /* Create frame window */
  59. CWIN(c->frame, ROOT,
  60. c->frame_geo.x,
  61. c->frame_geo.y,
  62. c->frame_geo.width,
  63. c->frame_geo.height, 0,
  64. CWOverrideRedirect | CWBackPixmap | CWEventMask,
  65. c->colors.frame, &at);
  66. /* Create titlebar window */
  67. if(TBARH - BORDH)
  68. {
  69. c->titlebar = barwin_create(c->frame, 0, 0,
  70. c->frame_geo.width ,
  71. TBARH,
  72. c->colors.frame,
  73. c->colors.fg,
  74. True, conf.titlebar.stipple.active, False);
  75. /* Buttons */
  76. if(BUTTONWH >= 1)
  77. {
  78. c->button = emalloc(conf.titlebar.nbutton, sizeof(Window));
  79. for(i = 0; i < conf.titlebar.nbutton; ++i)
  80. {
  81. CWIN(c->button[i], c->titlebar->win,
  82. (c->button_last_x = (BORDH + (BUTTONWH * i) + (4 * i))),
  83. ((BUTTONWH - 1) / 2), BUTTONWH, BUTTONWH,
  84. 1, CWEventMask|CWOverrideRedirect|CWBackPixmap,
  85. c->colors.frame, &at);
  86. XSetWindowBorder(dpy, c->button[i], getcolor(c->colors.fg));
  87. }
  88. }
  89. }
  90. at.event_mask &= ~(EnterWindowMask | LeaveWindowMask); /* <- Delete useless mask */
  91. /* Create resize area */
  92. at.cursor = cursor[CurRightResize];
  93. CWIN(c->resize[Right], c->frame,
  94. c->frame_geo.width - RESHW,
  95. c->frame_geo.height - RESHW,
  96. RESHW, RESHW, 0,
  97. CWEventMask | CWBackPixel | CWCursor,
  98. c->colors.resizecorner, &at);
  99. at.cursor = cursor[CurLeftResize];
  100. CWIN(c->resize[Left], c->frame,
  101. 0, c->frame_geo.height - RESHW,
  102. RESHW, RESHW, 0,
  103. CWEventMask | CWBackPixel | CWCursor,
  104. c->colors.resizecorner, &at);
  105. /* Border (for shadow) */
  106. if(conf.client.border_shadow)
  107. {
  108. CWIN(c->left, c->frame, 0, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, color_enlight(c->colors.frame), &at);
  109. CWIN(c->top, c->frame, 0, 0, c->frame_geo.width, SHADH, 0, CWBackPixel, color_enlight(c->colors.frame), &at);
  110. CWIN(c->bottom, c->frame, 0, c->frame_geo.height - SHADH, c->frame_geo.width, SHADH, 0, CWBackPixel, SHADC, &at);
  111. CWIN(c->right, c->frame, c->frame_geo.width - SHADH, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, SHADC, &at);
  112. }
  113. /* Reparent window with the frame */
  114. XReparentWindow(dpy, c->win, c->frame, BORDH, TBARH);
  115. return;
  116. }
  117. /** Delete a frame
  118. * \param c The client frame
  119. */
  120. void
  121. frame_delete(Client *c)
  122. {
  123. /* If there is, delete the titlebar */
  124. if(TBARH - BORDH)
  125. {
  126. barwin_delete_subwin(c->titlebar);
  127. barwin_delete(c->titlebar);
  128. }
  129. /* Delete the frame's sub win and the frame */
  130. XDestroySubwindows(dpy, c->frame);
  131. XDestroyWindow(dpy, c->frame);
  132. return;
  133. }
  134. /** Move a frame
  135. * \param c The client frame
  136. * \param geo Coordinate info for move the frame
  137. */
  138. void
  139. frame_moveresize(Client *c, XRectangle geo)
  140. {
  141. CHECK(c);
  142. c->frame_geo.x = (geo.x) ? geo.x - BORDH : c->frame_geo.x;
  143. c->frame_geo.y = (geo.y) ? geo.y - TBARH : c->frame_geo.y;
  144. c->frame_geo.width = (geo.width) ? FRAMEW(geo.width) : c->frame_geo.width;
  145. c->frame_geo.height = (geo.height) ? FRAMEH(geo.height) : c->frame_geo.height;
  146. /* Frame */
  147. XMoveResizeWindow(dpy, c->frame,
  148. c->frame_geo.x,
  149. c->frame_geo.y,
  150. c->frame_geo.width,
  151. c->frame_geo.height);
  152. /* Titlebar */
  153. if(TBARH - BORDH)
  154. barwin_resize(c->titlebar, c->frame_geo.width, TBARH);
  155. /* Resize area */
  156. XMoveWindow(dpy, c->resize[Right], c->frame_geo.width - RESHW, c->frame_geo.height - RESHW);
  157. XMoveWindow(dpy, c->resize[Left], 0, c->frame_geo.height - RESHW);
  158. /* Border */
  159. if(conf.client.border_shadow)
  160. {
  161. XResizeWindow(dpy, c->left, SHADH, c->frame_geo.height - SHADH);
  162. XResizeWindow(dpy, c->top, c->frame_geo.width, SHADH);
  163. XMoveResizeWindow(dpy, c->bottom, 0, c->frame_geo.height - SHADH, c->frame_geo.width, SHADH);
  164. XMoveResizeWindow(dpy, c->right, c->frame_geo.width - SHADH, 0, SHADH, c->frame_geo.height);
  165. }
  166. return;
  167. }
  168. /** Update the client frame; Set the new color
  169. * and the title --> refresh
  170. * \param c Client pointer
  171. */
  172. void
  173. frame_update(Client *c)
  174. {
  175. int i;
  176. CHECK(c);
  177. if(TBARH - BORDH)
  178. {
  179. c->titlebar->bg = c->colors.frame;
  180. c->titlebar->fg = c->colors.fg;
  181. barwin_refresh_color(c->titlebar);
  182. /* Buttons */
  183. if(conf.titlebar.nbutton && BUTTONWH >= 1)
  184. {
  185. if(conf.titlebar.stipple.active)
  186. draw_rectangle(c->titlebar->dr, 0, 0, c->button_last_x + TBARH - (TBARH / 4),
  187. TBARH + BORDH * 2, c->colors.frame);
  188. for(i = 0; i < conf.titlebar.nbutton; ++i)
  189. {
  190. XSetWindowBackground(dpy, c->button[i], c->colors.frame);
  191. XClearWindow(dpy, c->button[i]);
  192. XSetWindowBorder(dpy, c->button[i], getcolor(c->colors.fg));
  193. /* Button's lines */
  194. if(conf.titlebar.button[i].nlines)
  195. {
  196. XSetForeground(dpy, gc, getcolor(c->colors.fg));
  197. XDrawSegments(dpy, c->button[i], gc,
  198. conf.titlebar.button[i].linecoord,
  199. conf.titlebar.button[i].nlines);
  200. }
  201. }
  202. }
  203. barwin_refresh(c->titlebar);
  204. }
  205. XSetWindowBackground(dpy, c->frame, c->colors.frame);
  206. XSetWindowBackground(dpy, c->resize[Right], c->colors.resizecorner);
  207. XSetWindowBackground(dpy, c->resize[Left], c->colors.resizecorner);
  208. XClearWindow(dpy, c->frame);
  209. XClearWindow(dpy, c->resize[Right]);
  210. XClearWindow(dpy, c->resize[Left]);
  211. if(conf.client.border_shadow)
  212. {
  213. XSetWindowBackground(dpy, c->left, color_enlight(c->colors.frame));
  214. XSetWindowBackground(dpy, c->top, color_enlight(c->colors.frame));
  215. XSetWindowBackground(dpy, c->right, SHADC);
  216. XSetWindowBackground(dpy, c->bottom, SHADC);
  217. XClearWindow(dpy, c->left);
  218. XClearWindow(dpy, c->top);
  219. XClearWindow(dpy, c->right);
  220. XClearWindow(dpy, c->bottom);
  221. }
  222. if(TBARH - BORDH)
  223. barwin_draw_text(c->titlebar,
  224. (c->frame_geo.width / 2) - (textw(c->title) / 2),
  225. ((font->height - font->descent) + (TBARH - font->height) / 2),
  226. c->title);
  227. return;
  228. }