diff --git a/src/common.h b/src/common.h
index 477a790..1a898be 100644
--- a/src/common.h
+++ b/src/common.h
@@ -12,46 +12,40 @@
#define DEFAULT_LINUX_PREFIX "/usr/local"
-typedef struct
-{
+typedef struct {
int x;
int y;
int w;
int h;
} Bounds;
-typedef struct
-{
+typedef struct {
float sensitivityX;
float sensitivityY;
} LayerConfig;
-typedef struct
-{
+typedef struct {
int loaded;
int repeatX;
int repeatY;
int layersCount;
- LayerConfig *layerConfigs;
+ LayerConfig* layerConfigs;
} WallpaperConfig;
-typedef struct
-{
+typedef struct {
char name[WALLPAPER_NAME_MAX];
char dirPath[PATH_MAX];
int isDefault;
WallpaperConfig config;
} WallpaperInfo;
-typedef struct
-{
+typedef struct {
int loaded;
char wlpName[WALLPAPER_NAME_MAX];
Bounds wlpBounds;
} MonitorConfig;
-typedef struct
-{
+typedef struct {
char displayName[MONITOR_NAME_MAX];
char name[MONITOR_NAME_MAX];
Bounds pixelBounds;
@@ -60,10 +54,11 @@ typedef struct
MonitorConfig config;
} MonitorInfo;
-typedef struct
-{
+typedef struct {
int targetFps;
char renderQuality[8];
+ int unfocusedComeback;
+ int wndTargetPoint;
} AppConfig;
//
@@ -74,12 +69,12 @@ typedef struct
#define APP_DIR_SHARE 1
#define APP_DIR_USER_SETTINGS 2
-void getAppDir(char *buff, int type);
+void getAppDir(char* buff, int type);
-void getMonitorCfgPath(char *buff, const char *name);
-void getWlpCfgPath(char *buff, const char *dirPath);
-void getAppCfgPath(char *buff);
-void getLogPath(char *buff);
+void getMonitorCfgPath(char* buff, const char* name);
+void getWlpCfgPath(char* buff, const char* dirPath);
+void getAppCfgPath(char* buff);
+void getLogPath(char* buff);
void createUserDirs();
@@ -87,24 +82,24 @@ void createUserDirs();
// monitorScanner.c
//
-MonitorInfo *scanMonitors(int *count);
+MonitorInfo* scanMonitors(int* count);
//
// wallpaperScanner.c
//
-WallpaperInfo *scanWallpapers(int *count);
+WallpaperInfo* scanWallpapers(int* count);
//
// config.c
//
-void saveMonitorConfig(const char *name, MonitorConfig *mc);
-int loadMonitorConfig(const char *name, MonitorConfig *mc);
+void saveMonitorConfig(const char* name, MonitorConfig* mc);
+int loadMonitorConfig(const char* name, MonitorConfig* mc);
-int loadAppConfig(AppConfig *ac);
-void saveAppConfig(AppConfig *ac);
+int loadAppConfig(AppConfig* ac);
+void saveAppConfig(AppConfig* ac);
-int loadWallpaperConfig(const char *dirName, WallpaperConfig *wc);
+int loadWallpaperConfig(const char* dirName, WallpaperConfig* wc);
#endif
diff --git a/src/common/config.c b/src/common/config.c
index 94bea6f..a81c6f7 100644
--- a/src/common/config.c
+++ b/src/common/config.c
@@ -7,8 +7,7 @@
#define CONFIG_DEFAULT 0
#define CONFIG_USER 1
-static void generateEmptyMonitorConfig(MonitorConfig *mc)
-{
+static void generateEmptyMonitorConfig(MonitorConfig* mc) {
sprintf(mc->wlpName, "");
mc->wlpBounds.x = 0;
mc->wlpBounds.y = 0;
@@ -16,8 +15,7 @@ static void generateEmptyMonitorConfig(MonitorConfig *mc)
mc->wlpBounds.h = 1080;
}
-void saveMonitorConfig(const char *name, MonitorConfig *mc)
-{
+void saveMonitorConfig(const char* name, MonitorConfig* mc) {
config_t cfg;
config_setting_t *root, *setting;
@@ -39,8 +37,7 @@ void saveMonitorConfig(const char *name, MonitorConfig *mc)
char path[PATH_MAX];
getMonitorCfgPath(path, name);
- if (!config_write_file(&cfg, path))
- {
+ if (!config_write_file(&cfg, path)) {
fprintf(stderr, "Error while writing file.\n");
config_destroy(&cfg);
}
@@ -48,8 +45,7 @@ void saveMonitorConfig(const char *name, MonitorConfig *mc)
config_destroy(&cfg);
}
-int loadMonitorConfig(const char *name, MonitorConfig *mc)
-{
+int loadMonitorConfig(const char* name, MonitorConfig* mc) {
mc->loaded = 0;
config_t cfg;
@@ -58,15 +54,15 @@ int loadMonitorConfig(const char *name, MonitorConfig *mc)
char path[PATH_MAX];
getMonitorCfgPath(path, name);
- if (!g_file_test(path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS))
- {
+ if (!g_file_test(path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS)) {
generateEmptyMonitorConfig(mc);
saveMonitorConfig(name, mc);
return 1;
}
config_init(&cfg);
- if (config_read_file(&cfg, path) == CONFIG_FALSE) return 0;
+ if (config_read_file(&cfg, path) == CONFIG_FALSE)
+ return 0;
root = config_root_setting(&cfg);
setting = config_setting_get_member(root, "wlpName");
@@ -87,14 +83,14 @@ int loadMonitorConfig(const char *name, MonitorConfig *mc)
return 1;
}
-static void useDefaultAppCfg(AppConfig *ac)
-{
+static void useDefaultAppCfg(AppConfig* ac) {
ac->targetFps = 60;
strcpy(ac->renderQuality, "best");
+ ac->wndTargetPoint = 0;
+ ac->unfocusedComeback = 1;
}
-void saveAppConfig(AppConfig *ac)
-{
+void saveAppConfig(AppConfig* ac) {
config_t cfg;
config_setting_t *root, *setting;
@@ -105,12 +101,15 @@ void saveAppConfig(AppConfig *ac)
config_setting_set_int(setting, ac->targetFps);
setting = config_setting_add(root, "render_quality", CONFIG_TYPE_STRING);
config_setting_set_string(setting, ac->renderQuality);
+ setting = config_setting_add(root, "unfocused_comeback", CONFIG_TYPE_INT);
+ config_setting_set_int(setting, ac->unfocusedComeback);
+ setting = config_setting_add(root, "wnd_target_point", CONFIG_TYPE_INT);
+ config_setting_set_int(setting, ac->wndTargetPoint);
char path[PATH_MAX];
getAppCfgPath(path);
- if (!config_write_file(&cfg, path))
- {
+ if (!config_write_file(&cfg, path)) {
fprintf(stderr, "Error while writing file.\n");
config_destroy(&cfg);
}
@@ -118,8 +117,7 @@ void saveAppConfig(AppConfig *ac)
config_destroy(&cfg);
}
-int loadAppConfig(AppConfig *ac)
-{
+int loadAppConfig(AppConfig* ac) {
config_t cfg;
config_setting_t *root, *setting;
@@ -127,25 +125,40 @@ int loadAppConfig(AppConfig *ac)
getAppCfgPath(path);
config_init(&cfg);
- if (config_read_file(&cfg, path) == CONFIG_FALSE)
- {
+ if (config_read_file(&cfg, path) == CONFIG_FALSE) {
useDefaultAppCfg(ac);
return 1;
}
root = config_root_setting(&cfg);
- setting = config_setting_get_member(root, "target_fps");
- ac->targetFps = config_setting_get_int(setting);
- setting = config_setting_get_member(root, "render_quality");
- strcpy(ac->renderQuality, config_setting_get_string(setting));
-
- config_destroy(&cfg);
+ setting = config_setting_get_member(root, "target_fps");
+ if (setting == NULL)
+ ac->targetFps = 60;
+ else
+ ac->targetFps = config_setting_get_int(setting);
+
+ setting = config_setting_get_member(root, "render_quality");
+ if (setting == NULL)
+ strcpy(ac->renderQuality, "best");
+ else
+ strcpy(ac->renderQuality, config_setting_get_string(setting));
+
+ setting = config_setting_get_member(root, "unfocused_comeback");
+ if (setting == NULL)
+ ac->unfocusedComeback = 1;
+ else
+ ac->unfocusedComeback = config_setting_get_int(setting);
+
+ setting = config_setting_get_member(root, "wnd_target_point");
+ if (setting == NULL)
+ ac->wndTargetPoint = 0;
+ else
+ ac->wndTargetPoint = config_setting_get_int(setting);
return 1;
}
-int loadWallpaperConfig(const char *dirPath, WallpaperConfig *wc)
-{
+int loadWallpaperConfig(const char* dirPath, WallpaperConfig* wc) {
wc->loaded = 0;
config_t cfg;
@@ -156,10 +169,10 @@ int loadWallpaperConfig(const char *dirPath, WallpaperConfig *wc)
char path[PATH_MAX];
getWlpCfgPath(path, dirPath);
- if (config_read_file(&cfg, path) == CONFIG_FALSE)
- {
+ if (config_read_file(&cfg, path) == CONFIG_FALSE) {
getWlpCfgPath(path, dirPath);
- if (config_read_file(&cfg, path) == CONFIG_FALSE) return 0;
+ if (config_read_file(&cfg, path) == CONFIG_FALSE)
+ return 0;
}
root = config_root_setting(&cfg);
@@ -177,9 +190,8 @@ int loadWallpaperConfig(const char *dirPath, WallpaperConfig *wc)
setting = config_setting_get_member(root, "movement_y");
float movY = config_setting_get_float(setting);
- for (int i = 0; i < wc->layersCount; i++)
- {
- LayerConfig *lc = wc->layerConfigs + i;
+ for (int i = 0; i < wc->layersCount; i++) {
+ LayerConfig* lc = wc->layerConfigs + i;
lc->sensitivityX = movX * i;
lc->sensitivityY = movY * i;
diff --git a/src/core/main.c b/src/core/main.c
index ea68c80..41fe2f9 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -5,22 +5,24 @@
GtkApplication *app = NULL;
GtkBuilder *builder = NULL;
-GtkWidget *mainWnd = NULL;
-GtkWidget *exitDialog = NULL;
-GtkWidget *wallpaperMgrWnd = NULL;
-GtkWidget *monitorWnd = NULL;
-GtkWidget *monitorListBox = NULL;
-GtkWidget *wallpaperListBox = NULL;
-GtkWidget *wallpaperComboBox = NULL;
-GtkWidget *xPosSpinBtn = NULL;
-GtkWidget *yPosSpinBtn = NULL;
-GtkWidget *widthSpinBtn = NULL;
-GtkWidget *heightSpinBtn = NULL;
-GtkWidget *monitorNameLabel = NULL;
-GtkWidget *versionLabel = NULL;
-GtkWidget *appSettingsWnd = NULL;
-GtkWidget *targetFpsComboBox = NULL;
-GtkWidget *renderQualityComboBox = NULL;
+GtkWidget *mainWnd = NULL;
+GtkWidget *exitDialog = NULL;
+GtkWidget *wallpaperMgrWnd = NULL;
+GtkWidget *monitorWnd = NULL;
+GtkWidget *monitorListBox = NULL;
+GtkWidget *wallpaperListBox = NULL;
+GtkWidget *wallpaperComboBox = NULL;
+GtkWidget *xPosSpinBtn = NULL;
+GtkWidget *yPosSpinBtn = NULL;
+GtkWidget *widthSpinBtn = NULL;
+GtkWidget *heightSpinBtn = NULL;
+GtkWidget *monitorNameLabel = NULL;
+GtkWidget *versionLabel = NULL;
+GtkWidget *appSettingsWnd = NULL;
+GtkWidget *targetFpsComboBox = NULL;
+GtkWidget *renderQualityComboBox = NULL;
+GtkWidget *unfocusedComebackComboBox = NULL;
+GtkWidget *targetPointComboBox = NULL;
static void reloadMonitorListBox()
{
@@ -156,6 +158,12 @@ static void activate(GtkApplication *app, gpointer userdata)
renderQualityComboBox = (GtkWidget *)gtk_builder_get_object(
builder, "SettingsWindow_TexFilteringComboBox"
);
+ unfocusedComebackComboBox = (GtkWidget *)gtk_builder_get_object(
+ builder, "SettingsWindow_UnfocusedCombackComboBox"
+ );
+ targetPointComboBox = (GtkWidget *)gtk_builder_get_object(
+ builder, "SettingsWindow_TargetPointComboBox"
+ );
gtk_window_set_application(GTK_WINDOW(mainWnd), GTK_APPLICATION(app));
gtk_window_set_application(GTK_WINDOW(exitDialog), GTK_APPLICATION(app));
diff --git a/src/core/main.h b/src/core/main.h
index b775e33..cf8ecca 100644
--- a/src/core/main.h
+++ b/src/core/main.h
@@ -22,7 +22,8 @@ extern GtkWidget *monitorNameLabel;
extern GtkWidget *appSettingsWnd;
extern GtkWidget *targetFpsComboBox;
extern GtkWidget *renderQualityComboBox;
-extern GtkWidget *drawOnRootWndComboBox;
+extern GtkWidget *unfocusedComebackComboBox;
+extern GtkWidget *targetPointComboBox;
void runWlp();
void killWlp();
diff --git a/src/core/windowHandlers.c b/src/core/windowHandlers.c
index f506c2e..21ec158 100644
--- a/src/core/windowHandlers.c
+++ b/src/core/windowHandlers.c
@@ -173,10 +173,22 @@ G_MODULE_EXPORT void SettingsWindowShow()
char targetFpsStr[4];
sprintf(targetFpsStr, "%d", ac.targetFps);
+ char unfocusedComebackStr[2];
+ sprintf(unfocusedComebackStr, "%d", ac.unfocusedComeback);
+
+ char targetPointStr[2];
+ sprintf(targetPointStr, "%d", ac.wndTargetPoint);
+
gtk_combo_box_set_active_id(
GTK_COMBO_BOX(renderQualityComboBox), ac.renderQuality
);
gtk_combo_box_set_active_id(GTK_COMBO_BOX(targetFpsComboBox), targetFpsStr);
+ gtk_combo_box_set_active_id(
+ GTK_COMBO_BOX(unfocusedComebackComboBox), unfocusedComebackStr
+ );
+ gtk_combo_box_set_active_id(
+ GTK_COMBO_BOX(targetPointComboBox), targetPointStr
+ );
}
G_MODULE_EXPORT void SettingsWindowClose()
@@ -194,6 +206,13 @@ G_MODULE_EXPORT void SettingsWindow_ApplyBtnClick()
ac.targetFps =
atoi(gtk_combo_box_get_active_id(GTK_COMBO_BOX(targetFpsComboBox)));
+ ac.unfocusedComeback =
+ atoi(gtk_combo_box_get_active_id(GTK_COMBO_BOX(unfocusedComebackComboBox))
+ );
+
+ ac.wndTargetPoint =
+ atoi(gtk_combo_box_get_active_id(GTK_COMBO_BOX(targetPointComboBox)));
+
saveAppConfig(&ac);
killWlp();
diff --git a/src/window_templates/main.glade b/src/window_templates/main.glade
index ba18481..f784548 100644
--- a/src/window_templates/main.glade
+++ b/src/window_templates/main.glade
@@ -625,7 +625,7 @@ Layered WallPaper
-
+
+
+
+
+ 0
+ 2
+
+
+
+
+
+ 1
+ 2
+
+
+
+
+
+ 0
+ 3
+
+
+
+
+
+ 1
+ 3
+
+
False
diff --git a/src/wlp/CMakeLists.txt b/src/wlp/CMakeLists.txt
index 354ccfb..f98bdb1 100644
--- a/src/wlp/CMakeLists.txt
+++ b/src/wlp/CMakeLists.txt
@@ -9,6 +9,7 @@ set(_SOURCE_FILES
../common/wallpaperScanner.c
main.c
debug.c
+ targetPoint.c
render.c
window.c
)
diff --git a/src/wlp/main.c b/src/wlp/main.c
index bb616ac..0f2c2d7 100644
--- a/src/wlp/main.c
+++ b/src/wlp/main.c
@@ -6,6 +6,10 @@ static App app;
static void atExit()
{
+#ifdef __LINUX
+ XCloseDisplay(app.display);
+#endif
+
for (int i = 0; i < app.monitorsCount; i++)
{
Monitor *m = app.monitors + i;
@@ -21,7 +25,7 @@ static void atExit()
m++;
}
-
+
free(app.monitors);
SDL_Quit();
@@ -33,7 +37,9 @@ void exitSignalHandler(int s)
exit(0);
}
-void initWallpaper(App *app, Monitor *m, WallpaperInfo *wallpapers, int wallpapersCount)
+void initWallpaper(
+ App *app, Monitor *m, WallpaperInfo *wallpapers, int wallpapersCount
+)
{
MonitorInfo *mi = &m->info;
@@ -54,7 +60,9 @@ void initWallpaper(App *app, Monitor *m, WallpaperInfo *wallpapers, int wallpape
Wallpaper *wallpaper = &m->wlp;
lwpLog(LOG_INFO, "Initializing wallpaper %s...", wallpaper->info.name);
- lwpLog(LOG_INFO, "Layers count: %d", wallpaper->info.config.layersCount);
+ lwpLog(
+ LOG_INFO, "Layers count: %d", wallpaper->info.config.layersCount
+ );
lwpLog(
LOG_INFO,
"Repeat X Y: %d %d",
@@ -70,10 +78,15 @@ void initWallpaper(App *app, Monitor *m, WallpaperInfo *wallpapers, int wallpape
mi->clientBounds.h
);
if (m->tex == NULL)
- lwpLog(LOG_ERROR, "Failed creating a texture for the monitor: %s", SDL_GetError());
-
- wallpaper->layers = malloc(sizeof(Layer) * wallpaper->info.config.layersCount);
- wallpaper->tex = SDL_CreateTexture(
+ lwpLog(
+ LOG_ERROR,
+ "Failed creating a texture for the monitor: %s",
+ SDL_GetError()
+ );
+
+ wallpaper->layers =
+ malloc(sizeof(Layer) * wallpaper->info.config.layersCount);
+ wallpaper->tex = SDL_CreateTexture(
m->renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_TARGET,
@@ -81,7 +94,11 @@ void initWallpaper(App *app, Monitor *m, WallpaperInfo *wallpapers, int wallpape
mi->config.wlpBounds.h
);
if (wallpaper->tex == NULL)
- lwpLog(LOG_ERROR, "Failed creating a texture for the monitor: %s", SDL_GetError());
+ lwpLog(
+ LOG_ERROR,
+ "Failed creating a texture for the monitor: %s",
+ SDL_GetError()
+ );
for (int l = 0; l < wallpaper->info.config.layersCount; l++)
{
@@ -97,9 +114,15 @@ void initWallpaper(App *app, Monitor *m, WallpaperInfo *wallpapers, int wallpape
wallpaper->originalH = surf->h;
}
- wallpaper->layers[l].tex = SDL_CreateTextureFromSurface(m->renderer, surf);
+ wallpaper->layers[l].tex =
+ SDL_CreateTextureFromSurface(m->renderer, surf);
if (wallpaper->tex == NULL)
- lwpLog(LOG_ERROR, "Failed creating a texture for the layer %d: %s", l, SDL_GetError());
+ lwpLog(
+ LOG_ERROR,
+ "Failed creating a texture for the layer %d: %s",
+ l,
+ SDL_GetError()
+ );
SDL_FreeSurface(surf);
}
@@ -109,7 +132,8 @@ void initWallpaper(App *app, Monitor *m, WallpaperInfo *wallpapers, int wallpape
break;
}
}
- if (!foundWlp) lwpLog(LOG_WARNING, "Couldn't find the wallpaper. Ignoring...");
+ if (!foundWlp)
+ lwpLog(LOG_WARNING, "Couldn't find the wallpaper. Ignoring...");
}
int initMonitors(App *app)
@@ -129,16 +153,28 @@ int initMonitors(App *app)
MonitorInfo *mi = &app->monitors[i].info;
+ app->monitors[i].currentPoint.x = 0;
+ app->monitors[i].currentPoint.y = 0;
+
if (!loadMonitorConfig(mi->name, &mi->config))
{
- lwpLog(LOG_WARNING, "Couldn't find config file for monitor %s. Ignoring...", mi->name);
+ lwpLog(
+ LOG_WARNING,
+ "Couldn't find config file for monitor %s. Ignoring...",
+ mi->name
+ );
}
else
{
lwpLog(LOG_INFO, "Initializing monitor %d...", i);
lwpLog(LOG_INFO, "Wallpaper: %s", mi->config.wlpName);
lwpLog(
- LOG_INFO, "Bounds: %d %d %dx%d", mi->clientBounds.x, mi->clientBounds.y, mi->clientBounds.w, mi->clientBounds.h
+ LOG_INFO,
+ "Bounds: %d %d %dx%d",
+ mi->clientBounds.x,
+ mi->clientBounds.y,
+ mi->clientBounds.w,
+ mi->clientBounds.h
);
lwpLog(
LOG_INFO,
@@ -194,6 +230,10 @@ int main(int argc, char *argv[])
atexit(atExit);
lwpLog(LOG_INFO, "Starting wallpaper loop");
+
+#ifdef __LINUX
+ app.display = XOpenDisplay(NULL);
+#endif
runWallpaperLoop(&app);
return 0;
diff --git a/src/wlp/main.h b/src/wlp/main.h
index 983eb6e..6df44f8 100644
--- a/src/wlp/main.h
+++ b/src/wlp/main.h
@@ -29,7 +29,13 @@
typedef struct
{
- SDL_Texture *tex;
+ float x;
+ float y;
+} Point;
+
+typedef struct
+{
+ SDL_Texture* tex;
} Layer;
typedef struct
@@ -37,36 +43,38 @@ typedef struct
WallpaperInfo info;
int originalW;
int originalH;
- SDL_Texture *tex;
- Layer *layers;
+ SDL_Texture* tex;
+ Layer* layers;
} Wallpaper;
typedef struct
{
- MonitorInfo info;
- SDL_Texture *tex;
- Wallpaper wlp;
- SDL_Window *window;
- SDL_Renderer *renderer;
- int aborted;
+ MonitorInfo info;
+ SDL_Texture* tex;
+ Wallpaper wlp;
+ SDL_Window* window;
+ SDL_Renderer* renderer;
+ Point currentPoint;
+ int aborted;
} Monitor;
typedef struct
{
- AppConfig config;
- int monitorsCount;
- Monitor *monitors;
+ AppConfig config;
+ int monitorsCount;
+ Monitor* monitors;
+
+#ifdef __LINUX
+ Display* display;
+#endif
+
} App;
-typedef struct
-{
- float x;
- float y;
-} Point;
+void lwpLog(int type, const char* str, ...);
-void lwpLog(int type, const char *str, ...);
+void initWindow(App* app, Monitor* monitor);
+void runWallpaperLoop(App* app);
-void initWindow(App *app, Monitor *monitor);
-void runWallpaperLoop(App *app);
+void getTargetPoint(App* app, Point* p);
#endif // MAIN_H
diff --git a/src/wlp/render.c b/src/wlp/render.c
index f1fea90..0b48e92 100644
--- a/src/wlp/render.c
+++ b/src/wlp/render.c
@@ -2,47 +2,75 @@
#include "main.h"
-static int lerp(int a, int b, float t)
-{
- if (t > 1) t = 1;
+static int lerp(int a, int b, float t) {
+ if (t > 1)
+ t = 1;
return (int)((float)a + (float)t * ((float)b - (float)a));
}
-static float clamp(float a, float min, float max)
-{
- if (a < min) return min;
- if (a > max) return max;
+static float clamp(float a, float min, float max) {
+ if (a < min)
+ return min;
+ if (a > max)
+ return max;
return a;
}
-static void getRelativeTargetPoint(
- Point *dest, Point *globalTargetPoint, Monitor *m
-)
-{
+static void lerpTargetPoint(Point* p, Point* target, float dT) {
+ p->x = lerp(p->x, target->x, dT * 4); // 4: smooth
+ p->y = lerp(p->y, target->y, dT * 4);
+}
+
+static void getRelativeTargetPoint(Point* dest, const Point* globalTargetPoint,
+ const Monitor* m) {
dest->x = globalTargetPoint->x - m->info.clientBounds.x;
dest->y = globalTargetPoint->y - m->info.clientBounds.y;
+}
+
+static void clampTargetPoint(Point* p, Monitor* m) {
+ p->x = clamp(p->x, 0, m->info.clientBounds.w);
+ p->y = clamp(p->y, 0, m->info.clientBounds.h);
+}
- dest->x = clamp(dest->x, 0, m->info.clientBounds.w);
- dest->y = clamp(dest->y, 0, m->info.clientBounds.h);
+static void comeBackTargetPoint(Point* p, Monitor* m) {
+ if (p->x < 0 || p->x > m->info.clientBounds.w || p->y < 0 ||
+ p->y > m->info.clientBounds.h) {
+ p->x = m->info.clientBounds.w / 2;
+ p->y = m->info.clientBounds.h / 2;
+ }
}
-static void renderMonitor(App *app, Monitor *monitor, Point *globalTargetPoint)
-{
- if (!monitor->info.config.loaded || !monitor->wlp.info.config.loaded) return;
+static float distanceSquared(const Point* p, const Point* q) {
+ return (p->x - q->x) * (p->x - q->x) + (p->y - q->y) * (p->y - q->y);
+}
+
+static void renderMonitor(App* app, Monitor* monitor,
+ const Point* globalTargetPoint, float dT,
+ int firstRender) {
+ if (!monitor->info.config.loaded || !monitor->wlp.info.config.loaded)
+ return;
Point targetPoint;
getRelativeTargetPoint(&targetPoint, globalTargetPoint, monitor);
- if (SDL_SetRenderTarget(monitor->renderer, monitor->wlp.tex) != 0)
- {
+ if (app->config.unfocusedComeback)
+ comeBackTargetPoint(&targetPoint, monitor);
+ else
+ clampTargetPoint(&targetPoint, monitor);
+
+ lerpTargetPoint(&monitor->currentPoint, &targetPoint, dT);
+
+ if (distanceSquared(&monitor->currentPoint, &targetPoint) < 1 && !firstRender)
+ return;
+
+ if (SDL_SetRenderTarget(monitor->renderer, monitor->wlp.tex) != 0) {
lwpLog(LOG_ERROR, "Error setting the renderer target: %s", SDL_GetError());
monitor->aborted = 1;
return;
}
SDL_RenderClear(monitor->renderer);
- for (int i = 0; i < monitor->wlp.info.config.layersCount; i++)
- {
+ for (int i = 0; i < monitor->wlp.info.config.layersCount; i++) {
SDL_Rect src = {
.x = 0,
.y = 0,
@@ -50,21 +78,15 @@ static void renderMonitor(App *app, Monitor *monitor, Point *globalTargetPoint)
.h = monitor->wlp.originalH,
};
- int x =
- -((targetPoint.x - monitor->info.clientBounds.w / 2) *
- monitor->wlp.info.config.layerConfigs[i].sensitivityX);
- int y =
- -((targetPoint.y - monitor->info.clientBounds.h / 2) *
- monitor->wlp.info.config.layerConfigs[i].sensitivityY);
+ int x = -((monitor->currentPoint.x - monitor->info.clientBounds.w / 2) *
+ monitor->wlp.info.config.layerConfigs[i].sensitivityX);
+ int y = -((monitor->currentPoint.y - monitor->info.clientBounds.h / 2) *
+ monitor->wlp.info.config.layerConfigs[i].sensitivityY);
for (int k = -monitor->wlp.info.config.repeatY;
- k <= monitor->wlp.info.config.repeatY;
- k++)
- {
+ k <= monitor->wlp.info.config.repeatY; k++) {
for (int j = -monitor->wlp.info.config.repeatX;
- j <= monitor->wlp.info.config.repeatX;
- j++)
- {
+ j <= monitor->wlp.info.config.repeatX; j++) {
SDL_Rect dest = {
.x = x + j * monitor->info.config.wlpBounds.w,
.y = y + k * monitor->info.config.wlpBounds.h,
@@ -72,10 +94,8 @@ static void renderMonitor(App *app, Monitor *monitor, Point *globalTargetPoint)
.h = monitor->info.config.wlpBounds.h,
};
- if (SDL_RenderCopy(
- monitor->renderer, monitor->wlp.layers[i].tex, &src, &dest
- ) != 0)
- {
+ if (SDL_RenderCopy(monitor->renderer, monitor->wlp.layers[i].tex, &src,
+ &dest) != 0) {
lwpLog(LOG_ERROR, "Error rendering copy: %s", SDL_GetError());
monitor->aborted = 1;
}
@@ -83,8 +103,7 @@ static void renderMonitor(App *app, Monitor *monitor, Point *globalTargetPoint)
}
}
- if (SDL_SetRenderTarget(monitor->renderer, monitor->tex) != 0)
- {
+ if (SDL_SetRenderTarget(monitor->renderer, monitor->tex) != 0) {
lwpLog(LOG_ERROR, "Error setting the renderer target: %s", SDL_GetError());
monitor->aborted = 1;
}
@@ -103,16 +122,14 @@ static void renderMonitor(App *app, Monitor *monitor, Point *globalTargetPoint)
.h = monitor->info.config.wlpBounds.h,
};
- if (SDL_RenderCopy(monitor->renderer, monitor->wlp.tex, &src, &dest) != 0)
- {
+ if (SDL_RenderCopy(monitor->renderer, monitor->wlp.tex, &src, &dest) != 0) {
lwpLog(LOG_ERROR, "Error rendering copy: %s", SDL_GetError());
monitor->aborted = 1;
}
SDL_SetRenderTarget(monitor->renderer, NULL);
- if (SDL_RenderCopy(monitor->renderer, monitor->tex, NULL, NULL) != 0)
- {
+ if (SDL_RenderCopy(monitor->renderer, monitor->tex, NULL, NULL) != 0) {
lwpLog(LOG_ERROR, "Error rendering copy: %s", SDL_GetError());
monitor->aborted = 1;
}
@@ -121,43 +138,20 @@ static void renderMonitor(App *app, Monitor *monitor, Point *globalTargetPoint)
SDL_Delay(1000 / app->config.targetFps);
}
-static void getInput(int *quit)
-{
+static void getInput(int* quit) {
SDL_Event event;
while (SDL_PollEvent(&event))
- if (event.type == SDL_QUIT) (*quit) = 1;
-}
-
-static void getTargetPoint(Point *p)
-{
-#ifdef __WIN32
- POINT mPos;
- GetCursorPos(&mPos);
- p->x = mPos.x - GetSystemMetrics(SM_XVIRTUALSCREEN);
- p->y = mPos.y - GetSystemMetrics(SM_YVIRTUALSCREEN);
-#else
- int x, y;
- SDL_GetGlobalMouseState(&x, &y);
- p->x = x;
- p->y = y;
-#endif
+ if (event.type == SDL_QUIT)
+ (*quit) = 1;
}
-static void lerpTargetPoint(Point *p, Point *target, float dT)
-{
- p->x = lerp(p->x, target->x, dT * 4); // 4: smooth
- p->y = lerp(p->y, target->y, dT * 4);
-}
-
-void runWallpaperLoop(App *app)
-{
+void runWallpaperLoop(App* app) {
Point targetPoint;
- Point point;
- int quit = 0;
- while (!quit)
- {
+ int firstRender = 1;
+ int quit = 0;
+ while (!quit) {
static int lastTicks = 0;
int ticks = SDL_GetTicks();
@@ -166,11 +160,12 @@ void runWallpaperLoop(App *app)
getInput(&quit);
- getTargetPoint(&targetPoint);
- lerpTargetPoint(&point, &targetPoint, dT);
+ getTargetPoint(app, &targetPoint);
- for (int m = 0; m < app->monitorsCount; m++)
+ for (int m = 0; m < app->monitorsCount; m++) {
if (!app->monitors[m].aborted)
- renderMonitor(app, app->monitors + m, &point);
+ renderMonitor(app, app->monitors + m, &targetPoint, dT, firstRender);
+ }
+ firstRender = 0;
}
}
diff --git a/src/wlp/targetPoint.c b/src/wlp/targetPoint.c
new file mode 100644
index 0000000..98dd075
--- /dev/null
+++ b/src/wlp/targetPoint.c
@@ -0,0 +1,46 @@
+#include "main.h"
+
+void getTargetPoint(App* app, Point* p)
+{
+ if (app->config.wndTargetPoint)
+ {
+#ifdef __WIN32
+ HWND focusedWnd = GetForegroundWindow();
+
+ if (focusedWnd)
+ {
+ RECT rect;
+ GetWindowRect(focusedWnd, &rect);
+
+ p->x = rect.left + (rect.right - rect.left) / 2;
+ p->y = rect.top + (rect.bottom - rect.top) / 2;
+ }
+#else
+ Window wnd;
+ int revertTo;
+ XGetInputFocus(app->display, &wnd, &revertTo);
+
+ int x, y;
+ unsigned int w, h, bw, bh;
+ Window rootWnd;
+ XGetGeometry(app->display, wnd, &rootWnd, &x, &y, &w, &h, &bw, &bh);
+
+ p->x = x;
+ p->y = y;
+#endif
+ }
+ else
+ {
+#ifdef __WIN32
+ POINT mPos;
+ GetCursorPos(&mPos);
+ p->x = mPos.x - GetSystemMetrics(SM_XVIRTUALSCREEN);
+ p->y = mPos.y - GetSystemMetrics(SM_YVIRTUALSCREEN);
+#else
+ int x, y;
+ SDL_GetGlobalMouseState(&x, &y);
+ p->x = x;
+ p->y = y;
+#endif
+ }
+}