wmbutton: wmbutton.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.
This commit is contained in:
Rodolfo García Peñas (kix) 2012-08-21 20:33:40 +02:00 committed by Carlos R. Mafra
parent e07b2facf2
commit 77a89054f5

View file

@ -67,21 +67,21 @@ Pixel bg_pixel, fg_pixel;
struct Config_t Config; struct Config_t Config;
typedef struct _XpmIcon { typedef struct _XpmIcon {
Pixmap pixmap; Pixmap pixmap;
Pixmap mask; Pixmap mask;
XpmAttributes attributes; XpmAttributes attributes;
} XpmIcon; } XpmIcon;
typedef struct _button_region { typedef struct _button_region {
int x,y; int x, y;
int i,j; int i, j;
} ButtonArea; } ButtonArea;
ButtonArea button_region[9]; ButtonArea button_region[9];
XpmIcon template, visible, buttons; XpmIcon template, visible, buttons;
int border = 0; int border = 0;
int button_pressed = -1; /* button to be drawn pressed *charkins*/ int button_pressed = -1; /* button to be drawn pressed *charkins*/
char *app_name = "wmbutton"; char *app_name = "wmbutton";
@ -89,301 +89,312 @@ char *app_name = "wmbutton";
/*********************************************************************** /***********************************************************************
* Main * Main
***********************************************************************/ ***********************************************************************/
int main( int argc, char ** argv ) { int main(int argc, char **argv)
{
XEvent report;
XGCValues xgcValues;
XTextProperty app_name_atom;
XSizeHints xsizehints;
Pixmap pixmask;
XEvent report; int dummy = 0;
XGCValues xgcValues; int N = 1; /* Button number pressed to goto app # */
XTextProperty app_name_atom;
XSizeHints xsizehints;
Pixmap pixmask; /* Added for Tool Tip Support */
long nTooltipShowDelay = TOOLTIP_SHOW_DELAY;
long nTooltipReshowDelay = TOOLTIP_RESHOW_DELAY;
long nTooltipTimer = -1;
long nTooltipHideTimer = -1;
long nNow;
int nTooltipButton = 0, nTooltipX = 0, nTooltipY = 0;
int dummy = 0; /* Parse Command Line Arguments */
int N = 1; /* Button number pressed to goto app # */ parseargs(argc, argv);
/* Added for Tool Tip Support */ /* Open Display */
long nTooltipShowDelay = TOOLTIP_SHOW_DELAY; if ((display = XOpenDisplay(Config.Display_str)) == NULL)
long nTooltipReshowDelay = TOOLTIP_RESHOW_DELAY; err_mess(FAILDISP, Config.Display_str);
long nTooltipTimer = -1;
long nTooltipHideTimer = -1;
long nNow;
int nTooltipButton = 0, nTooltipX = 0, nTooltipY = 0;
/* Parse Command Line Arguments */ screen = DefaultScreen(display);
parseargs(argc, argv); rootwin = RootWindow(display, screen);
depth = DefaultDepth(display, screen);
/* Open Display */ bg_pixel = WhitePixel(display, screen);
if ( (display = XOpenDisplay(Config.Display_str)) == NULL ) fg_pixel = BlackPixel(display, screen);
err_mess(FAILDISP, Config.Display_str);
screen = DefaultScreen(display); xsizehints.flags = USSize | USPosition;
rootwin = RootWindow(display,screen); xsizehints.width = 64;
depth = DefaultDepth(display, screen); xsizehints.height = 64;
bg_pixel = WhitePixel(display, screen ); /* Parse Geometry string and fill in sizehints fields */
fg_pixel = BlackPixel(display, screen ); XWMGeometry(display, screen,
Config.Geometry_str,
NULL,
border,
&xsizehints,
&xsizehints.x,
&xsizehints.y,
&xsizehints.width,
&xsizehints.height,
&dummy);
xsizehints.flags = USSize | USPosition; if ((win = XCreateSimpleWindow(display,
xsizehints.width = 64; rootwin,
xsizehints.height = 64; xsizehints.x,
xsizehints.y,
xsizehints.width,
xsizehints.height,
border,
fg_pixel, bg_pixel)) == 0)
err_mess(FAILSWIN, NULL);
/* Parse Geometry string and fill in sizehints fields */ if ((iconwin = XCreateSimpleWindow(display,
XWMGeometry(display, screen, win,
Config.Geometry_str, xsizehints.x,
NULL, xsizehints.y,
border, xsizehints.width,
&xsizehints, xsizehints.height,
&xsizehints.x, border,
&xsizehints.y, fg_pixel, bg_pixel)) == 0)
&xsizehints.width,
&xsizehints.height,
&dummy);
if ( (win = XCreateSimpleWindow(display, err_mess(FAILICON, NULL);
rootwin,
xsizehints.x,
xsizehints.y,
xsizehints.width,
xsizehints.height,
border,
fg_pixel, bg_pixel) ) == 0 )
err_mess(FAILSWIN, NULL);
/* Set up shaped windows */
/* Gives the appicon a border so you can grab and move it. */
if ((pixmask = XCreateBitmapFromData(display,
win,
mask_bits,
mask_width,
mask_height)) == 0)
err_mess(FAILXPM, NULL);
if ( (iconwin = XCreateSimpleWindow(display, XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
win, XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
xsizehints.x,
xsizehints.y,
xsizehints.width,
xsizehints.height,
border,
fg_pixel, bg_pixel) ) == 0 )
err_mess(FAILICON, NULL);
/* Set up shaped windows */ /* Convert in pixmaps from .xpm includes. */
/*Gives the appicon a border so you can grab and move it. */ getPixmaps();
if ( ( pixmask = XCreateBitmapFromData(display, /* Interclient Communication stuff */
win, /* Appicons don't work with out this stuff */
mask_bits, SetWmHints();
mask_width, SetClassHints();
mask_height) ) == 0 )
err_mess(FAILXPM,NULL);
XSetWMNormalHints(display, win, &xsizehints);
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet ); /* Tell window manager what the title bar name is. We never see */
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); /* this anyways in the WithdrawnState */
if (XStringListToTextProperty(&app_name, 1, &app_name_atom) == 0)
err_mess(FAILWNAM, app_name);
/* Convert in pixmaps from .xpm includes. */ XSetWMName(display, win, &app_name_atom);
getPixmaps();
/* Interclient Communication stuff */ /* Create Graphic Context */
/* Appicons don't work with out this stuff */ if ((gc = XCreateGC(display, win, (GCForeground | GCBackground),
SetWmHints(); &xgcValues)) == NULL)
SetClassHints(); err_mess(FAILGC, NULL);
/* XEvent Masks. We want both window to process X events */
XSelectInput(display, win,
ExposureMask |
ButtonPressMask |
ButtonReleaseMask | /* added ButtonReleaseMask *charkins*/
PointerMotionMask |
StructureNotifyMask |
LeaveWindowMask);
XSetWMNormalHints( display, win, &xsizehints ); XSelectInput(display, iconwin,
ExposureMask |
ButtonPressMask |
ButtonReleaseMask | /* added ButtonReleaseMask *charkins*/
PointerMotionMask |
StructureNotifyMask |
LeaveWindowMask);
/* Tell window manager what the title bar name is. We never see */ /* Store the 'state' of the application for restarting */
/* this anyways in the WithdrawnState */ XSetCommand(display, win, argv, argc);
if ( XStringListToTextProperty(&app_name, 1, &app_name_atom) == 0 )
err_mess(FAILWNAM,app_name);
XSetWMName( display, win, &app_name_atom );
/* Create Graphic Context */ /* Window won't ever show up until it is mapped.. then drawn after a */
if (( gc = XCreateGC(display, win,(GCForeground | GCBackground), &xgcValues)) /* ConfigureNotify */
== NULL ) XMapWindow(display, win);
err_mess(FAILGC,NULL);
/* XEvent Masks. We want both window to process X events */ /* Initialize Tooltip Support */
XSelectInput(display, win, initTime();
ExposureMask | initTooltip(!Config.bTooltipDisable, Config.szTooltipFont, Config.bTooltipSwapColors);
ButtonPressMask |
ButtonReleaseMask | /* added ButtonReleaseMask *charkins*/
PointerMotionMask |
StructureNotifyMask |
LeaveWindowMask );
XSelectInput(display, iconwin,
ExposureMask |
ButtonPressMask |
ButtonReleaseMask | /* added ButtonReleaseMask *charkins*/
PointerMotionMask |
StructureNotifyMask |
LeaveWindowMask );
/* Store the 'state' of the application for restarting */ /* X Event Loop */
XSetCommand( display, win, argv, argc ); while (1) {
while (XPending(display) || nTooltipTimer == -1) {
XNextEvent(display, &report);
/* Window won't ever show up until it is mapped.. then drawn after a */ switch (report.type) {
/* ConfigureNotify */ case Expose:
XMapWindow( display, win ); if (report.xexpose.count != 0)
break;
/* Initialize Tooltip Support */ if (Config.Verbose)
initTime(); fprintf(stdout, "Event: Expose\n");
initTooltip(!Config.bTooltipDisable, Config.szTooltipFont, Config.bTooltipSwapColors);
/* X Event Loop */ redraw();
while (1) { break;
while (XPending(display) || nTooltipTimer == -1) {
XNextEvent(display, &report ); case ConfigureNotify:
switch (report.type) { if (Config.Verbose)
case Expose: fprintf(stdout, "Event: ConfigureNotify\n");
if (report.xexpose.count != 0) {
break; redraw();
break;
case MotionNotify:
if (hasTooltipSupport()) {
if (!hasTooltip()) {
nTooltipTimer = currentTimeMillis();
nTooltipX = report.xbutton.x;
nTooltipY = report.xbutton.y;
nTooltipButton = whichButton(report.xbutton.x, report.xbutton.y);
} else {
int nButton = whichButton(report.xbutton.x, report.xbutton.y);
if (nButton != nTooltipButton) {
hideTooltip();
nTooltipTimer = -1;
nTooltipX = report.xbutton.x;
nTooltipY = report.xbutton.y;
nTooltipButton = nButton;
showTooltip(nTooltipButton, nTooltipX, nTooltipY);
}
}
}
break;
case LeaveNotify:
if (Config.Verbose)
fprintf(stdout, "Event: LeaveNotify\n");
if (hasTooltip()) {
hideTooltip();
nTooltipHideTimer = currentTimeMillis();
}
nTooltipTimer = -1;
break;
case ButtonPress: /* draw button pressed, don't launch *charkins*/
if (hasTooltip()) {
hideTooltip();
nTooltipHideTimer = currentTimeMillis();
}
switch (report.xbutton.button) {
case Button1:
N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS)) {
button_pressed = N + LMASK;
redraw();
}
if (Config.Verbose)
fprintf(stdout, "Button 1:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+LMASK);
break;
case Button2:
if (Config.mmouse) {
N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS)) {
button_pressed = N + MMASK;
redraw();
}
if (Config.Verbose)
fprintf(stdout, "Button 2:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+MMASK);
}
break;
case Button3:
N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS)) {
button_pressed = N + RMASK;
redraw();
}
if (Config.Verbose)
fprintf(stdout, "Button 3:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+RMASK);
break;
}
break;
case ButtonRelease: /* launch app here if still over button *charkins*/
switch (report.xbutton.button) {
case Button1:
N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN(N + LMASK);
button_pressed = -1;
redraw();
if (Config.Verbose)
fprintf(stdout, "Button 1:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+LMASK);
break;
case Button2:
if (Config.mmouse) {
N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN(N + MMASK);
button_pressed = -1;
redraw();
if (Config.Verbose)
fprintf(stdout, "Button 2:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+MMASK);
}
break;
case Button3:
N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN(N + RMASK);
button_pressed = -1;
redraw();
if (Config.Verbose)
fprintf(stdout, "Button 3:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+RMASK);
break;
}
break;
case DestroyNotify:
if (Config.Verbose)
fprintf(stdout, "Bye\n");
destroyTooltip();
XFreeGC(display, gc);
XDestroyWindow(display, win);
XDestroyWindow(display, iconwin);
XCloseDisplay(display);
exit(0);
break;
}
}
usleep(50000);
nNow = currentTimeMillis();
if (nTooltipTimer != -1 &&
((nNow > nTooltipTimer + nTooltipShowDelay) ||
(nNow < nTooltipHideTimer + nTooltipReshowDelay))) {
showTooltip(nTooltipButton, nTooltipX, nTooltipY);
nTooltipTimer = -1;
}
} }
if ( Config.Verbose ) fprintf(stdout,"Event: Expose\n");
redraw();
break;
case ConfigureNotify: return (0);
if ( Config.Verbose ) fprintf(stdout,"Event: ConfigureNotify\n"); }
redraw(); /***********************************************************************/
break;
case MotionNotify:
if (hasTooltipSupport()) {
if (!hasTooltip()) {
nTooltipTimer= currentTimeMillis();
nTooltipX= report.xbutton.x;
nTooltipY= report.xbutton.y;
nTooltipButton= whichButton(report.xbutton.x, report.xbutton.y);
} else {
int nButton = whichButton(report.xbutton.x, report.xbutton.y);
if (nButton != nTooltipButton) {
hideTooltip();
nTooltipTimer= -1;
nTooltipX = report.xbutton.x;
nTooltipY = report.xbutton.y;
nTooltipButton = nButton;
showTooltip(nTooltipButton, nTooltipX, nTooltipY);
}
}
}
break;
case LeaveNotify:
if ( Config.Verbose ) fprintf(stdout,"Event: LeaveNotify\n");
if (hasTooltip()) {
hideTooltip();
nTooltipHideTimer= currentTimeMillis();
}
nTooltipTimer= -1;
break;
case ButtonPress: /* draw button pressed, don't launch *charkins*/
if (hasTooltip()) {
hideTooltip();
nTooltipHideTimer= currentTimeMillis();
} switch (report.xbutton.button) {
case Button1:
N = whichButton(report.xbutton.x, report.xbutton.y );
if ( (N >= 0) && (N <= NUMB_OF_APPS) ) {
button_pressed = N + LMASK;
redraw();
}
if ( Config.Verbose )
fprintf(stdout,"Button 1:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+LMASK);
break;
case Button2:
if (Config.mmouse) {
N = whichButton(report.xbutton.x, report.xbutton.y );
if ( (N >= 0) && (N <= NUMB_OF_APPS) ) {
button_pressed = N + MMASK;
redraw();
}
if ( Config.Verbose )
fprintf(stdout,"Button 2:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+MMASK);
}
break;
case Button3:
N = whichButton(report.xbutton.x, report.xbutton.y );
if ( (N >= 0) && (N <= NUMB_OF_APPS) ) {
button_pressed = N + RMASK;
redraw();
}
if ( Config.Verbose )
fprintf(stdout,"Button 3:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+RMASK);
break;
}
break;
case ButtonRelease: /* launch app here if still over button *charkins*/
switch (report.xbutton.button) {
case Button1:
N = whichButton(report.xbutton.x, report.xbutton.y );
if ( (N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN( N + LMASK);
button_pressed=-1;
redraw();
if ( Config.Verbose )
fprintf(stdout,"Button 1:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+LMASK);
break;
case Button2:
if (Config.mmouse) {
N = whichButton(report.xbutton.x, report.xbutton.y );
if ( (N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN( N + MMASK);
button_pressed=-1;
redraw();
if ( Config.Verbose )
fprintf(stdout,"Button 2:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+MMASK);
}
break;
case Button3:
N = whichButton(report.xbutton.x, report.xbutton.y );
if ( (N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN( N + RMASK);
button_pressed=-1;
redraw();
if ( Config.Verbose )
fprintf(stdout,"Button 3:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+RMASK);
break;
}
break;
case DestroyNotify:
if ( Config.Verbose ) fprintf(stdout, "Bye\n");
destroyTooltip();
XFreeGC(display, gc);
XDestroyWindow(display,win);
XDestroyWindow(display,iconwin);
XCloseDisplay(display);
exit(0);
break;
}
}
usleep(50000);
nNow = currentTimeMillis();
if ( nTooltipTimer != -1 &&
( (nNow > nTooltipTimer + nTooltipShowDelay) || (nNow < nTooltipHideTimer + nTooltipReshowDelay) ) ) {
showTooltip(nTooltipButton, nTooltipX, nTooltipY);
nTooltipTimer = -1;
}
}
return (0);
}/***********************************************************************/
/*********************************************************************** /***********************************************************************
* redraw * redraw
@ -397,67 +408,69 @@ int main( int argc, char ** argv ) {
* main window and the icon window which is the main window's icon image.) * main window and the icon window which is the main window's icon image.)
***********************************************************************/ ***********************************************************************/
void redraw() { void redraw() {
int n; int n, i, j, dest_x, dest_y, space, offset, bsize = 18;
int i,j;
int dest_x, dest_y;
int space;
int offset;
int bsize = 18;
if ( Config.Verbose ) fprintf(stdout,"In Redraw()\n"); if (Config.Verbose)
space = 0; fprintf(stdout, "In Redraw()\n");
offset = 5;
XCopyArea(display, template.pixmap, visible.pixmap, gc, 0, 0,
template.attributes.width, template.attributes.height, 0, 0 );
for ( j=0; j < 3; j++ ) { space = 0;
for ( i=0; i < 3; i++ ) { offset = 5;
n = i + j * 3; XCopyArea(display, template.pixmap, visible.pixmap, gc, 0, 0,
dest_x = i*(bsize + space) + offset + space; template.attributes.width, template.attributes.height, 0, 0);
dest_y = j*(bsize + space) + offset + space;
/* Define button mouse coords */ for (j = 0; j < 3; j++) {
button_region[n].x = dest_x; for (i = 0; i < 3; i++) {
button_region[n].y = dest_y; n = i + j * 3;
button_region[n].i = dest_x + bsize - 1; dest_x = i * (bsize + space) + offset + space;
button_region[n].j = dest_y + bsize - 1; dest_y = j * (bsize + space) + offset + space;
/* Copy button images for valid apps */ /* Define button mouse coords */
if ( (n + 1) <= NUMB_OF_APPS ) { button_region[n].x = dest_x;
XCopyArea(display, buttons.pixmap, visible.pixmap, gc, button_region[n].y = dest_y;
i * bsize, j * bsize, bsize, bsize, dest_x, dest_y); button_region[n].i = dest_x + bsize - 1;
} button_region[n].j = dest_y + bsize - 1;
}
}
if ( button_pressed>0 ) { /* draw pressed button *charkins*/ /* Copy button images for valid apps */
if(button_pressed>RMASK) button_pressed-=RMASK; if ((n + 1) <= NUMB_OF_APPS)
else if(button_pressed>MMASK) button_pressed-=MMASK; XCopyArea(display, buttons.pixmap, visible.pixmap, gc,
else if(button_pressed>LMASK) button_pressed-=LMASK; i * bsize, j * bsize, bsize, bsize, dest_x, dest_y);
i = (button_pressed-1) % 3; /* get col of button */ }
j = (button_pressed-1) / 3; /* get row of button */ }
dest_x = i * (bsize + space) + offset + space;
dest_y = j * (bsize + space) + offset + space;
XSetForeground(display, gc, bg_pixel);
XDrawLine(display, visible.pixmap, gc,
dest_x+1, dest_y+bsize-1, dest_x+bsize-1, dest_y+bsize-1);
XDrawLine(display, visible.pixmap, gc,
dest_x+bsize-1, dest_y+bsize-1, dest_x+bsize-1, dest_y+1);
XSetForeground(display, gc, fg_pixel);
XDrawLine(display, visible.pixmap, gc,
dest_x, dest_y, dest_x+bsize-2, dest_y);
XDrawLine(display, visible.pixmap, gc,
dest_x, dest_y, dest_x, dest_y+bsize-2);
} /*charkins*/
flush_expose( win ); if (button_pressed > 0) { /* draw pressed button *charkins*/
XCopyArea(display, visible.pixmap, win, gc, 0, 0, if (button_pressed > RMASK)
visible.attributes.width, visible.attributes.height, 0, 0 ); button_pressed -= RMASK;
flush_expose( iconwin ); else if (button_pressed > MMASK)
XCopyArea(display, visible.pixmap, iconwin, gc, 0, 0, button_pressed -= MMASK;
visible.attributes.width, visible.attributes.height, 0, 0 ); else if (button_pressed > LMASK)
button_pressed -= LMASK;
}/***********************************************************************/ i = (button_pressed - 1) % 3; /* get col of button */
j = (button_pressed - 1) / 3; /* get row of button */
dest_x = i * (bsize + space) + offset + space;
dest_y = j * (bsize + space) + offset + space;
XSetForeground(display, gc, bg_pixel);
XDrawLine(display, visible.pixmap, gc,
dest_x + 1, dest_y + bsize - 1,
dest_x + bsize - 1, dest_y + bsize - 1);
XDrawLine(display, visible.pixmap, gc,
dest_x + bsize - 1, dest_y + bsize - 1,
dest_x + bsize - 1, dest_y + 1);
XSetForeground(display, gc, fg_pixel);
XDrawLine(display, visible.pixmap, gc,
dest_x, dest_y, dest_x + bsize - 2, dest_y);
XDrawLine(display, visible.pixmap, gc,
dest_x, dest_y, dest_x, dest_y + bsize - 2);
} /*charkins*/
flush_expose(win);
XCopyArea(display, visible.pixmap, win, gc, 0, 0,
visible.attributes.width, visible.attributes.height, 0, 0);
flush_expose(iconwin);
XCopyArea(display, visible.pixmap, iconwin, gc, 0, 0,
visible.attributes.width, visible.attributes.height, 0, 0);
}
/***********************************************************************/
/*********************************************************************** /***********************************************************************
* whichButton * whichButton
@ -465,19 +478,20 @@ void redraw() {
* Return the button that at the x,y coordinates. The button need not * Return the button that at the x,y coordinates. The button need not
* be visible ( drawn ). Return -1 if no button match. * be visible ( drawn ). Return -1 if no button match.
***********************************************************************/ ***********************************************************************/
int whichButton( int x, int y ) { int whichButton(int x, int y)
int index; {
int index;
for ( index=0; index < NUMB_OF_APPS; index++ ) { for (index = 0; index < NUMB_OF_APPS; index++) {
if ( x >= button_region[index].x && if (x >= button_region[index].x &&
x <= button_region[index].i && x <= button_region[index].i &&
y >= button_region[index].y && y >= button_region[index].y &&
y <= button_region[index].j ) { y <= button_region[index].j)
return( index + 1); return(index + 1);
} }
} return -1;
return(-1); }
}/***********************************************************************/ /***********************************************************************/
/*********************************************************************** /***********************************************************************
@ -491,67 +505,75 @@ int whichButton( int x, int y ) {
* Pixmap buttons holds the images for individual buttons that are * Pixmap buttons holds the images for individual buttons that are
* later copied onto Pixmap visible. * later copied onto Pixmap visible.
***********************************************************************/ ***********************************************************************/
void getPixmaps() { void getPixmaps()
int loaded = 0; {
template.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions); int loaded = 0;
visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions); template.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
buttons.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions); visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
buttons.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
if (Config.Verbose)
fprintf(stdout, "In getPixmaps\n");
if (Config.Verbose) fprintf(stdout, "In getPixmaps\n"); /* Template Pixmap. Never Drawn To. */
/* Template Pixmap. Never Drawn To. */ if (XpmCreatePixmapFromData(display, rootwin, backdrop_xpm,
if ( XpmCreatePixmapFromData( display, rootwin, backdrop_xpm,
&template.pixmap, &template.mask, &template.pixmap, &template.mask,
&template.attributes) != XpmSuccess ) &template.attributes) != XpmSuccess)
err_mess(FAILTMPL, NULL); err_mess(FAILTMPL, NULL);
/* Visible Pixmap. Copied from template Pixmap and then drawn to. */ /* Visible Pixmap. Copied from template Pixmap and then drawn to. */
if ( XpmCreatePixmapFromData( display, rootwin, backdrop_xpm, if (XpmCreatePixmapFromData(display, rootwin, backdrop_xpm,
&visible.pixmap, &visible.mask, &visible.pixmap, &visible.mask,
&visible.attributes) != XpmSuccess ) &visible.attributes) != XpmSuccess)
err_mess(FAILVIS, NULL); err_mess(FAILVIS, NULL);
/* Button Pixmap. */ /* Button Pixmap. */
if ( access( Config.buttonfile, R_OK ) == 0 ) { if (access(Config.buttonfile, R_OK) == 0) {
/* load buttons from file */ /* load buttons from file */
if ( XpmReadFileToPixmap( display, rootwin, Config.buttonfile, if (XpmReadFileToPixmap(display, rootwin, Config.buttonfile,
&buttons.pixmap, &buttons.mask, &buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess ) { &buttons.attributes) != XpmSuccess)
err_mess(FAILBUT, NULL); err_mess(FAILBUT, NULL);
} else { else
loaded = 1; loaded = 1;
} }
}
if (! loaded) {
/* Use Builtin Button Pixmap. */
if (Config.Verbose) fprintf(stdout, "Using builtin buttons pixmap\n");
if ( XpmCreatePixmapFromData( display, rootwin, buttons_xpm,
&buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess )
err_mess(FAILBUT, NULL);
}
if (Config.Verbose) fprintf(stdout, "Leaving getPixmaps\n");
}/*********************************************************************/ if (!loaded) {
/* Use Builtin Button Pixmap. */
if (Config.Verbose)
fprintf(stdout, "Using builtin buttons pixmap\n");
void SetWmHints() { if (XpmCreatePixmapFromData(display, rootwin, buttons_xpm,
XWMHints *xwmhints; &buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess)
err_mess(FAILBUT, NULL);
}
xwmhints = XAllocWMHints(); if (Config.Verbose)
xwmhints->flags = WindowGroupHint | IconWindowHint | StateHint; fprintf(stdout, "Leaving getPixmaps\n");
xwmhints->icon_window = iconwin;
xwmhints->window_group = win; }
xwmhints->initial_state = WithdrawnState; /*********************************************************************/
XSetWMHints( display, win, xwmhints );
void SetWmHints()
{
XWMHints *xwmhints;
xwmhints = XAllocWMHints();
xwmhints->flags = WindowGroupHint | IconWindowHint | StateHint;
xwmhints->icon_window = iconwin;
xwmhints->window_group = win;
xwmhints->initial_state = WithdrawnState;
XSetWMHints(display, win, xwmhints);
XFree(xwmhints); XFree(xwmhints);
xwmhints = NULL; xwmhints = NULL;
} }
void SetClassHints() { void SetClassHints()
XClassHint xclasshint; {
XClassHint xclasshint;
xclasshint.res_name = "wmbutton"; xclasshint.res_name = "wmbutton";
xclasshint.res_class = "Wmbutton"; xclasshint.res_class = "Wmbutton";
XSetClassHint( display, win, &xclasshint ); XSetClassHint(display, win, &xclasshint);
} }