]> git.tdb.fi Git - libs/gui.git/commitdiff
Add an availability check to Touchscreen
authorMikko Rasa <tdb@tdb.fi>
Fri, 19 Dec 2014 12:05:07 +0000 (14:05 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 19 Dec 2014 12:05:07 +0000 (14:05 +0200)
source/input/android/touchscreen.cpp
source/input/generic/touchscreen.cpp
source/input/touchscreen.cpp
source/input/touchscreen.h
source/input/windows/touchscreen.cpp

index f4703c340b8d5cca4fc9164a16a57d0474b01726..6472f4476b973d2b813f6404af8e787f3d7e14e1 100644 (file)
@@ -4,6 +4,11 @@
 namespace Msp {
 namespace Input {
 
+bool Touchscreen::is_available()
+{
+       return true;
+}
+
 void Touchscreen::input_event(const Graphics::Window::Event &event)
 {
        int action = AMotionEvent_getAction(event.aevent);
index bfbf7aaa8181c78aa73373fddf56de71b989f374..aff6b8227d0a64cdf031160cb177ce639ec5a8b8 100644 (file)
@@ -3,6 +3,11 @@
 namespace Msp {
 namespace Input {
 
+bool Touchscreen::is_available()
+{
+       return false;
+}
+
 void Touchscreen::input_event(const Graphics::Window::Event &)
 {
 }
index 18e795fe83a91da20451ef42e85a17423cc2373c..4facb8c60e44f9b662c636a225946923245497dc 100644 (file)
@@ -8,6 +8,9 @@ namespace Input {
 Touchscreen::Touchscreen(Graphics::Window &w):
        window(w)
 {
+       if(!is_available())
+               throw runtime_error("touchscreen not available");
+
        name = "Touchscreen";
 
        window.set_touch_input(true);
index 99432d22309a2e889e8910793dc4c461c133fca5..0c964068db266d6831d69a643bbb7f1eee681781 100644 (file)
@@ -23,6 +23,8 @@ public:
        Touchscreen(Graphics::Window &);
        ~Touchscreen();
 
+       static bool is_available();
+
        Graphics::Window &get_window() const { return window; }
 
        virtual std::string get_button_name(unsigned) const;
index 180f1c04f568816bb9fc8de1ce7ed383c156173e..7e314ca98d39f99ab4eb2cdbc5d1942292ae7d08 100644 (file)
@@ -8,6 +8,28 @@ using namespace std;
 namespace Msp {
 namespace Input {
 
+bool Touchscreen::is_available()
+{
+       // Must have at least Windows 7 (WinNT 6.1) for WM_TOUCHMOVE
+       OSVERSIONINFOEX version;
+       version.dwOSVersionInfoSize = sizeof(version);
+       version.dwMajorVersion = 6;
+       version.dwMinorVersion = 1;
+       version.dwServicePackMajor = 0;
+       version.dwServicePackMinor = 0;
+       DWORD mask = VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR;
+       DWORDLONG cond = VerSetConditionMask(0, mask, VER_GREATER_EQUAL);
+       if(!VerifyVersionInfo(&version, type, cond))
+               return false;
+
+       if(!GetSystemMetrics(SM_TABLETPC))
+               return false;
+       if(!(GetSystemMetrics(SM_DIGITIZER)&NID_READY))
+               return false;
+
+       return true;
+}
+
 void Touchscreen::input_event(const Graphics::Window::Event &event)
 {
        if(event.msg==WM_TOUCHMOVE)