Compare commits
1 Commits
click
...
auto-gener
| Author | SHA1 | Date | |
|---|---|---|---|
| 901ca9ec76 |
20
autogen.sh
Executable file
20
autogen.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Run this to generate all the initial makefiles, etc.
|
||||
|
||||
srcdir=`dirname $0`
|
||||
test -z "$srcdir" && srcdir=.
|
||||
|
||||
PKG_NAME="eekboard"
|
||||
|
||||
(test -f $srcdir/configure.ac \
|
||||
&& test -f $srcdir/README.md ) || {
|
||||
echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
|
||||
echo " top-level $PKG_NAME directory"
|
||||
exit 1
|
||||
}
|
||||
|
||||
ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4"
|
||||
REQUIRED_AUTOMAKE_VERSION=1.10
|
||||
REQUIRED_AUTOCONF_VERSION=2.60
|
||||
|
||||
. gnome-autogen.sh
|
||||
@ -3,51 +3,51 @@
|
||||
<bounds x="0" y="10.000000" width="426.0000" height="296.5853"/>
|
||||
<section angle="0">
|
||||
<row orientation="1">
|
||||
<key keycode="24" name="AD01" oref="outline2" />
|
||||
<key keycode="25" name="AD02" oref="outline2" />
|
||||
<key keycode="26" name="AD03" oref="outline2" />
|
||||
<key keycode="27" name="AD04" oref="outline2" />
|
||||
<key keycode="28" name="AD05" oref="outline2" />
|
||||
<key keycode="29" name="AD06" oref="outline2" />
|
||||
<key keycode="30" name="AD07" oref="outline2" />
|
||||
<key keycode="31" name="AD08" oref="outline2" />
|
||||
<key keycode="32" name="AD09" oref="outline2" />
|
||||
<key keycode="33" name="AD10" oref="outline2" />
|
||||
<key name="AD01" oref="outline2" />
|
||||
<key name="AD02" oref="outline2" />
|
||||
<key name="AD03" oref="outline2" />
|
||||
<key name="AD04" oref="outline2" />
|
||||
<key name="AD05" oref="outline2" />
|
||||
<key name="AD06" oref="outline2" />
|
||||
<key name="AD07" oref="outline2" />
|
||||
<key name="AD08" oref="outline2" />
|
||||
<key name="AD09" oref="outline2" />
|
||||
<key name="AD10" oref="outline2" />
|
||||
</row>
|
||||
</section>
|
||||
<section angle="0">
|
||||
<row orientation="1">
|
||||
<key keycode="38" name="AC01" oref="outline2" />
|
||||
<key keycode="39" name="AC02" oref="outline2" />
|
||||
<key keycode="40" name="AC03" oref="outline2" />
|
||||
<key keycode="41" name="AC04" oref="outline2" />
|
||||
<key keycode="42" name="AC05" oref="outline2" />
|
||||
<key keycode="43" name="AC06" oref="outline2" />
|
||||
<key keycode="44" name="AC07" oref="outline2" />
|
||||
<key keycode="45" name="AC08" oref="outline2" />
|
||||
<key keycode="46" name="AC09" oref="outline2" />
|
||||
<key name="AC01" oref="outline2" />
|
||||
<key name="AC02" oref="outline2" />
|
||||
<key name="AC03" oref="outline2" />
|
||||
<key name="AC04" oref="outline2" />
|
||||
<key name="AC05" oref="outline2" />
|
||||
<key name="AC06" oref="outline2" />
|
||||
<key name="AC07" oref="outline2" />
|
||||
<key name="AC08" oref="outline2" />
|
||||
<key name="AC09" oref="outline2" />
|
||||
</row>
|
||||
</section>
|
||||
<section angle="0">
|
||||
<row orientation="1">
|
||||
<key keycode="50" name="LFSH" oref="altline" />
|
||||
<key keycode="52" name="AB01" oref="outline2" />
|
||||
<key keycode="53" name="AB02" oref="outline2" />
|
||||
<key keycode="54" name="AB03" oref="outline2" />
|
||||
<key keycode="55" name="AB04" oref="outline2" />
|
||||
<key keycode="56" name="AB05" oref="outline2" />
|
||||
<key keycode="57" name="AB06" oref="outline2" />
|
||||
<key keycode="58" name="AB07" oref="outline2" />
|
||||
<key keycode="22" name="BKSP" oref="altline" />
|
||||
<key name="LFSH" oref="altline" />
|
||||
<key name="AB01" oref="outline2" />
|
||||
<key name="AB02" oref="outline2" />
|
||||
<key name="AB03" oref="outline2" />
|
||||
<key name="AB04" oref="outline2" />
|
||||
<key name="AB05" oref="outline2" />
|
||||
<key name="AB06" oref="outline2" />
|
||||
<key name="AB07" oref="outline2" />
|
||||
<key name="BKSP" oref="altline" />
|
||||
</row>
|
||||
</section>
|
||||
<section angle="0">
|
||||
<row orientation="1">
|
||||
<key keycode="0" name="ABC123" oref="altline" />
|
||||
<key keycode="150" name="I150" oref="altline" />
|
||||
<key keycode="65" name="SPCE" oref="spaceline" />
|
||||
<key keycode="60" name="AB09" oref="outline2" />
|
||||
<key keycode="36" name="RTRN" oref="outline7" />
|
||||
<key name="ABC123" oref="altline" />
|
||||
<key name="I150" oref="altline" />
|
||||
<key name="SPCE" oref="spaceline" />
|
||||
<key name="AB08" oref="outline2" />
|
||||
<key name="RTRN" oref="outline7" />
|
||||
</row>
|
||||
</section>
|
||||
<outline id="outline2" corner-radius="1.000000">
|
||||
|
||||
@ -1,276 +1,180 @@
|
||||
<?xml version="1.0"?>
|
||||
<symbols version="0.90">
|
||||
<key keycode="9" name="ESC">
|
||||
<keysym keyval="65307">Escape</keysym>
|
||||
</key>
|
||||
<key keycode="67" name="FK01">
|
||||
<keysym keyval="65470">F1</keysym>
|
||||
</key>
|
||||
<key keycode="68" name="FK02">
|
||||
<keysym keyval="65471">F2</keysym>
|
||||
</key>
|
||||
<key keycode="69" name="FK03">
|
||||
<keysym keyval="65472">F3</keysym>
|
||||
</key>
|
||||
<key keycode="70" name="FK04">
|
||||
<keysym keyval="65473">F4</keysym>
|
||||
</key>
|
||||
<key keycode="71" name="FK05">
|
||||
<keysym keyval="65474">F5</keysym>
|
||||
</key>
|
||||
<key keycode="72" name="FK06">
|
||||
<keysym keyval="65475">F6</keysym>
|
||||
</key>
|
||||
<key keycode="73" name="FK07">
|
||||
<keysym keyval="65476">F7</keysym>
|
||||
</key>
|
||||
<key keycode="74" name="FK08">
|
||||
<keysym keyval="65477">F8</keysym>
|
||||
</key>
|
||||
<key keycode="75" name="FK09">
|
||||
<keysym keyval="65478">F9</keysym>
|
||||
</key>
|
||||
<key keycode="76" name="FK10">
|
||||
<keysym keyval="65479">F10</keysym>
|
||||
</key>
|
||||
<key keycode="95" name="FK11">
|
||||
<keysym keyval="65480">F11</keysym>
|
||||
</key>
|
||||
<key keycode="96" name="FK12">
|
||||
<keysym keyval="65481">F12</keysym>
|
||||
</key>
|
||||
<key keycode="22" name="BKSP">
|
||||
<keysym keyval="65288" icon="edit-clear-symbolic">backspace</keysym>
|
||||
</key>
|
||||
<key keycode="23" name="TAB">
|
||||
<keysym keyval="65289">Tab</keysym>
|
||||
<keysym keyval="65056">ISO_Left_Tab</keysym>
|
||||
</key>
|
||||
<key keycode="24" name="AD01">
|
||||
<key name="AD01">
|
||||
<keysym keyval="113">q</keysym>
|
||||
<keysym keyval="81">Q</keysym>
|
||||
<keysym keyval="49">1</keysym>
|
||||
<keysym keyval="126">asciitilde</keysym>
|
||||
</key>
|
||||
<key keycode="25" name="AD02">
|
||||
<key name="AD02">
|
||||
<keysym keyval="119">w</keysym>
|
||||
<keysym keyval="87">W</keysym>
|
||||
<keysym keyval="50">2</keysym>
|
||||
<keysym keyval="96">quoteleft</keysym>
|
||||
</key>
|
||||
<key keycode="26" name="AD03">
|
||||
<key name="AD03">
|
||||
<keysym keyval="101">e</keysym>
|
||||
<keysym keyval="69">E</keysym>
|
||||
<keysym keyval="51">3</keysym>
|
||||
<keysym keyval="124">bar</keysym>
|
||||
</key>
|
||||
<key keycode="27" name="AD04">
|
||||
<key name="AD04">
|
||||
<keysym keyval="114">r</keysym>
|
||||
<keysym keyval="82">R</keysym>
|
||||
<keysym keyval="52">4</keysym>
|
||||
<keysym keyval="183">middledot</keysym>
|
||||
</key>
|
||||
<key keycode="28" name="AD05">
|
||||
<key name="AD05">
|
||||
<keysym keyval="116">t</keysym>
|
||||
<keysym keyval="84">T</keysym>
|
||||
<keysym keyval="53">5</keysym>
|
||||
</key>
|
||||
<key keycode="29" name="AD06">
|
||||
<key name="AD06">
|
||||
<keysym keyval="121">y</keysym>
|
||||
<keysym keyval="89">Y</keysym>
|
||||
<keysym keyval="54">6</keysym>
|
||||
</key>
|
||||
<key keycode="30" name="AD07">
|
||||
<key name="AD07">
|
||||
<keysym keyval="117">u</keysym>
|
||||
<keysym keyval="85">U</keysym>
|
||||
<keysym keyval="55">7</keysym>
|
||||
</key>
|
||||
<key keycode="31" name="AD08">
|
||||
<key name="AD08">
|
||||
<keysym keyval="105">i</keysym>
|
||||
<keysym keyval="73">I</keysym>
|
||||
<keysym keyval="56">8</keysym>
|
||||
</key>
|
||||
<key keycode="32" name="AD09">
|
||||
<key name="AD09">
|
||||
<keysym keyval="111">o</keysym>
|
||||
<keysym keyval="79">O</keysym>
|
||||
<keysym keyval="57">9</keysym>
|
||||
</key>
|
||||
<key keycode="33" name="AD10">
|
||||
<key name="AD10">
|
||||
<keysym keyval="112">p</keysym>
|
||||
<keysym keyval="80">P</keysym>
|
||||
<keysym keyval="48">0</keysym>
|
||||
</key>
|
||||
<key keycode="34" name="AD11">
|
||||
<keysym keyval="91">bracketleft</keysym>
|
||||
<keysym keyval="123">braceleft</keysym>
|
||||
</key>
|
||||
<key keycode="35" name="AD12">
|
||||
<keysym keyval="93">bracketright</keysym>
|
||||
<keysym keyval="125">braceright</keysym>
|
||||
</key>
|
||||
<key keycode="51" name="BKSL">
|
||||
<keysym keyval="92">backslash</keysym>
|
||||
<keysym keyval="124">bar</keysym>
|
||||
</key>
|
||||
<key keycode="0" name="ABC123">
|
||||
<symbol label="123">show-numbers</symbol>
|
||||
<symbol label="123">show-numbers</symbol>
|
||||
<symbol label="ABC">show-letters</symbol>
|
||||
<symbol label="ABC">show-letters</symbol>
|
||||
</key>
|
||||
<key keycode="38" name="AC01">
|
||||
<key name="AC01">
|
||||
<keysym keyval="97">a</keysym>
|
||||
<keysym keyval="65">A</keysym>
|
||||
<keysym keyval="64">at</keysym>
|
||||
<keysym keyval="169">copyright</keysym>
|
||||
</key>
|
||||
<key keycode="39" name="AC02">
|
||||
<key name="AC02">
|
||||
<keysym keyval="115">s</keysym>
|
||||
<keysym keyval="83">S</keysym>
|
||||
<keysym keyval="35">numbersign</keysym>
|
||||
<keysym keyval="174">registeredtrademark</keysym>
|
||||
</key>
|
||||
<key keycode="40" name="AC03">
|
||||
<key name="AC03">
|
||||
<keysym keyval="100">d</keysym>
|
||||
<keysym keyval="68">D</keysym>
|
||||
<keysym keyval="36">dollar</keysym>
|
||||
<keysym keyval="163">poundsign</keysym>
|
||||
</key>
|
||||
<key keycode="41" name="AC04">
|
||||
<key name="AC04">
|
||||
<keysym keyval="102">f</keysym>
|
||||
<keysym keyval="70">F</keysym>
|
||||
<keysym keyval="37">percent</keysym>
|
||||
<text>€</text>
|
||||
</key>
|
||||
<key keycode="42" name="AC05">
|
||||
<key name="AC05">
|
||||
<keysym keyval="103">g</keysym>
|
||||
<keysym keyval="71">G</keysym>
|
||||
<keysym keyval="38">ampersand</keysym>
|
||||
<keysym keyval="165">yensign</keysym>
|
||||
</key>
|
||||
<key keycode="43" name="AC06">
|
||||
<key name="AC06">
|
||||
<keysym keyval="104">h</keysym>
|
||||
<keysym keyval="72">H</keysym>
|
||||
<keysym keyval="45">minus</keysym>
|
||||
<keysym keyval="94">asciicircum</keysym>
|
||||
</key>
|
||||
<key keycode="44" name="AC07">
|
||||
<key name="AC07">
|
||||
<keysym keyval="106">j</keysym>
|
||||
<keysym keyval="74">J</keysym>
|
||||
<keysym keyval="43">plus</keysym>
|
||||
<keysym keyval="176">degreesign</keysym>
|
||||
</key>
|
||||
<key keycode="45" name="AC08">
|
||||
<key name="AC08">
|
||||
<keysym keyval="107">k</keysym>
|
||||
<keysym keyval="75">K</keysym>
|
||||
<keysym keyval="40">parenleft</keysym>
|
||||
<keysym keyval="123">braceleft</keysym>
|
||||
</key>
|
||||
<key keycode="46" name="AC09">
|
||||
<key name="AC09">
|
||||
<keysym keyval="108">l</keysym>
|
||||
<keysym keyval="76">L</keysym>
|
||||
<keysym keyval="41">parenright</keysym>
|
||||
<keysym keyval="125">braceright</keysym>
|
||||
</key>
|
||||
<key keycode="47" name="AC10">
|
||||
<keysym keyval="59">semicolon</keysym>
|
||||
<keysym keyval="58">colon</keysym>
|
||||
</key>
|
||||
<key keycode="48" name="AC11">
|
||||
<keysym keyval="39">quoteright</keysym>
|
||||
<keysym keyval="34">quotedbl</keysym>
|
||||
</key>
|
||||
<key keycode="36" name="RTRN">
|
||||
<key name="RTRN">
|
||||
<keysym keyval="65293" icon="key-enter">Return</keysym>
|
||||
</key>
|
||||
<key keycode="50" name="LFSH">
|
||||
<key name="LFSH">
|
||||
<keysym keyval="65505" icon="key-shift">Shift_L</keysym>
|
||||
<keysym keyval="65505" icon="key-shift">Shift_L</keysym>
|
||||
<keysym keyval="65505" label="=/+">Shift_L</keysym>
|
||||
<keysym keyval="65505" label="123">Shift_L</keysym>
|
||||
</key>
|
||||
<key keycode="52" name="AB01">
|
||||
<key name="AB01">
|
||||
<keysym keyval="122">z</keysym>
|
||||
<keysym keyval="90">Z</keysym>
|
||||
<keysym keyval="44">comma</keysym>
|
||||
<keysym keyval="92">backslash</keysym>
|
||||
</key>
|
||||
<key keycode="53" name="AB02">
|
||||
<key name="AB02">
|
||||
<keysym keyval="120">x</keysym>
|
||||
<keysym keyval="88">X</keysym>
|
||||
<keysym keyval="34">quotedbl</keysym>
|
||||
<keysym keyval="47">slash</keysym>
|
||||
</key>
|
||||
<key keycode="54" name="AB03">
|
||||
<key name="AB03">
|
||||
<keysym keyval="99">c</keysym>
|
||||
<keysym keyval="67">C</keysym>
|
||||
<keysym keyval="39">quoteright</keysym>
|
||||
<keysym keyval="60">less</keysym>
|
||||
</key>
|
||||
<key keycode="55" name="AB04">
|
||||
<key name="AB04">
|
||||
<keysym keyval="118">v</keysym>
|
||||
<keysym keyval="86">V</keysym>
|
||||
<keysym keyval="58">colon</keysym>
|
||||
<keysym keyval="62">greater</keysym>
|
||||
</key>
|
||||
<key keycode="56" name="AB05">
|
||||
<key name="AB05">
|
||||
<keysym keyval="98">b</keysym>
|
||||
<keysym keyval="66">B</keysym>
|
||||
<keysym keyval="59">semicolon</keysym>
|
||||
<keysym keyval="61">equal</keysym>
|
||||
</key>
|
||||
<key keycode="57" name="AB06">
|
||||
<key name="AB06">
|
||||
<keysym keyval="110">n</keysym>
|
||||
<keysym keyval="78">N</keysym>
|
||||
<keysym keyval="33">exclam</keysym>
|
||||
<keysym keyval="91">bracketleft</keysym>
|
||||
</key>
|
||||
<key keycode="58" name="AB07">
|
||||
<key name="AB07">
|
||||
<keysym keyval="109">m</keysym>
|
||||
<keysym keyval="77">M</keysym>
|
||||
<keysym keyval="63">question</keysym>
|
||||
<keysym keyval="93">bracketright</keysym>
|
||||
</key>
|
||||
<key keycode="59" name="AB08">
|
||||
<keysym keyval="44">comma</keysym>
|
||||
<keysym keyval="60">less</keysym>
|
||||
</key>
|
||||
<key keycode="60" name="AB09">
|
||||
<key name="AB08">
|
||||
<keysym keyval="46">period</keysym>
|
||||
</key>
|
||||
<key keycode="61" name="AB10">
|
||||
<keysym keyval="47">slash</keysym>
|
||||
<keysym keyval="63">question</keysym>
|
||||
<key name="ABC123">
|
||||
<symbol label="123">show-numbers</symbol>
|
||||
<symbol label="123">show-numbers</symbol>
|
||||
<symbol label="ABC">show-letters</symbol>
|
||||
<symbol label="ABC">show-letters</symbol>
|
||||
</key>
|
||||
<key keycode="62" name="RTSH">
|
||||
<keysym keyval="65506">Shift_R</keysym>
|
||||
</key>
|
||||
<key keycode="149" name="I149">
|
||||
<symbol label="⌨" icon="input-keyboard-symbolic" tooltip="Change keyboard">cycle-keyboard</symbol>
|
||||
</key>
|
||||
<key keycode="150" name="I150">
|
||||
<key name="I150">
|
||||
<symbol label="☺" icon="keyboard-mode-symbolic" tooltip="Setup">preferences</symbol>
|
||||
</key>
|
||||
<key keycode="37" name="LCTL">
|
||||
<keysym keyval="65507">Control_L</keysym>
|
||||
</key>
|
||||
<key keycode="64" name="LALT">
|
||||
<keysym keyval="65513">Alt_L</keysym>
|
||||
<keysym keyval="65511">Meta_L</keysym>
|
||||
</key>
|
||||
<key keycode="65" name="SPCE">
|
||||
<key name="SPCE">
|
||||
<keysym keyval="32">space</keysym>
|
||||
</key>
|
||||
<key keycode="113" name="LEFT">
|
||||
<keysym keyval="65361">Left</keysym>
|
||||
</key>
|
||||
<key keycode="111" name="UP">
|
||||
<keysym keyval="65362">Up</keysym>
|
||||
</key>
|
||||
<key keycode="116" name="DOWN">
|
||||
<keysym keyval="65364">Down</keysym>
|
||||
</key>
|
||||
<key keycode="114" name="RGHT">
|
||||
<keysym keyval="65363">Right</keysym>
|
||||
<key name="BKSP">
|
||||
<keysym keyval="65288" icon="edit-clear-symbolic">backspace</keysym>
|
||||
</key>
|
||||
</symbols>
|
||||
|
||||
0
eek/config.h
Normal file
0
eek/config.h
Normal file
@ -23,10 +23,12 @@
|
||||
* @short_description: a #GtkWidget displaying #EekKeyboard
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#ifdef HAVE_GSOUND
|
||||
#include <gsound.h>
|
||||
#ifdef HAVE_LIBCANBERRA
|
||||
#include <canberra-gtk.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
@ -55,10 +57,10 @@ typedef struct _EekGtkKeyboardPrivate
|
||||
{
|
||||
EekRenderer *renderer;
|
||||
EekKeyboard *keyboard;
|
||||
gulong key_locked_handler;
|
||||
gulong key_unlocked_handler;
|
||||
gulong symbol_index_changed_handler;
|
||||
EekTheme *theme;
|
||||
#ifdef HAVE_GSOUND
|
||||
GSoundContext *sound_ctx;
|
||||
#endif
|
||||
|
||||
GdkEventSequence *sequence; // unowned reference
|
||||
} EekGtkKeyboardPrivate;
|
||||
@ -122,8 +124,6 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
|
||||
eek_renderer_set_allocation_size (priv->renderer,
|
||||
allocation.width,
|
||||
allocation.height);
|
||||
eek_renderer_set_scale_factor (priv->renderer,
|
||||
gtk_widget_get_scale_factor (self));
|
||||
}
|
||||
|
||||
eek_renderer_render_keyboard (priv->renderer, cr);
|
||||
@ -330,21 +330,15 @@ eek_gtk_keyboard_set_keyboard (EekGtkKeyboard *self,
|
||||
EekKeyboard *keyboard)
|
||||
{
|
||||
EekGtkKeyboardPrivate *priv = eek_gtk_keyboard_get_instance_private (self);
|
||||
|
||||
if (priv->keyboard == keyboard)
|
||||
return;
|
||||
|
||||
if (priv->keyboard) {
|
||||
g_signal_handlers_disconnect_by_data(priv->keyboard, self);
|
||||
g_object_unref (priv->keyboard);
|
||||
}
|
||||
|
||||
priv->keyboard = g_object_ref (keyboard);
|
||||
|
||||
priv->key_locked_handler =
|
||||
g_signal_connect (priv->keyboard, "key-locked",
|
||||
G_CALLBACK(on_key_locked), self);
|
||||
priv->key_unlocked_handler =
|
||||
g_signal_connect (priv->keyboard, "key-unlocked",
|
||||
G_CALLBACK(on_key_unlocked), self);
|
||||
priv->symbol_index_changed_handler =
|
||||
g_signal_connect (priv->keyboard, "symbol-index-changed",
|
||||
G_CALLBACK(on_symbol_index_changed), self);
|
||||
}
|
||||
@ -380,9 +374,21 @@ eek_gtk_keyboard_dispose (GObject *object)
|
||||
}
|
||||
|
||||
if (priv->keyboard) {
|
||||
if (g_signal_handler_is_connected (priv->keyboard,
|
||||
priv->key_locked_handler))
|
||||
g_signal_handler_disconnect (priv->keyboard,
|
||||
priv->key_locked_handler);
|
||||
if (g_signal_handler_is_connected (priv->keyboard,
|
||||
priv->key_unlocked_handler))
|
||||
g_signal_handler_disconnect (priv->keyboard,
|
||||
priv->key_unlocked_handler);
|
||||
if (g_signal_handler_is_connected (priv->keyboard,
|
||||
priv->symbol_index_changed_handler))
|
||||
g_signal_handler_disconnect (priv->keyboard,
|
||||
priv->symbol_index_changed_handler);
|
||||
|
||||
GList *list, *head;
|
||||
|
||||
g_signal_handlers_disconnect_by_data(priv->keyboard, self);
|
||||
list = eek_keyboard_get_pressed_keys (priv->keyboard);
|
||||
for (head = list; head; head = g_list_next (head)) {
|
||||
g_log("squeek", G_LOG_LEVEL_DEBUG, "emit EekKey pressed");
|
||||
@ -439,16 +445,7 @@ eek_gtk_keyboard_class_init (EekGtkKeyboardClass *klass)
|
||||
static void
|
||||
eek_gtk_keyboard_init (EekGtkKeyboard *self)
|
||||
{
|
||||
#if HAVE_GSOUND
|
||||
EekGtkKeyboardPrivate *priv = eek_gtk_keyboard_get_instance_private (self);
|
||||
GError *err = NULL;
|
||||
|
||||
priv->sound_ctx = gsound_context_new(NULL, &err);
|
||||
if (!priv->sound_ctx) {
|
||||
g_warning ("GSound init failed: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
}
|
||||
#endif
|
||||
/* void */
|
||||
}
|
||||
|
||||
/**
|
||||
@ -487,6 +484,45 @@ magnify_bounds (GtkWidget *self,
|
||||
large_bounds->y = CLAMP(y, 0, allocation.height - large_bounds->height);
|
||||
}
|
||||
|
||||
/*
|
||||
* Alleviate the asymmetry between drawing a pressed key and a released key,
|
||||
* and consistently draw to the exact same area.
|
||||
*
|
||||
* By saving the dirty rectangle we can limit drawing of the backbuffer to
|
||||
* the screen as well, eg gdk_window_invalidate_rect() instead of
|
||||
* gtk_widget_queue_draw() which redraws the entire widget.
|
||||
*
|
||||
* b1 is mandatory, b2 is optional
|
||||
*/
|
||||
static GdkRectangle
|
||||
clip_bounds_to_dirty_rectangle (cairo_t *cr, EekBounds *b1, EekBounds *b2)
|
||||
{
|
||||
if (b2)
|
||||
cairo_rectangle (cr, b2->x, b2->y, b2->width, b2->height);
|
||||
|
||||
cairo_rectangle (cr, b1->x, b1->y, b1->width, b1->height);
|
||||
cairo_clip (cr);
|
||||
|
||||
/*
|
||||
* save the clipped region to a bounding box so we can limit
|
||||
* the drawing of the backbuffer to the screen to the same area
|
||||
*/
|
||||
cairo_rectangle_t bbox;
|
||||
|
||||
cairo_clip_extents (cr, &bbox.x, &bbox.y, &bbox.width, &bbox.height);
|
||||
|
||||
/* convert double to int, making sure r strictly covers bbox to avoid
|
||||
* artefacts. floor() is unnecessary, ceil() is not */
|
||||
GdkRectangle r = {
|
||||
floor (bbox.x),
|
||||
floor (bbox.y),
|
||||
ceil (bbox.width),
|
||||
ceil (bbox.height)
|
||||
};
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
render_pressed_key (GtkWidget *widget,
|
||||
EekKey *key)
|
||||
@ -503,6 +539,12 @@ render_pressed_key (GtkWidget *widget,
|
||||
eek_renderer_get_key_bounds (priv->renderer, key, &bounds, TRUE);
|
||||
magnify_bounds (widget, &bounds, &large_bounds, 1.5);
|
||||
|
||||
/*
|
||||
* clip to limit drawing to backbuffer and save clip region to dirty_rect
|
||||
* to limit redrawing of the backbuffer to the same area
|
||||
*/
|
||||
GdkRectangle dirty_rect = clip_bounds_to_dirty_rectangle (cr, &bounds, &large_bounds);
|
||||
|
||||
cairo_save (cr);
|
||||
cairo_translate (cr, bounds.x, bounds.y);
|
||||
eek_renderer_render_key (priv->renderer, cr, key, 1.0, TRUE);
|
||||
@ -516,6 +558,9 @@ render_pressed_key (GtkWidget *widget,
|
||||
gdk_window_end_draw_frame (window, context);
|
||||
|
||||
cairo_region_destroy (region);
|
||||
|
||||
/* force immediate drawing of the backbuffer to the screen */
|
||||
gdk_window_invalidate_rect (window, &dirty_rect, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -533,12 +578,21 @@ render_locked_key (GtkWidget *widget,
|
||||
|
||||
eek_renderer_get_key_bounds (priv->renderer, key, &bounds, TRUE);
|
||||
|
||||
/*
|
||||
* clip to limit drawing to backbuffer and save clip region to dirty_rect
|
||||
* to limit redrawing of the backbuffer to the same area
|
||||
*/
|
||||
GdkRectangle dirty_rect = clip_bounds_to_dirty_rectangle (cr, &bounds, NULL);
|
||||
|
||||
cairo_translate (cr, bounds.x, bounds.y);
|
||||
eek_renderer_render_key (priv->renderer, cr, key, 1.0, TRUE);
|
||||
|
||||
gdk_window_end_draw_frame (window, context);
|
||||
|
||||
cairo_region_destroy (region);
|
||||
|
||||
/* force immediate drawing of the backbuffer to the screen */
|
||||
gdk_window_invalidate_rect (window, &dirty_rect, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -557,11 +611,20 @@ render_released_key (GtkWidget *widget,
|
||||
eek_renderer_get_key_bounds (priv->renderer, key, &bounds, TRUE);
|
||||
magnify_bounds (widget, &bounds, &large_bounds, 1.5);
|
||||
|
||||
/*
|
||||
* clip to limit drawing to backbuffer and save clip region to dirty_rect
|
||||
* to limit redrawing of the backbuffer to the same area
|
||||
*/
|
||||
GdkRectangle dirty_rect = clip_bounds_to_dirty_rectangle(cr, &bounds, &large_bounds);
|
||||
|
||||
eek_renderer_render_keyboard (priv->renderer, cr);
|
||||
|
||||
gdk_window_end_draw_frame (window, context);
|
||||
|
||||
cairo_region_destroy (region);
|
||||
|
||||
/* force immediate drawing of the backbuffer to the screen */
|
||||
gdk_window_invalidate_rect (window, &dirty_rect, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -575,13 +638,12 @@ on_key_pressed (EekKey *key,
|
||||
return;
|
||||
|
||||
render_pressed_key (GTK_WIDGET(self), key);
|
||||
gtk_widget_queue_draw (GTK_WIDGET(self));
|
||||
|
||||
#if HAVE_GSOUND
|
||||
g_return_if_fail (GSOUND_IS_CONTEXT (priv->sound_ctx));
|
||||
gsound_context_play_simple(priv->sound_ctx, NULL, NULL,
|
||||
GSOUND_ATTR_EVENT_ID, "button-pressed",
|
||||
GSOUND_ATTR_EVENT_DESCRIPTION, "Button pressed",
|
||||
#if HAVE_LIBCANBERRA
|
||||
ca_gtk_play_for_widget (widget, 0,
|
||||
CA_PROP_EVENT_ID, "button-pressed",
|
||||
CA_PROP_EVENT_DESCRIPTION, "virtual key pressed",
|
||||
CA_PROP_APPLICATION_ID, "org.fedorahosted.Eekboard",
|
||||
NULL);
|
||||
#endif
|
||||
}
|
||||
@ -597,13 +659,12 @@ on_key_released (EekKey *key,
|
||||
return;
|
||||
|
||||
render_released_key (GTK_WIDGET(self), key);
|
||||
gtk_widget_queue_draw (GTK_WIDGET(self));
|
||||
|
||||
#if HAVE_GSOUND
|
||||
g_return_if_fail (GSOUND_IS_CONTEXT (priv->sound_ctx));
|
||||
gsound_context_play_simple(priv->sound_ctx, NULL, NULL,
|
||||
GSOUND_ATTR_EVENT_ID, "button-released",
|
||||
GSOUND_ATTR_EVENT_DESCRIPTION, "Button released",
|
||||
#if HAVE_LIBCANBERRA
|
||||
ca_gtk_play_for_widget (widget, 0,
|
||||
CA_PROP_EVENT_ID, "button-released",
|
||||
CA_PROP_EVENT_DESCRIPTION, "virtual key pressed",
|
||||
CA_PROP_APPLICATION_ID, "org.fedorahosted.Eekboard",
|
||||
NULL);
|
||||
#endif
|
||||
}
|
||||
@ -621,7 +682,6 @@ on_key_locked (EekKeyboard *keyboard,
|
||||
return;
|
||||
|
||||
render_locked_key (widget, key);
|
||||
gtk_widget_queue_draw (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -637,7 +697,6 @@ on_key_unlocked (EekKeyboard *keyboard,
|
||||
return;
|
||||
|
||||
render_released_key (widget, key);
|
||||
gtk_widget_queue_draw (GTK_WIDGET(widget));
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -30,29 +30,66 @@
|
||||
|
||||
G_DEFINE_TYPE (EekGtkRenderer, eek_gtk_renderer, EEK_TYPE_RENDERER);
|
||||
|
||||
static cairo_surface_t *
|
||||
pixbuf_to_cairo_surface (GdkPixbuf *pixbuf)
|
||||
{
|
||||
cairo_surface_t *dummy_surface;
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
|
||||
dummy_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
|
||||
|
||||
cr = cairo_create (dummy_surface);
|
||||
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
|
||||
pattern = cairo_get_source (cr);
|
||||
cairo_pattern_get_surface (pattern, &surface);
|
||||
cairo_surface_reference (surface);
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (dummy_surface);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
static cairo_surface_t *
|
||||
eek_gtk_renderer_real_get_icon_surface (EekRenderer *self,
|
||||
const gchar *icon_name,
|
||||
gint size,
|
||||
gint scale)
|
||||
gint size)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
GError *error = NULL;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
|
||||
gchar *path = g_strconcat("/sm/puri/squeekboard/icons/", icon_name, ".svg", NULL);
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_resource_at_scale (path, size, size,
|
||||
TRUE, &error);
|
||||
|
||||
if (pixbuf != NULL)
|
||||
goto found;
|
||||
else {
|
||||
/* g_warning ("can't get icon pixbuf for %s: %s", path, error->message);*/
|
||||
g_error_free (error);
|
||||
error = NULL;
|
||||
}
|
||||
g_free(path);
|
||||
|
||||
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
|
||||
icon_name,
|
||||
size,
|
||||
scale,
|
||||
NULL,
|
||||
0,
|
||||
&error);
|
||||
if (surface == NULL) {
|
||||
g_warning ("can't get icon surface for %s: %s",
|
||||
if (pixbuf == NULL) {
|
||||
g_warning ("can't get icon pixbuf for %s: %s",
|
||||
icon_name,
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
found:
|
||||
surface = pixbuf_to_cairo_surface (pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
return surface;
|
||||
}
|
||||
|
||||
@ -67,9 +104,6 @@ eek_gtk_renderer_class_init (EekGtkRendererClass *klass)
|
||||
static void
|
||||
eek_gtk_renderer_init (EekGtkRenderer *self)
|
||||
{
|
||||
GtkIconTheme *theme = gtk_icon_theme_get_default ();
|
||||
|
||||
gtk_icon_theme_add_resource_path (theme, "/sm/puri/squeekboard/icons");
|
||||
}
|
||||
|
||||
EekRenderer *
|
||||
|
||||
@ -74,7 +74,7 @@ struct _EekKeyboardPrivate
|
||||
GList *pressed_keys;
|
||||
GList *locked_keys;
|
||||
GArray *outline_array;
|
||||
GHashTable *keycodes;
|
||||
GHashTable *names;
|
||||
|
||||
/* modifiers dynamically assigned at run time */
|
||||
EekModifierType num_lock_mask;
|
||||
@ -129,9 +129,9 @@ section_child_added_cb (EekContainer *container,
|
||||
EekElement *element,
|
||||
EekKeyboard *keyboard)
|
||||
{
|
||||
guint keycode = eek_key_get_keycode (EEK_KEY(element));
|
||||
g_hash_table_insert (keyboard->priv->keycodes,
|
||||
GUINT_TO_POINTER(keycode),
|
||||
const gchar *name = eek_element_get_name(element);
|
||||
g_hash_table_insert (keyboard->priv->names,
|
||||
(gpointer)name,
|
||||
element);
|
||||
}
|
||||
|
||||
@ -140,9 +140,9 @@ section_child_removed_cb (EekContainer *container,
|
||||
EekElement *element,
|
||||
EekKeyboard *keyboard)
|
||||
{
|
||||
guint keycode = eek_key_get_keycode (EEK_KEY(element));
|
||||
g_hash_table_remove (keyboard->priv->keycodes,
|
||||
GUINT_TO_POINTER(keycode));
|
||||
const gchar *name = eek_element_get_name(element);
|
||||
g_hash_table_remove (keyboard->priv->names,
|
||||
name);
|
||||
}
|
||||
|
||||
static EekSection *
|
||||
@ -221,7 +221,7 @@ set_level_from_modifiers (EekKeyboard *self, EekKey *key)
|
||||
gint level = priv->old_level & 2;
|
||||
|
||||
/* Handle non-emitting keys */
|
||||
if (key && (eek_key_get_keycode(key) == 0)) {
|
||||
if (key) {
|
||||
const gchar *name = eek_element_get_name(EEK_ELEMENT(key));
|
||||
if (g_strcmp0(name, "ABC123") == 0)
|
||||
level ^= 2;
|
||||
@ -400,7 +400,7 @@ eek_keyboard_finalize (GObject *object)
|
||||
g_list_free_full (priv->locked_keys,
|
||||
(GDestroyNotify) eek_modifier_key_free);
|
||||
|
||||
g_hash_table_destroy (priv->keycodes);
|
||||
g_hash_table_destroy (priv->names);
|
||||
|
||||
for (i = 0; i < priv->outline_array->len; i++) {
|
||||
EekOutline *outline = &g_array_index (priv->outline_array,
|
||||
@ -528,7 +528,7 @@ eek_keyboard_init (EekKeyboard *self)
|
||||
self->priv = EEK_KEYBOARD_GET_PRIVATE(self);
|
||||
self->priv->modifier_behavior = EEK_MODIFIER_BEHAVIOR_NONE;
|
||||
self->priv->outline_array = g_array_new (FALSE, TRUE, sizeof (EekOutline));
|
||||
self->priv->keycodes = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
self->priv->names = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
eek_element_set_symbol_index (EEK_ELEMENT(self), 0, 0);
|
||||
}
|
||||
|
||||
@ -548,20 +548,20 @@ eek_keyboard_create_section (EekKeyboard *keyboard)
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_keyboard_find_key_by_keycode:
|
||||
* eek_keyboard_find_key_by_name:
|
||||
* @keyboard: an #EekKeyboard
|
||||
* @keycode: a keycode
|
||||
* @name: a key name
|
||||
*
|
||||
* Find an #EekKey whose keycode is @keycode.
|
||||
* Return value: (transfer none): #EekKey whose keycode is @keycode
|
||||
* Find an #EekKey whose name is @name.
|
||||
* Return value: (transfer none): #EekKey whose name is @name
|
||||
*/
|
||||
EekKey *
|
||||
eek_keyboard_find_key_by_keycode (EekKeyboard *keyboard,
|
||||
guint keycode)
|
||||
eek_keyboard_find_key_by_name (EekKeyboard *keyboard,
|
||||
const gchar *name)
|
||||
{
|
||||
g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL);
|
||||
return g_hash_table_lookup (keyboard->priv->keycodes,
|
||||
GUINT_TO_POINTER(keycode));
|
||||
return g_hash_table_lookup (keyboard->priv->names,
|
||||
name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -69,8 +69,8 @@ struct _EekKeyboard
|
||||
/**
|
||||
* EekKeyboardClass:
|
||||
* @create_section: virtual function for creating a section
|
||||
* @find_key_by_keycode: virtual function for finding a key in the
|
||||
* keyboard by keycode
|
||||
* @find_key_by_name: virtual function for finding a key in the
|
||||
* keyboard by name
|
||||
* @key_pressed: class handler for #EekKeyboard::key-pressed signal
|
||||
* @key_released: class handler for #EekKeyboard::key-released signal
|
||||
* @key_locked: class handler for #EekKeyboard::key-locked signal
|
||||
@ -89,8 +89,8 @@ struct _EekKeyboardClass
|
||||
/*< public >*/
|
||||
EekSection *(* create_section) (EekKeyboard *self);
|
||||
|
||||
EekKey *(* find_key_by_keycode) (EekKeyboard *self,
|
||||
guint keycode);
|
||||
EekKey *(* find_key_by_name) (EekKeyboard *self,
|
||||
const gchar *name);
|
||||
|
||||
/*< private >*/
|
||||
/* obsolete members moved to EekElement */
|
||||
@ -155,9 +155,9 @@ EekModifierType eek_keyboard_get_modifiers
|
||||
EekSection *eek_keyboard_create_section
|
||||
(EekKeyboard *keyboard);
|
||||
|
||||
EekKey *eek_keyboard_find_key_by_keycode
|
||||
EekKey *eek_keyboard_find_key_by_name
|
||||
(EekKeyboard *keyboard,
|
||||
guint keycode);
|
||||
const gchar *name);
|
||||
|
||||
guint eek_keyboard_add_outline
|
||||
(EekKeyboard *keyboard,
|
||||
|
||||
@ -48,7 +48,6 @@ typedef struct _EekRendererPrivate
|
||||
gdouble allocation_width;
|
||||
gdouble allocation_height;
|
||||
gdouble scale;
|
||||
gint scale_factor; /* the outputs scale factor */
|
||||
|
||||
PangoFontDescription *ascii_font;
|
||||
PangoFontDescription *font;
|
||||
@ -500,21 +499,21 @@ render_key (EekRenderer *self,
|
||||
|
||||
#define SCALE 0.4
|
||||
if (eek_symbol_get_icon_name (symbol)) {
|
||||
gint scale = priv->scale_factor;
|
||||
|
||||
cairo_surface_t *icon_surface =
|
||||
eek_renderer_get_icon_surface (self,
|
||||
eek_symbol_get_icon_name (symbol),
|
||||
SCALE * MIN(bounds.width, bounds.height),
|
||||
scale);
|
||||
MIN(bounds.width, bounds.height));
|
||||
if (icon_surface) {
|
||||
gint width = cairo_image_surface_get_width (icon_surface);
|
||||
gint height = cairo_image_surface_get_height (icon_surface);
|
||||
|
||||
cairo_save (cr);
|
||||
cairo_translate (cr,
|
||||
(bounds.width - width / scale) / 2,
|
||||
(bounds.height - height / scale) / 2);
|
||||
(bounds.width - width * SCALE) / 2,
|
||||
(bounds.height - height * SCALE) / 2);
|
||||
cairo_rectangle (cr, 0, 0, width, height);
|
||||
cairo_scale (cr, SCALE, SCALE);
|
||||
cairo_clip (cr);
|
||||
/* Draw the shape of the icon using the foreground color */
|
||||
cairo_set_source_rgba (cr, foreground.red,
|
||||
@ -845,7 +844,6 @@ eek_renderer_init (EekRenderer *self)
|
||||
priv->allocation_width = 0.0;
|
||||
priv->allocation_height = 0.0;
|
||||
priv->scale = 1.0;
|
||||
priv->scale_factor = 1;
|
||||
priv->font = NULL;
|
||||
priv->outline_surface_cache =
|
||||
g_hash_table_new_full (g_direct_hash,
|
||||
@ -1030,15 +1028,6 @@ eek_renderer_get_scale (EekRenderer *renderer)
|
||||
return priv->scale;
|
||||
}
|
||||
|
||||
void
|
||||
eek_renderer_set_scale_factor (EekRenderer *renderer, gint scale)
|
||||
{
|
||||
g_return_if_fail (EEK_IS_RENDERER(renderer));
|
||||
|
||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
|
||||
priv->scale_factor = scale;
|
||||
}
|
||||
|
||||
PangoLayout *
|
||||
eek_renderer_create_pango_layout (EekRenderer *renderer)
|
||||
{
|
||||
@ -1082,8 +1071,7 @@ eek_renderer_render_key_outline (EekRenderer *renderer,
|
||||
cairo_surface_t *
|
||||
eek_renderer_get_icon_surface (EekRenderer *renderer,
|
||||
const gchar *icon_name,
|
||||
gint size,
|
||||
gint scale)
|
||||
gint size)
|
||||
{
|
||||
EekRendererClass *klass;
|
||||
|
||||
@ -1091,7 +1079,7 @@ eek_renderer_get_icon_surface (EekRenderer *renderer,
|
||||
|
||||
klass = EEK_RENDERER_GET_CLASS(renderer);
|
||||
if (klass->get_icon_surface)
|
||||
return klass->get_icon_surface (renderer, icon_name, size, scale);
|
||||
return klass->get_icon_surface (renderer, icon_name, size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -58,8 +58,7 @@ struct _EekRendererClass
|
||||
|
||||
cairo_surface_t *(* get_icon_surface) (EekRenderer *self,
|
||||
const gchar *icon_name,
|
||||
gint size,
|
||||
gint scale);
|
||||
gint size);
|
||||
|
||||
/*< private >*/
|
||||
/* padding */
|
||||
@ -82,8 +81,6 @@ void eek_renderer_get_key_bounds (EekRenderer *renderer,
|
||||
gboolean rotate);
|
||||
|
||||
gdouble eek_renderer_get_scale (EekRenderer *renderer);
|
||||
void eek_renderer_set_scale_factor (EekRenderer *renderer,
|
||||
gint scale);
|
||||
|
||||
PangoLayout *eek_renderer_create_pango_layout
|
||||
(EekRenderer *renderer);
|
||||
@ -106,8 +103,7 @@ void eek_renderer_render_key (EekRenderer *renderer,
|
||||
|
||||
cairo_surface_t *eek_renderer_get_icon_surface (EekRenderer *renderer,
|
||||
const gchar *icon_name,
|
||||
gint size,
|
||||
gint scale);
|
||||
gint size);
|
||||
|
||||
void eek_renderer_render_keyboard (EekRenderer *renderer,
|
||||
cairo_t *cr);
|
||||
|
||||
@ -124,7 +124,8 @@ on_unlocked (EekKey *key,
|
||||
|
||||
static EekKey *
|
||||
eek_section_real_create_key (EekSection *self,
|
||||
guint keycode,
|
||||
const gchar *name,
|
||||
gint keycode,
|
||||
gint column_index,
|
||||
gint row_index)
|
||||
{
|
||||
@ -142,6 +143,7 @@ eek_section_real_create_key (EekSection *self,
|
||||
row->num_columns = column_index + 1;
|
||||
|
||||
key = g_object_new (EEK_TYPE_KEY,
|
||||
"name", name,
|
||||
"keycode", keycode,
|
||||
"column", column_index,
|
||||
"row", row_index,
|
||||
@ -463,6 +465,7 @@ eek_section_get_row (EekSection *section,
|
||||
/**
|
||||
* eek_section_create_key:
|
||||
* @section: an #EekSection
|
||||
* @name: a name
|
||||
* @keycode: a keycode
|
||||
* @column: the column index of the key
|
||||
* @row: the row index of the key
|
||||
@ -473,12 +476,14 @@ eek_section_get_row (EekSection *section,
|
||||
*/
|
||||
EekKey *
|
||||
eek_section_create_key (EekSection *section,
|
||||
guint keycode,
|
||||
const gchar *name,
|
||||
gint keycode,
|
||||
gint column,
|
||||
gint row)
|
||||
{
|
||||
g_return_val_if_fail (EEK_IS_SECTION(section), NULL);
|
||||
return EEK_SECTION_GET_CLASS(section)->create_key (section,
|
||||
name,
|
||||
keycode,
|
||||
column,
|
||||
row);
|
||||
|
||||
@ -62,7 +62,8 @@ struct _EekSectionClass
|
||||
EekOrientation *orientation);
|
||||
|
||||
EekKey *(* create_key) (EekSection *self,
|
||||
guint keycode,
|
||||
const gchar *name,
|
||||
gint keycode,
|
||||
gint row,
|
||||
gint column);
|
||||
|
||||
@ -99,7 +100,8 @@ void eek_section_get_row (EekSection *section,
|
||||
EekOrientation *orientation);
|
||||
|
||||
EekKey *eek_section_create_key (EekSection *section,
|
||||
guint keycode,
|
||||
const gchar *name,
|
||||
gint keycode,
|
||||
gint column,
|
||||
gint row);
|
||||
|
||||
|
||||
30
eek/eek-xkb-0.90.pc.in
Normal file
30
eek/eek-xkb-0.90.pc.in
Normal file
@ -0,0 +1,30 @@
|
||||
# Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
# Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License
|
||||
# as published by the Free Software Foundation; either version 2 of
|
||||
# the License, or (at your option) any later version.
|
||||
|
||||
# This library is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
# 02110-1301 USA
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: libeek-xkb
|
||||
Description: A Library to Create Keyboard-like UI (XKB Support)
|
||||
URL: http://fedorahosted.org/eekboard/
|
||||
Version: @VERSION@
|
||||
Requires: eek-@EEK_API_VERSION@ gtk+-x11-@GTK_API_VERSION@
|
||||
Libs: -L${libdir} -leek-xkb
|
||||
Cflags: -I${includedir}/eek-@EEK_API_VERSION@
|
||||
684
eek/eek-xkb-layout.c
Normal file
684
eek/eek-xkb-layout.c
Normal file
@ -0,0 +1,684 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Sergey V. Udaltsov <svu@gnome.org>
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:eek-xkb-layout
|
||||
* @short_description: Layout engine using XKB configuration
|
||||
*
|
||||
* The #EekXkbLayout inherits #EekLayout class and arranges keyboard
|
||||
* elements using XKB.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include "eek-xkb-layout.h"
|
||||
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/extensions/XKBgeom.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "eek-keyboard.h"
|
||||
#include "eek-section.h"
|
||||
#include "eek-key.h"
|
||||
#include "eek-keysym.h"
|
||||
|
||||
#define XKB_COMPONENT_MASK (XkbGBN_GeometryMask | \
|
||||
XkbGBN_KeyNamesMask | \
|
||||
XkbGBN_OtherNamesMask | \
|
||||
XkbGBN_SymbolsMask | \
|
||||
XkbGBN_IndicatorMapMask)
|
||||
|
||||
static void initable_iface_init (GInitableIface *initable_iface);
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DISPLAY,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
typedef struct _EekXkbLayoutPrivate
|
||||
{
|
||||
/* Configuration names that should synch'ed to the symbolic names
|
||||
in priv->xkb->names. Since we use GLib's memory allocator,
|
||||
don't store any address returned from the X server here. */
|
||||
XkbComponentNamesRec names;
|
||||
|
||||
Display *display;
|
||||
|
||||
/* Actual XKB configuration of DISPLAY. */
|
||||
XkbDescRec *xkb;
|
||||
|
||||
/* Hash table to cache orefs by shape address. */
|
||||
GHashTable *shape_oref_hash;
|
||||
|
||||
gint scale_numerator;
|
||||
gint scale_denominator;
|
||||
} EekXkbLayoutPrivate;
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (EekXkbLayout, eek_xkb_layout, EEK_TYPE_LAYOUT,
|
||||
0, /* GTypeFlags */
|
||||
G_ADD_PRIVATE(EekXkbLayout)
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||
initable_iface_init))
|
||||
|
||||
static guint find_keycode (EekXkbLayout *layout,
|
||||
gchar *key_name);
|
||||
|
||||
static gboolean get_keyboard_from_server (EekXkbLayout *layout,
|
||||
GError **error);
|
||||
|
||||
static gboolean get_names_from_server (EekXkbLayout *layout,
|
||||
GError **error);
|
||||
|
||||
static void setup_scaling (EekXkbLayout *layout,
|
||||
gdouble width,
|
||||
gdouble height);
|
||||
|
||||
G_INLINE_FUNC gint
|
||||
xkb_to_pixmap_coord (EekXkbLayout *layout,
|
||||
gint n)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
return n * priv->scale_numerator / priv->scale_denominator;
|
||||
}
|
||||
|
||||
G_INLINE_FUNC gdouble
|
||||
xkb_to_pixmap_double (EekXkbLayout *layout,
|
||||
gdouble d)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
return d * priv->scale_numerator / priv->scale_denominator;
|
||||
}
|
||||
|
||||
static void
|
||||
create_key (EekXkbLayout *layout,
|
||||
EekKeyboard *keyboard,
|
||||
EekSection *section,
|
||||
gint column,
|
||||
gint row,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
XkbKeyRec *xkbkey)
|
||||
{
|
||||
XkbGeometryRec *xkbgeometry;
|
||||
XkbBoundsRec *xkbbounds;
|
||||
XkbShapeRec *xkbshape;
|
||||
XkbOutlineRec *xkboutline;
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
EekKey *key;
|
||||
EekBounds bounds;
|
||||
EekSymbolMatrix *matrix = NULL;
|
||||
gchar name[XkbKeyNameLength + 1];
|
||||
KeyCode keycode;
|
||||
gint num_groups, num_levels;
|
||||
guint oref;
|
||||
gpointer v;
|
||||
|
||||
xkbgeometry = priv->xkb->geom;
|
||||
xkbshape = &xkbgeometry->shapes[xkbkey->shape_ndx];
|
||||
if (g_hash_table_lookup_extended (priv->shape_oref_hash, xkbshape,
|
||||
NULL, &v)) {
|
||||
oref = GPOINTER_TO_UINT(v);
|
||||
} else {
|
||||
EekOutline *outline;
|
||||
|
||||
xkboutline = xkbshape->primary == NULL ? &xkbshape->outlines[0] :
|
||||
xkbshape->primary;
|
||||
|
||||
outline = g_slice_new (EekOutline);
|
||||
outline->corner_radius = xkb_to_pixmap_coord(layout,
|
||||
xkboutline->corner_radius);
|
||||
|
||||
if (xkboutline->num_points <= 2) { /* rectangular */
|
||||
gdouble x1, y1, x2, y2;
|
||||
|
||||
outline->num_points = 4;
|
||||
outline->points = g_slice_alloc0 (sizeof (EekPoint) *
|
||||
outline->num_points);
|
||||
if (xkboutline->num_points == 1) {
|
||||
x1 = xkb_to_pixmap_coord(layout, xkbshape->bounds.x1);
|
||||
y1 = xkb_to_pixmap_coord(layout, xkbshape->bounds.y1);
|
||||
x2 = xkb_to_pixmap_coord(layout, xkboutline->points[0].x);
|
||||
y2 = xkb_to_pixmap_coord(layout, xkboutline->points[0].y);
|
||||
} else {
|
||||
x1 = xkb_to_pixmap_coord(layout, xkboutline->points[0].x);
|
||||
y1 = xkb_to_pixmap_coord(layout, xkboutline->points[0].y);
|
||||
x2 = xkb_to_pixmap_coord(layout, xkboutline->points[1].x);
|
||||
y2 = xkb_to_pixmap_coord(layout, xkboutline->points[1].y);
|
||||
}
|
||||
outline->points[0].x = outline->points[3].x = x1;
|
||||
outline->points[0].y = outline->points[1].y = y1;
|
||||
outline->points[1].x = outline->points[2].x = x2;
|
||||
outline->points[2].y = outline->points[3].y = y2;
|
||||
} else { /* polygon */
|
||||
gint i;
|
||||
|
||||
outline->num_points = xkboutline->num_points;
|
||||
outline->points = g_new0 (EekPoint, outline->num_points);
|
||||
for (i = 0; i < xkboutline->num_points; i++) {
|
||||
outline->points[i].x =
|
||||
xkb_to_pixmap_coord(layout, xkboutline->points[i].x);
|
||||
outline->points[i].y =
|
||||
xkb_to_pixmap_coord(layout, xkboutline->points[i].y);
|
||||
}
|
||||
}
|
||||
oref = eek_keyboard_add_outline (keyboard, outline);
|
||||
eek_outline_free (outline);
|
||||
g_hash_table_insert (priv->shape_oref_hash, xkbshape,
|
||||
GUINT_TO_POINTER(oref));
|
||||
}
|
||||
|
||||
memset (name, 0, sizeof name);
|
||||
memcpy (name, xkbkey->name.name, sizeof name - 1);
|
||||
|
||||
xkbbounds = &xkbgeometry->shapes[xkbkey->shape_ndx].bounds;
|
||||
bounds.x = xkb_to_pixmap_coord(layout, xkbbounds->x1 + x);
|
||||
bounds.y = xkb_to_pixmap_coord(layout, xkbbounds->y1 + y);
|
||||
bounds.width = xkb_to_pixmap_coord(layout, xkbbounds->x2 - xkbbounds->x1);
|
||||
bounds.height = xkb_to_pixmap_coord(layout, xkbbounds->y2 - xkbbounds->y1);
|
||||
|
||||
keycode = find_keycode (layout, name);
|
||||
if (keycode == EEK_INVALID_KEYCODE) {
|
||||
num_groups = num_levels = 0;
|
||||
matrix = eek_symbol_matrix_new (0, 0);
|
||||
} else {
|
||||
KeySym keysym;
|
||||
gint i, j;
|
||||
|
||||
num_groups = XkbKeyNumGroups (priv->xkb, keycode);
|
||||
num_levels = XkbKeyGroupsWidth (priv->xkb, keycode);
|
||||
matrix = eek_symbol_matrix_new (num_groups, num_levels);
|
||||
for (i = 0; i < num_groups; i++)
|
||||
for (j = 0; j < num_levels; j++) {
|
||||
EekModifierType modifier;
|
||||
|
||||
keysym = XkbKeySymEntry (priv->xkb, keycode, j, i);
|
||||
modifier = XkbKeysymToModifiers (priv->display, keysym);
|
||||
matrix->data[i * num_levels + j] =
|
||||
EEK_SYMBOL(eek_keysym_new_with_modifier (keysym,
|
||||
modifier));
|
||||
}
|
||||
}
|
||||
|
||||
key = eek_section_create_key (section, keycode, column, row);
|
||||
eek_element_set_name (EEK_ELEMENT(key), name);
|
||||
eek_element_set_bounds (EEK_ELEMENT(key), &bounds);
|
||||
eek_key_set_symbol_matrix (key, matrix);
|
||||
eek_symbol_matrix_free (matrix);
|
||||
eek_key_set_oref (key, oref);
|
||||
}
|
||||
|
||||
static void
|
||||
create_section (EekXkbLayout *layout,
|
||||
EekKeyboard *keyboard,
|
||||
XkbSectionRec *xkbsection)
|
||||
{
|
||||
XkbGeometryRec *xkbgeometry;
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
EekSection *section;
|
||||
EekBounds bounds;
|
||||
gchar *name;
|
||||
gfloat left, top;
|
||||
gint i, j;
|
||||
|
||||
bounds.x = xkb_to_pixmap_coord(layout, xkbsection->left);
|
||||
bounds.y = xkb_to_pixmap_coord(layout, xkbsection->top);
|
||||
bounds.width = xkb_to_pixmap_coord(layout, xkbsection->width);
|
||||
bounds.height = xkb_to_pixmap_coord(layout, xkbsection->height);
|
||||
|
||||
xkbgeometry = priv->xkb->geom;
|
||||
section = eek_keyboard_create_section (keyboard);
|
||||
name = XGetAtomName (priv->display, xkbsection->name);
|
||||
eek_element_set_name (EEK_ELEMENT(section), name);
|
||||
XFree (name);
|
||||
eek_element_set_bounds (EEK_ELEMENT(section), &bounds);
|
||||
eek_section_set_angle (section,
|
||||
/* angle is in tenth of degree */
|
||||
xkbsection->angle / 10);
|
||||
|
||||
for (i = 0; i < xkbsection->num_rows; i++) {
|
||||
XkbRowRec *xkbrow;
|
||||
|
||||
xkbrow = &xkbsection->rows[i];
|
||||
left = xkbrow->left;
|
||||
top = xkbrow->top;
|
||||
eek_section_add_row (section,
|
||||
xkbrow->num_keys,
|
||||
xkbrow->vertical ?
|
||||
EEK_ORIENTATION_VERTICAL :
|
||||
EEK_ORIENTATION_HORIZONTAL);
|
||||
for (j = 0; j < xkbrow->num_keys; j++) {
|
||||
XkbKeyRec *xkbkey;
|
||||
XkbBoundsRec *xkbbounds;
|
||||
|
||||
xkbkey = &xkbrow->keys[j];
|
||||
if (xkbrow->vertical)
|
||||
top += xkbkey->gap;
|
||||
else
|
||||
left += xkbkey->gap;
|
||||
create_key (layout, keyboard, section, j, i, left, top, xkbkey);
|
||||
xkbbounds = &xkbgeometry->shapes[xkbkey->shape_ndx].bounds;
|
||||
if (xkbrow->vertical)
|
||||
top += xkbbounds->y2 - xkbbounds->y1;
|
||||
else
|
||||
left += xkbbounds->x2 - xkbbounds->x1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
create_keyboard (EekXkbLayout *layout, EekKeyboard *keyboard)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
XkbGeometryRec *xkbgeometry;
|
||||
EekBounds bounds;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (priv->xkb);
|
||||
g_return_if_fail (priv->xkb->geom);
|
||||
|
||||
xkbgeometry = priv->xkb->geom;
|
||||
|
||||
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
|
||||
setup_scaling (EEK_XKB_LAYOUT(layout), bounds.width, bounds.height);
|
||||
|
||||
bounds.x = bounds.y = 0;
|
||||
bounds.width = xkb_to_pixmap_coord(layout, xkbgeometry->width_mm);
|
||||
bounds.height = xkb_to_pixmap_coord(layout, xkbgeometry->height_mm);
|
||||
|
||||
for (i = 0; i < xkbgeometry->num_sections; i++) {
|
||||
XkbSectionRec *xkbsection;
|
||||
|
||||
xkbsection = &xkbgeometry->sections[i];
|
||||
create_section (layout, keyboard, xkbsection);
|
||||
}
|
||||
eek_element_set_bounds (EEK_ELEMENT(keyboard), &bounds);
|
||||
}
|
||||
|
||||
static EekKeyboard *
|
||||
eek_xkb_layout_real_create_keyboard (EekboardContextService *manager,
|
||||
EekLayout *self,
|
||||
gdouble initial_width,
|
||||
gdouble initial_height)
|
||||
{
|
||||
EekKeyboard *keyboard = g_object_new (EEK_TYPE_KEYBOARD, "layout", self, NULL);
|
||||
keyboard->manager = manager;
|
||||
|
||||
EekBounds bounds = {
|
||||
.x = 0.0,
|
||||
.y = 0.0,
|
||||
.width = initial_width,
|
||||
.height = initial_height
|
||||
};
|
||||
eek_element_set_bounds (EEK_ELEMENT(keyboard), &bounds);
|
||||
|
||||
/* resolve modifiers dynamically assigned at run time */
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (
|
||||
EEK_XKB_LAYOUT(self));
|
||||
eek_keyboard_set_num_lock_mask (keyboard,
|
||||
XkbKeysymToModifiers (priv->display,
|
||||
XK_Num_Lock));
|
||||
eek_keyboard_set_alt_gr_mask (keyboard,
|
||||
XkbKeysymToModifiers (priv->display,
|
||||
XK_ISO_Level3_Shift));
|
||||
|
||||
if (priv->shape_oref_hash)
|
||||
g_hash_table_destroy (priv->shape_oref_hash);
|
||||
|
||||
priv->shape_oref_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
create_keyboard (EEK_XKB_LAYOUT(self), keyboard);
|
||||
g_hash_table_destroy (priv->shape_oref_hash);
|
||||
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkb_layout_finalize (GObject *object)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (
|
||||
EEK_XKB_LAYOUT (object));
|
||||
|
||||
g_free (priv->names.keycodes);
|
||||
g_free (priv->names.geometry);
|
||||
g_free (priv->names.symbols);
|
||||
XkbFreeKeyboard (priv->xkb, 0, TRUE); /* free_all = TRUE */
|
||||
G_OBJECT_CLASS (eek_xkb_layout_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkb_layout_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EekXkbLayout *layout = EEK_XKB_LAYOUT (object);
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DISPLAY:
|
||||
priv->display = g_value_get_pointer (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkb_layout_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EekXkbLayout *layout = EEK_XKB_LAYOUT (object);
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DISPLAY:
|
||||
g_value_set_pointer (value, priv->display);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkb_layout_class_init (EekXkbLayoutClass *klass)
|
||||
{
|
||||
EekLayoutClass *layout_class = EEK_LAYOUT_CLASS (klass);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
layout_class->create_keyboard = eek_xkb_layout_real_create_keyboard;
|
||||
|
||||
gobject_class->finalize = eek_xkb_layout_finalize;
|
||||
gobject_class->set_property = eek_xkb_layout_set_property;
|
||||
gobject_class->get_property = eek_xkb_layout_get_property;
|
||||
|
||||
pspec = g_param_spec_pointer ("display",
|
||||
"Display",
|
||||
"X Display",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (gobject_class, PROP_DISPLAY, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkb_layout_init (EekXkbLayout *self)
|
||||
{
|
||||
/* void */
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_names_from_server (EekXkbLayout *layout,
|
||||
GError **error)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
gchar *name;
|
||||
|
||||
XkbGetNames (priv->display, XkbAllNamesMask, priv->xkb);
|
||||
|
||||
if (priv->xkb->names->keycodes <= 0)
|
||||
g_warning ("XKB keycodes setting is not loaded properly");
|
||||
else {
|
||||
name = XGetAtomName (priv->display, priv->xkb->names->keycodes);
|
||||
if (!name)
|
||||
g_warning ("Can't get the name of keycodes");
|
||||
else if (!priv->names.keycodes ||
|
||||
g_strcmp0 (name, priv->names.keycodes)) {
|
||||
g_free (priv->names.keycodes);
|
||||
priv->names.keycodes = g_strdup (name);
|
||||
XFree (name);
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->xkb->names->geometry <= 0)
|
||||
g_warning ("XKB geometry setting is not loaded");
|
||||
else {
|
||||
name = XGetAtomName (priv->display, priv->xkb->names->geometry);
|
||||
if (!name)
|
||||
g_warning ("Can't get the name of geometry");
|
||||
else if (!priv->names.geometry ||
|
||||
g_strcmp0 (name, priv->names.geometry)) {
|
||||
g_free (priv->names.geometry);
|
||||
priv->names.geometry = g_strdup (name);
|
||||
XFree (name);
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->xkb->names->symbols <= 0)
|
||||
g_warning ("XKB symbols setting is not loaded");
|
||||
else {
|
||||
name = XGetAtomName (priv->display, priv->xkb->names->symbols);
|
||||
if (!name)
|
||||
g_warning ("Can't get the name of symbols");
|
||||
else if (!priv->names.symbols ||
|
||||
g_strcmp0 (name, priv->names.symbols)) {
|
||||
g_free (priv->names.symbols);
|
||||
priv->names.symbols = g_strdup (name);
|
||||
XFree (name);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkb_layout_new:
|
||||
*
|
||||
* Create a new #EekXkbLayout.
|
||||
*/
|
||||
EekLayout *
|
||||
eek_xkb_layout_new (Display *display,
|
||||
GError **error)
|
||||
{
|
||||
return (EekLayout *) g_initable_new (EEK_TYPE_XKB_LAYOUT,
|
||||
NULL,
|
||||
error,
|
||||
"display", display,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkb_layout_set_names: (skip)
|
||||
* @layout: an #EekXkbLayout
|
||||
* @names: XKB component names
|
||||
* @error: a #GError
|
||||
*
|
||||
* Set the XKB component names to @layout.
|
||||
* Returns: %TRUE if the component names are successfully set, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkb_layout_set_names (EekXkbLayout *layout,
|
||||
XkbComponentNamesRec *names,
|
||||
GError **error)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
|
||||
if (g_strcmp0 (names->keycodes, priv->names.keycodes)) {
|
||||
g_free (priv->names.keycodes);
|
||||
priv->names.keycodes = g_strdup (names->keycodes);
|
||||
}
|
||||
|
||||
if (g_strcmp0 (names->geometry, priv->names.geometry)) {
|
||||
g_free (priv->names.geometry);
|
||||
priv->names.geometry = g_strdup (names->geometry);
|
||||
}
|
||||
|
||||
if (g_strcmp0 (names->symbols, priv->names.symbols)) {
|
||||
g_free (priv->names.symbols);
|
||||
priv->names.symbols = g_strdup (names->symbols);
|
||||
}
|
||||
|
||||
return get_keyboard_from_server (layout, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_keyboard_from_server (EekXkbLayout *layout,
|
||||
GError **error)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
|
||||
if (priv->xkb) {
|
||||
XkbFreeKeyboard (priv->xkb, 0, True);
|
||||
priv->xkb = NULL;
|
||||
}
|
||||
|
||||
if (priv->names.keycodes && priv->names.geometry && priv->names.symbols) {
|
||||
priv->xkb = XkbGetKeyboardByName (priv->display,
|
||||
XkbUseCoreKbd,
|
||||
&priv->names,
|
||||
0,
|
||||
XKB_COMPONENT_MASK,
|
||||
False);
|
||||
} else {
|
||||
priv->xkb = XkbGetKeyboard (priv->display,
|
||||
XKB_COMPONENT_MASK,
|
||||
XkbUseCoreKbd);
|
||||
if (!get_names_from_server (layout, error)) {
|
||||
XkbFreeKeyboard (priv->xkb, 0, True);
|
||||
priv->xkb = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->xkb == NULL) {
|
||||
g_set_error (error,
|
||||
EEK_ERROR,
|
||||
EEK_ERROR_LAYOUT_ERROR,
|
||||
"can't get keyboard from server");
|
||||
g_free (priv->names.keycodes);
|
||||
priv->names.keycodes = NULL;
|
||||
g_free (priv->names.geometry);
|
||||
priv->names.geometry = NULL;
|
||||
g_free (priv->names.symbols);
|
||||
priv->names.symbols = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static guint
|
||||
find_keycode (EekXkbLayout *layout, gchar *key_name)
|
||||
{
|
||||
#define KEYSYM_NAME_MAX_LENGTH 4
|
||||
guint keycode;
|
||||
gint i, j;
|
||||
XkbKeyNamePtr pkey;
|
||||
XkbKeyAliasPtr palias;
|
||||
guint is_name_matched;
|
||||
gchar *src, *dst;
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
|
||||
if (!priv->xkb)
|
||||
return EEK_INVALID_KEYCODE;
|
||||
|
||||
pkey = priv->xkb->names->keys + priv->xkb->min_key_code;
|
||||
for (keycode = priv->xkb->min_key_code;
|
||||
keycode <= priv->xkb->max_key_code; keycode++) {
|
||||
is_name_matched = 1;
|
||||
src = key_name;
|
||||
dst = pkey->name;
|
||||
for (i = KEYSYM_NAME_MAX_LENGTH; --i >= 0;) {
|
||||
if ('\0' == *src)
|
||||
break;
|
||||
if (*src++ != *dst++) {
|
||||
is_name_matched = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_name_matched)
|
||||
return keycode;
|
||||
pkey++;
|
||||
}
|
||||
|
||||
palias = priv->xkb->names->key_aliases;
|
||||
for (j = priv->xkb->names->num_key_aliases; --j >= 0;) {
|
||||
is_name_matched = 1;
|
||||
src = key_name;
|
||||
dst = palias->alias;
|
||||
for (i = KEYSYM_NAME_MAX_LENGTH; --i >= 0;) {
|
||||
if ('\0' == *src)
|
||||
break;
|
||||
if (*src++ != *dst++) {
|
||||
is_name_matched = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_name_matched) {
|
||||
keycode = find_keycode (layout, palias->real);
|
||||
return keycode;
|
||||
}
|
||||
palias++;
|
||||
}
|
||||
|
||||
return EEK_INVALID_KEYCODE;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_scaling (EekXkbLayout *layout,
|
||||
gdouble width,
|
||||
gdouble height)
|
||||
{
|
||||
EekXkbLayoutPrivate *priv = eek_xkb_layout_get_instance_private (layout);
|
||||
|
||||
g_return_if_fail (priv->xkb);
|
||||
|
||||
g_return_if_fail (priv->xkb->geom->width_mm > 0);
|
||||
g_return_if_fail (priv->xkb->geom->height_mm > 0);
|
||||
|
||||
if (width * priv->xkb->geom->height_mm <
|
||||
height * priv->xkb->geom->width_mm) {
|
||||
priv->scale_numerator = width;
|
||||
priv->scale_denominator = priv->xkb->geom->width_mm;
|
||||
} else {
|
||||
priv->scale_numerator = height;
|
||||
priv->scale_denominator = priv->xkb->geom->height_mm;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
EekXkbLayout *layout = EEK_XKB_LAYOUT (initable);
|
||||
|
||||
if (!get_keyboard_from_server (layout, error))
|
||||
return FALSE;
|
||||
|
||||
if (!get_names_from_server (layout, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
initable_iface_init (GInitableIface *initable_iface)
|
||||
{
|
||||
initable_iface->init = initable_init;
|
||||
}
|
||||
55
eek/eek-xkb-layout.h
Normal file
55
eek/eek-xkb-layout.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(__EEK_H_INSIDE__) && !defined(EEK_COMPILATION)
|
||||
#error "Only <eek/eek-xkb.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef EEK_XKB_LAYOUT_H
|
||||
#define EEK_XKB_LAYOUT_H 1
|
||||
|
||||
#include <X11/XKBlib.h>
|
||||
#include "eek-layout.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EEK_TYPE_XKB_LAYOUT (eek_xkb_layout_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE (EekXkbLayout, eek_xkb_layout, EEK, XKB_LAYOUT, EekLayout)
|
||||
|
||||
struct _EekXkbLayoutClass
|
||||
{
|
||||
/*< private >*/
|
||||
EekLayoutClass parent_class;
|
||||
|
||||
/*< private >*/
|
||||
/* padding */
|
||||
gpointer pdummy[24];
|
||||
};
|
||||
|
||||
GType eek_xkb_layout_get_type (void) G_GNUC_CONST;
|
||||
EekLayout *eek_xkb_layout_new (Display *display,
|
||||
GError **error);
|
||||
|
||||
gboolean eek_xkb_layout_set_names (EekXkbLayout *layout,
|
||||
XkbComponentNamesRec *names,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* #ifndef EEK_XKB_LAYOUT_H */
|
||||
26
eek/eek-xkb.h
Normal file
26
eek/eek-xkb.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
#ifndef EEK_XKB_H
|
||||
#define EEK_XKB_H 1
|
||||
|
||||
#include "eek.h"
|
||||
#include "eek-xkb-layout.h"
|
||||
|
||||
#endif /* EEK_XKB_H */
|
||||
30
eek/eek-xkl-0.90.pc.in
Normal file
30
eek/eek-xkl-0.90.pc.in
Normal file
@ -0,0 +1,30 @@
|
||||
# Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
# Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License
|
||||
# as published by the Free Software Foundation; either version 2 of
|
||||
# the License, or (at your option) any later version.
|
||||
|
||||
# This library is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
# 02110-1301 USA
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: libeek-xkl
|
||||
Description: A Library to Create Keyboard-like UI (Libxklavier Support)
|
||||
URL: http://fedorahosted.org/eekboard/
|
||||
Version: @VERSION@
|
||||
Requires: eek-@EEK_API_VERSION@ libxklavier
|
||||
Libs: -L${libdir} -leek-xkl
|
||||
Cflags: -I${includedir}/eek-@EEK_API_VERSION@
|
||||
662
eek/eek-xkl-layout.c
Normal file
662
eek/eek-xkl-layout.c
Normal file
@ -0,0 +1,662 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:eek-xkl-layout
|
||||
* @short_description: Layout engine using Libxklavier configuration
|
||||
*
|
||||
* The #EekXklLayout is a simple wrapper around #EekXkbLayout class
|
||||
* to use Libxklavier configuration.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <libxklavier/xklavier.h>
|
||||
#include <gio/gio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "eek-xkl-layout.h"
|
||||
|
||||
#define noKBDRAW_DEBUG
|
||||
|
||||
static GInitableIface *parent_initable_iface;
|
||||
|
||||
static void initable_iface_init (GInitableIface *initable_iface);
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_MODEL,
|
||||
PROP_LAYOUTS,
|
||||
PROP_VARIANTS,
|
||||
PROP_OPTIONS,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
typedef struct _EekXklLayoutPrivate
|
||||
{
|
||||
XklEngine *engine;
|
||||
XklConfigRec *config;
|
||||
} EekXklLayoutPrivate;
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (EekXklLayout, eek_xkl_layout, EEK_TYPE_XKB_LAYOUT,
|
||||
0, /* GTypeFlags */
|
||||
G_ADD_PRIVATE (EekXklLayout)
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||
initable_iface_init))
|
||||
|
||||
/* from gnome-keyboard-properties-xkbpv.c:
|
||||
* BAD STYLE: Taken from xklavier_private_xkb.h
|
||||
* Any ideas on architectural improvements are WELCOME
|
||||
*/
|
||||
extern gboolean xkl_xkb_config_native_prepare (XklEngine * engine,
|
||||
const XklConfigRec * data,
|
||||
XkbComponentNamesPtr
|
||||
component_names);
|
||||
|
||||
extern void xkl_xkb_config_native_cleanup (XklEngine * engine,
|
||||
XkbComponentNamesPtr
|
||||
component_names);
|
||||
|
||||
static gboolean set_xkb_component_names (EekXklLayout *layout,
|
||||
XklConfigRec *config);
|
||||
|
||||
static void
|
||||
eek_xkl_layout_dispose (GObject *object)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (
|
||||
EEK_XKL_LAYOUT (object));
|
||||
|
||||
if (priv->config) {
|
||||
g_object_unref (priv->config);
|
||||
priv->config = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (eek_xkl_layout_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkl_layout_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EekXklLayout *layout = EEK_XKL_LAYOUT(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MODEL:
|
||||
eek_xkl_layout_set_model (layout, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_LAYOUTS:
|
||||
eek_xkl_layout_set_layouts (layout, g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_VARIANTS:
|
||||
eek_xkl_layout_set_variants (layout, g_value_get_boxed (value));
|
||||
break;
|
||||
case PROP_OPTIONS:
|
||||
eek_xkl_layout_set_options (layout, g_value_get_boxed (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkl_layout_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EekXklLayout *layout = EEK_XKL_LAYOUT(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MODEL:
|
||||
g_value_set_string (value,
|
||||
eek_xkl_layout_get_model (layout));
|
||||
break;
|
||||
case PROP_LAYOUTS:
|
||||
g_value_set_boxed (value,
|
||||
eek_xkl_layout_get_layouts (layout));
|
||||
break;
|
||||
case PROP_VARIANTS:
|
||||
g_value_set_boxed (value,
|
||||
eek_xkl_layout_get_variants (layout));
|
||||
break;
|
||||
case PROP_OPTIONS:
|
||||
g_value_set_boxed (value,
|
||||
eek_xkl_layout_get_options (layout));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkl_layout_class_init (EekXklLayoutClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobject_class->dispose = eek_xkl_layout_dispose;
|
||||
gobject_class->set_property = eek_xkl_layout_set_property;
|
||||
gobject_class->get_property = eek_xkl_layout_get_property;
|
||||
|
||||
/**
|
||||
* EekXklLayout:model:
|
||||
*
|
||||
* The libxklavier model name of #EekXklLayout.
|
||||
*/
|
||||
pspec = g_param_spec_string ("model",
|
||||
"Model",
|
||||
"Libxklavier model",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_MODEL, pspec);
|
||||
|
||||
/**
|
||||
* EekXklLayout:layouts:
|
||||
*
|
||||
* The libxklavier layout names of #EekXklLayout.
|
||||
*/
|
||||
pspec = g_param_spec_boxed ("layouts",
|
||||
"Layouts",
|
||||
"Libxklavier layouts",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_LAYOUTS, pspec);
|
||||
|
||||
/**
|
||||
* EekXklLayout:variants:
|
||||
*
|
||||
* The libxklavier variant names of #EekXklLayout.
|
||||
*/
|
||||
pspec = g_param_spec_boxed ("variants",
|
||||
"Variants",
|
||||
"Libxklavier variants",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_VARIANTS, pspec);
|
||||
|
||||
/**
|
||||
* EekXklLayout:options:
|
||||
*
|
||||
* The libxklavier option names of #EekXklLayout.
|
||||
*/
|
||||
pspec = g_param_spec_boxed ("options",
|
||||
"Options",
|
||||
"Libxklavier options",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_OPTIONS, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
eek_xkl_layout_init (EekXklLayout *self)
|
||||
{
|
||||
/* void */
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_new:
|
||||
*
|
||||
* Create a new #EekXklLayout.
|
||||
*/
|
||||
EekLayout *
|
||||
eek_xkl_layout_new (Display *display, GError **error)
|
||||
{
|
||||
return (EekLayout *) g_initable_new (EEK_TYPE_XKL_LAYOUT,
|
||||
NULL,
|
||||
error,
|
||||
"display", display,
|
||||
NULL);
|
||||
}
|
||||
|
||||
G_INLINE_FUNC void
|
||||
merge_xkl_config_rec (XklConfigRec *dst, XklConfigRec *src)
|
||||
{
|
||||
if (src->model) {
|
||||
g_free (dst->model);
|
||||
dst->model = g_strdup (src->model);
|
||||
}
|
||||
if (src->layouts) {
|
||||
g_strfreev (dst->layouts);
|
||||
dst->layouts = g_strdupv (src->layouts);
|
||||
}
|
||||
if (src->variants) {
|
||||
g_strfreev (dst->variants);
|
||||
dst->variants = g_strdupv (src->variants);
|
||||
}
|
||||
if (src->options) {
|
||||
g_strfreev (dst->options);
|
||||
dst->options = g_strdupv (src->options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_set_config: (skip)
|
||||
* @layout: an #EekXklLayout
|
||||
* @config: Libxklavier configuration
|
||||
*
|
||||
* Reconfigure @layout with @config.
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_set_config (EekXklLayout *layout,
|
||||
XklConfigRec *config)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
XklConfigRec *c;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (priv, FALSE);
|
||||
c = xkl_config_rec_new ();
|
||||
merge_xkl_config_rec (c, priv->config);
|
||||
merge_xkl_config_rec (c, config);
|
||||
retval = set_xkb_component_names (layout, c);
|
||||
g_object_unref (c);
|
||||
merge_xkl_config_rec (priv->config, config);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_set_config_full:
|
||||
* @layout: an #EekXklLayout
|
||||
* @model: Libxklavier model name
|
||||
* @layouts: Libxklavier layouts
|
||||
* @variants: Libxklavier variants
|
||||
* @options: Libxklavier options
|
||||
*
|
||||
* Reconfigure @layout with @model, @layouts, @variants, and @options.
|
||||
* This function is merely a wrapper around
|
||||
* eek_xkl_layout_set_config() to avoid passing a pointer of
|
||||
* XklConfigRec, which is not currently available in the
|
||||
* gobject-introspection repository.
|
||||
*
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
* Since: 0.0.2
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_set_config_full (EekXklLayout *layout,
|
||||
gchar *model,
|
||||
gchar **layouts,
|
||||
gchar **variants,
|
||||
gchar **options)
|
||||
{
|
||||
XklConfigRec *config;
|
||||
gboolean retval;
|
||||
|
||||
config = xkl_config_rec_new ();
|
||||
config->model = g_strdup (model);
|
||||
config->layouts = g_strdupv (layouts);
|
||||
config->variants = g_strdupv (variants);
|
||||
config->options = g_strdupv (options);
|
||||
retval = eek_xkl_layout_set_config (layout, config);
|
||||
g_object_unref (config);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_set_model:
|
||||
* @layout: an #EekXklLayout
|
||||
* @model: model name
|
||||
*
|
||||
* Set the model name of @layout configuration (in the Libxklavier terminology).
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_set_model (EekXklLayout *layout,
|
||||
const gchar *model)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
XklConfigRec *config;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (priv, FALSE);
|
||||
config = xkl_config_rec_new ();
|
||||
/* config->model will be freed on g_object_unref (config) */
|
||||
if (model)
|
||||
config->model = g_strdup (model);
|
||||
else
|
||||
config->model = NULL;
|
||||
retval = eek_xkl_layout_set_config (layout, config);
|
||||
g_object_unref (config);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_set_layouts:
|
||||
* @layout: an #EekXklLayout
|
||||
* @layouts: layout names
|
||||
*
|
||||
* Set the layout names of @layout (in the Libxklavier terminology).
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_set_layouts (EekXklLayout *layout,
|
||||
gchar **layouts)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
XklConfigRec *config;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (priv, FALSE);
|
||||
config = xkl_config_rec_new ();
|
||||
/* config->layouts will be freed on g_object_unref (config) */
|
||||
if (layouts)
|
||||
config->layouts = g_strdupv (layouts);
|
||||
else
|
||||
config->layouts = layouts;
|
||||
retval = eek_xkl_layout_set_config (layout, config);
|
||||
g_object_unref (config);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_set_variants:
|
||||
* @layout: an #EekXklLayout
|
||||
* @variants: variant names
|
||||
*
|
||||
* Set the variant names of @layout (in the Libxklavier terminology).
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_set_variants (EekXklLayout *layout,
|
||||
gchar **variants)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
XklConfigRec *config;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (priv, FALSE);
|
||||
config = xkl_config_rec_new ();
|
||||
/* config->variants will be freed on g_object_unref (config) */
|
||||
if (variants)
|
||||
config->variants = g_strdupv (variants);
|
||||
else
|
||||
config->variants = NULL;
|
||||
retval = eek_xkl_layout_set_config (layout, config);
|
||||
g_object_unref (config);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_set_options:
|
||||
* @layout: an #EekXklLayout
|
||||
* @options: option names
|
||||
*
|
||||
* Set the option names of @layout (in the Libxklavier terminology).
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_set_options (EekXklLayout *layout,
|
||||
gchar **options)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
XklConfigRec *config;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (priv, FALSE);
|
||||
config = xkl_config_rec_new ();
|
||||
/* config->options will be freed on g_object_unref (config) */
|
||||
if (options)
|
||||
config->options = options;
|
||||
else
|
||||
config->options = NULL;
|
||||
retval = eek_xkl_layout_set_config (layout, config);
|
||||
g_object_unref (config);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_enable_option:
|
||||
* @layout: an #EekXklLayout
|
||||
* @option: option name
|
||||
*
|
||||
* Set the option of @layout (in the Libxklavier terminology).
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_enable_option (EekXklLayout *layout,
|
||||
const gchar *option)
|
||||
{
|
||||
gchar **options, **_options;
|
||||
gint i, j;
|
||||
|
||||
options = eek_xkl_layout_get_options (layout);
|
||||
for (i = 0; options && options[i]; i++)
|
||||
if (g_strcmp0 (options[i], option) == 0)
|
||||
return TRUE;
|
||||
_options = g_new0 (gchar *, (i + 2));
|
||||
for (j = 0; j < i; j++)
|
||||
_options[j] = g_strdup (options[j]);
|
||||
_options[i] = g_strdup (option);
|
||||
/* eek_xkl_layout_set_options() will free _options and its elements. */
|
||||
return eek_xkl_layout_set_options (layout, _options);
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_disable_option:
|
||||
* @layout: an #EekXklLayout
|
||||
* @option: option name
|
||||
*
|
||||
* Unset the option of @layout (in the Libxklavier terminology).
|
||||
* Returns: %TRUE if the current layout changed, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_disable_option (EekXklLayout *layout,
|
||||
const gchar *option)
|
||||
{
|
||||
gchar **options, **_options;
|
||||
gint i, j, k;
|
||||
|
||||
options = eek_xkl_layout_get_options (layout);
|
||||
if (!options)
|
||||
return TRUE;
|
||||
for (i = 0, k = 0; options[i]; i++)
|
||||
if (g_strcmp0 (options[i], option) == 0)
|
||||
k = i;
|
||||
if (options[k] == NULL)
|
||||
return TRUE;
|
||||
_options = g_new0 (gchar *, i);
|
||||
for (j = 0; j < k; j++)
|
||||
_options[j] = g_strdup (options[j]);
|
||||
for (j = k + 1; j < i; j++)
|
||||
_options[j] = g_strdup (options[j]);
|
||||
/* eek_xkl_layout_set_options() will free _options and its elements. */
|
||||
return eek_xkl_layout_set_options (layout, _options);
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_get_model:
|
||||
* @layout: an #EekXklLayout
|
||||
*
|
||||
* Get the model name of @layout configuration (in the Libxklavier terminology).
|
||||
*/
|
||||
gchar *
|
||||
eek_xkl_layout_get_model (EekXklLayout *layout)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
|
||||
g_return_val_if_fail (priv, NULL);
|
||||
return g_strdup (priv->config->model);
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_get_layouts:
|
||||
* @layout: an #EekXklLayout
|
||||
*
|
||||
* Get the layout names of @layout configuration (in the Libxklavier
|
||||
* terminology).
|
||||
*/
|
||||
gchar **
|
||||
eek_xkl_layout_get_layouts (EekXklLayout *layout)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
|
||||
g_return_val_if_fail (priv, NULL);
|
||||
return g_strdupv (priv->config->layouts);
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_get_variants:
|
||||
* @layout: an #EekXklLayout
|
||||
*
|
||||
* Get the variant names of @layout configuration (in the Libxklavier
|
||||
* terminology).
|
||||
*/
|
||||
gchar **
|
||||
eek_xkl_layout_get_variants (EekXklLayout *layout)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
|
||||
g_return_val_if_fail (priv, NULL);
|
||||
return g_strdupv (priv->config->variants);
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_get_options:
|
||||
* @layout: an #EekXklLayout
|
||||
*
|
||||
* Get the option names of @layout configuration (in the Libxklavier
|
||||
* terminology).
|
||||
*/
|
||||
gchar **
|
||||
eek_xkl_layout_get_options (EekXklLayout *layout)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
|
||||
g_return_val_if_fail (priv, NULL);
|
||||
return g_strdupv (priv->config->options);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_xkb_component_names (EekXklLayout *layout, XklConfigRec *config)
|
||||
{
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
XkbComponentNamesRec names;
|
||||
gboolean retval = FALSE;
|
||||
|
||||
#if DEBUG
|
||||
if (config->layouts) {
|
||||
gint i;
|
||||
|
||||
fprintf (stderr, "layout = ");
|
||||
for (i = 0; config->layouts[i] != NULL; i++)
|
||||
fprintf (stderr, "\"%s\" ", config->layouts[i]);
|
||||
fputc ('\n', stderr);
|
||||
} else
|
||||
fprintf (stderr, "layouts = NULL\n");
|
||||
if (config->variants) {
|
||||
gint i;
|
||||
|
||||
fprintf (stderr, "variant = ");
|
||||
for (i = 0; config->variants[i]; i++)
|
||||
fprintf (stderr, "\"%s\" ", config->variants[i]);
|
||||
fputc ('\n', stderr);
|
||||
} else
|
||||
fprintf (stderr, "variants = NULL\n");
|
||||
if (config->options) {
|
||||
gint i;
|
||||
|
||||
fprintf (stderr, "option = ");
|
||||
for (i = 0; config->options[i]; i++)
|
||||
fprintf (stderr, "\"%s\" ", config->options[i]);
|
||||
fputc ('\n', stderr);
|
||||
} else
|
||||
fprintf (stderr, "options = NULL\n");
|
||||
#endif
|
||||
|
||||
if (xkl_xkb_config_native_prepare (priv->engine, config, &names)) {
|
||||
GError *error = NULL;
|
||||
retval = eek_xkb_layout_set_names (EEK_XKB_LAYOUT(layout),
|
||||
&names,
|
||||
&error);
|
||||
if (!retval)
|
||||
g_warning ("can't set XKB layout");
|
||||
xkl_xkb_config_native_cleanup (priv->engine, &names);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* eek_xkl_layout_get_option:
|
||||
* @layout: an #EekXklLayout
|
||||
* @option: option name
|
||||
*
|
||||
* Tell if the option of @layout (in the Libxklavier terminology) is set.
|
||||
* Returns: %TRUE if the option is set, %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
eek_xkl_layout_get_option (EekXklLayout *layout,
|
||||
const gchar *option)
|
||||
{
|
||||
gchar **options;
|
||||
gint i;
|
||||
|
||||
options = eek_xkl_layout_get_options (layout);
|
||||
for (i = 0; options && options[i]; i++)
|
||||
if (g_strcmp0 (options[i], option) == 0)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
EekXklLayout *layout = EEK_XKL_LAYOUT (initable);
|
||||
EekXklLayoutPrivate *priv = eek_xkl_layout_get_instance_private (layout);
|
||||
Display *display;
|
||||
|
||||
if (!parent_initable_iface->init (initable, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
priv->config = xkl_config_rec_new ();
|
||||
|
||||
g_object_get (G_OBJECT (initable),
|
||||
"display", &display,
|
||||
NULL);
|
||||
|
||||
priv->engine = xkl_engine_get_instance (display);
|
||||
|
||||
if (!xkl_config_rec_get_from_server (priv->config,
|
||||
priv->engine)) {
|
||||
g_set_error (error,
|
||||
EEK_ERROR,
|
||||
EEK_ERROR_LAYOUT_ERROR,
|
||||
"can't load libxklavier configuration");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
set_xkb_component_names (layout, priv->config);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
initable_iface_init (GInitableIface *initable_iface)
|
||||
{
|
||||
parent_initable_iface = g_type_interface_peek_parent (initable_iface);
|
||||
initable_iface->init = initable_init;
|
||||
}
|
||||
|
||||
81
eek/eek-xkl-layout.h
Normal file
81
eek/eek-xkl-layout.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(__EEK_H_INSIDE__) && !defined(EEK_COMPILATION)
|
||||
#error "Only <eek/eek-xkl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef EEK_XKL_LAYOUT_H
|
||||
#define EEK_XKL_LAYOUT_H 1
|
||||
|
||||
#include <libxklavier/xklavier.h>
|
||||
#include "eek-xkb-layout.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EEK_TYPE_XKL_LAYOUT (eek_xkl_layout_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE (EekXklLayout, eek_xkl_layout, EEK, XKL_LAYOUT, EekLayout)
|
||||
|
||||
struct _EekXklLayoutClass
|
||||
{
|
||||
/*< private >*/
|
||||
EekXkbLayoutClass parent_class;
|
||||
|
||||
/*< private >*/
|
||||
/* padding */
|
||||
gpointer pdummy[24];
|
||||
};
|
||||
|
||||
GType eek_xkl_layout_get_type (void) G_GNUC_CONST;
|
||||
|
||||
EekLayout *eek_xkl_layout_new (Display *display,
|
||||
GError **error);
|
||||
|
||||
gboolean eek_xkl_layout_set_config (EekXklLayout *layout,
|
||||
XklConfigRec *config);
|
||||
|
||||
gboolean eek_xkl_layout_set_config_full (EekXklLayout *layout,
|
||||
gchar *model,
|
||||
gchar **layouts,
|
||||
gchar **variants,
|
||||
gchar **options);
|
||||
|
||||
gboolean eek_xkl_layout_set_model (EekXklLayout *layout,
|
||||
const gchar *model);
|
||||
gboolean eek_xkl_layout_set_layouts (EekXklLayout *layout,
|
||||
gchar **layouts);
|
||||
gboolean eek_xkl_layout_set_variants (EekXklLayout *layout,
|
||||
gchar **variants);
|
||||
gboolean eek_xkl_layout_set_options (EekXklLayout *layout,
|
||||
gchar **options);
|
||||
gboolean eek_xkl_layout_enable_option (EekXklLayout *layout,
|
||||
const gchar *option);
|
||||
gboolean eek_xkl_layout_disable_option (EekXklLayout *layout,
|
||||
const gchar *option);
|
||||
|
||||
gchar *eek_xkl_layout_get_model (EekXklLayout *layout);
|
||||
gchar **eek_xkl_layout_get_layouts (EekXklLayout *layout);
|
||||
gchar **eek_xkl_layout_get_variants (EekXklLayout *layout);
|
||||
gchar **eek_xkl_layout_get_options (EekXklLayout *layout);
|
||||
gboolean eek_xkl_layout_get_option (EekXklLayout *layout,
|
||||
const gchar *option);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* #ifndef EEK_XKL_LAYOUT_H */
|
||||
26
eek/eek-xkl.h
Normal file
26
eek/eek-xkl.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
#ifndef EEK_XKL_H
|
||||
#define EEK_XKL_H 1
|
||||
|
||||
#include "eek.h"
|
||||
#include "eek-xkl-layout.h"
|
||||
|
||||
#endif /* EEK_XKL_H */
|
||||
@ -249,6 +249,7 @@ struct _GeometryParseData {
|
||||
gchar *name;
|
||||
EekOutline outline;
|
||||
gchar *oref;
|
||||
gint keycode;
|
||||
|
||||
GHashTable *key_oref_hash;
|
||||
GHashTable *oref_outline_hash;
|
||||
@ -271,6 +272,7 @@ geometry_parse_data_new (EekKeyboard *keyboard)
|
||||
g_str_equal,
|
||||
g_free,
|
||||
(GDestroyNotify)eek_outline_free);
|
||||
data->keycode = 1;
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -396,29 +398,23 @@ geometry_start_element_callback (GMarkupParseContext *pcontext,
|
||||
}
|
||||
|
||||
if (g_strcmp0 (element_name, "key") == 0) {
|
||||
guint keycode;
|
||||
|
||||
attribute = get_attribute (attribute_names, attribute_values,
|
||||
"keycode");
|
||||
"name");
|
||||
if (attribute == NULL) {
|
||||
g_set_error (error,
|
||||
G_MARKUP_ERROR,
|
||||
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
|
||||
"no \"keycode\" attribute for \"key\"");
|
||||
"no \"name\" attribute for \"key\"");
|
||||
return;
|
||||
}
|
||||
keycode = strtoul (attribute, NULL, 10);
|
||||
|
||||
data->key = eek_section_create_key (data->section,
|
||||
keycode,
|
||||
g_strdup (attribute),
|
||||
data->keycode++,
|
||||
data->num_columns,
|
||||
data->num_rows - 1);
|
||||
|
||||
attribute = get_attribute (attribute_names, attribute_values,
|
||||
"name");
|
||||
if (attribute != NULL)
|
||||
eek_element_set_name (EEK_ELEMENT(data->key), attribute);
|
||||
|
||||
attribute = get_attribute (attribute_names, attribute_values,
|
||||
"oref");
|
||||
if (attribute == NULL) {
|
||||
@ -622,28 +618,25 @@ symbols_start_element_callback (GMarkupParseContext *pcontext,
|
||||
return;
|
||||
|
||||
if (g_strcmp0 (element_name, "key") == 0) {
|
||||
guint keycode;
|
||||
|
||||
attribute = get_attribute (attribute_names, attribute_values,
|
||||
"keycode");
|
||||
"name");
|
||||
if (attribute == NULL) {
|
||||
g_set_error (error,
|
||||
G_MARKUP_ERROR,
|
||||
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
|
||||
"no \"keycode\" attribute for \"key\"");
|
||||
"no \"name\" attribute for \"key\"");
|
||||
return;
|
||||
}
|
||||
keycode = strtoul (attribute, NULL, 10);
|
||||
|
||||
data->key = eek_keyboard_find_key_by_keycode (data->keyboard,
|
||||
keycode);
|
||||
/*if (data->key == NULL) {
|
||||
data->key = eek_keyboard_find_key_by_name (data->keyboard,
|
||||
attribute);
|
||||
if (data->key == NULL) {
|
||||
g_set_error (error,
|
||||
G_MARKUP_ERROR,
|
||||
G_MARKUP_ERROR_INVALID_CONTENT,
|
||||
"no such keycode %u", keycode);
|
||||
return;
|
||||
}*/
|
||||
"no such key %s", attribute);
|
||||
}
|
||||
|
||||
attribute = get_attribute (attribute_names, attribute_values,
|
||||
"groups");
|
||||
|
||||
404
eekboard/eekboard-client.c
Normal file
404
eekboard/eekboard-client.c
Normal file
@ -0,0 +1,404 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2011 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:eekboard-client
|
||||
* @short_description: client interface of eekboard service
|
||||
*
|
||||
* The #EekboardClient class provides a client side access to eekboard-server.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include "eekboard/eekboard-client.h"
|
||||
|
||||
enum {
|
||||
DESTROYED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
typedef struct _EekboardClientPrivate
|
||||
{
|
||||
GHashTable *context_hash;
|
||||
} EekboardClientPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (EekboardClient, eekboard_client, G_TYPE_DBUS_PROXY)
|
||||
|
||||
static void send_destroy_context (EekboardClient *client,
|
||||
EekboardContext *context,
|
||||
GCancellable *cancellable);
|
||||
|
||||
static void
|
||||
eekboard_client_real_destroyed (EekboardClient *self)
|
||||
{
|
||||
EekboardClientPrivate *priv = eekboard_client_get_instance_private (self);
|
||||
|
||||
// g_debug ("eekboard_client_real_destroyed");
|
||||
g_hash_table_remove_all (priv->context_hash);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_client_dispose (GObject *object)
|
||||
{
|
||||
EekboardClient *client = EEKBOARD_CLIENT(object);
|
||||
EekboardClientPrivate *priv = eekboard_client_get_instance_private (client);
|
||||
|
||||
if (priv->context_hash) {
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
|
||||
g_hash_table_iter_init (&iter, priv->context_hash);
|
||||
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
||||
send_destroy_context (client, (EekboardContext *)value, NULL);
|
||||
g_hash_table_iter_remove (&iter);
|
||||
}
|
||||
g_hash_table_destroy (priv->context_hash);
|
||||
priv->context_hash = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (eekboard_client_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_client_class_init (EekboardClientClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
klass->destroyed = eekboard_client_real_destroyed;
|
||||
|
||||
gobject_class->dispose = eekboard_client_dispose;
|
||||
|
||||
/**
|
||||
* EekboardClient::destroyed:
|
||||
* @eekboard: an #EekboardClient
|
||||
*
|
||||
* The ::destroyed signal is emitted each time the name of remote
|
||||
* end is vanished.
|
||||
*/
|
||||
signals[DESTROYED] =
|
||||
g_signal_new (I_("destroyed"),
|
||||
G_TYPE_FROM_CLASS(gobject_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET(EekboardClientClass, destroyed),
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE,
|
||||
0);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_client_init (EekboardClient *self)
|
||||
{
|
||||
EekboardClientPrivate *priv = eekboard_client_get_instance_private (self);
|
||||
|
||||
priv->context_hash =
|
||||
g_hash_table_new_full (g_str_hash,
|
||||
g_str_equal,
|
||||
(GDestroyNotify)g_free,
|
||||
(GDestroyNotify)g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_name_vanished_callback (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
EekboardClient *client = user_data;
|
||||
g_signal_emit_by_name (client, "destroyed", NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* eekboard_client_new:
|
||||
* @connection: a #GDBusConnection
|
||||
* @cancellable: a #GCancellable
|
||||
*
|
||||
* Create a client.
|
||||
*/
|
||||
EekboardClient *
|
||||
eekboard_client_new (GDBusConnection *connection,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
GInitable *initable;
|
||||
GError *error;
|
||||
|
||||
g_assert (G_IS_DBUS_CONNECTION(connection));
|
||||
|
||||
error = NULL;
|
||||
initable =
|
||||
g_initable_new (EEKBOARD_TYPE_CLIENT,
|
||||
cancellable,
|
||||
&error,
|
||||
"g-connection", connection,
|
||||
"g-name", "org.fedorahosted.Eekboard",
|
||||
"g-interface-name", "org.fedorahosted.Eekboard",
|
||||
"g-object-path", "/org/fedorahosted/Eekboard",
|
||||
NULL);
|
||||
if (initable != NULL) {
|
||||
EekboardClient *client = EEKBOARD_CLIENT (initable);
|
||||
gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY(client));
|
||||
if (name_owner == NULL) {
|
||||
g_object_unref (client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* the vanished callback is called when the server is disconnected */
|
||||
g_bus_watch_name_on_connection (connection,
|
||||
name_owner,
|
||||
G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||
NULL,
|
||||
eekboard_name_vanished_callback,
|
||||
client,
|
||||
NULL);
|
||||
g_free (name_owner);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
g_warning ("can't create client: %s", error->message);
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
on_context_destroyed (EekboardContext *context,
|
||||
gpointer user_data)
|
||||
{
|
||||
EekboardClient *client = user_data;
|
||||
EekboardClientPrivate *priv = eekboard_client_get_instance_private (client);
|
||||
|
||||
g_hash_table_remove (priv->context_hash,
|
||||
g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)));
|
||||
}
|
||||
|
||||
/**
|
||||
* eekboard_client_create_context:
|
||||
* @eekboard: an #EekboardClient
|
||||
* @client_name: name of the client
|
||||
* @cancellable: a #GCancellable
|
||||
*
|
||||
* Create a new input context.
|
||||
*
|
||||
* Return value: (transfer full): a newly created #EekboardContext.
|
||||
*/
|
||||
EekboardContext *
|
||||
eekboard_client_create_context (EekboardClient *client,
|
||||
const gchar *client_name,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
GVariant *variant;
|
||||
const gchar *object_path;
|
||||
EekboardContext *context;
|
||||
GError *error;
|
||||
GDBusConnection *connection;
|
||||
|
||||
g_assert (EEKBOARD_IS_CLIENT(client));
|
||||
g_assert (client_name);
|
||||
|
||||
error = NULL;
|
||||
variant = g_dbus_proxy_call_sync (G_DBUS_PROXY(client),
|
||||
"CreateContext",
|
||||
g_variant_new ("(s)", client_name),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
&error);
|
||||
if (!variant) {
|
||||
g_warning ("failed to call CreateContext: %s", error->message);
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_get (variant, "(&s)", &object_path);
|
||||
connection = g_dbus_proxy_get_connection (G_DBUS_PROXY(client));
|
||||
context = eekboard_context_new (connection, object_path, cancellable);
|
||||
if (!context) {
|
||||
g_variant_unref (variant);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EekboardClientPrivate *priv = eekboard_client_get_instance_private (client);
|
||||
|
||||
g_hash_table_insert (priv->context_hash,
|
||||
g_strdup (object_path),
|
||||
g_object_ref (context));
|
||||
g_signal_connect (context, "destroyed",
|
||||
G_CALLBACK(on_context_destroyed), client);
|
||||
return context;
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_async_ready_callback (GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GVariant *result;
|
||||
|
||||
result = g_dbus_proxy_call_finish (G_DBUS_PROXY(source_object),
|
||||
res,
|
||||
&error);
|
||||
if (result)
|
||||
g_variant_unref (result);
|
||||
else {
|
||||
g_warning ("error in D-Bus proxy call: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* eekboard_client_push_context:
|
||||
* @eekboard: an #EekboardClient
|
||||
* @context: an #EekboardContext
|
||||
* @cancellable: a #GCancellable
|
||||
*
|
||||
* Enable the input context @context and disable the others.
|
||||
*/
|
||||
void
|
||||
eekboard_client_push_context (EekboardClient *client,
|
||||
EekboardContext *context,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
const gchar *object_path;
|
||||
|
||||
g_return_if_fail (EEKBOARD_IS_CLIENT(client));
|
||||
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
|
||||
|
||||
EekboardClientPrivate *priv = eekboard_client_get_instance_private (client);
|
||||
|
||||
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
|
||||
|
||||
context = g_hash_table_lookup (priv->context_hash,
|
||||
object_path);
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
eekboard_context_set_enabled (context, TRUE);
|
||||
g_dbus_proxy_call (G_DBUS_PROXY(client),
|
||||
"PushContext",
|
||||
g_variant_new ("(s)", object_path),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
eekboard_async_ready_callback,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* eekboard_client_pop_context:
|
||||
* @eekboard: an #EekboardClient
|
||||
* @cancellable: a #GCancellable
|
||||
*
|
||||
* Disable the current input context and enable the previous one.
|
||||
*/
|
||||
void
|
||||
eekboard_client_pop_context (EekboardClient *client,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
g_return_if_fail (EEKBOARD_IS_CLIENT(client));
|
||||
|
||||
g_dbus_proxy_call (G_DBUS_PROXY(client),
|
||||
"PopContext",
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
eekboard_async_ready_callback,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
eekboard_client_show_keyboard (EekboardClient *client,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
g_return_if_fail (EEKBOARD_IS_CLIENT(client));
|
||||
|
||||
g_dbus_proxy_call (G_DBUS_PROXY(client),
|
||||
"ShowKeyboard",
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
eekboard_async_ready_callback,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
eekboard_client_hide_keyboard (EekboardClient *client,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
g_return_if_fail (EEKBOARD_IS_CLIENT(client));
|
||||
|
||||
g_dbus_proxy_call (G_DBUS_PROXY(client),
|
||||
"HideKeyboard",
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
eekboard_async_ready_callback,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
send_destroy_context (EekboardClient *client,
|
||||
EekboardContext *context,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
const gchar *object_path;
|
||||
|
||||
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
|
||||
|
||||
g_dbus_proxy_call (G_DBUS_PROXY(client),
|
||||
"DestroyContext",
|
||||
g_variant_new ("(s)", object_path),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
-1,
|
||||
cancellable,
|
||||
eekboard_async_ready_callback,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* eekboard_client_destroy_context:
|
||||
* @eekboard: an #EekboardClient
|
||||
* @context: an #EekboardContext
|
||||
* @cancellable: a #GCancellable
|
||||
*
|
||||
* Remove @context from @eekboard.
|
||||
*/
|
||||
void
|
||||
eekboard_client_destroy_context (EekboardClient *client,
|
||||
EekboardContext *context,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
const gchar *object_path;
|
||||
|
||||
g_return_if_fail (EEKBOARD_IS_CLIENT(client));
|
||||
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
|
||||
|
||||
EekboardClientPrivate *priv = eekboard_client_get_instance_private (client);
|
||||
|
||||
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
|
||||
g_hash_table_remove (priv->context_hash, object_path);
|
||||
|
||||
send_destroy_context (client, context, cancellable);
|
||||
}
|
||||
64
eekboard/eekboard-client.h
Normal file
64
eekboard/eekboard-client.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef EEKBOARD_CLIENT_H
|
||||
#define EEKBOARD_CLIENT_H 1
|
||||
|
||||
#define __EEKBOARD_CLIENT_H_INSIDE__ 1
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include "eekboard/eekboard-context.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EEKBOARD_TYPE_CLIENT (eekboard_client_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE (EekboardClient, eekboard_client, EEKBOARD, CLIENT, GDBusProxy)
|
||||
|
||||
struct _EekboardClientClass {
|
||||
/*< private >*/
|
||||
GDBusProxyClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (* destroyed) (EekboardClient *self);
|
||||
|
||||
/*< private >*/
|
||||
/* padding */
|
||||
gpointer pdummy[23];
|
||||
};
|
||||
|
||||
GType eekboard_client_get_type (void) G_GNUC_CONST;
|
||||
|
||||
EekboardClient *eekboard_client_new (GDBusConnection *connection,
|
||||
GCancellable *cancellable);
|
||||
EekboardContext *eekboard_client_create_context (EekboardClient *eekboard,
|
||||
const gchar *client_name,
|
||||
GCancellable *cancellable);
|
||||
void eekboard_client_push_context (EekboardClient *eekboard,
|
||||
EekboardContext *context,
|
||||
GCancellable *cancellable);
|
||||
void eekboard_client_pop_context (EekboardClient *eekboard,
|
||||
GCancellable *cancellable);
|
||||
void eekboard_client_show_keyboard (EekboardClient *eekboard,
|
||||
GCancellable *cancellable);
|
||||
void eekboard_client_hide_keyboard (EekboardClient *eekboard,
|
||||
GCancellable *cancellable);
|
||||
void eekboard_client_destroy_context (EekboardClient *eekboard,
|
||||
EekboardContext *context,
|
||||
GCancellable *cancellable);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* EEKBOARD_CLIENT_H */
|
||||
@ -135,11 +135,6 @@ eekboard_service_dispose (GObject *object)
|
||||
priv->introspection_data = NULL;
|
||||
}
|
||||
|
||||
if (priv->context) {
|
||||
g_signal_handlers_disconnect_by_data (priv->context, service);
|
||||
priv->context = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (eekboard_service_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
@ -171,22 +166,6 @@ handle_set_visible(SmPuriOSK0 *object, GDBusMethodInvocation *invocation,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void on_visible(EekboardService *service,
|
||||
GParamSpec *pspec,
|
||||
EekboardContextService *context)
|
||||
{
|
||||
gboolean visible;
|
||||
EekboardServicePrivate *priv;
|
||||
|
||||
g_return_if_fail (EEKBOARD_IS_SERVICE (service));
|
||||
g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE (context));
|
||||
|
||||
priv = eekboard_service_get_instance_private (service);
|
||||
g_object_get (context, "visible", &visible, NULL);
|
||||
|
||||
sm_puri_osk0_set_visible(priv->dbus_interface, visible);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_service_constructed (GObject *object)
|
||||
{
|
||||
@ -194,6 +173,7 @@ eekboard_service_constructed (GObject *object)
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
|
||||
priv->dbus_interface = sm_puri_osk0_skeleton_new();
|
||||
sm_puri_osk0_set_visible(priv->dbus_interface, FALSE); // TODO: use actual value
|
||||
g_signal_connect(priv->dbus_interface, "handle-set-visible",
|
||||
G_CALLBACK(handle_set_visible), service);
|
||||
|
||||
@ -299,12 +279,5 @@ eekboard_service_set_context(EekboardService *service,
|
||||
{
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
|
||||
g_return_if_fail (!priv->context);
|
||||
|
||||
priv->context = context;
|
||||
|
||||
g_signal_connect_swapped (priv->context,
|
||||
"notify::visible",
|
||||
G_CALLBACK(on_visible),
|
||||
service);
|
||||
}
|
||||
|
||||
168
eekboard/eekboard-xklutil.c
Normal file
168
eekboard/eekboard-xklutil.c
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "eekboard/eekboard-xklutil.h"
|
||||
|
||||
XklConfigRec *
|
||||
eekboard_xkl_config_rec_from_string (const gchar *layouts)
|
||||
{
|
||||
XklConfigRec *rec;
|
||||
gchar **strv, **l, **v;
|
||||
gint i;
|
||||
|
||||
strv = g_strsplit (layouts, "/", -1);
|
||||
g_return_val_if_fail (g_strv_length (strv) == 3, NULL);
|
||||
|
||||
l = g_strsplit (strv[1], ";", -1);
|
||||
v = g_strdupv (l);
|
||||
for (i = 0; l[i]; i++) {
|
||||
gchar *layout = l[i], *variant = v[i],
|
||||
*variant_start, *variant_end;
|
||||
|
||||
variant_start = strchr (layout, '(');
|
||||
variant_end = strrchr (layout, ')');
|
||||
if (variant_start && variant_end) {
|
||||
*variant_start++ = '\0';
|
||||
g_strlcpy (variant, variant_start,
|
||||
variant_end - variant_start + 1);
|
||||
} else
|
||||
*variant = '\0';
|
||||
}
|
||||
|
||||
rec = xkl_config_rec_new ();
|
||||
rec->model = g_strdup (strv[0]);
|
||||
rec->layouts = l;
|
||||
rec->variants = v;
|
||||
rec->options = g_strsplit (strv[2], ";", -1);
|
||||
g_strfreev (strv);
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
gchar *
|
||||
eekboard_xkl_config_rec_to_string (XklConfigRec *rec)
|
||||
{
|
||||
gchar **strv, **sp, **lp, **vp, *p;
|
||||
gint n_layouts;
|
||||
GString *str;
|
||||
|
||||
n_layouts = g_strv_length (rec->layouts);
|
||||
strv = g_malloc0_n (n_layouts + 2, sizeof (gchar *));
|
||||
for (sp = strv, lp = rec->layouts, vp = rec->variants; *lp; sp++, lp++) {
|
||||
if (*vp != NULL && **vp != '\0')
|
||||
*sp = g_strdup_printf ("%s(%s)", *lp, *vp++);
|
||||
else
|
||||
*sp = g_strdup_printf ("%s", *lp);
|
||||
}
|
||||
|
||||
/* MODEL/L0(V0);L1(V1);...;Ln(Vn)/O0;O1;...;On */
|
||||
str = g_string_new (rec->model);
|
||||
|
||||
g_string_append_c (str, '/');
|
||||
p = g_strjoinv (";", strv);
|
||||
g_strfreev (strv);
|
||||
g_string_append (str, p);
|
||||
g_free (p);
|
||||
|
||||
g_string_append_c (str, '/');
|
||||
p = g_strjoinv (";", rec->options);
|
||||
g_string_append (str, p);
|
||||
g_free (p);
|
||||
|
||||
return g_string_free (str,FALSE);
|
||||
}
|
||||
|
||||
static XklConfigItem *
|
||||
xkl_config_item_copy (const XklConfigItem *item)
|
||||
{
|
||||
XklConfigItem *_item = xkl_config_item_new ();
|
||||
memcpy (_item->name,
|
||||
item->name,
|
||||
sizeof (item->name));
|
||||
memcpy (_item->short_description,
|
||||
item->short_description,
|
||||
sizeof (item->short_description));
|
||||
memcpy (_item->description,
|
||||
item->description,
|
||||
sizeof (item->description));
|
||||
return _item;
|
||||
}
|
||||
|
||||
static void
|
||||
prepend_item (XklConfigRegistry *registry,
|
||||
const XklConfigItem *item,
|
||||
gpointer data)
|
||||
{
|
||||
GSList **list = data;
|
||||
XklConfigItem *_item = xkl_config_item_copy (item);
|
||||
*list = g_slist_prepend (*list, _item);
|
||||
}
|
||||
|
||||
static gint
|
||||
compare_item_by_name (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const XklConfigItem *ia = a, *ib = b;
|
||||
return g_strcmp0 (ia->name, ib->name);
|
||||
}
|
||||
|
||||
GSList *
|
||||
eekboard_xkl_list_models (XklConfigRegistry *registry)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
xkl_config_registry_foreach_model (registry, prepend_item, &list);
|
||||
return g_slist_sort (list, compare_item_by_name);
|
||||
}
|
||||
|
||||
GSList *
|
||||
eekboard_xkl_list_layouts (XklConfigRegistry *registry)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
xkl_config_registry_foreach_layout (registry, prepend_item, &list);
|
||||
return g_slist_sort (list, compare_item_by_name);
|
||||
}
|
||||
|
||||
GSList *
|
||||
eekboard_xkl_list_option_groups (XklConfigRegistry *registry)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
xkl_config_registry_foreach_option_group (registry, prepend_item, &list);
|
||||
return g_slist_sort (list, compare_item_by_name);
|
||||
}
|
||||
|
||||
GSList *
|
||||
eekboard_xkl_list_layout_variants (XklConfigRegistry *registry,
|
||||
const gchar *layout)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
xkl_config_registry_foreach_layout_variant (registry,
|
||||
layout,
|
||||
prepend_item,
|
||||
&list);
|
||||
return g_slist_sort (list, compare_item_by_name);
|
||||
}
|
||||
|
||||
GSList *
|
||||
eekboard_xkl_list_options (XklConfigRegistry *registry,
|
||||
const gchar *group)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
xkl_config_registry_foreach_option (registry, group, prepend_item, &list);
|
||||
return g_slist_sort (list, compare_item_by_name);
|
||||
}
|
||||
39
eekboard/eekboard-xklutil.h
Normal file
39
eekboard/eekboard-xklutil.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2011 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
#ifndef EEKBOARD_XKLUTIL_H
|
||||
#define EEKBOARD_XKLUTIL_H 1
|
||||
|
||||
#include <libxklavier/xklavier.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
XklConfigRec *eekboard_xkl_config_rec_from_string (const gchar *layouts);
|
||||
gchar *eekboard_xkl_config_rec_to_string (XklConfigRec *rec);
|
||||
|
||||
GSList *eekboard_xkl_list_models (XklConfigRegistry *registry);
|
||||
GSList *eekboard_xkl_list_layouts (XklConfigRegistry *registry);
|
||||
GSList *eekboard_xkl_list_option_groups (XklConfigRegistry *registry);
|
||||
GSList *eekboard_xkl_list_layout_variants (XklConfigRegistry *registry,
|
||||
const gchar *layout);
|
||||
GSList *eekboard_xkl_list_options (XklConfigRegistry *registry,
|
||||
const gchar *group);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* EEKBOARD_XKLUTIL_H */
|
||||
20
meson.build
20
meson.build
@ -3,14 +3,12 @@ project(
|
||||
'c', 'rust',
|
||||
version: '1.0.10',
|
||||
license: 'GPLv3',
|
||||
meson_version: '>=0.49.0',
|
||||
meson_version: '>=0.43.0',
|
||||
default_options: [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11' ],
|
||||
)
|
||||
|
||||
i18n = import('i18n')
|
||||
|
||||
conf_data = configuration_data()
|
||||
|
||||
if get_option('buildtype').startswith('debug')
|
||||
add_project_arguments('-DDEBUG=1', language : 'c')
|
||||
endif
|
||||
@ -28,22 +26,6 @@ else
|
||||
endif
|
||||
dbusdir = join_paths(depdatadir, 'dbus-1/interfaces')
|
||||
|
||||
gsound_dep = dependency('gsound', required : false)
|
||||
if gsound_dep.found()
|
||||
conf_data.set10('HAVE_GSOUND', true)
|
||||
endif
|
||||
|
||||
summary = [
|
||||
'',
|
||||
'------------------',
|
||||
'squeekboard @0@'.format(meson.project_version()),
|
||||
'',
|
||||
' gsound: @0@'.format(conf_data.get('HAVE_GSOUND', false)),
|
||||
'------------------',
|
||||
''
|
||||
]
|
||||
message('\n'.join(summary))
|
||||
|
||||
subdir('data')
|
||||
subdir('protocols')
|
||||
subdir('eek')
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
/*
|
||||
* Autogenerated by the Meson build system.
|
||||
* Do not edit, your changes will be lost.
|
||||
*/
|
||||
|
||||
#mesondefine HAVE_GSOUND
|
||||
@ -4,10 +4,7 @@ dbus_src = gnome.gdbus_codegen(
|
||||
join_paths(meson.source_root() / 'data' / 'dbus', 'sm.puri.OSK0.xml')
|
||||
)
|
||||
|
||||
config_h = configure_file(input: 'config.h.in', output: 'config.h',configuration: conf_data)
|
||||
|
||||
sources = [
|
||||
config_h,
|
||||
'imservice.c',
|
||||
'server-context-service.c',
|
||||
'server-main.c',
|
||||
@ -63,7 +60,6 @@ deps = [
|
||||
cc.find_library('dl'),
|
||||
cc.find_library('pthread'),
|
||||
# dependency('libxklavier'), # FIXME remove
|
||||
gsound_dep,
|
||||
]
|
||||
|
||||
# Replacement for eekboard-server
|
||||
|
||||
@ -275,7 +275,6 @@ set_geometry (ServerContextService *context)
|
||||
}
|
||||
}
|
||||
|
||||
#define KEYBOARD_HEIGHT 210
|
||||
static void
|
||||
make_window (ServerContextService *context)
|
||||
{
|
||||
@ -286,13 +285,13 @@ make_window (ServerContextService *context)
|
||||
PHOSH_TYPE_LAYER_SURFACE,
|
||||
"layer-shell", squeek_wayland->layer_shell,
|
||||
"wl-output", g_ptr_array_index(squeek_wayland->outputs, 0), // TODO: select output as needed,
|
||||
"height", KEYBOARD_HEIGHT,
|
||||
"height", 210,
|
||||
"anchor", ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
|
||||
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
|
||||
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT,
|
||||
"layer", ZWLR_LAYER_SHELL_V1_LAYER_TOP,
|
||||
"kbd-interactivity", FALSE,
|
||||
"exclusive-zone", KEYBOARD_HEIGHT,
|
||||
"exclusive-zone", 200,
|
||||
//"namespace", "phosh home",
|
||||
NULL
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user