root/misc.c

Revision 1, 2.5 KB (checked in by root, 3 years ago)

Initial commit

Line 
1/* evilwm - Minimalist Window Manager for X
2 * Copyright (C) 1999-2006 Ciaran Anscomb <evilwm@6809.org.uk>
3 * see README for license and other details. */
4
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"
13
14int need_client_tidy = 0;
15int ignore_xerror = 0;
16
17/* Now do this by fork()ing twice so we don't have to worry about SIGCHLDs */
18void spawn(const char *const cmd[]) {
19        ScreenInfo *current_screen = find_current_screen();
20        pid_t pid;
21
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);
34                }
35        }
36        if (pid > 0)
37                wait(NULL);
38}
39
40void handle_signal(int signo) {
41        int i;
42        (void)signo;  /* unused */
43        /* SIGCHLD check no longer necessary */
44        /* Quit Nicely */
45        while(head_client) remove_client(head_client);
46        XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
47        if (font) XFreeFont(dpy, font);
48        for (i = 0; i < num_screens; i++) {
49                XFreeGC(dpy, screens[i].invert_gc);
50                XInstallColormap(dpy, DefaultColormap(dpy, i));
51        }
52        free(screens);
53        XCloseDisplay(dpy);
54        exit(0);
55}
56
57int handle_xerror(Display *dsply, XErrorEvent *e) {
58        Client *c;
59        (void)dsply;  /* unused */
60
61        if (ignore_xerror) {
62                LOG_DEBUG("handle_xerror() ignored an XErrorEvent: %d\n", e->error_code);
63                return 0;
64        }
65        /* If this error actually occurred while setting up the new
66         * window, best let make_new_client() know not to bother */
67        if (initialising != None && e->resourceid == initialising) {
68                LOG_DEBUG("\t **SAVED?** handle_xerror() caught error %d while initialising\n", e->error_code);
69                initialising = None;
70                return 0;
71        }
72        LOG_DEBUG("**ERK** handle_xerror() caught an XErrorEvent: error_code=%d request_code=%d minor_code=%d\n",
73                        e->error_code, e->request_code, e->minor_code);
74        if (e->error_code == BadAccess && e->request_code == X_ChangeWindowAttributes) {
75                LOG_ERROR("root window unavailable (maybe another wm is running?)\n");
76                exit(1);
77        }
78
79        c = find_client(e->resourceid);
80        if (c) {
81                LOG_DEBUG("\thandle_xerror() : flagging client for removal\n");
82                c->remove = 1;
83                need_client_tidy = 1;
84        }
85        return 0;
86}
Note: See TracBrowser for help on using the browser.