chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / E.h
1 /*****************************************************************************/
2 /* Enlightenment - The Window Manager that dares to do what others don't     */
3 /*****************************************************************************/
4 /*
5  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
6  * Copyright (C) 2004-2009 Kim Woelders
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to
10  * deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12  * sell copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies of the Software, its documentation and marketing & publicity
17  * materials, and acknowledgment shall be given in the documentation, materials
18  * and software packages that this Software was used.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #include "config.h"
28
29 #include "alert.h"
30 #include "edebug.h"
31 #include "lang.h"
32 #include "sounds.h"
33 #include "util.h"
34
35 #include <X11/X.h>
36
37 #include "xtypes.h"
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <stdarg.h>
42 #include <string.h>
43 #include <sys/types.h>
44 #include <unistd.h>
45
46 #define FILEPATH_LEN_MAX 4096
47
48 #ifndef MAX
49 #define MAX(a,b)  ((a)>(b)?(a):(b))
50 #endif
51 #ifndef MIN
52 #define MIN(a,b)  ((a)<(b)?(a):(b))
53 #endif
54
55 #define IN_RANGE(a, b, range) \
56    ((((a) >  (b)) && ((a) - (b) <= (range))) || \
57    (((a) <= (b)) && ((b) - (a) <= (range))))
58
59 #define IN_ABOVE(a, b, range) \
60    (((a) >=  (b)) && ((a) - (b) <= (range)))
61
62 #define IN_BELOW(a, b, range) \
63    (((a) <= (b)) && ((b) - (a) <= (range)))
64
65 #define SPANS_COMMON(x1, w1, x2, w2) \
66    (!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1)))))
67
68 #define STATE_NORMAL            0
69 #define STATE_HILITED           1
70 #define STATE_CLICKED           2
71 #define STATE_DISABLED          3
72
73 #define FLAG_BUTTON             0
74 #define FLAG_TITLE              1
75 #define FLAG_MINIICON           2
76 #define FLAG_FIXED              4
77 #define FLAG_FIXED_HORIZ        8
78 #define FLAG_FIXED_VERT         16
79
80 #define MODE_FOCUS_POINTER      0
81 #define MODE_FOCUS_SLOPPY       1
82 #define MODE_FOCUS_CLICK        2
83
84 #define EDGE_FLIP_OFF           0
85 #define EDGE_FLIP_ON            1
86 #define EDGE_FLIP_MOVE          2
87
88 #define DOCK_LEFT               0
89 #define DOCK_RIGHT              1
90 #define DOCK_UP                 2
91 #define DOCK_DOWN               3
92
93 #define ICON_LEFT               0
94 #define ICON_RIGHT              1
95 #define ICON_UP                 2
96 #define ICON_DOWN               3
97
98 #define MODE_NONE                 0
99 #define MODE_MOVE_PENDING         1
100 #define MODE_MOVE                 2
101 #define MODE_RESIZE               3
102 #define MODE_RESIZE_H             4
103 #define MODE_RESIZE_V             5
104 #define MODE_DESKDRAG             6
105 #define MODE_BUTTONDRAG           7
106 #define MODE_DESKRAY              8
107 #define MODE_PAGER_DRAG_PENDING   9
108 #define MODE_PAGER_DRAG          10
109
110 #define EVENT_MOUSE_DOWN  0
111 #define EVENT_MOUSE_UP    1
112 #define EVENT_MOUSE_ENTER 2
113 #define EVENT_MOUSE_LEAVE 3
114 #define EVENT_KEY_DOWN    4
115 #define EVENT_KEY_UP      5
116 #define EVENT_DOUBLE_DOWN 6
117 #define EVENT_FOCUS_IN    7
118 #define EVENT_FOCUS_OUT   8
119
120 /* Server extensions */
121 #define XEXT_SHAPE       0
122 #define XEXT_SYNC        1
123 #define XEXT_SCRSAVER    2
124 #define XEXT_RANDR       3
125 #define XEXT_COMPOSITE   4
126 #define XEXT_DAMAGE      5
127 #define XEXT_FIXES       6
128 #define XEXT_RENDER      7
129 #define XEXT_GLX         8
130
131 #define XEXT_CM_ALL     16
132
133 #define XEXT_AVAILABLE(ext)  (Mode.server.extensions & (1 << ext))
134
135 /*
136  * Types
137  */
138 #include "etypes.h"
139
140 /* Configuration parameters */
141 typedef struct {
142    struct {
143       unsigned int        step; /* Animation time step, ms */
144    } animation;
145    struct {
146       char                enable;
147       int                 delay;        /* milliseconds */
148    } autoraise;
149    struct {
150       char                hiquality;
151       char                user;
152       char                no_scan;
153       int                 timeout;
154    } backgrounds;
155    struct {
156       int                 move_resistance;
157    } buttons;
158    struct {
159       unsigned int        num;
160       int                 dragdir;
161       int                 dragbar_width;
162       int                 dragbar_length;
163       int                 dragbar_ordering;
164       char                desks_wraparound;
165       char                slidein;
166       int                 slidespeed;
167       int                 areas_nx;
168       int                 areas_ny;
169       char                areas_wraparound;
170       int                 edge_flip_mode;
171       int                 edge_flip_resistance;
172    } desks;
173    struct {
174       char                headers;
175       char                button_image;
176    } dialogs;
177    struct {
178       char                enable;       /* wmdockapp only */
179       char                sticky;       /* Make dockapps sticky by default */
180       int                 dirmode;
181       int                 startx;
182       int                 starty;
183    } dock;
184    struct {
185       int                 mode;
186       char                clickraises;
187       char                transientsfollowleader;
188       char                switchfortransientmap;
189       char                all_new_windows_get_focus;
190       char                new_transients_get_focus;
191       char                new_transients_get_focus_if_group_focused;
192       char                raise_on_next;
193       char                warp_on_next;
194       char                warp_always;
195    } focus;
196    struct {
197       char                set_xroot_info_on_root_window;
198    } hints;
199    struct {
200       char                animate;
201       char                onscreen;
202       char                warp;
203       char                show_icons;
204       int                 icon_size;
205       struct {
206          KeySym              left, right, up, down, escape, ret;
207       } key;
208    } menus;
209    struct {
210       int                 mode_move;
211       int                 mode_resize;
212       int                 mode_info;
213       int                 mode_maximize_default;
214       unsigned int        color;
215       char                avoid_server_grab;
216       char                update_while_moving;
217       char                enable_sync_request;
218       char                dragbar_nocover;
219    } movres;
220    struct {
221       int                 movres;
222       int                 menus;
223       int                 tooltips;
224       int                 focused;
225       int                 unfocused;
226    } opacity;
227    struct {
228       char                manual;
229       char                manual_mouse_pointer;
230       char                center_if_desk_full;
231       char                ignore_struts;
232       char                raise_fullscreen;
233       char                slidein;
234       char                cleanupslide;
235       int                 slidemode;
236       int                 slidespeedmap;
237       int                 slidespeedcleanup;
238 #ifdef USE_XINERAMA_no          /* Not implemented */
239       char                extra_head;   /* Not used */
240 #endif
241    } place;
242    struct {
243       char                enable_script;
244       char               *script;
245       char                enable_logout_dialog;
246       char                enable_reboot_halt;
247       char               *cmd_reboot;
248       char               *cmd_halt;
249    } session;
250    struct {
251       char                animate;
252       int                 speed;
253    } shading;
254    struct {
255       char                enable;
256       int                 edge_snap_dist;
257       int                 screen_snap_dist;
258    } snap;
259    struct {
260       char                firsttime;
261       char                animate;
262    } startup;
263    struct {
264       char                use_theme_font_cfg;
265       char                use_alt_font_cfg;
266       char               *name;
267       char               *extra_path;
268       char               *font_cfg;
269    } theme;
270 #ifdef ENABLE_THEME_TRANSPARENCY
271    struct {
272       int                 alpha;
273       int                 border;
274       int                 widget;
275       int                 iconbox;
276       int                 menu;
277       int                 menu_item;
278       int                 tooltip;
279       int                 dialog;
280       int                 hilight;
281       int                 pager;
282       int                 warplist;
283    } trans;
284 #endif
285    struct {
286       char                enable;
287       char                showsticky;
288       char                showshaded;
289       char                showiconified;
290       char                showalldesks;
291       char                warpfocused;
292       char                raise_on_select;
293       char                warp_on_select;
294       int                 icon_mode;
295    } warplist;
296
297    struct {
298       char                argb_internal_objects;
299       char                argb_internal_clients;
300       char                argb_clients;
301       char                argb_clients_inherit_attr;
302       int                 image_cache_size;
303       int                 mask_alpha_threshold;
304       char                enable_startup_id;
305       char                use_render_for_scaling;
306       char                bindings_reload;
307       unsigned int        no_sync_mask;
308    } testing;
309
310    char                autosave;
311    char                memory_paranoia;
312    char                save_under;
313    char                difftime;
314 } EConf;
315
316 typedef struct {
317    struct {
318       unsigned int        startup_id;
319    } apps;
320    struct {
321       char                force_scan;
322    } backgrounds;
323    struct {
324       char               *name;
325       char               *dir;
326       char               *cache_dir;
327    } conf;
328    struct {
329       char                dummy;        /* Prevent empty struct */
330 #ifdef USE_XINERAMA
331       char                xinerama_active;
332 #endif
333 #if USE_XSYNC
334       XID                 server_time;
335 #endif
336    } display;
337    struct {
338       Time                time;
339       int                 cx, cy;       /* Any detected pointer movement */
340       int                 mx, my;       /* Motion event */
341       int                 px, py;       /* Previous motion event */
342       Time                last_btime;
343       Window              last_bpress;
344       Window              last_bpress2;
345       unsigned int        last_button;
346       unsigned int        last_keycode;
347       unsigned int        last_keystate;
348       char                double_click;
349       char                on_screen;
350 #if USE_COMPOSITE
351       unsigned int        damage_count;
352 #endif
353    } events;
354    struct {
355       char                pointer_grab_active;
356       Window              pointer_grab_window;
357    } grabs;
358    struct {
359       const char         *lang;
360       char                utf8_int;     /* Use UTF-8 internally */
361       char                utf8_loc;     /* Locale is UTF-8 */
362    } locale;
363    struct {
364       unsigned int        mod_key_mask;
365       unsigned int        mod_combos[8];
366    } masks;
367    struct {
368       char                check;        /* Avoid losing windows offscreen */
369       char                swap;
370       int                 swapcoord_x, swapcoord_y;
371    } move;
372    struct {
373       signed char         enable_features;
374       char                doing_manual;
375       char                doing_slide;
376    } place;
377    struct {
378       int                 w_old;
379       int                 h_old;
380    } screen;
381    struct {
382       unsigned int        extensions;
383    } server;
384    struct {
385       Pixmap              ext_pmap;
386       char                ext_pmap_valid;
387    } root;
388    struct {
389       char               *paths;
390       char               *path;
391    } theme;
392    struct {
393       char               *exec_name;    /* argv[0] */
394       char                master;       /* We are the master E */
395       char                single;       /* No slaves */
396       char                window;       /* Running in virtual root window */
397       pid_t               pid;
398       int                 master_screen;
399       char                session_start;
400       char                startup;
401       char                restart;
402       char                exiting;
403       char                in_signal_handler;
404       char                exit_now;
405       char                save_ok;
406       char                coredump;
407       int                 win_w, win_h;
408       int                 exit_mode;
409       char               *exit_param;
410       int                 child_count;
411       pid_t              *children;
412       char               *machine_name;
413    } wm;
414    int                 mode;
415    int                 op_source;
416    char                action_inhibit;
417    EWin               *focuswin;
418    EWin               *mouse_over_ewin;
419    EWin               *context_ewin;
420    Colormap            current_cmap;
421    Win                 context_win;
422    char                constrained;
423    char                nogroup;
424    char                keybinds_changed;
425    char                showing_desktop;
426    Window              button_proxy_win;
427    char                firsttime;
428    char                debug_exit;
429 } EMode;
430
431 /*
432  * Function prototypes
433  */
434
435 /* about.c */
436 void                About(void);
437
438 /* actions.c */
439 #define EXEC_SET_LANG       0x01
440 #define EXEC_SET_STARTUP_ID 0x02
441 int                 execApplication(const char *params, int flags);
442 void                Espawn(int argc, char **argv);
443 void                EspawnCmd(const char *cmd);
444
445 /* config.c */
446 void                SkipTillEnd(FILE * ConfigFile);
447 char               *GetLine(char *s, int size, FILE * f);
448 int                 ConfigParseline1(char *str, char *s2, char **p2, char **p3);
449 void                ConfigParseError(const char *where, const char *line);
450 void                ConfigAlertLoad(const char *txt);
451 char               *FindFile(const char *file, const char *themepath);
452 char               *ThemeFileFind(const char *file);
453 char               *ConfigFileFind(const char *name, const char *themepath,
454                                    int pp);
455 int                 ConfigFileLoad(const char *name, const char *themepath,
456                                    int (*parse) (FILE * fs), int preparse);
457 int                 ConfigFileRead(FILE * fs);
458 int                 ThemeConfigLoad(void);
459
460 /* dialog.c */
461 #if ENABLE_DIALOGS
462 void __PRINTF_2__   DialogOK(const char *title, const char *fmt, ...);
463 void                DialogOKstr(const char *title, const char *txt);
464 #else
465 #define DialogOK(title, fmt, ...) do {} while(0)
466 #define DialogOKstr(title, fmt) do {} while(0)
467 #endif /* ENABLE_DIALOGS */
468
469 /* econfig.c */
470 void                ConfigurationLoad(void);
471 void                ConfigurationSave(void);
472 void                ConfigurationSet(const char *params);
473 void                ConfigurationShow(const char *params);
474
475 /* edge.c */
476 void                EdgeCheckMotion(int x, int y);
477 void                EdgeWindowsShow(void);
478 void                EdgeWindowsHide(void);
479
480 /* extinitwin.c */
481 Window              ExtInitWinCreate(void);
482 void                ExtInitWinSet(Window win);
483 Window              ExtInitWinGet(void);
484 void                ExtInitWinKill(void);
485
486 /* fonts.c */
487 void                FontConfigLoad(void);
488 void                FontConfigUnload(void);
489 const char         *FontLookup(const char *name);
490
491 /* handlers.c */
492 void                SignalsSetup(void);
493 void                SignalsRestore(void);
494
495 /* main.c */
496 __NORETURN__ void   EExit(int exitcode);
497 __EXPORT__ const char *EDirRoot(void);
498 const char         *EDirBin(void);
499 const char         *EDirUser(void);
500 const char         *EDirUserCache(void);
501 void                EDirMake(const char *base, const char *name);
502 const char         *EGetSavePrefix(void);
503 void                Etmp(char *s);
504
505 /* misc.c */
506 void                Quicksort(void **a, int l, int r,
507                               int (*CompareFunc) (void *d1, void *d2));
508 void                ETimedLoopInit(int k1, int k2, int speed);
509 int                 ETimedLoopNext(void);
510
511 /* mod-misc.c */
512 void                autosave(void);
513
514 /* regex.c */
515 int                 matchregexp(const char *rx, const char *s);
516
517 /* setup.c */
518 void                SetupX(const char *dstr);
519
520 /* slideouts.c */
521 int                 SlideoutsConfigLoad(FILE * fs);
522
523 /* startup.c */
524 void                StartupWindowsCreate(void);
525 void                StartupWindowsOpen(void);
526 void                StartupBackgroundsDestroy(void);
527
528 /* theme.c */
529 char               *ThemeFind(const char *theme);
530 char               *ThemePathName(const char *path);
531 void                ThemePathFind(void);
532 char              **ThemesList(int *num);
533
534 /*
535  * Global vars
536  */
537 extern const char   e_wm_name[];
538 extern const char   e_wm_version[];
539 __EXPORT__ extern EConf Conf;
540 __EXPORT__ extern EMode Mode;