1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

Fix various abs() issues.

The abs() function should take an int as argument, but there were
several instances in the code where it was taking an unsigned int or a
double.  In these case, we took one of the following approaches:

* If the argument was a double, use fabs() instead.
* If the argument was unsigned and was certainly going to be positive
  (i.e,. no subtraction), then drop abs() altogether.
* If the argument was unsigned as result of adding or subtracting signed
  and unsigned ints, then we cast all the unsigned ints to signed ints.
This commit is contained in:
Doug Torrance
2020-04-18 14:28:41 -04:00
committed by Carlos R. Mafra
parent dfa92906c0
commit 44bc9cc264
5 changed files with 12 additions and 11 deletions

View File

@@ -22,6 +22,7 @@
#include "WPrefs.h" #include "WPrefs.h"
#include <unistd.h> #include <unistd.h>
#include <fontconfig/fontconfig.h> #include <fontconfig/fontconfig.h>
#include <math.h>
/* workaround for older fontconfig, that doesn't define these constants */ /* workaround for older fontconfig, that doesn't define these constants */
#ifndef FC_WEIGHT_NORMAL #ifndef FC_WEIGHT_NORMAL
@@ -521,7 +522,7 @@ static void selectedOption(WMWidget * w, void *data)
WMListItem *item = WMGetListItem(panel->sizeL, i); WMListItem *item = WMGetListItem(panel->sizeL, i);
int distance; int distance;
distance = abs(size - atoi(item->text)); distance = fabs(size - atoi(item->text));
if (i == 0 || distance < closest) { if (i == 0 || distance < closest) {
closest = distance; closest = distance;

View File

@@ -1436,7 +1436,7 @@ static void getScrollAmount(WMenu * menu, int *hamount, int *vamount)
} else if (xroot >= (rect.pos.x + rect.size.width - 2) && menuX2 > (rect.pos.x + rect.size.width - 1)) { } else if (xroot >= (rect.pos.x + rect.size.width - 2) && menuX2 > (rect.pos.x + rect.size.width - 1)) {
/* scroll to the left */ /* scroll to the left */
*hamount = WMIN(MENU_SCROLL_STEP, abs(menuX2 - rect.pos.x - rect.size.width - 1)); *hamount = WMIN(MENU_SCROLL_STEP, abs(menuX2 - rect.pos.x - (int)rect.size.width - 1));
if (*hamount == 0) if (*hamount == 0)
*hamount = 1; *hamount = 1;
@@ -1450,7 +1450,7 @@ static void getScrollAmount(WMenu * menu, int *hamount, int *vamount)
} else if (yroot >= (rect.pos.y + rect.size.height - 2) && menuY2 > (rect.pos.y + rect.size.height - 1)) { } else if (yroot >= (rect.pos.y + rect.size.height - 2) && menuY2 > (rect.pos.y + rect.size.height - 1)) {
/* scroll up */ /* scroll up */
*vamount = WMIN(MENU_SCROLL_STEP, abs(menuY2 - rect.pos.y - rect.size.height - 2)); *vamount = WMIN(MENU_SCROLL_STEP, abs(menuY2 - rect.pos.y - (int)rect.size.height - 2));
*vamount = -*vamount; *vamount = -*vamount;
} }

View File

@@ -2002,8 +2002,8 @@ static int getResizeDirection(WWindow * wwin, int x, int y, int dy, int flags)
int ydir = (abs(y) < (wwin->client.height / 2)) ? UP : DOWN; int ydir = (abs(y) < (wwin->client.height / 2)) ? UP : DOWN;
/* How much resize space is allowed */ /* How much resize space is allowed */
int spacew = abs(wwin->client.width / 3); int spacew = wwin->client.width / 3;
int spaceh = abs(wwin->client.height / 3); int spaceh = wwin->client.height / 3;
/* Determine where x fits */ /* Determine where x fits */
if ((abs(x) > wwin->client.width/2 - spacew/2) && if ((abs(x) > wwin->client.width/2 - spacew/2) &&

View File

@@ -997,9 +997,9 @@ WWindow *wManageWindow(WScreen *scr, Window window)
int head; int head;
x = transientOwner->frame_x + x = transientOwner->frame_x +
abs((transientOwner->frame->core->width - width) / 2) + offs; abs(((int)transientOwner->frame->core->width - (int)width) / 2) + offs;
y = transientOwner->frame_y + y = transientOwner->frame_y +
abs((transientOwner->frame->core->height - height) / 3) + offs; abs(((int)transientOwner->frame->core->height - (int)height) / 3) + offs;
/* limit transient windows to be inside their parent's head */ /* limit transient windows to be inside their parent's head */
rect.pos.x = transientOwner->frame_x; rect.pos.x = transientOwner->frame_x;

View File

@@ -261,28 +261,28 @@ int wGetHeadRelativeToCurrentHead(WScreen *scr, int current_head, int direction)
case DIRECTION_LEFT: case DIRECTION_LEFT:
if (rect->pos.x < crect.pos.x) { if (rect->pos.x < crect.pos.x) {
found = 1; found = 1;
distance = abs((rect->pos.x + rect->size.width) distance = abs((rect->pos.x + (int)rect->size.width)
- crect.pos.x) + abs(rect->pos.y + crect.pos.y); - crect.pos.x) + abs(rect->pos.y + crect.pos.y);
} }
break; break;
case DIRECTION_RIGHT: case DIRECTION_RIGHT:
if (rect->pos.x > crect.pos.x) { if (rect->pos.x > crect.pos.x) {
found = 1; found = 1;
distance = abs((crect.pos.x + crect.size.width) distance = abs((crect.pos.x + (int)crect.size.width)
- rect->pos.x) + abs(rect->pos.y + crect.pos.y); - rect->pos.x) + abs(rect->pos.y + crect.pos.y);
} }
break; break;
case DIRECTION_UP: case DIRECTION_UP:
if (rect->pos.y < crect.pos.y) { if (rect->pos.y < crect.pos.y) {
found = 1; found = 1;
distance = abs((rect->pos.y + rect->size.height) distance = abs((rect->pos.y + (int)rect->size.height)
- crect.pos.y) + abs(rect->pos.x + crect.pos.x); - crect.pos.y) + abs(rect->pos.x + crect.pos.x);
} }
break; break;
case DIRECTION_DOWN: case DIRECTION_DOWN:
if (rect->pos.y > crect.pos.y) { if (rect->pos.y > crect.pos.y) {
found = 1; found = 1;
distance = abs((crect.pos.y + crect.size.height) distance = abs((crect.pos.y + (int)crect.size.height)
- rect->pos.y) + abs(rect->pos.x + crect.pos.x); - rect->pos.y) + abs(rect->pos.x + crect.pos.x);
} }
break; break;