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:
parent
dc91096aa1
commit
b3028310eb
31
src/icons.cc
31
src/icons.cc
|
@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
|
||||||
*
|
*
|
||||||
* 10-Apr-89 Tom LaStrange Initial Version.
|
* 10-Apr-89 Tom LaStrange Initial Version.
|
||||||
*
|
*
|
||||||
|
* 31-Oct-20 Mike Small Switch to C++, simplify placement.
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -56,30 +57,20 @@ roundUp (int v, int multiple)
|
||||||
return ((v + multiple - 1) / multiple) * 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
|
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)
|
||||||
{
|
{
|
||||||
// TODO: one value initialized once wouldn't cut it for multiscreen.
|
// Try to place in a gap along the right side of the current screen.
|
||||||
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 (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;
|
int y = 0;
|
||||||
|
using Span = pair<int,int>;
|
||||||
vector<Span> occupied;
|
vector<Span> occupied;
|
||||||
cerr << "tmp_win: " << tmp_win->name << '\n';
|
cerr << "tmp_win: " << tmp_win->name << '\n';
|
||||||
for (TwmWindow* pw = Scr->TwmRoot.next; pw; pw = pw->next) {
|
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) {
|
if (pw->iconified) {
|
||||||
cerr << "pw, iconfified: " << pw->name << '\n';
|
cerr << "pw, iconfified: " << pw->name << '\n';
|
||||||
Window root;
|
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';
|
cerr << "pw, non-iconfified: " << pw->name << '\n';
|
||||||
|
|
||||||
// A small non-iconified window sitting where an icon would? E.g. xclock.
|
// 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
|
// non-iconified windows that look like icons are assumed never to have
|
||||||
// ever be iconified, making this an either or decision.
|
// been iconified.
|
||||||
if (pw->frame_x >= icon_area_x
|
if (pw->frame_x >= icon_area_x
|
||||||
&& pw->frame_width <= 150 && pw->frame_height <= 150) {
|
&& 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());
|
sort(occupied.begin(), occupied.end());
|
||||||
int prev = 0;
|
int prev = 0;
|
||||||
for (auto span : occupied) {
|
for (auto span : occupied) {
|
||||||
if (span.p1 - prev >= h) {
|
if (span.first - prev >= h) {
|
||||||
if (span.p1 - prev >= h + 2*icon_pad)
|
if (span.first - prev >= h + 2*icon_pad)
|
||||||
y = prev + icon_pad;
|
y = prev + icon_pad;
|
||||||
else
|
else
|
||||||
y = prev;
|
y = prev;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prev = span.p2;
|
prev = span.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user