Make PlaceIcon new position as return value.

minor cleanup to avoid returning values through pointer arguments.
This commit is contained in:
Mike Small 2020-11-07 12:45:13 -05:00
parent b3028310eb
commit dc914b56b2
1 changed files with 20 additions and 22 deletions

View File

@ -45,6 +45,8 @@ in this Software without prior written authorization from The Open Group.
#include <iostream> #include <iostream>
using namespace std; using namespace std;
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 = 8;
@ -57,8 +59,8 @@ roundUp (int v, int multiple)
return ((v + multiple - 1) / multiple) * multiple; return ((v + multiple - 1) / multiple) * multiple;
} }
static void static Coord
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)
{ {
// 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 the current screen.
@ -117,18 +119,14 @@ PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y)
} }
} }
Coord icon_pos { def_x, def_y };
if (y) { if (y) {
const int w = tmp_win->icon_w_width ? tmp_win->icon_w_width : 64; const int w = tmp_win->icon_w_width ? tmp_win->icon_w_width : 64;
const int offset = (icon_area_w - w) / 2; const int offset = (icon_area_w - w) / 2;
if (offset > 0) { icon_pos.first = icon_area_x + (offset > 0 ? offset : icon_pad);
*final_x = icon_area_x + offset; icon_pos.second = y;
} else
*final_x = icon_area_x + icon_pad;
*final_y = y;
} else {
*final_x = def_x;
*final_y = def_y;
} }
return icon_pos;
} }
void void
@ -148,7 +146,6 @@ CreateIconWindow(TwmWindow *tmp_win, int def_x, int def_y)
unsigned long valuemask; /* mask for create windows */ unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */ XSetWindowAttributes attributes; /* attributes for create windows */
Pixmap pm = None; /* tmp pixmap variable */ Pixmap pm = None; /* tmp pixmap variable */
int final_x, final_y;
int x; int x;
@ -360,31 +357,32 @@ CreateIconWindow(TwmWindow *tmp_win, int def_x, int def_y)
/* I need to figure out where to put the icon window now, because /* I need to figure out where to put the icon window now, because
* getting here means that I am going to make the icon visible * getting here means that I am going to make the icon visible
*/ */
Coord icon_pos;
if (tmp_win->wmhints && if (tmp_win->wmhints &&
tmp_win->wmhints->flags & IconPositionHint) tmp_win->wmhints->flags & IconPositionHint)
{ {
final_x = tmp_win->wmhints->icon_x; icon_pos = {tmp_win->wmhints->icon_x, tmp_win->wmhints->icon_y};
final_y = tmp_win->wmhints->icon_y;
} }
else else
{ {
PlaceIcon(tmp_win, def_x, def_y, &final_x, &final_y); icon_pos = PlaceIcon(tmp_win, def_x, def_y, &final_x, &final_y);
} }
if (final_x > Scr->MyDisplayWidth)
final_x = Scr->MyDisplayWidth - tmp_win->icon_w_width - BW2; if (icon_pos.first > Scr->MyDisplayWidth)
icon_pos.first = Scr->MyDisplayWidth - tmp_win->icon_w_width - BW2;
if (final_y > Scr->MyDisplayHeight) if (icon_pos.second > Scr->MyDisplayHeight)
final_y = Scr->MyDisplayHeight - tmp_win->icon_height - icon_pos.second = Scr->MyDisplayHeight - tmp_win->icon_height
Scr->IconFont.height - 4 - BW2; - Scr->IconFont.height - 4 - BW2;
XMoveWindow(dpy, tmp_win->icon_w, final_x, final_y); XMoveWindow(dpy, tmp_win->icon_w, icon_pos.first, icon_pos.second);
tmp_win->iconified = TRUE; tmp_win->iconified = TRUE;
XMapSubwindows(dpy, tmp_win->icon_w); XMapSubwindows(dpy, tmp_win->icon_w);
XSaveContext(dpy, tmp_win->icon_w, TwmContext, (caddr_t)tmp_win); XSaveContext(dpy, tmp_win->icon_w, TwmContext, (caddr_t)tmp_win);
XSaveContext(dpy, tmp_win->icon_w, ScreenContext, (caddr_t)Scr); XSaveContext(dpy, tmp_win->icon_w, ScreenContext, (caddr_t)Scr);
XDefineCursor(dpy, tmp_win->icon_w, Scr->IconCursor); XDefineCursor(dpy, tmp_win->icon_w, Scr->IconCursor);
if (pm) XFreePixmap (dpy, pm); if (pm)
return; XFreePixmap(dpy, pm);
} }