wmbutton: wmbutton.h and wmb_libs.c code clean

This patch is a code clean patch:

- Removes spaces and tabs at end of line.
- Remove curly brackets not needed.
- Change spaces by tabs.
- Add spaces after and before operators.
- Removes spaces not needed.
- Better code style.
- Added void as function argument.
This commit is contained in:
Rodolfo García Peñas (kix) 2012-08-21 20:51:17 +02:00 committed by Carlos R. Mafra
parent cc68392ccb
commit 1400c7f7a6
2 changed files with 603 additions and 573 deletions

View file

@ -15,7 +15,6 @@
#include <string.h> #include <string.h>
#include "wmbutton.h" #include "wmbutton.h"
/****** ToolTip Globals ***********************************************/ /****** ToolTip Globals ***********************************************/
static struct timeval _tStart; static struct timeval _tStart;
@ -25,11 +24,12 @@ int _bTooltip = 0;
XFontStruct* _fTooltip; XFontStruct* _fTooltip;
int _nFontHeight, _nFontY; int _nFontHeight, _nFontY;
int _nScreenWidth, _nScreenHeight; int _nScreenWidth, _nScreenHeight;
GC _gcMono= 0; GC _gcMono = 0;
Window _wTooltip; Window _wTooltip;
/****** Parse Command Line ********************************************/ /****** Parse Command Line ********************************************/
void parseargs(int argc, char **argv) { void parseargs(int argc, char **argv)
{
int current; int current;
char *Home = getenv("HOME"); char *Home = getenv("HOME");
@ -71,16 +71,16 @@ void parseargs(int argc, char **argv) {
if (!Config.configfile) { if (!Config.configfile) {
if (Home != NULL) { if (Home != NULL) {
Config.configfile = malloc( Config.configfile = malloc(strlen(Home) +
strlen(Home) + strlen(CONFFILENAME) + 1); strlen(CONFFILENAME) + 1);
sprintf(Config.configfile, "%s%s", Home, CONFFILENAME); sprintf(Config.configfile, "%s%s", Home, CONFFILENAME);
} }
} }
if (!Config.buttonfile) { if (!Config.buttonfile) {
if (Home != NULL) { if (Home != NULL) {
Config.buttonfile = malloc( Config.buttonfile = malloc(strlen(Home) +
strlen(Home) + strlen(BUTTONFILENAME) + 1); strlen(BUTTONFILENAME) + 1);
sprintf(Config.buttonfile, "%s%s", Home, BUTTONFILENAME); sprintf(Config.buttonfile, "%s%s", Home, BUTTONFILENAME);
} }
} }
@ -100,51 +100,52 @@ void parseargs(int argc, char **argv) {
} }
/****** Show Usage Information ****************************************/ /****** Show Usage Information ****************************************/
void show_usage() { void show_usage(void)
{
extern char *app_name; extern char *app_name;
fprintf(stderr,"\n"); fprintf(stderr, "\n");
fprintf(stderr,"usage: %s [-g geom] [-d dpy] [-f cfgfile] [-b btnfile] "\ fprintf(stderr, "usage: %s [-g geom] [-d dpy] [-f cfgfile] [-b btnfile] "\
"[-F <font>] [-v] [-s] [-n]\n",app_name); "[-F <font>] [-v] [-s] [-n]\n",app_name);
fprintf(stderr,"\n"); fprintf(stderr, "\n");
fprintf(stderr," wmbutton version %s\n", VER_STR); fprintf(stderr, " wmbutton version %s\n", VER_STR);
fprintf(stderr,"\n"); fprintf(stderr, "\n");
fprintf(stderr,"-g <geometry> Window Geometry - ie: 64x64+10+10\n"); fprintf(stderr, "-g <geometry> Window Geometry - ie: 64x64+10+10\n");
fprintf(stderr,"-d <display> Display - ie: 127.0.0.1:0.0\n"); fprintf(stderr, "-d <display> Display - ie: 127.0.0.1:0.0\n");
fprintf(stderr,"-f <filename> Full path to configuration file.\n"); fprintf(stderr, "-f <filename> Full path to configuration file.\n");
fprintf(stderr,"-b <filename> Full path to button xpm.\n"); fprintf(stderr, "-b <filename> Full path to button xpm.\n");
fprintf(stderr,"-F <font> Custom tooltip font (e.g. -b\\&h-lucidatypewriter-medium-*-*-*-12-*)\n"); fprintf(stderr, "-F <font> Custom tooltip font (e.g. -b\\&h-lucidatypewriter-medium-*-*-*-12-*)\n");
fprintf(stderr,"-v Verbose Mode.\n"); fprintf(stderr, "-v Verbose Mode.\n");
fprintf(stderr,"-h Help. This message.\n"); fprintf(stderr, "-h Help. This message.\n");
fprintf(stderr,"-m Disable Middle Mouse functionality.\n"); fprintf(stderr, "-m Disable Middle Mouse functionality.\n");
fprintf(stderr,"-s Swap tooltip colors.\n"); fprintf(stderr, "-s Swap tooltip colors.\n");
fprintf(stderr,"-n Turn off tooltips.\n"); fprintf(stderr, "-n Turn off tooltips.\n");
fprintf(stderr,"\n"); fprintf(stderr, "\n");
exit(0); exit(0);
}/***********************************************************************/ }
/***********************************************************************/
/****** Error Handler Routine *****************************************/ /****** Error Handler Routine *****************************************/
void err_mess(int err, char *str) { void err_mess(int err, char *str)
{
switch (err) { switch (err) {
case FAILDISP: case FAILDISP:
fprintf(stderr,"Fail: XOpenDisplay for %s\n", str); fprintf(stderr, "Fail: XOpenDisplay for %s\n", str);
exit(err); exit(err);
case FAILSWIN: case FAILSWIN:
fprintf(stderr,"Fail: XCreateSimpleWindow\n"); fprintf(stderr, "Fail: XCreateSimpleWindow\n");
exit(err); exit(err);
case FAILICON: case FAILICON:
fprintf(stderr,"Fail: XCreateSimpleWindow\n"); fprintf(stderr, "Fail: XCreateSimpleWindow\n");
exit(err); exit(err);
case FAILXPM: case FAILXPM:
fprintf(stderr,"Fail: XCreateBitmapFromData\n"); fprintf(stderr, "Fail: XCreateBitmapFromData\n");
break; break;
case FAILWNAM: case FAILWNAM:
fprintf(stderr,"%s: Can't set up window name\n", str); fprintf(stderr, "%s: Can't set up window name\n", str);
exit(err); exit(err);
case FAILGC: case FAILGC:
fprintf(stderr,"Fail: XCreateGC\n"); fprintf(stderr, "Fail: XCreateGC\n");
exit(err); exit(err);
case FAILCONF: case FAILCONF:
fprintf(stderr, "Fail: Can't Find user or system configuration file.\n"); fprintf(stderr, "Fail: Can't Find user or system configuration file.\n");
@ -161,38 +162,42 @@ void err_mess(int err, char *str) {
fprintf(stderr, "Fail: Can't Create 'buttons' Pixmap\n"); fprintf(stderr, "Fail: Can't Create 'buttons' Pixmap\n");
exit(err); exit(err);
default: default:
fprintf(stderr, "Fail: UnSpecified Error: %d\n",err); fprintf(stderr, "Fail: UnSpecified Error: %d\n", err);
fprintf(stderr, "Fail: %s\n",str); fprintf(stderr, "Fail: %s\n", str);
exit(err); exit(err);
} }
}
}/***********************************************************************/ /***********************************************************************/
/*********************************************************************** /***********************************************************************
* RunAppN(int app) * RunAppN(int app)
* *
* Run the command given in the configuration file 'configfile' * Run the command given in the configuration file 'configfile'
***********************************************************************/ ***********************************************************************/
void RunAppN( int app ) { void RunAppN(int app)
{
char *cmndstr; char *cmndstr;
extern struct Config_t Config; extern struct Config_t Config;
cmndstr = Parse(app); // Get command to pass to system cmndstr = Parse(app); /* Get command to pass to system */
if (Config.Verbose) fprintf(stderr, "Command String: %s", cmndstr); if (Config.Verbose)
fprintf(stderr, "Command String: %s", cmndstr);
if (cmndstr != NULL) { if (cmndstr != NULL) {
system(cmndstr); // if there's a command, run it system(cmndstr); /* if there's a command, run it */
free(cmndstr); free(cmndstr);
} }
}/***********************************************************************/ }
/***********************************************************************/
/*********************************************************************** /***********************************************************************
* Parse(int app) * Parse(int app)
* *
* Parses the file 'configfile' for command to execute. * Parses the file 'configfile' for command to execute.
***********************************************************************/ ***********************************************************************/
char *Parse(int app) { char *Parse(int app)
{
FILE *fp; FILE *fp;
char Buf[BUFFER_SIZE]; char Buf[BUFFER_SIZE];
char *Ptr; char *Ptr;
@ -211,15 +216,19 @@ char *Parse(int app) {
if (!Ptr) if (!Ptr)
return Ptr; return Ptr;
Ptr = strchr(Buf, '\t'); // find first tab Ptr = strchr(Buf, '\t'); /* find first tab */
if (Ptr == NULL) Ptr = strchr(Buf, ' '); // or space charater if (Ptr == NULL)
if (Ptr == NULL) return(NULL); Ptr = strchr(Buf, ' '); /* or space charater */
Ptr++;
if (Ptr == NULL)
return(NULL);
Ptr++;
Ptr = strdup(Ptr); Ptr = strdup(Ptr);
return(Ptr); return Ptr;
}/**********************************************************************/ }
/**********************************************************************/
/*********************************************************************** /***********************************************************************
* initTime * initTime
@ -227,43 +236,45 @@ char *Parse(int app) {
* Copyright (c) 2001 Bruno Essmann <essmann@users.sourceforge.net> * Copyright (c) 2001 Bruno Essmann <essmann@users.sourceforge.net>
***********************************************************************/ ***********************************************************************/
void initTime () { void initTime(void)
{
extern struct Config_t Config; extern struct Config_t Config;
if (Config.Verbose) { if (Config.Verbose)
fprintf(stdout, "[ ] initializing time\n"); fprintf(stdout, "[ ] initializing time\n");
}
gettimeofday(&_tStart, NULL); gettimeofday(&_tStart, NULL);
}/**********************************************************************/ }
/**********************************************************************/
long currentTimeMillis () { long currentTimeMillis(void)
struct timeval tNow; {
struct timeval tElapsed; struct timeval tNow, tElapsed;
gettimeofday(&tNow, NULL); gettimeofday(&tNow, NULL);
if (_tStart.tv_usec > tNow.tv_usec) { if (_tStart.tv_usec > tNow.tv_usec) {
tNow.tv_usec+= 1000000; tNow.tv_usec += 1000000;
tNow.tv_sec--; tNow.tv_sec--;
} }
tElapsed.tv_sec= tNow.tv_sec - _tStart.tv_sec;
tElapsed.tv_usec= tNow.tv_usec - _tStart.tv_usec; tElapsed.tv_sec = tNow.tv_sec - _tStart.tv_sec;
tElapsed.tv_usec = tNow.tv_usec - _tStart.tv_usec;
return (tElapsed.tv_sec * 1000) + (tElapsed.tv_usec / 1000); return (tElapsed.tv_sec * 1000) + (tElapsed.tv_usec / 1000);
}/**********************************************************************/ }
/**********************************************************************/
void getWindowOrigin(Window w, int *nX, int *nY)
void getWindowOrigin (Window w, int* nX, int* nY) { {
extern Display *display; extern Display *display;
Window wWindow, wParent, wRoot; Window wWindow, wParent, wRoot;
Window* wChildren; Window* wChildren;
unsigned int nChildren; unsigned int nChildren, ww, wh, wb, wd;
unsigned int ww, wh, wb, wd;
int wx, wy; int wx, wy;
wParent= w; wParent = w;
do { do {
wWindow= wParent; wWindow = wParent;
if (!XQueryTree(display, wParent, &wRoot, &wParent, &wChildren, &nChildren)) if (!XQueryTree(display, wParent, &wRoot, &wParent, &wChildren, &nChildren))
return; return;
@ -273,48 +284,54 @@ void getWindowOrigin (Window w, int* nX, int* nY) {
} while (wParent != wRoot); } while (wParent != wRoot);
if (XGetGeometry(display, wWindow, &wRoot, &wx, &wy, &ww, &wh, &wb, &wd)) { if (XGetGeometry(display, wWindow, &wRoot, &wx, &wy, &ww, &wh, &wb, &wd)) {
if (nX) { if (nX)
*nX= wx; *nX = wx;
if (nY)
*nY = wy;
} }
if (nY) { }
*nY= wy; /**********************************************************************/
}
}
}/**********************************************************************/
/*********************************************************************** /***********************************************************************
* getButtonLocation * getButtonLocation
* *
* compute location for each button's tooltip (not perfect) * compute location for each button's tooltip (not perfect)
***********************************************************************/ ***********************************************************************/
void getButtonLocation (int nButton, int* nLocationX, int* nLocationY) { void getButtonLocation (int nButton, int *nLocationX, int *nLocationY)
{
*nLocationX = 0; *nLocationX = 0;
*nLocationY = 8; *nLocationY = 8;
while (nButton > BUTTON_COLS) { while (nButton > BUTTON_COLS) {
*nLocationY += BUTTON_SIZE; *nLocationY += BUTTON_SIZE;
nButton -= BUTTON_COLS; nButton -= BUTTON_COLS;
} }
while (nButton > 0) { while (nButton > 0) {
*nLocationX += BUTTON_SIZE - 1; *nLocationX += BUTTON_SIZE - 1;
nButton--; nButton--;
} }
}/**********************************************************************/ }
/**********************************************************************/
/* SkipWord & SkipSpaces: utility functions for getNicenedString */ /* SkipWord & SkipSpaces: utility functions for getNicenedString */
char *SkipWord(char *Text) { char *SkipWord(char *Text) {
char *Result = Text; char *Result = Text;
while ((*Result != ' ')&&(*Result != '\t')&& while ((*Result != ' ') && (*Result != '\t') &&
(*Result != '\n')&&(*Result != 0x00)) (*Result != '\n') && (*Result != 0x00))
Result++; Result++;
return Result; return Result;
} }
char *SkipSpaces(char *Text) { char *SkipSpaces(char *Text) {
char *Result = Text; char *Result = Text;
while ((*Result == ' ')||(*Result == '\t')||(*Result == '\n')) while ((*Result == ' ') || (*Result == '\t') || (*Result == '\n'))
Result++; Result++;
return Result; return Result;
} }
@ -325,13 +342,9 @@ char *SkipSpaces(char *Text) {
* - cut if too long * - cut if too long
* - remove parameters, whitespace and the '&'... * - remove parameters, whitespace and the '&'...
***********************************************************************/ ***********************************************************************/
char* getNicenedString (char *old, int andAddSeparator) { char *getNicenedString(char *old, int andAddSeparator)
char *WorkStr; {
char *WorkStrEnd; char *WorkStr, *WorkStrEnd, *StartPtr, *EndPtr, *RetStr;
char *StartPtr;
char *EndPtr;
char *RetStr;
if (!old) { if (!old) {
if (andAddSeparator) if (andAddSeparator)
@ -340,31 +353,30 @@ char* getNicenedString (char *old, int andAddSeparator) {
return strdup("--"); return strdup("--");
} }
RetStr = malloc(strlen(old) + 3 + 1); // 3 for Seperator RetStr = malloc(strlen(old) + 3 + 1); /* 3 for Seperator */
*RetStr = 0x00; *RetStr = 0x00;
WorkStr = strdup(old); WorkStr = strdup(old);
WorkStrEnd = strchr(WorkStr, 0x00); WorkStrEnd = strchr(WorkStr, 0x00);
StartPtr = WorkStr; StartPtr = WorkStr;
while(StartPtr < WorkStrEnd) { while (StartPtr < WorkStrEnd) {
StartPtr = SkipSpaces(StartPtr); StartPtr = SkipSpaces(StartPtr);
EndPtr = SkipWord(StartPtr); EndPtr = SkipWord(StartPtr);
*EndPtr = 0x00; *EndPtr = 0x00;
if ((*StartPtr == '&')||(*StartPtr == '-')) if ((*StartPtr == '&') || (*StartPtr == '-'))
break; break;
strcat(RetStr, StartPtr); strcat(RetStr, StartPtr);
strcat(RetStr, " "); strcat(RetStr, " ");
StartPtr = EndPtr+1; StartPtr = EndPtr + 1;
} }
free(WorkStr); free(WorkStr);
if (andAddSeparator) { if (andAddSeparator)
strcat(RetStr, "| "); strcat(RetStr, "| ");
}
return RetStr; return RetStr;
} }
@ -372,16 +384,16 @@ char* getNicenedString (char *old, int andAddSeparator) {
/*********************************************************************** /***********************************************************************
* getButtonAppNames * getButtonAppNames
* *
* returns the 1..3 application names / commands to be shown in tooltip *returns the 1..3 application names / commands to be shown in tooltip
***********************************************************************/ ***********************************************************************/
char* getButtonAppNames (int nButton) { char *getButtonAppNames(int nButton)
char *str = NULL; {
char *tmp1,*tmp2; char *tmp1, *tmp2, *str = NULL;
if (!( nButton < 0 || nButton > 9 )) { if (!( nButton < 0 || nButton > 9 )) {
// FIXME: _Might_ overflow, but it's unlikely. /* FIXME: _Might_ overflow, but it's unlikely.
// Perhaps one should fix this sometime ;) * Perhaps one should fix this sometime ;) */
str = (char*) calloc (sizeof(char), BUFFER_SIZE); str = (char*) calloc (sizeof(char), BUFFER_SIZE);
tmp1 = Parse(nButton + LMASK); tmp1 = Parse(nButton + LMASK);
@ -403,15 +415,19 @@ char* getButtonAppNames (int nButton) {
free(tmp2); free(tmp2);
} }
return(str); return str;
}/**********************************************************************/ }
/**********************************************************************/
int hasTooltipSupport () { int hasTooltipSupport(void)
{
return !Config.bTooltipDisable; return !Config.bTooltipDisable;
}/**********************************************************************/ }
/**********************************************************************/
void showTooltip (int nButton, int nMouseX, int nMouseY) { void showTooltip (int nButton, int nMouseX, int nMouseY)
{
Pixmap pixmap, mask; Pixmap pixmap, mask;
int nMainWinX, nMainWinY; int nMainWinX, nMainWinY;
int nButtonX = 0, nButtonY = 0, nButtonWidth = 0, nButtonHeight = 0; int nButtonX = 0, nButtonY = 0, nButtonWidth = 0, nButtonHeight = 0;
@ -423,71 +439,66 @@ void showTooltip (int nButton, int nMouseX, int nMouseY) {
extern Display *display; extern Display *display;
extern GC gc; extern GC gc;
if (Config.bTooltipDisable || nButton == -1) { if (Config.bTooltipDisable || nButton == -1)
return; return;
}
if (_bTooltip) { if (_bTooltip)
hideTooltip(); hideTooltip();
}
if (Config.Verbose)
if (Config.Verbose) { fprintf(stdout,
fprintf(stdout, "[%8ld] showing tooltip for button %d at %d, %d\n", "[%8ld] showing tooltip for button %d at %d, %d\n",
currentTimeMillis(), currentTimeMillis(), nButton, nMouseX, nMouseY);
nButton, nMouseX, nMouseY);
}
szText = getButtonAppNames(nButton); szText = getButtonAppNames(nButton);
if(!szText) if(!szText)
return; return;
_bTooltip= 1; _bTooltip = 1;
nWidth= XTextWidth(_fTooltip, szText, strlen(szText)) + 16; nWidth = XTextWidth(_fTooltip, szText, strlen(szText)) + 16;
nHeight= _nFontHeight + 4; nHeight = _nFontHeight + 4;
if (nHeight < 16) { if (nHeight < 16)
nHeight= 16; nHeight = 16;
}
if (nWidth < nHeight) { if (nWidth < nHeight)
nWidth= nHeight; nWidth = nHeight;
}
if (Config.Verbose) { if (Config.Verbose)
fprintf(stdout, "[%8ld] tooltip size: %d, %d\n", fprintf(stdout, "[%8ld] tooltip size: %d, %d\n",
currentTimeMillis(), nWidth, nHeight); currentTimeMillis(), nWidth, nHeight);
}
getWindowOrigin(iconwin, &nMainWinX, &nMainWinY); getWindowOrigin(iconwin, &nMainWinX, &nMainWinY);
getButtonLocation(nButton, &nButtonX, &nButtonY); getButtonLocation(nButton, &nButtonX, &nButtonY);
nButtonX+= nMainWinX; nButtonX += nMainWinX;
nButtonY+= nMainWinY; nButtonY += nMainWinY;
nButtonWidth = BUTTON_SIZE; nButtonWidth = BUTTON_SIZE;
nButtonHeight = BUTTON_SIZE; nButtonHeight = BUTTON_SIZE;
if (nButtonX + nWidth > _nScreenWidth) { if (nButtonX + nWidth > _nScreenWidth) {
nSide= TOOLTIP_RIGHT; nSide = TOOLTIP_RIGHT;
nX= nButtonX - nWidth + nButtonWidth / 2; nX = nButtonX - nWidth + nButtonWidth / 2;
if (nX < 0) { if (nX < 0)
nX= 0; nX = 0;
}
} else { } else {
nSide= TOOLTIP_LEFT; nSide = TOOLTIP_LEFT;
nX= nButtonX + nButtonWidth / 2; nX = nButtonX + nButtonWidth / 2;
}
if (nX + nWidth > _nScreenWidth) {
nX= _nScreenWidth - nWidth;
} }
if (nX + nWidth > _nScreenWidth)
nX = _nScreenWidth - nWidth;
if (nButtonY - (nHeight + TOOLTIP_SPACE) < 0) { if (nButtonY - (nHeight + TOOLTIP_SPACE) < 0) {
nSide|= TOOLTIP_TOP; nSide |= TOOLTIP_TOP;
nY= nButtonY + nButtonHeight - 1; nY = nButtonY + nButtonHeight - 1;
nTextY= TOOLTIP_SPACE; nTextY = TOOLTIP_SPACE;
} else { } else {
nSide|= TOOLTIP_BOTTOM; nSide |= TOOLTIP_BOTTOM;
nY= nButtonY - (nHeight + TOOLTIP_SPACE); nY = nButtonY - (nHeight + TOOLTIP_SPACE);
nTextY= 0; nTextY = 0;
} }
pixmap= createTooltipPixmap(nWidth, nHeight, nSide, &mask); pixmap = createTooltipPixmap(nWidth, nHeight, nSide, &mask);
XSetForeground(display, gc, Config.bTooltipSwapColors ? fg_pixel : bg_pixel); XSetForeground(display, gc, Config.bTooltipSwapColors ? fg_pixel : bg_pixel);
XSetFont(display, gc, _fTooltip->fid); XSetFont(display, gc, _fTooltip->fid);
@ -505,32 +516,38 @@ void showTooltip (int nButton, int nMouseX, int nMouseY) {
XFreePixmap(display, pixmap); XFreePixmap(display, pixmap);
free(szText); free(szText);
}/**********************************************************************/ }
/**********************************************************************/
void hideTooltip () { void hideTooltip(void)
{
extern struct Config_t Config; extern struct Config_t Config;
extern Display *display; extern Display *display;
if (Config.bTooltipDisable) { if (Config.bTooltipDisable)
return; return;
}
if (_bTooltip) { if (_bTooltip) {
if (Config.Verbose) { if (Config.Verbose)
fprintf(stdout, "[%8ld] hiding tooltip\n", currentTimeMillis()); fprintf(stdout, "[%8ld] hiding tooltip\n", currentTimeMillis());
}
XUnmapWindow(display, _wTooltip); XUnmapWindow(display, _wTooltip);
_bTooltip= 0; _bTooltip = 0;
} }
}/**********************************************************************/ }
/**********************************************************************/
int hasTooltip () { int hasTooltip(void)
if (Config.bTooltipDisable) { {
if (Config.bTooltipDisable)
return 0; return 0;
}
return _bTooltip;
}/**********************************************************************/
void initTooltip () { return _bTooltip;
}
/**********************************************************************/
void initTooltip(void)
{
XSetWindowAttributes attribs; XSetWindowAttributes attribs;
unsigned long vmask; unsigned long vmask;
extern Display *display; extern Display *display;
@ -539,28 +556,28 @@ void initTooltip () {
extern Window rootwin, win; extern Window rootwin, win;
if (Config.bTooltipDisable) { if (Config.bTooltipDisable) {
if (Config.Verbose) { if (Config.Verbose)
fprintf(stdout, "[%8ld] initializing tooltips (disabled)\n", fprintf(stdout, "[%8ld] initializing tooltips (disabled)\n",
currentTimeMillis()); currentTimeMillis());
}
return; return;
} }
if (Config.Verbose) { if (Config.Verbose)
fprintf(stdout, "[%8ld] initializing tooltips\n", currentTimeMillis()); fprintf(stdout, "[%8ld] initializing tooltips\n", currentTimeMillis());
}
_fTooltip= XLoadQueryFont(display, Config.szTooltipFont); _fTooltip = XLoadQueryFont(display, Config.szTooltipFont);
if (!_fTooltip) { if (!_fTooltip) {
fprintf(stderr, "%s: couldn't allocate font '%s'.\n", app_name, Config.szTooltipFont); fprintf(stderr, "%s: couldn't allocate font '%s'.\n", app_name, Config.szTooltipFont);
if (!strcmp(Config.szTooltipFont, TOOLTIP_FONT)) if (!strcmp(Config.szTooltipFont, TOOLTIP_FONT))
fprintf(stderr, "%s: Use option -F <font>\n", app_name); fprintf(stderr, "%s: Use option -F <font>\n", app_name);
exit(-1); exit(-1);
} }
_nFontHeight= _fTooltip->ascent + _fTooltip->descent;
_nFontY= _fTooltip->ascent; _nFontHeight = _fTooltip->ascent + _fTooltip->descent;
_nScreenWidth= WidthOfScreen(ScreenOfDisplay(display, screen)); _nFontY = _fTooltip->ascent;
_nScreenHeight= HeightOfScreen(ScreenOfDisplay(display, screen)); _nScreenWidth = WidthOfScreen(ScreenOfDisplay(display, screen));
if (Config.Verbose) { _nScreenHeight = HeightOfScreen(ScreenOfDisplay(display, screen));
if (Config.Verbose)
fprintf(stdout, "[%8ld] configuring tooltip font:\n" \ fprintf(stdout, "[%8ld] configuring tooltip font:\n" \
"[%8ld] - '%s'\n" \ "[%8ld] - '%s'\n" \
"[%8ld] - font-height= %d, font-ascent= %d\n" \ "[%8ld] - font-height= %d, font-ascent= %d\n" \
@ -568,101 +585,109 @@ void initTooltip () {
currentTimeMillis(), currentTimeMillis(),
currentTimeMillis(), Config.szTooltipFont, currentTimeMillis(), Config.szTooltipFont,
currentTimeMillis(), _nFontHeight, _nFontY, currentTimeMillis(), _nFontHeight, _nFontY,
currentTimeMillis(), _nScreenWidth, _nScreenHeight ); currentTimeMillis(), _nScreenWidth, _nScreenHeight);
}
vmask= CWSaveUnder | CWOverrideRedirect | CWBorderPixel; vmask = CWSaveUnder | CWOverrideRedirect | CWBorderPixel;
attribs.save_under= True; attribs.save_under = True;
attribs.override_redirect= True; attribs.override_redirect = True;
attribs.border_pixel= 0; attribs.border_pixel = 0;
_wTooltip= XCreateWindow(display, rootwin, 1, 1, 10, 10, 1, _wTooltip = XCreateWindow(display, rootwin, 1, 1, 10, 10, 1,
CopyFromParent, CopyFromParent, CopyFromParent, CopyFromParent,
CopyFromParent, vmask, &attribs); CopyFromParent, vmask, &attribs);
if (win == 0) { if (win == 0) {
fprintf(stderr, "Cannot create tooltip window.\n"); fprintf(stderr, "Cannot create tooltip window.\n");
exit(-1); exit(-1);
} }
}/**********************************************************************/ }
/**********************************************************************/
void destroyTooltip () { void destroyTooltip(void)
{
extern Display *display; extern Display *display;
if (Config.bTooltipDisable) { if (Config.bTooltipDisable)
return; return;
}
if (_gcMono) { if (_gcMono) {
XFreeGC(display, _gcMono); XFreeGC(display, _gcMono);
_gcMono= 0; _gcMono = 0;
} }
XDestroyWindow(display, _wTooltip);
}/**********************************************************************/
void drawTooltipBalloon (Pixmap pix, GC gc, int x, int y, int w, int h, int side) { XDestroyWindow(display, _wTooltip);
}
/**********************************************************************/
void drawTooltipBalloon(Pixmap pix, GC gc, int x, int y, int w, int h, int side)
{
extern Display *display; extern Display *display;
int rad = h*3/10; int rad = h * 3 / 10;
XPoint pt[3]; XPoint pt[3];
XFillArc(display, pix, gc, x, y, rad, rad, 90*64, 90*64); XFillArc(display, pix, gc, x, y, rad, rad, 90 * 64, 90 * 64);
XFillArc(display, pix, gc, x, y+h-1-rad, rad, rad, 180*64, 90*64); XFillArc(display, pix, gc, x, y + h - 1 - rad, rad, rad, 180 * 64, 90 * 64);
XFillArc(display, pix, gc, x+w-1-rad, y, rad, rad, 0*64, 90*64); XFillArc(display, pix, gc, x + w - 1 - rad, y, rad, rad, 0 * 64, 90 * 64);
XFillArc(display, pix, gc, x+w-1-rad, y+h-1-rad, rad, rad, 270*64, 90*64); XFillArc(display, pix, gc, x + w - 1 - rad, y + h - 1 - rad, rad, rad, 270 * 64, 90 * 64);
XFillRectangle(display, pix, gc, x, y+rad/2, w, h-rad); XFillRectangle(display, pix, gc, x, y + rad / 2, w, h - rad);
XFillRectangle(display, pix, gc, x+rad/2, y, w-rad, h); XFillRectangle(display, pix, gc, x + rad / 2, y, w - rad, h);
if (side & TOOLTIP_BOTTOM) { if (side & TOOLTIP_BOTTOM) {
pt[0].y = y+h-1; pt[0].y = y + h - 1;
pt[1].y = y+h-1+TOOLTIP_SPACE; pt[1].y = y + h - 1 + TOOLTIP_SPACE;
pt[2].y = y+h-1; pt[2].y = y + h - 1;
} else { } else {
pt[0].y = y; pt[0].y = y;
pt[1].y = y-TOOLTIP_SPACE; pt[1].y = y-TOOLTIP_SPACE;
pt[2].y = y; pt[2].y = y;
} }
if (side & TOOLTIP_RIGHT) {
pt[0].x = x+w-h+2*h/16;
pt[1].x = x+w-h+11*h/16;
pt[2].x = x+w-h+7*h/16;
} else {
pt[0].x = x+h-2*h/16;
pt[1].x = x+h-11*h/16;
pt[2].x = x+h-7*h/16;
}
XFillPolygon(display, pix, gc, pt, 3, Convex, CoordModeOrigin);
}/**********************************************************************/
Pixmap createTooltipPixmap (int width, int height, int side, Pixmap *mask) { if (side & TOOLTIP_RIGHT) {
pt[0].x = x + w - h + 2 * h / 16;
pt[1].x = x + w - h + 11 * h / 16;
pt[2].x = x + w - h + 7 * h / 16;
} else {
pt[0].x = x + h - 2 * h /16;
pt[1].x = x + h - 11 * h /16;
pt[2].x = x + h - 7 * h /16;
}
XFillPolygon(display, pix, gc, pt, 3, Convex, CoordModeOrigin);
}
/**********************************************************************/
Pixmap createTooltipPixmap(int width, int height, int side, Pixmap *mask)
{
extern Display *display; extern Display *display;
extern GC gc; extern GC gc;
extern Pixel bg_pixel, fg_pixel; extern Pixel bg_pixel, fg_pixel;
extern int depth; extern int depth;
extern Window rootwin; extern Window rootwin;
Pixmap bitmap; Pixmap bitmap, pixmap;
Pixmap pixmap;
int x, y; int x, y;
bitmap = XCreatePixmap(display, rootwin, bitmap = XCreatePixmap(display, rootwin,
width+TOOLTIP_SPACE, height+TOOLTIP_SPACE, 1); width+TOOLTIP_SPACE, height+TOOLTIP_SPACE, 1);
if (!_gcMono) { if (!_gcMono)
_gcMono= XCreateGC(display, bitmap, 0, NULL); _gcMono = XCreateGC(display, bitmap, 0, NULL);
}
XSetForeground(display, _gcMono, 0); XSetForeground(display, _gcMono, 0);
XFillRectangle(display, bitmap, _gcMono, 0, 0, XFillRectangle(display, bitmap, _gcMono, 0, 0,
width+TOOLTIP_SPACE, height+TOOLTIP_SPACE); width+TOOLTIP_SPACE, height+TOOLTIP_SPACE);
pixmap = XCreatePixmap(display, rootwin, pixmap = XCreatePixmap(display, rootwin, width+TOOLTIP_SPACE,
width+TOOLTIP_SPACE, height+TOOLTIP_SPACE, depth); height+TOOLTIP_SPACE, depth);
XSetForeground(display, gc, Config.bTooltipSwapColors ? fg_pixel : bg_pixel); XSetForeground(display, gc, Config.bTooltipSwapColors ? fg_pixel : bg_pixel);
XFillRectangle(display, pixmap, gc, 0, 0, XFillRectangle(display, pixmap, gc, 0, 0, width+TOOLTIP_SPACE,
width+TOOLTIP_SPACE, height+TOOLTIP_SPACE); height+TOOLTIP_SPACE);
if (side & TOOLTIP_BOTTOM) { if (side & TOOLTIP_BOTTOM)
y = 0; y = 0;
} else { else
y = TOOLTIP_SPACE; y = TOOLTIP_SPACE;
}
x = 0; x = 0;
XSetForeground(display, _gcMono, 1); XSetForeground(display, _gcMono, 1);
@ -673,7 +698,8 @@ Pixmap createTooltipPixmap (int width, int height, int side, Pixmap *mask) {
*mask = bitmap; *mask = bitmap;
return pixmap; return pixmap;
}/***********************************************************************/ }
/***********************************************************************/
/*********************************************************************** /***********************************************************************
@ -681,11 +707,15 @@ Pixmap createTooltipPixmap (int width, int height, int side, Pixmap *mask) {
* *
* Everyone else has one of these... Can't hurt to throw it in. * Everyone else has one of these... Can't hurt to throw it in.
***********************************************************************/ ***********************************************************************/
int flush_expose(Window w) { int flush_expose(Window w)
{
extern Display *display; extern Display *display;
XEvent dummy; XEvent dummy;
int i=0; int i = 0;
while (XCheckTypedWindowEvent(display, w, Expose, &dummy)) i++; while (XCheckTypedWindowEvent(display, w, Expose, &dummy))
return(i); i++;
}/***********************************************************************/
return i;
}
/***********************************************************************/

View file

@ -78,29 +78,29 @@ struct Config_t {
}; };
/****** Function Prototyes *******************************************/ /****** Function Prototyes *******************************************/
void RunAppN(int app); // function to run app N as found in conf file void RunAppN(int app); /* function to run app N as found in conf file */
char *Parse(int app); // parse data in config file char *Parse(int app); /* parse data in config file */
void parseargs(int argc, char **argv); void parseargs(int argc, char **argv);
char *readln(FILE *fp); // read line from file, return pointer to it char *readln(FILE *fp); /* read line from file, return pointer to it */
void err_mess(int err, char *str); // Error Handling Routine void err_mess(int err, char *str); /* Error Handling Routine */
void show_usage(void); // show usage message to stderr void show_usage(void); /* show usage message to stderr */
int flush_expose(Window w); int flush_expose(Window w);
/****** Tooltip Function Prototypes **********************************/ /****** Tooltip Function Prototypes **********************************/
void initTooltip(); void initTooltip();
void destroyTooltip (); void destroyTooltip(void);
int hasTooltipSupport (); int hasTooltipSupport(void);
void showTooltip (int nButton, int nMouseX, int nMouseY); void showTooltip(int nButton, int nMouseX, int nMouseY);
void hideTooltip (); void hideTooltip(void);
int hasTooltip (); int hasTooltip(void);
void drawTooltipBalloon (Pixmap pix, GC gc, int x, int y, int w, int h, int side); void drawTooltipBalloon(Pixmap pix, GC gc, int x, int y, int w, int h, int side);
Pixmap createTooltipPixmap (int width, int height, int side, Pixmap *mask); Pixmap createTooltipPixmap(int width, int height, int side, Pixmap *mask);
void initTime (); void initTime(void);
long currentTimeMillis (); long currentTimeMillis(void);
void getWindowOrigin (Window w, int* nX, int* nY); void getWindowOrigin(Window w, int *nX, int *nY);
void getButtonLocation (int nButton, int* nLocationX, int* nLocationY); void getButtonLocation(int nButton, int *nLocationX, int *nLocationY);
char *getButtonAppNames (int nButton); char *getButtonAppNames(int nButton);
/**********************************************************************/ /**********************************************************************/