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
1 changed files with 38 additions and 32 deletions

View File

@ -67,45 +67,52 @@ inline bool operator<(Span a, Span b)
static void
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;
if (XQueryTree(dpy, Scr->Root, &root, &parent, &children, &nchildren)) {
XArray<Window> childarray(children, nchildren);
vector<Span> occupied;
for (Window w : childarray) {
if (XGetWindowAttributes(dpy, w, &attr)) {
// w looks like icon?
if (attr.map_state != IsUnmapped
&& attr.height <= 200 && attr.width <= 200
&& attr.x >= icon_area_x) {
occupied.push_back({attr.y, attr.y + attr.height});
}
vector<Span> occupied;
for (TwmWindow* pw = Scr->TwmRoot.next; pw; pw = pw->next) {
// Iconified means was it ever iconified.
if (pw->iconified) {
Window root;
int icon_x, icon_y;
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)});
}
}
int h = 64;
if (tmp_win->icon_height) {
h = tmp_win->icon_height;
}
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) {
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;
occupied.push_back({pw->frame_y, pw->frame_y + pw->frame_height});
}
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) {
*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_y = def_y;
}
return;
}
void