* added -bg image:
- name - name of the image - scale - scaling image - center - centering image - tile - tile image - color=<color> - use <color> as bg-color for centering * -bg blank interpretes the color-option now --HG-- extra : convert_revision : svn%3Aeebe1cee-a9af-4fe4-bd26-ad572b19c5ab/trunk%4014
This commit is contained in:
parent
6ac8241d2a
commit
220620fa34
11 changed files with 403 additions and 169 deletions
15
CHANGELOG
15
CHANGELOG
|
@ -1,8 +1,19 @@
|
||||||
Version 0.9
|
Version 0.9
|
||||||
|
|
||||||
|
2005-05-18:
|
||||||
|
|
||||||
|
* added -bg image:
|
||||||
|
- name - name of the image
|
||||||
|
- scale - scaling image
|
||||||
|
- center - centering image
|
||||||
|
- tile - tile image
|
||||||
|
- color=<color> - use <color> as bg-color for centering
|
||||||
|
|
||||||
|
|
||||||
2005-05-17:
|
2005-05-17:
|
||||||
|
|
||||||
* restructuring almost done, polished interface;
|
* restructuring almost done, polished interface:
|
||||||
- working -bg, -auth and -cursor with all the submodules
|
: working -bg, -auth and -cursor with all the submodules
|
||||||
- cleaned -h
|
- cleaned -h
|
||||||
- complete -flag - parsing
|
- complete -flag - parsing
|
||||||
* added -cursor font:list and -cursor theme:list
|
* added -cursor font:list and -cursor theme:list
|
||||||
|
|
30
SConstruct
30
SConstruct
|
@ -22,6 +22,7 @@ alock_options.AddOptions(
|
||||||
BoolOption('pam', 'support for pam', 1),
|
BoolOption('pam', 'support for pam', 1),
|
||||||
BoolOption('hash', 'support for hashs(sha1,md5)', 1),
|
BoolOption('hash', 'support for hashs(sha1,md5)', 1),
|
||||||
|
|
||||||
|
BoolOption('imlib2', 'support imagereading via imlib2', 1),
|
||||||
BoolOption('xcursor', 'support xcursor-themes', 1),
|
BoolOption('xcursor', 'support xcursor-themes', 1),
|
||||||
|
|
||||||
BoolOption('amd5', 'build a little md5-helper', 0),
|
BoolOption('amd5', 'build a little md5-helper', 0),
|
||||||
|
@ -51,6 +52,12 @@ alock_env.AppendUnique(
|
||||||
LIBPATH = ['/usr/X11R6/lib'],
|
LIBPATH = ['/usr/X11R6/lib'],
|
||||||
LIBS = [ 'X11' ])
|
LIBS = [ 'X11' ])
|
||||||
|
|
||||||
|
conf = alock_env.Configure()
|
||||||
|
if not conf.CheckLibWithHeader('X11', 'X11/Xlib.h', 'C', 'XOpenDisplay(0);', 1):
|
||||||
|
print "sorry, no headers or libs for X11 found, cant build alock."
|
||||||
|
Exit(1)
|
||||||
|
conf.Finish()
|
||||||
|
|
||||||
if alock_env['debug']:
|
if alock_env['debug']:
|
||||||
alock_env.AppendUnique(
|
alock_env.AppendUnique(
|
||||||
CPPDEFINES = [ 'DEBUG' ],
|
CPPDEFINES = [ 'DEBUG' ],
|
||||||
|
@ -90,6 +97,29 @@ if alock_env['xcursor']:
|
||||||
print "sorry, no xcursor-support found."
|
print "sorry, no xcursor-support found."
|
||||||
conf.Finish()
|
conf.Finish()
|
||||||
|
|
||||||
|
if alock_env['imlib2']:
|
||||||
|
conf = alock_env.Configure()
|
||||||
|
if not conf.env.WhereIs('imlib2-config'):
|
||||||
|
print "cant find 'imlib2-config. exit."
|
||||||
|
Exit(1)
|
||||||
|
|
||||||
|
imlib2_env = Environment()
|
||||||
|
imlib2_env.ParseConfig('imlib2-config --cflags --libs')
|
||||||
|
if not imlib2_env.Dictionary()['LIBS']:
|
||||||
|
print "missing imlib2, install it."
|
||||||
|
Exit(1)
|
||||||
|
|
||||||
|
alock_env.AppendUnique(
|
||||||
|
CPPDEFINES = [ 'HAVE_IMLIB2' ],
|
||||||
|
LIBPATH = imlib2_env.Dictionary()['LIBPATH'],
|
||||||
|
CPPAPTH = imlib2_env.Dictionary()['CPPPATH'],
|
||||||
|
LIBS = imlib2_env.Dictionary()['LIBS']
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
default_targets = [ alock_target ]
|
default_targets = [ alock_target ]
|
||||||
if alock_env['amd5']:
|
if alock_env['amd5']:
|
||||||
|
|
12
alock.txt
12
alock.txt
|
@ -44,14 +44,18 @@ OPTIONS
|
||||||
-bg type:options ::
|
-bg type:options ::
|
||||||
Define the type of alock should handle the background:
|
Define the type of alock should handle the background:
|
||||||
- list - Displays a list of available types
|
- list - Displays a list of available types
|
||||||
- none - you can see everything like it is
|
- none - You can see everything like it is
|
||||||
- blank:color - fill the background with color
|
- blank:color - Fill the background with color
|
||||||
|
- image:name,center,scale,tile,color=<color> - Use the image <name> and puts it as
|
||||||
|
the background.
|
||||||
|
|
||||||
-cursor type:options ::
|
-cursor type:options ::
|
||||||
Define the look-a-like of the cursor/mouse pointer:
|
Define the look-a-like of the cursor/mouse pointer:
|
||||||
- list - Displays a list of available types
|
- list - Displays a list of available types
|
||||||
- theme:name,bg=color,fg=color
|
- theme:name,bg=<color>,fg=<color> - Use the given internal cursor, if name == "list" it lists
|
||||||
- Use the given internal cursor
|
the available themes
|
||||||
|
- font:name,bg=<color>,fg=<color> - Use the given glyph of the "cursor"-font, if name ==
|
||||||
|
"list" it lists the available glyphnames
|
||||||
- xcursor:file - Use the given cursorfile in xcursor-format
|
- xcursor:file - Use the given cursorfile in xcursor-format
|
||||||
- none - no change to the current cursor
|
- none - no change to the current cursor
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ if build['pam']:
|
||||||
if build['xcursor']:
|
if build['xcursor']:
|
||||||
cursor_sources += [ 'cursor_xcursor.c' ]
|
cursor_sources += [ 'cursor_xcursor.c' ]
|
||||||
|
|
||||||
|
if build['imlib2']:
|
||||||
|
bg_sources += [ 'bg_imlib2.c' ]
|
||||||
|
|
||||||
alock_sources += auth_sources + bg_sources + cursor_sources
|
alock_sources += auth_sources + bg_sources + cursor_sources
|
||||||
|
|
||||||
|
|
235
src/alock.c
235
src/alock.c
|
@ -1,27 +1,15 @@
|
||||||
/*------------------------------------------------------------------*\
|
|
||||||
|
/* ---------------------------------------------------------------- *\
|
||||||
|
|
||||||
file : alock.c
|
file : alock.c
|
||||||
|
author : m. gumz <akira at fluxbox dot org>
|
||||||
|
copyr : copyright (c) 2005 by m. gumz
|
||||||
|
|
||||||
X Transparent Lock
|
license : see LICENSE
|
||||||
|
|
||||||
copyright:
|
start : Sa 30 April 2005 14:19:44 CEST
|
||||||
|
|
||||||
Copyright (C)2005 Mathias Gumz (forked alock)
|
\* ---------------------------------------------------------------- */
|
||||||
Copyright (C)1993,1994 Ian Jackson (xtrlock)
|
|
||||||
|
|
||||||
license:
|
|
||||||
|
|
||||||
This is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2, or (at your option)
|
|
||||||
any later version.
|
|
||||||
|
|
||||||
This is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
\*------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*\
|
/*------------------------------------------------------------------*\
|
||||||
\*------------------------------------------------------------------*/
|
\*------------------------------------------------------------------*/
|
||||||
|
@ -30,10 +18,6 @@
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/Xos.h>
|
#include <X11/Xos.h>
|
||||||
|
|
||||||
#ifdef HAVE_XPM
|
|
||||||
# include <X11/xpm.h>
|
|
||||||
#endif /* HAVE_XPM */
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -46,18 +30,6 @@
|
||||||
/*------------------------------------------------------------------*\
|
/*------------------------------------------------------------------*\
|
||||||
globals
|
globals
|
||||||
\*------------------------------------------------------------------*/
|
\*------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define TIMEOUTPERATTEMPT 30000
|
|
||||||
#define MAXGOODWILL (TIMEOUTPERATTEMPT*5)
|
|
||||||
#define INITIALGOODWILL MAXGOODWILL
|
|
||||||
#define GOODWILLPORTION 0.3
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
# define DBGMSG fprintf(stderr, "%s : %d\n", __FUNCTION__, __LINE__); fflush(stderr)
|
|
||||||
#else
|
|
||||||
# define DBGMSG
|
|
||||||
#endif // DEBUG
|
|
||||||
|
|
||||||
static struct aAuth* alock_authmodules[] = {
|
static struct aAuth* alock_authmodules[] = {
|
||||||
#ifdef PAM_PWD
|
#ifdef PAM_PWD
|
||||||
&alock_auth_pam,
|
&alock_auth_pam,
|
||||||
|
@ -76,6 +48,9 @@ static struct aAuth* alock_authmodules[] = {
|
||||||
static struct aBackground* alock_backgrounds[] = {
|
static struct aBackground* alock_backgrounds[] = {
|
||||||
&alock_bg_none,
|
&alock_bg_none,
|
||||||
&alock_bg_blank,
|
&alock_bg_blank,
|
||||||
|
#ifdef HAVE_IMLIB2
|
||||||
|
&alock_bg_imlib2,
|
||||||
|
#endif /* HAVE_IMLIB2 */
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,7 +63,6 @@ static struct aCursor* alock_cursors[] = {
|
||||||
#endif /* HAVE_XCURSOR */
|
#endif /* HAVE_XCURSOR */
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------------------*\
|
/*------------------------------------------------------------------*\
|
||||||
\*------------------------------------------------------------------*/
|
\*------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -114,32 +88,81 @@ void initXInfo(struct aXInfo* xinfo, struct aOpts* opts) {
|
||||||
|
|
||||||
xinfo->root = DefaultRootWindow(dpy);
|
xinfo->root = DefaultRootWindow(dpy);
|
||||||
xinfo->colormap = DefaultColormap(dpy, DefaultScreen(dpy));
|
xinfo->colormap = DefaultColormap(dpy, DefaultScreen(dpy));
|
||||||
|
|
||||||
/* TODO: doesnt work yet. */
|
|
||||||
/*
|
|
||||||
* if (opts->cursor_name && (strstr(opts->cursor_name, "xbm:"))) {
|
|
||||||
unsigned int w, h, xhot, yhot;
|
|
||||||
if (XReadBitmapFile(dpy, xinfo->root, &opts->cursor_name[4],
|
|
||||||
&w, &h, &pixmap_cursor, &xhot, &yhot)) {
|
|
||||||
xinfo->cursor = XCreatePixmapCursor(dpy,
|
|
||||||
pixmap_cursor, NULL,
|
|
||||||
&color_fg, &color_bg,
|
|
||||||
xhot, yhot);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
printf("alock: error, couldnt load [%s]\n", &opts->cursor_name[4]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
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;
|
int clen, rlen = 0;
|
||||||
long goodwill = INITIALGOODWILL, timeout = 0;
|
|
||||||
|
long goodwill = 5 * 30000;
|
||||||
|
long timeout = 0;
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
XNextEvent(xinfo->display, &ev);
|
||||||
|
switch (ev.type) {
|
||||||
|
case KeyPress:
|
||||||
|
|
||||||
|
if (ev.xkey.time < timeout) {
|
||||||
|
XBell(xinfo->display, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
clen = XLookupString(&ev.xkey, cbuf, 9, &ks, 0);
|
||||||
|
switch (ks) {
|
||||||
|
case XK_Escape:
|
||||||
|
case XK_Clear:
|
||||||
|
rlen = 0;
|
||||||
|
break;
|
||||||
|
case XK_Delete:
|
||||||
|
case XK_BackSpace:
|
||||||
|
if (rlen > 0)
|
||||||
|
rlen--;
|
||||||
|
break;
|
||||||
|
case XK_Linefeed:
|
||||||
|
case XK_Return:
|
||||||
|
if (rlen == 0)
|
||||||
|
break;
|
||||||
|
if (rlen < sizeof(rbuf))
|
||||||
|
rbuf[rlen] = 0;
|
||||||
|
|
||||||
|
if (opts->auth->auth(rbuf))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
XSync(xinfo->display, True); /* discard pending events to start really fresh */
|
||||||
|
XBell(xinfo->display, 0);
|
||||||
|
rlen = 0;
|
||||||
|
if (timeout) {
|
||||||
|
goodwill += ev.xkey.time - timeout;
|
||||||
|
if (goodwill > 5 * 30000) {
|
||||||
|
goodwill = 5 * 30000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timeout = -goodwill * 0.3;
|
||||||
|
goodwill += timeout;
|
||||||
|
timeout += ev.xkey.time + 30000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (clen != 1)
|
||||||
|
break;
|
||||||
|
if (rlen < sizeof(rbuf))
|
||||||
|
rbuf[rlen] = cbuf[0];
|
||||||
|
rlen++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
|
||||||
struct aXInfo xinfo;
|
struct aXInfo xinfo;
|
||||||
struct aOpts opts;
|
struct aOpts opts;
|
||||||
|
@ -180,12 +203,12 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bg_tmp) {
|
if (!bg_tmp) {
|
||||||
fprintf(stderr, "alock: error, couldnt find the bg-module you specified.\n");
|
printf("alock: error, couldnt find the bg-module you specified.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "alock, error, missing argument\n");
|
printf("alock, error, missing argument\n");
|
||||||
displayUsage();
|
displayUsage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -207,7 +230,7 @@ int main(int argc, char **argv) {
|
||||||
if(char_tmp && char_tmp == argv[arg]) {
|
if(char_tmp && char_tmp == argv[arg]) {
|
||||||
auth_tmp = (*i);
|
auth_tmp = (*i);
|
||||||
if (!auth_tmp->init(argv[arg])) {
|
if (!auth_tmp->init(argv[arg])) {
|
||||||
fprintf(stderr, "alock: error, failed init of [%s].\n", auth_tmp->name);
|
printf("alock: error, failed init of [%s].\n", auth_tmp->name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
opts.auth = auth_tmp;
|
opts.auth = auth_tmp;
|
||||||
|
@ -217,12 +240,12 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!auth_tmp) {
|
if (!auth_tmp) {
|
||||||
fprintf(stderr, "alock: error, couldnt find the auth-module you specified.\n");
|
printf("alock: error, couldnt find the auth-module you specified.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "alock, error, missing argument\n");
|
printf("alock, error, missing argument\n");
|
||||||
displayUsage();
|
displayUsage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -251,12 +274,12 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cursor_tmp) {
|
if (!cursor_tmp) {
|
||||||
fprintf(stderr, "alock: error, couldnt find the cursor-module you specified.\n");
|
printf("alock: error, couldnt find the cursor-module you specified.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "alock, error, missing argument\n");
|
printf("alock, error, missing argument\n");
|
||||||
displayUsage();
|
displayUsage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -290,30 +313,6 @@ int main(int argc, char **argv) {
|
||||||
XMapWindow(xinfo.display, xinfo.window);
|
XMapWindow(xinfo.display, xinfo.window);
|
||||||
XRaiseWindow(xinfo.display, xinfo.window);
|
XRaiseWindow(xinfo.display, xinfo.window);
|
||||||
|
|
||||||
/* TODO: -bg <blank|transparent|shaded> */
|
|
||||||
/* if (opts.use_blank) {
|
|
||||||
XImage* ximage;
|
|
||||||
|
|
||||||
ximage = XGetImage (xinfo.display, xinfo.root, 0, 0,
|
|
||||||
xinfo.width, xinfo.height, AllPlanes, ZPixmap);
|
|
||||||
|
|
||||||
if (ximage) {
|
|
||||||
GC gc;
|
|
||||||
XGCValues xgcv;
|
|
||||||
xgcv.background = BlackPixel(xinfo.display, DefaultScreen(xinfo.display));
|
|
||||||
xgcv.foreground = 0;
|
|
||||||
|
|
||||||
gc = XCreateGC(xinfo.display, xinfo.window, GCForeground|GCBackground, &xgcv);
|
|
||||||
|
|
||||||
XPutImage(xinfo.display, xinfo.window,
|
|
||||||
gc,
|
|
||||||
ximage,
|
|
||||||
0, 0,
|
|
||||||
0, 0, xinfo.width, xinfo.height);
|
|
||||||
XDestroyImage(ximage);
|
|
||||||
XFreeGC(xinfo.display, gc);
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
/* try to grab 2 times, another process (windowmanager) may have grabbed
|
/* try to grab 2 times, another process (windowmanager) may have grabbed
|
||||||
* the keyboard already */
|
* the keyboard already */
|
||||||
if ((XGrabKeyboard(xinfo.display, xinfo.window, True, GrabModeAsync, GrabModeAsync,
|
if ((XGrabKeyboard(xinfo.display, xinfo.window, True, GrabModeAsync, GrabModeAsync,
|
||||||
|
@ -321,7 +320,7 @@ int main(int argc, char **argv) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
if ((XGrabKeyboard(xinfo.display, xinfo.window, True, GrabModeAsync, GrabModeAsync,
|
if ((XGrabKeyboard(xinfo.display, xinfo.window, True, GrabModeAsync, GrabModeAsync,
|
||||||
CurrentTime)) != GrabSuccess) {
|
CurrentTime)) != GrabSuccess) {
|
||||||
perror("alock: couldnt grab the keyboard.\n");
|
printf("alock: couldnt grab the keyboard.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,69 +328,11 @@ int main(int argc, char **argv) {
|
||||||
if (XGrabPointer(xinfo.display, xinfo.window, False, (KeyPressMask|KeyReleaseMask) & 0,
|
if (XGrabPointer(xinfo.display, xinfo.window, False, (KeyPressMask|KeyReleaseMask) & 0,
|
||||||
GrabModeAsync, GrabModeAsync, None, xinfo.cursor, CurrentTime) != GrabSuccess) {
|
GrabModeAsync, GrabModeAsync, None, xinfo.cursor, CurrentTime) != GrabSuccess) {
|
||||||
XUngrabKeyboard(xinfo.display, CurrentTime);
|
XUngrabKeyboard(xinfo.display, CurrentTime);
|
||||||
perror("alock: couldnt grab the pointer.\n");
|
printf("alock: couldnt grab the pointer.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eventhandling */
|
event_loop(&opts, &xinfo);
|
||||||
for(;;) {
|
|
||||||
XNextEvent(xinfo.display, &ev);
|
|
||||||
switch (ev.type) {
|
|
||||||
case KeyPress:
|
|
||||||
|
|
||||||
if (ev.xkey.time < timeout) {
|
|
||||||
XBell(xinfo.display, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
clen = XLookupString(&ev.xkey, cbuf, 9, &ks, 0);
|
|
||||||
switch (ks) {
|
|
||||||
case XK_Escape:
|
|
||||||
case XK_Clear:
|
|
||||||
rlen = 0;
|
|
||||||
break;
|
|
||||||
case XK_Delete:
|
|
||||||
case XK_BackSpace:
|
|
||||||
if (rlen > 0)
|
|
||||||
rlen--;
|
|
||||||
break;
|
|
||||||
case XK_Linefeed:
|
|
||||||
case XK_Return:
|
|
||||||
if (rlen == 0)
|
|
||||||
break;
|
|
||||||
rbuf[rlen] = 0;
|
|
||||||
|
|
||||||
if (opts.auth->auth(rbuf))
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
XSync(xinfo.display, True); /* discard pending events to start really fresh */
|
|
||||||
XBell(xinfo.display, 0);
|
|
||||||
rlen = 0;
|
|
||||||
if (timeout) {
|
|
||||||
goodwill += ev.xkey.time - timeout;
|
|
||||||
if (goodwill > MAXGOODWILL) {
|
|
||||||
goodwill = MAXGOODWILL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timeout = -goodwill * GOODWILLPORTION;
|
|
||||||
goodwill += timeout;
|
|
||||||
timeout += ev.xkey.time + TIMEOUTPERATTEMPT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (clen != 1)
|
|
||||||
break;
|
|
||||||
if (rlen < sizeof(rbuf))
|
|
||||||
rbuf[rlen] = cbuf[0];
|
|
||||||
rlen++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
|
||||||
|
|
||||||
opts.auth->deinit();
|
opts.auth->deinit();
|
||||||
opts.cursor->deinit(&xinfo);
|
opts.cursor->deinit(&xinfo);
|
||||||
|
|
12
src/alock.h
12
src/alock.h
|
@ -21,8 +21,13 @@
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *\
|
/* ---------------------------------------------------------------- *\
|
||||||
\* ---------------------------------------------------------------- */
|
\* ---------------------------------------------------------------- */
|
||||||
|
#ifdef DEBUG
|
||||||
|
# define DBGMSG fprintf(stderr, "%s : %d\n", __FUNCTION__, __LINE__); fflush(stderr)
|
||||||
|
#else
|
||||||
|
# define DBGMSG
|
||||||
|
#endif // DEBUG
|
||||||
|
/*------------------------------------------------------------------*\
|
||||||
|
\*------------------------------------------------------------------*/
|
||||||
|
|
||||||
struct aXInfo {
|
struct aXInfo {
|
||||||
|
|
||||||
|
@ -64,6 +69,9 @@ struct aOpts {
|
||||||
\*------------------------------------------------------------------*/
|
\*------------------------------------------------------------------*/
|
||||||
extern struct aBackground alock_bg_none;
|
extern struct aBackground alock_bg_none;
|
||||||
extern struct aBackground alock_bg_blank;
|
extern struct aBackground alock_bg_blank;
|
||||||
|
#ifdef HAVE_IMLIB2
|
||||||
|
extern struct aBackground alock_bg_imlib2;
|
||||||
|
#endif /* HAVE_IMLIB2 */
|
||||||
/*------------------------------------------------------------------*\
|
/*------------------------------------------------------------------*\
|
||||||
\*------------------------------------------------------------------*/
|
\*------------------------------------------------------------------*/
|
||||||
extern struct aAuth alock_auth_none;
|
extern struct aAuth alock_auth_none;
|
||||||
|
|
|
@ -21,30 +21,54 @@
|
||||||
includes
|
includes
|
||||||
\* ---------------------------------------------------------------- */
|
\* ---------------------------------------------------------------- */
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "alock.h"
|
#include "alock.h"
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *\
|
/* ---------------------------------------------------------------- *\
|
||||||
\* ---------------------------------------------------------------- */
|
\* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
static Window window = 0;
|
static Window window = 0;
|
||||||
|
static XColor color;
|
||||||
|
|
||||||
static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
|
static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
|
||||||
|
|
||||||
XWindowAttributes xgwa;
|
XWindowAttributes xgwa;
|
||||||
XSetWindowAttributes xswa;
|
XSetWindowAttributes xswa;
|
||||||
long xsmask = 0;
|
long xsmask = 0;
|
||||||
|
XColor tmp_color;
|
||||||
|
char* color_name = strdup("black");
|
||||||
|
|
||||||
if (!xinfo)
|
if (!xinfo || !args)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* TODO: parse args for color */
|
if (strstr(args, "blank:") == 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp_color, &color)) == 0)
|
||||||
|
XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color);
|
||||||
|
|
||||||
|
free(color_name);
|
||||||
|
|
||||||
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa);
|
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa);
|
||||||
|
|
||||||
xswa.override_redirect = True;
|
xswa.override_redirect = True;
|
||||||
xswa.colormap = xinfo->colormap;
|
xswa.colormap = xinfo->colormap;
|
||||||
xswa.background_pixel = BlackPixel(xinfo->display,
|
xswa.background_pixel = color.pixel;
|
||||||
DefaultScreen(xinfo->display));
|
|
||||||
|
|
||||||
xsmask |= CWOverrideRedirect;
|
xsmask |= CWOverrideRedirect;
|
||||||
xsmask |= CWBackPixel;
|
xsmask |= CWBackPixel;
|
||||||
|
@ -58,6 +82,7 @@ static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
|
||||||
CopyFromParent, /* visual */
|
CopyFromParent, /* visual */
|
||||||
xsmask, &xswa);
|
xsmask, &xswa);
|
||||||
|
|
||||||
|
|
||||||
if (window)
|
if (window)
|
||||||
xinfo->window = window;
|
xinfo->window = window;
|
||||||
|
|
||||||
|
|
212
src/bg_imlib2.c
Normal file
212
src/bg_imlib2.c
Normal file
|
@ -0,0 +1,212 @@
|
||||||
|
/* ---------------------------------------------------------------- *\
|
||||||
|
|
||||||
|
file : bg_imlib2.c
|
||||||
|
author : m. gumz <akira at fluxbox dot org>
|
||||||
|
copyr : copyright (c) 2005 by m. gumz
|
||||||
|
|
||||||
|
license : see LICENSE
|
||||||
|
|
||||||
|
start : Mi 18 Mai 2005 00:51:10 CEST
|
||||||
|
|
||||||
|
\* ---------------------------------------------------------------- */
|
||||||
|
/* ---------------------------------------------------------------- *\
|
||||||
|
|
||||||
|
about :
|
||||||
|
|
||||||
|
provide -bg image:filename via imlib2
|
||||||
|
|
||||||
|
\* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *\
|
||||||
|
includes
|
||||||
|
\* ---------------------------------------------------------------- */
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <Imlib2.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "alock.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *\
|
||||||
|
\* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ALOCK_SCALE = 1,
|
||||||
|
ALOCK_CENTER = 2,
|
||||||
|
ALOCK_TILED = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
static Window window = 0;
|
||||||
|
static Pixmap pixmap = 0;
|
||||||
|
static XColor color;
|
||||||
|
|
||||||
|
static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) {
|
||||||
|
|
||||||
|
XWindowAttributes xgwa;
|
||||||
|
XSetWindowAttributes xswa;
|
||||||
|
long xsmask = 0;
|
||||||
|
long options = ALOCK_SCALE;
|
||||||
|
XColor tmp_color;
|
||||||
|
char* filename = NULL;
|
||||||
|
char* color_name = strdup("black");
|
||||||
|
|
||||||
|
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, "scale") == arg) {
|
||||||
|
options = ALOCK_SCALE;
|
||||||
|
} else if (strstr(arg, "center")) {
|
||||||
|
options = ALOCK_CENTER;
|
||||||
|
} else if (strstr(arg, "tile")) {
|
||||||
|
options = ALOCK_TILED;
|
||||||
|
} else if (strstr(arg, "color=") == arg && strlen(arg) > 6 && strlen(&arg[6])) {
|
||||||
|
free(color_name);
|
||||||
|
color_name = strdup(&arg[6]);
|
||||||
|
} else {
|
||||||
|
if (!filename)
|
||||||
|
filename = strdup(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filename) {
|
||||||
|
printf("alock: error, no filename specified for [image]\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp_color, &color)) == 0)
|
||||||
|
XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color);
|
||||||
|
|
||||||
|
free(color_name);
|
||||||
|
|
||||||
|
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa);
|
||||||
|
|
||||||
|
|
||||||
|
/* get image and set it as the background pixmap for the window */
|
||||||
|
{
|
||||||
|
Imlib_Context context = NULL;
|
||||||
|
Imlib_Image image = NULL;
|
||||||
|
|
||||||
|
context = imlib_context_new();
|
||||||
|
imlib_context_push(context);
|
||||||
|
imlib_context_set_display(xinfo->display);
|
||||||
|
imlib_context_set_visual(DefaultVisual(xinfo->display,
|
||||||
|
DefaultScreen(xinfo->display)));
|
||||||
|
imlib_context_set_colormap(xinfo->colormap);
|
||||||
|
|
||||||
|
image = imlib_load_image_without_cache(filename);
|
||||||
|
if (image) {
|
||||||
|
|
||||||
|
pixmap = XCreatePixmap(xinfo->display, xinfo->root,
|
||||||
|
xgwa.width, xgwa.height,
|
||||||
|
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display)));
|
||||||
|
|
||||||
|
imlib_context_set_image(image);
|
||||||
|
|
||||||
|
if (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);
|
||||||
|
} 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;
|
||||||
|
gcval.tile = tile;
|
||||||
|
gc = XCreateGC(xinfo->display, tile, GCFillStyle|GCTile, &gcval);
|
||||||
|
XFillRectangle(xinfo->display, pixmap, gc, 0, 0, xgwa.width, xgwa.height);
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("alock: error, couldnt load [%s].\n", filename);
|
||||||
|
if (filename)
|
||||||
|
free(filename);
|
||||||
|
XDestroyWindow(xinfo->display, window);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
imlib_context_pop();
|
||||||
|
imlib_context_free(context);
|
||||||
|
context = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
xswa.override_redirect = True;
|
||||||
|
xswa.colormap = xinfo->colormap;
|
||||||
|
xswa.background_pixmap = pixmap;
|
||||||
|
|
||||||
|
xsmask |= CWOverrideRedirect;
|
||||||
|
xsmask |= CWColormap;
|
||||||
|
xsmask |= CWBackPixmap;
|
||||||
|
|
||||||
|
window = XCreateWindow(xinfo->display, xinfo->root,
|
||||||
|
0, 0, xgwa.width, xgwa.height,
|
||||||
|
0, /* borderwidth */
|
||||||
|
CopyFromParent, /* depth */
|
||||||
|
InputOutput, /* class */
|
||||||
|
CopyFromParent, /* visual */
|
||||||
|
xsmask, &xswa);
|
||||||
|
|
||||||
|
XMapWindow(xinfo->display, window);
|
||||||
|
|
||||||
|
if (window)
|
||||||
|
xinfo->window = window;
|
||||||
|
|
||||||
|
if (filename)
|
||||||
|
free(filename);
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int alock_bg_imlib2_deinit(struct aXInfo* xinfo) {
|
||||||
|
if (!xinfo || !window)
|
||||||
|
return 0;
|
||||||
|
XDestroyWindow(xinfo->display, window);
|
||||||
|
XFreePixmap(xinfo->display, pixmap);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct aBackground alock_bg_imlib2 = {
|
||||||
|
"image",
|
||||||
|
alock_bg_imlib2_init,
|
||||||
|
alock_bg_imlib2_deinit
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *\
|
||||||
|
\* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -153,11 +153,11 @@ static int alock_cursor_font_init(const char* args, struct aXInfo* xinfo) {
|
||||||
free(arguments);
|
free(arguments);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if (strstr(arg, "fg=") == arg && strlen(&arg[3])) {
|
if (strstr(arg, "fg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) {
|
||||||
free(color_fg_name);
|
free(color_fg_name);
|
||||||
color_fg_name = strdup(&arg[3]);
|
color_fg_name = strdup(&arg[3]);
|
||||||
}
|
}
|
||||||
else if (strstr(arg, "bg=") == arg && strlen(&arg[3])) {
|
else if (strstr(arg, "bg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) {
|
||||||
free(color_bg_name);
|
free(color_bg_name);
|
||||||
color_bg_name = strdup(&arg[3]);
|
color_bg_name = strdup(&arg[3]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,11 +104,11 @@ static int alock_cursor_theme_init(const char* args, struct aXInfo* xinfo) {
|
||||||
free(arguments);
|
free(arguments);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if (strstr(arg, "fg=") == arg && strlen(&arg[3])) {
|
if (strstr(arg, "fg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) {
|
||||||
free(color_fg_name);
|
free(color_fg_name);
|
||||||
color_fg_name = strdup(&arg[3]);
|
color_fg_name = strdup(&arg[3]);
|
||||||
}
|
}
|
||||||
else if (strstr(arg, "bg=") == arg && strlen(&arg[3])) {
|
else if (strstr(arg, "bg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) {
|
||||||
free(color_bg_name);
|
free(color_bg_name);
|
||||||
color_bg_name = strdup(&arg[3]);
|
color_bg_name = strdup(&arg[3]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
\* ---------------------------------------------------------------- */
|
\* ---------------------------------------------------------------- */
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xcursor/Xcursor.h>
|
#include <X11/Xcursor/Xcursor.h>
|
||||||
|
#include <string.h>
|
||||||
#include "alock.h"
|
#include "alock.h"
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *\
|
/* ---------------------------------------------------------------- *\
|
||||||
|
@ -34,13 +35,13 @@ static int alock_cursor_xcursor_init(const char* args, struct aXInfo* xinfo) {
|
||||||
if (!xinfo)
|
if (!xinfo)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!args) {
|
if (!args || strlen(args) < 8) {
|
||||||
printf("alock: error, missing arguments for [xcursor]\n");
|
printf("alock: error, missing arguments for [xcursor]\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cursor = XcursorFilenameLoadCursor(xinfo->display, args))) {
|
if (!(cursor = XcursorFilenameLoadCursor(xinfo->display, &args[8]))) {
|
||||||
printf("alock: error, couldnt load [%s]\n", args);
|
printf("alock: error, couldnt load [%s]\n", &args[8]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue