init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
45
Telegram/ThirdParty/nimf/modules/services/wayland/Makefile.am
vendored
Normal file
45
Telegram/ThirdParty/nimf/modules/services/wayland/Makefile.am
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
moduledir = $(libdir)/nimf/modules/services
|
||||
module_LTLIBRARIES = libnimf-wayland.la
|
||||
|
||||
WAYLAND_IM_XML_PATH = `pkg-config --variable=pkgdatadir wayland-protocols`/unstable/input-method/input-method-unstable-v1.xml
|
||||
|
||||
BUILT_SOURCES = \
|
||||
input-method-unstable-v1-client-protocol.h \
|
||||
input-method-unstable-v1-protocol.c \
|
||||
$(NULL)
|
||||
|
||||
libnimf_wayland_la_SOURCES = \
|
||||
nimf-wayland.c \
|
||||
nimf-wayland-ic.c \
|
||||
nimf-wayland-ic.h \
|
||||
$(BUILT_SOURCES) \
|
||||
$(NULL)
|
||||
|
||||
libnimf_wayland_la_CFLAGS = \
|
||||
$(EXTRA_CFLAGS) \
|
||||
-I$(top_srcdir)/libnimf \
|
||||
-DG_LOG_DOMAIN=\"nimf\" \
|
||||
$(NIMF_WAYLAND_DEPS_CFLAGS)
|
||||
|
||||
libnimf_wayland_la_LDFLAGS = -avoid-version -module $(NIMF_WAYLAND_DEPS_LIBS)
|
||||
libnimf_wayland_la_LIBADD = $(top_builddir)/libnimf/libnimf.la
|
||||
|
||||
input-method-unstable-v1-client-protocol.h:
|
||||
$(AM_V_GEN) wayland-scanner client-header < $(WAYLAND_IM_XML_PATH) \
|
||||
> input-method-unstable-v1-client-protocol.h
|
||||
|
||||
input-method-unstable-v1-protocol.c:
|
||||
$(AM_V_GEN) wayland-scanner code < $(WAYLAND_IM_XML_PATH) \
|
||||
> input-method-unstable-v1-protocol.c
|
||||
|
||||
install-data-hook:
|
||||
chmod -x $(DESTDIR)$(moduledir)/libnimf-wayland.so
|
||||
rm -f $(DESTDIR)$(moduledir)/libnimf-wayland.la
|
||||
|
||||
uninstall-hook:
|
||||
rm -f $(DESTDIR)$(moduledir)/libnimf-wayland.so
|
||||
-rmdir -p $(DESTDIR)$(moduledir)
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
DISTCLEANFILES = Makefile.in
|
||||
105
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland-ic.c
vendored
Normal file
105
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland-ic.c
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-wayland-ic.c
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2017-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nimf-wayland-ic.h"
|
||||
#include "input-method-unstable-v1-client-protocol.h"
|
||||
|
||||
G_DEFINE_TYPE (NimfWaylandIC, nimf_wayland_ic, NIMF_TYPE_SERVICE_IC);
|
||||
|
||||
NimfWaylandIC *nimf_wayland_ic_new (NimfWayland *wayland)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWaylandIC *wic;
|
||||
|
||||
wic = g_object_new (NIMF_TYPE_WAYLAND_IC, NULL);
|
||||
wic->wayland = wayland;
|
||||
|
||||
return wic;
|
||||
}
|
||||
|
||||
void
|
||||
nimf_wayland_ic_emit_commit (NimfServiceIC *ic,
|
||||
const gchar *text)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = NIMF_WAYLAND_IC (ic)->wayland;
|
||||
|
||||
zwp_input_method_context_v1_commit_string (wayland->context,
|
||||
wayland->serial,
|
||||
text);
|
||||
}
|
||||
|
||||
void nimf_wayland_ic_emit_preedit_start (NimfServiceIC *ic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
void
|
||||
nimf_wayland_ic_emit_preedit_changed (NimfServiceIC *ic,
|
||||
const gchar *preedit_string,
|
||||
NimfPreeditAttr **attrs,
|
||||
gint cursor_pos)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = NIMF_WAYLAND_IC (ic)->wayland;
|
||||
|
||||
zwp_input_method_context_v1_preedit_cursor (wayland->context, cursor_pos);
|
||||
zwp_input_method_context_v1_preedit_string (wayland->context,
|
||||
wayland->serial, preedit_string, preedit_string);
|
||||
}
|
||||
|
||||
void nimf_wayland_ic_emit_preedit_end (NimfServiceIC *ic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_wayland_ic_init (NimfWaylandIC *wic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_wayland_ic_finalize (GObject *object)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
G_OBJECT_CLASS (nimf_wayland_ic_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_wayland_ic_class_init (NimfWaylandICClass *class)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
NimfServiceICClass *service_im_class = NIMF_SERVICE_IC_CLASS (class);
|
||||
|
||||
object_class->finalize = nimf_wayland_ic_finalize;
|
||||
|
||||
service_im_class->emit_commit = nimf_wayland_ic_emit_commit;
|
||||
service_im_class->emit_preedit_start = nimf_wayland_ic_emit_preedit_start;
|
||||
service_im_class->emit_preedit_changed = nimf_wayland_ic_emit_preedit_changed;
|
||||
service_im_class->emit_preedit_end = nimf_wayland_ic_emit_preedit_end;
|
||||
}
|
||||
59
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland-ic.h
vendored
Normal file
59
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland-ic.h
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-wayland-ic.h
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2017-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __NIMF_WAYLAND_IC_H__
|
||||
#define __NIMF_WAYLAND_IC_H__
|
||||
|
||||
#include "nimf.h"
|
||||
#include "nimf-wayland.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NIMF_TYPE_WAYLAND_IC (nimf_wayland_ic_get_type ())
|
||||
#define NIMF_WAYLAND_IC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NIMF_TYPE_WAYLAND_IC, NimfWaylandIC))
|
||||
#define NIMF_WAYLAND_IC_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), NIMF_TYPE_WAYLAND_IC, NimfWaylandICClass))
|
||||
#define NIMF_IS_WAYLAND_IC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NIMF_TYPE_WAYLAND_IC))
|
||||
#define NIMF_IS_WAYLAND_IC_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), NIMF_TYPE_WAYLAND_IC))
|
||||
#define NIMF_WAYLAND_IC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NIMF_TYPE_WAYLAND_IC, NimfWaylandICClass))
|
||||
|
||||
typedef struct _NimfWayland NimfWayland;
|
||||
|
||||
typedef struct _NimfWaylandIC NimfWaylandIC;
|
||||
typedef struct _NimfWaylandICClass NimfWaylandICClass;
|
||||
|
||||
struct _NimfWaylandICClass
|
||||
{
|
||||
NimfServiceICClass parent_class;
|
||||
};
|
||||
|
||||
struct _NimfWaylandIC
|
||||
{
|
||||
NimfServiceIC parent_instance;
|
||||
NimfWayland *wayland;
|
||||
};
|
||||
|
||||
GType nimf_wayland_ic_get_type (void) G_GNUC_CONST;
|
||||
NimfWaylandIC *nimf_wayland_ic_new (NimfWayland *wayland);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __NIMF_WAYLAND_IC_H__ */
|
||||
|
||||
621
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland.c
vendored
Normal file
621
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland.c
vendored
Normal file
@@ -0,0 +1,621 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-wayland.c
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2012 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "nimf-wayland-ic.h"
|
||||
#include "nimf-wayland.h"
|
||||
#include "nimf-service.h"
|
||||
|
||||
G_DEFINE_DYNAMIC_TYPE (NimfWayland, nimf_wayland, NIMF_TYPE_SERVICE);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GSource source;
|
||||
NimfWayland *wayland;
|
||||
GPollFD poll_fd;
|
||||
gboolean reading;
|
||||
} NimfWaylandEventSource;
|
||||
|
||||
static gboolean nimf_wayland_source_prepare (GSource *base,
|
||||
gint *timeout)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWaylandEventSource *source = (NimfWaylandEventSource *) base;
|
||||
|
||||
*timeout = -1;
|
||||
|
||||
if (source->reading)
|
||||
return FALSE;
|
||||
|
||||
if (wl_display_prepare_read (source->wayland->display) != 0)
|
||||
return TRUE;
|
||||
|
||||
source->reading = TRUE;
|
||||
|
||||
if (wl_display_flush (source->wayland->display) < 0)
|
||||
g_critical (G_STRLOC ": %s: wl_display_flush() failed: %s", G_STRFUNC,
|
||||
g_strerror (errno));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void nimf_wayland_stop (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = NIMF_WAYLAND (service);
|
||||
|
||||
if (!wayland->active)
|
||||
return;
|
||||
|
||||
if (wayland->event_source)
|
||||
{
|
||||
g_source_destroy (wayland->event_source);
|
||||
g_source_unref (wayland->event_source);
|
||||
}
|
||||
|
||||
wayland->active = FALSE;
|
||||
}
|
||||
|
||||
static gboolean nimf_wayland_source_check (GSource *base)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWaylandEventSource *source = (NimfWaylandEventSource *) base;
|
||||
|
||||
if (source->reading)
|
||||
{
|
||||
if (source->poll_fd.revents & G_IO_IN)
|
||||
{
|
||||
if (wl_display_read_events (source->wayland->display) < 0)
|
||||
{
|
||||
g_critical (G_STRLOC ": %s: wl_display_read_events() failed: %s",
|
||||
G_STRFUNC, g_strerror (errno));
|
||||
nimf_wayland_stop (NIMF_SERVICE (source->wayland));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wl_display_cancel_read (source->wayland->display);
|
||||
}
|
||||
|
||||
source->reading = FALSE;
|
||||
}
|
||||
|
||||
return source->poll_fd.revents;
|
||||
}
|
||||
|
||||
static gboolean nimf_wayland_source_dispatch (GSource *base,
|
||||
GSourceFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWaylandEventSource *source = (NimfWaylandEventSource *) base;
|
||||
|
||||
if (wl_display_dispatch_pending (source->wayland->display) < 0)
|
||||
{
|
||||
g_critical (G_STRLOC ": %s: wl_display_dispatch_pending() failed: %s: %m",
|
||||
G_STRFUNC, g_strerror (errno));
|
||||
nimf_wayland_stop (NIMF_SERVICE (source->wayland));
|
||||
}
|
||||
|
||||
source->poll_fd.revents = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void nimf_wayland_source_finalize (GSource *base)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWaylandEventSource *source = (NimfWaylandEventSource *) base;
|
||||
|
||||
if (source->reading)
|
||||
wl_display_cancel_read (source->wayland->display);
|
||||
|
||||
source->reading = FALSE;
|
||||
}
|
||||
|
||||
static GSourceFuncs event_funcs = {
|
||||
nimf_wayland_source_prepare,
|
||||
nimf_wayland_source_check,
|
||||
nimf_wayland_source_dispatch,
|
||||
nimf_wayland_source_finalize
|
||||
};
|
||||
|
||||
GSource *
|
||||
nimf_wayland_source_new (NimfWayland *wayland)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GSource *source;
|
||||
NimfWaylandEventSource *wl_source;
|
||||
|
||||
source = g_source_new (&event_funcs, sizeof (NimfWaylandEventSource));
|
||||
wl_source = (NimfWaylandEventSource *) source;
|
||||
|
||||
wl_source->wayland = wayland;
|
||||
wl_source->poll_fd.fd = wl_display_get_fd (wl_source->wayland->display);
|
||||
wl_source->poll_fd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
|
||||
g_source_add_poll (source, &wl_source->poll_fd);
|
||||
|
||||
g_source_set_priority (source, G_PRIORITY_DEFAULT);
|
||||
g_source_set_can_recurse (source, TRUE);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_surrounding_text (void *data,
|
||||
struct zwp_input_method_context_v1 *context,
|
||||
const char *text,
|
||||
uint32_t cursor,
|
||||
uint32_t anchor)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_reset (void *data,
|
||||
struct zwp_input_method_context_v1 *context)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_content_type (void *data,
|
||||
struct zwp_input_method_context_v1 *context,
|
||||
uint32_t hint,
|
||||
uint32_t purpose)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_invoke_action (void *data,
|
||||
struct zwp_input_method_context_v1 *context,
|
||||
uint32_t button,
|
||||
uint32_t index)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_commit_state (void *data,
|
||||
struct zwp_input_method_context_v1 *context,
|
||||
uint32_t serial)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = data;
|
||||
|
||||
wayland->serial = serial;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_preferred_language (void *data,
|
||||
struct zwp_input_method_context_v1 *context,
|
||||
const char *language)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static const struct zwp_input_method_context_v1_listener input_method_context_listener = {
|
||||
handle_surrounding_text,
|
||||
handle_reset,
|
||||
handle_content_type,
|
||||
handle_invoke_action,
|
||||
handle_commit_state,
|
||||
handle_preferred_language
|
||||
};
|
||||
|
||||
static void
|
||||
input_method_keyboard_keymap (void *data,
|
||||
struct wl_keyboard *wl_keyboard,
|
||||
uint32_t format,
|
||||
int32_t fd,
|
||||
uint32_t size)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = data;
|
||||
|
||||
char *map_str;
|
||||
|
||||
if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1)
|
||||
{
|
||||
close (fd);
|
||||
return;
|
||||
}
|
||||
|
||||
map_str = mmap (NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (map_str == MAP_FAILED)
|
||||
{
|
||||
close (fd);
|
||||
return;
|
||||
}
|
||||
|
||||
wayland->keymap = xkb_keymap_new_from_string (wayland->xkb_context,
|
||||
map_str,
|
||||
XKB_KEYMAP_FORMAT_TEXT_V1,
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
munmap (map_str, size);
|
||||
close (fd);
|
||||
|
||||
if (!wayland->keymap)
|
||||
{
|
||||
g_critical (G_STRLOC ": %s: xkb_keymap_new_from_string() failed",
|
||||
G_STRFUNC);
|
||||
return;
|
||||
}
|
||||
|
||||
wayland->state = xkb_state_new (wayland->keymap);
|
||||
if (!wayland->state)
|
||||
{
|
||||
g_critical (G_STRLOC ": %s: xkb_state_new() failed", G_STRFUNC);
|
||||
xkb_keymap_unref(wayland->keymap);
|
||||
return;
|
||||
}
|
||||
|
||||
wayland->shift_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Shift");
|
||||
wayland->lock_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Lock");
|
||||
wayland->control_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Control");
|
||||
wayland->mod1_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Mod1");
|
||||
wayland->mod2_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Mod2");
|
||||
wayland->mod3_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Mod3");
|
||||
wayland->mod4_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Mod4");
|
||||
wayland->mod5_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Mod5");
|
||||
wayland->super_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Super");
|
||||
wayland->hyper_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Hyper");
|
||||
wayland->meta_mask =
|
||||
1 << xkb_keymap_mod_get_index (wayland->keymap, "Meta");
|
||||
}
|
||||
|
||||
static void
|
||||
input_method_keyboard_key (void *data,
|
||||
struct wl_keyboard *wl_keyboard,
|
||||
uint32_t serial,
|
||||
uint32_t time,
|
||||
uint32_t key,
|
||||
uint32_t state_w)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = data;
|
||||
uint32_t code;
|
||||
uint32_t num_syms;
|
||||
const xkb_keysym_t *syms;
|
||||
xkb_keysym_t sym;
|
||||
enum wl_keyboard_key_state state = state_w;
|
||||
guint32 modifiers;
|
||||
NimfEvent *event;
|
||||
|
||||
if (!wayland->state)
|
||||
return;
|
||||
|
||||
code = key + 8;
|
||||
num_syms = xkb_state_key_get_syms (wayland->state, code, &syms);
|
||||
|
||||
sym = XKB_KEY_NoSymbol;
|
||||
if (num_syms == 1)
|
||||
sym = syms[0];
|
||||
|
||||
event = nimf_event_new (NIMF_EVENT_NOTHING);
|
||||
|
||||
modifiers = wayland->modifiers;
|
||||
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
|
||||
{
|
||||
modifiers |= NIMF_RELEASE_MASK;
|
||||
event->key.type = NIMF_EVENT_KEY_RELEASE;
|
||||
}
|
||||
else
|
||||
{
|
||||
event->key.type = NIMF_EVENT_KEY_PRESS;
|
||||
}
|
||||
|
||||
event->key.state = modifiers;
|
||||
event->key.keyval = sym;
|
||||
event->key.hardware_keycode = code;
|
||||
|
||||
if (!nimf_service_ic_filter_event (NIMF_SERVICE_IC (wayland->wic), event))
|
||||
zwp_input_method_context_v1_key (wayland->context, serial, time, key, state);
|
||||
|
||||
nimf_event_free (event);
|
||||
}
|
||||
|
||||
static void
|
||||
input_method_keyboard_modifiers (void *data,
|
||||
struct wl_keyboard *wl_keyboard,
|
||||
uint32_t serial,
|
||||
uint32_t mods_depressed,
|
||||
uint32_t mods_latched,
|
||||
uint32_t mods_locked,
|
||||
uint32_t group)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = data;
|
||||
struct zwp_input_method_context_v1 *context = wayland->context;
|
||||
xkb_mod_mask_t mask;
|
||||
|
||||
xkb_state_update_mask (wayland->state, mods_depressed,
|
||||
mods_latched, mods_locked, 0, 0, group);
|
||||
mask = xkb_state_serialize_mods (wayland->state,
|
||||
XKB_STATE_MODS_DEPRESSED |
|
||||
XKB_STATE_MODS_LATCHED);
|
||||
wayland->modifiers = 0;
|
||||
if (mask & wayland->shift_mask)
|
||||
wayland->modifiers |= NIMF_SHIFT_MASK;
|
||||
if (mask & wayland->lock_mask)
|
||||
wayland->modifiers |= NIMF_LOCK_MASK;
|
||||
if (mask & wayland->control_mask)
|
||||
wayland->modifiers |= NIMF_CONTROL_MASK;
|
||||
if (mask & wayland->mod1_mask)
|
||||
wayland->modifiers |= NIMF_MOD1_MASK;
|
||||
if (mask & wayland->mod2_mask)
|
||||
wayland->modifiers |= NIMF_MOD2_MASK;
|
||||
if (mask & wayland->mod3_mask)
|
||||
wayland->modifiers |= NIMF_MOD3_MASK;
|
||||
if (mask & wayland->mod4_mask)
|
||||
wayland->modifiers |= NIMF_MOD4_MASK;
|
||||
if (mask & wayland->mod5_mask)
|
||||
wayland->modifiers |= NIMF_MOD5_MASK;
|
||||
if (mask & wayland->super_mask)
|
||||
wayland->modifiers |= NIMF_SUPER_MASK;
|
||||
if (mask & wayland->hyper_mask)
|
||||
wayland->modifiers |= NIMF_HYPER_MASK;
|
||||
if (mask & wayland->meta_mask)
|
||||
wayland->modifiers |= NIMF_META_MASK;
|
||||
|
||||
zwp_input_method_context_v1_modifiers (context, serial,
|
||||
mods_depressed, mods_depressed,
|
||||
mods_latched, group);
|
||||
}
|
||||
|
||||
static const struct wl_keyboard_listener input_method_keyboard_listener = {
|
||||
input_method_keyboard_keymap,
|
||||
NULL, /* enter */
|
||||
NULL, /* leave */
|
||||
input_method_keyboard_key,
|
||||
input_method_keyboard_modifiers
|
||||
};
|
||||
|
||||
static void
|
||||
input_method_activate (void *data,
|
||||
struct zwp_input_method_v1 *input_method,
|
||||
struct zwp_input_method_context_v1 *context)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s: %p, %p", G_STRFUNC, input_method, context);
|
||||
|
||||
NimfWayland *wayland = data;
|
||||
|
||||
if (wayland->context)
|
||||
zwp_input_method_context_v1_destroy (wayland->context);
|
||||
|
||||
wayland->serial = 0;
|
||||
wayland->context = context;
|
||||
zwp_input_method_context_v1_add_listener (context,
|
||||
&input_method_context_listener,
|
||||
wayland);
|
||||
wayland->keyboard = zwp_input_method_context_v1_grab_keyboard (context);
|
||||
wl_keyboard_add_listener (wayland->keyboard,
|
||||
&input_method_keyboard_listener,
|
||||
wayland);
|
||||
}
|
||||
|
||||
static void
|
||||
input_method_deactivate (void *data,
|
||||
struct zwp_input_method_v1 *input_method,
|
||||
struct zwp_input_method_context_v1 *context)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s: %p, %p", G_STRFUNC, input_method, context);
|
||||
|
||||
NimfWayland *wayland = data;
|
||||
|
||||
if (!wayland->context)
|
||||
return;
|
||||
|
||||
nimf_service_ic_reset (NIMF_SERVICE_IC (wayland->wic));
|
||||
zwp_input_method_context_v1_destroy (wayland->context);
|
||||
wayland->context = NULL;
|
||||
}
|
||||
|
||||
static const struct zwp_input_method_v1_listener input_method_listener = {
|
||||
input_method_activate,
|
||||
input_method_deactivate
|
||||
};
|
||||
|
||||
static void
|
||||
registry_handle_global (void *data,
|
||||
struct wl_registry *registry,
|
||||
uint32_t name,
|
||||
const char *interface,
|
||||
uint32_t version)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = data;
|
||||
|
||||
if (!g_strcmp0 (interface, "zwp_input_method_v1"))
|
||||
{
|
||||
wayland->input_method =
|
||||
wl_registry_bind (registry, name, &zwp_input_method_v1_interface, 1);
|
||||
zwp_input_method_v1_add_listener (wayland->input_method,
|
||||
&input_method_listener, wayland);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
registry_handle_global_remove (void *data, struct wl_registry *registry,
|
||||
uint32_t name)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
registry_handle_global,
|
||||
registry_handle_global_remove
|
||||
};
|
||||
|
||||
static gboolean nimf_wayland_is_active (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
return NIMF_WAYLAND (service)->active;
|
||||
}
|
||||
|
||||
static gboolean nimf_wayland_start (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = NIMF_WAYLAND (service);
|
||||
const gchar *type;
|
||||
|
||||
if (wayland->active)
|
||||
return TRUE;
|
||||
|
||||
type = g_getenv ("XDG_SESSION_TYPE");
|
||||
|
||||
if (type && g_strcmp0 (type, "wayland"))
|
||||
return FALSE;
|
||||
|
||||
wayland->display = wl_display_connect (NULL);
|
||||
if (wayland->display == NULL)
|
||||
{
|
||||
g_warning (G_STRLOC ": %s: wl_display_connect() failed", G_STRFUNC);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wayland->registry = wl_display_get_registry (wayland->display);
|
||||
wl_registry_add_listener (wayland->registry, ®istry_listener, wayland);
|
||||
wl_display_roundtrip (wayland->display);
|
||||
if (wayland->input_method == NULL)
|
||||
{
|
||||
g_critical (G_STRLOC ": %s: No input_method global", G_STRFUNC);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wayland->xkb_context = xkb_context_new (XKB_CONTEXT_NO_FLAGS);
|
||||
if (wayland->xkb_context == NULL) {
|
||||
g_critical (G_STRLOC ": %s: xkb_context_new() failed", G_STRFUNC);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wayland->wic = nimf_wayland_ic_new (wayland);
|
||||
wayland->context = NULL;
|
||||
wayland->event_source = nimf_wayland_source_new (wayland);
|
||||
g_source_attach (wayland->event_source, NULL);
|
||||
|
||||
wayland->active = TRUE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
nimf_wayland_get_id (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
g_return_val_if_fail (NIMF_IS_SERVICE (service), NULL);
|
||||
|
||||
return NIMF_WAYLAND (service)->id;
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_wayland_init (NimfWayland *wayland)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
wayland->id = g_strdup ("nimf-wayland");
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_wayland_finalize (GObject *object)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfWayland *wayland = NIMF_WAYLAND (object);
|
||||
|
||||
if (wayland->active)
|
||||
nimf_wayland_stop (NIMF_SERVICE (wayland));
|
||||
|
||||
g_free (wayland->id);
|
||||
|
||||
if (wayland->wic)
|
||||
g_object_unref (wayland->wic);
|
||||
|
||||
G_OBJECT_CLASS (nimf_wayland_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_wayland_class_init (NimfWaylandClass *class)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
NimfServiceClass *service_class = NIMF_SERVICE_CLASS (class);
|
||||
|
||||
service_class->get_id = nimf_wayland_get_id;
|
||||
service_class->start = nimf_wayland_start;
|
||||
service_class->stop = nimf_wayland_stop;
|
||||
service_class->is_active = nimf_wayland_is_active;
|
||||
|
||||
object_class->finalize = nimf_wayland_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_wayland_class_finalize (NimfWaylandClass *class)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
void module_register_type (GTypeModule *type_module)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
nimf_wayland_register_type (type_module);
|
||||
}
|
||||
|
||||
GType module_get_type ()
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
return nimf_wayland_get_type ();
|
||||
}
|
||||
96
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland.h
vendored
Normal file
96
Telegram/ThirdParty/nimf/modules/services/wayland/nimf-wayland.h
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-wayland.h
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2012 Intel Corporation
|
||||
* Copyright (C) 2017 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __NIMF_WAYLAND_H__
|
||||
#define __NIMF_WAYLAND_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-server.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "input-method-unstable-v1-client-protocol.h"
|
||||
|
||||
#define NIMF_TYPE_WAYLAND (nimf_wayland_get_type ())
|
||||
#define NIMF_WAYLAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NIMF_TYPE_WAYLAND, NimfWayland))
|
||||
#define NIMF_WAYLAND_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), NIMF_TYPE_WAYLAND, NimfWaylandClass))
|
||||
#define NIMF_IS_WAYLAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NIMF_TYPE_WAYLAND))
|
||||
#define NIMF_IS_WAYLAND_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), NIMF_TYPE_WAYLAND))
|
||||
#define NIMF_WAYLAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NIMF_TYPE_WAYLAND, NimfWaylandClass))
|
||||
|
||||
typedef struct _NimfWaylandIC NimfWaylandIC;
|
||||
|
||||
typedef struct _NimfWayland NimfWayland;
|
||||
typedef struct _NimfWaylandClass NimfWaylandClass;
|
||||
|
||||
struct _NimfWaylandClass
|
||||
{
|
||||
NimfServiceClass parent_class;
|
||||
};
|
||||
|
||||
struct _NimfWayland
|
||||
{
|
||||
NimfService parent_instance;
|
||||
|
||||
GSource *event_source;
|
||||
gchar *id;
|
||||
gboolean active;
|
||||
NimfWaylandIC *wic;
|
||||
|
||||
struct zwp_input_method_v1 *input_method;
|
||||
struct zwp_input_method_context_v1 *context;
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry;
|
||||
struct wl_keyboard *keyboard;
|
||||
|
||||
struct xkb_context *xkb_context;
|
||||
|
||||
NimfModifierType modifiers;
|
||||
|
||||
struct xkb_keymap *keymap;
|
||||
struct xkb_state *state;
|
||||
xkb_mod_mask_t shift_mask;
|
||||
xkb_mod_mask_t lock_mask;
|
||||
xkb_mod_mask_t control_mask;
|
||||
xkb_mod_mask_t mod1_mask;
|
||||
xkb_mod_mask_t mod2_mask;
|
||||
xkb_mod_mask_t mod3_mask;
|
||||
xkb_mod_mask_t mod4_mask;
|
||||
xkb_mod_mask_t mod5_mask;
|
||||
xkb_mod_mask_t super_mask;
|
||||
xkb_mod_mask_t hyper_mask;
|
||||
xkb_mod_mask_t meta_mask;
|
||||
|
||||
uint32_t serial;
|
||||
};
|
||||
|
||||
GType nimf_wayland_get_type (void) G_GNUC_CONST;
|
||||
|
||||
#endif /* __NIMF_WAYLAND_H__ */
|
||||
Reference in New Issue
Block a user