adjustments to icon placement
- the biggest part of this is fixing a bug that prevented the last empty space in the icon area to be used. - also prefer new C++ style variable initialization.
This commit is contained in:
parent
d98d0940c0
commit
09842b93dc
59
src/icons.cc
59
src/icons.cc
@ -29,7 +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.
|
||||
* 07-Nov-20 Mike Small Switch to C++, simplify placement.
|
||||
**********************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
@ -41,14 +41,12 @@ in this Software without prior written authorization from The Open Group.
|
||||
#include "parse.h"
|
||||
#include "util.h"
|
||||
|
||||
// DEBUG
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
using Coord = pair<int, int>;
|
||||
|
||||
const int icon_area_w = 70;
|
||||
const int icon_pad = 8;
|
||||
const int icon_pad = 2;
|
||||
|
||||
#define iconWidth(w) (BW2 + w->icon_w_width)
|
||||
#define iconHeight(w) (BW2 + w->icon_w_height)
|
||||
@ -62,19 +60,19 @@ roundUp (int v, int multiple)
|
||||
static Coord
|
||||
PlaceIcon(const TwmWindow& win, int def_x, int def_y)
|
||||
{
|
||||
// Try to place in a gap along the right side of the current screen.
|
||||
|
||||
// icons are dropped to the right of this x offset.
|
||||
const int icon_area_x = Scr->MyDisplayWidth - icon_area_w;
|
||||
const int icon_area_x {Scr->MyDisplayWidth - icon_area_w};
|
||||
const int height {win.icon_w_height ? win.icon_w_height : 64};
|
||||
|
||||
// always place xconsole's icon on the lower right.
|
||||
if (strcmp(win.name, "xconsole") == 0)
|
||||
return {icon_area_x + icon_pad, Scr->MyDisplayHeight - height};
|
||||
|
||||
int y = 0;
|
||||
using Span = pair<int,int>;
|
||||
vector<Span> occupied;
|
||||
cerr << "win: " << win.name << '\n';
|
||||
for (TwmWindow* pw = Scr->TwmRoot.next; pw; pw = pw->next) {
|
||||
// Iconified means it was iconified at some point.
|
||||
if (pw->iconified) {
|
||||
cerr << "pw, iconfified: " << pw->name << '\n';
|
||||
Window root;
|
||||
int icon_x, icon_y;
|
||||
unsigned icon_w, icon_h, border_width, depth;
|
||||
@ -87,8 +85,6 @@ PlaceIcon(const TwmWindow& win, int def_x, int def_y)
|
||||
}
|
||||
}
|
||||
else {
|
||||
cerr << "pw, non-iconfified: " << pw->name << '\n';
|
||||
|
||||
// A small non-iconified window sitting where an icon would? E.g. xclock.
|
||||
// non-iconified windows that look like icons are assumed never to have
|
||||
// been iconified.
|
||||
@ -99,30 +95,31 @@ PlaceIcon(const TwmWindow& win, int def_x, int def_y)
|
||||
}
|
||||
}
|
||||
}
|
||||
const int h = win.icon_w_height ? win.icon_w_height : 64;
|
||||
|
||||
if (occupied.size() == 0) {
|
||||
y = Scr->MyDisplayHeight - h;
|
||||
}
|
||||
else {
|
||||
sort(occupied.begin(), occupied.end());
|
||||
int prev = 0;
|
||||
for (auto span : occupied) {
|
||||
if (span.first - prev >= h) {
|
||||
if (span.first - prev >= h + 2*icon_pad)
|
||||
y = prev + icon_pad;
|
||||
else
|
||||
y = prev;
|
||||
break;
|
||||
}
|
||||
prev = span.second;
|
||||
sort(occupied.begin(), occupied.end());
|
||||
// The loop below looks for a gap in the icon area. Add a sentinel to represent
|
||||
// the end of the open area, if any, after all icons.
|
||||
occupied.push_back({Scr->MyDisplayHeight + icon_pad,
|
||||
Scr->MyDisplayHeight + 2 * icon_pad});
|
||||
|
||||
int y {0}, prev {0};
|
||||
for (const auto span : occupied) {
|
||||
const int gap = span.first - prev;
|
||||
if (gap >= height + icon_pad) {
|
||||
y = prev + icon_pad;
|
||||
break;
|
||||
}
|
||||
else if (gap >= height) {
|
||||
y = min(prev, 1);
|
||||
break;
|
||||
}
|
||||
prev = span.second;
|
||||
}
|
||||
|
||||
Coord icon_pos { def_x, def_y };
|
||||
if (y) {
|
||||
const int w = win.icon_w_width ? win.icon_w_width : 64;
|
||||
const int offset = (icon_area_w - w) / 2;
|
||||
if (y != 0) {
|
||||
const int w {win.icon_w_width ? win.icon_w_width : 64};
|
||||
const int offset { (icon_area_w - w) / 2 };
|
||||
icon_pos.first = icon_area_x + (offset > 0 ? offset : icon_pad);
|
||||
icon_pos.second = y;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user