wmgeneral: Bump to 1998-09-11 version found in wmcpufreq and wmppp.app.

We update the dockapps with the older 1998-05-02 version (wmfsm, wmifs, and
wmkeys), and also remove trailing whitespace from the wmcpufreq copy.
This commit is contained in:
Doug Torrance 2015-05-19 22:30:47 -05:00 committed by Carlos R. Mafra
parent 7d77c17cc1
commit 6c8c14e710
14 changed files with 601 additions and 282 deletions

View file

@ -1,11 +1,11 @@
/* Generic single linked list to keep various information /* Generic single linked list to keep various information
Copyright (C) 1993, 1994 Free Software Foundation, Inc. Copyright (C) 1993, 1994 Free Software Foundation, Inc.
Author: Kresten Krab Thorup Author: Kresten Krab Thorup
Many modifications by Alfredo K. Kojima Many modifications by Alfredo K. Kojima
This file is part of GNU CC. This file is part of GNU CC.
@ -21,8 +21,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02111-1307, USA. */ Boston, MA 02110-1301 USA. */
/* As a special exception, if you link this library with files compiled with /* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable GCC to produce an executable, this does not cause the resulting executable
@ -63,7 +63,7 @@ list_length(LinkedList* list)
return i; return i;
} }
/* Return the Nth element of LIST, where N count from zero. If N /* Return the Nth element of LIST, where N count from zero. If N
larger than the list length, NULL is returned */ larger than the list length, NULL is returned */
void* void*
@ -84,7 +84,7 @@ list_nth(int index, LinkedList* list)
void void
list_remove_head(LinkedList** list) list_remove_head(LinkedList** list)
{ {
if (!*list) return; if (!*list) return;
if ((*list)->tail) if ((*list)->tail)
{ {
LinkedList* tail = (*list)->tail; /* fetch next */ LinkedList* tail = (*list)->tail; /* fetch next */
@ -116,7 +116,7 @@ LinkedList *
list_remove_elem(LinkedList* list, void* elem) list_remove_elem(LinkedList* list, void* elem)
{ {
LinkedList *tmp; LinkedList *tmp;
if (list) { if (list) {
if (list->head == elem) { if (list->head == elem) {
tmp = list->tail; tmp = list->tail;

View file

@ -1,4 +1,4 @@
/* Generic single linked list to keep various information /* Generic single linked list to keep various information
Copyright (C) 1993, 1994 Free Software Foundation, Inc. Copyright (C) 1993, 1994 Free Software Foundation, Inc.
Author: Kresten Krab Thorup Author: Kresten Krab Thorup
@ -17,8 +17,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, the Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02111-1307, USA. */ Boston, MA 02110-1301 USA. */
/* As a special exception, if you link this library with files compiled with /* As a special exception, if you link this library with files compiled with
GCC to produce an executable, this does not cause the resulting executable GCC to produce an executable, this does not cause the resulting executable

View file

@ -1,9 +1,9 @@
/* dock.c- built-in Dock module for WindowMaker /* dock.c- built-in Dock module for WindowMaker
* *
* WindowMaker window manager * WindowMaker window manager
* *
* Copyright (c) 1997 Alfredo K. Kojima * Copyright (c) 1997 Alfredo K. Kojima
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -29,7 +29,7 @@
*---------------------------------------------------------------------- *----------------------------------------------------------------------
* parse_command-- * parse_command--
* Divides a command line into a argv/argc pair. * Divides a command line into a argv/argc pair.
*---------------------------------------------------------------------- *----------------------------------------------------------------------
*/ */
#define PRC_ALPHA 0 #define PRC_ALPHA 0
#define PRC_BLANK 1 #define PRC_BLANK 1
@ -69,11 +69,11 @@ next_token(char *word, char **next)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ptr = word; ptr = word;
state = 0; state = 0;
*t = 0; *t = 0;
while (1) { while (1) {
if (*ptr==0) if (*ptr==0)
ctype = PRC_EOS; ctype = PRC_EOS;
else if (*ptr=='\\') else if (*ptr=='\\')
ctype = PRC_ESCAPE; ctype = PRC_ESCAPE;
@ -103,12 +103,12 @@ next_token(char *word, char **next)
t = strdup(ret); t = strdup(ret);
free(ret); free(ret);
if (ctype==PRC_EOS) if (ctype==PRC_EOS)
*next = NULL; *next = NULL;
else else
*next = ptr; *next = ptr;
return t; return t;
} }
@ -123,7 +123,7 @@ parse_command(char *command, char ***argv, int *argc)
line = command; line = command;
do { do {
token = next_token(line, &line); token = next_token(line, &line);
if (token) { if (token) {
list = list_cons(token, list); list = list_cons(token, list);
} }
} while (token!=NULL && line!=NULL); } while (token!=NULL && line!=NULL);
@ -146,15 +146,15 @@ execCommand(char *command)
int argc; int argc;
parse_command(command, &argv, &argc); parse_command(command, &argv, &argc);
if (argv==NULL) { if (argv==NULL) {
return 0; return 0;
} }
if ((pid=fork())==0) { if ((pid=fork())==0) {
char **args; char **args;
int i; int i;
args = malloc(sizeof(char*)*(argc+1)); args = malloc(sizeof(char*)*(argc+1));
if (!args) if (!args)
exit(10); exit(10);

View file

@ -14,7 +14,7 @@
--- ---
11/09/1998 (Martijn Pieterse, pieterse@xs4all.nl) 11/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
* Removed a bug from parse_rcfile. You could * Removed a bug from parse_rcfile. You could
not use "start" in a command if a label was not use "start" in a command if a label was
also start. also start.
* Changed the needed geometry string. * Changed the needed geometry string.
We don't use window size, and don't support We don't use window size, and don't support
@ -174,7 +174,7 @@ static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) {
err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen->pixmap), err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen->pixmap),
&(wmgen->mask), &(wmgen->attributes)); &(wmgen->mask), &(wmgen->attributes));
if (err != XpmSuccess) { if (err != XpmSuccess) {
fprintf(stderr, "Not enough free colorcells.\n"); fprintf(stderr, "Not enough free colorcells.\n");
exit(1); exit(1);
@ -221,9 +221,9 @@ static int flush_expose(Window w) {
\*******************************************************************************/ \*******************************************************************************/
void RedrawWindow(void) { void RedrawWindow(void) {
flush_expose(iconwin); flush_expose(iconwin);
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0); 0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0);
flush_expose(win); flush_expose(win);
XCopyArea(display, wmgen.pixmap, win, NormalGC, XCopyArea(display, wmgen.pixmap, win, NormalGC,
@ -235,9 +235,9 @@ void RedrawWindow(void) {
\*******************************************************************************/ \*******************************************************************************/
void RedrawWindowXY(int x, int y) { void RedrawWindowXY(int x, int y) {
flush_expose(iconwin); flush_expose(iconwin);
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0); x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0);
flush_expose(win); flush_expose(win);
XCopyArea(display, wmgen.pixmap, win, NormalGC, XCopyArea(display, wmgen.pixmap, win, NormalGC,
@ -292,7 +292,7 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
char zero; char zero;
unsigned char bwrite; unsigned char bwrite;
int bcount; int bcount;
sscanf(*xpm, "%d %d %d", &width, &height, &numcol); sscanf(*xpm, "%d %d %d", &width, &height, &numcol);
@ -377,7 +377,7 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
} }
if (!(display = XOpenDisplay(display_name))) { if (!(display = XOpenDisplay(display_name))) {
fprintf(stderr, "%s: can't open display %s\n", fprintf(stderr, "%s: can't open display %s\n",
wname, XDisplayName(display_name)); wname, XDisplayName(display_name));
exit(1); exit(1);
} }
@ -402,10 +402,10 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
mysizehints.width = 64; mysizehints.width = 64;
mysizehints.height = 64; mysizehints.height = 64;
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
@ -426,7 +426,7 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
XSetWMName(display, win, &name); XSetWMName(display, win, &name);
/* Create GC for drawing */ /* Create GC for drawing */
gcm = GCForeground | GCBackground | GCGraphicsExposures; gcm = GCForeground | GCBackground | GCGraphicsExposures;
gcv.foreground = fore_pix; gcv.foreground = fore_pix;
gcv.background = back_pix; gcv.background = back_pix;

View file

@ -45,7 +45,7 @@ Display *display;
void AddMouseRegion(int index, int left, int top, int right, int bottom); void AddMouseRegion(int index, int left, int top, int right, int bottom);
int CheckMouseRegion(int x, int y); int CheckMouseRegion(int x, int y);
void openXwindow(int argc, char *argv[],char **,char *, int, int); void openXwindow(int argc, char *argv[], char **, char *, int, int);
void RedrawWindow(void); void RedrawWindow(void);
void RedrawWindowXY(int x, int y); void RedrawWindowXY(int x, int y);

View file

@ -12,8 +12,22 @@
--- ---
CHANGES: CHANGES:
--- ---
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) 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. * debugged the parse_rc file.
30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl) 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
* Ripped similar code from all the wm* programs, * Ripped similar code from all the wm* programs,
@ -63,7 +77,6 @@ typedef struct {
int right; int right;
} MOUSE_REGION; } MOUSE_REGION;
#define MAX_MOUSE_REGION (8)
MOUSE_REGION mouse_region[MAX_MOUSE_REGION]; MOUSE_REGION mouse_region[MAX_MOUSE_REGION];
/***********************/ /***********************/
@ -77,16 +90,52 @@ void AddMouseRegion(int, int, int, int, int);
int CheckMouseRegion(int, int); int CheckMouseRegion(int, int);
/*******************************************************************************\ /*******************************************************************************\
|* read_rc_file *| |* parse_rcfile *|
\*******************************************************************************/ \*******************************************************************************/
void parse_rcfile(const char *filename, rckeys *keys) { 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 *p;
char temp[128]; char temp[128];
char *tokens = " :\t\n"; char *tokens = " :\t\n";
FILE *fp; FILE *fp;
int i,key; int i,key;
char *family = NULL;
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (fp) { if (fp) {
@ -105,6 +154,7 @@ void parse_rcfile(const char *filename, rckeys *keys) {
} }
fclose(fp); fclose(fp);
} }
free(family);
} }
@ -232,6 +282,40 @@ int CheckMouseRegion(int x, int y) {
return (i-1); return (i-1);
} }
/*******************************************************************************\
|* createXBMfromXPM *|
\*******************************************************************************/
void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
int i,j;
int width, height, numcol;
char zero;
unsigned char bwrite;
int bcount;
sscanf(*xpm, "%d %d %d", &width, &height, &numcol);
zero = xpm[1][0];
for (i=numcol+1; i < numcol+sy+1; i++) {
bcount = 0;
bwrite = 0;
for (j=0; j<sx; j++) {
bwrite >>= 1;
if (xpm[i][j] != zero) {
bwrite += 128;
}
bcount++;
if (bcount == 8) {
*xbm = bwrite;
xbm++;
bcount = 0;
bwrite = 0;
}
}
}
}
/*******************************************************************************\ /*******************************************************************************\
|* copyXPMArea *| |* copyXPMArea *|
\*******************************************************************************/ \*******************************************************************************/
@ -276,13 +360,20 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
XGCValues gcv; XGCValues gcv;
unsigned long gcm; unsigned long gcm;
char *geometry = NULL;
int dummy=0; int dummy=0;
int i; int i, wx, wy;
for (i=1; argv[i]; i++) { for (i=1; argv[i]; i++) {
if (!strcmp(argv[i], "-display")) if (!strcmp(argv[i], "-display")) {
display_name = argv[i+1]; display_name = argv[i+1];
i++;
}
if (!strcmp(argv[i], "-geometry")) {
geometry = argv[i+1];
i++;
}
} }
if (!(display = XOpenDisplay(display_name))) { if (!(display = XOpenDisplay(display_name))) {
@ -363,4 +454,11 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
XSetCommand(display, win, argv, argc); XSetCommand(display, win, argv, argc);
XMapWindow(display, win); 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);
}
} }

View file

@ -5,7 +5,7 @@
/* Defines */ /* Defines */
/***********/ /***********/
#define MAX_MOUSE_REGION (8) #define MAX_MOUSE_REGION (16)
/************/ /************/
/* Typedefs */ /* Typedefs */
@ -18,6 +18,14 @@ struct _rckeys {
char **var; char **var;
}; };
typedef struct _rckeys2 rckeys2;
struct _rckeys2 {
const char *family;
const char *label;
char **var;
};
typedef struct { typedef struct {
Pixmap pixmap; Pixmap pixmap;
Pixmap mask; Pixmap mask;
@ -41,6 +49,7 @@ void openXwindow(int argc, char *argv[], char **, char *, int, int);
void RedrawWindow(void); void RedrawWindow(void);
void RedrawWindowXY(int x, int y); void RedrawWindowXY(int x, int y);
void createXBMfromXPM(char *, char **, int, int);
void copyXPMArea(int, int, int, int, int, int); void copyXPMArea(int, int, int, int, int, int);
void copyXBMArea(int, int, int, int, int, int); void copyXBMArea(int, int, int, int, int, int);
void setMaskXY(int, int); void setMaskXY(int, int);

View file

@ -38,117 +38,132 @@ Boston, MA 02110-1301 USA. */
/* Return a cons cell produced from (head . tail) */ /* Return a cons cell produced from (head . tail) */
LinkedList *list_cons(void *head, LinkedList *tail) LinkedList*
list_cons(void* head, LinkedList* tail)
{ {
LinkedList *cell; LinkedList* cell;
cell = (LinkedList *)malloc(sizeof(LinkedList)); cell = (LinkedList*)malloc(sizeof(LinkedList));
cell->head = head; cell->head = head;
cell->tail = tail; cell->tail = tail;
return cell; return cell;
} }
/* Return the length of a list, list_length(NULL) returns zero */ /* Return the length of a list, list_length(NULL) returns zero */
int list_length(LinkedList *list) int
list_length(LinkedList* list)
{ {
int i = 0; int i = 0;
while (list) { while(list)
i += 1; {
list = list->tail; i += 1;
} list = list->tail;
return i; }
return i;
} }
/* Return the Nth element of LIST, where N count from zero. If N /* Return the Nth element of LIST, where N count from zero. If N
larger than the list length, NULL is returned */ larger than the list length, NULL is returned */
void *list_nth(int index, LinkedList *list) void*
list_nth(int index, LinkedList* list)
{ {
while (index-- != 0) { while(index-- != 0)
if (list->tail) {
list = list->tail; if(list->tail)
else list = list->tail;
return 0; else
} return 0;
return list->head; }
return list->head;
} }
/* Remove the element at the head by replacing it by its successor */ /* Remove the element at the head by replacing it by its successor */
void list_remove_head(LinkedList **list) void
list_remove_head(LinkedList** list)
{ {
if (!*list) if (!*list) return;
return; if ((*list)->tail)
if ((*list)->tail) { {
LinkedList *tail = (*list)->tail; /* fetch next */ LinkedList* tail = (*list)->tail; /* fetch next */
*(*list) = *tail; /* copy next to list head */ *(*list) = *tail; /* copy next to list head */
free(tail); /* free next */ free(tail); /* free next */
} else { /* only one element in list */ }
free(*list); else /* only one element in list */
(*list) = 0; {
} free(*list);
(*list) = 0;
}
} }
/* Remove the element with `car' set to ELEMENT */ /* Remove the element with `car' set to ELEMENT */
/* /*
void void
list_remove_elem(LinkedList** list, void* elem) list_remove_elem(LinkedList** list, void* elem)
{
while (*list)
{
if ((*list)->head == elem)
list_remove_head(list);
*list = (*list ? (*list)->tail : NULL);
}
}*/
LinkedList *list_remove_elem(LinkedList *list, void *elem)
{ {
LinkedList *tmp; while (*list)
{
if ((*list)->head == elem)
list_remove_head(list);
*list = (*list ? (*list)->tail : NULL);
}
}*/
if (list) { LinkedList *
if (list->head == elem) { list_remove_elem(LinkedList* list, void* elem)
tmp = list->tail; {
free(list); LinkedList *tmp;
return tmp;
} if (list) {
list->tail = list_remove_elem(list->tail, elem); if (list->head == elem) {
return list; tmp = list->tail;
free(list);
return tmp;
} }
return NULL; list->tail = list_remove_elem(list->tail, elem);
return list;
}
return NULL;
} }
/* Return element that has ELEM as car */ /* Return element that has ELEM as car */
LinkedList *list_find(LinkedList *list, void *elem) LinkedList*
list_find(LinkedList* list, void* elem)
{ {
while (list) { while(list)
if (list->head == elem) {
return list; if (list->head == elem)
list = list->tail; return list;
} list = list->tail;
return NULL; }
return NULL;
} }
/* Free list (backwards recursive) */ /* Free list (backwards recursive) */
void list_free(LinkedList *list) void
list_free(LinkedList* list)
{ {
if (list) { if(list)
list_free(list->tail); {
free(list); list_free(list->tail);
} free(list);
}
} }
/* Map FUNCTION over all elements in LIST */ /* Map FUNCTION over all elements in LIST */
void list_mapcar(LinkedList *list, void(*function)(void *)) void
list_mapcar(LinkedList* list, void(*function)(void*))
{ {
while (list) { while(list)
(*function)(list->head); {
list = list->tail; (*function)(list->head);
} list = list->tail;
}
} }

View file

@ -30,24 +30,24 @@ Boston, MA 02110-1301 USA. */
#define __LIST_H_ #define __LIST_H_
typedef struct LinkedList { typedef struct LinkedList {
void *head; void *head;
struct LinkedList *tail; struct LinkedList *tail;
} LinkedList; } LinkedList;
LinkedList *list_cons(void *head, LinkedList *tail); LinkedList* list_cons(void* head, LinkedList* tail);
int list_length(LinkedList *list); int list_length(LinkedList* list);
void *list_nth(int index, LinkedList *list); void* list_nth(int index, LinkedList* list);
void list_remove_head(LinkedList **list); void list_remove_head(LinkedList** list);
LinkedList *list_remove_elem(LinkedList *list, void *elem); LinkedList *list_remove_elem(LinkedList* list, void* elem);
void list_mapcar(LinkedList *list, void(*function)(void *)); void list_mapcar(LinkedList* list, void(*function)(void*));
LinkedList *list_find(LinkedList *list, void *elem); LinkedList*list_find(LinkedList* list, void* elem);
void list_free(LinkedList *list); void list_free(LinkedList* list);
#endif #endif

View file

@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -28,7 +28,7 @@
/* /*
*---------------------------------------------------------------------- *----------------------------------------------------------------------
* parse_command-- * parse_command--
* Divides a command line into a argv/argc pair. * Divides a command line into a argv/argc pair.
*---------------------------------------------------------------------- *----------------------------------------------------------------------
*/ */
#define PRC_ALPHA 0 #define PRC_ALPHA 0
@ -39,129 +39,132 @@
#define PRC_SQUOTE 5 #define PRC_SQUOTE 5
typedef struct { typedef struct {
short nstate; short nstate;
short output; short output;
} DFA; } DFA;
static DFA mtable[9][6] = { static DFA mtable[9][6] = {
{{3, 1}, {0, 0}, {4, 0}, {1, 0}, {8, 0}, {6, 0} }, {{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
{{1, 1}, {1, 1}, {2, 0}, {3, 0}, {5, 0}, {1, 1} }, {{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
{{1, 1}, {1, 1}, {1, 1}, {1, 1}, {5, 0}, {1, 1} }, {{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
{{3, 1}, {5, 0}, {4, 0}, {1, 0}, {5, 0}, {6, 0} }, {{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
{{3, 1}, {3, 1}, {3, 1}, {3, 1}, {5, 0}, {3, 1} }, {{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} }, /* final state */ {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
{{6, 1}, {6, 1}, {7, 0}, {6, 1}, {5, 0}, {3, 0} }, {{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
{{6, 1}, {6, 1}, {6, 1}, {6, 1}, {5, 0}, {6, 1} }, {{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} } /* final state */ {{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
}; };
char* char*
next_token(char *word, char **next) next_token(char *word, char **next)
{ {
char *ptr; char *ptr;
char *ret, *t; char *ret, *t;
int state, ctype; int state, ctype;
t = ret = malloc(strlen(word)+1); t = ret = malloc(strlen(word)+1);
if (ret == NULL) { if (ret == NULL) {
fprintf(stderr, "Insufficient memory.\n"); fprintf(stderr, "Insufficient memory.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ptr = word; ptr = word;
state = 0; state = 0;
*t = 0; *t = 0;
while (1) { while (1) {
if (*ptr == 0) if (*ptr==0)
ctype = PRC_EOS; ctype = PRC_EOS;
else if (*ptr == '\\') else if (*ptr=='\\')
ctype = PRC_ESCAPE; ctype = PRC_ESCAPE;
else if (*ptr == '"') else if (*ptr=='"')
ctype = PRC_DQUOTE; ctype = PRC_DQUOTE;
else if (*ptr == '\'') else if (*ptr=='\'')
ctype = PRC_SQUOTE; ctype = PRC_SQUOTE;
else if (*ptr == ' ' || *ptr == '\t') else if (*ptr==' ' || *ptr=='\t')
ctype = PRC_BLANK; ctype = PRC_BLANK;
else
ctype = PRC_ALPHA;
if (mtable[state][ctype].output) {
*t = *ptr; t++;
*t = 0;
}
state = mtable[state][ctype].nstate;
ptr++;
if (mtable[state][0].output < 0)
break;
}
if (*ret == 0)
t = NULL;
else else
t = strdup(ret); ctype = PRC_ALPHA;
free(ret); if (mtable[state][ctype].output) {
*t = *ptr; t++;
*t = 0;
}
state = mtable[state][ctype].nstate;
ptr++;
if (mtable[state][0].output<0) {
break;
}
}
if (ctype == PRC_EOS) if (*ret==0)
*next = NULL; t = NULL;
else else
*next = ptr; t = strdup(ret);
return t; free(ret);
if (ctype==PRC_EOS)
*next = NULL;
else
*next = ptr;
return t;
} }
extern void extern void
parse_command(char *command, char ***argv, int *argc) parse_command(char *command, char ***argv, int *argc)
{ {
LinkedList *list = NULL; LinkedList *list = NULL;
char *token, *line; char *token, *line;
int count, i; int count, i;
line = command; line = command;
do { do {
token = next_token(line, &line); token = next_token(line, &line);
if (token) if (token) {
list = list_cons(token, list); list = list_cons(token, list);
} while (token != NULL && line != NULL);
count = list_length(list);
*argv = malloc(sizeof(char *)*count);
i = count;
while (list != NULL) {
(*argv)[--i] = list->head;
list_remove_head(&list);
} }
*argc = count; } while (token!=NULL && line!=NULL);
count = list_length(list);
*argv = malloc(sizeof(char*)*count);
i = count;
while (list!=NULL) {
(*argv)[--i] = list->head;
list_remove_head(&list);
}
*argc = count;
} }
extern pid_t extern pid_t
execCommand(char *command) execCommand(char *command)
{ {
pid_t pid; pid_t pid;
char **argv; char **argv;
int argc; int argc;
parse_command(command, &argv, &argc); parse_command(command, &argv, &argc);
if (argv == NULL) if (argv==NULL) {
return 0; return 0;
}
pid = fork(); if ((pid=fork())==0) {
if (pid == 0) { char **args;
char **args; int i;
int i;
args = malloc(sizeof(char *)*(argc+1)); args = malloc(sizeof(char*)*(argc+1));
if (!args) if (!args)
exit(10); exit(10);
for (i = 0; i < argc; i++) for (i=0; i<argc; i++) {
args[i] = argv[i]; args[i] = argv[i];
args[argc] = NULL; }
execvp(argv[0], args); args[argc] = NULL;
exit(10); execvp(argv[0], args);
} exit(10);
free(argv); }
return pid; free(argv);
return pid;
} }

View file

@ -12,8 +12,22 @@
--- ---
CHANGES: CHANGES:
--- ---
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) 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. * debugged the parse_rc file.
30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl) 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
* Ripped similar code from all the wm* programs, * Ripped similar code from all the wm* programs,
@ -63,7 +77,6 @@ typedef struct {
int right; int right;
} MOUSE_REGION; } MOUSE_REGION;
#define MAX_MOUSE_REGION (8)
MOUSE_REGION mouse_region[MAX_MOUSE_REGION]; MOUSE_REGION mouse_region[MAX_MOUSE_REGION];
/***********************/ /***********************/
@ -77,39 +90,71 @@ void AddMouseRegion(int, int, int, int, int);
int CheckMouseRegion(int, int); int CheckMouseRegion(int, int);
/*******************************************************************************\ /*******************************************************************************\
|* read_rc_file *| |* parse_rcfile *|
\*******************************************************************************/ \*******************************************************************************/
void parse_rcfile(const char *filename, rckeys *keys) 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 *p;
char temp[128]; char temp[128];
char *tokens = " :\t\n"; char *tokens = " :\t\n";
FILE *fp; FILE *fp;
int i, key; int i,key;
char *family = NULL;
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (fp) { if (fp) {
while (fgets(temp, 128, fp)) { while (fgets(temp, 128, fp)) {
key = 0; key = 0;
while (key >= 0 && keys[key].label) { while (key >= 0 && keys[key].label) {
p = strstr(temp, keys[key].label); if ((p = strstr(temp, keys[key].label))) {
if (p) {
p += strlen(keys[key].label); p += strlen(keys[key].label);
p += strspn(p, tokens); p += strspn(p, tokens);
i = strcspn(p, "#\n"); if ((i = strcspn(p, "#\n"))) p[i] = 0;
if (i)
p[i] = 0;
free(*keys[key].var); free(*keys[key].var);
*keys[key].var = strdup(p); *keys[key].var = strdup(p);
key = -1; key = -1;
} else } else key++;
key++;
} }
} }
fclose(fp); fclose(fp);
} }
free(family);
} }
@ -117,8 +162,7 @@ void parse_rcfile(const char *filename, rckeys *keys)
|* GetXPM *| |* GetXPM *|
\*******************************************************************************/ \*******************************************************************************/
static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) {
{
XWindowAttributes attributes; XWindowAttributes attributes;
int err; int err;
@ -141,8 +185,7 @@ static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[])
|* GetColor *| |* GetColor *|
\*******************************************************************************/ \*******************************************************************************/
static Pixel GetColor(char *name) static Pixel GetColor(char *name) {
{
XColor color; XColor color;
XWindowAttributes attributes; XWindowAttributes attributes;
@ -150,10 +193,11 @@ static Pixel GetColor(char *name)
XGetWindowAttributes(display, Root, &attributes); XGetWindowAttributes(display, Root, &attributes);
color.pixel = 0; color.pixel = 0;
if (!XParseColor(display, attributes.colormap, name, &color)) if (!XParseColor(display, attributes.colormap, name, &color)) {
fprintf(stderr, "wm.app: can't parse %s.\n", name); fprintf(stderr, "wm.app: can't parse %s.\n", name);
else if (!XAllocColor(display, attributes.colormap, &color)) } else if (!XAllocColor(display, attributes.colormap, &color)) {
fprintf(stderr, "wm.app: can't allocate %s.\n", name); fprintf(stderr, "wm.app: can't allocate %s.\n", name);
}
return color.pixel; return color.pixel;
} }
@ -161,11 +205,10 @@ static Pixel GetColor(char *name)
|* flush_expose *| |* flush_expose *|
\*******************************************************************************/ \*******************************************************************************/
static int flush_expose(Window w) static int flush_expose(Window w) {
{
XEvent dummy; XEvent dummy;
int i = 0; int i=0;
while (XCheckTypedWindowEvent(display, w, Expose, &dummy)) while (XCheckTypedWindowEvent(display, w, Expose, &dummy))
i++; i++;
@ -177,38 +220,35 @@ static int flush_expose(Window w)
|* RedrawWindow *| |* RedrawWindow *|
\*******************************************************************************/ \*******************************************************************************/
void RedrawWindow(void) void RedrawWindow(void) {
{
flush_expose(iconwin); flush_expose(iconwin);
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
0, 0, wmgen.attributes.width, wmgen.attributes.height, 0, 0); 0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0);
flush_expose(win); flush_expose(win);
XCopyArea(display, wmgen.pixmap, win, NormalGC, XCopyArea(display, wmgen.pixmap, win, NormalGC,
0, 0, wmgen.attributes.width, wmgen.attributes.height, 0, 0); 0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0);
} }
/*******************************************************************************\ /*******************************************************************************\
|* RedrawWindowXY *| |* RedrawWindowXY *|
\*******************************************************************************/ \*******************************************************************************/
void RedrawWindowXY(int x, int y) void RedrawWindowXY(int x, int y) {
{
flush_expose(iconwin); flush_expose(iconwin);
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
x, y, wmgen.attributes.width, wmgen.attributes.height, 0, 0); x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0);
flush_expose(win); flush_expose(win);
XCopyArea(display, wmgen.pixmap, win, NormalGC, XCopyArea(display, wmgen.pixmap, win, NormalGC,
x, y, wmgen.attributes.width, wmgen.attributes.height, 0, 0); x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0);
} }
/*******************************************************************************\ /*******************************************************************************\
|* AddMouseRegion *| |* AddMouseRegion *|
\*******************************************************************************/ \*******************************************************************************/
void AddMouseRegion(int index, int left, int top, int right, int bottom) void AddMouseRegion(int index, int left, int top, int right, int bottom) {
{
if (index < MAX_MOUSE_REGION) { if (index < MAX_MOUSE_REGION) {
mouse_region[index].enable = 1; mouse_region[index].enable = 1;
@ -223,15 +263,14 @@ void AddMouseRegion(int index, int left, int top, int right, int bottom)
|* CheckMouseRegion *| |* CheckMouseRegion *|
\*******************************************************************************/ \*******************************************************************************/
int CheckMouseRegion(int x, int y) int CheckMouseRegion(int x, int y) {
{
int i; int i;
int found; int found;
found = 0; found = 0;
for (i = 0; i < MAX_MOUSE_REGION && !found; i++) { for (i=0; i<MAX_MOUSE_REGION && !found; i++) {
if (mouse_region[i].enable && if (mouse_region[i].enable &&
x <= mouse_region[i].right && x <= mouse_region[i].right &&
x >= mouse_region[i].left && x >= mouse_region[i].left &&
@ -239,17 +278,49 @@ int CheckMouseRegion(int x, int y)
y >= mouse_region[i].top) y >= mouse_region[i].top)
found = 1; found = 1;
} }
if (!found) if (!found) return -1;
return -1;
return (i-1); return (i-1);
} }
/*******************************************************************************\
|* createXBMfromXPM *|
\*******************************************************************************/
void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
int i,j;
int width, height, numcol;
char zero;
unsigned char bwrite;
int bcount;
sscanf(*xpm, "%d %d %d", &width, &height, &numcol);
zero = xpm[1][0];
for (i=numcol+1; i < numcol+sy+1; i++) {
bcount = 0;
bwrite = 0;
for (j=0; j<sx; j++) {
bwrite >>= 1;
if (xpm[i][j] != zero) {
bwrite += 128;
}
bcount++;
if (bcount == 8) {
*xbm = bwrite;
xbm++;
bcount = 0;
bwrite = 0;
}
}
}
}
/*******************************************************************************\ /*******************************************************************************\
|* copyXPMArea *| |* copyXPMArea *|
\*******************************************************************************/ \*******************************************************************************/
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) {
{
XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
@ -259,8 +330,7 @@ void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy)
|* copyXBMArea *| |* copyXBMArea *|
\*******************************************************************************/ \*******************************************************************************/
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) {
{
XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
} }
@ -270,8 +340,7 @@ void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy)
|* setMaskXY *| |* setMaskXY *|
\*******************************************************************************/ \*******************************************************************************/
void setMaskXY(int x, int y) void setMaskXY(int x, int y) {
{
XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet); XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet); XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet);
@ -280,9 +349,7 @@ void setMaskXY(int x, int y)
/*******************************************************************************\ /*******************************************************************************\
|* openXwindow *| |* openXwindow *|
\*******************************************************************************/ \*******************************************************************************/
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) {
char *pixmask_bits, int pixmask_width, int pixmask_height)
{
unsigned int borderwidth = 1; unsigned int borderwidth = 1;
XClassHint classHint; XClassHint classHint;
@ -293,17 +360,23 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[],
XGCValues gcv; XGCValues gcv;
unsigned long gcm; unsigned long gcm;
char *geometry = NULL;
int dummy = 0; int dummy=0;
int i; int i, wx, wy;
for (i = 1; argv[i]; i++) { for (i=1; argv[i]; i++) {
if (!strcmp(argv[i], "-display")) if (!strcmp(argv[i], "-display")) {
display_name = argv[i+1]; display_name = argv[i+1];
i++;
}
if (!strcmp(argv[i], "-geometry")) {
geometry = argv[i+1];
i++;
}
} }
display = XOpenDisplay(display_name); if (!(display = XOpenDisplay(display_name))) {
if (!display) {
fprintf(stderr, "%s: can't open display %s\n", fprintf(stderr, "%s: can't open display %s\n",
wname, XDisplayName(display_name)); wname, XDisplayName(display_name));
exit(1); exit(1);
@ -325,7 +398,7 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[],
fore_pix = GetColor("black"); fore_pix = GetColor("black");
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, 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);
mysizehints.width = 64; mysizehints.width = 64;
mysizehints.height = 64; mysizehints.height = 64;
@ -342,10 +415,8 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[],
classHint.res_class = wname; classHint.res_class = wname;
XSetClassHint(display, win, &classHint); XSetClassHint(display, win, &classHint);
XSelectInput(display, win, XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask); XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
XSelectInput(display, iconwin,
ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
if (XStringListToTextProperty(&wname, 1, &name) == 0) { if (XStringListToTextProperty(&wname, 1, &name) == 0) {
fprintf(stderr, "%s: can't allocate window name\n", wname); fprintf(stderr, "%s: can't allocate window name\n", wname);
@ -383,4 +454,11 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[],
XSetCommand(display, win, argv, argc); XSetCommand(display, win, argv, argc);
XMapWindow(display, win); 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);
}
} }

View file

@ -5,7 +5,7 @@
/* Defines */ /* Defines */
/***********/ /***********/
#define MAX_MOUSE_REGION (8) #define MAX_MOUSE_REGION (16)
/************/ /************/
/* Typedefs */ /* Typedefs */
@ -18,6 +18,14 @@ struct _rckeys {
char **var; char **var;
}; };
typedef struct _rckeys2 rckeys2;
struct _rckeys2 {
const char *family;
const char *label;
char **var;
};
typedef struct { typedef struct {
Pixmap pixmap; Pixmap pixmap;
Pixmap mask; Pixmap mask;
@ -41,6 +49,7 @@ void openXwindow(int argc, char *argv[], char **, char *, int, int);
void RedrawWindow(void); void RedrawWindow(void);
void RedrawWindowXY(int x, int y); void RedrawWindowXY(int x, int y);
void createXBMfromXPM(char *, char **, int, int);
void copyXPMArea(int, int, int, int, int, int); void copyXPMArea(int, int, int, int, int, int);
void copyXBMArea(int, int, int, int, int, int); void copyXBMArea(int, int, int, int, int, int);
void setMaskXY(int, int); void setMaskXY(int, int);

View file

@ -12,8 +12,22 @@
--- ---
CHANGES: CHANGES:
--- ---
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) 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. * debugged the parse_rc file.
30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl) 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
* Ripped similar code from all the wm* programs, * Ripped similar code from all the wm* programs,
@ -63,7 +77,6 @@ typedef struct {
int right; int right;
} MOUSE_REGION; } MOUSE_REGION;
#define MAX_MOUSE_REGION (8)
MOUSE_REGION mouse_region[MAX_MOUSE_REGION]; MOUSE_REGION mouse_region[MAX_MOUSE_REGION];
/***********************/ /***********************/
@ -77,16 +90,52 @@ void AddMouseRegion(int, int, int, int, int);
int CheckMouseRegion(int, int); int CheckMouseRegion(int, int);
/*******************************************************************************\ /*******************************************************************************\
|* read_rc_file *| |* parse_rcfile *|
\*******************************************************************************/ \*******************************************************************************/
void parse_rcfile(const char *filename, rckeys *keys) { 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 *p;
char temp[128]; char temp[128];
char *tokens = " :\t\n"; char *tokens = " :\t\n";
FILE *fp; FILE *fp;
int i,key; int i,key;
char *family = NULL;
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (fp) { if (fp) {
@ -105,6 +154,7 @@ void parse_rcfile(const char *filename, rckeys *keys) {
} }
fclose(fp); fclose(fp);
} }
free(family);
} }
@ -232,6 +282,40 @@ int CheckMouseRegion(int x, int y) {
return (i-1); return (i-1);
} }
/*******************************************************************************\
|* createXBMfromXPM *|
\*******************************************************************************/
void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
int i,j;
int width, height, numcol;
char zero;
unsigned char bwrite;
int bcount;
sscanf(*xpm, "%d %d %d", &width, &height, &numcol);
zero = xpm[1][0];
for (i=numcol+1; i < numcol+sy+1; i++) {
bcount = 0;
bwrite = 0;
for (j=0; j<sx; j++) {
bwrite >>= 1;
if (xpm[i][j] != zero) {
bwrite += 128;
}
bcount++;
if (bcount == 8) {
*xbm = bwrite;
xbm++;
bcount = 0;
bwrite = 0;
}
}
}
}
/*******************************************************************************\ /*******************************************************************************\
|* copyXPMArea *| |* copyXPMArea *|
\*******************************************************************************/ \*******************************************************************************/
@ -276,13 +360,20 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
XGCValues gcv; XGCValues gcv;
unsigned long gcm; unsigned long gcm;
char *geometry = NULL;
int dummy=0; int dummy=0;
int i; int i, wx, wy;
for (i=1; argv[i]; i++) { for (i=1; argv[i]; i++) {
if (!strcmp(argv[i], "-display")) if (!strcmp(argv[i], "-display")) {
display_name = argv[i+1]; display_name = argv[i+1];
i++;
}
if (!strcmp(argv[i], "-geometry")) {
geometry = argv[i+1];
i++;
}
} }
if (!(display = XOpenDisplay(display_name))) { if (!(display = XOpenDisplay(display_name))) {
@ -363,4 +454,11 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
XSetCommand(display, win, argv, argc); XSetCommand(display, win, argv, argc);
XMapWindow(display, win); 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);
}
} }

View file

@ -5,7 +5,7 @@
/* Defines */ /* Defines */
/***********/ /***********/
#define MAX_MOUSE_REGION (8) #define MAX_MOUSE_REGION (16)
/************/ /************/
/* Typedefs */ /* Typedefs */
@ -18,6 +18,14 @@ struct _rckeys {
char **var; char **var;
}; };
typedef struct _rckeys2 rckeys2;
struct _rckeys2 {
const char *family;
const char *label;
char **var;
};
typedef struct { typedef struct {
Pixmap pixmap; Pixmap pixmap;
Pixmap mask; Pixmap mask;
@ -41,6 +49,7 @@ void openXwindow(int argc, char *argv[], char **, char *, int, int);
void RedrawWindow(void); void RedrawWindow(void);
void RedrawWindowXY(int x, int y); void RedrawWindowXY(int x, int y);
void createXBMfromXPM(char *, char **, int, int);
void copyXPMArea(int, int, int, int, int, int); void copyXPMArea(int, int, int, int, int, int);
void copyXBMArea(int, int, int, int, int, int); void copyXBMArea(int, int, int, int, int, int);
void setMaskXY(int, int); void setMaskXY(int, int);