2 * Copyright (C) 2003-2008 Kim Woelders
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies of the Software, its documentation and marketing & publicity
13 * materials, and acknowledgment shall be given in the documentation, materials
14 * and software packages that this Software was used.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Feeble attempt to collect hint stuff in one place
27 #include "borders.h" /* FIXME - Should not be here */
28 #include "desktops.h" /* FIXME - Should not be here */
29 #include "e16-ecore_hints.h"
34 #include <X11/Xatom.h>
36 #define N_ITEMS(x) (sizeof(x)/sizeof(x[0]))
38 static const char *const atoms_misc_names[] = {
42 /* Root background atoms */
47 "ENLIGHTENMENT_VERSION",
49 "ENLIGHTENMENT_COMMS",
52 "ENL_INTERNAL_AREA_DATA",
53 "ENL_INTERNAL_DESK_DATA",
58 unsigned int atoms_misc[10];
61 AtomListIntern(const char *const *names, unsigned int num, unsigned int *atoms)
63 #if SIZEOF_INT == SIZEOF_LONG
64 XInternAtoms(disp, (char **)names, num, False, (Atom *) atoms);
69 _atoms = EMALLOC(Atom, num);
73 XInternAtoms(disp, (char **)names, num, False, _atoms);
74 for (i = 0; i < num; i++)
86 AtomListIntern(atoms_misc_names, N_ITEMS(atoms_misc_names), atoms_misc);
88 win = XCreateSimpleWindow(disp, WinGetXwin(VROOT), -200, -200, 5, 5,
98 ecore_x_window_prop_string_set(WinGetXwin(VROOT), E16_ATOM_VERSION,
103 HintsSetWindowName(VROOT, "Enlightenment");
104 HintsSetWindowClass(VROOT, "Virtual-Root", "Enlightenment");
107 Mode.root.ext_pmap = HintsGetRootPixmap(VROOT);
108 Mode.root.ext_pmap_valid = EDrawableCheck(Mode.root.ext_pmap, 0);
112 * Functions that set X11-properties from E-internals
116 HintsSetRootHints(Win win __UNUSED__)
118 /* Nothing done here for now */
122 HintsSetClientList(void)
125 GNOME_SetClientList();
127 EWMH_SetClientList();
128 EWMH_SetClientStacking();
132 HintsSetClientStacking(void)
134 EWMH_SetClientStacking();
138 HintsSetDesktopConfig(void)
141 GNOME_SetDeskCount();
142 GNOME_SetDeskNames();
144 EWMH_SetDesktopCount();
145 EWMH_SetDesktopRoots();
146 EWMH_SetDesktopNames();
151 HintsSetViewportConfig(void)
154 GNOME_SetAreaCount();
156 EWMH_SetDesktopSize();
160 HintsSetCurrentDesktop(void)
163 GNOME_SetCurrentDesk();
165 EWMH_SetCurrentDesktop();
166 HintsSetDesktopViewport();
170 HintsSetDesktopViewport(void)
173 GNOME_SetCurrentArea();
175 EWMH_SetDesktopViewport();
179 HintsSetActiveWindow(Window win)
181 EWMH_SetActiveWindow(win);
185 HintsSetWindowName(Win win, const char *name)
190 ecore_x_icccm_title_set(WinGetXwin(win), name);
192 EWMH_SetWindowName(WinGetXwin(win), name);
196 HintsSetWindowClass(Win win, const char *name, const char *clss)
203 ecore_x_icccm_name_class_set(WinGetXwin(win), name, clss);
207 HintsSetWindowDesktop(const EWin * ewin)
210 GNOME_SetEwinDesk(ewin);
212 EWMH_SetWindowDesktop(ewin);
216 HintsSetWindowArea(const EWin * ewin __UNUSED__)
219 GNOME_SetEwinArea(ewin);
224 HintsSetWindowState(const EWin * ewin)
229 EWMH_SetWindowState(ewin);
230 EWMH_SetWindowActions(ewin);
234 HintsSetWindowOpacity(const EWin * ewin)
236 EWMH_SetWindowOpacity(ewin);
240 HintsSetWindowBorder(const EWin * ewin)
242 EWMH_SetWindowBorder(ewin);
246 * Functions that set E-internals from X11-properties
250 HintsGetWindowHints(EWin * ewin)
253 GNOME_GetHints(ewin, 0);
255 EWMH_GetWindowHints(ewin);
259 * Functions that delete X11-properties
263 HintsDelWindowHints(const EWin * ewin)
266 GNOME_DelHints(ewin);
268 EWMH_DelWindowHints(ewin);
272 * Functions processing received X11 messages
276 HintsProcessPropertyChange(EWin * ewin, XEvent * ev)
278 if (ICCCM_ProcessPropertyChange(ewin, ev->xproperty.atom))
280 if (EWMH_ProcessPropertyChange(ewin, ev->xproperty.atom))
282 #if 0 /* No! - ENABLE_GNOME */
283 if (GNOME_GetHints(ewin, ev->xproperty.atom))
289 Eprintf("HintsProcessPropertyChange:\n");
296 HintsProcessClientClientMessage(EWin * ewin, XClientMessageEvent * event)
298 if (ICCCM_ProcessClientClientMessage(ewin, event))
300 if (EWMH_ProcessClientClientMessage(ewin, event))
303 if (GNOME_ProcessClientClientMessage(ewin, event))
308 Eprintf("HintsProcessClientClientMessage:\n");
309 EventShow((XEvent *) event);
314 HintsProcessRootClientMessage(XClientMessageEvent * event)
316 if (ICCCM_ProcessRootClientMessage(event))
318 if (EWMH_ProcessRootClientMessage(event))
321 if (GNOME_ProcessRootClientMessage(event))
326 Eprintf("HintsProcessRootClientMessage:\n");
327 EventShow((XEvent *) event);
332 HintsGetRootPixmap(Win win)
339 ecore_x_window_prop_xid_get(WinGetXwin(win), E_XROOTPMAP_ID, XA_PIXMAP,
346 HintsSetRootInfo(Win win, Pixmap pmap, unsigned int color)
351 ecore_x_window_prop_xid_set(WinGetXwin(win), E_XROOTPMAP_ID, XA_PIXMAP, &pm,
354 ecore_x_window_prop_card32_set(WinGetXwin(win), E_XROOTCOLOR_PIXEL, &color,
363 unsigned iconified:1;
368 #define ENL_DATA_ITEMS 12
369 #define ENL_DATA_VERSION 0
372 EHintsSetInfo(const EWin * ewin)
374 int c[ENL_DATA_ITEMS];
375 unsigned int flags[2];
378 if (EwinIsInternal(ewin))
382 f.b.version = ENL_DATA_VERSION;
383 f.b.docked = ewin->state.docked;
384 f.b.iconified = ewin->state.iconified;
387 EwinFlagsEncode(ewin, flags);
391 c[3] = ewin->save_max.x;
392 c[4] = ewin->save_max.y;
393 c[5] = ewin->save_max.w;
394 c[6] = ewin->save_max.h;
395 c[7] = ewin->save_fs.x;
396 c[8] = ewin->save_fs.y;
397 c[9] = ewin->save_fs.w;
398 c[10] = ewin->save_fs.h;
399 c[11] = ewin->save_fs.layer;
401 ecore_x_window_prop_card32_set(EwinGetClientXwin(ewin), E16_ATOM_WIN_DATA,
402 (unsigned int *)c, ENL_DATA_ITEMS);
404 ecore_x_window_prop_string_set(EwinGetClientXwin(ewin), E16_ATOM_WIN_BORDER,
405 ewin->normal_border->name);
407 if (EDebug(EDBUG_TYPE_SNAPS))
408 Eprintf("Snap set einf %#lx: %4d+%4d %4dx%4d: %s\n",
409 EwinGetClientXwin(ewin), ewin->client.x, ewin->client.y,
410 ewin->client.w, ewin->client.h, EwinGetTitle(ewin));
414 EHintsGetInfo(EWin * ewin)
418 int c[ENL_DATA_ITEMS + 1];
419 unsigned int flags[2];
422 if (EwinIsInternal(ewin))
426 ecore_x_window_prop_card32_get(EwinGetClientXwin(ewin), E16_ATOM_WIN_DATA,
427 (unsigned int *)c, ENL_DATA_ITEMS + 1);
431 ewin->state.identified = 1;
432 ewin->state.placed = 1;
438 if (f.b.version != ENL_DATA_VERSION)
440 ewin->icccm.start_iconified = f.b.iconified;
441 ewin->state.docked = f.b.docked;
445 EwinFlagsDecode(ewin, flags);
447 if (num == ENL_DATA_ITEMS)
449 ewin->save_max.x = c[3];
450 ewin->save_max.y = c[4];
451 ewin->save_max.w = c[5];
452 ewin->save_max.h = c[6];
453 ewin->save_fs.x = c[7];
454 ewin->save_fs.y = c[8];
455 ewin->save_fs.w = c[9];
456 ewin->save_fs.h = c[10];
457 ewin->save_fs.layer = c[11];
461 ecore_x_window_prop_string_get(EwinGetClientXwin(ewin),
462 E16_ATOM_WIN_BORDER);
464 EwinBorderSetInitially(ewin, str);
467 if (EDebug(EDBUG_TYPE_SNAPS))
468 Eprintf("Snap get einf %#lx: %4d+%4d %4dx%4d: %s\n",
469 EwinGetClientXwin(ewin), ewin->client.x, ewin->client.y,
470 ewin->client.w, ewin->client.h, EwinGetTitle(ewin));
474 EHintsSetDeskInfo(void)
476 int i, ax, ay, n_desks;
479 if (!DesksGetCurrent()) /* Quit if current desk isn't assigned yet */
482 n_desks = DesksGetNumber();
486 c = EMALLOC(unsigned int, 2 * n_desks);
490 for (i = 0; i < n_desks; i++)
492 DeskGetArea(DeskGet(i), &ax, &ay);
497 ecore_x_window_prop_card32_set(WinGetXwin(VROOT),
498 E16_ATOM_INTERNAL_AREA_DATA, c, 2 * n_desks);
500 c[0] = DesksGetCurrentNum();
501 ecore_x_window_prop_card32_set(WinGetXwin(VROOT),
502 E16_ATOM_INTERNAL_DESK_DATA, c, 1);
506 if (Mode.root.ext_pmap_valid)
508 HintsSetRootInfo(VROOT, Mode.root.ext_pmap, 0);
509 ESetWindowBackgroundPixmap(VROOT, Mode.root.ext_pmap);
514 EHintsGetDeskInfo(void)
519 n_desks = DesksGetNumber();
520 c = EMALLOC(unsigned int, 2 * n_desks);
525 num = ecore_x_window_prop_card32_get(WinGetXwin(VROOT),
526 E16_ATOM_INTERNAL_AREA_DATA,
530 for (i = 0; i < (num / 2); i++)
531 DeskSetArea(DeskGet(i), c[(i * 2)], c[(i * 2) + 1]);
534 num = ecore_x_window_prop_card32_get(WinGetXwin(VROOT),
535 E16_ATOM_INTERNAL_DESK_DATA, c, 1);
538 DesksSetCurrent(DeskGet(c[0]));
542 /* Used to test if we should run cmd_init */
543 Mode.wm.session_start = 1;
550 EHintsSetInfoOnAll(void)
555 if (EDebug(EDBUG_TYPE_SESSION))
556 Eprintf("SetEInfoOnAll\n");
558 lst = EwinListGetAll(&num);
559 for (i = 0; i < num; i++)
560 if (!EwinIsInternal(lst[i]))
561 EHintsSetInfo(lst[i]);
574 EventCallbackFunc *func;
579 SelectionAcquire(const char *name, EventCallbackFunc * func, void *data)
584 sel = ECALLOC(ESelection, 1);
588 Esnprintf(buf, sizeof(buf), "%s%d", name, Dpy.screen);
590 sel->atom = EInternAtom(buf);
591 sel->time = EGetTimestamp();
592 sel->win = ECreateEventWindow(VROOT, -100, -100, 1, 1);
597 XSetSelectionOwner(disp, sel->atom, WinGetXwin(sel->win), sel->time);
598 if (XGetSelectionOwner(disp, sel->atom) != WinGetXwin(sel->win))
600 DialogOK(_("Selection Error!"), _("Could not acquire selection: %s"),
602 EDestroyWindow(sel->win);
609 ESelectInput(sel->win, SubstructureNotifyMask);
610 EventCallbackRegister(sel->win, 0, sel->func, sel->data);
613 ecore_x_client_message32_send(WinGetXwin(VROOT), E_XA_MANAGER,
614 StructureNotifyMask, CurrentTime, sel->atom,
615 WinGetXwin(sel->win), 0, 0);
617 if (EDebug(EDBUG_TYPE_SELECTION))
618 Eprintf("Window %#lx is now %s owner, time=%lu\n",
619 WinGetXwin(sel->win), buf, sel->time);
625 SelectionRelease(ESelection * sel)
630 if (EDebug(EDBUG_TYPE_SELECTION))
631 Eprintf("Window %#lx is no longer %s owner\n",
632 WinGetXwin(sel->win), XGetAtomName(disp, sel->atom));
634 XSetSelectionOwner(disp, sel->atom, None, sel->time);
637 EventCallbackUnregister(sel->win, 0, sel->func, sel->data);
639 EDestroyWindow(sel->win);