@@ -36,26 +36,40 @@ static int init(App *app, Config *cfg)
3636#ifdef __WIN32
3737static void initCmd ()
3838{
39+ // Create console
3940 AllocConsole ();
4041 AttachConsole (ATTACH_PARENT_PROCESS );
4142 freopen ("CONOUT$" , "w" , stdout );
4243 HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE );
4344 DWORD dwMode = 0 ;
4445 GetConsoleMode (hOut , & dwMode );
4546 SetConsoleMode (hOut , dwMode | 0x0004 );
47+
48+ // Remove closing button (because closing it closes the entire app)
49+ HWND hwnd = GetConsoleWindow ();
50+ HMENU hMenu = GetSystemMenu (hwnd , FALSE);
51+ DeleteMenu (hMenu , SC_CLOSE , MF_BYCOMMAND );
52+
53+ // Set console title
54+ SetConsoleTitle ("Layered WallPaper" );
4655}
4756#endif
4857
4958int main (int argc , char * argv [])
5059{
60+ lwpLog (LOG_INFO , "Starting Layered WallPaper" );
61+
5162#ifdef __WIN32
5263 if (argc == 2 && strcmp (argv [1 ], "/console" ) == 0 ) initCmd ();
64+ initTrayIcon ();
5365#endif
5466
5567 App app ;
5668 Config cfg ;
5769
58- if (!parseConfig (& app , & cfg ) || !init (& app , & cfg ) || !loadMonitors (& app , & cfg )) return 1 ;
70+ int canRender = 1 ;
71+
72+ if (!parseConfig (& app , & cfg ) || !init (& app , & cfg ) || !loadMonitors (& app , & cfg )) canRender = 0 ;
5973
6074 SDL_Event event ;
6175 int quit = 0 ;
@@ -65,115 +79,125 @@ int main(int argc, char *argv[])
6579
6680 while (!quit )
6781 {
68- static int currentX = 0 ;
69- static int currentY = 0 ;
70-
71- static int lastTicks = 0 ;
72-
73- int ticks = SDL_GetTicks ();
74- float dT = (ticks - lastTicks ) / 1000.0f ;
75- lastTicks = ticks ;
76-
82+ if (canRender )
83+ {
84+ static int currentX = 0 ;
85+ static int currentY = 0 ;
86+
87+ static int lastTicks = 0 ;
88+
89+ int ticks = SDL_GetTicks ();
90+ float dT = (ticks - lastTicks ) / 1000.0f ;
91+ lastTicks = ticks ;
92+
93+ #ifdef __WIN32
94+ POINT mPos ;
95+ GetCursorPos (& mPos );
96+ mx = mPos .x ;
97+ my = mPos .y ;
98+ #else
99+ SDL_GetGlobalMouseState (& mx , & my );
100+ #endif
101+
102+ while (SDL_PollEvent (& event ))
103+ if (event .type == SDL_QUIT ) quit = 1 ;
104+
105+ currentX = lerp (currentX , mx , dT * cfg .smooth );
106+ currentY = lerp (currentY , my , dT * cfg .smooth );
107+
108+ for (int m = 0 ; m < cfg .monitorsCount ; m ++ )
109+ {
110+ int relativeCurrentX = currentX - cfg .monitors [m ].x ;
111+ int relativeCurrentY = currentY - cfg .monitors [m ].y ;
112+
113+ if (relativeCurrentX < 0 ) relativeCurrentX = 0 ;
114+ if (relativeCurrentY < 0 ) relativeCurrentY = 0 ;
115+ if (relativeCurrentX > cfg .monitors [m ].w ) relativeCurrentX = cfg .monitors [m ].w ;
116+ if (relativeCurrentY > cfg .monitors [m ].h ) relativeCurrentY = cfg .monitors [m ].h ;
117+
118+ SDL_SetRenderTarget (app .renderer , cfg .monitors [m ].wallpaper .tex );
119+ SDL_RenderClear (app .renderer );
120+
121+ for (int i = 0 ; i < cfg .monitors [m ].wallpaper .layersCount ; i ++ )
122+ {
123+ SDL_Rect src = {
124+ .x = 0 ,
125+ .y = 0 ,
126+ .w = cfg .monitors [m ].wallpaper .originalW ,
127+ .h = cfg .monitors [m ].wallpaper .originalH ,
128+ };
129+
130+ int x = - ((relativeCurrentX - cfg .monitors [m ].w / 2 ) *
131+ cfg .monitors [m ].wallpaper .layers [i ].sensitivityX );
132+ int y = - ((relativeCurrentY - cfg .monitors [m ].h / 2 ) *
133+ cfg .monitors [m ].wallpaper .layers [i ].sensitivityY );
134+
135+ for (int k = - cfg .monitors [m ].wallpaper .repeatY ; k <= cfg .monitors [m ].wallpaper .repeatY ;
136+ k ++ )
137+ {
138+ for (int j = - cfg .monitors [m ].wallpaper .repeatX ; j <= cfg .monitors [m ].wallpaper .repeatX ;
139+ j ++ )
140+ {
141+ SDL_Rect dest = {
142+ .x = x + j * cfg .monitors [m ].wallpaperW ,
143+ .y = y + k * cfg .monitors [m ].wallpaperH ,
144+ .w = cfg .monitors [m ].wallpaperW ,
145+ .h = cfg .monitors [m ].wallpaperH ,
146+ };
147+
148+ SDL_RenderCopy (app .renderer , cfg .monitors [m ].wallpaper .layers [i ].tex , & src , & dest );
149+ }
150+ }
151+ }
152+
153+ SDL_SetRenderTarget (app .renderer , cfg .monitors [m ].tex );
154+
155+ SDL_Rect src = {
156+ .x = 0 ,
157+ .y = 0 ,
158+ .w = cfg .monitors [m ].wallpaperW ,
159+ .h = cfg .monitors [m ].wallpaperH ,
160+ };
161+
162+ SDL_Rect dest = {
163+ .x = cfg .monitors [m ].wallpaperX ,
164+ .y = cfg .monitors [m ].wallpaperY ,
165+ .w = cfg .monitors [m ].wallpaperW ,
166+ .h = cfg .monitors [m ].wallpaperH ,
167+ };
168+
169+ SDL_RenderCopy (app .renderer , cfg .monitors [m ].wallpaper .tex , & src , & dest );
170+
171+ SDL_SetRenderTarget (app .renderer , NULL );
172+
173+ SDL_Rect finalSrc = {
174+ .x = 0 ,
175+ .y = 0 ,
176+ .w = cfg .monitors [m ].w ,
177+ .h = cfg .monitors [m ].h ,
178+ };
179+
180+ SDL_Rect finalDest = {
181+ .x = cfg .monitors [m ].x ,
182+ .y = cfg .monitors [m ].y ,
183+ .w = cfg .monitors [m ].w ,
184+ .h = cfg .monitors [m ].h ,
185+ };
186+
187+ SDL_RenderCopy (app .renderer , cfg .monitors [m ].tex , & finalSrc , & finalDest );
188+ }
189+ SDL_RenderPresent (app .renderer );
190+ }
191+ SDL_Delay (1000 / cfg .targetFPS );
77192#ifdef __WIN32
78- POINT mPos ;
79- GetCursorPos (& mPos );
80- mx = mPos .x ;
81- my = mPos .y ;
82- #else
83- SDL_GetGlobalMouseState (& mx , & my );
193+ if (!updateTrayIcon ()) quit = 1 ;
84194#endif
85-
86- while (SDL_PollEvent (& event ))
87- if (event .type == SDL_QUIT ) quit = 1 ;
88-
89- currentX = lerp (currentX , mx , dT * cfg .smooth );
90- currentY = lerp (currentY , my , dT * cfg .smooth );
91-
92- for (int m = 0 ; m < cfg .monitorsCount ; m ++ )
93- {
94- int relativeCurrentX = currentX - cfg .monitors [m ].x ;
95- int relativeCurrentY = currentY - cfg .monitors [m ].y ;
96-
97- if (relativeCurrentX < 0 ) relativeCurrentX = 0 ;
98- if (relativeCurrentY < 0 ) relativeCurrentY = 0 ;
99- if (relativeCurrentX > cfg .monitors [m ].w ) relativeCurrentX = cfg .monitors [m ].w ;
100- if (relativeCurrentY > cfg .monitors [m ].h ) relativeCurrentY = cfg .monitors [m ].h ;
101-
102- SDL_SetRenderTarget (app .renderer , cfg .monitors [m ].wallpaper .tex );
103- SDL_RenderClear (app .renderer );
104-
105- for (int i = 0 ; i < cfg .monitors [m ].wallpaper .layersCount ; i ++ )
106- {
107- SDL_Rect src = {
108- .x = 0 ,
109- .y = 0 ,
110- .w = cfg .monitors [m ].wallpaper .originalW ,
111- .h = cfg .monitors [m ].wallpaper .originalH ,
112- };
113-
114- int x = - ((relativeCurrentX - cfg .monitors [m ].w / 2 ) *
115- cfg .monitors [m ].wallpaper .layers [i ].sensitivityX );
116- int y = - ((relativeCurrentY - cfg .monitors [m ].h / 2 ) *
117- cfg .monitors [m ].wallpaper .layers [i ].sensitivityY );
118-
119- for (int k = - cfg .monitors [m ].wallpaper .repeatY ; k <= cfg .monitors [m ].wallpaper .repeatY ;
120- k ++ )
121- {
122- for (int j = - cfg .monitors [m ].wallpaper .repeatX ; j <= cfg .monitors [m ].wallpaper .repeatX ;
123- j ++ )
124- {
125- SDL_Rect dest = {
126- .x = x + j * cfg .monitors [m ].wallpaperW ,
127- .y = y + k * cfg .monitors [m ].wallpaperH ,
128- .w = cfg .monitors [m ].wallpaperW ,
129- .h = cfg .monitors [m ].wallpaperH ,
130- };
131-
132- SDL_RenderCopy (app .renderer , cfg .monitors [m ].wallpaper .layers [i ].tex , & src , & dest );
133- }
134- }
135- }
136-
137- SDL_SetRenderTarget (app .renderer , cfg .monitors [m ].tex );
138-
139- SDL_Rect src = {
140- .x = 0 ,
141- .y = 0 ,
142- .w = cfg .monitors [m ].wallpaperW ,
143- .h = cfg .monitors [m ].wallpaperH ,
144- };
145-
146- SDL_Rect dest = {
147- .x = cfg .monitors [m ].wallpaperX ,
148- .y = cfg .monitors [m ].wallpaperY ,
149- .w = cfg .monitors [m ].wallpaperW ,
150- .h = cfg .monitors [m ].wallpaperH ,
151- };
152-
153- SDL_RenderCopy (app .renderer , cfg .monitors [m ].wallpaper .tex , & src , & dest );
154-
155- SDL_SetRenderTarget (app .renderer , NULL );
156-
157- SDL_Rect finalSrc = {
158- .x = 0 ,
159- .y = 0 ,
160- .w = cfg .monitors [m ].w ,
161- .h = cfg .monitors [m ].h ,
162- };
163-
164- SDL_Rect finalDest = {
165- .x = cfg .monitors [m ].x ,
166- .y = cfg .monitors [m ].y ,
167- .w = cfg .monitors [m ].w ,
168- .h = cfg .monitors [m ].h ,
169- };
170-
171- SDL_RenderCopy (app .renderer , cfg .monitors [m ].tex , & finalSrc , & finalDest );
172- }
173- SDL_RenderPresent (app .renderer );
174- SDL_Delay (1000 / 60 );
175195 }
176196
197+ #ifdef __WIN32
198+ removeTrayIcon ();
199+ #endif
200+
177201 freeConfig (& cfg );
178202
179203 SDL_DestroyRenderer (app .renderer );
0 commit comments