summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c236
1 files changed, 123 insertions, 113 deletions
diff --git a/src/util.c b/src/util.c
index 38ca66a..e53c606 100644
--- a/src/util.c
+++ b/src/util.c
@@ -123,59 +123,59 @@ void MoveOutline(Window root, int x, int y, int width, int height, int bw, int t
xthird = (xinnerr - xinnerl) / 3; \
ythird = (yinnerb - yinnert) / 3; \
\
- r->x1 = xl; \
- r->y1 = yt; \
- r->x2 = xr; \
- r->y2 = yt; \
+ r->x1 = (short)(xl); \
+ r->y1 = (short)(yt); \
+ r->x2 = (short)(xr); \
+ r->y2 = (short)(yt); \
r++; \
\
- r->x1 = xl; \
- r->y1 = yb; \
- r->x2 = xr; \
- r->y2 = yb; \
+ r->x1 = (short)(xl); \
+ r->y1 = (short)(yb); \
+ r->x2 = (short)(xr); \
+ r->y2 = (short)(yb); \
r++; \
\
- r->x1 = xl; \
- r->y1 = yt; \
- r->x2 = xl; \
- r->y2 = yb; \
+ r->x1 = (short)(xl); \
+ r->y1 = (short)(yt); \
+ r->x2 = (short)(xl); \
+ r->y2 = (short)(yb); \
r++; \
\
- r->x1 = xr; \
- r->y1 = yt; \
- r->x2 = xr; \
- r->y2 = yb; \
+ r->x1 = (short)(xr); \
+ r->y1 = (short)(yt); \
+ r->x2 = (short)(xr); \
+ r->y2 = (short)(yb); \
r++; \
\
- r->x1 = xinnerl + xthird; \
- r->y1 = yinnert; \
- r->x2 = r->x1; \
- r->y2 = yinnerb; \
+ r->x1 = (short)(xinnerl + xthird); \
+ r->y1 = (short)(yinnert); \
+ r->x2 = (short)(r->x1); \
+ r->y2 = (short)(yinnerb); \
r++; \
\
- r->x1 = xinnerl + (2 * xthird); \
- r->y1 = yinnert; \
- r->x2 = r->x1; \
- r->y2 = yinnerb; \
+ r->x1 = (short)(xinnerl + (2 * xthird)); \
+ r->y1 = (short)(yinnert); \
+ r->x2 = (short)(r->x1); \
+ r->y2 = (short)(yinnerb); \
r++; \
\
- r->x1 = xinnerl; \
- r->y1 = yinnert + ythird; \
- r->x2 = xinnerr; \
- r->y2 = r->y1; \
+ r->x1 = (short)(xinnerl); \
+ r->y1 = (short)(yinnert + ythird); \
+ r->x2 = (short)(xinnerr); \
+ r->y2 = (short)(r->y1); \
r++; \
\
- r->x1 = xinnerl; \
- r->y1 = yinnert + (2 * ythird); \
- r->x2 = xinnerr; \
- r->y2 = r->y1; \
+ r->x1 = (short)(xinnerl); \
+ r->y1 = (short)(yinnert + (2 * ythird)); \
+ r->x2 = (short)(xinnerr); \
+ r->y2 = (short)(r->y1); \
r++; \
\
if (lastTH != 0) { \
- r->x1 = xl; \
- r->y1 = yt + lastTH; \
- r->x2 = xr; \
- r->y2 = r->y1; \
+ r->x1 = (short)(xl); \
+ r->y1 = (short)(yt + lastTH); \
+ r->x2 = (short)(xr); \
+ r->y2 = (short)(r->y1); \
r++; \
} \
}
@@ -198,7 +198,7 @@ void MoveOutline(Window root, int x, int y, int width, int height, int bw, int t
if (r != outline)
{
- XDrawSegments(dpy, root, Scr->DrawGC, outline, r - outline);
+ XDrawSegments(dpy, root, Scr->DrawGC, outline, (int)(r - outline));
}
}
@@ -259,17 +259,17 @@ char *
ExpandFilename(const char *name)
{
char *newname;
+ int retval;
if (name[0] != '~') return strdup(name);
- asprintf(&newname, "%s/%s", Home, &name[1]);
- if (!newname) {
+ retval = asprintf(&newname, "%s/%s", Home, &name[1]);
+ if (retval == -1 || !newname) {
fprintf (stderr,
"%s: unable to allocate %ld bytes to expand filename %s/%s\n",
- ProgramName, HomeLen + (unsigned long)strlen(name) + 2,
+ ProgramName, (unsigned long)HomeLen + (unsigned long)strlen(name) + 2,
Home, &name[1]);
}
-
return newname;
}
@@ -325,7 +325,7 @@ FindBitmap (const char *name, unsigned *widthp, unsigned *heightp)
{ TBPM_QUESTION, CreateQuestionPixmap },
};
- for (i = 0; i < (sizeof pmtab)/(sizeof pmtab[0]); i++) {
+ for (i = 0; (size_t)i < (sizeof pmtab)/(sizeof pmtab[0]); i++) {
if (XmuCompareISOLatin1 (pmtab[i].name, name) == 0)
return (*pmtab[i].proc) (widthp, heightp);
}
@@ -520,13 +520,13 @@ GetColor(int kind, Pixel *what, const char *name)
if (stdcmap) {
color.pixel = (stdcmap->base_pixel +
((Pixel)(((float)color.red / 65535.0) *
- stdcmap->red_max + 0.5) *
+ (double)stdcmap->red_max + 0.5) *
stdcmap->red_mult) +
((Pixel)(((float)color.green /65535.0) *
- stdcmap->green_max + 0.5) *
+ (double)stdcmap->green_max + 0.5) *
stdcmap->green_mult) +
((Pixel)(((float)color.blue / 65535.0) *
- stdcmap->blue_max + 0.5) *
+ (double)stdcmap->blue_max + 0.5) *
stdcmap->blue_mult));
} else {
fprintf (stderr, "%s: unable to allocate color \"%s\"\n",
@@ -563,20 +563,9 @@ GetColorValue(int kind, XColor *what, const char *name)
}
}
-/*
- * The following functions are sensible to 'use_fontset'.
- * When 'use_fontset' is True,
- * - XFontSet-related internationalized functions are used
- * so as multibyte languages can be displayed.
- * When 'use_fontset' is False,
- * - XFontStruct-related conventional functions are used
- * so as 8-bit characters can be displayed even when
- * locale is not set properly.
- */
-void
-GetFont(MyFont *font)
+static Boolean
+FindFontSet(MyFont *font, const char *fontname)
{
- const char *deffontname = "fixed";
char **missing_charset_list_return;
int missing_charset_count_return;
char *def_string_return;
@@ -593,13 +582,11 @@ GetFont(MyFont *font)
XFreeFontSet(dpy, font->fontset);
}
- if( (font->fontset = XCreateFontSet(dpy, font->name,
+ if( (font->fontset = XCreateFontSet(dpy, fontname,
&missing_charset_list_return,
&missing_charset_count_return,
&def_string_return)) == NULL) {
- fprintf (stderr, "%s: unable to open fontset \"%s\"\n",
- ProgramName, font->name);
- exit(1);
+ return False;
}
for(i=0; i<missing_charset_count_return; i++){
printf("%s: warning: font for charset %s is lacking.\n",
@@ -617,29 +604,52 @@ GetFont(MyFont *font)
font->y = ascent;
font->ascent = ascent;
font->descent = descent;
- return;
+ return True;
}
if (font->font != NULL)
XFreeFont(dpy, font->font);
- if ((font->font = XLoadQueryFont(dpy, font->name)) == NULL)
+ if ((font->font = XLoadQueryFont(dpy, fontname)) == NULL)
{
- if (Scr->DefaultFont.name) {
- deffontname = Scr->DefaultFont.name;
- }
- if ((font->font = XLoadQueryFont(dpy, deffontname)) == NULL)
- {
- fprintf (stderr, "%s: unable to open fonts \"%s\" or \"%s\"\n",
- ProgramName, font->name, deffontname);
- exit(1);
- }
-
+ return False;
}
font->height = font->font->ascent + font->font->descent;
font->y = font->font->ascent;
font->ascent = font->font->ascent;
font->descent = font->font->descent;
+ return True;
+}
+
+/*
+ * The following functions are sensible to 'use_fontset'.
+ * When 'use_fontset' is True,
+ * - XFontSet-related internationalized functions are used
+ * so as multibyte languages can be displayed.
+ * When 'use_fontset' is False,
+ * - XFontStruct-related conventional functions are used
+ * so as 8-bit characters can be displayed even when
+ * locale is not set properly.
+ */
+void
+GetFont(MyFont *font)
+{
+ const char *deffontname = "fixed";
+
+ if (!FindFontSet(font, font->name)) {
+ const char *what = "fonts";
+
+ if (use_fontset) {
+ what = "fontsets";
+ } else if (Scr->DefaultFont.name) {
+ deffontname = Scr->DefaultFont.name;
+ }
+ if (!FindFontSet(font, deffontname)) {
+ fprintf (stderr, "%s: unable to open %s \"%s\" or \"%s\"\n",
+ ProgramName, what, font->name, deffontname);
+ exit(1);
+ }
+ }
}
int
@@ -657,25 +667,25 @@ MyFont_TextWidth(MyFont *font, const char *string, int len)
}
void
-MyFont_DrawImageString(Display *dpy, Drawable d, MyFont *font, GC gc,
+MyFont_DrawImageString(Display *dpy2, Drawable d, MyFont *font, GC gc,
int x, int y, const char *string, int len)
{
if (use_fontset) {
- XmbDrawImageString(dpy, d, font->fontset, gc, x, y, string, len);
+ XmbDrawImageString(dpy2, d, font->fontset, gc, x, y, string, len);
return;
}
- XDrawImageString (dpy, d, gc, x, y, string, len);
+ XDrawImageString (dpy2, d, gc, x, y, string, len);
}
void
-MyFont_DrawString(Display *dpy, Drawable d, MyFont *font, GC gc,
+MyFont_DrawString(Display *dpy2, Drawable d, MyFont *font, GC gc,
int x, int y, const char *string, int len)
{
if (use_fontset) {
- XmbDrawString(dpy, d, font->fontset, gc, x, y, string, len);
+ XmbDrawString(dpy2, d, font->fontset, gc, x, y, string, len);
return;
}
- XDrawString (dpy, d, gc, x, y, string, len);
+ XDrawString (dpy2, d, gc, x, y, string, len);
}
void
@@ -701,19 +711,19 @@ MyFont_ChangeGC(unsigned long fix_fore, unsigned long fix_back,
* not XFree().
*/
Status
-I18N_FetchName(Display *dpy, Window w, char **winname)
+I18N_FetchName(Display *dpy2, Window w, char **winname)
{
int status;
XTextProperty text_prop;
char **list;
int num;
- status = XGetWMName(dpy, w, &text_prop);
+ status = XGetWMName(dpy2, w, &text_prop);
if (!status || !text_prop.value || !text_prop.nitems) {
*winname = NULL;
return 0;
}
- status = XmbTextPropertyToTextList(dpy, &text_prop, &list, &num);
+ status = XmbTextPropertyToTextList(dpy2, &text_prop, &list, &num);
if (status < Success || !num || !*list) {
*winname = NULL;
return 0;
@@ -725,16 +735,16 @@ I18N_FetchName(Display *dpy, Window w, char **winname)
}
Status
-I18N_GetIconName(Display *dpy, Window w, char **iconname)
+I18N_GetIconName(Display *dpy2, Window w, char **iconname)
{
int status;
XTextProperty text_prop;
char **list;
int num;
- status = XGetWMIconName(dpy, w, &text_prop);
+ status = XGetWMIconName(dpy2, w, &text_prop);
if (!status || !text_prop.value || !text_prop.nitems) return 0;
- status = XmbTextPropertyToTextList(dpy, &text_prop, &list, &num);
+ status = XmbTextPropertyToTextList(dpy2, &text_prop, &list, &num);
if (status < Success || !num || !*list) return 0;
XFree(text_prop.value);
*iconname = (char *)strdup(*list);
@@ -773,10 +783,10 @@ CreateXLogoPixmap (unsigned *widthp, unsigned *heightp)
if (Scr->tbpm.xlogo == None) {
GC gc, gcBack;
- Scr->tbpm.xlogo = XCreatePixmap (dpy, Scr->Root, h, h, 1);
+ Scr->tbpm.xlogo = XCreatePixmap (dpy, Scr->Root, (unsigned)h, (unsigned)h, 1);
gc = XCreateGC (dpy, Scr->tbpm.xlogo, 0L, NULL);
XSetForeground (dpy, gc, 0);
- XFillRectangle (dpy, Scr->tbpm.xlogo, gc, 0, 0, h, h);
+ XFillRectangle (dpy, Scr->tbpm.xlogo, gc, 0, 0, (unsigned)h, (unsigned)h);
XSetForeground (dpy, gc, 1);
gcBack = XCreateGC (dpy, Scr->tbpm.xlogo, 0L, NULL);
XSetForeground (dpy, gcBack, 0);
@@ -785,8 +795,8 @@ CreateXLogoPixmap (unsigned *widthp, unsigned *heightp)
* draw the logo large so that it gets as dense as possible; then white
* out the edges so that they look crisp
*/
- XmuDrawLogo (dpy, Scr->tbpm.xlogo, gc, gcBack, -1, -1, h + 2, h + 2);
- XDrawRectangle (dpy, Scr->tbpm.xlogo, gcBack, 0, 0, h - 1, h - 1);
+ XmuDrawLogo (dpy, Scr->tbpm.xlogo, gc, gcBack, -1, -1, (unsigned)(h + 2), (unsigned)(h + 2));
+ XDrawRectangle (dpy, Scr->tbpm.xlogo, gcBack, 0, 0, (unsigned)(h - 1), (unsigned)(h - 1));
/*
* done drawing
@@ -814,34 +824,34 @@ CreateResizePixmap (unsigned *widthp, unsigned *heightp)
/*
* create the pixmap
*/
- Scr->tbpm.resize = XCreatePixmap (dpy, Scr->Root, h, h, 1);
+ Scr->tbpm.resize = XCreatePixmap (dpy, Scr->Root, (unsigned)h, (unsigned)h, 1);
gc = XCreateGC (dpy, Scr->tbpm.resize, 0L, NULL);
XSetForeground (dpy, gc, 0);
- XFillRectangle (dpy, Scr->tbpm.resize, gc, 0, 0, h, h);
+ XFillRectangle (dpy, Scr->tbpm.resize, gc, 0, 0, (unsigned)h, (unsigned)h);
XSetForeground (dpy, gc, 1);
lw = h / 16;
if (lw == 1)
lw = 0;
- XSetLineAttributes (dpy, gc, lw, LineSolid, CapButt, JoinMiter);
+ XSetLineAttributes (dpy, gc, (unsigned)lw, LineSolid, CapButt, JoinMiter);
/*
* draw the resize button,
*/
w = (h * 2) / 3;
- points[0].x = w;
+ points[0].x = (short)w;
points[0].y = 0;
- points[1].x = w;
- points[1].y = w;
+ points[1].x = (short)w;
+ points[1].y = (short)w;
points[2].x = 0;
- points[2].y = w;
+ points[2].y = (short)w;
XDrawLines (dpy, Scr->tbpm.resize, gc, points, 3, CoordModeOrigin);
w = w / 2;
- points[0].x = w;
+ points[0].x = (short)w;
points[0].y = 0;
- points[1].x = w;
- points[1].y = w;
+ points[1].x = (short)w;
+ points[1].y = (short)w;
points[2].x = 0;
- points[2].y = w;
+ points[2].y = (short)w;
XDrawLines (dpy, Scr->tbpm.resize, gc, points, 3, CoordModeOrigin);
/*
@@ -867,11 +877,11 @@ CreateDotPixmap (unsigned *widthp, unsigned *heightp)
GC gc;
Pixmap pix;
- pix = Scr->tbpm.delete = XCreatePixmap (dpy, Scr->Root, h, h, 1);
+ pix = Scr->tbpm.delete = XCreatePixmap (dpy, Scr->Root, (unsigned)h, (unsigned)h, 1);
gc = XCreateGC (dpy, pix, 0L, NULL);
- XSetLineAttributes (dpy, gc, h, LineSolid, CapRound, JoinRound);
+ XSetLineAttributes (dpy, gc, (unsigned)h, LineSolid, CapRound, JoinRound);
XSetForeground (dpy, gc, 0L);
- XFillRectangle (dpy, pix, gc, 0, 0, h, h);
+ XFillRectangle (dpy, pix, gc, 0, 0, (unsigned)h, (unsigned)h);
XSetForeground (dpy, gc, 1L);
XDrawLine (dpy, pix, gc, h/2, h/2, h/2, h/2);
XFreeGC (dpy, gc);
@@ -929,16 +939,16 @@ CreateMenuIcon (int height, unsigned *widthp, unsigned *heightp)
h = 1;
if (w < 1)
w = 1;
- *widthp = w;
- *heightp = h;
+ *widthp = (unsigned)w;
+ *heightp = (unsigned)h;
if (Scr->tbpm.menu == None) {
Pixmap pix;
GC gc;
- pix = Scr->tbpm.menu = XCreatePixmap (dpy, Scr->Root, w, h, 1);
+ pix = Scr->tbpm.menu = XCreatePixmap (dpy, Scr->Root, (unsigned)w, (unsigned)h, 1);
gc = XCreateGC (dpy, pix, 0L, NULL);
XSetForeground (dpy, gc, 0L);
- XFillRectangle (dpy, pix, gc, 0, 0, w, h);
+ XFillRectangle (dpy, pix, gc, 0, 0, (unsigned)w, (unsigned)h);
XSetForeground (dpy, gc, 1L);
ix = 1;
iy = 1;
@@ -952,10 +962,10 @@ CreateMenuIcon (int height, unsigned *widthp, unsigned *heightp)
bw = 1;
tw = mw - bw * 2;
th = mh - bw * 2;
- XFillRectangle (dpy, pix, gc, ix, iy, mw, mh);
- XFillRectangle (dpy, pix, gc, ix + iw - mw, iy + ih - mh, mw, mh);
+ XFillRectangle (dpy, pix, gc, ix, iy, (unsigned)mw, (unsigned)mh);
+ XFillRectangle (dpy, pix, gc, ix + iw - mw, iy + ih - mh, (unsigned)mw, (unsigned)mh);
XSetForeground (dpy, gc, 0L);
- XFillRectangle (dpy, pix, gc, ix+bw, iy+bw, tw, th);
+ XFillRectangle (dpy, pix, gc, ix+bw, iy+bw, (unsigned)tw, (unsigned)th);
XSetForeground (dpy, gc, 1L);
lw = tw / 2;
if ((tw & 1) ^ (lw & 1))
@@ -975,7 +985,7 @@ CreateMenuIcon (int height, unsigned *widthp, unsigned *heightp)
dly = lh / (lines - 1);
while (lines--)
{
- XFillRectangle (dpy, pix, gc, lx, ly, lw, bw);
+ XFillRectangle (dpy, pix, gc, lx, ly, (unsigned)lw, (unsigned)bw);
ly += dly;
}
XFreeGC (dpy, gc);
@@ -984,7 +994,7 @@ CreateMenuIcon (int height, unsigned *widthp, unsigned *heightp)
}
void
-Bell(int type, int percent, Window win)
+Bell(int type _X_UNUSED, int percent, Window win _X_UNUSED)
{
#ifdef XKB
XkbStdBell(dpy, win, percent, type);