Skip to content

Commit f509d33

Browse files
Merge pull request #46 from jszczerbinsky/dev
v1.7
2 parents 50ff76f + 7742a97 commit f509d33

File tree

10 files changed

+301
-110
lines changed

10 files changed

+301
-110
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ https://user-images.githubusercontent.com/38699473/220888934-09788a6b-873c-469b-
8585
cd lwp
8686
build.bat
8787
```
88-
- Download [SDL2](https://github.com/libsdl-org/SDL/releases/latest) and put `SDL2.dll` in `data` directory
88+
- Download [SDL2](https://github.com/libsdl-org/SDL/releases/latest) and put `SDL2.dll` in repository root
8989
- Run `install.bat` as Administrator
9090
- Lwp should run immediately after the installation
9191

@@ -147,6 +147,7 @@ https://user-images.githubusercontent.com/38699473/220888934-09788a6b-873c-469b-
147147
| int | monitor[n]_wallpaper_y | Position of the wallpaper relative to the monitor |
148148
| int | monitor[n]_wallpaper_w | Wallpaper resolution |
149149
| int | monitor[n]_wallpaper_h | Wallpaper resolution |
150+
| int | target_fps | How many times per second should the wallpaper render (imprecise, hence "target") |
150151

151152
## Creating Wallpapers
152153

build.bat

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
if exist data rmdir /S /Q data
33
mkdir data || goto err
44
windres resource.rc -O coff -o resource.res || goto err
5-
gcc -mwindows main.c wallpaper.c parser.c debug.c window.c resource.res -lmingw32 -lSDL2main -lSDL2 -o data\lwp.exe || goto err
5+
gcc -mwindows main.c wallpaper.c parser.c debug.c window.c resource.res -lmingw32 -lshcore -lSDL2main -lSDL2 -o data\lwp.exe || goto err
66
xcopy wallpapers data\wallpapers\ /E /Y || goto err
7+
TYPE wallpapers\default-fullhd\wallpaper.cfg | FIND /V "" > data\wallpapers\default-fullhd\wallpaper.cfg
78
copy uninstall.bat data || goto err
89
copy defaultWin.cfg data || goto err
910
copy LICENSE data\LICENSE.txt || goto err
11+
if exist SDL2.dll (
12+
copy SDL2.dll data
13+
)
1014
echo.
1115
echo --- Done! ---
12-
echo --- Remember to put SDL2.dll into 'data' directory before installing ---
16+
if not exist SDL2.dll (
17+
echo --- Remember to put SDL2.dll into 'data' directory before installing ---
18+
)
1319
pause>nul
1420
exit
1521

default.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ monitor1_wallpaper_x=0
3333
monitor1_wallpaper_y=0
3434
monitor1_wallpaper_w=1920
3535
monitor1_wallpaper_h=1080
36+
37+
# How many times per second should the wallpaper render
38+
# (imprecise, but accurate enough)
39+
target_fps=60

defaultMac.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ monitor1_wallpaper_y=0
3131
monitor1_wallpaper_w=1920
3232
monitor1_wallpaper_h=1080
3333

34+
# How many times per second should the wallpaper render
35+
# (imprecise, but accurate enough)
36+
target_fps=60

defaultWin.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ monitor1_wallpaper_x=0
3030
monitor1_wallpaper_y=0
3131
monitor1_wallpaper_w=1920
3232
monitor1_wallpaper_h=1080
33+
34+
# How many times per second should the wallpaper render
35+
# (imprecise, but accurate enough)
36+
target_fps=60

main.c

Lines changed: 130 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,40 @@ static int init(App *app, Config *cfg)
3636
#ifdef __WIN32
3737
static 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

4958
int 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);

main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef struct
5151
int reloadRootWnd;
5252
int monitorsCount;
5353
float smooth;
54+
int targetFPS;
5455
Monitor *monitors;
5556
} Config;
5657

0 commit comments

Comments
 (0)