diff --git a/ChangeLog b/ChangeLog index 8306079..034d16f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2019-10-12 Mike Small + + * src/icons.cc (PlaceIcon): stop hard coding the minimum x for + icon placement and the placement within that space. I've been + negligent with changelog entries. This change goes with a + simplification to icon placement and conversion of icons.c to C++. + 2019-09-28 Mike Small * remove more vestiges of the icon manager diff --git a/src/icons.cc b/src/icons.cc index 6c8aa9d..d3f5925 100644 --- a/src/icons.cc +++ b/src/icons.cc @@ -43,9 +43,8 @@ in this Software without prior written authorization from The Open Group. using namespace std; -// TODO: initialize at runtime. Per screen unless you simplify to only one screen allowed. -const int icon_area_x = 1600; // big enough area for my xclock to look like an icon, not be stacked on. -const int icon_pad = 10; +const int icon_area_w = 70; +const int icon_pad = 8; #define iconWidth(w) (BW2 + w->icon_w_width) #define iconHeight(w) (BW2 + w->icon_w_height) @@ -67,6 +66,12 @@ 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) { + // 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 (current?) screen. int y = 0; @@ -96,10 +101,7 @@ PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y) } } } - int h = 64; - if (tmp_win->icon_height) { - h = tmp_win->icon_height; - } + const int h = tmp_win->icon_w_height ? tmp_win->icon_w_height : 64; sort(occupied.begin(), occupied.end()); int prev = 0; @@ -115,7 +117,12 @@ PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y) } if (y) { - *final_x = icon_area_x + 20; // TODO: stick the icon roughly in the center of the space. + const int w = tmp_win->icon_w_width ? tmp_win->icon_w_width : 64; + const int offset = (icon_area_w - w) / 2; + if (offset > 0) { + *final_x = icon_area_x + offset; + } else + *final_x = icon_area_x + icon_pad; *final_y = y; } else { *final_x = def_x;