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.
41 void (*evcb) (Win win, XEvent * ev, void *data);
49 void (*init) (Hiwin * phi);
50 void (*draw) (Hiwin * phi);
51 void (*fini) (Hiwin * phi, int shown);
54 static ImageClass *hiwin_ic = NULL;
56 /* TBD: Move elsewhere? */
58 EobjGetImage(EObj * eo, Drawable draw)
63 mask = EWindowGetShapePixmap(EobjGetWin(eo));
64 im = EImageGrabDrawable(draw, mask, 0, 0, EobjGetW(eo), EobjGetH(eo), 0);
72 HiwinRenderImageInit(Hiwin * phi)
74 EWin *ewin = phi->ewin;
77 pmap = EoGetPixmap(ewin);
80 phi->im = EobjGetImage(EoObj(ewin), pmap);
81 /* Skip zoom effect if composite is active */
84 else if (phi->zoom > 2 && EwinIsOnScreen(ewin))
86 phi->im = EobjGetImage(EoObj(ewin), EoGetXwin(ewin));
91 EImageGrabDrawable(ewin->mini_pmm.pmap, ewin->mini_pmm.mask, 0, 0,
92 ewin->mini_w, ewin->mini_h, 0);
95 ESetWindowBackgroundPixmap(EoGetWin(phi), None);
98 EShapeSetMask(EoGetWin(phi), 0, 0, None);
99 EoShapeUpdate(phi, 0);
103 HiwinRenderImageDrawX(Hiwin * phi, Drawable draw __UNUSED__)
105 EImageApplyToWin(phi->im, EoGetWin(phi), EIMAGE_ANTI_ALIAS,
106 EoGetW(phi), EoGetH(phi));
107 EoShapeUpdate(phi, 0);
111 HiwinRenderImageDraw(Hiwin * phi)
113 HiwinRenderImageDrawX(phi, EoGetXwin(phi));
117 HiwinRenderImageFini(Hiwin * phi, int shown)
120 HiwinRenderImageDraw(phi);
121 EImageDecache(phi->im);
127 HiwinRenderImageUpdate(Hiwin * phi)
130 EWin *ewin = phi->ewin;
132 pmap = EoGetPixmap(ewin);
136 phi->im = EobjGetImage(EoObj(ewin), pmap);
137 HiwinRenderImageDraw(phi);
138 EImageDecache(phi->im);
143 static const HiwinRender HiwinRenderImage = {
144 HiwinRenderImageInit, HiwinRenderImageDraw, HiwinRenderImageFini
148 HiwinRenderIclassInit(Hiwin * phi __UNUSED__)
153 HiwinRenderIclassDraw(Hiwin * phi)
155 ImageclassApply(hiwin_ic, EoGetWin(phi), 0, 0, STATE_NORMAL, ST_PAGER);
159 HiwinRenderIclassFini(Hiwin * phi, int shown)
162 HiwinRenderIclassDraw(phi);
165 static const HiwinRender HiwinRenderIclass = {
166 HiwinRenderIclassInit, HiwinRenderIclassDraw, HiwinRenderIclassFini
170 HiwinRenderPixmapInit(Hiwin * phi)
172 phi->gc = EXCreateGC(EoGetXwin(phi), 0, NULL);
176 HiwinRenderPixmapDrawX(Hiwin * phi, Drawable draw)
178 XSetForeground(disp, phi->gc, Dpy.pixel_black);
179 XFillRectangle(disp, draw, phi->gc, 0, 0, EoGetW(phi), EoGetH(phi));
180 XSetForeground(disp, phi->gc, Dpy.pixel_white);
181 XFillRectangle(disp, draw, phi->gc, 1, 1, EoGetW(phi) - 2, EoGetH(phi) - 2);
185 HiwinRenderPixmapDraw(Hiwin * phi)
187 HiwinRenderPixmapDrawX(phi, EoGetXwin(phi));
188 EClearWindow(EoGetWin(phi));
192 HiwinRenderPixmapFini(Hiwin * phi, int shown)
198 pmap = EGetWindowBackgroundPixmap(EoGetWin(phi));
199 HiwinRenderPixmapDrawX(phi, pmap);
200 EClearWindow(EoGetWin(phi));
207 static const HiwinRender HiwinRenderPixmap = {
208 HiwinRenderPixmapInit, HiwinRenderPixmapDraw, HiwinRenderPixmapFini
212 HiwinEvent(Win win, XEvent * ev, void *prm)
214 Hiwin *phi = (Hiwin *) prm;
217 phi->evcb(win, ev, phi->data);
222 HiwinEwinEvent(Win win __UNUSED__, XEvent * ev, void *prm)
224 Hiwin *phi = (Hiwin *) prm;
227 Eprintf("HiwinEwinEvent type=%d %s\n", ev->type, EwinGetTitle(phi->ewin));
232 case EX_EVENT_DAMAGE_NOTIFY:
233 HiwinRenderImageUpdate(phi);
244 phi = ECALLOC(Hiwin, 1);
248 EoInit(phi, EOBJ_TYPE_MISC, None, 0, 0, 3, 3, 1, "HiWin");
250 EoSetFloating(phi, 1);
252 EventCallbackRegister(EoGetWin(phi), 0, HiwinEvent, phi);
253 ESelectInput(EoGetWin(phi),
254 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
255 EnterWindowMask | LeaveWindowMask);
261 HiwinSetGeom(Hiwin * phi, int x, int y, int w, int h)
270 HiwinInit(Hiwin * phi, EWin * ewin)
272 if (ewin == phi->ewin)
279 Eprintf("Unregister %s\n", EwinGetTitle(phi->ewin));
281 EventCallbackUnregister(EoGetWin(phi->ewin), 0, HiwinEwinEvent, phi);
291 Eprintf("Register %s\n", EwinGetTitle(phi->ewin));
293 EventCallbackRegister(EoGetWin(phi->ewin), 0, HiwinEwinEvent, phi);
298 hiwin_ic = ImageclassFind("PAGER_WIN", 0);
302 HiwinSetCallback(Hiwin * phi, void (*func) (Win win, XEvent * ev, void *data),
310 HiwinGetXY(Hiwin * phi, int *x, int *y)
317 HiwinMove(Hiwin * phi, int x, int y)
323 HiwinGetEwin(Hiwin * phi, int check)
329 if (!check || !phi->ewin)
332 ewin = EwinFindByPtr(phi->ewin);
338 HiwinHide(Hiwin * phi)
345 GrabPointerRelease();
346 HiwinInit(phi, NULL);
355 HiwinShow(Hiwin * phi, EWin * ewin, int zoom, int confine)
357 const HiwinRender *pz;
358 int x, y, w, h, zold;
359 int xx, yy, ww, hh, i, i1, i2, step, px, py;
366 if (ewin->mini_pmm.pmap)
367 pz = &HiwinRenderImage;
369 pz = &HiwinRenderIclass;
371 pz = &HiwinRenderPixmap;
373 if (phi->zoom <= 2 && zoom == 2)
377 x = phi->xo + phi->wo / 2;
378 y = phi->yo + phi->ho / 2;
382 step = zoom - phi->zoom;
386 x = phi->xo + phi->wo / 2;
387 y = phi->yo + phi->ho / 2;
394 x = WinGetW(VROOT) / 2;
395 y = WinGetH(VROOT) / 2;
396 w = zoom * EoGetW(phi->ewin) / 4;
397 h = zoom * EoGetH(phi->ewin) / 4;
402 Eprintf("HiwinShow %s zoom=%d->%d step=%d %d,%d %dx%d\n",
403 EoGetName(ewin), phi->zoom, zoom, step, x, y, w, h);
414 if (step && phi->animate)
432 for (i = i1; i != i2; i += step)
446 xx = x + ((w - ww) / 2);
447 yy = y + ((h - hh) / 2);
448 EoMoveResize(phi, xx, yy, ww, hh);
451 on_screen = EQueryPointer(NULL, &px, &py, NULL, NULL);
453 (px < x) || (py < y) || (px >= (x + w)) || (py >= (y + h)))
463 EoMoveResize(phi, x - w / 2, y - h / 2, w, h);
466 GrabPointerSet(EoGetWin(phi), ECSR_ACT_MOVE, confine);