wmfs.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #ifndef WMFS_H
  6. #define WMFS_H
  7. /* Standard */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <stdbool.h>
  11. #include <stdarg.h>
  12. #include <signal.h>
  13. #include <unistd.h>
  14. #include <locale.h>
  15. #include <err.h>
  16. #include <sys/queue.h>
  17. /* Xlib */
  18. #include <X11/Xlib.h>
  19. #include <X11/Xatom.h>
  20. /* Local */
  21. #include "log.h"
  22. #define CONFIG_DEFAULT_PATH ".config/wmfs/wmfsrc"
  23. #define ButtonMask (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
  24. #define MouseMask (ButtonMask | PointerMotionMask)
  25. #define KeyMask (KeyPressMask | KeyReleaseMask)
  26. typedef unsigned long Flags;
  27. typedef unsigned int Color;
  28. typedef const char* Uicb;
  29. enum barpos
  30. {
  31. BarTop = 0,
  32. BarBottom,
  33. BarHide,
  34. BarLast
  35. };
  36. enum position
  37. {
  38. Right = 0,
  39. Left,
  40. Top,
  41. Bottom,
  42. Center,
  43. NoAlign,
  44. PositionLast
  45. };
  46. enum size_hints
  47. {
  48. BASEW, BASEH,
  49. INCW, INCH,
  50. MAXW, MAXH,
  51. MINW, MINH,
  52. MINAX, MINAY,
  53. MAXAX, MAXAY,
  54. SHLAST
  55. };
  56. /*
  57. * Structures
  58. */
  59. struct geo
  60. {
  61. int x, y, w, h;
  62. };
  63. struct geo_list
  64. {
  65. struct geo geo;
  66. SLIST_ENTRY(geo_list) next;
  67. };
  68. struct colpair
  69. {
  70. Color fg, bg;
  71. };
  72. struct barwin
  73. {
  74. struct geo geo;
  75. Window win;
  76. Drawable dr;
  77. Color fg, bg;
  78. void *ptr; /* Special cases */
  79. SLIST_HEAD(mbhead, mousebind) mousebinds;
  80. SLIST_HEAD(, mousebind) statusmousebinds;
  81. SLIST_ENTRY(barwin) next; /* global barwin */
  82. SLIST_ENTRY(barwin) enext; /* element barwin */
  83. SLIST_ENTRY(barwin) vnext; /* volatile barwin */
  84. };
  85. struct status_seq
  86. {
  87. struct geo geo;
  88. enum position align;
  89. int data[4];
  90. char type;
  91. char *str;
  92. Color color, color2;
  93. SLIST_HEAD(, mousebind) mousebinds;
  94. SLIST_ENTRY(status_seq) next;
  95. };
  96. struct status_ctx
  97. {
  98. struct barwin *barwin;
  99. struct theme *theme;
  100. #define STATUS_BLOCK_REFRESH 0x01
  101. Flags flags;
  102. char *status;
  103. bool update;
  104. SLIST_HEAD(, status_gcache) gcache;
  105. SLIST_HEAD(, status_seq) statushead;
  106. };
  107. struct status_gcache
  108. {
  109. char *name;
  110. int *datas;
  111. int ndata;
  112. SLIST_ENTRY(status_gcache) next;
  113. };
  114. struct element
  115. {
  116. struct geo geo;
  117. struct infobar *infobar;
  118. struct status_ctx *statusctx;
  119. int type;
  120. char *data;
  121. enum position align;
  122. void (*func_init)(struct element *e);
  123. void (*func_update)(struct element *e);
  124. SLIST_HEAD(, barwin) bars;
  125. TAILQ_ENTRY(element) next;
  126. };
  127. struct infobar
  128. {
  129. struct barwin *bar;
  130. struct geo geo;
  131. struct screen *screen;
  132. struct theme *theme;
  133. struct status_ctx statusctx;
  134. enum barpos pos;
  135. char *elemorder;
  136. char *name;
  137. TAILQ_HEAD(esub, element) elements;
  138. SLIST_ENTRY(infobar) next;
  139. };
  140. struct screen
  141. {
  142. struct geo geo, ugeo;
  143. struct tag *seltag;
  144. #define SCREEN_TAG_UPDATE 0x01
  145. Flags flags;
  146. int id;
  147. TAILQ_HEAD(tsub, tag) tags;
  148. SLIST_HEAD(, infobar) infobars;
  149. SLIST_ENTRY(screen) next;
  150. };
  151. SLIST_HEAD(chead, client);
  152. struct tag
  153. {
  154. struct screen *screen;
  155. struct client *sel;
  156. struct client *prevsel;
  157. struct tag *prev;
  158. struct status_ctx statusctx;
  159. char *name;
  160. int id;
  161. #define TAG_URGENT 0x01
  162. #define TAG_IGNORE_ENTER 0x02
  163. Flags flags;
  164. SLIST_HEAD(, client) clients;
  165. TAILQ_HEAD(ssub, layout_set) sets;
  166. TAILQ_ENTRY(tag) next;
  167. };
  168. struct client
  169. {
  170. struct tag *tag, *prevtag;
  171. struct screen *screen;
  172. struct barwin *titlebar;
  173. struct geo geo, wgeo, tgeo, ttgeo, rgeo, *tbgeo;
  174. struct colpair ncol, scol;
  175. struct theme *theme;
  176. struct client *tabmaster;
  177. int sizeh[SHLAST];
  178. char *title;
  179. int border, tbarw;
  180. #define CLIENT_HINT_FLAG 0x01
  181. #define CLIENT_IGNORE_ENTER 0x02
  182. #define CLIENT_DID_WINSIZE 0x04
  183. #define CLIENT_FAC_APPLIED 0x08
  184. #define CLIENT_IGNORE_LAYOUT 0x10
  185. #define CLIENT_RULED 0x20
  186. #define CLIENT_TABBED 0x40
  187. #define CLIENT_TABMASTER 0x80
  188. #define CLIENT_DYING 0x100 /* Saddest flag ever */
  189. #define CLIENT_REMOVEALL 0x200
  190. #define CLIENT_MAPPED 0x400
  191. #define CLIENT_FULLSCREEN 0x800
  192. #define CLIENT_FREE 0x1000
  193. #define CLIENT_TILED 0x2000
  194. #define CLIENT_MOUSE 0x4000
  195. Flags flags;
  196. Window win, frame, tmp;
  197. SLIST_ENTRY(client) next; /* Global list */
  198. SLIST_ENTRY(client) tnext; /* struct tag list */
  199. };
  200. struct layout_set
  201. {
  202. int n;
  203. SLIST_HEAD(, geo_list) geos;
  204. TAILQ_ENTRY(layout_set) next;
  205. };
  206. struct keybind
  207. {
  208. unsigned int mod;
  209. void (*func)(Uicb);
  210. Uicb cmd;
  211. KeySym keysym;
  212. SLIST_ENTRY(keybind) next;
  213. };
  214. struct mousebind
  215. {
  216. struct geo area;
  217. unsigned int button;
  218. bool use_area;
  219. void (*func)(Uicb);
  220. Uicb cmd;
  221. SLIST_ENTRY(mousebind) next;
  222. SLIST_ENTRY(mousebind) snext;
  223. SLIST_ENTRY(mousebind) globnext;
  224. };
  225. struct theme
  226. {
  227. char *name;
  228. /* Font */
  229. struct
  230. {
  231. int as, de, width, height;
  232. XFontSet fontset;
  233. } font;
  234. /* Bars */
  235. struct colpair bars;
  236. int bars_width;
  237. /* struct elements */
  238. struct colpair tags_n, tags_s, tags_o, tags_u; /* normal / selected / occupied */
  239. struct status_ctx tags_n_sl, tags_s_sl, tags_o_sl, tags_u_sl; /* status line */
  240. int tags_border_width;
  241. Color tags_border_col;
  242. /* client / frame */
  243. struct colpair client_n, client_s;
  244. struct status_ctx client_n_sl, client_s_sl, client_f_sl;
  245. Color frame_bg;
  246. int client_titlebar_width;
  247. int client_border_width;
  248. SLIST_ENTRY(theme) next;
  249. };
  250. struct rule
  251. {
  252. struct theme *theme;
  253. char *class;
  254. char *instance;
  255. char *role;
  256. char *name;
  257. int tag, screen;
  258. #define RULE_FREE 0x01
  259. #define RULE_TAB 0x02
  260. #define RULE_IGNORE_TAG 0x04
  261. Flags flags;
  262. SLIST_ENTRY(rule) next;
  263. };
  264. struct launcher
  265. {
  266. char *name;
  267. char *prompt;
  268. char *command;
  269. #define HISTOLEN 64
  270. char histo[HISTOLEN][256];
  271. int nhisto;
  272. int width;
  273. SLIST_ENTRY(launcher) next;
  274. };
  275. struct launcher_ccache
  276. {
  277. char *start;
  278. char **namelist;
  279. size_t hits;
  280. };
  281. struct _systray
  282. {
  283. struct geo geo;
  284. Window win;
  285. SLIST_ENTRY(_systray) next;
  286. };
  287. #define MAX_PATH_LEN 8192
  288. struct wmfs
  289. {
  290. /* X11 stuffs */
  291. Display *dpy;
  292. Window root;
  293. int xscreen, xdepth;
  294. int xmaxw, xmaxh;
  295. int nscreen;
  296. unsigned int client_mod;
  297. Flags numlockmask;
  298. #define WMFS_SCAN 0x01
  299. #define WMFS_RUNNING 0x02
  300. #define WMFS_RELOAD 0x04
  301. #define WMFS_SYSTRAY 0x08
  302. #define WMFS_LOG 0x10
  303. #define WMFS_LAUNCHER 0x20
  304. #define WMFS_SIGCHLD 0x40
  305. #define WMFS_TABNOC 0x80 /* tab next opened client */
  306. Flags flags;
  307. GC gc, rgc;
  308. Atom *net_atom;
  309. char **argv;
  310. char *confpath;
  311. struct barwin *last_clicked_barwin;
  312. struct theme *ctheme;
  313. #define CFOCUS_ENTER 0x01
  314. #define CFOCUS_CLICK 0x02
  315. Flags cfocus; /* Focus configuration, can be set to 0, CFOCUS_ENTER or CFOCUS_CLICK*/
  316. /* Log file */
  317. FILE *log;
  318. /* Lists heads */
  319. struct
  320. {
  321. SLIST_HEAD(, screen) screen;
  322. SLIST_HEAD(, client) client;
  323. SLIST_HEAD(, keybind) keybind;
  324. SLIST_HEAD(, barwin) barwin;
  325. SLIST_HEAD(, theme) theme;
  326. SLIST_HEAD(, rule) rule;
  327. SLIST_HEAD(, mousebind) mousebind;
  328. SLIST_HEAD(, launcher) launcher;
  329. SLIST_HEAD(, barwin) vbarwin;
  330. } h;
  331. /*
  332. * Temporary head of mousebind list from config
  333. * Will be copied in barwin of clickable drawable
  334. * later in code
  335. */
  336. struct
  337. {
  338. struct mbhead tag;
  339. struct mbhead client;
  340. struct mbhead root;
  341. } tmp_head;
  342. /*
  343. * Because there is only one systray per display,
  344. * set struct there
  345. */
  346. struct
  347. {
  348. struct barwin *barwin;
  349. struct infobar *infobar;
  350. bool redim;
  351. Window win;
  352. SLIST_HEAD(, _systray) head;
  353. } systray;
  354. /*
  355. * Selected screen, client
  356. */
  357. struct screen *screen;
  358. struct client *client;
  359. };
  360. int wmfs_error_handler(Display *d, XErrorEvent *event);
  361. int wmfs_error_handler_dummy(Display *d, XErrorEvent *event);
  362. void wmfs_grab_keys(void);
  363. void wmfs_numlockmask(void);
  364. void wmfs_init_font(char *font, struct theme *t);
  365. void wmfs_quit(void);
  366. void uicb_reload(Uicb cmd);
  367. void uicb_quit(Uicb cmd);
  368. /* Single global variable */
  369. struct wmfs *W;
  370. #endif /* WMFS_H */