From 591be993dcebf28f2848ab8047e0080e12e25c74 Mon Sep 17 00:00:00 2001 From: "U. Artie Eoff" Date: Wed, 30 Jan 2013 07:41:18 -0800 Subject: [PATCH] core,ext: button press support and test Signed-off-by: U. Artie Eoff --- src/core/display.cpp | 7 +++++-- src/core/display.h | 5 +++-- src/core/pointer.cpp | 6 ++++++ src/core/pointer.h | 2 ++ src/core/shm.cpp | 19 ++++++++++++----- src/core/surface.cpp | 3 +++ src/core/test_surface.cpp | 35 ++++++++++++++++++++++++++++++++ src/extensions/protocol/wayland-fits.xml | 4 ++++ src/extensions/weston/weston-wfits.c | 24 ++++++++++++++++++++++ 9 files changed, 96 insertions(+), 9 deletions(-) diff --git a/src/core/display.cpp b/src/core/display.cpp index 68cbb06..b78a047 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -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)); } diff --git a/src/core/display.h b/src/core/display.h index c36de45..4a98dfa 100644 --- a/src/core/display.h +++ b/src/core/display.h @@ -17,7 +17,7 @@ public: template 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_; diff --git a/src/core/pointer.cpp b/src/core/pointer.cpp index b8085ab..a3cd3da 100644 --- a/src/core/pointer.cpp +++ b/src/core/pointer.cpp @@ -87,6 +87,9 @@ bool Pointer::hasFocus(const Surface* surface) Pointer* pointer = static_cast(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(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); } diff --git a/src/core/pointer.h b/src/core/pointer.h index 998aeec..4019d65 100644 --- a/src/core/pointer.h +++ b/src/core/pointer.h @@ -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*); diff --git a/src/core/shm.cpp b/src/core/shm.cpp index 5268b5a..395ad82 100644 --- a/src/core/shm.cpp +++ b/src/core/shm.cpp @@ -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); } - diff --git a/src/core/surface.cpp b/src/core/surface.cpp index b7f78d8..5d350d9 100644 --- a/src/core/surface.cpp +++ b/src/core/surface.cpp @@ -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); diff --git a/src/core/test_surface.cpp b/src/core/test_surface.cpp index 98fb363..a9bb302 100644 --- a/src/core/test_surface.cpp +++ b/src/core/test_surface.cpp @@ -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 + 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); } diff --git a/src/extensions/protocol/wayland-fits.xml b/src/extensions/protocol/wayland-fits.xml index f884fcb..4adbe34 100644 --- a/src/extensions/protocol/wayland-fits.xml +++ b/src/extensions/protocol/wayland-fits.xml @@ -31,6 +31,10 @@ + + + + diff --git a/src/extensions/weston/weston-wfits.c b/src/extensions/weston/weston-wfits.c index 806de06..645eb45 100644 --- a/src/extensions/weston/weston-wfits.c +++ b/src/extensions/weston/weston-wfits.c @@ -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); } -- 2.7.4