infobar.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * infobar.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. /** Init the Infobar
  34. */
  35. void
  36. infobar_init(void)
  37. {
  38. int s, sc, i, j = 0;
  39. s = screen_count();
  40. if(!infobar)
  41. infobar = emalloc(s, sizeof(InfoBar));
  42. for(sc = 0; sc < s; ++sc)
  43. {
  44. j = 0;
  45. infobar[sc].geo.height = INFOBARH;
  46. switch(tags[sc][seltag[sc]].barpos)
  47. {
  48. case IB_Hide:
  49. sgeo[sc].y = spgeo[sc].y + TBARH;
  50. sgeo[sc].height += INFOBARH;
  51. infobar[sc].geo.y = -(infobar[sc].geo.height) * 2;
  52. break;
  53. case IB_Bottom:
  54. sgeo[sc].y = TBARH;
  55. infobar[sc].geo.y = spgeo[sc].y + sgeo[sc].height + TBARH;
  56. break;
  57. default:
  58. case IB_Top:
  59. sgeo[sc].y = spgeo[sc].y + INFOBARH + TBARH;
  60. infobar[sc].geo.y = spgeo[sc].y;
  61. break;
  62. }
  63. /* Create infobar barwindow */
  64. infobar[sc].bar = barwin_create(ROOT, sgeo[sc].x - BORDH, infobar[sc].geo.y,
  65. sgeo[sc].width, infobar[sc].geo.height,
  66. conf.colors.bar, conf.colors.text, False, False, conf.border.bar);
  67. infobar[sc].tags_board = barwin_create(infobar[sc].bar->win,
  68. ((conf.layout_placement) ? textw(tags[sc][seltag[sc]].layout.symbol) + PAD * 1.5: 0), 0,
  69. textw(tags[sc][0].name) + PAD, /* Base size, will change */
  70. infobar[sc].geo.height,
  71. conf.colors.bar, conf.colors.text, False, False, False);
  72. /* Create tags window */
  73. for(i = 1; i < conf.ntag[sc] + 1; ++i)
  74. {
  75. infobar[sc].tags[i] = barwin_create(infobar[sc].tags_board->win, j, 0,
  76. textw(tags[sc][i].name) + PAD,
  77. infobar[sc].geo.height,
  78. conf.colors.bar, conf.colors.text, False, False, conf.border.tag);
  79. j += textw(tags[sc][i].name) + PAD;
  80. barwin_resize(infobar[sc].tags_board, j, infobar[sc].geo.height);
  81. barwin_map_subwin(infobar[sc].tags[i]);
  82. }
  83. /* Create layout switch barwindow */
  84. infobar[sc].layout_button = barwin_create(infobar[sc].bar->win,
  85. ((conf.layout_placement) ? 0 : (j + PAD / 2)), 0,
  86. textw(tags[sc][seltag[sc]].layout.symbol) + PAD,
  87. infobar[sc].geo.height,
  88. conf.colors.layout_bg, conf.colors.layout_fg,
  89. False, False, conf.border.layout);
  90. /* Selbar */
  91. if(conf.bars.selbar)
  92. infobar[sc].selbar = barwin_create(infobar[sc].bar->win,
  93. ((conf.layout_placement)
  94. ? (j + PAD / 2)
  95. : infobar[sc].layout_button->geo.x + infobar[sc].layout_button->geo.width + PAD / 2), 1,
  96. (sel) ? textw(sel->title) + PAD : 1,
  97. infobar[sc].geo.height - 2,
  98. conf.colors.bar, conf.colors.text, False, False, False);
  99. /* Map/Refresh all */
  100. barwin_map(infobar[sc].bar);
  101. barwin_map_subwin(infobar[sc].bar);
  102. barwin_map(infobar[sc].tags_board);
  103. barwin_map_subwin(infobar[sc].tags_board);
  104. if(conf.border.layout)
  105. barwin_map_subwin(infobar[sc].layout_button);
  106. if(conf.bars.selbar)
  107. barwin_map(infobar[sc].selbar);
  108. barwin_refresh_color(infobar[sc].bar);
  109. barwin_refresh(infobar[sc].bar);
  110. /* Default statustext is set here */
  111. for(i = 0; i < s; ++i)
  112. infobar[i].statustext = _strdup(WMFS_VERSION);
  113. infobar_draw(sc);
  114. }
  115. return;
  116. }
  117. /** Draw the Infobar
  118. *\param sc Screen number
  119. */
  120. void
  121. infobar_draw(int sc)
  122. {
  123. infobar_draw_taglist(sc);
  124. infobar_draw_layout(sc);
  125. infobar_draw_selbar(sc);
  126. barwin_refresh_color(infobar[sc].bar);
  127. statustext_handle(sc, infobar[sc].statustext);
  128. return;
  129. }
  130. /** Draw the layout button in the InfoBar
  131. *\param sc Screen number
  132. */
  133. void
  134. infobar_draw_layout(int sc)
  135. {
  136. barwin_resize(infobar[sc].layout_button, textw(tags[sc][seltag[sc]].layout.symbol) + PAD, infobar[sc].geo.height);
  137. barwin_refresh_color(infobar[sc].layout_button);
  138. if(tags[sc][seltag[sc]].layout.symbol)
  139. barwin_draw_text(infobar[sc].layout_button, PAD / 2, FHINFOBAR, tags[sc][seltag[sc]].layout.symbol);
  140. return;
  141. }
  142. /** Draw Selbar (selected client title bar in infobar
  143. *\param sc Screen Number
  144. */
  145. void
  146. infobar_draw_selbar(int sc)
  147. {
  148. if(!conf.bars.selbar)
  149. return;
  150. barwin_move(infobar[sc].selbar,
  151. ((conf.layout_placement)
  152. ? (infobar[sc].tags_board->geo.x + infobar[sc].tags_board->geo.width + PAD / 2)
  153. : (infobar[sc].layout_button->geo.x + infobar[sc].layout_button->geo.width + PAD / 2)), 1);
  154. barwin_resize(infobar[sc].selbar, textw(sel ? sel->title : NULL) + PAD, infobar[sc].geo.height - 2);
  155. barwin_refresh_color(infobar[sc].selbar);
  156. barwin_draw_text(infobar[sc].selbar, PAD / 2, FHINFOBAR - 1, (sel) ? sel->title : NULL);
  157. barwin_refresh(infobar[sc].selbar);
  158. return;
  159. }
  160. /** Draw the taglist in the InfoBar
  161. *\param sc Screen number
  162. */
  163. void
  164. infobar_draw_taglist(int sc)
  165. {
  166. int i;
  167. Client *c;
  168. if(conf.layout_placement)
  169. barwin_move(infobar[sc].tags_board, textw(tags[sc][seltag[sc]].layout.symbol) + PAD * 1.5, 0);
  170. for(i = 1; i < conf.ntag[sc] + 1; ++i)
  171. {
  172. infobar[sc].tags[i]->bg = ((i == seltag[sc]) ? conf.colors.tagselbg : conf.colors.bar);
  173. infobar[sc].tags[i]->fg = ((i == seltag[sc]) ? conf.colors.tagselfg : conf.colors.text);
  174. barwin_refresh_color(infobar[sc].tags[i]);
  175. /* Colorize a tag if there are clients in this */
  176. for(c = clients; c; c = c->next)
  177. {
  178. if(c->screen == sc)
  179. {
  180. infobar[sc].tags[c->tag]->bg = ((c->tag == seltag[sc]) ? conf.colors.tagselbg : conf.colors.tag_occupied_bg);
  181. barwin_refresh_color(infobar[sc].tags[i]);
  182. }
  183. }
  184. if(tags[sc][i].name)
  185. barwin_draw_text(infobar[sc].tags[i], PAD / 2, FHINFOBAR, tags[sc][i].name);
  186. }
  187. return;
  188. }
  189. /** Destroy the InfoBar
  190. */
  191. void
  192. infobar_destroy(void)
  193. {
  194. int sc, i;
  195. for(sc = 0; sc < screen_count(); ++sc)
  196. {
  197. barwin_delete(infobar[sc].layout_button);
  198. barwin_delete_subwin(infobar[sc].layout_button);
  199. for(i = 1; i < conf.ntag[sc] + 1; ++i)
  200. {
  201. barwin_delete_subwin(infobar[sc].tags[i]);
  202. barwin_delete(infobar[sc].tags[i]);
  203. }
  204. barwin_delete_subwin(infobar[sc].tags_board);
  205. barwin_delete(infobar[sc].tags_board);
  206. barwin_delete_subwin(infobar[sc].bar);
  207. barwin_delete(infobar[sc].bar);
  208. }
  209. return;
  210. }
  211. /* Set the infobar position
  212. * \param pos Position of the bar
  213. */
  214. void
  215. infobar_set_position(int pos)
  216. {
  217. screen_get_sel();
  218. switch(pos)
  219. {
  220. case IB_Hide:
  221. sgeo[selscreen].y = spgeo[selscreen].y + TBARH;
  222. sgeo[selscreen].height = spgeo[selscreen].height - TBARH;
  223. infobar[selscreen].geo.y = -(infobar[selscreen].geo.height) * 2;
  224. break;
  225. case IB_Bottom:
  226. sgeo[selscreen].y = spgeo[selscreen].y + TBARH;
  227. sgeo[selscreen].height = spgeo[selscreen].height - INFOBARH - TBARH;
  228. infobar[selscreen].geo.y = spgeo[selscreen].y + sgeo[selscreen].height + TBARH;
  229. break;
  230. default:
  231. case IB_Top:
  232. sgeo[selscreen].y = spgeo[selscreen].y + INFOBARH + TBARH;
  233. sgeo[selscreen].height = spgeo[selscreen].height - INFOBARH - TBARH;
  234. infobar[selscreen].geo.y = spgeo[selscreen].y;
  235. break;
  236. }
  237. tags[selscreen][seltag[selscreen]].barpos = pos;
  238. barwin_move(infobar[selscreen].bar, sgeo[selscreen].x - BORDH, infobar[selscreen].geo.y);
  239. infobar_draw(selscreen);
  240. ewmh_set_workarea();
  241. arrange(selscreen, True);
  242. return;
  243. }
  244. /** Toggle the infobar position
  245. * \param cmd uicb_t type unused
  246. */
  247. void
  248. uicb_infobar_togglepos(uicb_t cmd)
  249. {
  250. screen_get_sel();
  251. infobar_set_position((tags[selscreen][seltag[selscreen]].barpos
  252. = (tags[selscreen][seltag[selscreen]].barpos < 2)
  253. ? tags[selscreen][seltag[selscreen]].barpos + 1
  254. : 0));
  255. return;
  256. }