aboutsummaryrefslogtreecommitdiffstats
path: root/matchbox/core/mb-wm-props.c
blob: 01a74bb56d3413f0fa9c6ac9e85fec6e65ec7e7e (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "mb-wm.h"
#include "xas.h"

MBWMCookie
mb_wm_property_req (MBWindowManager *wm,
		    Window           win,
		    Atom             property,
		    long             offset,
		    long             length,
		    Bool             delete,
		    Atom             req_type)
{
  XasCookie cookie;

  cookie = xas_get_property(wm->xas_context,
			    win,
			    property,
			    offset,
			    length,
			    delete,
			    req_type);

  return (MBWMCookie)cookie;
}


Status
mb_wm_property_reply (MBWindowManager  *wm,
		      MBWMCookie        cookie,
		      Atom             *actual_type_return,
		      int              *actual_format_return,
		      unsigned long    *nitems_return,
		      unsigned long    *bytes_after_return,
		      unsigned char   **prop_return,
		      int              *x_error_code)
{
  return  xas_get_property_reply(wm->xas_context,
			         (XasCookie)cookie,
				 actual_type_return,
				 actual_format_return,
				 nitems_return,
				 bytes_after_return,
				 prop_return,
				 x_error_code);
}

void*
mb_wm_property_get_reply_and_validate (MBWindowManager  *wm,
				       MBWMCookie        cookie,
				       Atom              expected_type,
				       int               expected_format,
				       int               expected_n_items,
				       int              *n_items_ret,
				       int              *x_error_code)
{
  Atom             actual_type_return;
  int              actual_format_return;
  unsigned long    nitems_return;
  unsigned long    bytes_after_return;
  unsigned char   *prop_data = NULL;

  *x_error_code = 0;

  xas_get_property_reply(wm->xas_context,
			 (XasCookie)cookie,
			 &actual_type_return,
			 &actual_format_return,
			 &nitems_return,
			 &bytes_after_return,
			 &prop_data,
			 x_error_code);

  if (*x_error_code || prop_data == NULL)
    goto fail;

  if (expected_format && actual_format_return != expected_format)
    goto fail;

  if (expected_n_items && nitems_return != expected_n_items)
    goto fail;

  if (n_items_ret)
    *n_items_ret = nitems_return;

  return prop_data;

 fail:

  if (prop_data)
    XFree(prop_data);

  return NULL;
}



Bool
mb_wm_property_have_reply (MBWindowManager     *wm,
			   MBWMCookie           cookie)
{
  return xas_have_reply(wm->xas_context, (XasCookie)cookie);
}


MBWMCookie
mb_wm_xwin_get_attributes (MBWindowManager   *wm,
			   Window             win)
{
  return xas_get_window_attributes(wm->xas_context, win);
}

MBWMCookie
mb_wm_xwin_get_geometry (MBWindowManager   *wm,
			 Drawable            d)
{
  return xas_get_geometry(wm->xas_context, d);
}

MBWMClientWindowAttributes*
mb_wm_xwin_get_attributes_reply (MBWindowManager   *wm,
				 MBWMCookie         cookie,
				 int               *x_error_code)
{
  return (MBWMClientWindowAttributes*)
    xas_get_window_attributes_reply(wm->xas_context,
				    cookie,
				    x_error_code);
}

Status
mb_wm_xwin_get_geometry_reply (MBWindowManager   *wm,
			       XasCookie          cookie,
			       MBGeometry        *geom_return,
			       unsigned int      *border_width_return,
			       unsigned int      *depth_return,
			       int               *x_error_code)
{
  return xas_get_geometry_reply (wm->xas_context,
				 cookie,
				 &geom_return->x,
				 &geom_return->y,
				 &geom_return->width,
				 &geom_return->height,
				 border_width_return,
				 depth_return,
				 x_error_code);
}


void
mb_wm_props_send_x_message (MBWindowManager *wm,
			    Window           xwin_src,
			    Window           xwin_dest,
			    Atom             delivery_atom,
			    unsigned long    data0,
			    unsigned long    data1,
			    unsigned long    data2,
			    unsigned long    data3,
			    unsigned long    data4,
			    unsigned long    mask)
{
  XEvent ev;

  memset(&ev, 0, sizeof(ev));

  ev.xclient.type = ClientMessage;
  ev.xclient.window = xwin_src;
  ev.xclient.message_type = delivery_atom;
  ev.xclient.format = 32;
  ev.xclient.data.l[0] = data0;
  ev.xclient.data.l[1] = data1;
  ev.xclient.data.l[2] = data2;
  ev.xclient.data.l[3] = data3;
  ev.xclient.data.l[4] = data4;

  if (!mask)
    mask = NoEventMask;

  /* FIXME: traps */

  XSendEvent(wm->xdpy, xwin_dest, False, mask, &ev);
  XSync(wm->xdpy, False);

}

void
mb_wm_props_sync_root_props (MBWindowManager *wm)
{




}

void
mb_wm_props_root_message (MBWindowManager *wm)
{




}