1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include "mb-wm-config.h"
#include "mb-wm-util.h"
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
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);
}
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);
}
|