]> git.sur5r.net Git - i3/i3lock/commitdiff
Handle error codes when loading the pixmap
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 27 Jun 2009 20:35:59 +0000 (22:35 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 27 Jun 2009 20:35:59 +0000 (22:35 +0200)
i3lock.c

index 5b495b554e471c65996d8cb6b22b15cca59bf908..a824c6ab4f943e7e0950b3132a657aeef57b0199 100644 (file)
--- a/i3lock.c
+++ b/i3lock.c
@@ -48,7 +48,7 @@ static void die(const char *errstr, ...) {
  * 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");
         if(file)
@@ -59,6 +59,31 @@ bool file_exists(const char * filename)
         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.
@@ -188,12 +213,16 @@ int main(int argc, char *argv[]) {
                 int disp_width = DisplayWidth(dpy, screen);
                 int disp_height = DisplayHeight(dpy, screen);
                 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);
         }
 
         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)
                         break;
                 usleep(1000);