<commit_before>#define _XOPEN_SOURCE 500
#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <wayland-client.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/interfaces/wlr_touch.h>
#include <wlr/util/log.h>
#include "backend/wayland.h"

static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
		uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x,
		wl_fixed_t surface_y) {
	struct wlr_input_device *dev = data;
	assert(dev && dev->pointer && dev->pointer->state);
	struct wlr_output* output = wlr_wl_output_for_surface(dev->state->backend,
			surface);

	if (!output) {
		wlr_log(L_ERROR, "pointer entered invalid surface");
		return;
	}

	dev->pointer->state->current_output = output;
}

static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
		uint32_t serial, struct wl_surface *surface) {

}

static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
		uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
	struct wlr_input_device *dev = data;
	assert(dev && dev->pointer && dev->pointer->state);
	struct wlr_pointer_state *state = dev->pointer->state;
	assert(state->current_output);

	int width, height;
	wl_egl_window_get_attached_size(state->current_output->state->egl_window,
		&width, &height);

	struct wlr_event_pointer_motion_absolute wlr_event;
	wlr_event.time_sec = time / 1000;
	wlr_event.time_usec = time * 1000;
	wlr_event.width_mm = width;
	wlr_event.height_mm = height;
	wlr_event.x_mm = wl_fixed_to_double(surface_x);
	wlr_event.y_mm = wl_fixed_to_double(surface_y);
	wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event);<commit_msg>Improve wayland backend pointer error logging<commit_after>#define _XOPEN_SOURCE 500
#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <wayland-client.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/interfaces/wlr_touch.h>
#include <wlr/util/log.h>
#include "backend/wayland.h"

static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
		uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x,
		wl_fixed_t surface_y) {
	struct wlr_input_device *dev = data;
	assert(dev && dev->pointer && dev->pointer->state);
	struct wlr_output* output = wlr_wl_output_for_surface(dev->state->backend,
			surface);

	if (!output) {
		wlr_log(L_ERROR, "pointer entered invalid surface");
		return;
	}

	dev->pointer->state->current_output = output;
}

static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
		uint32_t serial, struct wl_surface *surface) {
	struct wlr_input_device *dev = data;
	assert(dev && dev->pointer && dev->pointer->state);
	dev->pointer->state->current_output = NULL;
}

static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
		uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
	struct wlr_input_device *dev = data;
	assert(dev && dev->pointer && dev->pointer->state);
	struct wlr_pointer_state *state = dev->pointer->state;

	if(!state->current_output) {
		wlr_log(L_ERROR, "pointer motion event without current output");
		return;
	}

	int width, height;
	wl_egl_window_get_attached_size(state->current_output->state->egl_window,
		&width, &height);

	struct wlr_event_pointer_motion_absolute wlr_event;
	wlr_event.time_sec = time / 1000;
	wlr_event.time_usec = time * 1000;
	wlr_event.width_mm = width;
	wlr_event.height_mm = height;
	wlr_event.x_mm = wl_fixed_to_double(surface_x);
	wlr_event.y_mm = wl_fixed_to_double(surface_y);
	wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event);
{'fraction_non_alphanumeric': 0.12268518518518519, 'fraction_numerical': 0.00874485596707819, 'mean_word_length': 6.215213358070501, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3678752', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1453, 'n_words': 275}