2014-10-22 11:53:03 +02:00
|
|
|
/* Copyright (c) 2012, Bastien Dejean
|
2013-10-08 21:05:56 +02:00
|
|
|
* All rights reserved.
|
2014-01-19 14:41:37 +01:00
|
|
|
*
|
2014-01-18 16:30:00 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
2014-01-19 14:41:37 +01:00
|
|
|
*
|
2014-01-18 16:30:00 +01:00
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
2014-01-19 14:41:37 +01:00
|
|
|
*
|
2014-01-18 16:30:00 +01:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
2013-10-08 21:05:56 +02:00
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2014-01-18 16:30:00 +01:00
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2013-10-08 21:05:56 +02:00
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2012-07-30 22:51:33 +02:00
|
|
|
#include <stdio.h>
|
2013-10-05 22:32:40 +02:00
|
|
|
#include <stdlib.h>
|
2012-08-01 23:16:07 +02:00
|
|
|
#include <string.h>
|
2013-10-05 22:32:40 +02:00
|
|
|
#include <sys/select.h>
|
2013-10-07 22:25:42 +02:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2013-11-09 11:08:36 +01:00
|
|
|
#include <sys/wait.h>
|
2012-08-02 21:53:27 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
2013-11-07 14:28:39 +01:00
|
|
|
#include <signal.h>
|
2013-10-05 22:32:40 +02:00
|
|
|
#include <unistd.h>
|
2013-12-15 20:24:21 -05:00
|
|
|
#include <xcb/xinerama.h>
|
2012-08-17 22:18:26 +02:00
|
|
|
#include "types.h"
|
2013-09-19 15:02:49 +02:00
|
|
|
#include "desktop.h"
|
|
|
|
#include "monitor.h"
|
2012-07-30 14:54:20 +02:00
|
|
|
#include "settings.h"
|
2012-07-31 14:32:13 +02:00
|
|
|
#include "messages.h"
|
2013-11-07 14:28:39 +01:00
|
|
|
#include "subscribe.h"
|
2012-08-01 12:56:57 +02:00
|
|
|
#include "events.h"
|
2012-08-02 22:37:20 +02:00
|
|
|
#include "common.h"
|
2013-09-19 15:38:22 +02:00
|
|
|
#include "window.h"
|
2013-10-01 10:48:03 +02:00
|
|
|
#include "history.h"
|
|
|
|
#include "stack.h"
|
2012-08-23 22:32:11 +02:00
|
|
|
#include "ewmh.h"
|
2013-11-08 20:31:23 +01:00
|
|
|
#include "rule.h"
|
2013-10-05 22:32:40 +02:00
|
|
|
#include "bspwm.h"
|
2012-09-07 12:51:16 +02:00
|
|
|
|
2012-10-24 12:30:37 +02:00
|
|
|
int main(int argc, char *argv[])
|
2012-07-29 22:46:12 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
fd_set descriptors;
|
|
|
|
char socket_path[MAXLEN];
|
|
|
|
config_path[0] = '\0';
|
|
|
|
int sock_fd, cli_fd, dpy_fd, max_fd, n;
|
|
|
|
struct sockaddr_un sock_address;
|
|
|
|
char msg[BUFSIZ] = {0};
|
|
|
|
xcb_generic_event_t *event;
|
|
|
|
char opt;
|
|
|
|
|
|
|
|
while ((opt = getopt(argc, argv, "hvc:")) != (char)-1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'h':
|
|
|
|
printf(WM_NAME " [-h|-v|-c CONFIG_PATH]\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
printf("%s\n", VERSION);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
snprintf(config_path, sizeof(config_path), "%s", optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *sp = getenv(SOCKET_ENV_VAR);
|
2014-11-23 15:38:49 +01:00
|
|
|
if (sp != NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
snprintf(socket_path, sizeof(socket_path), "%s", sp);
|
2014-11-23 15:38:49 +01:00
|
|
|
} else {
|
|
|
|
char *host = NULL;
|
|
|
|
int dn = 0, sn = 0;
|
|
|
|
if (xcb_parse_display(NULL, &host, &dn, &sn) != 0)
|
|
|
|
snprintf(socket_path, sizeof(socket_path), SOCKET_PATH_TPL, host, dn, sn);
|
|
|
|
free(host);
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
sock_address.sun_family = AF_UNIX;
|
|
|
|
snprintf(sock_address.sun_path, sizeof(sock_address.sun_path), "%s", socket_path);
|
|
|
|
|
|
|
|
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
|
|
|
|
if (sock_fd == -1)
|
|
|
|
err("Couldn't create the socket.\n");
|
|
|
|
|
2015-08-17 10:14:07 +02:00
|
|
|
unlink(socket_path);
|
2014-01-18 16:30:00 +01:00
|
|
|
if (bind(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address)) == -1)
|
|
|
|
err("Couldn't bind a name to the socket.\n");
|
|
|
|
|
|
|
|
if (listen(sock_fd, SOMAXCONN) == -1)
|
|
|
|
err("Couldn't listen to the socket.\n");
|
|
|
|
|
2015-08-17 10:14:07 +02:00
|
|
|
if (config_path[0] == '\0') {
|
|
|
|
char *config_home = getenv(CONFIG_HOME_ENV);
|
|
|
|
if (config_home != NULL)
|
|
|
|
snprintf(config_path, sizeof(config_path), "%s/%s/%s", config_home, WM_NAME, CONFIG_NAME);
|
|
|
|
else
|
|
|
|
snprintf(config_path, sizeof(config_path), "%s/%s/%s/%s", getenv("HOME"), ".config", WM_NAME, CONFIG_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpy = xcb_connect(NULL, &default_screen);
|
|
|
|
|
|
|
|
if (!check_connection(dpy))
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
load_settings();
|
|
|
|
setup();
|
|
|
|
|
|
|
|
dpy_fd = xcb_get_file_descriptor(dpy);
|
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
signal(SIGHUP, sig_handler);
|
|
|
|
signal(SIGTERM, sig_handler);
|
|
|
|
signal(SIGCHLD, sig_handler);
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
run_config();
|
|
|
|
running = true;
|
|
|
|
|
|
|
|
while (running) {
|
|
|
|
|
|
|
|
xcb_flush(dpy);
|
|
|
|
|
|
|
|
FD_ZERO(&descriptors);
|
|
|
|
FD_SET(sock_fd, &descriptors);
|
|
|
|
FD_SET(dpy_fd, &descriptors);
|
|
|
|
max_fd = MAX(sock_fd, dpy_fd);
|
|
|
|
for (pending_rule_t *pr = pending_rule_head; pr != NULL; pr = pr->next) {
|
|
|
|
FD_SET(pr->fd, &descriptors);
|
|
|
|
if (pr->fd > max_fd)
|
|
|
|
max_fd = pr->fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (select(max_fd + 1, &descriptors, NULL, NULL, NULL) > 0) {
|
|
|
|
|
|
|
|
pending_rule_t *pr = pending_rule_head;
|
|
|
|
while (pr != NULL) {
|
|
|
|
pending_rule_t *next = pr->next;
|
|
|
|
if (FD_ISSET(pr->fd, &descriptors)) {
|
|
|
|
manage_window(pr->win, pr->csq, pr->fd);
|
|
|
|
remove_pending_rule(pr);
|
|
|
|
}
|
|
|
|
pr = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FD_ISSET(sock_fd, &descriptors)) {
|
|
|
|
cli_fd = accept(sock_fd, NULL, 0);
|
|
|
|
if (cli_fd > 0 && (n = recv(cli_fd, msg, sizeof(msg), 0)) > 0) {
|
|
|
|
msg[n] = '\0';
|
2014-02-17 11:55:34 +01:00
|
|
|
FILE *rsp = fdopen(cli_fd, "w");
|
|
|
|
if (rsp != NULL) {
|
|
|
|
int ret = handle_message(msg, n, rsp);
|
2015-05-09 21:12:19 +02:00
|
|
|
if (ret != MSG_SUBSCRIBE) {
|
2014-02-17 11:55:34 +01:00
|
|
|
if (ret != MSG_SUCCESS)
|
|
|
|
fprintf(rsp, "%c", ret);
|
|
|
|
fflush(rsp);
|
|
|
|
fclose(rsp);
|
2014-02-11 18:40:34 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
warn("Can't open the client socket as file.\n");
|
2014-01-18 16:30:00 +01:00
|
|
|
close(cli_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FD_ISSET(dpy_fd, &descriptors)) {
|
|
|
|
while ((event = xcb_poll_for_event(dpy)) != NULL) {
|
|
|
|
handle_event(event);
|
|
|
|
free(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-09 13:56:46 +01:00
|
|
|
if (!check_connection(dpy))
|
2014-01-18 16:30:00 +01:00
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
close(sock_fd);
|
|
|
|
unlink(socket_path);
|
|
|
|
xcb_ewmh_connection_wipe(ewmh);
|
2015-06-06 18:25:20 +02:00
|
|
|
xcb_destroy_window(dpy, meta_window);
|
2015-06-12 22:05:22 +02:00
|
|
|
xcb_destroy_window(dpy, motion_recorder);
|
2014-01-18 16:30:00 +01:00
|
|
|
free(ewmh);
|
|
|
|
xcb_flush(dpy);
|
|
|
|
xcb_disconnect(dpy);
|
|
|
|
return exit_status;
|
2012-07-29 22:46:12 +02:00
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
|
|
|
void init(void)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
num_monitors = num_desktops = num_clients = 0;
|
|
|
|
monitor_uid = desktop_uid = 0;
|
|
|
|
mon = mon_head = mon_tail = pri_mon = NULL;
|
|
|
|
history_head = history_tail = history_needle = NULL;
|
|
|
|
rule_head = rule_tail = NULL;
|
|
|
|
stack_head = stack_tail = NULL;
|
|
|
|
subscribe_head = subscribe_tail = NULL;
|
|
|
|
pending_rule_head = pending_rule_tail = NULL;
|
|
|
|
last_motion_time = last_motion_x = last_motion_y = 0;
|
|
|
|
visible = auto_raise = sticky_still = record_history = true;
|
|
|
|
randr_base = 0;
|
|
|
|
exit_status = 0;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup(void)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
init();
|
|
|
|
ewmh_init();
|
|
|
|
screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data;
|
|
|
|
if (screen == NULL)
|
|
|
|
err("Can't acquire the default screen.\n");
|
|
|
|
root = screen->root;
|
|
|
|
register_events();
|
|
|
|
|
|
|
|
screen_width = screen->width_in_pixels;
|
|
|
|
screen_height = screen->height_in_pixels;
|
|
|
|
root_depth = screen->root_depth;
|
|
|
|
|
2015-06-06 18:25:20 +02:00
|
|
|
meta_window = xcb_generate_id(dpy);
|
|
|
|
xcb_create_window(dpy, XCB_COPY_FROM_PARENT, meta_window, root, -1, -1, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, XCB_NONE, NULL);
|
2015-10-31 22:19:17 +01:00
|
|
|
xcb_icccm_set_wm_class(dpy, meta_window, sizeof(META_WINDOW_IC), META_WINDOW_IC);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2015-06-12 22:05:22 +02:00
|
|
|
motion_recorder = xcb_generate_id(dpy);
|
|
|
|
uint32_t values[] = {XCB_EVENT_MASK_POINTER_MOTION};
|
|
|
|
xcb_create_window(dpy, XCB_COPY_FROM_PARENT, motion_recorder, root, 0, 0, screen_width, screen_height, 0, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, XCB_CW_EVENT_MASK, values);
|
2015-10-31 22:19:17 +01:00
|
|
|
xcb_icccm_set_wm_class(dpy, motion_recorder, sizeof(MOTION_RECORDER_IC), MOTION_RECORDER_IC);
|
2015-06-12 22:05:22 +02:00
|
|
|
|
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
xcb_atom_t net_atoms[] = {ewmh->_NET_SUPPORTED,
|
|
|
|
ewmh->_NET_SUPPORTING_WM_CHECK,
|
|
|
|
ewmh->_NET_DESKTOP_NAMES,
|
|
|
|
ewmh->_NET_NUMBER_OF_DESKTOPS,
|
|
|
|
ewmh->_NET_CURRENT_DESKTOP,
|
|
|
|
ewmh->_NET_CLIENT_LIST,
|
|
|
|
ewmh->_NET_ACTIVE_WINDOW,
|
|
|
|
ewmh->_NET_CLOSE_WINDOW,
|
|
|
|
ewmh->_NET_WM_DESKTOP,
|
|
|
|
ewmh->_NET_WM_STATE,
|
|
|
|
ewmh->_NET_WM_STATE_FULLSCREEN,
|
2015-10-26 20:56:56 +01:00
|
|
|
ewmh->_NET_WM_STATE_BELOW,
|
|
|
|
ewmh->_NET_WM_STATE_ABOVE,
|
2014-01-18 16:30:00 +01:00
|
|
|
ewmh->_NET_WM_STATE_STICKY,
|
|
|
|
ewmh->_NET_WM_STATE_DEMANDS_ATTENTION,
|
|
|
|
ewmh->_NET_WM_WINDOW_TYPE,
|
|
|
|
ewmh->_NET_WM_WINDOW_TYPE_DOCK,
|
|
|
|
ewmh->_NET_WM_WINDOW_TYPE_DESKTOP,
|
|
|
|
ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION,
|
|
|
|
ewmh->_NET_WM_WINDOW_TYPE_DIALOG,
|
|
|
|
ewmh->_NET_WM_WINDOW_TYPE_UTILITY,
|
|
|
|
ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR};
|
|
|
|
|
|
|
|
xcb_ewmh_set_supported(ewmh, default_screen, LENGTH(net_atoms), net_atoms);
|
2015-06-06 18:25:20 +02:00
|
|
|
ewmh_set_supporting(meta_window);
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2013-09-05 15:37:54 +02:00
|
|
|
#define GETATOM(a) \
|
2014-01-18 16:30:00 +01:00
|
|
|
get_atom(#a, &a);
|
|
|
|
GETATOM(WM_DELETE_WINDOW)
|
|
|
|
GETATOM(WM_TAKE_FOCUS)
|
2013-09-05 15:37:54 +02:00
|
|
|
#undef GETATOM
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
const xcb_query_extension_reply_t *qep = xcb_get_extension_data(dpy, &xcb_randr_id);
|
2014-05-05 11:35:06 +02:00
|
|
|
if (qep->present && update_monitors()) {
|
2014-01-18 16:30:00 +01:00
|
|
|
randr = true;
|
|
|
|
randr_base = qep->first_event;
|
|
|
|
xcb_randr_select_input(dpy, root, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE);
|
|
|
|
} else {
|
|
|
|
randr = false;
|
|
|
|
warn("Couldn't retrieve monitors via RandR.\n");
|
|
|
|
bool xinerama_is_active = false;
|
|
|
|
if (xcb_get_extension_data(dpy, &xcb_xinerama_id)->present) {
|
|
|
|
xcb_xinerama_is_active_reply_t *xia = xcb_xinerama_is_active_reply(dpy, xcb_xinerama_is_active(dpy), NULL);
|
|
|
|
if (xia != NULL) {
|
|
|
|
xinerama_is_active = xia->state;
|
|
|
|
free(xia);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xinerama_is_active) {
|
|
|
|
xcb_xinerama_query_screens_reply_t *xsq = xcb_xinerama_query_screens_reply(dpy, xcb_xinerama_query_screens(dpy), NULL);
|
|
|
|
xcb_xinerama_screen_info_t *xsi = xcb_xinerama_query_screens_screen_info(xsq);
|
|
|
|
int n = xcb_xinerama_query_screens_screen_info_length(xsq);
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
xcb_xinerama_screen_info_t info = xsi[i];
|
|
|
|
xcb_rectangle_t rect = (xcb_rectangle_t) {info.x_org, info.y_org, info.width, info.height};
|
2015-11-09 15:00:47 +01:00
|
|
|
monitor_t *m = make_monitor(rect);
|
|
|
|
add_monitor(m);
|
2014-01-18 16:30:00 +01:00
|
|
|
add_desktop(m, make_desktop(NULL));
|
|
|
|
}
|
|
|
|
free(xsq);
|
|
|
|
} else {
|
|
|
|
warn("Xinerama is inactive.\n");
|
|
|
|
xcb_rectangle_t rect = (xcb_rectangle_t) {0, 0, screen_width, screen_height};
|
2015-11-09 15:00:47 +01:00
|
|
|
monitor_t *m = make_monitor(rect);
|
|
|
|
add_monitor(m);
|
2014-01-18 16:30:00 +01:00
|
|
|
add_desktop(m, make_desktop(NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ewmh_update_number_of_desktops();
|
|
|
|
ewmh_update_desktop_names();
|
|
|
|
ewmh_update_current_desktop();
|
|
|
|
frozen_pointer = make_pointer_state();
|
|
|
|
xcb_get_input_focus_reply_t *ifo = xcb_get_input_focus_reply(dpy, xcb_get_input_focus(dpy), NULL);
|
|
|
|
if (ifo != NULL && (ifo->focus == XCB_INPUT_FOCUS_POINTER_ROOT || ifo->focus == XCB_NONE))
|
|
|
|
clear_input_focus();
|
|
|
|
free(ifo);
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void register_events(void)
|
|
|
|
{
|
2015-06-12 22:05:22 +02:00
|
|
|
uint32_t values[] = {ROOT_EVENT_MASK};
|
2014-01-18 16:30:00 +01:00
|
|
|
xcb_generic_error_t *e = xcb_request_check(dpy, xcb_change_window_attributes_checked(dpy, root, XCB_CW_EVENT_MASK, values));
|
|
|
|
if (e != NULL) {
|
|
|
|
xcb_disconnect(dpy);
|
|
|
|
err("Another window manager is already running.\n");
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup(void)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
while (mon_head != NULL)
|
|
|
|
remove_monitor(mon_head);
|
|
|
|
while (rule_head != NULL)
|
|
|
|
remove_rule(rule_head);
|
|
|
|
while (stack_head != NULL)
|
|
|
|
remove_stack(stack_head);
|
|
|
|
while (subscribe_head != NULL)
|
|
|
|
remove_subscriber(subscribe_head);
|
|
|
|
while (pending_rule_head != NULL)
|
|
|
|
remove_pending_rule(pending_rule_head);
|
|
|
|
empty_history();
|
|
|
|
free(frozen_pointer);
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
2015-02-09 13:56:46 +01:00
|
|
|
bool check_connection (xcb_connection_t *dpy)
|
|
|
|
{
|
|
|
|
int xerr;
|
|
|
|
if ((xerr = xcb_connection_has_error(dpy)) != 0) {
|
|
|
|
warn("The server closed the connection: ");
|
|
|
|
switch (xerr) {
|
|
|
|
case XCB_CONN_ERROR:
|
|
|
|
warn("socket, pipe or stream error.\n");
|
|
|
|
break;
|
|
|
|
case XCB_CONN_CLOSED_EXT_NOTSUPPORTED:
|
|
|
|
warn("unsupported extension.\n");
|
|
|
|
break;
|
|
|
|
case XCB_CONN_CLOSED_MEM_INSUFFICIENT:
|
|
|
|
warn("not enough memory.\n");
|
|
|
|
break;
|
|
|
|
case XCB_CONN_CLOSED_REQ_LEN_EXCEED:
|
|
|
|
warn("request length exceeded.\n");
|
|
|
|
break;
|
|
|
|
case XCB_CONN_CLOSED_PARSE_ERR:
|
|
|
|
warn("can't parse display string.\n");
|
|
|
|
break;
|
|
|
|
case XCB_CONN_CLOSED_INVALID_SCREEN:
|
|
|
|
warn("invalid screen.\n");
|
|
|
|
break;
|
|
|
|
case XCB_CONN_CLOSED_FDPASSING_FAILED:
|
|
|
|
warn("failed to pass FD.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warn("unknown error.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-09 11:08:36 +01:00
|
|
|
void sig_handler(int sig)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
if (sig == SIGCHLD) {
|
|
|
|
signal(sig, sig_handler);
|
|
|
|
while (waitpid(-1, 0, WNOHANG) > 0)
|
|
|
|
;
|
|
|
|
} else if (sig == SIGINT || sig == SIGHUP || sig == SIGTERM) {
|
|
|
|
running = false;
|
|
|
|
}
|
2013-11-09 11:08:36 +01:00
|
|
|
}
|