Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Librem5
squeekboard
Commits
0087f741
Commit
0087f741
authored
Feb 28, 2011
by
Daiki Ueno
Browse files
Make input context have multiple keyboards.
parent
639ad8df
Changes
6
Hide whitespace changes
Inline
Side-by-side
bindings/python/eekboard/context.py
View file @
0087f741
...
...
@@ -51,8 +51,14 @@ class Context(gobject.GObject):
def
get_giobject
(
self
):
return
self
.
__giobject
def
set_keyboard
(
self
,
keyboard
):
self
.
__giobject
.
set_keyboard
(
keyboard
,
None
)
def
add_keyboard
(
self
,
keyboard
):
return
self
.
__giobject
.
add_keyboard
(
keyboard
,
None
)
def
remove_keyboard
(
self
,
keyboard_id
):
return
self
.
__giobject
.
remove_keyboard
(
keyboard_id
,
None
)
def
set_keyboard
(
self
,
keyboard_id
):
self
.
__giobject
.
set_keyboard
(
keyboard_id
,
None
)
def
show_keyboard
(
self
):
self
.
__giobject
.
show_keyboard
(
None
)
...
...
eekboard/eekboard-context.c
View file @
0087f741
...
...
@@ -56,6 +56,7 @@ G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
struct
_EekboardContextPrivate
{
EekKeyboard
*
keyboard
;
GHashTable
*
keyboard_hash
;
gboolean
keyboard_visible
;
gboolean
enabled
;
};
...
...
@@ -173,6 +174,11 @@ eekboard_context_dispose (GObject *self)
g_object_unref
(
priv
->
keyboard
);
priv
->
keyboard
=
NULL
;
}
if
(
priv
->
keyboard_hash
)
{
g_hash_table_destroy
(
priv
->
keyboard_hash
);
priv
->
keyboard_hash
=
NULL
;
}
}
static
void
...
...
@@ -293,6 +299,11 @@ eekboard_context_init (EekboardContext *self)
priv
->
keyboard
=
NULL
;
priv
->
keyboard_visible
=
FALSE
;
priv
->
enabled
=
FALSE
;
priv
->
keyboard_hash
=
g_hash_table_new_full
(
g_direct_hash
,
g_direct_equal
,
NULL
,
(
GDestroyNotify
)
g_object_unref
);
}
/**
...
...
@@ -347,39 +358,127 @@ context_async_ready_callback (GObject *source_object,
}
/**
* eekboard_context_
set
_keyboard:
* eekboard_context_
add
_keyboard:
* @context: an #EekboardContext
* @keyboard: an #EekKeyboard
* @cancellable: a #GCancellable
*
* Set the keyboard description of @context to @keyboard.
* Register @keyboard in @context.
*/
guint
eekboard_context_add_keyboard
(
EekboardContext
*
context
,
EekKeyboard
*
keyboard
,
GCancellable
*
cancellable
)
{
EekboardContextPrivate
*
priv
;
GVariant
*
variant
,
*
result
;
GError
*
error
;
g_return_val_if_fail
(
EEKBOARD_IS_CONTEXT
(
context
),
0
);
g_return_val_if_fail
(
EEK_IS_KEYBOARD
(
keyboard
),
0
);
priv
=
EEKBOARD_CONTEXT_GET_PRIVATE
(
context
);
variant
=
eek_serializable_serialize
(
EEK_SERIALIZABLE
(
keyboard
));
error
=
NULL
;
result
=
g_dbus_proxy_call_sync
(
G_DBUS_PROXY
(
context
),
"AddKeyboard"
,
g_variant_new
(
"(v)"
,
variant
),
G_DBUS_CALL_FLAGS_NONE
,
-
1
,
cancellable
,
&
error
);
g_variant_unref
(
variant
);
if
(
result
)
{
guint
keyboard_id
;
g_variant_get
(
result
,
"(u)"
,
&
keyboard_id
);
g_variant_unref
(
result
);
if
(
keyboard_id
!=
0
)
{
g_hash_table_insert
(
priv
->
keyboard_hash
,
GUINT_TO_POINTER
(
keyboard_id
),
g_object_ref
(
keyboard
));
}
return
keyboard_id
;
}
return
0
;
}
/**
* eekboard_context_remove_keyboard:
* @context: an #EekboardContext
* @keyboard_id: keyboard ID
* @cancellable: a #GCancellable
*
* Unregister the keyboard with @keyboard_id in @context.
*/
void
eekboard_context_remove_keyboard
(
EekboardContext
*
context
,
guint
keyboard_id
,
GCancellable
*
cancellable
)
{
EekboardContextPrivate
*
priv
;
EekKeyboard
*
keyboard
;
g_return_if_fail
(
EEKBOARD_IS_CONTEXT
(
context
));
priv
=
EEKBOARD_CONTEXT_GET_PRIVATE
(
context
);
keyboard
=
g_hash_table_lookup
(
priv
->
keyboard_hash
,
GUINT_TO_POINTER
(
keyboard_id
));
if
(
keyboard
==
priv
->
keyboard
)
priv
->
keyboard
=
NULL
;
g_hash_table_remove
(
priv
->
keyboard_hash
,
GUINT_TO_POINTER
(
keyboard_id
));
g_dbus_proxy_call
(
G_DBUS_PROXY
(
context
),
"RemoveKeyboard"
,
g_variant_new
(
"(u)"
,
keyboard_id
),
G_DBUS_CALL_FLAGS_NONE
,
-
1
,
cancellable
,
context_async_ready_callback
,
NULL
);
}
/**
* eekboard_context_set_keyboard:
* @context: an #EekboardContext
* @keyboard_id: keyboard ID
* @cancellable: a #GCancellable
*
* Select a keyboard with ID @keyboard_id in @context.
*/
void
eekboard_context_set_keyboard
(
EekboardContext
*
context
,
EekKeyboard
*
keyboard
,
guint
keyboard
_id
,
GCancellable
*
cancellable
)
{
EekboardContextPrivate
*
priv
;
GVariant
*
variant
;
EekKeyboard
*
keyboard
;
g_return_if_fail
(
EEKBOARD_IS_CONTEXT
(
context
));
g_return_if_fail
(
EEK_IS_KEYBOARD
(
keyboard
));
priv
=
EEKBOARD_CONTEXT_GET_PRIVATE
(
context
);
if
(
priv
->
keyboard
)
g_object_unref
(
priv
->
keyboard
);
priv
->
keyboard
=
g_object_ref
(
keyboard
);
priv
=
EEKBOARD_CONTEXT_GET_PRIVATE
(
context
);
keyboard
=
g_hash_table_lookup
(
priv
->
keyboard_hash
,
GUINT_TO_POINTER
(
keyboard_id
));
if
(
!
keyboard
||
keyboard
==
priv
->
keyboard
)
return
;
priv
->
keyboard
=
keyboard
;
variant
=
eek_serializable_serialize
(
EEK_SERIALIZABLE
(
priv
->
keyboard
));
g_dbus_proxy_call
(
G_DBUS_PROXY
(
context
),
"SetKeyboard"
,
g_variant_new
(
"(
v
)"
,
variant
),
g_variant_new
(
"(
u
)"
,
keyboard_id
),
G_DBUS_CALL_FLAGS_NONE
,
-
1
,
cancellable
,
context_async_ready_callback
,
NULL
);
g_variant_unref
(
variant
);
}
/**
...
...
eekboard/eekboard-context.h
View file @
0087f741
...
...
@@ -77,9 +77,16 @@ GType eekboard_context_get_type (void) G_GNUC_CONST;
EekboardContext
*
eekboard_context_new
(
GDBusConnection
*
connection
,
const
gchar
*
object_path
,
GCancellable
*
cancellable
);
void
eekboard_context_
set
_keyboard
(
EekboardContext
*
context
,
guint
eekboard_context_
add
_keyboard
(
EekboardContext
*
context
,
EekKeyboard
*
keyboard
,
GCancellable
*
cancellable
);
void
eekboard_context_remove_keyboard
(
EekboardContext
*
context
,
guint
keyboard_id
,
GCancellable
*
cancellable
);
void
eekboard_context_set_keyboard
(
EekboardContext
*
context
,
guint
keyboard_id
,
GCancellable
*
cancellable
);
void
eekboard_context_show_keyboard
(
EekboardContext
*
context
,
GCancellable
*
cancellable
);
void
eekboard_context_hide_keyboard
(
EekboardContext
*
context
,
...
...
src/client-main.c
View file @
0087f741
...
...
@@ -151,6 +151,7 @@ main (int argc, char **argv)
GFileInputStream
*
input
;
EekLayout
*
layout
;
EekKeyboard
*
keyboard
;
guint
keyboard_id
;
file
=
g_file_new_for_path
(
opt_set_keyboard
);
...
...
@@ -168,8 +169,10 @@ main (int argc, char **argv)
keyboard
=
eek_keyboard_new
(
layout
,
640
,
480
);
g_object_unref
(
layout
);
eekboard_context_
set
_keyboard
(
context
,
keyboard
,
NULL
);
keyboard_id
=
eekboard_context_
add
_keyboard
(
context
,
keyboard
,
NULL
);
g_object_unref
(
keyboard
);
eekboard_context_set_keyboard
(
context
,
keyboard_id
,
NULL
);
}
if
(
opt_set_group
>=
0
)
{
...
...
src/desktop-client.c
View file @
0087f741
...
...
@@ -474,6 +474,7 @@ set_keyboard (EekboardDesktopClient *client,
EekLayout
*
layout
;
gchar
*
keyboard_name
;
static
gint
keyboard_serial
=
0
;
guint
keyboard_id
;
if
(
client
->
keyboard
)
g_object_unref
(
client
->
keyboard
);
...
...
@@ -485,7 +486,10 @@ set_keyboard (EekboardDesktopClient *client,
keyboard_name
=
g_strdup_printf
(
"keyboard%d"
,
keyboard_serial
++
);
eek_element_set_name
(
EEK_ELEMENT
(
client
->
keyboard
),
keyboard_name
);
eekboard_context_set_keyboard
(
client
->
context
,
client
->
keyboard
,
NULL
);
keyboard_id
=
eekboard_context_add_keyboard
(
client
->
context
,
client
->
keyboard
,
NULL
);
eekboard_context_set_keyboard
(
client
->
context
,
keyboard_id
,
NULL
);
if
(
show
)
eekboard_context_show_keyboard
(
client
->
context
,
NULL
);
}
...
...
src/server-context.c
View file @
0087f741
...
...
@@ -46,8 +46,15 @@ enum {
static
const
gchar
introspection_xml
[]
=
"<node>"
" <interface name='com.redhat.Eekboard.Context'>"
" <method name='AddKeyboard'>"
" <arg direction='in' type='v' name='keyboard'/>"
" <arg direction='out' type='u' name='keyboard_id'/>"
" </method>"
" <method name='RemoveKeyboard'>"
" <arg direction='in' type='u' name='keyboard_id'/>"
" </method>"
" <method name='SetKeyboard'>"
" <arg type='
v
' name='keyboard'/>"
" <arg type='
u
' name='keyboard
_id
'/>"
" </method>"
" <method name='ShowKeyboard'/>"
" <method name='HideKeyboard'/>"
...
...
@@ -90,7 +97,9 @@ struct _ServerContext {
GtkWidget
*
window
;
GtkWidget
*
widget
;
guint
keyboard_id
;
EekKeyboard
*
keyboard
;
GHashTable
*
keyboard_hash
;
gulong
key_pressed_handler
;
gulong
key_released_handler
;
...
...
@@ -264,10 +273,14 @@ server_context_dispose (GObject *object)
if
(
context
->
keyboard
)
{
disconnect_keyboard_signals
(
context
);
g_object_unref
(
context
->
keyboard
);
context
->
keyboard
=
NULL
;
}
if
(
context
->
keyboard_hash
)
{
g_hash_table_destroy
(
context
->
keyboard_hash
);
context
->
keyboard_hash
=
NULL
;
}
if
(
context
->
window
)
{
gtk_widget_destroy
(
context
->
window
);
context
->
window
=
NULL
;
...
...
@@ -367,6 +380,12 @@ server_context_init (ServerContext *context)
context
->
last_keyboard_visible
=
FALSE
;
context
->
keyboard
=
NULL
;
context
->
keyboard_hash
=
g_hash_table_new_full
(
g_direct_hash
,
g_direct_equal
,
NULL
,
(
GDestroyNotify
)
g_object_unref
);
context
->
widget
=
NULL
;
context
->
window
=
NULL
;
context
->
key_pressed_handler
=
0
;
...
...
@@ -444,11 +463,13 @@ handle_method_call (GDBusConnection *connection,
{
ServerContext
*
context
=
user_data
;
if
(
g_strcmp0
(
method_name
,
"SetKeyboard"
)
==
0
)
{
EekSerializable
*
serializable
;
if
(
g_strcmp0
(
method_name
,
"AddKeyboard"
)
==
0
)
{
GVariant
*
variant
;
EekSerializable
*
serializable
;
static
guint
keyboard_id
=
0
;
g_variant_get
(
parameters
,
"(v)"
,
&
variant
);
serializable
=
eek_serializable_deserialize
(
variant
);
if
(
!
EEK_IS_KEYBOARD
(
serializable
))
{
g_dbus_method_invocation_return_error
(
invocation
,
...
...
@@ -457,9 +478,65 @@ handle_method_call (GDBusConnection *connection,
"not a keyboard"
);
return
;
}
context
->
keyboard
=
EEK_KEYBOARD
(
serializable
);
disconnect_keyboard_signals
(
context
);
eek_keyboard_set_modifier_behavior
(
EEK_KEYBOARD
(
serializable
),
EEK_MODIFIER_BEHAVIOR_LATCH
);
g_hash_table_insert
(
context
->
keyboard_hash
,
GUINT_TO_POINTER
(
++
keyboard_id
),
g_object_ref
(
serializable
));
g_dbus_method_invocation_return_value
(
invocation
,
g_variant_new
(
"(u)"
,
keyboard_id
));
return
;
}
if
(
g_strcmp0
(
method_name
,
"RemoveKeyboard"
)
==
0
)
{
guint
keyboard_id
;
g_variant_get
(
parameters
,
"(u)"
,
&
keyboard_id
);
if
(
keyboard_id
==
context
->
keyboard_id
)
{
disconnect_keyboard_signals
(
context
);
if
(
context
->
window
)
{
gtk_widget_hide
(
context
->
window
);
gtk_widget_destroy
(
context
->
widget
);
}
context
->
keyboard
=
NULL
;
}
g_hash_table_remove
(
context
->
keyboard_hash
,
GUINT_TO_POINTER
(
keyboard_id
));
g_dbus_method_invocation_return_value
(
invocation
,
NULL
);
return
;
}
if
(
g_strcmp0
(
method_name
,
"SetKeyboard"
)
==
0
)
{
EekKeyboard
*
keyboard
;
guint
keyboard_id
;
g_variant_get
(
parameters
,
"(u)"
,
&
keyboard_id
);
keyboard
=
g_hash_table_lookup
(
context
->
keyboard_hash
,
GUINT_TO_POINTER
(
keyboard_id
));
if
(
!
keyboard
)
{
g_dbus_method_invocation_return_error
(
invocation
,
G_IO_ERROR
,
G_IO_ERROR_FAILED_HANDLED
,
"no such keyboard"
);
return
;
}
if
(
keyboard
==
context
->
keyboard
)
{
g_dbus_method_invocation_return_value
(
invocation
,
NULL
);
return
;
}
if
(
context
->
keyboard
)
disconnect_keyboard_signals
(
context
);
context
->
keyboard
=
keyboard
;
context
->
key_pressed_handler
=
g_signal_connect
(
context
->
keyboard
,
"key-pressed"
,
G_CALLBACK
(
on_key_pressed
),
...
...
@@ -468,8 +545,6 @@ handle_method_call (GDBusConnection *connection,
g_signal_connect
(
context
->
keyboard
,
"key-released"
,
G_CALLBACK
(
on_key_released
),
context
);
eek_keyboard_set_modifier_behavior
(
context
->
keyboard
,
EEK_MODIFIER_BEHAVIOR_LATCH
);
if
(
context
->
window
)
{
gboolean
was_visible
=
gtk_widget_get_visible
(
context
->
window
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment