---
wmfortune/Makefile | 8 +-
wmfortune/dockapp.c | 565 --------------------------------------------------
wmfortune/dockapp.h | 230 --------------------
wmfortune/wmfortune.c | 2 +-
4 files changed, 3 insertions(+), 802 deletions(-)
delete mode 100644 wmfortune/dockapp.c
delete mode 100644 wmfortune/dockapp.h
diff --git a/wmfortune/Makefile b/wmfortune/Makefile
index 000cd71..79a07d7 100644
--- a/wmfortune/Makefile
+++ b/wmfortune/Makefile
@@ -12,16 +12,12 @@ UNINSTALL_PROGRAM = rm -f
CC = gcc
OPTIMIZE = -O2
XLIBDIR = /usr/X11R6/lib
-#XLIB = -ldockapp -lXpm -lXext -lX11
-XLIB = -lXpm -lXext -lX11
-OBJ = wmfortune.o dockapp.o
+XLIB = -ldockapp -lXpm -lXext -lX11
+OBJ = wmfortune.o
$(DEST) : $(OBJ)
$(CC) $(OBJ) -L$(XLIBDIR) $(XLIB) -o $(DEST)
-dockapp.o: dockapp.c
- $(CC) $(OPTIMIZE) $< -c
-
wmfortune.o: wmfortune.c
$(CC) $(OPTIMIZE) $< -c
diff --git a/wmfortune/dockapp.c b/wmfortune/dockapp.c
deleted file mode 100644
index 4aeeef4..0000000
--- a/wmfortune/dockapp.c
+++ /dev/null
@@ -1,565 +0,0 @@
-/*
- *
- * Copyright (c) 1999 Alfredo K. Kojima
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-
-#include "dockapp.h"
-
-#include <string.h>
-#include <X11/extensions/shape.h>
-#include <X11/Xatom.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-
-static char *progName = NULL;
-static unsigned d_width, d_height;
-static DACallbacks d_callbacks = {NULL, NULL, NULL, NULL, NULL, NULL};
-static int d_iswmaker = 0;
-static int d_timeout = 0;
-
-Display *DADisplay = NULL;
-Window DAWindow = None;
-Window DALeader = None;
-int DADepth = 0;
-Visual *DAVisual = NULL;
-
-
-static unsigned char*
-PropGetCheckProperty(Display *dpy, Window window, Atom hint, Atom type,
- int format, int count, int *retCount)
-{
- Atom type_ret;
- int fmt_ret;
- unsigned long nitems_ret;
- unsigned long bytes_after_ret;
- unsigned char *data;
- int tmp;
-
- if (count <= 0)
- tmp = 0xffffff;
- else
- tmp = count;
-
- if (XGetWindowProperty(dpy, window, hint, 0, tmp, False, type,
- &type_ret, &fmt_ret, &nitems_ret, &bytes_after_ret,
- (unsigned char **)&data)!=Success || !data)
- return NULL;
-
- if ((type!=AnyPropertyType && type!=type_ret)
- || (count > 0 && nitems_ret != count)
- || (format != 0 && format != fmt_ret)) {
- XFree(data);
- return NULL;
- }
-
- if (retCount)
- *retCount = nitems_ret;
-
- return data;
-}
-
-
-static Bool
-iswmaker(Display *dpy)
-{
- Atom *data;
- Atom atom;
- Atom noticeboard;
- int i, count;
-
- atom = XInternAtom(dpy, "_WINDOWMAKER_WM_PROTOCOLS", False);
- noticeboard = XInternAtom(dpy, "_WINDOWMAKER_NOTICEBOARD", False);
-
- data = (Atom*)PropGetCheckProperty(dpy, DefaultRootWindow(dpy), atom,
- XA_ATOM, 32, -1, &count);
-
- if (!data)
- return False;
-
- for (i = 0; i < count; i++) {
- if (data[i] == noticeboard) {
- Window *win;
- void *d;
-
- XFree(data);
-
- win = (Window*)PropGetCheckProperty(dpy, DefaultRootWindow(dpy),
- noticeboard, XA_WINDOW, 32, -1,
- &count);
-
- if (!win) {
- return False;
- }
-
- d = PropGetCheckProperty(dpy, *win, noticeboard, XA_WINDOW, 32, 1,
- NULL);
- if (d) {
- XFree(d);
-
- return True;
- }
- return False;
- }
- }
-
- XFree(data);
-
- /* not 100% sure */
- return True;
-}
-
-
-
-void
-DAInitialize(char *display, char *name, unsigned width, unsigned height,
- int argc, char **argv)
-{
- XClassHint *chint;
- XWMHints *hints;
-
- d_width = width;
- d_height = height;
-
- progName = argv[0];
-
- DADisplay = XOpenDisplay(display);
- if (!DADisplay) {
- printf("%s: could not open display %s!\n", progName,
- XDisplayName(display));
-
- exit(1);
- }
-
- DAWindow = XCreateSimpleWindow(DADisplay, DefaultRootWindow(DADisplay),
- 0, 0, width, height, 0, 0, 0);
-
- DALeader = XCreateSimpleWindow(DADisplay, DefaultRootWindow(DADisplay),
- 0, 0, 1, 1, 0, 0, 0);
- chint = XAllocClassHint();
- if (!chint) {
- printf("%s: cant allocate memory for class hints!\n", progName);
- exit(1);
- }
- chint->res_class = name;
- chint->res_name = strrchr(argv[0], '/');
- if (!chint->res_name)
- chint->res_name = argv[0];
- else
- chint->res_name++;
-
- XSetClassHint(DADisplay, DALeader, chint);
- XFree(chint);
-
- hints = XAllocWMHints();
- if (!hints) {
- printf("%s: cant allocate memory for hints!\n", progName);
- exit(1);
- }
- hints->flags = IconWindowHint|WindowGroupHint;
-
- d_iswmaker = iswmaker(DADisplay);
- if (d_iswmaker) {
- hints->flags |= StateHint;
- hints->initial_state = WithdrawnState;
- }
- hints->window_group = DALeader;
- hints->icon_window = DAWindow;
-
- XSetWMHints(DADisplay, DALeader, hints);
-
- XSetCommand(DADisplay, DALeader, argv, argc);
-
- DADepth = DefaultDepth(DADisplay, DefaultScreen(DADisplay));
- DAVisual = DefaultVisual(DADisplay, DefaultScreen(DADisplay));
-
-
- XFlush(DADisplay);
-}
-
-
-void
-DASetShape(Pixmap shapeMask)
-{
- XShapeCombineMask(DADisplay, DAWindow, ShapeBounding, 0, 0, shapeMask,
- ShapeSet);
- XFlush(DADisplay);
-}
-
-
-void
-DASetPixmap(Pixmap pixmap)
-{
- XSetWindowBackgroundPixmap(DADisplay, DAWindow, pixmap);
- XClearWindow(DADisplay, DAWindow);
- XFlush(DADisplay);
-}
-
-
-Pixmap
-DAMakePixmap()
-{
- Pixmap p;
-
- p = XCreatePixmap(DADisplay, DAWindow, d_width, d_height,
- DefaultDepth(DADisplay, DefaultScreen(DADisplay)));
-
- return p;
-}
-
-
-
-Bool
-DAMakePixmapFromData(char **data, Pixmap *pixmap, Pixmap *mask,
- unsigned *width, unsigned *height)
-{
- XpmAttributes xpmat;
-
- xpmat.valuemask = XpmCloseness;
- xpmat.closeness = 40000;
-
- if (XpmCreatePixmapFromData(DADisplay, DAWindow, data, pixmap, mask,
- &xpmat)!=0) {
- return False;
- }
-
- *width = xpmat.width;
- *height = xpmat.height;
-
- return True;
-}
-
-
-void
-DAShow()
-{
- if (d_iswmaker) {
- XMapRaised(DADisplay, DALeader);
- } else {
- XMapRaised(DADisplay, DAWindow);
- }
-
- XFlush(DADisplay);
-}
-
-
-void
-DASetCallbacks(DACallbacks *callbacks)
-{
- long mask = 0;
-
- d_callbacks = *callbacks;
-
- if (callbacks->buttonPress)
- mask |= ButtonPressMask;
-
- if (callbacks->buttonRelease)
- mask |= ButtonReleaseMask;
-
- XSelectInput(DADisplay, DAWindow, mask);
- XFlush(DADisplay);
-}
-
-
-Bool
-DAProcessEvent(XEvent *event)
-{
- if (event->xany.window != DAWindow
- && event->xany.window != DALeader)
- return False;
-
- switch (event->type) {
- case DestroyNotify:
- if (d_callbacks.destroy) {
- (*d_callbacks.destroy)();
- }
- exit(0);
- break;
-
- case ButtonPress:
- if (d_callbacks.buttonPress) {
- (*d_callbacks.buttonPress)(event->xbutton.button,
event->xbutton.state,
- event->xbutton.x, event->xbutton.y);
- }
- break;
-
- case ButtonRelease:
- if (d_callbacks.buttonRelease) {
- (*d_callbacks.buttonRelease)(event->xbutton.button,
event->xbutton.state,
- event->xbutton.x, event->xbutton.y);
- }
- break;
-
- case MotionNotify:
- if (d_callbacks.motion) {
- (*d_callbacks.motion)(event->xbutton.x, event->xbutton.y);
- }
- break;
-
- case EnterNotify:
- if (d_callbacks.enter) {
- (*d_callbacks.enter)();
- }
- break;
-
- case LeaveNotify:
- if (d_callbacks.leave) {
- (*d_callbacks.leave)();
- }
- break;
-
- default:
- return False;
- break;
- }
-
- return True;
-}
-
-
-void
-DAEventLoop()
-{
- XEvent ev;
-
- for (;;) {
- if (d_timeout >= 0) {
- if (!DANextEventOrTimeout(&ev, d_timeout)) {
- if (d_callbacks.timeout)
- (*d_callbacks.timeout)();
- continue;
- }
- } else {
- XNextEvent(DADisplay, &ev);
- }
- DAProcessEvent(&ev);
- }
-}
-
-
-static DAProgramOption defaultOptions[]= {
- {"-h", "--help", "shows this help text and exit", DONone, False,
- {NULL}},
- {"-v", "--version", "shows program version and exit", DONone, False,
- {NULL}}
-};
-
-
-static void
-printHelp(char *prog, char *description, DAProgramOption *options,
- int count)
-{
- int j;
-
- printf("Usage: %s [OPTIONS]\n", prog);
- if (description)
- puts(description);
-
- for (j = 0; j < count + 2; j++) {
- char blank[35];
- int c;
- int i;
-
- if (j >= count) {
- options = defaultOptions;
- i = j - count;
- } else {
- i = j;
- }
-
- if (options[i].shortForm && options[i].longForm)
- c = printf(" %s, %s", options[i].shortForm, options[i].longForm);
- else if (options[i].shortForm)
- c = printf(" %s", options[i].shortForm);
- else if (options[i].longForm)
- c = printf(" %s", options[i].longForm);
- else
- continue;
-
- if (options[i].type != DONone) {
- switch (options[i].type) {
- case DOInteger:
- c += printf(" <integer>");
- break;
- case DOString:
- c += printf(" <string>");
- break;
- case DONatural:
- c+= printf(" <number>");
- break;
- }
- }
-
- memset(blank, ' ', 30);
- if (c > 29)
- c = 1;
- blank[30-c] = 0;
- printf("%s %s\n", blank, options[i].description);
- }
-}
-
-
-void
-DAParseArguments(int argc, char **argv, DAProgramOption *options,
- int count, char *programDescription, char *versionDescription)
-{
- int i, j;
- int found = 0;
-
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-h")==0 || strcmp(argv[i], "--help")==0) {
-
- printHelp(argv[0], programDescription, options, count);
- exit(0);
-
- } else if (strcmp(argv[i], "--version")==0) {
-
- puts(versionDescription);
- exit(0);
-
- }
-
- found = 0;
- for (j = 0; j < count; j++) {
- if ((options[j].shortForm
- && strcmp(options[j].shortForm, argv[i])==0)
- ||
- (options[j].longForm
- && strcmp(options[j].longForm, argv[i])==0)) {
-
- found = 1;
-
- options[j].used = True;
-
- if (options[j].type == DONone)
- break;
-
- i++;
- if (i >= argc) {
- printf("%s: missing argument for option '%s'\n", argv[0],
- argv[i-1]);
- exit(1);
- }
-
- switch (options[j].type) {
- case DOInteger:
- {
- int integer;
-
- if (sscanf(argv[i], "%i", &integer)!=1) {
- printf("%s: error parsing argument for option %s\n",
- argv[0], argv[i-1]);
- exit(1);
- }
- *options[j].value.integer = integer;
- }
- break;
- case DONatural:
- {
- int integer;
-
- if (sscanf(argv[i], "%i", &integer)!=1) {
- printf("%s: error parsing argument for option %s\n",
- argv[0], argv[i-1]);
- exit(1);
- }
- if (integer < 0) {
- printf("%s: argument %s must be >= 0\n",
- argv[0], argv[i-1]);
- exit(1);
- }
- *options[j].value.integer = integer;
- }
- break;
- case DOString:
- *options[j].value.string = argv[i];
- break;
- }
- break;
- }
- }
- if (!found) {
- printf("%s: unrecognized option '%s'\n", argv[0], argv[i]);
- printHelp(argv[0], programDescription, options, count);
- exit(1);
- }
- }
-}
-
-
-unsigned long
-DAGetColor(char *colorName)
-{
- XColor color;
-
- if (!XParseColor(DADisplay,
- DefaultColormap(DADisplay, DefaultScreen(DADisplay)),
- colorName, &color)) {
- printf("%s: could not parse color %s\n", progName, colorName);
- exit(1);
- }
-
- if (!XAllocColor(DADisplay, DefaultColormap(DADisplay,
DefaultScreen(DADisplay)),
- &color)) {
- printf("%s: could not allocate color %s. Using black\n", progName,
colorName);
- return BlackPixel(DADisplay, DefaultScreen(DADisplay));
- }
-
- return color.pixel;
-}
-
-
-void
-DASetTimeout(int milliseconds)
-{
- d_timeout = milliseconds;
-}
-
-
-
-Bool
-DANextEventOrTimeout(XEvent *event, unsigned long millisec)
-{
- struct timeval timeout;
- fd_set rset;
-
- XSync(DADisplay, False);
- if (XPending(DADisplay)) {
- XNextEvent(DADisplay, event);
- return True;
- }
-
- timeout.tv_sec = millisec/1000;
- timeout.tv_usec = (millisec%1000)*10;
-
- FD_ZERO(&rset);
- FD_SET(ConnectionNumber(DADisplay), &rset);
-
- if (select(ConnectionNumber(DADisplay)+1, &rset, NULL, NULL,
- &timeout) > 0) {
- XNextEvent(DADisplay, event);
- return True;
- }
- return False;
-}
-
diff --git a/wmfortune/dockapp.h b/wmfortune/dockapp.h
deleted file mode 100644
index b95330a..0000000
--- a/wmfortune/dockapp.h
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- *
- * Copyright (c) 1999 Alfredo K. Kojima
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef _DOCKAPP_H_
-#define _DOCKAPP_H_
-
-
-/*
- * This is a simple (trivial) library for writing Window Maker dock
- * applications, or dockapps (those that only show up in the dock), easily.
- *
- * It is very limited and can be only used for dockapps that open a single
- * appicon for process in only one single display, but this seems to be
- * enough for most, if not all, dockapps.
- */
-
-
-#include <X11/Xlib.h>
-#include <X11/xpm.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-
-
-extern Display *DADisplay;
-
-extern Window DAWindow;
-
-extern int DADepth;
-
-extern Visual *DAVisual;
-
-
-/* the callbacks for events related to the dockapp window your program wants
- * to handle */
-typedef struct {
- /* the dockapp window was destroyed */
- void (*destroy)();
- /* button pressed */
- void (*buttonPress)(int button, int state, int x, int y);
- /* button released */
- void (*buttonRelease)(int button, int state, int x, int y);
- /* pointer motion */
- void (*motion)(int x, int y);
- /* pointer entered dockapp window */
- void (*enter)();
- /* pointer leaved dockapp window */
- void (*leave)();
- /* timer expired */
- void (*timeout)();
-} DACallbacks;
-
-
-/* option argument types */
-enum {
- DONone, /* simple on/off flag */
- DOInteger, /* an integer number */
- DOString, /* a string */
- DONatural /* positive integer number */
-};
-
-
-typedef struct {
- char *shortForm; /* short form for option, like -w */
- char *longForm; /* long form for option, like
--withdrawn */
- char *description; /* description for the option */
-
- short type; /* type of argument */
-
- Bool used; /* if the argument was passed in the
- cmd line */
- /* the following are only set if the "used" field is True */
- union { /* a ptr for the value that was passed
- in the command line */
- void *ptr;
-
- int *integer;
-
- char **string;
- } value;
-} DAProgramOption;
-
-
-
-/*
- * DAParseArguments-
- * Command line argument parser. The program is exited if there are
- * syntax errors.
- *
- * -h, --help and --version are automatically handled (causing the program
- * to exit)
- *
- */
-void DAParseArguments(int argc, char **argv, DAProgramOption *options,
- int count, char *programDescription,
- char *versionDescription);
-
-
-/*
- * DAInitialize-
- * Initialize the dockapp, open a connection to the X server,
- * create the needed windows and setup them to become an appicon window.
- * It will automatically detect if Window Maker is present and use
- * an appropriate form form
- *
- * You must call this always before calling anything else (except for
- * DAParseArguments())
- *
- * Arguments:
- * display - the name of the display to connect to. Use "" to use the
- * default value
- * name - the name of your dockapp, used as the class name for
- * the WM_CLASS hint. Like WMYAClock
- * width, height - the size of the dockapp window. 48x48 is the
- * preferred size
- * argc, argv - the program arguments. argv[0] will be used as the
- * instance name for the WM_CLASS hint.
- */
-void DAInitialize(char *display, char *name, unsigned width, unsigned height,
- int argc, char **argv);
-
-/*
- * DASetShape-
- * Sets the shape mask of the dockapp to the specified one. This is
- * optional. If you pass None as shapeMask, the dockapp will become
- * non-shaped.
- *
- * This is only needed if you want the dockapp to be shaped.
- */
-void DASetShape(Pixmap shapeMask);
-
-/*
- * DASetPixmap-
- * Sets the image pixmap for the dockapp. Once you set the image with
- * it, you don't need to handle expose events.
- */
-void DASetPixmap(Pixmap pixmap);
-
-/*
- * DAMakePixmap-
- * Creates a pixmap suitable for using with DASetPixmap()
- */
-Pixmap DAMakePixmap();
-
-
-
-/*
- * DAMakePixmapFromData-
- * Creates a pixmap and mask from XPM data
- */
-Bool DAMakePixmapFromData(char **data, Pixmap *pixmap, Pixmap *mask,
- unsigned *width, unsigned *height);
-
-
-/*
- * Returns a color.
- */
-unsigned long DAGetColor(char *colorName);
-/*
- * DAShow-
- * Opens the dockapp.
- *
- * Always call this function or the dockapp won't show up.
- */
-void DAShow();
-
-/*
- * DASetCallbacks-
- * Register a set of callbacks for events like mouse clicks.
- *
- * Only needed if you want to receive some event.
- */
-void DASetCallbacks(DACallbacks *callbacks);
-
-/*
- * DASetTimeout-
- * Sets a timeout for the DAEventLoop(). The timeout callback
- * will be called whenever the app doens't get any events from the
- * X server in the specified time.
- */
-void DASetTimeout(int milliseconds);
-
-
-/*
- * DANextEventOrTimeout-
- * Waits until an event is received or the timeout limit is
- * expired. Returns True if an event was received.
- */
-Bool DANextEventOrTimeout(XEvent *event, unsigned long millisec);
-
-
-/*
- * DAProcessEvent-
- * Processes an event. Returns True if the event was handled and
- * False otherwise.
- *
- * Must be called from your event loop, unless you use DAEventLoop()
- */
-Bool DAProcessEvent(XEvent *event);
-
-/*
- * DAEventLoop-
- * Enters an event loop where events are processed until the dockapp
- * is closed. This function never returns.
- */
-void DAEventLoop();
-
-
-
-#endif
diff --git a/wmfortune/wmfortune.c b/wmfortune/wmfortune.c
index 83f0b4f..a32c380 100644
--- a/wmfortune/wmfortune.c
+++ b/wmfortune/wmfortune.c
@@ -25,7 +25,7 @@
#include <unistd.h>
#include <stdio.h>
-#include "dockapp.h"
+#include <libdockapp/dockapp.h>
#include "XPM/panel.xpm"
#include "XPM/panel_button_pressed.xpm"
#include "XPM/panel_window.xpm"
--
2.7.4
--
To unsubscribe, send mail to [email protected].