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 ***************************************************************************/
35 #include "defnimap.xpm"
42 int main(int argc
, char *argv
[])
44 unsigned int borderwidth
= 1;
46 char *wname
= argv
[0];
51 XWindowAttributes attributes
;
56 XSizeHints mysizehints
;
58 Pixel back_pix
, fore_pix
;
64 int ok
, redoaction
, wait_release
, move_lat_flag
;
67 /** initialisation *********************/
72 move_lat_flag
= FALSE
;
76 setlocale(LC_TIME
, "");
79 fprintf(stdout
, "%s\n", setlocale(LC_TIME
, ""));
89 for (i
= 0; i
< nb_marker
; i
++)
90 if (i
!= moon_marker
&& i
!= sun_marker
) {
91 marker
[i
][0] = marker
[i
][0] * PI
/ 180.;
92 marker
[i
][1] = marker
[i
][1] * PI
/ 180.;
100 rond_bits
= cadre1_bits
;
103 rond_bits
= cadre2_bits
;
106 rond_bits
= cadre0_bits
;
108 if (p_type
== PTRANDOM
) {
113 /* setup long term mem allocation */
117 tdelay
.tv_sec
= (int) floor(delay
);
118 tdelay
.tv_usec
= (int) ((delay
- tdelay
.tv_sec
) * 1000000);
119 aml
= (int) floor(ambient_light
* 256);
122 /* ctx initialization */
124 if (!(dpy
= XOpenDisplay(dpy_name
))) {
125 fprintf(stderr
, "%s: can't open display \"%s\"\n",
126 wname
, XDisplayName(dpy_name
));
129 ctx
= myRCreateContext(dpy
, DefaultScreen(dpy
), NULL
);
131 if (ctx
->attribs
->use_shared_memory
) {
133 fprintf(stdout
, "remove flags use_shared_memory\n");
135 ctx
->attribs
->flags
^= RC_UseSharedMemory
;
136 ctx
->attribs
->use_shared_memory
= FALSE
;
137 ctx
->flags
.use_shared_pixmap
= 0;
140 fprintf(stdout
, "depth %d\n", ctx
->depth
);
145 * loading maps .............
148 if (dayfile
!= NULL
) {
149 map
= RLoadImage(ctx
, dayfile
, 0);
150 if (!use_default_nightmap
)
151 use_nightmap
= FALSE
;
154 fprintf(stdout
, "pb map ! file not found ?\n");
159 map
= RGetImageFromXPMData(ctx
, defmap_xpm
);
160 use_default_nightmap
= TRUE
;
163 fprintf(stdout
, "pb def map ! file not found ?\n");
168 fprintf(stdout
, "need a map !\n");
173 use_nightmap
= FALSE
;
174 use_default_nightmap
= FALSE
;
177 if (nightfile
!= NULL
) {
178 mapnight
= RLoadImage(ctx
, nightfile
, 0);
181 fprintf(stdout
, "pb map night! file not found ?\n");
186 if (use_default_nightmap
) {
187 mapnight
= RGetImageFromXPMData(ctx
, defnimap_xpm
);
191 "pb def map night ! file not found ?\n");
197 use_nightmap
= FALSE
;
202 use_nmap_ini
= use_nightmap
;
204 /* we need a night map of same size as day map */
206 if ((mapnight
->width
!= map
->width
)
207 || (mapnight
->height
!= map
->height
)) {
210 mapnight
= RScaleImage(tmp
, map
->width
, map
->height
);
216 /* some other init ..................................... */
217 ratiox
= (double) map
->width
/ (2 * PI
);
218 ratioy
= (double) map
->height
/ PI
;
219 mratiox
= (int) floor(ratiox
* 256);
220 mratioy
= (int) floor(ratioy
* 256);
221 loadxpm(ctx
->drawable
);
223 small
= RCreateImage(DIAMETRE
, DIAMETRE
, 0);
228 * first rendering of the earth
230 rotation_terre(DIAMETRE
/ 2, DIAMETRE
/ 2, 0);
232 do_something
= FALSE
;
234 /*************************************************************************
235 * well, here the problems begin : this code is a merge from wmgeneral and
236 * some stuff of wmaker, should be rewritten ...
237 ************************************************************************/
239 XGetWindowAttributes(dpy
, ctx
->drawable
, &attributes
);
241 if (!RConvertImage(ctx
, small
, &pix
)) {
242 fprintf(stdout
, "error small->&pix\n");
243 puts(RMessageForError(RErrorCode
));
249 mysizehints
.flags
= USSize
| USPosition
;
254 if (!XParseColor(dpy
, attributes
.colormap
, "white", &color
)) {
255 fprintf(stdout
, "wmglobe: can't parse white\n");
256 } else if (!XAllocColor(dpy
, attributes
.colormap
, &color
)) {
257 fprintf(stdout
, "wmglobe: can't allocate white\n");
259 back_pix
= color
.pixel
;
261 XGetWindowAttributes(dpy
, ctx
->drawable
, &attributes
);
264 if (!XParseColor(dpy
, attributes
.colormap
, "black", &color
)) {
265 fprintf(stdout
, "wmglobe: can't parse black\n");
266 } else if (!XAllocColor(dpy
, attributes
.colormap
, &color
)) {
267 fprintf(stdout
, "wmglobe: can't allocate black\n");
269 fore_pix
= color
.pixel
;
272 XWMGeometry(dpy
, ctx
->screen_number
, Geometry
, NULL
, borderwidth
,
273 &mysizehints
, &mysizehints
.x
, &mysizehints
.y
,
274 &mysizehints
.width
, &mysizehints
.height
, &dummy
);
275 mysizehints
.width
= DIAMETRE
;
276 mysizehints
.height
= DIAMETRE
;
279 XCreateSimpleWindow(dpy
, ctx
->drawable
, mysizehints
.x
,
280 mysizehints
.y
, mysizehints
.width
,
281 mysizehints
.height
, borderwidth
, fore_pix
,
284 iconwin
= XCreateSimpleWindow(dpy
, win
, mysizehints
.x
, mysizehints
.y
,
285 mysizehints
.width
, mysizehints
.height
,
286 borderwidth
, fore_pix
, back_pix
);
289 XSetWMNormalHints(dpy
, win
, &mysizehints
);
290 classHint
.res_name
= wname
;
291 classHint
.res_class
= wname
;
292 XSetClassHint(dpy
, win
, &classHint
);
294 XSelectInput(dpy
, win
,
295 ButtonPressMask
| ExposureMask
| ButtonReleaseMask
|
296 PointerMotionMask
| StructureNotifyMask
);
297 XSelectInput(dpy
, iconwin
,
298 ButtonPressMask
| ExposureMask
| ButtonReleaseMask
|
299 PointerMotionMask
| StructureNotifyMask
);
301 if (XStringListToTextProperty(&wname
, 1, &name
) == 0) {
302 fprintf(stdout
, "%s: can't allocate window name\n", wname
);
305 XSetWMName(dpy
, win
, &name
);
307 /* Create GC for drawing */
309 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
310 gcv
.foreground
= fore_pix
;
311 gcv
.background
= back_pix
;
312 gcv
.graphics_exposures
= 0;
313 NormalGC
= XCreateGC(dpy
, ctx
->drawable
, gcm
, &gcv
);
318 XCreateBitmapFromData(dpy
, win
, rond_bits
, DIAMETRE
, DIAMETRE
);
319 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, pixmask
,
321 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, pixmask
,
326 mywmhints
.initial_state
= option_iw
;
327 mywmhints
.icon_window
= iconwin
;
328 mywmhints
.icon_x
= mysizehints
.x
;
329 mywmhints
.icon_y
= mysizehints
.y
;
330 mywmhints
.window_group
= win
;
332 StateHint
| IconWindowHint
| IconPositionHint
| WindowGroupHint
;
334 XSetWMHints(dpy
, win
, &mywmhints
);
336 XSetCommand(dpy
, win
, argv
, argc
);
337 XMapWindow(dpy
, win
);
340 XCopyArea(dpy
, wmg
.pixmap
, win
, NormalGC
, 0, 0, DIAMETRE
, DIAMETRE
, 0,
343 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
346 * ================= MAIN LOOP ==================
349 while (XPending(dpy
)) {
350 XNextEvent(dpy
, &Event
);
351 switch (Event
.type
) {
353 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
361 * earth rotate when clic left (1) , zooming when middle (2)
362 * change screen to longitude / latitude when (3)
364 switch (Event
.xbutton
.button
) {
366 #ifdef MOUSE_LAT_NO_SHIFT
367 move_lat_flag
= TRUE
;
369 if (Event
.xbutton
.state
& ShiftMask
)
370 move_lat_flag
= TRUE
;
372 move_lat_flag
= FALSE
;
378 if (Event
.xbutton
.state
& ShiftMask
)
403 usleep(2 * VAL_USLEEP_SHORT
);
405 rotation_terre(Event
.xbutton
.x
, Event
.xbutton
.y
,
408 zooming(Event
.xbutton
.state
& ShiftMask
);
411 if (diftimev(tnext
, getimev()).tv_sec
< 0 || ok
) {
413 recalc(redoaction
== 1);
415 if (!myRConvertImage(ctx
, small
, &pix
)) {
416 fprintf(stderr
, "crash !?\n");
417 fprintf(stderr
, RMessageForError(RErrorCode
));
422 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
424 fprintf(stdout
, "draw\n");
426 do_something
= FALSE
;