Move window-related fields to dedicated struct
The first step in allowing dunst to have multiple windows.
This commit is contained in:
parent
ce5c49f0e8
commit
a2863d5312
10
src/dunst.c
10
src/dunst.c
@ -59,19 +59,19 @@ static gboolean run(void *data)
|
|||||||
|
|
||||||
static gint64 next_timeout = 0;
|
static gint64 next_timeout = 0;
|
||||||
|
|
||||||
if (!xctx.visible && queues_length_displayed() > 0) {
|
if (!xctx.win.visible && queues_length_displayed() > 0) {
|
||||||
x_win_show();
|
x_win_show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xctx.visible && queues_length_displayed() == 0) {
|
if (xctx.win.visible && queues_length_displayed() == 0) {
|
||||||
x_win_hide();
|
x_win_hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xctx.visible) {
|
if (xctx.win.visible) {
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xctx.visible) {
|
if (xctx.win.visible) {
|
||||||
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;
|
||||||
@ -190,7 +190,7 @@ int dunst_main(int argc, char *argv[])
|
|||||||
GSource *x11_source =
|
GSource *x11_source =
|
||||||
g_source_new(&x11_source_funcs, sizeof(x11_source_t));
|
g_source_new(&x11_source_funcs, sizeof(x11_source_t));
|
||||||
((x11_source_t *) x11_source)->dpy = xctx.dpy;
|
((x11_source_t *) x11_source)->dpy = xctx.dpy;
|
||||||
((x11_source_t *) x11_source)->w = xctx.win;
|
((x11_source_t *) x11_source)->w = xctx.win.xwin;
|
||||||
g_source_add_poll(x11_source, &dpy_pollfd);
|
g_source_add_poll(x11_source, &dpy_pollfd);
|
||||||
|
|
||||||
g_source_attach(x11_source, NULL);
|
g_source_attach(x11_source, NULL);
|
||||||
|
36
src/x11/x.c
36
src/x11/x.c
@ -48,7 +48,7 @@ static void x_win_setup(void);
|
|||||||
cairo_surface_t *x_create_cairo_surface(void)
|
cairo_surface_t *x_create_cairo_surface(void)
|
||||||
{
|
{
|
||||||
return cairo_xlib_surface_create(xctx.dpy,
|
return cairo_xlib_surface_create(xctx.dpy,
|
||||||
xctx.win, DefaultVisual(xctx.dpy, 0), WIDTH, HEIGHT);
|
xctx.win.xwin, DefaultVisual(xctx.dpy, 0), WIDTH, HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void x_win_move(int width, int height)
|
void x_win_move(int width, int height)
|
||||||
@ -59,7 +59,7 @@ void x_win_move(int width, int height)
|
|||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
screen_info *scr = get_active_screen();
|
screen_info *scr = get_active_screen();
|
||||||
xctx.cur_screen = scr->id;
|
xctx.win.cur_screen = scr->id;
|
||||||
|
|
||||||
/* calculate window position */
|
/* calculate window position */
|
||||||
if (settings.geometry.negative_x) {
|
if (settings.geometry.negative_x) {
|
||||||
@ -76,10 +76,10 @@ void x_win_move(int width, int height)
|
|||||||
|
|
||||||
/* move and resize */
|
/* move and resize */
|
||||||
if (x != window_dim.x || y != window_dim.y) {
|
if (x != window_dim.x || y != window_dim.y) {
|
||||||
XMoveWindow(xctx.dpy, xctx.win, x, y);
|
XMoveWindow(xctx.dpy, xctx.win.xwin, x, y);
|
||||||
}
|
}
|
||||||
if (width != window_dim.w || height != window_dim.h) {
|
if (width != window_dim.w || height != window_dim.h) {
|
||||||
XResizeWindow(xctx.dpy, xctx.win, width, height);
|
XResizeWindow(xctx.dpy, xctx.win.xwin, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
window_dim.x = x;
|
window_dim.x = x;
|
||||||
@ -189,12 +189,12 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer
|
|||||||
|
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case Expose:
|
case Expose:
|
||||||
if (ev.xexpose.count == 0 && xctx.visible) {
|
if (ev.xexpose.count == 0 && xctx.win.visible) {
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
if (ev.xbutton.window == xctx.win) {
|
if (ev.xbutton.window == xctx.win.xwin) {
|
||||||
x_handle_click(ev);
|
x_handle_click(ev);
|
||||||
wake_up();
|
wake_up();
|
||||||
}
|
}
|
||||||
@ -250,8 +250,8 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer
|
|||||||
* same screen. PropertyNotify is only neccessary
|
* same screen. PropertyNotify is only neccessary
|
||||||
* to detect a focus change to another screen
|
* to detect a focus change to another screen
|
||||||
*/
|
*/
|
||||||
&& xctx.visible
|
&& xctx.win.visible
|
||||||
&& get_active_screen()->id != xctx.cur_screen) {
|
&& get_active_screen()->id != xctx.win.cur_screen) {
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -477,7 +477,7 @@ static void x_win_setup(void)
|
|||||||
ButtonReleaseMask | FocusChangeMask| StructureNotifyMask;
|
ButtonReleaseMask | FocusChangeMask| StructureNotifyMask;
|
||||||
|
|
||||||
screen_info *scr = get_active_screen();
|
screen_info *scr = get_active_screen();
|
||||||
xctx.win = XCreateWindow(xctx.dpy,
|
xctx.win.xwin = XCreateWindow(xctx.dpy,
|
||||||
root,
|
root,
|
||||||
scr->x,
|
scr->x,
|
||||||
scr->y,
|
scr->y,
|
||||||
@ -490,10 +490,10 @@ static void x_win_setup(void)
|
|||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask,
|
CWOverrideRedirect | CWBackPixmap | CWEventMask,
|
||||||
&wa);
|
&wa);
|
||||||
|
|
||||||
x_set_wm(xctx.win);
|
x_set_wm(xctx.win.xwin);
|
||||||
settings.transparency =
|
settings.transparency =
|
||||||
settings.transparency > 100 ? 100 : settings.transparency;
|
settings.transparency > 100 ? 100 : settings.transparency;
|
||||||
setopacity(xctx.win,
|
setopacity(xctx.win.xwin,
|
||||||
(unsigned long)((100 - settings.transparency) *
|
(unsigned long)((100 - settings.transparency) *
|
||||||
(0xffffffff / 100)));
|
(0xffffffff / 100)));
|
||||||
|
|
||||||
@ -509,7 +509,7 @@ static void x_win_setup(void)
|
|||||||
void x_win_show(void)
|
void x_win_show(void)
|
||||||
{
|
{
|
||||||
/* window is already mapped or there's nothing to show */
|
/* window is already mapped or there's nothing to show */
|
||||||
if (xctx.visible || queues_length_displayed() == 0) {
|
if (xctx.win.visible || queues_length_displayed() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +521,7 @@ void x_win_show(void)
|
|||||||
XGrabButton(xctx.dpy,
|
XGrabButton(xctx.dpy,
|
||||||
AnyButton,
|
AnyButton,
|
||||||
AnyModifier,
|
AnyModifier,
|
||||||
xctx.win,
|
xctx.win.xwin,
|
||||||
false,
|
false,
|
||||||
BUTTONMASK,
|
BUTTONMASK,
|
||||||
GrabModeAsync,
|
GrabModeAsync,
|
||||||
@ -532,8 +532,8 @@ void x_win_show(void)
|
|||||||
LOG_W("Unable to grab mouse button(s).");
|
LOG_W("Unable to grab mouse button(s).");
|
||||||
}
|
}
|
||||||
|
|
||||||
XMapRaised(xctx.dpy, xctx.win);
|
XMapRaised(xctx.dpy, xctx.win.xwin);
|
||||||
xctx.visible = true;
|
xctx.win.visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -545,10 +545,10 @@ void x_win_hide(void)
|
|||||||
x_shortcut_ungrab(&settings.close_all_ks);
|
x_shortcut_ungrab(&settings.close_all_ks);
|
||||||
x_shortcut_ungrab(&settings.context_ks);
|
x_shortcut_ungrab(&settings.context_ks);
|
||||||
|
|
||||||
XUngrabButton(xctx.dpy, AnyButton, AnyModifier, xctx.win);
|
XUngrabButton(xctx.dpy, AnyButton, AnyModifier, xctx.win.xwin);
|
||||||
XUnmapWindow(xctx.dpy, xctx.win);
|
XUnmapWindow(xctx.dpy, xctx.win.xwin);
|
||||||
XFlush(xctx.dpy);
|
XFlush(xctx.dpy);
|
||||||
xctx.visible = false;
|
xctx.win.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
12
src/x11/x.h
12
src/x11/x.h
@ -33,11 +33,17 @@ struct dimensions {
|
|||||||
int h;
|
int h;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Window xwin;
|
||||||
|
cairo_surface_t *root_surface;
|
||||||
|
int cur_screen;
|
||||||
|
bool visible;
|
||||||
|
struct dimensions dim;
|
||||||
|
} window_x11;
|
||||||
|
|
||||||
typedef struct _xctx {
|
typedef struct _xctx {
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
int cur_screen;
|
window_x11 win;
|
||||||
Window win;
|
|
||||||
bool visible;
|
|
||||||
const char *colors[3][3];
|
const char *colors[3][3];
|
||||||
XScreenSaverInfo *screensaver_info;
|
XScreenSaverInfo *screensaver_info;
|
||||||
} xctx_t;
|
} xctx_t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user