wmfortune: Add version 0.241 to repository.
From http://gentoo.osuosl.org/distfiles/wmfortune-0.241.tar.gz
This commit is contained in:
parent
ee10905069
commit
5eab1dd9f3
34
wmfortune/CHANGES
Normal file
34
wmfortune/CHANGES
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
RCS file: RCS/wmfortune.c,v
|
||||||
|
Working file: wmfortune.c
|
||||||
|
head: 0.24
|
||||||
|
branch:
|
||||||
|
locks: strict
|
||||||
|
access list:
|
||||||
|
symbolic names:
|
||||||
|
keyword substitution: kv
|
||||||
|
total revisions: 5; selected revisions: 5
|
||||||
|
description:
|
||||||
|
wmfortune: DockApp that shows the fortune messages.
|
||||||
|
----------------------------
|
||||||
|
revision 0.24
|
||||||
|
date: 2000/03/28 01:49:58; author: sugano; state: Exp; lines: +4 -2
|
||||||
|
found the small bug arround the button press.
|
||||||
|
----------------------------
|
||||||
|
revision 0.23
|
||||||
|
date: 2000/03/27 00:18:55; author: sugano; state: Exp; lines: +6 -6
|
||||||
|
changed the UI a little.
|
||||||
|
----------------------------
|
||||||
|
revision 0.22
|
||||||
|
date: 2000/03/26 23:39:58; author: sugano; state: Exp; lines: +30 -27
|
||||||
|
very stable, but UI's not finished.
|
||||||
|
----------------------------
|
||||||
|
revision 0.21
|
||||||
|
date: 2000/03/25 17:03:52; author: sugano; state: Exp; lines: +136 -87
|
||||||
|
beautifulized the code a little.
|
||||||
|
much better to read.
|
||||||
|
----------------------------
|
||||||
|
revision 0.20
|
||||||
|
date: 2000/03/25 14:50:27; author: sugano; state: Exp;
|
||||||
|
Started using the RCS.
|
||||||
|
=============================================================================
|
17
wmfortune/INSTALL
Normal file
17
wmfortune/INSTALL
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
WMFORTUNE INSTALLATION
|
||||||
|
|
||||||
|
Before installation.
|
||||||
|
|
||||||
|
Make sure fortune command is in your path.
|
||||||
|
|
||||||
|
|
||||||
|
To compile and install wmfortune.
|
||||||
|
|
||||||
|
(1) Edit Makefile as you like.
|
||||||
|
(2) Type "make"
|
||||||
|
(3) Then type "make install"
|
||||||
|
|
||||||
|
|
||||||
|
To uninstall.
|
||||||
|
|
||||||
|
Just type "make uninstall".
|
35
wmfortune/Makefile
Normal file
35
wmfortune/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
### Edit here as you like :)
|
||||||
|
BINDIR = /usr/local/bin
|
||||||
|
############################
|
||||||
|
|
||||||
|
DEST = wmfortune
|
||||||
|
|
||||||
|
# Programs used to move the binary to the proper place.
|
||||||
|
INSTALL = /usr/bin/install
|
||||||
|
INSTALL_PROGRAM = ${INSTALL} -m 755
|
||||||
|
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
|
||||||
|
|
||||||
|
$(DEST) : $(OBJ)
|
||||||
|
$(CC) $(OBJ) -L$(XLIBDIR) $(XLIB) -o $(DEST)
|
||||||
|
|
||||||
|
dockapp.o: dockapp.c
|
||||||
|
$(CC) $(OPTIMIZE) $< -c
|
||||||
|
|
||||||
|
wmfortune.o: wmfortune.c
|
||||||
|
$(CC) $(OPTIMIZE) $< -c
|
||||||
|
|
||||||
|
install:
|
||||||
|
$(INSTALL_PROGRAM) ./$(DEST) $(BINDIR)/$(DEST)
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
$(UNINSTALL_PROGRAM) $(BINDIR)/$(DEST)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(DEST) $(OBJ) *~
|
28
wmfortune/README
Normal file
28
wmfortune/README
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
WMFORTUNE
|
||||||
|
Copyrigth(C) 2000, Makoto SUGANO.
|
||||||
|
(m-sugano@01.246.ne.jp)
|
||||||
|
|
||||||
|
|
||||||
|
What is this?
|
||||||
|
============
|
||||||
|
|
||||||
|
It's a dock-app that shows you forune messages.
|
||||||
|
|
||||||
|
The latest version will be in available in:
|
||||||
|
http://www.01.246.ne.jp/~m-sugano/apps.html
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
How I install it?
|
||||||
|
=================
|
||||||
|
|
||||||
|
Read INSTALL files.
|
||||||
|
|
||||||
|
|
||||||
|
License?
|
||||||
|
========
|
||||||
|
|
||||||
|
wmfortune is based on GPL'ed software.
|
||||||
|
This program is distributed under the GPL license.
|
||||||
|
|
2
wmfortune/TODO
Normal file
2
wmfortune/TODO
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
2000 JAN 25
|
||||||
|
...
|
1143
wmfortune/XPM/panel.xpm
Normal file
1143
wmfortune/XPM/panel.xpm
Normal file
File diff suppressed because it is too large
Load diff
1083
wmfortune/XPM/panel_button_pressed.xpm
Normal file
1083
wmfortune/XPM/panel_button_pressed.xpm
Normal file
File diff suppressed because it is too large
Load diff
70
wmfortune/XPM/panel_window.xpm
Normal file
70
wmfortune/XPM/panel_window.xpm
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/* XPM */
|
||||||
|
static char * panel_window_xpm[] = {
|
||||||
|
"64 64 3 1",
|
||||||
|
" c None",
|
||||||
|
". c #000000",
|
||||||
|
"+ c #FFFFFF",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" .......................................................+ ",
|
||||||
|
" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" "};
|
565
wmfortune/dockapp.c
Normal file
565
wmfortune/dockapp.c
Normal file
|
@ -0,0 +1,565 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
230
wmfortune/dockapp.h
Normal file
230
wmfortune/dockapp.h
Normal file
|
@ -0,0 +1,230 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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
|
222
wmfortune/wmfortune.c
Normal file
222
wmfortune/wmfortune.c
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
/*
|
||||||
|
* $Id: wmfortune.c,v 0.24 2000/03/28 01:49:58 sugano Exp $
|
||||||
|
* wmfortune Copyright (c) 2000 Makoto Sugano
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define BUFF_SIZE 1024
|
||||||
|
#define SCROLL_DEFAULT_SPEED 1000
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "dockapp.h"
|
||||||
|
#include "XPM/panel.xpm"
|
||||||
|
#include "XPM/panel_button_pressed.xpm"
|
||||||
|
#include "XPM/panel_window.xpm"
|
||||||
|
|
||||||
|
/* WINDOW: window for showing the messages */
|
||||||
|
#define WINDOW_X 4
|
||||||
|
#define WINDOW_Y 4
|
||||||
|
#define WINDOW_WIDTH 56
|
||||||
|
#define WINDOW_HEIGHT 22
|
||||||
|
|
||||||
|
/* BUTTON: button for the new fortune message */
|
||||||
|
#define BUTTON_X 6
|
||||||
|
#define BUTTON_Y 32
|
||||||
|
#define BUTTON_WIDTH 52
|
||||||
|
#define BUTTON_HEIGHT 28
|
||||||
|
|
||||||
|
/* 6 pixels are used to draw a letter */
|
||||||
|
#define PIXELS_PER_LETTER 6
|
||||||
|
|
||||||
|
#define STRING_Y 18
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pixel lag between the last letter of the previous message
|
||||||
|
* and the first letter of the next message.
|
||||||
|
* if set to 0, the messages appear quickly after
|
||||||
|
* the previous messages ends.
|
||||||
|
*/
|
||||||
|
#define MESSAGE_LAG 5
|
||||||
|
|
||||||
|
char *displayName = "";
|
||||||
|
int speed = SCROLL_DEFAULT_SPEED;
|
||||||
|
|
||||||
|
/* global variables for main() and callbacks */
|
||||||
|
FILE *fortune;
|
||||||
|
Pixmap pixmap;
|
||||||
|
Pixmap panel_button_pressed_pixmap;
|
||||||
|
Pixmap panel_pixmap, panel_mask;
|
||||||
|
GC gc;
|
||||||
|
int c;
|
||||||
|
char buff[BUFF_SIZE];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* i: used to count the number of letters in fill_buff().
|
||||||
|
* j: the number that points the message starting pixel.
|
||||||
|
*/
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
/* fill the buffer with the fortune message. */
|
||||||
|
static void
|
||||||
|
fill_buff (void)
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
memset(buff, '\0', BUFF_SIZE);
|
||||||
|
if (!(fortune = popen("fortune -s", "r")))
|
||||||
|
{
|
||||||
|
perror("fortune");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (( c = fgetc(fortune)) != EOF)
|
||||||
|
{
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
buff[i++] = ' ';
|
||||||
|
}
|
||||||
|
else if (c == '\t')
|
||||||
|
{
|
||||||
|
buff[i++] = ' ';
|
||||||
|
buff[i++] = ' ';
|
||||||
|
buff[i++] = ' ';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buff[i++] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
j = i + MESSAGE_LAG;
|
||||||
|
pclose(fortune);
|
||||||
|
}
|
||||||
|
|
||||||
|
static DAProgramOption options[] = {
|
||||||
|
{"-d", "--displayname", "display to use.", DOString, False, {&displayName}},
|
||||||
|
{"-s", "--speed", "scrolling speed. (default 1000 dot/ms)", DOInteger, False, {&speed}},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
buttonReleaseCallback (int button, int state, int x, int y)
|
||||||
|
{
|
||||||
|
if (button == 1 && BUTTON_X < x &&
|
||||||
|
x < (BUTTON_X + BUTTON_WIDTH) &&
|
||||||
|
BUTTON_Y < y && y < (BUTTON_Y + BUTTON_HEIGHT))
|
||||||
|
{
|
||||||
|
fill_buff();
|
||||||
|
}
|
||||||
|
XCopyArea(DADisplay, panel_pixmap, pixmap, gc,
|
||||||
|
BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
|
BUTTON_X, BUTTON_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
buttonPressCallback (int button, int state, int x, int y)
|
||||||
|
{
|
||||||
|
if (button == 1 && BUTTON_X < x &&
|
||||||
|
x < (BUTTON_X + BUTTON_WIDTH) &&
|
||||||
|
BUTTON_Y < y && y < (BUTTON_Y + BUTTON_HEIGHT))
|
||||||
|
{
|
||||||
|
XCopyArea(DADisplay, panel_button_pressed_pixmap, pixmap, gc,
|
||||||
|
BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
|
BUTTON_X, BUTTON_Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
Pixmap panel_window_pixmap;
|
||||||
|
|
||||||
|
int w = 64, h = 64;
|
||||||
|
|
||||||
|
DACallbacks callbacks = {NULL,buttonPressCallback
|
||||||
|
,buttonReleaseCallback,NULL,NULL,NULL,NULL};
|
||||||
|
|
||||||
|
DAParseArguments(argc, argv, options,
|
||||||
|
sizeof(options)/sizeof(DAProgramOption),
|
||||||
|
"dockapp that shows the messages from fortune command.", "$Id: wmfortune.c,v 0.24 2000/03/28 01:49:58 sugano Exp $");
|
||||||
|
|
||||||
|
fill_buff();
|
||||||
|
|
||||||
|
DAInitialize(displayName, "wmfortune", 64, 64, argc, argv);
|
||||||
|
pixmap = DAMakePixmap();
|
||||||
|
|
||||||
|
/* making pixmap for the panel */
|
||||||
|
DAMakePixmapFromData(panel_xpm, &panel_pixmap,
|
||||||
|
&panel_mask, &w, &h);
|
||||||
|
DAMakePixmapFromData(panel_button_pressed_xpm,
|
||||||
|
&panel_button_pressed_pixmap, NULL, &w, &h);
|
||||||
|
DAMakePixmapFromData(panel_window_xpm,
|
||||||
|
&panel_window_pixmap, NULL, &w, &h);
|
||||||
|
|
||||||
|
/* setting up the mask for the panel */
|
||||||
|
DASetShape(panel_mask);
|
||||||
|
DASetPixmap(panel_pixmap);
|
||||||
|
|
||||||
|
/* setting up the graphic context */
|
||||||
|
gc = DefaultGC(DADisplay, DefaultScreen(DADisplay));
|
||||||
|
|
||||||
|
DASetCallbacks(&callbacks);
|
||||||
|
DAShow();
|
||||||
|
|
||||||
|
/* drawing the button */
|
||||||
|
XCopyArea(DADisplay, panel_pixmap, pixmap, gc,
|
||||||
|
BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
|
BUTTON_X, BUTTON_Y);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
|
/* sets the foreground color green */
|
||||||
|
XSetForeground(DADisplay, gc, DAGetColor("green"));
|
||||||
|
XCopyArea(DADisplay, panel_window_pixmap, pixmap, gc,
|
||||||
|
WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT,
|
||||||
|
WINDOW_X, WINDOW_Y);
|
||||||
|
XDrawString(DADisplay, pixmap, gc, j, STRING_Y, buff, strlen(buff));
|
||||||
|
|
||||||
|
DASetPixmap(pixmap);
|
||||||
|
|
||||||
|
/* scroll the message by a pixel to left */
|
||||||
|
i--;
|
||||||
|
j = i + MESSAGE_LAG;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* starts scrolling the messages from the beginning
|
||||||
|
* if the message ends.
|
||||||
|
*/
|
||||||
|
if (j == - (PIXELS_PER_LETTER) * strlen(buff))
|
||||||
|
{
|
||||||
|
/* if not 64, message suddenly appears in the window */
|
||||||
|
i = 64;
|
||||||
|
j = i + MESSAGE_LAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle all pending X events */
|
||||||
|
while (XPending(DADisplay))
|
||||||
|
{
|
||||||
|
XNextEvent(DADisplay, &ev);
|
||||||
|
DAProcessEvent(&ev);
|
||||||
|
}
|
||||||
|
usleep(speed);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue