4 Best viewed with vim5, using ts=4
6 wmgeneral was taken from wmppp.
8 It has a lot of routines which most of the wm* programs use.
10 ------------------------------------------------------------
12 Author: Martijn Pieterse (pieterse@xs4all.nl)
17 15/08/2002 (Brad Jorsch, anomie@users.sourceforge.net)
18 * Pulled createXBMfromXPM into its own file, because it's the same in
21 11/08/2002 (Brad Jorsch, anomie@users.sourceforge.net)
22 * Removed the rc-file and mouse region stuff to their own files.
23 * Renamed this file to "wmgeneral-x11.c"
24 * Renamed a few of the functions
26 28/08/2001 (Brad Jorsch, anomie@users.sourceforge.net)
27 * Added EnableMouseRegion and DisableMouseRegion
28 * Got annoyed with the 81-character lines. Fixed it. If you don't like
29 it, find a different copy of wmgeneral.c ;)
30 * GraphicsExpose events are enabled here.
31 * GetXPM is exported. It optionally takes an XpmColorSymbol array.
32 * GetColor is exported.
34 30/09/2000 (Brad Jorsch, anomie@users.sourceforge.net)
35 * You know, wmgen.mask sounds like a much nicer place to store the
36 mask... why don't we do that?
38 21/09/1999 (Brad Jorsch, anomie@users.sourceforge.net)
39 * Changed openXwindow to use only the filename, sans path,
40 as the name and class properties of the app.
42 14/09/1998 (Dave Clark, clarkd@skyia.com)
43 * Updated createXBMfromXPM routine
44 * Now supports >256 colors
45 11/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
46 * Removed a bug from parse_rcfile. You could
47 not use "start" in a command if a label was
49 * Changed the needed geometry string.
50 We don't use window size, and don't support
52 03/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
54 02/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
55 * Added -geometry support (untested)
56 28/08/1998 (Martijn Pieterse, pieterse@xs4all.nl)
57 * Added createXBMfromXPM routine
58 * Saves a lot of work with changing xpm's.
59 02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
60 * changed the read_rc_file to parse_rcfile, as suggested by Marcelo E. Magallon
61 * debugged the parse_rc file.
62 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
63 * Ripped similar code from all the wm* programs,
64 and put them in a single file.
77 #include <X11/extensions/shape.h>
79 #include "wmgeneral-x11.h"
89 XSizeHints mysizehints
;
91 Pixel back_pix
, fore_pix
;
98 /***********************/
99 /* Function Prototypes */
100 /***********************/
102 void RedrawWindow(void);
104 /******************************************************************************\
106 \******************************************************************************/
108 void GetXPM(XpmIcon
*wmgen
, char *pixmap_bytes
[]) {
110 XWindowAttributes attributes
;
113 /* For the colormap */
114 XGetWindowAttributes(display
, Root
, &attributes
);
116 wmgen
->attributes
.valuemask
|= (XpmReturnPixels
| XpmReturnExtensions
);
117 err
= XpmCreatePixmapFromData(display
, Root
, pixmap_bytes
, &(wmgen
->pixmap
),
118 &(wmgen
->mask
), &(wmgen
->attributes
));
120 if (err
!= XpmSuccess
) {
121 fprintf(stderr
, "Not enough free colorcells.\n");
126 /******************************************************************************\
128 \******************************************************************************/
130 Pixel
GetColor(char *name
) {
133 XWindowAttributes attributes
;
135 XGetWindowAttributes(display
, Root
, &attributes
);
138 if (!XParseColor(display
, attributes
.colormap
, name
, &color
)) {
139 fprintf(stderr
, "wm.app: can't parse %s.\n", name
);
140 } else if (!XAllocColor(display
, attributes
.colormap
, &color
)) {
141 fprintf(stderr
, "wm.app: can't allocate %s.\n", name
);
146 /******************************************************************************\
148 \******************************************************************************/
150 static int flush_expose(Window w
) {
155 while (XCheckTypedWindowEvent(display
, w
, Expose
, &dummy
))
161 /******************************************************************************\
163 \******************************************************************************/
165 void RedrawWindow(void) {
167 flush_expose(iconwin
);
168 XCopyArea(display
, wmgen
.pixmap
, iconwin
, RedrawGC
,
169 0,0, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0,0);
171 XCopyArea(display
, wmgen
.pixmap
, win
, RedrawGC
,
172 0,0, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0,0);
175 /******************************************************************************\
177 \******************************************************************************/
179 void RedrawWindowXY(int x
, int y
) {
181 flush_expose(iconwin
);
182 XCopyArea(display
, wmgen
.pixmap
, iconwin
, RedrawGC
,
183 x
,y
, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0,0);
185 XCopyArea(display
, wmgen
.pixmap
, win
, RedrawGC
,
186 x
,y
, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0,0);
189 /******************************************************************************\
191 \******************************************************************************/
193 void copyPixmapArea(int x
, int y
, int sx
, int sy
, int dx
, int dy
) {
195 XCopyArea(display
, wmgen
.pixmap
, wmgen
.pixmap
, NormalGC
, x
, y
, sx
, sy
, dx
, dy
);
199 /******************************************************************************\
201 \******************************************************************************/
203 void copyMaskArea(int x
, int y
, int sx
, int sy
, int dx
, int dy
) {
205 XCopyArea(display
, wmgen
.mask
, wmgen
.pixmap
, NormalGC
, x
, y
, sx
, sy
, dx
, dy
);
209 /******************************************************************************\
211 \******************************************************************************/
213 void setMaskXY(int x
, int y
) {
215 XShapeCombineMask(display
, win
, ShapeBounding
, x
, y
, wmgen
.mask
, ShapeSet
);
216 XShapeCombineMask(display
, iconwin
, ShapeBounding
, x
, y
, wmgen
.mask
, ShapeSet
);
219 /******************************************************************************\
221 \******************************************************************************/
222 void openDockWindow(int argc
, char *argv
[], char *pixmap_bytes
[], char *pixmask_bits
, int pixmask_width
, int pixmask_height
) {
224 unsigned int borderwidth
= 1;
225 XClassHint classHint
;
226 char *display_name
= NULL
;
233 char *geometry
= NULL
;
238 wname
=strrchr(argv
[0], '/');
239 if(wname
==NULL
) wname
=argv
[0];
242 for (i
=1; argv
[i
]; i
++) {
243 if (!strcmp(argv
[i
], "-display")) {
244 display_name
= argv
[i
+1];
247 if (!strcmp(argv
[i
], "-geometry")) {
248 geometry
= argv
[i
+1];
253 if (!(display
= XOpenDisplay(display_name
))) {
254 fprintf(stderr
, "%s: can't open display %s\n",
255 wname
, XDisplayName(display_name
));
258 screen
= DefaultScreen(display
);
259 Root
= RootWindow(display
, screen
);
260 d_depth
= DefaultDepth(display
, screen
);
261 x_fd
= XConnectionNumber(display
);
263 /* Convert XPM to XImage */
264 GetXPM(&wmgen
, pixmap_bytes
);
266 /* Create a window to hold the stuff */
267 mysizehints
.flags
= USSize
| USPosition
;
271 back_pix
= GetColor("white");
272 fore_pix
= GetColor("black");
274 XWMGeometry(display
, screen
, Geometry
, NULL
, borderwidth
, &mysizehints
,
275 &mysizehints
.x
, &mysizehints
.y
,&mysizehints
.width
,&mysizehints
.height
, &dummy
);
277 mysizehints
.width
= 64;
278 mysizehints
.height
= 64;
280 win
= XCreateSimpleWindow(display
, Root
, mysizehints
.x
, mysizehints
.y
,
281 mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
283 iconwin
= XCreateSimpleWindow(display
, win
, mysizehints
.x
, mysizehints
.y
,
284 mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
287 XSetWMNormalHints(display
, win
, &mysizehints
);
288 classHint
.res_name
= wname
;
289 classHint
.res_class
= wname
;
290 XSetClassHint(display
, win
, &classHint
);
292 XSelectInput(display
, win
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
293 XSelectInput(display
, iconwin
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
295 if (XStringListToTextProperty(&wname
, 1, &name
) == 0) {
296 fprintf(stderr
, "%s: can't allocate window name\n", wname
);
300 XSetWMName(display
, win
, &name
);
302 /* Create GC for drawing */
304 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
305 gcv
.foreground
= fore_pix
;
306 gcv
.background
= back_pix
;
307 gcv
.graphics_exposures
= True
;
308 NormalGC
= XCreateGC(display
, Root
, gcm
, &gcv
);
309 gcv
.graphics_exposures
= False
;
310 RedrawGC
= XCreateGC(display
, Root
, gcm
, &gcv
);
314 if(pixmask_bits
!=NULL
){
315 XFreePixmap(display
, wmgen
.mask
);
316 wmgen
.mask
= XCreateBitmapFromData(display
, win
, pixmask_bits
, pixmask_width
, pixmask_height
);
319 XShapeCombineMask(display
, win
, ShapeBounding
, 0, 0, wmgen
.mask
, ShapeSet
);
320 XShapeCombineMask(display
, iconwin
, ShapeBounding
, 0, 0, wmgen
.mask
, ShapeSet
);
324 mywmhints
.initial_state
= WithdrawnState
;
325 mywmhints
.icon_window
= iconwin
;
326 mywmhints
.icon_x
= mysizehints
.x
;
327 mywmhints
.icon_y
= mysizehints
.y
;
328 mywmhints
.window_group
= win
;
329 mywmhints
.flags
= StateHint
| IconWindowHint
| IconPositionHint
| WindowGroupHint
;
331 XSetWMHints(display
, win
, &mywmhints
);
333 XSetCommand(display
, win
, argv
, argc
);
334 XMapWindow(display
, win
);
337 if (sscanf(geometry
, "+%d+%d", &wx
, &wy
) != 2) {
338 fprintf(stderr
, "Bad geometry string.\n");
341 XMoveWindow(display
, win
, wx
, wy
);