* lock all screens when X runs in multiscreen mode and display whatever the

-bg defines

--HG--
extra : convert_revision : svn%3Aeebe1cee-a9af-4fe4-bd26-ad572b19c5ab/trunk%4040
This commit is contained in:
mathias 2006-05-05 00:41:21 +00:00
parent 569a19488c
commit 83cf2e7a88
16 changed files with 508 additions and 353 deletions

View file

@ -1,4 +1,6 @@
Version 1.0 Version 1.0
2006-05-05:
* lock all screens if in X is running in multiscreen mode
2005-12-25: 2005-12-25:
* added -auth sha256 * added -auth sha256
* added -auth sha384 * added -auth sha384

4
README
View file

@ -1,7 +1,7 @@
alock - README alock - README
============== ==============
Mathias Gumz <akira@fluxbox.org> Mathias Gumz <akira@fluxbox.org>
v1.0, 25 December 2005 v1.0, 05 May 2006
About About
----- -----
@ -68,7 +68,7 @@ from 'xtrlock' left.
Author / Contributors Author / Contributors
--------------------- ---------------------
* 2005 Mathias Gumz aka akira <akira@fluxbox.org> (code) * 2005 - 2006 Mathias Gumz aka akira <akira@fluxbox.org> (code)
* 1993 - 1994 Ian Jackson (xtrlock) * 1993 - 1994 Ian Jackson (xtrlock)
* 2005 Tenner (alock-logo) * 2005 Tenner (alock-logo)

View file

@ -1,7 +1,7 @@
ALOCK(1) ALOCK(1)
======== ========
Mathias Gumz <akira@fluxbox.org> Mathias Gumz <akira@fluxbox.org>
v1.0, 25 December 2005 v1.0, 05 May 2006
NAME NAME
---- ----
@ -108,6 +108,6 @@ Other Lockers ::
COPYING COPYING
------- -------
Copyright (C) 2005 Mathias Gumz. Free use of this software is Copyright (C) 2005 - 2006 Mathias Gumz. Free use of this software is
granted under the terms of the MIT. See LICENSE provided in the granted under the terms of the MIT. See LICENSE provided in the
distribution. distribution.

View file

@ -2,7 +2,7 @@
#define alock_height 100 #define alock_height 100
#define alock_x_hot 23 #define alock_x_hot 23
#define alock_y_hot 46 #define alock_y_hot 46
static unsigned char alock_bits[] = { static char alock_bits[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

View file

@ -131,10 +131,21 @@ void initXInfo(struct aXInfo* xinfo, struct aOpts* opts) {
} }
xinfo->display = dpy; xinfo->display = dpy;
xinfo->window = 0; xinfo->nr_screens = ScreenCount(dpy);
xinfo->root = DefaultRootWindow(dpy); xinfo->window = (Window*)calloc(xinfo->nr_screens, sizeof(Window));
xinfo->colormap = DefaultColormap(dpy, DefaultScreen(dpy)); xinfo->root = (Window*)calloc(xinfo->nr_screens, sizeof(Window));
xinfo->colormap = (Colormap*)calloc(xinfo->nr_screens, sizeof(Colormap));
xinfo->cursor = (Cursor*)calloc(xinfo->nr_screens, sizeof(Cursor));
{
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
xinfo->window[scr] = 0;
xinfo->root[scr] = RootWindow(dpy, scr);
xinfo->colormap[scr] = DefaultColormap(dpy, scr);
}
}
} }
int event_loop(struct aOpts* opts, struct aXInfo* xinfo) { int event_loop(struct aOpts* opts, struct aXInfo* xinfo) {
@ -358,24 +369,33 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
XSelectInput(xinfo.display, xinfo.window, KeyPressMask|KeyReleaseMask); {
XMapWindow(xinfo.display, xinfo.window); int scr;
XRaiseWindow(xinfo.display, xinfo.window); for (scr = 0; scr < xinfo.nr_screens; scr++) {
XSelectInput(xinfo.display, xinfo.window[scr], KeyPressMask|KeyReleaseMask);
XMapWindow(xinfo.display, xinfo.window[scr]);
XRaiseWindow(xinfo.display, xinfo.window[scr]);
}
}
/* 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[0], True, GrabModeAsync, GrabModeAsync,
CurrentTime)) != GrabSuccess) { CurrentTime)) != GrabSuccess) {
sleep(1); sleep(1);
if ((XGrabKeyboard(xinfo.display, xinfo.window, True, GrabModeAsync, GrabModeAsync, if ((XGrabKeyboard(xinfo.display, xinfo.window[0], True, GrabModeAsync, GrabModeAsync,
CurrentTime)) != GrabSuccess) { CurrentTime)) != GrabSuccess) {
printf("alock: couldnt grab the keyboard.\n"); printf("alock: couldnt grab the keyboard.\n");
exit(1); exit(1);
} }
} }
if (XGrabPointer(xinfo.display, xinfo.window, False, (KeyPressMask|KeyReleaseMask) & 0, /* TODO: think about it: do we really need NR_SCREEN cursors ? we grab the
GrabModeAsync, GrabModeAsync, None, xinfo.cursor, CurrentTime) != GrabSuccess) { * pointer on :*.0 anyway ... */
if (XGrabPointer(xinfo.display, xinfo.window[0], False, (KeyPressMask|KeyReleaseMask) & 0,
GrabModeAsync, GrabModeAsync, None, xinfo.cursor[0], CurrentTime) != GrabSuccess) {
XUngrabKeyboard(xinfo.display, CurrentTime); XUngrabKeyboard(xinfo.display, CurrentTime);
printf("alock: couldnt grab the pointer.\n"); printf("alock: couldnt grab the pointer.\n");
exit(1); exit(1);

View file

@ -34,11 +34,14 @@
struct aXInfo { struct aXInfo {
Display* display; Display* display;
Window root;
Colormap colormap;
Window window; int nr_screens;
Cursor cursor;
Window* root;
Colormap* colormap;
Window* window;
Cursor* cursor;
}; };
struct aAuth { struct aAuth {
@ -71,8 +74,10 @@ struct aOpts {
\*------------------------------------------------------------------*/ \*------------------------------------------------------------------*/
void alock_string2lower(char* string); void alock_string2lower(char* string);
int alock_native_byte_order(); int alock_native_byte_order();
int alock_alloc_color(const struct aXInfo* xinfo, const char* color_name, int alock_alloc_color(const struct aXInfo* xinfo, const int scr,
const char* fallback_name, XColor* result); const char* color_name,
const char* fallback_name,
XColor* result);
int alock_check_xrender(const struct aXInfo* xinfo); int alock_check_xrender(const struct aXInfo* xinfo);
int alock_shade_pixmap(const struct aXInfo* xinfo, int alock_shade_pixmap(const struct aXInfo* xinfo,
const Pixmap src_pm, const Pixmap src_pm,

View file

@ -39,16 +39,18 @@ void alock_string2lower(char* string) {
/* ---------------------------------------------------------------- *\ /* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */ \* ---------------------------------------------------------------- */
int alock_alloc_color(const struct aXInfo* xinfo, const char* color_name, int alock_alloc_color(const struct aXInfo* xinfo, const int scr, const char* color_name,
const char* fallback_name, XColor* result) { const char* fallback_name, XColor* result) {
static XColor tmp; static XColor tmp;
if (!xinfo || !color_name || !fallback_name || !result) if (!xinfo ||
!xinfo->colormap || xinfo->nr_screens < scr || scr < 0 ||
!color_name || !fallback_name || !result)
return 0; return 0;
if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_name, &tmp, result)) == 0) if((XAllocNamedColor(xinfo->display, xinfo->colormap[scr], color_name, &tmp, result)) == 0)
if ((XAllocNamedColor(xinfo->display, xinfo->colormap, fallback_name, &tmp, result)) == 0) if ((XAllocNamedColor(xinfo->display, xinfo->colormap[scr], fallback_name, &tmp, result)) == 0)
return 0; return 0;
return 1; return 1;
} }

View file

@ -31,8 +31,8 @@
/* ---------------------------------------------------------------- *\ /* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */ \* ---------------------------------------------------------------- */
static Window window = 0; static Window* window = NULL;
static XColor color; static XColor* color = NULL;
static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) { static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
@ -60,20 +60,28 @@ static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
free(arguments); free(arguments);
} }
alock_alloc_color(xinfo, color_name, "black", &color); {
free(color_name); color = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
window = (Window*)calloc(xinfo->nr_screens, sizeof(Window));
}
XGetWindowAttributes(xinfo->display, xinfo->root, &xgwa); {
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
alock_alloc_color(xinfo, scr, color_name, "black", &color[scr]);
XGetWindowAttributes(xinfo->display, xinfo->root[scr], &xgwa);
xswa.override_redirect = True; xswa.override_redirect = True;
xswa.colormap = xinfo->colormap; xswa.colormap = xinfo->colormap[scr];
xswa.background_pixel = color.pixel; xswa.background_pixel = color[scr].pixel;
xsmask |= CWOverrideRedirect; xsmask |= CWOverrideRedirect;
xsmask |= CWBackPixel; xsmask |= CWBackPixel;
xsmask |= CWColormap; xsmask |= CWColormap;
window = XCreateWindow(xinfo->display, xinfo->root, window[scr] = XCreateWindow(xinfo->display, xinfo->root[scr],
0, 0, xgwa.width, xgwa.height, 0, 0, xgwa.width, xgwa.height,
0, /* borderwidth */ 0, /* borderwidth */
CopyFromParent, /* depth */ CopyFromParent, /* depth */
@ -82,16 +90,30 @@ static int alock_bg_blank_init(const char* args, struct aXInfo* xinfo) {
xsmask, &xswa); xsmask, &xswa);
if (window) if (window[scr])
xinfo->window = window; xinfo->window[scr] = window[scr];
return window; }
}
free(color_name);
return 1;
} }
static int alock_bg_blank_deinit(struct aXInfo* xinfo) { static int alock_bg_blank_deinit(struct aXInfo* xinfo) {
if (!xinfo || !window) if (!xinfo)
return 0; return 0;
XDestroyWindow(xinfo->display, window);
{
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
if (window[scr])
XDestroyWindow(xinfo->display, window[scr]);
}
free(window);
free(color);
}
return 1; return 1;
} }

View file

@ -39,9 +39,9 @@ enum {
ALOCK_TILED = 4 ALOCK_TILED = 4
}; };
static Window window = 0; static Window* window = NULL;
static Pixmap pixmap = 0; static Pixmap* pixmap = NULL;
static XColor color; static XColor* color = NULL;
static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) { static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
@ -103,10 +103,20 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
shade = 0; shade = 0;
} }
alock_alloc_color(xinfo, color_name, "black", &color); {
free(color_name); pixmap = (Pixmap*)calloc(xinfo->nr_screens, sizeof(Pixmap));
window = (Window*)calloc(xinfo->nr_screens, sizeof(Window));
color = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
}
{
int scr;
for (scr = 0; xinfo->nr_screens; scr++) {
alock_alloc_color(xinfo, scr, color_name, "black", &color[scr]);
XGetWindowAttributes(xinfo->display, xinfo->root[scr], &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;
@ -116,7 +126,7 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
imlib_context_set_display(xinfo->display); imlib_context_set_display(xinfo->display);
imlib_context_set_visual(DefaultVisual(xinfo->display, imlib_context_set_visual(DefaultVisual(xinfo->display,
DefaultScreen(xinfo->display))); DefaultScreen(xinfo->display)));
imlib_context_set_colormap(xinfo->colormap); imlib_context_set_colormap(xinfo->colormap[scr]);
image = imlib_load_image_without_cache(filename); image = imlib_load_image_without_cache(filename);
if (image) { if (image) {
@ -125,11 +135,11 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
int w; int w;
int h; int h;
pixmap = XCreatePixmap(xinfo->display, xinfo->root, pixmap[scr] = XCreatePixmap(xinfo->display, xinfo->root[scr],
xgwa.width, xgwa.height, xgwa.width, xgwa.height,
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); DefaultDepth(xinfo->display, scr));
imlib_context_set_drawable(pixmap); imlib_context_set_drawable(pixmap[scr]);
imlib_context_set_image(image); imlib_context_set_image(image);
w = imlib_image_get_width(); w = imlib_image_get_width();
@ -140,9 +150,9 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
GC gc; GC gc;
XGCValues gcval; XGCValues gcval;
gcval.foreground = color.pixel; gcval.foreground = color[scr].pixel;
gc = XCreateGC(xinfo->display, xinfo->root, GCForeground, &gcval); gc = XCreateGC(xinfo->display, xinfo->root[scr], GCForeground, &gcval);
XFillRectangle(xinfo->display, pixmap, gc, 0, 0, xgwa.width, xgwa.height); XFillRectangle(xinfo->display, pixmap[scr], gc, 0, 0, xgwa.width, xgwa.height);
XFreeGC(xinfo->display, gc); XFreeGC(xinfo->display, gc);
} }
@ -150,12 +160,12 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
GC gc; GC gc;
XGCValues gcval; XGCValues gcval;
Pixmap tmp_pixmap = XCreatePixmap(xinfo->display, xinfo->root, w, h, Pixmap tmp_pixmap = XCreatePixmap(xinfo->display, xinfo->root[scr], w, h,
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); DefaultDepth(xinfo->display, scr));
Pixmap shaded_pixmap = XCreatePixmap(xinfo->display, xinfo->root, w, h, Pixmap shaded_pixmap = XCreatePixmap(xinfo->display, xinfo->root[scr], w, h,
DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); DefaultDepth(xinfo->display, scr));
gcval.foreground = color.pixel; gcval.foreground = color[scr].pixel;
gc = XCreateGC(xinfo->display, xinfo->root, GCForeground, &gcval); gc = XCreateGC(xinfo->display, xinfo->root[scr], GCForeground, &gcval);
XFillRectangle(xinfo->display, shaded_pixmap, gc, 0, 0, w, h); XFillRectangle(xinfo->display, shaded_pixmap, gc, 0, 0, w, h);
imlib_context_set_drawable(tmp_pixmap); imlib_context_set_drawable(tmp_pixmap);
@ -171,7 +181,7 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
XFreePixmap(xinfo->display, shaded_pixmap); XFreePixmap(xinfo->display, shaded_pixmap);
XFreePixmap(xinfo->display, tmp_pixmap); XFreePixmap(xinfo->display, tmp_pixmap);
imlib_context_set_drawable(pixmap); imlib_context_set_drawable(pixmap[scr]);
imlib_context_set_image(image); imlib_context_set_image(image);
} }
@ -182,15 +192,15 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
GC gc; GC gc;
XGCValues gcval; XGCValues gcval;
tile = XCreatePixmap(xinfo->display, xinfo->root, tile = XCreatePixmap(xinfo->display, xinfo->root[scr],
w, h, DefaultDepth(xinfo->display, DefaultScreen(xinfo->display))); w, h, DefaultDepth(xinfo->display, scr));
imlib_render_image_on_drawable(0, 0); imlib_render_image_on_drawable(0, 0);
gcval.fill_style = FillTiled; gcval.fill_style = FillTiled;
gcval.tile = tile; gcval.tile = tile;
gc = XCreateGC(xinfo->display, tile, GCFillStyle|GCTile, &gcval); gc = XCreateGC(xinfo->display, tile, GCFillStyle|GCTile, &gcval);
XFillRectangle(xinfo->display, pixmap, gc, 0, 0, xgwa.width, xgwa.height); XFillRectangle(xinfo->display, pixmap[scr], gc, 0, 0, xgwa.width, xgwa.height);
XFreeGC(xinfo->display, gc); XFreeGC(xinfo->display, gc);
XFreePixmap(xinfo->display, tile); XFreePixmap(xinfo->display, tile);
@ -203,7 +213,7 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
printf("alock: error, couldnt load [%s].\n", filename); printf("alock: error, couldnt load [%s].\n", filename);
if (filename) if (filename)
free(filename); free(filename);
XDestroyWindow(xinfo->display, window); XDestroyWindow(xinfo->display, window[scr]);
return 0; return 0;
} }
@ -212,14 +222,14 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
} }
xswa.override_redirect = True; xswa.override_redirect = True;
xswa.colormap = xinfo->colormap; xswa.colormap = xinfo->colormap[scr];
xswa.background_pixmap = pixmap; xswa.background_pixmap = pixmap[scr];
xsmask |= CWOverrideRedirect; xsmask |= CWOverrideRedirect;
xsmask |= CWColormap; xsmask |= CWColormap;
xsmask |= CWBackPixmap; xsmask |= CWBackPixmap;
window = XCreateWindow(xinfo->display, xinfo->root, window[scr] = XCreateWindow(xinfo->display, xinfo->root[scr],
0, 0, xgwa.width, xgwa.height, 0, 0, xgwa.width, xgwa.height,
0, /* borderwidth */ 0, /* borderwidth */
CopyFromParent, /* depth */ CopyFromParent, /* depth */
@ -227,10 +237,15 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
CopyFromParent, /* visual */ CopyFromParent, /* visual */
xsmask, &xswa); xsmask, &xswa);
XMapWindow(xinfo->display, window); XMapWindow(xinfo->display, window[scr]);
if (window) if (window[scr])
xinfo->window = window; xinfo->window[scr] = window[scr];
}
free(color_name);
}
if (filename) if (filename)
free(filename); free(filename);
@ -242,8 +257,16 @@ static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) {
static int alock_bg_image_deinit(struct aXInfo* xinfo) { static int alock_bg_image_deinit(struct aXInfo* xinfo) {
if (!xinfo || !window) if (!xinfo || !window)
return 0; return 0;
XDestroyWindow(xinfo->display, window); {
XFreePixmap(xinfo->display, pixmap); int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
XDestroyWindow(xinfo->display, window[scr]);
XFreePixmap(xinfo->display, pixmap[scr]);
}
free(color);
free(pixmap);
free(window);
}
return 1; return 1;
} }

View file

@ -21,11 +21,12 @@
includes includes
\* ---------------------------------------------------------------- */ \* ---------------------------------------------------------------- */
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <stdlib.h>
#include "alock.h" #include "alock.h"
/* ---------------------------------------------------------------- *\ /* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */ \* ---------------------------------------------------------------- */
static Window window = 0; static Window* window = NULL;
static int alock_bg_none_init(const char* args, struct aXInfo* xinfo) { static int alock_bg_none_init(const char* args, struct aXInfo* xinfo) {
@ -35,10 +36,14 @@ static int alock_bg_none_init(const char* args, struct aXInfo* xinfo) {
if (!xinfo) if (!xinfo)
return 0; return 0;
window = (Window*)calloc(xinfo->nr_screens, sizeof(Window));
xswa.override_redirect = True; xswa.override_redirect = True;
xsmask |= CWOverrideRedirect; xsmask |= CWOverrideRedirect;
{
window = XCreateWindow(xinfo->display, xinfo->root, int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
window[scr] = XCreateWindow(xinfo->display, xinfo->root[scr],
0, 0, 1, 1, 0, 0, 1, 1,
0, /* borderwidth */ 0, /* borderwidth */
CopyFromParent, /* depth */ CopyFromParent, /* depth */
@ -46,16 +51,23 @@ static int alock_bg_none_init(const char* args, struct aXInfo* xinfo) {
CopyFromParent, /* visual */ CopyFromParent, /* visual */
xsmask, &xswa); xsmask, &xswa);
if (window) if (window[scr])
xinfo->window = window; xinfo->window[scr] = window[scr];
}
}
return window; return 1;
} }
static int alock_bg_none_deinit(struct aXInfo* xinfo) { static int alock_bg_none_deinit(struct aXInfo* xinfo) {
if (!xinfo || !window) if (!xinfo || !window)
return 0; return 0;
XDestroyWindow(xinfo->display, window); {
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
XDestroyWindow(xinfo->display, window[scr]);
}
}
return 1; return 1;
} }

View file

@ -32,8 +32,8 @@
/* ---------------------------------------------------------------- *\ /* ---------------------------------------------------------------- *\
\* ---------------------------------------------------------------- */ \* ---------------------------------------------------------------- */
static Window window = 0; static Window* window = NULL;
static XColor color; static XColor* color = NULL;
static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) { static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
@ -83,23 +83,29 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
return 0; return 0;
} }
{
window = (Window*)calloc(xinfo->nr_screens, sizeof(Window));
color = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
}
{
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
/* get a color from color_name */ /* get a color from color_name */
alock_alloc_color(xinfo, color_name, "black", &color); alock_alloc_color(xinfo, scr, color_name, "black", &color[scr]);
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[scr], &xgwa);
width = xgwa.width; width = xgwa.width;
height = xgwa.height; height = xgwa.height;
} }
{ /* xrender stuff */ { /* xrender stuff */
Display* dpy = xinfo->display; Display* dpy = xinfo->display;
Window root = xinfo->root; Window root = xinfo->root[scr];
int scrnr = DefaultScreen(dpy); int depth = DefaultDepth(dpy, scr);
int depth = DefaultDepth(dpy, scrnr); GC gc = DefaultGC(dpy, scr);
GC gc = DefaultGC(dpy, scrnr);
{ /* grab whats on the screen */ { /* grab whats on the screen */
XImage* image = XGetImage(dpy, root, 0, 0, width, height, AllPlanes, ZPixmap); XImage* image = XGetImage(dpy, root, 0, 0, width, height, AllPlanes, ZPixmap);
@ -114,7 +120,7 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
GC tintgc; GC tintgc;
XGCValues tintval; XGCValues tintval;
tintval.foreground = color.pixel; tintval.foreground = color[scr].pixel;
tintgc = XCreateGC(dpy, dst_pm, GCForeground, &tintval); tintgc = XCreateGC(dpy, dst_pm, GCForeground, &tintval);
XFillRectangle(dpy, dst_pm, tintgc, 0, 0, width, height); XFillRectangle(dpy, dst_pm, tintgc, 0, 0, width, height);
XFreeGC(dpy, tintgc); XFreeGC(dpy, tintgc);
@ -128,14 +134,14 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
long xsmask = 0; long xsmask = 0;
xswa.override_redirect = True; xswa.override_redirect = True;
xswa.colormap = xinfo->colormap; xswa.colormap = xinfo->colormap[scr];
xswa.background_pixmap = dst_pm; xswa.background_pixmap = dst_pm;
xsmask |= CWOverrideRedirect; xsmask |= CWOverrideRedirect;
xsmask |= CWBackPixmap; xsmask |= CWBackPixmap;
xsmask |= CWColormap; xsmask |= CWColormap;
window = XCreateWindow(xinfo->display, xinfo->root, window[scr] = XCreateWindow(xinfo->display, xinfo->root[scr],
0, 0, width, height, 0, 0, width, height,
0, /* borderwidth */ 0, /* borderwidth */
CopyFromParent, /* depth */ CopyFromParent, /* depth */
@ -146,16 +152,26 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) {
XFreePixmap(xinfo->display, dst_pm); XFreePixmap(xinfo->display, dst_pm);
} }
if (window) if (window[scr])
xinfo->window = window; xinfo->window[scr] = window[scr];
}
free(color_name);
}
return window; return 1;
} }
static int alock_bg_shade_deinit(struct aXInfo* xinfo) { static int alock_bg_shade_deinit(struct aXInfo* xinfo) {
if (!xinfo || !window) if (!xinfo || !window)
return 0; return 0;
XDestroyWindow(xinfo->display, window); {
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
XDestroyWindow(xinfo->display, window[scr]);
}
free(window);
free(color);
}
return 1; return 1;
} }

View file

@ -123,9 +123,9 @@ static const struct CursorFontName cursor_names[] = {
\*------------------------------------------------------------------*/ \*------------------------------------------------------------------*/
static Cursor cursor = 0; static Cursor* cursor = NULL;
static XColor color_fg; static XColor* color_fg = NULL;
static XColor color_bg; static XColor* color_bg = NULL;
static int alock_cursor_glyph_init(const char* args, struct aXInfo* xinfo) { static int alock_cursor_glyph_init(const char* args, struct aXInfo* xinfo) {
@ -179,20 +179,32 @@ static int alock_cursor_glyph_init(const char* args, struct aXInfo* xinfo) {
free(arguments); free(arguments);
} }
alock_alloc_color(xinfo, color_bg_name, "black", &color_bg); {
alock_alloc_color(xinfo, color_fg_name, "white", &color_fg); cursor = (Cursor*)calloc(xinfo->nr_screens, sizeof(Cursor));
color_fg = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
color_bg = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
}
free(color_fg_name); {
free(color_bg_name); int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
alock_alloc_color(xinfo, scr, color_bg_name, "black", &color_bg[scr]);
alock_alloc_color(xinfo, scr, color_fg_name, "white", &color_fg[scr]);
/* create cursor from X11/cursorfont.h */ /* create cursor from X11/cursorfont.h */
if ((cursor = XCreateFontCursor(xinfo->display, shape))) { if ((cursor[scr] = XCreateFontCursor(xinfo->display, shape))) {
XRecolorCursor(xinfo->display, cursor, &color_fg, &color_bg); XRecolorCursor(xinfo->display, cursor[scr], &color_fg[scr], &color_bg[scr]);
xinfo->cursor = cursor; xinfo->cursor[scr] = cursor[scr];
} else { } else {
printf("alock: error, couldnt create fontcursor [%d].\n", shape); printf("alock: error, couldnt create fontcursor [%d].\n", shape);
return 0; return 0;
} }
}
free(color_fg_name);
free(color_bg_name);
}
return 1; return 1;
} }
@ -202,7 +214,16 @@ static int alock_cursor_glyph_deinit(struct aXInfo* xinfo) {
if (!xinfo || !cursor) if (!xinfo || !cursor)
return 0; return 0;
XFreeCursor(xinfo->display, cursor); {
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
XFreeCursor(xinfo->display, cursor[scr]);
}
free(cursor);
free(color_bg);
free(color_fg);
}
return 1; return 1;
} }

View file

@ -90,7 +90,7 @@ static int alock_cursor_image_init(const char* args, struct aXInfo* xinfo) {
imlib_context_push(ctx); imlib_context_push(ctx);
imlib_context_set_display(xinfo->display); imlib_context_set_display(xinfo->display);
imlib_context_set_visual(DefaultVisual(xinfo->display, DefaultScreen(xinfo->display))); imlib_context_set_visual(DefaultVisual(xinfo->display, DefaultScreen(xinfo->display)));
imlib_context_set_colormap(xinfo->colormap); imlib_context_set_colormap(xinfo->colormap[0]);
img = imlib_load_image_without_cache(filename); img = imlib_load_image_without_cache(filename);
if (img) { if (img) {
@ -120,7 +120,7 @@ static int alock_cursor_image_init(const char* args, struct aXInfo* xinfo) {
XInitImage(&ximage); XInitImage(&ximage);
cursor_pm = XCreatePixmap(xinfo->display, xinfo->root, w, h, 32); cursor_pm = XCreatePixmap(xinfo->display, xinfo->root[0], w, h, 32);
gc = XCreateGC(xinfo->display, cursor_pm, 0, 0); gc = XCreateGC(xinfo->display, cursor_pm, 0, 0);
XPutImage(xinfo->display, cursor_pm, gc, &ximage, 0, 0, 0, 0, w, h); XPutImage(xinfo->display, cursor_pm, gc, &ximage, 0, 0, 0, 0, w, h);
XFreeGC(xinfo->display, gc); XFreeGC(xinfo->display, gc);
@ -140,7 +140,7 @@ static int alock_cursor_image_init(const char* args, struct aXInfo* xinfo) {
h = img->height; h = img->height;
cursor_pm = XCreatePixmap(xinfo->display, cursor_pm = XCreatePixmap(xinfo->display,
xinfo->root, xinfo->root[0],
w, h, w, h,
img->depth); img->depth);
gc = XCreateGC(xinfo->display, cursor_pm, 0, NULL); gc = XCreateGC(xinfo->display, cursor_pm, 0, NULL);
@ -179,7 +179,12 @@ static int alock_cursor_image_init(const char* args, struct aXInfo* xinfo) {
free(filename); free(filename);
xinfo->cursor = cursor; {
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
xinfo->cursor[scr] = cursor;
}
}
return cursor; return cursor;
} }

View file

@ -29,7 +29,11 @@
\* ---------------------------------------------------------------- */ \* ---------------------------------------------------------------- */
static int alock_cursor_none_init(const char* args, struct aXInfo* xinfo) { static int alock_cursor_none_init(const char* args, struct aXInfo* xinfo) {
xinfo->cursor = None;
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
xinfo->cursor[scr] = None;
}
return 1; return 1;
} }

View file

@ -82,9 +82,9 @@ static struct ThemeCursor cursors[] = {
/*------------------------------------------------------------------*\ /*------------------------------------------------------------------*\
\*------------------------------------------------------------------*/ \*------------------------------------------------------------------*/
static Cursor cursor = 0; static Cursor* cursor = NULL;
static XColor color_fg; static XColor* color_fg = NULL;
static XColor color_bg; static XColor* color_bg = NULL;
static int alock_cursor_theme_init(const char* args, struct aXInfo* xinfo) { static int alock_cursor_theme_init(const char* args, struct aXInfo* xinfo) {
char* color_bg_name = strdup("steelblue3"); char* color_bg_name = strdup("steelblue3");
@ -139,34 +139,52 @@ static int alock_cursor_theme_init(const char* args, struct aXInfo* xinfo) {
free(arguments); free(arguments);
} }
alock_alloc_color(xinfo, color_fg_name, "white", &color_fg); {
alock_alloc_color(xinfo, color_bg_name, "blank", &color_bg); int scr;
for (scr = 0; xinfo->nr_screens; scr++) {
alock_alloc_color(xinfo, scr, color_fg_name, "white", &color_fg[scr]);
alock_alloc_color(xinfo, scr, color_bg_name, "blank", &color_bg[scr]);
}
cursor = (Cursor*)calloc(xinfo->nr_screens, sizeof(Cursor));
color_bg = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
color_fg = (XColor*)calloc(xinfo->nr_screens, sizeof(XColor));
free(color_fg_name); free(color_fg_name);
free(color_bg_name); free(color_bg_name);
pixmap_cursor = XCreateBitmapFromData(xinfo->display, xinfo->root, for (scr = 0; xinfo->nr_screens; scr++) {
pixmap_cursor = XCreateBitmapFromData(xinfo->display, xinfo->root[scr],
theme->bits, theme->width, theme->height); theme->bits, theme->width, theme->height);
pixmap_cursor_mask = XCreateBitmapFromData(xinfo->display, xinfo->root, pixmap_cursor_mask = XCreateBitmapFromData(xinfo->display, xinfo->root[scr],
theme->mask, theme->width, theme->height); theme->mask, theme->width, theme->height);
cursor = XCreatePixmapCursor(xinfo->display, cursor[scr] = XCreatePixmapCursor(xinfo->display,
pixmap_cursor, pixmap_cursor_mask, pixmap_cursor, pixmap_cursor_mask,
&color_fg, &color_bg, &color_fg[scr], &color_bg[scr],
theme->x_hot, theme->y_hot); theme->x_hot, theme->y_hot);
if (cursor) { if (cursor)
xinfo->cursor = cursor; xinfo->cursor = cursor;
}
}
return 1; return 1;
} else
return 0;
} }
static int alock_cursor_theme_deinit(struct aXInfo* xinfo) { static int alock_cursor_theme_deinit(struct aXInfo* xinfo) {
if (!xinfo || !cursor) if (!xinfo || !cursor)
return 0; return 0;
{
XFreeCursor(xinfo->display, cursor); int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
XFreeCursor(xinfo->display, cursor[scr]);
}
free(cursor);
free(color_bg);
free(color_fg);
}
return 1; return 1;
} }

View file

@ -52,7 +52,12 @@ static int alock_cursor_xcursor_init(const char* args, struct aXInfo* xinfo) {
return 0; return 0;
} }
xinfo->cursor = cursor; {
int scr;
for (scr = 0; scr < xinfo->nr_screens; scr++) {
xinfo->cursor[scr] = cursor;
}
}
return 1; return 1;
} }