From faca6bfcb0d4a3255e6e9d2c902585dbc9cf89a9 Mon Sep 17 00:00:00 2001 From: mathias Date: Mon, 23 May 2005 13:06:27 +0000 Subject: [PATCH] * added -bg image:shade= * added alock_utils.c, shared code goes to that file --HG-- extra : convert_revision : svn%3Aeebe1cee-a9af-4fe4-bd26-ad572b19c5ab/trunk%4024 --- CHANGELOG | 6 +++- alock.txt | 8 ++++- src/SConscript | 2 +- src/alock.c | 2 +- src/alock.h | 14 +++++++++ src/bg_blank.c | 4 +-- src/bg_imlib2.c | 83 +++++++++++++++++++++++++++++++++++++------------ src/bg_shade.c | 74 +++++-------------------------------------- 8 files changed, 100 insertions(+), 93 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b9bbf23..feca33a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,8 @@ -Version 0.9 +Version 1.0 + +2005-05-23: + + * added -bg image:shade= 2005-05-20: diff --git a/alock.txt b/alock.txt index b4b8fd1..625c7f4 100644 --- a/alock.txt +++ b/alock.txt @@ -48,7 +48,7 @@ OPTIONS - blank:color - Fill the background with color - shade:shade=,color= - Dims content of the screen and recolors it. - - image:name,center,scale,tile,color= - Use the image and puts it as + - image:name,center,scale,tile,color=,shade= - Use the image and puts it as the background. -cursor type:options :: @@ -69,6 +69,12 @@ RESOURCES --------- Web site: http://darkshed.net +Other lockers:: + - xlockmore http://www.tux.org/~bagleyd/xlockmore.html + - xscreensaver http://www.jwz.org/xscreensaver/ + - xtrlock ftp://ftp.debian.org/debian/dists/stable/main/source/x11/ + - vlock ftp://ftp.ibiblio.org/pub/Linux/utils/console/ + - lockvc ftp://ftp.ibiblio.org/pub/Linux/utils/console/ COPYING ------- diff --git a/src/SConscript b/src/SConscript index 57eb5ee..43933aa 100644 --- a/src/SConscript +++ b/src/SConscript @@ -5,7 +5,7 @@ # ########################################################## -alock_sources = [ 'alock.c' ] +alock_sources = [ 'alock.c', 'alock_utils.c' ] auth_sources = [ 'auth_none.c' ] bg_sources = [ 'bg_none.c', 'bg_blank.c' ] diff --git a/src/alock.c b/src/alock.c index 9e8a0ed..773d7ce 100644 --- a/src/alock.c +++ b/src/alock.c @@ -98,7 +98,7 @@ int event_loop(struct aOpts* opts, struct aXInfo* xinfo) { XEvent ev; KeySym ks; char cbuf[10], rbuf[50]; - int clen, rlen = 0; + unsigned int clen, rlen = 0; long goodwill = 5 * 30000; long timeout = 0; diff --git a/src/alock.h b/src/alock.h index 8e391dd..f2050de 100644 --- a/src/alock.h +++ b/src/alock.h @@ -65,6 +65,20 @@ struct aOpts { }; +/*------------------------------------------------------------------*\ +\*------------------------------------------------------------------*/ +int alock_alloc_color(const struct aXInfo* xinfo, const char* color_name, + const char* fallback_name, XColor* result); +int alock_check_xrender(const struct aXInfo* xinfo); +int alock_shade_pixmap(const struct aXInfo* xinfo, + const Pixmap src_pm, + Pixmap dst_pm, + unsigned char shade, + int src_x, int src_y, + int dst_x, int dst_y, + unsigned int width, + unsigned int height); + /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ extern struct aBackground alock_bg_none; diff --git a/src/bg_blank.c b/src/bg_blank.c index b21aaec..586b179 100644 --- a/src/bg_blank.c +++ b/src/bg_blank.c @@ -59,9 +59,7 @@ static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) { free(arguments); } - if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp_color, &color)) == 0) - XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color); - + alock_alloc_color(xinfo, color_name, "black", &color); free(color_name); XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa); diff --git a/src/bg_imlib2.c b/src/bg_imlib2.c index c89ba30..9524e51 100644 --- a/src/bg_imlib2.c +++ b/src/bg_imlib2.c @@ -47,9 +47,9 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { XSetWindowAttributes xswa; long xsmask = 0; long options = ALOCK_SCALE; - XColor tmp_color; char* filename = NULL; char* color_name = strdup("black"); + unsigned int shade = 0; if (!xinfo || !args) return 0; @@ -70,6 +70,17 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { } else if (strstr(arg, "color=") == arg && strlen(arg) > 6 && strlen(&arg[6])) { free(color_name); color_name = strdup(&arg[6]); + } else if (strstr(arg, "shade=") == arg && strlen(arg) > 6 && strlen(&arg[6])) { + unsigned int tmp_shade = atoi(&arg[6]); + if (tmp_shade > 0 && tmp_shade < 100) { + shade = tmp_shade; + } else { + printf("alock: error, shade not in range [1, 99] for [image].\n"); + free(color_name); + free(arguments); + return 0; + } + } else { if (!filename) filename = strdup(arg); @@ -84,16 +95,15 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { return 1; } - if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp_color, &color)) == 0) - XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color); - + if (!alock_check_xrender(xinfo)) { + shade = 0; + } + + alock_alloc_color(xinfo, color_name, "black", &color); free(color_name); XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa); - - - /* get image and set it as the background pixmap for the window */ - { + { /* get image and set it as the background pixmap for the window */ Imlib_Context context = NULL; Imlib_Image image = NULL; @@ -107,35 +117,70 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { image = imlib_load_image_without_cache(filename); if (image) { + char do_shade = shade > 0 && shade < 100; + int w; + int h; + pixmap = XCreatePixmap(xinfo->display, xinfo->root, xgwa.width, xgwa.height, DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); + imlib_context_set_drawable(pixmap); imlib_context_set_image(image); - - if (options & ALOCK_CENTER) { + + w = imlib_image_get_width(); + h = imlib_image_get_height(); + + if (do_shade || options & ALOCK_CENTER) { + GC gc; XGCValues gcval; - int w = imlib_image_get_width(); - int h = imlib_image_get_height(); - + gcval.foreground = color.pixel; gc = XCreateGC(xinfo->display, xinfo->root, GCForeground, &gcval); XFillRectangle(xinfo->display, pixmap, gc, 0, 0, xgwa.width, xgwa.height); - imlib_context_set_drawable(pixmap); - imlib_render_image_on_drawable((xgwa.width - w)/2, (xgwa.height - h)/2); XFreeGC(xinfo->display, gc); + } + + if (do_shade) { + GC gc; + XGCValues gcval; + + Pixmap tmp_pixmap = XCreatePixmap(xinfo->display, xinfo->root, w, h, + DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); + Pixmap shaded_pixmap = XCreatePixmap(xinfo->display, xinfo->root, w, h, + DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); + gcval.foreground = color.pixel; + gc = XCreateGC(xinfo->display, xinfo->root, GCForeground, &gcval); + XFillRectangle(xinfo->display, shaded_pixmap, gc, 0, 0, w, h); + + imlib_context_set_drawable(tmp_pixmap); + imlib_render_image_on_drawable(0, 0); + + alock_shade_pixmap(xinfo, tmp_pixmap, shaded_pixmap, shade, 0, 0, 0, 0, w, h); + + imlib_free_image_and_decache(); + imlib_context_set_drawable(shaded_pixmap); + + image = imlib_create_image_from_drawable(None, 0, 0, w, h, 0); + + XFreePixmap(xinfo->display, shaded_pixmap); + XFreePixmap(xinfo->display, tmp_pixmap); + + imlib_context_set_drawable(pixmap); + imlib_context_set_image(image); + } + + if (options & ALOCK_CENTER) { + imlib_render_image_on_drawable((xgwa.width - w)/2, (xgwa.height - h)/2); } else if (options & ALOCK_TILED) { Pixmap tile; GC gc; XGCValues gcval; - int w = imlib_image_get_width(); - int h = imlib_image_get_height(); tile = XCreatePixmap(xinfo->display, xinfo->root, w, h, DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); - imlib_context_set_drawable(tile); imlib_render_image_on_drawable(0, 0); gcval.fill_style = FillTiled; @@ -146,7 +191,6 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { XFreeGC(xinfo->display, gc); XFreePixmap(xinfo->display, tile); } else {/* fallback is ALOCK_SCALE */ - imlib_context_set_drawable(pixmap); imlib_render_image_on_drawable_at_size(0, 0, xgwa.width, xgwa.height); } imlib_free_image_and_decache(); @@ -161,7 +205,6 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { imlib_context_pop(); imlib_context_free(context); - context = NULL; } xswa.override_redirect = True; diff --git a/src/bg_shade.c b/src/bg_shade.c index 49672e3..a6356df 100644 --- a/src/bg_shade.c +++ b/src/bg_shade.c @@ -76,25 +76,15 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) { free(arguments); } - { /* check for RENDER-extension */ - int major_opcode, first_event, first_error; - if (XQueryExtension(xinfo->display, "RENDER", - &major_opcode, - &first_event, &first_error) == False) { - printf("alock: error, no xrender-support found\n"); - free(color_name); - return 0; - } - } - - { /* get a color from color_name */ - XColor tmp_color; - if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp_color, &color)) == 0) - XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color); - + if (!alock_check_xrender(xinfo)) { free(color_name); + return 0; } + /* get a color from color_name */ + alock_alloc_color(xinfo, color_name, "black", &color); + free(color_name); + { /* get dimension of the screen */ XWindowAttributes xgwa; XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa); @@ -119,7 +109,7 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) { dst_pm = XCreatePixmap(dpy, root, width, height, depth); - { /* tint the src */ + { /* tint the dst*/ GC tintgc; XGCValues tintval; @@ -129,55 +119,7 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) { XFreeGC(dpy, tintgc); } - { /* now do the "hot" stuff */ - Picture alpha_pic = None; - XRenderPictFormat* format = None; - XRenderPictFormat alpha_format; - - alpha_format.type = PictTypeDirect; - alpha_format.depth = 8; - alpha_format.direct.alpha = 0; - alpha_format.direct.alphaMask = 0xff; - - format = XRenderFindStandardFormat(dpy, PictStandardA8); - if (!format) { - printf("error, couldnt find valid format for alpha.\n"); - XFreePixmap(dpy, dst_pm); - XFreePixmap(dpy, src_pm); - return 0; - } - - { /* fill the alpha-picture */ - Pixmap alpha_pm = None; - XRenderColor alpha_color; - XRenderPictureAttributes alpha_attr; - - alpha_color.alpha = 0xffff * (shade)/100; - - alpha_attr.repeat = True; - //alpha_attr.component_alpha = True; - - alpha_pm = XCreatePixmap(dpy, src_pm, 1, 1, 8); - alpha_pic = XRenderCreatePicture(dpy, alpha_pm, format, CPRepeat/*|CPComponentAlpha*/, &alpha_attr); - XRenderFillRectangle(dpy, PictOpSrc, alpha_pic, &alpha_color, 0, 0, 1, 1); - XFreePixmap(dpy, alpha_pm); - } - - { /* blend all together */ - Picture src_pic; - Picture dst_pic; - - format = XRenderFindVisualFormat(dpy, vis); - - src_pic = XRenderCreatePicture(dpy, src_pm, format, 0, 0); - dst_pic = XRenderCreatePicture(dpy, dst_pm, format, 0, 0); - - XRenderComposite(dpy, PictOpOver, src_pic, alpha_pic, dst_pic, 0, 0, 0, 0, 0, 0, width, height); - XRenderFreePicture(dpy, src_pic); - XRenderFreePicture(dpy, dst_pic); - } - } - + alock_shade_pixmap(xinfo, src_pm, dst_pm, shade, 0, 0, 0, 0, width, height); } { /* create final window */