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

@ -89,13 +89,12 @@ char *app_name = "wmbutton";
/*********************************************************************** /***********************************************************************
* Main * Main
***********************************************************************/ ***********************************************************************/
int main( int argc, char ** argv ) { int main(int argc, char **argv)
{
XEvent report; XEvent report;
XGCValues xgcValues; XGCValues xgcValues;
XTextProperty app_name_atom; XTextProperty app_name_atom;
XSizeHints xsizehints; XSizeHints xsizehints;
Pixmap pixmask; Pixmap pixmask;
int dummy = 0; int dummy = 0;
@ -149,7 +148,6 @@ int main( int argc, char ** argv ) {
fg_pixel, bg_pixel)) == 0) fg_pixel, bg_pixel)) == 0)
err_mess(FAILSWIN, NULL); err_mess(FAILSWIN, NULL);
if ((iconwin = XCreateSimpleWindow(display, if ((iconwin = XCreateSimpleWindow(display,
win, win,
xsizehints.x, xsizehints.x,
@ -158,11 +156,11 @@ int main( int argc, char ** argv ) {
xsizehints.height, xsizehints.height,
border, border,
fg_pixel, bg_pixel)) == 0) fg_pixel, bg_pixel)) == 0)
err_mess(FAILICON, NULL); err_mess(FAILICON, NULL);
/* Set up shaped windows */ /* Set up shaped windows */
/* Gives the appicon a border so you can grab and move it. */ /* Gives the appicon a border so you can grab and move it. */
if ((pixmask = XCreateBitmapFromData(display, if ((pixmask = XCreateBitmapFromData(display,
win, win,
mask_bits, mask_bits,
@ -170,7 +168,6 @@ int main( int argc, char ** argv ) {
mask_height)) == 0) mask_height)) == 0)
err_mess(FAILXPM, NULL); err_mess(FAILXPM, NULL);
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet); XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
@ -182,18 +179,18 @@ int main( int argc, char ** argv ) {
SetWmHints(); SetWmHints();
SetClassHints(); SetClassHints();
XSetWMNormalHints(display, win, &xsizehints); XSetWMNormalHints(display, win, &xsizehints);
/* Tell window manager what the title bar name is. We never see */ /* Tell window manager what the title bar name is. We never see */
/* this anyways in the WithdrawnState */ /* this anyways in the WithdrawnState */
if (XStringListToTextProperty(&app_name, 1, &app_name_atom) == 0) if (XStringListToTextProperty(&app_name, 1, &app_name_atom) == 0)
err_mess(FAILWNAM, app_name); err_mess(FAILWNAM, app_name);
XSetWMName(display, win, &app_name_atom); XSetWMName(display, win, &app_name_atom);
/* Create Graphic Context */ /* Create Graphic Context */
if (( gc = XCreateGC(display, win,(GCForeground | GCBackground), &xgcValues)) if ((gc = XCreateGC(display, win, (GCForeground | GCBackground),
== NULL ) &xgcValues)) == NULL)
err_mess(FAILGC, NULL); err_mess(FAILGC, NULL);
/* XEvent Masks. We want both window to process X events */ /* XEvent Masks. We want both window to process X events */
@ -204,6 +201,7 @@ int main( int argc, char ** argv ) {
PointerMotionMask | PointerMotionMask |
StructureNotifyMask | StructureNotifyMask |
LeaveWindowMask); LeaveWindowMask);
XSelectInput(display, iconwin, XSelectInput(display, iconwin,
ExposureMask | ExposureMask |
ButtonPressMask | ButtonPressMask |
@ -227,17 +225,22 @@ int main( int argc, char ** argv ) {
while (1) { while (1) {
while (XPending(display) || nTooltipTimer == -1) { while (XPending(display) || nTooltipTimer == -1) {
XNextEvent(display, &report); XNextEvent(display, &report);
switch (report.type) { switch (report.type) {
case Expose: case Expose:
if (report.xexpose.count != 0) { if (report.xexpose.count != 0)
break; break;
}
if ( Config.Verbose ) fprintf(stdout,"Event: Expose\n"); if (Config.Verbose)
fprintf(stdout, "Event: Expose\n");
redraw(); redraw();
break; break;
case ConfigureNotify: case ConfigureNotify:
if ( Config.Verbose ) fprintf(stdout,"Event: ConfigureNotify\n"); if (Config.Verbose)
fprintf(stdout, "Event: ConfigureNotify\n");
redraw(); redraw();
break; break;
@ -263,7 +266,9 @@ int main( int argc, char ** argv ) {
break; break;
case LeaveNotify: case LeaveNotify:
if ( Config.Verbose ) fprintf(stdout,"Event: LeaveNotify\n"); if (Config.Verbose)
fprintf(stdout, "Event: LeaveNotify\n");
if (hasTooltip()) { if (hasTooltip()) {
hideTooltip(); hideTooltip();
nTooltipHideTimer = currentTimeMillis(); nTooltipHideTimer = currentTimeMillis();
@ -275,7 +280,9 @@ int main( int argc, char ** argv ) {
if (hasTooltip()) { if (hasTooltip()) {
hideTooltip(); hideTooltip();
nTooltipHideTimer = currentTimeMillis(); nTooltipHideTimer = currentTimeMillis();
} switch (report.xbutton.button) { }
switch (report.xbutton.button) {
case Button1: case Button1:
N = whichButton(report.xbutton.x, report.xbutton.y); N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS)) { if ((N >= 0) && (N <= NUMB_OF_APPS)) {
@ -286,8 +293,8 @@ int main( int argc, char ** argv ) {
if (Config.Verbose) if (Config.Verbose)
fprintf(stdout, "Button 1:x=%d y=%d N=%d\n", fprintf(stdout, "Button 1:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+LMASK); report.xbutton.x, report.xbutton.y, N+LMASK);
break; break;
case Button2: case Button2:
if (Config.mmouse) { if (Config.mmouse) {
N = whichButton(report.xbutton.x, report.xbutton.y); N = whichButton(report.xbutton.x, report.xbutton.y);
@ -299,9 +306,9 @@ int main( int argc, char ** argv ) {
if (Config.Verbose) if (Config.Verbose)
fprintf(stdout, "Button 2:x=%d y=%d N=%d\n", fprintf(stdout, "Button 2:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+MMASK); report.xbutton.x, report.xbutton.y, N+MMASK);
} }
break; break;
case Button3: case Button3:
N = whichButton(report.xbutton.x, report.xbutton.y); N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS)) { if ((N >= 0) && (N <= NUMB_OF_APPS)) {
@ -312,55 +319,58 @@ int main( int argc, char ** argv ) {
if (Config.Verbose) if (Config.Verbose)
fprintf(stdout, "Button 3:x=%d y=%d N=%d\n", fprintf(stdout, "Button 3:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+RMASK); report.xbutton.x, report.xbutton.y, N+RMASK);
break; break;
} }
break; break;
case ButtonRelease: /* launch app here if still over button *charkins*/ case ButtonRelease: /* launch app here if still over button *charkins*/
switch (report.xbutton.button) { switch (report.xbutton.button) {
case Button1: case Button1:
N = whichButton(report.xbutton.x, report.xbutton.y); N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed)) if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN(N + LMASK); RunAppN(N + LMASK);
button_pressed = -1; button_pressed = -1;
redraw(); redraw();
if (Config.Verbose) if (Config.Verbose)
fprintf(stdout, "Button 1:x=%d y=%d N=%d\n", fprintf(stdout, "Button 1:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+LMASK); report.xbutton.x, report.xbutton.y, N+LMASK);
break; break;
case Button2: case Button2:
if (Config.mmouse) { if (Config.mmouse) {
N = whichButton(report.xbutton.x, report.xbutton.y); N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed)) if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN(N + MMASK); RunAppN(N + MMASK);
button_pressed = -1; button_pressed = -1;
redraw(); redraw();
if (Config.Verbose) if (Config.Verbose)
fprintf(stdout, "Button 2:x=%d y=%d N=%d\n", fprintf(stdout, "Button 2:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+MMASK); report.xbutton.x, report.xbutton.y, N+MMASK);
} }
break; break;
case Button3: case Button3:
N = whichButton(report.xbutton.x, report.xbutton.y); N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed)) if ((N >= 0) && (N <= NUMB_OF_APPS) && (N == button_pressed))
RunAppN(N + RMASK); RunAppN(N + RMASK);
button_pressed = -1; button_pressed = -1;
redraw(); redraw();
if (Config.Verbose) if (Config.Verbose)
fprintf(stdout, "Button 3:x=%d y=%d N=%d\n", fprintf(stdout, "Button 3:x=%d y=%d N=%d\n",
report.xbutton.x, report.xbutton.y, N+RMASK); report.xbutton.x, report.xbutton.y, N+RMASK);
break; break;
} }
break; break;
case DestroyNotify:
if ( Config.Verbose ) fprintf(stdout, "Bye\n"); case DestroyNotify:
if (Config.Verbose)
fprintf(stdout, "Bye\n");
destroyTooltip(); destroyTooltip();
XFreeGC(display, gc); XFreeGC(display, gc);
@ -375,15 +385,16 @@ int main( int argc, char ** argv ) {
usleep(50000); usleep(50000);
nNow = currentTimeMillis(); nNow = currentTimeMillis();
if (nTooltipTimer != -1 && if (nTooltipTimer != -1 &&
( (nNow > nTooltipTimer + nTooltipShowDelay) || (nNow < nTooltipHideTimer + nTooltipReshowDelay) ) ) { ((nNow > nTooltipTimer + nTooltipShowDelay) ||
(nNow < nTooltipHideTimer + nTooltipReshowDelay))) {
showTooltip(nTooltipButton, nTooltipX, nTooltipY); showTooltip(nTooltipButton, nTooltipX, nTooltipY);
nTooltipTimer = -1; nTooltipTimer = -1;
} }
} }
return (0); return (0);
}/***********************************************************************/ }
/***********************************************************************/
/*********************************************************************** /***********************************************************************
* redraw * redraw
@ -397,14 +408,11 @@ 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; if (Config.Verbose)
int space; fprintf(stdout, "In Redraw()\n");
int offset;
int bsize = 18;
if ( Config.Verbose ) fprintf(stdout,"In Redraw()\n");
space = 0; space = 0;
offset = 5; offset = 5;
XCopyArea(display, template.pixmap, visible.pixmap, gc, 0, 0, XCopyArea(display, template.pixmap, visible.pixmap, gc, 0, 0,
@ -423,26 +431,31 @@ void redraw() {
button_region[n].j = dest_y + bsize - 1; button_region[n].j = dest_y + bsize - 1;
/* Copy button images for valid apps */ /* Copy button images for valid apps */
if ( (n + 1) <= NUMB_OF_APPS ) { if ((n + 1) <= NUMB_OF_APPS)
XCopyArea(display, buttons.pixmap, visible.pixmap, gc, XCopyArea(display, buttons.pixmap, visible.pixmap, gc,
i * bsize, j * bsize, bsize, bsize, dest_x, dest_y); i * bsize, j * bsize, bsize, bsize, dest_x, dest_y);
} }
} }
}
if (button_pressed > 0) { /* draw pressed button *charkins*/ if (button_pressed > 0) { /* draw pressed button *charkins*/
if(button_pressed>RMASK) button_pressed-=RMASK; if (button_pressed > RMASK)
else if(button_pressed>MMASK) button_pressed-=MMASK; button_pressed -= RMASK;
else if(button_pressed>LMASK) button_pressed-=LMASK; else if (button_pressed > MMASK)
button_pressed -= MMASK;
else if (button_pressed > LMASK)
button_pressed -= LMASK;
i = (button_pressed - 1) % 3; /* get col of button */ i = (button_pressed - 1) % 3; /* get col of button */
j = (button_pressed - 1) / 3; /* get row of button */ j = (button_pressed - 1) / 3; /* get row of button */
dest_x = i * (bsize + space) + offset + space; dest_x = i * (bsize + space) + offset + space;
dest_y = j * (bsize + space) + offset + space; dest_y = j * (bsize + space) + offset + space;
XSetForeground(display, gc, bg_pixel); XSetForeground(display, gc, bg_pixel);
XDrawLine(display, visible.pixmap, gc, XDrawLine(display, visible.pixmap, gc,
dest_x+1, dest_y+bsize-1, dest_x+bsize-1, dest_y+bsize-1); dest_x + 1, dest_y + bsize - 1,
dest_x + bsize - 1, dest_y + bsize - 1);
XDrawLine(display, visible.pixmap, gc, XDrawLine(display, visible.pixmap, gc,
dest_x+bsize-1, dest_y+bsize-1, dest_x+bsize-1, dest_y+1); dest_x + bsize - 1, dest_y + bsize - 1,
dest_x + bsize - 1, dest_y + 1);
XSetForeground(display, gc, fg_pixel); XSetForeground(display, gc, fg_pixel);
XDrawLine(display, visible.pixmap, gc, XDrawLine(display, visible.pixmap, gc,
dest_x, dest_y, dest_x + bsize - 2, dest_y); dest_x, dest_y, dest_x + bsize - 2, dest_y);
@ -456,8 +469,8 @@ void redraw() {
flush_expose(iconwin); flush_expose(iconwin);
XCopyArea(display, visible.pixmap, iconwin, gc, 0, 0, XCopyArea(display, visible.pixmap, iconwin, gc, 0, 0,
visible.attributes.width, visible.attributes.height, 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,14 +505,16 @@ 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; int loaded = 0;
template.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions); template.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions); visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
buttons.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,
@ -516,25 +532,31 @@ void getPixmaps() {
/* 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) { if (!loaded) {
/* Use Builtin Button Pixmap. */ /* Use Builtin Button Pixmap. */
if (Config.Verbose) fprintf(stdout, "Using builtin buttons pixmap\n"); if (Config.Verbose)
fprintf(stdout, "Using builtin buttons pixmap\n");
if (XpmCreatePixmapFromData(display, rootwin, buttons_xpm, if (XpmCreatePixmapFromData(display, rootwin, buttons_xpm,
&buttons.pixmap, &buttons.mask, &buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess) &buttons.attributes) != XpmSuccess)
err_mess(FAILBUT, NULL); err_mess(FAILBUT, NULL);
} }
if (Config.Verbose) fprintf(stdout, "Leaving getPixmaps\n");
}/*********************************************************************/ if (Config.Verbose)
fprintf(stdout, "Leaving getPixmaps\n");
void SetWmHints() { }
/*********************************************************************/
void SetWmHints()
{
XWMHints *xwmhints; XWMHints *xwmhints;
xwmhints = XAllocWMHints(); xwmhints = XAllocWMHints();
@ -547,11 +569,11 @@ void SetWmHints() {
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);
} }