diff --git a/src/draw.c b/src/draw.c new file mode 100644 index 0000000..25287e8 --- /dev/null +++ b/src/draw.c @@ -0,0 +1,50 @@ +#include "draw.h" + +#include +#include +#include +#include +#include +#include + +#include "notification.h" +#include "x11/x.h" + +typedef struct { + PangoLayout *l; + color_t fg; + color_t bg; + color_t frame; + char *text; + PangoAttrList *attr; + cairo_surface_t *icon; + notification *n; +} colored_layout; + +cairo_surface_t *root_surface; +cairo_t *c_context; + +PangoFontDescription *pango_fdesc; + +void draw_setup(void) +{ + x_setup(); + + root_surface = x_create_cairo_surface(); + c_context = cairo_create(root_surface); + pango_fdesc = pango_font_description_from_string(settings.font); +} + +void draw(void) +{ + x_win_draw(); +} + +void draw_deinit(void) +{ + cairo_destroy(c_context); + cairo_surface_destroy(root_surface); + + x_free(); +} +/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/draw.h b/src/draw.h new file mode 100644 index 0000000..de9fb28 --- /dev/null +++ b/src/draw.h @@ -0,0 +1,11 @@ +#ifndef DUNST_DRAW_H +#define DUNST_DRAW_H + +void draw_setup(void); + +void draw(void); + +void draw_deinit(void); + +#endif +/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/dunst.c b/src/dunst.c index 2bf6899..f6f3a24 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -13,6 +13,7 @@ #include #include "dbus.h" +#include "draw.h" #include "log.h" #include "menu.h" #include "notification.h" @@ -67,7 +68,7 @@ static gboolean run(void *data) } if (xctx.visible) { - x_win_draw(); + draw(); } if (xctx.visible) { @@ -120,7 +121,7 @@ static void teardown(void) teardown_queues(); - x_free(); + draw_deinit(); } int dunst_main(int argc, char *argv[]) @@ -154,7 +155,7 @@ int dunst_main(int argc, char *argv[]) int owner_id = initdbus(); - x_setup(); + draw_setup(); if (settings.startup_notification) { notification *n = notification_create(); diff --git a/src/x11/x.c b/src/x11/x.c index b0130ab..1c0310f 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -23,6 +23,7 @@ #include #include +#include "src/draw.h" #include "src/dbus.h" #include "src/dunst.h" #include "src/icon.h" @@ -148,6 +149,12 @@ static void x_cairo_setup(void) cairo_ctx.desc = pango_font_description_from_string(settings.font); } +cairo_surface_t *x_create_cairo_surface(void) +{ + return cairo_xlib_surface_create(xctx.dpy, + xctx.win, DefaultVisual(xctx.dpy, 0), WIDTH, HEIGHT); +} + static void r_setup_pango_layout(PangoLayout *layout, int width) { pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); @@ -725,7 +732,7 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer switch (ev.type) { case Expose: if (ev.xexpose.count == 0 && xctx.visible) { - x_win_draw(); + draw(); } break; case SelectionNotify: @@ -790,7 +797,7 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer */ && xctx.visible && get_active_screen()->scr != xctx.cur_screen) { - x_win_draw(); + draw(); } break; default: diff --git a/src/x11/x.h b/src/x11/x.h index 8ee757a..b6ac16e 100644 --- a/src/x11/x.h +++ b/src/x11/x.h @@ -2,6 +2,7 @@ #ifndef DUNST_X_H #define DUNST_X_H +#include #include #include #include @@ -59,6 +60,8 @@ bool x_is_idle(void); void x_setup(void); void x_free(void); +cairo_surface_t *x_create_cairo_surface(void); + gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); gboolean x_mainloop_fd_check(GSource *source);