* added -bg image:shade=<perc>
* added alock_utils.c, shared code goes to that file --HG-- extra : convert_revision : svn%3Aeebe1cee-a9af-4fe4-bd26-ad572b19c5ab/trunk%4024
This commit is contained in:
parent
4c6b2c7955
commit
faca6bfcb0
8 changed files with 100 additions and 93 deletions
|
@ -1,4 +1,8 @@
|
||||||
Version 0.9
|
Version 1.0
|
||||||
|
|
||||||
|
2005-05-23:
|
||||||
|
|
||||||
|
* added -bg image:shade=<perc>
|
||||||
|
|
||||||
2005-05-20:
|
2005-05-20:
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ OPTIONS
|
||||||
- blank:color - Fill the background with color
|
- blank:color - Fill the background with color
|
||||||
- shade:shade=<perc>,color=<color> - Dims content of the screen and
|
- shade:shade=<perc>,color=<color> - Dims content of the screen and
|
||||||
recolors it.
|
recolors it.
|
||||||
- image:name,center,scale,tile,color=<color> - Use the image <name> and puts it as
|
- image:name,center,scale,tile,color=<color>,shade=<perc> - Use the image <name> and puts it as
|
||||||
the background.
|
the background.
|
||||||
|
|
||||||
-cursor type:options ::
|
-cursor type:options ::
|
||||||
|
@ -69,6 +69,12 @@ RESOURCES
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Web site: http://darkshed.net
|
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
|
COPYING
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#
|
#
|
||||||
##########################################################
|
##########################################################
|
||||||
|
|
||||||
alock_sources = [ 'alock.c' ]
|
alock_sources = [ 'alock.c', 'alock_utils.c' ]
|
||||||
|
|
||||||
auth_sources = [ 'auth_none.c' ]
|
auth_sources = [ 'auth_none.c' ]
|
||||||
bg_sources = [ 'bg_none.c', 'bg_blank.c' ]
|
bg_sources = [ 'bg_none.c', 'bg_blank.c' ]
|
||||||
|
|
|
@ -98,7 +98,7 @@ int event_loop(struct aOpts* opts, struct aXInfo* xinfo) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
KeySym ks;
|
KeySym ks;
|
||||||
char cbuf[10], rbuf[50];
|
char cbuf[10], rbuf[50];
|
||||||
int clen, rlen = 0;
|
unsigned int clen, rlen = 0;
|
||||||
|
|
||||||
long goodwill = 5 * 30000;
|
long goodwill = 5 * 30000;
|
||||||
long timeout = 0;
|
long timeout = 0;
|
||||||
|
|
14
src/alock.h
14
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;
|
extern struct aBackground alock_bg_none;
|
||||||
|
|
|
@ -59,9 +59,7 @@ static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
|
||||||
free(arguments);
|
free(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp_color, &color)) == 0)
|
alock_alloc_color(xinfo, color_name, "black", &color);
|
||||||
XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color);
|
|
||||||
|
|
||||||
free(color_name);
|
free(color_name);
|
||||||
|
|
||||||
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa);
|
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa);
|
||||||
|
|
|
@ -47,9 +47,9 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) {
|
||||||
XSetWindowAttributes xswa;
|
XSetWindowAttributes xswa;
|
||||||
long xsmask = 0;
|
long xsmask = 0;
|
||||||
long options = ALOCK_SCALE;
|
long options = ALOCK_SCALE;
|
||||||
XColor tmp_color;
|
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
char* color_name = strdup("black");
|
char* color_name = strdup("black");
|
||||||
|
unsigned int shade = 0;
|
||||||
|
|
||||||
if (!xinfo || !args)
|
if (!xinfo || !args)
|
||||||
return 0;
|
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])) {
|
} else if (strstr(arg, "color=") == arg && strlen(arg) > 6 && strlen(&arg[6])) {
|
||||||
free(color_name);
|
free(color_name);
|
||||||
color_name = strdup(&arg[6]);
|
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 {
|
} else {
|
||||||
if (!filename)
|
if (!filename)
|
||||||
filename = strdup(arg);
|
filename = strdup(arg);
|
||||||
|
@ -84,16 +95,15 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp_color, &color)) == 0)
|
if (!alock_check_xrender(xinfo)) {
|
||||||
XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color);
|
shade = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
alock_alloc_color(xinfo, color_name, "black", &color);
|
||||||
free(color_name);
|
free(color_name);
|
||||||
|
|
||||||
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa);
|
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_Context context = NULL;
|
||||||
Imlib_Image image = 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);
|
image = imlib_load_image_without_cache(filename);
|
||||||
if (image) {
|
if (image) {
|
||||||
|
|
||||||
|
char do_shade = shade > 0 && shade < 100;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
|
||||||
pixmap = XCreatePixmap(xinfo->display, xinfo->root,
|
pixmap = XCreatePixmap(xinfo->display, xinfo->root,
|
||||||
xgwa.width, xgwa.height,
|
xgwa.width, xgwa.height,
|
||||||
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display)));
|
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display)));
|
||||||
|
|
||||||
|
imlib_context_set_drawable(pixmap);
|
||||||
imlib_context_set_image(image);
|
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;
|
GC gc;
|
||||||
XGCValues gcval;
|
XGCValues gcval;
|
||||||
int w = imlib_image_get_width();
|
|
||||||
int h = imlib_image_get_height();
|
|
||||||
|
|
||||||
gcval.foreground = color.pixel;
|
gcval.foreground = color.pixel;
|
||||||
gc = XCreateGC(xinfo->display, xinfo->root, GCForeground, &gcval);
|
gc = XCreateGC(xinfo->display, xinfo->root, GCForeground, &gcval);
|
||||||
XFillRectangle(xinfo->display, pixmap, gc, 0, 0, xgwa.width, xgwa.height);
|
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);
|
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) {
|
} else if (options & ALOCK_TILED) {
|
||||||
Pixmap tile;
|
Pixmap tile;
|
||||||
GC gc;
|
GC gc;
|
||||||
XGCValues gcval;
|
XGCValues gcval;
|
||||||
int w = imlib_image_get_width();
|
|
||||||
int h = imlib_image_get_height();
|
|
||||||
|
|
||||||
tile = XCreatePixmap(xinfo->display, xinfo->root,
|
tile = XCreatePixmap(xinfo->display, xinfo->root,
|
||||||
w, h, DefaultDepth(xinfo->display, DefaultScreen(xinfo->display)));
|
w, h, DefaultDepth(xinfo->display, DefaultScreen(xinfo->display)));
|
||||||
|
|
||||||
imlib_context_set_drawable(tile);
|
|
||||||
imlib_render_image_on_drawable(0, 0);
|
imlib_render_image_on_drawable(0, 0);
|
||||||
|
|
||||||
gcval.fill_style = FillTiled;
|
gcval.fill_style = FillTiled;
|
||||||
|
@ -146,7 +191,6 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) {
|
||||||
XFreeGC(xinfo->display, gc);
|
XFreeGC(xinfo->display, gc);
|
||||||
XFreePixmap(xinfo->display, tile);
|
XFreePixmap(xinfo->display, tile);
|
||||||
} else {/* fallback is ALOCK_SCALE */
|
} else {/* fallback is ALOCK_SCALE */
|
||||||
imlib_context_set_drawable(pixmap);
|
|
||||||
imlib_render_image_on_drawable_at_size(0, 0, xgwa.width, xgwa.height);
|
imlib_render_image_on_drawable_at_size(0, 0, xgwa.width, xgwa.height);
|
||||||
}
|
}
|
||||||
imlib_free_image_and_decache();
|
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_pop();
|
||||||
imlib_context_free(context);
|
imlib_context_free(context);
|
||||||
context = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xswa.override_redirect = True;
|
xswa.override_redirect = True;
|
||||||
|
|
|
@ -76,25 +76,15 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
|
||||||
free(arguments);
|
free(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ /* check for RENDER-extension */
|
if (!alock_check_xrender(xinfo)) {
|
||||||
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);
|
|
||||||
|
|
||||||
free(color_name);
|
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 */
|
{ /* get dimension of the screen */
|
||||||
XWindowAttributes xgwa;
|
XWindowAttributes xgwa;
|
||||||
XGetWindowAttributes(xinfo->display, xinfo->root, &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);
|
dst_pm = XCreatePixmap(dpy, root, width, height, depth);
|
||||||
|
|
||||||
{ /* tint the src */
|
{ /* tint the dst*/
|
||||||
GC tintgc;
|
GC tintgc;
|
||||||
XGCValues tintval;
|
XGCValues tintval;
|
||||||
|
|
||||||
|
@ -129,55 +119,7 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
|
||||||
XFreeGC(dpy, tintgc);
|
XFreeGC(dpy, tintgc);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ /* now do the "hot" stuff */
|
alock_shade_pixmap(xinfo, src_pm, dst_pm, shade, 0, 0, 0, 0, width, height);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ /* create final window */
|
{ /* create final window */
|
||||||
|
|
Reference in a new issue