Setup initial file for draw.c
Setup the initial template for draw.c to be between X11 calls and the rest of the codebase. This prepares the file to move all the drawing related function here in the next commit.
This commit is contained in:
parent
52055f12c7
commit
045ec98c0e
50
src/draw.c
Normal file
50
src/draw.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include "draw.h"
|
||||
|
||||
#include <cairo.h>
|
||||
#include <pango/pango-attributes.h>
|
||||
#include <pango/pango-font.h>
|
||||
#include <pango/pango-layout.h>
|
||||
#include <pango/pango-types.h>
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
#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: */
|
11
src/draw.h
Normal file
11
src/draw.h
Normal file
@ -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: */
|
@ -13,6 +13,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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();
|
||||
|
11
src/x11/x.c
11
src/x11/x.c
@ -23,6 +23,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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:
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifndef DUNST_X_H
|
||||
#define DUNST_X_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/scrnsaver.h>
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user