summaryrefslogtreecommitdiff
path: root/text.c
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-09-06 18:21:54 +0200
committerAki <please@ignore.pl>2021-09-06 18:21:54 +0200
commit55ad9c74c62e896c67d585e6ec0f58745fe0dd52 (patch)
tree5b80ae9de80c47ce3a59880ee80d5604601f4fe6 /text.c
parentb035d701ac78d984be4a983bed7711ff4ad5517f (diff)
downloadtext-55ad9c74c62e896c67d585e6ec0f58745fe0dd52.zip
text-55ad9c74c62e896c67d585e6ec0f58745fe0dd52.tar.gz
text-55ad9c74c62e896c67d585e6ec0f58745fe0dd52.tar.bz2
Moved x state to static variables
Diffstat (limited to 'text.c')
-rw-r--r--text.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/text.c b/text.c
index 956385b..17a6cbd 100644
--- a/text.c
+++ b/text.c
@@ -9,37 +9,33 @@
#include <xcb/xcb.h>
#include <xcb/xcb_util.h>
+int init_x(void);
void draw_text(cairo_t *, const char *);
xcb_visualtype_t * find_visual(xcb_screen_t *);
static const int MARGIN = 20;
-static const char * FONT = "Serif 34";
+static const char * const FONT = "Serif 34";
+
static int width = 800;
static int height = 600;
+static xcb_connection_t * c;
+static xcb_screen_t * s;
+static xcb_visualtype_t * v;
+static xcb_window_t w;
+
int main(int argc, const char ** argv)
{
const char * text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
if (2 == argc)
text = argv[2];
- xcb_connection_t * c = xcb_connect(NULL, NULL);
- if (xcb_connection_has_error(c))
- {
- dprintf(2, "Could not connect to X11 server");
+ const int res = init_x();
+ if (-1 == res)
return 1;
- }
- xcb_screen_t * s = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
- xcb_window_t w = xcb_generate_id(c);
- const uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
- const uint32_t values[] = {s->white_pixel, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY};
- xcb_visualtype_t * visual = find_visual(s);
- xcb_create_window(
- c, XCB_COPY_FROM_PARENT, w, s->root, 0, 0, width, height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
- s->root_visual, mask, values);
- xcb_map_window(c, w);
- cairo_surface_t * surface = cairo_xcb_surface_create(c, w, visual, width, height);
+ cairo_surface_t * surface = cairo_xcb_surface_create(c, w, v, width, height);
cairo_t * ctx = cairo_create(surface);
+ xcb_map_window(c, w);
xcb_flush(c);
int done = 0;
xcb_generic_event_t * e;
@@ -82,14 +78,38 @@ int main(int argc, const char ** argv)
}
-xcb_visualtype_t * find_visual(xcb_screen_t * s)
+int init_x(void)
+{
+ c = xcb_connect(NULL, NULL);
+ if (xcb_connection_has_error(c))
+ {
+ dprintf(2, "Could not connect to X11 server");
+ return -1;
+ }
+ s = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
+ w = xcb_generate_id(c);
+ v = find_visual(s);
+ const uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
+ const uint32_t values[] = {
+ s->white_pixel,
+ XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY,
+ };
+ xcb_create_window(
+ c, XCB_COPY_FROM_PARENT, w, s->root, 0, 0, width, height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ s->root_visual, mask, values);
+ xcb_flush(c);
+ return 0;
+}
+
+
+xcb_visualtype_t * find_visual(xcb_screen_t * screen)
{
- xcb_depth_iterator_t d = xcb_screen_allowed_depths_iterator(s);
+ xcb_depth_iterator_t d = xcb_screen_allowed_depths_iterator(screen);
for (; d.rem; xcb_depth_next(&d))
{
xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator(d.data);
for (; v.rem; xcb_visualtype_next(&v))
- if (v.data->visual_id == s->root_visual)
+ if (v.data->visual_id == screen->root_visual)
return v.data;
}
return NULL;