1 /* -copyright-
2 #-#
3 #-# xsnow: let it snow on your desktop
4 #-# Copyright (C) 1984,1988,1990,1993-1995,2000-2001 Rick Jansen
5 #-# 	      2019,2020,2021 Willem Vermin
6 #-#
7 #-# This program is free software: you can redistribute it and/or modify
8 #-# it under the terms of the GNU General Public License as published by
9 #-# the Free Software Foundation, either version 3 of the License, or
10 #-# (at your option) any later version.
11 #-#
12 #-# This program is distributed in the hope that it will be useful,
13 #-# but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #-# GNU General Public License for more details.
16 #-#
17 #-# You should have received a copy of the GNU General Public License
18 #-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #-#
20 */
21 #pragma once
22 
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 #include <X11/Intrinsic.h>
26 #include <gtk/gtk.h>
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #ifdef HAVE_XDBEALLOCATEBACKBUFFERNAME
33 #define XDBE_AVAILABLE
34 #endif
35 
36 #ifdef NO_USE_BITS
37 #define BITS(n)
38 #else
39 #define BITS(n) :n
40 #endif
41 
42 #define FLAGSFILE ".xsnowrc"
43 #define FLAKES_PER_SEC_PER_PIXEL 30
44 #define INITIALSCRPAINTSNOWDEPTH 8  /* Painted in advance */
45 #define INITIALYSPEED 120   // has to do with vertical flake speed
46 #define MAXBLOWOFFFACTOR 100
47 #define MAXSANTA	4    // santa types 0..4
48 #define MAXTANNENPLACES 10   // number of trees
49 #define MAXTREETYPE 7        // treetypes: 0..MAXTREETYPE
50 #define MAXWSENS 0.2        // sensibility of flakes for wind
51 #define MAXXSTEP 2             /* drift speed max */
52 #define MAXYSTEP 10             /* falling speed max */
53 #define PIXINANIMATION	4    // nr of santa animations
54 #define SANTASENS 0.2       // sensibility of Santa for wind
55 #define SANTASPEED0 12
56 #define SANTASPEED1 25
57 #define SANTASPEED2 50
58 #define SANTASPEED3 50
59 #define SANTASPEED4 70
60 //#define SNOWFLAKEMAXTYPE 13  // type is 0..SNOWFLAKEMAXTYPE
61 #define SNOWFREE 25  /* Must stay snowfree on display :) */
62 #define SNOWSPEED 0.7    // the higher, the speedier the snow
63 #define WHIRL 150
64 
65 
66 // timers
67 
68 #define time_below_confirm        1.0    // time between check of 'confirm' button (after 'below' button)
69 #define time_blowoff              0.50   // time between blow snow off windows
70 #define time_change_attr          60.0   // time between changing attraction point
71 #define time_clean                1.00   // time between cleaning desktop
72 #define time_desktop_type         2.0    // time between showing desktop type
73 #define time_display_dimensions   0.5    // time between check of screen dimensions
74 #define time_displaychanged       1.00   // time between checks if display has changed
75 #define time_emeteorite           0.20   // time between meteorites erasures
76 #define time_event                0.50   // time between checking events
77 #define time_flakecount           1.00   // time between updates of show flakecount
78 #define time_fuse                 1.00   // time between testing on too much flakes
79 #define time_genflakes            0.10   // time between generation of flakes
80 #define time_init_snow            0.2    // time between killing flakes (used in emergency only)
81 #define time_initbaum             0.30   // time between check for (re)create trees
82 #define time_initstars            1.00   // time between check for (re)create stars
83 #define time_main_window          0.5    // time between checks for birds window
84 #define time_measure              0.1    // time between cpu load measurements
85 #define time_meteorite            3.00   // time between meteorites
86 #define time_newwind              1.00   // time between changing wind
87 #define time_sendevent            0.5    // time between sendEvent() calls
88 #define time_sfallen              2.30   // time between smoothing of fallen snow
89 #define time_show_range_etc       0.50   // time between showing range etc.
90 #define time_snow_on_trees        0.50   // time between redrawings of snow on trees
91 #define time_star                 0.50   // time between drawing stars
92 #define time_switchflakes         0.2    // time between checks if flakes should be switched beteen default and vintage
93 #define time_testing              2.10   // time between testing code
94 #define time_ui_check             0.25   // time between checking values from ui
95 #define time_umoon                0.04   // time between update position of moon
96 #define time_usanta               0.04   // time between update of santa position
97 #define time_ustar                2.00   // time between updating stars
98 #define time_wind                 0.10   // time between starting or ending wind
99 #define time_wupdate              0.20   // time between getting windows information
100 
101 #define time_change_bottom        300.0   // time between changing properties of bottom snow
102 #define time_adjust_bottom        (time_change_bottom/20)// time between adjusting height of bottom snow
103 //#define time_fallen           (0.04 * global.cpufactor)  // time between redraw fallen snow
104 #define time_fallen                0.20   // time between recompute fallen snow surfaces
105 #define time_snowflakes       (0.02 * global.cpufactor)  // time between updates of snowflakes positions etc
106 #define time_draw_all         (0.04 * global.cpufactor)  // time between updates of screen
107 
108 #define ALPHA (0.01*(100 - Flags.Transparency))
109 #define XPM_TYPE const char
110 /* ------------------------------------------------------------------ */
111 
112 typedef struct _WinInfo
113 {
114    Window id              ;
115    int x,y                ; // x,y coordinates
116    int xa,ya              ; // x,y coordinates absolute
117    unsigned int w,h       ; // width, height
118    int ws                 ; // workspace
119 
120    unsigned int sticky BITS(1); // is visible on all workspaces
121    unsigned int dock   BITS(1); // is a "dock" (panel)
122    unsigned int hidden BITS(1); // is hidden (iconified)
123 } WinInfo;
124 
125 typedef struct _FallenSnow {
126    WinInfo             win;          // WinInfo of window, win.id == 0 if snow at bottom
127    int                 x,y;          // Coordinates of fallen snow, y for bottom of fallen snow
128    int                 w,h;          // width, max height of fallen snow
129    int                 prevx,prevy;  // x,y of last draw
130    int                 prevw,prevh;  // w,h of last draw
131    int                 w8;           // width rounded up to 8-fold
132    short int          *acth;         // actual heights
133    short int          *desh;         // desired heights
134    short int          *r;            // small random numbers used by drawing
135    short int          *pacth;        // painted actual heights
136    struct _FallenSnow *next;         // pointer to next item
137    cairo_surface_t    *surface;      //
138 } FallenSnow;
139 
140 typedef struct _MeteoMap {
141    int x1,x2,y1,y2,active;
142    double starttime;
143 } MeteoMap;
144 
145 typedef struct _StarMap {
146    unsigned char *starBits;
147    Pixmap pixmap;
148    int width;
149    int height;
150 } StarMap;
151 
152 typedef struct _Skoordinaten {
153    int x;
154    int y;
155    int color;
156 } Skoordinaten;
157 
158 typedef struct Treeinfo {
159    int              x;             // x position
160    int              y;             // y position
161    int              w;             // width
162    int              h;             // height
163    cairo_surface_t *surface;
164    float            scale;
165    unsigned int     type BITS(8);  // type (TreeType, -treetype)
166    unsigned int     rev  BITS(1);  // reversed
167 } Treeinfo;
168 
169 
170 typedef struct _Snow {
171    float rx;                         // x position
172    float ry;                         // y position
173    int   ix;
174    int   iy;                         // position after draw
175    float vx;                         // speed in x-direction, pixels/second
176    float vy;                         // speed in y-direction, pixels/second
177    float m;                          // mass of flake
178    float ivy;                        // initial speed in y direction
179    float wsens;                      // wind dependency factor
180    float flufftimer;                 // fluff timeout timer
181    float flufftime;                  // fluff timeout
182    unsigned int whatFlake;           // snowflake index
183    unsigned int cyclic     BITS(1);  // flake is cyclic
184    unsigned int fluff      BITS(1);  // flake is in fluff state
185    unsigned int freeze     BITS(1);  // flake does not move
186    unsigned int testing    BITS(2);  // for testing purposes
187 
188 } Snow;
189 
190 typedef struct _SnowMap {
191    //Pixmap pixmap;
192    cairo_surface_t     *surface;
193    unsigned int width   BITS(16);
194    unsigned int height  BITS(16);
195 } SnowMap;
196 
197 extern struct _global
198 {
199    SnowMap        *fluffpix;
200    int             counter;
201    unsigned int    xxposures BITS(1);
202    unsigned int    Desktop   BITS(1);
203    unsigned int    Trans     BITS(1);
204    unsigned int    UseDouble BITS(1);
205    unsigned int    IsDouble  BITS(1);
206 
207    int             XscreensaverMode;
208 
209    double          cpufactor;
210 
211    float           ActualSantaSpeed;
212    Region          SantaPlowRegion;
213    int             SantaHeight;
214    int             SantaWidth;
215    int             SantaX;
216    int             SantaY;
217 
218    float           WindowScale;
219 
220    unsigned int    MaxSnowFlakeHeight;  /* Biggest flake */
221    unsigned int    MaxSnowFlakeWidth;   /* Biggest flake */
222    int             FlakeCount;          /* number of flakes */
223    int             FluffCount;          /* number of fluff flakes */
224 
225    Display        *display;
226    Window          SnowWin;
227    int             SnowWinBorderWidth;
228    int             SnowWinWidth;
229    int             SnowWinHeight;
230    int             SnowWinDepth;
231    char           *DesktopSession;
232    int             IsCompiz;
233    int             IsWayland;
234    int             CWorkSpace;  // int? Yes, in compiz we take the placement of the desktop
235    //                                     which can easily be > 16 bits
236    Window          Rootwindow;
237    int             Xroot;
238    int             Yroot;
239    unsigned int    Wroot;
240    unsigned int    Hroot;
241    int             SnowWinX;
242    int             SnowWinY;
243    int             WindowsChanged;
244 
245    FallenSnow     *FsnowFirst;
246    int             MaxScrSnowDepth;
247    int             RemoveFluff;
248 
249    double          moonX;
250    double          moonY;
251    double          moonR;  // radius of moon in pixels
252 
253    //Region          TreeRegion;
254    cairo_region_t *TreeRegion;
255 
256    cairo_region_t *gSnowOnTreesRegion;
257    XPoint         *SnowOnTrees;
258    int             OnTrees;
259 
260    Pixel           Black;
261    Pixel           White;
262 
263    int             Wind;
264    // Wind = 0: no wind
265    // Wind = 1: wind only affecting snow
266    // Wind = 2: wind affecting snow and santa
267    // Direction =  0: no wind direction I guess
268    // Direction =  1: wind from left to right
269    // Direction = -1: wind from right to left
270    int             Direction;
271    float           Whirl;
272    double          WindTimer;
273    double          WindTimerStart;
274    float           NewWind;
275    float           WindMax;
276 
277    int             HaltedByInterrupt;
278    char            Message[256];
279 } global;
280 
281 
282