1 /* WMGlobe 0.5 - All the Earth on a WMaker Icon
2 * copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 ***************************************************************************/
19 * I used many functions of wmgeneral.c ("openXwindow")
20 * for the main function of wmglobe.c
21 * wmgeneral.c was taken from wmaker applet wmtune-1.0 :
22 * Author: Martijn Pieterse (pieterse@xs4all.nl)
24 * wmglobe.c uses functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib
25 ***************************************************************************/
35 #include "defnimap.xpm"
38 /***************************************************************************/
40 int main(int argc
, char *argv
[])
42 unsigned int borderwidth
= 1;
44 char *wname
= argv
[0];
49 XWindowAttributes attributes
;
54 XSizeHints mysizehints
;
56 Pixel back_pix
, fore_pix
;
62 int ok
, redoaction
, wait_release
, move_lat_flag
;
65 /** initialisation *********************/
70 move_lat_flag
= FALSE
;
74 setlocale(LC_TIME
, "");
77 fprintf(stdout
, "%s\n", setlocale(LC_TIME
, ""));
86 rond_bits
= cadre1_bits
;
89 rond_bits
= cadre2_bits
;
92 rond_bits
= cadre0_bits
;
94 if (p_type
== PTRANDOM
) {
100 tdelay
.tv_sec
= (int) floor(delay
);
101 tdelay
.tv_usec
= (int) ((delay
- tdelay
.tv_sec
) * 1000000);
102 aml
= (int) floor(ambient_light
* 256);
104 /****************************************************************************/
106 if (!(dpy
= XOpenDisplay(dpy_name
))) {
107 fprintf(stderr
, "%s: can't open display \"%s\"\n",
108 wname
, XDisplayName(dpy_name
));
111 ctx
= myRCreateContext(dpy
, DefaultScreen(dpy
), NULL
);
113 if (ctx
->attribs
->use_shared_memory
) {
115 fprintf(stdout
, "enleve les flags use_shared_memory\n");
117 ctx
->attribs
->flags
^= RC_UseSharedMemory
;
118 ctx
->attribs
->use_shared_memory
= FALSE
;
119 ctx
->flags
.use_shared_pixmap
= 0;
122 fprintf(stdout
, "depth %d\n", ctx
->depth
);
127 * loading maps .............
131 if (dayfile
!= NULL
) {
132 map
= RLoadImage(ctx
, dayfile
, 0);
134 fprintf(stdout
, "pb map ! file not found ?\n");
139 map
= RGetImageFromXPMData(ctx
, defmap_xpm
);
141 fprintf(stdout
, "pb def map ! file not found ?\n");
148 fprintf(stdout
, "need a map !\n");
154 if (nightfile
!= NULL
) {
155 mapnight
= RLoadImage(ctx
, nightfile
, 0);
157 fprintf(stdout
, "pb map night! file not found ?\n");
162 mapnight
= RGetImageFromXPMData(ctx
, defnimap_xpm
);
164 fprintf(stdout
, "pb def map night ! file not found ?\n");
169 /* not very useful... */
170 use_nightmap
= FALSE
;
174 use_nmap_ini
= use_nightmap
;
176 use_nightmap
= FALSE
;
177 /* some other init ..................................... */
178 ratiox
= (double) map
->width
/ (2 * PI
);
179 ratioy
= (double) map
->height
/ PI
;
180 mratiox
= (int) floor(ratiox
* 256);
181 mratioy
= (int) floor(ratioy
* 256);
182 loadxpm(ctx
->drawable
);
184 small
= RCreateImage(DIAMETRE
, DIAMETRE
, 1);
187 /*...................................................... */
190 * first rendering of the earth
193 do_something
= FALSE
;
196 /*************************************************************************
197 * well, here the problems begin : this code is a merge from wmgeneral and
198 * some stuff of wmaker, should be rewritten ...
199 ************************************************************************/
203 XGetWindowAttributes(dpy
, ctx
->drawable
, &attributes
);
205 if (!RConvertImage(ctx
, small
, &pix
)) {
206 fprintf(stdout
, "error small->&pix\n");
207 puts(RMessageForError(RErrorCode
));
213 mysizehints
.flags
= USSize
| USPosition
;
218 if (!XParseColor(dpy
, attributes
.colormap
, "white", &color
)) {
219 fprintf(stdout
, "wmglobe: can't parse white\n");
220 } else if (!XAllocColor(dpy
, attributes
.colormap
, &color
)) {
221 fprintf(stdout
, "wmglobe: can't allocate white\n");
223 back_pix
= color
.pixel
;
225 XGetWindowAttributes(dpy
, ctx
->drawable
, &attributes
);
228 if (!XParseColor(dpy
, attributes
.colormap
, "black", &color
)) {
229 fprintf(stdout
, "wmglobe: can't parse black\n");
230 } else if (!XAllocColor(dpy
, attributes
.colormap
, &color
)) {
231 fprintf(stdout
, "wmglobe: can't allocate black\n");
233 fore_pix
= color
.pixel
;
236 XWMGeometry(dpy
, ctx
->screen_number
, Geometry
, NULL
, borderwidth
, &mysizehints
,
237 &mysizehints
.x
, &mysizehints
.y
, &mysizehints
.width
, &mysizehints
.height
, &dummy
);
238 mysizehints
.width
= DIAMETRE
;
239 mysizehints
.height
= DIAMETRE
;
241 win
= XCreateSimpleWindow(dpy
, ctx
->drawable
, mysizehints
.x
, mysizehints
.y
,
242 mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
244 iconwin
= XCreateSimpleWindow(dpy
, win
, mysizehints
.x
, mysizehints
.y
,
245 mysizehints
.width
, mysizehints
.height
, borderwidth
, fore_pix
, back_pix
);
248 XSetWMNormalHints(dpy
, win
, &mysizehints
);
249 classHint
.res_name
= wname
;
250 classHint
.res_class
= wname
;
251 XSetClassHint(dpy
, win
, &classHint
);
253 XSelectInput(dpy
, win
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
254 XSelectInput(dpy
, iconwin
, ButtonPressMask
| ExposureMask
| ButtonReleaseMask
| PointerMotionMask
| StructureNotifyMask
);
256 if (XStringListToTextProperty(&wname
, 1, &name
) == 0) {
257 fprintf(stdout
, "%s: can't allocate window name\n", wname
);
260 XSetWMName(dpy
, win
, &name
);
262 /* Create GC for drawing */
264 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
265 gcv
.foreground
= fore_pix
;
266 gcv
.background
= back_pix
;
267 gcv
.graphics_exposures
= 0;
268 NormalGC
= XCreateGC(dpy
, ctx
->drawable
, gcm
, &gcv
);
272 pixmask
= XCreateBitmapFromData(dpy
, win
, rond_bits
, DIAMETRE
, DIAMETRE
);
273 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
274 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
278 mywmhints
.initial_state
= option_iw
;
279 mywmhints
.icon_window
= iconwin
;
280 mywmhints
.icon_x
= mysizehints
.x
;
281 mywmhints
.icon_y
= mysizehints
.y
;
282 mywmhints
.window_group
= win
;
283 mywmhints
.flags
= StateHint
| IconWindowHint
| IconPositionHint
| WindowGroupHint
;
285 XSetWMHints(dpy
, win
, &mywmhints
);
287 XSetCommand(dpy
, win
, argv
, argc
);
288 XMapWindow(dpy
, win
);
290 /****************************************************************************/
293 XCopyArea(dpy
, wmg
.pixmap
, win
, NormalGC
, 0, 0, DIAMETRE
, DIAMETRE
, 0, 0);
296 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
299 * ================= MAIN LOOP ==================
302 while (XPending(dpy
)) {
303 XNextEvent(dpy
, &Event
);
304 switch (Event
.type
) {
306 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
314 * earth rotate when clic left (1) , zooming when middle (2)
315 * change screen to longitude / latitude when (3)
317 switch (Event
.xbutton
.button
) {
319 #ifdef MOUSE_LAT_NO_SHIFT
320 move_lat_flag
= TRUE
;
322 if (Event
.xbutton
.state
& ShiftMask
)
323 move_lat_flag
= TRUE
;
325 move_lat_flag
= FALSE
;
331 if (Event
.xbutton
.state
& ShiftMask
)
356 usleep(2 * VAL_USLEEP_SHORT
);
358 rotation_terre(Event
.xbutton
.x
, Event
.xbutton
.y
, move_lat_flag
);
360 zooming(Event
.xbutton
.state
& ShiftMask
);
363 if (diftimev(tnext
, getimev()).tv_sec
< 0 || ok
) {
365 recalc(redoaction
== 1);
367 if (!myRConvertImage(ctx
, small
, &pix
)) {
368 fprintf(stdout
, "plante !?\n");
369 fprintf(stdout
, RMessageForError(RErrorCode
));
374 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
376 fprintf(stdout
, "draw\n");
378 do_something
= FALSE
;
384 * Still wonder about freeing some memory for X