diff --git a/src/draw.c b/src/draw.c index a670fe2..f6487ae 100644 --- a/src/draw.c +++ b/src/draw.c @@ -555,7 +555,7 @@ static void calc_window_pos(int width, int height, int *ret_x, int *ret_y) void draw(void) { - GSList *layouts = create_layouts(win->c_ctx); + GSList *layouts = create_layouts(x_win_get_context(win)); struct dimensions dim = calculate_dimensions(layouts); diff --git a/src/dunst.c b/src/dunst.c index 081e2f3..8b6ae46 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -51,19 +51,19 @@ static gboolean run(void *data) static gint64 next_timeout = 0; - if (!win->visible && queues_length_displayed() > 0) { - x_win_show(); + if (!x_win_visible(win) && queues_length_displayed() > 0) { + x_win_show(win); } - if (win->visible && queues_length_displayed() == 0) { - x_win_hide(); + if (x_win_visible(win) && queues_length_displayed() == 0) { + x_win_hide(win); } - if (win->visible) { + if (x_win_visible(win)) { draw(); } - if (win->visible) { + if (x_win_visible(win)) { gint64 now = time_monotonic_now(); gint64 sleep = queues_get_next_datachange(now); gint64 timeout_at = now + sleep; diff --git a/src/x11/x.c b/src/x11/x.c index e298548..a559fbf 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -33,10 +33,19 @@ #define WIDTH 400 #define HEIGHT 400 +struct window_x11 { + Window xwin; + cairo_surface_t *root_surface; + cairo_t *c_ctx; + GSource *esrc; + int cur_screen; + bool visible; + struct dimensions dim; +}; + struct x11_source { GSource source; - Display *dpy; - Window w; + window_x11 *win; }; xctx_t xctx; @@ -84,6 +93,16 @@ void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimen } +bool x_win_visible(window_x11 *win) +{ + return win->visible; +} + +cairo_t* x_win_get_context(window_x11 *win) +{ + return win->c_ctx; +} + static void setopacity(Window win, unsigned long opacity) { Atom _NET_WM_WINDOW_OPACITY = @@ -176,6 +195,8 @@ gboolean x_mainloop_fd_check(GSource *source) */ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { + window_x11 *win = ((struct x11_source*) source)->win; + bool fullscreen_now; screen_info *scr; XEvent ev; @@ -481,8 +502,7 @@ GSource* x_win_reg_source(window_x11 *win) struct x11_source *xsrc = (struct x11_source*) g_source_new(&xsrc_fn, sizeof(struct x11_source)); - xsrc->dpy = xctx.dpy; - xsrc->w = win->xwin; + xsrc->win = win; g_source_add_unix_fd((GSource*) xsrc, xctx.dpy->fd, G_IO_IN | G_IO_HUP | G_IO_ERR); @@ -561,7 +581,7 @@ void x_win_destroy(window_x11 *win) /* * Show the window and grab shortcuts. */ -void x_win_show(void) +void x_win_show(window_x11 *win) { /* window is already mapped or there's nothing to show */ if (win->visible || queues_length_displayed() == 0) { @@ -594,7 +614,7 @@ void x_win_show(void) /* * Hide the window and ungrab unused keyboard_shortcuts */ -void x_win_hide(void) +void x_win_hide(window_x11 *win) { x_shortcut_ungrab(&settings.close_ks); x_shortcut_ungrab(&settings.close_all_ks); diff --git a/src/x11/x.h b/src/x11/x.h index df1e100..f32fefa 100644 --- a/src/x11/x.h +++ b/src/x11/x.h @@ -24,6 +24,8 @@ typedef struct _keyboard_shortcut { // Cyclical dependency #include "src/settings.h" +typedef struct window_x11 window_x11; + struct dimensions { int x; int y; @@ -31,16 +33,6 @@ struct dimensions { int h; }; -typedef struct { - Window xwin; - cairo_surface_t *root_surface; - cairo_t *c_ctx; - GSource *esrc; - int cur_screen; - bool visible; - struct dimensions dim; -} window_x11; - typedef struct _xctx { Display *dpy; const char *colors[3][3]; @@ -57,11 +49,16 @@ extern xctx_t xctx; /* window */ window_x11 *x_win_create(void); -void x_win_hide(void); -void x_win_show(void); void x_win_destroy(window_x11 *win); + +void x_win_show(window_x11 *win); +void x_win_hide(window_x11 *win); + void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimensions *dim); +bool x_win_visible(window_x11 *win); +cairo_t* x_win_get_context(window_x11 *win); + /* X misc */ bool x_is_idle(void); void x_setup(void);