removed the rest of old drawing code
This commit is contained in:
parent
c2032b9cc6
commit
ced9186cf1
4
dunst.c
4
dunst.c
@ -281,7 +281,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
mainloop = g_main_loop_new(NULL, FALSE);
|
mainloop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
GPollFD dpy_pollfd = { xctx.dc->dpy->fd,
|
GPollFD dpy_pollfd = { xctx.dpy->fd,
|
||||||
G_IO_IN | G_IO_HUP | G_IO_ERR, 0
|
G_IO_IN | G_IO_HUP | G_IO_ERR, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ int 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.dc->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;
|
||||||
g_source_add_poll(x11_source, &dpy_pollfd);
|
g_source_add_poll(x11_source, &dpy_pollfd);
|
||||||
|
|
||||||
|
1
dunst.h
1
dunst.h
@ -26,7 +26,6 @@ extern GQueue *history;
|
|||||||
extern GSList *rules;
|
extern GSList *rules;
|
||||||
extern bool pause_display;
|
extern bool pause_display;
|
||||||
extern const char *color_strings[2][3];
|
extern const char *color_strings[2][3];
|
||||||
extern DC *dc;
|
|
||||||
|
|
||||||
/* return id of notification */
|
/* return id of notification */
|
||||||
gboolean run(void *data);
|
gboolean run(void *data);
|
||||||
|
@ -305,8 +305,6 @@ int notification_init(notification * n, int id)
|
|||||||
bg = xctx.color_strings[ColBG][n->urgency];
|
bg = xctx.color_strings[ColBG][n->urgency];
|
||||||
}
|
}
|
||||||
|
|
||||||
n->colors = initcolor(xctx.dc, fg, bg);
|
|
||||||
|
|
||||||
n->timeout =
|
n->timeout =
|
||||||
n->timeout == -1 ? settings.timeouts[n->urgency] : n->timeout;
|
n->timeout == -1 ? settings.timeouts[n->urgency] : n->timeout;
|
||||||
n->start = 0;
|
n->start = 0;
|
||||||
|
@ -29,7 +29,7 @@ typedef struct _notification {
|
|||||||
bool redisplayed; /* has been displayed before? */
|
bool redisplayed; /* has been displayed before? */
|
||||||
int id;
|
int id;
|
||||||
int dup_count;
|
int dup_count;
|
||||||
ColorSet *colors;
|
int displayed_height;
|
||||||
char *color_strings[2];
|
char *color_strings[2];
|
||||||
|
|
||||||
int progress; /* percentage + 1, 0 to hide */
|
int progress; /* percentage + 1, 0 to hide */
|
||||||
|
253
x.c
253
x.c
@ -1,34 +1,4 @@
|
|||||||
/*
|
/* copyright 2013 Sascha Kruse and contributors (see LICENSE for licensing information) */
|
||||||
MIT/X Consortium License
|
|
||||||
|
|
||||||
© 2013 Sascha Kruse <knopwob@googlemail.com> and contributors
|
|
||||||
© 2010-2011 Connor Lane Smith <cls@lubutu.com>
|
|
||||||
© 2006-2011 Anselm R Garbe <anselm@garbe.us>
|
|
||||||
© 2009 Gottox <gottox@s01.de>
|
|
||||||
© 2009 Markus Schnalke <meillo@marmaro.de>
|
|
||||||
© 2009 Evan Gates <evan.gates@gmail.com>
|
|
||||||
© 2006-2008 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
|
||||||
© 2006-2007 Michał Janeczek <janeczek at gmail dot com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
|
||||||
copy of this software and associated documentation files (the "Software"),
|
|
||||||
to deal in the Software without restriction, including without limitation
|
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -72,8 +42,8 @@ static void x_win_move(int width, int height);
|
|||||||
|
|
||||||
void x_cairo_setup(void)
|
void x_cairo_setup(void)
|
||||||
{
|
{
|
||||||
cairo_ctx.surface = cairo_xlib_surface_create(xctx.dc->dpy,
|
cairo_ctx.surface = cairo_xlib_surface_create(xctx.dpy,
|
||||||
xctx.win, DefaultVisual(xctx.dc->dpy, 0), WIDTH, HEIGHT);
|
xctx.win, DefaultVisual(xctx.dpy, 0), WIDTH, HEIGHT);
|
||||||
|
|
||||||
cairo_ctx.desc = pango_font_description_from_string(settings.font);
|
cairo_ctx.desc = pango_font_description_from_string(settings.font);
|
||||||
}
|
}
|
||||||
@ -116,6 +86,9 @@ PangoLayout *r_create_layout_from_notification(cairo_t *c, notification *n)
|
|||||||
|
|
||||||
pango_layout_set_text(layout, n->text_to_render, -1);
|
pango_layout_set_text(layout, n->text_to_render, -1);
|
||||||
|
|
||||||
|
pango_layout_get_pixel_size(layout, NULL, &(n->displayed_height));
|
||||||
|
n->displayed_height += 2 * settings.padding;
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +143,7 @@ void x_win_draw(void)
|
|||||||
|
|
||||||
printf("(%d,%d)[%d]\n", width, height, settings.separator_height);
|
printf("(%d,%d)[%d]\n", width, height, settings.separator_height);
|
||||||
|
|
||||||
XResizeWindow(xctx.dc->dpy, xctx.win, width, height);
|
XResizeWindow(xctx.dpy, xctx.win, width, height);
|
||||||
|
|
||||||
/* FIXME frame color */
|
/* FIXME frame color */
|
||||||
cairo_set_source_rgb(c, 0.0, 0.0, 0.8);
|
cairo_set_source_rgb(c, 0.0, 0.0, 0.8);
|
||||||
@ -262,7 +235,7 @@ static void x_win_move(int width, int height)
|
|||||||
if (x != xctx.window_dim.x || y != xctx.window_dim.y
|
if (x != xctx.window_dim.x || y != xctx.window_dim.y
|
||||||
|| width != xctx.window_dim.w || height != xctx.window_dim.h) {
|
|| width != xctx.window_dim.w || height != xctx.window_dim.h) {
|
||||||
|
|
||||||
XMoveWindow(xctx.dc->dpy, xctx.win, x, y);
|
XMoveWindow(xctx.dpy, xctx.win, x, y);
|
||||||
|
|
||||||
xctx.window_dim.x = x;
|
xctx.window_dim.x = x;
|
||||||
xctx.window_dim.y = y;
|
xctx.window_dim.y = y;
|
||||||
@ -287,95 +260,11 @@ void eprintf(const char *fmt, ...)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void freecol(DC * dc, ColorSet * col)
|
void setopacity(Window win, unsigned long opacity)
|
||||||
{
|
|
||||||
if (col) {
|
|
||||||
if (&col->FG_xft)
|
|
||||||
XftColorFree(dc->dpy,
|
|
||||||
DefaultVisual(dc->dpy,
|
|
||||||
DefaultScreen(dc->dpy)),
|
|
||||||
DefaultColormap(dc->dpy,
|
|
||||||
DefaultScreen(dc->dpy)),
|
|
||||||
&col->FG_xft);
|
|
||||||
free(col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void freedc(DC * dc)
|
|
||||||
{
|
|
||||||
if (dc->font.xft_font) {
|
|
||||||
XftFontClose(dc->dpy, dc->font.xft_font);
|
|
||||||
XftDrawDestroy(dc->xftdraw);
|
|
||||||
}
|
|
||||||
if (dc->font.set)
|
|
||||||
XFreeFontSet(dc->dpy, dc->font.set);
|
|
||||||
if (dc->font.xfont)
|
|
||||||
XFreeFont(dc->dpy, dc->font.xfont);
|
|
||||||
if (dc->canvas)
|
|
||||||
XFreePixmap(dc->dpy, dc->canvas);
|
|
||||||
if (dc->gc)
|
|
||||||
XFreeGC(dc->dpy, dc->gc);
|
|
||||||
if (dc->dpy)
|
|
||||||
XCloseDisplay(dc->dpy);
|
|
||||||
if (dc)
|
|
||||||
free(dc);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long getcolor(DC * dc, const char *colstr)
|
|
||||||
{
|
|
||||||
Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
|
|
||||||
XColor color;
|
|
||||||
|
|
||||||
if (!XAllocNamedColor(dc->dpy, cmap, colstr, &color, &color))
|
|
||||||
eprintf("cannot allocate color '%s'\n", colstr);
|
|
||||||
return color.pixel;
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorSet *initcolor(DC * dc, const char *foreground, const char *background)
|
|
||||||
{
|
|
||||||
ColorSet *col = (ColorSet *) malloc(sizeof(ColorSet));
|
|
||||||
if (!col) {
|
|
||||||
eprintf("error, cannot allocate memory for color set");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
col->BG = getcolor(dc, background);
|
|
||||||
col->FG = getcolor(dc, foreground);
|
|
||||||
if (dc->font.xft_font)
|
|
||||||
if (!XftColorAllocName
|
|
||||||
(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
|
|
||||||
DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)),
|
|
||||||
foreground, &col->FG_xft))
|
|
||||||
eprintf("error, cannot allocate xft font color '%s'\n",
|
|
||||||
foreground);
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
|
|
||||||
DC *initdc(void)
|
|
||||||
{
|
|
||||||
DC *dc;
|
|
||||||
|
|
||||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
|
||||||
fputs("no locale support\n", stderr);
|
|
||||||
if (!(dc = calloc(1, sizeof *dc))) {
|
|
||||||
eprintf("cannot malloc %u bytes:", sizeof *dc);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(dc->dpy = XOpenDisplay(NULL))) {
|
|
||||||
eprintf("cannot open display\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL);
|
|
||||||
XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter);
|
|
||||||
return dc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setopacity(DC * dc, Window win, unsigned long opacity)
|
|
||||||
{
|
{
|
||||||
Atom _NET_WM_WINDOW_OPACITY =
|
Atom _NET_WM_WINDOW_OPACITY =
|
||||||
XInternAtom(dc->dpy, "_NET_WM_WINDOW_OPACITY", false);
|
XInternAtom(xctx.dpy, "_NET_WM_WINDOW_OPACITY", false);
|
||||||
XChangeProperty(dc->dpy, win, _NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32,
|
XChangeProperty(xctx.dpy, win, _NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32,
|
||||||
PropModeReplace, (unsigned char *)&opacity, 1L);
|
PropModeReplace, (unsigned char *)&opacity, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,7 +291,7 @@ gboolean x_mainloop_fd_prepare(GSource * source, gint * timeout)
|
|||||||
*/
|
*/
|
||||||
gboolean x_mainloop_fd_check(GSource * source)
|
gboolean x_mainloop_fd_check(GSource * source)
|
||||||
{
|
{
|
||||||
return XPending(xctx.dc->dpy) > 0;
|
return XPending(xctx.dpy) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -412,8 +301,8 @@ gboolean x_mainloop_fd_dispatch(GSource * source, GSourceFunc callback,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
while (XPending(xctx.dc->dpy) > 0) {
|
while (XPending(xctx.dpy) > 0) {
|
||||||
XNextEvent(xctx.dc->dpy, &ev);
|
XNextEvent(xctx.dpy, &ev);
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case Expose:
|
case Expose:
|
||||||
if (ev.xexpose.count == 0 && xctx.visible) {
|
if (ev.xexpose.count == 0 && xctx.visible) {
|
||||||
@ -424,7 +313,7 @@ gboolean x_mainloop_fd_dispatch(GSource * source, GSourceFunc callback,
|
|||||||
break;
|
break;
|
||||||
case VisibilityNotify:
|
case VisibilityNotify:
|
||||||
if (ev.xvisibility.state != VisibilityUnobscured)
|
if (ev.xvisibility.state != VisibilityUnobscured)
|
||||||
XRaiseWindow(xctx.dc->dpy, xctx.win);
|
XRaiseWindow(xctx.dpy, xctx.win);
|
||||||
break;
|
break;
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
if (ev.xbutton.window == xctx.win) {
|
if (ev.xbutton.window == xctx.win) {
|
||||||
@ -471,7 +360,7 @@ gboolean x_mainloop_fd_dispatch(GSource * source, GSourceFunc callback,
|
|||||||
*/
|
*/
|
||||||
bool x_is_idle(void)
|
bool x_is_idle(void)
|
||||||
{
|
{
|
||||||
XScreenSaverQueryInfo(xctx.dc->dpy, DefaultRootWindow(xctx.dc->dpy),
|
XScreenSaverQueryInfo(xctx.dpy, DefaultRootWindow(xctx.dpy),
|
||||||
xctx.screensaver_info);
|
xctx.screensaver_info);
|
||||||
if (settings.idle_threshold == 0) {
|
if (settings.idle_threshold == 0) {
|
||||||
return false;
|
return false;
|
||||||
@ -494,20 +383,16 @@ void x_handle_click(XEvent ev)
|
|||||||
if (ev.xbutton.button == Button1) {
|
if (ev.xbutton.button == Button1) {
|
||||||
int y = settings.separator_height;
|
int y = settings.separator_height;
|
||||||
notification *n = NULL;
|
notification *n = NULL;
|
||||||
|
int first = true;
|
||||||
for (GList * iter = g_queue_peek_head_link(displayed); iter;
|
for (GList * iter = g_queue_peek_head_link(displayed); iter;
|
||||||
iter = iter->next) {
|
iter = iter->next) {
|
||||||
n = iter->data;
|
n = iter->data;
|
||||||
int text_h =
|
if (ev.xbutton.y > y && ev.xbutton.y < y + n->displayed_height)
|
||||||
MAX(xctx.font_h,
|
|
||||||
settings.line_height) * n->line_count;
|
|
||||||
int padding = 2 * settings.h_padding;
|
|
||||||
|
|
||||||
int height = text_h + padding;
|
|
||||||
|
|
||||||
if (ev.xbutton.y > y && ev.xbutton.y < y + height)
|
|
||||||
break;
|
break;
|
||||||
else
|
|
||||||
y += height + settings.separator_height;
|
y += n->displayed_height + settings.separator_height;
|
||||||
|
if (first)
|
||||||
|
y += settings.frame_width;
|
||||||
}
|
}
|
||||||
if (n)
|
if (n)
|
||||||
notification_close(n, 2);
|
notification_close(n, 2);
|
||||||
@ -525,11 +410,11 @@ Window get_focused_window(void)
|
|||||||
int format;
|
int format;
|
||||||
unsigned long nitems, bytes_after;
|
unsigned long nitems, bytes_after;
|
||||||
unsigned char *prop_return = NULL;
|
unsigned char *prop_return = NULL;
|
||||||
Window root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
Window root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
|
||||||
Atom netactivewindow =
|
Atom netactivewindow =
|
||||||
XInternAtom(xctx.dc->dpy, "_NET_ACTIVE_WINDOW", false);
|
XInternAtom(xctx.dpy, "_NET_ACTIVE_WINDOW", false);
|
||||||
|
|
||||||
XGetWindowProperty(xctx.dc->dpy, root, netactivewindow, 0L,
|
XGetWindowProperty(xctx.dpy, root, netactivewindow, 0L,
|
||||||
sizeof(Window), false, XA_WINDOW,
|
sizeof(Window), false, XA_WINDOW,
|
||||||
&type, &format, &nitems, &bytes_after, &prop_return);
|
&type, &format, &nitems, &bytes_after, &prop_return);
|
||||||
if (prop_return) {
|
if (prop_return) {
|
||||||
@ -549,21 +434,21 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
|||||||
{
|
{
|
||||||
if (settings.f_mode == FOLLOW_NONE) {
|
if (settings.f_mode == FOLLOW_NONE) {
|
||||||
return settings.monitor >=
|
return settings.monitor >=
|
||||||
0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
0 ? settings.monitor : XDefaultScreen(xctx.dpy);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int x, y;
|
int x, y;
|
||||||
assert(settings.f_mode == FOLLOW_MOUSE
|
assert(settings.f_mode == FOLLOW_MOUSE
|
||||||
|| settings.f_mode == FOLLOW_KEYBOARD);
|
|| settings.f_mode == FOLLOW_KEYBOARD);
|
||||||
Window root =
|
Window root =
|
||||||
RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
|
||||||
|
|
||||||
if (settings.f_mode == FOLLOW_MOUSE) {
|
if (settings.f_mode == FOLLOW_MOUSE) {
|
||||||
int dummy;
|
int dummy;
|
||||||
unsigned int dummy_ui;
|
unsigned int dummy_ui;
|
||||||
Window dummy_win;
|
Window dummy_win;
|
||||||
|
|
||||||
XQueryPointer(xctx.dc->dpy, root, &dummy_win,
|
XQueryPointer(xctx.dpy, root, &dummy_win,
|
||||||
&dummy_win, &x, &y, &dummy,
|
&dummy_win, &x, &y, &dummy,
|
||||||
&dummy, &dummy_ui);
|
&dummy, &dummy_ui);
|
||||||
}
|
}
|
||||||
@ -575,13 +460,11 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
|||||||
if (focused == 0) {
|
if (focused == 0) {
|
||||||
/* something went wrong. Fallback to default */
|
/* something went wrong. Fallback to default */
|
||||||
return settings.monitor >=
|
return settings.monitor >=
|
||||||
0 ? settings.monitor : XDefaultScreen(xctx.
|
0 ? settings.monitor : XDefaultScreen(xctx.dpy);
|
||||||
dc->
|
|
||||||
dpy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window child_return;
|
Window child_return;
|
||||||
XTranslateCoordinates(xctx.dc->dpy, focused, root,
|
XTranslateCoordinates(xctx.dpy, focused, root,
|
||||||
0, 0, &x, &y, &child_return);
|
0, 0, &x, &y, &child_return);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,7 +478,7 @@ int select_screen(XineramaScreenInfo * info, int info_len)
|
|||||||
|
|
||||||
/* something seems to be wrong. Fallback to default */
|
/* something seems to be wrong. Fallback to default */
|
||||||
return settings.monitor >=
|
return settings.monitor >=
|
||||||
0 ? settings.monitor : XDefaultScreen(xctx.dc->dpy);
|
0 ? settings.monitor : XDefaultScreen(xctx.dpy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -609,7 +492,7 @@ void x_screen_info(screen_info * scr)
|
|||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
int n;
|
int n;
|
||||||
XineramaScreenInfo *info;
|
XineramaScreenInfo *info;
|
||||||
if ((info = XineramaQueryScreens(xctx.dc->dpy, &n))) {
|
if ((info = XineramaQueryScreens(xctx.dpy, &n))) {
|
||||||
int screen = select_screen(info, n);
|
int screen = select_screen(info, n);
|
||||||
if (screen >= n) {
|
if (screen >= n) {
|
||||||
/* invalid monitor, fallback to default */
|
/* invalid monitor, fallback to default */
|
||||||
@ -630,10 +513,10 @@ void x_screen_info(screen_info * scr)
|
|||||||
if (settings.monitor >= 0)
|
if (settings.monitor >= 0)
|
||||||
screen = settings.monitor;
|
screen = settings.monitor;
|
||||||
else
|
else
|
||||||
screen = DefaultScreen(xctx.dc->dpy);
|
screen = DefaultScreen(xctx.dpy);
|
||||||
|
|
||||||
scr->dim.w = DisplayWidth(xctx.dc->dpy, screen);
|
scr->dim.w = DisplayWidth(xctx.dpy, screen);
|
||||||
scr->dim.h = DisplayHeight(xctx.dc->dpy, screen);
|
scr->dim.h = DisplayHeight(xctx.dpy, screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,7 +527,11 @@ void x_setup(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
/* initialize xctx.dc, font, keyboard, colors */
|
/* initialize xctx.dc, font, keyboard, colors */
|
||||||
xctx.dc = initdc();
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
|
fputs("no locale support\n", stderr);
|
||||||
|
if (!(xctx.dpy = XOpenDisplay(NULL))) {
|
||||||
|
die("cannot open display\n", EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
x_shortcut_init(&settings.close_ks);
|
x_shortcut_init(&settings.close_ks);
|
||||||
x_shortcut_init(&settings.close_all_ks);
|
x_shortcut_init(&settings.close_all_ks);
|
||||||
@ -668,15 +555,6 @@ void x_setup(void)
|
|||||||
xctx.color_strings[ColBG][NORM] = settings.normbgcolor;
|
xctx.color_strings[ColBG][NORM] = settings.normbgcolor;
|
||||||
xctx.color_strings[ColBG][CRIT] = settings.critbgcolor;
|
xctx.color_strings[ColBG][CRIT] = settings.critbgcolor;
|
||||||
|
|
||||||
xctx.framec = getcolor(xctx.dc, settings.frame_color);
|
|
||||||
|
|
||||||
if (settings.sep_color == CUSTOM) {
|
|
||||||
xctx.sep_custom_col =
|
|
||||||
getcolor(xctx.dc, settings.sep_custom_color_str);
|
|
||||||
} else {
|
|
||||||
xctx.sep_custom_col = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* parse and set xctx.geometry and monitor position */
|
/* parse and set xctx.geometry and monitor position */
|
||||||
if (settings.geom[0] == '-') {
|
if (settings.geom[0] == '-') {
|
||||||
xctx.geometry.negative_width = true;
|
xctx.geometry.negative_width = true;
|
||||||
@ -702,6 +580,8 @@ void x_setup(void)
|
|||||||
void x_win_setup(void)
|
void x_win_setup(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
printf("x_win_setup\n");
|
||||||
|
fflush(stdout);
|
||||||
Window root;
|
Window root;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
|
|
||||||
@ -710,9 +590,8 @@ void x_win_setup(void)
|
|||||||
xctx.window_dim.w = 0;
|
xctx.window_dim.w = 0;
|
||||||
xctx.window_dim.h = 0;
|
xctx.window_dim.h = 0;
|
||||||
|
|
||||||
root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
|
||||||
xctx.utf8 = XInternAtom(xctx.dc->dpy, "UTF8_STRING", false);
|
xctx.utf8 = XInternAtom(xctx.dpy, "UTF8_STRING", false);
|
||||||
xctx.font_h = xctx.dc->font.height + FONT_HEIGHT_BORDER;
|
|
||||||
|
|
||||||
wa.override_redirect = true;
|
wa.override_redirect = true;
|
||||||
wa.background_pixmap = ParentRelative;
|
wa.background_pixmap = ParentRelative;
|
||||||
@ -723,17 +602,15 @@ void x_win_setup(void)
|
|||||||
screen_info scr;
|
screen_info scr;
|
||||||
x_screen_info(&scr);
|
x_screen_info(&scr);
|
||||||
xctx.win =
|
xctx.win =
|
||||||
XCreateWindow(xctx.dc->dpy, root, scr.dim.x, scr.dim.y, scr.dim.w,
|
XCreateWindow(xctx.dpy, root, scr.dim.x, scr.dim.y, scr.dim.w,
|
||||||
xctx.font_h, 0, DefaultDepth(xctx.dc->dpy,
|
1, 0, DefaultDepth(xctx.dpy,
|
||||||
DefaultScreen(xctx.dc->
|
DefaultScreen(xctx.dpy)),
|
||||||
dpy)),
|
CopyFromParent, DefaultVisual(xctx.dpy,
|
||||||
CopyFromParent, DefaultVisual(xctx.dc->dpy,
|
DefaultScreen(xctx.dpy)),
|
||||||
DefaultScreen(xctx.dc->
|
|
||||||
dpy)),
|
|
||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
settings.transparency =
|
settings.transparency =
|
||||||
settings.transparency > 100 ? 100 : settings.transparency;
|
settings.transparency > 100 ? 100 : settings.transparency;
|
||||||
setopacity(xctx.dc, xctx.win,
|
setopacity(xctx.win,
|
||||||
(unsigned long)((100 - settings.transparency) *
|
(unsigned long)((100 - settings.transparency) *
|
||||||
(0xffffffff / 100)));
|
(0xffffffff / 100)));
|
||||||
}
|
}
|
||||||
@ -753,13 +630,13 @@ void x_win_show(void)
|
|||||||
x_shortcut_grab(&settings.context_ks);
|
x_shortcut_grab(&settings.context_ks);
|
||||||
|
|
||||||
x_shortcut_setup_error_handler();
|
x_shortcut_setup_error_handler();
|
||||||
XGrabButton(xctx.dc->dpy, AnyButton, AnyModifier, xctx.win, false,
|
XGrabButton(xctx.dpy, AnyButton, AnyModifier, xctx.win, false,
|
||||||
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||||
if (x_shortcut_tear_down_error_handler()) {
|
if (x_shortcut_tear_down_error_handler()) {
|
||||||
fprintf(stderr, "Unable to grab mouse button(s)\n");
|
fprintf(stderr, "Unable to grab mouse button(s)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
XMapRaised(xctx.dc->dpy, xctx.win);
|
XMapRaised(xctx.dpy, xctx.win);
|
||||||
xctx.visible = true;
|
xctx.visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -772,9 +649,9 @@ void x_win_hide()
|
|||||||
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.dc->dpy, AnyButton, AnyModifier, xctx.win);
|
XUngrabButton(xctx.dpy, AnyButton, AnyModifier, xctx.win);
|
||||||
XUnmapWindow(xctx.dc->dpy, xctx.win);
|
XUnmapWindow(xctx.dpy, xctx.win);
|
||||||
XFlush(xctx.dc->dpy);
|
XFlush(xctx.dpy);
|
||||||
xctx.visible = false;
|
xctx.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -827,7 +704,7 @@ static void x_shortcut_setup_error_handler(void)
|
|||||||
{
|
{
|
||||||
dunst_grab_errored = false;
|
dunst_grab_errored = false;
|
||||||
|
|
||||||
XFlush(xctx.dc->dpy);
|
XFlush(xctx.dpy);
|
||||||
XSetErrorHandler(GrabXErrorHandler);
|
XSetErrorHandler(GrabXErrorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,8 +713,8 @@ static void x_shortcut_setup_error_handler(void)
|
|||||||
*/
|
*/
|
||||||
static int x_shortcut_tear_down_error_handler(void)
|
static int x_shortcut_tear_down_error_handler(void)
|
||||||
{
|
{
|
||||||
XFlush(xctx.dc->dpy);
|
XFlush(xctx.dpy);
|
||||||
XSync(xctx.dc->dpy, false);
|
XSync(xctx.dpy, false);
|
||||||
XSetErrorHandler(NULL);
|
XSetErrorHandler(NULL);
|
||||||
return dunst_grab_errored;
|
return dunst_grab_errored;
|
||||||
}
|
}
|
||||||
@ -850,12 +727,12 @@ int x_shortcut_grab(keyboard_shortcut * ks)
|
|||||||
if (!ks->is_valid)
|
if (!ks->is_valid)
|
||||||
return 1;
|
return 1;
|
||||||
Window root;
|
Window root;
|
||||||
root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
|
||||||
|
|
||||||
x_shortcut_setup_error_handler();
|
x_shortcut_setup_error_handler();
|
||||||
|
|
||||||
if (ks->is_valid)
|
if (ks->is_valid)
|
||||||
XGrabKey(xctx.dc->dpy, ks->code, ks->mask, root,
|
XGrabKey(xctx.dpy, ks->code, ks->mask, root,
|
||||||
true, GrabModeAsync, GrabModeAsync);
|
true, GrabModeAsync, GrabModeAsync);
|
||||||
|
|
||||||
if (x_shortcut_tear_down_error_handler()) {
|
if (x_shortcut_tear_down_error_handler()) {
|
||||||
@ -872,9 +749,9 @@ int x_shortcut_grab(keyboard_shortcut * ks)
|
|||||||
void x_shortcut_ungrab(keyboard_shortcut * ks)
|
void x_shortcut_ungrab(keyboard_shortcut * ks)
|
||||||
{
|
{
|
||||||
Window root;
|
Window root;
|
||||||
root = RootWindow(xctx.dc->dpy, DefaultScreen(xctx.dc->dpy));
|
root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
|
||||||
if (ks->is_valid)
|
if (ks->is_valid)
|
||||||
XUngrabKey(xctx.dc->dpy, ks->code, ks->mask, root);
|
XUngrabKey(xctx.dpy, ks->code, ks->mask, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -910,13 +787,13 @@ void x_shortcut_init(keyboard_shortcut * ks)
|
|||||||
ks->sym = XStringToKeysym(str);
|
ks->sym = XStringToKeysym(str);
|
||||||
/* find matching keycode for ks->sym */
|
/* find matching keycode for ks->sym */
|
||||||
int min_keysym, max_keysym;
|
int min_keysym, max_keysym;
|
||||||
XDisplayKeycodes(xctx.dc->dpy, &min_keysym, &max_keysym);
|
XDisplayKeycodes(xctx.dpy, &min_keysym, &max_keysym);
|
||||||
|
|
||||||
ks->code = NoSymbol;
|
ks->code = NoSymbol;
|
||||||
|
|
||||||
for (int i = min_keysym; i <= max_keysym; i++) {
|
for (int i = min_keysym; i <= max_keysym; i++) {
|
||||||
if (XkbKeycodeToKeysym(xctx.dc->dpy, i, 0, 0) == ks->sym
|
if (XkbKeycodeToKeysym(xctx.dpy, i, 0, 0) == ks->sym
|
||||||
|| XkbKeycodeToKeysym(xctx.dc->dpy, i, 0, 1) == ks->sym) {
|
|| XkbKeycodeToKeysym(xctx.dpy, i, 0, 1) == ks->sym) {
|
||||||
ks->code = i;
|
ks->code = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
74
x.h
74
x.h
@ -1,35 +1,4 @@
|
|||||||
/*
|
/* copyright 2013 Sascha Kruse and contributors (see LICENSE for licensing information) */
|
||||||
|
|
||||||
MIT/X Consortium License
|
|
||||||
|
|
||||||
© 2013 Sascha Kruse <knopwob@googlemail.com> and contributors
|
|
||||||
© 2010-2011 Connor Lane Smith <cls@lubutu.com>
|
|
||||||
© 2006-2011 Anselm R Garbe <anselm@garbe.us>
|
|
||||||
© 2009 Gottox <gottox@s01.de>
|
|
||||||
© 2009 Markus Schnalke <meillo@marmaro.de>
|
|
||||||
© 2009 Evan Gates <evan.gates@gmail.com>
|
|
||||||
© 2006-2008 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
|
||||||
© 2006-2007 Michał Janeczek <janeczek at gmail dot com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
|
||||||
copy of this software and associated documentation files (the "Software"),
|
|
||||||
to deal in the Software without restriction, including without limitation
|
|
||||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
||||||
and/or sell copies of the Software, and to permit persons to whom the
|
|
||||||
Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
||||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
#ifndef DRAW_H
|
#ifndef DRAW_H
|
||||||
#define DRAW_H
|
#define DRAW_H
|
||||||
|
|
||||||
@ -51,30 +20,6 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
#define DEFFONT "Monospace-11"
|
#define DEFFONT "Monospace-11"
|
||||||
#define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh))
|
#define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh))
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x, y, w, h;
|
|
||||||
bool invert;
|
|
||||||
Display *dpy;
|
|
||||||
GC gc;
|
|
||||||
Pixmap canvas;
|
|
||||||
XftDraw *xftdraw;
|
|
||||||
struct {
|
|
||||||
int ascent;
|
|
||||||
int descent;
|
|
||||||
int height;
|
|
||||||
int width;
|
|
||||||
XFontSet set;
|
|
||||||
XFontStruct *xfont;
|
|
||||||
XftFont *xft_font;
|
|
||||||
} font;
|
|
||||||
} DC; /* draw context */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
unsigned long FG;
|
|
||||||
XftColor FG_xft;
|
|
||||||
unsigned long BG;
|
|
||||||
} ColorSet;
|
|
||||||
|
|
||||||
typedef struct _dimension_t {
|
typedef struct _dimension_t {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
@ -97,16 +42,9 @@ typedef struct _keyboard_shortcut {
|
|||||||
bool is_valid;
|
bool is_valid;
|
||||||
} keyboard_shortcut;
|
} keyboard_shortcut;
|
||||||
|
|
||||||
typedef struct _render_text {
|
|
||||||
ColorSet *colors;
|
|
||||||
GSList *lines;
|
|
||||||
} render_text;
|
|
||||||
|
|
||||||
typedef struct _xctx {
|
typedef struct _xctx {
|
||||||
int height_limit;
|
|
||||||
int font_h;
|
|
||||||
Atom utf8;
|
Atom utf8;
|
||||||
DC *dc;
|
Display *dpy;
|
||||||
Window win;
|
Window win;
|
||||||
bool visible;
|
bool visible;
|
||||||
dimension_t geometry;
|
dimension_t geometry;
|
||||||
@ -119,13 +57,7 @@ typedef struct _xctx {
|
|||||||
|
|
||||||
extern xctx_t xctx;
|
extern xctx_t xctx;
|
||||||
|
|
||||||
void freecol(DC * dc, ColorSet * col);
|
void setopacity(Window win, unsigned long opacity);
|
||||||
void eprintf(const char *fmt, ...);
|
|
||||||
void freedc(DC * dc);
|
|
||||||
unsigned long getcolor(DC * dc, const char *colstr);
|
|
||||||
ColorSet *initcolor(DC * dc, const char *foreground, const char *background);
|
|
||||||
DC *initdc(void);
|
|
||||||
void setopacity(DC * dc, Window win, unsigned long opacity);
|
|
||||||
|
|
||||||
/* window */
|
/* window */
|
||||||
void x_win_draw(void);
|
void x_win_draw(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user