Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemWayland.cpp
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
| /* Generated by `wayland-scanner`. */ | /* Generated by `wayland-scanner`. */ | ||||
| #include <pointer-constraints-unstable-v1-client-protocol.h> | #include <pointer-constraints-unstable-v1-client-protocol.h> | ||||
| #include <pointer-gestures-unstable-v1-client-protocol.h> | #include <pointer-gestures-unstable-v1-client-protocol.h> | ||||
| #include <primary-selection-unstable-v1-client-protocol.h> | #include <primary-selection-unstable-v1-client-protocol.h> | ||||
| #include <relative-pointer-unstable-v1-client-protocol.h> | #include <relative-pointer-unstable-v1-client-protocol.h> | ||||
| #include <tablet-unstable-v2-client-protocol.h> | #include <tablet-unstable-v2-client-protocol.h> | ||||
| #include <xdg-output-unstable-v1-client-protocol.h> | #include <xdg-output-unstable-v1-client-protocol.h> | ||||
| #ifdef WITH_INPUT_IME | |||||
| # include <text-input-unstable-v3-client-protocol.h> | |||||
| #endif | |||||
| /* Decorations `xdg_decor`. */ | /* Decorations `xdg_decor`. */ | ||||
| #include <xdg-decoration-unstable-v1-client-protocol.h> | #include <xdg-decoration-unstable-v1-client-protocol.h> | ||||
| #include <xdg-shell-client-protocol.h> | #include <xdg-shell-client-protocol.h> | ||||
| /* End `xdg_decor`. */ | /* End `xdg_decor`. */ | ||||
| #include <fcntl.h> | #include <fcntl.h> | ||||
| #include <sys/mman.h> | #include <sys/mman.h> | ||||
| ▲ Show 20 Lines • Show All 612 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| #ifdef ZWP_POINTER_GESTURE_PINCH_V1_INTERFACE | #ifdef ZWP_POINTER_GESTURE_PINCH_V1_INTERFACE | ||||
| struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch = nullptr; | struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch = nullptr; | ||||
| #endif | #endif | ||||
| #ifdef ZWP_POINTER_GESTURE_SWIPE_V1_INTERFACE | #ifdef ZWP_POINTER_GESTURE_SWIPE_V1_INTERFACE | ||||
| struct zwp_pointer_gesture_swipe_v1 *wp_pointer_gesture_swipe = nullptr; | struct zwp_pointer_gesture_swipe_v1 *wp_pointer_gesture_swipe = nullptr; | ||||
| #endif | #endif | ||||
| #ifdef WITH_INPUT_IME | |||||
| struct zwp_text_input_v3 *wp_text_input = nullptr; | |||||
| #endif | |||||
| /** All currently active tablet tools (needed for changing the cursor). */ | /** All currently active tablet tools (needed for changing the cursor). */ | ||||
| std::unordered_set<zwp_tablet_tool_v2 *> tablet_tools; | std::unordered_set<zwp_tablet_tool_v2 *> tablet_tools; | ||||
| /** Use to check if the last cursor input was tablet or pointer. */ | /** Use to check if the last cursor input was tablet or pointer. */ | ||||
| uint32_t cursor_source_serial = 0; | uint32_t cursor_source_serial = 0; | ||||
| GWL_SeatStatePointer pointer; | GWL_SeatStatePointer pointer; | ||||
| GWL_SeatStatePointerScroll pointer_scroll; | GWL_SeatStatePointerScroll pointer_scroll; | ||||
| ▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | #endif | ||||
| * a widely used feature. | * a widely used feature. | ||||
| */ | */ | ||||
| int seats_active_index = 0; | int seats_active_index = 0; | ||||
| /* Managers. */ | /* Managers. */ | ||||
| struct wl_data_device_manager *wl_data_device_manager = nullptr; | struct wl_data_device_manager *wl_data_device_manager = nullptr; | ||||
| struct zwp_tablet_manager_v2 *wp_tablet_manager = nullptr; | struct zwp_tablet_manager_v2 *wp_tablet_manager = nullptr; | ||||
| struct zwp_relative_pointer_manager_v1 *wp_relative_pointer_manager = nullptr; | struct zwp_relative_pointer_manager_v1 *wp_relative_pointer_manager = nullptr; | ||||
| #ifdef WITH_INPUT_IME | |||||
| struct zwp_text_input_manager_v3 *wp_text_input_manager = nullptr; | |||||
| #endif | |||||
| struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_device_manager = nullptr; | struct zwp_primary_selection_device_manager_v1 *wp_primary_selection_device_manager = nullptr; | ||||
| struct zwp_pointer_constraints_v1 *wp_pointer_constraints = nullptr; | struct zwp_pointer_constraints_v1 *wp_pointer_constraints = nullptr; | ||||
| struct zwp_pointer_gestures_v1 *wp_pointer_gestures = nullptr; | struct zwp_pointer_gestures_v1 *wp_pointer_gestures = nullptr; | ||||
| /* Threaded event handling. */ | /* Threaded event handling. */ | ||||
| #ifdef USE_EVENT_BACKGROUND_THREAD | #ifdef USE_EVENT_BACKGROUND_THREAD | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 3,127 Lines • ▼ Show 20 Lines | static const struct wl_keyboard_listener keyboard_listener = { | ||||
| keyboard_repeat_handle_info, | keyboard_repeat_handle_info, | ||||
| }; | }; | ||||
| #undef LOG | #undef LOG | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Listener (Text Input), #zwp_text_input_manager_v3 | |||||
| * \{ */ | |||||
| #ifdef WITH_INPUT_IME | |||||
| static CLG_LogRef LOG_WL_TEXT_INPUT = {"ghost.wl.handle.text_input"}; | |||||
| # define LOG (&LOG_WL_TEXT_INPUT) | |||||
| static void text_input_handle_enter(void * /*data*/, | |||||
| struct zwp_text_input_v3 * /*zwp_text_input_v3*/, | |||||
| struct wl_surface * /*surface*/) | |||||
| { | |||||
| CLOG_INFO(LOG, 2, "enter"); | |||||
| } | |||||
| static void text_input_handle_leave(void * /*data*/, | |||||
| struct zwp_text_input_v3 * /*zwp_text_input_v3*/, | |||||
| struct wl_surface * /*surface*/) | |||||
| { | |||||
| CLOG_INFO(LOG, 2, "leave"); | |||||
| } | |||||
| static void text_input_handle_preedit_string(void * /*data*/, | |||||
| struct zwp_text_input_v3 * /*zwp_text_input_v3*/, | |||||
| const char *text, | |||||
| int32_t cursor_begin, | |||||
| int32_t cursor_end) | |||||
| { | |||||
| CLOG_INFO(LOG, | |||||
| 2, | |||||
| "preedit_string (text=\"%s\", cursor_begin=%d, cursor_end=%d)", | |||||
| text, | |||||
| cursor_begin, | |||||
| cursor_end); | |||||
| } | |||||
| static void text_input_handle_commit_string(void * /*data*/, | |||||
| struct zwp_text_input_v3 * /*zwp_text_input_v3*/, | |||||
| const char *text) | |||||
| { | |||||
| CLOG_INFO(LOG, 2, "commit_string (text=\"%s\")", text); | |||||
| } | |||||
| static void text_input_handle_delete_surrounding_text( | |||||
| void * /*data*/, | |||||
| struct zwp_text_input_v3 * /*zwp_text_input_v3*/, | |||||
| uint32_t before_length, | |||||
| uint32_t after_length) | |||||
| { | |||||
| /* NOTE: Currently unused, do we care about this event? */ | |||||
| CLOG_INFO(LOG, | |||||
| 2, | |||||
| "delete_surrounding_text (before_length=%u, after_length=%u)", | |||||
| before_length, | |||||
| after_length); | |||||
| } | |||||
| static void text_input_handle_done(void * /*data*/, | |||||
| struct zwp_text_input_v3 * /*zwp_text_input_v3*/, | |||||
| uint32_t /*serial*/) | |||||
| { | |||||
| CLOG_INFO(LOG, 2, "done"); | |||||
| } | |||||
| static struct zwp_text_input_v3_listener text_input_listener = { | |||||
| text_input_handle_enter, | |||||
| text_input_handle_leave, | |||||
| text_input_handle_preedit_string, | |||||
| text_input_handle_commit_string, | |||||
| text_input_handle_delete_surrounding_text, | |||||
| text_input_handle_done, | |||||
| }; | |||||
| # undef LOG | |||||
| #endif /* WITH_INPUT_IME. */ | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Listener (Primary Selection Offer), #zwp_primary_selection_offer_v1_listener | /** \name Listener (Primary Selection Offer), #zwp_primary_selection_offer_v1_listener | ||||
| * \{ */ | * \{ */ | ||||
| static CLG_LogRef LOG_WL_PRIMARY_SELECTION_OFFER = {"ghost.wl.handle.primary_selection_offer"}; | static CLG_LogRef LOG_WL_PRIMARY_SELECTION_OFFER = {"ghost.wl.handle.primary_selection_offer"}; | ||||
| #define LOG (&LOG_WL_PRIMARY_SELECTION_OFFER) | #define LOG (&LOG_WL_PRIMARY_SELECTION_OFFER) | ||||
| static void primary_selection_offer_offer(void *data, | static void primary_selection_offer_offer(void *data, | ||||
| struct zwp_primary_selection_offer_v1 *id, | struct zwp_primary_selection_offer_v1 *id, | ||||
| ▲ Show 20 Lines • Show All 774 Lines • ▼ Show 20 Lines | if (seat->wp_tablet_seat == nullptr) { | ||||
| seat->wl_seat); | seat->wl_seat); | ||||
| zwp_tablet_seat_v2_add_listener(seat->wp_tablet_seat, &tablet_seat_listener, seat); | zwp_tablet_seat_v2_add_listener(seat->wp_tablet_seat, &tablet_seat_listener, seat); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| seat->wp_tablet_seat = nullptr; | seat->wp_tablet_seat = nullptr; | ||||
| } | } | ||||
| #ifdef WITH_INPUT_IME | |||||
| if (display->wp_text_input_manager) { | |||||
| if (seat->wp_text_input == nullptr) { | |||||
| seat->wp_text_input = zwp_text_input_manager_v3_get_text_input( | |||||
| display->wp_text_input_manager, seat->wl_seat); | |||||
| zwp_text_input_v3_set_user_data(seat->wp_text_input, seat); | |||||
| zwp_text_input_v3_add_listener(seat->wp_text_input, &text_input_listener, seat); | |||||
| } | |||||
| } | |||||
| else { | |||||
| seat->wp_text_input = nullptr; | |||||
| } | |||||
| #endif /* WITH_INPUT_IME */ | |||||
| if (display->wp_primary_selection_device_manager) { | if (display->wp_primary_selection_device_manager) { | ||||
| if (seat->wp_primary_selection_device == nullptr) { | if (seat->wp_primary_selection_device == nullptr) { | ||||
| seat->wp_primary_selection_device = zwp_primary_selection_device_manager_v1_get_device( | seat->wp_primary_selection_device = zwp_primary_selection_device_manager_v1_get_device( | ||||
| display->wp_primary_selection_device_manager, seat->wl_seat); | display->wp_primary_selection_device_manager, seat->wl_seat); | ||||
| zwp_primary_selection_device_v1_add_listener(seat->wp_primary_selection_device, | zwp_primary_selection_device_v1_add_listener(seat->wp_primary_selection_device, | ||||
| &primary_selection_device_listener, | &primary_selection_device_listener, | ||||
| &seat->primary_selection); | &seat->primary_selection); | ||||
| ▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | static void gwl_registry_wp_pointer_gestures_remove(GWL_Display *display, | ||||
| void * /*user_data*/, | void * /*user_data*/, | ||||
| const bool /*on_exit*/) | const bool /*on_exit*/) | ||||
| { | { | ||||
| struct zwp_pointer_gestures_v1 **value_p = &display->wp_pointer_gestures; | struct zwp_pointer_gestures_v1 **value_p = &display->wp_pointer_gestures; | ||||
| zwp_pointer_gestures_v1_destroy(*value_p); | zwp_pointer_gestures_v1_destroy(*value_p); | ||||
| *value_p = nullptr; | *value_p = nullptr; | ||||
| } | } | ||||
| #ifdef WITH_INPUT_IME | |||||
| /* #GWL_Display.wp_text_input_manager */ | |||||
| static void gwl_registry_wp_text_input_manager_add(GWL_Display *display, | |||||
| const GWL_RegisteryAdd_Params *params) | |||||
| { | |||||
| display->wp_text_input_manager = static_cast<zwp_text_input_manager_v3 *>(wl_registry_bind( | |||||
| display->wl_registry, params->name, &zwp_text_input_manager_v3_interface, 1)); | |||||
| gwl_registry_entry_add(display, params, nullptr); | |||||
| } | |||||
| static void gwl_registry_wp_text_input_manager_remove(GWL_Display *display, | |||||
| void * /*user_data*/, | |||||
| const bool /*on_exit*/) | |||||
| { | |||||
| struct zwp_text_input_manager_v3 **value_p = &display->wp_text_input_manager; | |||||
| zwp_text_input_manager_v3_destroy(*value_p); | |||||
| *value_p = nullptr; | |||||
| } | |||||
| #endif | |||||
| /* #GWL_Display.wp_primary_selection_device_manager */ | /* #GWL_Display.wp_primary_selection_device_manager */ | ||||
| static void gwl_registry_wp_primary_selection_device_manager_add( | static void gwl_registry_wp_primary_selection_device_manager_add( | ||||
| struct GWL_Display *display, const GWL_RegisteryAdd_Params *params) | struct GWL_Display *display, const GWL_RegisteryAdd_Params *params) | ||||
| { | { | ||||
| display->wp_primary_selection_device_manager = | display->wp_primary_selection_device_manager = | ||||
| static_cast<zwp_primary_selection_device_manager_v1 *>( | static_cast<zwp_primary_selection_device_manager_v1 *>( | ||||
| wl_registry_bind(display->wl_registry, | wl_registry_bind(display->wl_registry, | ||||
| ▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | /* Managers. */ | ||||
| gwl_registry_wp_tablet_manager_remove, | gwl_registry_wp_tablet_manager_remove, | ||||
| }, | }, | ||||
| { | { | ||||
| &zwp_relative_pointer_manager_v1_interface.name, | &zwp_relative_pointer_manager_v1_interface.name, | ||||
| gwl_registry_wp_relative_pointer_manager_add, | gwl_registry_wp_relative_pointer_manager_add, | ||||
| nullptr, | nullptr, | ||||
| gwl_registry_wp_relative_pointer_manager_remove, | gwl_registry_wp_relative_pointer_manager_remove, | ||||
| }, | }, | ||||
| #ifdef WITH_INPUT_IME | |||||
| { | |||||
| &zwp_text_input_manager_v3_interface.name, | |||||
| gwl_registry_wp_text_input_manager_add, | |||||
| nullptr, | |||||
| gwl_registry_wp_text_input_manager_remove, | |||||
| }, | |||||
| #endif | |||||
| /* Higher level interfaces. */ | /* Higher level interfaces. */ | ||||
| { | { | ||||
| &zwp_pointer_constraints_v1_interface.name, | &zwp_pointer_constraints_v1_interface.name, | ||||
| gwl_registry_wp_pointer_constraints_add, | gwl_registry_wp_pointer_constraints_add, | ||||
| nullptr, | nullptr, | ||||
| gwl_registry_wp_pointer_constraints_remove, | gwl_registry_wp_pointer_constraints_remove, | ||||
| }, | }, | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 1,955 Lines • ▼ Show 20 Lines | |||||
| # ifdef WITH_GHOST_WAYLAND_LIBDECOR | # ifdef WITH_GHOST_WAYLAND_LIBDECOR | ||||
| wayland_dynload_libdecor_exit(); | wayland_dynload_libdecor_exit(); | ||||
| # endif | # endif | ||||
| } | } | ||||
| #endif /* WITH_GHOST_WAYLAND_DYNLOAD */ | #endif /* WITH_GHOST_WAYLAND_DYNLOAD */ | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Public WAYLAND Text Input (IME) Functions | |||||
| * | |||||
| * Functionality only used for the WAYLAND implementation. | |||||
| * \{ */ | |||||
| #ifdef WITH_INPUT_IME | |||||
| void GHOST_SystemWayland::ime_begin( | |||||
| GHOST_WindowWayland *win, int32_t x, int32_t y, int32_t w, int32_t h, bool completed) const | |||||
| { | |||||
| if (UNLIKELY(display_->seats.empty())) { | |||||
| return; | |||||
| } | |||||
| GWL_Seat *seat = display_->seats[0]; | |||||
| /* NOTE(@flibit): For some reason this has to be done twice, | |||||
| * it appears to be a bug in mutter? Maybe? */ | |||||
| zwp_text_input_v3_enable(seat->wp_text_input); | |||||
| zwp_text_input_v3_commit(seat->wp_text_input); | |||||
| zwp_text_input_v3_enable(seat->wp_text_input); | |||||
| zwp_text_input_v3_commit(seat->wp_text_input); | |||||
| const wl_fixed_t scale = win->scale(); | |||||
| /* Now that it's enabled, set the input properties */ | |||||
| zwp_text_input_v3_set_content_type(seat->wp_text_input, | |||||
| ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE, | |||||
| ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL); | |||||
| zwp_text_input_v3_set_cursor_rectangle( | |||||
| seat->wp_text_input, x / scale, y / scale, (w * scale) + 1, (h * scale) + 1); | |||||
| zwp_text_input_v3_commit(seat->wp_text_input); | |||||
| } | |||||
| void GHOST_SystemWayland::ime_end(GHOST_WindowWayland * /*window*/) const | |||||
| { | |||||
| if (UNLIKELY(display_->seats.empty())) { | |||||
| return; | |||||
| } | |||||
| GWL_Seat *seat = display_->seats[0]; | |||||
| if (!seat->wp_text_input) { | |||||
| return; | |||||
| } | |||||
| zwp_text_input_v3_disable(seat->wp_text_input); | |||||
| zwp_text_input_v3_commit(seat->wp_text_input); | |||||
| } | |||||
| #endif | |||||
| /** \} */ | |||||