← easystroke

Improve autostart

e6bd3ebc4fea9c6b4604ec84aff35b0745bd636b · Thomas Jaeger · Oct 7, 2012 22:47

+8 −5 · 2 files changed

  • Makefile +1 −1
  • prefs.cc +7 −4
diff --git a/Makefile b/Makefile
index 181a783..c7b2af2 100644
--- a/Makefile
+++ b/Makefile
@@ -80,7 +80,7 @@ easystroke.desktop: easystroke.desktop.in $(MOFILES)
 
 desktop.c: easystroke.desktop
 	echo "const char *desktop_file = \"\\" > $@
-	sed 's/Exec=easystroke/Exec=%s/' $< | sed 's/"/\\"/g' | sed 's/.*/&\\n\\/' >> $@
+	sed 's/Exec=easystroke/Exec=%1$$s/' $< | sed 's/"/\\"/g' | sed 's/.*/&\\n\\/' >> $@
 	echo "\";" >> $@
 
 po/POTFILES.in: $(CCFILES) $(HFILES)
diff --git a/prefs.cc b/prefs.cc
index f246aa5..9928d1c 100644
--- a/prefs.cc
+++ b/prefs.cc
@@ -18,10 +18,13 @@
 #include "main.h"
 #include "grabber.h"
 #include <glibmm/i18n.h>
+#include <sys/stat.h>
 
 #include <set>
 #include <iostream>
 
+extern const char *desktop_file;
+
 class Check : private Base {
 	IO<bool> &io;
 	Gtk::CheckButton *check;
@@ -183,9 +186,6 @@ const Combo<TimeoutType>::Info timeout_info_exp[] = {
 
 Source<bool> autostart_ok(true);
 
-#include <sys/stat.h>
-extern const char *desktop_file;
-
 class Autostart : public IO<bool>, private Base {
 	bool a;
 	std::string filename;
@@ -208,8 +208,11 @@ public:
 	virtual bool get() const { return a; }
 	virtual void notify() {
 		if (a) {
+			char path[256] = "easystroke";
+			readlink("/proc/self/exe", path, sizeof(path));
+
 			FILE *file = fopen(filename.c_str(), "w");
-			if (!file || fprintf(file, desktop_file, "easystroke") == -1)
+			if (!file || fprintf(file, desktop_file, path) == -1)
 				autostart_ok.set(false);
 			if (file)
 				fclose(file);