src/video/wayland/SDL_waylandevents.c
changeset 8104 2e4f1bd21196
parent 8062 4fc5f66d63cc
child 8116 f7c2f71251e5
equal deleted inserted replaced
8103:d4a88c49247e 8104:2e4f1bd21196
    17   2. Altered source versions must be plainly marked as such, and must not be
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    20 */
    21 
    21 
    22 #include "SDL_config.h"
    22 #include "../../SDL_internal.h"
    23 
    23 
    24 #include "SDL_stdinc.h"
    24 #include "SDL_stdinc.h"
    25 #include "SDL_assert.h"
    25 #include "SDL_assert.h"
    26 
    26 
    27 #include "../../events/SDL_sysevents.h"
    27 #include "../../events/SDL_sysevents.h"
    29 #include "../../events/scancodes_xfree86.h"
    29 #include "../../events/scancodes_xfree86.h"
    30 
    30 
    31 #include "SDL_waylandvideo.h"
    31 #include "SDL_waylandvideo.h"
    32 #include "SDL_waylandevents_c.h"
    32 #include "SDL_waylandevents_c.h"
    33 #include "SDL_waylandwindow.h"
    33 #include "SDL_waylandwindow.h"
       
    34 
       
    35 #include "SDL_waylanddyn.h"
    34 
    36 
    35 #include <linux/input.h>
    37 #include <linux/input.h>
    36 #include <sys/select.h>
    38 #include <sys/select.h>
    37 #include <sys/mman.h>
    39 #include <sys/mman.h>
    38 #include <poll.h>
    40 #include <poll.h>
    58 Wayland_PumpEvents(_THIS)
    60 Wayland_PumpEvents(_THIS)
    59 {
    61 {
    60     SDL_VideoData *d = _this->driverdata;
    62     SDL_VideoData *d = _this->driverdata;
    61     struct pollfd pfd[1];
    63     struct pollfd pfd[1];
    62 
    64 
    63     pfd[0].fd = wl_display_get_fd(d->display);
    65     pfd[0].fd = WAYLAND_wl_display_get_fd(d->display);
    64     pfd[0].events = POLLIN;
    66     pfd[0].events = POLLIN;
    65     poll(pfd, 1, 0);
    67     poll(pfd, 1, 0);
    66 
    68 
    67     if (pfd[0].revents & POLLIN)
    69     if (pfd[0].revents & POLLIN)
    68         wl_display_dispatch(d->display);
    70         WAYLAND_wl_display_dispatch(d->display);
    69     else
    71     else
    70         wl_display_dispatch_pending(d->display);
    72         WAYLAND_wl_display_dispatch_pending(d->display);
    71 }
    73 }
    72 
    74 
    73 static void
    75 static void
    74 pointer_handle_enter(void *data, struct wl_pointer *pointer,
    76 pointer_handle_enter(void *data, struct wl_pointer *pointer,
    75                      uint32_t serial, struct wl_surface *surface,
    77                      uint32_t serial, struct wl_surface *surface,
   197     if (map_str == MAP_FAILED) {
   199     if (map_str == MAP_FAILED) {
   198         close(fd);
   200         close(fd);
   199         return;
   201         return;
   200     }
   202     }
   201 
   203 
   202     input->xkb.keymap = xkb_map_new_from_string(input->display->xkb_context,
   204     input->xkb.keymap = WAYLAND_xkb_keymap_new_from_string(input->display->xkb_context,
   203                                                 map_str,
   205                                                 map_str,
   204                                                 XKB_KEYMAP_FORMAT_TEXT_V1,
   206                                                 XKB_KEYMAP_FORMAT_TEXT_V1,
   205                                                 0);
   207                                                 0);
   206     munmap(map_str, size);
   208     munmap(map_str, size);
   207     close(fd);
   209     close(fd);
   209     if (!input->xkb.keymap) {
   211     if (!input->xkb.keymap) {
   210         fprintf(stderr, "failed to compile keymap\n");
   212         fprintf(stderr, "failed to compile keymap\n");
   211         return;
   213         return;
   212     }
   214     }
   213 
   215 
   214     input->xkb.state = xkb_state_new(input->xkb.keymap);
   216     input->xkb.state = WAYLAND_xkb_state_new(input->xkb.keymap);
   215     if (!input->xkb.state) {
   217     if (!input->xkb.state) {
   216         fprintf(stderr, "failed to create XKB state\n");
   218         fprintf(stderr, "failed to create XKB state\n");
   217         xkb_map_unref(input->xkb.keymap);
   219         WAYLAND_xkb_keymap_unref(input->xkb.keymap);
   218         input->xkb.keymap = NULL;
   220         input->xkb.keymap = NULL;
   219         return;
   221         return;
   220     }
   222     }
   221 }
   223 }
   222 
   224 
   264 
   266 
   265     if (!window || window->keyboard_device != input || !input->xkb.state)
   267     if (!window || window->keyboard_device != input || !input->xkb.state)
   266         return;
   268         return;
   267 
   269 
   268     // TODO can this happen?
   270     // TODO can this happen?
   269     if (xkb_key_get_syms(input->xkb.state, key + 8, &syms) != 1)
   271     if (WAYLAND_xkb_state_key_get_syms(input->xkb.state, key + 8, &syms) != 1)
   270         return;
   272         return;
   271 
   273 
   272     if (state) {
   274     if (state) {
   273         size = xkb_keysym_to_utf8(syms[0], text, sizeof text);
   275         size = WAYLAND_xkb_keysym_to_utf8(syms[0], text, sizeof text);
   274 
   276 
   275         if (size > 0) {
   277         if (size > 0) {
   276             text[size] = 0;
   278             text[size] = 0;
   277             SDL_SendKeyboardText(text);
   279             SDL_SendKeyboardText(text);
   278         }
   280         }
   285                           uint32_t mods_latched, uint32_t mods_locked,
   287                           uint32_t mods_latched, uint32_t mods_locked,
   286                           uint32_t group)
   288                           uint32_t group)
   287 {
   289 {
   288     struct SDL_WaylandInput *input = data;
   290     struct SDL_WaylandInput *input = data;
   289 
   291 
   290     xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
   292     WAYLAND_xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
   291                           mods_locked, 0, 0, group);
   293                           mods_locked, 0, 0, group);
   292 }
   294 }
   293 
   295 
   294 static const struct wl_keyboard_listener keyboard_listener = {
   296 static const struct wl_keyboard_listener keyboard_listener = {
   295     keyboard_handle_keymap,
   297     keyboard_handle_keymap,
   347     d->input = input;
   349     d->input = input;
   348 
   350 
   349     wl_seat_add_listener(input->seat, &seat_listener, input);
   351     wl_seat_add_listener(input->seat, &seat_listener, input);
   350     wl_seat_set_user_data(input->seat, input);
   352     wl_seat_set_user_data(input->seat, input);
   351 
   353 
   352     wayland_schedule_write(d);
   354     WAYLAND_wl_display_flush(d->display);
   353 }
   355 }
   354 
   356 
   355 void Wayland_display_destroy_input(SDL_VideoData *d)
   357 void Wayland_display_destroy_input(SDL_VideoData *d)
   356 {
   358 {
   357     struct SDL_WaylandInput *input = d->input;
   359     struct SDL_WaylandInput *input = d->input;
   367 
   369 
   368     if (input->seat)
   370     if (input->seat)
   369         wl_seat_destroy(input->seat);
   371         wl_seat_destroy(input->seat);
   370 
   372 
   371     if (input->xkb.state)
   373     if (input->xkb.state)
   372         xkb_state_unref(input->xkb.state);
   374         WAYLAND_xkb_state_unref(input->xkb.state);
   373 
   375 
   374     if (input->xkb.keymap)
   376     if (input->xkb.keymap)
   375         xkb_map_unref(input->xkb.keymap);
   377         WAYLAND_xkb_keymap_unref(input->xkb.keymap);
   376 
   378 
   377     free(input);
   379     free(input);
   378     d->input = NULL;
   380     d->input = NULL;
   379 }
   381 }
   380 
   382