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.
29 #include "windowmatch.h"
33 NetwmIconFindBestSize(unsigned int *val, unsigned int len, int size)
35 unsigned int i, j, sj, sbest, sz;
38 sz = (unsigned int)size;
43 i += 2 + val[i] * val[i + 1];
51 break; /* First exact match */
55 if (sbest > sz && sj >= sbest)
71 IB_IconGetSize(int ww, int hh, int size, int scale, int *pw, int *ph)
98 IB_SnapEWin(EWin * ewin, int size)
100 /* Make snapshot of window */
105 if (!EoIsShown(ewin))
110 if (ww <= 0 || hh <= 0)
113 if (ewin->state.shaded)
114 EwinInstantUnShade(ewin);
117 /* Oversample for nicer snapshots */
118 IB_IconGetSize(ww, hh, size, 4, &w, &h);
120 draw = EoGetPixmap(ewin);
125 mask = EWindowGetShapePixmap(EoGetWin(ewin));
126 im = EImageGrabDrawableScaled(EoGetWin(ewin), draw, mask, 0, 0, ww, hh,
127 w, h, !EServerIsGrabbed(), 0);
133 draw = EoGetXwin(ewin);
134 im = EImageGrabDrawableScaled(EoGetWin(ewin), draw, None, 0, 0, ww, hh,
135 w, h, !EServerIsGrabbed(), 1);
137 EImageSetHasAlpha(im, 1);
143 IB_GetAppIcon(EWin * ewin, int size)
145 /* Get the applications icon pixmap/mask */
149 if (ewin->ewmh.wm_icon)
153 x = NetwmIconFindBestSize(ewin->ewmh.wm_icon, ewin->ewmh.wm_icon_len,
157 im = EImageCreateFromData(ewin->ewmh.wm_icon[x],
158 ewin->ewmh.wm_icon[x + 1],
159 ewin->ewmh.wm_icon + x + 2);
160 EImageSetHasAlpha(im, 1);
165 if (!ewin->icccm.icon_pmap)
170 EXGetGeometry(ewin->icccm.icon_pmap, NULL, NULL, NULL, &w, &h, NULL, NULL);
175 im = EImageGrabDrawable(ewin->icccm.icon_pmap, ewin->icccm.icon_mask,
176 0, 0, w, h, !EServerIsGrabbed());
177 EImageSetHasAlpha(im, 1);
183 IB_GetEIcon(EWin * ewin)
185 /* get the icon defined for this window in E's iconf match file */
189 file = WindowMatchEwinIcon(ewin);
193 im = ThemeImageLoad(file);
199 IB_GetFallbackIcon(EWin * ewin, int size)
212 IB_IconGetSize(ww, hh, size, 1, &w, &h);
214 ic = ImageclassFind("ICONBOX_HORIZONTAL", 1);
215 im = ImageclassGetImageBlended(ic, EoGetWin(ewin), w, h, 0, 0,
216 STATE_NORMAL, ST_SOLID);
223 static const char ewin_icon_modes[N_MODES][N_TYPES] = {
224 {EWIN_ICON_TYPE_SNAP, EWIN_ICON_TYPE_APP, EWIN_ICON_TYPE_IMG,
226 {EWIN_ICON_TYPE_APP, EWIN_ICON_TYPE_IMG, EWIN_ICON_TYPE_SNAP,
228 {EWIN_ICON_TYPE_IMG, EWIN_ICON_TYPE_SNAP, EWIN_ICON_TYPE_APP,
230 {EWIN_ICON_TYPE_IMG, EWIN_ICON_TYPE_APP, EWIN_ICON_TYPE_NONE,
231 EWIN_ICON_TYPE_NONE},
232 {EWIN_ICON_TYPE_APP, EWIN_ICON_TYPE_IMG, EWIN_ICON_TYPE_NONE,
233 EWIN_ICON_TYPE_NONE},
237 EwinIconImageGet(EWin * ewin, int size, int mode)
242 if (mode < 0 || mode >= N_MODES)
245 for (i = 0; i < N_TYPES; i++)
247 type = ewin_icon_modes[mode][i];
254 case EWIN_ICON_TYPE_SNAP:
255 im = IB_SnapEWin(ewin, size);
258 case EWIN_ICON_TYPE_APP:
259 im = IB_GetAppIcon(ewin, size);
262 case EWIN_ICON_TYPE_IMG:
263 im = IB_GetEIcon(ewin);
266 case EWIN_ICON_TYPE_FB:
267 im = IB_GetFallbackIcon(ewin, size);