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-2021 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 #include "xtypes.h" 35 36 #include <stdio.h> 37 #include <stdlib.h> 38 #include <stdarg.h> 39 #include <string.h> 40 #include <sys/types.h> 41 #include <unistd.h> 42 43 #define FILEPATH_LEN_MAX 4096 44 45 #ifndef MAX 46 #define MAX(a,b) ((a)>(b)?(a):(b)) 47 #endif 48 #ifndef MIN 49 #define MIN(a,b) ((a)<(b)?(a):(b)) 50 #endif 51 52 #define IN_RANGE(a, b, range) \ 53 ((((a) > (b)) && ((a) - (b) <= (range))) || \ 54 (((a) <= (b)) && ((b) - (a) <= (range)))) 55 56 #define IN_ABOVE(a, b, range) \ 57 (((a) >= (b)) && ((a) - (b) <= (range))) 58 59 #define IN_BELOW(a, b, range) \ 60 (((a) <= (b)) && ((b) - (a) <= (range))) 61 62 #define SPANS_COMMON(x1, w1, x2, w2) \ 63 (!((((x2) + (w2)) <= (x1)) || ((x2) >= ((x1) + (w1))))) 64 65 #define STATE_NORMAL 0 66 #define STATE_HILITED 1 67 #define STATE_CLICKED 2 68 #define STATE_DISABLED 3 69 70 #define FLAG_BUTTON 0 71 #define FLAG_TITLE 1 72 #define FLAG_MINIICON 2 73 #define FLAG_FIXED 4 74 #define FLAG_FIXED_HORIZ 8 75 #define FLAG_FIXED_VERT 16 76 77 #define MODE_FOCUS_POINTER 0 78 #define MODE_FOCUS_SLOPPY 1 79 #define MODE_FOCUS_CLICK 2 80 81 #define EDGE_FLIP_OFF 0 82 #define EDGE_FLIP_ON 1 83 #define EDGE_FLIP_MOVE 2 84 85 #define DOCK_LEFT 0 86 #define DOCK_RIGHT 1 87 #define DOCK_UP 2 88 #define DOCK_DOWN 3 89 90 #define ICON_LEFT 0 91 #define ICON_RIGHT 1 92 #define ICON_UP 2 93 #define ICON_DOWN 3 94 95 #define MODE_NONE 0 96 #define MODE_MOVE_PENDING 1 97 #define MODE_MOVE 2 98 #define MODE_RESIZE 3 99 #define MODE_RESIZE_H 4 100 #define MODE_RESIZE_V 5 101 #define MODE_DESKDRAG 6 102 #define MODE_BUTTONDRAG 7 103 #define MODE_DESKRAY 8 104 #define MODE_PAGER_DRAG_PENDING 9 105 #define MODE_PAGER_DRAG 10 106 107 #define EVENT_MOUSE_DOWN 0 108 #define EVENT_MOUSE_UP 1 109 #define EVENT_MOUSE_ENTER 2 110 #define EVENT_MOUSE_LEAVE 3 111 #define EVENT_KEY_DOWN 4 112 #define EVENT_KEY_UP 5 113 #define EVENT_DOUBLE_DOWN 6 114 #define EVENT_FOCUS_IN 7 115 #define EVENT_FOCUS_OUT 8 116 117 /* Server extensions */ 118 #define XEXT_SHAPE 0 119 #define XEXT_XINERAMA 1 120 #define XEXT_SYNC 2 121 #define XEXT_SCRSAVER 3 122 #define XEXT_RANDR 4 123 #define XEXT_COMPOSITE 5 124 #define XEXT_DAMAGE 6 125 #define XEXT_FIXES 7 126 #define XEXT_RENDER 8 127 #define XEXT_GLX 9 128 #define XEXT_XI 10 129 #define XEXT_PRESENT 11 130 131 #define XEXT_CM_ALL 16 132 133 #define XEXT_AVAILABLE(ext) (Mode.server.extensions & (1 << ext)) 134 135 int ExtVersion(int ext_ix); 136 137 /* 138 * Types 139 */ 140 #include "etypes.h" 141 142 /* Configuration parameters */ 143 typedef struct { 144 struct { 145 unsigned int step; /* Animation time step, ms */ 146 } animation; 147 struct { 148 char enable; 149 int delay; /* milliseconds */ 150 } autoraise; 151 struct { 152 char hiquality; 153 char user; 154 char no_scan; 155 int timeout; 156 } backgrounds; 157 struct { 158 int move_resistance; 159 } buttons; 160 struct { 161 unsigned int num; 162 int dragdir; 163 int dragbar_width; 164 int dragbar_length; 165 int dragbar_ordering; 166 char desks_wraparound; 167 char slidein; 168 int slidespeed; 169 int areas_nx; 170 int areas_ny; 171 char areas_wraparound; 172 int edge_flip_mode; 173 int edge_flip_resistance; 174 } desks; 175 struct { 176 char headers; 177 char button_image; 178 } dialogs; 179 struct { 180 char enable; /* wmdockapp only */ 181 char sticky; /* Make dockapps sticky by default */ 182 int dirmode; 183 int startx; 184 int starty; 185 } dock; 186 struct { 187 int mode; 188 int clickraises; 189 char transientsfollowleader; 190 char switchfortransientmap; 191 char all_new_windows_get_focus; 192 char new_windows_get_focus_if_group_focused; 193 char new_transients_get_focus; 194 char new_transients_get_focus_if_group_focused; 195 char raise_on_next; 196 char warp_on_next; 197 char warp_always; 198 } focus; 199 struct { 200 char set_xroot_info_on_root_window; 201 } hints; 202 struct { 203 char dest; 204 char difftime; 205 } log; 206 struct { 207 int zoom_res; 208 } magwin; 209 struct { 210 char animate; 211 char onscreen; 212 char warp; 213 char show_icons; 214 int icon_size; 215 struct { 216 EX_KeySym left, right, up, down, escape, ret; 217 } key; 218 } menus; 219 struct { 220 int mode_move; 221 int mode_resize; 222 int mode_info; 223 int mode_maximize_default; 224 unsigned int color; 225 char avoid_server_grab; 226 char update_while_moving; 227 char enable_sync_request; 228 char dragbar_nocover; 229 char enable_smart_max_hv; 230 char maximize_animate; 231 int maximize_speed; 232 } movres; 233 struct { 234 int movres; 235 int menus; 236 int tooltips; 237 int focused; 238 int unfocused; 239 } opacity; 240 struct { 241 char manual; 242 char manual_mouse_pointer; 243 char center_if_desk_full; 244 char ignore_struts; 245 char ignore_struts_fullscreen; 246 char ignore_struts_maximize; 247 char raise_fullscreen; 248 char slidein; 249 char cleanupslide; 250 int slidemode; 251 int slidespeedmap; 252 int slidespeedcleanup; 253 #ifdef USE_XINERAMA_no /* Not implemented */ 254 char extra_head; /* Not used */ 255 #endif 256 } place; 257 struct { 258 char enable_script; 259 char *script; 260 char enable_logout_dialog; 261 char enable_reboot_halt; 262 char *cmd_reboot; 263 char *cmd_halt; 264 } session; 265 struct { 266 char animate; 267 int speed; 268 } shading; 269 struct { 270 char enable; 271 int edge_snap_dist; 272 int screen_snap_dist; 273 } snap; 274 struct { 275 char firsttime; 276 char animate; 277 } startup; 278 struct { 279 char use_theme_font_cfg; 280 char use_alt_font_cfg; 281 char *name; 282 char *extra_path; 283 char *font_cfg; 284 } theme; 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 char show_shape; 295 int icon_mode; 296 } warplist; 297 298 struct { 299 char argb_internal_objects; 300 char argb_internal_clients; 301 char argb_clients; 302 char argb_clients_inherit_attr; 303 int image_cache_size; 304 int ximage_cache_count; 305 int mask_alpha_threshold; 306 char enable_startup_id; 307 char use_render_for_scaling; 308 char bindings_reload; 309 unsigned int no_sync_mask; 310 } testing; 311 312 char autosave; 313 char memory_paranoia; 314 char save_under; 315 } EConf; 316 317 typedef struct { 318 struct { 319 unsigned int startup_id; 320 } apps; 321 struct { 322 char force_scan; 323 unsigned int mini_w, mini_h; 324 } backgrounds; 325 struct { 326 char *name; 327 char *prefix; 328 char *dir; 329 char *cache_dir; 330 } conf; 331 struct { 332 char dummy; /* Prevent empty struct */ 333 #if USE_XSYNC 334 EX_ID server_time; 335 #endif 336 } display; 337 struct { 338 unsigned int seqn; /* Event run sequence number */ 339 unsigned int time_ms; /* Local ms time */ 340 EX_Time time; /* Latest X event time */ 341 int cx, cy; /* Any detected pointer movement */ 342 int mx, my; /* Motion event */ 343 int px, py; /* Previous motion event */ 344 EX_Time last_btime; 345 EX_Window last_bpress; 346 EX_Window last_bpress2; 347 unsigned int last_button; 348 unsigned int last_keycode; 349 unsigned int last_keystate; 350 char block; 351 char double_click; 352 char on_screen; 353 #if USE_COMPOSITE 354 unsigned int damage_count; 355 #endif 356 #if USE_XI2 357 unsigned char xi2_ptr; 358 unsigned char xi2_kbd; 359 #endif 360 } events; 361 struct { 362 char pointer_grab_active; 363 EX_Window pointer_grab_window; 364 } grabs; 365 struct { 366 const char *lang; 367 char utf8_int; /* Use UTF-8 internally */ 368 char utf8_loc; /* Locale is UTF-8 */ 369 } locale; 370 struct { 371 unsigned int mod_key_mask; 372 unsigned int mod_combos[8]; 373 } masks; 374 struct { 375 char swap; 376 } move; 377 struct { 378 signed char enable_features; 379 char doing_manual; 380 } place; 381 struct { 382 int w_old; 383 int h_old; 384 short fps; 385 #ifdef USE_XRANDR 386 unsigned short rotation; 387 #endif 388 } screen; 389 struct { 390 unsigned int extensions; 391 } server; 392 struct { 393 EX_Pixmap ext_pmap; 394 char ext_pmap_valid; 395 } root; 396 struct { 397 char *paths; 398 char *path; 399 char *variant; 400 } theme; 401 struct { 402 char *exec_name; /* argv[0] */ 403 char master; /* We are the master E */ 404 char single; /* No slaves */ 405 char window; /* Running in virtual root window */ 406 pid_t pid; 407 int master_screen; 408 char session_start; 409 char startup; 410 char restart; 411 char exiting; 412 char in_signal_handler; 413 char exit_now; 414 char save_ok; 415 char coredump; 416 int win_x, win_y, win_w, win_h; 417 int exit_mode; 418 char *exit_param; 419 int child_count; 420 pid_t *children; 421 char *machine_name; 422 } wm; 423 int mode; 424 int op_source; 425 EWin *focuswin; 426 EWin *mouse_over_ewin; 427 EWin *context_ewin; 428 EX_Colormap current_cmap; 429 Win context_win; 430 char constrained; 431 char nogroup; 432 char showing_desktop; 433 EX_Window button_proxy_win; 434 char firsttime; 435 char debug_exit; 436 } EMode; 437 438 /* 439 * Function prototypes 440 */ 441 442 /* about.c */ 443 void About(void); 444 445 /* config.c */ 446 #define FILE_TYPE_CONFIG 0 447 #define FILE_TYPE_BACKGROUND 1 448 #define FILE_TYPE_IMAGE 1 449 #define FILE_TYPE_CURSOR 1 450 #define FILE_TYPE_SOUND 1 451 #define FILE_TYPE_MENU 2 452 #define FILE_TYPE_ICON 3 453 void SkipTillEnd(FILE * ConfigFile); 454 char *GetLine(char *s, int size, FILE * f); 455 int ConfigParseline1(char *str, char *s2, char **p2, char **p3); 456 void ConfigParseError(const char *where, const char *line); 457 void ConfigAlertLoad(const char *txt); 458 char *FindFile(const char *file, const char *themepath, int type); 459 char *ThemeFileFind(const char *file, int type); 460 int ConfigFileLoad(const char *name, const char *themepath, 461 int (*parse)(FILE * fs), int preparse); 462 int ConfigFileRead(FILE * fs); 463 int ThemeConfigLoad(void); 464 465 /* dialog.c */ 466 #if ENABLE_DIALOGS 467 void __PRINTF_2__ DialogOK(const char *title, const char *fmt, ...); 468 void DialogOKstr(const char *title, const char *txt); 469 #else 470 #define DialogOK(title, fmt, ...) do {} while(0) 471 #define DialogOKstr(title, fmt) do {} while(0) 472 #endif /* ENABLE_DIALOGS */ 473 474 /* draw.c (move to moveresize.h?) */ 475 /* Move/resize modes */ 476 #define MR_OPAQUE 0 477 #define MR_TECHNICAL 1 478 #define MR_BOX 2 479 #if 0 /* Obsolete */ 480 #define MR_SHADED 3 481 #define MR_SEMI_SOLID 4 482 #define MR_TRANSLUCENT 5 483 #endif 484 #define MR_TECH_OPAQUE 6 485 486 int MoveResizeModeValidateMove(int md); 487 int MoveResizeModeValidateResize(int md); 488 489 /* econfig.c */ 490 void ConfigurationLoad(void); 491 void ConfigurationSave(void); 492 void ConfigurationSet(const char *params); 493 void ConfigurationShow(const char *params); 494 495 /* edge.c */ 496 void EdgeCheckMotion(int x, int y); 497 void EdgeWindowsShow(void); 498 void EdgeWindowsHide(void); 499 500 /* extinitwin.c */ 501 EX_Window ExtInitWinCreate(void); 502 void ExtInitWinSet(EX_Window win); 503 EX_Window ExtInitWinGet(void); 504 void ExtInitWinKill(void); 505 506 /* fonts.c */ 507 void FontConfigLoad(void); 508 void FontConfigUnload(void); 509 const char *FontLookup(const char *name); 510 511 /* handlers.c */ 512 void SignalsSetup(void); 513 void SignalsRestore(void); 514 515 /* main.c */ 516 __NORETURN__ void EExit(int exitcode); 517 518 #define EDirRoot() ENLIGHTENMENT_ROOT 519 #define EDirBin() ENLIGHTENMENT_BIN 520 #define EDirLib() ENLIGHTENMENT_LIB 521 #define EDirUserConf() Mode.conf.dir 522 #define EDirUserCache() Mode.conf.cache_dir 523 #define EGetSavePrefix() Mode.conf.prefix 524 525 void Etmp(char *s); 526 527 /* mod-misc.c */ 528 void autosave(void); 529 530 /* regex.c */ 531 int matchregexp(const char *rx, const char *s); 532 533 /* setup.c */ 534 void SetupX(const char *dstr); 535 536 /* slideouts.c */ 537 int SlideoutsConfigLoad(FILE * fs); 538 539 /* startup.c */ 540 void StartupWindowsCreate(void); 541 void StartupWindowsOpen(void); 542 void StartupBackgroundsDestroy(void); 543 544 /* theme.c */ 545 char *ThemePathFind(const char *theme); 546 char *ThemePathName(const char *path); 547 void ThemeFind(const char *theme); 548 char **ThemesList(int *num); 549 550 /* 551 * Global vars 552 */ 553 extern const char e_wm_name[]; 554 extern const char e_wm_version[]; 555 extern EConf Conf; 556 extern EMode Mode; 557