void _ecore_wl_input_add(Ecore_Wl_Display *ewd, unsigned int id) { Ecore_Wl_Input *input; LOGFN(__FILE__, __LINE__, __FUNCTION__); if (!(input = malloc(sizeof(Ecore_Wl_Input)))) return; memset(input, 0, sizeof(Ecore_Wl_Input)); input->display = ewd; input->pointer_focus = NULL; input->keyboard_focus = NULL; input->input_device = wl_display_bind(ewd->wl.display, id, &wl_input_device_interface); wl_list_insert(ewd->inputs.prev, &input->link); wl_input_device_add_listener(input->input_device, &_ecore_wl_input_listener, input); wl_input_device_set_user_data(input->input_device, input); input->data_device = wl_data_device_manager_get_data_device(ewd->wl.data_device_manager, input->input_device); wl_data_device_add_listener(input->data_device, &_ecore_wl_data_listener, input); ewd->input = input; }
PasteboardWayland::PasteboardWayland() { ViewBackend::WaylandDisplay& display = ViewBackend::WaylandDisplay::singleton(); if (!display.interfaces().data_device_manager) return; m_dataDevice = wl_data_device_manager_get_data_device(display.interfaces().data_device_manager, display.interfaces().seat); wl_data_device_add_listener(m_dataDevice, &g_dataDeviceListener, &m_dataDeviceData); }
void Wayland_display_add_input(SDL_VideoData *d, uint32_t id) { struct SDL_WaylandInput *input; SDL_WaylandDataDevice *data_device = NULL; input = SDL_calloc(1, sizeof *input); if (input == NULL) return; input->display = d; input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1); input->sx_w = wl_fixed_from_int(0); input->sy_w = wl_fixed_from_int(0); d->input = input; if (d->data_device_manager != NULL) { data_device = SDL_calloc(1, sizeof *data_device); if (data_device == NULL) { return; } data_device->data_device = wl_data_device_manager_get_data_device( d->data_device_manager, input->seat ); data_device->video_data = d; if (data_device->data_device == NULL) { SDL_free(data_device); } else { wl_data_device_set_user_data(data_device->data_device, data_device); wl_data_device_add_listener(data_device->data_device, &data_device_listener, data_device); input->data_device = data_device; } } wl_seat_add_listener(input->seat, &seat_listener, input); wl_seat_set_user_data(input->seat, input); WAYLAND_wl_display_flush(d->display); }
nsRetrievalContextWayland::nsRetrievalContextWayland(void) : mInitialized(false) , mSeat(nullptr) , mDataDeviceManager(nullptr) , mDataOffer(nullptr) , mKeyboard(nullptr) { const gchar* charset; g_get_charset(&charset); mTextPlainLocale = g_strdup_printf("text/plain;charset=%s", charset); // Available as of GTK 3.8+ static auto sGdkWaylandDisplayGetWlDisplay = (wl_display *(*)(GdkDisplay *)) dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_wl_display"); mDisplay = sGdkWaylandDisplayGetWlDisplay(gdk_display_get_default()); wl_registry_add_listener(wl_display_get_registry(mDisplay), &clipboard_registry_listener, this); // Call wl_display_roundtrip() twice to make sure all // callbacks are processed. wl_display_roundtrip(mDisplay); wl_display_roundtrip(mDisplay); // mSeat/mDataDeviceManager should be set now by // gdk_registry_handle_global() as a response to // wl_registry_add_listener() call. if (!mDataDeviceManager || !mSeat) return; wl_data_device *dataDevice = wl_data_device_manager_get_data_device(mDataDeviceManager, mSeat); wl_data_device_add_listener(dataDevice, &data_device_listener, this); // We have to call wl_display_roundtrip() twice otherwise data_offer_listener // may not be processed because it's called from data_device_data_offer // callback. wl_display_roundtrip(mDisplay); wl_display_roundtrip(mDisplay); mInitialized = true; }
/* local functions */ void _ecore_wl_input_add(Ecore_Wl_Display *ewd, unsigned int id) { Ecore_Wl_Input *input; LOGFN(__FILE__, __LINE__, __FUNCTION__); if (!(input = malloc(sizeof(Ecore_Wl_Input)))) return; memset(input, 0, sizeof(Ecore_Wl_Input)); input->display = ewd; input->pointer_focus = NULL; input->keyboard_focus = NULL; input->touch_focus = NULL; input->seat = wl_registry_bind(ewd->wl.registry, id, &wl_seat_interface, 1); ewd->inputs = eina_inlist_append(ewd->inputs, EINA_INLIST_GET(input)); wl_seat_add_listener(input->seat, &_ecore_wl_seat_listener, input); wl_seat_set_user_data(input->seat, input); wl_array_init(&input->data_types); if (ewd->wl.data_device_manager) { input->data_device = wl_data_device_manager_get_data_device(ewd->wl.data_device_manager, input->seat); wl_data_device_add_listener(input->data_device, &_ecore_wl_data_listener, input); } ewd->input = input; }
int _glfwPlatformInit(void) { const char *cursorTheme; const char *cursorSizeStr; char *cursorSizeEnd; long cursorSizeLong; int cursorSize; _glfw.wl.cursor.handle = _glfw_dlopen("libwayland-cursor.so.0"); if (!_glfw.wl.cursor.handle) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Failed to open libwayland-cursor"); return GLFW_FALSE; } _glfw.wl.cursor.theme_load = (PFN_wl_cursor_theme_load) _glfw_dlsym(_glfw.wl.cursor.handle, "wl_cursor_theme_load"); _glfw.wl.cursor.theme_destroy = (PFN_wl_cursor_theme_destroy) _glfw_dlsym(_glfw.wl.cursor.handle, "wl_cursor_theme_destroy"); _glfw.wl.cursor.theme_get_cursor = (PFN_wl_cursor_theme_get_cursor) _glfw_dlsym(_glfw.wl.cursor.handle, "wl_cursor_theme_get_cursor"); _glfw.wl.cursor.image_get_buffer = (PFN_wl_cursor_image_get_buffer) _glfw_dlsym(_glfw.wl.cursor.handle, "wl_cursor_image_get_buffer"); _glfw.wl.egl.handle = _glfw_dlopen("libwayland-egl.so.1"); if (!_glfw.wl.egl.handle) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Failed to open libwayland-egl"); return GLFW_FALSE; } _glfw.wl.egl.window_create = (PFN_wl_egl_window_create) _glfw_dlsym(_glfw.wl.egl.handle, "wl_egl_window_create"); _glfw.wl.egl.window_destroy = (PFN_wl_egl_window_destroy) _glfw_dlsym(_glfw.wl.egl.handle, "wl_egl_window_destroy"); _glfw.wl.egl.window_resize = (PFN_wl_egl_window_resize) _glfw_dlsym(_glfw.wl.egl.handle, "wl_egl_window_resize"); _glfw.wl.xkb.handle = _glfw_dlopen("libxkbcommon.so.0"); if (!_glfw.wl.xkb.handle) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Failed to open libxkbcommon"); return GLFW_FALSE; } _glfw.wl.xkb.context_new = (PFN_xkb_context_new) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_context_new"); _glfw.wl.xkb.context_unref = (PFN_xkb_context_unref) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_context_unref"); _glfw.wl.xkb.keymap_new_from_string = (PFN_xkb_keymap_new_from_string) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_keymap_new_from_string"); _glfw.wl.xkb.keymap_unref = (PFN_xkb_keymap_unref) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_keymap_unref"); _glfw.wl.xkb.keymap_mod_get_index = (PFN_xkb_keymap_mod_get_index) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_keymap_mod_get_index"); _glfw.wl.xkb.keymap_key_repeats = (PFN_xkb_keymap_key_repeats) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_keymap_key_repeats"); _glfw.wl.xkb.state_new = (PFN_xkb_state_new) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_new"); _glfw.wl.xkb.state_unref = (PFN_xkb_state_unref) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_unref"); _glfw.wl.xkb.state_key_get_syms = (PFN_xkb_state_key_get_syms) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_key_get_syms"); _glfw.wl.xkb.state_update_mask = (PFN_xkb_state_update_mask) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_update_mask"); _glfw.wl.xkb.state_serialize_mods = (PFN_xkb_state_serialize_mods) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_state_serialize_mods"); #ifdef HAVE_XKBCOMMON_COMPOSE_H _glfw.wl.xkb.compose_table_new_from_locale = (PFN_xkb_compose_table_new_from_locale) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_table_new_from_locale"); _glfw.wl.xkb.compose_table_unref = (PFN_xkb_compose_table_unref) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_table_unref"); _glfw.wl.xkb.compose_state_new = (PFN_xkb_compose_state_new) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_state_new"); _glfw.wl.xkb.compose_state_unref = (PFN_xkb_compose_state_unref) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_state_unref"); _glfw.wl.xkb.compose_state_feed = (PFN_xkb_compose_state_feed) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_state_feed"); _glfw.wl.xkb.compose_state_get_status = (PFN_xkb_compose_state_get_status) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_state_get_status"); _glfw.wl.xkb.compose_state_get_one_sym = (PFN_xkb_compose_state_get_one_sym) _glfw_dlsym(_glfw.wl.xkb.handle, "xkb_compose_state_get_one_sym"); #endif _glfw.wl.display = wl_display_connect(NULL); if (!_glfw.wl.display) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Failed to connect to display"); return GLFW_FALSE; } _glfw.wl.registry = wl_display_get_registry(_glfw.wl.display); wl_registry_add_listener(_glfw.wl.registry, ®istryListener, NULL); createKeyTables(); _glfw.wl.xkb.context = xkb_context_new(0); if (!_glfw.wl.xkb.context) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Failed to initialize xkb context"); return GLFW_FALSE; } // Sync so we got all registry objects wl_display_roundtrip(_glfw.wl.display); // Sync so we got all initial output events wl_display_roundtrip(_glfw.wl.display); #ifdef __linux__ if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; #endif _glfwInitTimerPOSIX(); _glfw.wl.timerfd = -1; if (_glfw.wl.seatVersion >= 4) _glfw.wl.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); if (_glfw.wl.pointer && _glfw.wl.shm) { cursorTheme = getenv("XCURSOR_THEME"); cursorSizeStr = getenv("XCURSOR_SIZE"); cursorSize = 32; if (cursorSizeStr) { errno = 0; cursorSizeLong = strtol(cursorSizeStr, &cursorSizeEnd, 10); if (!*cursorSizeEnd && !errno && cursorSizeLong > 0 && cursorSizeLong <= INT_MAX) cursorSize = (int)cursorSizeLong; } _glfw.wl.cursorTheme = wl_cursor_theme_load(cursorTheme, cursorSize, _glfw.wl.shm); if (!_glfw.wl.cursorTheme) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Unable to load default cursor theme"); return GLFW_FALSE; } // If this happens to be NULL, we just fallback to the scale=1 version. _glfw.wl.cursorThemeHiDPI = wl_cursor_theme_load(cursorTheme, 2 * cursorSize, _glfw.wl.shm); _glfw.wl.cursorSurface = wl_compositor_create_surface(_glfw.wl.compositor); _glfw.wl.cursorTimerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); } if (_glfw.wl.seat && _glfw.wl.dataDeviceManager) { _glfw.wl.dataDevice = wl_data_device_manager_get_data_device(_glfw.wl.dataDeviceManager, _glfw.wl.seat); wl_data_device_add_listener(_glfw.wl.dataDevice, &dataDeviceListener, NULL); _glfw.wl.clipboardString = malloc(4096); if (!_glfw.wl.clipboardString) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Unable to allocate clipboard memory"); return GLFW_FALSE; } _glfw.wl.clipboardSize = 4096; } return GLFW_TRUE; }