Skip to content

Commit

Permalink
Target point comeback
Browse files Browse the repository at this point in the history
  • Loading branch information
jszczerbinsky committed May 3, 2024
1 parent 8c540ab commit e3fd1ef
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 65 deletions.
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct
{
int targetFps;
char renderQuality[8];
int unfocusedComeback;
} AppConfig;

//
Expand Down
26 changes: 20 additions & 6 deletions src/common/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void useDefaultAppCfg(AppConfig *ac)
{
ac->targetFps = 60;
strcpy(ac->renderQuality, "best");
ac->unfocusedComeback = 1;
}

void saveAppConfig(AppConfig *ac)
Expand All @@ -105,6 +106,8 @@ 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);

char path[PATH_MAX];
getAppCfgPath(path);
Expand Down Expand Up @@ -134,12 +137,23 @@ int loadAppConfig(AppConfig *ac)
}
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);

return 1;
}
Expand Down
36 changes: 20 additions & 16 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
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;

static void reloadMonitorListBox()
{
Expand Down Expand Up @@ -156,6 +157,9 @@ 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"
);

gtk_window_set_application(GTK_WINDOW(mainWnd), GTK_APPLICATION(app));
gtk_window_set_application(GTK_WINDOW(exitDialog), GTK_APPLICATION(app));
Expand Down
2 changes: 1 addition & 1 deletion src/core/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern GtkWidget *monitorNameLabel;
extern GtkWidget *appSettingsWnd;
extern GtkWidget *targetFpsComboBox;
extern GtkWidget *renderQualityComboBox;
extern GtkWidget *drawOnRootWndComboBox;
extern GtkWidget *unfocusedComebackComboBox;

void runWlp();
void killWlp();
Expand Down
10 changes: 10 additions & 0 deletions src/core/windowHandlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,16 @@ G_MODULE_EXPORT void SettingsWindowShow()
char targetFpsStr[4];
sprintf(targetFpsStr, "%d", ac.targetFps);

char unfocusedComebackStr[2];
sprintf(unfocusedComebackStr, "%d", ac.unfocusedComeback);

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
);
}

G_MODULE_EXPORT void SettingsWindowClose()
Expand All @@ -194,6 +200,10 @@ 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))
);

saveAppConfig(&ac);

killWlp();
Expand Down
28 changes: 27 additions & 1 deletion src/window_templates/main.glade
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ Layered WallPaper</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=2 -->
<!-- n-columns=2 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -690,6 +690,32 @@ Layered WallPaper</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Unfocused monitor behaviour</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="SettingsWindow_UnfocusedCombackComboBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<items>
<item id="1" translatable="yes">Come back</item>
<item id="0" translatable="yes">Clamp</item>
</items>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down
58 changes: 45 additions & 13 deletions src/wlp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void atExit()

m++;
}

free(app.monitors);

SDL_Quit();
Expand All @@ -33,7 +33,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;

Expand All @@ -54,7 +56,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",
Expand All @@ -70,18 +74,27 @@ 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,
mi->config.wlpBounds.w,
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++)
{
Expand All @@ -97,9 +110,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);
}
Expand All @@ -109,7 +128,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)
Expand All @@ -129,16 +149,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,
Expand Down
27 changes: 14 additions & 13 deletions src/wlp/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
#define LOG_INFO 1
#define LOG_WARNING 2

typedef struct
{
float x;
float y;
} Point;

typedef struct
{
SDL_Texture *tex;
Expand All @@ -43,27 +49,22 @@ typedef struct

typedef struct
{
MonitorInfo info;
SDL_Texture *tex;
Wallpaper wlp;
MonitorInfo info;
SDL_Texture *tex;
Wallpaper wlp;
SDL_Window *window;
SDL_Renderer *renderer;
int aborted;
Point currentPoint;
int aborted;
} Monitor;

typedef struct
{
AppConfig config;
int monitorsCount;
Monitor *monitors;
AppConfig config;
int monitorsCount;
Monitor *monitors;
} App;

typedef struct
{
float x;
float y;
} Point;

void lwpLog(int type, const char *str, ...);

void initWindow(App *app, Monitor *monitor);
Expand Down
Loading

0 comments on commit e3fd1ef

Please sign in to comment.