wmfs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /*
  2. * wmfs.h
  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. #ifndef WMFS_H
  33. #define WMFS_H
  34. /* Lib headers */
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <stdarg.h>
  38. #include <string.h>
  39. #include <signal.h>
  40. #include <unistd.h>
  41. #include <time.h>
  42. #include <getopt.h>
  43. #include <dirent.h>
  44. #include <err.h>
  45. #include <pthread.h>
  46. #include <sys/select.h>
  47. #include <sys/types.h>
  48. #include <sys/wait.h>
  49. #include <sys/stat.h>
  50. #include <X11/Xlib.h>
  51. #include <X11/Xatom.h>
  52. #include <X11/cursorfont.h>
  53. #include <X11/Xft/Xft.h>
  54. /* Local headers */
  55. #include "confparse/confparse.h"
  56. #include "config.h"
  57. #include "structs.h"
  58. /* Optional dependencies */
  59. #ifdef HAVE_XINERAMA
  60. #include <X11/extensions/Xinerama.h>
  61. #endif /* HAVE_XINERAMA */
  62. #ifdef HAVE_XRANDR
  63. #include <X11/extensions/Xrandr.h>
  64. #endif /* HAVE_XRANDR */
  65. #ifdef HAVE_IMLIB
  66. #include <Imlib2.h>
  67. #endif /* HAVE_IMLIB */
  68. /* MACRO */
  69. #define ButtonMask (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
  70. #define MouseMask (ButtonMask | PointerMotionMask)
  71. #define KeyMask (KeyPressMask | KeyReleaseMask)
  72. #define SCREEN DefaultScreen(dpy)
  73. #define ROOT RootWindow(dpy, SCREEN)
  74. #define MAXH DisplayHeight(dpy, DefaultScreen(dpy))
  75. #define MAXW DisplayWidth(dpy, DefaultScreen(dpy))
  76. #define INFOBARH ((conf.bars.height > 0) ? conf.bars.height : (font->height * 1.5))
  77. #define FHINFOBAR ((font->height - font->descent) + (INFOBARH - font->height) / 2)
  78. #define SHADH (1)
  79. #define SHADC (0x000000) /* 'Cause i don't know how darken a color yet */
  80. #define BORDH conf.client.borderheight
  81. #define TBARH ((conf.titlebar.height < BORDH) ? BORDH : conf.titlebar.height)
  82. #define RESHW (6 * BORDH)
  83. #define BUTTONWH (TBARH / 2)
  84. #define DEF_CONF ".config/wmfs/wmfsrc"
  85. #define DEF_STATUS ".config/wmfs/status.sh"
  86. #define PAD conf.pad
  87. #define MAXSTATUS 4096
  88. #define CWIN(win, parent, x, y, w, h, b, mask, col, at) \
  89. do { \
  90. win = XCreateWindow(dpy, (parent), (x), (y), (w), (h), (b), CopyFromParent, \
  91. InputOutput, CopyFromParent, (mask), (at)); \
  92. XSetWindowBackground(dpy, win, (col)); \
  93. } while (/* CONSTCOND */ 0)
  94. #define ATOM(a) XInternAtom(dpy, (a), False)
  95. #define FRAMEW(w) ((w) + BORDH * 2)
  96. #define FRAMEH(h) ((h) + (BORDH + TBARH))
  97. #define ROUND(x) (float)((x > 0) ? x + (float)0.5 : x - (float)0.5)
  98. #define CHECK(x) if(!(x)) return
  99. #define IFREE(x) if(x) free(x)
  100. #define LEN(x) (sizeof(x) / sizeof((x)[0]))
  101. /* barwin.c */
  102. BarWindow *barwin_create(Window parent,
  103. int x, int y,
  104. uint w, uint h,
  105. uint bg, char*fg,
  106. Bool entermask,
  107. Bool stipple,
  108. Bool border);
  109. void barwin_draw_text(BarWindow *bw, int x, int y, char *text);
  110. void barwin_delete(BarWindow *bw);
  111. void barwin_delete_subwin(BarWindow *bw);
  112. void barwin_map(BarWindow *bw);
  113. void barwin_map_subwin(BarWindow *bw);
  114. void barwin_unmap(BarWindow *bw);
  115. void barwin_unmap_subwin(BarWindow *bw);
  116. void barwin_move(BarWindow *bw, int x, int y);
  117. void barwin_resize(BarWindow *bw, uint w, uint h);
  118. void barwin_refresh_color(BarWindow *bw);
  119. void barwin_refresh(BarWindow *bw);
  120. /* draw.c */
  121. void draw_text(Drawable d, int x, int y, char* fg, int pad, char *str);
  122. void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color);
  123. #ifdef HAVE_IMLIB
  124. void draw_image(Drawable dr, int x, int y, int w, int h, char *name);
  125. #endif /* HAVE_IMLIB */
  126. ushort textw(char *text);
  127. /* infobar.c */
  128. void infobar_init(void);
  129. void infobar_draw(int sc);
  130. void infobar_draw_layout(int sc);
  131. void infobar_draw_selbar(int sc);
  132. void infobar_draw_taglist(int sc);
  133. void infobar_destroy(void);
  134. void infobar_set_position(int pos);
  135. void uicb_infobar_togglepos(uicb_t);
  136. /* client.c */
  137. void client_attach(Client *c);
  138. void client_configure(Client *c);
  139. void client_detach(Client *c);
  140. void client_above(Client *c);
  141. void client_focus(Client *c);
  142. Client* client_get_next(void);
  143. Client* client_get_prev(void);
  144. /* client_gb_*() {{{ */
  145. Client* client_gb_win(Window w);
  146. Client* client_gb_frame(Window w);
  147. Client* client_gb_titlebar(Window w);
  148. Client* client_gb_resize(Window w);
  149. Client* client_gb_button(Window w, int *n);
  150. /* }}} */
  151. void client_get_name(Client *c);
  152. void client_hide(Client *c);
  153. void client_kill(Client *c);
  154. Bool ishide(Client *c, int screen);
  155. void client_map(Client *c);
  156. Client* client_manage(Window w, XWindowAttributes *wa, Bool ar);
  157. void client_geo_hints(XRectangle *geo, Client *c);
  158. void client_moveresize(Client *c, XRectangle geo, Bool r);
  159. void client_maximize(Client *c);
  160. void client_size_hints(Client *c);
  161. void client_swap(Client *c1, Client *c2);
  162. void client_raise(Client *c);
  163. void client_unhide(Client *c);
  164. void client_unmanage(Client *c);
  165. void client_unmap(Client *c);
  166. void client_set_wanted_tag(Client *c);
  167. void client_update_attributes(Client *c);
  168. void uicb_client_raise(uicb_t);
  169. void uicb_client_next(uicb_t);
  170. void uicb_client_prev(uicb_t);
  171. void uicb_client_swap_next(uicb_t);
  172. void uicb_client_swap_prev(uicb_t);
  173. void uicb_client_kill(uicb_t);
  174. void uicb_client_screen_next(uicb_t);
  175. void uicb_client_screen_prev(uicb_t);
  176. void uicb_client_move(uicb_t cmd);
  177. void uicb_client_resize(uicb_t cmd);
  178. void uicb_ignore_next_client_rules(uicb_t cmd);
  179. /* ewmh.c */
  180. void ewmh_init_hints(void);
  181. void ewmh_get_number_of_desktop(void);
  182. void ewmh_update_current_tag_prop(void);
  183. void ewmh_get_client_list(void);
  184. void ewmh_get_desktop_names(void);
  185. void ewmh_set_desktop_geometry(void);
  186. void ewmh_set_workarea(void);
  187. void ewmh_manage_net_wm_state(long data_l[], Client *c);
  188. void ewmh_manage_window_type(Client *c);
  189. /* frame.c */
  190. void frame_create(Client *c);
  191. void frame_delete(Client *c);
  192. void frame_moveresize(Client *c, XRectangle geo);
  193. void frame_update(Client *c);
  194. /* config.c */
  195. void init_conf(void);
  196. /* event.c */
  197. void buttonpress(XButtonEvent *ev);
  198. void configureevent(XConfigureRequestEvent *ev);
  199. void clientmessageevent(XClientMessageEvent *ev);
  200. void destroynotify(XDestroyWindowEvent *ev);
  201. void enternotify(XCrossingEvent *ev);
  202. void expose(XExposeEvent *ev);
  203. void focusin(XFocusChangeEvent *ev);
  204. void grabkeys(void);
  205. void keypress(XKeyPressedEvent *ev);
  206. void mappingnotify(XMappingEvent *ev);
  207. void maprequest(XMapRequestEvent *ev);
  208. void propertynotify(XPropertyEvent *ev);
  209. void unmapnotify(XUnmapEvent *ev);
  210. void send_client_event(long data[5], char *atom_name);
  211. void getevent(XEvent ev);
  212. /* menu.c */
  213. void menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n);
  214. void menu_new_item(MenuItem *mi, char *name, void *func, char *cmd);
  215. void menu_draw(Menu menu, int x, int y);
  216. Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]);
  217. void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]);
  218. void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[]);
  219. int menu_get_longer_string(MenuItem *mt, int nitem);
  220. void uicb_menu(uicb_t cmd);
  221. /* launcher.c */
  222. void launcher_execute(Launcher launcher);
  223. void uicb_launcher(uicb_t);
  224. /* mouse.c */
  225. void mouse_dragborder(XRectangle geo, GC g);
  226. void mouse_move_tile_client(Client **c);
  227. void mouse_move_tag_client(Client *c);
  228. void mouse_move(Client *c);
  229. void mouse_resize(Client *c);
  230. void mouse_grabbuttons(Client *c, Bool focused);
  231. void uicb_mouse_move(uicb_t);
  232. void uicb_mouse_resize(uicb_t);
  233. /* util.c */
  234. ulong color_enlight(ulong col);
  235. void *emalloc(uint element, uint size);
  236. long getcolor(char *color);
  237. void setwinstate(Window win, long state);
  238. char* _strdup(char const *str);
  239. /* Conf usage {{{ */
  240. void* name_to_func(char *name, const func_name_list_t *l);
  241. ulong char_to_modkey(char *name, key_name_list_t key_l[]);
  242. uint char_to_button(char *name, name_to_uint_t blist[]);
  243. Layout layout_name_to_struct(Layout lt[], char *name, int n, const func_name_list_t llist[]);
  244. char* alias_to_str(char *conf_choice);
  245. /* }}} */
  246. XRectangle get_mouse_pos(void);
  247. char *char_to_str(const char c);
  248. void spawn(const char *str, ...);
  249. void swap_ptr(void **x, void **y);
  250. void uicb_spawn(uicb_t);
  251. #ifdef HAVE_IMLIB
  252. int parse_image_block(ImageAttr *im, char *str);
  253. #endif /* HAVE_IMLIB */
  254. /* tag.c */
  255. void tag_set(int tag);
  256. void tag_transfert(Client *c, int tag);
  257. void uicb_tag(uicb_t);
  258. void uicb_tag_next(uicb_t);
  259. void uicb_tag_prev(uicb_t);
  260. void uicb_tagtransfert(uicb_t);
  261. void uicb_tag_prev_sel(uicb_t);
  262. void uicb_tagtransfert_next(uicb_t);
  263. void uicb_tagtransfert_prev(uicb_t);
  264. /* screen.c */
  265. int screen_count(void);
  266. XRectangle screen_get_geo(int s);
  267. int screen_get_with_geo(int x, int y);
  268. int screen_get_sel(void);
  269. void screen_set_sel(int screen);
  270. void screen_init_geo(void);
  271. void uicb_screen_select(uicb_t);
  272. void uicb_screen_next(uicb_t);
  273. void uicb_screen_prev(uicb_t);
  274. void uicb_screen_prev_sel(uicb_t);
  275. /* status.c */
  276. int statustext_rectangle(StatusRec *r, char *str);
  277. int statustext_text(StatusText *s, char *str);
  278. void statustext_normal(int sc, char *str);
  279. void statustext_handle(int sc, char *str);
  280. /* layout.c */
  281. void arrange(int screen, Bool update_layout);
  282. void freelayout(int screen);
  283. void layoutswitch(Bool b);
  284. void maxlayout(int screen);
  285. Client *tiled_client(int screen, Client *c);
  286. /* tile {{{ */
  287. void grid(int screen);
  288. void tile(int screen);
  289. void tile_left(int screen);
  290. void tile_top(int screen);
  291. void tile_bottom(int screen);
  292. void mirror_vertical(int screen);
  293. void mirror_horizontal(int screen);
  294. void layer(int screen);
  295. /* }}} */
  296. void uicb_togglemax(uicb_t);
  297. void uicb_togglefree(uicb_t);
  298. void uicb_layout_prev(uicb_t);
  299. void uicb_layout_next(uicb_t);
  300. void uicb_set_mwfact(uicb_t);
  301. void uicb_set_nmaster(uicb_t);
  302. void uicb_set_layout(uicb_t);
  303. void uicb_toggle_resizehint(uicb_t);
  304. void uicb_toggle_abovefc(uicb_t cmd);
  305. void uicb_set_layer(uicb_t cmd);
  306. void uicb_set_client_layer(uicb_t cmd);
  307. void layout_set_client_master(Client *c);
  308. /* init.c */
  309. void init(void);
  310. void init_root(void);
  311. void init_font(void);
  312. void init_gc(void);
  313. void init_cursor(void);
  314. void init_key(void);
  315. void init_geometry(void);
  316. void init_status(void);
  317. /* getinfo.c */
  318. void getinfo_tag(void);
  319. void getinfo_screen(void);
  320. void getinfo_layout(void);
  321. void getinfo_mwfact(void);
  322. void getinfo_nmaster(void);
  323. void getinfo(char *info);
  324. /* viwmfs.c */
  325. void viwmfs(int argc, char **argv);
  326. /* wmfs.c */
  327. int errorhandler(Display *d, XErrorEvent *event);
  328. int errorhandlerdummy(Display *d, XErrorEvent *event);
  329. void quit(void);
  330. void *thread_process(void *arg);
  331. void mainloop(void);
  332. void scan(void);
  333. Bool check_wmfs_running(void);
  334. void exec_uicb_function(char *func, char *cmd);
  335. void set_statustext(int s, char *str);
  336. void update_status(void);
  337. void handle_signal(int signum);
  338. void uicb_quit(uicb_t);
  339. void uicb_reload(uicb_t);
  340. /* Variables */
  341. /* Principal */
  342. Display *dpy;
  343. GC gc, gc_stipple;
  344. int selscreen;
  345. int prevselscreen;
  346. Conf conf;
  347. Key *keys;
  348. Bool exiting, estatus;
  349. XRectangle *sgeo;
  350. XRectangle *spgeo;
  351. Cursor cursor[CurLast];
  352. char *argv_global;
  353. int xrandr_event;
  354. uint timing;
  355. /* Fonts */
  356. XftFont *font;
  357. /* Atoms list */
  358. Atom *net_atom;
  359. /* InfoBar/Tags */
  360. InfoBar *infobar;
  361. Tag **tags;
  362. int *seltag;
  363. int *prevseltag;
  364. Menu menulayout;
  365. /* Important Client */
  366. Client *clients;
  367. Client *sel;
  368. /* Other */
  369. func_name_list_t *func_list;
  370. extern const func_name_list_t layout_list[];
  371. uint numlockmask;
  372. #endif /* WMFS_H */