Example #1
0
File: unagi.c Project: ehntoo/unagi
/** Perform cleanup on normal exit */
static void
exit_cleanup(void)
{
  debug("Cleaning resources up");

  /* Destroy CM window, thus giving up _NET_WM_CM_Sn ownership */
  if(globalconf.cm_window != XCB_NONE)
    xcb_destroy_window(globalconf.connection, globalconf.cm_window);

  /* Free resources related to the plugins */
  plugin_unload_all();

  /* Destroy the  linked-list of  windows which has  to be  done after
     unloading the plugins as the  plugins may use the windows list to
     free memory */
  window_list_cleanup();

  /* Free resources related  to the rendering backend which  has to be
     done  after the  windows  list  cleanup as  the  latter free  the
     rendering information associated with each window */
  rendering_unload();

  /* Free resources related to the keymaps */
  xcb_key_symbols_free(globalconf.keysyms);

  /* Free resources related to EWMH */
  xcb_ewmh_connection_wipe(&globalconf.ewmh);

  cfg_free(globalconf.cfg);
  free(globalconf.rendering_dir);
  free(globalconf.plugins_dir);

  xcb_disconnect(globalconf.connection);
}
Example #2
0
void
_xcwm_atoms_release(xcwm_context_t *context)
{

    /* Free the xcb_ewmh_connection_t */
    xcb_ewmh_connection_wipe(&context->atoms.ewmh_conn);

    /* Close the wm window */
    xcb_destroy_window(context->conn, context->wm_cm_window);
}
Example #3
0
static void
_eventd_nd_xcb_stop(EventdNdBackendContext *self)
{
    if ( self->custom_map )
        xcb_free_colormap(self->xcb_connection, self->map);

    xcb_ewmh_connection_wipe(&self->ewmh);

    g_hash_table_unref(self->bubbles);
    g_water_xcb_source_free(self->source);
    self->bubbles = NULL;
    self->source = NULL;
}
Example #4
0
X11AppContext::~X11AppContext()
{
    if(xDisplay_) ::XFlush(&xDisplay());

	xcb_ewmh_connection_wipe(&ewmhConnection());
	impl_.reset();

	if(xDummyWindow_) xcb_destroy_window(xConnection_, xDummyWindow_);
    if(xDisplay_) ::XCloseDisplay(&xDisplay());

	xDisplay_ = nullptr;
	xConnection_ = nullptr;
	xDefaultScreen_ = nullptr;
}
Example #5
0
static void ya_cleanup_x() {
	ya_bar_t * curbar = ya.curbar;
	ya_block_t *curblk;
	for(;curbar; curbar = curbar->next_bar) {
		for (int align = 0; align < 3; align++) {
			for (curblk = curbar->curblk[align]; curblk; curblk = curblk->next_blk) {
				xcb_free_gc(ya.c, curblk->gc);
				xcb_free_pixmap(ya.c, curblk->pixmap);
			}
		}
		xcb_destroy_window(ya.c, curbar->win);
	}
#ifdef YA_INTERNAL_EWMH
	xcb_ewmh_connection_wipe(ya.ewmh);
#endif //YA_INTERNAL_EWMH
	xcb_flush(ya.c);
	xcb_disconnect(ya.c);
}
Example #6
0
    Ewmh(xcb_connection_t * const c)
    {
      m_ewmh = std::shared_ptr<xcb_ewmh_connection_t>(new xcb_ewmh_connection_t,
          [](xcb_ewmh_connection_t * ec) {
            xcb_ewmh_connection_wipe(ec);
            std::free(ec);
          });

      xcb_intern_atom_cookie_t * cookies = xcb_ewmh_init_atoms(c, m_ewmh.get());

      if (cookies) {
        xcb_generic_error_t * error = NULL;
        xcb_ewmh_init_atoms_replies(m_ewmh.get(), cookies, &error);
        if (error) {
          std::free(error);
          std::free(cookies);
          throw std::runtime_error(__PRETTY_FUNCTION__);
        }

      } else {
        throw std::runtime_error(__PRETTY_FUNCTION__);
      }
    }
Example #7
0
LXCB::~LXCB(){
  xcb_ewmh_connection_wipe(&EWMH);
}
Example #8
0
x_ewmh::~x_ewmh(void)
{
  m_c.detach(XCB_PROPERTY_NOTIFY, this);
  xcb_ewmh_connection_wipe(&m_ewmh);
}
Example #9
0
int main(void)
{
    fd_set descriptors;
    char socket_path[BUFSIZ];
    int sock_fd, ret_fd, dpy_fd, sel, n;
    struct sockaddr_un sock_address;
    char msg[BUFSIZ] = {0};
    char rsp[BUFSIZ] = {0};

    xcb_generic_event_t *event;

    running = true;

    dpy = xcb_connect(NULL, &default_screen);

    if (xcb_connection_has_error(dpy))
        die("error: cannot open display\n");

    setup();
    register_events();

    dpy_fd = xcb_get_file_descriptor(dpy);

    char *sp = getenv(SOCKET_ENV_VAR);

    strncpy(socket_path, (sp == NULL ? DEFAULT_SOCKET_PATH : sp), sizeof(socket_path));

    sock_address.sun_family = AF_UNIX;
    strncpy(sock_address.sun_path, socket_path, sizeof(sock_address.sun_path));
    unlink(socket_path);

    sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);

    if (sock_fd == -1)
        die("error: could not create socket\n");

    bind(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address));
    listen(sock_fd, SOMAXCONN);

    sel = MAX(sock_fd, dpy_fd) + 1;

    load_settings();
    run_autostart();
    ewmh_update_wm_name();
    update_root_dimensions();

    while (running) {

        xcb_flush(dpy);

        FD_ZERO(&descriptors);
        FD_SET(sock_fd, &descriptors);
        FD_SET(dpy_fd, &descriptors);

        if (select(sel, &descriptors, NULL, NULL, NULL)) {

            if (FD_ISSET(sock_fd, &descriptors)) {
                ret_fd = accept(sock_fd, NULL, 0);
                if (ret_fd > 0 && (n = recv(ret_fd, msg, sizeof(msg), 0)) > 0) {
                    msg[n] = '\0';
                    process_message(msg, rsp);
                    send(ret_fd, rsp, strlen(rsp), 0);
                    close(ret_fd);
                }
            }

            if (FD_ISSET(dpy_fd, &descriptors)) {
                while ((event = xcb_poll_for_event(dpy)) != NULL) {
                    handle_event(event);
                    free(event);
                }
            }

        }

        if (xcb_connection_has_error(dpy)) {
            die("connection has errors\n");
        }
    }

    close(sock_fd);
    xcb_ewmh_connection_wipe(ewmh);
    free(ewmh);
    xcb_flush(dpy);
    xcb_disconnect(dpy);
    return 0;
}
Example #10
0
void*
widget_main (struct widget *widget) {
	unsigned short i;
	int xcb_fd;
	int screen_nbr = 0;
	xcb_connection_t *conn = xcb_connect(NULL, NULL);
	xcb_ewmh_connection_t *ewmh = malloc(sizeof(xcb_ewmh_connection_t));
	struct epoll_event xcb_event;

	widget_epoll_init(widget);

	if (xcb_connection_has_error(conn)) {
		LOG_ERR("could not connect to display %s", getenv("DISPLAY"));
		goto cleanup;
	}

	xcb_intern_atom_cookie_t *ewmh_cookie = xcb_ewmh_init_atoms(conn, ewmh);
	xcb_ewmh_init_atoms_replies(ewmh, ewmh_cookie, NULL);

	uint32_t values[] = { XCB_EVENT_MASK_PROPERTY_CHANGE };
	xcb_generic_event_t *evt;
	xcb_generic_error_t *err = xcb_request_check(ewmh->connection,
	                                             xcb_change_window_attributes_checked(ewmh->connection,
	                                                                                  ewmh->screens[screen_nbr]->root,
	                                                                                  XCB_CW_EVENT_MASK,
	                                                                                  values));

	if (err != NULL) {
		LOG_ERR("could not request EWMH property change notifications");
		goto cleanup;
	}

	xcb_fd = xcb_get_file_descriptor(ewmh->connection);
	xcb_event.data.fd = xcb_fd;
	xcb_event.events = EPOLLIN | EPOLLET;
	if (epoll_ctl(efd, EPOLL_CTL_ADD, xcb_fd, &xcb_event) == -1) {
		LOG_ERR("failed to add fd to epoll instance: %s", strerror(errno));

		return 0;
	}

	widget_update(widget, ewmh, screen_nbr);
	while (true) {
		while ((nfds = epoll_wait(efd, events, MAX_EVENTS, -1)) > 0) {
			for (i = 0; i < nfds; i++) {
				if (events[i].data.fd == widget->bar->efd) {
					goto cleanup;
				}
			}

			while ((evt = xcb_poll_for_event(ewmh->connection)) != NULL) {
				xcb_property_notify_event_t *pne;
				switch (XCB_EVENT_RESPONSE_TYPE(evt)) {
				case XCB_PROPERTY_NOTIFY:
					pne = (xcb_property_notify_event_t*)evt;
					if (pne->atom == ewmh->_NET_DESKTOP_NAMES) {
						widget_update(widget, ewmh, screen_nbr);
					}
					else if (pne->atom == ewmh->_NET_NUMBER_OF_DESKTOPS) {
						widget_update(widget, ewmh, screen_nbr);
					}
					else if (pne->atom == ewmh->_NET_CURRENT_DESKTOP) {
						widget_update(widget, ewmh, screen_nbr);
					}
				default:
					break;
				}
				free(evt);
			}
		}
	}

cleanup:
	if (ewmh != NULL) {
		xcb_ewmh_connection_wipe(ewmh);
	}
	if (conn != NULL) {
		xcb_disconnect(conn);
	}

	widget_epoll_cleanup(widget);
	widget_clean_exit(widget);
}
Example #11
0
File: xtitle.c Project: mmso/xtitle
int main(int argc, char *argv[])
{
    bool snoop = false;
    char *format = NULL;
    char opt;

    while ((opt = getopt(argc, argv, "hvsf:")) != -1) {
        switch (opt) {
            case 'h':
                printf("xtitle [-h|-v|-s|-f FORMAT] [WID ...]\n");
                return EXIT_SUCCESS;
                break;
            case 'v':
                printf("%s\n", VERSION);
                return EXIT_SUCCESS;
                break;
            case 's':
                snoop = true;
                break;
            case 'f':
                format = optarg;
                break;
        }
    }

    int num = argc - optind;
    char **args = argv + optind;

    setup();

    char title[MAXLEN] = {0};

    if (num > 0) {
        char *end;
        for (int i = 0; i < num; i++) {
            errno = 0;
            long int wid = strtol(args[i], &end, 0);
            if (errno != 0 || *end != '\0')
                warn("Invalid window ID: '%s'.\n", args[i]);
            else
                output_title(wid, format, title, sizeof(title));
        }
    } else {
        xcb_window_t win = XCB_NONE;
        if (get_active_window(&win))
            output_title(win, format, title, sizeof(title));
        if (snoop) {
            signal(SIGINT, hold);
            signal(SIGHUP, hold);
            signal(SIGTERM, hold);
            watch(root, true);
            watch(win, true);
            xcb_window_t last_win = XCB_NONE;
            fd_set descriptors;
            int fd = xcb_get_file_descriptor(dpy);
            running = true;
            xcb_flush(dpy);
            while (running) {
                FD_ZERO(&descriptors);
                FD_SET(fd, &descriptors);
                if (select(fd + 1, &descriptors, NULL, NULL, NULL) > 0) {
                    xcb_generic_event_t *evt;
                    while ((evt = xcb_poll_for_event(dpy)) != NULL) {
                        if (title_changed(evt, &win, &last_win))
                            output_title(win, format, title, sizeof(title));
                        free(evt);
                    }
                }
                if (xcb_connection_has_error(dpy)) {
                    warn("The server closed the connection.\n");
                    running = false;
                }
            }
        }
    }

    xcb_ewmh_connection_wipe(ewmh);
    free(ewmh);
    xcb_disconnect(dpy);
    return EXIT_SUCCESS;
}
Example #12
0
File: bspwm.c Project: sunaku/bspwm
int main(int argc, char *argv[])
{
    if (argc == 2 && strcmp(argv[1], "-v") == 0) {
        printf("%s\n", VERSION);
        exit(EXIT_SUCCESS);
    }

    fd_set descriptors;
    char socket_path[MAXLEN];
    int sock_fd, ret_fd, dpy_fd, sel, n;
    struct sockaddr_un sock_address;
    size_t rsplen = 0;
    char msg[BUFSIZ] = {0};
    char rsp[BUFSIZ] = {0};

    xcb_generic_event_t *event;

    running = true;

    dpy = xcb_connect(NULL, &default_screen);

    if (xcb_connection_has_error(dpy))
        err("error: cannot open display\n");

    setup();
    register_events();

    dpy_fd = xcb_get_file_descriptor(dpy);

    char *sp = getenv(SOCKET_ENV_VAR);

    strncpy(socket_path, (sp == NULL ? DEFAULT_SOCKET_PATH : sp), sizeof(socket_path));

    sock_address.sun_family = AF_UNIX;
    strncpy(sock_address.sun_path, socket_path, sizeof(sock_address.sun_path));
    unlink(socket_path);

    sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);

    if (sock_fd == -1)
        err("error: could not create socket\n");

    bind(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address));
    listen(sock_fd, SOMAXCONN);

    sel = MAX(sock_fd, dpy_fd) + 1;

    load_settings();
    run_autostart();
    grab_buttons();
    ewmh_update_wm_name();

    while (running) {

        xcb_flush(dpy);

        FD_ZERO(&descriptors);
        FD_SET(sock_fd, &descriptors);
        FD_SET(dpy_fd, &descriptors);

        if (select(sel, &descriptors, NULL, NULL, NULL)) {

            if (FD_ISSET(sock_fd, &descriptors)) {
                ret_fd = accept(sock_fd, NULL, 0);
                if (ret_fd > 0 && (n = recv(ret_fd, msg, sizeof(msg), 0)) > 0) {
                    msg[n] = '\0';
                    process_message(msg, rsp);
                    rsplen = strlen(rsp);
                    if (rsp[rsplen - 1] == '\n')
                        rsp[--rsplen] = '\0';
                    send(ret_fd, rsp, rsplen, 0);
                    close(ret_fd);
                    rsp[0] = '\0';
                }
            }

            if (FD_ISSET(dpy_fd, &descriptors)) {
                while ((event = xcb_poll_for_event(dpy)) != NULL) {
                    handle_event(event);
                    free(event);
                }
            }

        }

        if (xcb_connection_has_error(dpy)) {
            err("connection has errors\n");
        }
    }

    close(sock_fd);
    xcb_ewmh_connection_wipe(ewmh);
    free(ewmh);
    xcb_flush(dpy);
    xcb_disconnect(dpy);
    return 0;
}
Example #13
0
Compositor::~Compositor()
{
    xcb_ewmh_connection_wipe(&ewmh_);
}