Fixed a potential overwrite bug. Also works with more than one screen,
only fancy stuff on screen 0, though. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@410 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -40,11 +40,6 @@ char STRING[] = "****************";
|
|||||||
|
|
||||||
#define MAX_PASSWD_LENGTH (sizeof(STRING))
|
#define MAX_PASSWD_LENGTH (sizeof(STRING))
|
||||||
|
|
||||||
/* The program should be something that outputs a small amount of text */
|
|
||||||
#define DEFAULT_PROGRAM "fortune -s"
|
|
||||||
#define DEFAULT_TEXT "I'm out running around."
|
|
||||||
#define FONT_NAME "-*-new century schoolbook-*-*-*-18-*"
|
|
||||||
|
|
||||||
#ifndef MAXPATHLEN
|
#ifndef MAXPATHLEN
|
||||||
#define MAXPATHLEN BUFSIZ
|
#define MAXPATHLEN BUFSIZ
|
||||||
#endif /* MAXPATHLEN */
|
#endif /* MAXPATHLEN */
|
||||||
@@ -73,7 +68,6 @@ Pixel Black, White;
|
|||||||
XFontStruct *font;
|
XFontStruct *font;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
char root_pw[16];
|
char root_pw[16];
|
||||||
char *def_words = DEFAULT_TEXT;
|
|
||||||
int time_left, prompt_x, prompt_y, time_x, time_y;
|
int time_left, prompt_x, prompt_y, time_x, time_y;
|
||||||
unsigned long interval;
|
unsigned long interval;
|
||||||
Pixmap left0, left1, right0, right1, left_front,
|
Pixmap left0, left1, right0, right1, left_front,
|
||||||
@@ -82,12 +76,6 @@ int test;
|
|||||||
|
|
||||||
#define MAXLINES 40
|
#define MAXLINES 40
|
||||||
|
|
||||||
#define FROM_ARGV 1
|
|
||||||
#define FROM_PROGRAM 2
|
|
||||||
#define FROM_FILE 3
|
|
||||||
#define FROM_RESRC 4
|
|
||||||
int getwordsfrom = FROM_RESRC;
|
|
||||||
|
|
||||||
#define IS_MOVING 1
|
#define IS_MOVING 1
|
||||||
#define GET_PASSWD 2
|
#define GET_PASSWD 2
|
||||||
int state; /* indicates states: walking or getting passwd */
|
int state; /* indicates states: walking or getting passwd */
|
||||||
@@ -96,154 +84,154 @@ int ALLOW_LOGOUT = (60*10); /* Allow logout after nn seconds */
|
|||||||
char LOGOUT_PASSWD[] = "LOGOUT"; /* when given password "xx" */
|
char LOGOUT_PASSWD[] = "LOGOUT"; /* when given password "xx" */
|
||||||
time_t locked_at;
|
time_t locked_at;
|
||||||
|
|
||||||
struct _resrcs {
|
struct appres_t {
|
||||||
Pixel fg, bg;
|
|
||||||
XFontStruct *font;
|
XFontStruct *font;
|
||||||
Boolean ignore_passwd;
|
Boolean ignore_passwd;
|
||||||
Boolean do_reverse;
|
Boolean do_reverse;
|
||||||
Boolean accept_root;
|
Boolean accept_root;
|
||||||
char *text, *text_prog, *file;
|
char *text, *text_prog, *file;
|
||||||
} Resrcs;
|
Boolean no_screensaver;
|
||||||
|
} appres;
|
||||||
|
|
||||||
static XtResource resources[] = {
|
static XtResource resources[] = {
|
||||||
{ XtNfont, XtCFont, XtRFontStruct, sizeof (XFontStruct *),
|
{ XtNfont, XtCFont, XtRFontStruct, sizeof (XFontStruct *),
|
||||||
XtOffsetOf(struct _resrcs,font), XtRImmediate, NULL },
|
XtOffsetOf(struct appres_t, font), XtRImmediate, NULL },
|
||||||
{ XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
|
|
||||||
/* note: the background is really the foreground color */
|
|
||||||
XtOffsetOf(struct _resrcs,fg), XtRString, XtDefaultBackground },
|
|
||||||
{ XtNbackground, XtCBackground, XtRPixel, sizeof (Pixel),
|
|
||||||
/* note: the foreground is really the background color */
|
|
||||||
XtOffsetOf(struct _resrcs,bg), XtRString, XtDefaultForeground },
|
|
||||||
{ XtNreverseVideo, XtCReverseVideo, XtRBoolean, sizeof(Boolean),
|
|
||||||
XtOffsetOf(struct _resrcs,do_reverse), XtRImmediate, (char *)False },
|
|
||||||
{ "ignorePasswd", "IgnorePasswd", XtRBoolean, sizeof(Boolean),
|
{ "ignorePasswd", "IgnorePasswd", XtRBoolean, sizeof(Boolean),
|
||||||
XtOffsetOf(struct _resrcs,ignore_passwd), XtRImmediate, (char *)False },
|
XtOffsetOf(struct appres_t,ignore_passwd),XtRImmediate,(XtPointer)False },
|
||||||
|
|
||||||
{ "acceptRootPasswd", "AcceptRootPasswd", XtRBoolean, sizeof(Boolean),
|
{ "acceptRootPasswd", "AcceptRootPasswd", XtRBoolean, sizeof(Boolean),
|
||||||
XtOffsetOf(struct _resrcs,accept_root), XtRImmediate, (char *)True },
|
XtOffsetOf(struct appres_t, accept_root), XtRImmediate, (XtPointer)True },
|
||||||
{ "text", "Text", XtRString, sizeof(char *),
|
|
||||||
XtOffsetOf(struct _resrcs,text), XtRImmediate, DEFAULT_TEXT },
|
{ "text", "Text", XtRString, sizeof(String),
|
||||||
{ "program", "Program", XtRString, sizeof(char *),
|
XtOffsetOf(struct appres_t, text), XtRImmediate, NULL },
|
||||||
XtOffsetOf(struct _resrcs,text_prog), XtRImmediate, DEFAULT_PROGRAM },
|
|
||||||
{ "file", "File", XtRString, sizeof(char *),
|
{ "program", "Program", XtRString, sizeof(String),
|
||||||
XtOffsetOf(struct _resrcs,file), XtRImmediate, NULL },
|
XtOffsetOf(struct appres_t, text_prog), XtRImmediate, NULL },
|
||||||
|
|
||||||
|
{ "file", "File", XtRString, sizeof(String),
|
||||||
|
XtOffsetOf(struct appres_t,file), XtRImmediate, NULL },
|
||||||
|
|
||||||
|
{ "noScreenSaver", "NoScreenSaver", XtRBoolean, sizeof(Boolean),
|
||||||
|
XtOffsetOf(struct appres_t,no_screensaver), XtRImmediate, (XtPointer)False },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
String fallback[]={
|
||||||
|
"*font : -*-new century schoolbook-*-*-*-18-*",
|
||||||
|
"*background : black",
|
||||||
|
"*foreground : white",
|
||||||
|
"*text : I'm out running around.",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
Widget *xshell, *xcore;
|
||||||
|
|
||||||
static XrmOptionDescRec options[] = {
|
static XrmOptionDescRec options[] = {
|
||||||
{ "-fn", "font", XrmoptionSepArg, NULL },
|
{ "-ip", ".ignorePasswd", XrmoptionNoArg, "True" },
|
||||||
{ "-fg", "foreground", XrmoptionSepArg, NULL },
|
{ "-noip", ".ignorePasswd", XrmoptionNoArg, "False" },
|
||||||
{ "-bg", "background", XrmoptionSepArg, NULL },
|
{ "-ar", ".acceptRootPasswd", XrmoptionNoArg, "True" },
|
||||||
{ "-rv", "reverseVideo", XrmoptionNoArg, "True" },
|
{ "-noar", ".acceptRootPasswd", XrmoptionNoArg, "False" },
|
||||||
{ "-norv", "reverseVideo", XrmoptionNoArg, "False" },
|
{ "-noscreensaver", ".noScreenSaver", XrmoptionNoArg, "True" },
|
||||||
{ "-ip", "ignorePasswd", XrmoptionNoArg, "True" },
|
|
||||||
{ "-noip", "ignorePasswd", XrmoptionNoArg, "False" },
|
|
||||||
{ "-ar", "acceptRootPasswd", XrmoptionNoArg, "True" },
|
|
||||||
{ "-noar", "acceptRootPasswd", XrmoptionNoArg, "False" },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *
|
static char*
|
||||||
get_words(char **argv)
|
get_words(void)
|
||||||
{
|
{
|
||||||
FILE *pp = 0;
|
FILE *pp = NULL;
|
||||||
static char buf[BUFSIZ];
|
static char buf[BUFSIZ];
|
||||||
register char *p = buf;
|
register char *p = buf;
|
||||||
|
|
||||||
if (getwordsfrom == FROM_RESRC)
|
if(appres.text_prog){
|
||||||
return Resrcs.text;
|
pp = popen(appres.text_prog, "r");
|
||||||
if (getwordsfrom == FROM_PROGRAM) {
|
if(!pp){
|
||||||
if (!(pp = popen(Resrcs.text_prog, "r"))) {
|
perror(appres.text_prog);
|
||||||
perror(Resrcs.text_prog);
|
return appres.text;
|
||||||
return def_words;
|
|
||||||
}
|
}
|
||||||
} else if (getwordsfrom == FROM_FILE)
|
fread(buf, BUFSIZ, 1, pp);
|
||||||
if (!(pp = fopen(Resrcs.file, "r"))) {
|
pclose(pp);
|
||||||
perror(Resrcs.file);
|
return buf;
|
||||||
return def_words;
|
|
||||||
}
|
}
|
||||||
else if (getwordsfrom != FROM_PROGRAM && getwordsfrom != FROM_FILE)
|
if(appres.file){
|
||||||
return def_words;
|
pp = fopen(appres.file, "r");
|
||||||
|
if(!pp){
|
||||||
buf[0] = 0;
|
perror(appres.file);
|
||||||
if (getwordsfrom == FROM_ARGV) {
|
return appres.text;
|
||||||
while (*argv) {
|
|
||||||
p += strlen(strcpy(p, *argv));
|
|
||||||
if (*++argv)
|
|
||||||
strcpy(p++, " ");
|
|
||||||
}
|
}
|
||||||
|
fread(buf, BUFSIZ, 1, pp);
|
||||||
|
fclose(pp);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BUG Alert: does not check for overflow */
|
return appres.text;
|
||||||
while (fgets(p, sizeof buf, pp))
|
}
|
||||||
p += strlen(p);
|
|
||||||
if (getwordsfrom == FROM_PROGRAM)
|
void usage(void)
|
||||||
(void) pclose(pp);
|
{
|
||||||
else
|
fprintf(stderr, "usage: %s [options] [message]\n", ProgName);
|
||||||
(void) fclose (pp);
|
fprintf(stderr, "-fg color foreground color\n");
|
||||||
if (!buf[0])
|
fprintf(stderr, "-bg color background color\n");
|
||||||
return def_words;
|
fprintf(stderr, "-rv reverse foreground/background colors\n");
|
||||||
return buf;
|
fprintf(stderr, "-nrv no reverse video\n");
|
||||||
|
fprintf(stderr, "-ip ignore passwd\n");
|
||||||
|
fprintf(stderr, "-nip don't ignore passwd\n");
|
||||||
|
fprintf(stderr, "-ar accept root's passwd to unlock\n");
|
||||||
|
fprintf(stderr, "-nar don't accept root's passwd\n");
|
||||||
|
fprintf(stderr, "-f [file] message is read from file or ~/.msgfile\n");
|
||||||
|
fprintf(stderr, "-prog program text is gotten from executing `program'\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_words (int argc, char **argv)
|
init_words (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
int c;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
while (*argv && **argv == '-') {
|
while(argv[i]){
|
||||||
switch(argv[0][1]) {
|
if(strcmp(argv[i], "-p") == 0){
|
||||||
case 'p':
|
i++;
|
||||||
getwordsfrom = FROM_PROGRAM;
|
if(argv[i]){
|
||||||
if (!*++argv)
|
appres.text_prog = argv[i];
|
||||||
puts("specify a program name to get text from!"), exit(1);
|
i++;
|
||||||
Resrcs.text_prog = *argv;
|
}else{
|
||||||
case 'f':
|
fprintf(stderr, "-p requires an argument\n");
|
||||||
getwordsfrom = FROM_FILE;
|
usage();
|
||||||
if (argv[1])
|
|
||||||
Resrcs.file = *++argv;
|
|
||||||
else {
|
|
||||||
sprintf(buf, "%s/.msgfile", pw->pw_dir);
|
|
||||||
Resrcs.file = strcpy(XtMalloc(strlen(buf)+1), buf);
|
|
||||||
}
|
}
|
||||||
default :
|
}else if(strcmp(argv[i], "-f") == 0){
|
||||||
printf("usage: %s [options] [message]\n", ProgName);
|
i++;
|
||||||
puts("-fg color foreground color");
|
if(argv[i]){
|
||||||
puts("-bg color background color");
|
appres.file = argv[i];
|
||||||
puts("-rv reverse foreground/background colors");
|
i++;
|
||||||
puts("-nrv no reverse video");
|
}else{
|
||||||
puts("-ip ignore passwd");
|
sprintf(buf, "%s/.msgfile", getenv("HOME"));
|
||||||
puts("-nip don't ignore passwd");
|
appres.file = strdup(buf);
|
||||||
puts("-ar accept root's passwd to unlock");
|
}
|
||||||
puts("-nar don't accept root's passwd");
|
}else{
|
||||||
puts("-f [file] message is read from file or ~/.msgfile");
|
strcpy(buf, "");
|
||||||
puts("-prog program text is gotten from executing `program'");
|
while(argv[i]){
|
||||||
exit(1);
|
strcat(buf, argv[i]);
|
||||||
|
strcat(buf, " ");
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
appres.text = strdup(buf);
|
||||||
}
|
}
|
||||||
argv++;
|
|
||||||
}
|
}
|
||||||
if (*argv) {
|
|
||||||
if (getwordsfrom != FROM_RESRC)
|
|
||||||
puts("I don't know what text you want displayed.");
|
|
||||||
getwordsfrom = FROM_ARGV;
|
|
||||||
} else if (!getwordsfrom)
|
|
||||||
if (Resrcs.text)
|
|
||||||
getwordsfrom = FROM_RESRC;
|
|
||||||
else if (Resrcs.file)
|
|
||||||
getwordsfrom = FROM_FILE;
|
|
||||||
else
|
|
||||||
getwordsfrom = FROM_PROGRAM;
|
|
||||||
words = get_words(argv); /* if getwordsfrom != FROM_ARGV, argv is a nop */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ScreenSaver(int save)
|
ScreenSaver(int save)
|
||||||
{
|
{
|
||||||
static int timeout, interval, prefer_blank, allow_exp;
|
static int timeout, interval, prefer_blank, allow_exp;
|
||||||
|
if(!appres.no_screensaver){
|
||||||
if (save) {
|
if (save) {
|
||||||
XGetScreenSaver(dpy, &timeout, &interval, &prefer_blank, &allow_exp);
|
XGetScreenSaver(dpy, &timeout, &interval,
|
||||||
|
&prefer_blank, &allow_exp);
|
||||||
XSetScreenSaver(dpy, 0, interval, prefer_blank, allow_exp);
|
XSetScreenSaver(dpy, 0, interval, prefer_blank, allow_exp);
|
||||||
} else
|
} else
|
||||||
/* restore state */
|
/* restore state */
|
||||||
XSetScreenSaver(dpy, timeout, interval, prefer_blank, allow_exp);
|
XSetScreenSaver(dpy, timeout, interval, prefer_blank, allow_exp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Forward decls necessary */
|
/* Forward decls necessary */
|
||||||
@@ -275,12 +263,8 @@ zrefresh()
|
|||||||
static void
|
static void
|
||||||
leave(void)
|
leave(void)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
XUngrabServer(dpy);
|
|
||||||
#else
|
|
||||||
XUngrabPointer(dpy, CurrentTime);
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
XUngrabKeyboard(dpy, CurrentTime);
|
XUngrabKeyboard(dpy, CurrentTime);
|
||||||
#endif
|
|
||||||
ScreenSaver(0);
|
ScreenSaver(0);
|
||||||
zrefresh();
|
zrefresh();
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -355,8 +339,7 @@ think(void)
|
|||||||
if (rand() & 1)
|
if (rand() & 1)
|
||||||
walk(FRONT);
|
walk(FRONT);
|
||||||
if (rand() & 1) {
|
if (rand() & 1) {
|
||||||
if (getwordsfrom > 1)
|
words = get_words();
|
||||||
words = get_words((char **)NULL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -484,11 +467,6 @@ ClearWindow(Widget w, XEvent *_event, String *_s, Cardinal *_n)
|
|||||||
XExposeEvent *event = (XExposeEvent *)_event;
|
XExposeEvent *event = (XExposeEvent *)_event;
|
||||||
if (!XtIsRealized(w))
|
if (!XtIsRealized(w))
|
||||||
return;
|
return;
|
||||||
XSetForeground(dpy, gc, Black);
|
|
||||||
XFillRectangle(dpy, XtWindow(w), gc,
|
|
||||||
event->x, event->y, event->width, event->height);
|
|
||||||
XSetForeground(dpy, gc, White);
|
|
||||||
XSetBackground(dpy, gc, Black);
|
|
||||||
if (state == GET_PASSWD)
|
if (state == GET_PASSWD)
|
||||||
post_prompt_box(XtWindow(w));
|
post_prompt_box(XtWindow(w));
|
||||||
if (timeout_id == 0 && event->count == 0) {
|
if (timeout_id == 0 && event->count == 0) {
|
||||||
@@ -505,7 +483,7 @@ static void
|
|||||||
countdown(XtPointer _t, XtIntervalId *_d)
|
countdown(XtPointer _t, XtIntervalId *_d)
|
||||||
{
|
{
|
||||||
int *timeout = (int *)_t;
|
int *timeout = (int *)_t;
|
||||||
char buf[16];
|
char buf[128];
|
||||||
time_t seconds;
|
time_t seconds;
|
||||||
|
|
||||||
if (--(*timeout) < 0) {
|
if (--(*timeout) < 0) {
|
||||||
@@ -550,7 +528,7 @@ GetPasswd(Widget w, XEvent *_event, String *_s, Cardinal *_n)
|
|||||||
/* guy is running around--change to post prompt box. */
|
/* guy is running around--change to post prompt box. */
|
||||||
XtRemoveTimeOut(timeout_id);
|
XtRemoveTimeOut(timeout_id);
|
||||||
state = GET_PASSWD;
|
state = GET_PASSWD;
|
||||||
if (Resrcs.ignore_passwd || !strlen(pw->pw_passwd))
|
if (appres.ignore_passwd || !strlen(pw->pw_passwd))
|
||||||
leave();
|
leave();
|
||||||
post_prompt_box(XtWindow(w));
|
post_prompt_box(XtWindow(w));
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
@@ -579,7 +557,7 @@ GetPasswd(Widget w, XEvent *_event, String *_s, Cardinal *_n)
|
|||||||
/*
|
/*
|
||||||
* First try with root password, if allowed.
|
* First try with root password, if allowed.
|
||||||
*/
|
*/
|
||||||
if (Resrcs.accept_root &&
|
if (appres.accept_root &&
|
||||||
(root_pw[0] == 0 && cnt == 0 ||
|
(root_pw[0] == 0 && cnt == 0 ||
|
||||||
cnt && root_pw[0] && !strcmp(crypt(passwd, root_pw), root_pw)))
|
cnt && root_pw[0] && !strcmp(crypt(passwd, root_pw), root_pw)))
|
||||||
leave();
|
leave();
|
||||||
@@ -689,7 +667,7 @@ init_images(void)
|
|||||||
for (i = 0; i < XtNumber(images); i++)
|
for (i = 0; i < XtNumber(images); i++)
|
||||||
if (!(*images[i] =
|
if (!(*images[i] =
|
||||||
XCreatePixmapFromBitmapData(dpy, DefaultRootWindow(dpy),
|
XCreatePixmapFromBitmapData(dpy, DefaultRootWindow(dpy),
|
||||||
bits[i], 64, 64, 1, 0, 1)))
|
(char*)(bits[i]), 64, 64, 1, 0, 1)))
|
||||||
XtError("Can't load nose images");
|
XtError("Can't load nose images");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,7 +708,7 @@ talk(int force_erase)
|
|||||||
/* possibly avoid a lot of work here
|
/* possibly avoid a lot of work here
|
||||||
* if no CR or only one, then just print the line
|
* if no CR or only one, then just print the line
|
||||||
*/
|
*/
|
||||||
if (!(p2 = index(p, '\n')) || !p2[1]) {
|
if (!(p2 = strchr(p, '\n')) || !p2[1]) {
|
||||||
register int w;
|
register int w;
|
||||||
|
|
||||||
if (p2)
|
if (p2)
|
||||||
@@ -765,7 +743,7 @@ talk(int force_erase)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p = p2+1;
|
p = p2+1;
|
||||||
if (!(p2 = index(p, '\n')))
|
if (!(p2 = strchr(p, '\n')))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
height++;
|
height++;
|
||||||
@@ -843,13 +821,15 @@ main (int argc, char **argv)
|
|||||||
XGCValues gcvalues;
|
XGCValues gcvalues;
|
||||||
char **list;
|
char **list;
|
||||||
|
|
||||||
|
int nscr;
|
||||||
|
|
||||||
srand(getpid());
|
srand(getpid());
|
||||||
for (i = 0; i < (sizeof(STRING)-2); i++)
|
for (i = 0; i < (sizeof(STRING)-2); i++)
|
||||||
STRING[i] = ((unsigned long)rand() % ('~' - ' ')) + ' ';
|
STRING[i] = ((unsigned long)rand() % ('~' - ' ')) + ' ';
|
||||||
|
|
||||||
locked_at = time(0);
|
locked_at = time(0);
|
||||||
|
|
||||||
if ((ProgName = rindex(*argv, '/')) != 0)
|
if ((ProgName = strrchr(*argv, '/')) != 0)
|
||||||
ProgName++;
|
ProgName++;
|
||||||
else
|
else
|
||||||
ProgName = *argv;
|
ProgName = *argv;
|
||||||
@@ -891,10 +871,16 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XtToolkitInitialize();
|
|
||||||
app = XtCreateApplicationContext();
|
override = XtVaAppInitialize(&app, "XNlock", options, XtNumber(options),
|
||||||
dpy = XtOpenDisplay(app, NULL,
|
&argc, argv, fallback,
|
||||||
"xnlock", "XNlock", options, XtNumber(options), &argc, argv);
|
XtNoverrideRedirect, True,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
XtVaGetApplicationResources(override,(XtPointer)&appres,
|
||||||
|
resources,XtNumber(resources),
|
||||||
|
NULL);
|
||||||
|
dpy = XtDisplay(override);
|
||||||
|
|
||||||
if (dpy == 0)
|
if (dpy == 0)
|
||||||
{
|
{
|
||||||
@@ -904,14 +890,31 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
Width = DisplayWidth(dpy, DefaultScreen(dpy)) + 2;
|
Width = DisplayWidth(dpy, DefaultScreen(dpy)) + 2;
|
||||||
Height = DisplayHeight(dpy, DefaultScreen(dpy)) + 2;
|
Height = DisplayHeight(dpy, DefaultScreen(dpy)) + 2;
|
||||||
override = XtVaAppCreateShell("xnlock", "XNlock",
|
|
||||||
overrideShellWidgetClass, dpy,
|
nscr = ScreenCount(dpy) - 1;
|
||||||
|
|
||||||
|
if(nscr > 0){
|
||||||
|
xshell = (Widget*)malloc(nscr*sizeof(Widget));
|
||||||
|
xcore = (Widget*)malloc(nscr*sizeof(Widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < nscr; i++){
|
||||||
|
char name[32];
|
||||||
|
sprintf(name, "xnlock%d", i+1);
|
||||||
|
xshell[i] = XtVaAppCreateShell(NULL, NULL, /*name, "XNlock", */
|
||||||
|
applicationShellWidgetClass, dpy,
|
||||||
|
XtNscreen, ScreenOfDisplay(dpy, i+1),
|
||||||
|
XtNoverrideRedirect, True,
|
||||||
XtNx, -1,
|
XtNx, -1,
|
||||||
XtNy, -1,
|
XtNy, -1,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
XtGetApplicationResources(override, &Resrcs,
|
xcore[i] = XtVaCreateManagedWidget("_foo", widgetClass, xshell[i],
|
||||||
resources, XtNumber(resources), NULL, 0);
|
XtNwidth, Width,
|
||||||
|
XtNheight, Height,
|
||||||
|
NULL);
|
||||||
|
XtRealizeWidget(xshell[i]);
|
||||||
|
}
|
||||||
|
|
||||||
widget = XtVaCreateManagedWidget("_foo", widgetClass, override,
|
widget = XtVaCreateManagedWidget("_foo", widgetClass, override,
|
||||||
XtNwidth, Width,
|
XtNwidth, Width,
|
||||||
@@ -922,25 +925,15 @@ main (int argc, char **argv)
|
|||||||
init_images();
|
init_images();
|
||||||
|
|
||||||
/* the background is black and the little guy is white */
|
/* the background is black and the little guy is white */
|
||||||
Black = Resrcs.do_reverse? Resrcs.fg : Resrcs.bg;
|
XtVaGetValues(override,
|
||||||
White = Resrcs.do_reverse? Resrcs.bg : Resrcs.fg;
|
XtNbackground, &Black,
|
||||||
|
XtNforeground, &White,
|
||||||
|
NULL);
|
||||||
gcvalues.foreground = Black;
|
gcvalues.foreground = Black;
|
||||||
gcvalues.background = White;
|
gcvalues.background = White;
|
||||||
|
|
||||||
if (!(font = Resrcs.font)) {
|
|
||||||
list = XListFonts(dpy, FONT_NAME, 32767, &foo);
|
font = appres.font;
|
||||||
for (i = 0; i < foo; i++)
|
|
||||||
if ((font = XLoadQueryFont(dpy, list[i])) != 0)
|
|
||||||
break;
|
|
||||||
if (!font)
|
|
||||||
{
|
|
||||||
list = XListFonts(dpy, "fixed", 1, &foo);
|
|
||||||
font = XLoadQueryFont(dpy, list[0]);
|
|
||||||
}
|
|
||||||
if (!font)
|
|
||||||
XtError("Can't find a font (so call me stupid).");
|
|
||||||
XFreeFontNames(list);
|
|
||||||
}
|
|
||||||
gcvalues.font = font->fid;
|
gcvalues.font = font->fid;
|
||||||
gcvalues.graphics_exposures = False;
|
gcvalues.graphics_exposures = False;
|
||||||
gc = XCreateGC(dpy, DefaultRootWindow(dpy),
|
gc = XCreateGC(dpy, DefaultRootWindow(dpy),
|
||||||
@@ -969,14 +962,10 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
XtRealizeWidget(override);
|
XtRealizeWidget(override);
|
||||||
#if 0
|
|
||||||
XGrabServer(dpy);
|
|
||||||
#else
|
|
||||||
XGrabPointer(dpy, XtWindow(widget), TRUE, 0, GrabModeAsync,
|
XGrabPointer(dpy, XtWindow(widget), TRUE, 0, GrabModeAsync,
|
||||||
GrabModeAsync, XtWindow(widget), None, CurrentTime);
|
GrabModeAsync, XtWindow(widget), None, CurrentTime);
|
||||||
XGrabKeyboard(dpy, XtWindow(widget), TRUE, GrabModeAsync,
|
XGrabKeyboard(dpy, XtWindow(widget), TRUE, GrabModeAsync,
|
||||||
GrabModeAsync, CurrentTime);
|
GrabModeAsync, CurrentTime);
|
||||||
#endif
|
|
||||||
ScreenSaver(1);
|
ScreenSaver(1);
|
||||||
XtAppMainLoop(app);
|
XtAppMainLoop(app);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
Reference in New Issue
Block a user