Browse Source

Handle error codes when loading the pixmap

master
Michael Stapelberg 16 years ago
parent
commit
69a987db55
  1. 35
      i3lock.c

35
i3lock.c

@ -48,7 +48,7 @@ static void die(const char *errstr, ...) {
* Check if given file can be opened => exists * Check if given file can be opened => exists
* *
*/ */
bool file_exists(const char * filename) bool file_exists(const char *filename)
{ {
FILE * file = fopen(filename, "r"); FILE * file = fopen(filename, "r");
if(file) if(file)
@ -59,6 +59,31 @@ bool file_exists(const char * filename)
return false; return false;
} }
/*
* Puts the given XPM error code to stderr
*
*/
void print_xpm_error(int err)
{
switch (err) {
case XpmColorError:
fprintf(stderr, "XPM: Could not parse or alloc requested color\n");
break;
case XpmOpenFailed:
fprintf(stderr, "XPM: Cannot open file\n");
break;
case XpmFileInvalid:
fprintf(stderr, "XPM: invalid XPM file\n");
break;
case XpmNoMemory:
fprintf(stderr, "XPM: Not enough memory\n");
break;
case XpmColorFailed:
fprintf(stderr, "XPM: Color not found\n");
break;
}
}
/* /*
* Callback function for PAM. We only react on password request callbacks. * Callback function for PAM. We only react on password request callbacks.
@ -188,12 +213,16 @@ int main(int argc, char *argv[]) {
int disp_width = DisplayWidth(dpy, screen); int disp_width = DisplayWidth(dpy, screen);
int disp_height = DisplayHeight(dpy, screen); int disp_height = DisplayHeight(dpy, screen);
Pixmap pix = XCreatePixmap(dpy, w, disp_width, disp_height, depth); Pixmap pix = XCreatePixmap(dpy, w, disp_width, disp_height, depth);
XpmReadFileToPixmap(dpy, w, xpm_image_path, &pix, 0, 0); int err = XpmReadFileToPixmap(dpy, w, xpm_image_path, &pix, 0, 0);
if (err != 0) {
print_xpm_error(err);
return 1;
}
XCopyArea(dpy, pix, w, gc, 0, 0, disp_width, disp_height, 0, 0); XCopyArea(dpy, pix, w, gc, 0, 0, disp_width, disp_height, 0, 0);
} }
for(len = 1000; len; len--) { for(len = 1000; len; len--) {
if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess) GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
break; break;
usleep(1000); usleep(1000);

Loading…
Cancel
Save