Skip to content

Commit 92771d0

Browse files
committed
src/ibusengine: Add focus_in_id()/focus_out_id() class methods
IBusEngine constructor now has a 'has-focus-id' property and if it's %TRUE, IBusEngine::focus_in_id()/focus_out_id() are called instaed of IBusEngine::focus_in()/focus_out() and the class method has an object_path argument for the unique input context ID and a client argument for the client application type likes ibus-gtk, ibus-gtk4, xim.
1 parent c957c5f commit 92771d0

File tree

8 files changed

+505
-115
lines changed

8 files changed

+505
-115
lines changed

bus/engineproxy.c

Lines changed: 223 additions & 81 deletions
Large diffs are not rendered by default.

bus/engineproxy.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* vim:set et sts=4: */
33
/* ibus - The Input Bus
44
* Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
5-
* Copyright (C) 2018 Takao Fujiwara <takao.fujiwara@gmail.com>
5+
* Copyright (C) 2018-2022 Takao Fujiwara <takao.fujiwara@gmail.com>
66
* Copyright (C) 2008-2018 Red Hat, Inc.
77
*
88
* This library is free software; you can redistribute it and/or
@@ -126,20 +126,26 @@ void bus_engine_proxy_set_cursor_location
126126
/**
127127
* bus_engine_proxy_focus_in:
128128
* @engine: A #BusEngineProxy.
129+
* @object_path: An object path.
130+
* @client: A client name.
129131
*
130132
* Call "FocusIn" method of an engine asynchronously. Do nothing if
131133
* the engine already has a focus.
132134
*/
133-
void bus_engine_proxy_focus_in (BusEngineProxy *engine);
135+
void bus_engine_proxy_focus_in (BusEngineProxy *engine,
136+
const gchar *object_path,
137+
const gchar *client);
134138

135139
/**
136140
* bus_engine_proxy_focus_out:
137141
* @engine: A #BusEngineProxy.
142+
* @object_path: An object path.
138143
*
139144
* Call "FocusOut" method of an engine asynchronously. Do nothing if
140145
* the engine does not have a focus.
141146
*/
142-
void bus_engine_proxy_focus_out (BusEngineProxy *engine);
147+
void bus_engine_proxy_focus_out (BusEngineProxy *engine,
148+
const gchar *object_path);
143149

144150
/**
145151
* bus_engine_proxy_reset:

bus/ibusimpl.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct _BusIBusImpl {
7272
* IBusEngineDesc object. */
7373
GHashTable *engine_table;
7474

75+
GHashTable *engine_focus_id_table;
76+
7577
BusInputContext *focused_context;
7678
BusPanelProxy *panel;
7779
BusPanelProxy *emoji_extension;
@@ -596,6 +598,7 @@ bus_ibus_impl_init (BusIBusImpl *ibus)
596598
ibus->use_global_engine = TRUE;
597599
ibus->global_engine_name = NULL;
598600
ibus->global_previous_engine_name = NULL;
601+
ibus->engine_focus_id_table = g_hash_table_new (g_str_hash, g_str_equal);
599602

600603
/* focus the fake_context, if use_global_engine is enabled. */
601604
if (ibus->use_global_engine)
@@ -2384,3 +2387,13 @@ bus_ibus_impl_get_focused_input_context (BusIBusImpl *ibus)
23842387

23852388
return ibus->focused_context;
23862389
}
2390+
2391+
GHashTable *
2392+
bus_ibus_impl_get_engine_focus_id_table (BusIBusImpl *ibus)
2393+
{
2394+
2395+
g_assert (BUS_IS_IBUS_IMPL (ibus));
2396+
2397+
return ibus->engine_focus_id_table;
2398+
}
2399+

bus/ibusimpl.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/* vim:set et sts=4: */
33
/* bus - The Input Bus
44
* Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
5-
* Copyright (C) 2008-2013 Red Hat, Inc.
5+
* Copyright (C) 2022 Takao Fujiwara <takao.fujiwara1@gmail.com>
6+
* Copyright (C) 2008-2022 Red Hat, Inc.
67
*
78
* This library is free software; you can redistribute it and/or
89
* modify it under the terms of the GNU Lesser General Public
@@ -58,6 +59,13 @@ G_BEGIN_DECLS
5859
typedef struct _BusIBusImpl BusIBusImpl;
5960
typedef struct _BusIBusImplClass BusIBusImplClass;
6061

62+
typedef enum
63+
{
64+
ENGINE_FOCUS_CATEGORY_NONE = 0,
65+
ENGINE_FOCUS_CATEGORY_NO_ID,
66+
ENGINE_FOCUS_CATEGORY_HAS_ID
67+
} EngineFocusCategory;
68+
6169
GType bus_ibus_impl_get_type (void);
6270

6371
/**
@@ -81,6 +89,7 @@ gboolean bus_ibus_impl_is_embed_preedit_text
8189
(BusIBusImpl *ibus);
8290
BusInputContext *bus_ibus_impl_get_focused_input_context
8391
(BusIBusImpl *ibus);
84-
92+
GHashTable *bus_ibus_impl_get_engine_focus_id_table
93+
(BusIBusImpl *ibus);
8594
G_END_DECLS
8695
#endif

bus/inputcontext.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,8 @@ _ic_process_key_event_reply_cb (GObject *source,
846846
/**
847847
* _ic_process_key_event:
848848
*
849-
* Implement the "ProcessKeyEvent" method call of the org.freedesktop.IBus.InputContext interface.
849+
* Implement the "ProcessKeyEvent" method call of the
850+
* org.freedesktop.IBus.InputContext interface.
850851
*/
851852
static void
852853
_ic_process_key_event (BusInputContext *context,
@@ -860,11 +861,13 @@ _ic_process_key_event (BusInputContext *context,
860861
g_variant_get (parameters, "(uuu)", &keyval, &keycode, &modifiers);
861862
if (G_UNLIKELY (!context->has_focus)) {
862863
/* workaround: set focus if context does not have focus */
863-
BusInputContext *focused_context = bus_ibus_impl_get_focused_input_context (BUS_DEFAULT_IBUS);
864+
BusInputContext *focused_context =
865+
bus_ibus_impl_get_focused_input_context (BUS_DEFAULT_IBUS);
864866
if (focused_context == NULL ||
865867
focused_context->fake == TRUE ||
866868
context->fake == FALSE) {
867-
/* grab focus, if context is a real IC or current focused IC is fake */
869+
/* grab focus, if context is a real IC or current focused IC is
870+
* fake */
868871
bus_input_context_focus_in (context);
869872
}
870873
}
@@ -914,7 +917,8 @@ _ic_process_key_event (BusInputContext *context,
914917
data);
915918
}
916919
else {
917-
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", FALSE));
920+
g_dbus_method_invocation_return_value (invocation,
921+
g_variant_new ("(b)", FALSE));
918922
}
919923
}
920924

@@ -1438,7 +1442,9 @@ bus_input_context_focus_in (BusInputContext *context)
14381442
context->prev_modifiers = 0;
14391443

14401444
if (context->engine) {
1441-
bus_engine_proxy_focus_in (context->engine);
1445+
const gchar *path =
1446+
ibus_service_get_object_path ((IBusService *)context);
1447+
bus_engine_proxy_focus_in (context->engine, path, context->client);
14421448
bus_engine_proxy_enable (context->engine);
14431449
bus_engine_proxy_set_capabilities (context->engine, context->capabilities);
14441450
bus_engine_proxy_set_cursor_location (context->engine, context->x, context->y, context->w, context->h);
@@ -1538,7 +1544,9 @@ bus_input_context_focus_out (BusInputContext *context)
15381544
bus_input_context_register_properties (context, props_empty);
15391545

15401546
if (context->engine) {
1541-
bus_engine_proxy_focus_out (context->engine);
1547+
const gchar *path =
1548+
ibus_service_get_object_path ((IBusService *)context);
1549+
bus_engine_proxy_focus_out (context->engine, path);
15421550
}
15431551

15441552
context->has_focus = FALSE;
@@ -2376,11 +2384,19 @@ bus_input_context_enable (BusInputContext *context)
23762384
if (context->engine == NULL)
23772385
return;
23782386

2379-
bus_engine_proxy_focus_in (context->engine);
2380-
bus_engine_proxy_enable (context->engine);
2381-
bus_engine_proxy_set_capabilities (context->engine, context->capabilities);
2382-
bus_engine_proxy_set_cursor_location (context->engine, context->x, context->y, context->w, context->h);
2383-
bus_engine_proxy_set_content_type (context->engine, context->purpose, context->hints);
2387+
{
2388+
const gchar *path =
2389+
ibus_service_get_object_path ((IBusService *)context);
2390+
bus_engine_proxy_focus_in (context->engine, path, context->client);
2391+
bus_engine_proxy_enable (context->engine);
2392+
bus_engine_proxy_set_capabilities (context->engine,
2393+
context->capabilities);
2394+
bus_engine_proxy_set_cursor_location (context->engine,
2395+
context->x, context->y,
2396+
context->w, context->h);
2397+
bus_engine_proxy_set_content_type (context->engine,
2398+
context->purpose, context->hints);
2399+
}
23842400
}
23852401

23862402
void
@@ -2397,7 +2413,9 @@ bus_input_context_disable (BusInputContext *context)
23972413
bus_input_context_register_properties (context, props_empty);
23982414

23992415
if (context->engine) {
2400-
bus_engine_proxy_focus_out (context->engine);
2416+
const gchar *path =
2417+
ibus_service_get_object_path ((IBusService *)context);
2418+
bus_engine_proxy_focus_out (context->engine, path);
24012419
bus_engine_proxy_disable (context->engine);
24022420
}
24032421
}
@@ -2445,6 +2463,8 @@ bus_input_context_unset_engine (BusInputContext *context)
24452463

24462464
if (context->engine) {
24472465
gint i;
2466+
const gchar *path =
2467+
ibus_service_get_object_path ((IBusService *)context);
24482468
/* uninstall signal handlers for the engine. */
24492469
for (i = 0; i < G_N_ELEMENTS(engine_signals); i++) {
24502470
g_signal_handlers_disconnect_by_func (context->engine,
@@ -2453,7 +2473,7 @@ bus_input_context_unset_engine (BusInputContext *context)
24532473
/* focus out engine so that the next call of
24542474
bus_engine_proxy_focus_in() will take effect and trigger
24552475
RegisterProperties. */
2456-
bus_engine_proxy_focus_out (context->engine);
2476+
bus_engine_proxy_focus_out (context->engine, path);
24572477
g_object_unref (context->engine);
24582478
context->engine = NULL;
24592479
}
@@ -2488,7 +2508,9 @@ bus_input_context_set_engine (BusInputContext *context,
24882508
context);
24892509
}
24902510
if (context->has_focus) {
2491-
bus_engine_proxy_focus_in (context->engine);
2511+
const gchar *path =
2512+
ibus_service_get_object_path ((IBusService *)context);
2513+
bus_engine_proxy_focus_in (context->engine, path, context->client);
24922514
bus_engine_proxy_enable (context->engine);
24932515
bus_engine_proxy_set_capabilities (context->engine, context->capabilities);
24942516
bus_engine_proxy_set_cursor_location (context->engine, context->x, context->y, context->w, context->h);

0 commit comments

Comments
 (0)