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

@ -9,11 +9,11 @@
* Ralf Horstmann <ralf.horstmann@gmx.de> * Ralf Horstmann <ralf.horstmann@gmx.de>
* Added ability to load pixmaps at startup, * Added ability to load pixmaps at startup,
* without having to re-compile * without having to re-compile
* Michael Cohrs <camico@users.sourceforge.net> * Michael Cohrs <camico@users.sourceforge.net>
* Added Tool Tips, and updated graphics * Added Tool Tips, and updated graphics
* Bruno Essmann <essmann@users.sourceforge.net>) * Bruno Essmann <essmann@users.sourceforge.net>)
* Creator of wmpager * Creator of wmpager
* Casey Harkins <charkins@cs.wisc.edu> * Casey Harkins <charkins@cs.wisc.edu>
* Bug fix reading config file path - 3/6/99 * Bug fix reading config file path - 3/6/99
* Added button-presses, and other - denoted by *charkins* * Added button-presses, and other - denoted by *charkins*
* Ben Cohen <buddog@aztec.asu.edu> * Ben Cohen <buddog@aztec.asu.edu>
@ -22,15 +22,15 @@
* contributor to wmcp * contributor to wmcp
* Michael Henderson <mghenderson@lanl.gov> * Michael Henderson <mghenderson@lanl.gov>
* Application ideas, suggestions * Application ideas, suggestions
* Ryan ?? <pancake@mindspring.com> * Ryan ?? <pancake@mindspring.com>
* Modified wmbutton to asbutton. * Modified wmbutton to asbutton.
* Note: asbutton is a seperate program, not associated * Note: asbutton is a seperate program, not associated
* with wmbutton (just as wmbutton is not associated * with wmbutton (just as wmbutton is not associated
* with wmcp) * with wmcp)
* Jon Bruno * Jon Bruno
* Web Page Development * Web Page Development
* The contributors listed above are not necessarily involved with the * The contributors listed above are not necessarily involved with the
* development of wmbutton. I'm listing them here partially as thanks for * development of wmbutton. I'm listing them here partially as thanks for
* helping out, catching bugs in the code, etc. * helping out, catching bugs in the code, etc.
***********************************************************************/ ***********************************************************************/
#include <stdio.h> #include <stdio.h>
@ -47,7 +47,7 @@
#include "mask.xbm" /* Border Graphic */ #include "mask.xbm" /* Border Graphic */
/*************** Function Prototypes ***********************************/ /*************** Function Prototypes ***********************************/
void redraw(void); void redraw(void);
void getPixmaps(void); void getPixmaps(void);
int whichButton(int x, int y); // determine which button has been pressed int whichButton(int x, int y); // determine which button has been pressed
void SetWmHints(); void SetWmHints();
@ -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,375 +89,388 @@ 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 */
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;
/* Parse Command Line Arguments */ /* Open Display */
parseargs(argc, argv); if ((display = XOpenDisplay(Config.Display_str)) == NULL)
err_mess(FAILDISP, Config.Display_str);
/* Open Display */ screen = DefaultScreen(display);
if ( (display = XOpenDisplay(Config.Display_str)) == NULL ) rootwin = RootWindow(display, screen);
err_mess(FAILDISP, Config.Display_str); depth = DefaultDepth(display, screen);
screen = DefaultScreen(display);
rootwin = RootWindow(display,screen);
depth = DefaultDepth(display, screen);
bg_pixel = WhitePixel(display, screen );
fg_pixel = BlackPixel(display, screen );
xsizehints.flags = USSize | USPosition;
xsizehints.width = 64;
xsizehints.height = 64;
/* Parse Geometry string and fill in sizehints fields */
XWMGeometry(display, screen,
Config.Geometry_str,
NULL,
border,
&xsizehints,
&xsizehints.x,
&xsizehints.y,
&xsizehints.width,
&xsizehints.height,
&dummy);
if ( (win = XCreateSimpleWindow(display,
rootwin,
xsizehints.x,
xsizehints.y,
xsizehints.width,
xsizehints.height,
border,
fg_pixel, bg_pixel) ) == 0 )
err_mess(FAILSWIN, NULL);
bg_pixel = WhitePixel(display, screen);
if ( (iconwin = XCreateSimpleWindow(display, fg_pixel = BlackPixel(display, screen);
win,
xsizehints.x,
xsizehints.y,
xsizehints.width,
xsizehints.height,
border,
fg_pixel, bg_pixel) ) == 0 )
err_mess(FAILICON, NULL);
/* Set up shaped windows */ xsizehints.flags = USSize | USPosition;
/*Gives the appicon a border so you can grab and move it. */ xsizehints.width = 64;
xsizehints.height = 64;
if ( ( pixmask = XCreateBitmapFromData(display, /* Parse Geometry string and fill in sizehints fields */
win, XWMGeometry(display, screen,
mask_bits, Config.Geometry_str,
mask_width, NULL,
mask_height) ) == 0 ) border,
err_mess(FAILXPM,NULL); &xsizehints,
&xsizehints.x,
&xsizehints.y,
&xsizehints.width,
&xsizehints.height,
&dummy);
if ((win = XCreateSimpleWindow(display,
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet ); rootwin,
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); xsizehints.x,
xsizehints.y,
xsizehints.width,
xsizehints.height,
border,
fg_pixel, bg_pixel)) == 0)
err_mess(FAILSWIN, NULL);
/* Convert in pixmaps from .xpm includes. */ if ((iconwin = XCreateSimpleWindow(display,
getPixmaps(); win,
xsizehints.x,
xsizehints.y,
xsizehints.width,
xsizehints.height,
border,
fg_pixel, bg_pixel)) == 0)
/* Interclient Communication stuff */ err_mess(FAILICON, NULL);
/* Appicons don't work with out this stuff */
SetWmHints();
SetClassHints();
/* 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);
XSetWMNormalHints( display, win, &xsizehints ); XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
/* 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 )
err_mess(FAILGC,NULL);
/* XEvent Masks. We want both window to process X events */ /* Convert in pixmaps from .xpm includes. */
XSelectInput(display, win, getPixmaps();
ExposureMask |
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 */
XSetCommand( display, win, argv, argc );
/* Window won't ever show up until it is mapped.. then drawn after a */ /* Interclient Communication stuff */
/* ConfigureNotify */ /* Appicons don't work with out this stuff */
XMapWindow( display, win ); SetWmHints();
SetClassHints();
/* Initialize Tooltip Support */ XSetWMNormalHints(display, win, &xsizehints);
initTime();
initTooltip(!Config.bTooltipDisable, Config.szTooltipFont, Config.bTooltipSwapColors);
/* X Event Loop */ /* Tell window manager what the title bar name is. We never see */
while (1) { /* this anyways in the WithdrawnState */
while (XPending(display) || nTooltipTimer == -1) { if (XStringListToTextProperty(&app_name, 1, &app_name_atom) == 0)
XNextEvent(display, &report ); err_mess(FAILWNAM, app_name);
switch (report.type) {
case Expose: XSetWMName(display, win, &app_name_atom);
if (report.xexpose.count != 0) {
break; /* Create Graphic Context */
if ((gc = XCreateGC(display, win, (GCForeground | GCBackground),
&xgcValues)) == NULL)
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);
XSelectInput(display, iconwin,
ExposureMask |
ButtonPressMask |
ButtonReleaseMask | /* added ButtonReleaseMask *charkins*/
PointerMotionMask |
StructureNotifyMask |
LeaveWindowMask);
/* Store the 'state' of the application for restarting */
XSetCommand(display, win, argv, argc);
/* Window won't ever show up until it is mapped.. then drawn after a */
/* ConfigureNotify */
XMapWindow(display, win);
/* Initialize Tooltip Support */
initTime();
initTooltip(!Config.bTooltipDisable, Config.szTooltipFont, Config.bTooltipSwapColors);
/* X Event Loop */
while (1) {
while (XPending(display) || nTooltipTimer == -1) {
XNextEvent(display, &report);
switch (report.type) {
case Expose:
if (report.xexpose.count != 0)
break;
if (Config.Verbose)
fprintf(stdout, "Event: Expose\n");
redraw();
break;
case ConfigureNotify:
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;
}
} }
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
* *
* Map the button region coordinates. * Map the button region coordinates.
* *
* Draw the appropriate number of buttons on the 'visible' Pixmap * Draw the appropriate number of buttons on the 'visible' Pixmap
* using data from the 'buttons' pixmap. * using data from the 'buttons' pixmap.
* *
* Then, copy the 'visible' pixmap to the two windows ( the withdrawn * Then, copy the 'visible' pixmap to the two windows ( the withdrawn
* 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++ ) {
for ( i=0; i < 3; i++ ) {
n = i + j * 3;
dest_x = i*(bsize + space) + offset + space;
dest_y = j*(bsize + space) + offset + space;
/* Define button mouse coords */
button_region[n].x = dest_x;
button_region[n].y = dest_y;
button_region[n].i = dest_x + bsize - 1;
button_region[n].j = dest_y + bsize - 1;
/* Copy button images for valid 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*/ space = 0;
if(button_pressed>RMASK) button_pressed-=RMASK; offset = 5;
else if(button_pressed>MMASK) button_pressed-=MMASK; XCopyArea(display, template.pixmap, visible.pixmap, gc, 0, 0,
else if(button_pressed>LMASK) button_pressed-=LMASK; template.attributes.width, template.attributes.height, 0, 0);
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 );
}/***********************************************************************/ for (j = 0; j < 3; j++) {
for (i = 0; i < 3; i++) {
n = i + j * 3;
dest_x = i * (bsize + space) + offset + space;
dest_y = j * (bsize + space) + offset + space;
/* Define button mouse coords */
button_region[n].x = dest_x;
button_region[n].y = dest_y;
button_region[n].i = dest_x + bsize - 1;
button_region[n].j = dest_y + bsize - 1;
/* Copy button images for valid 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;
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,93 +478,102 @@ 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); }
}/***********************************************************************/ /***********************************************************************/
/*********************************************************************** /***********************************************************************
* getPixmaps * getPixmaps
* *
* Load XPM data into X Pixmaps. * Load XPM data into X Pixmaps.
* *
* Pixmap template contains the untouched window backdrop image. * Pixmap template contains the untouched window backdrop image.
* Pixmap visible is the template pixmap with buttons drawn on it. * Pixmap visible is the template pixmap with buttons drawn on it.
* -- what is seen by the user. * -- what is seen by the user.
* 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)
/* Template Pixmap. Never Drawn To. */ fprintf(stdout, "In getPixmaps\n");
if ( XpmCreatePixmapFromData( display, rootwin, backdrop_xpm,
&template.pixmap, &template.mask,
&template.attributes) != XpmSuccess )
err_mess(FAILTMPL, NULL);
/* Visible Pixmap. Copied from template Pixmap and then drawn to. */ /* Template Pixmap. Never Drawn To. */
if ( XpmCreatePixmapFromData( display, rootwin, backdrop_xpm, if (XpmCreatePixmapFromData(display, rootwin, backdrop_xpm,
&visible.pixmap, &visible.mask, &template.pixmap, &template.mask,
&visible.attributes) != XpmSuccess ) &template.attributes) != XpmSuccess)
err_mess(FAILVIS, NULL); err_mess(FAILTMPL, NULL);
/* Button Pixmap. */
if ( access( Config.buttonfile, R_OK ) == 0 ) {
/* load buttons from file */
if ( XpmReadFileToPixmap( display, rootwin, Config.buttonfile,
&buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess ) {
err_mess(FAILBUT, NULL);
} else {
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");
}/*********************************************************************/ /* Visible Pixmap. Copied from template Pixmap and then drawn to. */
if (XpmCreatePixmapFromData(display, rootwin, backdrop_xpm,
&visible.pixmap, &visible.mask,
&visible.attributes) != XpmSuccess)
err_mess(FAILVIS, NULL);
void SetWmHints() { /* Button Pixmap. */
XWMHints *xwmhints; if (access(Config.buttonfile, R_OK) == 0) {
/* load buttons from file */
if (XpmReadFileToPixmap(display, rootwin, Config.buttonfile,
&buttons.pixmap, &buttons.mask,
&buttons.attributes) != XpmSuccess)
err_mess(FAILBUT, NULL);
else
loaded = 1;
}
xwmhints = XAllocWMHints(); if (!loaded) {
xwmhints->flags = WindowGroupHint | IconWindowHint | StateHint; /* Use Builtin Button Pixmap. */
xwmhints->icon_window = iconwin; if (Config.Verbose)
xwmhints->window_group = win; fprintf(stdout, "Using builtin buttons pixmap\n");
xwmhints->initial_state = WithdrawnState;
XSetWMHints( display, win, xwmhints ); 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");
}
/*********************************************************************/
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);
} }