Skip to content

Commit

Permalink
Merge pull request #79 from jszczerbinsky/dev
Browse files Browse the repository at this point in the history
v2.1.2
  • Loading branch information
jszczerbinsky authored Jul 5, 2024
2 parents e8286aa + d71e088 commit 5d94c82
Show file tree
Hide file tree
Showing 22 changed files with 2,030 additions and 1,441 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ build/

.vscode

tags
types_c.taghl
*~

# Prerequisites
*.d

Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ set(CPACK_NSIS_MUI_ICON ${CMAKE_CURRENT_SOURCE_DIR}/icon.ico)
set(CPACK_NSIS_MUI_UNIICON ${CMAKE_CURRENT_SOURCE_DIR}/icon.ico)
set(CPACK_NSIS_INSTALLED_ICON_NAME ${CMAKE_CURRENT_SOURCE_DIR}/icon.ico)
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
WriteRegExpandStr HKLM 'Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run' 'lwp' '\$INSTDIR\\\\lwp.exe'
WriteRegExpandStr HKLM 'Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run' 'lwp' '\$INSTDIR\\\\lwp.exe'
Exec '\$INSTDIR\\\\lwp.exe'
CreateShortCut \\\"$DESKTOP\\\\Layered WallPaper.lnk\\\" \\\"$INSTDIR\\\\lwp.exe\\\"
")
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
DeleteRegValue HKLM 'Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run' 'lwp'
Delete \\\"$DESKTOP\\\\Layered WallPaper.lnk\\\"
")
set(CPACK_PACKAGE_NAME "Layered WallPaper")
set(CPACK_PACKAGE_VENDOR "Jakub Szczerbinski")
Expand Down
53 changes: 36 additions & 17 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#ifndef COMMON_H
#define COMMON_H

#include "platform_guard.h"

#ifdef __LINUX
#include <linux/limits.h>
#else
#include <windows.h>
#include <Windows.h>
#include <shellscalingapi.h>
#endif

#define MONITOR_NAME_MAX 100
#define MONITOR_NAME_MAX 128
#define WALLPAPER_NAME_MAX 100

#define DEFAULT_LINUX_PREFIX "/usr/local"

#define LOG_ERROR 0
#define LOG_INFO 1
#define LOG_WARNING 2

typedef struct
{
int x;
Expand All @@ -32,7 +39,7 @@ typedef struct
int repeatX;
int repeatY;
int layersCount;
LayerConfig *layerConfigs;
LayerConfig* layerConfigs;
} WallpaperConfig;

typedef struct
Expand All @@ -46,22 +53,27 @@ typedef struct
typedef struct
{
int loaded;
int active;
char wlpName[WALLPAPER_NAME_MAX];
Bounds wlpBounds;
} MonitorConfig;

typedef struct
{
char displayName[MONITOR_NAME_MAX];
char name[MONITOR_NAME_MAX];
Bounds bounds;
Bounds pixelBounds;
Bounds clientBounds;
Bounds virtualBounds;
MonitorConfig config;
} MonitorInfo;

typedef struct
{
int drawOnRootWindow;
int targetFps;
char renderQuality[8];
int unfocusedComeback;
int wndTargetPoint;
} AppConfig;

//
Expand All @@ -72,37 +84,44 @@ 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();

//
// 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);
//
// debug.c
//
void clearlog();
void printlog(int type, const char* str, ...);
char* readLogFile();

#endif
70 changes: 46 additions & 24 deletions src/common/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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;
Expand All @@ -16,14 +16,17 @@ 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;

config_init(&cfg);
root = config_root_setting(&cfg);

setting = config_setting_add(root, "active", CONFIG_TYPE_INT);
config_setting_set_int(setting, mc->active);

setting = config_setting_add(root, "wlpName", CONFIG_TYPE_STRING);
config_setting_set_string(setting, mc->wlpName);

Expand All @@ -48,7 +51,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;

Expand All @@ -69,6 +72,12 @@ int loadMonitorConfig(const char *name, MonitorConfig *mc)
if (config_read_file(&cfg, path) == CONFIG_FALSE) return 0;
root = config_root_setting(&cfg);

setting = config_setting_get_member(root, "active");
if (!setting)
mc->active = 1;
else
mc->active = config_setting_get_int(setting);

setting = config_setting_get_member(root, "wlpName");
strcpy(mc->wlpName, config_setting_get_string(setting));

Expand All @@ -87,31 +96,30 @@ int loadMonitorConfig(const char *name, MonitorConfig *mc)
return 1;
}

static void useDefaultAppCfg(AppConfig *ac)
static void useDefaultAppCfg(AppConfig* ac)
{
#ifdef __LINUX
ac->drawOnRootWindow = 0;
#endif
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;

config_init(&cfg);
root = config_root_setting(&cfg);

#ifdef __LINUX
setting = config_setting_add(root, "draw_on_rootwindow", CONFIG_TYPE_INT);
config_setting_set_int(setting, ac->drawOnRootWindow);
#endif
setting = config_setting_add(root, "target_fps", CONFIG_TYPE_INT);
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);
Expand All @@ -125,7 +133,7 @@ void saveAppConfig(AppConfig *ac)
config_destroy(&cfg);
}

int loadAppConfig(AppConfig *ac)
int loadAppConfig(AppConfig* ac)
{
config_t cfg;
config_setting_t *root, *setting;
Expand All @@ -141,21 +149,35 @@ int loadAppConfig(AppConfig *ac)
}
root = config_root_setting(&cfg);

#ifdef __LINUX
setting = config_setting_get_member(root, "draw_on_rootwindow");
ac->drawOnRootWindow = config_setting_get_int(setting);
#endif
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));
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);

config_destroy(&cfg);

return 1;
}

int loadWallpaperConfig(const char *dirPath, WallpaperConfig *wc)
int loadWallpaperConfig(const char* dirPath, WallpaperConfig* wc)
{
wc->loaded = 0;

Expand Down Expand Up @@ -190,7 +212,7 @@ int loadWallpaperConfig(const char *dirPath, WallpaperConfig *wc)

for (int i = 0; i < wc->layersCount; i++)
{
LayerConfig *lc = wc->layerConfigs + i;
LayerConfig* lc = wc->layerConfigs + i;

lc->sensitivityX = movX * i;
lc->sensitivityY = movY * i;
Expand Down
83 changes: 83 additions & 0 deletions src/common/debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <glib.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>

#include "../common.h"

void clearlog()
{
char path[PATH_MAX];
getLogPath(path);

FILE *file = fopen(path, "w");
fclose(file);
}

void printlog(int type, const char *str, ...)
{
char path[PATH_MAX];
getLogPath(path);

FILE *file = fopen(path, "a");

time_t t;
time(&t);
struct tm *time = localtime(&t);

char *typePrefix = "";

switch (type)
{
case LOG_ERROR:
typePrefix = "ERROR";
break;
case LOG_INFO:
typePrefix = "INFO";
break;
case LOG_WARNING:
typePrefix = "WARNING";
break;
}

fprintf(
file,
"%d-%02d-%02d %02d:%02d:%02d %s: ",
time->tm_year + 1900,
time->tm_mon + 1,
time->tm_mday,
time->tm_hour,
time->tm_min,
time->tm_sec,
typePrefix
);

va_list args;
va_start(args, str);
vfprintf(file, str, args);
va_end(args);

fprintf(file, "\n");

fclose(file);
}

char *readLogFile()
{
char path[PATH_MAX];
getLogPath(path);

FILE *file = fopen(path, "r");

fseek(file, 0, SEEK_END);
int len = ftell(file);
fseek(file, 0, SEEK_SET);

char *buff = malloc((len + 1) * sizeof(char));
fread(buff, sizeof(char), len, file);
buff[len] = '\0';

fclose(file);

return buff;
}
Loading

0 comments on commit 5d94c82

Please sign in to comment.