2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2008 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 static Window root_win;
34 str = getenv("ENL_WM_ROOT");
35 root_win = (str) ? strtoul(str, NULL, 0) : DefaultRootWindow(disp);
39 CommsSetup(Window win __UNUSED__)
41 XSetWindowAttributes attr;
43 attr.override_redirect = False;
44 my_win = XCreateWindow(disp, root_win, -100, -100, 5, 5, 0, 0, InputOnly,
45 DefaultVisual(disp, DefaultScreen(disp)),
46 CWOverrideRedirect, &attr);
52 CommsFindCommsWindow(void)
56 unsigned long num, after;
64 a = XInternAtom(disp, "ENLIGHTENMENT_COMMS", True);
69 XGetWindowProperty(disp, root_win, a, 0, 14, False, AnyPropertyType,
70 &ar, &format, &num, &after, &s);
74 sscanf((char *)s, "%*s %lx", &comms_win);
76 if (comms_win == None)
79 if (!XGetGeometry(disp, comms_win, &rt, &dint, &dint,
80 &duint, &duint, &duint, &duint))
84 XGetWindowProperty(disp, comms_win, a, 0, 14, False,
85 AnyPropertyType, &ar, &format, &num, &after, &s);
90 XSelectInput(disp, comms_win, StructureNotifyMask | SubstructureNotifyMask);
96 CommsSend(Client * c, const char *s)
103 if ((!s) || (!c) || (c->win == None))
106 a = XInternAtom(disp, "ENL_MSG", True);
108 ev.xclient.type = ClientMessage;
109 ev.xclient.serial = 0;
110 ev.xclient.send_event = True;
111 ev.xclient.window = c->win;
112 ev.xclient.message_type = a;
113 ev.xclient.format = 8;
116 for (i = 0; i < len + 1; i += 12)
118 sprintf(ss, "%8x", (int)my_win);
119 for (j = 0; j < 12; j++)
121 ss[8 + j] = s[i + j];
125 for (k = 0; k < 20; k++)
126 ev.xclient.data.b[k] = ss[k];
127 XSendEvent(disp, c->win, False, 0, &ev);
132 CommsGet(Client * c, XEvent * ev)
134 char s[13], s2[9], *msg;
140 if (ev->type != ClientMessage)
147 for (i = 0; i < 8; i++)
148 s2[i] = ev->xclient.data.b[i];
149 for (i = 0; i < 12; i++)
150 s[i] = ev->xclient.data.b[i + 8];
152 sscanf(s2, "%lx", &win);
154 /* append text to end of msg */
155 i = (c->msg) ? strlen(c->msg) : 0;
156 c->msg = EREALLOC(char, c->msg, i + strlen(s) + 1);
160 strcpy(c->msg + i, s);
172 ClientCreate(Window win)
176 c = EMALLOC(Client, 1);
187 ClientDestroy(Client * c)