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.
|
* 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>
|
#include <algorithm>
|
||||||
@ -41,14 +41,12 @@ in this Software without prior written authorization from The Open Group.
|
|||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
using Coord = pair<int, int>;
|
using Coord = pair<int, int>;
|
||||||
|
|
||||||
const int icon_area_w = 70;
|
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 iconWidth(w) (BW2 + w->icon_w_width)
|
||||||
#define iconHeight(w) (BW2 + w->icon_w_height)
|
#define iconHeight(w) (BW2 + w->icon_w_height)
|
||||||
@ -62,19 +60,19 @@ roundUp (int v, int multiple)
|
|||||||
static Coord
|
static Coord
|
||||||
PlaceIcon(const TwmWindow& win, int def_x, int def_y)
|
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.
|
// 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>;
|
using Span = pair<int,int>;
|
||||||
vector<Span> occupied;
|
vector<Span> occupied;
|
||||||
cerr << "win: " << 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 it was iconified at some point.
|
// Iconified means it was iconified at some point.
|
||||||
if (pw->iconified) {
|
if (pw->iconified) {
|
||||||
cerr << "pw, iconfified: " << pw->name << '\n';
|
|
||||||
Window root;
|
Window root;
|
||||||
int icon_x, icon_y;
|
int icon_x, icon_y;
|
||||||
unsigned icon_w, icon_h, border_width, depth;
|
unsigned icon_w, icon_h, border_width, depth;
|
||||||
@ -87,8 +85,6 @@ PlaceIcon(const TwmWindow& win, int def_x, int def_y)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
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.
|
||||||
// non-iconified windows that look like icons are assumed never to have
|
// non-iconified windows that look like icons are assumed never to have
|
||||||
// been iconified.
|
// 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) {
|
sort(occupied.begin(), occupied.end());
|
||||||
y = Scr->MyDisplayHeight - h;
|
// 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.
|
||||||
else {
|
occupied.push_back({Scr->MyDisplayHeight + icon_pad,
|
||||||
sort(occupied.begin(), occupied.end());
|
Scr->MyDisplayHeight + 2 * icon_pad});
|
||||||
int prev = 0;
|
|
||||||
for (auto span : occupied) {
|
int y {0}, prev {0};
|
||||||
if (span.first - prev >= h) {
|
for (const auto span : occupied) {
|
||||||
if (span.first - prev >= h + 2*icon_pad)
|
const int gap = span.first - prev;
|
||||||
y = prev + icon_pad;
|
if (gap >= height + icon_pad) {
|
||||||
else
|
y = prev + icon_pad;
|
||||||
y = prev;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
prev = span.second;
|
|
||||||
}
|
}
|
||||||
|
else if (gap >= height) {
|
||||||
|
y = min(prev, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev = span.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Coord icon_pos { def_x, def_y };
|
Coord icon_pos { def_x, def_y };
|
||||||
if (y) {
|
if (y != 0) {
|
||||||
const int w = win.icon_w_width ? win.icon_w_width : 64;
|
const int w {win.icon_w_width ? win.icon_w_width : 64};
|
||||||
const int offset = (icon_area_w - w) / 2;
|
const int offset { (icon_area_w - w) / 2 };
|
||||||
icon_pos.first = icon_area_x + (offset > 0 ? offset : icon_pad);
|
icon_pos.first = icon_area_x + (offset > 0 ? offset : icon_pad);
|
||||||
icon_pos.second = y;
|
icon_pos.second = y;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user