3 WMPPP - PPP dock app/helper for WindowMaker
4 Copyright (C) 1997-2000:
6 Authors: Martijn Pieterse (pieterse@xs4all.nl)
7 Antoine Nulle (warp@xs4all.nl)
8 Felipe Bergo (bergo@seul.org)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include <X11/extensions/shape.h>
37 #include "wmgeneral.h"
43 XSizeHints mysizehints
;
45 Pixel back_pix
, fore_pix
;
62 MOUSE_REGION mouse_region
[MAX_MOUSE_REGION
];
64 static void GetXPM (XpmIcon
*, char **);
65 static Pixel
GetColor (char *);
66 void RedrawWindow (void);
67 void AddMouseRegion (unsigned, int, int, int, int);
68 int CheckMouseRegion (int, int);
71 GetXPM (XpmIcon
* wmgen
, char *pixmap_bytes
[])
74 XWindowAttributes attributes
;
77 /* For the colormap */
78 XGetWindowAttributes (display
, Root
, &attributes
);
80 wmgen
->attributes
.valuemask
|= (XpmReturnPixels
| XpmReturnExtensions
);
82 err
= XpmCreatePixmapFromData (display
, Root
, pixmap_bytes
, &(wmgen
->pixmap
),
83 &(wmgen
->mask
), &(wmgen
->attributes
));
85 if (err
!= XpmSuccess
)
87 fprintf (stderr
, "Not enough free colorcells.\n");
97 XWindowAttributes attributes
;
99 XGetWindowAttributes (display
, Root
, &attributes
);
102 if (!XParseColor (display
, attributes
.colormap
, name
, &color
))
104 fprintf (stderr
, "wm.app: can't parse %s.\n", name
);
106 else if (!XAllocColor (display
, attributes
.colormap
, &color
))
108 fprintf (stderr
, "wm.app: can't allocate %s.\n", name
);
114 flush_expose (Window w
)
120 while (XCheckTypedWindowEvent (display
, w
, Expose
, &dummy
))
130 flush_expose (iconwin
);
131 XCopyArea (display
, wmgen
.pixmap
, iconwin
, NormalGC
,
132 0, 0, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0, 0);
134 XCopyArea (display
, wmgen
.pixmap
, win
, NormalGC
,
135 0, 0, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0, 0);
139 RedrawWindowXY (int x
, int y
)
142 flush_expose (iconwin
);
143 XCopyArea (display
, wmgen
.pixmap
, iconwin
, NormalGC
,
144 x
, y
, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0, 0);
146 XCopyArea (display
, wmgen
.pixmap
, win
, NormalGC
,
147 x
, y
, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0, 0);
151 AddMouseRegion (unsigned index
, int left
, int top
, int right
, int bottom
)
154 if (index
< MAX_MOUSE_REGION
)
156 mouse_region
[index
].enable
= 1;
157 mouse_region
[index
].top
= top
;
158 mouse_region
[index
].left
= left
;
159 mouse_region
[index
].bottom
= bottom
;
160 mouse_region
[index
].right
= right
;
165 CheckMouseRegion (int x
, int y
)
173 for (i
= 0; i
< MAX_MOUSE_REGION
&& !found
; i
++)
175 if (mouse_region
[i
].enable
&&
176 x
<= mouse_region
[i
].right
&&
177 x
>= mouse_region
[i
].left
&&
178 y
<= mouse_region
[i
].bottom
&&
179 y
>= mouse_region
[i
].top
)
188 createXBMfromXPM (char *xbm
, char **xpm
, int sx
, int sy
)
192 int width
, height
, numcol
;
194 unsigned char bwrite
;
198 sscanf (*xpm
, "%d %d %d", &width
, &height
, &numcol
);
201 for (i
= numcol
+ 1; i
< numcol
+ sy
+ 1; i
++)
205 for (j
= 0; j
< sx
; j
++)
208 if (xpm
[i
][j
] != zero
)
225 copyXPMArea (int x
, int y
, int sx
, int sy
, int dx
, int dy
)
228 XCopyArea (display
, wmgen
.pixmap
, wmgen
.pixmap
, NormalGC
, x
, y
, sx
, sy
, dx
, dy
);
233 copyXBMArea (int x
, int y
, int sx
, int sy
, int dx
, int dy
)
236 XCopyArea (display
, wmgen
.mask
, wmgen
.pixmap
, NormalGC
, x
, y
, sx
, sy
, dx
, dy
);
240 setMaskXY (int x
, int y
)
243 XShapeCombineMask (display
, win
, ShapeBounding
, x
, y
, pixmask
, ShapeSet
);
244 XShapeCombineMask (display
, iconwin
, ShapeBounding
, x
, y
, pixmask
, ShapeSet
);
248 openXwindow (int argc
, char *argv
[], char *pixmap_bytes
[], char *pixmask_bits
, int pixmask_width
, int pixmask_height
)
251 unsigned int borderwidth
= 1;
252 XClassHint classHint
;
253 char *display_name
= NULL
;
254 char *wname
= argv
[0];
260 char *geometry
= NULL
;
265 for (i
= 1; argv
[i
]; i
++)
267 if (!strcmp (argv
[i
], "-display"))
269 display_name
= argv
[i
+ 1];
272 if (!strcmp (argv
[i
], "-geometry"))
274 geometry
= argv
[i
+ 1];
279 if (!(display
= XOpenDisplay (display_name
)))
281 fprintf (stderr
, "%s: can't open display %s\n",
282 wname
, XDisplayName (display_name
));
285 screen
= DefaultScreen (display
);
286 Root
= RootWindow (display
, screen
);
287 d_depth
= DefaultDepth (display
, screen
);
288 x_fd
= XConnectionNumber (display
);
290 /* Convert XPM to XImage */
291 GetXPM (&wmgen
, pixmap_bytes
);
293 /* Create a window to hold the stuff */
294 mysizehints
.flags
= USSize
| USPosition
;
298 back_pix
= GetColor ("white");
299 fore_pix
= GetColor ("black");
301 XWMGeometry (display
, screen
, Geometry
, NULL
, borderwidth
, &mysizehints
,
302 &mysizehints
.x
, &mysizehints
.y
, &mysizehints
.width
, &mysizehints
.height
, &dummy
);
304 mysizehints
.width
= 64;
305 mysizehints
.height
= 64;
307 win
= XCreateSimpleWindow (display
, Root
, mysizehints
.x
, mysizehints
.y
,
308 mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
310 iconwin
= XCreateSimpleWindow (display
, win
, mysizehints
.x
, mysizehints
.y
,
311 mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
314 XSetWMNormalHints (display
, win
, &mysizehints
);
315 classHint
.res_name
= wname
;
316 classHint
.res_class
= wname
;
317 XSetClassHint (display
, win
, &classHint
);
319 XSelectInput (display
, win
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
320 XSelectInput (display
, iconwin
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
322 if (XStringListToTextProperty (&wname
, 1, &name
) == 0)
324 fprintf (stderr
, "%s: can't allocate window name\n", wname
);
328 XSetWMName (display
, win
, &name
);
330 /* Create GC for drawing */
332 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
333 gcv
.foreground
= fore_pix
;
334 gcv
.background
= back_pix
;
335 gcv
.graphics_exposures
= 0;
336 NormalGC
= XCreateGC (display
, Root
, gcm
, &gcv
);
340 pixmask
= XCreateBitmapFromData (display
, win
, pixmask_bits
, pixmask_width
, pixmask_height
);
342 XShapeCombineMask (display
, win
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
343 XShapeCombineMask (display
, iconwin
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
347 mywmhints
.initial_state
= WithdrawnState
;
348 mywmhints
.icon_window
= iconwin
;
349 mywmhints
.icon_x
= mysizehints
.x
;
350 mywmhints
.icon_y
= mysizehints
.y
;
351 mywmhints
.window_group
= win
;
352 mywmhints
.flags
= StateHint
| IconWindowHint
| IconPositionHint
| WindowGroupHint
;
354 XSetWMHints (display
, win
, &mywmhints
);
356 XSetCommand (display
, win
, argv
, argc
);
357 XMapWindow (display
, win
);
361 if (sscanf (geometry
, "+%d+%d", &wx
, &wy
) != 2)
363 fprintf (stderr
, "Bad geometry string.\n");
366 XMoveWindow (display
, win
, wx
, wy
);