2 * dockapp.c - dockapp part
4 * Copyright (C) 2003 Draghicioiu Mihai <misuceldestept@go.ro>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
29 #include <X11/extensions/shapeconst.h>
30 #include <X11/cursorfont.h>
32 #include "wmmemfree.h"
37 #include "xpm/off.xpm"
38 #include "xpm/numbers.xpm"
39 #include "xpm/panel.xpm"
41 #define WINDOW_WIDTH 64
42 #define WINDOW_HEIGHT 64
46 Window iconwindow
, window
, mapwindow
;
49 Pixmap background
, backgroundmask
, on
, off
, numbers
, buffer
, panel
;
50 Atom wm_delete_window
;
52 int moving
, oldx
, oldy
;
53 int screenwidth
, screenheight
;
58 XUnmapWindow(display
, mapwindow
);
60 XDestroyWindow(display
, iconwindow
);
61 XDestroyWindow(display
, window
);
62 XFreePixmap(display
, buffer
);
63 XFreePixmap(display
, numbers
);
64 XFreePixmap(display
, off
);
65 XFreePixmap(display
, on
);
66 XFreePixmap(display
, backgroundmask
);
67 XFreePixmap(display
, background
);
68 XCloseDisplay(display
);
71 void handle_signal(int sig
)
76 fprintf(stderr
, "Interrupt received\n");
79 fprintf(stderr
, "Quit signal received\n");
82 fprintf(stderr
, "Terminate signal received\n");
84 fprintf(stderr
, "Got signal %d\n", sig
);
94 XpmAttributes xpmattributes
;
95 XSetWindowAttributes windowattributes
;
96 int shapeevent
, shapeerror
;
98 XClassHint
*classhint
;
99 XSizeHints
*sizehints
;
112 display
= XOpenDisplay(opt_display
);
115 fprintf(stderr
, "Could not open display %s\n", opt_display
);
118 screen
= DefaultScreen(display
);
119 screenwidth
= DisplayWidth(display
, screen
);
120 screenheight
= DisplayHeight(display
, screen
);
121 rootwindow
= RootWindow(display
, screen
);
122 colormap
= DefaultColormap(display
, screen
);
123 depth
= DefaultDepth(display
, screen
);
124 xpmattributes
.valuemask
= XpmColormap
| XpmCloseness
;
125 xpmattributes
.colormap
= colormap
;
126 xpmattributes
.closeness
= 40000;
127 XpmCreatePixmapFromData(display
, rootwindow
, bg_xpm
,
128 &background
, &backgroundmask
, &xpmattributes
);
129 XpmCreatePixmapFromData(display
, rootwindow
, on_xpm
,
130 &on
, None
, &xpmattributes
);
131 XpmCreatePixmapFromData(display
, rootwindow
, off_xpm
,
132 &off
, None
, &xpmattributes
);
133 XpmCreatePixmapFromData(display
, rootwindow
, numbers_xpm
,
134 &numbers
, None
, &xpmattributes
);
135 buffer
= XCreatePixmap(display
, rootwindow
,
136 WINDOW_WIDTH
, WINDOW_HEIGHT
, depth
);
137 windowattributes
.background_pixmap
= background
;
138 windowattributes
.event_mask
= ExposureMask
|
143 windowattributes
.colormap
= colormap
;
144 window
= XCreateWindow(display
, rootwindow
,
145 0, 0, WINDOW_WIDTH
, WINDOW_HEIGHT
, 0,
149 CWBackPixmap
| CWEventMask
| CWColormap
,
151 iconwindow
= XCreateWindow(display
, rootwindow
,
152 0, 0, WINDOW_WIDTH
, WINDOW_HEIGHT
, 0,
156 CWBackPixmap
| CWEventMask
,
158 fleur
= XCreateFontCursor(display
, XC_fleur
);
159 if(XShapeQueryExtension(display
, &shapeevent
, &shapeerror
) && opt_shape
)
161 XShapeCombineMask(display
, window
, ShapeBounding
,
162 0, 0, backgroundmask
, ShapeSet
);
163 XShapeCombineMask(display
, iconwindow
, ShapeBounding
,
164 0, 0, backgroundmask
, ShapeSet
);
168 XpmCreatePixmapFromData(display
, rootwindow
, panel_xpm
,
169 &panel
, None
, &xpmattributes
);
170 gcvalues
.function
= GXcopy
;
171 gcvalues
.graphics_exposures
= False
;
172 gcvalues
.clip_mask
= backgroundmask
;
173 gcvalues
.clip_x_origin
= 0;
174 gcvalues
.clip_y_origin
= 0;
175 gc
= XCreateGC(display
, rootwindow
,
177 GCGraphicsExposures
|
182 XCopyArea(display
, background
, panel
, gc
, 0, 0, WINDOW_WIDTH
, WINDOW_HEIGHT
, 0, 0);
183 gcvalues
.clip_mask
= None
;
184 XChangeGC(display
, gc
, GCClipMask
, &gcvalues
);
185 XCopyArea(display
, panel
, background
, gc
, 0, 0, WINDOW_WIDTH
, WINDOW_HEIGHT
, 0, 0);
186 XFreeGC(display
, gc
);
187 XFreePixmap(display
, panel
);
190 mapwindow
= opt_window
? iconwindow
: window
;
191 wmhints
= XAllocWMHints();
192 wmhints
-> flags
= InputHint
| WindowGroupHint
| IconWindowHint
| StateHint
;
193 wmhints
-> input
= True
;
194 wmhints
-> window_group
= window
;
195 wmhints
-> icon_window
= iconwindow
;
196 wmhints
-> initial_state
= WithdrawnState
;
197 XSetWMHints(display
, window
, wmhints
);
200 classhint
= XAllocClassHint();
201 classhint
-> res_name
= OPT_CLASS_NAME
;
202 classhint
-> res_class
= OPT_CLASS_CLASS
;
203 XSetClassHint(display
, mapwindow
, classhint
);
206 sizehints
= XAllocSizeHints();
207 sizehints
-> flags
= USSize
| PSize
| PMinSize
| PMaxSize
| PBaseSize
;
208 sizehints
-> width
= WINDOW_WIDTH
;
209 sizehints
-> height
= WINDOW_HEIGHT
;
210 sizehints
-> min_width
= WINDOW_WIDTH
;
211 sizehints
-> min_height
= WINDOW_HEIGHT
;
212 sizehints
-> max_width
= WINDOW_WIDTH
;
213 sizehints
-> max_height
= WINDOW_HEIGHT
;
214 sizehints
-> base_width
= WINDOW_WIDTH
;
215 sizehints
-> base_height
= WINDOW_HEIGHT
;
216 XSetWMNormalHints(display
, mapwindow
, sizehints
);
219 XStoreName(display
, window
, OPT_WINDOW_NAME
);
220 XStoreName(display
, iconwindow
, OPT_WINDOW_NAME
); /* For other wms */
222 gcvalues
.graphics_exposures
= False
;
223 gcvalues
.function
= GXcopy
;
224 gc
= XCreateGC(display
, rootwindow
,
225 GCGraphicsExposures
| GCFunction
,
227 XCopyArea(display
, background
, buffer
, gc
, 0, 0, WINDOW_WIDTH
, WINDOW_HEIGHT
, 0, 0);
228 XSetCommand(display
, window
, argv
, argc
);
229 wm_delete_window
= XInternAtom(display
, "WM_DELETE_WINDOW", 0);
230 XSetWMProtocols(display
, mapwindow
, &wm_delete_window
, 1);
233 _motif_wm_hints
= XInternAtom(display
, "_MOTIF_WM_HINTS", 0);
235 mwmhints
.functions
= 0x71; /* WTF IS THIS ? */
236 mwmhints
.decorations
= 0;
237 XChangeProperty(display
, mapwindow
,
238 _motif_wm_hints
, _motif_wm_hints
,
239 32, PropModeReplace
, (unsigned char *)&mwmhints
, 5);
241 XMapWindow(display
, mapwindow
);
242 signal(SIGINT
, handle_signal
);
243 signal(SIGQUIT
, handle_signal
);
244 signal(SIGTERM
, handle_signal
);
249 XCopyArea(display
, buffer
, iconwindow
, gc
, 0, 0, WINDOW_WIDTH
, WINDOW_HEIGHT
, 0, 0);
250 XCopyArea(display
, buffer
, window
, gc
, 0, 0, WINDOW_WIDTH
, WINDOW_HEIGHT
, 0, 0);
253 void process_events()
258 XNextEvent(display
, &event
);
265 if(opt_window
&& (event
.xbutton
.button
== 1))
267 XDefineCursor(display
, mapwindow
, fleur
);
269 oldx
= event
.xbutton
.x
;
270 oldy
= event
.xbutton
.y
;
274 winx
= event
.xmotion
.x_root
- oldx
;
275 winy
= event
.xmotion
.y_root
- oldy
;
276 if(winx
< 0) winx
= 0;
277 if(winy
< 0) winy
= 0;
278 if(winx
> (screenwidth
- WINDOW_WIDTH
))
279 winx
= screenwidth
- WINDOW_WIDTH
;
280 if(winy
> (screenheight
- WINDOW_HEIGHT
))
281 winy
= screenheight
- WINDOW_HEIGHT
;
283 XMoveWindow(display
, mapwindow
, winx
, winy
);
289 XUndefineCursor(display
, mapwindow
);
293 if(event
.xclient
.data
.l
[0] == wm_delete_window
)