9 #include <X11/extensions/shape.h>
10 #include "wmgeneral.h"
16 XSizeHints mysizehints
;
18 Pixel back_pix
, fore_pix
;
24 /* Function Prototypes */
25 static void GetXPM(XpmIcon
*, char **);
26 static Pixel
GetColor(char *);
27 void RedrawWindow(void);
30 static void GetXPM(XpmIcon
*wmgen
, char *pixmap_bytes
[])
32 XWindowAttributes attributes
;
35 /* For the colormap */
36 XGetWindowAttributes(display
, Root
, &attributes
);
38 wmgen
->attributes
.valuemask
|= (XpmReturnPixels
| XpmReturnExtensions
);
40 err
= XpmCreatePixmapFromData(display
, Root
, pixmap_bytes
, &(wmgen
->pixmap
),
41 &(wmgen
->mask
), &(wmgen
->attributes
));
43 if (err
!= XpmSuccess
) {
44 fprintf(stderr
, "Not enough free colorcells.\n");
49 static Pixel
GetColor(char *name
)
52 XWindowAttributes attributes
;
54 XGetWindowAttributes(display
, Root
, &attributes
);
57 if (!XParseColor(display
, attributes
.colormap
, name
, &color
)) {
58 fprintf(stderr
, "wm.app: can't parse %s.\n", name
);
59 } else if (!XAllocColor(display
, attributes
.colormap
, &color
)) {
60 fprintf(stderr
, "wm.app: can't allocate %s.\n", name
);
65 static int flush_expose(Window w
)
70 while (XCheckTypedWindowEvent(display
, w
, Expose
, &dummy
))
75 void RedrawWindow(void)
77 flush_expose(iconwin
);
78 XCopyArea(display
, wmgen
.pixmap
, iconwin
, NormalGC
,
79 0,0, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0,0);
81 XCopyArea(display
, wmgen
.pixmap
, win
, NormalGC
,
82 0,0, wmgen
.attributes
.width
, wmgen
.attributes
.height
, 0,0);
86 void copyXPMArea(int x
, int y
, int sx
, int sy
, int dx
, int dy
)
88 XCopyArea(display
, wmnumbers
.pixmap
, wmgen
.pixmap
, NormalGC
, x
, y
, sx
, sy
, dx
, dy
);
93 XCopyArea(display
, wmempty
.pixmap
, wmgen
.pixmap
, NormalGC
, 0,0,64,64,0,0);
96 void openXwindow(int argc
, char *argv
[], char *pixmap_bytes_numbers
[], char *pixmap_bytes_background
[], char pixmask_bits
[], int pixmask_width
, int pixmask_height
)
98 unsigned int borderwidth
= 1;
100 char *display_name
= NULL
;
101 char *wname
= argv
[0];
107 if (!(display
= XOpenDisplay(display_name
))) {
108 fprintf(stderr
, "%s: can't open display %s\n",
109 wname
, XDisplayName(display_name
));
112 screen
= DefaultScreen(display
);
113 Root
= RootWindow(display
, screen
);
114 d_depth
= DefaultDepth(display
, screen
);
115 x_fd
= XConnectionNumber(display
);
117 /* Convert XPM to XImage */
118 GetXPM(&wmgen
, pixmap_bytes_background
);
119 GetXPM(&wmempty
, pixmap_bytes_background
);
120 GetXPM(&wmnumbers
,pixmap_bytes_numbers
);
122 /* Create a window to hold the stuff */
123 mysizehints
.flags
= USSize
| USPosition
;
127 back_pix
= GetColor("white");
128 fore_pix
= GetColor("black");
130 XWMGeometry(display
, screen
, Geometry
, NULL
, borderwidth
, &mysizehints
, &mysizehints
.x
, &mysizehints
.y
,&mysizehints
.width
,&mysizehints
.height
, &dummy
);
132 mysizehints
.width
= 64;
133 mysizehints
.height
= 64;
135 win
= XCreateSimpleWindow(display
, Root
, mysizehints
.x
, mysizehints
.y
, mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
137 iconwin
= XCreateSimpleWindow(display
, win
, mysizehints
.x
, mysizehints
.y
, mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
140 XSetWMNormalHints(display
, win
, &mysizehints
);
141 classHint
.res_name
= wname
;
142 classHint
.res_class
= wname
;
143 XSetClassHint(display
, win
, &classHint
);
145 XSelectInput(display
, win
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
146 XSelectInput(display
, iconwin
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
148 if (XStringListToTextProperty(&wname
, 1, &name
) == 0) {
149 fprintf(stderr
, "%s: can't allocate window name\n", wname
);
153 XSetWMName(display
, win
, &name
);
155 /* Create GC for drawing */
156 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
157 gcv
.foreground
= fore_pix
;
158 gcv
.background
= back_pix
;
159 gcv
.graphics_exposures
= 0;
160 NormalGC
= XCreateGC(display
, Root
, gcm
, &gcv
);
163 pixmask
= XCreateBitmapFromData(display
, win
, pixmask_bits
, pixmask_width
, pixmask_height
);
164 XShapeCombineMask(display
, win
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
165 XShapeCombineMask(display
, iconwin
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
168 mywmhints
.initial_state
= WithdrawnState
;
169 mywmhints
.icon_window
= iconwin
;
170 mywmhints
.icon_x
= mysizehints
.x
;
171 mywmhints
.icon_y
= mysizehints
.y
;
172 mywmhints
.window_group
= win
;
173 mywmhints
.flags
= StateHint
| IconWindowHint
| IconPositionHint
| WindowGroupHint
;
175 XSetWMHints(display
, win
, &mywmhints
);
177 XSetCommand(display
, win
, argv
, argc
);
178 XMapWindow(display
, win
);