Add basic WM calls and move to dedicated file
This commit is contained in:
parent
bbed8a6b3e
commit
42ff4ed563
4
Makefile
4
Makefile
@ -20,8 +20,8 @@ V = 0.0
|
||||
XCB_INCS = -I/usr/X11R6/include
|
||||
XCB_LIBS = -L/usr/X11R6/lib -lxcb
|
||||
|
||||
HDR = err.h
|
||||
OBJ = err.o main.o
|
||||
HDR = err.h wm.h
|
||||
OBJ = err.o main.o wm.o
|
||||
SRC = ${OBJ:.o=.c}
|
||||
DIST_FILES = COPYING Makefile THANKS ${HDR} ${SRC}
|
||||
|
||||
|
29
main.c
29
main.c
@ -13,30 +13,13 @@
|
||||
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "err.h"
|
||||
|
||||
static struct {
|
||||
xcb_connection_t *conn;
|
||||
} wm;
|
||||
|
||||
static void
|
||||
wm_setup(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wm_print_info(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wm_teardown(void)
|
||||
{
|
||||
}
|
||||
#include "wm.h"
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
@ -48,12 +31,14 @@ usage(void)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct wm wm;
|
||||
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
wm_setup();
|
||||
wm_print_info();
|
||||
wm_teardown();
|
||||
wm_setup(&wm);
|
||||
wm_print_screen_info(stderr, &wm);
|
||||
wm_teardown(&wm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
63
wm.c
Normal file
63
wm.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
25
wm.h
Normal file
25
wm.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 <xcb/xcb.h>
|
||||
|
||||
struct wm {
|
||||
xcb_connection_t *conn;
|
||||
int screen;
|
||||
};
|
||||
|
||||
void wm_setup(struct wm *);
|
||||
void wm_print_screen_info(FILE *, const struct wm *);
|
||||
void wm_teardown(struct wm *);
|
Loading…
Reference in New Issue
Block a user