Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clients can choose whether to commit preedit text before resetting im or not #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

clients can choose whether to commit preedit text before resetting in…

…put method or not
  • Loading branch information...
Hodong Kim
Hodong Kim committed Jan 24, 2015
commit 1eb236a0989c56b6dc47aac4516c0acf406edc68
@@ -61,6 +61,8 @@ struct _BusIBusImpl {

gboolean embed_preedit_text;

gboolean commit_preedit_text_before_resetting_im;

IBusRegistry *registry;

/* a list of BusComponent objects that are created from component XML
@@ -194,6 +196,11 @@ static const gchar introspection_xml[] =
" name='org.freedesktop.DBus.Property.EmitsChangedSignal'\n"
" value='true' />\n"
" </property>\n"
" <property name='CommitPreeditTextBeforeResettingIM' type='b' access='readwrite'>\n"
" <annotation\n"
" name='org.freedesktop.DBus.Property.EmitsChangedSignal'\n"
" value='true' />\n"
" </property>\n"
" <method name='CreateInputContext'>\n"
" <arg direction='in' type='s' name='client_name' />\n"
" <arg direction='out' type='o' name='object_path' />\n"
@@ -408,6 +415,7 @@ bus_ibus_impl_init (BusIBusImpl *ibus)

ibus->use_sys_layout = TRUE;
ibus->embed_preedit_text = TRUE;
ibus->commit_preedit_text_before_resetting_im = TRUE;
ibus->use_global_engine = TRUE;
ibus->global_engine_name = NULL;
ibus->global_previous_engine_name = NULL;
@@ -1640,6 +1648,49 @@ _ibus_set_embed_preedit_text (BusIBusImpl *ibus,
return TRUE;
}

/**
* _ibus_get_commit_preedit_text_before_resetting_im:
*
* Implement the "CommitPreeditTextBeforeResettingIM" method call of the
* org.freedesktop.IBus interface.
*/
static GVariant *
_ibus_get_commit_preedit_text_before_resetting_im (BusIBusImpl *ibus,
GDBusConnection *connection,
GError **error)
{
if (error) {
*error = NULL;
}

return g_variant_new_boolean (ibus->commit_preedit_text_before_resetting_im);
}

/**
* _ibus_set_commit_preedit_text_before_resetting_im:
*
* Implement the "CommitPreeditTextBeforeResettingIM" method call of
* the org.freedesktop.IBus interface.
*/
static gboolean
_ibus_set_commit_preedit_text_before_resetting_im (BusIBusImpl *ibus,
GDBusConnection *connection,
GVariant *value,
GError **error)
{
if (error) {
*error = NULL;
}

gboolean commit_preedit_text_before_resetting_im = g_variant_get_boolean (value);
if (commit_preedit_text_before_resetting_im != ibus->commit_preedit_text_before_resetting_im) {
ibus->commit_preedit_text_before_resetting_im = commit_preedit_text_before_resetting_im;
bus_ibus_impl_property_changed (ibus, "CommitPreeditTextBeforeResettingIM", value);
}

return TRUE;
}

/**
* bus_ibus_impl_service_method_call:
*
@@ -1732,6 +1783,8 @@ bus_ibus_impl_service_get_property (IBusService *service,
{ "ActiveEngines", _ibus_get_active_engines },
{ "GlobalEngine", _ibus_get_global_engine },
{ "EmbedPreeditText", _ibus_get_embed_preedit_text },
{ "CommitPreeditTextBeforeResettingIM",
_ibus_get_commit_preedit_text_before_resetting_im },
};

if (g_strcmp0 (interface_name, IBUS_INTERFACE_IBUS) != 0) {
@@ -1781,6 +1834,8 @@ bus_ibus_impl_service_set_property (IBusService *service,
} methods [] = {
{ "PreloadEngines", _ibus_set_preload_engines },
{ "EmbedPreeditText", _ibus_set_embed_preedit_text },
{ "CommitPreeditTextBeforeResettingIM",
_ibus_set_commit_preedit_text_before_resetting_im },
};

if (g_strcmp0 (interface_name, IBUS_INTERFACE_IBUS) != 0) {
@@ -2098,6 +2153,14 @@ bus_ibus_impl_is_embed_preedit_text (BusIBusImpl *ibus)
return ibus->embed_preedit_text;
}

gboolean
bus_ibus_impl_is_commit_preedit_text_before_resetting_im (BusIBusImpl *ibus)
{
g_assert (BUS_IS_IBUS_IMPL (ibus));

return ibus->commit_preedit_text_before_resetting_im;
}

BusInputContext *
bus_ibus_impl_get_focused_input_context (BusIBusImpl *ibus)
{
@@ -79,6 +79,8 @@ BusComponent *bus_ibus_impl_lookup_component_by_name
gboolean bus_ibus_impl_is_use_sys_layout (BusIBusImpl *ibus);
gboolean bus_ibus_impl_is_embed_preedit_text
(BusIBusImpl *ibus);
gboolean bus_ibus_impl_is_commit_preedit_text_before_resetting_im
(BusIBusImpl *ibus);
BusInputContext *bus_ibus_impl_get_focused_input_context
(BusIBusImpl *ibus);

@@ -91,6 +91,8 @@ static IBusInputContext *_fake_context = NULL;
static GdkWindow *_input_window = NULL;
static GtkWidget *_input_widget = NULL;

static gboolean _commit_preedit_text_before_resetting_im = FALSE;

/* functions prototype */
static void ibus_im_context_class_init (IBusIMContextClass *class);
static void ibus_im_context_class_fini (IBusIMContextClass *class);
@@ -132,6 +134,17 @@ static gboolean _set_cursor_location_internal

static void _bus_connected_cb (IBusBus *bus,
IBusIMContext *context);
static void _ibus_context_commit_text_cb
(IBusInputContext *ibuscontext,
IBusText *text,
IBusIMContext *ibusimcontext);
static void _ibus_context_update_preedit_text_cb
(IBusInputContext *ibuscontext,
IBusText *text,
gint cursor_pos,
gboolean visible,
IBusIMContext *ibusimcontext);

/* callback functions for slave context */
static void _slave_commit_cb (GtkIMContext *slave,
gchar *string,
@@ -715,6 +728,13 @@ ibus_im_context_init (GObject *obj)
ibusimcontext);

if (ibus_bus_is_connected (_bus)) {
GVariant *value = NULL;
value = ibus_bus_get_ibus_property (_bus, "CommitPreeditTextBeforeResettingIM");
if (value) {
_commit_preedit_text_before_resetting_im = g_variant_get_boolean (value);
g_variant_unref (value);
}

_create_input_context (ibusimcontext);
}

@@ -931,6 +951,25 @@ ibus_im_context_reset (GtkIMContext *context)
IBusIMContext *ibusimcontext = IBUS_IM_CONTEXT (context);

if (ibusimcontext->ibuscontext) {
if (_commit_preedit_text_before_resetting_im &&
ibusimcontext->preedit_string &&
g_strcmp0 (ibusimcontext->preedit_string, ""))
{
IBusText *text_to_commit = ibus_text_new_from_string (g_strdup (ibusimcontext->preedit_string));
/* clear and update preedit text */
IBusText *empty_text = ibus_text_new_from_static_string ("");
_ibus_context_update_preedit_text_cb (ibusimcontext->ibuscontext,
empty_text,
0,
ibusimcontext->preedit_visible,
ibusimcontext);
g_object_unref (empty_text);
/* commit text */
_ibus_context_commit_text_cb (ibusimcontext->ibuscontext,
text_to_commit,
ibusimcontext);
g_object_unref (text_to_commit);
}
ibus_input_context_reset (ibusimcontext->ibuscontext);
}
gtk_im_context_reset (ibusimcontext->slave);
@@ -1173,8 +1212,17 @@ _bus_connected_cb (IBusBus *bus,
IBusIMContext *ibusimcontext)
{
IDEBUG ("%s", __FUNCTION__);
if (ibusimcontext)

if (ibusimcontext) {
GVariant *value = NULL;
value = ibus_bus_get_ibus_property (bus, "CommitPreeditTextBeforeResettingIM");
if (value) {
_commit_preedit_text_before_resetting_im = g_variant_get_boolean (value);
g_variant_unref (value);
}

_create_input_context (ibusimcontext);
}
else
_create_fake_input_context ();
}
@@ -1,5 +1,6 @@
[org.freedesktop.ibus.general]
embed-preedit-text = /desktop/ibus/general/embed_preedit_text
commit-preedit-text-before-resetting-im = /desktop/ibus/general/commit_preedit_text_before_resetting_im
enable-by-default = /desktop/ibus/general/enable_by_default
preload-engines = /desktop/ibus/general/preload_engines
use-global-engine = /desktop/ibus/general/use_global_engine
@@ -359,7 +359,17 @@
<long>Share the same input method among all applications</long>
</locale>
</schema>

<schema>
<key>/schemas/desktop/ibus/general/commit_preedit_text_before_resetting_im</key>
<applyto>/desktop/ibus/general/commit_preedit_text_before_resetting_im</applyto>
<owner>ibus</owner>
<type>bool</type>
<default>true</default>
<locale name="C">
<short>Commit preedit text before resetting input method</short>
<long>Commit preedit text before resetting input method</long>
</locale>
</schema>
<schema>
<key>/schemas/desktop/ibus/general/enable_by_default</key>
<applyto>/desktop/ibus/general/enable_by_default</applyto>
@@ -201,6 +201,14 @@ def __init_general(self):
'active',
Gio.SettingsBindFlags.DEFAULT)

# commit preedit text before resetting im
self.__commit_preedit_text_before_resetting_im = self.__builder.get_object(
"checkbutton_commit_preedit_text_before_resetting_im")
self.__settings_general.bind('commit-preedit-text-before-resetting-im',
self.__commit_preedit_text_before_resetting_im,
'active',
Gio.SettingsBindFlags.DEFAULT)

# init engine page
self.__engines = self.__bus.list_engines()
self.__combobox = self.__builder.get_object("combobox_engines")
@@ -1056,6 +1056,23 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_commit_preedit_text_before_resetting_im">
<property name="label" translatable="yes">Commit preedit text before resetting input method</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
@@ -143,6 +143,10 @@ class Panel : IBus.PanelService {
set_embed_preedit_text();
});

m_settings_general.changed["commit-preedit-text-before-resetting-im"].connect((key) => {
set_commit_preedit_text_before_resetting_im();
});

m_settings_general.changed["use-global-engine"].connect((key) => {
set_use_global_engine();
});
@@ -492,6 +496,17 @@ class Panel : IBus.PanelService {
m_bus.set_ibus_property("EmbedPreeditText", variant);
}

private void set_commit_preedit_text_before_resetting_im() {
Variant variant =
m_settings_general.get_value("commit-preedit-text-before-resetting-im");

if (variant == null) {
return;
}

m_bus.set_ibus_property("CommitPreeditTextBeforeResettingIM", variant);
}

private void set_use_global_engine() {
m_use_global_engine =
m_settings_general.get_boolean("use-global-engine");
@@ -661,6 +676,7 @@ class Panel : IBus.PanelService {
set_use_system_keyboard_layout();
set_use_global_engine();
set_use_xmodmap();
set_commit_preedit_text_before_resetting_im();
update_engines(m_settings_general.get_strv("preload-engines"),
m_settings_general.get_strv("engines-order"));
unbind_switch_shortcut();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.