git: initial import (.gitignore)
[evilwm.git] / misc.c
blob3da8d72f98ae7ad5ff9f7384280e4edef7eb140c
1 /* evilwm - Minimalist Window Manager for X
2 * Copyright (C) 1999-2009 Ciaran Anscomb <evilwm@6809.org.uk>
3 * see README for license and other details. */
5 #include <X11/Xproto.h>
6 #include <stdlib.h>
7 #include <stdarg.h>
8 #include <signal.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
11 #include "evilwm.h"
12 #include "log.h"
14 int need_client_tidy = 0;
15 int ignore_xerror = 0;
17 /* Now do this by fork()ing twice so we don't have to worry about SIGCHLDs */
18 void spawn(const char *const cmd[]) {
19 ScreenInfo *current_screen = find_current_screen();
20 pid_t pid;
22 if (current_screen && current_screen->display)
23 putenv(current_screen->display);
24 if (!(pid = fork())) {
25 setsid();
26 switch (fork()) {
27 /* Expect compiler warnings because of half-broken SUS
28 * execvp prototype: "char *const argv[]" should have
29 * been "const char *const argv[]", but the committee
30 * favored legacy code over modern code, and modern
31 * compilers bark at our extra const. (LD) */
32 case 0: execvp(cmd[0], cmd+1);
33 default: _exit(0);
36 if (pid > 0)
37 wait(NULL);
40 void handle_signal(int signo) {
41 (void)signo; /* unused */
42 wm_exit = 1;
45 int handle_xerror(Display *dsply, XErrorEvent *e) {
46 Client *c;
47 (void)dsply; /* unused */
49 LOG_ENTER("handle_xerror(error=%d, request=%d/%d, resourceid=%lx)", e->error_code, e->request_code, e->minor_code, e->resourceid);
51 if (ignore_xerror) {
52 LOG_DEBUG("ignoring...\n");
53 LOG_LEAVE();
54 return 0;
56 /* If this error actually occurred while setting up the new
57 * window, best let make_new_client() know not to bother */
58 if (initialising != None && e->resourceid == initialising) {
59 LOG_DEBUG("error caught while initialising window=%lx\n", initialising);
60 initialising = None;
61 LOG_LEAVE();
62 return 0;
64 if (e->error_code == BadAccess && e->request_code == X_ChangeWindowAttributes) {
65 LOG_ERROR("root window unavailable (maybe another wm is running?)\n");
66 exit(1);
69 c = find_client(e->resourceid);
70 if (c) {
71 LOG_DEBUG("flagging client for removal\n");
72 c->remove = 1;
73 need_client_tidy = 1;
74 } else {
75 LOG_DEBUG("unknown error: not handling\n");
77 LOG_LEAVE();
78 return 0;