aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson_options.txt1
-rw-r--r--src/configuration.c16
-rw-r--r--src/extString.c50
-rw-r--r--src/main.c20
-rw-r--r--src/meson.build6
5 files changed, 56 insertions, 37 deletions
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..cf555c1
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1 @@
+option('gclue_support', type: 'feature', value : 'enabled', description : 'Enable support for retreiving the current location via GeoClue') \ No newline at end of file
diff --git a/src/configuration.c b/src/configuration.c
index 7d978f6..1bf9eb9 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -1,6 +1,6 @@
/* configuration.c
*
- * Copyright 2024 axtlos <axtlos@disroot.org>
+ * Copyright 2025 Rose <rose@pinkro.se>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,18 +31,21 @@ dictionary *
load_config(void)
{
char *xdg_config = getenv ("XDG_CONFIG_HOME");
- char *home = getenv ("HOME");
- if (home == NULL)
- return NULL;
if (xdg_config == NULL) {
+ char *home = getenv ("HOME");
+ if (home == NULL)
+ return NULL;
+
+ // the getenv output cannot be freed, it results in a segfault
+ // but this one should be freed, as it is manually allocated
+ // however this isnt freed. that is bad. i am too lazy to free it properly
+ // autodarkmode can leak some memory, as a treat
xdg_config = malloc (strlen(home)*sizeof(char)+strlen("/.config")*sizeof(char)+1);
sprintf (xdg_config, "%s/.config", home);
}
char *config_path = malloc(strlen(xdg_config)*sizeof(char)+strlen("/autodarkmode/config.ini")*sizeof(char)+1);
sprintf (config_path, "%s/autodarkmode/config.ini", xdg_config);
- free (xdg_config);
-
if (access(config_path, F_OK) != 0) {
g_printerr ("Config file not found. Using default values.\n");
free (config_path);
@@ -93,4 +96,3 @@ config_get_longitude (dictionary *d)
return iniparser_getdouble (d, "manual:longitude", 0);
}
-
diff --git a/src/extString.c b/src/extString.c
index e7ebeaa..2703ed6 100644
--- a/src/extString.c
+++ b/src/extString.c
@@ -52,31 +52,31 @@ char *trim(const char *s)
}
char *replaceStr(const char *s, const char *old, const char *replace) {
- char* result;
- int i, cnt = 0;
- size_t newSize = strlen(replace);
- size_t oldSize = strlen(old);
-
- for (i = 0; s[i] != '\0'; i++) {
- if (strstr(&s[i], old) == &s[i]) {
- cnt++;
- i += oldSize - 1;
- }
- }
+ char* result;
+ int i, cnt = 0;
+ size_t newSize = strlen(replace);
+ size_t oldSize = strlen(old);
- result = (char*)malloc(i + cnt * (newSize - oldSize) + 1);
-
- i = 0;
- while (*s) {
- if (strstr(s, old) == s) {
- strcpy(&result[i], replace);
- i += newSize;
- s += oldSize;
- }
+ for (i = 0; s[i] != '\0'; i++) {
+ if (strstr(&s[i], old) == &s[i]) {
+ cnt++;
+ i += oldSize - 1;
+ }
+ }
+
+ result = (char*)malloc(i + cnt * (newSize - oldSize) + 1);
+
+ i = 0;
+ while (*s) {
+ if (strstr(s, old) == s) {
+ strcpy(&result[i], replace);
+ i += newSize;
+ s += oldSize;
+ }
else
- result[i++] = *s++;
- }
-
- result[i] = '\0';
- return result;
+ result[i++] = *s++;
+ }
+
+ result[i] = '\0';
+ return result;
};
diff --git a/src/main.c b/src/main.c
index 3d317a8..8dc859f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * Copyright 2024 Unknown
+ * Copyright 2025 Rose <rose@pinkro.se>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,17 +21,22 @@
#include "configuration.h"
#include "sun.h"
+#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <signal.h>
+#include <unistd.h>
#include <glib.h>
-#include <stdlib.h>
+
+#ifdef USE_GCLUE
#include <geoclue.h>
static GClueAccuracyLevel accuracy_level = GCLUE_ACCURACY_LEVEL_EXACT;
GClueSimple *simple = NULL;
GClueClient *client = NULL;
+#endif
+
GMainLoop *main_loop;
enum LocationType loctype = 0;
@@ -42,6 +47,7 @@ bool isdark = false;
float lat = 0;
float lng = 0;
+#ifdef USE_GCLUE
static void
get_gclue_location (GClueSimple *simple)
{
@@ -58,6 +64,7 @@ get_gclue_location (GClueSimple *simple)
return;
}
+#endif
void
on_dark (void)
@@ -159,7 +166,6 @@ gint
main (gint argc,
gchar *argv[])
{
- //g_print ("%s\n", argv[1]);
g_autoptr(GError) error = NULL;
g_autoptr(GOptionContext) context = NULL;
@@ -187,12 +193,18 @@ main (gint argc,
lat = config_get_latitude (dict);
lng = config_get_longitude (dict);
} else {
+#if defined USE_GCLUE
get_gclue_location (gclue_simple_new_sync ("autodarkmode",
accuracy_level,
NULL,
NULL));
g_print ("lat: %f\n", lat);
g_print ("lng: %f\n", lng);
+#else
+ fprintf (stderr, "ERROR: autodarkmode was not compiled with gclue support.\n");
+ iniparser_freedict (dict);
+ return 1;
+#endif
}
lat = locLat == 100 ? lat : locLat;
@@ -206,5 +218,5 @@ main (gint argc,
iniparser_freedict (dict);
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
diff --git a/src/meson.build b/src/meson.build
index 6642e9d..e91cc83 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -9,9 +9,13 @@ autodarkmode_sources = [
autodarkmode_deps = [
dependency('glib-2.0'),
- dependency('libgeoclue-2.0'),
+ dependency('libgeoclue-2.0', required : get_option('gclue_support')),
]
+if get_option('gclue_support').enabled()
+ add_project_arguments('-DUSE_GCLUE', language: 'c')
+endif
+
executable('autodarkmode', autodarkmode_sources,
dependencies: autodarkmode_deps,
install: true,