2 * Copyright (C) 2004-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.
25 #include "e16-ecore_hints.h"
28 #include "ewins.h" /* FIXME - Should not be here */
33 OpacityFix(int op, int op_0)
39 else if (op > 100) /* Hack to convert old 0-255 range */
40 op = (100 * op) / 255;
45 OpacityFromPercent(int opx)
47 unsigned int op = (unsigned int)opx;
49 /* op is 0-100, extend to 32 bit */
50 /* op <= 0 and op > 100 is mapped to 100 (opaque) */
57 OpacityToPercent(unsigned int opacity)
59 return (int)(opacity / 42949672);
63 EobjSetLayer(EObj * eo, int layer)
65 int ilayer = eo->ilayer;
69 * For usual EWin's the internal layer is the "old" E-layer * 10.
73 * 3: Desktop type apps
77 * 20: Normal below ewins
83 * 512-: Floating windows
84 * + 0: Virtual desktops
86 * +40: Override redirects
93 eo->ilayer = 10 * eo->layer;
98 case EOBJ_TYPE_BUTTON:
100 eo->ilayer = 75; /* Ontop */
101 else if (eo->layer == 0)
102 eo->ilayer = 15; /* Normal */
103 else if (eo->layer < 0)
104 eo->ilayer = 5; /* Below */
105 if (eo->layer > 0 && eo->sticky)
110 eo->ilayer = 10 * eo->layer;
121 if (eo->ilayer != ilayer)
126 EobjSetFloating(EObj * eo, int floating)
128 if (floating == eo->floating)
143 eo->floating = floating;
144 EobjSetLayer(eo, eo->layer);
147 #if 1 /* FIXME - Remove */
149 EobjIsShaped(const EObj * eo)
154 return 0; /* FIXME */
156 return ((EWin *) eo)->state.shaped;
162 #define WINTYPE(t) ((t == EOBJ_TYPE_GLX) ? WIN_TYPE_GLX : WIN_TYPE_INTERNAL)
164 #define WINTYPE(t) WIN_TYPE_INTERNAL
168 EobjInit(EObj * eo, int type, Win win, int x, int y, int w, int h,
169 int su, const char *name)
172 eo->desk = DeskGet(0);
176 if (type == EOBJ_TYPE_EVENT)
178 win = ECreateEventWindow(VROOT, x, y, w, h);
183 win = ECreateObjectWindow(EoGetWin(eo->desk), x, y, w, h, su,
184 WINTYPE(type), NULL);
193 if (type == EOBJ_TYPE_EXT)
195 eo->icccm.wm_name = ecore_x_icccm_title_get(WinGetXwin(win));
196 ecore_x_icccm_name_class_get(WinGetXwin(win),
197 &eo->icccm.wm_res_name,
198 &eo->icccm.wm_res_class);
201 eo->icccm.wm_name = Estrdup(name);
202 if (!eo->icccm.wm_name)
203 eo->icccm.wm_name = Estrdup("-?-");
205 if (type != EOBJ_TYPE_EWIN && type != EOBJ_TYPE_EXT)
206 HintsSetWindowName(EobjGetWin(eo), eo->icccm.wm_name);
211 case EOBJ_TYPE_EVENT:
212 case EOBJ_TYPE_MISC_NR:
213 case EOBJ_TYPE_ROOT_BG:
219 if (EobjGetXwin(eo) != WinGetXwin(VROOT))
220 EobjListStackAdd(eo, 1);
222 if (EDebug(EDBUG_TYPE_EWINS))
223 Eprintf("EobjInit: %#lx %s\n", EobjGetXwin(eo), EobjGetName(eo));
229 if (EDebug(EDBUG_TYPE_EWINS))
230 Eprintf("EobjFini: %#lx %s\n", EobjGetXwin(eo), EobjGetName(eo));
232 EobjListStackDel(eo);
236 eo->gone = 1; /* Actually not yet (but soon) */
243 EUnregisterWindow(EobjGetWin(eo));
245 EDestroyWindow(EobjGetWin(eo));
247 Efree(eo->icccm.wm_name);
248 Efree(eo->icccm.wm_res_name);
249 Efree(eo->icccm.wm_res_class);
253 EobjDestroy(EObj * eo)
255 if (EDebug(EDBUG_TYPE_EWINS))
256 Eprintf("EobjDestroy: %#lx %s\n", EobjGetXwin(eo), EobjGetName(eo));
264 EobjWindowCreate(int type, int x, int y, int w, int h, int su, const char *name)
268 eo = ECALLOC(EObj, 1);
271 EobjSetLayer(eo, 20);
272 EobjInit(eo, type, EobjGetWin(eo), x, y, w, h, su, name);
283 EobjWindowDestroy(EObj * eo)
289 EobjRegister(Window xwin, int type)
292 XWindowAttributes attr;
295 eo = EobjListStackFind(xwin);
299 if (!XGetWindowAttributes(disp, xwin, &attr))
302 if (type == EOBJ_TYPE_EXT && !attr.override_redirect)
305 win = ERegisterWindow(xwin, &attr);
309 eo = ECALLOC(EObj, 1);
314 if (attr.c_class == InputOnly)
316 if (attr.class == InputOnly)
324 EobjInit(eo, type, win, attr.x, attr.y, attr.width, attr.height, 0, NULL);
326 #if 1 /* FIXME - TBD */
327 if (type == EOBJ_TYPE_EXT)
329 eo->shaped = 0; /* FIXME - Assume unshaped for now */
330 EobjSetFloating(eo, 1);
335 Eprintf("EobjRegister: %#lx type=%d or=%d: %s\n", xwin, type,
336 attr.override_redirect, EobjGetName(eo));
343 EobjUnregister(EObj * eo)
346 Eprintf("EobjUnregister: %#lx type=%d: %s\n", eo->win, eo->type,
353 EobjMap(EObj * eo, int raise)
360 EobjListStackRaise(eo, 0);
362 if (eo->stacked <= 0 || raise > 1)
363 DeskRestack(eo->desk);
366 EobjShapeUpdate(eo, 0);
368 EMapWindow(EobjGetWin(eo));
382 ECompMgrWinUnmap(eo);
384 EUnmapWindow(EobjGetWin(eo));
389 EobjMoveResize(EObj * eo, int x, int y, int w, int h)
393 move = x != EobjGetX(eo) || y != EobjGetY(eo);
394 resize = w != EobjGetW(eo) || h != EobjGetH(eo);
396 if (eo->type == EOBJ_TYPE_EWIN)
398 ECompMgrMoveResizeFix(eo, x, y, w, h);
403 EMoveResizeWindow(EobjGetWin(eo), x, y, w, h);
407 ECompMgrWinMoveResize(eo, move, resize, 0);
412 EobjMove(EObj * eo, int x, int y)
414 EobjMoveResize(eo, x, y, EobjGetW(eo), EobjGetH(eo));
418 EobjResize(EObj * eo, int w, int h)
420 EobjMoveResize(eo, EobjGetX(eo), EobjGetY(eo), w, h);
424 EobjDamage(EObj * eo)
428 ECompMgrWinDamageArea(eo, 0, 0, 0, 0);
435 EobjReparent(EObj * eo, EObj * dst, int x, int y)
439 move = x != EobjGetX(eo) || y != EobjGetY(eo);
441 EReparentWindow(EobjGetWin(eo), EobjGetWin(dst), x, y);
442 if (dst->type == EOBJ_TYPE_DESK)
444 Desk *dsk = (Desk *) dst;
452 DeskSetDirtyStack(dsk, eo);
455 ECompMgrWinReparent(eo, dsk, move);
461 EobjListStackDel(eo);
475 num = EobjListStackRaise(eo, 1);
480 num = EobjListStackRaise(eo, 0);
481 if (eo->shown && eo->cmhook)
482 ECompMgrWinRaiseLower(eo, num);
484 num = EobjListStackRaise(eo, 0);
488 return EobjListStackRaise(eo, 0);
498 num = EobjListStackLower(eo, 1);
503 num = EobjListStackLower(eo, 0);
504 if (eo->shown && eo->cmhook)
505 ECompMgrWinRaiseLower(eo, num);
507 num = EobjListStackLower(eo, 0);
511 return EobjListStackLower(eo, 0);
516 EobjShapeUpdate(EObj * eo, int propagate)
519 int was_shaped = eo->shaped;
523 eo->shaped = EShapePropagate(EobjGetWin(eo)) != 0;
525 eo->shaped = EShapeCheck(EobjGetWin(eo)) != 0;
528 if (was_shaped <= 0 && eo->shaped <= 0)
531 /* Shape may still be unchanged. Well ... */
532 if (eo->shown && eo->cmhook)
533 ECompMgrWinChangeShape(eo);
538 EobjGetPixmap(const EObj * eo)
543 pmap = ECompMgrWinGetPixmap(eo);
551 EobjChangeOpacity(EObj * eo, unsigned int opacity)
554 if (eo->opacity == opacity)
556 eo->opacity = opacity;
557 ECompMgrWinChangeOpacity(eo, opacity);
566 EobjChangeShadow(EObj * eo, int shadow)
568 ECompMgrWinChangeShadow(eo, shadow);
573 EobjSlideTo(EObj * eo, int fx, int fy, int tx, int ty, int speed)
579 ETimedLoopInit(0, 1024, speed);
580 for (k = 0; k <= 1024;)
582 x = ((fx * (1024 - k)) + (tx * k)) >> 10;
583 y = ((fy * (1024 - k)) + (ty * k)) >> 10;
586 k = ETimedLoopNext();
588 EobjMove(eo, tx, ty);
594 EobjsSlideBy(EObj ** peo, int num, int dx, int dy, int speed)
604 xy = EMALLOC(struct _xy, num);
608 for (i = 0; i < num; i++)
610 xy[i].x = EobjGetX(peo[i]);
611 xy[i].y = EobjGetY(peo[i]);
614 ETimedLoopInit(0, 1024, speed);
615 for (k = 0; k <= 1024;)
617 for (i = 0; i < num; i++)
619 x = ((xy[i].x * (1024 - k)) + ((xy[i].x + dx) * k)) >> 10;
620 y = ((xy[i].y * (1024 - k)) + ((xy[i].y + dy) * k)) >> 10;
621 EobjMove(peo[i], x, y);
624 k = ETimedLoopNext();
627 for (i = 0; i < num; i++)
628 EobjMove(peo[i], xy[i].x + dx, xy[i].y + dy);
634 EobjSlideSizeTo(EObj * eo, int fx, int fy, int tx, int ty, int fw, int fh,
635 int tw, int th, int speed)
639 ETimedLoopInit(0, 1024, speed);
640 for (k = 0; k <= 1024;)
642 x = ((fx * (1024 - k)) + (tx * k)) >> 10;
643 y = ((fy * (1024 - k)) + (ty * k)) >> 10;
644 w = ((fw * (1024 - k)) + (tw * k)) >> 10;
645 h = ((fh * (1024 - k)) + (th * k)) >> 10;
646 EobjMoveResize(eo, x, y, w, h);
648 k = ETimedLoopNext();
650 EobjMoveResize(eo, tx, ty, tw, th);
657 if (ECompMgrIsActive())
666 EobjsOpacityUpdate(int op_or)
668 EObj *eo, *const *lst;
671 lst = EobjListStackGet(&num);
672 for (i = 0; i < num; i++)
680 EwinUpdateOpacity((EWin *) eo);
683 EobjChangeOpacity(eo, OpacityFromPercent(op_or));