X-Git-Url: https://git.subgeniuskitty.com/xmenu/.git/blobdiff_plain/70f5db0f88fcc7525dd3b71fc1408cb6e9cb36f5..d3c213125090d49408c78d2c4a9200ec1575c187:/xmenu.c diff --git a/xmenu.c b/xmenu.c index 4407229..d557f6d 100644 --- a/xmenu.c +++ b/xmenu.c @@ -316,6 +316,8 @@ initmonitor(void) mon.y = info[selmon].y_org; mon.w = info[selmon].width; mon.h = info[selmon].height; + + XFree(info); } if (!pflag) { @@ -331,9 +333,9 @@ initmonitor(void) static void initresources(void) { - char *xrm; long n; char *type; + char *xrm; XrmDatabase xdb; XrmValue xval; @@ -888,13 +890,55 @@ static Imlib_Image loadicon(const char *file) { Imlib_Image icon; + Imlib_Load_Error errcode; + const char *errstr; int width; int height; int imgsize; - icon = imlib_load_image(file); - if (icon == NULL) - errx(1, "could not load icon %s", file); + icon = imlib_load_image_with_error_return(file, &errcode); + if (*file == '\0') { + warnx("could not load icon (file name is blank)"); + return NULL; + } else if (icon == NULL) { + switch (errcode) { + case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: + errstr = "file does not exist"; + break; + case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: + errstr = "file is directory"; + break; + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: + errstr = "permission denied"; + break; + case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: + errstr = "unknown file format"; + break; + case IMLIB_LOAD_ERROR_PATH_TOO_LONG: + errstr = "path too long"; + break; + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: + case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: + errstr = "improper path"; + break; + case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: + errstr = "too many symbolic links"; + break; + case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: + errstr = "out of memory"; + break; + case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS: + errstr = "out of file descriptors"; + break; + default: + errstr = "unknown error"; + break; + } + warnx("could not load icon (%s): %s", errstr, file); + return NULL; + } imlib_context_set_image(icon); @@ -971,15 +1015,21 @@ drawitems(struct Menu *menu) Convex, CoordModeOrigin); } - /* draw icon */ - if (item->file != NULL && !iflag) { + /* try to load icon */ + if (item->file && !iflag) { item->icon = loadicon(item->file); + free(item->file); + } + /* draw icon if properly loaded */ + if (item->icon) { imlib_context_set_image(item->icon); imlib_context_set_drawable(item->sel); imlib_render_image_on_drawable(config.horzpadding, config.iconpadding); imlib_context_set_drawable(item->unsel); imlib_render_image_on_drawable(config.horzpadding, config.iconpadding); + imlib_context_set_image(item->icon); + imlib_free_image(); } } } @@ -1271,13 +1321,6 @@ cleanmenu(struct Menu *menu) if (tmp->label != tmp->output) free(tmp->label); free(tmp->output); - if (tmp->file != NULL) { - free(tmp->file); - if (tmp->icon != NULL) { - imlib_context_set_image(tmp->icon); - imlib_free_image(); - } - } item = item->next; free(tmp); }