[PATCH wfits] weston-wfits: Allow user to configure the input emulator

U. Artie Eoff ullysses.a.eoff at intel.com
Mon Jun 3 22:37:55 PDT 2013


From: "U. Artie Eoff" <ullysses.a.eoff at intel.com>

The available emulators are "uinput" and "notify".  To choose
which emulator to use, define the environment variable:

WESTON_WFITS_INPUT_EMULATOR

equal to the name of the desired emulator before loading the
weston-wfits.so module into Weston.

For example:

 $ export WESTON_WFITS_INPUT_EMULATOR="notify"
 $ weston --modules=weston-wfits.so

If WESTON_WFITS_INPUT_EMULATOR is not defined in the environment
and Weston is using the headless-backend then weston-wfits.so will
choose "notify" by default.  Otherwise, it chooses "uinput" by
default.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff at intel.com>
---
 src/extensions/weston/Makefile.am               |  1 +
 src/extensions/weston/input-emulator-notify.cpp |  2 +
 src/extensions/weston/input-emulator-notify.h   |  3 ++
 src/extensions/weston/input-emulator-uinput.cpp | 14 +++++--
 src/extensions/weston/input-emulator-uinput.h   |  2 +
 src/extensions/weston/input-emulator.cpp        | 50 +++++++++++++++++++++++++
 src/extensions/weston/input-emulator.h          | 25 +++++++++++++
 src/extensions/weston/weston-wfits-input.cpp    | 31 +++++++--------
 src/extensions/weston/weston-wfits.cpp          | 10 +++++
 9 files changed, 120 insertions(+), 18 deletions(-)
 create mode 100644 src/extensions/weston/input-emulator.cpp

diff --git a/src/extensions/weston/Makefile.am b/src/extensions/weston/Makefile.am
index a5447d3..9c13376 100644
--- a/src/extensions/weston/Makefile.am
+++ b/src/extensions/weston/Makefile.am
@@ -20,6 +20,7 @@ weston_wfits_la_SOURCES =						\
 	weston-wfits-init.cpp						\
 	weston-wfits-query.cpp						\
 	weston-wfits-input.cpp						\
+	input-emulator.cpp						\
 	input-emulator-uinput.cpp					\
 	input-emulator-notify.cpp					\
 	$(top_srcdir)/src/extensions/protocol/wayland-fits-protocol.c
diff --git a/src/extensions/weston/input-emulator-notify.cpp b/src/extensions/weston/input-emulator-notify.cpp
index daf9b43..24920ad 100644
--- a/src/extensions/weston/input-emulator-notify.cpp
+++ b/src/extensions/weston/input-emulator-notify.cpp
@@ -30,6 +30,8 @@
 namespace wfits {
 namespace weston {
 
+/*static*/ bool InputEmulatorNotify::registered_ = InputEmulatorFactory::registerEmulator("notify", Create<InputEmulatorNotify>());
+
 InputEmulatorNotify::InputEmulatorNotify()
 	: InputEmulator::InputEmulator()
 {
diff --git a/src/extensions/weston/input-emulator-notify.h b/src/extensions/weston/input-emulator-notify.h
index d23eaac..4b13c3b 100644
--- a/src/extensions/weston/input-emulator-notify.h
+++ b/src/extensions/weston/input-emulator-notify.h
@@ -36,6 +36,9 @@ public:
 
 	/*virtual*/ void movePointer(const int32_t x, const int32_t y) const;
 	/*virtual*/ void keySend(const uint32_t key, const uint32_t state) const;
+
+private:
+	static bool registered_;
 };
 
 } // namespace weston
diff --git a/src/extensions/weston/input-emulator-uinput.cpp b/src/extensions/weston/input-emulator-uinput.cpp
index e6bf591..b850411 100644
--- a/src/extensions/weston/input-emulator-uinput.cpp
+++ b/src/extensions/weston/input-emulator-uinput.cpp
@@ -56,6 +56,8 @@ struct x11_output {
 namespace wfits {
 namespace weston {
 
+/*static*/ bool InputEmulatorUInput::registered_ = InputEmulatorFactory::registerEmulator("uinput", Create<InputEmulatorUInput>());
+
 /**
  * Get the width and height (size) of the current display output.  If Weston is
  * using the x11 backend then the result is the size of the X screen.
@@ -127,10 +129,10 @@ InputEmulatorUInput::InputEmulatorUInput()
 	, fd_(-1)
 {
 	struct uinput_user_dev device;
-	struct weston_output *output(Globals::output());
-	int32_t width, height;
 
-	weston_log("weston-wfits: creating uinput device\n");
+	weston_log("weston-wfits: %s\n", BOOST_CURRENT_FUNCTION);
+
+	assert(not Globals::isHeadless());
 
 	fd_ = open("/dev/uinput", O_WRONLY | O_NDELAY);
 	if (fd_ < 0) {
@@ -182,6 +184,7 @@ InputEmulatorUInput::InputEmulatorUInput()
 	/*
 	* TODO: Need to handle multidisplay, eventually.
 	*/
+	int32_t width, height;
 	screenSize(&width, &height);
 	device.absmin[ABS_X] = 0;
 	device.absmax[ABS_X] = width - 1;
@@ -195,6 +198,11 @@ InputEmulatorUInput::InputEmulatorUInput()
 	if (ioctl(fd_, UI_DEV_CREATE) < 0) {
 		exit(EXIT_FAILURE);
 	}
+
+	/* sync our input pointer device with weston */
+	wl_fixed_t cx, cy;
+	Globals::pointerXY(&cx, &cy);
+	movePointer(wl_fixed_to_int(cx), wl_fixed_to_int(cy));
 }
 
 /*virtual*/
diff --git a/src/extensions/weston/input-emulator-uinput.h b/src/extensions/weston/input-emulator-uinput.h
index 2d34ab6..75a78e0 100644
--- a/src/extensions/weston/input-emulator-uinput.h
+++ b/src/extensions/weston/input-emulator-uinput.h
@@ -41,6 +41,8 @@ private:
 	void writeEvent(struct input_event *event) const;
 
 	int fd_;
+
+	static bool registered_;
 };
 
 } // namespace weston
diff --git a/src/extensions/weston/input-emulator.cpp b/src/extensions/weston/input-emulator.cpp
new file mode 100644
index 0000000..8af3c45
--- /dev/null
+++ b/src/extensions/weston/input-emulator.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "input-emulator.h"
+
+namespace wfits {
+namespace weston {
+
+/*static*/ InputEmulatorFactory::Creators InputEmulatorFactory::creators_;
+
+/*static*/ bool InputEmulatorFactory::registerEmulator(const std::string& name, Creator creator)
+{
+	std::pair<Creators::iterator, bool> result;
+	result = creators_.insert(std::make_pair(name, creator));
+	return result.second;
+}
+
+/*static*/ InputEmulator* InputEmulatorFactory::create(const std::string& name)
+{
+	const Creators::const_iterator creator(creators_.find(name));
+	if (creator == creators_.end())
+	{
+		weston_log("weston-wfits: warning, no input emulator named '%s' found\n", name.c_str());
+		return NULL;
+	}
+
+	return creator->second();
+}
+
+} // namespace weston
+} // namespace wfits
diff --git a/src/extensions/weston/input-emulator.h b/src/extensions/weston/input-emulator.h
index 5974f83..8ad9e2d 100644
--- a/src/extensions/weston/input-emulator.h
+++ b/src/extensions/weston/input-emulator.h
@@ -23,6 +23,8 @@
 #ifndef __INPUT_EMULATOR_H__
 #define __INPUT_EMULATOR_H__
 
+#include <map>
+#include "common/util.h"
 #include "weston-wfits.h"
 
 namespace wfits {
@@ -45,6 +47,29 @@ public:
 	virtual void keySend(const uint32_t key, const uint32_t state) const = 0;
 };
 
+class InputEmulatorFactory
+{
+public:
+	typedef boost::function<InputEmulator* (void)> Creator;
+	typedef std::map<std::string, Creator> Creators;
+
+	static bool registerEmulator(const std::string&, Creator);
+	static InputEmulator* create(const std::string&);
+
+private:
+	static Creators creators_;
+};
+
+template <class T>
+class Create
+{
+public:
+	T* operator()()
+	{
+		return new T;
+	}
+};
+
 } // namespace weston
 } // namespace wfits
 
diff --git a/src/extensions/weston/weston-wfits-input.cpp b/src/extensions/weston/weston-wfits-input.cpp
index c921709..90e7de0 100644
--- a/src/extensions/weston/weston-wfits-input.cpp
+++ b/src/extensions/weston/weston-wfits-input.cpp
@@ -22,9 +22,6 @@
 
 #include "common/util.h"
 #include "input-emulator.h"
-#include "input-emulator-uinput.h"
-#include "input-emulator-notify.h"
-
 #include "weston-wfits-input.h"
 
 namespace wfits {
@@ -96,20 +93,24 @@ void InputInterface::unbind(struct wl_resource *resource)
 /*static*/
 void InputInterface::initEmulator(void *data)
 {
-	if (not Globals::isHeadless()) {
-		emulator_ = new InputEmulatorUInput();
+	const char* emu(getenv("WESTON_WFITS_INPUT_EMULATOR"));
+	std::string stremu;
+
+	if (not emu) {
+		if (Globals::isHeadless()) {
+			stremu = "notify";
+		}
+		else {
+			stremu = "uinput";
+		}
+	}
+	else {
+		stremu = std::string(emu);
+	}
 
-		/* sync our input pointer device with weston */
-		wl_fixed_t cx, cy;
-		Globals::pointerXY(&cx, &cy);
-		InputInterface::movePointer(wl_fixed_to_int(cx), wl_fixed_to_int(cy));
-	} else {
-		emulator_ = new InputEmulatorNotify();
+	emulator_ = InputEmulatorFactory::create(stremu);
 
-		struct weston_seat *seat(Globals::seat());
-		weston_seat_init_pointer(seat);
-		weston_seat_init_keyboard(seat, NULL);
-	}
+	assert(emulator_);
 }
 
 void InputInterface::keySend(const uint32_t key, const uint32_t state)
diff --git a/src/extensions/weston/weston-wfits.cpp b/src/extensions/weston/weston-wfits.cpp
index f124e4e..aa4c74a 100644
--- a/src/extensions/weston/weston-wfits.cpp
+++ b/src/extensions/weston/weston-wfits.cpp
@@ -37,6 +37,16 @@ void Globals::init(struct weston_compositor *compositor)
 
 	compositor_ = compositor;
 	initialized_ = true;
+
+	struct weston_seat *seat(Globals::seat());
+
+	if (not seat->pointer) {
+		weston_seat_init_pointer(seat);
+	}
+
+	if (not seat->keyboard) {
+		weston_seat_init_keyboard(seat, NULL);
+	}
 }
 
 /*static*/
-- 
1.7.11.7



More information about the wayland-devel mailing list