icons.cc minor cleanup

- use std::pair instead of own struct
- initialize icon_area_x each time instead of caching the value.
- comment tidying
This commit is contained in:
Mike Small 2020-10-17 20:49:04 -04:00
parent dc91096aa1
commit b3028310eb
1 changed files with 11 additions and 20 deletions

View File

@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
*
* 10-Apr-89 Tom LaStrange Initial Version.
*
* 31-Oct-20 Mike Small Switch to C++, simplify placement.
**********************************************************************/
#include <algorithm>
@ -56,30 +57,20 @@ roundUp (int v, int multiple)
return ((v + multiple - 1) / multiple) * multiple;
}
struct Span {
int p1, p2;
};
inline bool operator<(Span a, Span b)
{
return a.p1 == b.p1 && a.p2 < b.p2 || a.p1 < b.p1;
}
static void
PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y)
{
// TODO: one value initialized once wouldn't cut it for multiscreen.
static int icon_area_x = 0; // icons are dropped to the right of this x.
if (icon_area_x == 0) {
icon_area_x = Scr->MyDisplayWidth - icon_area_w;
}
// Try to place in a gap along the right side of the current screen.
// Try to place in a gap along the right side of (current?) screen.
// icons are dropped to the right of this x offset.
const int icon_area_x = Scr->MyDisplayWidth - icon_area_w;
int y = 0;
using Span = pair<int,int>;
vector<Span> occupied;
cerr << "tmp_win: " << tmp_win->name << '\n';
for (TwmWindow* pw = Scr->TwmRoot.next; pw; pw = pw->next) {
// Iconified means was it ever iconified.
// Iconified means it was iconified at some point.
if (pw->iconified) {
cerr << "pw, iconfified: " << pw->name << '\n';
Window root;
@ -97,8 +88,8 @@ PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y)
cerr << "pw, non-iconfified: " << pw->name << '\n';
// 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.
// non-iconified windows that look like icons are assumed never to have
// been iconified.
if (pw->frame_x >= icon_area_x
&& pw->frame_width <= 150 && pw->frame_height <= 150) {
@ -115,14 +106,14 @@ PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y)
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)
if (span.first - prev >= h) {
if (span.first - prev >= h + 2*icon_pad)
y = prev + icon_pad;
else
y = prev;
break;
}
prev = span.p2;
prev = span.second;
}
}