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);
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));
}
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));
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_;
Pointer* pointer = static_cast<Pointer*>(data);
ASSERT(wl_pointer == *pointer);
+ std::cout << "Pointer::button(): " << button << " "
+ << state << std::endl;
+
pointer->button_ = button;
pointer->buttonState_ = state;
}
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);
}
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*);
, 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);
}
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);
FAIL_UNLESS_EQUAL(buffer.stride(), 4*24);
FAIL_UNLESS_EQUAL(buffer.size(), 4*24*13);
}
-
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);
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;
Input input;
};
+#include <linux/input.h>
+
TEST(SurfacePointer, "Core/Input")
{
Client client(120, 75);
}
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);
}
<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">
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
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);
}