static Container * SelectIconboxForEwin(EWin * ewin) { /* find the appropriate iconbox from all available ones for this app */ /* if it is to be iconified, or if it is alreayd return which iconbox */ /* it's in */ Container *ct, *ib_sel = NULL; if (!ewin) return NULL; if (ewin->state.iconified) { /* find the iconbox this window got iconifed into */ ib_sel = ContainersIterate(IconboxFindEwin, IB_TYPE_ICONBOX, ewin); } else { /* pick the closest iconbox physically on screen to put it in */ int min_dist; int dx, dy, dist; int i, num; Container **lst; lst = ContainersGetList(&num); min_dist = 0x7fffffff; for (i = 0; i < num; i++) { ct = lst[i]; if (!ct->ewin || ct->type != IB_TYPE_ICONBOX) continue; dx = (EoGetX(ct->ewin) + (EoGetW(ct->ewin) / 2)) - (EoGetX(ewin) + (EoGetW(ewin) / 2)); dy = (EoGetY(ct->ewin) + (EoGetH(ct->ewin) / 2)) - (EoGetY(ewin) + (EoGetH(ewin) / 2)); dist = (dx * dx) + (dy * dy); if ((!EoIsSticky(ct->ewin)) && (EoGetDesk(ct->ewin) != EoGetDesk(ewin))) dist += (WinGetW(VROOT) * WinGetW(VROOT)) + (WinGetH(VROOT) * WinGetH(VROOT)); if (dist < min_dist) { min_dist = dist; ib_sel = ct; } } Efree(lst); } return ib_sel; }
static void _SnapUpdateEwinLocation(Snapshot * sn, const EWin * ewin) { int ax, ay; sn->x = EoGetX(ewin); sn->y = EoGetY(ewin); sn->area_x = ewin->area_x; sn->area_y = ewin->area_y; if (!EoIsSticky(ewin)) { DeskGetArea(EoGetDesk(ewin), &ax, &ay); sn->x += ((ax - sn->area_x) * WinGetW(VROOT)); sn->y += ((ay - sn->area_y) * WinGetH(VROOT)); } }
void DrawEwinShape(EWin * ewin, int md, int x, int y, int w, int h, int firstlast, int seqno) { ShapeData *psd; int dx, dy; /* Quit if no change */ if (firstlast == 1 && (x == ewin->shape_x && y == ewin->shape_y && (ewin->state.shaded || (w == ewin->shape_w && h == ewin->shape_h)))) return; if ((md == MR_OPAQUE) || (md == MR_TECH_OPAQUE)) { EwinOpMoveResize(ewin, OPSRC_USER, x, y, w, h); EwinShapeSet(ewin); CoordsShow(ewin); if (md == MR_OPAQUE) goto done; } if (firstlast == 0) { EwinShapeSet(ewin); psd = ECALLOC(ShapeData, 1); ewin->shape_data = psd; if (!psd) goto done; psd->root = WinGetXwin(VROOT); EwinBorderGetSize(ewin, &psd->bl, &psd->br, &psd->bt, &psd->bb); } psd = (ShapeData *) ewin->shape_data; if (!psd) goto done; dx = EoGetX(EoGetDesk(ewin)); dy = EoGetY(EoGetDesk(ewin)); ewin->shape_x = x; ewin->shape_y = y; x += dx; y += dy; if (!ewin->state.shaded) { ewin->shape_w = w; ewin->shape_h = h; } else { w = ewin->shape_w; h = ewin->shape_h; } if (((md <= MR_BOX) || (md == MR_TECH_OPAQUE)) && Conf.movres.avoid_server_grab) { _ShapeDrawNograb_tech_box(ewin, md, firstlast, x, y, w, h, seqno); goto done; } switch (md) { case MR_TECHNICAL: case MR_TECH_OPAQUE: case MR_BOX: _ShapeDrawNontranslucent(ewin, md, firstlast, x, y, w, h); break; default: /* Fall back to opaque mode */ Conf.movres.mode_move = MR_OPAQUE; break; } psd->xo = x; psd->yo = y; psd->wo = w; psd->ho = h; done: if (firstlast == 0 || firstlast == 2 || firstlast == 4) { ewin->req_x = ewin->shape_x; ewin->req_y = ewin->shape_y; if (firstlast == 2) { CoordsHide(); Efree(ewin->shape_data); ewin->shape_data = NULL; } } }
static void _CoordsShow(EWin * ewin, int mode) { TextClass *tc; ImageClass *ic; char s[256]; int md; int x, y; unsigned int w, h; int cx, cy, cw, ch; EObj *eo = coord_eo; EImageBorder *pad; int bl, br, bt, bb; if (!Conf.movres.mode_info) return; if (!ewin || !ewin->state.show_coords) return; tc = TextclassFind("COORDS", 1); ic = ImageclassFind("COORDS", 1); if ((!ic) || (!tc)) return; cx = cy = cw = ch = 0; x = ewin->shape_x; y = ewin->shape_y; w = (ewin->state.shaded) ? ewin->client.w : ewin->shape_w; h = (ewin->state.shaded) ? ewin->client.h : ewin->shape_h; ICCCM_GetIncrementalSize(ewin, w, h, &w, &h); switch (mode) { default: case 0: Esnprintf(s, sizeof(s), "%i x %i (%i, %i)", w, h, x, y); break; case 1: Esnprintf(s, sizeof(s), _("Focused/unfocused opacity: %d/%d %%"), OpacityToPercent(ewin->props.focused_opacity), OpacityToPercent(ewin->ewmh.opacity)); break; } TextSize(tc, 0, 0, 0, s, &cw, &ch, 17); pad = ImageclassGetPadding(ic); cw += pad->left + pad->right; ch += pad->top + pad->bottom; /* Width hysteresis (hack - assuming horizontal text) */ cw += 8; if (eo && abs(EobjGetW(eo) - cw) < 8) cw = EobjGetW(eo); if (Mode.mode == MODE_MOVE) md = Conf.movres.mode_move; else md = Conf.movres.mode_resize; if ((md == 0) || ((cw < ewin->shape_w - 2) && (ch < ewin->shape_h - 2))) { if (Conf.movres.mode_info == 1) { switch (md) { case 0: case 1: case 2: EwinBorderGetSize(ewin, &bl, &br, &bt, &bb); w = (ewin->state.shaded) ? EoGetW(ewin) : ewin->shape_w + bl + br; h = (ewin->state.shaded) ? EoGetH(ewin) : ewin->shape_h + bt + bb; cx = x + (w - cw) / 2 + EoGetX(EoGetDesk(ewin)); cy = y + (h - ch) / 2 + EoGetY(EoGetDesk(ewin)); break; } } } if (!eo) { eo = EobjWindowCreate(EOBJ_TYPE_MISC, 0, 0, 1, 1, 2, "Coord"); if (!eo) return; coord_eo = eo; eo->fade = eo->shadow = 1; /* Center text (override theme) */ TextclassSetJustification(tc, 512); } #define TEST_COORD_REPARENT_TO_FRAME 0 #if TEST_COORD_REPARENT_TO_FRAME cx -= x; cy -= y; #endif md = cw != EobjGetW(eo) || ch != EobjGetH(eo); /* md is change size flag */ EobjMoveResize(eo, cx, cy, cw, ch); if (!eo->shown) { #if TEST_COORD_REPARENT_TO_FRAME EobjReparent(eo, EoObj(ewin), cx, cy); #endif EobjMap(eo, 0); } ITApply(EobjGetWin(eo), ic, NULL, STATE_NORMAL, 1, 0, ST_SOLID, tc, NULL, s, 1); if (md) /* Assuming that shape change only happens when size changes too */ EobjShapeUpdate(eo, 0); EFlush(); }
static void IB_Animate_A(char iconify, EWin * ewin, EWin * ibox) { EWin *fr, *to; unsigned int t0; double a, aa, spd; int x, y, x1, y1, x2, y2, x3, y3, x4, y4, w, h; int fx, fy, fw, fh, tx, ty, tw, th; Window root = WinGetXwin(VROOT); GC gc; XGCValues gcv; /* Window: Extents, Iconbox: Center */ if (iconify) { fr = ewin; to = ibox; fw = EoGetW(fr) + 4; fh = EoGetH(fr) + 4; fx = EoGetX(fr) - 2; fy = EoGetY(fr) - 2; tw = 4; th = 4; tx = EoGetX(to) + EoGetW(to) / 2 - 2; ty = EoGetY(to) + EoGetH(to) / 2 - 2; } else { fr = ibox; to = ewin; fw = 4; fh = 4; fx = EoGetX(fr) + EoGetW(fr) / 2 - 2; fy = EoGetY(fr) + EoGetH(fr) / 2 - 2; tw = EoGetW(to) + 4; th = EoGetH(to) + 4; tx = EoGetX(to) + 2; ty = EoGetY(to) + 2; } fx += EoGetX(EoGetDesk(fr)); fy += EoGetY(EoGetDesk(fr)); tx += EoGetX(EoGetDesk(to)); ty += EoGetY(EoGetDesk(to)); gcv.subwindow_mode = IncludeInferiors; gcv.function = GXxor; gcv.line_width = 2; gcv.foreground = Dpy.pixel_white; if (gcv.foreground == 0) gcv.foreground = Dpy.pixel_black; gc = EXCreateGC(root, GCFunction | GCForeground | GCSubwindowMode | GCLineWidth, &gcv); spd = (1. * IB_ANIM_STEP) / IB_ANIM_TIME; t0 = GetTimeMs(); for (a = 0.0; a < 1.0; a += spd) { aa = 1.0 - a; x = (int)((fx * aa) + (tx * a)); y = (int)((fy * aa) + (ty * a)); w = (int)((fw * aa) + (tw * a)); h = (int)((fh * aa) + (th * a)); x = (2 * x + w) / 2; /* x middle */ y = (2 * y + h) / 2; /* y middle */ w /= 2; /* width/2 */ h /= 2; /* height/2 */ x1 = (int)(x + w * (1 - .5 * sin(3.14159 + a * 6.2831853072))); y1 = (int)(y + h * cos(a * 6.2831853072)); x2 = (int)(x + w * (1 - .5 * sin(a * 6.2831853072))); y2 = (int)(y - h * cos(a * 6.2831853072)); x3 = (int)(x - w * (1 - .5 * sin(3.14159 + a * 6.2831853072))); y3 = (int)(y - h * cos(a * 6.2831853072)); x4 = (int)(x - w * (1 - .5 * sin(a * 6.2831853072))); y4 = (int)(y + h * cos(a * 6.2831853072)); XDrawLine(disp, root, gc, x1, y1, x2, y2); XDrawLine(disp, root, gc, x2, y2, x3, y3); XDrawLine(disp, root, gc, x3, y3, x4, y4); XDrawLine(disp, root, gc, x4, y4, x1, y1); ESync(0); IB_Animate_Sleep(t0, a); XDrawLine(disp, root, gc, x1, y1, x2, y2); XDrawLine(disp, root, gc, x2, y2, x3, y3); XDrawLine(disp, root, gc, x3, y3, x4, y4); XDrawLine(disp, root, gc, x4, y4, x1, y1); } EXFreeGC(gc); }
static void IB_Animate_B(char iconify, EWin * ewin, EWin * ibox) { EWin *fr, *to; unsigned int t0; double a, spd; int x, y, w, h; int fx, fy, fw, fh, tx, ty, tw, th; Window root = WinGetXwin(VROOT); GC gc; XGCValues gcv; if (iconify) { fr = ewin; to = ibox; } else { fr = ibox; to = ewin; } fx = EoGetX(fr) - 2; fy = EoGetY(fr) - 2; fw = EoGetW(fr) + 3; fh = EoGetH(fr) + 3; tx = EoGetX(to) - 2; ty = EoGetY(to) - 2; tw = EoGetW(to) + 3; th = EoGetH(to) + 3; fx += EoGetX(EoGetDesk(fr)); fy += EoGetY(EoGetDesk(fr)); tx += EoGetX(EoGetDesk(to)); ty += EoGetY(EoGetDesk(to)); gcv.subwindow_mode = IncludeInferiors; gcv.function = GXxor; gcv.fill_style = FillOpaqueStippled; gcv.foreground = Dpy.pixel_white; if (gcv.foreground == 0) gcv.foreground = Dpy.pixel_black; gc = EXCreateGC(root, GCFunction | GCForeground | GCSubwindowMode | GCFillStyle, &gcv); XDrawLine(disp, root, gc, fx, fy, tx, ty); XDrawLine(disp, root, gc, fx + fw, fy, tx + tw, ty); XDrawLine(disp, root, gc, fx, fy + fh, tx, ty + th); XDrawLine(disp, root, gc, fx + fw, fy + fh, tx + tw, ty + th); XDrawRectangle(disp, root, gc, tx, ty, tw, th); XDrawRectangle(disp, root, gc, fx, fy, fw, fh); spd = (1. * IB_ANIM_STEP) / IB_ANIM_TIME; t0 = GetTimeMs(); for (a = 0.0; a < 1.0; a += spd) { x = (int)(fx + a * (tx - fx)); w = (int)(fw + a * (tw - fw)); y = (int)(fy + a * (ty - fy)); h = (int)(fh + a * (th - fh)); XDrawRectangle(disp, root, gc, x, y, w, h); ESync(0); IB_Animate_Sleep(t0, a); XDrawRectangle(disp, root, gc, x, y, w, h); } XDrawLine(disp, root, gc, fx, fy, tx, ty); XDrawLine(disp, root, gc, fx + fw, fy, tx + tw, ty); XDrawLine(disp, root, gc, fx, fy + fh, tx, ty + th); XDrawLine(disp, root, gc, fx + fw, fy + fh, tx + tw, ty + th); XDrawRectangle(disp, root, gc, tx, ty, tw, th); XDrawRectangle(disp, root, gc, fx, fy, fw, fh); EXFreeGC(gc); }