← easystroke

Don't use keycodes internally

17bd36c275db2e4a70e0323ae3e5f74f4bda3c72 · Thomas Jaeger · Dec 9, 2009 12:01

+12 −22 · 4 files changed

  • actiondb.cc +2 −0
  • actiondb.h +4 −7
  • actions.cc +3 −9
  • main.cc +3 −6
diff --git a/actiondb.cc b/actiondb.cc
index ac73f23..7637499 100644
--- a/actiondb.cc
+++ b/actiondb.cc
@@ -56,6 +56,7 @@ template<class Archive> void ModAction::serialize(Archive & ar, const unsigned i
 }
 
 template<class Archive> void SendKey::load(Archive & ar, const unsigned int version) {
+	guint code;
 	ar & boost::serialization::base_object<ModAction>(*this);
 	ar & key;
 	ar & code;
@@ -66,6 +67,7 @@ template<class Archive> void SendKey::load(Archive & ar, const unsigned int vers
 }
 
 template<class Archive> void SendKey::save(Archive & ar, const unsigned int version) const {
+	guint code = 0;
 	ar & boost::serialization::base_object<ModAction>(*this);
 	ar & key;
 	ar & code;
diff --git a/actiondb.h b/actiondb.h
index 7097b34..35a548a 100644
--- a/actiondb.h
+++ b/actiondb.h
@@ -88,18 +88,15 @@ public:
 class SendKey : public ModAction {
 	friend class boost::serialization::access;
 	guint key;
-	guint code;
 	BOOST_SERIALIZATION_SPLIT_MEMBER()
 	template<class Archive> void load(Archive & ar, const unsigned int version);
 	template<class Archive> void save(Archive & ar, const unsigned int version) const;
-	SendKey(guint key_, Gdk::ModifierType mods, guint code_) :
-		ModAction(mods), key(key_), code(code_) {}
-
-	void compute_code();
+	SendKey(guint key_, Gdk::ModifierType mods) :
+		ModAction(mods), key(key_) {}
 public:
 	SendKey() {}
-	static RSendKey create(guint key, Gdk::ModifierType mods, guint code) {
-		return RSendKey(new SendKey(key, mods, code));
+	static RSendKey create(guint key, Gdk::ModifierType mods) {
+		return RSendKey(new SendKey(key, mods));
 	}
 
 	virtual void run();
diff --git a/actions.cc b/actions.cc
index 9e7ff13..d340769 100644
--- a/actions.cc
+++ b/actions.cc
@@ -511,7 +511,7 @@ void Actions::on_type_edited(const Glib::ustring &path, const Glib::ustring &new
 			row[cols.cmd_save] = (Glib::ustring)row[cols.arg];
 		}
 		if (new_type == KEY) {
-			new_action = SendKey::create(0, (Gdk::ModifierType)0, 0);
+			new_action = SendKey::create(0, (Gdk::ModifierType)0);
 			edit = true;
 		}
 		if (new_type == TEXT) {
@@ -930,7 +930,7 @@ void Actions::on_accel_edited(const Glib::ustring& path_string, guint accel_key,
 	Gtk::TreeRow row(*tm->get_iter(path_string));
 	Type type = from_name(row[cols.type]);
 	if (type == KEY) {
-		RSendKey send_key = SendKey::create(accel_key, accel_mods, hardware_keycode);
+		RSendKey send_key = SendKey::create(accel_key, accel_mods);
 		Glib::ustring str = send_key->get_label();
 		if (row[cols.arg] == str)
 			return;
@@ -992,13 +992,7 @@ void Actions::on_arg_editing_started(Gtk::CellEditable* editable, const Glib::us
 }
 
 const Glib::ustring SendKey::get_label() const {
-	Glib::ustring str = Gtk::AccelGroup::get_label(key, mods);
-	if (key == 0) {
-		char buf[10];
-		snprintf(buf, 9, "0x%x", code);
-		str += buf;
-	}
-	return str;
+	return Gtk::AccelGroup::get_label(key, mods);
 }
 
 const Glib::ustring ModAction::get_label() const {
diff --git a/main.cc b/main.cc
index 1abfdab..4073eee 100644
--- a/main.cc
+++ b/main.cc
@@ -1401,16 +1401,13 @@ void Button::run() {
 }
 
 void SendKey::run() {
-	compute_code();
+	if (!key)
+		return;
+	guint code = XKeysymToKeycode(dpy, key);
 	XTestFakeKeyEvent(dpy, code, true, 0);
 	XTestFakeKeyEvent(dpy, code, false, 0);
 }
 
-void SendKey::compute_code() {
-	if (key)
-		code = XKeysymToKeycode(dpy, key);
-}
-
 void fake_unicode(gunichar c) {
 	static const KeySym numcode[10] = { XK_0, XK_1, XK_2, XK_3, XK_4, XK_5, XK_6, XK_7, XK_8, XK_9 };
 	static const KeySym hexcode[6] = { XK_a, XK_b, XK_c, XK_d, XK_e, XK_f };