From dc914b56b21db349527a719b445a024b29052da8 Mon Sep 17 00:00:00 2001 From: Mike Small Date: Sat, 7 Nov 2020 12:45:13 -0500 Subject: [PATCH] Make PlaceIcon new position as return value. minor cleanup to avoid returning values through pointer arguments. --- src/icons.cc | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/icons.cc b/src/icons.cc index 9e9b965..74f1edb 100644 --- a/src/icons.cc +++ b/src/icons.cc @@ -45,6 +45,8 @@ in this Software without prior written authorization from The Open Group. #include using namespace std; +using Coord = pair; + const int icon_area_w = 70; const int icon_pad = 8; @@ -57,8 +59,8 @@ roundUp (int v, int multiple) return ((v + multiple - 1) / multiple) * multiple; } -static void -PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y, int *final_x, int *final_y) +static Coord +PlaceIcon(TwmWindow *tmp_win, int def_x, int def_y) { // 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) { 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; - *final_y = def_y; + icon_pos.first = icon_area_x + (offset > 0 ? offset : icon_pad); + icon_pos.second = y; } + return icon_pos; } void @@ -148,7 +146,6 @@ CreateIconWindow(TwmWindow *tmp_win, int def_x, int def_y) unsigned long valuemask; /* mask for create windows */ XSetWindowAttributes attributes; /* attributes for create windows */ Pixmap pm = None; /* tmp pixmap variable */ - int final_x, final_y; 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 * getting here means that I am going to make the icon visible */ + Coord icon_pos; if (tmp_win->wmhints && tmp_win->wmhints->flags & IconPositionHint) { - final_x = tmp_win->wmhints->icon_x; - final_y = tmp_win->wmhints->icon_y; + icon_pos = {tmp_win->wmhints->icon_x, tmp_win->wmhints->icon_y}; } 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) - final_y = Scr->MyDisplayHeight - tmp_win->icon_height - - Scr->IconFont.height - 4 - BW2; + if (icon_pos.second > Scr->MyDisplayHeight) + icon_pos.second = Scr->MyDisplayHeight - tmp_win->icon_height + - 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; XMapSubwindows(dpy, tmp_win->icon_w); XSaveContext(dpy, tmp_win->icon_w, TwmContext, (caddr_t)tmp_win); XSaveContext(dpy, tmp_win->icon_w, ScreenContext, (caddr_t)Scr); XDefineCursor(dpy, tmp_win->icon_w, Scr->IconCursor); - if (pm) XFreePixmap (dpy, pm); - return; + if (pm) + XFreePixmap(dpy, pm); }