summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-09-01 19:18:56 +0200
committerAki <please@ignore.pl>2021-09-01 19:18:56 +0200
commitb035d701ac78d984be4a983bed7711ff4ad5517f (patch)
tree3a9a4df12ccf37fe2299bf075537e433b156a3fe
parent266f20e8f0b688ba075ee0f5e81cfd9e4b0af18a (diff)
downloadtext-b035d701ac78d984be4a983bed7711ff4ad5517f.zip
text-b035d701ac78d984be4a983bed7711ff4ad5517f.tar.gz
text-b035d701ac78d984be4a983bed7711ff4ad5517f.tar.bz2
Added handler for ConfigureNotify event
-rw-r--r--text.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/text.c b/text.c
index f0bd074..956385b 100644
--- a/text.c
+++ b/text.c
@@ -13,9 +13,9 @@ void draw_text(cairo_t *, const char *);
xcb_visualtype_t * find_visual(xcb_screen_t *);
static const int MARGIN = 20;
-static const int WIDTH = 800;
-static const int HEIGHT = 1131;
static const char * FONT = "Serif 34";
+static int width = 800;
+static int height = 600;
int main(int argc, const char ** argv)
@@ -32,13 +32,13 @@ int main(int argc, const char ** argv)
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};
+ 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,
+ 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, visual, width, height);
cairo_t * ctx = cairo_create(surface);
xcb_flush(c);
int done = 0;
@@ -63,6 +63,16 @@ int main(int argc, const char ** argv)
cairo_surface_flush(surface);
xcb_flush(c);
break;
+ case XCB_CONFIGURE_NOTIFY:
+ ;
+ xcb_configure_notify_event_t * conf = (xcb_configure_notify_event_t *) e;
+ if (width != conf->width || height != conf->height)
+ {
+ cairo_xcb_surface_set_size(surface, conf->width, conf->height);
+ width = conf->width;
+ height = conf->height;
+ }
+ break;
}
free(e);
}
@@ -95,7 +105,7 @@ void draw_text(cairo_t * ctx, const char * text)
pango_font_description_free(desc);
pango_layout_set_text(layout, text, -1);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
- pango_layout_set_width(layout, (WIDTH - 2 * MARGIN) * PANGO_SCALE);
+ pango_layout_set_width(layout, (width - 2 * MARGIN) * PANGO_SCALE);
pango_cairo_update_layout(ctx, layout);
pango_cairo_show_layout(ctx, layout);
g_object_unref(layout);