#include "mb-wm-config.h" #include "mb-wm-util.h" #include #include #include #include #include static int TrappedErrorCode = 0; static int (*old_error_handler) (Display *, XErrorEvent *); static int error_handler(Display *xdpy, XErrorEvent *error) { TrappedErrorCode = error->error_code; return 0; } void mb_wm_util_trap_x_errors(void) { /* MBWM_DBG("### X Errors Trapped ###"); */ TrappedErrorCode = 0; old_error_handler = XSetErrorHandler(error_handler); } int mb_wm_util_untrap_x_errors(void) { /* MBWM_DBG("### X Errors Untrapped (%i) ###", TrappedErrorCode); */ XSetErrorHandler(old_error_handler); return TrappedErrorCode; } void* mb_wm_util_malloc0(int size) { return g_malloc0 (size); } Bool /* FIXME: define, inline ? */ mb_geometry_compare (MBGeometry *g1, MBGeometry *g2) { return (g1->x == g2->x && g1->y == g2->y && g1->width == g2->width && g1->height == g2->height); } Bool /* True if overlaps */ mb_geometry_intersects (MBGeometry *g1, MBGeometry *g2) { if ((g1->x > g2->x + g2->width) || (g1->y > g2->y + g2->height) || (g2->x > g1->x + g1->width) || (g2->y > g1->y + g1->height)) return False; return True; } void mb_wm_util_fatal_error (char *msg) { fprintf(stderr, "matchbox-window-manager: *Error* %s\n", msg); exit(1); } void mb_wm_util_warn (const char *format, ...) { va_list ap; char *msg = NULL; va_start(ap, format); vasprintf(&msg, format, ap); va_end(ap); fprintf(stderr, "*MBWM Warning* %s\n", msg); if (msg) free(msg); } int mb_wm_util_list_length(MBWMList *list) { return g_list_length ((GList *)list); } MBWMList* mb_wm_util_list_get_last(MBWMList *list) { return (MBWMList *)g_list_last ((GList *)list); } MBWMList* mb_wm_util_list_get_first(MBWMList *list) { return (MBWMList *)g_list_first ((GList *)list); } void* mb_wm_util_list_get_nth_data(MBWMList *list, int n) { return g_list_nth_data ((GList *)list, n); } MBWMList* mb_wm_util_list_prepend(MBWMList *list, void *data) { return (MBWMList *)g_list_prepend ((GList *)list, data); } MBWMList* mb_wm_util_list_append(MBWMList *list, void *data) { return (MBWMList *)g_list_append ((GList *)list, data); } MBWMList* mb_wm_util_list_remove(MBWMList *list, void *data) { return (MBWMList *)g_list_remove ((GList *)list, data); } void mb_wm_util_list_foreach (const MBWMList *list, MBWMListForEachCB func, void *userdata) { g_list_foreach ((GList *)list, (GFunc)func, userdata); } void mb_wm_util_list_free (MBWMList * list) { g_list_free ((GList *)list); } MBWMRgbaIcon * mb_wm_rgba_icon_new () { return mb_wm_util_malloc0 (sizeof (MBWMRgbaIcon)); } void mb_wm_rgba_icon_free (MBWMRgbaIcon *icon) { if (icon->pixels) free (icon->pixels); free (icon); }