1 /* WMGlobe 1.3 - All the Earth on a WMaker Icon
2 * copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
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 ***************************************************************************/
37 #include "defnimap.xpm"
44 int main(int argc
, char *argv
[])
46 unsigned int borderwidth
= 1;
48 char *wname
= argv
[0];
53 XWindowAttributes attributes
;
58 XSizeHints mysizehints
;
60 Pixel back_pix
, fore_pix
;
66 int ok
, redoaction
, wait_release
, move_lat_flag
;
69 /** initialisation *********************/
74 move_lat_flag
= FALSE
;
78 setlocale(LC_TIME
, "");
81 fprintf(stdout
, "%s\n", setlocale(LC_TIME
, ""));
91 for (i
= 0; i
< nb_marker
; i
++)
92 if (i
!= moon_marker
&& i
!= sun_marker
) {
93 marker
[i
][0] = marker
[i
][0] * PI
/ 180.;
94 marker
[i
][1] = marker
[i
][1] * PI
/ 180.;
102 rond_bits
= cadre1_bits
;
105 rond_bits
= cadre2_bits
;
108 rond_bits
= cadre0_bits
;
110 if (p_type
== PTRANDOM
) {
115 /* setup long term mem allocation */
119 tdelay
.tv_sec
= (int) floor(delay
);
120 tdelay
.tv_usec
= (int) ((delay
- tdelay
.tv_sec
) * 1000000);
121 aml
= (int) floor(ambient_light
* 256);
124 /* ctx initialization */
126 if (!(dpy
= XOpenDisplay(dpy_name
))) {
127 fprintf(stderr
, "%s: can't open display \"%s\"\n",
128 wname
, XDisplayName(dpy_name
));
131 ctx
= myRCreateContext(dpy
, DefaultScreen(dpy
), NULL
);
133 if (ctx
->attribs
->use_shared_memory
) {
135 fprintf(stdout
, "remove flags use_shared_memory\n");
137 ctx
->attribs
->flags
^= RC_UseSharedMemory
;
138 ctx
->attribs
->use_shared_memory
= FALSE
;
139 ctx
->flags
.use_shared_pixmap
= 0;
142 fprintf(stdout
, "depth %d\n", ctx
->depth
);
147 * loading maps .............
150 if (dayfile
!= NULL
) {
151 map
= RLoadImage(ctx
, dayfile
, 0);
152 if (!use_default_nightmap
)
153 use_nightmap
= FALSE
;
156 fprintf(stdout
, "pb map ! file not found ?\n");
161 map
= RGetImageFromXPMData(ctx
, defmap_xpm
);
162 use_default_nightmap
= TRUE
;
165 fprintf(stdout
, "pb def map ! file not found ?\n");
170 fprintf(stdout
, "need a map !\n");
175 use_nightmap
= FALSE
;
176 use_default_nightmap
= FALSE
;
179 if (nightfile
!= NULL
) {
180 mapnight
= RLoadImage(ctx
, nightfile
, 0);
183 fprintf(stdout
, "pb map night! file not found ?\n");
188 if (use_default_nightmap
) {
189 mapnight
= RGetImageFromXPMData(ctx
, defnimap_xpm
);
193 "pb def map night ! file not found ?\n");
199 use_nightmap
= FALSE
;
204 use_nmap_ini
= use_nightmap
;
206 /* we need a night map of same size as day map */
208 if ((mapnight
->width
!= map
->width
)
209 || (mapnight
->height
!= map
->height
)) {
212 mapnight
= RScaleImage(tmp
, map
->width
, map
->height
);
218 /* some other init ..................................... */
219 ratiox
= (double) map
->width
/ (2 * PI
);
220 ratioy
= (double) map
->height
/ PI
;
221 mratiox
= (int) floor(ratiox
* 256);
222 mratioy
= (int) floor(ratioy
* 256);
223 loadxpm(ctx
->drawable
);
225 small
= RCreateImage(DIAMETRE
, DIAMETRE
, 0);
230 * first rendering of the earth
232 rotation_terre(DIAMETRE
/ 2, DIAMETRE
/ 2, 0);
234 do_something
= FALSE
;
236 /*************************************************************************
237 * well, here the problems begin : this code is a merge from wmgeneral and
238 * some stuff of wmaker, should be rewritten ...
239 ************************************************************************/
241 XGetWindowAttributes(dpy
, ctx
->drawable
, &attributes
);
243 if (!RConvertImage(ctx
, small
, &pix
)) {
244 fprintf(stdout
, "error small->&pix\n");
245 puts(RMessageForError(RErrorCode
));
251 mysizehints
.flags
= USSize
| USPosition
;
256 if (!XParseColor(dpy
, attributes
.colormap
, "white", &color
)) {
257 fprintf(stdout
, "wmglobe: can't parse white\n");
258 } else if (!XAllocColor(dpy
, attributes
.colormap
, &color
)) {
259 fprintf(stdout
, "wmglobe: can't allocate white\n");
261 back_pix
= color
.pixel
;
263 XGetWindowAttributes(dpy
, ctx
->drawable
, &attributes
);
266 if (!XParseColor(dpy
, attributes
.colormap
, "black", &color
)) {
267 fprintf(stdout
, "wmglobe: can't parse black\n");
268 } else if (!XAllocColor(dpy
, attributes
.colormap
, &color
)) {
269 fprintf(stdout
, "wmglobe: can't allocate black\n");
271 fore_pix
= color
.pixel
;
274 XWMGeometry(dpy
, ctx
->screen_number
, Geometry
, NULL
, borderwidth
,
275 &mysizehints
, &mysizehints
.x
, &mysizehints
.y
,
276 &mysizehints
.width
, &mysizehints
.height
, &dummy
);
277 mysizehints
.width
= DIAMETRE
;
278 mysizehints
.height
= DIAMETRE
;
281 XCreateSimpleWindow(dpy
, ctx
->drawable
, mysizehints
.x
,
282 mysizehints
.y
, mysizehints
.width
,
283 mysizehints
.height
, borderwidth
, fore_pix
,
286 iconwin
= XCreateSimpleWindow(dpy
, win
, mysizehints
.x
, mysizehints
.y
,
287 mysizehints
.width
, mysizehints
.height
,
288 borderwidth
, fore_pix
, back_pix
);
291 XSetWMNormalHints(dpy
, win
, &mysizehints
);
292 classHint
.res_name
= wname
;
293 classHint
.res_class
= wname
;
294 XSetClassHint(dpy
, win
, &classHint
);
296 XSelectInput(dpy
, win
,
297 ButtonPressMask
| ExposureMask
| ButtonReleaseMask
|
298 PointerMotionMask
| StructureNotifyMask
);
299 XSelectInput(dpy
, iconwin
,
300 ButtonPressMask
| ExposureMask
| ButtonReleaseMask
|
301 PointerMotionMask
| StructureNotifyMask
);
303 if (XStringListToTextProperty(&wname
, 1, &name
) == 0) {
304 fprintf(stdout
, "%s: can't allocate window name\n", wname
);
307 XSetWMName(dpy
, win
, &name
);
309 /* Create GC for drawing */
311 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
312 gcv
.foreground
= fore_pix
;
313 gcv
.background
= back_pix
;
314 gcv
.graphics_exposures
= 0;
315 NormalGC
= XCreateGC(dpy
, ctx
->drawable
, gcm
, &gcv
);
320 XCreateBitmapFromData(dpy
, win
, rond_bits
, DIAMETRE
, DIAMETRE
);
321 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, pixmask
,
323 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, pixmask
,
328 mywmhints
.initial_state
= option_iw
;
329 mywmhints
.icon_window
= iconwin
;
330 mywmhints
.icon_x
= mysizehints
.x
;
331 mywmhints
.icon_y
= mysizehints
.y
;
332 mywmhints
.window_group
= win
;
334 StateHint
| IconWindowHint
| IconPositionHint
| WindowGroupHint
;
336 XSetWMHints(dpy
, win
, &mywmhints
);
338 XSetCommand(dpy
, win
, argv
, argc
);
339 XMapWindow(dpy
, win
);
342 XCopyArea(dpy
, wmg
.pixmap
, win
, NormalGC
, 0, 0, DIAMETRE
, DIAMETRE
, 0,
345 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
348 * ================= MAIN LOOP ==================
351 while (XPending(dpy
)) {
352 XNextEvent(dpy
, &Event
);
353 switch (Event
.type
) {
355 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
363 * earth rotate when clic left (1) , zooming when middle (2)
364 * change screen to longitude / latitude when (3)
366 switch (Event
.xbutton
.button
) {
368 #ifdef MOUSE_LAT_NO_SHIFT
369 move_lat_flag
= TRUE
;
371 if (Event
.xbutton
.state
& ShiftMask
)
372 move_lat_flag
= TRUE
;
374 move_lat_flag
= FALSE
;
380 if (Event
.xbutton
.state
& ShiftMask
)
405 usleep(2 * VAL_USLEEP_SHORT
);
407 rotation_terre(Event
.xbutton
.x
, Event
.xbutton
.y
,
410 zooming(Event
.xbutton
.state
& ShiftMask
);
413 if (diftimev(tnext
, getimev()).tv_sec
< 0 || ok
) {
415 recalc(redoaction
== 1);
417 if (!myRConvertImage(ctx
, small
, &pix
)) {
418 fprintf(stderr
, "crash !?\n");
419 fprintf(stderr
, RMessageForError(RErrorCode
));
424 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
426 fprintf(stdout
, "draw\n");
428 do_something
= FALSE
;