From 18d1ef46f24ff52668d1d1e31cf804c47ca62a0a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 7 Sep 2022 14:04:01 +1000 Subject: Cleanup: rename internal types for GHOST/Wayland - Use pascel-case type names, instead of snake-case with `_t` suffix. - Use `GWL_` prefix (short for GhostWayLand), to distinguish these types from ghost (`GHOST_*`) and wayland (`wl_*`) types. - Rename `input` to `seat` (following wayland's own terminology). - Use `wl_` prefix for wayland native variables which have locally defined equivalents so `GWL_Output *output` isn't confused with `struct wl_output *wl_output`. As the locally defined types are used more often this is less verbose overall. --- intern/ghost/intern/GHOST_SystemWayland.cpp | 1261 ++++++++++++++------------- intern/ghost/intern/GHOST_SystemWayland.h | 18 +- intern/ghost/intern/GHOST_WindowWayland.cpp | 62 +- intern/ghost/intern/GHOST_WindowWayland.h | 14 +- 4 files changed, 678 insertions(+), 677 deletions(-) (limited to 'intern') diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 8792ee239a8..4c663e98824 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -64,7 +64,7 @@ /* Logging, use `ghost.wl.*` prefix. */ #include "CLG_log.h" -static void keyboard_handle_key_repeat_cancel(struct input_t *input); +static void keyboard_handle_key_repeat_cancel(struct GWL_Seat *seat); static void output_handle_done(void *data, struct wl_output *wl_output); @@ -136,7 +136,7 @@ static bool use_gnome_confine_hack = false; */ #define EVDEV_OFFSET 8 -struct cursor_t { +struct GWL_Cursor { bool visible = false; /** * When false, hide the hardware cursor, while the cursor is still considered to be `visible`, @@ -163,28 +163,28 @@ struct cursor_t { * WAYLAND exposes tools via #zwp_tablet_tool_v2. * Since are no API's to access properties of the tool, store the values here. */ -struct tablet_tool_input_t { - struct input_t *input = nullptr; - struct wl_surface *cursor_surface = nullptr; - /** Used to delay clearing tablet focused surface until the frame is handled. */ +struct GWL_TabletTool { + struct GWL_Seat *seat = nullptr; + struct wl_surface *wl_surface_cursor = nullptr; + /** Used to delay clearing tablet focused wl_surface until the frame is handled. */ bool proximity = false; GHOST_TabletData data = GHOST_TABLET_DATA_NONE; }; -struct data_offer_t { +struct GWL_DataOffer { std::unordered_set types; uint32_t source_actions = 0; uint32_t dnd_action = 0; struct wl_data_offer *id = nullptr; std::atomic in_use = false; struct { - /** Compatible with #input_t.xy coordinates. */ + /** Compatible with #GWL_Seat.xy coordinates. */ wl_fixed_t xy[2] = {0, 0}; } dnd; }; -struct data_source_t { +struct GWL_DataSource { struct wl_data_source *data_source = nullptr; char *buffer_out = nullptr; }; @@ -194,11 +194,11 @@ struct data_source_t { * * \note it's important not to store the target window here * as it can be closed while the key is repeating, - * instead use the focused keyboard from #intput_t which is cleared when windows are closed. + * instead use the focused keyboard from #GWL_Seat which is cleared when windows are closed. * Therefor keyboard events must always check the window has not been cleared. */ -struct key_repeat_payload_t { - struct input_t *input = nullptr; +struct GWL_KeyRepeatPlayload { + struct GWL_Seat *seat = nullptr; xkb_keycode_t key_code; @@ -212,7 +212,7 @@ struct key_repeat_payload_t { }; /** Internal variables used to track grab-state. */ -struct input_grab_state_t { +struct GWL_SeatStateGrab { bool use_lock = false; bool use_confine = false; }; @@ -220,7 +220,7 @@ struct input_grab_state_t { /** * State of the pointing device (tablet or mouse). */ -struct input_state_pointer_t { +struct GWL_SeatStatePointer { /** * High precision coordinates. * @@ -229,15 +229,15 @@ struct input_state_pointer_t { * \code{.cc} * const wl_fixed_t scale = win->scale(); * const int event_xy[2] = { - * wl_fixed_to_int(scale * input_state->xy[0]), - * wl_fixed_to_int(scale * input_state->xy[1]), + * wl_fixed_to_int(scale * seat_state_pointer->xy[0]), + * wl_fixed_to_int(scale * seat_state_pointer->xy[1]), * }; * \endcode */ wl_fixed_t xy[2] = {0, 0}; /** Outputs on which the cursor is visible. */ - std::unordered_set outputs; + std::unordered_set outputs; int theme_scale = 1; @@ -245,7 +245,7 @@ struct input_state_pointer_t { uint32_t serial = 0; /** - * The surface last used with this pointing device + * The wl_surface last used with this pointing device * (events with this pointing device will be sent here). */ struct wl_surface *wl_surface = nullptr; @@ -254,20 +254,20 @@ struct input_state_pointer_t { }; /** - * State of the keyboard. + * State of the keyboard (in #GWL_Seat). */ -struct input_state_keyboard_t { +struct GWL_SeatStateKeyboard { /** The serial of the last used pointer or tablet. */ uint32_t serial = 0; /** - * The surface last used with this pointing device + * The wl_surface last used with this pointing device * (events with this pointing device will be sent here). */ struct wl_surface *wl_surface = nullptr; }; -struct input_t { +struct GWL_Seat { GHOST_SystemWayland *system = nullptr; std::string name; @@ -282,12 +282,12 @@ struct input_t { /** Use to check if the last cursor input was tablet or pointer. */ uint32_t cursor_source_serial = 0; - input_state_pointer_t pointer; + GWL_SeatStatePointer pointer; /** Mostly this can be interchanged with `pointer` however it can't be locked/confined. */ - input_state_pointer_t tablet; + GWL_SeatStatePointer tablet; - input_state_keyboard_t keyboard; + GWL_SeatStateKeyboard keyboard; #ifdef USE_GNOME_CONFINE_HACK bool use_pointer_software_confine = false; @@ -295,7 +295,7 @@ struct input_t { /** The cursor location (in pixel-space) when hidden grab started (#GHOST_kGrabHide). */ wl_fixed_t grab_lock_xy[2] = {0, 0}; - struct cursor_t cursor; + struct GWL_Cursor cursor; struct zwp_relative_pointer_v1 *relative_pointer = nullptr; struct zwp_locked_pointer_v1 *locked_pointer = nullptr; @@ -337,25 +337,25 @@ struct input_t { GHOST_ITimerTask *timer = nullptr; } key_repeat; - struct wl_surface *focus_dnd = nullptr; + struct wl_surface *wl_surface_focus_dnd = nullptr; struct wl_data_device *data_device = nullptr; /** Drag & Drop. */ - struct data_offer_t *data_offer_dnd = nullptr; + struct GWL_DataOffer *data_offer_dnd = nullptr; std::mutex data_offer_dnd_mutex; /** Copy & Paste. */ - struct data_offer_t *data_offer_copy_paste = nullptr; + struct GWL_DataOffer *data_offer_copy_paste = nullptr; std::mutex data_offer_copy_paste_mutex; - struct data_source_t *data_source = nullptr; + struct GWL_DataSource *data_source = nullptr; std::mutex data_source_mutex; /** Last device that was active. */ uint32_t data_source_serial = 0; }; -struct display_t { +struct GWL_Display { GHOST_SystemWayland *system = nullptr; struct wl_display *display = nullptr; @@ -370,8 +370,8 @@ struct display_t { struct zxdg_output_manager_v1 *xdg_output_manager = nullptr; struct wl_shm *shm = nullptr; - std::vector outputs; - std::vector inputs; + std::vector outputs; + std::vector seats; struct wl_data_device_manager *data_device_manager = nullptr; struct zwp_tablet_manager_v2 *tablet_manager = nullptr; @@ -409,31 +409,31 @@ static void ghost_wayland_log_handler(const char *msg, va_list arg) } } -static input_state_pointer_t *input_state_pointer_active(input_t *input) +static GWL_SeatStatePointer *seat_state_pointer_active(GWL_Seat *seat) { - if (input->pointer.serial == input->cursor_source_serial) { - return &input->pointer; + if (seat->pointer.serial == seat->cursor_source_serial) { + return &seat->pointer; } - if (input->tablet.serial == input->cursor_source_serial) { - return &input->tablet; + if (seat->tablet.serial == seat->cursor_source_serial) { + return &seat->tablet; } return nullptr; } -static input_state_pointer_t *input_state_pointer_from_cursor_surface(input_t *input, - const wl_surface *wl_surface) +static GWL_SeatStatePointer *seat_state_pointer_from_cursor_surface(GWL_Seat *seat, + const wl_surface *wl_surface) { if (ghost_wl_surface_own_cursor_pointer(wl_surface)) { - return &input->pointer; + return &seat->pointer; } if (ghost_wl_surface_own_cursor_tablet(wl_surface)) { - return &input->tablet; + return &seat->tablet; } GHOST_ASSERT(0, "Surface found without pointer/tablet tag"); return nullptr; } -static void display_destroy(display_t *d) +static void display_destroy(GWL_Display *d) { if (d->data_device_manager) { wl_data_device_manager_destroy(d->data_device_manager); @@ -443,77 +443,77 @@ static void display_destroy(display_t *d) zwp_tablet_manager_v2_destroy(d->tablet_manager); } - for (output_t *output : d->outputs) { + for (GWL_Output *output : d->outputs) { wl_output_destroy(output->wl_output); delete output; } - for (input_t *input : d->inputs) { + for (GWL_Seat *seat : d->seats) { /* First handle members that require locking. * While highly unlikely, it's possible they are being used while this function runs. */ { - std::lock_guard lock{input->data_source_mutex}; - if (input->data_source) { - free(input->data_source->buffer_out); - if (input->data_source->data_source) { - wl_data_source_destroy(input->data_source->data_source); + std::lock_guard lock{seat->data_source_mutex}; + if (seat->data_source) { + free(seat->data_source->buffer_out); + if (seat->data_source->data_source) { + wl_data_source_destroy(seat->data_source->data_source); } - delete input->data_source; + delete seat->data_source; } } { - std::lock_guard lock{input->data_offer_dnd_mutex}; - if (input->data_offer_dnd) { - wl_data_offer_destroy(input->data_offer_dnd->id); - delete input->data_offer_dnd; + std::lock_guard lock{seat->data_offer_dnd_mutex}; + if (seat->data_offer_dnd) { + wl_data_offer_destroy(seat->data_offer_dnd->id); + delete seat->data_offer_dnd; } } { - std::lock_guard lock{input->data_offer_copy_paste_mutex}; - if (input->data_offer_copy_paste) { - wl_data_offer_destroy(input->data_offer_copy_paste->id); - delete input->data_offer_copy_paste; + std::lock_guard lock{seat->data_offer_copy_paste_mutex}; + if (seat->data_offer_copy_paste) { + wl_data_offer_destroy(seat->data_offer_copy_paste->id); + delete seat->data_offer_copy_paste; } } - if (input->data_device) { - wl_data_device_release(input->data_device); + if (seat->data_device) { + wl_data_device_release(seat->data_device); } - if (input->cursor.custom_data) { - munmap(input->cursor.custom_data, input->cursor.custom_data_size); + if (seat->cursor.custom_data) { + munmap(seat->cursor.custom_data, seat->cursor.custom_data_size); } - if (input->wl_pointer) { - if (input->cursor.wl_surface) { - wl_surface_destroy(input->cursor.wl_surface); + if (seat->wl_pointer) { + if (seat->cursor.wl_surface) { + wl_surface_destroy(seat->cursor.wl_surface); } - if (input->cursor.wl_theme) { - wl_cursor_theme_destroy(input->cursor.wl_theme); + if (seat->cursor.wl_theme) { + wl_cursor_theme_destroy(seat->cursor.wl_theme); } - if (input->wl_pointer) { - wl_pointer_destroy(input->wl_pointer); + if (seat->wl_pointer) { + wl_pointer_destroy(seat->wl_pointer); } } - if (input->wl_keyboard) { - if (input->key_repeat.timer) { - keyboard_handle_key_repeat_cancel(input); + if (seat->wl_keyboard) { + if (seat->key_repeat.timer) { + keyboard_handle_key_repeat_cancel(seat); } - wl_keyboard_destroy(input->wl_keyboard); + wl_keyboard_destroy(seat->wl_keyboard); } /* Un-referencing checks for NULL case. */ - xkb_state_unref(input->xkb_state); - xkb_state_unref(input->xkb_state_empty); - xkb_state_unref(input->xkb_state_empty_with_numlock); + xkb_state_unref(seat->xkb_state); + xkb_state_unref(seat->xkb_state_empty); + xkb_state_unref(seat->xkb_state_empty_with_numlock); - xkb_context_unref(input->xkb_context); + xkb_context_unref(seat->xkb_context); - wl_seat_destroy(input->wl_seat); - delete input; + wl_seat_destroy(seat->wl_seat); + delete seat; } if (d->shm) { @@ -872,19 +872,19 @@ static CLG_LogRef LOG_WL_RELATIVE_POINTER = {"ghost.wl.handle.relative_pointer"} #define LOG (&LOG_WL_RELATIVE_POINTER) /** - * The caller is responsible for setting the value of `input->xy`. + * The caller is responsible for setting the value of `seat->xy`. */ -static void relative_pointer_handle_relative_motion_impl(input_t *input, +static void relative_pointer_handle_relative_motion_impl(GWL_Seat *seat, GHOST_WindowWayland *win, const wl_fixed_t xy[2]) { const wl_fixed_t scale = win->scale(); - input->pointer.xy[0] = xy[0]; - input->pointer.xy[1] = xy[1]; + seat->pointer.xy[0] = xy[0]; + seat->pointer.xy[1] = xy[1]; #ifdef USE_GNOME_CONFINE_HACK - if (input->use_pointer_software_confine) { + if (seat->use_pointer_software_confine) { GHOST_Rect bounds; win->getClientBounds(bounds); /* Needed or the cursor is considered outside the window and doesn't restore the location. */ @@ -895,15 +895,15 @@ static void relative_pointer_handle_relative_motion_impl(input_t *input, bounds.m_t = wl_fixed_from_int(bounds.m_t) / scale; bounds.m_r = wl_fixed_from_int(bounds.m_r) / scale; bounds.m_b = wl_fixed_from_int(bounds.m_b) / scale; - bounds.clampPoint(UNPACK2(input->pointer.xy)); + bounds.clampPoint(UNPACK2(seat->pointer.xy)); } #endif - input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(), - GHOST_kEventCursorMove, - win, - wl_fixed_to_int(scale * input->pointer.xy[0]), - wl_fixed_to_int(scale * input->pointer.xy[1]), - GHOST_TABLET_DATA_NONE)); + seat->system->pushEvent(new GHOST_EventCursor(seat->system->getMilliSeconds(), + GHOST_kEventCursorMove, + win, + wl_fixed_to_int(scale * seat->pointer.xy[0]), + wl_fixed_to_int(scale * seat->pointer.xy[1]), + GHOST_TABLET_DATA_NONE)); } static void relative_pointer_handle_relative_motion( @@ -916,16 +916,16 @@ static void relative_pointer_handle_relative_motion( const wl_fixed_t /*dx_unaccel*/, const wl_fixed_t /*dy_unaccel*/) { - input_t *input = static_cast(data); - if (wl_surface *focus_surface = input->pointer.wl_surface) { + GWL_Seat *seat = static_cast(data); + if (wl_surface *wl_surface_focus = seat->pointer.wl_surface) { CLOG_INFO(LOG, 2, "relative_motion"); - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); const wl_fixed_t scale = win->scale(); const wl_fixed_t xy_next[2] = { - input->pointer.xy[0] + (dx / scale), - input->pointer.xy[1] + (dy / scale), + seat->pointer.xy[0] + (dx / scale), + seat->pointer.xy[1] + (dy / scale), }; - relative_pointer_handle_relative_motion_impl(input, win, xy_next); + relative_pointer_handle_relative_motion_impl(seat, win, xy_next); } else { CLOG_INFO(LOG, 2, "relative_motion (skipped)"); @@ -947,26 +947,26 @@ static const zwp_relative_pointer_v1_listener relative_pointer_listener = { static CLG_LogRef LOG_WL_DATA_SOURCE = {"ghost.wl.handle.data_source"}; #define LOG (&LOG_WL_DATA_SOURCE) -static void dnd_events(const input_t *const input, const GHOST_TEventType event) +static void dnd_events(const GWL_Seat *const seat, const GHOST_TEventType event) { - /* NOTE: `input->data_offer_dnd_mutex` must already be locked. */ - if (wl_surface *focus_surface = input->focus_dnd) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); + /* NOTE: `seat->data_offer_dnd_mutex` must already be locked. */ + if (wl_surface *wl_surface_focus = seat->wl_surface_focus_dnd) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); const wl_fixed_t scale = win->scale(); const int event_xy[2] = { - wl_fixed_to_int(scale * input->data_offer_dnd->dnd.xy[0]), - wl_fixed_to_int(scale * input->data_offer_dnd->dnd.xy[1]), + wl_fixed_to_int(scale * seat->data_offer_dnd->dnd.xy[0]), + wl_fixed_to_int(scale * seat->data_offer_dnd->dnd.xy[1]), }; - const uint64_t time = input->system->getMilliSeconds(); + const uint64_t time = seat->system->getMilliSeconds(); for (const std::string &type : mime_preference_order) { - input->system->pushEvent(new GHOST_EventDragnDrop( + seat->system->pushEvent(new GHOST_EventDragnDrop( time, event, mime_dnd.at(type), win, UNPACK2(event_xy), nullptr)); } } } -static std::string read_pipe(data_offer_t *data_offer, +static std::string read_pipe(GWL_DataOffer *data_offer, const std::string mime_receive, std::mutex *mutex) { @@ -1013,12 +1013,12 @@ static void data_source_handle_send(void *data, const char * /*mime_type*/, const int32_t fd) { - input_t *input = static_cast(data); - std::lock_guard lock{input->data_source_mutex}; + GWL_Seat *seat = static_cast(data); + std::lock_guard lock{seat->data_source_mutex}; CLOG_INFO(LOG, 2, "send"); - const char *const buffer = input->data_source->buffer_out; + const char *const buffer = seat->data_source->buffer_out; if (write(fd, buffer, strlen(buffer)) < 0) { GHOST_PRINT("error writing to clipboard: " << std::strerror(errno) << std::endl); } @@ -1096,7 +1096,7 @@ static void data_offer_handle_offer(void *data, const char *mime_type) { CLOG_INFO(LOG, 2, "offer (mime_type=%s)", mime_type); - static_cast(data)->types.insert(mime_type); + static_cast(data)->types.insert(mime_type); } static void data_offer_handle_source_actions(void *data, @@ -1104,7 +1104,7 @@ static void data_offer_handle_source_actions(void *data, const uint32_t source_actions) { CLOG_INFO(LOG, 2, "source_actions (%u)", source_actions); - static_cast(data)->source_actions = source_actions; + static_cast(data)->source_actions = source_actions; } static void data_offer_handle_action(void *data, @@ -1112,7 +1112,7 @@ static void data_offer_handle_action(void *data, const uint32_t dnd_action) { CLOG_INFO(LOG, 2, "actions (%u)", dnd_action); - static_cast(data)->dnd_action = dnd_action; + static_cast(data)->dnd_action = dnd_action; } static const struct wl_data_offer_listener data_offer_listener = { @@ -1138,7 +1138,7 @@ static void data_device_handle_data_offer(void * /*data*/, { CLOG_INFO(LOG, 2, "data_offer"); - data_offer_t *data_offer = new data_offer_t; + GWL_DataOffer *data_offer = new GWL_DataOffer; data_offer->id = id; wl_data_offer_add_listener(id, &data_offer_listener, data_offer); } @@ -1146,23 +1146,23 @@ static void data_device_handle_data_offer(void * /*data*/, static void data_device_handle_enter(void *data, struct wl_data_device * /*wl_data_device*/, const uint32_t serial, - struct wl_surface *surface, + struct wl_surface *wl_surface, const wl_fixed_t x, const wl_fixed_t y, struct wl_data_offer *id) { - if (!ghost_wl_surface_own(surface)) { + if (!ghost_wl_surface_own(wl_surface)) { CLOG_INFO(LOG, 2, "enter (skipped)"); return; } CLOG_INFO(LOG, 2, "enter"); - input_t *input = static_cast(data); - std::lock_guard lock{input->data_offer_dnd_mutex}; + GWL_Seat *seat = static_cast(data); + std::lock_guard lock{seat->data_offer_dnd_mutex}; - delete input->data_offer_dnd; - input->data_offer_dnd = static_cast(wl_data_offer_get_user_data(id)); - data_offer_t *data_offer = input->data_offer_dnd; + delete seat->data_offer_dnd; + seat->data_offer_dnd = static_cast(wl_data_offer_get_user_data(id)); + GWL_DataOffer *data_offer = seat->data_offer_dnd; data_offer->in_use.store(true); data_offer->dnd.xy[0] = x; @@ -1177,24 +1177,24 @@ static void data_device_handle_enter(void *data, wl_data_offer_accept(id, serial, type.c_str()); } - input->focus_dnd = surface; - dnd_events(input, GHOST_kEventDraggingEntered); + seat->wl_surface_focus_dnd = wl_surface; + dnd_events(seat, GHOST_kEventDraggingEntered); } static void data_device_handle_leave(void *data, struct wl_data_device * /*wl_data_device*/) { - input_t *input = static_cast(data); - std::lock_guard lock{input->data_offer_dnd_mutex}; + GWL_Seat *seat = static_cast(data); + std::lock_guard lock{seat->data_offer_dnd_mutex}; CLOG_INFO(LOG, 2, "leave"); - dnd_events(input, GHOST_kEventDraggingExited); - input->focus_dnd = nullptr; + dnd_events(seat, GHOST_kEventDraggingExited); + seat->wl_surface_focus_dnd = nullptr; - if (input->data_offer_dnd && !input->data_offer_dnd->in_use.load()) { - wl_data_offer_destroy(input->data_offer_dnd->id); - delete input->data_offer_dnd; - input->data_offer_dnd = nullptr; + if (seat->data_offer_dnd && !seat->data_offer_dnd->in_use.load()) { + wl_data_offer_destroy(seat->data_offer_dnd->id); + delete seat->data_offer_dnd; + seat->data_offer_dnd = nullptr; } } @@ -1204,23 +1204,23 @@ static void data_device_handle_motion(void *data, const wl_fixed_t x, const wl_fixed_t y) { - input_t *input = static_cast(data); - std::lock_guard lock{input->data_offer_dnd_mutex}; + GWL_Seat *seat = static_cast(data); + std::lock_guard lock{seat->data_offer_dnd_mutex}; CLOG_INFO(LOG, 2, "motion"); - input->data_offer_dnd->dnd.xy[0] = x; - input->data_offer_dnd->dnd.xy[1] = y; + seat->data_offer_dnd->dnd.xy[0] = x; + seat->data_offer_dnd->dnd.xy[1] = y; - dnd_events(input, GHOST_kEventDraggingUpdated); + dnd_events(seat, GHOST_kEventDraggingUpdated); } static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_data_device*/) { - input_t *input = static_cast(data); - std::lock_guard lock{input->data_offer_dnd_mutex}; + GWL_Seat *seat = static_cast(data); + std::lock_guard lock{seat->data_offer_dnd_mutex}; - data_offer_t *data_offer = input->data_offer_dnd; + GWL_DataOffer *data_offer = seat->data_offer_dnd; const std::string mime_receive = *std::find_first_of(mime_preference_order.begin(), mime_preference_order.end(), @@ -1229,9 +1229,9 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat CLOG_INFO(LOG, 2, "drop mime_recieve=%s", mime_receive.c_str()); - auto read_uris_fn = [](input_t *const input, - data_offer_t *data_offer, - wl_surface *surface, + auto read_uris_fn = [](GWL_Seat *const seat, + GWL_DataOffer *data_offer, + wl_surface *wl_surface, const std::string mime_receive) { const wl_fixed_t xy[2] = {UNPACK2(data_offer->dnd.xy)}; @@ -1243,13 +1243,13 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat wl_data_offer_finish(data_offer->id); wl_data_offer_destroy(data_offer->id); - if (input->data_offer_dnd == data_offer) { - input->data_offer_dnd = nullptr; + if (seat->data_offer_dnd == data_offer) { + seat->data_offer_dnd = nullptr; } delete data_offer; data_offer = nullptr; - GHOST_SystemWayland *const system = input->system; + GHOST_SystemWayland *const system = seat->system; if (mime_receive == mime_text_uri) { static constexpr const char *file_proto = "file://"; @@ -1257,7 +1257,7 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat * So support both, once `\n` is found, strip the preceding `\r` if found. */ static constexpr const char *lf = "\n"; - GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface); + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface); std::vector uris; size_t pos = 0; @@ -1304,9 +1304,10 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat wl_display_roundtrip(system->display()); }; - /* Pass in `input->focus_dnd` instead of accessing it from `input` since the leave callback - * (#data_device_handle_leave) will clear the value once this function starts. */ - std::thread read_thread(read_uris_fn, input, data_offer, input->focus_dnd, mime_receive); + /* Pass in `seat->wl_surface_focus_dnd` instead of accessing it from `seat` since the leave + * callback (#data_device_handle_leave) will clear the value once this function starts. */ + std::thread read_thread( + read_uris_fn, seat, data_offer, seat->wl_surface_focus_dnd, mime_receive); read_thread.detach(); } @@ -1314,18 +1315,18 @@ static void data_device_handle_selection(void *data, struct wl_data_device * /*wl_data_device*/, struct wl_data_offer *id) { - input_t *input = static_cast(data); + GWL_Seat *seat = static_cast(data); - std::lock_guard lock{input->data_offer_copy_paste_mutex}; + std::lock_guard lock{seat->data_offer_copy_paste_mutex}; - data_offer_t *data_offer = input->data_offer_copy_paste; + GWL_DataOffer *data_offer = seat->data_offer_copy_paste; /* Delete old data offer. */ if (data_offer != nullptr) { wl_data_offer_destroy(data_offer->id); delete data_offer; data_offer = nullptr; - input->data_offer_copy_paste = nullptr; + seat->data_offer_copy_paste = nullptr; } if (id == nullptr) { @@ -1335,14 +1336,14 @@ static void data_device_handle_selection(void *data, CLOG_INFO(LOG, 2, "selection"); /* Get new data offer. */ - data_offer = static_cast(wl_data_offer_get_user_data(id)); - input->data_offer_copy_paste = data_offer; + data_offer = static_cast(wl_data_offer_get_user_data(id)); + seat->data_offer_copy_paste = data_offer; - auto read_selection_fn = [](input_t *input) { - GHOST_SystemWayland *const system = input->system; - input->data_offer_copy_paste_mutex.lock(); + auto read_selection_fn = [](GWL_Seat *seat) { + GHOST_SystemWayland *const system = seat->system; + seat->data_offer_copy_paste_mutex.lock(); - data_offer_t *data_offer = input->data_offer_copy_paste; + GWL_DataOffer *data_offer = seat->data_offer_copy_paste; std::string mime_receive; for (const std::string type : {mime_text_utf8, mime_text_plain}) { if (data_offer->types.count(type)) { @@ -1351,7 +1352,7 @@ static void data_device_handle_selection(void *data, } } const std::string data = read_pipe( - data_offer, mime_receive, &input->data_offer_copy_paste_mutex); + data_offer, mime_receive, &seat->data_offer_copy_paste_mutex); { std::lock_guard lock{system_selection_mutex}; @@ -1359,7 +1360,7 @@ static void data_device_handle_selection(void *data, } }; - std::thread read_thread(read_selection_fn, input); + std::thread read_thread(read_selection_fn, seat); read_thread.detach(); } @@ -1387,7 +1388,7 @@ static void cursor_buffer_handle_release(void *data, struct wl_buffer *wl_buffer { CLOG_INFO(LOG, 2, "release"); - cursor_t *cursor = static_cast(data); + GWL_Cursor *cursor = static_cast(data); wl_buffer_destroy(wl_buffer); if (wl_buffer == cursor->wl_buffer) { @@ -1411,22 +1412,22 @@ static const struct wl_buffer_listener cursor_buffer_listener = { static CLG_LogRef LOG_WL_CURSOR_SURFACE = {"ghost.wl.handle.cursor_surface"}; #define LOG (&LOG_WL_CURSOR_SURFACE) -static bool update_cursor_scale(cursor_t &cursor, +static bool update_cursor_scale(GWL_Cursor &cursor, wl_shm *shm, - input_state_pointer_t *input_state, - wl_surface *cursor_surface) + GWL_SeatStatePointer *seat_state_pointer, + wl_surface *wl_cursor_surface) { int scale = 0; - for (const output_t *output : input_state->outputs) { + for (const GWL_Output *output : seat_state_pointer->outputs) { if (output->scale > scale) { scale = output->scale; } } - if (scale > 0 && input_state->theme_scale != scale) { - input_state->theme_scale = scale; + if (scale > 0 && seat_state_pointer->theme_scale != scale) { + seat_state_pointer->theme_scale = scale; if (!cursor.is_custom) { - wl_surface_set_buffer_scale(cursor_surface, scale); + wl_surface_set_buffer_scale(wl_cursor_surface, scale); } wl_cursor_theme_destroy(cursor.wl_theme); cursor.wl_theme = wl_cursor_theme_load(cursor.theme_name.c_str(), scale * cursor.size, shm); @@ -1437,36 +1438,38 @@ static bool update_cursor_scale(cursor_t &cursor, static void cursor_surface_handle_enter(void *data, struct wl_surface *wl_surface, - struct wl_output *output) + struct wl_output *wl_output) { - if (!ghost_wl_output_own(output)) { + if (!ghost_wl_output_own(wl_output)) { CLOG_INFO(LOG, 2, "handle_enter (skipped)"); return; } CLOG_INFO(LOG, 2, "handle_enter"); - input_t *input = static_cast(data); - input_state_pointer_t *input_state = input_state_pointer_from_cursor_surface(input, wl_surface); - const output_t *reg_output = ghost_wl_output_user_data(output); - input_state->outputs.insert(reg_output); - update_cursor_scale(input->cursor, input->system->shm(), input_state, wl_surface); + GWL_Seat *seat = static_cast(data); + GWL_SeatStatePointer *seat_state_pointer = seat_state_pointer_from_cursor_surface(seat, + wl_surface); + const GWL_Output *reg_output = ghost_wl_output_user_data(wl_output); + seat_state_pointer->outputs.insert(reg_output); + update_cursor_scale(seat->cursor, seat->system->shm(), seat_state_pointer, wl_surface); } static void cursor_surface_handle_leave(void *data, struct wl_surface *wl_surface, - struct wl_output *output) + struct wl_output *wl_output) { - if (!(output && ghost_wl_output_own(output))) { + if (!(wl_output && ghost_wl_output_own(wl_output))) { CLOG_INFO(LOG, 2, "handle_leave (skipped)"); return; } CLOG_INFO(LOG, 2, "handle_leave"); - input_t *input = static_cast(data); - input_state_pointer_t *input_state = input_state_pointer_from_cursor_surface(input, wl_surface); - const output_t *reg_output = ghost_wl_output_user_data(output); - input_state->outputs.erase(reg_output); - update_cursor_scale(input->cursor, input->system->shm(), input_state, wl_surface); + GWL_Seat *seat = static_cast(data); + GWL_SeatStatePointer *seat_state_pointer = seat_state_pointer_from_cursor_surface(seat, + wl_surface); + const GWL_Output *reg_output = ghost_wl_output_user_data(wl_output); + seat_state_pointer->outputs.erase(reg_output); + update_cursor_scale(seat->cursor, seat->system->shm(), seat_state_pointer, wl_surface); } static const struct wl_surface_listener cursor_surface_listener = { @@ -1488,48 +1491,48 @@ static CLG_LogRef LOG_WL_POINTER = {"ghost.wl.handle.pointer"}; static void pointer_handle_enter(void *data, struct wl_pointer * /*wl_pointer*/, const uint32_t serial, - struct wl_surface *surface, + struct wl_surface *wl_surface, const wl_fixed_t surface_x, const wl_fixed_t surface_y) { - if (!ghost_wl_surface_own(surface)) { + if (!ghost_wl_surface_own(wl_surface)) { CLOG_INFO(LOG, 2, "enter (skipped)"); return; } CLOG_INFO(LOG, 2, "enter"); - GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface); + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface); win->activate(); - input_t *input = static_cast(data); - input->cursor_source_serial = serial; - input->pointer.serial = serial; - input->pointer.xy[0] = surface_x; - input->pointer.xy[1] = surface_y; - input->pointer.wl_surface = surface; + GWL_Seat *seat = static_cast(data); + seat->cursor_source_serial = serial; + seat->pointer.serial = serial; + seat->pointer.xy[0] = surface_x; + seat->pointer.xy[1] = surface_y; + seat->pointer.wl_surface = wl_surface; win->setCursorShape(win->getCursorShape()); const wl_fixed_t scale = win->scale(); - input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(), - GHOST_kEventCursorMove, - win, - wl_fixed_to_int(scale * input->pointer.xy[0]), - wl_fixed_to_int(scale * input->pointer.xy[1]), - GHOST_TABLET_DATA_NONE)); + seat->system->pushEvent(new GHOST_EventCursor(seat->system->getMilliSeconds(), + GHOST_kEventCursorMove, + win, + wl_fixed_to_int(scale * seat->pointer.xy[0]), + wl_fixed_to_int(scale * seat->pointer.xy[1]), + GHOST_TABLET_DATA_NONE)); } static void pointer_handle_leave(void *data, struct wl_pointer * /*wl_pointer*/, const uint32_t /*serial*/, - struct wl_surface *surface) + struct wl_surface *wl_surface) { /* First clear the `pointer.wl_surface`, since the window won't exist when closing the window. */ - static_cast(data)->pointer.wl_surface = nullptr; - if (surface && ghost_wl_surface_own(surface)) { + static_cast(data)->pointer.wl_surface = nullptr; + if (wl_surface && ghost_wl_surface_own(wl_surface)) { CLOG_INFO(LOG, 2, "leave"); - GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface); + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface); win->deactivate(); } else { @@ -1543,20 +1546,20 @@ static void pointer_handle_motion(void *data, const wl_fixed_t surface_x, const wl_fixed_t surface_y) { - input_t *input = static_cast(data); - input->pointer.xy[0] = surface_x; - input->pointer.xy[1] = surface_y; + GWL_Seat *seat = static_cast(data); + seat->pointer.xy[0] = surface_x; + seat->pointer.xy[1] = surface_y; - if (wl_surface *focus_surface = input->pointer.wl_surface) { + if (wl_surface *wl_surface_focus = seat->pointer.wl_surface) { CLOG_INFO(LOG, 2, "motion"); - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); const wl_fixed_t scale = win->scale(); - input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(), - GHOST_kEventCursorMove, - win, - wl_fixed_to_int(scale * input->pointer.xy[0]), - wl_fixed_to_int(scale * input->pointer.xy[1]), - GHOST_TABLET_DATA_NONE)); + seat->system->pushEvent(new GHOST_EventCursor(seat->system->getMilliSeconds(), + GHOST_kEventCursorMove, + win, + wl_fixed_to_int(scale * seat->pointer.xy[0]), + wl_fixed_to_int(scale * seat->pointer.xy[1]), + GHOST_TABLET_DATA_NONE)); } else { CLOG_INFO(LOG, 2, "motion (skipped)"); @@ -1572,7 +1575,7 @@ static void pointer_handle_button(void *data, { CLOG_INFO(LOG, 2, "button (button=%u, state=%u)", button, state); - input_t *input = static_cast(data); + GWL_Seat *seat = static_cast(data); GHOST_TEventType etype = GHOST_kEventUnknown; switch (state) { case WL_POINTER_BUTTON_STATE_RELEASED: @@ -1608,13 +1611,13 @@ static void pointer_handle_button(void *data, break; } - input->data_source_serial = serial; - input->pointer.buttons.set(ebutton, state == WL_POINTER_BUTTON_STATE_PRESSED); + seat->data_source_serial = serial; + seat->pointer.buttons.set(ebutton, state == WL_POINTER_BUTTON_STATE_PRESSED); - if (wl_surface *focus_surface = input->pointer.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - input->system->pushEvent(new GHOST_EventButton( - input->system->getMilliSeconds(), etype, win, ebutton, GHOST_TABLET_DATA_NONE)); + if (wl_surface *wl_surface_focus = seat->pointer.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + seat->system->pushEvent(new GHOST_EventButton( + seat->system->getMilliSeconds(), etype, win, ebutton, GHOST_TABLET_DATA_NONE)); } } @@ -1651,15 +1654,15 @@ static void pointer_handle_axis_discrete(void *data, { CLOG_INFO(LOG, 2, "axis_discrete (axis=%u, discrete=%d)", axis, discrete); - input_t *input = static_cast(data); + GWL_Seat *seat = static_cast(data); if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL) { return; } - if (wl_surface *focus_surface = input->pointer.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - input->system->pushEvent(new GHOST_EventWheel( - input->system->getMilliSeconds(), win, std::signbit(discrete) ? +1 : -1)); + if (wl_surface *wl_surface_focus = seat->pointer.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + seat->system->pushEvent(new GHOST_EventWheel( + seat->system->getMilliSeconds(), win, std::signbit(discrete) ? +1 : -1)); } } @@ -1692,9 +1695,9 @@ static void tablet_tool_handle_type(void *data, { CLOG_INFO(LOG, 2, "type (type=%u)", tool_type); - tablet_tool_input_t *tool_input = static_cast(data); + GWL_TabletTool *tablet_tool = static_cast(data); - tool_input->data.Active = tablet_tool_map_type((enum zwp_tablet_tool_v2_type)tool_type); + tablet_tool->data.Active = tablet_tool_map_type((enum zwp_tablet_tool_v2_type)tool_type); } static void tablet_tool_handle_hardware_serial(void * /*data*/, @@ -1737,47 +1740,47 @@ static void tablet_tool_handle_removed(void *data, struct zwp_tablet_tool_v2 *zw { CLOG_INFO(LOG, 2, "removed"); - tablet_tool_input_t *tool_input = static_cast(data); - input_t *input = tool_input->input; + GWL_TabletTool *tablet_tool = static_cast(data); + GWL_Seat *seat = tablet_tool->seat; - if (tool_input->cursor_surface) { - wl_surface_destroy(tool_input->cursor_surface); + if (tablet_tool->wl_surface_cursor) { + wl_surface_destroy(tablet_tool->wl_surface_cursor); } - input->tablet_tools.erase(zwp_tablet_tool_v2); + seat->tablet_tools.erase(zwp_tablet_tool_v2); - delete tool_input; + delete tablet_tool; } static void tablet_tool_handle_proximity_in(void *data, struct zwp_tablet_tool_v2 * /*zwp_tablet_tool_v2*/, const uint32_t serial, struct zwp_tablet_v2 * /*tablet*/, - struct wl_surface *surface) + struct wl_surface *wl_surface) { - if (!ghost_wl_surface_own(surface)) { + if (!ghost_wl_surface_own(wl_surface)) { CLOG_INFO(LOG, 2, "proximity_in (skipped)"); return; } CLOG_INFO(LOG, 2, "proximity_in"); - tablet_tool_input_t *tool_input = static_cast(data); - tool_input->proximity = true; + GWL_TabletTool *tablet_tool = static_cast(data); + tablet_tool->proximity = true; - input_t *input = tool_input->input; - input->cursor_source_serial = serial; - input->tablet.wl_surface = surface; - input->tablet.serial = serial; + GWL_Seat *seat = tablet_tool->seat; + seat->cursor_source_serial = serial; + seat->tablet.wl_surface = wl_surface; + seat->tablet.serial = serial; - input->data_source_serial = serial; + seat->data_source_serial = serial; /* Update #GHOST_TabletData. */ - GHOST_TabletData &td = tool_input->data; + GHOST_TabletData &td = tablet_tool->data; /* Reset, to avoid using stale tilt/pressure. */ td.Xtilt = 0.0f; td.Ytilt = 0.0f; /* In case pressure isn't supported. */ td.Pressure = 1.0f; - GHOST_WindowWayland *win = ghost_wl_surface_user_data(input->tablet.wl_surface); + GHOST_WindowWayland *win = ghost_wl_surface_user_data(seat->tablet.wl_surface); win->activate(); @@ -1787,10 +1790,10 @@ static void tablet_tool_handle_proximity_out(void *data, struct zwp_tablet_tool_v2 * /*zwp_tablet_tool_v2*/) { CLOG_INFO(LOG, 2, "proximity_out"); - tablet_tool_input_t *tool_input = static_cast(data); - /* Defer clearing the surface until the frame is handled. - * Without this, the frame can not access the surface. */ - tool_input->proximity = false; + GWL_TabletTool *tablet_tool = static_cast(data); + /* Defer clearing the wl_surface until the frame is handled. + * Without this, the frame can not access the wl_surface. */ + tablet_tool->proximity = false; } static void tablet_tool_handle_down(void *data, @@ -1799,18 +1802,18 @@ static void tablet_tool_handle_down(void *data, { CLOG_INFO(LOG, 2, "down"); - tablet_tool_input_t *tool_input = static_cast(data); - input_t *input = tool_input->input; + GWL_TabletTool *tablet_tool = static_cast(data); + GWL_Seat *seat = tablet_tool->seat; const GHOST_TButton ebutton = GHOST_kButtonMaskLeft; const GHOST_TEventType etype = GHOST_kEventButtonDown; - input->data_source_serial = serial; - input->tablet.buttons.set(ebutton, true); + seat->data_source_serial = serial; + seat->tablet.buttons.set(ebutton, true); - if (wl_surface *focus_surface = input->tablet.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - input->system->pushEvent(new GHOST_EventButton( - input->system->getMilliSeconds(), etype, win, ebutton, tool_input->data)); + if (wl_surface *wl_surface_focus = seat->tablet.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + seat->system->pushEvent(new GHOST_EventButton( + seat->system->getMilliSeconds(), etype, win, ebutton, tablet_tool->data)); } } @@ -1818,17 +1821,17 @@ static void tablet_tool_handle_up(void *data, struct zwp_tablet_tool_v2 * /*zwp_ { CLOG_INFO(LOG, 2, "up"); - tablet_tool_input_t *tool_input = static_cast(data); - input_t *input = tool_input->input; + GWL_TabletTool *tablet_tool = static_cast(data); + GWL_Seat *seat = tablet_tool->seat; const GHOST_TButton ebutton = GHOST_kButtonMaskLeft; const GHOST_TEventType etype = GHOST_kEventButtonUp; - input->tablet.buttons.set(ebutton, false); + seat->tablet.buttons.set(ebutton, false); - if (wl_surface *focus_surface = input->tablet.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - input->system->pushEvent(new GHOST_EventButton( - input->system->getMilliSeconds(), etype, win, ebutton, tool_input->data)); + if (wl_surface *wl_surface_focus = seat->tablet.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + seat->system->pushEvent(new GHOST_EventButton( + seat->system->getMilliSeconds(), etype, win, ebutton, tablet_tool->data)); } } @@ -1839,11 +1842,11 @@ static void tablet_tool_handle_motion(void *data, { CLOG_INFO(LOG, 2, "motion"); - tablet_tool_input_t *tool_input = static_cast(data); - input_t *input = tool_input->input; + GWL_TabletTool *tablet_tool = static_cast(data); + GWL_Seat *seat = tablet_tool->seat; - input->tablet.xy[0] = x; - input->tablet.xy[1] = y; + seat->tablet.xy[0] = x; + seat->tablet.xy[1] = y; /* NOTE: #tablet_tool_handle_frame generates the event (with updated pressure, tilt... etc). */ } @@ -1855,8 +1858,8 @@ static void tablet_tool_handle_pressure(void *data, const float pressure_unit = (float)pressure / 65535; CLOG_INFO(LOG, 2, "pressure (%.4f)", pressure_unit); - tablet_tool_input_t *tool_input = static_cast(data); - GHOST_TabletData &td = tool_input->data; + GWL_TabletTool *tablet_tool = static_cast(data); + GHOST_TabletData &td = tablet_tool->data; td.Pressure = pressure_unit; } static void tablet_tool_handle_distance(void * /*data*/, @@ -1877,8 +1880,8 @@ static void tablet_tool_handle_tilt(void *data, (float)(wl_fixed_to_double(tilt_y) / 90.0), }; CLOG_INFO(LOG, 2, "tilt (x=%.4f, y=%.4f)", UNPACK2(tilt_unit)); - tablet_tool_input_t *tool_input = static_cast(data); - GHOST_TabletData &td = tool_input->data; + GWL_TabletTool *tablet_tool = static_cast(data); + GHOST_TabletData &td = tablet_tool->data; td.Xtilt = tilt_unit[0]; td.Ytilt = tilt_unit[1]; CLAMP(td.Xtilt, -1.0f, 1.0f); @@ -1908,11 +1911,11 @@ static void tablet_tool_handle_wheel(void *data, } CLOG_INFO(LOG, 2, "wheel (clicks=%d)", clicks); - tablet_tool_input_t *tool_input = static_cast(data); - input_t *input = tool_input->input; - if (wl_surface *focus_surface = input->tablet.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - input->system->pushEvent(new GHOST_EventWheel(input->system->getMilliSeconds(), win, clicks)); + GWL_TabletTool *tablet_tool = static_cast(data); + GWL_Seat *seat = tablet_tool->seat; + if (wl_surface *wl_surface_focus = seat->tablet.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + seat->system->pushEvent(new GHOST_EventWheel(seat->system->getMilliSeconds(), win, clicks)); } } static void tablet_tool_handle_button(void *data, @@ -1923,8 +1926,8 @@ static void tablet_tool_handle_button(void *data, { CLOG_INFO(LOG, 2, "button (button=%u, state=%u)", button, state); - tablet_tool_input_t *tool_input = static_cast(data); - input_t *input = tool_input->input; + GWL_TabletTool *tablet_tool = static_cast(data); + GWL_Seat *seat = tablet_tool->seat; GHOST_TEventType etype = GHOST_kEventUnknown; switch (state) { @@ -1949,13 +1952,13 @@ static void tablet_tool_handle_button(void *data, break; } - input->data_source_serial = serial; - input->tablet.buttons.set(ebutton, state == WL_POINTER_BUTTON_STATE_PRESSED); + seat->data_source_serial = serial; + seat->tablet.buttons.set(ebutton, state == WL_POINTER_BUTTON_STATE_PRESSED); - if (wl_surface *focus_surface = input->tablet.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - input->system->pushEvent(new GHOST_EventButton( - input->system->getMilliSeconds(), etype, win, ebutton, tool_input->data)); + if (wl_surface *wl_surface_focus = seat->tablet.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + seat->system->pushEvent(new GHOST_EventButton( + seat->system->getMilliSeconds(), etype, win, ebutton, tablet_tool->data)); } } static void tablet_tool_handle_frame(void *data, @@ -1964,26 +1967,26 @@ static void tablet_tool_handle_frame(void *data, { CLOG_INFO(LOG, 2, "frame"); - tablet_tool_input_t *tool_input = static_cast(data); - input_t *input = tool_input->input; + GWL_TabletTool *tablet_tool = static_cast(data); + GWL_Seat *seat = tablet_tool->seat; /* No need to check the surfaces origin, it's already known to be owned by GHOST. */ - if (wl_surface *focus_surface = input->tablet.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); + if (wl_surface *wl_surface_focus = seat->tablet.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); const wl_fixed_t scale = win->scale(); - input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(), - GHOST_kEventCursorMove, - win, - wl_fixed_to_int(scale * input->tablet.xy[0]), - wl_fixed_to_int(scale * input->tablet.xy[1]), - tool_input->data)); - if (tool_input->proximity == false) { + seat->system->pushEvent(new GHOST_EventCursor(seat->system->getMilliSeconds(), + GHOST_kEventCursorMove, + win, + wl_fixed_to_int(scale * seat->tablet.xy[0]), + wl_fixed_to_int(scale * seat->tablet.xy[1]), + tablet_tool->data)); + if (tablet_tool->proximity == false) { win->setCursorShape(win->getCursorShape()); } } - if (tool_input->proximity == false) { - input->tablet.wl_surface = nullptr; + if (tablet_tool->proximity == false) { + seat->tablet.wl_surface = nullptr; } } @@ -2033,19 +2036,19 @@ static void tablet_seat_handle_tool_added(void *data, { CLOG_INFO(LOG, 2, "tool_added (id=%p)", id); - input_t *input = static_cast(data); - tablet_tool_input_t *tool_input = new tablet_tool_input_t(); - tool_input->input = input; + GWL_Seat *seat = static_cast(data); + GWL_TabletTool *tablet_tool = new GWL_TabletTool(); + tablet_tool->seat = seat; - /* Every tool has it's own cursor surface. */ - tool_input->cursor_surface = wl_compositor_create_surface(input->system->compositor()); - ghost_wl_surface_tag_cursor_tablet(tool_input->cursor_surface); + /* Every tool has it's own cursor wl_surface. */ + tablet_tool->wl_surface_cursor = wl_compositor_create_surface(seat->system->compositor()); + ghost_wl_surface_tag_cursor_tablet(tablet_tool->wl_surface_cursor); - wl_surface_add_listener(tool_input->cursor_surface, &cursor_surface_listener, (void *)input); + wl_surface_add_listener(tablet_tool->wl_surface_cursor, &cursor_surface_listener, (void *)seat); - zwp_tablet_tool_v2_add_listener(id, &tablet_tool_listner, tool_input); + zwp_tablet_tool_v2_add_listener(id, &tablet_tool_listner, tablet_tool); - input->tablet_tools.insert(id); + seat->tablet_tools.insert(id); } static void tablet_seat_handle_pad_added(void * /*data*/, @@ -2078,7 +2081,7 @@ static void keyboard_handle_keymap(void *data, const int32_t fd, const uint32_t size) { - input_t *input = static_cast(data); + GWL_Seat *seat = static_cast(data); if ((!data) || (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1)) { CLOG_INFO(LOG, 2, "keymap (no data or wrong version)"); @@ -2093,7 +2096,7 @@ static void keyboard_handle_keymap(void *data, } struct xkb_keymap *keymap = xkb_keymap_new_from_string( - input->xkb_context, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); + seat->xkb_context, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(map_str, size); close(fd); @@ -2105,31 +2108,31 @@ static void keyboard_handle_keymap(void *data, CLOG_INFO(LOG, 2, "keymap"); /* In practice we can assume `xkb_state_new` always succeeds. */ - xkb_state_unref(input->xkb_state); - input->xkb_state = xkb_state_new(keymap); + xkb_state_unref(seat->xkb_state); + seat->xkb_state = xkb_state_new(keymap); - xkb_state_unref(input->xkb_state_empty); - input->xkb_state_empty = xkb_state_new(keymap); + xkb_state_unref(seat->xkb_state_empty); + seat->xkb_state_empty = xkb_state_new(keymap); - xkb_state_unref(input->xkb_state_empty_with_numlock); - input->xkb_state_empty_with_numlock = nullptr; + xkb_state_unref(seat->xkb_state_empty_with_numlock); + seat->xkb_state_empty_with_numlock = nullptr; { const xkb_mod_index_t mod2 = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); const xkb_mod_index_t num = xkb_keymap_mod_get_index(keymap, "NumLock"); if (num != XKB_MOD_INVALID && mod2 != XKB_MOD_INVALID) { - input->xkb_state_empty_with_numlock = xkb_state_new(keymap); + seat->xkb_state_empty_with_numlock = xkb_state_new(keymap); xkb_state_update_mask( - input->xkb_state_empty_with_numlock, (1 << mod2), 0, (1 << num), 0, 0, 0); + seat->xkb_state_empty_with_numlock, (1 << mod2), 0, (1 << num), 0, 0, 0); } } - input->xkb_keymap_mod_index.shift = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_SHIFT); - input->xkb_keymap_mod_index.caps = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CAPS); - input->xkb_keymap_mod_index.ctrl = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CTRL); - input->xkb_keymap_mod_index.alt = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_ALT); - input->xkb_keymap_mod_index.num = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); - input->xkb_keymap_mod_index.logo = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_LOGO); + seat->xkb_keymap_mod_index.shift = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_SHIFT); + seat->xkb_keymap_mod_index.caps = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CAPS); + seat->xkb_keymap_mod_index.ctrl = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CTRL); + seat->xkb_keymap_mod_index.alt = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_ALT); + seat->xkb_keymap_mod_index.num = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); + seat->xkb_keymap_mod_index.logo = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_LOGO); xkb_keymap_unref(keymap); } @@ -2137,41 +2140,40 @@ static void keyboard_handle_keymap(void *data, /** * Enter event. * - * Notification that this seat's keyboard focus is on a certain - * surface. + * Notification that this seat's keyboard focus is on a certain wl_surface. */ static void keyboard_handle_enter(void *data, struct wl_keyboard * /*wl_keyboard*/, const uint32_t serial, - struct wl_surface *surface, + struct wl_surface *wl_surface, struct wl_array *keys) { - if (!ghost_wl_surface_own(surface)) { + if (!ghost_wl_surface_own(wl_surface)) { CLOG_INFO(LOG, 2, "enter (skipped)"); return; } CLOG_INFO(LOG, 2, "enter"); - input_t *input = static_cast(data); - input->keyboard.serial = serial; - input->keyboard.wl_surface = surface; + GWL_Seat *seat = static_cast(data); + seat->keyboard.serial = serial; + seat->keyboard.wl_surface = wl_surface; if (keys->size != 0) { /* If there are any keys held when activating the window, - * modifiers will be compared against the input state, + * modifiers will be compared against the seat state, * only enabling modifiers that were previously disabled. */ - const xkb_mod_mask_t state = xkb_state_serialize_mods(input->xkb_state, XKB_STATE_MODS_ALL); + const xkb_mod_mask_t state = xkb_state_serialize_mods(seat->xkb_state, XKB_STATE_MODS_ALL); uint32_t *key; WL_ARRAY_FOR_EACH (key, keys) { const xkb_keycode_t key_code = *key + EVDEV_OFFSET; - const xkb_keysym_t sym = xkb_state_key_get_one_sym(input->xkb_state, key_code); + const xkb_keysym_t sym = xkb_state_key_get_one_sym(seat->xkb_state, key_code); GHOST_TKey gkey = GHOST_kKeyUnknown; #define MOD_TEST(state, mod) ((mod != XKB_MOD_INVALID) && (state & (1 << mod))) #define MOD_TEST_CASE(xkb_key, ghost_key, mod_index) \ case xkb_key: \ - if (!MOD_TEST(state, input->xkb_keymap_mod_index.mod_index)) { \ + if (!MOD_TEST(state, seat->xkb_keymap_mod_index.mod_index)) { \ gkey = ghost_key; \ } \ break @@ -2191,9 +2193,9 @@ static void keyboard_handle_enter(void *data, #undef MOD_TEST_CASE if (gkey != GHOST_kKeyUnknown) { - GHOST_IWindow *win = ghost_wl_surface_user_data(surface); - GHOST_SystemWayland *system = input->system; - input->system->pushEvent( + GHOST_IWindow *win = ghost_wl_surface_user_data(wl_surface); + GHOST_SystemWayland *system = seat->system; + seat->system->pushEvent( new GHOST_EventKey(system->getMilliSeconds(), GHOST_kEventKeyDown, win, gkey, false)); } } @@ -2203,26 +2205,25 @@ static void keyboard_handle_enter(void *data, /** * Leave event. * - * Notification that this seat's keyboard focus is no longer on a - * certain surface. + * Notification that this seat's keyboard focus is no longer on a certain wl_surface. */ static void keyboard_handle_leave(void *data, struct wl_keyboard * /*wl_keyboard*/, const uint32_t /*serial*/, - struct wl_surface *surface) + struct wl_surface *wl_surface) { - if (!(surface && ghost_wl_surface_own(surface))) { + if (!(wl_surface && ghost_wl_surface_own(wl_surface))) { CLOG_INFO(LOG, 2, "leave (skipped)"); return; } CLOG_INFO(LOG, 2, "leave"); - input_t *input = static_cast(data); - input->keyboard.wl_surface = nullptr; + GWL_Seat *seat = static_cast(data); + seat->keyboard.wl_surface = nullptr; /* Losing focus must stop repeating text. */ - if (input->key_repeat.timer) { - keyboard_handle_key_repeat_cancel(input); + if (seat->key_repeat.timer) { + keyboard_handle_key_repeat_cancel(seat); } } @@ -2256,12 +2257,12 @@ static xkb_keysym_t xkb_state_key_get_one_sym_without_modifiers( return sym; } -static void keyboard_handle_key_repeat_cancel(input_t *input) +static void keyboard_handle_key_repeat_cancel(GWL_Seat *seat) { - GHOST_ASSERT(input->key_repeat.timer != nullptr, "Caller much check for timer"); - delete static_cast(input->key_repeat.timer->getUserData()); - input->system->removeTimer(input->key_repeat.timer); - input->key_repeat.timer = nullptr; + GHOST_ASSERT(seat->key_repeat.timer != nullptr, "Caller much check for timer"); + delete static_cast(seat->key_repeat.timer->getUserData()); + seat->system->removeTimer(seat->key_repeat.timer); + seat->key_repeat.timer = nullptr; } /** @@ -2269,17 +2270,17 @@ static void keyboard_handle_key_repeat_cancel(input_t *input) * \param use_delay: When false, use the interval * (prevents pause when the setting changes while the key is held). */ -static void keyboard_handle_key_repeat_reset(input_t *input, const bool use_delay) +static void keyboard_handle_key_repeat_reset(GWL_Seat *seat, const bool use_delay) { - GHOST_ASSERT(input->key_repeat.timer != nullptr, "Caller much check for timer"); - GHOST_SystemWayland *system = input->system; - GHOST_ITimerTask *timer = input->key_repeat.timer; + GHOST_ASSERT(seat->key_repeat.timer != nullptr, "Caller much check for timer"); + GHOST_SystemWayland *system = seat->system; + GHOST_ITimerTask *timer = seat->key_repeat.timer; GHOST_TimerProcPtr key_repeat_fn = timer->getTimerProc(); - GHOST_TUserDataPtr payload = input->key_repeat.timer->getUserData(); - input->system->removeTimer(input->key_repeat.timer); - const uint64_t time_step = 1000 / input->key_repeat.rate; - const uint64_t time_start = use_delay ? input->key_repeat.delay : time_step; - input->key_repeat.timer = system->installTimer(time_start, time_step, key_repeat_fn, payload); + GHOST_TUserDataPtr payload = seat->key_repeat.timer->getUserData(); + seat->system->removeTimer(seat->key_repeat.timer); + const uint64_t time_step = 1000 / seat->key_repeat.rate; + const uint64_t time_start = use_delay ? seat->key_repeat.delay : time_step; + seat->key_repeat.timer = system->installTimer(time_start, time_step, key_repeat_fn, payload); } static void keyboard_handle_key(void *data, @@ -2289,11 +2290,11 @@ static void keyboard_handle_key(void *data, const uint32_t key, const uint32_t state) { - input_t *input = static_cast(data); + GWL_Seat *seat = static_cast(data); const xkb_keycode_t key_code = key + EVDEV_OFFSET; const xkb_keysym_t sym = xkb_state_key_get_one_sym_without_modifiers( - input->xkb_state_empty, input->xkb_state_empty_with_numlock, key_code); + seat->xkb_state_empty, seat->xkb_state_empty_with_numlock, key_code); if (sym == XKB_KEY_NoSymbol) { CLOG_INFO(LOG, 2, "key (no symbol, skipped)"); return; @@ -2310,15 +2311,15 @@ static void keyboard_handle_key(void *data, break; } - struct key_repeat_payload_t *key_repeat_payload = nullptr; + struct GWL_KeyRepeatPlayload *key_repeat_payload = nullptr; /* Delete previous timer. */ - if (input->key_repeat.timer) { + if (seat->key_repeat.timer) { enum { NOP = 1, RESET, CANCEL } timer_action = NOP; - key_repeat_payload = static_cast( - input->key_repeat.timer->getUserData()); + key_repeat_payload = static_cast( + seat->key_repeat.timer->getUserData()); - if (input->key_repeat.rate == 0) { + if (seat->key_repeat.rate == 0) { /* Repeat was disabled (unlikely but possible). */ timer_action = CANCEL; } @@ -2326,7 +2327,7 @@ static void keyboard_handle_key(void *data, /* Releasing the key that was held always cancels. */ timer_action = CANCEL; } - else if (xkb_keymap_key_repeats(xkb_state_get_keymap(input->xkb_state), key_code)) { + else if (xkb_keymap_key_repeats(xkb_state_get_keymap(seat->xkb_state), key_code)) { if (etype == GHOST_kEventKeyDown) { /* Any other key-down always cancels (and may start it's own repeat timer). */ timer_action = CANCEL; @@ -2349,16 +2350,16 @@ static void keyboard_handle_key(void *data, } case RESET: { /* The payload will be added again. */ - input->system->removeTimer(input->key_repeat.timer); - input->key_repeat.timer = nullptr; + seat->system->removeTimer(seat->key_repeat.timer); + seat->key_repeat.timer = nullptr; break; } case CANCEL: { delete key_repeat_payload; key_repeat_payload = nullptr; - input->system->removeTimer(input->key_repeat.timer); - input->key_repeat.timer = nullptr; + seat->system->removeTimer(seat->key_repeat.timer); + seat->key_repeat.timer = nullptr; break; } } @@ -2367,24 +2368,24 @@ static void keyboard_handle_key(void *data, const GHOST_TKey gkey = xkb_map_gkey_or_scan_code(sym, key); char utf8_buf[sizeof(GHOST_TEventKeyData::utf8_buf)] = {'\0'}; if (etype == GHOST_kEventKeyDown) { - xkb_state_key_get_utf8(input->xkb_state, key_code, utf8_buf, sizeof(utf8_buf)); + xkb_state_key_get_utf8(seat->xkb_state, key_code, utf8_buf, sizeof(utf8_buf)); } - input->data_source_serial = serial; + seat->data_source_serial = serial; - if (wl_surface *focus_surface = input->keyboard.wl_surface) { - GHOST_IWindow *win = ghost_wl_surface_user_data(focus_surface); - input->system->pushEvent( - new GHOST_EventKey(input->system->getMilliSeconds(), etype, win, gkey, false, utf8_buf)); + if (wl_surface *wl_surface_focus = seat->keyboard.wl_surface) { + GHOST_IWindow *win = ghost_wl_surface_user_data(wl_surface_focus); + seat->system->pushEvent( + new GHOST_EventKey(seat->system->getMilliSeconds(), etype, win, gkey, false, utf8_buf)); } /* An existing payload means the key repeat timer is reset and will be added again. */ if (key_repeat_payload == nullptr) { /* Start timer for repeating key, if applicable. */ - if ((input->key_repeat.rate > 0) && (etype == GHOST_kEventKeyDown) && - xkb_keymap_key_repeats(xkb_state_get_keymap(input->xkb_state), key_code)) { - key_repeat_payload = new key_repeat_payload_t({ - .input = input, + if ((seat->key_repeat.rate > 0) && (etype == GHOST_kEventKeyDown) && + xkb_keymap_key_repeats(xkb_state_get_keymap(seat->xkb_state), key_code)) { + key_repeat_payload = new GWL_KeyRepeatPlayload({ + .seat = seat, .key_code = key_code, .key_data = {.gkey = gkey}, }); @@ -2393,16 +2394,16 @@ static void keyboard_handle_key(void *data, if (key_repeat_payload) { auto key_repeat_fn = [](GHOST_ITimerTask *task, uint64_t /*time*/) { - struct key_repeat_payload_t *payload = static_cast( + struct GWL_KeyRepeatPlayload *payload = static_cast( task->getUserData()); - input_t *input = payload->input; - if (wl_surface *focus_surface = input->keyboard.wl_surface) { - GHOST_IWindow *win = ghost_wl_surface_user_data(focus_surface); - GHOST_SystemWayland *system = input->system; + GWL_Seat *seat = payload->seat; + if (wl_surface *wl_surface_focus = seat->keyboard.wl_surface) { + GHOST_IWindow *win = ghost_wl_surface_user_data(wl_surface_focus); + GHOST_SystemWayland *system = seat->system; /* Calculate this value every time in case modifier keys are pressed. */ char utf8_buf[sizeof(GHOST_TEventKeyData::utf8_buf)] = {'\0'}; - xkb_state_key_get_utf8(input->xkb_state, payload->key_code, utf8_buf, sizeof(utf8_buf)); + xkb_state_key_get_utf8(seat->xkb_state, payload->key_code, utf8_buf, sizeof(utf8_buf)); system->pushEvent(new GHOST_EventKey(system->getMilliSeconds(), GHOST_kEventKeyDown, win, @@ -2411,8 +2412,8 @@ static void keyboard_handle_key(void *data, utf8_buf)); } }; - input->key_repeat.timer = input->system->installTimer( - input->key_repeat.delay, 1000 / input->key_repeat.rate, key_repeat_fn, key_repeat_payload); + seat->key_repeat.timer = seat->system->installTimer( + seat->key_repeat.delay, 1000 / seat->key_repeat.rate, key_repeat_fn, key_repeat_payload); } } @@ -2432,13 +2433,13 @@ static void keyboard_handle_modifiers(void *data, mods_locked, group); - input_t *input = static_cast(data); - xkb_state_update_mask(input->xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); + GWL_Seat *seat = static_cast(data); + xkb_state_update_mask(seat->xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); /* A modifier changed so reset the timer, * see comment in #keyboard_handle_key regarding this behavior. */ - if (input->key_repeat.timer) { - keyboard_handle_key_repeat_reset(input, true); + if (seat->key_repeat.timer) { + keyboard_handle_key_repeat_reset(seat, true); } } @@ -2449,13 +2450,13 @@ static void keyboard_repeat_handle_info(void *data, { CLOG_INFO(LOG, 2, "info (rate=%d, delay=%d)", rate, delay); - input_t *input = static_cast(data); - input->key_repeat.rate = rate; - input->key_repeat.delay = delay; + GWL_Seat *seat = static_cast(data); + seat->key_repeat.rate = rate; + seat->key_repeat.delay = delay; /* Unlikely possible this setting changes while repeating. */ - if (input->key_repeat.timer) { - keyboard_handle_key_repeat_reset(input, false); + if (seat->key_repeat.timer) { + keyboard_handle_key_repeat_reset(seat, false); } } @@ -2490,35 +2491,35 @@ static void seat_handle_capabilities(void *data, (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) != 0, (capabilities & WL_SEAT_CAPABILITY_TOUCH) != 0); - input_t *input = static_cast(data); - input->wl_pointer = nullptr; - input->wl_keyboard = nullptr; + GWL_Seat *seat = static_cast(data); + seat->wl_pointer = nullptr; + seat->wl_keyboard = nullptr; if (capabilities & WL_SEAT_CAPABILITY_POINTER) { - input->wl_pointer = wl_seat_get_pointer(wl_seat); - input->cursor.wl_surface = wl_compositor_create_surface(input->system->compositor()); - input->cursor.visible = true; - input->cursor.wl_buffer = nullptr; - if (!get_cursor_settings(input->cursor.theme_name, input->cursor.size)) { - input->cursor.theme_name = std::string(); - input->cursor.size = default_cursor_size; + seat->wl_pointer = wl_seat_get_pointer(wl_seat); + seat->cursor.wl_surface = wl_compositor_create_surface(seat->system->compositor()); + seat->cursor.visible = true; + seat->cursor.wl_buffer = nullptr; + if (!get_cursor_settings(seat->cursor.theme_name, seat->cursor.size)) { + seat->cursor.theme_name = std::string(); + seat->cursor.size = default_cursor_size; } - wl_pointer_add_listener(input->wl_pointer, &pointer_listener, data); + wl_pointer_add_listener(seat->wl_pointer, &pointer_listener, data); - wl_surface_add_listener(input->cursor.wl_surface, &cursor_surface_listener, data); - ghost_wl_surface_tag_cursor_pointer(input->cursor.wl_surface); + wl_surface_add_listener(seat->cursor.wl_surface, &cursor_surface_listener, data); + ghost_wl_surface_tag_cursor_pointer(seat->cursor.wl_surface); } if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) { - input->wl_keyboard = wl_seat_get_keyboard(wl_seat); - wl_keyboard_add_listener(input->wl_keyboard, &keyboard_listener, data); + seat->wl_keyboard = wl_seat_get_keyboard(wl_seat); + wl_keyboard_add_listener(seat->wl_keyboard, &keyboard_listener, data); } } static void seat_handle_name(void *data, struct wl_seat * /*wl_seat*/, const char *name) { CLOG_INFO(LOG, 2, "name (name=\"%s\")", name); - static_cast(data)->name = std::string(name); + static_cast(data)->name = std::string(name); } static const struct wl_seat_listener seat_listener = { @@ -2544,7 +2545,7 @@ static void xdg_output_handle_logical_position(void *data, { CLOG_INFO(LOG, 2, "logical_position [%d, %d]", x, y); - output_t *output = static_cast(data); + GWL_Output *output = static_cast(data); output->position_logical[0] = x; output->position_logical[1] = y; output->has_position_logical = true; @@ -2557,7 +2558,7 @@ static void xdg_output_handle_logical_size(void *data, { CLOG_INFO(LOG, 2, "logical_size [%d, %d]", width, height); - output_t *output = static_cast(data); + GWL_Output *output = static_cast(data); if (output->size_logical[0] != 0 && output->size_logical[1] != 0) { /* Original comment from SDL. */ /* FIXME(@flibit): GNOME has a bug where the logical size does not account for @@ -2589,7 +2590,7 @@ static void xdg_output_handle_done(void *data, struct zxdg_output_v1 * /*xdg_out CLOG_INFO(LOG, 2, "done"); /* NOTE: `xdg-output.done` events are deprecated and only apply below version 3 of the protocol. * `wl-output.done` event will be emitted in version 3 or higher. */ - output_t *output = static_cast(data); + GWL_Output *output = static_cast(data); if (zxdg_output_v1_get_version(output->xdg_output) < 3) { output_handle_done(data, output->wl_output); } @@ -2648,7 +2649,7 @@ static void output_handle_geometry(void *data, physical_width, physical_height); - output_t *output = static_cast(data); + GWL_Output *output = static_cast(data); output->transform = transform; output->make = std::string(make); output->model = std::string(model); @@ -2669,7 +2670,7 @@ static void output_handle_mode(void *data, } CLOG_INFO(LOG, 2, "mode (size=[%d, %d], flags=%u)", width, height, flags); - output_t *output = static_cast(data); + GWL_Output *output = static_cast(data); output->size_native[0] = width; output->size_native[1] = height; @@ -2693,7 +2694,7 @@ static void output_handle_done(void *data, struct wl_output * /*wl_output*/) { CLOG_INFO(LOG, 2, "done"); - output_t *output = static_cast(data); + GWL_Output *output = static_cast(data); int32_t size_native[2]; if (output->transform & WL_OUTPUT_TRANSFORM_90) { size_native[0] = output->size_native[1]; @@ -2721,7 +2722,7 @@ static void output_handle_done(void *data, struct wl_output * /*wl_output*/) static void output_handle_scale(void *data, struct wl_output * /*wl_output*/, const int32_t factor) { CLOG_INFO(LOG, 2, "scale"); - static_cast(data)->scale = factor; + static_cast(data)->scale = factor; if (window_manager) { for (GHOST_IWindow *iwin : window_manager->getWindows()) { @@ -2816,7 +2817,7 @@ static void global_handle_add(void *data, /* Log last since it can be noted if the interface was handled or not. */ bool found = true; - struct display_t *display = static_cast(data); + struct GWL_Display *display = static_cast(data); if (!strcmp(interface, wl_compositor_interface.name)) { display->compositor = static_cast( wl_registry_bind(wl_registry, name, &wl_compositor_interface, 3)); @@ -2837,14 +2838,14 @@ static void global_handle_add(void *data, else if (!strcmp(interface, zxdg_output_manager_v1_interface.name)) { display->xdg_output_manager = static_cast( wl_registry_bind(wl_registry, name, &zxdg_output_manager_v1_interface, 2)); - for (output_t *output : display->outputs) { + for (GWL_Output *output : display->outputs) { output->xdg_output = zxdg_output_manager_v1_get_xdg_output(display->xdg_output_manager, output->wl_output); zxdg_output_v1_add_listener(output->xdg_output, &xdg_output_listener, output); } } else if (!strcmp(interface, wl_output_interface.name)) { - output_t *output = new output_t; + GWL_Output *output = new GWL_Output; output->wl_output = static_cast( wl_registry_bind(wl_registry, name, &wl_output_interface, 2)); ghost_wl_output_tag(output->wl_output); @@ -2860,14 +2861,14 @@ static void global_handle_add(void *data, } } else if (!strcmp(interface, wl_seat_interface.name)) { - input_t *input = new input_t; - input->system = display->system; - input->xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - input->data_source = new data_source_t; - input->wl_seat = static_cast( + GWL_Seat *seat = new GWL_Seat; + seat->system = display->system; + seat->xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + seat->data_source = new GWL_DataSource; + seat->wl_seat = static_cast( wl_registry_bind(wl_registry, name, &wl_seat_interface, 5)); - display->inputs.push_back(input); - wl_seat_add_listener(input->wl_seat, &seat_listener, input); + display->seats.push_back(seat); + wl_seat_add_listener(seat->wl_seat, &seat_listener, seat); } else if (!strcmp(interface, wl_shm_interface.name)) { display->shm = static_cast( @@ -2933,7 +2934,7 @@ static const struct wl_registry_listener registry_listener = { * WAYLAND specific implementation of the #GHOST_System interface. * \{ */ -GHOST_SystemWayland::GHOST_SystemWayland() : GHOST_System(), d(new display_t) +GHOST_SystemWayland::GHOST_SystemWayland() : GHOST_System(), d(new GWL_Display) { wl_log_set_handler_client(ghost_wayland_log_handler); @@ -2969,18 +2970,17 @@ GHOST_SystemWayland::GHOST_SystemWayland() : GHOST_System(), d(new display_t) /* Register data device per seat for IPC between Wayland clients. */ if (d->data_device_manager) { - for (input_t *input : d->inputs) { - input->data_device = wl_data_device_manager_get_data_device(d->data_device_manager, - input->wl_seat); - wl_data_device_add_listener(input->data_device, &data_device_listener, input); + for (GWL_Seat *seat : d->seats) { + seat->data_device = wl_data_device_manager_get_data_device(d->data_device_manager, + seat->wl_seat); + wl_data_device_add_listener(seat->data_device, &data_device_listener, seat); } } if (d->tablet_manager) { - for (input_t *input : d->inputs) { - input->tablet_seat = zwp_tablet_manager_v2_get_tablet_seat(d->tablet_manager, - input->wl_seat); - zwp_tablet_seat_v2_add_listener(input->tablet_seat, &tablet_seat_listener, input); + for (GWL_Seat *seat : d->seats) { + seat->tablet_seat = zwp_tablet_manager_v2_get_tablet_seat(d->tablet_manager, seat->wl_seat); + zwp_tablet_seat_v2_add_listener(seat->tablet_seat, &tablet_seat_listener, seat); } } } @@ -3042,36 +3042,36 @@ bool GHOST_SystemWayland::setConsoleWindowState(GHOST_TConsoleWindowState /*acti GHOST_TSuccess GHOST_SystemWayland::getModifierKeys(GHOST_ModifierKeys &keys) const { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; + GWL_Seat *seat = d->seats[0]; bool val; /* NOTE: XKB doesn't differentiate between left/right modifiers * for it's internal modifier state storage. */ - const xkb_mod_mask_t state = xkb_state_serialize_mods(input->xkb_state, XKB_STATE_MODS_ALL); + const xkb_mod_mask_t state = xkb_state_serialize_mods(seat->xkb_state, XKB_STATE_MODS_ALL); #define MOD_TEST(state, mod) ((mod != XKB_MOD_INVALID) && (state & (1 << mod))) - val = MOD_TEST(state, input->xkb_keymap_mod_index.shift); + val = MOD_TEST(state, seat->xkb_keymap_mod_index.shift); keys.set(GHOST_kModifierKeyLeftShift, val); keys.set(GHOST_kModifierKeyRightShift, val); - val = MOD_TEST(state, input->xkb_keymap_mod_index.alt); + val = MOD_TEST(state, seat->xkb_keymap_mod_index.alt); keys.set(GHOST_kModifierKeyLeftAlt, val); keys.set(GHOST_kModifierKeyRightAlt, val); - val = MOD_TEST(state, input->xkb_keymap_mod_index.ctrl); + val = MOD_TEST(state, seat->xkb_keymap_mod_index.ctrl); keys.set(GHOST_kModifierKeyLeftControl, val); keys.set(GHOST_kModifierKeyRightControl, val); - val = MOD_TEST(state, input->xkb_keymap_mod_index.logo); + val = MOD_TEST(state, seat->xkb_keymap_mod_index.logo); keys.set(GHOST_kModifierKeyOS, val); - val = MOD_TEST(state, input->xkb_keymap_mod_index.num); + val = MOD_TEST(state, seat->xkb_keymap_mod_index.num); keys.set(GHOST_kModifierKeyNum, val); #undef MOD_TEST @@ -3081,16 +3081,16 @@ GHOST_TSuccess GHOST_SystemWayland::getModifierKeys(GHOST_ModifierKeys &keys) co GHOST_TSuccess GHOST_SystemWayland::getButtons(GHOST_Buttons &buttons) const { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; - input_state_pointer_t *input_state = input_state_pointer_active(input); - if (!input_state) { + GWL_Seat *seat = d->seats[0]; + GWL_SeatStatePointer *seat_state_pointer = seat_state_pointer_active(seat); + if (!seat_state_pointer) { return GHOST_kFailure; } - buttons = input_state->buttons; + buttons = seat_state_pointer->buttons; return GHOST_kSuccess; } @@ -3103,15 +3103,15 @@ char *GHOST_SystemWayland::getClipboard(bool /*selection*/) const void GHOST_SystemWayland::putClipboard(const char *buffer, bool /*selection*/) const { - if (UNLIKELY(!d->data_device_manager || d->inputs.empty())) { + if (UNLIKELY(!d->data_device_manager || d->seats.empty())) { return; } - input_t *input = d->inputs[0]; + GWL_Seat *seat = d->seats[0]; - std::lock_guard lock{input->data_source_mutex}; + std::lock_guard lock{seat->data_source_mutex}; - data_source_t *data_source = input->data_source; + GWL_DataSource *data_source = seat->data_source; /* Copy buffer. */ free(data_source->buffer_out); @@ -3121,15 +3121,15 @@ void GHOST_SystemWayland::putClipboard(const char *buffer, bool /*selection*/) c data_source->data_source = wl_data_device_manager_create_data_source(d->data_device_manager); - wl_data_source_add_listener(data_source->data_source, &data_source_listener, input); + wl_data_source_add_listener(data_source->data_source, &data_source_listener, seat); for (const std::string &type : mime_send) { wl_data_source_offer(data_source->data_source, type.c_str()); } - if (input->data_device) { + if (seat->data_device) { wl_data_device_set_selection( - input->data_device, data_source->data_source, input->data_source_serial); + seat->data_device, data_source->data_source, seat->data_source_serial); } } @@ -3139,18 +3139,18 @@ uint8_t GHOST_SystemWayland::getNumDisplays() const } static GHOST_TSuccess getCursorPositionClientRelative_impl( - const input_state_pointer_t *input_state, + const GWL_SeatStatePointer *seat_state_pointer, const GHOST_WindowWayland *win, int32_t &x, int32_t &y) { const wl_fixed_t scale = win->scale(); - x = wl_fixed_to_int(scale * input_state->xy[0]); - y = wl_fixed_to_int(scale * input_state->xy[1]); + x = wl_fixed_to_int(scale * seat_state_pointer->xy[0]); + y = wl_fixed_to_int(scale * seat_state_pointer->xy[1]); return GHOST_kSuccess; } -static GHOST_TSuccess setCursorPositionClientRelative_impl(input_t *input, +static GHOST_TSuccess setCursorPositionClientRelative_impl(GWL_Seat *seat, GHOST_WindowWayland *win, const int32_t x, const int32_t y) @@ -3158,7 +3158,7 @@ static GHOST_TSuccess setCursorPositionClientRelative_impl(input_t *input, /* NOTE: WAYLAND doesn't support warping the cursor. * However when grab is enabled, we already simulate a cursor location * so that can be set to a new location. */ - if (!input->relative_pointer) { + if (!seat->relative_pointer) { return GHOST_kFailure; } const wl_fixed_t scale = win->scale(); @@ -3168,7 +3168,7 @@ static GHOST_TSuccess setCursorPositionClientRelative_impl(input_t *input, }; /* As the cursor was "warped" generate an event at the new location. */ - relative_pointer_handle_relative_motion_impl(input, win, xy_next); + relative_pointer_handle_relative_motion_impl(seat, win, xy_next); return GHOST_kSuccess; } @@ -3177,60 +3177,60 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorPositionClientRelative(const GHOST_ int32_t &x, int32_t &y) const { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; - input_state_pointer_t *input_state = input_state_pointer_active(input); - if (!input_state || !input_state->wl_surface) { + GWL_Seat *seat = d->seats[0]; + GWL_SeatStatePointer *seat_state_pointer = seat_state_pointer_active(seat); + if (!seat_state_pointer || !seat_state_pointer->wl_surface) { return GHOST_kFailure; } const GHOST_WindowWayland *win = static_cast(window); - return getCursorPositionClientRelative_impl(input_state, win, x, y); + return getCursorPositionClientRelative_impl(seat_state_pointer, win, x, y); } GHOST_TSuccess GHOST_SystemWayland::setCursorPositionClientRelative(GHOST_IWindow *window, const int32_t x, const int32_t y) { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; + GWL_Seat *seat = d->seats[0]; GHOST_WindowWayland *win = static_cast(window); - return setCursorPositionClientRelative_impl(input, win, x, y); + return setCursorPositionClientRelative_impl(seat, win, x, y); } GHOST_TSuccess GHOST_SystemWayland::getCursorPosition(int32_t &x, int32_t &y) const { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; - input_state_pointer_t *input_state = input_state_pointer_active(input); - if (!input_state) { + GWL_Seat *seat = d->seats[0]; + GWL_SeatStatePointer *seat_state_pointer = seat_state_pointer_active(seat); + if (!seat_state_pointer) { return GHOST_kFailure; } - if (wl_surface *focus_surface = input_state->wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - return getCursorPositionClientRelative_impl(input_state, win, x, y); + if (wl_surface *wl_surface_focus = seat_state_pointer->wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + return getCursorPositionClientRelative_impl(seat_state_pointer, win, x, y); } return GHOST_kFailure; } GHOST_TSuccess GHOST_SystemWayland::setCursorPosition(const int32_t x, const int32_t y) { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; + GWL_Seat *seat = d->seats[0]; /* Intentionally different from `getCursorPosition` which supports both tablet & pointer. * In the case of setting the cursor location, tablets don't support this. */ - if (wl_surface *focus_surface = input->pointer.wl_surface) { - GHOST_WindowWayland *win = ghost_wl_surface_user_data(focus_surface); - return setCursorPositionClientRelative_impl(input, win, x, y); + if (wl_surface *wl_surface_focus = seat->pointer.wl_surface) { + GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface_focus); + return setCursorPositionClientRelative_impl(seat, win, x, y); } return GHOST_kFailure; } @@ -3250,7 +3250,7 @@ void GHOST_SystemWayland::getAllDisplayDimensions(uint32_t &width, uint32_t &hei int32_t xy_min[2] = {INT32_MAX, INT32_MAX}; int32_t xy_max[2] = {INT32_MIN, INT32_MIN}; - for (const output_t *output : d->outputs) { + for (const GWL_Output *output : d->outputs) { int32_t xy[2] = {0, 0}; if (output->has_position_logical) { xy[0] = output->position_logical[0]; @@ -3395,32 +3395,32 @@ GHOST_IWindow *GHOST_SystemWayland::createWindow(const char *title, * Show the buffer defined by #cursor_buffer_set without changing anything else, * so #cursor_buffer_hide can be used to display it again. * - * The caller is responsible for setting `input->cursor.visible`. + * The caller is responsible for setting `seat->cursor.visible`. */ -static void cursor_buffer_show(const input_t *input) +static void cursor_buffer_show(const GWL_Seat *seat) { - const cursor_t *c = &input->cursor; + const GWL_Cursor *c = &seat->cursor; - if (input->wl_pointer) { - const int scale = c->is_custom ? c->custom_scale : input->pointer.theme_scale; + if (seat->wl_pointer) { + const int scale = c->is_custom ? c->custom_scale : seat->pointer.theme_scale; const int32_t hotspot_x = int32_t(c->wl_image.hotspot_x) / scale; const int32_t hotspot_y = int32_t(c->wl_image.hotspot_y) / scale; - if (input->wl_pointer) { + if (seat->wl_pointer) { wl_pointer_set_cursor( - input->wl_pointer, input->pointer.serial, c->wl_surface, hotspot_x, hotspot_y); + seat->wl_pointer, seat->pointer.serial, c->wl_surface, hotspot_x, hotspot_y); } } - if (!input->tablet_tools.empty()) { - const int scale = c->is_custom ? c->custom_scale : input->tablet.theme_scale; + if (!seat->tablet_tools.empty()) { + const int scale = c->is_custom ? c->custom_scale : seat->tablet.theme_scale; const int32_t hotspot_x = int32_t(c->wl_image.hotspot_x) / scale; const int32_t hotspot_y = int32_t(c->wl_image.hotspot_y) / scale; - for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : input->tablet_tools) { - tablet_tool_input_t *tool_input = static_cast( + for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : seat->tablet_tools) { + GWL_TabletTool *tablet_tool = static_cast( zwp_tablet_tool_v2_get_user_data(zwp_tablet_tool_v2)); zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, - input->tablet.serial, - tool_input->cursor_surface, + seat->tablet.serial, + tablet_tool->wl_surface_cursor, hotspot_x, hotspot_y); } @@ -3431,13 +3431,13 @@ static void cursor_buffer_show(const input_t *input) * Hide the buffer defined by #cursor_buffer_set without changing anything else, * so #cursor_buffer_show can be used to display it again. * - * The caller is responsible for setting `input->cursor.visible`. + * The caller is responsible for setting `seat->cursor.visible`. */ -static void cursor_buffer_hide(const input_t *input) +static void cursor_buffer_hide(const GWL_Seat *seat) { - wl_pointer_set_cursor(input->wl_pointer, input->pointer.serial, nullptr, 0, 0); - for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : input->tablet_tools) { - zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, input->tablet.serial, nullptr, 0, 0); + wl_pointer_set_cursor(seat->wl_pointer, seat->pointer.serial, nullptr, 0, 0); + for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : seat->tablet_tools) { + zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, seat->tablet.serial, nullptr, 0, 0); } } @@ -3458,12 +3458,12 @@ static int cursor_buffer_compatible_scale_from_image(const struct wl_cursor_imag return scale; } -static void cursor_buffer_set_surface_impl(const input_t *input, +static void cursor_buffer_set_surface_impl(const GWL_Seat *seat, wl_buffer *buffer, struct wl_surface *wl_surface, const int scale) { - const wl_cursor_image *wl_image = &input->cursor.wl_image; + const wl_cursor_image *wl_image = &seat->cursor.wl_image; const int32_t image_size_x = int32_t(wl_image->width); const int32_t image_size_y = int32_t(wl_image->height); GHOST_ASSERT((image_size_x % scale) == 0 && (image_size_y % scale) == 0, @@ -3475,40 +3475,40 @@ static void cursor_buffer_set_surface_impl(const input_t *input, wl_surface_commit(wl_surface); } -static void cursor_buffer_set(const input_t *input, wl_buffer *buffer) +static void cursor_buffer_set(const GWL_Seat *seat, wl_buffer *buffer) { - const cursor_t *c = &input->cursor; - const wl_cursor_image *wl_image = &input->cursor.wl_image; + const GWL_Cursor *c = &seat->cursor; + const wl_cursor_image *wl_image = &seat->cursor.wl_image; const bool visible = (c->visible && c->is_hardware); /* This is a requirement of WAYLAND, when this isn't the case, * it causes Blender's window to close intermittently. */ - if (input->wl_pointer) { + if (seat->wl_pointer) { const int scale = cursor_buffer_compatible_scale_from_image( - wl_image, c->is_custom ? c->custom_scale : input->pointer.theme_scale); + wl_image, c->is_custom ? c->custom_scale : seat->pointer.theme_scale); const int32_t hotspot_x = int32_t(wl_image->hotspot_x) / scale; const int32_t hotspot_y = int32_t(wl_image->hotspot_y) / scale; - cursor_buffer_set_surface_impl(input, buffer, c->wl_surface, scale); - wl_pointer_set_cursor(input->wl_pointer, - input->pointer.serial, + cursor_buffer_set_surface_impl(seat, buffer, c->wl_surface, scale); + wl_pointer_set_cursor(seat->wl_pointer, + seat->pointer.serial, visible ? c->wl_surface : nullptr, hotspot_x, hotspot_y); } /* Set the cursor for all tablet tools as well. */ - if (!input->tablet_tools.empty()) { + if (!seat->tablet_tools.empty()) { const int scale = cursor_buffer_compatible_scale_from_image( - wl_image, c->is_custom ? c->custom_scale : input->tablet.theme_scale); + wl_image, c->is_custom ? c->custom_scale : seat->tablet.theme_scale); const int32_t hotspot_x = int32_t(wl_image->hotspot_x) / scale; const int32_t hotspot_y = int32_t(wl_image->hotspot_y) / scale; - for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : input->tablet_tools) { - tablet_tool_input_t *tool_input = static_cast( + for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : seat->tablet_tools) { + GWL_TabletTool *tablet_tool = static_cast( zwp_tablet_tool_v2_get_user_data(zwp_tablet_tool_v2)); - cursor_buffer_set_surface_impl(input, buffer, tool_input->cursor_surface, scale); + cursor_buffer_set_surface_impl(seat, buffer, tablet_tool->wl_surface_cursor, scale); zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, - input->tablet.serial, - visible ? tool_input->cursor_surface : nullptr, + seat->tablet.serial, + visible ? tablet_tool->wl_surface_cursor : nullptr, hotspot_x, hotspot_y); } @@ -3521,12 +3521,12 @@ enum eCursorSetMode { CURSOR_VISIBLE_ONLY_SHOW, }; -static void cursor_visible_set(input_t *input, +static void cursor_visible_set(GWL_Seat *seat, const bool visible, const bool is_hardware, const enum eCursorSetMode set_mode) { - cursor_t *cursor = &input->cursor; + GWL_Cursor *cursor = &seat->cursor; const bool was_visible = cursor->is_hardware && cursor->visible; const bool use_visible = is_hardware && visible; @@ -3546,12 +3546,12 @@ static void cursor_visible_set(input_t *input, if (use_visible) { if (!was_visible) { - cursor_buffer_show(input); + cursor_buffer_show(seat); } } else { if (was_visible) { - cursor_buffer_hide(input); + cursor_buffer_hide(seat); } } cursor->visible = visible; @@ -3577,7 +3577,7 @@ static bool cursor_is_software(const GHOST_TGrabCursorMode mode, const bool use_ GHOST_TSuccess GHOST_SystemWayland::setCursorShape(const GHOST_TStandardCursor shape) { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } auto cursor_find = cursors.find(shape); @@ -3585,13 +3585,12 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorShape(const GHOST_TStandardCursor s cursors.at(GHOST_kStandardCursorDefault) : (*cursor_find).second; - input_t *input = d->inputs[0]; - cursor_t *c = &input->cursor; + GWL_Seat *seat = d->seats[0]; + GWL_Cursor *c = &seat->cursor; if (!c->wl_theme) { - /* The cursor surface hasn't entered an output yet. Initialize theme with scale 1. */ - c->wl_theme = wl_cursor_theme_load( - c->theme_name.c_str(), c->size, d->inputs[0]->system->shm()); + /* The cursor wl_surface hasn't entered an output yet. Initialize theme with scale 1. */ + c->wl_theme = wl_cursor_theme_load(c->theme_name.c_str(), c->size, d->seats[0]->system->shm()); } wl_cursor *cursor = wl_cursor_theme_get_cursor(c->wl_theme, cursor_name); @@ -3612,7 +3611,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorShape(const GHOST_TStandardCursor s c->wl_buffer = buffer; c->wl_image = *image; - cursor_buffer_set(input, buffer); + cursor_buffer_set(seat, buffer); return GHOST_kSuccess; } @@ -3638,11 +3637,11 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap, const int hotY, const bool /*canInvertColor*/) { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - cursor_t *cursor = &d->inputs[0]->cursor; + GWL_Cursor *cursor = &d->seats[0]->cursor; if (cursor->custom_data) { munmap(cursor->custom_data, cursor->custom_data_size); @@ -3698,14 +3697,14 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap, cursor->wl_image.hotspot_x = uint32_t(hotX); cursor->wl_image.hotspot_y = uint32_t(hotY); - cursor_buffer_set(d->inputs[0], buffer); + cursor_buffer_set(d->seats[0], buffer); return GHOST_kSuccess; } GHOST_TSuccess GHOST_SystemWayland::getCursorBitmap(GHOST_CursorBitmapRef *bitmap) { - cursor_t *cursor = &d->inputs[0]->cursor; + GWL_Cursor *cursor = &d->seats[0]->cursor; if (cursor->custom_data == nullptr) { return GHOST_kFailure; } @@ -3726,12 +3725,12 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorBitmap(GHOST_CursorBitmapRef *bitma GHOST_TSuccess GHOST_SystemWayland::setCursorVisibility(const bool visible) { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; - cursor_visible_set(input, visible, input->cursor.is_hardware, CURSOR_VISIBLE_ALWAYS_SET); + GWL_Seat *seat = d->seats[0]; + cursor_visible_set(seat, visible, seat->cursor.is_hardware, CURSOR_VISIBLE_ALWAYS_SET); return GHOST_kSuccess; } @@ -3750,13 +3749,13 @@ bool GHOST_SystemWayland::supportsWindowPosition() bool GHOST_SystemWayland::getCursorGrabUseSoftwareDisplay(const GHOST_TGrabCursorMode mode) { - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return false; } #ifdef USE_GNOME_CONFINE_HACK - input_t *input = d->inputs[0]; - const bool use_software_confine = input->use_pointer_software_confine; + GWL_Seat *seat = d->seats[0]; + const bool use_software_confine = seat->use_pointer_software_confine; #else const bool use_software_confine = false; #endif @@ -3766,7 +3765,7 @@ bool GHOST_SystemWayland::getCursorGrabUseSoftwareDisplay(const GHOST_TGrabCurso #ifdef USE_GNOME_CONFINE_HACK static bool setCursorGrab_use_software_confine(const GHOST_TGrabCursorMode mode, - wl_surface *surface) + wl_surface *wl_surface) { # ifndef USE_GNOME_CONFINE_HACK_ALWAYS_ON if (use_gnome_confine_hack == false) { @@ -3776,7 +3775,7 @@ static bool setCursorGrab_use_software_confine(const GHOST_TGrabCursorMode mode, if (mode != GHOST_kGrabNormal) { return false; } - const GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface); + const GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface); if (!win) { return false; } @@ -3790,11 +3789,11 @@ static bool setCursorGrab_use_software_confine(const GHOST_TGrabCursorMode mode, } #endif -static input_grab_state_t input_grab_state_from_mode(const GHOST_TGrabCursorMode mode, - const bool use_software_confine) +static GWL_SeatStateGrab seat_grab_state_from_mode(const GHOST_TGrabCursorMode mode, + const bool use_software_confine) { /* Initialize all members. */ - const struct input_grab_state_t grab_state = { + const struct GWL_SeatStateGrab grab_state = { /* Warping happens to require software cursor which also hides. */ .use_lock = ELEM(mode, GHOST_kGrabWrap, GHOST_kGrabHide) || use_software_confine, .use_confine = (mode == GHOST_kGrabNormal) && (use_software_confine == false), @@ -3813,44 +3812,45 @@ static const char *ghost_wl_surface_tag_id = "GHOST-window"; static const char *ghost_wl_surface_cursor_pointer_tag_id = "GHOST-cursor-pointer"; static const char *ghost_wl_surface_cursor_tablet_tag_id = "GHOST-cursor-tablet"; -bool ghost_wl_output_own(const struct wl_output *output) +bool ghost_wl_output_own(const struct wl_output *wl_output) { - return wl_proxy_get_tag((struct wl_proxy *)output) == &ghost_wl_output_tag_id; + return wl_proxy_get_tag((struct wl_proxy *)wl_output) == &ghost_wl_output_tag_id; } -bool ghost_wl_surface_own(const struct wl_surface *surface) +bool ghost_wl_surface_own(const struct wl_surface *wl_surface) { - return wl_proxy_get_tag((struct wl_proxy *)surface) == &ghost_wl_surface_tag_id; + return wl_proxy_get_tag((struct wl_proxy *)wl_surface) == &ghost_wl_surface_tag_id; } -bool ghost_wl_surface_own_cursor_pointer(const struct wl_surface *surface) +bool ghost_wl_surface_own_cursor_pointer(const struct wl_surface *wl_surface) { - return wl_proxy_get_tag((struct wl_proxy *)surface) == &ghost_wl_surface_cursor_pointer_tag_id; + return wl_proxy_get_tag((struct wl_proxy *)wl_surface) == + &ghost_wl_surface_cursor_pointer_tag_id; } -bool ghost_wl_surface_own_cursor_tablet(const struct wl_surface *surface) +bool ghost_wl_surface_own_cursor_tablet(const struct wl_surface *wl_surface) { - return wl_proxy_get_tag((struct wl_proxy *)surface) == &ghost_wl_surface_cursor_tablet_tag_id; + return wl_proxy_get_tag((struct wl_proxy *)wl_surface) == &ghost_wl_surface_cursor_tablet_tag_id; } -void ghost_wl_output_tag(struct wl_output *output) +void ghost_wl_output_tag(struct wl_output *wl_output) { - wl_proxy_set_tag((struct wl_proxy *)output, &ghost_wl_output_tag_id); + wl_proxy_set_tag((struct wl_proxy *)wl_output, &ghost_wl_output_tag_id); } -void ghost_wl_surface_tag(struct wl_surface *surface) +void ghost_wl_surface_tag(struct wl_surface *wl_surface) { - wl_proxy_set_tag((struct wl_proxy *)surface, &ghost_wl_surface_tag_id); + wl_proxy_set_tag((struct wl_proxy *)wl_surface, &ghost_wl_surface_tag_id); } -void ghost_wl_surface_tag_cursor_pointer(struct wl_surface *surface) +void ghost_wl_surface_tag_cursor_pointer(struct wl_surface *wl_surface) { - wl_proxy_set_tag((struct wl_proxy *)surface, &ghost_wl_surface_cursor_pointer_tag_id); + wl_proxy_set_tag((struct wl_proxy *)wl_surface, &ghost_wl_surface_cursor_pointer_tag_id); } -void ghost_wl_surface_tag_cursor_tablet(struct wl_surface *surface) +void ghost_wl_surface_tag_cursor_tablet(struct wl_surface *wl_surface) { - wl_proxy_set_tag((struct wl_proxy *)surface, &ghost_wl_surface_cursor_tablet_tag_id); + wl_proxy_set_tag((struct wl_proxy *)wl_surface, &ghost_wl_surface_cursor_tablet_tag_id); } /** \} */ @@ -3892,7 +3892,7 @@ zxdg_decoration_manager_v1 *GHOST_SystemWayland::xdg_decoration_manager() #endif /* !WITH_GHOST_WAYLAND_LIBDECOR */ -const std::vector &GHOST_SystemWayland::outputs() const +const std::vector &GHOST_SystemWayland::outputs() const { return d->outputs; } @@ -3908,19 +3908,20 @@ wl_shm *GHOST_SystemWayland::shm() const /** \name Public WAYLAND Query Access * \{ */ -struct output_t *ghost_wl_output_user_data(struct wl_output *wl_output) +struct GWL_Output *ghost_wl_output_user_data(struct wl_output *wl_output) { GHOST_ASSERT(wl_output, "output must not be NULL"); GHOST_ASSERT(ghost_wl_output_own(wl_output), "output is not owned by GHOST"); - output_t *output = static_cast(wl_output_get_user_data(wl_output)); + GWL_Output *output = static_cast(wl_output_get_user_data(wl_output)); return output; } -GHOST_WindowWayland *ghost_wl_surface_user_data(struct wl_surface *surface) +GHOST_WindowWayland *ghost_wl_surface_user_data(struct wl_surface *wl_surface) { - GHOST_ASSERT(surface, "surface must not be NULL"); - GHOST_ASSERT(ghost_wl_surface_own(surface), "surface is not owned by GHOST"); - GHOST_WindowWayland *win = static_cast(wl_surface_get_user_data(surface)); + GHOST_ASSERT(wl_surface, "wl_surface must not be NULL"); + GHOST_ASSERT(ghost_wl_surface_own(wl_surface), "wl_surface is not owned by GHOST"); + GHOST_WindowWayland *win = static_cast( + wl_surface_get_user_data(wl_surface)); return win; } @@ -3937,20 +3938,20 @@ void GHOST_SystemWayland::selection_set(const std::string &selection) this->selection = selection; } -void GHOST_SystemWayland::window_surface_unref(const wl_surface *surface) +void GHOST_SystemWayland::window_surface_unref(const wl_surface *wl_surface) { #define SURFACE_CLEAR_PTR(surface_test) \ - if (surface_test == surface) { \ + if (surface_test == wl_surface) { \ surface_test = nullptr; \ } \ ((void)0); /* Only clear window surfaces (not cursors, off-screen surfaces etc). */ - for (input_t *input : d->inputs) { - SURFACE_CLEAR_PTR(input->pointer.wl_surface); - SURFACE_CLEAR_PTR(input->tablet.wl_surface); - SURFACE_CLEAR_PTR(input->keyboard.wl_surface); - SURFACE_CLEAR_PTR(input->focus_dnd); + for (GWL_Seat *seat : d->seats) { + SURFACE_CLEAR_PTR(seat->pointer.wl_surface); + SURFACE_CLEAR_PTR(seat->tablet.wl_surface); + SURFACE_CLEAR_PTR(seat->keyboard.wl_surface); + SURFACE_CLEAR_PTR(seat->wl_surface_focus_dnd); } #undef SURFACE_CLEAR_PTR } @@ -3960,7 +3961,7 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod int32_t init_grab_xy[2], const GHOST_Rect *wrap_bounds, const GHOST_TAxisFlag wrap_axis, - wl_surface *surface, + wl_surface *wl_surface, const int scale) { /* Ignore, if the required protocols are not supported. */ @@ -3968,7 +3969,7 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod return GHOST_kFailure; } - if (UNLIKELY(d->inputs.empty())) { + if (UNLIKELY(d->seats.empty())) { return GHOST_kFailure; } /* No change, success. */ @@ -3976,20 +3977,20 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod return GHOST_kSuccess; } - input_t *input = d->inputs[0]; + GWL_Seat *seat = d->seats[0]; #ifdef USE_GNOME_CONFINE_HACK - const bool was_software_confine = input->use_pointer_software_confine; - const bool use_software_confine = setCursorGrab_use_software_confine(mode, surface); + const bool was_software_confine = seat->use_pointer_software_confine; + const bool use_software_confine = setCursorGrab_use_software_confine(mode, wl_surface); #else const bool was_software_confine = false; const bool use_software_confine = false; #endif - const struct input_grab_state_t grab_state_prev = input_grab_state_from_mode( - mode_current, was_software_confine); - const struct input_grab_state_t grab_state_next = input_grab_state_from_mode( - mode, use_software_confine); + const struct GWL_SeatStateGrab grab_state_prev = seat_grab_state_from_mode(mode_current, + was_software_confine); + const struct GWL_SeatStateGrab grab_state_next = seat_grab_state_from_mode(mode, + use_software_confine); /* Check for wrap as #supportsCursorWarp isn't supported. */ const bool use_visible = !(ELEM(mode, GHOST_kGrabHide, GHOST_kGrabWrap) || use_software_confine); @@ -3997,17 +3998,17 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod /* Only hide so the cursor is not made visible before it's location is restored. * This function is called again at the end of this function which only shows. */ - cursor_visible_set(input, use_visible, is_hardware_cursor, CURSOR_VISIBLE_ONLY_HIDE); + cursor_visible_set(seat, use_visible, is_hardware_cursor, CURSOR_VISIBLE_ONLY_HIDE); /* Switching from one grab mode to another, * in this case disable the current locks as it makes logic confusing, * postpone changing the cursor to avoid flickering. */ if (!grab_state_next.use_lock) { - if (input->relative_pointer) { - zwp_relative_pointer_v1_destroy(input->relative_pointer); - input->relative_pointer = nullptr; + if (seat->relative_pointer) { + zwp_relative_pointer_v1_destroy(seat->relative_pointer); + seat->relative_pointer = nullptr; } - if (input->locked_pointer) { + if (seat->locked_pointer) { /* Potentially add a motion event so the application has updated X/Y coordinates. */ int32_t xy_motion[2] = {0, 0}; bool xy_motion_create_event = false; @@ -4016,7 +4017,7 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod if (mode_current == GHOST_kGrabWrap) { /* Since this call is initiated by Blender, we can be sure the window wasn't closed * by logic outside this function - as the window was needed to make this call. */ - int32_t xy_next[2] = {UNPACK2(input->pointer.xy)}; + int32_t xy_next[2] = {UNPACK2(seat->pointer.xy)}; GHOST_Rect bounds_scale; @@ -4028,26 +4029,26 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod bounds_scale.wrapPoint(UNPACK2(xy_next), 0, wrap_axis); /* Push an event so the new location is registered. */ - if ((xy_next[0] != input->pointer.xy[0]) || (xy_next[1] != input->pointer.xy[1])) { + if ((xy_next[0] != seat->pointer.xy[0]) || (xy_next[1] != seat->pointer.xy[1])) { xy_motion[0] = xy_next[0]; xy_motion[1] = xy_next[1]; xy_motion_create_event = true; } - input->pointer.xy[0] = xy_next[0]; - input->pointer.xy[1] = xy_next[1]; + seat->pointer.xy[0] = xy_next[0]; + seat->pointer.xy[1] = xy_next[1]; - zwp_locked_pointer_v1_set_cursor_position_hint(input->locked_pointer, UNPACK2(xy_next)); - wl_surface_commit(surface); + zwp_locked_pointer_v1_set_cursor_position_hint(seat->locked_pointer, UNPACK2(xy_next)); + wl_surface_commit(wl_surface); } else if (mode_current == GHOST_kGrabHide) { - if ((init_grab_xy[0] != input->grab_lock_xy[0]) || - (init_grab_xy[1] != input->grab_lock_xy[1])) { + if ((init_grab_xy[0] != seat->grab_lock_xy[0]) || + (init_grab_xy[1] != seat->grab_lock_xy[1])) { const wl_fixed_t xy_next[2] = { wl_fixed_from_int(init_grab_xy[0]) / scale, wl_fixed_from_int(init_grab_xy[1]) / scale, }; - zwp_locked_pointer_v1_set_cursor_position_hint(input->locked_pointer, UNPACK2(xy_next)); - wl_surface_commit(surface); + zwp_locked_pointer_v1_set_cursor_position_hint(seat->locked_pointer, UNPACK2(xy_next)); + wl_surface_commit(wl_surface); /* NOTE(@campbellbarton): The new cursor position is a hint, * it's possible the hint is ignored. It doesn't seem like there is a good way to @@ -4060,31 +4061,31 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod #ifdef USE_GNOME_CONFINE_HACK else if (mode_current == GHOST_kGrabNormal) { if (was_software_confine) { - zwp_locked_pointer_v1_set_cursor_position_hint(input->locked_pointer, - UNPACK2(input->pointer.xy)); - wl_surface_commit(surface); + zwp_locked_pointer_v1_set_cursor_position_hint(seat->locked_pointer, + UNPACK2(seat->pointer.xy)); + wl_surface_commit(wl_surface); } } #endif if (xy_motion_create_event) { - input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(), - GHOST_kEventCursorMove, - ghost_wl_surface_user_data(surface), - wl_fixed_to_int(scale * xy_motion[0]), - wl_fixed_to_int(scale * xy_motion[1]), - GHOST_TABLET_DATA_NONE)); + seat->system->pushEvent(new GHOST_EventCursor(seat->system->getMilliSeconds(), + GHOST_kEventCursorMove, + ghost_wl_surface_user_data(wl_surface), + wl_fixed_to_int(scale * xy_motion[0]), + wl_fixed_to_int(scale * xy_motion[1]), + GHOST_TABLET_DATA_NONE)); } - zwp_locked_pointer_v1_destroy(input->locked_pointer); - input->locked_pointer = nullptr; + zwp_locked_pointer_v1_destroy(seat->locked_pointer); + seat->locked_pointer = nullptr; } } if (!grab_state_next.use_confine) { - if (input->confined_pointer) { - zwp_confined_pointer_v1_destroy(input->confined_pointer); - input->confined_pointer = nullptr; + if (seat->confined_pointer) { + zwp_confined_pointer_v1_destroy(seat->confined_pointer); + seat->confined_pointer = nullptr; } } @@ -4095,32 +4096,32 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod * possible to support #GHOST_kGrabWrap by pragmatically settings it's coordinates. * An alternative could be to draw the cursor in software (and hide the real cursor), * or just accept a locked cursor on WAYLAND. */ - input->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer( - d->relative_pointer_manager, input->wl_pointer); + seat->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer( + d->relative_pointer_manager, seat->wl_pointer); zwp_relative_pointer_v1_add_listener( - input->relative_pointer, &relative_pointer_listener, input); - input->locked_pointer = zwp_pointer_constraints_v1_lock_pointer( + seat->relative_pointer, &relative_pointer_listener, seat); + seat->locked_pointer = zwp_pointer_constraints_v1_lock_pointer( d->pointer_constraints, - surface, - input->wl_pointer, + wl_surface, + seat->wl_pointer, nullptr, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); } if (mode == GHOST_kGrabHide) { /* Set the initial position to detect any changes when un-grabbing, * otherwise the unlocked cursor defaults to un-locking in-place. */ - init_grab_xy[0] = wl_fixed_to_int(scale * input->pointer.xy[0]); - init_grab_xy[1] = wl_fixed_to_int(scale * input->pointer.xy[1]); - input->grab_lock_xy[0] = init_grab_xy[0]; - input->grab_lock_xy[1] = init_grab_xy[1]; + init_grab_xy[0] = wl_fixed_to_int(scale * seat->pointer.xy[0]); + init_grab_xy[1] = wl_fixed_to_int(scale * seat->pointer.xy[1]); + seat->grab_lock_xy[0] = init_grab_xy[0]; + seat->grab_lock_xy[1] = init_grab_xy[1]; } } else if (grab_state_next.use_confine) { if (!grab_state_prev.use_confine) { - input->confined_pointer = zwp_pointer_constraints_v1_confine_pointer( + seat->confined_pointer = zwp_pointer_constraints_v1_confine_pointer( d->pointer_constraints, - surface, - input->wl_pointer, + wl_surface, + seat->wl_pointer, nullptr, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); } @@ -4128,10 +4129,10 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod } /* Only show so the cursor is made visible as the last step. */ - cursor_visible_set(input, use_visible, is_hardware_cursor, CURSOR_VISIBLE_ONLY_SHOW); + cursor_visible_set(seat, use_visible, is_hardware_cursor, CURSOR_VISIBLE_ONLY_SHOW); #ifdef USE_GNOME_CONFINE_HACK - input->use_pointer_software_confine = use_software_confine; + seat->use_pointer_software_confine = use_software_confine; #endif return GHOST_kSuccess; diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h index f3b42de5a1b..caea7b0d748 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.h +++ b/intern/ghost/intern/GHOST_SystemWayland.h @@ -31,11 +31,11 @@ class GHOST_WindowWayland; -struct display_t; +struct GWL_Display; -bool ghost_wl_output_own(const struct wl_output *output); -void ghost_wl_output_tag(struct wl_output *output); -struct output_t *ghost_wl_output_user_data(struct wl_output *output); +bool ghost_wl_output_own(const struct wl_output *wl_output); +void ghost_wl_output_tag(struct wl_output *wl_output); +struct GWL_Output *ghost_wl_output_user_data(struct wl_output *wl_output); bool ghost_wl_surface_own(const struct wl_surface *surface); void ghost_wl_surface_tag(struct wl_surface *surface); @@ -55,7 +55,7 @@ void ghost_wl_surface_tag_cursor_tablet(struct wl_surface *surface); bool ghost_wl_dynload_libraries(); #endif -struct output_t { +struct GWL_Output { struct wl_output *wl_output = nullptr; struct zxdg_output_v1 *xdg_output = nullptr; /** Dimensions in pixels. */ @@ -173,7 +173,7 @@ class GHOST_SystemWayland : public GHOST_System { zxdg_decoration_manager_v1 *xdg_decoration_manager(); #endif - const std::vector &outputs() const; + const std::vector &outputs() const; wl_shm *shm() const; @@ -182,17 +182,17 @@ class GHOST_SystemWayland : public GHOST_System { void selection_set(const std::string &selection); /** Clear all references to this surface to prevent accessing NULL pointers. */ - void window_surface_unref(const wl_surface *surface); + void window_surface_unref(const wl_surface *wl_surface); bool window_cursor_grab_set(const GHOST_TGrabCursorMode mode, const GHOST_TGrabCursorMode mode_current, int32_t init_grab_xy[2], const GHOST_Rect *wrap_bounds, GHOST_TAxisFlag wrap_axis, - wl_surface *surface, + wl_surface *wl_surface, int scale); private: - struct display_t *d; + struct GWL_Display *d; std::string selection; }; diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp index d06ec872eca..5f3cb3e3f3a 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.cpp +++ b/intern/ghost/intern/GHOST_WindowWayland.cpp @@ -38,7 +38,7 @@ static constexpr size_t base_dpi = 96; static GHOST_WindowManager *window_manager = nullptr; -struct window_t { +struct GWL_Window { GHOST_WindowWayland *w = nullptr; struct wl_surface *wl_surface = nullptr; /** @@ -47,7 +47,7 @@ struct window_t { * This is an ordered set (whoever adds to this is responsible for keeping members unique). * In practice this is rarely manipulated and is limited by the number of physical displays. */ - std::vector outputs; + std::vector outputs; /** The scale value written to #wl_surface_set_buffer_scale. */ int scale = 0; @@ -87,7 +87,7 @@ struct window_t { /** * Return -1 if `output_a` has a scale smaller than `output_b`, 0 when there equal, otherwise 1. */ -static int output_scale_cmp(const output_t *output_a, const output_t *output_b) +static int output_scale_cmp(const GWL_Output *output_a, const GWL_Output *output_b) { if (output_a->scale < output_b->scale) { return -1; @@ -112,12 +112,12 @@ static int output_scale_cmp(const output_t *output_a, const output_t *output_b) return 0; } -static int outputs_max_scale_or_default(const std::vector &outputs, +static int outputs_max_scale_or_default(const std::vector &outputs, const int32_t scale_default, uint32_t *r_dpi) { - const output_t *output_max = nullptr; - for (const output_t *reg_output : outputs) { + const GWL_Output *output_max = nullptr; + for (const GWL_Output *reg_output : outputs) { if (!output_max || (output_scale_cmp(output_max, reg_output) == -1)) { output_max = reg_output; } @@ -160,7 +160,7 @@ static void xdg_toplevel_handle_configure(void *data, /* TODO: log `states`, not urgent. */ CLOG_INFO(LOG, 2, "configure (size=[%d, %d])", width, height); - window_t *win = static_cast(data); + GWL_Window *win = static_cast(data); win->size_pending[0] = win->scale * width; win->size_pending[1] = win->scale * height; @@ -189,7 +189,7 @@ static void xdg_toplevel_handle_configure(void *data, static void xdg_toplevel_handle_close(void *data, xdg_toplevel * /*xdg_toplevel*/) { CLOG_INFO(LOG, 2, "close"); - static_cast(data)->w->close(); + static_cast(data)->w->close(); } static const xdg_toplevel_listener toplevel_listener = { @@ -218,7 +218,7 @@ static void frame_handle_configure(struct libdecor_frame *frame, { CLOG_INFO(LOG, 2, "configure"); - window_t *win = static_cast(data); + GWL_Window *win = static_cast(data); int size_next[2]; enum libdecor_window_state window_state; @@ -257,7 +257,7 @@ static void frame_handle_close(struct libdecor_frame * /*frame*/, void *data) { CLOG_INFO(LOG, 2, "close"); - static_cast(data)->w->close(); + static_cast(data)->w->close(); } static void frame_handle_commit(struct libdecor_frame * /*frame*/, void *data) @@ -265,8 +265,8 @@ static void frame_handle_commit(struct libdecor_frame * /*frame*/, void *data) CLOG_INFO(LOG, 2, "commit"); /* We have to swap twice to keep any pop-up menus alive. */ - static_cast(data)->w->swapBuffers(); - static_cast(data)->w->swapBuffers(); + static_cast(data)->w->swapBuffers(); + static_cast(data)->w->swapBuffers(); } static struct libdecor_frame_interface libdecor_frame_iface = { @@ -296,7 +296,7 @@ static void xdg_toplevel_decoration_handle_configure( const uint32_t mode) { CLOG_INFO(LOG, 2, "configure (mode=%u)", mode); - static_cast(data)->decoration_mode = (zxdg_toplevel_decoration_v1_mode)mode; + static_cast(data)->decoration_mode = (zxdg_toplevel_decoration_v1_mode)mode; } static const zxdg_toplevel_decoration_v1_listener toplevel_decoration_v1_listener = { @@ -322,7 +322,7 @@ static void xdg_surface_handle_configure(void *data, xdg_surface *xdg_surface, const uint32_t serial) { - window_t *win = static_cast(data); + GWL_Window *win = static_cast(data); if (win->xdg_surface != xdg_surface) { CLOG_INFO(LOG, 2, "configure (skipped)"); @@ -369,15 +369,15 @@ static CLG_LogRef LOG_WL_SURFACE = {"ghost.wl.handle.surface"}; static void surface_handle_enter(void *data, struct wl_surface * /*wl_surface*/, - struct wl_output *output) + struct wl_output *wl_output) { - if (!ghost_wl_output_own(output)) { + if (!ghost_wl_output_own(wl_output)) { CLOG_INFO(LOG, 2, "enter (skipped)"); return; } CLOG_INFO(LOG, 2, "enter"); - output_t *reg_output = ghost_wl_output_user_data(output); + GWL_Output *reg_output = ghost_wl_output_user_data(wl_output); GHOST_WindowWayland *win = static_cast(data); if (win->outputs_enter(reg_output)) { win->outputs_changed_update_scale(); @@ -386,15 +386,15 @@ static void surface_handle_enter(void *data, static void surface_handle_leave(void *data, struct wl_surface * /*wl_surface*/, - struct wl_output *output) + struct wl_output *wl_output) { - if (!ghost_wl_output_own(output)) { + if (!ghost_wl_output_own(wl_output)) { CLOG_INFO(LOG, 2, "leave (skipped)"); return; } CLOG_INFO(LOG, 2, "leave"); - output_t *reg_output = ghost_wl_output_user_data(output); + GWL_Output *reg_output = ghost_wl_output_user_data(wl_output); GHOST_WindowWayland *win = static_cast(data); if (win->outputs_leave(reg_output)) { win->outputs_changed_update_scale(); @@ -435,7 +435,7 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system, const bool exclusive) : GHOST_Window(width, height, state, stereoVisual, exclusive), m_system(system), - w(new window_t) + w(new GWL_Window) { /* Globally store pointer to window manager. */ if (!window_manager) { @@ -877,12 +877,12 @@ int GHOST_WindowWayland::scale() const return w->scale; } -wl_surface *GHOST_WindowWayland::surface() const +wl_surface *GHOST_WindowWayland::wl_surface() const { return w->wl_surface; } -const std::vector &GHOST_WindowWayland::outputs() +const std::vector &GHOST_WindowWayland::outputs() { return w->outputs; } @@ -946,7 +946,7 @@ bool GHOST_WindowWayland::outputs_changed_update_scale() return false; } - window_t *win = this->w; + GWL_Window *win = this->w; const uint32_t dpi_curr = win->dpi; const int scale_curr = win->scale; bool changed = false; @@ -977,21 +977,21 @@ bool GHOST_WindowWayland::outputs_changed_update_scale() return changed; } -bool GHOST_WindowWayland::outputs_enter(output_t *reg_output) +bool GHOST_WindowWayland::outputs_enter(GWL_Output *output) { - std::vector &outputs = w->outputs; - auto it = std::find(outputs.begin(), outputs.end(), reg_output); + std::vector &outputs = w->outputs; + auto it = std::find(outputs.begin(), outputs.end(), output); if (it != outputs.end()) { return false; } - outputs.push_back(reg_output); + outputs.push_back(output); return true; } -bool GHOST_WindowWayland::outputs_leave(output_t *reg_output) +bool GHOST_WindowWayland::outputs_leave(GWL_Output *output) { - std::vector &outputs = w->outputs; - auto it = std::find(outputs.begin(), outputs.end(), reg_output); + std::vector &outputs = w->outputs; + auto it = std::find(outputs.begin(), outputs.end(), output); if (it == outputs.end()) { return false; } diff --git a/intern/ghost/intern/GHOST_WindowWayland.h b/intern/ghost/intern/GHOST_WindowWayland.h index c754e4cd9e7..9b4c17ecd95 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.h +++ b/intern/ghost/intern/GHOST_WindowWayland.h @@ -14,8 +14,8 @@ class GHOST_SystemWayland; -struct output_t; -struct window_t; +struct GWL_Output; +struct GWL_Window; class GHOST_WindowWayland : public GHOST_Window { public: @@ -97,8 +97,8 @@ class GHOST_WindowWayland : public GHOST_Window { uint16_t dpi() const; int scale() const; - struct wl_surface *surface() const; - const std::vector &outputs(); + struct wl_surface *wl_surface() const; + const std::vector &outputs(); /* WAYLAND window-level functions. */ @@ -109,14 +109,14 @@ class GHOST_WindowWayland : public GHOST_Window { /* WAYLAND utility functions. */ - bool outputs_enter(output_t *reg_output); - bool outputs_leave(output_t *reg_output); + bool outputs_enter(GWL_Output *output); + bool outputs_leave(GWL_Output *output); bool outputs_changed_update_scale(); private: GHOST_SystemWayland *m_system; - struct window_t *w; + struct GWL_Window *w; std::string title; /** -- cgit v1.2.3