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,45 +67,52 @@ 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)) { vector<Span> occupied;
XArray<Window> childarray(children, nchildren); for (TwmWindow* pw = Scr->TwmRoot.next; pw; pw = pw->next) {
vector<Span> occupied; // Iconified means was it ever iconified.
for (Window w : childarray) { if (pw->iconified) {
if (XGetWindowAttributes(dpy, w, &attr)) { Window root;
// w looks like icon? int icon_x, icon_y;
if (attr.map_state != IsUnmapped unsigned icon_w, icon_h, border_width, depth;
&& attr.height <= 200 && attr.width <= 200 if (pw->icon_w
&& attr.x >= icon_area_x) { && XGetGeometry(dpy, pw->icon_w, &root,
&icon_x, &icon_y, &icon_w, &icon_h,
occupied.push_back({attr.y, attr.y + attr.height}); &border_width, &depth)) {
} if (icon_x >= icon_area_x)
occupied.push_back({icon_y, icon_y + static_cast<int>(icon_h)});
} }
} }
int h = 64; else {
if (tmp_win->icon_height) { // A small non-iconified window sitting where an icon would? E.g. xclock.
h = tmp_win->icon_height; // 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) {
sort(occupied.begin(), occupied.end()); occupied.push_back({pw->frame_y, pw->frame_y + pw->frame_height});
int prev = 0;
for (auto span : occupied) {
if (span.p1 - prev >= h) {
if (span.p1 - prev >= h + 2*icon_pad)
y = prev + icon_pad;
else
y = prev;
break;
} }
prev = span.p2;
} }
} }
int h = 64;
if (tmp_win->icon_height) {
h = tmp_win->icon_height;
}
sort(occupied.begin(), occupied.end());
int prev = 0;
for (auto span : occupied) {
if (span.p1 - prev >= h) {
if (span.p1 - prev >= h + 2*icon_pad)
y = prev + icon_pad;
else
y = prev;
break;
}
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