2 * Copyright (c) 1999-2005 Alfredo K. Kojima, Alban Hertroys
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #define DA_VERSION 20050716
28 * This is a simple (trivial) library for writing Window Maker dock
29 * applications, or dockapps (those that only show up in the dock), easily.
31 * It is very limited and can be only used for dockapps that open a single
32 * appicon for process in only ibe single display, but this seems to be
33 * enough for most, if not all, dockapps.
37 #include <X11/Xresource.h>
45 /* class-name for X-resources and Window Maker attributes */
46 #define RES_CLASSNAME "DockApp"
50 * This feature may be removed in the future. Use DAEventCallbacks instead.
52 * the callbacks for events related to the dockapp window your program wants
56 /* the dockapp window was destroyed */
57 void (*destroy
)(void);
59 void (*buttonPress
)(int button
, int state
, int x
, int y
);
61 void (*buttonRelease
)(int button
, int state
, int x
, int y
);
63 void (*motion
)(int x
, int y
);
64 /* pointer entered dockapp window */
66 /* pointer left dockapp window */
69 void (*timeout
)(void);
74 char *shortForm
; /* short form for option, like -w */
75 char *longForm
; /* long form for option, like --withdrawn */
76 char *description
; /* description for the option */
78 short type
; /* type of argument */
79 Bool used
; /* if the argument was passed on the cmd-line */
81 /* the following are only set if the "used" field is True */
83 void *ptr
; /* a ptr for the value that was passed */
84 int *integer
; /* on the command line */
90 typedef XRectangle DARect
;
93 * A callback function for an event on an "action rectangle"
95 typedef void DARectCallback(int x
, int y
, DARect rect
, void *data
);
98 * The action rectangle structure
102 DARectCallback
*action
;
106 /* option argument types */
108 DONone
, /* simple on/off flag */
109 DOInteger
, /* an integer number */
110 DOString
, /* a string */
111 DONatural
/* positive integer number */
115 /* Shaped pixmaps: Shapes in combination with pixmaps */
118 Pixmap shape
; /* needs a 1-bit plane GC (shapeGC). */
119 GC drawGC
, clearGC
, shapeGC
;
120 DARect geometry
; /* position and size */
121 DAActionRect
*triggers
;
126 extern Display
*DADisplay
;
127 extern Window DAWindow
, DALeader
, DAIcon
; /* see [NOTE] */
129 extern Visual
*DAVisual
;
130 extern GC DAGC
, DAClearGC
;
131 extern DARect DANoRect
;
132 extern unsigned long DAExpectedVersion
;
135 * DALeader is the group-leader window, DAIcon is the icon window.
136 * DAWindow is the one of these two that is visible. Depending on whether the
137 * dockapp was started normally or windowed, that will be DAIcon and DALeader
139 * DAIcon is None if the dockapp runs in "windowed mode".
144 * Set the version of the library that the dockapp expects.
145 * This is a date in the format 'yyyymmdd'. You can find this date
148 void DASetExpectedVersion(unsigned long expectedVersion
);
153 * Command line arguments parser. The program is exited if there are
156 * -h, --help and --version are automatically handled (causing the program
158 * -w is handled automatically as well and causes the dockapp to be run
161 void DAParseArguments(int argc
, char **argv
, DAProgramOption
*options
,
162 int count
, char *programDescription
, char *versionDescription
);
166 * Initialize the dockapp, open a connection to the X Server,
167 * create the needed windows and set them up to become an appicon window.
168 * It will automatically detect if Window Maker is present and use
169 * an appropriate window form.
171 * You must call this always before calling anything else (except for
172 * DAParseArguments())
175 * display - the name of the display to connect to.
176 * Use "" to use the default value.
177 * name - the name of your dockapp, used as the instance name
178 * for the WM_CLASS hint. Like wmyaclock.
179 * The ClassName is set to "DockApp" on default.
180 * width, height - the size of the dockapp window. 48x48 is the
182 * argc, argc - the program arguments. argv[0] will be used
183 * as the instance name for the WM_CLASS hint.
186 void DAInitialize(char *display
, char *name
, unsigned width
, unsigned height
,
187 int argc
, char **argv
);
189 void DAOpenDisplay(char *display
, int argc
, char **argv
);
191 void DACreateIcon(char *name
, unsigned width
, unsigned height
,
192 int argc
, char **argv
);
194 void DAProposeIconSize(unsigned width
, unsigned height
);
198 * Wrapper functions for global variables.
201 /* Get/Set DADisplay value. For use with external code.
202 * Call with NULL as only argument. Other arguments are for backward compatibility
204 * XXX: Argument list is a kludge.
206 Display
*DAGetDisplay(char *d
, ...);
207 void DASetDisplay(Display
*display
);
209 /* Get program name (from argv[0]). Returns a reference. */
210 char *DAGetProgramName();
212 /* Get/Set DAWindow and DALeader values respectively. For use with external code. */
213 Window
DAGetWindow(void);
214 void DASetWindow(Window window
);
216 Window
DAGetLeader(void);
217 void DASetLeader(Window leader
);
219 Window
DAGetIconWindow(void);
220 void DASetIconWindow(Window icon_win
);
222 /* Get/Set DADepth; the display depth. For use with external code. */
223 int DAGetDepth(void);
224 void DASetDepth(int depth
);
226 /* Get/Set DAVisual; the visual type for the screen. For use with external code. */
227 Visual
*DAGetVisual(void);
228 void DASetVisual(Visual
*visual
);
232 * DASetShapeWithOffset-
233 * Sets the shape mask of the dockapp to the specified one. This is
234 * optional. If you pass None as shapeMask, the dockapp will become
237 * This is only needed if you want the dockapp to be shaped.
239 #define DASetShape(shapeMask) \
240 (DASetShapeWithOffset((shapeMask), 0, 0))
241 #define DASetShapeForWindow(window, shapeMask) \
242 (DASetShapeWithOffsetForWindow((window), (shapeMask), 0, 0))
244 void DASetShapeWithOffset(Pixmap shapeMask
, int x_ofs
, int y_ofs
);
245 void DASetShapeWithOffsetForWindow(Window window
, Pixmap shapeMask
,
246 int x_ofs
, int y_ofs
);
249 * Sets the image pixmap for the dockapp. Once you set the image with it,
250 * you don't need to handle expose events.
252 void DASetPixmap(Pixmap pixmap
);
253 void DASetPixmapForWindow(Window window
, Pixmap pixmap
);
257 * Creates a pixmap suitable for use with DASetPixmap()
259 Pixmap
DAMakePixmap(void);
263 * Creates a shape pixmap suitable for use with DASetShape()
265 Pixmap
DAMakeShape(void);
268 * DAMakeShapeFromData-
269 * Creates a shape pixmap suitable for use with DASetShape() from XBM data.
271 Pixmap
DAMakeShapeFromData(char *data
, unsigned int width
, unsigned int height
);
274 * DAMakeShapeFromFile-
275 * Creates a shape pixmap suitable for use with DASetShape() from an
278 Pixmap
DAMakeShapeFromFile(char *filename
);
281 * DAMakePixmapFromData-
282 * Creates a pixmap and mask from XPM data
283 * Returns true on success, false on failure.
285 Bool
DAMakePixmapFromData(char **data
, Pixmap
*pixmap
, Pixmap
*mask
,
286 unsigned short *width
, unsigned short *height
);
289 * DAMakePixmapFromFile-
290 * Creates a pixmap and mask from an XPM file
291 * Returns true on success, false on failure.
293 Bool
DAMakePixmapFromFile(char *filename
, Pixmap
*pixmap
, Pixmap
*mask
,
294 unsigned short *width
, unsigned short *height
);
297 * DAMakeShapedPixmap-
298 * Creates a shaped pixmap with width & height of dockapp window.
300 DAShapedPixmap
*DAMakeShapedPixmap();
303 * DAMakeShapedPixmapFromData-
304 * Creates a shaped pixmap from XPM-data.
305 * Returns shaped pixmap on success, NULL on failure.
307 DAShapedPixmap
*DAMakeShapedPixmapFromData(char **data
);
310 * DAMakeShapedPixmapFromFile-
311 * Creates a shaped pixmap from an XPM file.
312 * Returns shaped pixmap on success, NULL on failure.
314 DAShapedPixmap
*DAMakeShapedPixmapFromFile(char *filename
);
317 * DAFreeShapedPixmap-
318 * Free memory reserved for a ShapedPixmap
320 void DAFreeShapedPixmap(DAShapedPixmap
*dasp
);
324 * Copies shape-mask and pixmap-data from an area in one shaped pixmap
325 * into another shaped pixmap.
327 void DASPCopyArea(DAShapedPixmap
*src
, DAShapedPixmap
*dst
,
328 int x1
, int y1
, int w
, int h
, int x2
, int y2
);
332 * Clears a shaped pixmaps contents.
334 void DASPClear(DAShapedPixmap
*dasp
);
337 * Displays the pixmap in the dockapp-window.
339 void DASPSetPixmap(DAShapedPixmap
*dasp
);
340 void DASPSetPixmapForWindow(Window window
, DAShapedPixmap
*dasp
);
344 * Returns an X color index.
346 unsigned long DAGetColor(char *colorName
);
350 * Displays the dockapp.
352 * Always call this function or the dockapp won't show up.
358 * Display a window. Also displays subwindows if it is the dockapp leader
361 void DAShowWindow(Window window
);
365 * Register a set of callbacks for events like mouse clicks.
367 * Only needed if you want to receive some event.
369 void DASetCallbacks(DACallbacks
*callbacks
);
373 * Sets a timeout for the DAEventLoop(). The timeout callback
374 * will be called whenever the app doesn't get any events from the
375 * X server in the specified time.
377 void DASetTimeout(int milliseconds
);
380 * DANextEventOrTimeout-
381 * Waits until a event is received or the timeout limit has
382 * expired. Returns True if an event was received.
384 Bool
DANextEventOrTimeout(XEvent
*event
, unsigned long milliseconds
);
388 * Processes an event. Returns True if the event was handled and
391 * Must be called from your event loop, unless you use DAEventLoop()
393 Bool
DAProcessEvent(XEvent
*event
);
394 Bool
DAProcessEventForWindow(Window window
, XEvent
*event
);
398 * Enters an event loop where events are processed until the dockapp
399 * is closed. This function never returns.
401 void DAEventLoop(void);
402 void DAEventLoopForWindow(Window window
);
405 * DAProcessActionRects-
406 * Processes the current coordinates with one of the functions in
407 * the array of action rectangles. Coordinates are converted to relative
408 * coordinates in one of the rectangles. The last item in the array of
409 * action rectangles must be NULL.
411 void DAProcessActionRects(int x
, int y
, DAActionRect
*actionrects
,
412 int count
, void *data
);
416 * Error handling functions
419 /* Print a warning to stderr and continue */
420 void DAWarning(const char *fmt
, ...);
422 /* Print an error to stderr and exit with 1 */
423 void DAError(const char *fmt
, ...);