init.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * wmfs.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. const func_name_list_t layout_list[] =
  34. {
  35. {"tile", tile },
  36. {"tile_right", tile },
  37. {"tile_left", tile_left },
  38. {"tile_top", tile_top },
  39. {"tile_bottom", tile_bottom },
  40. {"tile_grid", grid },
  41. {"grid", grid },
  42. {"mirror_vertical", mirror_vertical },
  43. {"tile_mirror_vertical", mirror_vertical },
  44. {"mirror_horizontal", mirror_horizontal },
  45. {"tile_mirror_horizontal", mirror_horizontal },
  46. {"layer", layer },
  47. {"max", maxlayout },
  48. {"maxlayout", maxlayout },
  49. {"freelayout", freelayout },
  50. {"free", freelayout },
  51. { NULL, NULL }
  52. };
  53. /** Init WMFS
  54. */
  55. void
  56. init(void)
  57. {
  58. /* First init */
  59. ewmh_init_hints();
  60. init_conf();
  61. init_gc();
  62. init_font();
  63. init_cursor();
  64. init_key();
  65. init_root();
  66. screen_init_geo();
  67. infobar_init();
  68. init_status();
  69. ewmh_update_current_tag_prop();
  70. grabkeys();
  71. return;
  72. }
  73. /** Init the font
  74. */
  75. void
  76. init_font(void)
  77. {
  78. font = XftFontOpenName(dpy, SCREEN, conf.font);
  79. if(!font)
  80. {
  81. warnx("WMFS Error: Cannot initialize font");
  82. font = XftFontOpenName(dpy, SCREEN, "sans-10");
  83. }
  84. return;
  85. }
  86. /** Init the graphic context
  87. */
  88. void
  89. init_gc(void)
  90. {
  91. XGCValues gcv;
  92. /* Bits sequences */
  93. const char pix_bits[] =
  94. {
  95. 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
  96. 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
  97. 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
  98. 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55
  99. };
  100. gc = DefaultGC(dpy, SCREEN);
  101. /* Stipple GC */
  102. gcv.function = GXcopy;
  103. gcv.fill_style = FillStippled;
  104. gcv.stipple = XCreateBitmapFromData(dpy, ROOT, pix_bits, 10, 4);
  105. gc_stipple = XCreateGC(dpy, ROOT, GCFunction | GCFillStyle | GCStipple, &gcv);
  106. return;
  107. }
  108. /** Init WMFS cursor
  109. */
  110. void
  111. init_cursor(void)
  112. {
  113. cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  114. cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  115. cursor[CurRightResize] = XCreateFontCursor(dpy, XC_lr_angle);
  116. cursor[CurLeftResize] = XCreateFontCursor(dpy, XC_ll_angle);
  117. cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  118. return;
  119. }
  120. /** Init key modifier
  121. */
  122. void
  123. init_key(void)
  124. {
  125. int i, j;
  126. XModifierKeymap *modmap = XGetModifierMapping(dpy);
  127. for(i = 0; i < 8; i++)
  128. for(j = 0; j < modmap->max_keypermod; ++j)
  129. if(modmap->modifiermap[i * modmap->max_keypermod + j]
  130. == XKeysymToKeycode(dpy, XK_Num_Lock))
  131. numlockmask = (1 << i);
  132. XFreeModifiermap(modmap);
  133. return;
  134. }
  135. /** Init root Window
  136. */
  137. void
  138. init_root(void)
  139. {
  140. XSetWindowAttributes at;
  141. at.event_mask = KeyMask | ButtonMask | MouseMask | PropertyChangeMask
  142. | SubstructureRedirectMask | SubstructureNotifyMask | StructureNotifyMask;
  143. at.cursor = cursor[CurNormal];
  144. XChangeWindowAttributes(dpy, ROOT, CWEventMask | CWCursor, &at);
  145. if(conf.root.background_command)
  146. spawn("%s", conf.root.background_command);
  147. ewmh_init_hints();
  148. ewmh_get_number_of_desktop();
  149. ewmh_get_desktop_names();
  150. return;
  151. }
  152. /** Init statustext shell script
  153. */
  154. void
  155. init_status(void)
  156. {
  157. int fd;
  158. struct stat st;
  159. char *home;
  160. if(!conf.status_path)
  161. {
  162. if(!(home = getenv("HOME")))
  163. {
  164. warnx("HOME not set, can't launch status.sh");
  165. estatus = False;
  166. return;
  167. }
  168. conf.status_path = emalloc(strlen(home) + strlen(DEF_STATUS) + 2, sizeof(char));
  169. sprintf(conf.status_path, "%s/"DEF_STATUS, home);
  170. }
  171. if(!(fd = open(conf.status_path, O_RDONLY))
  172. || !fopen(conf.status_path, "r"))
  173. {
  174. free(conf.status_path);
  175. estatus = False;
  176. return;
  177. }
  178. stat(conf.status_path, &st);
  179. if(st.st_size && st.st_mode & S_IXUSR)
  180. {
  181. estatus = True;
  182. spawn(conf.status_path);
  183. }
  184. else
  185. warnx("status file specified in configuratin (status_path) or present in wmfs directory can't be executed, try 'chmod +x %s'.", conf.status_path);
  186. close(fd);
  187. return;
  188. }