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
***********************************************************************/
int main( int argc, char ** argv ) {
int main(int argc, char **argv)
{
XEvent report;
XGCValues xgcValues;
XTextProperty app_name_atom;
XSizeHints xsizehints;
Pixmap pixmask;
int dummy = 0;
@ -149,7 +148,6 @@ int main( int argc, char ** argv ) {
fg_pixel, bg_pixel)) == 0)
err_mess(FAILSWIN, NULL);
if ((iconwin = XCreateSimpleWindow(display,
win,
xsizehints.x,
@ -158,11 +156,11 @@ int main( int argc, char ** argv ) {
xsizehints.height,
border,
fg_pixel, bg_pixel)) == 0)
err_mess(FAILICON, NULL);
/* Set up shaped windows */
/* Gives the appicon a border so you can grab and move it. */
if ((pixmask = XCreateBitmapFromData(display,
win,
mask_bits,
@ -170,7 +168,6 @@ int main( int argc, char ** argv ) {
mask_height)) == 0)
err_mess(FAILXPM, NULL);
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
@ -182,18 +179,18 @@ int main( int argc, char ** argv ) {
SetWmHints();
SetClassHints();
XSetWMNormalHints(display, win, &xsizehints);
/* Tell window manager what the title bar name is. We never see */
/* this anyways in the WithdrawnState */
if (XStringListToTextProperty(&app_name, 1, &app_name_atom) == 0)
err_mess(FAILWNAM, app_name);
XSetWMName(display, win, &app_name_atom);
/* Create Graphic Context */
if (( gc = XCreateGC(display, win,(GCForeground | GCBackground), &xgcValues))
== NULL )
if ((gc = XCreateGC(display, win, (GCForeground | GCBackground),
&xgcValues)) == NULL)
err_mess(FAILGC, NULL);
/* XEvent Masks. We want both window to process X events */
@ -204,6 +201,7 @@ int main( int argc, char ** argv ) {
PointerMotionMask |
StructureNotifyMask |
LeaveWindowMask);
XSelectInput(display, iconwin,
ExposureMask |
ButtonPressMask |
@ -227,17 +225,22 @@ int main( int argc, char ** argv ) {
while (1) {
while (XPending(display) || nTooltipTimer == -1) {
XNextEvent(display, &report);
switch (report.type) {
case Expose:
if (report.xexpose.count != 0) {
if (report.xexpose.count != 0)
break;
}
if ( Config.Verbose ) fprintf(stdout,"Event: Expose\n");
if (Config.Verbose)
fprintf(stdout, "Event: Expose\n");
redraw();
break;
case ConfigureNotify:
if ( Config.Verbose ) fprintf(stdout,"Event: ConfigureNotify\n");
if (Config.Verbose)
fprintf(stdout, "Event: ConfigureNotify\n");
redraw();
break;
@ -263,7 +266,9 @@ int main( int argc, char ** argv ) {
break;
case LeaveNotify:
if ( Config.Verbose ) fprintf(stdout,"Event: LeaveNotify\n");
if (Config.Verbose)
fprintf(stdout, "Event: LeaveNotify\n");
if (hasTooltip()) {
hideTooltip();
nTooltipHideTimer = currentTimeMillis();
@ -275,7 +280,9 @@ int main( int argc, char ** argv ) {
if (hasTooltip()) {
hideTooltip();
nTooltipHideTimer = currentTimeMillis();
} switch (report.xbutton.button) {
}
switch (report.xbutton.button) {
case Button1:
N = whichButton(report.xbutton.x, report.xbutton.y);
if ((N >= 0) && (N <= NUMB_OF_APPS)) {
@ -286,8 +293,8 @@ int main( int argc, char ** argv ) {
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);
@ -299,9 +306,9 @@ int main( int argc, char ** argv ) {
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)) {
@ -312,55 +319,58 @@ int main( int argc, char ** argv ) {
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");
case DestroyNotify:
if (Config.Verbose)
fprintf(stdout, "Bye\n");
destroyTooltip();
XFreeGC(display, gc);
@ -375,15 +385,16 @@ int main( int argc, char ** argv ) {
usleep(50000);
nNow = currentTimeMillis();
if (nTooltipTimer != -1 &&
( (nNow > nTooltipTimer + nTooltipShowDelay) || (nNow < nTooltipHideTimer + nTooltipReshowDelay) ) ) {
((nNow > nTooltipTimer + nTooltipShowDelay) ||
(nNow < nTooltipHideTimer + nTooltipReshowDelay))) {
showTooltip(nTooltipButton, nTooltipX, nTooltipY);
nTooltipTimer = -1;
}
}
return (0);
}/***********************************************************************/
}
/***********************************************************************/
/***********************************************************************
* 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.)
***********************************************************************/
void redraw() {
int n;
int i,j;
int dest_x, dest_y;
int space;
int offset;
int bsize = 18;
int n, i, j, dest_x, dest_y, space, offset, bsize = 18;
if (Config.Verbose)
fprintf(stdout, "In Redraw()\n");
if ( Config.Verbose ) fprintf(stdout,"In Redraw()\n");
space = 0;
offset = 5;
XCopyArea(display, template.pixmap, visible.pixmap, gc, 0, 0,
@ -423,26 +431,31 @@ void redraw() {
button_region[n].j = dest_y + bsize - 1;
/* 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,
i * bsize, j * bsize, bsize, bsize, dest_x, dest_y);
}
}
}
if (button_pressed > 0) { /* draw pressed button *charkins*/
if(button_pressed>RMASK) button_pressed-=RMASK;
else if(button_pressed>MMASK) button_pressed-=MMASK;
else if(button_pressed>LMASK) button_pressed-=LMASK;
if (button_pressed > RMASK)
button_pressed -= RMASK;
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 */
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);
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);
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);
@ -456,8 +469,8 @@ void redraw() {
flush_expose(iconwin);
XCopyArea(display, visible.pixmap, iconwin, gc, 0, 0,
visible.attributes.width, visible.attributes.height, 0, 0);
}/***********************************************************************/
}
/***********************************************************************/
/***********************************************************************
* whichButton
@ -465,19 +478,20 @@ void redraw() {
* Return the button that at the x,y coordinates. The button need not
* be visible ( drawn ). Return -1 if no button match.
***********************************************************************/
int whichButton( int x, int y ) {
int whichButton(int x, int y)
{
int index;
for (index = 0; index < NUMB_OF_APPS; index++) {
if (x >= button_region[index].x &&
x <= button_region[index].i &&
y >= button_region[index].y &&
y <= button_region[index].j ) {
y <= button_region[index].j)
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
* later copied onto Pixmap visible.
***********************************************************************/
void getPixmaps() {
void getPixmaps()
{
int loaded = 0;
template.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. */
if (XpmCreatePixmapFromData(display, rootwin, backdrop_xpm,
&template.pixmap, &template.mask,
@ -516,25 +532,31 @@ void getPixmaps() {
/* load buttons from file */
if (XpmReadFileToPixmap(display, rootwin, Config.buttonfile,
&buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess ) {
&buttons.attributes) != XpmSuccess)
err_mess(FAILBUT, NULL);
} else {
else
loaded = 1;
}
}
if (!loaded) {
/* 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,
&buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess)
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 = XAllocWMHints();
@ -547,11 +569,11 @@ void SetWmHints() {
xwmhints = NULL;
}
void SetClassHints() {
void SetClassHints()
{
XClassHint xclasshint;
xclasshint.res_name = "wmbutton";
xclasshint.res_class = "Wmbutton";
XSetClassHint(display, win, &xclasshint);
}