2014-10-22 21:34:28 +00:00
|
|
|
/*
|
|
|
|
wmgeneral was taken from wmppp.
|
|
|
|
|
|
|
|
It has a lot of routines which most of the wm* programs use.
|
|
|
|
|
|
|
|
------------------------------------------------------------
|
|
|
|
|
2015-05-20 03:30:53 +00:00
|
|
|
Copyright (C) 1998 Martijn Pieterse (pieterse@xs4all.nl)
|
|
|
|
|
|
|
|
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 the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301, USA.
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
CHANGES:
|
2015-05-20 03:30:49 +00:00
|
|
|
---
|
|
|
|
10/10/2003 (Simon Law, sfllaw@debian.org)
|
2015-05-20 03:30:53 +00:00
|
|
|
* changed the parse_rcfile function to use getline instead of
|
|
|
|
fgets.
|
2015-05-20 03:30:54 +00:00
|
|
|
10/14/2000 (Chris Gray, cgray@tribsoft.com)
|
|
|
|
* Removed a bug from parse_rcfile. An extra
|
|
|
|
newline would cause a segfault.
|
2015-05-20 03:30:53 +00:00
|
|
|
14/09/1998 (Dave Clark, clarkd@skyia.com)
|
|
|
|
* Updated createXBMfromXPM routine
|
|
|
|
* Now supports >256 colors
|
2015-05-20 03:30:47 +00:00
|
|
|
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.
|
2014-10-22 21:34:28 +00:00
|
|
|
02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
|
2015-05-20 03:30:53 +00:00
|
|
|
* changed the read_rc_file to parse_rcfile, as suggested by
|
|
|
|
Marcelo E. Magallon
|
2014-10-22 21:34:28 +00:00
|
|
|
* debugged the parse_rc file.
|
|
|
|
30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
|
|
|
|
* Ripped similar code from all the wm* programs,
|
|
|
|
and put them in a single file.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wmgeneral.h"
|
2015-05-20 03:30:52 +00:00
|
|
|
#include <X11/Xlib.h> /* for XCopyArea, etc */
|
|
|
|
#include <X11/Xutil.h> /* for XSizeHints, XWMHints, etc */
|
|
|
|
#include <X11/extensions/shape.h> /* for XShapeCombineMask */
|
|
|
|
#include <X11/extensions/shapeconst.h> /* for ShapeBounding, ShapeSet */
|
|
|
|
#include <X11/xpm.h> /* for XpmAttributes, Pixel, etc */
|
|
|
|
#include <stddef.h> /* for size_t */
|
|
|
|
#include <stdio.h> /* for fprintf, stderr, NULL, etc */
|
|
|
|
#include <stdlib.h> /* for exit, free */
|
|
|
|
#include <string.h> /* for strcmp, strdup, strcspn, etc */
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
/*****************/
|
|
|
|
/* X11 Variables */
|
|
|
|
/*****************/
|
|
|
|
|
|
|
|
Window Root;
|
|
|
|
int screen;
|
|
|
|
int x_fd;
|
|
|
|
int d_depth;
|
|
|
|
XSizeHints mysizehints;
|
|
|
|
XWMHints mywmhints;
|
|
|
|
Pixel back_pix, fore_pix;
|
|
|
|
char *Geometry = "";
|
|
|
|
Window iconwin, win;
|
|
|
|
GC NormalGC;
|
|
|
|
XpmIcon wmgen;
|
|
|
|
Pixmap pixmask;
|
|
|
|
|
|
|
|
/*****************/
|
|
|
|
/* Mouse Regions */
|
|
|
|
/*****************/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int enable;
|
|
|
|
int top;
|
|
|
|
int bottom;
|
|
|
|
int left;
|
|
|
|
int right;
|
|
|
|
} MOUSE_REGION;
|
|
|
|
|
|
|
|
MOUSE_REGION mouse_region[MAX_MOUSE_REGION];
|
|
|
|
|
|
|
|
/***********************/
|
|
|
|
/* Function Prototypes */
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
static void GetXPM(XpmIcon *, char **);
|
|
|
|
static Pixel GetColor(char *);
|
|
|
|
void RedrawWindow(void);
|
|
|
|
void AddMouseRegion(int, int, int, int, int);
|
|
|
|
int CheckMouseRegion(int, int);
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
2015-05-20 03:30:47 +00:00
|
|
|
|* parse_rcfile *|
|
2014-10-22 21:34:28 +00:00
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
void parse_rcfile(const char *filename, rckeys *keys) {
|
|
|
|
|
2015-05-20 03:30:50 +00:00
|
|
|
char *p;
|
2015-05-20 03:30:47 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (fp) {
|
2015-05-20 03:30:50 +00:00
|
|
|
char temp[128];
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
while (fgets(temp, 128, fp)) {
|
2015-05-20 03:30:50 +00:00
|
|
|
char *q;
|
|
|
|
char *tokens = " :\t\n";
|
|
|
|
int key;
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
key = 0;
|
|
|
|
q = strdup(temp);
|
|
|
|
q = strtok(q, tokens);
|
2015-05-20 03:30:54 +00:00
|
|
|
if(!q)
|
|
|
|
continue;
|
2015-05-20 03:30:47 +00:00
|
|
|
while (key >= 0 && keys[key].label) {
|
|
|
|
if ((!strcmp(q, keys[key].label))) {
|
2015-05-20 03:30:50 +00:00
|
|
|
int i;
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
p = strstr(temp, keys[key].label);
|
|
|
|
p += strlen(keys[key].label);
|
|
|
|
p += strspn(p, tokens);
|
2015-05-20 03:30:54 +00:00
|
|
|
if ((i = strcspn(p, "#\n"))) p[i] = '\0';
|
2015-05-20 03:30:47 +00:00
|
|
|
*keys[key].var = strdup(p);
|
|
|
|
key = -1;
|
|
|
|
} else key++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* parse_rcfile2 *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
|
|
|
void parse_rcfile2(const char *filename, rckeys2 *keys) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
char *p;
|
2015-05-20 03:30:49 +00:00
|
|
|
char *line = NULL;
|
|
|
|
size_t line_size = 0;
|
2014-10-22 21:34:28 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (fp) {
|
2015-05-20 03:30:49 +00:00
|
|
|
while (getline(&line, &line_size, fp) >= 0) {
|
2015-05-20 03:30:50 +00:00
|
|
|
int key;
|
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
key = 0;
|
|
|
|
while (key >= 0 && keys[key].label) {
|
2015-05-20 03:30:49 +00:00
|
|
|
if ((p = strstr(line, keys[key].label))) {
|
2015-05-20 03:30:50 +00:00
|
|
|
char *tokens = " :\t\n";
|
|
|
|
int i;
|
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
p += strlen(keys[key].label);
|
|
|
|
p += strspn(p, tokens);
|
2015-05-20 03:30:47 +00:00
|
|
|
if ((i = strcspn(p, "#\n"))) p[i] = 0;
|
2014-10-22 21:34:28 +00:00
|
|
|
*keys[key].var = strdup(p);
|
|
|
|
key = -1;
|
2015-05-20 03:30:47 +00:00
|
|
|
} else key++;
|
2014-10-22 21:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* GetXPM *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
static void GetXPM(XpmIcon *wmgen, char *pixmap_bytes[]) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
XWindowAttributes attributes;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* For the colormap */
|
|
|
|
XGetWindowAttributes(display, Root, &attributes);
|
|
|
|
|
|
|
|
wmgen->attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
|
|
|
|
|
|
|
|
err = XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen->pixmap),
|
|
|
|
&(wmgen->mask), &(wmgen->attributes));
|
2014-10-22 21:34:41 +00:00
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
if (err != XpmSuccess) {
|
|
|
|
fprintf(stderr, "Not enough free colorcells.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* GetColor *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
static Pixel GetColor(char *name) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
XColor color;
|
|
|
|
XWindowAttributes attributes;
|
|
|
|
|
|
|
|
XGetWindowAttributes(display, Root, &attributes);
|
|
|
|
|
|
|
|
color.pixel = 0;
|
2015-05-20 03:30:47 +00:00
|
|
|
if (!XParseColor(display, attributes.colormap, name, &color)) {
|
2014-10-22 21:34:28 +00:00
|
|
|
fprintf(stderr, "wm.app: can't parse %s.\n", name);
|
2015-05-20 03:30:47 +00:00
|
|
|
} else if (!XAllocColor(display, attributes.colormap, &color)) {
|
2014-10-22 21:34:28 +00:00
|
|
|
fprintf(stderr, "wm.app: can't allocate %s.\n", name);
|
2015-05-20 03:30:47 +00:00
|
|
|
}
|
2014-10-22 21:34:28 +00:00
|
|
|
return color.pixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* flush_expose *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
static int flush_expose(Window w) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
XEvent dummy;
|
|
|
|
int i=0;
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
while (XCheckTypedWindowEvent(display, w, Expose, &dummy))
|
|
|
|
i++;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* RedrawWindow *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
void RedrawWindow(void) {
|
2014-10-22 21:34:41 +00:00
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
flush_expose(iconwin);
|
2014-10-22 21:34:41 +00:00
|
|
|
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
|
2015-05-20 03:30:47 +00:00
|
|
|
0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0);
|
2014-10-22 21:34:28 +00:00
|
|
|
flush_expose(win);
|
|
|
|
XCopyArea(display, wmgen.pixmap, win, NormalGC,
|
2015-05-20 03:30:47 +00:00
|
|
|
0,0, wmgen.attributes.width, wmgen.attributes.height, 0,0);
|
2014-10-22 21:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* RedrawWindowXY *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
void RedrawWindowXY(int x, int y) {
|
2014-10-22 21:34:41 +00:00
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
flush_expose(iconwin);
|
2014-10-22 21:34:41 +00:00
|
|
|
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC,
|
2015-05-20 03:30:47 +00:00
|
|
|
x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0);
|
2014-10-22 21:34:28 +00:00
|
|
|
flush_expose(win);
|
|
|
|
XCopyArea(display, wmgen.pixmap, win, NormalGC,
|
2015-05-20 03:30:47 +00:00
|
|
|
x,y, wmgen.attributes.width, wmgen.attributes.height, 0,0);
|
2014-10-22 21:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* AddMouseRegion *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
void AddMouseRegion(int index, int left, int top, int right, int bottom) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
if (index < MAX_MOUSE_REGION) {
|
|
|
|
mouse_region[index].enable = 1;
|
|
|
|
mouse_region[index].top = top;
|
|
|
|
mouse_region[index].left = left;
|
|
|
|
mouse_region[index].bottom = bottom;
|
|
|
|
mouse_region[index].right = right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* CheckMouseRegion *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
int CheckMouseRegion(int x, int y) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
for (i=0; i<MAX_MOUSE_REGION && !found; i++) {
|
2014-10-22 21:34:28 +00:00
|
|
|
if (mouse_region[i].enable &&
|
|
|
|
x <= mouse_region[i].right &&
|
|
|
|
x >= mouse_region[i].left &&
|
|
|
|
y <= mouse_region[i].bottom &&
|
|
|
|
y >= mouse_region[i].top)
|
|
|
|
found = 1;
|
|
|
|
}
|
2015-05-20 03:30:47 +00:00
|
|
|
if (!found) return -1;
|
2014-10-22 21:34:28 +00:00
|
|
|
return (i-1);
|
|
|
|
}
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
/*******************************************************************************\
|
|
|
|
|* createXBMfromXPM *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
|
|
|
|
|
2015-05-20 03:30:50 +00:00
|
|
|
int i,j,k;
|
|
|
|
int width, height, numcol, depth;
|
|
|
|
int zero=0;
|
|
|
|
int curpixel;
|
2015-05-20 03:30:48 +00:00
|
|
|
|
2015-05-20 03:30:51 +00:00
|
|
|
sscanf(*xpm, "%10d %10d %10d %10d", &width, &height, &numcol, &depth);
|
2015-05-20 03:30:47 +00:00
|
|
|
|
|
|
|
|
2015-05-20 03:30:50 +00:00
|
|
|
for (k=0; k!=depth; k++)
|
|
|
|
{
|
|
|
|
zero <<=8;
|
|
|
|
zero |= xpm[1][k];
|
|
|
|
}
|
2015-05-20 03:30:47 +00:00
|
|
|
|
|
|
|
for (i=numcol+1; i < numcol+sy+1; i++) {
|
2015-05-20 03:30:50 +00:00
|
|
|
unsigned char bwrite;
|
|
|
|
int bcount;
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
bcount = 0;
|
|
|
|
bwrite = 0;
|
2015-05-20 03:30:48 +00:00
|
|
|
for (j=0; j<sx*depth; j+=depth) {
|
2015-05-20 03:30:50 +00:00
|
|
|
bwrite >>= 1;
|
2015-05-20 03:30:48 +00:00
|
|
|
|
2015-05-20 03:30:50 +00:00
|
|
|
curpixel=0;
|
|
|
|
for (k=0; k!=depth; k++)
|
|
|
|
{
|
|
|
|
curpixel <<=8;
|
|
|
|
curpixel |= xpm[i][j+k];
|
|
|
|
}
|
2015-05-20 03:30:48 +00:00
|
|
|
|
2015-05-20 03:30:50 +00:00
|
|
|
if ( curpixel != zero ) {
|
2015-05-20 03:30:47 +00:00
|
|
|
bwrite += 128;
|
|
|
|
}
|
|
|
|
bcount++;
|
|
|
|
if (bcount == 8) {
|
|
|
|
*xbm = bwrite;
|
|
|
|
xbm++;
|
|
|
|
bcount = 0;
|
|
|
|
bwrite = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
/*******************************************************************************\
|
|
|
|
|* copyXPMArea *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* copyXBMArea *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* setMaskXY *|
|
|
|
|
\*******************************************************************************/
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
void setMaskXY(int x, int y) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet);
|
|
|
|
XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************\
|
|
|
|
|* openXwindow *|
|
|
|
|
\*******************************************************************************/
|
2015-05-20 03:30:47 +00:00
|
|
|
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) {
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
unsigned int borderwidth = 1;
|
|
|
|
XClassHint classHint;
|
|
|
|
char *display_name = NULL;
|
|
|
|
char *wname = argv[0];
|
|
|
|
XTextProperty name;
|
|
|
|
|
|
|
|
XGCValues gcv;
|
|
|
|
unsigned long gcm;
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
char *geometry = NULL;
|
2014-10-22 21:34:28 +00:00
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
int dummy=0;
|
|
|
|
int i, wx, wy;
|
2014-10-22 21:34:28 +00:00
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
for (i=1; argv[i]; i++) {
|
2015-05-20 03:30:49 +00:00
|
|
|
if (!strcmp(argv[i], "-display"))
|
|
|
|
display_name = argv[++i];
|
|
|
|
else if (!strcmp(argv[i], "-geometry"))
|
|
|
|
geometry = argv[++i];
|
2014-10-22 21:34:28 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
if (!(display = XOpenDisplay(display_name))) {
|
2014-10-22 21:34:41 +00:00
|
|
|
fprintf(stderr, "%s: can't open display %s\n",
|
2014-10-22 21:34:28 +00:00
|
|
|
wname, XDisplayName(display_name));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
screen = DefaultScreen(display);
|
|
|
|
Root = RootWindow(display, screen);
|
|
|
|
d_depth = DefaultDepth(display, screen);
|
|
|
|
x_fd = XConnectionNumber(display);
|
|
|
|
|
|
|
|
/* Convert XPM to XImage */
|
|
|
|
GetXPM(&wmgen, pixmap_bytes);
|
|
|
|
|
|
|
|
/* Create a window to hold the stuff */
|
|
|
|
mysizehints.flags = USSize | USPosition;
|
|
|
|
mysizehints.x = 0;
|
|
|
|
mysizehints.y = 0;
|
|
|
|
|
|
|
|
back_pix = GetColor("white");
|
|
|
|
fore_pix = GetColor("black");
|
|
|
|
|
|
|
|
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
|
2015-05-20 03:30:47 +00:00
|
|
|
&mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
|
2015-05-20 03:30:49 +00:00
|
|
|
if (geometry)
|
|
|
|
XParseGeometry(geometry, &mysizehints.x, &mysizehints.y,
|
|
|
|
(unsigned int *) &mysizehints.width, (unsigned int *) &mysizehints.height);
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
mysizehints.width = 64;
|
|
|
|
mysizehints.height = 64;
|
2014-10-22 21:34:41 +00:00
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
|
|
|
|
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
|
2014-10-22 21:34:41 +00:00
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
|
|
|
|
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
|
|
|
|
|
|
|
|
/* Activate hints */
|
|
|
|
XSetWMNormalHints(display, win, &mysizehints);
|
|
|
|
classHint.res_name = wname;
|
|
|
|
classHint.res_class = wname;
|
|
|
|
XSetClassHint(display, win, &classHint);
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
|
|
|
|
XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
|
2014-10-22 21:34:28 +00:00
|
|
|
|
|
|
|
if (XStringListToTextProperty(&wname, 1, &name) == 0) {
|
|
|
|
fprintf(stderr, "%s: can't allocate window name\n", wname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
XSetWMName(display, win, &name);
|
|
|
|
|
|
|
|
/* Create GC for drawing */
|
2014-10-22 21:34:41 +00:00
|
|
|
|
2014-10-22 21:34:28 +00:00
|
|
|
gcm = GCForeground | GCBackground | GCGraphicsExposures;
|
|
|
|
gcv.foreground = fore_pix;
|
|
|
|
gcv.background = back_pix;
|
|
|
|
gcv.graphics_exposures = 0;
|
|
|
|
NormalGC = XCreateGC(display, Root, gcm, &gcv);
|
|
|
|
|
|
|
|
/* ONLYSHAPE ON */
|
|
|
|
|
|
|
|
pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height);
|
|
|
|
|
|
|
|
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
|
|
|
|
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
|
|
|
|
|
|
|
|
/* ONLYSHAPE OFF */
|
|
|
|
|
|
|
|
mywmhints.initial_state = WithdrawnState;
|
|
|
|
mywmhints.icon_window = iconwin;
|
|
|
|
mywmhints.icon_x = mysizehints.x;
|
|
|
|
mywmhints.icon_y = mysizehints.y;
|
|
|
|
mywmhints.window_group = win;
|
|
|
|
mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
|
|
|
|
|
|
|
|
XSetWMHints(display, win, &mywmhints);
|
|
|
|
|
|
|
|
XSetCommand(display, win, argv, argc);
|
|
|
|
XMapWindow(display, win);
|
|
|
|
|
2015-05-20 03:30:47 +00:00
|
|
|
if (geometry) {
|
2015-05-20 03:30:51 +00:00
|
|
|
if (sscanf(geometry, "+%10d+%10d", &wx, &wy) != 2) {
|
2015-05-20 03:30:47 +00:00
|
|
|
fprintf(stderr, "Bad geometry string.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
XMoveWindow(display, win, wx, wy);
|
|
|
|
}
|
2014-10-22 21:34:28 +00:00
|
|
|
}
|