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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
#include "plcm.h"
static void handle_message(const XClientMessageEvent *ev);
static void handle_expose(const XExposeEvent *ev);
static void handle_configure(const XConfigureEvent *ev);
static void handle_destroy(const XDestroyWindowEvent *ev);
static void handle_map(const XMapEvent *ev);
static void handle_unmap(const XUnmapEvent *ev);
static void handle_property(const XPropertyEvent *ev);
static void handle_visibility(const XVisibilityEvent *ev);
static void handle_damage(const XDamageNotifyEvent *ev);
void event_loop(void)
{
while (1)
{
XEvent ev;
XNextEvent(disp, &ev);
switch (ev.type)
{
case ClientMessage:
handle_message(&ev.xclient);
break;
case Expose:
handle_expose(&ev.xexpose);
break;
case ConfigureNotify:
handle_configure(&ev.xconfigure);
break;
case DestroyNotify:
handle_destroy(&ev.xdestroywindow);
break;
case MapNotify:
handle_map(&ev.xmap);
break;
case UnmapNotify:
handle_unmap(&ev.xunmap);
break;
case PropertyNotify:
handle_property(&ev.xproperty);
break;
case VisibilityNotify:
handle_visibility(&ev.xvisibility);
break;
default:
if (ev.type == damage_event_base + XDamageNotify)
handle_damage((XDamageNotifyEvent*) &ev.xany);
}
}
}
static void handle_message(const XClientMessageEvent *ev)
{
if (ev->window != ctrl_win)
{
info("received message for unexpected window 0x%08lx",
(unsigned long) ev->window);
return;
}
if (ev->message_type == _PLCM_ENABLE && ev->format == 32)
{
Window source, target;
projection_t* proj;
source = ev->data.l[0];
target = ev->data.l[1];
info("recieved ENABLE message for 0x%08x -> 0x%08x",
(int) source, (int) target);
proj = add_projection(source, target);
if (proj != NULL)
{
info("projection enabled");
}
else
{
info("projection NOT enabled");
}
}
else if (ev->message_type == _PLCM_DISABLE && ev->format == 32)
{
Window source, target;
projection_t* proj;
source = ev->data.l[0];
target = ev->data.l[1];
info("recieved DISABLE message for 0x%08x -> 0x%08x",
(int) source, (int) target);
proj = find_source_window(source);
if (proj == NULL || proj->target_window != target)
{
info("DISABLE for unknown projection, ignoring");
}
else
{
free_projection(proj);
}
}
else
{
info("unknown message: %d (format %d)",
(int) ev->message_type, ev->format);
return;
}
}
static void handle_expose(const XExposeEvent *ev)
{
projection_t *proj = find_target_window(ev->window);
if (proj)
{
XRectangle rect;
/* Translate from target to source coordinated */
rect.x = ev->x + proj->source_geometry.x;
rect.y = ev->y + proj->source_geometry.y;
rect.width = ev->width;
rect.height = ev->height;
project_rectangle(proj, &rect);
}
}
static void handle_configure(const XConfigureEvent *ev)
{
projection_t *proj = find_any_window(ev->window);
if (proj)
{
/* Update the geometry info for the windows. But don't trigger
a redraw, wait for Expose or Damage events for that.
*/
if (proj->target_window == ev->window)
{
project_target_resized(proj, ev->width, ev->height);
}
else
{
/* Ignore the border when it comes to projection */
proj->source_geometry.x = ev->x + ev->border_width;
proj->source_geometry.y = ev->y + ev->border_width;
proj->source_geometry.width = ev->width;
proj->source_geometry.height = ev->height;
}
}
}
static void handle_destroy(const XDestroyWindowEvent *ev)
{
projection_t *proj = find_any_window(ev->window);
if (proj)
{
info("0x%08x: destroyed, taking down projection",
(int) ev->window);
/* Reset either window parameter in proj to avoid getting
XBadWindow errors during shutdown.
*/
if (proj->target_window == ev->window)
proj->target_window = None;
else
proj->source_window = None;
free_projection(proj);
}
}
static void handle_map(const XMapEvent *ev)
{
projection_t *proj = find_any_window(ev->window);
if (proj)
{
info("0x%08x: mapped", (int) ev->window);
if (proj->target_window == ev->window)
proj->target_is_visible = 1;
else
proj->source_is_mapped = 1;
}
}
static void handle_unmap(const XUnmapEvent *ev)
{
projection_t *proj = find_any_window(ev->window);
if (proj)
{
info("0x%08x: unmapped", (int) ev->window);
if (proj->target_window == ev->window)
proj->target_is_visible = 0;
else
proj->source_is_mapped = 0;
}
}
static void handle_property(const XPropertyEvent *ev)
{
projection_t *proj = find_target_window(ev->window);
if (!proj)
return;
if (ev->atom == _PLCM_BRIGHTNESS)
{
if (update_brightness(proj))
{
/* Need redraw */
project_all(proj);
}
}
}
static void handle_visibility(const XVisibilityEvent *ev)
{
projection_t *proj = find_target_window(ev->window);
if (proj)
{
proj->target_is_visible = (ev->state != VisibilityFullyObscured);
info("0x%08x: is visible: %d",
(int) proj->target_window,
proj->target_is_visible);
}
}
static void handle_damage(const XDamageNotifyEvent *ev)
{
projection_t *proj = find_source_window(ev->drawable);
if (proj)
{
/* Get the accumulated damage */
XDamageSubtract(disp, proj->damage, None, proj->damage_region);
project_region(proj);
}
}
|