* added -cursor image:file=<filename>, uses xrender and xpm/imlib2

* minor tweaks in alock_util.c

--HG--
extra : convert_revision : svn%3Aeebe1cee-a9af-4fe4-bd26-ad572b19c5ab/trunk%4033
This commit is contained in:
mathias 2005-06-01 10:06:15 +00:00
parent 60a2ad9af5
commit 37bb87fdff
11 changed files with 264 additions and 58 deletions

View file

@ -1,5 +1,9 @@
Version 1.0
2005-06-01:
* added -cursor image:file=<filename>, uses xrender and xpm/imlib2
2005-05-25:
* solved problems install-problems: use at least scons 0.96.90

2
README
View file

@ -1,7 +1,7 @@
alock - README
==============
Mathias Gumz <akira@fluxbox.org>
v1.0, 24 May 2005
v1.0, 01 June 2005
About
-----

View file

@ -9,6 +9,9 @@ import sys
import os
from scons_alock import *
from SCons.Script.SConscript import SConsEnvironment # just do this once
SConsEnvironment.InstallAsMode = alock_installAs
alock_name = 'alock'
alock_version = '1.0'
alock_optfile = [ 'scons.opts', 'user.opts' ]
@ -43,7 +46,8 @@ alock_options.AddOptions(
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('xrender', 'support for -bg shade via xrender or -cursor image', 1),
BoolOption('xpm', 'support for reading images via libxpm', 1),
BoolOption('xcursor', 'support for -bg xcursor:<file>', 1),
@ -131,6 +135,11 @@ if alock_env['xcursor']:
print "sorry, no xcursor-support found."
conf.Finish()
if alock_env['xpm']:
alock_env.AppendUnique(
CPPDEFINES = ['HAVE_XPM'],
LIBS = [ 'Xpm' ])
if alock_env['imlib2']:
conf = alock_env.Configure()
print "Checking for Imlib2... ",
@ -198,10 +207,10 @@ alock_env.AddPostAction('alock.html', Chmod('alock.html', 0644))
############################################################################
#
# installing
alock_env.Install(alock_instdir_bin, alock_target)
alock_env.Install(alock_instdir_meta, alock_meta_files)
alock_env.Install(alock_instdir_man, alock_manpage)
alock_env.Install(alock_instdir_meta_contrib, alock_contrib_files)
#alock_env.InstallAs(prefixCombiner(alock_instdir_bin, ['alock'], os.sep), [alock_target], 0755)
#alock_env.InstallAs(prefixCombiner(alock_meta_files, alock_instdir_meta, os.sep), alock_meta_files, 0644)
#alock_env.InstallAs(prefixCombiner(alock_instdir_man, [alock_manpage], os.sep), [alock_manpage], 0644)
#alock_env.InstallAs(prefixCombiner(alock_instdir_meta_contrib, alock_contrib_files, os.sep), alock_contrib_files, 0645)
# TODO: add a "scons dist" command which builds a propper tarball
#alock_env.Alias('dist', alock_env.Tar(alock_target + '-' + alock_version,
@ -213,6 +222,6 @@ alock_env.Install(alock_instdir_meta_contrib, alock_contrib_files)
# aliases
alock_env.Alias('docs', alock_doc_files)
alock_env.Alias('install', alock_instdir)
#alock_env.Alias('install', alock_instdir)
# vim:ft=python

View file

@ -75,6 +75,8 @@ OPTIONS
* fg=<color>
- xcursor - Use the given <filename> in xcursor-format
* file=<filename>
- image - Use the given <filename>
* file=<filename>
- none - No change to the current cursor
AUTHOR

View file

@ -21,6 +21,12 @@ def prefixCombiner(prefix, itemlist, glue=''):
result.append(prefix + glue + item)
return result
def alock_installAs(env, dest, source, mode = 0644):
env.InstallAs(dest, source)
for file in dest:
env.Chmod(file, mode)
# http://scons.tigris.org/servlets/ReadMsg?listName=users&msgNo=2739
# http://scons.tigris.org/servlets/ReadMsg?list=users&msgNo=2783
def alock_installFunc(dest, source, env):

View file

@ -29,6 +29,8 @@ if build['imlib2']:
bg_sources += [ 'bg_image.c' ]
if build['xrender']:
bg_sources += [ 'bg_shade.c']
if build['xrender'] or build['xpm']:
cursor_sources += ['cursor_image.c']
alock_sources += auth_sources + bg_sources + cursor_sources

View file

@ -32,6 +32,18 @@
/*------------------------------------------------------------------*\
globals
\*------------------------------------------------------------------*/
extern struct aAuth alock_auth_none;
#ifdef HASH_PWD
extern struct aAuth alock_auth_md5;
extern struct aAuth alock_auth_sha1;
#endif /* HASH_PWD */
#ifdef PASSWD_PWD
extern struct aAuth alock_auth_passwd;
#endif /* PASSWD_PWD */
#ifdef PAM_PWD
extern struct aAuth alock_auth_pam;
#endif /* PAM_PWD */
static struct aAuth* alock_authmodules[] = {
&alock_auth_none,
#ifdef PAM_PWD
@ -46,6 +58,16 @@ static struct aAuth* alock_authmodules[] = {
#endif /* HASH_PWD */
NULL
};
/*------------------------------------------------------------------*\
\*------------------------------------------------------------------*/
extern struct aBackground alock_bg_none;
extern struct aBackground alock_bg_blank;
#ifdef HAVE_IMLIB2
extern struct aBackground alock_bg_image;
#endif /* HAVE_IMLIB2 */
#ifdef HAVE_XRENDER
extern struct aBackground alock_bg_shade;
#endif /* HAVE_XRENDER */
static struct aBackground* alock_backgrounds[] = {
&alock_bg_none,
@ -58,6 +80,17 @@ static struct aBackground* alock_backgrounds[] = {
#endif /* HAVE_XRENDER */
NULL
};
/* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */
extern struct aCursor alock_cursor_none;
extern struct aCursor alock_cursor_theme;
extern struct aCursor alock_cursor_glyph;
#ifdef HAVE_XCURSOR
extern struct aCursor alock_cursor_xcursor;
#endif /* HAVE_XCURSOR */
#ifdef HAVE_XRENDER
extern struct aCursor alock_cursor_image;
#endif /* HAVE_XRENDER */
static struct aCursor* alock_cursors[] = {
&alock_cursor_none,
@ -66,6 +99,9 @@ static struct aCursor* alock_cursors[] = {
#ifdef HAVE_XCURSOR
&alock_cursor_xcursor,
#endif /* HAVE_XCURSOR */
#ifdef HAVE_XRENDER
&alock_cursor_image,
#endif /* HAVE_XRENDER */
NULL
};
/*------------------------------------------------------------------*\

View file

@ -82,38 +82,5 @@ int alock_shade_pixmap(const struct aXInfo* xinfo,
unsigned int width,
unsigned int height);
/*------------------------------------------------------------------*\
\*------------------------------------------------------------------*/
extern struct aBackground alock_bg_none;
extern struct aBackground alock_bg_blank;
#ifdef HAVE_IMLIB2
extern struct aBackground alock_bg_image;
#endif /* HAVE_IMLIB2 */
#ifdef HAVE_XRENDER
extern struct aBackground alock_bg_shade;
#endif /* HAVE_XRENDER */
/*------------------------------------------------------------------*\
\*------------------------------------------------------------------*/
extern struct aAuth alock_auth_none;
#ifdef HASH_PWD
extern struct aAuth alock_auth_md5;
extern struct aAuth alock_auth_sha1;
#endif /* HASH_PWD */
#ifdef PASSWD_PWD
extern struct aAuth alock_auth_passwd;
#endif /* PASSWD_PWD */
#ifdef PAM_PWD
extern struct aAuth alock_auth_pam;
#endif /* PAM_PWD */
/*------------------------------------------------------------------*\
\*------------------------------------------------------------------*/
extern struct aCursor alock_cursor_none;
extern struct aCursor alock_cursor_theme;
extern struct aCursor alock_cursor_glyph;
#ifdef HAVE_XCURSOR
extern struct aCursor alock_cursor_xcursor;
#endif /* HAVE_XCURSOR */
/* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */
#endif // _ALOCK_H_

View file

@ -57,14 +57,22 @@ int alock_alloc_color(const struct aXInfo* xinfo, const char* color_name,
\*------------------------------------------------------------------*/
int alock_check_xrender(const struct aXInfo* xinfo) {
#ifdef HAVE_XRENDER
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");
return 0;
static int have_xrender = 0;
static int checked_already = 0;
if (!checked_already) {
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");
have_xrender = 0;
} else
have_xrender = 1;
checked_already = 1;
}
return 1;
return have_xrender;
#else
printf("alock: error, i wasnt compiled to support xrender.\n");
return 0;
@ -86,14 +94,18 @@ int alock_shade_pixmap(const struct aXInfo* xinfo,
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;
{
XRenderPictFormat alpha_format;
unsigned long mask = PictFormatType|PictFormatDepth|PictFormatAlpha|PictFormatAlphaMask;
alpha_format.type = PictTypeDirect;
alpha_format.depth = 8;
alpha_format.direct.alpha = 0;
alpha_format.direct.alphaMask = 0xff;
format = XRenderFindFormat(dpy, mask, &alpha_format, 0);
}
format = XRenderFindStandardFormat(dpy, PictStandardA8);
if (!format) {
printf("error, couldnt find valid format for alpha.\n");
XFreePixmap(dpy, dst_pm);
@ -138,10 +150,6 @@ int alock_shade_pixmap(const struct aXInfo* xinfo,
#endif /* HAVE_XRENDER */
}
/* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */

View file

@ -39,7 +39,6 @@ static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
XWindowAttributes xgwa;
XSetWindowAttributes xswa;
long xsmask = 0;
XColor tmp_color;
char* color_name = strdup("black");
if (!xinfo || !args)

173
src/cursor_image.c Normal file
View file

@ -0,0 +1,173 @@
/* ---------------------------------------------------------------- *\
file : cursor_image.c
author : m. gumz <akira at fluxbox dot org>
copyr : copyright (c) 2005 by m. gumz
license : see LICENSE
start : Mi 01 June 2005 10:48:21 CEST
$Id: $
\* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- *\
about :
provide -cursor image:file=<file>
\* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- *\
includes
\* ---------------------------------------------------------------- */
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
#ifdef HAVE_IMLIB2
# include <Imlib2.h>
#elif HAVE_XPM
# include <X11/xpm.h>
#endif /* HAVE_IMLIB2 | HAVE_XPM */
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "alock.h"
/* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */
static Cursor cursor = 0;
static int alock_cursor_image_init(const char* args, struct aXInfo* xinfo) {
char* filename = NULL;
if (!xinfo || !args)
return 0;
if (strstr(args, "image:") == 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, "file=") == arg && strlen(arg) > 6) {
if (!filename)
filename = strdup(&arg[5]);
}
}
}
free(arguments);
}
if (!filename) {
printf("alock: error, missing argument for [image].\n");
return 0;
}
if (!alock_check_xrender(xinfo)) {
printf("alock: error, no running xrender extension found [image].\n");
free(filename);
return 0;
}
{
unsigned int w = 0;
unsigned int h = 0;
Pixmap cursor_pm = None;
#ifdef HAVE_IMLIB2
{
Imlib_Image img;
Imlib_Context ctx = imlib_context_new();
imlib_context_push(ctx);
imlib_context_set_display(xinfo->display);
imlib_context_set_visual(DefaultVisual(xinfo->display, DefaultScreen(xinfo->display)));
imlib_context_set_colormap(xinfo->colormap);
img = imlib_load_image_without_cache(filename);
if (img) {
imlib_context_set_image(img);
w = imlib_image_get_width();
h = imlib_image_get_height();
cursor_pm = XCreatePixmap(xinfo->display,
xinfo->root,
w, h,
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display)));
imlib_context_set_drawable(cursor_pm);
imlib_render_image_on_drawable(0, 0);
imlib_free_image_and_decache();
}
imlib_context_pop();
imlib_context_free(ctx);
}
#elif HAVE_XPM
if (!cursor_pm) {
XImage* img = NULL;
XpmReadFileToImage(xinfo->display, filename, &img, NULL, NULL);
if (img) {
w = img->width;
h = img->height;
cursor_pm = XCreatePixmap(xinfo->display,
xinfo->root,
w, h,
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display)));
XPutImage(xinfo->display, cursor_pm,
DefaultGC(xinfo->display, DefaultScreen(xinfo->display)),
img,
0, 0, 0, 0, w, h);
XDestroyImage(img);
}
}
#else
#warning compiling this file without having either imlib2 or xpm is pretty useless since no image can be loaded.
#endif /* HAVE_XPM|HAVE_IMLIB2 */
if (!cursor_pm) {
printf("alock: error while loading [%s] in [image].\n", filename);
free(filename);
return 0;
}
{
XRenderPictFormat* format = XRenderFindVisualFormat(xinfo->display,
DefaultVisual(xinfo->display, DefaultScreen(xinfo->display)));
if (format) {
Picture cursor_pic = XRenderCreatePicture(xinfo->display, cursor_pm, format, 0, 0);
cursor = XRenderCreateCursor(xinfo->display, cursor_pic, w / 2, h / 2);
XRenderFreePicture(xinfo->display, cursor_pic);
}
}
}
free(filename);
xinfo->cursor = cursor;
return cursor;
}
static int alock_cursor_image_deinit(struct aXInfo* xinfo) {
if (!xinfo || !cursor)
return 0;
XFreeCursor(xinfo->display, cursor);
return 1;
}
struct aCursor alock_cursor_image = {
"image",
alock_cursor_image_init,
alock_cursor_image_deinit
};
/* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */