In addition to the obvious simplification to the code by removing all the
window creation stuff, this also allows us to let users pick whether they
want to run fookb as a dockapp or as a normal windowed application at
runtime using libdockapp's --windowed command line option.  Previously,
this was done during build using configure's --enable-wmaker option.
---
 fookb/Makefile.am  |   4 +-
 fookb/configure.ac |   1 +
 fookb/fookb.c      | 229 ++++++-----------------------------------------------
 fookb/images.c     |   2 +-
 4 files changed, 29 insertions(+), 207 deletions(-)

diff --git a/fookb/Makefile.am b/fookb/Makefile.am
index 0f0a075..4c1840f 100644
--- a/fookb/Makefile.am
+++ b/fookb/Makefile.am
@@ -5,8 +5,8 @@ dist_man_MANS = fookb.1x
 dist_pkgdata_DATA = 1.xpm 2.xpm 3.xpm 4.xpm rus.xpm lat.xpm boom.xpm \
        En.xpm Ru.xpm beep_spring.au
 
-AM_CFLAGS = $(Xlib_CFLAGS) $(libXpm_CFLAGS) $(WUtil_CFLAGS)
-LIBS += $(Xlib_LIBS) $(libXpm_LIBS) $(WUtil_LIBS)
+AM_CFLAGS = $(Xlib_CFLAGS) $(libXpm_CFLAGS) $(WUtil_CFLAGS) 
$(libdockapp_CFLAGS)
+LIBS += $(Xlib_LIBS) $(libXpm_LIBS) $(WUtil_LIBS) $(libdockapp_LIBS)
 
 EXTRA_DIST = copyright fookb.cf KNOWN_BUGS LICENSE README.russian.koi8-r \
        README.russian.utf-8
diff --git a/fookb/configure.ac b/fookb/configure.ac
index ef0f509..ac37c18 100644
--- a/fookb/configure.ac
+++ b/fookb/configure.ac
@@ -17,6 +17,7 @@ dnl Checks for libraries.
 PKG_CHECK_MODULES([Xlib], [x11])
 PKG_CHECK_MODULES([libXpm], [xpm])
 PKG_CHECK_MODULES([WUtil], [WUtil])
+PKG_CHECK_MODULES([libdockapp], [dockapp])
 
 AC_ARG_ENABLE(
   [wmaker],
diff --git a/fookb/fookb.c b/fookb/fookb.c
index 7535214..c6cf888 100644
--- a/fookb/fookb.c
+++ b/fookb/fookb.c
@@ -17,6 +17,8 @@
 /* XKB fun */
 #include <X11/XKBlib.h>
 
+#include <libdockapp/dockapp.h>
+
 /* My own fun */
 #include "fookb.h"
 #include "images.h"
@@ -26,92 +28,27 @@
 #define sterror(x) (void)printf("Strange error, please report! %s:%d, %s\n",\
                __FILE__, __LINE__, x)
 
-
-static void getGC(Window win, GC *gc, Display *dpy)
-{
-       unsigned long valuemask = 0;    /* No data in ``values'' */
-       XGCValues values;
-       *gc = XCreateGC(dpy, win, valuemask, &values);
-       /* FIXME Check if there was an error */
-/*     XSetForeground(dpy, *gc, BlackPixel(dpy, scr)); */
-}
-
-
 int main(int argc, register char *argv[])
 {
-       Display *dpy;
-       int scr;
-       Window root;
-
-       int err;
-
-       int event_rtrn; /* for XkbOpenDisplay */
-       int error_rtrn;
-       int reason_rtrn;
-
-       XkbEvent labuda;        /* Xkb event. X event will be labuda.core */
-
-       Window billy;           /*   _The_ Window  */
-
-#ifdef WMAKER
-       Window dilly;           /* ...and his icon */
-#endif
-
-       int border = 0;         /* _The_ Window parameters */
-
-       XWMHints *wm_hints;
-       XClassHint class_hints;
-
-#ifdef WMAKER                  /* If we use Windowmaker, _The_ Window will */
-       XSizeHints *BigBunny;   /* be withdrawn. And we do not want to
-                                  place empty border by hand. */
-#endif
-
-       GC gc;                  /* Graphic context */
-
-       char resn[] = "fookb";
-       char resc[] = "Fookb";
-
-
+       XkbEvent labuda;        /* Xkb event. X event will be labuda.core */
        int state = 0;          /* We suppose that latin keyboard is the
                                   primal state FIXME */
+       Pixmap pixmap;
 
-       /*
-       event_rtrn = malloc(sizeof(int));
-       error_rtrn = malloc(sizeof(int));
-       reason_rtrn = malloc(sizeof(int));
-       */
-
-       XrmInitialize();        /* We should initialize X resource
-                                  manager before doing something else
-                                */
 
-       ParseOptions(&argc, argv);      /* We should parse command line
-                                          options and try to find '-display'
-                                          before opening X display */
+       DAParseArguments(argc, argv, NULL, 0,
+                        "XKB state indicator for Window Maker",
+                        PACKAGE_STRING);
 
-/* Go, fighters, go! */
-       dpy = XkbOpenDisplay(mydispname,
-                            &event_rtrn,
-                            &error_rtrn, NULL, NULL, &reason_rtrn);
-
-/* Oops. */
-       if (dpy == NULL) {
-               (void)puts("Cannot open display.");
-               exit(EXIT_FAILURE);
-       }
-
-       scr = DefaultScreen(dpy);
-       root = RootWindow(dpy, scr);
-
-       MoreOptions(dpy);               /* Now we can parse X server resource
-                                  database. It is not available
-                                  before display is opened */
+       DAOpenDisplay(NULL, argc, argv);
+       read_images(DADisplay);         /* Let's read icon images */
+       DACreateIcon(PACKAGE_NAME, get_width(), get_height(), argc, argv);
+       XSelectInput(DADisplay, DAWindow, ButtonPressMask);
 
 /* We would like receive the only Xkb event: XkbStateNotify. And only
  * when XkbLockGroup happens. */
 
-       if (False == XkbSelectEvents(dpy,
+       if (False == XkbSelectEvents(DADisplay,
                        XkbUseCoreKbd,
                        XkbAllEventsMask,
                        0)) {
@@ -119,7 +56,7 @@ int main(int argc, register char *argv[])
                exit(EXIT_FAILURE);
        } /* Deselect all events */
 
-       if (False == XkbSelectEventDetails(dpy,
+       if (False == XkbSelectEventDetails(DADisplay,
                                XkbUseCoreKbd,
                                XkbStateNotify,
                                XkbAllEventsMask,
@@ -128,127 +65,18 @@ int main(int argc, register char *argv[])
                exit(EXIT_FAILURE);
        } /* Select XkbStateNotify/XkbgroupLock */
 
-       read_images(dpy);               /* Let's read icon images */
-
-/* Run out! */
-       billy = XCreateSimpleWindow(dpy,
-                                   root,
-                                   0, 0,
-                                   get_width(), get_height(),
-                                   border,
-                                   BlackPixel(dpy, scr),
-                                   WhitePixel(dpy, scr));
-       XStoreName(dpy, billy, "fookb");
-
-#ifdef WMAKER
-       dilly = XCreateSimpleWindow(dpy,
-                                   root,
-                                   0, 0,
-                                   get_width(), get_height(),
-                                   border,
-                                   BlackPixel(dpy, scr),
-                                   WhitePixel(dpy, scr));
-#endif
-
-       class_hints.res_name = resn;
-       class_hints.res_class = resc;
-
-       err = XSetClassHint(dpy, billy, &class_hints);
-       switch(err) {
-               case BadAlloc:
-                       sterror("BadAlloc");
-                       exit(EXIT_FAILURE);
-               case BadWindow:
-                       sterror("BadWindow");
-                       exit(EXIT_FAILURE);
-       }
-
-       wm_hints = XAllocWMHints();
-       wm_hints->window_group = billy;
-
-#ifdef WMAKER
-       wm_hints->icon_window = dilly;
-#endif
-
-       wm_hints->input = False;
-       wm_hints->flags = InputHint | WindowGroupHint;
-
-#ifdef WMAKER
-       wm_hints->flags = wm_hints->flags | IconWindowHint;
-       err = XSetWMHints(dpy, dilly, wm_hints);
-       switch(err) {
-               case BadAlloc:
-                       sterror("BadAlloc");
-                       exit(EXIT_FAILURE);
-               case BadWindow:
-                       sterror("BadWindow");
-                       exit(EXIT_FAILURE);
-       }
-       wm_hints->initial_state = WithdrawnState;
-       wm_hints->flags = wm_hints->flags | StateHint;
-#endif
-
-       err = XSetWMHints(dpy, billy, wm_hints);
-       switch(err) {
-               case BadAlloc:
-                       sterror("BadAlloc");
-                       exit(EXIT_FAILURE);
-               case BadWindow:
-                       sterror("BadWindow");
-                       exit(EXIT_FAILURE);
-       }
-
-#ifdef WMAKER
-       /* Look at the comment for XSizeHints * BigBunny */
-       BigBunny = XAllocSizeHints();
-       if (NULL == BigBunny) {
-               (void)printf("Not enough memory, %s:%d.\n", __FILE__, __LINE__);
-               exit(EXIT_FAILURE);
-       }
-/* Nasty Hack. XSizeHints.x & XSizeHints.y are obsolete. */
-       BigBunny->x = 0;
-       BigBunny->y = 0;
-       BigBunny->flags = PPosition;
-       XSetWMNormalHints(dpy, billy, BigBunny);
-       XFree(BigBunny);
-#endif
-
-/* The only thing we would like to do - update our billy */
-#ifndef WMAKER
-       XSelectInput(dpy, billy, ExposureMask | ButtonPressMask);
-#else                          /* ...or dilly?! */
-       XSelectInput(dpy, dilly, ExposureMask | ButtonPressMask);
-#endif
-
-       XSetCommand(dpy, billy, argv, argc);
-
-/* Programmer supplied functions */
-#ifndef WMAKER
-       getGC(billy, &gc, dpy);
-#else
-       getGC(dilly, &gc, dpy);
-#endif
+       pixmap = DAMakePixmap();
 
+       update_window(pixmap, DAGC, state, DADisplay);
+       DASetPixmap(pixmap);
 
-/* Let's look */
-       XMapWindow(dpy, billy); /* We would like to see the window. */
+       DAShow();
 
 /* HELLO! HELLO! HELLO! Is that our GOOD FRIEND main loop here? */
        while (1) {
-               XNextEvent(dpy, &labuda.core);
+               XNextEvent(DADisplay, &labuda.core);
                switch (labuda.core.type) {
 
-               case Expose:    /* We should update our window. */
-                       if (labuda.core.xexpose.count != 0)
-                               /* Well, I knew what does it mean,
-                                  but I forgot :) */
-                               break;
-#ifndef WMAKER
-                       update_window(billy, gc, state, dpy);
-#else
-                       update_window(dilly, gc, state, dpy);
-#endif
-                       break;
                case ButtonPress:
 
                        switch (labuda.core.xbutton.button) {
@@ -256,7 +84,7 @@ int main(int argc, register char *argv[])
 #ifdef DEBUG
                                puts("Button1 pressed.");
 #endif
-                               XkbLockGroup(dpy,
+                               XkbLockGroup(DADisplay,
                                             XkbUseCoreKbd,
                                             (state + 1) % 4);
                                break;
@@ -264,7 +92,7 @@ int main(int argc, register char *argv[])
 #ifdef DEBUG
                                puts("Button2 pressed.");
 #endif
-                               XkbLockGroup(dpy,
+                               XkbLockGroup(DADisplay,
                                             XkbUseCoreKbd,
                                             (state + 3) % 4);
                                break;
@@ -272,12 +100,9 @@ int main(int argc, register char *argv[])
 #ifdef DEBUG
                                puts("Button3 pressed, bye.");
 #endif
-                               XFreeGC(dpy, gc);
-                               XDestroyWindow(dpy, billy);
-#ifdef WMAKER
-                               XDestroyWindow(dpy, dilly);
-#endif
-                               XCloseDisplay(dpy);
+                               XFreeGC(DADisplay, DAGC);
+                               XDestroyWindow(DADisplay, DAWindow);
+                               XCloseDisplay(DADisplay);
                                exit(0);
                        }
                        break;
@@ -289,16 +114,12 @@ int main(int argc, register char *argv[])
 #endif
                        if ((state < 0) || (state > 4))
                                state = 4;
-#ifndef WMAKER
-                       update_window(billy, gc, state, dpy);
-#else
-                       update_window(dilly, gc, state, dpy);
-#endif
+                       update_window(pixmap, DAGC, state, DADisplay);
+                       DASetPixmap(pixmap);
 
 #ifdef DEBUG
                        puts(".");      /* XkbLockGroup happens */
 #endif
                }
        }
-
 }
diff --git a/fookb/images.c b/fookb/images.c
index 8f24949..21c04e9 100644
--- a/fookb/images.c
+++ b/fookb/images.c
@@ -150,7 +150,7 @@ void read_images(Display *dpy)
 
 }
 
-void update_window(Window win, GC gc, unsigned int whattodo, Display *dpy)
+void update_window(Drawable win, GC gc, unsigned int whattodo, Display *dpy)
 {
        int err;
 
-- 
2.11.0


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to