2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
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.
33 static EObj *coord_eo = NULL;
36 _CoordsShow(EWin * ewin, int mode)
49 if (!Conf.movres.mode_info)
51 if (ewin == NULL || !ewin->state.show_coords)
54 tc = TextclassFind("COORDS", 1);
55 ic = ImageclassFind("COORDS", 1);
59 cx = cy = cw = ch = 0;
63 w = (ewin->state.shaded) ? ewin->client.w : ewin->shape_w;
64 h = (ewin->state.shaded) ? ewin->client.h : ewin->shape_h;
65 ICCCM_GetIncrementalSize(ewin, w, h, &w, &h);
71 Esnprintf(s, sizeof(s), "%i x %i (%i, %i)", w, h, x, y);
74 Esnprintf(s, sizeof(s), _("Focused/unfocused opacity: %d/%d %%"),
75 OpacityToPercent(ewin->props.focused_opacity),
76 OpacityToPercent(ewin->ewmh.opacity));
79 TextSize(tc, 0, 0, 0, s, &cw, &ch, 17);
80 pad = ImageclassGetPadding(ic);
81 cw += pad->left + pad->right;
82 ch += pad->top + pad->bottom;
84 /* Width hysteresis (hack - assuming horizontal text) */
86 if (eo && abs(EobjGetW(eo) - cw) < 8)
89 if (Mode.mode == MODE_MOVE)
90 md = Conf.movres.mode_move;
92 md = Conf.movres.mode_resize;
94 if ((md == 0) || ((cw < ewin->shape_w - 2) && (ch < ewin->shape_h - 2)))
96 if (Conf.movres.mode_info == 1)
103 EwinBorderGetSize(ewin, &bl, &br, &bt, &bb);
104 cx = x + (ewin->shape_w + bl + br - cw) / 2 +
105 EoGetX(EoGetDesk(ewin));
106 cy = y + (ewin->shape_h + bt + bb - ch) / 2 +
107 EoGetY(EoGetDesk(ewin));
115 eo = EobjWindowCreate(EOBJ_TYPE_MISC, 0, 0, 1, 1, 2, "Coord");
119 eo->fade = eo->shadow = 1;
121 /* Center text (override theme) */
122 TextclassSetJustification(tc, 512);
125 #define TEST_COORD_REPARENT_TO_FRAME 0
126 #if TEST_COORD_REPARENT_TO_FRAME
130 md = cw != EobjGetW(eo) || ch != EobjGetH(eo); /* md is change size flag */
131 EobjMoveResize(eo, cx, cy, cw, ch);
135 #if TEST_COORD_REPARENT_TO_FRAME
136 EobjReparent(eo, EoObj(ewin), cx, cy);
141 ITApply(EobjGetWin(eo), ic, NULL, STATE_NORMAL, 1, 0, ST_SOLID, tc, NULL, s,
144 if (md) /* Assuming that shape change only happens when size changes too */
145 EobjShapeUpdate(eo, 0);
158 #if TEST_COORD_REPARENT_TO_FRAME
159 EobjReparent(eo, EoObj(DeskGet(0)), 0, 0);
165 CoordsShow(EWin * ewin)
167 _CoordsShow(ewin, 0);
170 static Timer *timer_show_op = NULL;
173 _CoordsHideTimeout(void *data __UNUSED__)
177 timer_show_op = NULL;
182 CoordsShowOpacity(EWin * ewin)
185 ewin->state.show_coords = 1;
186 _CoordsShow(ewin, 1);
187 TIMER_DEL(timer_show_op);
188 TIMER_ADD(timer_show_op, 1., _CoordsHideTimeout, NULL);