You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

430 lines
14 KiB

  1. /*
  2. * neercs console-based window manager
  3. * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
  4. * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * All Rights Reserved
  6. *
  7. * This program is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What The Fuck You Want
  10. * To Public License, Version 2, as published by Sam Hocevar. See
  11. * http://www.wtfpl.net/ for more details.
  12. */
  13. #pragma once
  14. #include <stdint.h>
  15. #include <caca.h>
  16. #include "widgets.h"
  17. enum wm_types
  18. {
  19. WM_FULL,
  20. WM_CARD,
  21. WM_HSPLIT,
  22. WM_VSPLIT,
  23. WM_MAX,
  24. };
  25. enum mouse_report
  26. {
  27. MOUSE_NONE,
  28. MOUSE_X10,
  29. MOUSE_VT200,
  30. MOUSE_VT200_HIGHLIGHT,
  31. MOUSE_BTN_EVENT,
  32. MOUSE_ANY_EVENT,
  33. };
  34. /* ISO-2022 Conversion State */
  35. struct iso2022_conv_state
  36. {
  37. /* cs = coding system/coding method: */
  38. /* (with standard return) */
  39. /* '@' = ISO-2022, */
  40. /* 'G' = UTF-8 without implementation level, */
  41. /* '8' = UTF-8 (Linux console and imitators), */
  42. /* and many others that are rarely used; */
  43. /* (without standard return) */
  44. /* '/G' = UTF-8 Level 1, */
  45. /* '/H' = UTF-8 Level 2, */
  46. /* '/I' = UTF-8 Level 3, */
  47. /* and many others that are rarely used */
  48. uint32_t cs;
  49. /* ctrl8bit = allow 8-bit controls */
  50. uint8_t ctrl8bit;
  51. /* cn[0] = C0 control charset (0x00 ... 0x1f):
  52. * '@' = ISO 646,
  53. * '~' = empty,
  54. * and many others that are rarely used */
  55. /* cn[1] = C1 control charset (0x80 ... 0x9f):
  56. * 'C' = ISO 6429-1983,
  57. * '~' = empty,
  58. * and many others that are rarely used */
  59. uint32_t cn[2];
  60. /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e,
  61. * 94x94-char. 0x21/0x21 ... 0x7e/0x7e),
  62. * and
  63. * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe,
  64. * 96-char. 0xa0 ... 0xff,
  65. * 94x94-char. 0xa1/0xa1 ... 0xfe/0xfe,
  66. * 96x96-char. 0xa0/0xa0 ... 0xff/0xff):
  67. * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */
  68. uint8_t glr[2];
  69. /* gn[i] = G0/G1/G2/G3 graphic charset state:
  70. * (94-char. sets)
  71. * '0' = DEC ACS (VT100 and imitators),
  72. * 'B' = US-ASCII,
  73. * and many others that are rarely used for e.g. various national ASCII variations;
  74. * (96-char. sets)
  75. * '.A' = ISO 8859-1 "Latin 1" GR,
  76. * '.~' = empty 96-char. set,
  77. * and many others that are rarely used for e.g. ISO 8859-n GR;
  78. * (double-byte 94x94-charsets)
  79. * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978),
  80. * '$A' = Chinese Character Set (GB 2312),
  81. * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983),
  82. * '$C' = Korean Graphic Character Set (KSC 5601:1987),
  83. * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212),
  84. * '$E' = CCITT Chinese Set (GB 2312 + GB 8565),
  85. * '$G' = CNS 11643 plane 1,
  86. * '$H' = CNS 11643 plane 2,
  87. * '$I' = CNS 11643 plane 3,
  88. * '$J' = CNS 11643 plane 4,
  89. * '$K' = CNS 11643 plane 5,
  90. * '$L' = CNS 11643 plane 6,
  91. * '$M' = CNS 11643 plane 7,
  92. * '$O' = JIS X 0213 plane 1,
  93. * '$P' = JIS X 0213 plane 2,
  94. * '$Q' = JIS X 0213-2004 Plane 1,
  95. * and many others that are rarely used for e.g. traditional
  96. * ideographic Vietnamese and BlissSymbolics;
  97. * (double-byte 96x96-charsets)
  98. * none standardized or in use on terminals AFAIK (Mule does use
  99. * some internally)
  100. */
  101. uint32_t gn[4];
  102. /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */
  103. uint8_t ss;
  104. };
  105. struct screen
  106. {
  107. /* Graphics stuff */
  108. int init;
  109. caca_canvas_t *cv;
  110. uint32_t clearattr;
  111. uint8_t fg, bg; /* ANSI-context fg/bg */
  112. uint8_t dfg, dbg; /* Default fg/bg */
  113. uint8_t bold, blink, italics, negative, concealed, underline;
  114. uint8_t faint, strike, proportional; /* unsupported */
  115. struct iso2022_conv_state conv_state; /* charset mess */
  116. /* Other stuff */
  117. int visible; /* Draw canvas and border flag */
  118. int fd; /* pty fd */
  119. unsigned char *buf; /* text buffer */
  120. long int total; /* buffer length */
  121. char *title; /* tty title */
  122. int bell; /* bell occuring */
  123. unsigned int scroll, s1, s2; /* FIXME, ANSI scroll properties */
  124. int pid; /* running program pid */
  125. int changed; /* content was updated */
  126. int x, y; /* Canvas position */
  127. int w, h; /* Canvas size */
  128. int orig_x, orig_y; /* Used by recurrents */
  129. int orig_w, orig_h; /* Used by recurrents */
  130. int report_mouse; /* ANSI */
  131. };
  132. enum socket_type
  133. {
  134. SOCK_SERVER=0,
  135. SOCK_CLIENT=1
  136. };
  137. struct cube_props
  138. {
  139. int in_switch;
  140. int side;
  141. long long unsigned int duration;
  142. };
  143. struct interpreter_props
  144. {
  145. /* Input box */
  146. struct input_box *box;
  147. };
  148. struct screensaver
  149. {
  150. /* ScreenSaver stuff */
  151. long long unsigned int timeout; /* Screensaver timeout in us */
  152. int in_screensaver;
  153. void *data;
  154. };
  155. struct comm
  156. {
  157. /* Detaching */
  158. int attached; /* Are we attached to a terminal or a server */
  159. int socket[2]; /* Sockets to write to the server / to the client */
  160. char *socket_path[2]; /* Sockets to write to the server / to the client */
  161. char *socket_dir; /* Where to create the socket */
  162. char *session_name; /* Name of the session */
  163. };
  164. struct lock
  165. {
  166. int locked;
  167. int lock_offset;
  168. int lock_on_detach;
  169. long long unsigned int autolock_timeout;
  170. char lockpass[1024];
  171. char lockmsg[1024];
  172. };
  173. struct modals
  174. {
  175. /* Add-ons*/
  176. int mini; /* Thumbnails */
  177. int status; /* Status bar */
  178. int help; /* Help */
  179. int python_command; /* Python command */
  180. int window_list; /* Window list */
  181. int cur_in_list; /* Window list */
  182. };
  183. struct sys
  184. {
  185. char *default_shell;
  186. char *user_path;
  187. int *to_grab;
  188. char **to_start;
  189. int nb_to_grab;
  190. int attach, forceattach;
  191. };
  192. struct screen_list
  193. {
  194. int outfd; /* Debug */
  195. int in_bell; /* Bell occuring in a window */
  196. int was_in_bell;
  197. int dont_update_coords; /* Used by recurrents */
  198. int changed; /* Global redraw (e.g. adding a screen) */
  199. int delay; /* Minimal time between two refresh (ms) */
  200. int requested_delay;
  201. int force_refresh;
  202. int need_refresh; /* If we skipped a refresh, do it next time */
  203. int command;
  204. int eyecandy; /* Eye Candy */
  205. long long unsigned int last_key_time;
  206. long long unsigned int last_refresh_time;
  207. struct comm comm; /* Client/Server communications */
  208. struct lock lock; /* Lock */
  209. struct modals modals; /* Modal windows */
  210. struct interpreter_props interpreter_props; /* Python interpreter */
  211. struct screensaver screensaver;/* Screensaver stuff */
  212. int pty, prevpty; /* Current and previous window */
  213. int count; /* Window count */
  214. int wm_type; /* Window manager type */
  215. int border_size; /* Borders */
  216. struct cube_props cube; /* Cube */
  217. long long unsigned int last_switch; /* Cube */
  218. struct screen **screen; /* Windows */
  219. struct option *config; /* Option parsing and configuration */
  220. struct sys sys; /* System stuff */
  221. struct recurrent_list *recurrent_list; /* Recurrents functions */
  222. char *title; /* Window title */
  223. int width, height; /* caca window size */
  224. int old_x, old_y; /* Mouse */
  225. int mouse_button;
  226. caca_canvas_t *cv;
  227. caca_display_t *dp;
  228. };
  229. /* Configuration */
  230. struct option
  231. {
  232. char *key;
  233. char *value;
  234. struct option *next;
  235. };
  236. struct config_line
  237. {
  238. const char name[32];
  239. int (*set) (const char *argv, struct screen_list * screen_list);
  240. char* (*get) (struct screen_list * screen_list);
  241. };
  242. /* Recurrents */
  243. struct recurrent
  244. {
  245. int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
  246. void *user;
  247. long long unsigned int start_time;
  248. int kill_me;
  249. };
  250. struct recurrent_list
  251. {
  252. int count;
  253. struct recurrent **recurrent;
  254. };
  255. void version(void);
  256. void usage(int argc, char **argv);
  257. struct screen_list *init_neercs(int argc, char **argv);
  258. int handle_command_line(int argc, char *argv[], struct screen_list *screen_list);
  259. struct screen_list *create_screen_list(void);
  260. void free_screen_list(struct screen_list *screen_list);
  261. int start_client(struct screen_list * screen_list);
  262. /** \defgroup client neercs client
  263. * @{ */
  264. void mainloop(struct screen_list *screen_list);
  265. int mainloop_tick(char **pbuf, struct screen_list *screen_list);
  266. /** }@ */
  267. int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid);
  268. int create_pty_grab(long pid, unsigned int w, unsigned int h, int *cpid);
  269. int grab_process(long pid, char *ptyname, int ptyfd, int *newpid);
  270. long select_process(struct screen_list* screen_list);
  271. long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size);
  272. int set_tty_size(int fd, unsigned int w, unsigned int h);
  273. int update_terms(struct screen_list* screen_list);
  274. void refresh_screens(struct screen_list *screen_list);
  275. int update_screens_contents(struct screen_list* screen_list);
  276. int install_fds(struct screen_list *screen_list);
  277. long long get_us(void);
  278. void attach(struct screen_list* screen_list);
  279. int detach(struct screen_list* screen_list);
  280. int request_attach(struct screen_list* screen_list);
  281. char * build_socket_path(char *socket_dir, char *session_name, enum socket_type socktype);
  282. int create_socket(struct screen_list* screen_list, enum socket_type socktype);
  283. char * connect_socket(struct screen_list* screen_list, enum socket_type socktype);
  284. char ** list_sockets(char *socket_dir, char *session_name);
  285. int start_server(struct screen_list *screen_list);
  286. int send_event(caca_event_t ev, struct screen_list* screen_list);
  287. int send_delay(struct screen_list* screen_list);
  288. int send_ansi_sequence(struct screen_list *screen_list, char *str);
  289. /* Screens management */
  290. struct screen* create_screen(int w, int h, char *command);
  291. struct screen* create_screen_grab(int w, int h, int pid);
  292. int destroy_screen(struct screen *s);
  293. int add_screen(struct screen_list *list, struct screen *s);
  294. int remove_screen(struct screen_list *list, int n, int please_kill);
  295. void resize_screen(struct screen *s, int z, int h);
  296. /* Window managers */
  297. void update_windows_props(struct screen_list *screen_list);
  298. void update_windows_props_cards(struct screen_list *screen_list);
  299. void update_windows_props_hsplit(struct screen_list *screen_list);
  300. void update_windows_props_full(struct screen_list *screen_list);
  301. void update_windows_props_vsplit(struct screen_list *screen_list);
  302. void update_windows_props_cube(struct screen_list *screen_list);
  303. void wm_refresh(struct screen_list *screen_list);
  304. void wm_refresh_card(struct screen_list *screen_list);
  305. void wm_refresh_cube(struct screen_list *screen_list);
  306. void wm_refresh_full(struct screen_list *screen_list);
  307. void wm_refresh_hsplit(struct screen_list *screen_list);
  308. void wm_refresh_vsplit(struct screen_list *screen_list);
  309. int switch_screen_recurrent(struct screen_list* screen_list, struct recurrent* rec, void *user, long long unsigned int t);
  310. /* Effects and addons */
  311. void draw_thumbnails(struct screen_list *screen_list);
  312. void draw_status(struct screen_list *screen_list);
  313. void draw_help(struct screen_list *screen_list);
  314. int help_handle_key(struct screen_list *screen_list, unsigned int c);
  315. int update_window_list(int c, struct screen_list *screen_list);
  316. void draw_list(struct screen_list *screen_list);
  317. void draw_lock(struct screen_list *screen_list);
  318. int update_lock(int c, struct screen_list *screen_list);
  319. int validate_lock(struct screen_list *screen_list, char *user, char *pass);
  320. int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t);
  321. /* Input to ANSI */
  322. void *convert_input_ansi(unsigned int *c, int *size);
  323. int handle_command_input(struct screen_list*screen_list, unsigned int c);
  324. /* Screensavers */
  325. void screensaver_init(struct screen_list *screen_list);
  326. void screensaver_kill(struct screen_list *screen_list);
  327. void draw_screensaver(struct screen_list *screen_list);
  328. void screensaver_flying_toasters(struct screen_list *screen_list);
  329. void screensaver_flying_toasters_init(struct screen_list *screen_list);
  330. void screensaver_flying_toasters_kill(struct screen_list *screen_list);
  331. /* Actions */
  332. void dump_to_file(struct screen_list *screen_list);
  333. /* Recurrents */
  334. int handle_recurrents(struct screen_list* screen_list);
  335. int add_recurrent(struct recurrent_list *list,
  336. int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t),
  337. void *user);
  338. int remove_recurrent(struct recurrent_list *list, int n);
  339. /* Configuration file */
  340. int read_configuration_file(char *filename, struct screen_list *screen_list);
  341. int parse_conf_line(char *buf, int size, struct screen_list *screen_list);
  342. int get_key_value(char *line, struct option *option);
  343. int fill_config(struct screen_list *screen_list);
  344. struct config_line *get_config(const char *name);
  345. struct config_line *get_config_option(void);
  346. /* Python interpreter */
  347. #ifdef USE_PYTHON
  348. int python_init(struct screen_list *sl);
  349. int python_close(struct screen_list *sl);
  350. int python_command_handle_key(struct screen_list *screen_list, unsigned int c);
  351. void draw_python_command(struct screen_list *screen_list);
  352. #endif
  353. #if defined DEBUG
  354. # include <stdio.h>
  355. # include <stdarg.h>
  356. static inline void debug(const char *format, ...)
  357. {
  358. va_list args;
  359. va_start(args, format);
  360. fprintf(stderr, "** neercs debug ** ");
  361. vfprintf(stderr, format, args);
  362. fprintf(stderr, "\n");
  363. va_end(args);
  364. }
  365. #else
  366. # define debug(format, ...) do {} while(0)
  367. #endif