Skip to content
GitLab
Explore
Sign in
Register
Hypra
ibus-braille
Compare revisions
f621283cc8347c3eefb288db627b55c29eba2f00 to 9a034aeaac51f3c7f3a58edc4bf01aa4ce162604
Commits on Source (2)
fix braille pattern mask
· fbaedda5
Samuel Thibault
authored
Jun 13, 2019
fbaedda5
Handle BRLTTY restarts
· 9a034aea
Samuel Thibault
authored
Jun 13, 2019
9a034aea
Hide whitespace changes
Inline
Side-by-side
ibus-braille.py
View file @
9a034aea
...
...
@@ -145,7 +145,7 @@ class EngineBraille(IBus.Engine):
debug
(
2
,
"
focus out
"
)
self
.
__commit
()
self
.
enabled
=
False
self
.
brlapi_
disable
()
self
.
brlapi_
set
()
def
do_process_key_event
(
self
,
keysym
,
scancode
,
state
):
"""
...
...
@@ -168,10 +168,8 @@ class EngineBraille(IBus.Engine):
if
is_press
:
self
.
enabled
=
not
self
.
enabled
self
.
math
=
keysym
==
XK_Shift_R
or
keysym
==
XK_Control_R
if
self
.
enabled
:
self
.
brlapi_enable
()
else
:
self
.
brlapi_disable
()
self
.
brlapi_set
()
if
not
self
.
enabled
:
self
.
__commit
()
debug
(
2
,
"
enabled
"
if
self
.
enabled
else
"
disabled
"
)
debug
(
2
,
"
math
"
if
self
.
math
else
"
text
"
)
...
...
@@ -320,7 +318,7 @@ class EngineBraille(IBus.Engine):
self
.
__process_dot_key
(
keysym
-
XK_braille_dot_1
+
1
,
is_press
)
return
True
elif
keysym
&
~
0xff
==
XK_braille_blank
:
self
.
__process_pattern
(
keysym
&
0xff
ff
)
self
.
__process_pattern
(
keysym
&
0xff
)
return
True
else
:
if
self
.
contracted
:
...
...
@@ -331,33 +329,66 @@ class EngineBraille(IBus.Engine):
def
brlapi_init
(
self
):
"""
Initialization, called only once at startup
"""
def
_brlapi_init
():
"""
Try to (re)connect to BrlAPI
"""
self
.
brlapi_connection
=
brlapi
.
Connection
()
self
.
brlapi_connection
.
enterTtyModeWithPath
()
self
.
brlapi_set
()
GLib
.
io_add_watch
(
self
.
brlapi_connection
.
fileDescriptor
,
GLib
.
IOCondition
.
IN
,
process_brlapi
)
def
_brlapi_reconnect
():
"""
Callback which tries to reconnect to BrlAPI, to be called at
regular interval
"""
try
:
_brlapi_init
()
debug
(
4
,
"
Reconnected to BrlAPI
"
)
return
False
except
:
return
True
def
process_brlapi
(
fd
,
cond
):
# TODO: handle brltty restarts
k
=
self
.
brlapi_connection
.
readKey
(
wait
=
False
)
"""
The BrlAPI fd is available for read, process it
"""
try
:
k
=
self
.
brlapi_connection
.
readKey
(
wait
=
False
)
except
:
debug
(
4
,
"
BrlAPI connection lost, trying to reconnect...
"
)
try
:
self
.
brlapi_connection
.
closeConnection
()
except
:
pass
self
.
brlapi_connection
=
None
GLib
.
timeout_add_seconds
(
1
,
_brlapi_reconnect
)
return
False
if
k
==
None
:
# Processed some
stuff
, but no key event
# Processed some
data
, but no key event
in the pipe
return
True
dots
=
k
&
brlapi
.
KEY_CMD_ARG_MASK
debug
(
4
,
"
got braille %x from BrlAPI
"
%
dots
)
self
.
__process_pattern
(
dots
)
return
True
"""
At initialization, only try to connect to BrlAPI once, and if not
available, assume that it will never be
"""
try
:
self
.
brlapi_connection
=
brlapi
.
Connection
()
self
.
brlapi_connection
.
enterTtyModeWithPath
()
self
.
brlapi_disable
()
GLib
.
io_add_watch
(
self
.
brlapi_connection
.
fileDescriptor
,
GLib
.
IOCondition
.
IN
,
process_brlapi
)
_brlapi_init
()
except
:
debug
(
4
,
"
BrlAPI not available
"
)
pass
def
brlapi_enable
(
self
):
# TODO: clean and copy this example in python bindings doc
if
self
.
brlapi_connection
!=
None
:
self
.
brlapi_connection
.
acceptKeyRanges
([(
brlapi
.
KEY_TYPE_CMD
|
brlapi
.
KEY_CMD_PASSDOTS
,
brlapi
.
KEY_TYPE_CMD
|
brlapi
.
KEY_CMD_PASSDOTS
|
brlapi
.
KEY_CMD_ARG_MASK
)])
def
brlapi_set
(
self
):
"""
Update whether BrlAPI should pass us the dot patterns, or let
something else (e.g. brltty+xbrlapi) process them
"""
if
self
.
brlapi_connection
==
None
:
# Not connected
return
def
brlapi_disable
(
self
):
if
self
.
brlapi_connection
!=
None
:
self
.
brlapi_connection
.
ignoreKeys
(
brlapi
.
rangeType_all
,[
0
])
if
self
.
enabled
:
self
.
brlapi_connection
.
acceptKeyRanges
([(
brlapi
.
KEY_TYPE_CMD
|
brlapi
.
KEY_CMD_PASSDOTS
,
brlapi
.
KEY_TYPE_CMD
|
brlapi
.
KEY_CMD_PASSDOTS
|
brlapi
.
KEY_CMD_ARG_MASK
)])
else
:
self
.
brlapi_connection
.
ignoreAllKeys
()
def
__process_dot_key
(
self
,
dot
,
is_press
):
...
...