Skip to content

Commit

Permalink
Autostart
Browse files Browse the repository at this point in the history
  • Loading branch information
thjaeger committed Dec 6, 2008
1 parent ca2112f commit 9ce793b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ easystroke
easystroke.1
gui.gb
gui.c
desktop.c
*.swp
dbus-server.h
debug.mk
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ MENU = easystroke.desktop
MANPAGE = easystroke.1

CCFILES = $(wildcard *.cc)
OFILES = $(patsubst %.cc,%.o,$(CCFILES)) gui.o version.o
OFILES = $(patsubst %.cc,%.o,$(CCFILES)) gui.o desktop.o version.o
DEPFILES = $(wildcard *.Po)
GENFILES = gui.gb gui.c dbus-server.h
GENFILES = gui.gb gui.c desktop.c dbus-server.h

VERSION = $(shell test -e debian/changelog && grep '(.*)' debian/changelog | sed 's/.*(//' | sed 's/).*//' | head -n1 || (test -e version && cat version || git describe))
GIT = $(wildcard .git/index version)
Expand Down Expand Up @@ -66,9 +66,14 @@ gui.gb: gui.glade
gtk-builder-convert gui.glade gui.gb

gui.c: gui.gb
echo "const char *gui_buffer = \"\\" > gui.c
sed 's/"/\\"/g' gui.gb | sed 's/.*/&\\n\\/' >> gui.c
echo "\";" >> gui.c
echo "const char *gui_buffer = \"\\" > $@
sed 's/"/\\"/g' $< | sed 's/.*/&\\n\\/' >> $@
echo "\";" >> $@

desktop.c: easystroke.desktop
echo "const char *desktop_file = \"\\" > $@
sed 's/Exec=easystroke/Exec=%s/' $< | sed 's/"/\\"/g' | sed 's/.*/&\\n\\/' >> $@
echo "\";" >> $@

dbus-server.cc: dbus-server.h

Expand Down
151 changes: 84 additions & 67 deletions gui.glade
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Wed Nov 12 14:10:42 2008 -->
<!--Generated with glade3 3.4.5 on Fri Nov 28 19:19:50 2008 -->
<glade-interface>
<widget class="GtkWindow" id="main">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
Expand Down Expand Up @@ -34,20 +34,31 @@
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<widget class="GtkButton" id="button_reset_actions">
<widget class="GtkScrolledWindow" id="scrolledwindow5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">Reset Action(s)</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<child>
<widget class="GtkTreeView" id="treeview_apps">
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="check_show_deleted">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show deleted rows</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -107,33 +118,22 @@
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="check_show_deleted">
<widget class="GtkButton" id="button_reset_actions">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show deleted rows</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">Reset Action(s)</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<child>
<widget class="GtkTreeView" id="treeview_apps">
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
Expand Down Expand Up @@ -523,12 +523,29 @@ Water (compiz)</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="check_tray_icon">
<widget class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show tray icon</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
<child>
<widget class="GtkCheckButton" id="check_tray_icon">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show tray icon</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="check_autostart">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Autostart easystroke</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="position">2</property>
Expand Down Expand Up @@ -1344,95 +1361,95 @@ Please place your mouse or pen in the box below and press the button that you wa
<property name="row_spacing">6</property>
<property name="homogeneous">True</property>
<child>
<widget class="GtkComboBox" id="select_button">
<widget class="GtkToggleButton" id="toggle_control">
<property name="visible">True</property>
<property name="items" translatable="yes">Button 1
Button 2
Button 3
Button 4
Button 5
Button 6
Button 7
Button 8
Button 9
Button 10
Button 11
Button 12</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">_Control</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<widget class="GtkToggleButton" id="toggle_any">
<widget class="GtkToggleButton" id="toggle_shift">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">An_y Modifier</property>
<property name="label" translatable="yes">_Shift</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkToggleButton" id="toggle_super">
<widget class="GtkToggleButton" id="toggle_alt">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">S_uper</property>
<property name="label" translatable="yes">_Alt</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkToggleButton" id="toggle_alt">
<widget class="GtkToggleButton" id="toggle_super">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">_Alt</property>
<property name="label" translatable="yes">S_uper</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkToggleButton" id="toggle_shift">
<widget class="GtkToggleButton" id="toggle_any">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">_Shift</property>
<property name="label" translatable="yes">An_y Modifier</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkToggleButton" id="toggle_control">
<widget class="GtkComboBox" id="select_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">_Control</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="items" translatable="yes">Button 1
Button 2
Button 3
Button 4
Button 5
Button 6
Button 7
Button 8
Button 9
Button 10
Button 11
Button 12</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND</property>
</packing>
</child>
</widget>
Expand Down
47 changes: 47 additions & 0 deletions prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,50 @@ TraceType int_to_trace(int i) {
}
}

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;
public:
Autostart() {
std::string dir = getenv("HOME");
dir += "/.config/autostart";
filename = dir + "/easystroke.desktop";

struct stat sb;
if (stat(dir.c_str(), &sb) == -1 || (sb.st_mode & S_IFMT) != S_IFDIR) {
autostart_ok.set(false);
return;
}
a = stat(filename.c_str(), &sb) != -1 &&
((sb.st_mode & S_IFMT) == S_IFREG || (sb.st_mode & S_IFMT) == S_IFLNK);
}
virtual void set(const bool a_) {
a = a_;
notify();
}
virtual bool get() const { return a; }
virtual void notify() {
if (a) {
FILE *file = fopen(filename.c_str(), "w");
if (!file || fprintf(file, desktop_file, "easystroke") == -1)
autostart_ok.set(false);
if (file)
fclose(file);
} else {
if (remove(filename.c_str()) == -1)
autostart_ok.set(false);
}
update();
}
};

Autostart autostart;

void remove_last_entry(const Glib::ustring & name) {
Gtk::ComboBox *combo;
widgets->get_widget(name, combo);
Expand Down Expand Up @@ -204,6 +248,9 @@ Prefs::Prefs() {

new Check(prefs.tray_icon, "check_tray_icon");

new Check(autostart, "check_autostart");
new Sensitive(autostart_ok, "check_autostart");

new Spin(prefs.init_timeout, "spin_timeout");
new Spin(prefs.min_speed, "spin_min_speed");

Expand Down

0 comments on commit 9ce793b

Please sign in to comment.