* added -bg shade:
- shade=<perc> - percentage, 0 - 100 - color=<color> - tint with <color>, default is "black" --HG-- extra : convert_revision : svn%3Aeebe1cee-a9af-4fe4-bd26-ad572b19c5ab/trunk%4023
This commit is contained in:
parent
0f178f0083
commit
4c6b2c7955
7 changed files with 269 additions and 6 deletions
|
@ -1,5 +1,11 @@
|
|||
Version 0.9
|
||||
|
||||
2005-05-20:
|
||||
|
||||
* added -bg shade:
|
||||
- shade=<perc> - percentage, 0 - 100
|
||||
- color=<color> - tint with <color>, default is "black"
|
||||
|
||||
2005-05-18:
|
||||
|
||||
* fixed minor issues with defaults
|
||||
|
|
32
SConstruct
32
SConstruct
|
@ -17,13 +17,16 @@ Default(alock_target)
|
|||
alock_options = Options(alock_optfile)
|
||||
alock_options.AddOptions(
|
||||
BoolOption('debug', 'build debug version', 0),
|
||||
BoolOption('passwd', 'support for classic passwd', 0),
|
||||
BoolOption('shadow', 'support for shadowpasswords', 0),
|
||||
BoolOption('pam', 'support for pam', 1),
|
||||
BoolOption('hash', 'support for hashs(sha1,md5)', 1),
|
||||
|
||||
BoolOption('imlib2', 'support imagereading via imlib2', 1),
|
||||
BoolOption('xcursor', 'support xcursor-themes', 1),
|
||||
BoolOption('passwd', 'support for -auth passwd', 0),
|
||||
BoolOption('shadow', 'support for -auth passwd with shadow', 0),
|
||||
BoolOption('pam', 'support for -auth pam', 1),
|
||||
BoolOption('hash', 'support for -auth <md5|sha1>', 1),
|
||||
|
||||
BoolOption('imlib2', 'support for -bg image via imlib2', 1),
|
||||
BoolOption('xrender', 'support for -bg shade via xrender', 1),
|
||||
|
||||
BoolOption('xcursor', 'support for -bg xcursor:<file>', 1),
|
||||
|
||||
BoolOption('amd5', 'build a little md5-helper', 0),
|
||||
BoolOption('asha1', 'build a little sha1-helper', 0),
|
||||
|
@ -99,6 +102,7 @@ if alock_env['xcursor']:
|
|||
|
||||
if alock_env['imlib2']:
|
||||
conf = alock_env.Configure()
|
||||
print "Checking for Imlib2... ",
|
||||
if not conf.env.WhereIs('imlib2-config'):
|
||||
print "cant find 'imlib2-config."
|
||||
alock_env['imlib2'] = 0
|
||||
|
@ -109,12 +113,28 @@ if alock_env['imlib2']:
|
|||
print "missing imlib2, install it."
|
||||
alock_env['imlib2'] = 0
|
||||
else:
|
||||
print "yes"
|
||||
alock_env.AppendUnique(
|
||||
CPPDEFINES = [ 'HAVE_IMLIB2' ],
|
||||
LIBPATH = imlib2_env.Dictionary()['LIBPATH'],
|
||||
CPPAPTH = imlib2_env.Dictionary()['CPPPATH'],
|
||||
LIBS = imlib2_env.Dictionary()['LIBS']
|
||||
)
|
||||
conf.Finish()
|
||||
|
||||
if alock_env['xrender']:
|
||||
conf = alock_env.Configure()
|
||||
if conf.CheckLib('Xrender', 'XRenderCreatePicture', 1):
|
||||
alock_env.AppendUnique(
|
||||
CPPDEFINES = [ 'HAVE_XRENDER' ],
|
||||
LIBS = [ 'Xrender' ]
|
||||
)
|
||||
else:
|
||||
print "sorry, no xrender-support found."
|
||||
alock_env['xrender'] = 0
|
||||
conf.Finish()
|
||||
|
||||
|
||||
|
||||
|
||||
############################################################################
|
||||
|
|
|
@ -46,6 +46,8 @@ OPTIONS
|
|||
- list - Displays a list of available types
|
||||
- none - You can see everything like it is
|
||||
- blank:color - Fill the background with color
|
||||
- shade:shade=<perc>,color=<color> - Dims content of the screen and
|
||||
recolors it.
|
||||
- image:name,center,scale,tile,color=<color> - Use the image <name> and puts it as
|
||||
the background.
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ if build['xcursor']:
|
|||
|
||||
if build['imlib2']:
|
||||
bg_sources += [ 'bg_imlib2.c' ]
|
||||
if build['xrender']:
|
||||
bg_sources += [ 'bg_shade.c']
|
||||
|
||||
alock_sources += auth_sources + bg_sources + cursor_sources
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ static struct aBackground* alock_backgrounds[] = {
|
|||
#ifdef HAVE_IMLIB2
|
||||
&alock_bg_imlib2,
|
||||
#endif /* HAVE_IMLIB2 */
|
||||
#ifdef HAVE_XRENDER
|
||||
&alock_bg_shade,
|
||||
#endif /* HAVE_XRENDER */
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
|
@ -72,6 +72,9 @@ extern struct aBackground alock_bg_blank;
|
|||
#ifdef HAVE_IMLIB2
|
||||
extern struct aBackground alock_bg_imlib2;
|
||||
#endif /* HAVE_IMLIB2 */
|
||||
#ifdef HAVE_XRENDER
|
||||
extern struct aBackground alock_bg_shade;
|
||||
#endif /* HAVE_XRENDER */
|
||||
/*------------------------------------------------------------------*\
|
||||
\*------------------------------------------------------------------*/
|
||||
extern struct aAuth alock_auth_none;
|
||||
|
|
227
src/bg_shade.c
Normal file
227
src/bg_shade.c
Normal file
|
@ -0,0 +1,227 @@
|
|||
/* ---------------------------------------------------------------- *\
|
||||
|
||||
file : bg_shade.c
|
||||
author : m. gumz <akira at fluxbox dot org>
|
||||
copyr : copyright (c) 2005 by m. gumz
|
||||
|
||||
license : see LICENSE
|
||||
|
||||
start : Di 18 Mai 2005 10:44:20 CEST
|
||||
|
||||
\* ---------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------- *\
|
||||
|
||||
about :
|
||||
|
||||
provides -bg shade:color=<color>,shade=<int>
|
||||
|
||||
\* ---------------------------------------------------------------- */
|
||||
|
||||
/* ---------------------------------------------------------------- *\
|
||||
includes
|
||||
\* ---------------------------------------------------------------- */
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrender.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "alock.h"
|
||||
|
||||
/* ---------------------------------------------------------------- *\
|
||||
\* ---------------------------------------------------------------- */
|
||||
|
||||
static Window window = 0;
|
||||
static XColor color;
|
||||
|
||||
static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
|
||||
|
||||
char* color_name = strdup("black");
|
||||
unsigned int shade = 80;
|
||||
|
||||
Pixmap src_pm = None;
|
||||
Pixmap dst_pm = None;
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
if (!xinfo || !args)
|
||||
return 0;
|
||||
|
||||
if (strstr(args, "shade:") == args && strlen(&args[6]) > 0) {
|
||||
char* arguments = strdup(&args[6]);
|
||||
char* tmp;
|
||||
char* arg = NULL;
|
||||
for (tmp = arguments; tmp; ) {
|
||||
arg = strsep(&tmp, ",");
|
||||
if (arg) {
|
||||
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])) {
|
||||
long int tmp_shade;
|
||||
char* tmp_char;
|
||||
tmp_shade = strtol(&arg[6], &tmp_char, 0);
|
||||
if ((!tmp_shade || tmp_char != &arg[6]) && tmp_shade > 0 && tmp_shade < 100)
|
||||
shade = tmp_shade;
|
||||
else {
|
||||
printf("alock: error, given value invalid or out of range for [shade].\n");
|
||||
free(arguments);
|
||||
free(color_name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
free(color_name);
|
||||
}
|
||||
|
||||
{ /* get dimension of the screen */
|
||||
XWindowAttributes xgwa;
|
||||
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa);
|
||||
width = xgwa.width;
|
||||
height = xgwa.height;
|
||||
}
|
||||
|
||||
{ /* xrender stuff */
|
||||
Display* dpy = xinfo->display;
|
||||
Window root = xinfo->root;
|
||||
int scrnr = DefaultScreen(dpy);
|
||||
int depth = DefaultDepth(dpy, scrnr);
|
||||
Visual* vis = DefaultVisual(dpy, scrnr);
|
||||
GC gc = DefaultGC(dpy, scrnr);
|
||||
|
||||
{ /* grab whats on the screen */
|
||||
XImage* image = XGetImage(dpy, root, 0, 0, width, height, AllPlanes, ZPixmap);
|
||||
src_pm = XCreatePixmap(dpy, root, width, height, depth);
|
||||
XPutImage(dpy, src_pm, gc, image, 0, 0, 0, 0, width, height);
|
||||
XDestroyImage(image);
|
||||
}
|
||||
|
||||
dst_pm = XCreatePixmap(dpy, root, width, height, depth);
|
||||
|
||||
{ /* tint the src */
|
||||
GC tintgc;
|
||||
XGCValues tintval;
|
||||
|
||||
tintval.foreground = color.pixel;
|
||||
tintgc = XCreateGC(dpy, dst_pm, GCForeground, &tintval);
|
||||
XFillRectangle(dpy, dst_pm, tintgc, 0, 0, width, height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{ /* create final window */
|
||||
XSetWindowAttributes xswa;
|
||||
long xsmask = 0;
|
||||
|
||||
xswa.override_redirect = True;
|
||||
xswa.colormap = xinfo->colormap;
|
||||
xswa.background_pixmap = dst_pm;
|
||||
|
||||
xsmask |= CWOverrideRedirect;
|
||||
xsmask |= CWBackPixmap;
|
||||
xsmask |= CWColormap;
|
||||
|
||||
window = XCreateWindow(xinfo->display, xinfo->root,
|
||||
0, 0, width, height,
|
||||
0, /* borderwidth */
|
||||
CopyFromParent, /* depth */
|
||||
InputOutput, /* class */
|
||||
CopyFromParent, /* visual */
|
||||
xsmask, &xswa);
|
||||
XFreePixmap(xinfo->display, src_pm);
|
||||
XFreePixmap(xinfo->display, dst_pm);
|
||||
}
|
||||
|
||||
if (window)
|
||||
xinfo->window = window;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
static int alock_bg_shade_deinit(struct aXInfo* xinfo) {
|
||||
if (!xinfo || !window)
|
||||
return 0;
|
||||
XDestroyWindow(xinfo->display, window);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct aBackground alock_bg_shade = {
|
||||
"shade",
|
||||
alock_bg_shade_init,
|
||||
alock_bg_shade_deinit
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------- *\
|
||||
\* ---------------------------------------------------------------- */
|
||||
|
Reference in a new issue