From 6dc4716c2977242374875b7edc1c01c2ee24dafa Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Tue, 19 May 2015 22:30:49 -0500 Subject: [PATCH] wmgeneral: Merge 2003-10-10 version from wmmon and wmtime. Note that this was a fork of the earlier 1998-05-02 version and didn't contain the later changes. Therefore we merge the best of both versions. wmtime had some additional unnecessary dummy variables, so we use the wmmon version. --- wmSMPmon/wmgeneral/wmgeneral.c | 26 +++--- wmckgmail/wmgeneral/wmgeneral.c | 26 +++--- wmcpufreq/wmgeneral/wmgeneral.c | 26 +++--- wmfsm/wmgeneral/wmgeneral.c | 26 +++--- wmifs/wmgeneral/wmgeneral.c | 26 +++--- wmitime/wmgeneral/wmgeneral.c | 26 +++--- wmkeys/wmgeneral/wmgeneral.c | 26 +++--- wmmon/wmgeneral/wmgeneral.c | 125 +++++++++++++++++++++++++--- wmmon/wmgeneral/wmgeneral.h | 11 ++- wmppp.app/wmgeneral/wmgeneral.c | 26 +++--- wmsm.app/wmgeneral/wmgeneral.c | 26 +++--- wmtime/wmgeneral/wmgeneral.c | 141 +++++++++++++++++++++++++++----- wmtime/wmgeneral/wmgeneral.h | 11 ++- wmtz/wmgeneral/wmgeneral.c | 26 +++--- 14 files changed, 393 insertions(+), 155 deletions(-) diff --git a/wmSMPmon/wmgeneral/wmgeneral.c b/wmSMPmon/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmSMPmon/wmgeneral/wmgeneral.c +++ b/wmSMPmon/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmckgmail/wmgeneral/wmgeneral.c b/wmckgmail/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmckgmail/wmgeneral/wmgeneral.c +++ b/wmckgmail/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmcpufreq/wmgeneral/wmgeneral.c b/wmcpufreq/wmgeneral/wmgeneral.c index c064b39..739003d 100755 --- a/wmcpufreq/wmgeneral/wmgeneral.c +++ b/wmcpufreq/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmfsm/wmgeneral/wmgeneral.c b/wmfsm/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmfsm/wmgeneral/wmgeneral.c +++ b/wmfsm/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmifs/wmgeneral/wmgeneral.c b/wmifs/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmifs/wmgeneral/wmgeneral.c +++ b/wmifs/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmitime/wmgeneral/wmgeneral.c b/wmitime/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmitime/wmgeneral/wmgeneral.c +++ b/wmitime/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmkeys/wmgeneral/wmgeneral.c b/wmkeys/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmkeys/wmgeneral/wmgeneral.c +++ b/wmkeys/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmmon/wmgeneral/wmgeneral.c b/wmmon/wmgeneral/wmgeneral.c index b4865bc..739003d 100644 --- a/wmmon/wmgeneral/wmgeneral.c +++ b/wmmon/wmgeneral/wmgeneral.c @@ -14,8 +14,25 @@ --- 10/10/2003 (Simon Law, sfllaw@debian.org) * changed the parse_rcfile function to use getline instead of fgets. + 14/09/1998 (Dave Clark, clarkd@skyia.com) + * Updated createXBMfromXPM routine + * Now supports >256 colors + 11/09/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Removed a bug from parse_rcfile. You could + not use "start" in a command if a label was + also start. + * Changed the needed geometry string. + We don't use window size, and don't support + negative positions. + 03/09/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Added parse_rcfile2 + 02/09/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Added -geometry support (untested) + 28/08/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Added createXBMfromXPM routine + * Saves a lot of work with changing xpm's. 02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl) - * changed the read_rc_file to parse_rcfile, as suggester by Marcelo E. Magallon + * changed the read_rc_file to parse_rcfile, as suggested by Marcelo E. Magallon * debugged the parse_rc file. 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl) * Ripped similar code from all the wm* programs, @@ -23,7 +40,6 @@ */ -#define _GNU_SOURCE #include #include #include @@ -66,7 +82,6 @@ typedef struct { int right; } MOUSE_REGION; -#define MAX_MOUSE_REGION (8) MOUSE_REGION mouse_region[MAX_MOUSE_REGION]; /***********************/ @@ -80,17 +95,53 @@ void AddMouseRegion(int, int, int, int, int); int CheckMouseRegion(int, int); /*******************************************************************************\ -|* read_rc_file *| +|* parse_rcfile *| \*******************************************************************************/ void parse_rcfile(const char *filename, rckeys *keys) { + char *p,*q; + char temp[128]; + char *tokens = " :\t\n"; + FILE *fp; + int i,key; + + fp = fopen(filename, "r"); + if (fp) { + while (fgets(temp, 128, fp)) { + key = 0; + q = strdup(temp); + q = strtok(q, tokens); + while (key >= 0 && keys[key].label) { + if ((!strcmp(q, keys[key].label))) { + p = strstr(temp, keys[key].label); + p += strlen(keys[key].label); + p += strspn(p, tokens); + if ((i = strcspn(p, "#\n"))) p[i] = 0; + free(*keys[key].var); + *keys[key].var = strdup(p); + key = -1; + } else key++; + } + free(q); + } + fclose(fp); + } +} + +/*******************************************************************************\ +|* parse_rcfile2 *| +\*******************************************************************************/ + +void parse_rcfile2(const char *filename, rckeys2 *keys) { + char *p; char *line = NULL; size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; + char *family = NULL; fp = fopen(filename, "r"); if (fp) { @@ -109,6 +160,7 @@ void parse_rcfile(const char *filename, rckeys *keys) { } fclose(fp); } + free(family); } @@ -236,6 +288,54 @@ int CheckMouseRegion(int x, int y) { return (i-1); } +/*******************************************************************************\ +|* createXBMfromXPM *| +\*******************************************************************************/ +void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) { + + int i,j,k; + int width, height, numcol, depth; + int zero=0; + unsigned char bwrite; + int bcount; + int curpixel; + + sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth); + + + for (k=0; k!=depth; k++) + { + zero <<=8; + zero |= xpm[1][k]; + } + + for (i=numcol+1; i < numcol+sy+1; i++) { + bcount = 0; + bwrite = 0; + for (j=0; j>= 1; + + curpixel=0; + for (k=0; k!=depth; k++) + { + curpixel <<=8; + curpixel |= xpm[i][j+k]; + } + + if ( curpixel != zero ) { + bwrite += 128; + } + bcount++; + if (bcount == 8) { + *xbm = bwrite; + xbm++; + bcount = 0; + bwrite = 0; + } + } + } +} + /*******************************************************************************\ |* copyXPMArea *| \*******************************************************************************/ @@ -274,16 +374,16 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit unsigned int borderwidth = 1; XClassHint classHint; char *display_name = NULL; - char *geometry = NULL; char *wname = argv[0]; XTextProperty name; XGCValues gcv; unsigned long gcm; + char *geometry = NULL; int dummy=0; - int i; + int i, wx, wy; for (i=1; argv[i]; i++) { if (!strcmp(argv[i], "-display")) @@ -314,8 +414,7 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit fore_pix = GetColor("black"); XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, - &mysizehints.x, &mysizehints.y, - &mysizehints.width, &mysizehints.height, &dummy); + &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); if (geometry) XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); @@ -374,7 +473,11 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XSetCommand(display, win, argv, argc); XMapWindow(display, win); + if (geometry) { + if (sscanf(geometry, "+%d+%d", &wx, &wy) != 2) { + fprintf(stderr, "Bad geometry string.\n"); + exit(1); + } + XMoveWindow(display, win, wx, wy); + } } - -/* vim: sw=4 ts=4 columns=82 - */ diff --git a/wmmon/wmgeneral/wmgeneral.h b/wmmon/wmgeneral/wmgeneral.h index 55b37dd..e9d6ca6 100644 --- a/wmmon/wmgeneral/wmgeneral.h +++ b/wmmon/wmgeneral/wmgeneral.h @@ -5,7 +5,7 @@ /* Defines */ /***********/ -#define MAX_MOUSE_REGION (8) +#define MAX_MOUSE_REGION (16) /************/ /* Typedefs */ @@ -18,6 +18,14 @@ struct _rckeys { char **var; }; +typedef struct _rckeys2 rckeys2; + +struct _rckeys2 { + const char *family; + const char *label; + char **var; +}; + typedef struct { Pixmap pixmap; Pixmap mask; @@ -41,6 +49,7 @@ void openXwindow(int argc, char *argv[], char **, char *, int, int); void RedrawWindow(void); void RedrawWindowXY(int x, int y); +void createXBMfromXPM(char *, char **, int, int); void copyXPMArea(int, int, int, int, int, int); void copyXBMArea(int, int, int, int, int, int); void setMaskXY(int, int); diff --git a/wmppp.app/wmgeneral/wmgeneral.c b/wmppp.app/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmppp.app/wmgeneral/wmgeneral.c +++ b/wmppp.app/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmsm.app/wmgeneral/wmgeneral.c b/wmsm.app/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmsm.app/wmgeneral/wmgeneral.c +++ b/wmsm.app/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64; diff --git a/wmtime/wmgeneral/wmgeneral.c b/wmtime/wmgeneral/wmgeneral.c index 7e3b508..739003d 100644 --- a/wmtime/wmgeneral/wmgeneral.c +++ b/wmtime/wmgeneral/wmgeneral.c @@ -14,8 +14,25 @@ --- 10/10/2003 (Simon Law, sfllaw@debian.org) * changed the parse_rcfile function to use getline instead of fgets. + 14/09/1998 (Dave Clark, clarkd@skyia.com) + * Updated createXBMfromXPM routine + * Now supports >256 colors + 11/09/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Removed a bug from parse_rcfile. You could + not use "start" in a command if a label was + also start. + * Changed the needed geometry string. + We don't use window size, and don't support + negative positions. + 03/09/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Added parse_rcfile2 + 02/09/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Added -geometry support (untested) + 28/08/1998 (Martijn Pieterse, pieterse@xs4all.nl) + * Added createXBMfromXPM routine + * Saves a lot of work with changing xpm's. 02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl) - * changed the read_rc_file to parse_rcfile, as suggester by Marcelo E. Magallon + * changed the read_rc_file to parse_rcfile, as suggested by Marcelo E. Magallon * debugged the parse_rc file. 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl) * Ripped similar code from all the wm* programs, @@ -23,7 +40,6 @@ */ -#define _GNU_SOURCE #include #include #include @@ -46,11 +62,6 @@ int screen; int x_fd; int d_depth; XSizeHints mysizehints; -/* Deal with strange X11 function prototyping... - * If I don't do this, I will get warnings about the sign - * of the width/height variables - which are thrown away anyway. */ -int dummy_int_width, dummy_int_height; -unsigned int uint_width, uint_height; XWMHints mywmhints; Pixel back_pix, fore_pix; char *Geometry = ""; @@ -71,7 +82,6 @@ typedef struct { int right; } MOUSE_REGION; -#define MAX_MOUSE_REGION (8) MOUSE_REGION mouse_region[MAX_MOUSE_REGION]; /***********************/ @@ -85,17 +95,53 @@ void AddMouseRegion(int, int, int, int, int); int CheckMouseRegion(int, int); /*******************************************************************************\ -|* read_rc_file *| +|* parse_rcfile *| \*******************************************************************************/ void parse_rcfile(const char *filename, rckeys *keys) { + char *p,*q; + char temp[128]; + char *tokens = " :\t\n"; + FILE *fp; + int i,key; + + fp = fopen(filename, "r"); + if (fp) { + while (fgets(temp, 128, fp)) { + key = 0; + q = strdup(temp); + q = strtok(q, tokens); + while (key >= 0 && keys[key].label) { + if ((!strcmp(q, keys[key].label))) { + p = strstr(temp, keys[key].label); + p += strlen(keys[key].label); + p += strspn(p, tokens); + if ((i = strcspn(p, "#\n"))) p[i] = 0; + free(*keys[key].var); + *keys[key].var = strdup(p); + key = -1; + } else key++; + } + free(q); + } + fclose(fp); + } +} + +/*******************************************************************************\ +|* parse_rcfile2 *| +\*******************************************************************************/ + +void parse_rcfile2(const char *filename, rckeys2 *keys) { + char *p; char *line = NULL; size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; + char *family = NULL; fp = fopen(filename, "r"); if (fp) { @@ -114,6 +160,7 @@ void parse_rcfile(const char *filename, rckeys *keys) { } fclose(fp); } + free(family); } @@ -241,6 +288,54 @@ int CheckMouseRegion(int x, int y) { return (i-1); } +/*******************************************************************************\ +|* createXBMfromXPM *| +\*******************************************************************************/ +void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) { + + int i,j,k; + int width, height, numcol, depth; + int zero=0; + unsigned char bwrite; + int bcount; + int curpixel; + + sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth); + + + for (k=0; k!=depth; k++) + { + zero <<=8; + zero |= xpm[1][k]; + } + + for (i=numcol+1; i < numcol+sy+1; i++) { + bcount = 0; + bwrite = 0; + for (j=0; j>= 1; + + curpixel=0; + for (k=0; k!=depth; k++) + { + curpixel <<=8; + curpixel |= xpm[i][j+k]; + } + + if ( curpixel != zero ) { + bwrite += 128; + } + bcount++; + if (bcount == 8) { + *xbm = bwrite; + xbm++; + bcount = 0; + bwrite = 0; + } + } + } +} + /*******************************************************************************\ |* copyXPMArea *| \*******************************************************************************/ @@ -279,16 +374,16 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit unsigned int borderwidth = 1; XClassHint classHint; char *display_name = NULL; - char *geometry = NULL; char *wname = argv[0]; XTextProperty name; XGCValues gcv; unsigned long gcm; + char *geometry = NULL; int dummy=0; - int i; + int i, wx, wy; for (i=1; argv[i]; i++) { if (!strcmp(argv[i], "-display")) @@ -319,21 +414,19 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit fore_pix = GetColor("black"); XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, - &mysizehints.x, &mysizehints.y, - &dummy_int_width, &dummy_int_height, &dummy); + &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); if (geometry) XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, - &uint_width, &uint_height); + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); - /* Override width/height anyway */ - uint_width = 64; - uint_height = 64; + mysizehints.width = 64; + mysizehints.height = 64; win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, - uint_width, uint_height, borderwidth, fore_pix, back_pix); + mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, - uint_width, uint_height, borderwidth, fore_pix, back_pix); + mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); /* Activate hints */ XSetWMNormalHints(display, win, &mysizehints); @@ -380,7 +473,11 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XSetCommand(display, win, argv, argc); XMapWindow(display, win); + if (geometry) { + if (sscanf(geometry, "+%d+%d", &wx, &wy) != 2) { + fprintf(stderr, "Bad geometry string.\n"); + exit(1); + } + XMoveWindow(display, win, wx, wy); + } } - -/* vim: ts=4 columns=82 - */ diff --git a/wmtime/wmgeneral/wmgeneral.h b/wmtime/wmgeneral/wmgeneral.h index 55b37dd..e9d6ca6 100644 --- a/wmtime/wmgeneral/wmgeneral.h +++ b/wmtime/wmgeneral/wmgeneral.h @@ -5,7 +5,7 @@ /* Defines */ /***********/ -#define MAX_MOUSE_REGION (8) +#define MAX_MOUSE_REGION (16) /************/ /* Typedefs */ @@ -18,6 +18,14 @@ struct _rckeys { char **var; }; +typedef struct _rckeys2 rckeys2; + +struct _rckeys2 { + const char *family; + const char *label; + char **var; +}; + typedef struct { Pixmap pixmap; Pixmap mask; @@ -41,6 +49,7 @@ void openXwindow(int argc, char *argv[], char **, char *, int, int); void RedrawWindow(void); void RedrawWindowXY(int x, int y); +void createXBMfromXPM(char *, char **, int, int); void copyXPMArea(int, int, int, int, int, int); void copyXBMArea(int, int, int, int, int, int); void setMaskXY(int, int); diff --git a/wmtz/wmgeneral/wmgeneral.c b/wmtz/wmgeneral/wmgeneral.c index c064b39..739003d 100644 --- a/wmtz/wmgeneral/wmgeneral.c +++ b/wmtz/wmgeneral/wmgeneral.c @@ -11,7 +11,9 @@ --- CHANGES: - --- + --- + 10/10/2003 (Simon Law, sfllaw@debian.org) + * changed the parse_rcfile function to use getline instead of fgets. 14/09/1998 (Dave Clark, clarkd@skyia.com) * Updated createXBMfromXPM routine * Now supports >256 colors @@ -134,7 +136,8 @@ void parse_rcfile(const char *filename, rckeys *keys) { void parse_rcfile2(const char *filename, rckeys2 *keys) { char *p; - char temp[128]; + char *line = NULL; + size_t line_size = 0; char *tokens = " :\t\n"; FILE *fp; int i,key; @@ -142,10 +145,10 @@ void parse_rcfile2(const char *filename, rckeys2 *keys) { fp = fopen(filename, "r"); if (fp) { - while (fgets(temp, 128, fp)) { + while (getline(&line, &line_size, fp) >= 0) { key = 0; while (key >= 0 && keys[key].label) { - if ((p = strstr(temp, keys[key].label))) { + if ((p = strstr(line, keys[key].label))) { p += strlen(keys[key].label); p += strspn(p, tokens); if ((i = strcspn(p, "#\n"))) p[i] = 0; @@ -383,14 +386,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit int i, wx, wy; for (i=1; argv[i]; i++) { - if (!strcmp(argv[i], "-display")) { - display_name = argv[i+1]; - i++; - } - if (!strcmp(argv[i], "-geometry")) { - geometry = argv[i+1]; - i++; - } + if (!strcmp(argv[i], "-display")) + display_name = argv[++i]; + else if (!strcmp(argv[i], "-geometry")) + geometry = argv[++i]; } if (!(display = XOpenDisplay(display_name))) { @@ -416,6 +415,9 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); + if (geometry) + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y, + (unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height); mysizehints.width = 64; mysizehints.height = 64;