wmfs.h 12 KB

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