Fine tune the simple icon placement technique.

iconifying is working how I want it now.
This commit is contained in:
Mike Small 2019-10-07 23:58:20 -04:00
parent 740a9e9e79
commit 0bc3929750

View File

@ -67,24 +67,32 @@ inline bool operator<(Span a, Span b)
static void static void
PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y) PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y)
{ {
// Try to place in a gap on the right side. // Try to place in a gap along the right side of (current?) screen.
Window root, parent;
Window* children;
unsigned int nchildren;
XWindowAttributes attr;
int y = 0; int y = 0;
if (XQueryTree(dpy, Scr->Root, &root, &parent, &children, &nchildren)) {
XArray<Window> childarray(children, nchildren);
vector<Span> occupied; vector<Span> occupied;
for (Window w : childarray) { for (TwmWindow* pw = Scr->TwmRoot.next; pw; pw = pw->next) {
if (XGetWindowAttributes(dpy, w, &attr)) { // Iconified means was it ever iconified.
// w looks like icon? if (pw->iconified) {
if (attr.map_state != IsUnmapped Window root;
&& attr.height <= 200 && attr.width <= 200 int icon_x, icon_y;
&& attr.x >= icon_area_x) { unsigned icon_w, icon_h, border_width, depth;
if (pw->icon_w
&& XGetGeometry(dpy, pw->icon_w, &root,
&icon_x, &icon_y, &icon_w, &icon_h,
&border_width, &depth)) {
if (icon_x >= icon_area_x)
occupied.push_back({icon_y, icon_y + static_cast<int>(icon_h)});
}
}
else {
// A small non-iconified window sitting where an icon would? E.g. xclock.
// I assume here that non-iconified windows that look like icons won't
// ever be iconified, making this an either or decision.
if (pw->frame_x >= icon_area_x
&& pw->frame_width <= 150 && pw->frame_height <= 150) {
occupied.push_back({attr.y, attr.y + attr.height}); occupied.push_back({pw->frame_y, pw->frame_y + pw->frame_height});
} }
} }
} }
@ -105,7 +113,6 @@ PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y)
} }
prev = span.p2; prev = span.p2;
} }
}
if (y) { if (y) {
*final_x = icon_area_x + 20; // TODO: stick the icon roughly in the center of the space. *final_x = icon_area_x + 20; // TODO: stick the icon roughly in the center of the space.
@ -114,7 +121,6 @@ PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y)
*final_x = def_x; *final_x = def_x;
*final_y = def_y; *final_y = def_y;
} }
return;
} }
void void