2 * $Id: wmfortune.c,v 0.24 2000/03/28 01:49:58 sugano Exp $
3 * wmfortune Copyright (c) 2000 Makoto Sugano
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #define BUFF_SIZE 1024
24 #define SCROLL_DEFAULT_SPEED 1000
29 #include <libdockapp/dockapp.h>
30 #include "XPM/panel.xpm"
31 #include "XPM/panel_button_pressed.xpm"
32 #include "XPM/panel_window.xpm"
34 /* WINDOW: window for showing the messages */
37 #define WINDOW_WIDTH 56
38 #define WINDOW_HEIGHT 22
40 /* BUTTON: button for the new fortune message */
43 #define BUTTON_WIDTH 52
44 #define BUTTON_HEIGHT 28
46 /* 6 pixels are used to draw a letter */
47 #define PIXELS_PER_LETTER 6
52 * pixel lag between the last letter of the previous message
53 * and the first letter of the next message.
54 * if set to 0, the messages appear quickly after
55 * the previous messages ends.
59 char *displayName
= "";
60 int speed
= SCROLL_DEFAULT_SPEED
;
62 /* global variables for main() and callbacks */
65 Pixmap panel_button_pressed_pixmap
;
66 Pixmap panel_pixmap
, panel_mask
;
72 * i: used to count the number of letters in fill_buff().
73 * j: the number that points the message starting pixel.
77 /* fill the buffer with the fortune message. */
83 memset(buff
, '\0', BUFF_SIZE
);
84 if (!(fortune
= popen("fortune -s", "r")))
90 while (( c
= fgetc(fortune
)) != EOF
)
112 static DAProgramOption options
[] = {
113 {"-d", "--displayname", "display to use.", DOString
, False
, {&displayName
}},
114 {"-s", "--speed", "scrolling speed. (default 1000 dot/ms)", DOInteger
, False
, {&speed
}},
118 buttonReleaseCallback (int button
, int state
, int x
, int y
)
120 if (button
== 1 && BUTTON_X
< x
&&
121 x
< (BUTTON_X
+ BUTTON_WIDTH
) &&
122 BUTTON_Y
< y
&& y
< (BUTTON_Y
+ BUTTON_HEIGHT
))
126 XCopyArea(DADisplay
, panel_pixmap
, pixmap
, gc
,
127 BUTTON_X
, BUTTON_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
,
132 buttonPressCallback (int button
, int state
, int x
, int y
)
134 if (button
== 1 && BUTTON_X
< x
&&
135 x
< (BUTTON_X
+ BUTTON_WIDTH
) &&
136 BUTTON_Y
< y
&& y
< (BUTTON_Y
+ BUTTON_HEIGHT
))
138 XCopyArea(DADisplay
, panel_button_pressed_pixmap
, pixmap
, gc
,
139 BUTTON_X
, BUTTON_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
,
145 main(int argc
, char **argv
)
147 Pixmap panel_window_pixmap
;
149 short unsigned int w
= 64, h
= 64;
151 DACallbacks callbacks
= {NULL
,buttonPressCallback
152 ,buttonReleaseCallback
,NULL
,NULL
,NULL
,NULL
};
154 DAParseArguments(argc
, argv
, options
,
155 sizeof(options
)/sizeof(DAProgramOption
),
156 "dockapp that shows the messages from fortune command.", "$Id: wmfortune.c,v 0.24 2000/03/28 01:49:58 sugano Exp $");
160 DAInitialize(displayName
, "wmfortune", 64, 64, argc
, argv
);
161 pixmap
= DAMakePixmap();
163 /* making pixmap for the panel */
164 DAMakePixmapFromData(panel_xpm
, &panel_pixmap
,
165 &panel_mask
, &w
, &h
);
166 DAMakePixmapFromData(panel_button_pressed_xpm
,
167 &panel_button_pressed_pixmap
, NULL
, &w
, &h
);
168 DAMakePixmapFromData(panel_window_xpm
,
169 &panel_window_pixmap
, NULL
, &w
, &h
);
171 /* setting up the mask for the panel */
172 DASetShape(panel_mask
);
173 DASetPixmap(panel_pixmap
);
175 /* setting up the graphic context */
176 gc
= DefaultGC(DADisplay
, DefaultScreen(DADisplay
));
178 DASetCallbacks(&callbacks
);
181 /* drawing the button */
182 XCopyArea(DADisplay
, panel_pixmap
, pixmap
, gc
,
183 BUTTON_X
, BUTTON_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
,
190 /* sets the foreground color green */
191 XSetForeground(DADisplay
, gc
, DAGetColor("green"));
192 XCopyArea(DADisplay
, panel_window_pixmap
, pixmap
, gc
,
193 WINDOW_X
, WINDOW_Y
, WINDOW_WIDTH
, WINDOW_HEIGHT
,
195 XDrawString(DADisplay
, pixmap
, gc
, j
, STRING_Y
, buff
, strlen(buff
));
199 /* scroll the message by a pixel to left */
204 * starts scrolling the messages from the beginning
205 * if the message ends.
207 if (j
== - (PIXELS_PER_LETTER
) * strlen(buff
))
209 /* if not 64, message suddenly appears in the window */
214 /* handle all pending X events */
215 while (XPending(DADisplay
))
217 XNextEvent(DADisplay
, &ev
);