ime: Add support for local IMEs
This commit is contained in:
parent
1c186cd286
commit
b0f2b7e89f
2 changed files with 42 additions and 4 deletions
42
src/ime.cpp
42
src/ime.cpp
|
|
@ -22,6 +22,8 @@ extern "C" {
|
|||
|
||||
#include "gamescope-input-method-protocol.h"
|
||||
|
||||
struct wlserver_input_method_manager *global_manager = nullptr;
|
||||
|
||||
/* The C/C++ standard library doesn't expose a reliable way to decode UTF-8,
|
||||
* so we need to ship our own implementation. Yay for locales. */
|
||||
|
||||
|
|
@ -362,7 +364,7 @@ static bool try_type_keysym(struct wlserver_input_method *ime, xkb_keysym_t keys
|
|||
return false;
|
||||
}
|
||||
|
||||
static void type_text(struct wlserver_input_method *ime, const char *text)
|
||||
void type_text(struct wlserver_input_method *ime, const char *text)
|
||||
{
|
||||
// If possible, try to type the character without switching the keymap
|
||||
// ...unless we're already using a fancy keymap
|
||||
|
|
@ -491,15 +493,21 @@ static const struct gamescope_input_method_interface ime_impl = {
|
|||
.set_action = ime_handle_set_action,
|
||||
};
|
||||
|
||||
void destroy_ime(struct wlserver_input_method *ime)
|
||||
{
|
||||
if (ime == active_input_method)
|
||||
active_input_method = nullptr;
|
||||
|
||||
wlr_keyboard_finish(&ime->keyboard);
|
||||
}
|
||||
|
||||
static void ime_handle_resource_destroy(struct wl_resource *ime_resource)
|
||||
{
|
||||
struct wlserver_input_method *ime = (struct wlserver_input_method *)wl_resource_get_user_data(ime_resource);
|
||||
if (ime == nullptr)
|
||||
return;
|
||||
|
||||
active_input_method = nullptr;
|
||||
|
||||
wlr_keyboard_finish(&ime->keyboard);
|
||||
destroy_ime(ime);
|
||||
|
||||
delete ime;
|
||||
}
|
||||
|
|
@ -556,6 +564,30 @@ static void manager_handle_create_input_method(struct wl_client *client, struct
|
|||
active_input_method = ime;
|
||||
}
|
||||
|
||||
struct wlserver_input_method *create_local_ime()
|
||||
{
|
||||
struct wlserver_input_method *ime = new wlserver_input_method();
|
||||
ime->resource = nullptr;
|
||||
ime->manager = global_manager;
|
||||
ime->serial = 1;
|
||||
ime->next_keycode_index = 0;
|
||||
ime->held_keycode = -1;
|
||||
ime->held_modifier_mask = 0;
|
||||
ime->prev_mods = wlr_keyboard_modifiers{0};
|
||||
|
||||
wlr_keyboard_init(&ime->keyboard, &keyboard_impl, "local_ime");
|
||||
|
||||
wlr_keyboard_set_repeat_info(&ime->keyboard, 0, 0);
|
||||
|
||||
wl_resource_set_user_data(ime->resource, ime);
|
||||
gamescope_input_method_send_done(ime->resource, ime->serial);
|
||||
|
||||
ime->ime_reset_ime_keyboard_event_source = wl_event_loop_add_timer(global_manager->server->event_loop, reset_ime_keyboard, ime);
|
||||
ime->ime_release_ime_keypress_event_source = wl_event_loop_add_timer(global_manager->server->event_loop, release_key_if_needed, ime);
|
||||
|
||||
return ime;
|
||||
}
|
||||
|
||||
static void manager_handle_destroy(struct wl_client *client, struct wl_resource *manager_resource)
|
||||
{
|
||||
wl_resource_destroy(manager_resource);
|
||||
|
|
@ -593,4 +625,6 @@ void create_ime_manager(struct wlserver_t *wlserver)
|
|||
manager->server = wlserver;
|
||||
manager->global = wl_global_create(wlserver->display, &gamescope_input_method_manager_interface, IME_MANAGER_VERSION, manager, manager_bind);
|
||||
manager->ime_reset_keyboard_event_source = wl_event_loop_add_timer(wlserver->event_loop, reset_keyboard, wlserver);
|
||||
|
||||
global_manager = manager;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,3 +5,7 @@
|
|||
#include "wlserver.hpp"
|
||||
|
||||
void create_ime_manager(struct wlserver_t *wlserver);
|
||||
|
||||
struct wlserver_input_method *create_local_ime();
|
||||
void destroy_ime(struct wlserver_input_method * ime);
|
||||
void type_text(struct wlserver_input_method *ime, const char *text);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue