orcawm/wm.c

64 lines
1.4 KiB
C

/*
* orcawm - XCB window manager
*
* Written in 2020 by Lucas
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include <inttypes.h>
#include <stdio.h>
#include "err.h"
#include "wm.h"
static int
detect_other_window_manager(const struct wm *wm)
{
return 0;
}
void
wm_setup(struct wm *wm)
{
wm->conn = xcb_connect(NULL, &wm->screen);
if (xcb_connection_has_error(wm->conn))
errx(1, "Error connecting to X server");
if (detect_other_window_manager(wm))
errx(1, "Another window manager is already running");
}
void
wm_print_screen_info(FILE *fp, const struct wm *wm)
{
const xcb_setup_t *setup;
xcb_screen_t *screen;
xcb_screen_iterator_t iter;
int i;
setup = xcb_get_setup(wm->conn);
iter = xcb_setup_roots_iterator(setup);
for (i = 0; i < wm->screen; i++)
xcb_screen_next(&iter);
if ((screen = iter.data) != NULL)
fprintf(fp, "[%d] %08" PRIx32 " %" PRIu16 "x%" PRIu16 "\n",
wm->screen, screen->root, screen->width_in_pixels,
screen->height_in_pixels);
else
fprintf(fp, "[%d] NO_DATA\n", wm->screen);
}
void
wm_teardown(struct wm *wm)
{
xcb_disconnect(wm->conn);
}