core,ext: button press support and test
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 30 Jan 2013 15:41:18 +0000 (07:41 -0800)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 30 Jan 2013 15:41:18 +0000 (07:41 -0800)
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
src/core/display.cpp
src/core/display.h
src/core/pointer.cpp
src/core/pointer.h
src/core/shm.cpp
src/core/surface.cpp
src/core/test_surface.cpp
src/extensions/protocol/wayland-fits.xml
src/extensions/weston/weston-wfits.c

index 68cbb06..b78a047 100644 (file)
@@ -9,10 +9,11 @@ Display::Display()
 
        wl_registry_ = wl_display_get_registry(*this);
 
-       wl_display_set_user_data(*this, this);
-       
        ASSERT(wl_registry_ != NULL);
 
+       wl_display_set_user_data(*this, this);
+       wl_registry_set_user_data(*this, this);
+
        static const struct wl_registry_listener listener = {global};
 
        wl_registry_add_listener(wl_registry_, &listener, this);
@@ -60,7 +61,9 @@ TEST(Display, "Core/Wrapper")
        Display display;
 
        FAIL_IF((wl_display*)display == NULL);
+       FAIL_IF((wl_registry*)display == NULL);
        FAIL_UNLESS_EQUAL(wl_display_get_user_data(display), &display);
+       FAIL_UNLESS_EQUAL(wl_registry_get_user_data(display), &display);
 
        ASSERT(not wl_display_get_error(display));
 }
index c36de45..4a98dfa 100644 (file)
@@ -17,7 +17,7 @@ public:
        template <typename T>
        T* bind(
                const std::string& interface,
-               const struct wl_interface *wl_interface) const
+               const wl_interface *wl_interface) const
        {
                const Globals::const_iterator match(globals_.find(interface));
 
@@ -34,10 +34,11 @@ public:
        void yield(const unsigned = 0.001 * 1e6) const;
 
        operator wl_display*() const { return wl_display_; }
+       operator wl_registry*() const { return wl_registry_; }
 
 private:
        static void global(
-               void*, struct wl_registry*, uint32_t, const char*, uint32_t);
+               void*, wl_registry*, uint32_t, const char*, uint32_t);
 
        wl_display      *wl_display_;
        wl_registry     *wl_registry_;
index b8085ab..a3cd3da 100644 (file)
@@ -87,6 +87,9 @@ bool Pointer::hasFocus(const Surface* surface)
        Pointer* pointer = static_cast<Pointer*>(data);
        ASSERT(wl_pointer == *pointer);
 
+       std::cout << "Pointer::button(): " << button << " "
+               << state << std::endl;
+
        pointer->button_ = button;
        pointer->buttonState_ = state;
 }
@@ -98,6 +101,9 @@ bool Pointer::hasFocus(const Surface* surface)
        Pointer* pointer = static_cast<Pointer*>(data);
        ASSERT(wl_pointer == *pointer);
 
+       std::cout << "Pointer::axis(): " << axis << " "
+               << wl_fixed_to_double(value) << std::endl;
+
        pointer->axis_ = axis;
        pointer->axisValue_ = wl_fixed_to_double(value);
 }
index 998aeec..4019d65 100644 (file)
@@ -16,6 +16,8 @@ public:
        const Seat& seat() const { return seat_; }
        const int32_t x() const { return x_; }
        const int32_t y() const { return y_; }
+       const uint32_t button() const { return button_; }
+       const uint32_t buttonState() const { return buttonState_; }
        const Surface* focus() const { return focus_; }
 
        bool hasFocus(const Surface*);
index 5268b5a..395ad82 100644 (file)
@@ -44,7 +44,7 @@ SharedMemoryBuffer::SharedMemoryBuffer(const SharedMemory& shm, int width, int h
        , stride_(width_ * 4)
        , size_(stride_ * height_)
 {
-       wl_shm_pool *pool;
+       wl_shm_pool *pool(NULL);
        char tmp[] = "/tmp/wfits_shm-XXXXXX";
        int fd = mkstemp(tmp);
 
@@ -65,13 +65,23 @@ SharedMemoryBuffer::SharedMemoryBuffer(const SharedMemory& shm, int width, int h
        }
 
        pool = wl_shm_create_pool(shm_, fd, size_);
+       if (not pool) {
+               close(fd);
+               ASSERT(pool != NULL);
+       }
 
-       ASSERT(pool != NULL);
+       wl_shm_pool_set_user_data(pool, this);
+       if (wl_shm_pool_get_user_data(pool) != this) {
+               close(fd);
+               ASSERT(wl_shm_pool_get_user_data(pool) == this);
+       }
 
        wl_buffer_ = wl_shm_pool_create_buffer(
                pool, 0, width_, height_, stride_, WL_SHM_FORMAT_ARGB8888);
-
-       ASSERT(wl_buffer_ != NULL);
+       if (not wl_buffer_) {
+               close(fd);
+               ASSERT(wl_buffer_ != NULL);
+       }
 
        wl_shm_pool_destroy(pool);
        close(fd);
@@ -112,4 +122,3 @@ TEST(SharedMemoryBuffer, "Core/Wrapper")
        FAIL_UNLESS_EQUAL(buffer.stride(), 4*24);
        FAIL_UNLESS_EQUAL(buffer.size(), 4*24*13);
 }
-
index b7f78d8..5d350d9 100644 (file)
@@ -35,6 +35,9 @@ void Surface::commit() const
        bool            done(false);
        wl_callback*    callback(wl_surface_frame(*this));
 
+       wl_callback_set_user_data(callback, &done);
+       FAIL_IF(wl_callback_get_user_data(callback) != &done);
+
        wl_callback_add_listener(callback, &doneListener, &done);
        wl_surface_commit(*this);
 
index 98fb363..a9bb302 100644 (file)
@@ -56,6 +56,18 @@ public:
                FAIL_UNLESS_EQUAL(pointer.y(), y);
        }
 
+       void checkButton(uint32_t button, uint32_t state)
+       {
+               display.yield();
+               for (unsigned i(0);
+                    i < 20 && (pointer.button() != button
+                    || pointer.buttonState() != state); ++i) {
+                       display.yield(i*0.001*1e6);
+               }
+               FAIL_UNLESS_EQUAL(pointer.button(), button);
+               FAIL_UNLESS_EQUAL(pointer.buttonState(), state);
+       }
+
        Display display;
        Compositor compositor;
        Shell shell;
@@ -69,6 +81,8 @@ public:
        Input input;
 };
 
+#include <linux/input.h>
+
 TEST(SurfacePointer, "Core/Input")
 {
        Client client(120, 75);
@@ -82,4 +96,25 @@ TEST(SurfacePointer, "Core/Input")
        }
        client.movePointer(-1, -1);
        client.checkFocus(false);
+
+       client.movePointer(5, 5);
+       client.checkFocus(true);
+       
+       wfits_input_key_press(client.input, BTN_LEFT, 1);
+       client.checkButton(BTN_LEFT, 1);
+
+       wfits_input_key_press(client.input, BTN_LEFT, 0);
+       client.checkButton(BTN_LEFT, 0);
+
+       wfits_input_key_press(client.input, BTN_RIGHT, 1);
+       client.checkButton(BTN_RIGHT, 1);
+
+       wfits_input_key_press(client.input, BTN_RIGHT, 0);
+       client.checkButton(BTN_RIGHT, 0);
+
+       wfits_input_key_press(client.input, BTN_MIDDLE, 1);
+       client.checkButton(BTN_MIDDLE, 1);
+
+       wfits_input_key_press(client.input, BTN_MIDDLE, 0);
+       client.checkButton(BTN_MIDDLE, 0);
 }
index f884fcb..4adbe34 100644 (file)
       <arg name="x" type="int"/>
       <arg name="y" type="int"/>
     </request>
+    <request name="key_press">
+      <arg name="key" type="uint"/>
+      <arg name="state" type="uint"/>
+    </request>
   </interface>
   <interface name="wfits_query" version="1">
     <request name="surface_geometry">
index 806de06..645eb45 100644 (file)
@@ -176,9 +176,29 @@ input_move_pointer(struct wl_client *client, struct wl_resource *resource,
        event.value = 0;
        write(wfits->pointer_fd, &event, sizeof(event));
 }
+static void
+input_key_press(struct wl_client *client, struct wl_resource *resource,
+                 int32_t key, uint32_t state)
+{
+       struct wfits *wfits = resource->data;
+       struct input_event event;
+
+       memset(&event, 0, sizeof(event));
+
+       event.type = EV_KEY;
+       event.code = key;
+       event.value = state;
+       write(wfits->pointer_fd, &event, sizeof(event));
+
+       event.type = EV_SYN;
+       event.code = SYN_REPORT;
+       event.value = 0;
+       write(wfits->pointer_fd, &event, sizeof(event));
+}
 
 static const struct wfits_input_interface wfits_input_implementation = {
        input_move_pointer,
+       input_key_press,
 };
 
 static void
@@ -219,6 +239,10 @@ create_pointer(struct wfits* wfits)
                exit(EXIT_FAILURE);
        }
 
+       if (ioctl(wfits->pointer_fd, UI_SET_KEYBIT, BTN_MIDDLE) < 0) {
+               exit(EXIT_FAILURE);
+       }
+
        if (ioctl(wfits->pointer_fd, UI_SET_EVBIT, EV_ABS) < 0) {
                exit(EXIT_FAILURE);
        }