mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
xcb: add xcb_init(): checks the x server + extensions, and caches atoms
This commit is contained in:
parent
8bf8a398b9
commit
7c468c20c0
5 changed files with 126 additions and 106 deletions
10
bar.c
10
bar.c
|
@ -290,16 +290,6 @@ run(struct bar_run_context *run_ctx)
|
||||||
XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
|
XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
|
||||||
strlen(title), title);
|
strlen(title), title);
|
||||||
|
|
||||||
const xcb_atom_t _NET_WM_PID = get_atom(bar->conn, "_NET_WM_PID");
|
|
||||||
const xcb_atom_t _NET_WM_WINDOW_TYPE = get_atom(bar->conn, "_NET_WM_WINDOW_TYPE");
|
|
||||||
const xcb_atom_t _NET_WM_WINDOW_TYPE_DOCK = get_atom(bar->conn, "_NET_WM_WINDOW_TYPE_DOCK");
|
|
||||||
const xcb_atom_t _NET_WM_STATE = get_atom(bar->conn, "_NET_WM_STATE");
|
|
||||||
const xcb_atom_t _NET_WM_STATE_ABOVE = get_atom(bar->conn, "_NET_WM_STATE_ABOVE");
|
|
||||||
const xcb_atom_t _NET_WM_STATE_STICKY = get_atom(bar->conn, "_NET_WM_STATE_STICKY");
|
|
||||||
const xcb_atom_t _NET_WM_DESKTOP = get_atom(bar->conn, "_NET_WM_DESKTOP");
|
|
||||||
const xcb_atom_t _NET_WM_STRUT = get_atom(bar->conn, "_NET_WM_STRUT");
|
|
||||||
const xcb_atom_t _NET_WM_STRUT_PARTIAL = get_atom(bar->conn, "_NET_WM_STRUT_PARTIAL");
|
|
||||||
|
|
||||||
xcb_change_property(
|
xcb_change_property(
|
||||||
bar->conn,
|
bar->conn,
|
||||||
XCB_PROP_MODE_REPLACE, bar->win,
|
XCB_PROP_MODE_REPLACE, bar->win,
|
||||||
|
|
67
main.c
67
main.c
|
@ -11,14 +11,10 @@
|
||||||
|
|
||||||
#include <sys/eventfd.h>
|
#include <sys/eventfd.h>
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
|
||||||
#include <xcb/randr.h>
|
|
||||||
#include <xcb/render.h>
|
|
||||||
|
|
||||||
#include "bar.h"
|
#include "bar.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "yml.h"
|
#include "yml.h"
|
||||||
|
#include "xcb.h"
|
||||||
|
|
||||||
static volatile sig_atomic_t aborted = 0;
|
static volatile sig_atomic_t aborted = 0;
|
||||||
|
|
||||||
|
@ -36,66 +32,7 @@ main(int argc, const char *const *argv)
|
||||||
struct yml_node *conf = yml_load(conf_file);
|
struct yml_node *conf = yml_load(conf_file);
|
||||||
fclose(conf_file);
|
fclose(conf_file);
|
||||||
|
|
||||||
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
xcb_init();
|
||||||
assert(conn != NULL);
|
|
||||||
|
|
||||||
const xcb_setup_t *setup = xcb_get_setup(conn);
|
|
||||||
|
|
||||||
/* Vendor string */
|
|
||||||
int length = xcb_setup_vendor_length(setup);
|
|
||||||
char *vendor = malloc(length + 1);
|
|
||||||
memcpy(vendor, xcb_setup_vendor(setup), length);
|
|
||||||
vendor[length] = '\0';
|
|
||||||
|
|
||||||
/* Vendor release number */
|
|
||||||
unsigned release = setup->release_number;
|
|
||||||
unsigned major = release / 10000000; release %= 10000000;
|
|
||||||
unsigned minor = release / 100000; release %= 100000;
|
|
||||||
unsigned patch = release / 1000;
|
|
||||||
|
|
||||||
printf("%s %u.%u.%u (protocol: %u.%u)\n", vendor,
|
|
||||||
major, minor, patch,
|
|
||||||
setup->protocol_major_version,
|
|
||||||
setup->protocol_minor_version);
|
|
||||||
free(vendor);
|
|
||||||
|
|
||||||
const xcb_query_extension_reply_t *randr =
|
|
||||||
xcb_get_extension_data(conn, &xcb_randr_id);
|
|
||||||
assert(randr->present);
|
|
||||||
|
|
||||||
const xcb_query_extension_reply_t *render =
|
|
||||||
xcb_get_extension_data(conn, &xcb_render_id);
|
|
||||||
assert(render->present);
|
|
||||||
|
|
||||||
xcb_randr_query_version_cookie_t randr_cookie =
|
|
||||||
xcb_randr_query_version(conn, XCB_RANDR_MAJOR_VERSION,
|
|
||||||
XCB_RANDR_MINOR_VERSION);
|
|
||||||
xcb_render_query_version_cookie_t render_cookie =
|
|
||||||
xcb_render_query_version(conn, XCB_RENDER_MAJOR_VERSION,
|
|
||||||
XCB_RENDER_MINOR_VERSION);
|
|
||||||
|
|
||||||
xcb_generic_error_t *e;
|
|
||||||
xcb_randr_query_version_reply_t *randr_version =
|
|
||||||
xcb_randr_query_version_reply(conn, randr_cookie, &e);
|
|
||||||
assert(e == NULL);
|
|
||||||
|
|
||||||
xcb_render_query_version_reply_t *render_version =
|
|
||||||
xcb_render_query_version_reply(conn, render_cookie, &e);
|
|
||||||
assert(e == NULL);
|
|
||||||
|
|
||||||
xcb_flush(conn);
|
|
||||||
|
|
||||||
printf(" RANDR: %u.%u\n"
|
|
||||||
" RENDER: %u.%u\n",
|
|
||||||
randr_version->major_version,
|
|
||||||
randr_version->minor_version,
|
|
||||||
render_version->major_version,
|
|
||||||
render_version->minor_version);
|
|
||||||
|
|
||||||
free(randr_version);
|
|
||||||
free(render_version);
|
|
||||||
|
|
||||||
xcb_disconnect(conn);
|
|
||||||
|
|
||||||
const struct sigaction sa = {.sa_handler = &signal_handler};
|
const struct sigaction sa = {.sa_handler = &signal_handler};
|
||||||
sigaction(SIGINT, &sa, NULL);
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
|
|
@ -17,14 +17,6 @@
|
||||||
#include "../bar.h"
|
#include "../bar.h"
|
||||||
#include "../xcb.h"
|
#include "../xcb.h"
|
||||||
|
|
||||||
static bool globals_inited = false;
|
|
||||||
xcb_atom_t UTF8_STRING;
|
|
||||||
xcb_atom_t _NET_ACTIVE_WINDOW;
|
|
||||||
xcb_atom_t _NET_CURRENT_DESKTOP;
|
|
||||||
xcb_atom_t _NET_WM_VISIBLE_NAME;
|
|
||||||
xcb_atom_t _NET_WM_NAME;
|
|
||||||
xcb_atom_t _NET_WM_PID;
|
|
||||||
|
|
||||||
struct private {
|
struct private {
|
||||||
/* Accessed from bar thread only */
|
/* Accessed from bar thread only */
|
||||||
struct particle *label;
|
struct particle *label;
|
||||||
|
@ -41,26 +33,6 @@ struct private {
|
||||||
xcb_window_t active_win;
|
xcb_window_t active_win;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
init_globals(void)
|
|
||||||
{
|
|
||||||
if (globals_inited)
|
|
||||||
return;
|
|
||||||
|
|
||||||
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
|
||||||
assert(conn != NULL);
|
|
||||||
|
|
||||||
UTF8_STRING = get_atom(conn, "UTF8_STRING");
|
|
||||||
_NET_ACTIVE_WINDOW = get_atom(conn, "_NET_ACTIVE_WINDOW");
|
|
||||||
_NET_CURRENT_DESKTOP = get_atom(conn, "_NET_CURRENT_DESKTOP");
|
|
||||||
_NET_WM_VISIBLE_NAME = get_atom(conn, "_NET_WM_VISIBLE_NAME");
|
|
||||||
_NET_WM_NAME = get_atom(conn, "_NET_WM_NAME");
|
|
||||||
_NET_WM_PID = get_atom(conn, "_NET_WM_PID");
|
|
||||||
globals_inited = true;
|
|
||||||
|
|
||||||
xcb_disconnect(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_active_window(struct private *m)
|
update_active_window(struct private *m)
|
||||||
{
|
{
|
||||||
|
@ -317,8 +289,6 @@ destroy(struct module *mod)
|
||||||
struct module *
|
struct module *
|
||||||
module_xwindow(struct particle *label)
|
module_xwindow(struct particle *label)
|
||||||
{
|
{
|
||||||
init_globals();
|
|
||||||
|
|
||||||
struct private *m = calloc(1, sizeof(*m));
|
struct private *m = calloc(1, sizeof(*m));
|
||||||
m->label = label;
|
m->label = label;
|
||||||
mtx_init(&m->lock, mtx_plain);
|
mtx_init(&m->lock, mtx_plain);
|
||||||
|
|
104
xcb.c
104
xcb.c
|
@ -1,9 +1,113 @@
|
||||||
#include "xcb.h"
|
#include "xcb.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <xcb/xcb.h>
|
||||||
|
#include <xcb/randr.h>
|
||||||
|
#include <xcb/render.h>
|
||||||
|
|
||||||
|
xcb_atom_t UTF8_STRING;
|
||||||
|
xcb_atom_t _NET_WM_PID;
|
||||||
|
xcb_atom_t _NET_WM_WINDOW_TYPE;
|
||||||
|
xcb_atom_t _NET_WM_WINDOW_TYPE_DOCK;
|
||||||
|
xcb_atom_t _NET_WM_STATE;
|
||||||
|
xcb_atom_t _NET_WM_STATE_ABOVE;
|
||||||
|
xcb_atom_t _NET_WM_STATE_STICKY;
|
||||||
|
xcb_atom_t _NET_WM_DESKTOP;
|
||||||
|
xcb_atom_t _NET_WM_STRUT;
|
||||||
|
xcb_atom_t _NET_WM_STRUT_PARTIAL;
|
||||||
|
xcb_atom_t _NET_ACTIVE_WINDOW;
|
||||||
|
xcb_atom_t _NET_CURRENT_DESKTOP;
|
||||||
|
xcb_atom_t _NET_WM_VISIBLE_NAME;
|
||||||
|
xcb_atom_t _NET_WM_NAME;
|
||||||
|
|
||||||
|
bool
|
||||||
|
xcb_init(void)
|
||||||
|
{
|
||||||
|
xcb_connection_t *conn = xcb_connect(NULL, NULL);
|
||||||
|
assert(conn != NULL);
|
||||||
|
|
||||||
|
const xcb_setup_t *setup = xcb_get_setup(conn);
|
||||||
|
|
||||||
|
/* Vendor string */
|
||||||
|
int length = xcb_setup_vendor_length(setup);
|
||||||
|
char *vendor = malloc(length + 1);
|
||||||
|
memcpy(vendor, xcb_setup_vendor(setup), length);
|
||||||
|
vendor[length] = '\0';
|
||||||
|
|
||||||
|
/* Vendor release number */
|
||||||
|
unsigned release = setup->release_number;
|
||||||
|
unsigned major = release / 10000000; release %= 10000000;
|
||||||
|
unsigned minor = release / 100000; release %= 100000;
|
||||||
|
unsigned patch = release / 1000;
|
||||||
|
|
||||||
|
printf("%s %u.%u.%u (protocol: %u.%u)\n", vendor,
|
||||||
|
major, minor, patch,
|
||||||
|
setup->protocol_major_version,
|
||||||
|
setup->protocol_minor_version);
|
||||||
|
free(vendor);
|
||||||
|
|
||||||
|
const xcb_query_extension_reply_t *randr =
|
||||||
|
xcb_get_extension_data(conn, &xcb_randr_id);
|
||||||
|
assert(randr->present);
|
||||||
|
|
||||||
|
const xcb_query_extension_reply_t *render =
|
||||||
|
xcb_get_extension_data(conn, &xcb_render_id);
|
||||||
|
assert(render->present);
|
||||||
|
|
||||||
|
xcb_randr_query_version_cookie_t randr_cookie =
|
||||||
|
xcb_randr_query_version(conn, XCB_RANDR_MAJOR_VERSION,
|
||||||
|
XCB_RANDR_MINOR_VERSION);
|
||||||
|
xcb_render_query_version_cookie_t render_cookie =
|
||||||
|
xcb_render_query_version(conn, XCB_RENDER_MAJOR_VERSION,
|
||||||
|
XCB_RENDER_MINOR_VERSION);
|
||||||
|
|
||||||
|
xcb_generic_error_t *e;
|
||||||
|
xcb_randr_query_version_reply_t *randr_version =
|
||||||
|
xcb_randr_query_version_reply(conn, randr_cookie, &e);
|
||||||
|
assert(e == NULL);
|
||||||
|
|
||||||
|
xcb_render_query_version_reply_t *render_version =
|
||||||
|
xcb_render_query_version_reply(conn, render_cookie, &e);
|
||||||
|
assert(e == NULL);
|
||||||
|
|
||||||
|
xcb_flush(conn);
|
||||||
|
|
||||||
|
printf(" RANDR: %u.%u\n"
|
||||||
|
" RENDER: %u.%u\n",
|
||||||
|
randr_version->major_version,
|
||||||
|
randr_version->minor_version,
|
||||||
|
render_version->major_version,
|
||||||
|
render_version->minor_version);
|
||||||
|
|
||||||
|
free(randr_version);
|
||||||
|
free(render_version);
|
||||||
|
|
||||||
|
/* Cache atoms */
|
||||||
|
UTF8_STRING = get_atom(conn, "UTF8_STRING");
|
||||||
|
_NET_WM_PID = get_atom(conn, "_NET_WM_PID");
|
||||||
|
_NET_WM_WINDOW_TYPE = get_atom(conn, "_NET_WM_WINDOW_TYPE");
|
||||||
|
_NET_WM_WINDOW_TYPE_DOCK = get_atom(conn, "_NET_WM_WINDOW_TYPE_DOCK");
|
||||||
|
_NET_WM_STATE = get_atom(conn, "_NET_WM_STATE");
|
||||||
|
_NET_WM_STATE_ABOVE = get_atom(conn, "_NET_WM_STATE_ABOVE");
|
||||||
|
_NET_WM_STATE_STICKY = get_atom(conn, "_NET_WM_STATE_STICKY");
|
||||||
|
_NET_WM_DESKTOP = get_atom(conn, "_NET_WM_DESKTOP");
|
||||||
|
_NET_WM_STRUT = get_atom(conn, "_NET_WM_STRUT");
|
||||||
|
_NET_WM_STRUT_PARTIAL = get_atom(conn, "_NET_WM_STRUT_PARTIAL");
|
||||||
|
_NET_ACTIVE_WINDOW = get_atom(conn, "_NET_ACTIVE_WINDOW");
|
||||||
|
_NET_CURRENT_DESKTOP = get_atom(conn, "_NET_CURRENT_DESKTOP");
|
||||||
|
_NET_WM_VISIBLE_NAME = get_atom(conn, "_NET_WM_VISIBLE_NAME");
|
||||||
|
_NET_WM_NAME = get_atom(conn, "_NET_WM_NAME");
|
||||||
|
_NET_WM_PID = get_atom(conn, "_NET_WM_PID");
|
||||||
|
|
||||||
|
xcb_disconnect(conn);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
xcb_atom_t
|
xcb_atom_t
|
||||||
get_atom(xcb_connection_t *conn, const char *name)
|
get_atom(xcb_connection_t *conn, const char *name)
|
||||||
{
|
{
|
||||||
|
|
19
xcb.h
19
xcb.h
|
@ -1,6 +1,25 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
|
bool xcb_init(void);
|
||||||
|
|
||||||
xcb_atom_t get_atom(xcb_connection_t *conn, const char *name);
|
xcb_atom_t get_atom(xcb_connection_t *conn, const char *name);
|
||||||
char *get_atom_name(xcb_connection_t *conn, xcb_atom_t atom);
|
char *get_atom_name(xcb_connection_t *conn, xcb_atom_t atom);
|
||||||
|
|
||||||
|
/* Cached atoms */
|
||||||
|
xcb_atom_t UTF8_STRING;
|
||||||
|
xcb_atom_t _NET_WM_PID;
|
||||||
|
xcb_atom_t _NET_WM_WINDOW_TYPE;
|
||||||
|
xcb_atom_t _NET_WM_WINDOW_TYPE_DOCK;
|
||||||
|
xcb_atom_t _NET_WM_STATE;
|
||||||
|
xcb_atom_t _NET_WM_STATE_ABOVE;
|
||||||
|
xcb_atom_t _NET_WM_STATE_STICKY;
|
||||||
|
xcb_atom_t _NET_WM_DESKTOP;
|
||||||
|
xcb_atom_t _NET_WM_STRUT;
|
||||||
|
xcb_atom_t _NET_WM_STRUT_PARTIAL;
|
||||||
|
xcb_atom_t _NET_ACTIVE_WINDOW;
|
||||||
|
xcb_atom_t _NET_CURRENT_DESKTOP;
|
||||||
|
xcb_atom_t _NET_WM_VISIBLE_NAME;
|
||||||
|
xcb_atom_t _NET_WM_NAME;
|
||||||
|
|
Loading…
Add table
Reference in a new issue