Refactor window_x11 struct to be opaque
This removes window accesses from outside the x.c file which will allow us to abstract the window struct to implement multiple outputs in the future.
This commit is contained in:
parent
54face5956
commit
4891710af3
@ -555,7 +555,7 @@ static void calc_window_pos(int width, int height, int *ret_x, int *ret_y)
|
|||||||
void draw(void)
|
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);
|
struct dimensions dim = calculate_dimensions(layouts);
|
||||||
|
|
||||||
|
12
src/dunst.c
12
src/dunst.c
@ -51,19 +51,19 @@ static gboolean run(void *data)
|
|||||||
|
|
||||||
static gint64 next_timeout = 0;
|
static gint64 next_timeout = 0;
|
||||||
|
|
||||||
if (!win->visible && queues_length_displayed() > 0) {
|
if (!x_win_visible(win) && queues_length_displayed() > 0) {
|
||||||
x_win_show();
|
x_win_show(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (win->visible && queues_length_displayed() == 0) {
|
if (x_win_visible(win) && queues_length_displayed() == 0) {
|
||||||
x_win_hide();
|
x_win_hide(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (win->visible) {
|
if (x_win_visible(win)) {
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (win->visible) {
|
if (x_win_visible(win)) {
|
||||||
gint64 now = time_monotonic_now();
|
gint64 now = time_monotonic_now();
|
||||||
gint64 sleep = queues_get_next_datachange(now);
|
gint64 sleep = queues_get_next_datachange(now);
|
||||||
gint64 timeout_at = now + sleep;
|
gint64 timeout_at = now + sleep;
|
||||||
|
32
src/x11/x.c
32
src/x11/x.c
@ -33,10 +33,19 @@
|
|||||||
#define WIDTH 400
|
#define WIDTH 400
|
||||||
#define HEIGHT 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 {
|
struct x11_source {
|
||||||
GSource source;
|
GSource source;
|
||||||
Display *dpy;
|
window_x11 *win;
|
||||||
Window w;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
xctx_t xctx;
|
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)
|
static void setopacity(Window win, unsigned long opacity)
|
||||||
{
|
{
|
||||||
Atom _NET_WM_WINDOW_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)
|
gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
window_x11 *win = ((struct x11_source*) source)->win;
|
||||||
|
|
||||||
bool fullscreen_now;
|
bool fullscreen_now;
|
||||||
screen_info *scr;
|
screen_info *scr;
|
||||||
XEvent ev;
|
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,
|
struct x11_source *xsrc = (struct x11_source*) g_source_new(&xsrc_fn,
|
||||||
sizeof(struct x11_source));
|
sizeof(struct x11_source));
|
||||||
|
|
||||||
xsrc->dpy = xctx.dpy;
|
xsrc->win = win;
|
||||||
xsrc->w = win->xwin;
|
|
||||||
|
|
||||||
g_source_add_unix_fd((GSource*) xsrc, xctx.dpy->fd, G_IO_IN | G_IO_HUP | G_IO_ERR);
|
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.
|
* 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 */
|
/* window is already mapped or there's nothing to show */
|
||||||
if (win->visible || queues_length_displayed() == 0) {
|
if (win->visible || queues_length_displayed() == 0) {
|
||||||
@ -594,7 +614,7 @@ void x_win_show(void)
|
|||||||
/*
|
/*
|
||||||
* Hide the window and ungrab unused keyboard_shortcuts
|
* 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_ks);
|
||||||
x_shortcut_ungrab(&settings.close_all_ks);
|
x_shortcut_ungrab(&settings.close_all_ks);
|
||||||
|
21
src/x11/x.h
21
src/x11/x.h
@ -24,6 +24,8 @@ typedef struct _keyboard_shortcut {
|
|||||||
// Cyclical dependency
|
// Cyclical dependency
|
||||||
#include "src/settings.h"
|
#include "src/settings.h"
|
||||||
|
|
||||||
|
typedef struct window_x11 window_x11;
|
||||||
|
|
||||||
struct dimensions {
|
struct dimensions {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
@ -31,16 +33,6 @@ struct dimensions {
|
|||||||
int h;
|
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 {
|
typedef struct _xctx {
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
const char *colors[3][3];
|
const char *colors[3][3];
|
||||||
@ -57,11 +49,16 @@ extern xctx_t xctx;
|
|||||||
|
|
||||||
/* window */
|
/* window */
|
||||||
window_x11 *x_win_create(void);
|
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_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);
|
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 */
|
/* X misc */
|
||||||
bool x_is_idle(void);
|
bool x_is_idle(void);
|
||||||
void x_setup(void);
|
void x_setup(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user