← easystroke

have users enable the whitelist behavior explicitly

03dbbf79ffc48342d71e2c8577ea0a0e5641977a · Thomas Jaeger · Sep 23, 2012 03:46

Also, always use the default options when recording strokes

+51 −27 · 6 files changed

  • actions.cc +4 −4
  • grabber.cc +15 −16
  • gui.glade +25 −5
  • prefdb.cc +4 −1
  • prefdb.h +2 −1
  • prefs.cc +1 −0
diff --git a/actions.cc b/actions.cc
index c17857c..8e6f126 100644
--- a/actions.cc
+++ b/actions.cc
@@ -760,7 +760,7 @@ void Actions::update_row(const Gtk::TreeRow &row) {
 }
 
 extern boost::shared_ptr<sigc::slot<void, RStroke> > stroke_action;
-Source<ActionListDiff *> stroke_app(NULL);
+Source<bool> recording(false);
 
 class Actions::OnStroke {
 	Actions *parent;
@@ -796,7 +796,7 @@ public:
 		stroke = stroke_;
 		Glib::signal_idle().connect(sigc::mem_fun(*this, &OnStroke::run));
 		stroke_action.reset();
-		stroke_app.set(NULL);
+		recording.set(false);
 	}
 };
 
@@ -824,14 +824,14 @@ void Actions::on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewCo
 
 	OnStroke ps(this, dialog, row);
 	stroke_action.reset(new sigc::slot<void, RStroke>(sigc::mem_fun(ps, &OnStroke::delayed_run)));
-	stroke_app.set(action_list);
+	recording.set(true);
 
 	dialog->show();
 	cancel->grab_focus();
 	int response = dialog->run();
 	dialog->hide();
 	stroke_action.reset();
-	stroke_app.set(NULL);
+	recording.set(false);
 	if (response != 1)
 		return;
 
diff --git a/grabber.cc b/grabber.cc
index 434861d..90b4b86 100644
--- a/grabber.cc
+++ b/grabber.cc
@@ -27,7 +27,7 @@
 extern Window get_window(Window w, Atom prop);
 extern Source<bool> disabled;
 extern Source<Window> current_app_window;
-extern Source<ActionListDiff *> stroke_app;
+extern Source<bool> recording;
 extern bool in_proximity;
 
 Grabber *grabber = 0;
@@ -189,9 +189,7 @@ void activate(Window w, Time t) {
 	XSendEvent(dpy, ROOT, False, SubstructureNotifyMask | SubstructureRedirectMask, (XEvent *)&ev);
 }
 
-std::string get_wm_class(Window w, ActionListDiff *actions) {
-	if (actions && actions->app)
-		return actions->name;
+std::string get_wm_class(Window w) {
 	if (!w)
 		return "";
 	XClassHint ch;
@@ -236,8 +234,9 @@ Grabber::Grabber() : children(ROOT) {
 	init_xi();
 	prefs.excluded_devices.connect(new IdleNotifier(sigc::mem_fun(*this, &Grabber::update)));
 	prefs.button.connect(new IdleNotifier(sigc::mem_fun(*this, &Grabber::update)));
-	current_class = fun2(&get_wm_class, current_app_window, stroke_app);
+	current_class = fun(&get_wm_class, current_app_window);
 	current_class->connect(new IdleNotifier(sigc::mem_fun(*this, &Grabber::update)));
+	recording.connect(new IdleNotifier(sigc::mem_fun(*this, &Grabber::update)));
 	disabled.connect(new IdleNotifier(sigc::mem_fun(*this, &Grabber::set)));
 	update();
 	resume();
@@ -511,20 +510,20 @@ guint Grabber::get_default_mods(guint button) {
 }
 
 void Grabber::update() {
-	std::map<std::string, RButtonInfo>::const_iterator i = prefs.exceptions.ref().find(current_class->get());
-	active = true;
 	ButtonInfo bi = prefs.button.ref();
-	if (i != prefs.exceptions.ref().end()) {
-		if (i->second)
-			bi = *i->second;
-		else
+	active = true;
+	if (!recording.get()) {
+		std::map<std::string, RButtonInfo>::const_iterator i = prefs.exceptions.ref().find(current_class->get());
+		if (i != prefs.exceptions.ref().end()) {
+			if (i->second)
+				bi = *i->second;
+			else
+				active = false;
+		}
+
+		if (prefs.whitelist.get() && !actions.apps.count(current_class->get()))
 			active = false;
 	}
-	const ActionListDiff *a = stroke_app.get();
-	if (!a)
-		a = actions.get_action_list(current_class->get());
-	if (active && actions.get_root()->size_rec() && !a->count_actions())
-		active = false;
 	const std::vector<ButtonInfo> &extra = prefs.extra_buttons.ref();
 	if (grabbed_button == bi && buttons.size() == extra.size() + 1 &&
 			std::equal(extra.begin(), extra.end(), ++buttons.begin())) {
diff --git a/gui.glade b/gui.glade
index b3b288e..9529193 100644
--- a/gui.glade
+++ b/gui.glade
@@ -971,6 +971,9 @@ Van Diep Duong (Vietnamese)</property>
                                         <property name="height_request">120</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">True</property>
+                                        <child internal-child="selection">
+                                          <object class="GtkTreeSelection" id="treeview-selection2"/>
+                                        </child>
                                       </object>
                                     </child>
                                   </object>
@@ -1501,6 +1504,23 @@ Van Diep Duong (Vietnamese)</property>
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkCheckButton" id="check_whitelist">
+                            <property name="label" translatable="yes">Only enable easystroke for applications listed on 'Actions' tab</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="xalign">0</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
                         <child>
                           <object class="GtkCheckButton" id="check_timeout_gestures">
                             <property name="label" translatable="yes">Timeout Gestures</property>
@@ -1513,7 +1533,7 @@ Van Diep Duong (Vietnamese)</property>
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">0</property>
+                            <property name="position">1</property>
                           </packing>
                         </child>
                         <child>
@@ -1555,7 +1575,7 @@ Van Diep Duong (Vietnamese)</property>
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">True</property>
-                            <property name="position">1</property>
+                            <property name="position">2</property>
                           </packing>
                         </child>
                         <child>
@@ -1597,7 +1617,7 @@ Van Diep Duong (Vietnamese)</property>
                           <packing>
                             <property name="expand">True</property>
                             <property name="fill">True</property>
-                            <property name="position">2</property>
+                            <property name="position">3</property>
                           </packing>
                         </child>
                         <child>
@@ -1650,7 +1670,7 @@ Van Diep Duong (Vietnamese)</property>
                             <property name="expand">True</property>
                             <property name="fill">True</property>
                             <property name="padding">6</property>
-                            <property name="position">3</property>
+                            <property name="position">4</property>
                           </packing>
                         </child>
                         <child>
@@ -1665,7 +1685,7 @@ Van Diep Duong (Vietnamese)</property>
                           <packing>
                             <property name="expand">True</property>
                             <property name="fill">True</property>
-                            <property name="position">4</property>
+                            <property name="position">5</property>
                           </packing>
                         </child>
                       </object>
diff --git a/prefdb.cc b/prefdb.cc
index a9e3726..0c924f5 100644
--- a/prefdb.cc
+++ b/prefdb.cc
@@ -51,7 +51,8 @@ PrefDB::PrefDB() :
 	scroll_speed(2.0),
 	tray_feedback(false),
 	show_osd(true),
-	move_back(false)
+	move_back(false),
+	whitelist(false)
 {}
 
 template<class Archive> void PrefDB::serialize(Archive & ar, const unsigned int version) {
@@ -132,6 +133,8 @@ template<class Archive> void PrefDB::serialize(Archive & ar, const unsigned int
 	ar & move_back.unsafe_ref();
 	if (version < 17) return;
 	ar & device_timeout.unsafe_ref();
+	if (version < 18) return;
+	ar & whitelist.unsafe_ref();
 }
 
 void PrefDB::timeout() {
diff --git a/prefdb.h b/prefdb.h
index aaf3f81..4a325f8 100644
--- a/prefdb.h
+++ b/prefdb.h
@@ -132,12 +132,13 @@ public:
 	PrefSource<bool> show_osd;
 	PrefSource<bool> move_back;
 	PrefSource<std::map<std::string, TimeoutType> > device_timeout;
+	PrefSource<bool> whitelist;
 
 	void init();
 	virtual void timeout();
 };
 
-BOOST_CLASS_VERSION(PrefDB, 17)
+BOOST_CLASS_VERSION(PrefDB, 18)
 
 extern PrefDB prefs;
 
diff --git a/prefs.cc b/prefs.cc
index dca328a..efbf091 100644
--- a/prefs.cc
+++ b/prefs.cc
@@ -257,6 +257,7 @@ Prefs::Prefs() {
 	new Adjustment<int>(prefs.trace_width, "adjustment_trace_width");
 	new Combo<TimeoutType>(prefs.timeout_profile, "box_timeout", experimental ? timeout_info_exp : timeout_info);
 
+	new Check(prefs.whitelist, "check_whitelist");
 	new Check(prefs.timeout_gestures, "check_timeout_gestures");
 
 	new Check(prefs.scroll_invert, "check_scroll_invert");