Beispiel #1
0
static void keyboard_repeat_func(UwacTask *task, uint32_t events)
{
	UwacSeat *input = container_of(task, UwacSeat, repeat_task);
	UwacWindow *window = input->keyboard_focus;
	uint64_t exp;

	if (read(input->repeat_timer_fd, &exp, sizeof exp) != sizeof exp)
		/* If we change the timer between the fd becoming
		 * readable and getting here, there'll be nothing to
		 * read and we get EAGAIN. */
		return;

	if (window) {
		UwacKeyEvent *key;

		key = (UwacKeyEvent *)UwacDisplayNewEvent(input->display, UWAC_EVENT_KEY);
		if (!key)
			return;

		key->window = window;
		key->sym = input->repeat_sym;
		key->pressed = true;
	}

}
Beispiel #2
0
static void keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial,
		struct wl_surface *surface, struct wl_array *keys)
{
	uint32_t *key, *pressedKey;
	UwacSeat *input = (UwacSeat *)data;
	int i, found;
	UwacKeyboardEnterLeaveEvent *event;

	event = (UwacKeyboardEnterLeaveEvent *)UwacDisplayNewEvent(input->display, UWAC_EVENT_KEYBOARD_ENTER);
	if (!event)
		return;

	event->window = input->keyboard_focus = (UwacWindow *)wl_surface_get_user_data(surface);

	/* look for keys that have been released */
	found = false;
	for (pressedKey = input->pressed_keys.data, i = 0; i < input->pressed_keys.size; i += sizeof(uint32_t)) {
		wl_array_for_each(key, keys) {
			if (*key == *pressedKey) {
				found = true;
				break;
			}
		}

		if (!found) {
			keyboard_handle_key(data, keyboard, serial, 0, *pressedKey, WL_KEYBOARD_KEY_STATE_RELEASED);
		} else {
			pressedKey++;
		}
	}

	/* handle keys that are now pressed */
	wl_array_for_each(key, keys) {
		keyboard_handle_key(data, keyboard, serial, 0, *key, WL_KEYBOARD_KEY_STATE_PRESSED);
	}
Beispiel #3
0
static void frame_done_cb(void* data, struct wl_callback* callback, uint32_t time)
{
	UwacWindow* window = (UwacWindow*)data;
	UwacFrameDoneEvent* event;
	window->pendingBuffer = NULL;
	event = (UwacFrameDoneEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_FRAME_DONE);

	if (event)
		event->window = window;
}
Beispiel #4
0
static void xdg_handle_close(void* data, struct xdg_surface* xdg_surface)
{
	UwacCloseEvent* event;
	UwacWindow* window = (UwacWindow*)data;
	event = (UwacCloseEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_CLOSE);

	if (!event)
	{
		assert(uwacErrorHandler(window->display, UWAC_ERROR_INTERNAL,
		                        "failed to allocate a close event\n"));
		return;
	}

	event->window = window;
}
Beispiel #5
0
void shell_configure(void* data, struct wl_shell_surface* surface, uint32_t edges,
                     int32_t width, int32_t height)
{
	UwacWindow* window = (UwacWindow*)data;
	UwacConfigureEvent* event;
	int ret;
	event = (UwacConfigureEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_CONFIGURE);

	if (!event)
	{
		assert(uwacErrorHandler(window->display, UWAC_ERROR_NOMEMORY,
		                        "failed to allocate a configure event\n"));
		return;
	}

	event->window = window;
	event->states = 0;

	if (width && height)
	{
		event->width = width;
		event->height = height;
		UwacWindowDestroyBuffers(window);
		window->width = width;
		window->stride = width * bppFromShmFormat(window->format);
		window->height = height;
		ret = UwacWindowShmAllocBuffers(window, UWAC_INITIAL_BUFFERS, window->stride * height,
		                                width, height, window->format);

		if (ret != UWAC_SUCCESS)
		{
			assert(uwacErrorHandler(window->display, ret, "failed to reallocate a wayland buffers\n"));
			window->drawingBuffer = window->pendingBuffer = NULL;
			return;
		}

		window->drawingBuffer = window->pendingBuffer = &window->buffers[0];
	}
	else
	{
		event->width = window->width;
		event->height = window->height;
	}
}
Beispiel #6
0
static void xdg_handle_configure(void* data, struct xdg_surface* surface,
                                 int32_t width, int32_t height,
                                 struct wl_array* states, uint32_t serial)
{
	UwacWindow* window = (UwacWindow*)data;
	UwacConfigureEvent* event;
	int ret, surfaceState;
	enum xdg_surface_state* state;
	surfaceState = 0;
	wl_array_for_each(state, states)
	{
		switch (*state)
		{
			case XDG_SURFACE_STATE_MAXIMIZED:
				surfaceState |= UWAC_WINDOW_MAXIMIZED;
				break;

			case XDG_SURFACE_STATE_FULLSCREEN:
				surfaceState |= UWAC_WINDOW_FULLSCREEN;
				break;

			case XDG_SURFACE_STATE_ACTIVATED:
				surfaceState |= UWAC_WINDOW_ACTIVATED;
				break;

			case XDG_SURFACE_STATE_RESIZING:
				surfaceState |= UWAC_WINDOW_RESIZING;
				break;

			default:
				break;
		}
	}
	window->surfaceStates = surfaceState;
	event = (UwacConfigureEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_CONFIGURE);

	if (!event)
	{
		assert(uwacErrorHandler(window->display, UWAC_ERROR_NOMEMORY,
		                        "failed to allocate a configure event\n"));
		goto ack;
	}

	event->window = window;
	event->states = surfaceState;

	if (width && height)
	{
		event->width = width;
		event->height = height;
		UwacWindowDestroyBuffers(window);
		window->width = width;
		window->stride = width * bppFromShmFormat(window->format);
		window->height = height;
		ret = UwacWindowShmAllocBuffers(window, UWAC_INITIAL_BUFFERS, window->stride * height,
		                                width, height, window->format);

		if (ret != UWAC_SUCCESS)
		{
			assert(uwacErrorHandler(window->display, ret, "failed to reallocate a wayland buffers\n"));
			window->drawingBuffer = window->pendingBuffer = NULL;
			goto ack;
		}

		window->drawingBuffer = window->pendingBuffer = &window->buffers[0];
	}
	else
	{
		event->width = window->width;
		event->height = window->height;
	}

ack:
	xdg_surface_ack_configure(surface, serial);
}