diff options
Diffstat (limited to 'dwm-wallpaper.diff')
| -rw-r--r-- | dwm-wallpaper.diff | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/dwm-wallpaper.diff b/dwm-wallpaper.diff new file mode 100644 index 0000000..fb2c310 --- /dev/null +++ b/dwm-wallpaper.diff @@ -0,0 +1,138 @@ +diff --git a/config.mk b/config.mk +index b469a2b..bdd8c9f 100644 +--- a/config.mk ++++ b/config.mk +@@ -23,7 +23,7 @@ FREETYPEINC = /usr/include/freetype2 + + # includes and libs + INCS = -I${X11INC} -I${FREETYPEINC} +-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} ++LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lImlib2 -lXrender -lm + + # flags + CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} +diff --git a/dwm.c b/dwm.c +index 4f345ee..7b238ed 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -43,6 +43,12 @@ + + #include "drw.h" + #include "util.h" ++/* Wallpaper stuff */ ++#include <X11/extensions/Xrender.h> ++#include <Imlib2.h> ++#include <time.h> ++#include <math.h> ++ + + /* macros */ + #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) +@@ -232,6 +238,8 @@ static int xerror(Display *dpy, XErrorEvent *ee); + static int xerrordummy(Display *dpy, XErrorEvent *ee); + static int xerrorstart(Display *dpy, XErrorEvent *ee); + static void zoom(const Arg *arg); ++static void nw_key(const Arg *arg); ++ + + /* variables */ + static const char broken[] = "broken"; +@@ -1378,6 +1386,90 @@ restack(Monitor *m) + while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); + } + ++static Pixmap current_pm = 0; ++ ++static void ++load_wallpaper(Display *dpy, Window root, Pixmap *pm, const char *path) ++{ ++ Screen *screen = DefaultScreenOfDisplay(dpy); ++ int sw = screen->width; ++ int sh = screen->height; ++ Visual *vis = DefaultVisual(dpy, DefaultScreen(dpy)); ++ Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy)); ++ int depth = DefaultDepth(dpy, DefaultScreen(dpy)); ++ ++ Imlib_Image img = imlib_load_image(path); ++ if (!img) ++ return; ++ ++ imlib_context_set_display(dpy); ++ imlib_context_set_visual(vis); ++ imlib_context_set_colormap(cmap); ++ imlib_context_set_image(img); ++ ++ int iw = imlib_image_get_width(); ++ int ih = imlib_image_get_height(); ++ ++#ifdef ENABLE_ASPECT_SCALE ++ double scale = fmin((double)sw / iw, (double)sh / ih); ++ int dw = iw * scale; ++ int dh = ih * scale; ++ int xoff = (sw - dw) / 2; ++ int yoff = (sh - dh) / 2; ++#else ++ int dw = sw; ++ int dh = sh; ++ int xoff = 0; ++ int yoff = 0; ++#endif ++ ++ *pm = XCreatePixmap(dpy, root, sw, sh, depth); ++ Pixmap img_pm = XCreatePixmap(dpy, root, dw, dh, depth); ++ imlib_context_set_drawable(img_pm); ++ imlib_render_image_on_drawable_at_size(0, 0, dw, dh); ++ ++ XSetWindowBackgroundPixmap(dpy, root, img_pm); ++ XClearWindow(dpy, root); ++ XFlush(dpy); ++ if (current_pm) ++ XFreePixmap(dpy, current_pm); ++ current_pm = img_pm; ++ imlib_free_image(); ++} ++ ++static void ++next_wall(Display *dpy, Window root, const char **wals, int len) ++{ ++ static int idx = -1; ++ if (len <= 0) ++ return; ++ ++ idx = (idx + 1) % len; ++ load_wallpaper(dpy, root, ¤t_pm, wals[idx]); ++} ++ ++static void ++set_wall(void) ++{ ++ int len = sizeof(wals) / sizeof(wals[0]); ++ if (len <= 0) ++ return; ++ ++ const char *s = (len > 1) ? wals[rand() % len] : wals[0]; ++ load_wallpaper(dpy, root, ¤t_pm, s); ++} ++ ++ ++static ++void ++nw_key(const Arg *arg) ++{ ++ (void) arg; ++ int len = sizeof(wals)/sizeof(wals[0]); ++ next_wall(dpy, root, wals, len); ++} ++ ++ + void + run(void) + { +@@ -1586,6 +1678,7 @@ setup(void) + scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); + for (i = 0; i < LENGTH(colors); i++) + scheme[i] = drw_scm_create(drw, colors[i], 3); ++ set_wall(); + /* init bars */ + updatebars(); + updatestatus(); |
