Skip to content

Commit ac58d50

Browse files
Merge pull request #17 from jszczerbinsky/dev
v1.4
2 parents 08b6f65 + 952d733 commit ac58d50

File tree

8 files changed

+220
-103
lines changed

8 files changed

+220
-103
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default:
77
mkdir -p build/etc
88
gcc main.c window.c parser.c debug.c -lSDL2 -lX11 -o build/usr/bin/lwp
99
cp -R wallpapers build/usr/share/lwp
10-
cp default.cfg build/etc
10+
cp default.cfg build/etc/lwp.cfg
1111
cp LICENSE build/usr/share/lwp
1212
install:
1313
cp -R build/* /

default.cfg

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,41 @@
55
# ███████╗╚███╔███╔╝██║
66
# ╚══════╝ ╚══╝╚══╝ ╚═╝
77

8+
# Path to wallpaper directory
89
path=/usr/share/lwp/wallpapers/test
10+
11+
# Wallpaper layers count
912
count=3
1013

14+
# If You are using a compositor, or lwp window deosn't show,
15+
# try setting this to 1
16+
reload_rootwindow=0
17+
18+
# Movement smoothness
1119
smooth=8
12-
movementX = 0.05
13-
movementY = 0.05
1420

21+
# Movement sensitivity:
22+
movementX=0.05
23+
movementY=0.05
24+
25+
# You can also set movement sensitivity for a specific layer
26+
# Here is an example of setting movement in X axis for the 2nd one
27+
# movementX_2=0.08
28+
29+
# Monitors count
1530
monitors=1
1631

32+
# Monitor position and resolution
1733
monitor1_x=0
1834
monitor1_y=0
1935
monitor1_w=1920
2036
monitor1_h=1080
37+
38+
# If Your wallpaper has different resolution than Your monitor
39+
# You can set wallpaper's resolution and position relative to monitor
40+
# Overflowing parts of the wallpaper will be cropped
41+
# monitor1_render_x=0
42+
# monitor1_render_y=0
43+
# monitor1_render_w=1920
44+
# monitor1_render_h=1080
45+

defaultWin.cfg

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,38 @@
55
# ███████╗╚███╔███╔╝██║
66
# ╚══════╝ ╚══╝╚══╝ ╚═╝
77

8+
# Path to wallpaper directory
9+
# Set empty value to use default wallpaper
810
path=
11+
12+
# Wallpaper layers count
913
count=3
1014

15+
# Movement smoothness
1116
smooth=8
12-
movementX = 0.05
13-
movementY = 0.05
1417

18+
# Movement sensitivity:
19+
movementX=0.05
20+
movementY=0.05
21+
22+
# You can also set movement sensitivity for a specific layer
23+
# Here is an example of setting movement in X axis for the 2nd one
24+
# movementX_2=0.08
25+
26+
# Monitors count
1527
monitors=1
1628

29+
# Monitor position and resolution
1730
monitor1_x=0
1831
monitor1_y=0
1932
monitor1_w=1920
2033
monitor1_h=1080
34+
35+
# If Your wallpaper has different resolution than Your monitor
36+
# You can set wallpaper's resolution and position relative to monitor
37+
# Overflowing parts of the wallpaper will be cropped
38+
# monitor1_render_x=-100
39+
# monitor1_render_y=-40
40+
# monitor1_render_w=2500
41+
# monitor1_render_h=1200
42+

main.c

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ App app;
88

99
int lerp(int a, int b, float t) { return (int)((float)a + (float)t * ((float)b - (float)a)); }
1010

11-
void init()
11+
void init(Config *cfg)
1212
{
1313
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) SDL_Log("%s", SDL_GetError());
1414

1515
#ifndef __WIN32
1616
app.display = XOpenDisplay(NULL);
1717
#endif
1818

19-
initWindow();
19+
initWindow(&app, cfg);
2020

2121
app.renderer =
2222
SDL_CreateRenderer(app.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
6969
Instance instances[cfg.monitors];
7070
SDL_Texture *tex[cfg.count];
7171

72-
init();
72+
init(&cfg);
7373

7474
if (!loadTextures(&cfg, tex)) return 1;
7575

@@ -86,12 +86,11 @@ int main(int argc, char *argv[])
8686
instances[i].buffTex =
8787
SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET,
8888
instances[i].dest.w, instances[i].dest.h);
89+
instances[i].finalTex =
90+
SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET,
91+
instances[i].finalDest.w, instances[i].finalDest.h);
8992
}
9093

91-
#ifndef __WIN32
92-
SDL_SetRelativeMouseMode(SDL_TRUE);
93-
#endif
94-
9594
SDL_Event event;
9695
int quit = 0;
9796

@@ -114,34 +113,35 @@ int main(int argc, char *argv[])
114113
GetCursorPos(&mPos);
115114
mx = mPos.x;
116115
my = mPos.y;
116+
#else
117+
SDL_GetGlobalMouseState(&mx, &my);
117118
#endif
118119

119120
while (SDL_PollEvent(&event))
120-
{
121121
if (event.type == SDL_QUIT) quit = 1;
122-
#ifndef __WIN32
123-
else if (event.type == SDL_MOUSEMOTION)
124-
{
125-
mx = event.motion.x;
126-
my = event.motion.y;
127-
}
128-
#endif
129-
}
130122

131123
currentX = lerp(currentX, mx, dT * cfg.smooth);
132124
currentY = lerp(currentY, my, dT * cfg.smooth);
133125

134126
for (int u = 0; u < cfg.monitors; u++)
135127
{
128+
int relativeCurrentX = currentX - instances[u].finalDest.x;
129+
int relativeCurrentY = currentY - instances[u].finalDest.y;
130+
131+
if (relativeCurrentX < 0) relativeCurrentX = 0;
132+
if (relativeCurrentY < 0) relativeCurrentY = 0;
133+
if (relativeCurrentX > instances[u].finalDest.w) relativeCurrentX = instances[u].finalDest.w;
134+
if (relativeCurrentY > instances[u].finalDest.y) relativeCurrentY = instances[u].finalDest.h;
135+
136136
SDL_SetRenderTarget(app.renderer, instances[u].buffTex);
137137
SDL_RenderClear(app.renderer);
138138

139139
for (int i = 0; i < cfg.count; i++)
140140
{
141141
SDL_Rect src = {.x = 0, .y = 0, .w = app.srcWidth, .h = app.srcHeight};
142142

143-
int x = -((currentX - instances[u].dest.w / 2) * layerMovX[i]) * i;
144-
int y = -((currentY - instances[u].dest.h / 2) * layerMovY[i]) * i;
143+
int x = -((relativeCurrentX - instances[u].dest.w / 2) * layerMovX[i]);
144+
int y = -((relativeCurrentY - instances[u].dest.h / 2) * layerMovY[i]);
145145

146146
for (int j = -1; j <= 1; j++)
147147
{
@@ -154,17 +154,36 @@ int main(int argc, char *argv[])
154154
}
155155
}
156156

157-
SDL_SetRenderTarget(app.renderer, NULL);
158-
SDL_Rect src = {.x = 0, .y = 0, .w = instances[u].dest.w, .h = instances[u].dest.h};
157+
SDL_SetRenderTarget(app.renderer, instances[u].finalTex);
158+
SDL_Rect src = {
159+
.x = 0,
160+
.y = 0,
161+
.w = instances[u].dest.w,
162+
.h = instances[u].dest.h,
163+
};
159164

160165
SDL_RenderCopy(app.renderer, instances[u].buffTex, &src, &instances[u].dest);
166+
167+
SDL_SetRenderTarget(app.renderer, NULL);
168+
SDL_Rect finalSrc = {
169+
.x = 0,
170+
.y = 0,
171+
.w = instances[u].finalDest.w,
172+
.h = instances[u].finalDest.h,
173+
};
174+
175+
SDL_RenderCopy(app.renderer, instances[u].finalTex, &finalSrc, &instances[u].finalDest);
161176
}
162177
SDL_RenderPresent(app.renderer);
163178
SDL_Delay(1000 / 60);
164179
}
165180

166181
for (int i = 0; i < cfg.count; i++) SDL_DestroyTexture(tex[i]);
167-
for (int i = 0; i < cfg.monitors; i++) SDL_DestroyTexture(instances[i].buffTex);
182+
for (int i = 0; i < cfg.monitors; i++)
183+
{
184+
SDL_DestroyTexture(instances[i].buffTex);
185+
SDL_DestroyTexture(instances[i].finalTex);
186+
}
168187
#ifndef __WIN32
169188
XCloseDisplay(app.display);
170189
#endif

main.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@
33

44
#include <SDL2/SDL.h>
55
#ifdef __WIN32
6-
#include <windows.h>
7-
#include <stdio.h>
8-
#include <SDL2/SDL_syswm.h>
6+
#include <SDL2/SDL_syswm.h>
7+
#include <stdio.h>
8+
#include <windows.h>
99
#else
10-
#include <X11/Xlib.h>
11-
#include <linux/limits.h>
12-
#include <unistd.h>
13-
#include <pwd.h>
10+
#include <X11/Xatom.h>
11+
#include <X11/Xlib.h>
12+
#include <linux/limits.h>
13+
#include <pwd.h>
14+
#include <unistd.h>
1415
#endif
1516

1617
typedef struct
1718
{
18-
SDL_Rect dest;
19-
SDL_Texture *buffTex;
19+
SDL_Rect dest;
20+
SDL_Texture *buffTex;
21+
SDL_Rect finalDest;
22+
SDL_Texture *finalTex;
2023
} Instance;
2124

2225
typedef struct
2326
{
24-
int srcWidth;
25-
int srcHeight;
26-
SDL_Window *window;
27-
SDL_Renderer *renderer;
28-
#ifndef __WIN32
29-
Display *display;
30-
#endif
27+
int srcWidth;
28+
int srcHeight;
29+
SDL_Window *window;
30+
SDL_Renderer *renderer;
31+
#ifndef __WIN32
32+
Display *display;
33+
#endif
3134
} App;
3235

33-
extern App app;
34-
3536
#endif

parser.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,22 @@ int findLine(const char *name, int type, void *output)
125125

126126
int parseConfig(Config *cfg)
127127
{
128-
const char *names[] = {"path", "monitors", "count", "smooth", "movementX", "movementY"};
128+
const char *names[] = {
129+
"path", "monitors", "count", "smooth", "movementX", "movementY", "reload_rootwindow",
130+
};
129131

130-
const int types[] = {TYPE_STR, TYPE_INT, TYPE_INT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT};
132+
const int types[] = {TYPE_STR, TYPE_INT, TYPE_INT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_INT};
131133

132134
void *outputs[] = {
133-
cfg->path, &cfg->monitors, &cfg->count, &cfg->smooth, &cfg->movementX, &cfg->movementY,
135+
cfg->path, &cfg->monitors, &cfg->count, &cfg->smooth,
136+
&cfg->movementX, &cfg->movementY, &cfg->reloadRootWnd,
134137
};
135138

139+
#ifdef __WIN32
136140
for (int i = 0; i < 6; i++)
141+
#else
142+
for (int i = 0; i < 7; i++) // ignore reload_rootwindow on Windows
143+
#endif
137144
{
138145
if (!findLine(names[i], types[i], outputs[i]))
139146
{
@@ -157,13 +164,22 @@ int parseConfig(Config *cfg)
157164

158165
void parseInstancesConfig(Instance *instances, int instancesCount)
159166
{
160-
char str[15];
167+
char str[35];
161168

162169
const char *paramStr[] = {"_x", "_y", "_w", "_h"};
163170

171+
const char *renderParamStr[] = {"_render_x", "_render_y", "_render_w", "_render_h"};
172+
164173
for (int i = 0; i < instancesCount; i++)
165174
{
166175
int *outputPtr[] = {
176+
&instances[i].finalDest.x,
177+
&instances[i].finalDest.y,
178+
&instances[i].finalDest.w,
179+
&instances[i].finalDest.h,
180+
};
181+
182+
int *renderOutputPtr[] = {
167183
&instances[i].dest.x,
168184
&instances[i].dest.y,
169185
&instances[i].dest.w,
@@ -176,6 +192,24 @@ void parseInstancesConfig(Instance *instances, int instancesCount)
176192
if (!findLine(str, TYPE_INT, outputPtr[p]))
177193
lwpLog(LOG_ERROR, "Can't find line '%s' in config", str);
178194
}
195+
for (int p = 0; p < 4; p++)
196+
{
197+
sprintf(str, "monitor%d%s", i + 1, renderParamStr[p]);
198+
if (!findLine(str, TYPE_INT, renderOutputPtr[p]))
199+
{
200+
if (p > 1)
201+
{
202+
lwpLog(LOG_WARNING,
203+
"Can't find line '%s' in config, setting the same value as the monitor size", str);
204+
*(renderOutputPtr[p]) = *(outputPtr[p]);
205+
}
206+
else
207+
{
208+
lwpLog(LOG_WARNING, "Can't find line '%s' in config, setting the value to 0", str);
209+
*(renderOutputPtr[p]) = 0;
210+
}
211+
}
212+
}
179213
}
180214
}
181215

@@ -187,8 +221,8 @@ void parsePerLayerMovements(float *layerMovX, float *layerMovY, int count, float
187221
for (int i = 0; i < count; i++)
188222
{
189223
sprintf(str, "movementX_%d", i + 1);
190-
if (!findLine(str, TYPE_FLOAT, layerMovX + i)) layerMovX[i] = defaultValX;
224+
if (!findLine(str, TYPE_FLOAT, layerMovX + i)) layerMovX[i] = defaultValX * i;
191225
sprintf(str, "movementY_%d", i + 1);
192-
if (!findLine(str, TYPE_FLOAT, layerMovY + i)) layerMovY[i] = defaultValY;
226+
if (!findLine(str, TYPE_FLOAT, layerMovY + i)) layerMovY[i] = defaultValY * i;
193227
}
194228
}

parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef struct
1111
float movementY;
1212
int monitors;
1313
int count;
14+
int reloadRootWnd;
1415
} Config;
1516

1617
void openConfig();

0 commit comments

Comments
 (0)