Compare commits

..

73 Commits

Author SHA1 Message Date
0739fbf464 Fix packaging mistake of *.desktop file. 2011-03-11 18:17:41 +09:00
d1b38f8eb2 0.90.6 released. 2011-03-11 18:05:41 +09:00
e6d17fa4cb Fix the last commit. 2011-03-11 17:39:55 +09:00
d62b8b49a2 Fix the last commit. 2011-03-11 17:18:29 +09:00
149dd7dc8b Ignore some files. 2011-03-11 14:26:57 +09:00
0177f96795 Move eekboard-client from src to examples; rename eekboard-desktop-client to eekboard. 2011-03-11 14:25:48 +09:00
ec56773dc6 Don't hardcode gtk.main_quit() in inscript.py. 2011-03-11 13:24:22 +09:00
881bf34ec4 Handle the case when both shift and altgr keys are pressed. 2011-03-11 13:11:05 +09:00
6787308061 Set label/category anyway if inscript key cannot convert to keyval. 2011-03-11 12:53:54 +09:00
0cd01bf165 Fix make distcheck. 2011-03-11 12:53:35 +09:00
132ae3899f Terminate eekboard-inscript when the window is closed. 2011-03-11 12:06:07 +09:00
72f84fa4ef Export EekSymbolCategory in python binding. 2011-03-11 12:06:00 +09:00
16d81f3f71 Generate inscript keyboard on-the-fly. 2011-03-11 11:38:53 +09:00
42a0ea148b Handle "destroyed" signal in eekboard-inscript. 2011-03-10 19:38:42 +09:00
2021311a4e Add destroyed signal in python binding. 2011-03-10 19:37:30 +09:00
b64e91dffa Latch modifiers in eekboard-inscript. 2011-03-10 19:18:56 +09:00
57bb7030fb Fix toggle English feature. 2011-03-10 18:54:53 +09:00
425fe7829b Add toggle English. 2011-03-10 18:43:24 +09:00
aa88315924 Set AltGr mask in python binding. 2011-03-10 18:24:09 +09:00
39a59fb049 Serialize alt_gr_mask. 2011-03-10 18:23:49 +09:00
e0993a5e55 Add eekboard-inscript. 2011-03-10 18:14:06 +09:00
4eb59ba7ed Display client name as window title. 2011-03-10 18:11:48 +09:00
cc9fb31e61 Add examples. 2011-03-10 17:17:37 +09:00
c44ebecfb2 Improve font size computation. 2011-03-10 17:16:31 +09:00
f60e1d763e Move EekSymbolMatrix code from eek-types.[ch] to eek-symbol-matrix.[ch]. 2011-03-09 11:57:02 +09:00
5c3cb477ef Let PopContext return error if the current context is not owned by the client. 2011-03-08 19:00:04 +09:00
5fd4005967 Add transfer mode annotation for eekboard_eekboard_create_context(). 2011-03-08 14:39:41 +09:00
76d1b8f7fb 0.90.4 released. 2011-03-08 11:27:49 +09:00
2bbc65958a Doc and typo fix for eekboard_context_set_fullscreen(). 2011-03-08 11:27:20 +09:00
cbdd0fd2ba Add eekboard/eekboard-eekboard.c to POTFILES.skip. 2011-03-08 11:26:49 +09:00
2f7aa77c11 Fix focus listener logic. 2011-03-08 11:26:15 +09:00
bed39570ff Add eek-theme-private.h in distribution. 2011-03-08 11:25:59 +09:00
8bc3b204b4 Add credit. 2011-03-08 11:25:19 +09:00
fa030ebcbb Fix fullscreen code. 2011-03-08 11:03:48 +09:00
af365024b7 Update default theme. 2011-03-08 10:43:17 +09:00
c742877b77 Add "SetFullscreen" D-Bus method. 2011-03-08 10:42:57 +09:00
ace4391b79 Use font from style. 2011-03-08 10:41:45 +09:00
627cbf2898 Pass base_font during size calculation. 2011-03-08 07:04:12 +09:00
baae80fa41 Port st-theme-context.[ch] to eek-theme-context.[ch]. 2011-03-08 06:58:20 +09:00
9be07710dd Fix clutter build. 2011-03-08 06:27:59 +09:00
163e005561 Simplify "blank background" code. 2011-03-08 06:04:41 +09:00
d8e691d3f5 Optimize redraw on key release. 2011-03-08 05:53:00 +09:00
85a1a6ba24 Abolish EekThemeNodePrivate. 2011-03-08 05:17:20 +09:00
828a59b298 Fix typo. 2011-03-07 19:17:32 +09:00
f1b91c0223 Add border style configuration (WIP). 2011-03-07 19:01:10 +09:00
cadb0f18a9 Fix gradient drawing. 2011-03-07 16:51:01 +09:00
2a8d7cf0a8 Revert to use fakekey_send_event. 2011-03-07 16:49:38 +09:00
c9b54ba87f Remove eek-theme-private.h. 2011-03-07 14:40:04 +09:00
d57ae91995 Move level change logic from key-pressed to key-released handler. 2011-03-07 14:39:35 +09:00
dd86b132ce Set pseudo class "active" to EekKey if the key is pressed. 2011-03-07 12:38:32 +09:00
3967558bae Add setter function of pseudo class. 2011-03-07 12:37:58 +09:00
668ce51f3c Mark EekKey::pressed as G_SIGNAL_RUN_FIRST. 2011-03-07 12:37:25 +09:00
1db2a4aeea Use g_object_set_qdata() to attach theme-node to element. 2011-03-07 10:42:27 +09:00
e20425f385 Add eek-theme-private.h. 2011-03-04 19:35:50 +09:00
a20224f969 Add default theme. 2011-03-04 19:23:08 +09:00
d66318a031 Fix the last commit. 2011-03-04 19:04:39 +09:00
37c2579253 Merge theme handling code (WIP). 2011-03-04 18:52:25 +09:00
23ab2a343f Fix coding style. 2011-03-04 14:28:20 +09:00
e6dfc595ab Lower gobject-introspection version requirement. 2011-03-04 13:01:17 +09:00
98e15d7741 Resolve AltGr modifier at run time. 2011-03-04 10:42:31 +09:00
38b226b46f Clear allocation box when drawing keyboard. 2011-03-03 18:18:04 +09:00
c53b4d398e Remove floating ref from a serialized keyboard. 2011-03-03 17:31:09 +09:00
fbcf6b6c65 Fix infloop when multiple clients are disconnected after another. 2011-03-03 17:02:12 +09:00
09c95b20da Add "Destroy" D-Bus signal to server for debug. 2011-03-03 16:36:10 +09:00
a7f81c3cfb Destroy clutter texture cache properly. 2011-03-03 16:04:24 +09:00
a66256f390 Fix coding style. 2011-03-03 15:53:51 +09:00
8b7da18641 Make eekboard-xml build with clutter. 2011-03-03 15:25:39 +09:00
a9c0356611 Fix XML serialization of EekOutline to include corner_radius. 2011-03-03 15:06:03 +09:00
b25a9a5407 Add comments. 2011-03-03 15:06:03 +09:00
8b632356e9 Fix memleaks. 2011-03-03 15:05:59 +09:00
b8a01d794e Check if the server is active. 2011-03-03 12:23:31 +09:00
cfd33921a1 Fix crash with clutter build. 2011-03-02 18:49:39 +09:00
979aa010b9 Update gobject-introspection version requirement. 2011-03-02 18:40:01 +09:00
75 changed files with 6851 additions and 964 deletions

2
.gitignore vendored
View File

@ -72,3 +72,5 @@ po/Makefile.in.in
po/POTFILES
po/stamp-it
bindings/vala/*.vapi
py-compile

38
AUTHORS
View File

@ -1,6 +1,36 @@
eekboard is written by Daiki Ueno <ueno@unixuser.org>
eekboard is written by Daiki Ueno <ueno@unixuser.org>. The following
files contain code derived from other free software packages:
Cairo keyboard drawing functions are borrowed from the libgnomekbd
library by Sergey V. Udaltsov <svu@gnome.org>. See the comments in
eek/eek-drawing.c for detail.
eek/eek-keyboard-drawing.h
eek/eek-keyboard-drawing.c
These files contain code derived from the libgnomekbd library.
Copyright (C) 2006 Sergey V. Udaltsov <svu@gnome.org>
eek/eek-theme.h
eek/eek-theme.c
eek/eek-theme-context.h
eek/eek-theme-context.c
eek/eek-theme-node.h
eek/eek-theme-node.c
These files contain code derived from gnome-shell.
Copyright 2008-2010 Red Hat, Inc.
Copyright 2009 Steve Frécinaux
Copyright 2009, 2010 Florian Müllner
Copyright 2010 Adel Gadllah
Copyright 2010 Giovanni Campagna
Copyright 2003-2004 Dodji Seketeli
data/icons/8x8/Makefile.am
data/icons/16x16/Makefile.am
data/icons/22x22/Makefile.am
data/icons/24x24/Makefile.am
data/icons/32x32/Makefile.am
data/icons/48x48/Makefile.am
data/icons/scalable/Makefile.am
These files contain code derived from im-chooser.
Copyright (C) 2006-2008 Red Hat, Inc. All rights reserved.

View File

@ -17,5 +17,5 @@
# 02110-1301 USA
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = eek eekboard src tests bindings docs po data
SUBDIRS = eek eekboard src tests bindings docs po data examples
DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc --enable-introspection

26
README
View File

@ -7,7 +7,7 @@ tools to implement desktop virtual keyboards.
** Dependencies
REQUIRED: GLib2, GTK, GConf2, PangoCairo, libxklavier
REQUIRED: GLib2, GTK, GConf2, PangoCairo, libxklavier, libcroco
OPTIONAL: fakekey, CSPI, Clutter, Clutter-Gtk, Vala, gobject-introspection
** Build from git repo
@ -26,7 +26,7 @@ OPTIONAL: fakekey, CSPI, Clutter, Clutter-Gtk, Vala, gobject-introspection
* How to test
eekboard currently includes 4 tools to implement your own virtual
eekboard currently includes 3 tools to implement your own virtual
keyboard.
** eekboard-server
@ -38,14 +38,14 @@ do that with:
$ eekboard-server &
** eekboard-desktop-client
** eekboard
eekboard-desktop-client is a client of eekboard-server. It listens
desktop events (keyboard change, focus in/out, and keystroke) and
generates key events when some keys are pressed on the on-screen
keyboard. It can be started with:
eekboard is a client of eekboard-server. It listens desktop events
(keyboard change, focus in/out, and keystroke) and generates key
events when some keys are pressed on the on-screen keyboard. It can
be started with:
$ eekboard-desktop-client
$ eekboard
** eekboard-xml
@ -60,16 +60,6 @@ You can display the dumped layout with:
$ eekboard-xml --load keyboard.xml
** eekboard-client
eekboard-client is a simple test client of eekboard-server. To upload
the keyboard description to the server, display it, and listen
key events.
$ eekboard-client --set-keyboard keyboard.xml --show-keyboard --listen
KeyPressed XXXXX
KeyReleased XXXXX
* Documentation
See file:docs/reference/eek/html/index.html

View File

@ -25,6 +25,7 @@ Section = Eek.Section
Key = Eek.Key
Symbol = Eek.Symbol
Keysym = Eek.Keysym
SymbolMatrix = Eek.SymbolMatrix
MODIFIER_BEHAVIOR_NONE, \
MODIFIER_BEHAVIOR_LOCK, \
@ -33,6 +34,8 @@ MODIFIER_BEHAVIOR_LATCH = \
Eek.ModifierBehavior.LOCK,
Eek.ModifierBehavior.LATCH)
SymbolCategory = Eek.SymbolCategory
CSW = 640
CSH = 480
@ -41,6 +44,7 @@ def XmlKeyboard(path, modifier_behavior=MODIFIER_BEHAVIOR_NONE):
layout = Eek.XmlLayout.new(_file.read())
keyboard = Eek.Keyboard.new(layout, CSW, CSH)
keyboard.set_modifier_behavior(modifier_behavior)
keyboard.set_alt_gr_mask(Eek.ModifierType.MOD5_MASK)
return keyboard
def XklKeyboard(modifier_behavior=MODIFIER_BEHAVIOR_NONE):

View File

@ -36,17 +36,38 @@ class Context(gobject.GObject):
'key-released': (
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_UINT,))
(gobject.TYPE_UINT,)),
'destroyed': (
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
()),
}
__gproperties__ = {
'keyboard-visible': (bool, None, None, False, gobject.PARAM_READWRITE),
}
def __init__(self, giobject):
super(Context, self).__init__()
import sys
self.__properties = dict()
self.__giobject = giobject
self.__giobject.connect('enabled', lambda *args: self.emit('enabled'))
self.__giobject.connect('disabled', lambda *args: self.emit('disabled'))
self.__giobject.connect('key-pressed', lambda *args: self.emit('key-pressed', args[1]))
self.__giobject.connect('key-released', lambda *args: self.emit('key-released', args[1]))
self.__giobject.connect('destroyed', lambda *args: self.emit('destroyed'))
self.__giobject.connect('notify::keyboard-visible', self.__notify_keyboard_visible_cb)
def do_set_property(self, pspec, value):
self.__properties[pspec.name] = value
def do_get_property(self, pspec):
return self.__properties[pspec.name]
def __notify_keyboard_visible_cb(self, *args):
self.set_property('keyboard-visible',
self.__giobject.get_property(args[1].name))
self.notify('keyboard-visible')
def get_giobject(self):
return self.__giobject

View File

@ -22,11 +22,18 @@ from context import Context
class Eekboard(gobject.GObject):
__gtype_name__ = "PYEekboardEekboard"
__gsignals__ = {
'destroyed': (
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
())
}
def __init__(self):
super(Eekboard, self).__init__()
self.__connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
self.__eekboard = gi.repository.Eekboard.Eekboard.new(self.__connection, None);
self.__eekboard.connect('destroyed', lambda *args: self.emit('destroyed'))
def create_context(self, client_name):
context = self.__eekboard.create_context(client_name, None)

View File

@ -20,7 +20,7 @@ AC_PREREQ(2.63)
dnl AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])
AC_INIT([eekboard], [0.90.3], [ueno@unixuser.org])
AC_INIT([eekboard], [0.90.6], [ueno@unixuser.org])
dnl Init automake
AM_INIT_AUTOMAKE
@ -101,6 +101,8 @@ PKG_CHECK_MODULES([XKB], [x11], ,
[AC_MSG_ERROR([XKB support not found])])
PKG_CHECK_MODULES([LIBXKLAVIER], [libxklavier x11], ,
[AC_MSG_ERROR([Libxklavier not found])])
PKG_CHECK_MODULES([LIBCROCO], [libcroco-0.6], ,
[AC_MSG_ERROR([libcroco not found])])
dnl use libfakekey to generate key events
AC_MSG_CHECKING([whether you enable fakekey])
@ -217,7 +219,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Define to the read-only
AM_GLIB_GNU_GETTEXT
AM_GLIB_DEFINE_LOCALEDIR(EEKBOARD_LOCALEDIR)
GOBJECT_INTROSPECTION_CHECK([0.6.7])
GOBJECT_INTROSPECTION_CHECK([0.9.0])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile
@ -242,6 +244,11 @@ data/icons/24x24/Makefile
data/icons/32x32/Makefile
data/icons/48x48/Makefile
data/icons/scalable/Makefile
data/themes/Makefile
data/keyboards/Makefile
examples/Makefile
examples/eekboard-inscript/Makefile
examples/simple-client/Makefile
eek/eek-${EEK_API_VERSION}.pc
eek/eek-clutter-${EEK_API_VERSION}.pc
eek/eek-gtk-${EEK_API_VERSION}.pc

View File

@ -1 +1,9 @@
SUBDIRS = icons
SUBDIRS = icons themes keyboards
desktopdir = $(datadir)/applications
desktop_in_files = eekboard.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
CLEANFILES = $(desktop_DATA)
EXTRA_DIST = $(desktop_in_files)

9
data/eekboard.desktop.in Normal file
View File

@ -0,0 +1,9 @@
[Desktop Entry]
Name=Eekboard
GenericName=Eekboard Virtual Keyboard
Comment=Virtual Keyboard
Exec=eekboard-desktop-client
Icon=eekboard
Terminal=false
Type=Application
Categories=GTK;Utility;

View File

@ -0,0 +1,2 @@
keyboarddir = $(pkgdatadir)/keyboards
dist_keyboard_DATA = us-qwerty.xml

View File

@ -0,0 +1,707 @@
<?xml version="1.0"?>
<keyboard version="0.90">
<bounds>0.000000,0.000000,410.000000,190.000000</bounds>
<section name="Alpha">
<bounds>10.000000,50.000000,390.000000,129.000000</bounds>
<angle>0</angle>
<row>
<columns>14</columns>
<orientation>1</orientation>
</row>
<row>
<columns>14</columns>
<orientation>1</orientation>
</row>
<row>
<columns>13</columns>
<orientation>1</orientation>
</row>
<row>
<columns>12</columns>
<orientation>1</orientation>
</row>
<row>
<columns>8</columns>
<orientation>1</orientation>
</row>
<key id="keycode105" name="RCTL" column="7" row="4">
<bounds>359.000000,104.000000,31.000000,24.000000</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="1">
<keysym keyval="65508">Control_R</keysym>
</symbols>
</key>
<key id="keycode135" name="MENU" column="6" row="4">
<bounds>326.000000,104.000000,31.000000,24.000000</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="1">
<keysym keyval="65383">Menu</keysym>
</symbols>
</key>
<key id="keycode134" name="RWIN" column="5" row="4">
<bounds>294.000000,104.000000,31.000000,24.000000</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="1">
<keysym keyval="65516">Super_R</keysym>
</symbols>
</key>
<key id="keycode108" name="RALT" column="4" row="4">
<bounds>261.000000,104.000000,31.000000,24.000000</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="1">
<keysym keyval="65027">ISO_Level3_Shift</keysym>
</symbols>
</key>
<key id="keycode65" name="SPCE" column="3" row="4">
<bounds>106.000000,104.000000,153.000000,24.000000</bounds>
<oref>outline11</oref>
<symbols groups="1" levels="1">
<keysym keyval="32">space</keysym>
</symbols>
</key>
<key id="keycode64" name="LALT" column="2" row="4">
<bounds>73.000000,104.000000,31.000000,24.000000</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="2">
<keysym keyval="65513">Alt_L</keysym>
<keysym keyval="65511">Meta_L</keysym>
</symbols>
</key>
<key id="keycode133" name="LWIN" column="1" row="4">
<bounds>40.000000,104.000000,31.000000,24.000000</bounds>
<oref>outline10</oref>
<symbols groups="1" levels="1">
<keysym keyval="65515">Super_L</keysym>
</symbols>
</key>
<key id="keycode37" name="LCTL" column="0" row="4">
<bounds>2.000000,104.000000,36.000000,24.000000</bounds>
<oref>outline9</oref>
<symbols groups="1" levels="1">
<keysym keyval="65507">Control_L</keysym>
</symbols>
</key>
<key id="keycode62" name="RTSH" column="11" row="3">
<bounds>320.000000,78.000000,70.000000,24.000000</bounds>
<oref>outline8</oref>
<symbols groups="1" levels="1">
<keysym keyval="65506">Shift_R</keysym>
</symbols>
</key>
<key id="keycode61" name="AB10" column="10" row="3">
<bounds>294.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="47">slash</keysym>
<keysym keyval="63">question</keysym>
</symbols>
</key>
<key id="keycode60" name="AB09" column="9" row="3">
<bounds>268.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="46">period</keysym>
<keysym keyval="62">greater</keysym>
</symbols>
</key>
<key id="keycode59" name="AB08" column="8" row="3">
<bounds>242.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="44">comma</keysym>
<keysym keyval="60">less</keysym>
</symbols>
</key>
<key id="keycode58" name="AB07" column="7" row="3">
<bounds>216.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="109">m</keysym>
<keysym keyval="77">M</keysym>
</symbols>
</key>
<key id="keycode57" name="AB06" column="6" row="3">
<bounds>190.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="110">n</keysym>
<keysym keyval="78">N</keysym>
</symbols>
</key>
<key id="keycode56" name="AB05" column="5" row="3">
<bounds>164.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="98">b</keysym>
<keysym keyval="66">B</keysym>
</symbols>
</key>
<key id="keycode55" name="AB04" column="4" row="3">
<bounds>138.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="118">v</keysym>
<keysym keyval="86">V</keysym>
</symbols>
</key>
<key id="keycode54" name="AB03" column="3" row="3">
<bounds>113.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="99">c</keysym>
<keysym keyval="67">C</keysym>
</symbols>
</key>
<key id="keycode53" name="AB02" column="2" row="3">
<bounds>87.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="120">x</keysym>
<keysym keyval="88">X</keysym>
</symbols>
</key>
<key id="keycode52" name="AB01" column="1" row="3">
<bounds>61.000000,78.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="122">z</keysym>
<keysym keyval="90">Z</keysym>
</symbols>
</key>
<key id="keycode50" name="LFSH" column="0" row="3">
<bounds>2.000000,78.000000,57.000000,24.000000</bounds>
<oref>outline7</oref>
<symbols groups="1" levels="1">
<keysym keyval="65505">Shift_L</keysym>
</symbols>
</key>
<key id="keycode36" name="RTRN" column="12" row="2">
<bounds>333.000000,53.000000,57.000000,24.000000</bounds>
<oref>outline6</oref>
<symbols groups="1" levels="1">
<keysym keyval="65293">Return</keysym>
</symbols>
</key>
<key id="keycode48" name="AC11" column="11" row="2">
<bounds>307.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="39">quoteright</keysym>
<keysym keyval="34">quotedbl</keysym>
</symbols>
</key>
<key id="keycode47" name="AC10" column="10" row="2">
<bounds>281.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="59">semicolon</keysym>
<keysym keyval="58">colon</keysym>
</symbols>
</key>
<key id="keycode46" name="AC09" column="9" row="2">
<bounds>256.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="108">l</keysym>
<keysym keyval="76">L</keysym>
</symbols>
</key>
<key id="keycode45" name="AC08" column="8" row="2">
<bounds>230.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="107">k</keysym>
<keysym keyval="75">K</keysym>
</symbols>
</key>
<key id="keycode44" name="AC07" column="7" row="2">
<bounds>204.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="106">j</keysym>
<keysym keyval="74">J</keysym>
</symbols>
</key>
<key id="keycode43" name="AC06" column="6" row="2">
<bounds>178.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="104">h</keysym>
<keysym keyval="72">H</keysym>
</symbols>
</key>
<key id="keycode42" name="AC05" column="5" row="2">
<bounds>152.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="103">g</keysym>
<keysym keyval="71">G</keysym>
</symbols>
</key>
<key id="keycode41" name="AC04" column="4" row="2">
<bounds>126.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="102">f</keysym>
<keysym keyval="70">F</keysym>
</symbols>
</key>
<key id="keycode40" name="AC03" column="3" row="2">
<bounds>100.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="100">d</keysym>
<keysym keyval="68">D</keysym>
</symbols>
</key>
<key id="keycode39" name="AC02" column="2" row="2">
<bounds>74.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="115">s</keysym>
<keysym keyval="83">S</keysym>
</symbols>
</key>
<key id="keycode38" name="AC01" column="1" row="2">
<bounds>49.000000,53.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="97">a</keysym>
<keysym keyval="65">A</keysym>
</symbols>
</key>
<key id="keycode66" name="CAPS" column="0" row="2">
<bounds>2.000000,53.000000,44.000000,24.000000</bounds>
<oref>outline5</oref>
<symbols groups="1" levels="2">
<keysym keyval="65507">Control_L</keysym>
<keysym keyval="65507">Control_L</keysym>
</symbols>
</key>
<key id="keycode51" name="BKSL" column="13" row="1">
<bounds>352.000000,27.000000,38.000000,24.000000</bounds>
<oref>outline4</oref>
<symbols groups="1" levels="2">
<keysym keyval="92">backslash</keysym>
<keysym keyval="124">bar</keysym>
</symbols>
</key>
<key id="keycode35" name="AD12" column="12" row="1">
<bounds>326.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="93">bracketright</keysym>
<keysym keyval="125">braceright</keysym>
</symbols>
</key>
<key id="keycode34" name="AD11" column="11" row="1">
<bounds>300.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="91">bracketleft</keysym>
<keysym keyval="123">braceleft</keysym>
</symbols>
</key>
<key id="keycode33" name="AD10" column="10" row="1">
<bounds>275.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="112">p</keysym>
<keysym keyval="80">P</keysym>
</symbols>
</key>
<key id="keycode32" name="AD09" column="9" row="1">
<bounds>249.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="111">o</keysym>
<keysym keyval="79">O</keysym>
</symbols>
</key>
<key id="keycode31" name="AD08" column="8" row="1">
<bounds>223.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="105">i</keysym>
<keysym keyval="73">I</keysym>
</symbols>
</key>
<key id="keycode30" name="AD07" column="7" row="1">
<bounds>197.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="117">u</keysym>
<keysym keyval="85">U</keysym>
</symbols>
</key>
<key id="keycode29" name="AD06" column="6" row="1">
<bounds>171.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="121">y</keysym>
<keysym keyval="89">Y</keysym>
</symbols>
</key>
<key id="keycode28" name="AD05" column="5" row="1">
<bounds>145.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="116">t</keysym>
<keysym keyval="84">T</keysym>
</symbols>
</key>
<key id="keycode27" name="AD04" column="4" row="1">
<bounds>119.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="114">r</keysym>
<keysym keyval="82">R</keysym>
</symbols>
</key>
<key id="keycode26" name="AD03" column="3" row="1">
<bounds>93.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="101">e</keysym>
<keysym keyval="69">E</keysym>
</symbols>
</key>
<key id="keycode25" name="AD02" column="2" row="1">
<bounds>68.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="119">w</keysym>
<keysym keyval="87">W</keysym>
</symbols>
</key>
<key id="keycode24" name="AD01" column="1" row="1">
<bounds>42.000000,27.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="113">q</keysym>
<keysym keyval="81">Q</keysym>
</symbols>
</key>
<key id="keycode23" name="TAB" column="0" row="1">
<bounds>2.000000,27.000000,38.000000,24.000000</bounds>
<oref>outline3</oref>
<symbols groups="1" levels="2">
<keysym keyval="65289">Tab</keysym>
<keysym keyval="65056">ISO_Left_Tab</keysym>
</symbols>
</key>
<key id="keycode22" name="BKSP" column="13" row="0">
<bounds>339.000000,1.000000,51.000000,24.000000</bounds>
<oref>outline2</oref>
<symbols groups="1" levels="1">
<keysym keyval="65288">BackSpace</keysym>
</symbols>
</key>
<key id="keycode21" name="AE12" column="12" row="0">
<bounds>313.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="61">equal</keysym>
<keysym keyval="43">plus</keysym>
</symbols>
</key>
<key id="keycode20" name="AE11" column="11" row="0">
<bounds>287.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="45">minus</keysym>
<keysym keyval="95">underscore</keysym>
</symbols>
</key>
<key id="keycode19" name="AE10" column="10" row="0">
<bounds>261.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="48">0</keysym>
<keysym keyval="41">parenright</keysym>
</symbols>
</key>
<key id="keycode18" name="AE09" column="9" row="0">
<bounds>235.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="57">9</keysym>
<keysym keyval="40">parenleft</keysym>
</symbols>
</key>
<key id="keycode17" name="AE08" column="8" row="0">
<bounds>209.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="56">8</keysym>
<keysym keyval="42">asterisk</keysym>
</symbols>
</key>
<key id="keycode16" name="AE07" column="7" row="0">
<bounds>183.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="55">7</keysym>
<keysym keyval="38">ampersand</keysym>
</symbols>
</key>
<key id="keycode15" name="AE06" column="6" row="0">
<bounds>157.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="54">6</keysym>
<keysym keyval="94">asciicircum</keysym>
</symbols>
</key>
<key id="keycode14" name="AE05" column="5" row="0">
<bounds>132.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="53">5</keysym>
<keysym keyval="37">percent</keysym>
</symbols>
</key>
<key id="keycode13" name="AE04" column="4" row="0">
<bounds>106.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="52">4</keysym>
<keysym keyval="36">dollar</keysym>
</symbols>
</key>
<key id="keycode12" name="AE03" column="3" row="0">
<bounds>80.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="51">3</keysym>
<keysym keyval="35">numbersign</keysym>
</symbols>
</key>
<key id="keycode11" name="AE02" column="2" row="0">
<bounds>54.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="50">2</keysym>
<keysym keyval="64">at</keysym>
</symbols>
</key>
<key id="keycode10" name="AE01" column="1" row="0">
<bounds>28.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="49">1</keysym>
<keysym keyval="33">exclam</keysym>
</symbols>
</key>
<key id="keycode49" name="TLDE" column="0" row="0">
<bounds>2.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="96">quoteleft</keysym>
<keysym keyval="126">asciitilde</keysym>
</symbols>
</key>
</section>
<section name="Function">
<bounds>10.000000,10.000000,410.000000,25.000000</bounds>
<angle>0</angle>
<row>
<columns>16</columns>
<orientation>1</orientation>
</row>
<key id="keycode96" name="FK12" column="12" row="0">
<bounds>366.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65481">F12</keysym>
<keysym keyval="269024780">(null)</keysym>
</symbols>
</key>
<key id="keycode95" name="FK11" column="11" row="0">
<bounds>340.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65480">F11</keysym>
<keysym keyval="269024779">(null)</keysym>
</symbols>
</key>
<key id="keycode76" name="FK10" column="10" row="0">
<bounds>314.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65479">F10</keysym>
<keysym keyval="269024778">(null)</keysym>
</symbols>
</key>
<key id="keycode75" name="FK09" column="9" row="0">
<bounds>288.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65478">F9</keysym>
<keysym keyval="269024777">(null)</keysym>
</symbols>
</key>
<key id="keycode74" name="FK08" column="8" row="0">
<bounds>249.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65477">F8</keysym>
<keysym keyval="269024776">(null)</keysym>
</symbols>
</key>
<key id="keycode73" name="FK07" column="7" row="0">
<bounds>223.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65476">F7</keysym>
<keysym keyval="269024775">(null)</keysym>
</symbols>
</key>
<key id="keycode72" name="FK06" column="6" row="0">
<bounds>197.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65475">F6</keysym>
<keysym keyval="269024774">(null)</keysym>
</symbols>
</key>
<key id="keycode71" name="FK05" column="5" row="0">
<bounds>171.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65474">F5</keysym>
<keysym keyval="269024773">(null)</keysym>
</symbols>
</key>
<key id="keycode70" name="FK04" column="4" row="0">
<bounds>132.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65473">F4</keysym>
<keysym keyval="269024772">(null)</keysym>
</symbols>
</key>
<key id="keycode69" name="FK03" column="3" row="0">
<bounds>106.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65472">F3</keysym>
<keysym keyval="269024771">(null)</keysym>
</symbols>
</key>
<key id="keycode68" name="FK02" column="2" row="0">
<bounds>80.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65471">F2</keysym>
<keysym keyval="269024770">(null)</keysym>
</symbols>
</key>
<key id="keycode67" name="FK01" column="1" row="0">
<bounds>54.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="2">
<keysym keyval="65470">F1</keysym>
<keysym keyval="269024769">(null)</keysym>
</symbols>
</key>
<key id="keycode9" name="ESC" column="0" row="0">
<bounds>2.000000,1.000000,24.000000,24.000000</bounds>
<oref>outline1</oref>
<symbols groups="1" levels="1">
<keysym keyval="65307">Escape</keysym>
</symbols>
</key>
</section>
<outline id="outline1">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>24.000000,0.000000</point>
<point>24.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline3">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>38.000000,0.000000</point>
<point>38.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline4">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>38.000000,0.000000</point>
<point>38.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline5">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>44.000000,0.000000</point>
<point>44.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline6">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>57.000000,0.000000</point>
<point>57.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline7">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>57.000000,0.000000</point>
<point>57.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline8">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>70.000000,0.000000</point>
<point>70.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline9">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>36.000000,0.000000</point>
<point>36.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline10">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>31.000000,0.000000</point>
<point>31.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline11">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>153.000000,0.000000</point>
<point>153.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline12">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>24.000000,0.000000</point>
<point>24.000000,50.000000</point>
<point>0.000000,50.000000</point>
</outline>
<outline id="outline13">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>50.000000,0.000000</point>
<point>50.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
<outline id="outline2">
<corner-radius>1.000000</corner-radius>
<point>0.000000,0.000000</point>
<point>51.000000,0.000000</point>
<point>51.000000,24.000000</point>
<point>0.000000,24.000000</point>
</outline>
</keyboard>

2
data/themes/Makefile.am Normal file
View File

@ -0,0 +1,2 @@
themedir = $(pkgdatadir)/themes
dist_theme_DATA = default.css

22
data/themes/default.css Normal file
View File

@ -0,0 +1,22 @@
.keyboard {
background-color: rgba(0, 0, 0, 255);
color: #ffffff;
font-family: cantarell, sans-serif;
}
.key {
color: #ffffff;
background-gradient-direction: vertical;
background-gradient-start: rgba(0, 0, 0, 255);
background-gradient-end: rgba(64, 64, 64, 255);
border-width: 2px;
border-color: rgba(128, 128, 128, 255);
border-radius: 3px;
}
.key:active {
background-gradient-direction: vertical;
background-gradient-start: rgba(0, 0, 255, 255);
background-gradient-end: rgba(64, 64, 255, 255);
border-color: rgba(160, 160, 255, 255);
}

View File

@ -35,10 +35,12 @@ libeek_public_headers = \
$(srcdir)/eek-key.h \
$(srcdir)/eek-symbol.h \
$(srcdir)/eek-keysym.h \
$(srcdir)/eek-symbol-matrix.h \
$(srcdir)/eek-types.h \
$(srcdir)/eek-xml.h \
$(srcdir)/eek-xml-layout.h \
$(srcdir)/eek-serializable.h \
$(srcdir)/eek-theme.h \
$(srcdir)/eek.h
libeek_private_headers = \
@ -46,7 +48,10 @@ libeek_private_headers = \
$(srcdir)/eek-special-keysym-entries.h \
$(srcdir)/eek-unicode-keysym-entries.h \
$(srcdir)/eek-xkeysym-keysym-entries.h \
$(srcdir)/eek-marshalers.h
$(srcdir)/eek-marshalers.h \
$(srcdir)/eek-theme-context.h \
$(srcdir)/eek-theme-private.h \
$(srcdir)/eek-theme-node.h
libeek_sources = \
$(srcdir)/eek-layout.c \
@ -55,6 +60,7 @@ libeek_sources = \
$(srcdir)/eek-keyboard.c \
$(srcdir)/eek-section.c \
$(srcdir)/eek-key.c \
$(srcdir)/eek-symbol-matrix.c \
$(srcdir)/eek-symbol.c \
$(srcdir)/eek-keysym.c \
$(srcdir)/eek-types.c \
@ -62,7 +68,10 @@ libeek_sources = \
$(srcdir)/eek-xml.c \
$(srcdir)/eek-xml-layout.c \
$(srcdir)/eek-renderer.c \
$(srcdir)/eek-keyboard-drawing.c
$(srcdir)/eek-keyboard-drawing.c \
$(srcdir)/eek-theme.c \
$(srcdir)/eek-theme-context.c \
$(srcdir)/eek-theme-node.c
libeek_keysym_sources = \
$(srcdir)/eek-special-keysym-entries.h \
@ -85,8 +94,8 @@ libeek_la_SOURCES = \
$(libeek_sources) \
$(srcdir)/eek-marshalers.c
libeek_la_CFLAGS = $(GIO2_CFLAGS) $(PANGOCAIRO_CFLAGS)
libeek_la_LIBADD = $(GIO2_LIBS) $(PANGOCAIRO_LIBS) -lm
libeek_la_CFLAGS = $(GIO2_CFLAGS) $(PANGOCAIRO_CFLAGS) $(LIBCROCO_CFLAGS)
libeek_la_LIBADD = $(GIO2_LIBS) $(PANGOCAIRO_LIBS) $(LIBCROCO_LIBS) -lm
if ENABLE_CLUTTER
libeek_clutter_public_headers = \

View File

@ -22,13 +22,14 @@
* SECTION:eek-clutter-keyboard
* @short_description: a #ClutterActor displaying #EekKeyboard
*/
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "eek-clutter-keyboard.h"
#include "eek-clutter-section.h"
#include "eek-clutter-renderer.h"
@ -49,6 +50,7 @@ struct _EekClutterKeyboardPrivate
{
EekKeyboard *keyboard;
EekClutterRenderer *renderer;
EekTheme *theme;
};
struct _CreateSectionCallbackData {
@ -77,6 +79,9 @@ eek_clutter_keyboard_real_realize (ClutterActor *self)
priv = EEK_CLUTTER_KEYBOARD_GET_PRIVATE(self);
if (priv->theme)
eek_renderer_set_theme (EEK_RENDERER(priv->renderer), priv->theme);
scale = eek_renderer_get_scale (EEK_RENDERER(priv->renderer));
clutter_actor_set_position (CLUTTER_ACTOR(self),
bounds.x * scale,
@ -125,7 +130,6 @@ eek_clutter_keyboard_real_allocate (ClutterActor *self,
{
EekClutterKeyboardPrivate *priv = EEK_CLUTTER_KEYBOARD_GET_PRIVATE(self);
g_assert (priv->renderer);
eek_renderer_set_allocation_size (EEK_RENDERER(priv->renderer),
box->x2 - box->x1,
box->y2 - box->y1);
@ -192,6 +196,11 @@ eek_clutter_keyboard_dispose (GObject *object)
priv->keyboard = NULL;
}
if (priv->theme) {
g_object_unref (priv->theme);
priv->keyboard = NULL;
}
G_OBJECT_CLASS (eek_clutter_keyboard_parent_class)->dispose (object);
}
@ -248,3 +257,16 @@ eek_clutter_keyboard_new (EekKeyboard *keyboard)
{
return g_object_new (EEK_TYPE_CLUTTER_KEYBOARD, "keyboard", keyboard, NULL);
}
void
eek_clutter_keyboard_set_theme (EekClutterKeyboard *keyboard,
EekTheme *theme)
{
EekClutterKeyboardPrivate *priv;
g_return_if_fail (EEK_IS_CLUTTER_KEYBOARD(keyboard));
g_return_if_fail (EEK_IS_THEME(theme));
priv = EEK_CLUTTER_KEYBOARD_GET_PRIVATE(keyboard);
priv->theme = g_object_ref (theme);
}

View File

@ -55,6 +55,8 @@ struct _EekClutterKeyboardClass
GType eek_clutter_keyboard_get_type (void) G_GNUC_CONST;
ClutterActor *eek_clutter_keyboard_new (EekKeyboard *keyboard);
void eek_clutter_keyboard_set_theme (EekClutterKeyboard *keyboard,
EekTheme *theme);
G_END_DECLS
#endif /* EEK_CLUTTER_KEYBOARD_H */

View File

@ -18,16 +18,16 @@
* 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <cogl/cogl.h>
#include <cogl/cogl-pango.h>
#include <clutter/clutter.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eek-clutter-renderer.h"
#include "eek-key.h"
@ -77,6 +77,14 @@ cairo_pixels_to_pixbuf (guint8 *pixels,
}
}
static void
eek_clutter_renderer_finalize (GObject *object)
{
EekClutterRendererPrivate *priv = EEK_CLUTTER_RENDERER_GET_PRIVATE(object);
g_hash_table_destroy (priv->outline_texture_cache);
G_OBJECT_CLASS (eek_clutter_renderer_parent_class)->finalize (object);
}
static void
eek_clutter_renderer_class_init (EekClutterRendererClass *klass)
{
@ -84,6 +92,8 @@ eek_clutter_renderer_class_init (EekClutterRendererClass *klass)
g_type_class_add_private (gobject_class,
sizeof (EekClutterRendererPrivate));
gobject_class->finalize = eek_clutter_renderer_finalize;
}
static void
@ -109,7 +119,8 @@ eek_clutter_renderer_render_key (EekClutterRenderer *renderer,
CoglHandle *outline_texture;
PangoLayout *layout;
PangoRectangle extents = { 0, };
CoglColor color = { 0x00, 0x00, 0x00, 0xFF };
EekColor foreground;
CoglColor color;
ClutterGeometry geom;
gulong oref;
EekKeyboard *keyboard;
@ -190,6 +201,17 @@ eek_clutter_renderer_render_key (EekClutterRenderer *renderer,
layout = eek_renderer_create_pango_layout (EEK_RENDERER(renderer));
eek_renderer_render_key_label (EEK_RENDERER(renderer), layout, key);
pango_layout_get_extents (layout, NULL, &extents);
eek_renderer_get_foreground_color (EEK_RENDERER(renderer),
EEK_ELEMENT(key),
&foreground);
cogl_color_set_from_4f (&color,
foreground.red,
foreground.green,
foreground.blue,
foreground.alpha);
cogl_pango_render_layout (layout,
(geom.width - extents.width / PANGO_SCALE) / 2,
(geom.height - extents.height / PANGO_SCALE) / 2,

View File

@ -249,7 +249,7 @@ eek_container_init (EekContainer *self)
/**
* eek_container_foreach_child:
* @container: an #EekContainer
* @callback: an #EekCallback
* @callback: (scope call): an #EekCallback
* @user_data: additional data passed to @callback
*
* Enumerate children of @container and run @callback with each child.

View File

@ -34,6 +34,14 @@ G_BEGIN_DECLS
typedef struct _EekContainerClass EekContainerClass;
typedef struct _EekContainerPrivate EekContainerPrivate;
/**
* EekCallback:
* @element: an #EekElement
* @user_data: user-supplied data
*
* The type of the callback function used for iterating over the
* children of a container, see eek_container_foreach_child().
*/
typedef void (*EekCallback) (EekElement *element, gpointer user_data);
typedef gint (*EekCompareFunc) (EekElement *element, gpointer user_data);

View File

@ -26,12 +26,12 @@
* shall be used to implement #EekKeyboard, #EekSection, or #EekKey.
*/
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include "eek-element.h"
#include "eek-container.h"
#include "eek-marshalers.h"

View File

@ -22,12 +22,13 @@
* SECTION:eek-gtk-keyboard
* @short_description: a #GtkWidget displaying #EekKeyboard
*/
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include "eek-gtk-keyboard.h"
#include "eek-gtk-renderer.h"
#include "eek-keyboard.h"
@ -60,6 +61,7 @@ struct _EekGtkKeyboardPrivate
gulong key_pressed_handler;
gulong key_released_handler;
gulong symbol_index_changed_handler;
EekTheme *theme;
};
static EekColor * color_from_gdk_color (GdkColor *gdk_color);
@ -96,6 +98,7 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
{
EekGtkKeyboardPrivate *priv = EEK_GTK_KEYBOARD_GET_PRIVATE(self);
GtkAllocation allocation;
EekColor background;
gtk_widget_get_allocation (self, &allocation);
@ -103,9 +106,12 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
GtkStyle *style;
GtkStateType state;
PangoContext *pcontext;
EekColor *color;
pcontext = gtk_widget_get_pango_context (self);
priv->renderer = eek_gtk_renderer_new (priv->keyboard, pcontext, self);
if (priv->theme)
eek_renderer_set_theme (priv->renderer, priv->theme);
eek_renderer_set_allocation_size (priv->renderer,
allocation.width,
@ -114,14 +120,26 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
style = gtk_widget_get_style (self);
state = gtk_widget_get_state (self);
eek_renderer_set_foreground
(priv->renderer,
color_from_gdk_color (&style->fg[state]));
eek_renderer_set_background
(priv->renderer,
color_from_gdk_color (&style->bg[state]));
color = color_from_gdk_color (&style->fg[state]);
eek_renderer_set_default_foreground_color (priv->renderer, color);
eek_color_free (color);
color = color_from_gdk_color (&style->bg[state]);
eek_renderer_set_default_background_color (priv->renderer, color);
eek_color_free (color);
}
/* blank background */
eek_renderer_get_background_color (priv->renderer,
EEK_ELEMENT(priv->keyboard),
&background);
cairo_set_source_rgba (cr,
background.red,
background.green,
background.blue,
background.alpha);
cairo_paint (cr);
eek_renderer_render_keyboard (priv->renderer, cr);
/* redraw dragged key */
@ -271,6 +289,11 @@ eek_gtk_keyboard_dispose (GObject *object)
priv->keyboard = NULL;
}
if (priv->theme) {
g_object_unref (priv->theme);
priv->theme = NULL;
}
G_OBJECT_CLASS (eek_gtk_keyboard_parent_class)->dispose (object);
}
@ -336,14 +359,10 @@ eek_gtk_keyboard_new (EekKeyboard *keyboard)
static EekColor *
color_from_gdk_color (GdkColor *gdk_color)
{
EekColor *color;
color = g_slice_new (EekColor);
color->red = gdk_color->red / (gdouble)0xFFFF;
color->green = gdk_color->green / (gdouble)0xFFFF;
color->blue = gdk_color->blue / (gdouble)0xFFFF;
color->alpha = 1.0;
return color;
return eek_color_new (gdk_color->red / (gdouble)0xFFFF,
gdk_color->green / (gdouble)0xFFFF,
gdk_color->blue / (gdouble)0xFFFF,
1.0);
}
static void
@ -416,6 +435,7 @@ on_key_released (EekKeyboard *keyboard,
large_bounds.height);
cairo_clip (cr);
eek_renderer_render_keyboard (priv->renderer, cr);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_destroy (cr);
}
@ -429,3 +449,16 @@ on_symbol_index_changed (EekKeyboard *keyboard,
gtk_widget_queue_draw (widget);
}
void
eek_gtk_keyboard_set_theme (EekGtkKeyboard *keyboard,
EekTheme *theme)
{
EekGtkKeyboardPrivate *priv;
g_return_if_fail (EEK_IS_GTK_KEYBOARD(keyboard));
g_return_if_fail (EEK_IS_THEME(theme));
priv = EEK_GTK_KEYBOARD_GET_PRIVATE(keyboard);
priv->theme = g_object_ref (theme);
}

View File

@ -57,6 +57,8 @@ struct _EekGtkKeyboardClass
GType eek_gtk_keyboard_get_type (void) G_GNUC_CONST;
GtkWidget *eek_gtk_keyboard_new (EekKeyboard *keyboard);
void eek_gtk_keyboard_set_theme (EekGtkKeyboard *keyboard,
EekTheme *theme);
G_END_DECLS
#endif /* EEK_GTK_KEYBOARD_H */

View File

@ -99,6 +99,7 @@ eek_gtk_renderer_real_render_key_icon (EekRenderer *self,
eek_renderer_apply_transformation_for_key (self, cr, key, scale, rotate);
surface = pixbuf_to_cairo_surface (pixbuf);
g_object_unref (pixbuf);
cairo_set_source_surface (cr, surface, 0.0, 0.0);
cairo_paint (cr);
cairo_restore (cr);

View File

@ -25,15 +25,16 @@
* The #EekKeyClass class represents a key.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eek-key.h"
#include "eek-section.h"
#include "eek-keyboard.h"
@ -157,6 +158,7 @@ eek_key_real_deserialize (EekSerializable *self,
g_variant_get_child (variant, index++, "u", &priv->keycode);
g_variant_get_child (variant, index++, "v", &symbol_matrix);
eek_symbol_matrix_free (priv->symbol_matrix);
priv->symbol_matrix = _g_variant_get_symbol_matrix (symbol_matrix);
g_variant_get_child (variant, index++, "i", &priv->column);
g_variant_get_child (variant, index++, "i", &priv->row);
@ -446,12 +448,14 @@ eek_key_class_init (EekKeyClass *klass)
* @key: an #EekKey
*
* The ::pressed signal is emitted each time @key is shifted to
* the pressed state.
* the pressed state. The class handler runs before signal
* handlers to allow signal handlers to read the status of @key
* with eek_key_is_pressed().
*/
signals[PRESSED] =
g_signal_new (I_("pressed"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(EekKeyClass, pressed),
NULL,
NULL,

View File

@ -20,9 +20,8 @@
#ifndef EEK_KEY_H
#define EEK_KEY_H 1
#include <glib-object.h>
#include "eek-element.h"
#include "eek-types.h"
#include "eek-symbol-matrix.h"
G_BEGIN_DECLS

View File

@ -17,13 +17,13 @@
* Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include <pango/pangocairo.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <math.h>
#include <pango/pangocairo.h>
#include "eek-types.h"
static gdouble

View File

@ -68,7 +68,10 @@ struct _EekKeyboardPrivate
EekModifierBehavior modifier_behavior;
EekModifierType modifiers;
GArray *outline_array;
/* modifiers dynamically assigned at run time */
EekModifierType num_lock_mask;
EekModifierType alt_gr_mask;
};
static EekSerializableIface *eek_keyboard_parent_serializable_iface;
@ -144,6 +147,7 @@ eek_keyboard_real_serialize (EekSerializable *self,
}
g_variant_builder_add (builder, "v", g_variant_builder_end (&array));
g_variant_builder_add (builder, "u", priv->num_lock_mask);
g_variant_builder_add (builder, "u", priv->alt_gr_mask);
}
static gsize
@ -165,8 +169,11 @@ eek_keyboard_real_deserialize (EekSerializable *self,
while (g_variant_iter_next (&iter, "v", &outline)) {
EekOutline *_outline = _g_variant_get_outline (outline);
g_array_append_val (priv->outline_array, *_outline);
/* don't use eek_outline_free here, so as to keep _outline->points */
g_slice_free (EekOutline, _outline);
}
g_variant_get_child (variant, index++, "u", &priv->num_lock_mask);
g_variant_get_child (variant, index++, "u", &priv->alt_gr_mask);
return index;
}
@ -307,7 +314,7 @@ set_level_from_modifiers (EekKeyboard *self)
EekKeyboardPrivate *priv = EEK_KEYBOARD_GET_PRIVATE(self);
gint level = 0;
if (priv->modifiers & EEK_MOD5_MASK)
if (priv->modifiers & priv->alt_gr_mask)
level |= 2;
if (priv->modifiers & EEK_SHIFT_MASK)
level |= 1;
@ -327,19 +334,11 @@ eek_keyboard_real_key_pressed (EekKeyboard *self,
return;
modifier = eek_symbol_get_modifier_mask (symbol);
switch (priv->modifier_behavior) {
case EEK_MODIFIER_BEHAVIOR_NONE:
if (priv->modifier_behavior == EEK_MODIFIER_BEHAVIOR_NONE) {
priv->modifiers |= modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LOCK:
priv->modifiers ^= modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LATCH:
priv->modifiers = (priv->modifiers ^ modifier) & modifier;
break;
}
set_level_from_modifiers (self);
}
}
static void
eek_keyboard_real_key_released (EekKeyboard *self,
@ -354,9 +353,19 @@ eek_keyboard_real_key_released (EekKeyboard *self,
return;
modifier = eek_symbol_get_modifier_mask (symbol);
if (modifier != 0) {
if (priv->modifier_behavior == EEK_MODIFIER_BEHAVIOR_NONE)
switch (priv->modifier_behavior) {
case EEK_MODIFIER_BEHAVIOR_NONE:
priv->modifiers &= ~modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LOCK:
priv->modifiers ^= modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LATCH:
if (modifier == priv->alt_gr_mask || modifier == EEK_SHIFT_MASK)
priv->modifiers ^= modifier;
else
priv->modifiers = (priv->modifiers ^ modifier) & modifier;
break;
}
set_level_from_modifiers (self);
}
@ -775,6 +784,8 @@ eek_keyboard_add_outline (EekKeyboard *keyboard,
_outline = eek_outline_copy (outline);
g_array_append_val (priv->outline_array, *_outline);
/* don't use eek_outline_free here, so as to keep _outline->points */
g_slice_free (EekOutline, _outline);
return priv->outline_array->len;
}
@ -801,6 +812,13 @@ eek_keyboard_get_outline (EekKeyboard *keyboard,
return &g_array_index (priv->outline_array, EekOutline, oref - 1);
}
/**
* eek_keyboard_set_num_lock_mask:
* @keyboard: an #EekKeyboard
* @num_lock_mask: an #EekModifierType
*
* Set modifier mask used as Num_Lock.
*/
void
eek_keyboard_set_num_lock_mask (EekKeyboard *keyboard,
EekModifierType num_lock_mask)
@ -813,6 +831,13 @@ eek_keyboard_set_num_lock_mask (EekKeyboard *keyboard,
priv->num_lock_mask = num_lock_mask;
}
/**
* eek_keyboard_get_num_lock_mask:
* @keyboard: an #EekKeyboard
*
* Get modifier mask used as Num_Lock.
* Returns: an #EekModifierType
*/
EekModifierType
eek_keyboard_get_num_lock_mask (EekKeyboard *keyboard)
{
@ -823,3 +848,40 @@ eek_keyboard_get_num_lock_mask (EekKeyboard *keyboard)
return priv->num_lock_mask;
}
/**
* eek_keyboard_set_alt_gr_mask:
* @keyboard: an #EekKeyboard
* @alt_gr_mask: an #EekModifierType
*
* Set modifier mask used as Alt_Gr.
*/
void
eek_keyboard_set_alt_gr_mask (EekKeyboard *keyboard,
EekModifierType alt_gr_mask)
{
EekKeyboardPrivate *priv;
g_assert (EEK_IS_KEYBOARD(keyboard));
priv = EEK_KEYBOARD_GET_PRIVATE(keyboard);
priv->alt_gr_mask = alt_gr_mask;
}
/**
* eek_keyboard_get_alt_gr_mask:
* @keyboard: an #EekKeyboard
*
* Get modifier mask used as Alt_Gr.
* Returns: an #EekModifierType
*/
EekModifierType
eek_keyboard_get_alt_gr_mask (EekKeyboard *keyboard)
{
EekKeyboardPrivate *priv;
g_assert (EEK_IS_KEYBOARD(keyboard));
priv = EEK_KEYBOARD_GET_PRIVATE(keyboard);
return priv->alt_gr_mask;
}

View File

@ -153,5 +153,11 @@ void eek_keyboard_set_num_lock_mask
EekModifierType eek_keyboard_get_num_lock_mask
(EekKeyboard *keyboard);
void eek_keyboard_set_alt_gr_mask
(EekKeyboard *keyboard,
EekModifierType alt_gr_mask);
EekModifierType eek_keyboard_get_alt_gr_mask
(EekKeyboard *keyboard);
G_END_DECLS
#endif /* EEK_KEYBOARD_H */

View File

@ -23,13 +23,13 @@
* @short_description: an #EekSymbol represents an X keysym
*/
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include <stdlib.h>
#include "eek-keysym.h"
#include "eek-serializable.h"

View File

@ -18,12 +18,12 @@
* 02110-1301 USA
*/
#include <math.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <math.h>
#include "eek-key.h"
#include "eek-section.h"
#include "eek-renderer.h"
@ -45,25 +45,34 @@ struct _EekRendererPrivate
EekKeyboard *keyboard;
PangoContext *pcontext;
EekColor *foreground;
EekColor *background;
EekColor default_foreground_color;
EekColor default_background_color;
gdouble border_width;
gdouble allocation_width;
gdouble allocation_height;
gdouble scale;
PangoFontDescription *ascii_font;
PangoFontDescription *font;
GHashTable *outline_surface_cache;
GHashTable *active_outline_surface_cache;
cairo_surface_t *keyboard_surface;
gulong symbol_index_changed_handler;
EekTheme *theme;
};
struct {
static const EekColor DEFAULT_FOREGROUND_COLOR = {0.3, 0.3, 0.3, 1.0};
static const EekColor DEFAULT_BACKGROUND_COLOR = {1.0, 1.0, 1.0, 1.0};
struct _TextProperty {
gint category;
gboolean ascii;
gdouble scale;
} symbol_category_scale_factors[EEK_SYMBOL_CATEGORY_LAST] = {
{ EEK_SYMBOL_CATEGORY_LETTER, 1.0 },
{ EEK_SYMBOL_CATEGORY_FUNCTION, 0.5 },
{ EEK_SYMBOL_CATEGORY_KEYNAME, 0.5 }
gboolean ellipses;
};
typedef struct _TextProperty TextProperty;
/* eek-keyboard-drawing.c */
extern void _eek_rounded_polygon (cairo_t *cr,
@ -144,6 +153,14 @@ create_keyboard_surface (EekRenderer *renderer)
EekBounds bounds;
cairo_surface_t *keyboard_surface;
CreateKeyboardSurfaceCallbackData data;
EekColor foreground, background;
eek_renderer_get_foreground_color (renderer,
EEK_ELEMENT(priv->keyboard),
&foreground);
eek_renderer_get_background_color (renderer,
EEK_ELEMENT(priv->keyboard),
&background);
eek_element_get_bounds (EEK_ELEMENT(priv->keyboard), &bounds);
keyboard_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
@ -156,22 +173,24 @@ create_keyboard_surface (EekRenderer *renderer)
/* blank background */
cairo_set_source_rgba (data.cr,
priv->background->red,
priv->background->green,
priv->background->blue,
priv->background->alpha);
cairo_rectangle (data.cr,
0.0,
0.0,
cairo_image_surface_get_width (keyboard_surface),
cairo_image_surface_get_height (keyboard_surface));
cairo_fill (data.cr);
background.red,
background.green,
background.blue,
background.alpha);
cairo_paint (data.cr);
cairo_set_source_rgba (data.cr,
foreground.red,
foreground.green,
foreground.blue,
foreground.alpha);
/* draw sections */
eek_container_foreach_child (EEK_CONTAINER(priv->keyboard),
create_keyboard_surface_section_callback,
&data);
cairo_destroy (data.cr);
return keyboard_surface;
}
@ -183,21 +202,54 @@ render_key_outline (EekRenderer *renderer,
EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(renderer);
EekOutline *outline;
EekBounds bounds;
cairo_pattern_t *pat;
gdouble scale;
gint i;
gulong oref;
/* need to rescale so that the border fit inside the clipping
region */
eek_element_get_bounds (EEK_ELEMENT(key), &bounds);
scale = MIN((bounds.width - priv->border_width) / bounds.width,
(bounds.height - priv->border_width) / bounds.height);
EekThemeNode *theme_node;
EekColor foreground, background, gradient_start, gradient_end, border_color;
EekGradientType gradient_type;
gint border_width;
gint border_radius;
oref = eek_key_get_oref (key);
if (oref == 0)
return;
if (eek_key_is_pressed (key))
theme_node = g_object_get_data (G_OBJECT(key), "theme-node-pressed");
else
theme_node = g_object_get_data (G_OBJECT(key), "theme-node");
if (theme_node) {
eek_theme_node_get_foreground_color (theme_node, &foreground);
eek_theme_node_get_background_color (theme_node, &background);
eek_theme_node_get_background_gradient (theme_node,
&gradient_type,
&gradient_start,
&gradient_end);
border_width = eek_theme_node_get_border_width (theme_node,
EEK_SIDE_TOP);
border_radius = eek_theme_node_get_border_radius (theme_node,
EEK_SIDE_TOP);
eek_theme_node_get_border_color (theme_node, EEK_SIDE_TOP,
&border_color);
} else {
foreground = priv->default_foreground_color;
background = priv->default_background_color;
gradient_type = EEK_GRADIENT_NONE;
border_width = priv->border_width;
border_radius = -1;
border_color.red = ABS(background.red - foreground.red) * 0.7;
border_color.green = ABS(background.green - foreground.green) * 0.7;
border_color.blue = ABS(background.blue - foreground.blue) * 0.7;
border_color.alpha = foreground.alpha;
}
/* need to rescale so that the border fit inside the clipping
region */
eek_element_get_bounds (EEK_ELEMENT(key), &bounds);
scale = MIN((bounds.width - border_width) / bounds.width,
(bounds.height - border_width) / bounds.height);
outline = eek_keyboard_get_outline (priv->keyboard, oref);
outline = eek_outline_copy (outline);
for (i = 0; i < outline->num_points; i++) {
@ -206,49 +258,81 @@ render_key_outline (EekRenderer *renderer,
}
cairo_translate (cr,
priv->border_width / 2 * priv->scale,
priv->border_width / 2 * priv->scale);
border_width / 2 * priv->scale,
border_width / 2 * priv->scale);
/* paint the background with gradient */
if (gradient_type != EEK_GRADIENT_NONE) {
cairo_pattern_t *pat;
gdouble cx, cy;
switch (gradient_type) {
case EEK_GRADIENT_VERTICAL:
pat = cairo_pattern_create_linear (0.0,
0.0,
0.0,
bounds.height * priv->scale * 5.0);
bounds.height * priv->scale);
break;
case EEK_GRADIENT_HORIZONTAL:
pat = cairo_pattern_create_linear (0.0,
0.0,
bounds.width * priv->scale,
0.0);
break;
case EEK_GRADIENT_RADIAL:
cx = bounds.width / 2 * priv->scale;
cy = bounds.height / 2 * priv->scale;
pat = cairo_pattern_create_radial (cx,
cy,
0,
cx,
cy,
MIN(cx, cy));
break;
default:
g_assert_not_reached ();
break;
}
cairo_pattern_add_color_stop_rgba (pat,
1,
priv->background->red * 0.5,
priv->background->green * 0.5,
priv->background->blue * 0.5,
priv->background->alpha);
gradient_start.red * 0.5,
gradient_start.green * 0.5,
gradient_start.blue * 0.5,
gradient_start.alpha);
cairo_pattern_add_color_stop_rgba (pat,
0,
priv->background->red,
priv->background->green,
priv->background->blue,
priv->background->alpha);
gradient_end.red,
gradient_end.green,
gradient_end.blue,
gradient_end.alpha);
cairo_set_source (cr, pat);
cairo_pattern_destroy (pat);
} else {
cairo_set_source_rgba (cr,
background.red,
background.green,
background.blue,
background.alpha);
}
_eek_rounded_polygon (cr,
outline->corner_radius,
border_radius >= 0 ? border_radius : outline->corner_radius,
outline->points,
outline->num_points);
cairo_fill (cr);
cairo_pattern_destroy (pat);
/* paint the border */
cairo_set_line_width (cr, priv->border_width);
cairo_set_line_width (cr, border_width);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
cairo_set_source_rgba
(cr,
ABS(priv->background->red - priv->foreground->red) * 0.7,
ABS(priv->background->green - priv->foreground->green) * 0.7,
ABS(priv->background->blue - priv->foreground->blue) * 0.7,
priv->foreground->alpha);
cairo_set_source_rgba (cr,
border_color.red,
border_color.green,
border_color.blue,
border_color.alpha);
_eek_rounded_polygon (cr,
outline->corner_radius,
border_radius >= 0 ? border_radius : outline->corner_radius,
outline->points,
outline->num_points);
cairo_stroke (cr);
@ -258,8 +342,9 @@ render_key_outline (EekRenderer *renderer,
struct _CalculateFontSizeCallbackData {
gdouble size;
gdouble em_size;
gboolean ascii;
EekRenderer *renderer;
const PangoFontDescription *base_font;
};
typedef struct _CalculateFontSizeCallbackData CalculateFontSizeCallbackData;
@ -270,23 +355,26 @@ calculate_font_size_key_callback (EekElement *element, gpointer user_data)
EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(data->renderer);
gdouble sx, sy;
PangoFontDescription *font;
const PangoFontDescription *base_font;
PangoRectangle extents = { 0, };
PangoLayout *layout;
gdouble size;
EekSymbol *symbol;
EekBounds bounds;
const gchar *label = NULL;
if (data->ascii)
label = "M";
else {
EekSymbol *symbol;
symbol = eek_key_get_symbol (EEK_KEY(element));
if (symbol &&
eek_symbol_get_category (symbol) == EEK_SYMBOL_CATEGORY_LETTER)
label = eek_symbol_get_label (symbol);
if (!label)
label = "M";
}
base_font = pango_context_get_font_description (priv->pcontext);
font = pango_font_description_copy (base_font);
font = pango_font_description_copy (data->base_font);
eek_element_get_bounds (element, &bounds);
size = eek_bounds_long_side (&bounds) * PANGO_SCALE;
@ -307,12 +395,8 @@ calculate_font_size_key_callback (EekElement *element, gpointer user_data)
sy = bounds.height * PANGO_SCALE / extents.height;
size *= MIN(sx, sy);
if (size >= pango_font_description_get_size (base_font)) {
if (size < data->size)
data->size = size;
if (size < data->em_size)
data->em_size = size;
}
}
static void
@ -324,20 +408,21 @@ calculate_font_size_section_callback (EekElement *element, gpointer user_data)
}
static gdouble
calculate_font_size (EekRenderer *renderer)
calculate_font_size (EekRenderer *renderer,
const PangoFontDescription *base_font,
gboolean ascii)
{
EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(renderer);
CalculateFontSizeCallbackData data;
PangoFontDescription *base_font;
base_font = pango_context_get_font_description (priv->pcontext);
data.size = G_MAXDOUBLE;
data.em_size = G_MAXDOUBLE;
data.ascii = ascii;
data.renderer = renderer;
data.base_font = base_font;
eek_container_foreach_child (EEK_CONTAINER(priv->keyboard),
calculate_font_size_section_callback,
&data);
return data.size > 0 ? data.size : data.em_size;
return data.size;
}
static void
@ -351,15 +436,20 @@ render_key (EekRenderer *self,
EekBounds bounds;
gulong oref;
EekSymbol *symbol;
GHashTable *outline_surface_cache;
eek_element_get_bounds (EEK_ELEMENT(key), &bounds);
oref = eek_key_get_oref (key);
if (oref == 0)
return;
if (eek_key_is_pressed (key))
outline_surface_cache = priv->active_outline_surface_cache;
else
outline_surface_cache = priv->outline_surface_cache;
outline = eek_keyboard_get_outline (priv->keyboard, oref);
outline_surface = g_hash_table_lookup (priv->outline_surface_cache,
outline);
outline_surface = g_hash_table_lookup (outline_surface_cache, outline);
if (!outline_surface) {
cairo_t *cr;
@ -370,18 +460,13 @@ render_key (EekRenderer *self,
cr = cairo_create (outline_surface);
/* blank background */
eek_element_get_bounds (EEK_ELEMENT(key), &bounds);
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
cairo_rectangle (cr,
0.0,
0.0,
bounds.width * priv->scale,
bounds.height * priv->scale);
cairo_fill (cr);
cairo_paint (cr);
eek_renderer_render_key_outline (self, cr, key, 1.0, 0);
cairo_destroy (cr);
g_hash_table_insert (priv->outline_surface_cache,
g_hash_table_insert (outline_surface_cache,
outline,
outline_surface);
}
@ -396,6 +481,8 @@ render_key (EekRenderer *self,
} else {
PangoLayout *layout;
PangoRectangle extents = { 0, };
EekColor foreground;
EekThemeNode *theme_node;
layout = pango_cairo_create_layout (cr);
eek_renderer_render_key_label (self, layout, key);
@ -406,11 +493,18 @@ render_key (EekRenderer *self,
(cr,
(bounds.width * priv->scale - extents.width / PANGO_SCALE) / 2,
(bounds.height * priv->scale - extents.height / PANGO_SCALE) / 2);
if (eek_key_is_pressed (key))
theme_node = g_object_get_data (G_OBJECT(key), "theme-node-pressed");
else
theme_node = g_object_get_data (G_OBJECT(key), "theme-node");
eek_renderer_get_foreground_color (self, EEK_ELEMENT(key), &foreground);
cairo_set_source_rgba (cr,
priv->foreground->red,
priv->foreground->green,
priv->foreground->blue,
priv->foreground->alpha);
foreground.red,
foreground.green,
foreground.blue,
foreground.alpha);
pango_cairo_show_layout (cr, layout);
cairo_restore (cr);
@ -447,6 +541,23 @@ eek_renderer_apply_transformation_for_key (EekRenderer *self,
}
}
static const TextProperty *
get_text_property_for_category (EekSymbolCategory category)
{
static const TextProperty props[EEK_SYMBOL_CATEGORY_LAST] = {
{ EEK_SYMBOL_CATEGORY_LETTER, FALSE, 1.0, FALSE },
{ EEK_SYMBOL_CATEGORY_FUNCTION, TRUE, 0.5, FALSE },
{ EEK_SYMBOL_CATEGORY_KEYNAME, TRUE, 0.5, TRUE }
};
gint i;
for (i = 0; i < G_N_ELEMENTS(props); i++)
if (props[i].category == category)
return &props[i];
g_return_val_if_reached (NULL);
}
static void
eek_renderer_real_render_key_label (EekRenderer *self,
PangoLayout *layout,
@ -457,9 +568,9 @@ eek_renderer_real_render_key_label (EekRenderer *self,
EekSymbolCategory category;
const gchar *label;
EekBounds bounds;
const TextProperty *prop;
PangoFontDescription *font;
gdouble size, scale;
gint i;
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (!symbol)
@ -470,11 +581,20 @@ eek_renderer_real_render_key_label (EekRenderer *self,
return;
if (!priv->font) {
PangoFontDescription *base_font;
gdouble size;
const PangoFontDescription *base_font;
gdouble ascii_size, size;
EekThemeNode *theme_node;
size = calculate_font_size (self);
theme_node = g_object_get_data (G_OBJECT(key), "theme-node");
if (theme_node)
base_font = eek_theme_node_get_font (theme_node);
else
base_font = pango_context_get_font_description (priv->pcontext);
ascii_size = calculate_font_size (self, base_font, TRUE);
priv->ascii_font = pango_font_description_copy (base_font);
pango_font_description_set_size (priv->ascii_font, ascii_size);
size = calculate_font_size (self, base_font, FALSE);
priv->font = pango_font_description_copy (base_font);
pango_font_description_set_size (priv->font, size);
}
@ -483,19 +603,22 @@ eek_renderer_real_render_key_label (EekRenderer *self,
scale = MIN((bounds.width - priv->border_width) / bounds.width,
(bounds.height - priv->border_width) / bounds.height);
font = pango_font_description_copy (priv->font);
size = pango_font_description_get_size (font);
category = eek_symbol_get_category (symbol);
for (i = 0; i < G_N_ELEMENTS(symbol_category_scale_factors); i++)
if (symbol_category_scale_factors[i].category == category) {
size *= symbol_category_scale_factors[i].scale;
break;
}
pango_font_description_set_size (font, size * priv->scale * scale);
prop = get_text_property_for_category (category);
font = pango_font_description_copy (prop->ascii ?
priv->ascii_font :
priv->font);
pango_font_description_set_size (font,
pango_font_description_get_size (font) *
prop->scale * priv->scale * scale);
pango_layout_set_font_description (layout, font);
pango_font_description_free (font);
pango_layout_set_text (layout, label, -1);
pango_layout_set_width (layout,
PANGO_SCALE * bounds.width * priv->scale * scale);
if (prop->ellipses)
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
}
@ -531,6 +654,10 @@ eek_renderer_real_render_keyboard (EekRenderer *self,
{
EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(self);
g_return_if_fail (priv->keyboard);
g_return_if_fail (priv->allocation_width > 0.0);
g_return_if_fail (priv->allocation_height > 0.0);
if (!priv->keyboard_surface)
priv->keyboard_surface = create_keyboard_surface (self);
@ -560,6 +687,31 @@ eek_renderer_set_property (GObject *object,
priv->pcontext = g_value_get_object (value);
g_object_ref (priv->pcontext);
break;
default:
g_object_set_property (object,
g_param_spec_get_name (pspec),
value);
break;
}
}
static void
eek_renderer_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(object);
switch (prop_id) {
case PROP_KEYBOARD:
g_value_set_object (value, priv->keyboard);
break;
default:
g_object_get_property (object,
g_param_spec_get_name (pspec),
value);
break;
}
}
@ -592,6 +744,9 @@ eek_renderer_finalize (GObject *object)
{
EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(object);
g_hash_table_destroy (priv->outline_surface_cache);
g_hash_table_destroy (priv->active_outline_surface_cache);
pango_font_description_free (priv->ascii_font);
pango_font_description_free (priv->font);
G_OBJECT_CLASS (eek_renderer_parent_class)->finalize (object);
}
@ -610,6 +765,7 @@ eek_renderer_class_init (EekRendererClass *klass)
klass->render_keyboard = eek_renderer_real_render_keyboard;
gobject_class->set_property = eek_renderer_set_property;
gobject_class->get_property = eek_renderer_get_property;
gobject_class->dispose = eek_renderer_dispose;
gobject_class->finalize = eek_renderer_finalize;
@ -617,7 +773,7 @@ eek_renderer_class_init (EekRendererClass *klass)
"Keyboard",
"Keyboard",
EEK_TYPE_KEYBOARD,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_KEYBOARD,
pspec);
@ -632,12 +788,6 @@ eek_renderer_class_init (EekRendererClass *klass)
pspec);
}
static void
free_surface (gpointer data)
{
cairo_surface_destroy (data);
}
static void
eek_renderer_init (EekRenderer *self)
{
@ -646,16 +796,23 @@ eek_renderer_init (EekRenderer *self)
priv = self->priv = EEK_RENDERER_GET_PRIVATE(self);
priv->keyboard = NULL;
priv->pcontext = NULL;
priv->foreground = eek_color_new (0.3, 0.3, 0.3, 1.0);
priv->background = eek_color_new (1.0, 1.0, 1.0, 1.0);
priv->default_foreground_color = DEFAULT_FOREGROUND_COLOR;
priv->default_background_color = DEFAULT_BACKGROUND_COLOR;
priv->border_width = 1.0;
priv->allocation_width = 0.0;
priv->allocation_height = 0.0;
priv->scale = 1.0;
priv->font = NULL;
priv->outline_surface_cache =
g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
free_surface);
(GDestroyNotify)cairo_surface_destroy);
priv->active_outline_surface_cache =
g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify)cairo_surface_destroy);
priv->keyboard_surface = NULL;
priv->symbol_index_changed_handler = 0;
}
@ -668,6 +825,9 @@ invalidate (EekRenderer *renderer)
if (priv->outline_surface_cache)
g_hash_table_remove_all (priv->outline_surface_cache);
if (priv->active_outline_surface_cache)
g_hash_table_remove_all (priv->active_outline_surface_cache);
if (priv->keyboard_surface) {
cairo_surface_destroy (priv->keyboard_surface);
priv->keyboard_surface = NULL;
@ -712,6 +872,9 @@ eek_renderer_set_allocation_size (EekRenderer *renderer,
priv = EEK_RENDERER_GET_PRIVATE(renderer);
priv->allocation_width = width;
priv->allocation_height = height;
eek_element_get_bounds (EEK_ELEMENT(priv->keyboard), &bounds);
scale = width > height ? height / bounds.height :
width / bounds.width;
@ -906,55 +1069,94 @@ eek_renderer_render_keyboard (EekRenderer *renderer,
}
void
eek_renderer_set_foreground (EekRenderer *renderer,
EekColor *foreground)
eek_renderer_set_default_foreground_color (EekRenderer *renderer,
const EekColor *color)
{
EekRendererPrivate *priv;
g_return_if_fail (EEK_IS_RENDERER(renderer));
g_return_if_fail (foreground);
g_return_if_fail (color);
priv = EEK_RENDERER_GET_PRIVATE(renderer);
priv->foreground = g_boxed_copy (EEK_TYPE_COLOR, foreground);
priv->default_foreground_color = *color;
}
void
eek_renderer_set_background (EekRenderer *renderer,
EekColor *background)
eek_renderer_set_default_background_color (EekRenderer *renderer,
const EekColor *color)
{
EekRendererPrivate *priv;
g_return_if_fail (EEK_IS_RENDERER(renderer));
g_return_if_fail (background);
g_return_if_fail (color);
priv = EEK_RENDERER_GET_PRIVATE(renderer);
priv->background = g_boxed_copy (EEK_TYPE_COLOR, background);
priv->default_background_color = *color;
}
void
eek_renderer_get_foreground (EekRenderer *renderer,
EekColor *foreground)
eek_renderer_get_foreground_color (EekRenderer *renderer,
EekElement *element,
EekColor *color)
{
EekRendererPrivate *priv;
EekThemeNode *theme_node;
g_return_if_fail (EEK_IS_RENDERER(renderer));
g_return_if_fail (foreground);
g_return_if_fail (color);
priv = EEK_RENDERER_GET_PRIVATE(renderer);
*foreground = *priv->foreground;
theme_node = g_object_get_data (G_OBJECT(element), "theme-node");
if (theme_node)
eek_theme_node_get_foreground_color (theme_node, color);
else
*color = priv->default_foreground_color;
}
void
eek_renderer_get_background (EekRenderer *renderer,
EekColor *background)
eek_renderer_get_background_color (EekRenderer *renderer,
EekElement *element,
EekColor *color)
{
EekRendererPrivate *priv;
EekThemeNode *theme_node;
g_return_if_fail (EEK_IS_RENDERER(renderer));
g_return_if_fail (background);
g_return_if_fail (color);
priv = EEK_RENDERER_GET_PRIVATE(renderer);
*background = *priv->background;
theme_node = g_object_get_data (G_OBJECT(element), "theme-node");
if (theme_node)
eek_theme_node_get_background_color (theme_node, color);
else
*color = priv->default_background_color;
}
void
eek_renderer_get_background_gradient (EekRenderer *renderer,
EekElement *element,
EekGradientType *type,
EekColor *start,
EekColor *end)
{
EekRendererPrivate *priv;
EekThemeNode *theme_node;
g_return_if_fail (EEK_IS_RENDERER(renderer));
g_return_if_fail (EEK_IS_ELEMENT(element));
g_return_if_fail (type);
g_return_if_fail (start);
g_return_if_fail (end);
priv = EEK_RENDERER_GET_PRIVATE(renderer);
theme_node = g_object_get_data (G_OBJECT(element), "theme-node");
if (theme_node)
eek_theme_node_get_background_gradient (theme_node, type, start, end);
else
*type = EEK_GRADIENT_NONE;
}
struct _FindKeyByPositionCallbackData {
@ -1082,3 +1284,119 @@ eek_renderer_find_key_by_position (EekRenderer *renderer,
&data);
return data.key;
}
struct _CreateThemeNodeData {
EekThemeContext *context;
EekThemeNode *parent;
EekRenderer *renderer;
};
typedef struct _CreateThemeNodeData CreateThemeNodeData;
void
create_theme_node_key_callback (EekElement *element,
gpointer user_data)
{
CreateThemeNodeData *data = user_data;
EekRendererPrivate *priv;
EekThemeNode *theme_node;
priv = EEK_RENDERER_GET_PRIVATE(data->renderer);
theme_node = eek_theme_node_new (data->context,
data->parent,
priv->theme,
EEK_TYPE_KEY,
eek_element_get_name (element),
"key",
NULL,
NULL);
g_object_set_data_full (G_OBJECT(element),
"theme-node",
theme_node,
(GDestroyNotify)g_object_unref);
theme_node = eek_theme_node_new (data->context,
data->parent,
priv->theme,
EEK_TYPE_KEY,
eek_element_get_name (element),
"key",
"active",
NULL);
g_object_set_data_full (G_OBJECT(element),
"theme-node-pressed",
theme_node,
(GDestroyNotify)g_object_unref);
}
void
create_theme_node_section_callback (EekElement *element,
gpointer user_data)
{
CreateThemeNodeData *data = user_data;
EekRendererPrivate *priv;
EekThemeNode *theme_node, *parent;
priv = EEK_RENDERER_GET_PRIVATE(data->renderer);
theme_node = eek_theme_node_new (data->context,
data->parent,
priv->theme,
EEK_TYPE_SECTION,
eek_element_get_name (element),
"section",
NULL,
NULL);
g_object_set_data_full (G_OBJECT(element),
"theme-node",
theme_node,
(GDestroyNotify)g_object_unref);
parent = data->parent;
data->parent = theme_node;
eek_container_foreach_child (EEK_CONTAINER(element),
create_theme_node_key_callback,
data);
data->parent = parent;
}
void
eek_renderer_set_theme (EekRenderer *renderer,
EekTheme *theme)
{
EekRendererPrivate *priv;
EekThemeContext *theme_context;
EekThemeNode *theme_node;
CreateThemeNodeData data;
g_assert (EEK_IS_RENDERER(renderer));
g_assert (EEK_IS_THEME(theme));
priv = EEK_RENDERER_GET_PRIVATE(renderer);
g_assert (priv->keyboard);
if (priv->theme)
g_object_unref (priv->theme);
priv->theme = g_object_ref (theme);
theme_context = eek_theme_context_new ();
theme_node = eek_theme_node_new (theme_context,
NULL,
priv->theme,
EEK_TYPE_KEYBOARD,
"keyboard",
"keyboard",
NULL,
NULL);
g_object_set_data_full (G_OBJECT(priv->keyboard),
"theme-node",
theme_node,
(GDestroyNotify)g_object_unref);
data.context = theme_context;
data.parent = theme_node;
data.renderer = renderer;
eek_container_foreach_child (EEK_CONTAINER(priv->keyboard),
create_theme_node_section_callback,
&data);
}

View File

@ -25,6 +25,8 @@
#include "eek-keyboard.h"
#include "eek-keysym.h"
#include "eek-types.h"
#include "eek-theme.h"
#include "eek-theme-context.h"
G_BEGIN_DECLS
@ -121,14 +123,24 @@ void eek_renderer_render_key_icon (EekRenderer *renderer,
void eek_renderer_render_keyboard (EekRenderer *renderer,
cairo_t *cr);
void eek_renderer_set_foreground (EekRenderer *renderer,
EekColor *foreground);
void eek_renderer_set_background (EekRenderer *renderer,
EekColor *background);
void eek_renderer_get_foreground (EekRenderer *renderer,
EekColor *foreground);
void eek_renderer_get_background (EekRenderer *renderer,
EekColor *background);
void eek_renderer_set_default_foreground_color
(EekRenderer *renderer,
const EekColor *color);
void eek_renderer_set_default_background_color
(EekRenderer *renderer,
const EekColor *color);
void eek_renderer_get_foreground_color (EekRenderer *renderer,
EekElement *element,
EekColor *color);
void eek_renderer_get_background_color (EekRenderer *renderer,
EekElement *element,
EekColor *color);
void eek_renderer_get_background_gradient
(EekRenderer *renderer,
EekElement *element,
EekGradientType *type,
EekColor *start,
EekColor *end);
void eek_renderer_set_border_width (EekRenderer *renderer,
gdouble border_width);
EekKey *eek_renderer_find_key_by_position (EekRenderer *renderer,
@ -141,5 +153,8 @@ void eek_renderer_apply_transformation_for_key
gdouble scale,
gboolean rotate);
void eek_renderer_set_theme (EekRenderer *renderer,
EekTheme *theme);
G_END_DECLS
#endif /* EEK_RENDERER_H */

View File

@ -27,11 +27,12 @@
* of one or more keys of the #EekKeyClass class.
*/
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include "eek-keyboard.h"
#include "eek-section.h"
#include "eek-key.h"
@ -265,6 +266,21 @@ eek_section_real_find_key_by_keycode (EekSection *self,
(gpointer)(long)keycode);
}
static void
set_level_from_modifiers (EekSection *self)
{
EekSectionPrivate *priv = EEK_SECTION_GET_PRIVATE(self);
EekKeyboard *keyboard;
EekModifierType num_lock_mask;
gint level = -1;
keyboard = EEK_KEYBOARD(eek_element_get_parent (EEK_ELEMENT(self)));
num_lock_mask = eek_keyboard_get_num_lock_mask (keyboard);
if (priv->modifiers & num_lock_mask)
level = 1;
eek_element_set_level (EEK_ELEMENT(self), level);
}
static void
eek_section_real_key_pressed (EekSection *self, EekKey *key)
{
@ -273,8 +289,6 @@ eek_section_real_key_pressed (EekSection *self, EekKey *key)
EekKeyboard *keyboard;
EekModifierBehavior behavior;
EekModifierType modifier;
EekModifierType num_lock_mask;
gint level = -1;
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (!symbol)
@ -283,22 +297,10 @@ eek_section_real_key_pressed (EekSection *self, EekKey *key)
keyboard = EEK_KEYBOARD(eek_element_get_parent (EEK_ELEMENT(self)));
behavior = eek_keyboard_get_modifier_behavior (keyboard);
modifier = eek_symbol_get_modifier_mask (symbol);
switch (behavior) {
case EEK_MODIFIER_BEHAVIOR_NONE:
if (behavior == EEK_MODIFIER_BEHAVIOR_NONE) {
priv->modifiers |= modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LOCK:
priv->modifiers ^= modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LATCH:
priv->modifiers = (priv->modifiers ^ modifier) & modifier;
break;
set_level_from_modifiers (self);
}
num_lock_mask = eek_keyboard_get_num_lock_mask (keyboard);
if (priv->modifiers & num_lock_mask)
level = 1;
eek_element_set_level (EEK_ELEMENT(self), level);
}
static void
@ -309,8 +311,6 @@ eek_section_real_key_released (EekSection *self, EekKey *key)
EekKeyboard *keyboard;
EekModifierBehavior behavior;
EekModifierType modifier;
EekModifierType num_lock_mask;
gint level = -1;
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (!symbol)
@ -319,15 +319,18 @@ eek_section_real_key_released (EekSection *self, EekKey *key)
keyboard = EEK_KEYBOARD(eek_element_get_parent (EEK_ELEMENT(self)));
behavior = eek_keyboard_get_modifier_behavior (keyboard);
modifier = eek_symbol_get_modifier_mask (symbol);
if (modifier != 0) {
if (behavior == EEK_MODIFIER_BEHAVIOR_NONE)
switch (behavior) {
case EEK_MODIFIER_BEHAVIOR_NONE:
priv->modifiers &= ~modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LOCK:
priv->modifiers ^= modifier;
break;
case EEK_MODIFIER_BEHAVIOR_LATCH:
priv->modifiers = (priv->modifiers ^ modifier) & modifier;
break;
}
num_lock_mask = eek_keyboard_get_num_lock_mask (keyboard);
if (priv->modifiers & num_lock_mask)
level = 1;
eek_element_set_level (EEK_ELEMENT(self), level);
set_level_from_modifiers (self);
}
static void

105
eek/eek-symbol-matrix.c Normal file
View File

@ -0,0 +1,105 @@
/*
* 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 "eek-symbol-matrix.h"
EekSymbolMatrix *
eek_symbol_matrix_new (gint num_groups,
gint num_levels)
{
EekSymbolMatrix *matrix = g_slice_new (EekSymbolMatrix);
matrix->num_groups = num_groups;
matrix->num_levels = num_levels;
matrix->data = g_slice_alloc0 (sizeof (EekSymbol *) *
num_groups * num_levels);
return matrix;
}
EekSymbolMatrix *
eek_symbol_matrix_copy (const EekSymbolMatrix *matrix)
{
EekSymbolMatrix *retval;
gint i, num_symbols = matrix->num_groups * matrix->num_levels;
retval = g_slice_dup (EekSymbolMatrix, matrix);
retval->data = g_slice_copy (sizeof (EekSymbol *) * num_symbols,
matrix->data);
for (i = 0; i < num_symbols; i++)
if (retval->data[i])
g_object_ref (retval->data[i]);
return retval;
}
void
eek_symbol_matrix_free (EekSymbolMatrix *matrix)
{
gint i, num_symbols = matrix->num_groups * matrix->num_levels;
for (i = 0; i < num_symbols; i++)
if (matrix->data[i])
g_object_unref (matrix->data[i]);
g_slice_free1 (sizeof (EekSymbol *) * num_symbols, matrix->data);
g_slice_free (EekSymbolMatrix, matrix);
}
GType
eek_symbol_matrix_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type =
g_boxed_type_register_static ("EekSymbolMatrix",
(GBoxedCopyFunc)eek_symbol_matrix_copy,
(GBoxedFreeFunc)eek_symbol_matrix_free);
return our_type;
}
void
eek_symbol_matrix_set_symbol (EekSymbolMatrix *matrix,
gint group,
gint level,
EekSymbol *symbol)
{
g_return_if_fail (group >= 0 && group < matrix->num_groups);
g_return_if_fail (level >= 0 && level < matrix->num_levels);
g_return_if_fail (EEK_IS_SYMBOL(symbol));
matrix->data[group * matrix->num_levels + level] = g_object_ref (symbol);
}
/**
* eek_symbol_matrix_get_symbol:
* @matrix: an #EekSymbolMatrix
* @group: group index of @matrix
* @level: level index of @matrix
*
* Get an #EekSymbol stored in the cell selected by (@group, @level)
* in @matrix.
*
* Return value: (transfer none): an #EekSymbol.
*/
EekSymbol *
eek_symbol_matrix_get_symbol (EekSymbolMatrix *matrix,
gint group,
gint level)
{
g_return_val_if_fail (group >= 0 && group < matrix->num_groups, NULL);
g_return_val_if_fail (level >= 0 && level < matrix->num_levels, NULL);
return matrix->data[group * matrix->num_levels + level];
}

60
eek/eek-symbol-matrix.h Normal file
View File

@ -0,0 +1,60 @@
/*
* 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 EEK_SYMBOL_MATRIX_H
#define EEK_SYMBOL_MATRIX_H 1
#include "eek-symbol.h"
G_BEGIN_DECLS
/**
* EekSymbolMatrix:
* @data: array of symbols
* @num_groups: the number of groups (rows)
* @num_levels: the number of levels (columns)
*
* Symbol matrix of a key.
*/
struct _EekSymbolMatrix
{
gint num_groups;
gint num_levels;
EekSymbol **data;
};
GType eek_symbol_matrix_get_type (void) G_GNUC_CONST;
EekSymbolMatrix *eek_symbol_matrix_new (gint num_groups,
gint num_levels);
EekSymbolMatrix *eek_symbol_matrix_copy (const EekSymbolMatrix *matrix);
void eek_symbol_matrix_free (EekSymbolMatrix *matrix);
void eek_symbol_matrix_set_symbol
(EekSymbolMatrix *matrix,
gint group,
gint level,
EekSymbol *symbol);
EekSymbol *eek_symbol_matrix_get_symbol
(EekSymbolMatrix *matrix,
gint group,
gint level);
G_END_DECLS
#endif /* EEK_SYMBOL_MATRIX_H */

View File

@ -20,7 +20,6 @@
#ifndef EEK_SYMBOL_H
#define EEK_SYMBOL_H 1
#include <glib-object.h>
#include "eek-types.h"
G_BEGIN_DECLS

288
eek/eek-theme-context.c Normal file
View File

@ -0,0 +1,288 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/*
* eek-theme-context.c: holds global information about a tree of styled objects
*
* Copyright 2009, 2010 Red Hat, Inc.
* Copyright 2009 Florian Müllner
*
* This program 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.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eek-theme.h"
#include "eek-theme-context.h"
struct _EekThemeContext {
GObject parent;
double resolution;
PangoFontDescription *font;
EekThemeNode *root_node;
EekTheme *theme;
};
struct _EekThemeContextClass {
GObjectClass parent_class;
};
#define DEFAULT_RESOLUTION 96.
#define DEFAULT_FONT "sans-serif 10"
enum
{
CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (EekThemeContext, eek_theme_context, G_TYPE_OBJECT)
static void
eek_theme_context_finalize (GObject *object)
{
EekThemeContext *context = EEK_THEME_CONTEXT (object);
if (context->root_node)
g_object_unref (context->root_node);
if (context->theme)
g_object_unref (context->theme);
pango_font_description_free (context->font);
G_OBJECT_CLASS (eek_theme_context_parent_class)->finalize (object);
}
static void
eek_theme_context_class_init (EekThemeContextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = eek_theme_context_finalize;
signals[CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, /* no default handler slot */
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
static void
eek_theme_context_init (EekThemeContext *context)
{
context->resolution = DEFAULT_RESOLUTION;
context->font = pango_font_description_from_string (DEFAULT_FONT);
}
/**
* eek_theme_context_new:
*
* Create a new theme context.
*/
EekThemeContext *
eek_theme_context_new (void)
{
EekThemeContext *context;
context = g_object_new (EEK_TYPE_THEME_CONTEXT, NULL);
return context;
}
static void
eek_theme_context_changed (EekThemeContext *context)
{
EekThemeNode *old_root = context->root_node;
context->root_node = NULL;
g_signal_emit (context, signals[CHANGED], 0);
if (old_root)
g_object_unref (old_root);
}
/**
* eek_theme_context_set_theme:
* @context: a #EekThemeContext
*
* Sets the default set of theme stylesheets for the context. This theme will
* be used for the root node and for nodes descending from it, unless some other
* style is explicitely specified.
*/
void
eek_theme_context_set_theme (EekThemeContext *context,
EekTheme *theme)
{
g_return_if_fail (EEK_IS_THEME_CONTEXT (context));
g_return_if_fail (theme == NULL || EEK_IS_THEME (theme));
if (context->theme != theme)
{
if (context->theme)
g_object_unref (context->theme);
context->theme = theme;
if (context->theme)
g_object_ref (context->theme);
eek_theme_context_changed (context);
}
}
/**
* eek_theme_context_get_theme:
* @context: a #EekThemeContext
*
* Gets the default theme for the context. See eek_theme_context_set_theme()
*
* Return value: (transfer none): the default theme for the context
*/
EekTheme *
eek_theme_context_get_theme (EekThemeContext *context)
{
g_return_val_if_fail (EEK_IS_THEME_CONTEXT (context), NULL);
return context->theme;
}
/**
* eek_theme_context_set_resolution:
* @context: a #EekThemeContext
* @resolution: resolution of the context (number of pixels in an "inch")
*
* Sets the resolution of the theme context. This is the scale factor
* used to convert between points and the length units pt, in, and cm.
* This does not necessarily need to correspond to the actual number
* resolution of the device. A value of 72. means that points and
* pixels are identical. The default value is 96.
*/
void
eek_theme_context_set_resolution (EekThemeContext *context,
double resolution)
{
g_return_if_fail (EEK_IS_THEME_CONTEXT (context));
if (resolution == context->resolution)
return;
context->resolution = resolution;
eek_theme_context_changed (context);
}
/**
* eek_theme_context_set_default_resolution:
* @context: a #EekThemeContext
*
* Sets the resolution of the theme context to the default value of 96.
* See eek_theme_context_set_resolution().
*/
void
eek_theme_context_set_default_resolution (EekThemeContext *context)
{
g_return_if_fail (EEK_IS_THEME_CONTEXT (context));
if (context->resolution == DEFAULT_RESOLUTION)
return;
context->resolution = DEFAULT_RESOLUTION;
eek_theme_context_changed (context);
}
/**
* eek_theme_context_get_resolution:
* @context: a #EekThemeContext
*
* Gets the current resolution of the theme context.
* See eek_theme_context_set_resolution().
*
* Return value: the resolution (in dots-per-"inch")
*/
double
eek_theme_context_get_resolution (EekThemeContext *context)
{
g_return_val_if_fail (EEK_IS_THEME_CONTEXT (context), DEFAULT_RESOLUTION);
return context->resolution;
}
/**
* eek_theme_context_set_font:
* @context: a #EekThemeContext
* @font: the default font for theme context
*
* Sets the default font for the theme context. This is the font that
* is inherited by the root node of the tree of theme nodes. If the
* font is not overriden, then this font will be used. If the font is
* partially modified (for example, with 'font-size: 110%', then that
* modification is based on this font.
*/
void
eek_theme_context_set_font (EekThemeContext *context,
const PangoFontDescription *font)
{
g_return_if_fail (EEK_IS_THEME_CONTEXT (context));
g_return_if_fail (font != NULL);
if (context->font == font ||
pango_font_description_equal (context->font, font))
return;
pango_font_description_free (context->font);
context->font = pango_font_description_copy (font);
eek_theme_context_changed (context);
}
/**
* eek_theme_context_get_font:
* @context: a #EekThemeContext
*
* Gets the default font for the theme context. See eek_theme_context_set_font().
*
* Return value: the default font for the theme context.
*/
const PangoFontDescription *
eek_theme_context_get_font (EekThemeContext *context)
{
g_return_val_if_fail (EEK_IS_THEME_CONTEXT (context), NULL);
return context->font;
}
/**
* eek_theme_context_get_root_node:
* @context: a #EekThemeContext
*
* Gets the root node of the tree of theme style nodes that associated with this
* context. For the node tree associated with a stage, this node represents
* styles applied to the stage itself.
*
* Return value: (transfer none): the root node of the context's style tree
*/
EekThemeNode *
eek_theme_context_get_root_node (EekThemeContext *context)
{
if (context->root_node == NULL)
context->root_node = eek_theme_node_new (context, NULL, context->theme,
G_TYPE_NONE, NULL, NULL, NULL, NULL);
return context->root_node;
}

78
eek/eek-theme-context.h Normal file
View File

@ -0,0 +1,78 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
* eek-theme-context.c: holds global information about a tree of styled objects
*
* Copyright 2009, 2010 Red Hat, Inc.
* Copyright 2009 Florian Müllner
*
* This program 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.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EEK_THEME_CONTEXT_H__
#define __EEK_THEME_CONTEXT_H__
#include <pango/pango.h>
#include "eek-theme-node.h"
G_BEGIN_DECLS
/**
* SECTION:EekThemeContext
* @short_description: holds global information about a tree of styled objects
*
* #EekThemeContext is responsible for managing information global to
* a tree of styled objects, such as the set of stylesheets or the
* default font.
*/
typedef struct _EekThemeContextClass EekThemeContextClass;
#define EEK_TYPE_THEME_CONTEXT (eek_theme_context_get_type ())
#define EEK_THEME_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), EEK_TYPE_THEME_CONTEXT, EekThemeContext))
#define EEK_THEME_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEK_TYPE_THEME_CONTEXT, EekThemeContextClass))
#define EEK_IS_THEME_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), EEK_TYPE_THEME_CONTEXT))
#define EEK_IS_THEME_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEK_TYPE_THEME_CONTEXT))
#define EEK_THEME_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEK_TYPE_THEME_CONTEXT, EekThemeContextClass))
GType eek_theme_context_get_type
(void) G_GNUC_CONST;
EekThemeContext *eek_theme_context_new
(void);
void eek_theme_context_set_theme
(EekThemeContext *context,
EekTheme *theme);
EekTheme * eek_theme_context_get_theme
(EekThemeContext *context);
void eek_theme_context_set_resolution
(EekThemeContext *context,
gdouble resolution);
void eek_theme_context_set_default_resolution
(EekThemeContext *context);
double eek_theme_context_get_resolution
(EekThemeContext *context);
void eek_theme_context_set_font
(EekThemeContext *context,
const PangoFontDescription *font);
const PangoFontDescription *eek_theme_context_get_font
(EekThemeContext *context);
EekThemeNode * eek_theme_context_get_root_node
(EekThemeContext *context);
G_END_DECLS
#endif /* __EEK_THEME_CONTEXT_H__ */

1869
eek/eek-theme-node.c Normal file

File diff suppressed because it is too large Load Diff

141
eek/eek-theme-node.h Normal file
View File

@ -0,0 +1,141 @@
/*
* 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_THEME_NODE_H__
#define __EEK_THEME_NODE_H__
#include <pango/pango.h>
#include "eek-types.h"
G_BEGIN_DECLS
/**
* SECTION:EekThemeNode
* @short_description: style information for one node in a tree of
* themed objects
*
* A #EekThemeNode represents the CSS style information (the set of
* CSS properties) for one node in a tree of themed objects. In
* typical usage, it represents the style information for a single
* #EekElement. A #EekThemeNode is immutable: attributes such as the
* CSS classes for the node are passed in at construction. If the
* attributes of the node or any parent node change, the node should
* be discarded and a new node created. #EekThemeNode has generic
* accessors to look up properties by name and specific accessors for
* standard CSS properties that add caching and handling of various
* details of the CSS specification. #EekThemeNode also has
* convenience functions to help in implementing a #EekElement with
* borders and padding.
*/
typedef enum {
EEK_SIDE_TOP,
EEK_SIDE_RIGHT,
EEK_SIDE_BOTTOM,
EEK_SIDE_LEFT
} EekSide;
typedef enum {
EEK_CORNER_TOPLEFT,
EEK_CORNER_TOPRIGHT,
EEK_CORNER_BOTTOMRIGHT,
EEK_CORNER_BOTTOMLEFT
} EekCorner;
#define EEK_TYPE_THEME_NODE (eek_theme_node_get_type())
#define EEK_THEME_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEK_TYPE_THEME_NODE, EekThemeNode))
#define EEK_THEME_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEK_TYPE_THEME_NODE, EekThemeNodeClass))
#define EEK_IS_THEME_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEK_TYPE_THEME_NODE))
#define EEK_IS_THEME_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEK_TYPE_THEME_NODE))
#define EEK_THEME_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEK_TYPE_THEME_NODE, EekThemeNodeClass))
typedef struct _EekThemeNodeClass EekThemeNodeClass;
typedef struct _EekThemeNodePrivate EekThemeNodePrivate;
GType eek_theme_node_get_type
(void) G_GNUC_CONST;
EekThemeNode *eek_theme_node_new (EekThemeContext *context,
EekThemeNode *parent_node,
/* can be null */ EekTheme *theme,
/* can be null */ GType element_type,
const char *element_id,
const char *element_class,
const char *pseudo_class,
const char *inline_style);
EekThemeNode *eek_theme_node_get_parent
(EekThemeNode *node);
EekTheme *eek_theme_node_get_theme
(EekThemeNode *node);
GType eek_theme_node_get_element_type
(EekThemeNode *node);
const char *eek_theme_node_get_element_id
(EekThemeNode *node);
const char *eek_theme_node_get_element_class
(EekThemeNode *node);
const char *eek_theme_node_get_pseudo_class
(EekThemeNode *node);
/* Generic getters ... these are not cached so are less efficient. The other
* reason for adding the more specific version is that we can handle the
* details of the actual CSS rules, which can be complicated, especially
* for fonts
*/
void eek_theme_node_get_color
(EekThemeNode *node,
const char *property_name,
EekColor *color);
/* Specific getters for particular properties: cached
*/
void eek_theme_node_get_background_color
(EekThemeNode *node,
EekColor *color);
void eek_theme_node_get_foreground_color
(EekThemeNode *node,
EekColor *color);
void eek_theme_node_get_background_gradient
(EekThemeNode *node,
EekGradientType *type,
EekColor *start,
EekColor *end);
int eek_theme_node_get_border_width
(EekThemeNode *node,
EekSide side);
int eek_theme_node_get_border_radius
(EekThemeNode *node,
EekCorner corner);
void eek_theme_node_get_border_color
(EekThemeNode *node,
EekSide side,
EekColor *color);
/* Font rule processing is pretty complicated, so we just hardcode it
* under the standard font/font-family/font-size/etc names. This means
* you can't have multiple separate styled fonts for a single item,
* but that should be OK.
*/
const PangoFontDescription *eek_theme_node_get_font (EekThemeNode *node);
G_END_DECLS
#endif /* __EEK_THEME_NODE_H__ */

22
eek/eek-theme-private.h Normal file
View File

@ -0,0 +1,22 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#ifndef __EEK_THEME_PRIVATE_H__
#define __EEK_THEME_PRIVATE_H__
#include <libcroco/libcroco.h>
#include "eek-theme.h"
G_BEGIN_DECLS
GPtrArray *_eek_theme_get_matched_properties (EekTheme *theme,
EekThemeNode *node);
/* Resolve an URL from the stylesheet to a filename */
char *_eek_theme_resolve_url (EekTheme *theme,
CRStyleSheet *base_stylesheet,
const char *url);
CRDeclaration *_eek_theme_parse_declaration_list (const char *str);
G_END_DECLS
#endif /* __EEK_THEME_PRIVATE_H__ */

1133
eek/eek-theme.c Normal file

File diff suppressed because it is too large Load Diff

44
eek/eek-theme.h Normal file
View File

@ -0,0 +1,44 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
#ifndef __EEK_THEME_H__
#define __EEK_THEME_H__
#include <glib-object.h>
#include "eek-types.h"
G_BEGIN_DECLS
/**
* SECTION:EekTheme
* @short_description: a set of stylesheets
*
* #EekTheme holds a set of stylesheets. (The "cascade" of the name
* Cascading Stylesheets.) An #EekTheme can be set to apply to all the
* keyboard elements.
*/
typedef struct _EekThemeClass EekThemeClass;
#define EEK_TYPE_THEME (eek_theme_get_type())
#define EEK_THEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEK_TYPE_THEME, EekTheme))
#define EEK_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEK_TYPE_THEME, EekThemeClass))
#define EEK_IS_THEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEK_TYPE_THEME))
#define EEK_IS_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEK_TYPE_THEME))
#define EEK_THEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEK_TYPE_THEME, EekThemeClass))
GType eek_theme_get_type (void) G_GNUC_CONST;
EekTheme *eek_theme_new (const char *application_stylesheet,
const char *theme_stylesheet,
const char *default_stylesheet);
gboolean eek_theme_load_stylesheet (EekTheme *theme,
const char *path,
GError **error);
void eek_theme_unload_stylesheet (EekTheme *theme,
const char *path);
G_END_DECLS
#endif /* __EEK_THEME_H__ */

View File

@ -32,58 +32,6 @@
#include "eek-types.h"
/* EekSymbolMatrix */
EekSymbolMatrix *
eek_symbol_matrix_new (gint num_groups, gint num_levels)
{
EekSymbolMatrix *matrix = g_slice_new (EekSymbolMatrix);
matrix->num_groups = num_groups;
matrix->num_levels = num_levels;
matrix->data = g_slice_alloc0 (sizeof (EekSymbol *) *
num_groups * num_levels);
return matrix;
}
EekSymbolMatrix *
eek_symbol_matrix_copy (const EekSymbolMatrix *matrix)
{
EekSymbolMatrix *retval;
gint i, num_symbols = matrix->num_groups * matrix->num_levels;
retval = g_slice_dup (EekSymbolMatrix, matrix);
retval->data = g_slice_copy (sizeof (EekSymbol *) * num_symbols,
matrix->data);
for (i = 0; i < num_symbols; i++)
if (retval->data[i])
g_object_ref (retval->data[i]);
return retval;
}
void
eek_symbol_matrix_free (EekSymbolMatrix *matrix)
{
gint i, num_symbols = matrix->num_groups * matrix->num_levels;
for (i = 0; i < num_symbols; i++)
if (matrix->data[i])
g_object_unref (matrix->data[i]);
g_slice_free1 (sizeof (EekSymbol *) * num_symbols, matrix->data);
g_slice_free (EekSymbolMatrix, matrix);
}
GType
eek_symbol_matrix_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type =
g_boxed_type_register_static ("EekSymbolMatrix",
(GBoxedCopyFunc)eek_symbol_matrix_copy,
(GBoxedFreeFunc)eek_symbol_matrix_free);
return our_type;
}
/* EekPoint */
static EekPoint *
eek_point_copy (const EekPoint *point)
@ -153,6 +101,7 @@ EekOutline *
eek_outline_copy (const EekOutline *outline)
{
EekOutline *_outline = g_slice_dup (EekOutline, outline);
_outline->corner_radius = outline->corner_radius;
_outline->num_points = outline->num_points;
_outline->points = g_slice_alloc0 (sizeof (EekPoint) * outline->num_points);
memcpy (_outline->points, outline->points, sizeof (EekPoint) * outline->num_points);
@ -180,13 +129,13 @@ eek_outline_get_type (void)
}
/* EekColor */
static EekColor *
EekColor *
eek_color_copy (const EekColor *color)
{
return g_slice_dup (EekColor, color);
}
static void
void
eek_color_free (EekColor *color)
{
g_slice_free (EekColor, color);

View File

@ -136,6 +136,9 @@ typedef struct _EekSection EekSection;
typedef struct _EekKeyboard EekKeyboard;
typedef struct _EekSymbol EekSymbol;
typedef struct _EekKeysym EekKeysym;
typedef struct _EekTheme EekTheme;
typedef struct _EekThemeContext EekThemeContext;
typedef struct _EekThemeNode EekThemeNode;
typedef struct _EekSymbolMatrix EekSymbolMatrix;
typedef struct _EekPoint EekPoint;
@ -143,28 +146,6 @@ typedef struct _EekBounds EekBounds;
typedef struct _EekOutline EekOutline;
typedef struct _EekColor EekColor;
/**
* EekSymbolMatrix:
* @data: array of symbols
* @num_groups: the number of groups (rows)
* @num_levels: the number of levels (columns)
*
* Symbol matrix of a key.
*/
struct _EekSymbolMatrix
{
gint num_groups;
gint num_levels;
EekSymbol **data;
};
GType eek_symbol_matrix_get_type
(void) G_GNUC_CONST;
EekSymbolMatrix * eek_symbol_matrix_new (gint num_groups,
gint num_levels);
EekSymbolMatrix *eek_symbol_matrix_copy (const EekSymbolMatrix *matrix);
void eek_symbol_matrix_free (EekSymbolMatrix *matrix);
/**
* EekPoint:
* @x: X coordinate of the point
@ -250,6 +231,15 @@ EekColor *eek_color_new (gdouble red,
gdouble green,
gdouble blue,
gdouble alpha);
EekColor *eek_color_copy (const EekColor *color);
void eek_color_free (EekColor *color);
typedef enum {
EEK_GRADIENT_NONE,
EEK_GRADIENT_VERTICAL,
EEK_GRADIENT_HORIZONTAL,
EEK_GRADIENT_RADIAL
} EekGradientType;
G_END_DECLS
#endif /* EEK_TYPES_H */

View File

@ -27,16 +27,16 @@
* elements using XKB.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <gdk/gdkx.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBgeom.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include "eek-xkb-layout.h"
#include "eek-keyboard.h"
#include "eek-section.h"
@ -176,6 +176,7 @@ create_key (EekXkbLayout *layout,
}
}
oref = eek_keyboard_add_outline (keyboard, outline);
eek_outline_free (outline);
g_hash_table_insert (priv->shape_oref_hash, xkbshape, (gpointer)oref);
}
@ -324,9 +325,13 @@ eek_xkb_layout_real_create_keyboard (EekLayout *self,
bounds.height = initial_height;
eek_element_set_bounds (EEK_ELEMENT(keyboard), &bounds);
/* resolve modifiers dynamically assigned at run time */
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);

View File

@ -26,14 +26,14 @@
* to use Libxklavier configuration.
*/
#include <libxklavier/xklavier.h>
#include <gdk/gdkx.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <libxklavier/xklavier.h>
#include <gdk/gdkx.h>
#include <string.h>
#include "eek-xkl-layout.h"
#define noKBDRAW_DEBUG

View File

@ -62,6 +62,7 @@ struct _ParseCallbackData {
EekKey *key;
gint num_columns;
EekOrientation orientation;
gdouble corner_radius;
GSList *points;
GSList *symbols;
gchar *label;
@ -70,6 +71,7 @@ struct _ParseCallbackData {
gint groups, levels;
EekOutline outline;
gchar *oref;
GHashTable *key_oref_hash;
GHashTable *oref_outline_hash;
};
@ -97,7 +99,8 @@ static const gchar *valid_path_list[] = {
"icon/symbols/key/section/keyboard",
"invalid/symbols/key/section/keyboard",
"index/key/section/keyboard",
"point/outline/keyboard"
"point/outline/keyboard",
"corner-radius/outline/keyboard",
};
static gchar *
@ -299,6 +302,9 @@ end_element_callback (GMarkupParseContext *pcontext,
if (g_strcmp0 (element_name, "outline") == 0) {
EekOutline *outline = g_slice_new (EekOutline);
outline->corner_radius = data->corner_radius;
data->corner_radius = 0.0;
outline->num_points = g_slist_length (data->points);
outline->points = g_slice_alloc0 (sizeof (EekPoint) *
outline->num_points);
@ -318,6 +324,11 @@ end_element_callback (GMarkupParseContext *pcontext,
goto out;
}
if (g_strcmp0 (element_name, "corner-radius") == 0) {
data->corner_radius = g_strtod (text, NULL);
goto out;
}
if (g_strcmp0 (element_name, "point") == 0) {
EekPoint *point;

View File

@ -21,14 +21,14 @@
* @short_description: #EekKeyboard to XML conversion utilities
*/
#include <stdio.h>
#include <stdarg.h>
#include <glib/gprintf.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdarg.h>
#include <glib/gprintf.h>
#include "eek-section.h"
#include "eek-key.h"
#include "eek-xml.h"
@ -273,6 +273,9 @@ eek_keyboard_output (EekKeyboard *keyboard, GString *output, gint indent)
outline = eek_keyboard_get_outline (keyboard, oref);
g_string_append_indent (output, indent + 1);
g_string_markup_printf (output, "<outline id=\"outline%u\">\n", oref);
g_string_append_indent (output, indent + 2);
g_string_markup_printf (output, "<corner-radius>%lf</corner-radius>\n",
outline->corner_radius);
for (j = 0; j < outline->num_points; j++) {
g_string_append_indent (output, indent + 2);
g_string_markup_printf (output, "<point>%lf,%lf</point>\n",

View File

@ -28,5 +28,6 @@
#include "eek-keysym.h"
#include "eek-xml.h"
#include "eek-serializable.h"
#include "eek-theme.h"
#endif /* EEK_H */

View File

@ -37,6 +37,7 @@ enum {
DISABLED,
KEY_PRESSED,
KEY_RELEASED,
DESTROYED,
LAST_SIGNAL
};
@ -59,6 +60,7 @@ struct _EekboardContextPrivate
GHashTable *keyboard_hash;
gboolean keyboard_visible;
gboolean enabled;
gboolean fullscreen;
};
static void
@ -146,6 +148,12 @@ eekboard_context_real_key_released (EekboardContext *self,
}
}
static void
eekboard_context_real_destroyed (EekboardContext *self)
{
// g_debug ("eekboard_context_real_destroyed");
}
static void
eekboard_context_get_property (GObject *object,
guint prop_id,
@ -195,6 +203,7 @@ eekboard_context_class_init (EekboardContextClass *klass)
klass->disabled = eekboard_context_real_disabled;
klass->key_pressed = eekboard_context_real_key_pressed;
klass->key_released = eekboard_context_real_key_released;
klass->destroyed = eekboard_context_real_destroyed;
proxy_class->g_signal = eekboard_context_real_g_signal;
@ -288,6 +297,24 @@ eekboard_context_class_init (EekboardContextClass *klass)
G_TYPE_NONE,
1,
G_TYPE_UINT);
/**
* EekboardContext::destroyed:
* @context: an #EekboardContext
*
* 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(EekboardContextClass, destroyed),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
}
static void
@ -306,6 +333,15 @@ eekboard_context_init (EekboardContext *self)
(GDestroyNotify)g_object_unref);
}
static void
context_name_vanished_callback (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
EekboardContext *context = user_data;
g_signal_emit_by_name (context, "destroyed", NULL);
}
/**
* eekboard_context_new:
* @connection: a #GDBusConnection
@ -337,8 +373,27 @@ eekboard_context_new (GDBusConnection *connection,
"g-interface-name", "com.redhat.Eekboard.Context",
"g-object-path", object_path,
NULL);
if (initable != NULL)
return EEKBOARD_CONTEXT (initable);
if (initable != NULL) {
EekboardContext *context = EEKBOARD_CONTEXT (initable);
gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY(context));
if (name_owner == NULL) {
g_object_unref (context);
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,
context_name_vanished_callback,
context,
NULL);
g_free (name_owner);
return context;
}
return NULL;
}
@ -380,6 +435,8 @@ eekboard_context_add_keyboard (EekboardContext *context,
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
variant = eek_serializable_serialize (EEK_SERIALIZABLE(keyboard));
if (g_variant_is_floating (variant))
g_variant_ref_sink (variant);
error = NULL;
result = g_dbus_proxy_call_sync (G_DBUS_PROXY(context),
@ -502,6 +559,7 @@ eekboard_context_set_group (EekboardContext *context,
g_return_if_fail (priv->keyboard);
if (eek_element_get_group (EEK_ELEMENT(priv->keyboard)) != group) {
eek_element_set_group (EEK_ELEMENT(priv->keyboard), group);
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetGroup",
@ -512,6 +570,7 @@ eekboard_context_set_group (EekboardContext *context,
context_async_ready_callback,
NULL);
}
}
/**
* eekboard_context_show_keyboard:
@ -688,3 +747,33 @@ eekboard_context_is_enabled (EekboardContext *context)
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
return priv->enabled;
}
/**
* eekboard_context_set_fullscreen:
* @context: an #EekboardContext
* @fullscreen: a flag to indicate fullscreen mode
* @cancellable: a #GCancellable
*
* Set the fullscreen mode of @context.
*/
void
eekboard_context_set_fullscreen (EekboardContext *context,
gboolean fullscreen,
GCancellable *cancellable)
{
EekboardContextPrivate *priv;
g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
if (priv->fullscreen != fullscreen) {
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetFullscreen",
g_variant_new ("(b)", fullscreen),
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
context_async_ready_callback,
NULL);
}
}

View File

@ -66,10 +66,11 @@ struct _EekboardContextClass {
guint keycode);
void (*key_released) (EekboardContext *self,
guint keycode);
void (*destroyed) (EekboardContext *self);
/*< private >*/
/* padding */
gpointer pdummy[24];
gpointer pdummy[23];
};
GType eekboard_context_get_type (void) G_GNUC_CONST;
@ -80,8 +81,7 @@ EekboardContext *eekboard_context_new (GDBusConnection *connection,
guint eekboard_context_add_keyboard (EekboardContext *context,
EekKeyboard *keyboard,
GCancellable *cancellable);
void eekboard_context_remove_keyboard
(EekboardContext *context,
void eekboard_context_remove_keyboard (EekboardContext *context,
guint keyboard_id,
GCancellable *cancellable);
void eekboard_context_set_keyboard (EekboardContext *context,
@ -105,6 +105,9 @@ gboolean eekboard_context_is_keyboard_visible
void eekboard_context_set_enabled (EekboardContext *context,
gboolean enabled);
gboolean eekboard_context_is_enabled (EekboardContext *context);
void eekboard_context_set_fullscreen (EekboardContext *context,
gboolean fullscreen,
GCancellable *cancellable);
G_END_DECLS
#endif /* EEKBOARD_CONTEXT_H */

View File

@ -29,6 +29,13 @@
#include "eekboard/eekboard-eekboard.h"
enum {
DESTROYED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (EekboardEekboard, eekboard_eekboard, G_TYPE_DBUS_PROXY);
#define EEKBOARD_EEKBOARD_GET_PRIVATE(obj) \
@ -39,6 +46,15 @@ struct _EekboardEekboardPrivate
GHashTable *context_hash;
};
static void
eekboard_eekboard_real_destroyed (EekboardEekboard *self)
{
EekboardEekboardPrivate *priv = EEKBOARD_EEKBOARD_GET_PRIVATE(self);
// g_debug ("eekboard_eekboard_real_destroyed");
g_hash_table_remove_all (priv->context_hash);
}
static void
eekboard_eekboard_dispose (GObject *object)
{
@ -60,7 +76,27 @@ eekboard_eekboard_class_init (EekboardEekboardClass *klass)
g_type_class_add_private (gobject_class,
sizeof (EekboardEekboardPrivate));
klass->destroyed = eekboard_eekboard_real_destroyed;
gobject_class->dispose = eekboard_eekboard_dispose;
/**
* EekboardEekboard::destroyed:
* @eekboard: an #EekboardEekboard
*
* 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(EekboardEekboardClass, destroyed),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
}
static void
@ -76,6 +112,15 @@ eekboard_eekboard_init (EekboardEekboard *self)
(GDestroyNotify)g_object_unref);
}
static void
eekboard_name_vanished_callback (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
EekboardEekboard *eekboard = user_data;
g_signal_emit_by_name (eekboard, "destroyed", NULL);
}
/**
* eekboard_eekboard_new:
* @connection: a #GDBusConnection
@ -102,11 +147,40 @@ eekboard_eekboard_new (GDBusConnection *connection,
"g-interface-name", "com.redhat.Eekboard.Server",
"g-object-path", "/com/redhat/Eekboard/Server",
NULL);
if (initable != NULL)
return EEKBOARD_EEKBOARD (initable);
if (initable != NULL) {
EekboardEekboard *eekboard = EEKBOARD_EEKBOARD (initable);
gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY(eekboard));
if (name_owner == NULL) {
g_object_unref (eekboard);
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,
eekboard,
NULL);
g_free (name_owner);
return eekboard;
}
return NULL;
}
static void
on_context_destroyed (EekboardContext *context,
gpointer user_data)
{
EekboardEekboard *eekboard = user_data;
EekboardEekboardPrivate *priv = EEKBOARD_EEKBOARD_GET_PRIVATE(eekboard);
g_hash_table_remove (priv->context_hash,
g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)));
}
/**
* eekboard_eekboard_create_context:
* @eekboard: an #EekboardEekboard
@ -114,6 +188,8 @@ eekboard_eekboard_new (GDBusConnection *connection,
* @cancellable: a #GCancellable
*
* Create a new input context.
*
* Return value: (transfer full): a newly created #EekboardContext.
*/
EekboardContext *
eekboard_eekboard_create_context (EekboardEekboard *eekboard,
@ -153,6 +229,8 @@ eekboard_eekboard_create_context (EekboardEekboard *eekboard,
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), eekboard);
return context;
}

View File

@ -45,9 +45,12 @@ struct _EekboardEekboardClass {
/*< private >*/
GDBusProxyClass parent_class;
/* signals */
void (* destroyed) (EekboardEekboard *self);
/*< private >*/
/* padding */
gpointer pdummy[24];
gpointer pdummy[23];
};
GType eekboard_eekboard_get_type (void) G_GNUC_CONST;

1
examples/Makefile.am Normal file
View File

@ -0,0 +1 @@
SUBDIRS = eekboard-inscript simple-client

View File

@ -0,0 +1,14 @@
bin_SCRIPTS = eekboard-inscript
keyboarddir = $(pkgdatadir)/keyboards
eekboard_inscript_datadir = $(datarootdir)/eekboard-inscript
eekboard_inscript_data_PYTHON = inscript.py main.py
eekboard-inscript: eekboard-inscript.in
$(AM_V_GEN) sed -e 's!@''PYTHON@!'$(PYTHON)'!' \
-e 's!@EEKBOARD_KEYBOARDDIR@!'$(keyboarddir)'!' \
-e 's!@M17N_DIR@!'$(datadir)/m17n'!' \
-e 's!@EEKBOARD_INSCRIPT_DATADIR@!'$(eekboard_inscript_datadir)'!' < $< > $@
CLEANFILES = eekboard-inscript
EXTRA_DIST = eekboard-inscript.in

View File

@ -0,0 +1,23 @@
#!/bin/sh
# 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
export EEKBOARD_KEYBOARDDIR=@EEKBOARD_KEYBOARDDIR@
export M17N_DIR=@M17N_DIR@
exec @PYTHON@ @EEKBOARD_INSCRIPT_DATADIR@/main.py $@

View File

@ -0,0 +1,226 @@
#!/usr/bin/env python
# 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
import eekboard
import gobject, gtk, virtkey
import sys, os.path, re
KEYCODE_TABLE = {
'1': 10, '2': 11, '3': 12, '4': 13, '5': 14, '6': 15, '7': 16, '8': 17,
'9': 18, '0': 19, '-': 20, '=': 21, 'q': 24, 'w': 25, 'e': 26, 'r': 27,
't': 28, 'y': 29, 'u': 30, 'i': 31, 'o': 32, 'p': 33, '[': 34, ']': 35,
'a': 38, 's': 39, 'd': 40, 'f': 41, 'g': 42, 'h': 43, 'j': 44, 'k': 45,
'l': 46, ';': 47, '\'': 48, '`': 49, '\\': 51, 'z': 52, 'x': 53, 'c': 54,
'v': 55, 'b': 56, 'n': 57, 'm': 58, ',': 59, '.': 60, '/': 61
}
MARK_UPPER = '~!@#$%^&*()_+{}|:"<>?'
MARK_LOWER = '`1234567890-=[]\\;\',./'
INSCRIPT_MAPS = (
"as-inscript",
"bn-inscript",
"gu-inscript",
"hi-inscript",
"kn-inscript",
"ml-inscript",
"mr-inscript",
"or-inscript",
"pa-inscript",
"sd-inscript",
"ta-inscript",
"te-inscript",
"kn-inscript2",
"kok-inscript2-deva",
"mai-inscript2",
"ml-inscript2",
"mni-inscript2-beng",
"mni-inscript2-mtei",
"mr-inscript2",
"ne-inscript2-deva",
"or-inscript2",
"pa-inscript2-guru",
"sa-inscript2",
"sat-inscript2-deva",
"sat-inscript2-olck",
"sd-inscript2-deva",
"ta-inscript2",
"te-inscript2")
class MapFile(object):
MAPENTRY_PATTERN = re.compile(r'\A\s*\((?:\((.*?)\)|"(.*?)")\s*"(.*?)"\)')
def __init__(self, path):
self.__dict = dict()
with open(path, 'r') as fp:
for line in fp:
match = re.match(self.MAPENTRY_PATTERN, line)
if match:
insert = match.group(3).decode('UTF-8')
if match.group(1):
keyseq = re.sub(r'\\(.)', r'\1', match.group(1))
self.__add_symbol_entry(keyseq, insert)
else:
keyseq = re.sub(r'\\(.)', r'\1', match.group(2))
self.__add_text_entry(keyseq, insert)
def get_entry_for_keycode(self, keycode):
return self.__dict.get(keycode)
def __add_entry(self, letter, level, insert):
if letter.isupper():
level |= 1
letter = letter.lower()
elif letter in MARK_UPPER:
level |= 1
letter = MARK_LOWER[MARK_UPPER.index(letter)]
keycode = KEYCODE_TABLE[letter]
if keycode not in self.__dict:
self.__dict[keycode] = list([None,None,None,None])
self.__dict[keycode][level] = insert
def __add_symbol_entry(self, symbol, insert):
level = 0
if symbol.startswith('G-'):
level |= 2
symbol = symbol[2:]
if not symbol.startswith('KP_'):
self.__add_entry(symbol, level, insert)
def __add_text_entry(self, text, insert):
self.__add_entry(text, 0, insert)
class Keyboard(gobject.GObject):
__gtype_name__ = "PYInscriptKeyboard"
__gsignals__ = {
'quit': (
gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
()),
}
def __init__(self, client_name, map_path, kbd_path):
super(Keyboard, self).__init__()
self.__keyboard = self.__create_keyboard(map_path, kbd_path)
self.__eekboard = eekboard.Eekboard()
self.__context = self.__eekboard.create_context(client_name)
keyboard_id = self.__context.add_keyboard(self.__keyboard)
self.__context.set_keyboard(keyboard_id)
self.__keyboard.connect('key-pressed', self.__key_pressed_cb)
self.__keyboard.connect('key-released', self.__key_released_cb)
self.__virtkey = virtkey.virtkey()
self.__english = False
self.__eekboard.connect('destroyed', self.__destroyed_cb)
self.__context.connect('destroyed', self.__destroyed_cb)
self.__context.connect('notify::keyboard-visible', self.__notify_keyboard_visible_cb)
def __create_keyboard(self, map_path, kbd_path):
def __each_key(element, data):
keycode = element.get_keycode()
# keycode 37 is used to toggle English/Inscript
if keycode == 37:
matrix = eekboard.SymbolMatrix.new(2, 1)
keysym = eekboard.Keysym.new(0)
keysym.set_label("Ind")
keysym.set_category(eekboard.SymbolCategory.FUNCTION)
matrix.set_symbol(0, 0, keysym)
keysym = eekboard.Keysym.new(0)
keysym.set_label("Eng")
keysym.set_category(eekboard.SymbolCategory.FUNCTION)
matrix.set_symbol(1, 0, keysym)
element.set_symbol_matrix(matrix)
return
# group(0) is us keyboard
matrix = eekboard.SymbolMatrix.new(2, 4)
for l in xrange(4):
keysym = element.get_symbol_at_index(0, l, 0, 0)
matrix.set_symbol(0, l, keysym)
# group(1) is inscript keyboard
entry = data.get_entry_for_keycode(keycode)
for l in xrange(4):
if entry and entry[l]:
try:
keyval = gtk.gdk.unicode_to_keyval(ord(entry[l]))
keysym = eekboard.Keysym.new(keyval)
except:
keysym = eekboard.Keysym.new(0)
keysym.set_label(entry[l].encode('UTF-8'))
keysym.set_category(eekboard.SymbolCategory.LETTER)
print >> sys.stderr, "can't convert %s (%d) to keyval" % (entry[l], keycode)
else:
keysym = element.get_symbol_at_index(1, l, 0, 0)
matrix.set_symbol(1, l, keysym)
element.set_symbol_matrix(matrix)
def __each_section(element, data):
element.foreach_child(__each_key, data)
mapfile = MapFile(map_path)
keyboard = eekboard.XmlKeyboard(kbd_path,
eekboard.MODIFIER_BEHAVIOR_LATCH)
keyboard.foreach_child(__each_section, mapfile)
return keyboard
def __destroyed_cb(self, *args):
self.emit('quit')
def __notify_keyboard_visible_cb(self, obj, pspec):
if not obj.get_property(pspec.name):
self.emit('quit')
def enable(self):
self.__eekboard.push_context(self.__context)
def disable(self):
self.__eekboard.pop_context(self.__context)
def show(self):
self.__context.show_keyboard()
def set_group(self, group):
self.__group = group
self.__context.set_group(self.__group)
def __key_pressed_cb(self, keyboard, key):
if key.get_keycode() == 37:
return
symbol = key.get_symbol()
if isinstance(symbol, eekboard.Keysym):
xkeysym = symbol.get_xkeysym()
modifiers = self.__keyboard.get_modifiers()
self.__virtkey.latch_mod(modifiers)
self.__virtkey.press_keysym(xkeysym)
self.__virtkey.unlatch_mod(modifiers)
def __key_released_cb(self, keyboard, key):
if key.get_keycode() == 37:
if self.__english:
self.__context.set_group(self.__group)
self.__english = False
else:
self.__context.set_group(0)
self.__english = True
return
symbol = key.get_symbol()
if isinstance(symbol, eekboard.Keysym):
xkeysym = symbol.get_xkeysym()
self.__virtkey.release_keysym(xkeysym)

View File

@ -0,0 +1,60 @@
# 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
import inscript
import gtk
from optparse import OptionParser
import sys, os, os.path, glob
parser = OptionParser()
parser.add_option("-n", "--name=LANGCODE", dest="langcode",
help="Specify language code to LANGCODE",
metavar="LANGCODE")
parser.add_option("-l", "--list", dest="list", default=False,
action="store_true",
help="List available language codes")
(options, args) = parser.parse_args()
if options.list:
pat = os.path.join(os.getenv("M17N_DIR"), "*.mim")
for fname in sorted(glob.glob(pat)):
mname = os.path.basename(fname[:-4])
if mname in inscript.INSCRIPT_MAPS:
print mname
exit(0)
if options.langcode is None:
print >> sys.stderr, "Specify language code with -n"
exit(1)
map_path = os.path.join(os.getenv("M17N_DIR"), options.langcode + ".mim")
if not os.path.exists(map_path):
print >> sys.stderr, "%s not found" % map_path
exit(1)
kbd_path = os.path.join(os.getenv("EEKBOARD_KEYBOARDDIR"), "us-qwerty.xml")
if not os.path.exists(kbd_path):
print >> sys.stderr, "%s not found" % kbd_path
exit(1)
keyboard = inscript.Keyboard("eekboard-inscript", map_path, kbd_path)
keyboard.connect('quit', lambda *args: gtk.main_quit())
keyboard.set_group(1)
keyboard.enable()
keyboard.show()
gtk.main()

View File

@ -0,0 +1,12 @@
noinst_PROGRAMS = simple-client
simple_client_CFLAGS = \
-I$(top_srcdir) \
$(GIO2_CFLAGS)
simple_client_LDADD = \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(GIO2_LIBS)
simple_client_SOURCES = main.c

View File

@ -0,0 +1,217 @@
/*
* 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/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <glib/gi18n.h>
#include "eekboard/eekboard.h"
static gboolean opt_system = FALSE;
static gboolean opt_session = FALSE;
static gchar *opt_address = NULL;
static gchar *opt_set_keyboard = NULL;
static gint opt_set_group = -1;
static gboolean opt_show_keyboard = FALSE;
static gboolean opt_hide_keyboard = FALSE;
static gint opt_press_key = -1;
static gint opt_release_key = -1;
static gboolean opt_listen = FALSE;
static const GOptionEntry options[] = {
{"system", 'y', 0, G_OPTION_ARG_NONE, &opt_system,
N_("Connect to the system bus")},
{"session", 'e', 0, G_OPTION_ARG_NONE, &opt_session,
N_("Connect to the session bus")},
{"address", 'a', 0, G_OPTION_ARG_STRING, &opt_address,
N_("Connect to the given D-Bus address")},
{"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_keyboard,
N_("Upload keyboard description from an XML file")},
{"set-group", '\0', 0, G_OPTION_ARG_INT, &opt_set_group,
N_("Set group of the keyboard")},
{"show-keyboard", '\0', 0, G_OPTION_ARG_NONE, &opt_show_keyboard,
N_("Show keyboard")},
{"hide-keyboard", '\0', 0, G_OPTION_ARG_NONE, &opt_hide_keyboard,
N_("Hide keyboard")},
{"press-key", '\0', 0, G_OPTION_ARG_INT, &opt_press_key,
N_("Press key")},
{"release-key", '\0', 0, G_OPTION_ARG_INT, &opt_release_key,
N_("Release key")},
{"listen", '\0', 0, G_OPTION_ARG_NONE, &opt_listen,
N_("Listen events")},
{NULL}
};
static void
on_key_pressed (guint keycode, gpointer user_data)
{
g_print ("KeyPressed %u\n", keycode);
}
static void
on_key_released (guint keycode, gpointer user_data)
{
g_print ("KeyReleased %u\n", keycode);
}
int
main (int argc, char **argv)
{
EekboardEekboard *eekboard = NULL;
EekboardContext *context = NULL;
GBusType bus_type;
GDBusConnection *connection = NULL;
GError *error;
GOptionContext *option_context;
GMainLoop *loop = NULL;
gint retval = 0;
g_type_init ();
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
option_context = g_option_context_new ("eekboard-client");
g_option_context_add_main_entries (option_context, options, NULL);
g_option_context_parse (option_context, &argc, &argv, NULL);
g_option_context_free (option_context);
if (opt_system)
bus_type = G_BUS_TYPE_SYSTEM;
else if (opt_address)
bus_type = G_BUS_TYPE_NONE;
else
bus_type = G_BUS_TYPE_SESSION;
switch (bus_type) {
case G_BUS_TYPE_SYSTEM:
case G_BUS_TYPE_SESSION:
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (connection == NULL) {
g_printerr ("Can't connect to the bus: %s\n", error->message);
exit (1);
}
break;
case G_BUS_TYPE_NONE:
error = NULL;
connection = g_dbus_connection_new_for_address_sync (opt_address,
0,
NULL,
NULL,
&error);
if (connection == NULL) {
g_printerr ("Can't connect to the bus at %s: %s\n",
opt_address,
error->message);
exit (1);
}
break;
default:
g_assert_not_reached ();
break;
}
eekboard = eekboard_eekboard_new (connection, NULL);
if (eekboard == NULL) {
g_printerr ("Can't create eekboard proxy\n");
retval = 1;
goto out;
}
context = eekboard_eekboard_create_context (eekboard,
"eekboard-client",
NULL);
if (context == NULL) {
g_printerr ("Can't create context\n");
retval = 1;
goto out;
}
eekboard_eekboard_push_context (eekboard, context, NULL);
if (opt_set_keyboard) {
GFile *file;
GFileInputStream *input;
EekLayout *layout;
EekKeyboard *keyboard;
guint keyboard_id;
file = g_file_new_for_path (opt_set_keyboard);
error = NULL;
input = g_file_read (file, NULL, &error);
if (error) {
g_printerr ("Can't read file %s: %s\n",
opt_set_keyboard, error->message);
retval = 1;
goto out;
}
layout = eek_xml_layout_new (G_INPUT_STREAM(input));
g_object_unref (input);
keyboard = eek_keyboard_new (layout, 640, 480);
g_object_unref (layout);
keyboard_id = eekboard_context_add_keyboard (context, keyboard, NULL);
g_object_unref (keyboard);
eekboard_context_set_keyboard (context, keyboard_id, NULL);
}
if (opt_set_group >= 0) {
eekboard_context_set_group (context, opt_set_group, NULL);
}
if (opt_show_keyboard) {
eekboard_context_show_keyboard (context, NULL);
}
if (opt_hide_keyboard) {
eekboard_context_hide_keyboard (context, NULL);
}
if (opt_press_key >= 0) {
eekboard_context_press_key (context, opt_press_key, NULL);
}
if (opt_release_key >= 0) {
eekboard_context_release_key (context, opt_release_key, NULL);
}
if (opt_listen) {
g_signal_connect (context, "key-pressed",
G_CALLBACK(on_key_pressed), NULL);
g_signal_connect (context, "key-released",
G_CALLBACK(on_key_released), NULL);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
}
out:
if (context)
g_object_unref (context);
if (connection)
g_object_unref (connection);
if (loop)
g_main_loop_unref (loop);
return retval;
}

View File

@ -1,7 +1,7 @@
src/server-server.c
src/server-context.c
src/client-main.c
src/desktop-client.c
src/desktop-client-main.c
src/xml-main.c
src/server-main.c
src/client.c
src/client-main.c
src/xml-main.c
examples/simple-client/main.c

View File

@ -3,4 +3,5 @@ eek/eek-container.c
eek/eek-key.c
eek/eek-keyboard.c
eek/eek-section.c
eekboard/eekboard-eekboard.c
eekboard/eekboard-context.c

View File

@ -18,14 +18,13 @@
if ENABLE_EEKBOARD
bin_PROGRAMS = \
eekboard-desktop-client \
eekboard-client \
eekboard \
eekboard-server \
eekboard-xml
noinst_LTLIBRARIES = libxklutil.la
eekboard_desktop_client_CFLAGS = \
eekboard_CFLAGS = \
-I$(top_srcdir) \
$(GIO2_CFLAGS) \
$(GTK_CFLAGS) \
@ -33,7 +32,7 @@ eekboard_desktop_client_CFLAGS = \
$(XKB_CFLAGS) \
$(LIBXKLAVIER_CFLAGS)
eekboard_desktop_client_LDADD = \
eekboard_LDADD = \
$(builddir)/libxklutil.la \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
@ -45,26 +44,27 @@ eekboard_desktop_client_LDADD = \
$(LIBXKLAVIER_LIBS)
if ENABLE_FAKEKEY
eekboard_desktop_client_CFLAGS += \
eekboard_CFLAGS += \
$(FAKEKEY_CFLAGS)
eekboard_desktop_client_LDADD += \
eekboard_LDADD += \
$(FAKEKEY_LIBS)
endif
if ENABLE_CSPI
eekboard_desktop_client_CFLAGS += \
eekboard_CFLAGS += \
$(CSPI_CFLAGS)
eekboard_desktop_client_LDADD += \
eekboard_LDADD += \
$(CSPI_LIBS)
endif
eekboard_desktop_client_headers = desktop-client.h
eekboard_desktop_client_SOURCES = desktop-client.c desktop-client-main.c
eekboard_headers = client.h
eekboard_SOURCES = client.c client-main.c
eekboard_server_CFLAGS = \
-I$(top_srcdir) \
$(GIO2_CFLAGS) \
$(GTK_CFLAGS)
$(GTK_CFLAGS) \
-DTHEMEDIR=\"$(pkgdatadir)/themes\"
eekboard_server_LDADD = \
$(top_builddir)/eekboard/libeekboard.la \
@ -73,24 +73,13 @@ eekboard_server_LDADD = \
$(GIO2_LIBS) \
$(GTK_LIBS)
eekboard_server_headers = server-server.h server-context.h
eekboard_server_SOURCES = server-server.c server-context.c server-main.c
if ENABLE_CLUTTER
eekboard_server_CFLAGS += $(CLUTTER_CFLAGS) $(CLUTTER_GTK_CFLAGS)
eekboard_server_LDADD += $(CLUTTER_LIBS) $(top_builddir)/eek/libeek-clutter.la $(CLUTTER_GTK_LIBS)
endif
eekboard_client_CFLAGS = \
-I$(top_srcdir) \
$(GIO2_CFLAGS)
eekboard_client_LDADD = \
$(top_builddir)/eekboard/libeekboard.la \
$(top_builddir)/eek/libeek.la \
$(GIO2_LIBS)
eekboard_client_SOURCES = client-main.c
eekboard_server_headers = server-server.h server-context.h
eekboard_server_SOURCES = server-server.c server-context.c server-main.c
eekboard_xml_CFLAGS = \
-I$(top_srcdir) \
@ -107,6 +96,11 @@ eekboard_xml_LDADD = \
$(GTK_LIBS) \
$(LIBXKLAVIER_LIBS)
if ENABLE_CLUTTER
eekboard_xml_CFLAGS += $(CLUTTER_CFLAGS) $(CLUTTER_GTK_CFLAGS)
eekboard_xml_LDADD += $(CLUTTER_LIBS) $(top_builddir)/eek/libeek-clutter.la $(CLUTTER_GTK_LIBS)
endif
eekboard_xml_SOURCES = xml-main.c
libxklutil_la_headers = xklutil.h
@ -119,8 +113,7 @@ eekboard_HEADERS = \
$(libeekboard_headers)
noinst_HEADERS = \
$(eekboard_desktop_client_headers) \
$(eekboard_client_headers) \
$(eekboard_headers) \
$(eekboard_server_headers) \
$(eekboard_xml_headers) \
$(libxklutil_la_headers)

View File

@ -20,21 +20,29 @@
#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <cspi/spi.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <gconf/gconf-client.h>
#include "eekboard/eekboard.h"
#include "client.h"
static gboolean opt_system = FALSE;
static gboolean opt_session = FALSE;
static gchar *opt_address = NULL;
static gchar *opt_set_keyboard = NULL;
static gint opt_set_group = -1;
static gboolean opt_show_keyboard = FALSE;
static gboolean opt_hide_keyboard = FALSE;
static gint opt_press_key = -1;
static gint opt_release_key = -1;
static gboolean opt_listen = FALSE;
#ifdef HAVE_CSPI
static gboolean opt_focus = FALSE;
static gboolean opt_keystroke = FALSE;
#endif /* HAVE_CSPI */
static gchar *opt_keyboard = NULL;
static gchar *opt_model = NULL;
static gchar *opt_layouts = NULL;
static gchar *opt_options = NULL;
static gboolean opt_fullscreen = FALSE;
static const GOptionEntry options[] = {
{"system", 'y', 0, G_OPTION_ARG_NONE, &opt_system,
@ -43,51 +51,77 @@ static const GOptionEntry options[] = {
N_("Connect to the session bus")},
{"address", 'a', 0, G_OPTION_ARG_STRING, &opt_address,
N_("Connect to the given D-Bus address")},
{"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_keyboard,
N_("Upload keyboard description from an XML file")},
{"set-group", '\0', 0, G_OPTION_ARG_INT, &opt_set_group,
N_("Set group of the keyboard")},
{"show-keyboard", '\0', 0, G_OPTION_ARG_NONE, &opt_show_keyboard,
N_("Show keyboard")},
{"hide-keyboard", '\0', 0, G_OPTION_ARG_NONE, &opt_hide_keyboard,
N_("Hide keyboard")},
{"press-key", '\0', 0, G_OPTION_ARG_INT, &opt_press_key,
N_("Press key")},
{"release-key", '\0', 0, G_OPTION_ARG_INT, &opt_release_key,
N_("Release key")},
{"listen", '\0', 0, G_OPTION_ARG_NONE, &opt_listen,
N_("Listen events")},
#ifdef HAVE_CSPI
{"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus,
N_("Listen focus change events with AT-SPI")},
{"listen-keystroke", 's', 0, G_OPTION_ARG_NONE, &opt_keystroke,
N_("Listen keystroke events with AT-SPI")},
#endif /* HAVE_CSPI */
{"keyboard", 'k', 0, G_OPTION_ARG_STRING, &opt_keyboard,
N_("Specify keyboard file")},
{"model", '\0', 0, G_OPTION_ARG_STRING, &opt_model,
N_("Specify model")},
{"layouts", '\0', 0, G_OPTION_ARG_STRING, &opt_layouts,
N_("Specify layouts")},
{"options", '\0', 0, G_OPTION_ARG_STRING, &opt_options,
N_("Specify options")},
{"fullscreen", 'F', 0, G_OPTION_ARG_NONE, &opt_fullscreen,
N_("Create window in fullscreen mode")},
{NULL}
};
static void
on_key_pressed (guint keycode, gpointer user_data)
on_notify_keyboard_visible (GObject *object,
GParamSpec *spec,
gpointer user_data)
{
g_print ("KeyPressed %u\n", keycode);
GMainLoop *loop = user_data;
gboolean visible;
g_object_get (object, "keyboard-visible", &visible, NULL);
/* user explicitly closed the window */
if (!visible && eekboard_context_is_enabled (EEKBOARD_CONTEXT(object)))
g_main_loop_quit (loop);
}
static void
on_key_released (guint keycode, gpointer user_data)
on_context_destroyed (EekboardContext *context,
gpointer user_data)
{
g_print ("KeyReleased %u\n", keycode);
GMainLoop *loop = user_data;
g_main_loop_quit (loop);
}
static void
on_destroyed (EekboardEekboard *eekboard,
gpointer user_data)
{
GMainLoop *loop = user_data;
g_main_loop_quit (loop);
}
int
main (int argc, char **argv)
{
EekboardEekboard *eekboard = NULL;
EekboardContext *context = NULL;
EekboardClient *client;
EekboardEekboard *eekboard;
EekboardContext *context;
GBusType bus_type;
GDBusConnection *connection = NULL;
GDBusConnection *connection;
GError *error;
GConfClient *gconfc;
GOptionContext *option_context;
GMainLoop *loop = NULL;
gint retval = 0;
GMainLoop *loop;
g_type_init ();
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
if (!gtk_init_check (&argc, &argv)) {
g_printerr ("Can't init GTK\n");
exit (1);
}
option_context = g_option_context_new ("eekboard-client");
option_context = g_option_context_new ("eekboard-desktop-client");
g_option_context_add_main_entries (option_context, options, NULL);
g_option_context_parse (option_context, &argc, &argv, NULL);
g_option_context_free (option_context);
@ -128,90 +162,98 @@ main (int argc, char **argv)
break;
}
eekboard = eekboard_eekboard_new (connection, NULL);
if (eekboard == NULL) {
g_printerr ("Can't create eekboard proxy\n");
retval = 1;
goto out;
client = eekboard_client_new (connection);
if (client == NULL) {
g_printerr ("Can't create a client\n");
exit (1);
}
context = eekboard_eekboard_create_context (eekboard,
"eekboard-client",
NULL);
if (context == NULL) {
g_printerr ("Can't create context\n");
retval = 1;
goto out;
}
eekboard_eekboard_push_context (eekboard, context, NULL);
if (opt_set_keyboard) {
GFile *file;
GFileInputStream *input;
EekLayout *layout;
EekKeyboard *keyboard;
guint keyboard_id;
file = g_file_new_for_path (opt_set_keyboard);
gconfc = gconf_client_get_default ();
#ifdef HAVE_CSPI
error = NULL;
input = g_file_read (file, NULL, &error);
if (error) {
g_printerr ("Can't read file %s: %s\n",
opt_set_keyboard, error->message);
retval = 1;
goto out;
if (opt_focus || opt_keystroke) {
if (gconf_client_get_bool (gconfc,
"/desktop/gnome/interface/accessibility",
&error) ||
gconf_client_get_bool (gconfc,
"/desktop/gnome/interface/accessibility2",
&error)) {
if (SPI_init () != 0) {
g_printerr ("Can't init CSPI\n");
exit (1);
}
layout = eek_xml_layout_new (G_INPUT_STREAM(input));
g_object_unref (input);
keyboard = eek_keyboard_new (layout, 640, 480);
g_object_unref (layout);
keyboard_id = eekboard_context_add_keyboard (context, keyboard, NULL);
g_object_unref (keyboard);
eekboard_context_set_keyboard (context, keyboard_id, NULL);
if (opt_focus &&
!eekboard_client_enable_cspi_focus (client)) {
g_printerr ("Can't register focus change event listeners\n");
exit (1);
}
if (opt_set_group >= 0) {
eekboard_context_set_group (context, opt_set_group, NULL);
if (opt_keystroke &&
!eekboard_client_enable_cspi_keystroke (client)) {
g_printerr ("Can't register keystroke event listeners\n");
exit (1);
}
} else {
g_printerr ("Desktop accessibility support is disabled\n");
exit (1);
}
}
#endif /* HAVE_CSPI */
if (opt_keyboard && (opt_model || opt_layouts || opt_options)) {
g_printerr ("Can't use --keyboard option with xklavier options\n");
exit (1);
}
if (opt_show_keyboard) {
eekboard_context_show_keyboard (context, NULL);
if (opt_keyboard) {
if (!eekboard_client_load_keyboard_from_file (client, opt_keyboard)) {
g_printerr ("Can't load keyboard\n");
exit (1);
}
} else if (opt_model || opt_layouts || opt_options) {
if (!eekboard_client_set_xkl_config (client,
opt_model,
opt_layouts,
opt_options)) {
g_printerr ("Can't set xklavier config\n");
exit (1);
}
} else if (!eekboard_client_enable_xkl (client)) {
g_printerr ("Can't register xklavier event listeners\n");
exit (1);
}
if (opt_hide_keyboard) {
eekboard_context_hide_keyboard (context, NULL);
#ifdef HAVE_FAKEKEY
if (!eekboard_client_enable_fakekey (client)) {
g_printerr ("Can't init fakekey\n");
exit (1);
}
#endif /* HAVE_FAKEKEY */
if (opt_press_key >= 0) {
eekboard_context_press_key (context, opt_press_key, NULL);
}
if (opt_release_key >= 0) {
eekboard_context_release_key (context, opt_release_key, NULL);
}
if (opt_listen) {
g_signal_connect (context, "key-pressed",
G_CALLBACK(on_key_pressed), NULL);
g_signal_connect (context, "key-released",
G_CALLBACK(on_key_released), NULL);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
if (!opt_focus) {
g_object_get (client, "context", &context, NULL);
g_signal_connect (context, "notify::keyboard-visible",
G_CALLBACK(on_notify_keyboard_visible), loop);
g_signal_connect (context, "destroyed",
G_CALLBACK(on_context_destroyed), loop);
g_object_unref (context);
}
out:
if (context)
if (opt_fullscreen) {
g_object_get (client, "context", &context, NULL);
eekboard_context_set_fullscreen (context, TRUE, NULL);
g_object_unref (context);
if (connection)
g_object_unref (connection);
if (loop)
}
g_object_get (client, "eekboard", &eekboard, NULL);
g_signal_connect (eekboard, "destroyed",
G_CALLBACK(on_destroyed), loop);
g_main_loop_run (loop);
g_main_loop_unref (loop);
return retval;
return 0;
}

View File

@ -34,7 +34,7 @@
#include "eek/eek.h"
#include "eek/eek-xkl.h"
#include "eekboard/eekboard.h"
#include "desktop-client.h"
#include "client.h"
#include "xklutil.h"
#define CSW 640
@ -43,13 +43,14 @@
enum {
PROP_0,
PROP_CONNECTION,
PROP_EEKBOARD,
PROP_CONTEXT,
PROP_LAST
};
typedef struct _EekboardDesktopClientClass EekboardDesktopClientClass;
typedef struct _EekboardClientClass EekboardClientClass;
struct _EekboardDesktopClient {
struct _EekboardClient {
GObject parent;
EekboardEekboard *eekboard;
@ -67,6 +68,7 @@ struct _EekboardDesktopClient {
gulong key_released_handler;
#ifdef HAVE_CSPI
Accessible *acc;
AccessibleEventListener *focus_listener;
AccessibleEventListener *keystroke_listener;
#endif /* HAVE_CSPI */
@ -76,11 +78,11 @@ struct _EekboardDesktopClient {
#endif /* HAVE_FAKEKEY */
};
struct _EekboardDesktopClientClass {
struct _EekboardClientClass {
GObjectClass parent_class;
};
G_DEFINE_TYPE (EekboardDesktopClient, eekboard_desktop_client, G_TYPE_OBJECT);
G_DEFINE_TYPE (EekboardClient, eekboard_client, G_TYPE_OBJECT);
static GdkFilterReturn filter_xkl_event (GdkXEvent *xev,
GdkEvent *event,
@ -104,19 +106,22 @@ static SPIBoolean keystroke_listener_cb
(const AccessibleKeystroke *stroke,
void *user_data);
#endif /* HAVE_CSPI */
static gboolean set_keyboard (EekboardDesktopClient *client,
static gboolean set_keyboard (EekboardClient *client,
gboolean show,
EekLayout *layout);
static gboolean set_xkl_keyboard (EekboardClient *client,
gboolean show,
const gchar *model,
const gchar *layouts,
const gchar *options);
static void
eekboard_desktop_client_set_property (GObject *object,
eekboard_client_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EekboardDesktopClient *client = EEKBOARD_DESKTOP_CLIENT(object);
EekboardClient *client = EEKBOARD_CLIENT(object);
GDBusConnection *connection;
switch (prop_id) {
@ -124,15 +129,19 @@ eekboard_desktop_client_set_property (GObject *object,
connection = g_value_get_object (value);
client->eekboard = eekboard_eekboard_new (connection, NULL);
g_assert (client->eekboard);
if (client->eekboard != NULL) {
client->context =
eekboard_eekboard_create_context (client->eekboard,
"eekboard-desktop-client",
"eekboard",
NULL);
g_assert (client->context);
eekboard_eekboard_push_context (client->eekboard, client->context, NULL);
if (client->context == NULL) {
g_object_unref (client->eekboard);
client->eekboard = NULL;
} else
eekboard_eekboard_push_context (client->eekboard,
client->context,
NULL);
}
break;
default:
g_object_set_property (object,
@ -143,14 +152,17 @@ eekboard_desktop_client_set_property (GObject *object,
}
static void
eekboard_desktop_client_get_property (GObject *object,
eekboard_client_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EekboardDesktopClient *client = EEKBOARD_DESKTOP_CLIENT(object);
EekboardClient *client = EEKBOARD_CLIENT(object);
switch (prop_id) {
case PROP_EEKBOARD:
g_value_set_object (value, client->eekboard);
break;
case PROP_CONTEXT:
g_value_set_object (value, client->context);
break;
@ -163,19 +175,19 @@ eekboard_desktop_client_get_property (GObject *object,
}
static void
eekboard_desktop_client_dispose (GObject *object)
eekboard_client_dispose (GObject *object)
{
EekboardDesktopClient *client = EEKBOARD_DESKTOP_CLIENT(object);
EekboardClient *client = EEKBOARD_CLIENT(object);
eekboard_desktop_client_disable_xkl (client);
eekboard_client_disable_xkl (client);
#ifdef HAVE_CSPI
eekboard_desktop_client_disable_cspi_focus (client);
eekboard_desktop_client_disable_cspi_keystroke (client);
eekboard_client_disable_cspi_focus (client);
eekboard_client_disable_cspi_keystroke (client);
#endif /* HAVE_CSPI */
#ifdef HAVE_FAKEKEY
eekboard_desktop_client_disable_fakekey (client);
eekboard_client_disable_fakekey (client);
#endif /* HAVE_FAKEKEY */
if (client->context) {
@ -208,18 +220,18 @@ eekboard_desktop_client_dispose (GObject *object)
client->display = NULL;
}
G_OBJECT_CLASS (eekboard_desktop_client_parent_class)->dispose (object);
G_OBJECT_CLASS (eekboard_client_parent_class)->dispose (object);
}
static void
eekboard_desktop_client_class_init (EekboardDesktopClientClass *klass)
eekboard_client_class_init (EekboardClientClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
gobject_class->set_property = eekboard_desktop_client_set_property;
gobject_class->get_property = eekboard_desktop_client_get_property;
gobject_class->dispose = eekboard_desktop_client_dispose;
gobject_class->set_property = eekboard_client_set_property;
gobject_class->get_property = eekboard_client_get_property;
gobject_class->dispose = eekboard_client_dispose;
pspec = g_param_spec_object ("connection",
"Connection",
@ -230,6 +242,15 @@ eekboard_desktop_client_class_init (EekboardDesktopClientClass *klass)
PROP_CONNECTION,
pspec);
pspec = g_param_spec_object ("eekboard",
"Eekboard",
"Eekboard",
EEKBOARD_TYPE_EEKBOARD,
G_PARAM_READABLE);
g_object_class_install_property (gobject_class,
PROP_EEKBOARD,
pspec);
pspec = g_param_spec_object ("context",
"Context",
"Context",
@ -241,7 +262,7 @@ eekboard_desktop_client_class_init (EekboardDesktopClientClass *klass)
}
static void
eekboard_desktop_client_init (EekboardDesktopClient *client)
eekboard_client_init (EekboardClient *client)
{
client->eekboard = NULL;
client->context = NULL;
@ -263,19 +284,19 @@ eekboard_desktop_client_init (EekboardDesktopClient *client)
}
gboolean
eekboard_desktop_client_set_xkl_config (EekboardDesktopClient *client,
eekboard_client_set_xkl_config (EekboardClient *client,
const gchar *model,
const gchar *layouts,
const gchar *options)
{
#ifdef HAVE_CSPI
return set_keyboard (client,
return set_xkl_keyboard (client,
client->focus_listener ? FALSE : TRUE,
model,
layouts,
options);
#else
return set_keyboard (client,
return set_xkl_keyboard (client,
TRUE,
model,
layouts,
@ -284,7 +305,7 @@ eekboard_desktop_client_set_xkl_config (EekboardDesktopClient *client,
}
gboolean
eekboard_desktop_client_enable_xkl (EekboardDesktopClient *client)
eekboard_client_enable_xkl (EekboardClient *client)
{
if (!client->display) {
client->display = gdk_display_get_default ();
@ -320,15 +341,18 @@ eekboard_desktop_client_enable_xkl (EekboardDesktopClient *client)
xkl_engine_start_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
#ifdef HAVE_CSPI
return set_keyboard (client, client->focus_listener ? FALSE : TRUE,
NULL, NULL, NULL);
return set_xkl_keyboard (client,
client->focus_listener ? FALSE : TRUE,
NULL,
NULL,
NULL);
#else
return set_keyboard (client, TRUE, NULL, NULL, NULL);
return set_xkl_keyboard (client, TRUE, NULL, NULL, NULL);
#endif
}
void
eekboard_desktop_client_disable_xkl (EekboardDesktopClient *client)
eekboard_client_disable_xkl (EekboardClient *client)
{
if (client->xkl_engine)
xkl_engine_stop_listen (client->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
@ -344,7 +368,7 @@ eekboard_desktop_client_disable_xkl (EekboardDesktopClient *client)
#ifdef HAVE_CSPI
gboolean
eekboard_desktop_client_enable_cspi_focus (EekboardDesktopClient *client)
eekboard_client_enable_cspi_focus (EekboardClient *client)
{
client->focus_listener = SPI_createAccessibleEventListener
((AccessibleEventListenerCB)focus_listener_cb,
@ -362,7 +386,7 @@ eekboard_desktop_client_enable_cspi_focus (EekboardDesktopClient *client)
}
void
eekboard_desktop_client_disable_cspi_focus (EekboardDesktopClient *client)
eekboard_client_disable_cspi_focus (EekboardClient *client)
{
if (client->focus_listener) {
SPI_deregisterGlobalEventListenerAll (client->focus_listener);
@ -372,7 +396,7 @@ eekboard_desktop_client_disable_cspi_focus (EekboardDesktopClient *client)
}
gboolean
eekboard_desktop_client_enable_cspi_keystroke (EekboardDesktopClient *client)
eekboard_client_enable_cspi_keystroke (EekboardClient *client)
{
client->keystroke_listener =
SPI_createAccessibleKeystrokeListener (keystroke_listener_cb,
@ -390,7 +414,7 @@ eekboard_desktop_client_enable_cspi_keystroke (EekboardDesktopClient *client)
}
void
eekboard_desktop_client_disable_cspi_keystroke (EekboardDesktopClient *client)
eekboard_client_disable_cspi_keystroke (EekboardClient *client)
{
if (client->keystroke_listener) {
SPI_deregisterAccessibleKeystrokeListener (client->keystroke_listener,
@ -404,7 +428,7 @@ static SPIBoolean
focus_listener_cb (const AccessibleEvent *event,
void *user_data)
{
EekboardDesktopClient *client = user_data;
EekboardClient *client = user_data;
Accessible *accessible = event->source;
AccessibleStateSet *state_set = Accessible_getStateSet (accessible);
AccessibleRole role = Accessible_getRole (accessible);
@ -416,10 +440,24 @@ focus_listener_cb (const AccessibleEvent *event,
case SPI_ROLE_PARAGRAPH:
case SPI_ROLE_PASSWORD_TEXT:
case SPI_ROLE_TERMINAL:
case SPI_ROLE_ENTRY:
if (g_strcmp0 (event->type, "focus") == 0 || event->detail1 == 1) {
if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) {
client->acc = accessible;
eekboard_context_show_keyboard (client->context, NULL);
} else if (event->detail1 == 0 && accessible == client->acc) {
client->acc = NULL;
eekboard_context_hide_keyboard (client->context, NULL);
}
break;
case SPI_ROLE_ENTRY:
if (strncmp (event->type, "focus", 5) == 0 || event->detail1 == 1) {
client->acc = accessible;
eekboard_context_show_keyboard (client->context, NULL);
} else if (event->detail1 == 0) {
client->acc = NULL;
eekboard_context_hide_keyboard (client->context, NULL);
}
break;
default:
;
}
@ -434,7 +472,7 @@ static SPIBoolean
keystroke_listener_cb (const AccessibleKeystroke *stroke,
void *user_data)
{
EekboardDesktopClient *client = user_data;
EekboardClient *client = user_data;
EekKey *key;
/* Ignore modifiers since the keystroke listener does not called
@ -457,12 +495,15 @@ keystroke_listener_cb (const AccessibleKeystroke *stroke,
}
#endif /* HAVE_CSPI */
EekboardDesktopClient *
eekboard_desktop_client_new (GDBusConnection *connection)
EekboardClient *
eekboard_client_new (GDBusConnection *connection)
{
return g_object_new (EEKBOARD_TYPE_DESKTOP_CLIENT,
EekboardClient *client = g_object_new (EEKBOARD_TYPE_CLIENT,
"connection", connection,
NULL);
if (client->context)
return client;
return NULL;
}
static GdkFilterReturn
@ -470,7 +511,7 @@ filter_xkl_event (GdkXEvent *xev,
GdkEvent *event,
gpointer user_data)
{
EekboardDesktopClient *client = user_data;
EekboardClient *client = user_data;
XEvent *xevent = (XEvent *)xev;
xkl_engine_filter_events (client->xkl_engine, xevent);
@ -481,10 +522,10 @@ static void
on_xkl_config_changed (XklEngine *xklengine,
gpointer user_data)
{
EekboardDesktopClient *client = user_data;
EekboardClient *client = user_data;
gboolean retval;
retval = set_keyboard (client, FALSE, NULL, NULL, NULL);
retval = set_xkl_keyboard (client, FALSE, NULL, NULL, NULL);
g_return_if_fail (retval);
#ifdef HAVE_FAKEKEY
@ -494,16 +535,40 @@ on_xkl_config_changed (XklEngine *xklengine,
}
static gboolean
set_keyboard (EekboardDesktopClient *client,
set_keyboard (EekboardClient *client,
gboolean show,
EekLayout *layout)
{
gchar *keyboard_name;
static gint keyboard_serial = 0;
guint keyboard_id;
client->keyboard = eek_keyboard_new (layout, CSW, CSH);
eek_keyboard_set_modifier_behavior (client->keyboard,
EEK_MODIFIER_BEHAVIOR_LATCH);
keyboard_name = g_strdup_printf ("keyboard%d", keyboard_serial++);
eek_element_set_name (EEK_ELEMENT(client->keyboard), keyboard_name);
g_free (keyboard_name);
keyboard_id = eekboard_context_add_keyboard (client->context,
client->keyboard,
NULL);
eekboard_context_set_keyboard (client->context, keyboard_id, NULL);
if (show)
eekboard_context_show_keyboard (client->context, NULL);
return TRUE;
}
static gboolean
set_xkl_keyboard (EekboardClient *client,
gboolean show,
const gchar *model,
const gchar *layouts,
const gchar *options)
{
EekLayout *layout;
gchar *keyboard_name;
static gint keyboard_serial = 0;
guint keyboard_id;
gboolean retval;
if (client->keyboard)
g_object_unref (client->keyboard);
@ -548,21 +613,9 @@ set_keyboard (EekboardDesktopClient *client,
}
}
client->keyboard = eek_keyboard_new (layout, CSW, CSH);
eek_keyboard_set_modifier_behavior (client->keyboard,
EEK_MODIFIER_BEHAVIOR_LATCH);
keyboard_name = g_strdup_printf ("keyboard%d", keyboard_serial++);
eek_element_set_name (EEK_ELEMENT(client->keyboard), keyboard_name);
keyboard_id = eekboard_context_add_keyboard (client->context,
client->keyboard,
NULL);
eekboard_context_set_keyboard (client->context, keyboard_id, NULL);
if (show)
eekboard_context_show_keyboard (client->context, NULL);
return TRUE;
retval = set_keyboard (client, show, layout);
g_object_unref (layout);
return retval;
}
static void
@ -572,7 +625,7 @@ on_xkl_state_changed (XklEngine *xklengine,
gboolean restore,
gpointer user_data)
{
EekboardDesktopClient *client = user_data;
EekboardClient *client = user_data;
if (type == GROUP_CHANGED && client->keyboard) {
gint group = eek_element_get_group (EEK_ELEMENT(client->keyboard));
@ -583,22 +636,50 @@ on_xkl_state_changed (XklEngine *xklengine,
}
#ifdef HAVE_FAKEKEY
G_INLINE_FUNC FakeKeyModifier
get_fakekey_modifiers (EekModifierType modifiers)
{
FakeKeyModifier retval = 0;
if (modifiers & EEK_SHIFT_MASK)
retval |= FAKEKEYMOD_SHIFT;
if (modifiers & EEK_CONTROL_MASK)
retval |= FAKEKEYMOD_CONTROL;
if (modifiers & EEK_MOD1_MASK)
retval |= FAKEKEYMOD_ALT;
if (modifiers & EEK_META_MASK)
retval |= FAKEKEYMOD_META;
return retval;
}
static void
on_key_pressed (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data)
{
EekboardDesktopClient *client = user_data;
EekboardClient *client = user_data;
EekSymbol *symbol;
g_assert (client->fakekey);
symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
if (EEK_IS_KEYSYM(symbol) && !eek_symbol_is_modifier (symbol)) {
fakekey_press_keysym (client->fakekey,
eek_keysym_get_xkeysym (EEK_KEYSYM(symbol)),
0);
fakekey_release (client->fakekey);
guint xkeysym = eek_keysym_get_xkeysym (EEK_KEYSYM(symbol));
guint keycode =
XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (client->display), xkeysym);
EekModifierType modifiers =
eek_keyboard_get_modifiers (client->keyboard);
FakeKeyModifier fakekey_modifiers = get_fakekey_modifiers (modifiers);
fakekey_send_keyevent (client->fakekey,
keycode,
TRUE,
fakekey_modifiers);
fakekey_send_keyevent (client->fakekey,
keycode,
FALSE,
fakekey_modifiers);
}
}
@ -607,14 +688,14 @@ on_key_released (EekKeyboard *keyboard,
EekKey *key,
gpointer user_data)
{
EekboardDesktopClient *client = user_data;
EekboardClient *client = user_data;
g_assert (client->fakekey);
fakekey_release (client->fakekey);
}
gboolean
eekboard_desktop_client_enable_fakekey (EekboardDesktopClient *client)
eekboard_client_enable_fakekey (EekboardClient *client)
{
if (!client->display) {
client->display = gdk_display_get_default ();
@ -637,7 +718,7 @@ eekboard_desktop_client_enable_fakekey (EekboardDesktopClient *client)
}
void
eekboard_desktop_client_disable_fakekey (EekboardDesktopClient *client)
eekboard_client_disable_fakekey (EekboardClient *client)
{
if (client->fakekey)
fakekey_release (client->fakekey);
@ -651,4 +732,31 @@ eekboard_desktop_client_disable_fakekey (EekboardDesktopClient *client)
g_signal_handler_disconnect (client->keyboard,
client->key_released_handler);
}
gboolean
eekboard_client_load_keyboard_from_file (EekboardClient *client,
const gchar *keyboard_file)
{
GFile *file;
GFileInputStream *input;
GError *error;
EekLayout *layout;
EekKeyboard *keyboard;
guint keyboard_id;
gboolean retval;
file = g_file_new_for_path (keyboard_file);
error = NULL;
input = g_file_read (file, NULL, &error);
if (input == NULL)
return FALSE;
layout = eek_xml_layout_new (G_INPUT_STREAM(input));
g_object_unref (input);
retval = set_keyboard (client, TRUE, layout);
g_object_unref (layout);
return retval;
}
#endif /* HAVE_FAKEKEY */

61
src/client.h Normal file
View File

@ -0,0 +1,61 @@
/*
* 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
#include <gio/gio.h>
G_BEGIN_DECLS
#define EEKBOARD_TYPE_CLIENT (eekboard_client_get_type())
#define EEKBOARD_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_CLIENT, EekboardClient))
#define EEKBOARD_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_CLIENT, EekboardClientClass))
#define EEKBOARD_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_CLIENT))
#define EEKBOARD_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_CLIENT))
#define EEKBOARD_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_CLIENT, EekboardClientClass))
typedef struct _EekboardClient EekboardClient;
EekboardClient * eekboard_client_new (GDBusConnection *connection);
gboolean eekboard_client_load_keyboard_from_file
(EekboardClient *client,
const gchar *file);
gboolean eekboard_client_set_xkl_config (EekboardClient *client,
const gchar *model,
const gchar *layouts,
const gchar *options);
gboolean eekboard_client_enable_xkl (EekboardClient *client);
void eekboard_client_disable_xkl (EekboardClient *client);
gboolean eekboard_client_enable_cspi_focus
(EekboardClient *client);
void eekboard_client_disable_cspi_focus
(EekboardClient *client);
gboolean eekboard_client_enable_cspi_keystroke
(EekboardClient *client);
void eekboard_client_disable_cspi_keystroke
(EekboardClient *client);
gboolean eekboard_client_enable_fakekey (EekboardClient *client);
void eekboard_client_disable_fakekey (EekboardClient *client);
G_END_DECLS
#endif /* EEKBOARD_CLIENT_H */

View File

@ -1,206 +0,0 @@
/*
* 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/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <cspi/spi.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <gconf/gconf-client.h>
#include "eekboard/eekboard.h"
#include "desktop-client.h"
static gboolean opt_system = FALSE;
static gboolean opt_session = FALSE;
static gchar *opt_address = NULL;
#ifdef HAVE_CSPI
static gboolean opt_focus = FALSE;
static gboolean opt_keystroke = FALSE;
#endif /* HAVE_CSPI */
static gchar *opt_model = NULL;
static gchar *opt_layouts = NULL;
static gchar *opt_options = NULL;
static const GOptionEntry options[] = {
{"system", 'y', 0, G_OPTION_ARG_NONE, &opt_system,
N_("Connect to the system bus")},
{"session", 'e', 0, G_OPTION_ARG_NONE, &opt_session,
N_("Connect to the session bus")},
{"address", 'a', 0, G_OPTION_ARG_STRING, &opt_address,
N_("Connect to the given D-Bus address")},
#ifdef HAVE_CSPI
{"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus,
N_("Listen focus change events with AT-SPI")},
{"listen-keystroke", 's', 0, G_OPTION_ARG_NONE, &opt_keystroke,
N_("Listen keystroke events with AT-SPI")},
#endif /* HAVE_CSPI */
{"model", '\0', 0, G_OPTION_ARG_STRING, &opt_model,
N_("Specify model")},
{"layouts", '\0', 0, G_OPTION_ARG_STRING, &opt_layouts,
N_("Specify layouts")},
{"options", '\0', 0, G_OPTION_ARG_STRING, &opt_options,
N_("Specify options")},
{NULL}
};
static void
on_notify_keyboard_visible (GObject *object,
GParamSpec *spec,
gpointer user_data)
{
GMainLoop *loop = user_data;
gboolean visible;
g_object_get (object, "keyboard-visible", &visible, NULL);
/* user explicitly closed the window */
if (!visible && eekboard_context_is_enabled (EEKBOARD_CONTEXT(object)))
g_main_loop_quit (loop);
}
int
main (int argc, char **argv)
{
EekboardDesktopClient *client;
EekboardContext *context;
GBusType bus_type;
GDBusConnection *connection;
GError *error;
GConfClient *gconfc;
GOptionContext *option_context;
GMainLoop *loop;
if (!gtk_init_check (&argc, &argv)) {
g_printerr ("Can't init GTK\n");
exit (1);
}
option_context = g_option_context_new ("eekboard-desktop-client");
g_option_context_add_main_entries (option_context, options, NULL);
g_option_context_parse (option_context, &argc, &argv, NULL);
g_option_context_free (option_context);
if (opt_system)
bus_type = G_BUS_TYPE_SYSTEM;
else if (opt_address)
bus_type = G_BUS_TYPE_NONE;
else
bus_type = G_BUS_TYPE_SESSION;
switch (bus_type) {
case G_BUS_TYPE_SYSTEM:
case G_BUS_TYPE_SESSION:
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (connection == NULL) {
g_printerr ("Can't connect to the bus: %s\n", error->message);
exit (1);
}
break;
case G_BUS_TYPE_NONE:
error = NULL;
connection = g_dbus_connection_new_for_address_sync (opt_address,
0,
NULL,
NULL,
&error);
if (connection == NULL) {
g_printerr ("Can't connect to the bus at %s: %s\n",
opt_address,
error->message);
exit (1);
}
break;
default:
g_assert_not_reached ();
break;
}
client = eekboard_desktop_client_new (connection);
gconfc = gconf_client_get_default ();
#ifdef HAVE_CSPI
error = NULL;
if (opt_focus || opt_keystroke) {
if (gconf_client_get_bool (gconfc,
"/desktop/gnome/interface/accessibility",
&error) ||
gconf_client_get_bool (gconfc,
"/desktop/gnome/interface/accessibility2",
&error)) {
if (SPI_init () != 0) {
g_printerr ("Can't init CSPI\n");
exit (1);
}
if (opt_focus &&
!eekboard_desktop_client_enable_cspi_focus (client)) {
g_printerr ("Can't register focus change event listeners\n");
exit (1);
}
if (opt_keystroke &&
!eekboard_desktop_client_enable_cspi_keystroke (client)) {
g_printerr ("Can't register keystroke event listeners\n");
exit (1);
}
} else {
g_printerr ("Desktop accessibility support is disabled\n");
exit (1);
}
}
#endif /* HAVE_CSPI */
if (opt_model || opt_layouts || opt_options) {
if (!eekboard_desktop_client_set_xkl_config (client,
opt_model,
opt_layouts,
opt_options)) {
g_printerr ("Can't set xklavier config\n");
exit (1);
}
} else if (!eekboard_desktop_client_enable_xkl (client)) {
g_printerr ("Can't register xklavier event listeners\n");
exit (1);
}
#ifdef HAVE_FAKEKEY
if (!eekboard_desktop_client_enable_fakekey (client)) {
g_printerr ("Can't init fakekey\n");
exit (1);
}
#endif /* HAVE_FAKEKEY */
loop = g_main_loop_new (NULL, FALSE);
if (!opt_focus) {
g_object_get (client, "context", &context, NULL);
g_signal_connect (context, "notify::keyboard-visible",
G_CALLBACK(on_notify_keyboard_visible), loop);
g_object_unref (context);
}
g_main_loop_run (loop);
g_main_loop_unref (loop);
return 0;
}

View File

@ -1,64 +0,0 @@
/*
* 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_DESKTOP_CLIENT_H
#define EEKBOARD_DESKTOP_CLIENT_H 1
#include <gio/gio.h>
G_BEGIN_DECLS
#define EEKBOARD_TYPE_DESKTOP_CLIENT (eekboard_desktop_client_get_type())
#define EEKBOARD_DESKTOP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_DESKTOP_CLIENT, EekboardDesktopClient))
#define EEKBOARD_DESKTOP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_DESKTOP_CLIENT, EekboardDesktopClientClass))
#define EEKBOARD_IS_DESKTOP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_DESKTOP_CLIENT))
#define EEKBOARD_IS_DESKTOP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_DESKTOP_CLIENT))
#define EEKBOARD_DESKTOP_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_DESKTOP_CLIENT, EekboardDesktopClientClass))
typedef struct _EekboardDesktopClient EekboardDesktopClient;
EekboardDesktopClient * eekboard_desktop_client_new
(GDBusConnection *connection);
gboolean eekboard_desktop_client_set_xkl_config
(EekboardDesktopClient *client,
const gchar *model,
const gchar *layouts,
const gchar *options);
gboolean eekboard_desktop_client_enable_xkl
(EekboardDesktopClient *client);
void eekboard_desktop_client_disable_xkl
(EekboardDesktopClient *client);
gboolean eekboard_desktop_client_enable_cspi_focus
(EekboardDesktopClient *client);
void eekboard_desktop_client_disable_cspi_focus
(EekboardDesktopClient *client);
gboolean eekboard_desktop_client_enable_cspi_keystroke
(EekboardDesktopClient *client);
void eekboard_desktop_client_disable_cspi_keystroke
(EekboardDesktopClient *client);
gboolean eekboard_desktop_client_enable_fakekey
(EekboardDesktopClient *client);
void eekboard_desktop_client_disable_fakekey
(EekboardDesktopClient *client);
G_END_DECLS
#endif /* EEKBOARD_DESKTOP_CLIENT_H */

View File

@ -56,6 +56,9 @@ static const gchar introspection_xml[] =
" <method name='SetKeyboard'>"
" <arg type='u' name='keyboard_id'/>"
" </method>"
" <method name='SetFullscreen'>"
" <arg type='b' name='fullscreen'/>"
" </method>"
" <method name='ShowKeyboard'/>"
" <method name='HideKeyboard'/>"
" <method name='SetGroup'>"
@ -91,9 +94,11 @@ struct _ServerContext {
guint registration_id;
char *object_path;
char *client_connection;
char *client_name;
gboolean enabled;
gboolean last_keyboard_visible;
gboolean fullscreen;
GtkWidget *window;
GtkWidget *widget;
@ -191,30 +196,37 @@ on_realize (GtkWidget *widget,
GDK_FUNC_CLOSE);
}
#define DEFAULT_THEME (THEMEDIR "/default.css")
static void
update_widget (ServerContext *context)
set_geometry (ServerContext *context)
{
GdkScreen *screen;
GdkWindow *root;
gint monitor;
GdkRectangle rect;
EekBounds bounds;
#if HAVE_CLUTTER_GTK
ClutterActor *stage, *actor;
ClutterColor stage_color = { 0xff, 0xff, 0xff, 0xff };
#endif
if (context->widget)
gtk_widget_destroy (context->widget);
screen = gdk_screen_get_default ();
root = gtk_widget_get_root_window (context->window);
monitor = gdk_screen_get_monitor_at_window (screen, root);
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
eek_element_get_bounds (EEK_ELEMENT(context->keyboard), &bounds);
#if HAVE_CLUTTER_GTK
context->widget = gtk_clutter_embed_new ();
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
actor = eek_clutter_keyboard_new (context->keyboard);
clutter_container_add_actor (CLUTTER_CONTAINER(stage), actor);
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
if (context->fullscreen) {
gtk_window_set_decorated (GTK_WINDOW(context->window), FALSE);
gtk_window_set_resizable (GTK_WINDOW(context->window), FALSE);
gtk_widget_set_size_request (context->widget,
rect.width,
rect.height / 2);
gtk_window_move (GTK_WINDOW(context->window),
0,
rect.height / 2);
gtk_window_set_opacity (GTK_WINDOW(context->window), 0.8);
} else {
#if HAVE_CLUTTER_GTK
ClutterActor *stage =
gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), TRUE);
clutter_stage_set_minimum_size (CLUTTER_STAGE(stage),
bounds.width / 3,
@ -224,9 +236,45 @@ update_widget (ServerContext *context)
G_CALLBACK(on_allocation_changed),
actor);
#else
context->widget = eek_gtk_keyboard_new (context->keyboard);
gtk_widget_set_size_request (context->widget,
bounds.width,
bounds.height);
#endif
gtk_window_move (GTK_WINDOW(context->window),
MAX(rect.width - 20 - bounds.width, 0),
MAX(rect.height - 40 - bounds.height, 0));
}
}
static void
update_widget (ServerContext *context)
{
EekBounds bounds;
EekTheme *theme;
#if HAVE_CLUTTER_GTK
ClutterActor *stage, *actor;
ClutterColor stage_color = { 0xff, 0xff, 0xff, 0xff };
#endif
if (context->widget)
gtk_widget_destroy (context->widget);
theme = eek_theme_new (DEFAULT_THEME, NULL, NULL);
eek_element_get_bounds (EEK_ELEMENT(context->keyboard), &bounds);
#if HAVE_CLUTTER_GTK
context->widget = gtk_clutter_embed_new ();
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
actor = eek_clutter_keyboard_new (context->keyboard);
if (theme)
eek_clutter_keyboard_set_theme (EEK_CLUTTER_KEYBOARD(actor), theme);
clutter_container_add_actor (CLUTTER_CONTAINER(stage), actor);
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
#else
context->widget = eek_gtk_keyboard_new (context->keyboard);
if (theme)
eek_gtk_keyboard_set_theme (EEK_GTK_KEYBOARD(context->widget), theme);
#endif
gtk_widget_set_size_request (context->widget, bounds.width, bounds.height);
if (!context->window) {
context->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@ -238,20 +286,17 @@ update_widget (ServerContext *context)
gtk_widget_set_can_focus (context->window, FALSE);
g_object_set (G_OBJECT(context->window), "accept_focus", FALSE, NULL);
gtk_window_set_title (GTK_WINDOW(context->window), _("Keyboard"));
gtk_window_set_title (GTK_WINDOW(context->window),
context->client_name ?
context->client_name :
_("Keyboard"));
gtk_window_set_icon_name (GTK_WINDOW(context->window), "eekboard");
gtk_window_set_keep_above (GTK_WINDOW(context->window), TRUE);
g_signal_connect (context->window, "realize",
G_CALLBACK(on_realize), context);
screen = gdk_screen_get_default ();
root = gtk_widget_get_root_window (context->window);
monitor = gdk_screen_get_monitor_at_window (screen, root);
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
gtk_window_move (GTK_WINDOW(context->window),
MAX(rect.width - 20 - bounds.width, 0),
MAX(rect.height - 40 - bounds.height, 0));
set_geometry (context);
}
gtk_container_add (GTK_CONTAINER(context->window), context->widget);
}
@ -329,7 +374,9 @@ server_context_finalize (GObject *object)
{
ServerContext *context = SERVER_CONTEXT(object);
g_free (context->object_path);
g_free (context->client_connection);
g_free (context->client_name);
G_OBJECT_CLASS (server_context_parent_class)->finalize (object);
}
@ -502,7 +549,7 @@ handle_method_call (GDBusConnection *connection,
g_hash_table_insert (context->keyboard_hash,
GUINT_TO_POINTER(++keyboard_id),
g_object_ref (serializable));
serializable);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(u)",
keyboard_id));
@ -581,6 +628,23 @@ handle_method_call (GDBusConnection *connection,
return;
}
if (g_strcmp0 (method_name, "SetFullscreen") == 0) {
gboolean fullscreen;
g_variant_get (parameters, "(b)", &fullscreen);
if (context->fullscreen == fullscreen) {
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
context->fullscreen = fullscreen;
if (context->window)
set_geometry (context);
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
if (g_strcmp0 (method_name, "SetGroup") == 0) {
gint group;
@ -738,6 +802,7 @@ void
server_context_set_client_connection (ServerContext *context,
const gchar *client_connection)
{
g_free (context->client_connection);
context->client_connection = g_strdup (client_connection);
}
@ -746,3 +811,11 @@ server_context_get_client_connection (ServerContext *context)
{
return context->client_connection;
}
void
server_context_set_client_name (ServerContext *context,
const gchar *client_name)
{
g_free (context->client_name);
context->client_name = g_strdup (client_name);
}

View File

@ -43,6 +43,9 @@ void server_context_set_client_connection
const gchar *client_connection);
const gchar *server_context_get_client_connection
(ServerContext *context);
void server_context_set_client_name
(ServerContext *context,
const gchar *client_name);
G_END_DECLS
#endif /* SERVER_CONTEXT_H */

View File

@ -60,6 +60,15 @@ on_name_lost (GDBusConnection *connection,
exit (1);
}
static void
on_destroyed (ServerServer *server,
gpointer user_data)
{
GMainLoop *loop = user_data;
g_main_loop_quit (loop);
}
int
main (int argc, char **argv)
{
@ -84,6 +93,7 @@ main (int argc, char **argv)
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
/* preload Eek* types for EekKeyboard deserialization */
g_type_class_ref (EEK_TYPE_KEYBOARD);
g_type_class_ref (EEK_TYPE_SECTION);
g_type_class_ref (EEK_TYPE_KEY);
@ -146,6 +156,9 @@ main (int argc, char **argv)
}
loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (server, "destroyed", G_CALLBACK(on_destroyed), loop);
g_main_loop_run (loop);
g_bus_unown_name (owner_id);

View File

@ -22,6 +22,8 @@
#include "server-server.h"
#include "server-context.h"
#define I_(string) g_intern_static_string (string)
enum {
PROP_0,
PROP_OBJECT_PATH,
@ -29,6 +31,13 @@ enum {
PROP_LAST
};
enum {
DESTROYED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
static const gchar introspection_xml[] =
"<node>"
" <interface name='com.redhat.Eekboard.Server'>"
@ -43,6 +52,7 @@ static const gchar introspection_xml[] =
" <method name='DestroyContext'>"
" <arg direction='in' type='s' name='object_path'/>"
" </method>"
" <method name='Destroy'/>"
/* signals */
" </interface>"
"</node>";
@ -147,6 +157,16 @@ server_server_dispose (GObject *object)
G_OBJECT_CLASS (server_server_parent_class)->dispose (object);
}
static void
server_server_finalize (GObject *object)
{
ServerServer *server = SERVER_SERVER(object);
g_free (server->object_path);
G_OBJECT_CLASS (server_server_parent_class)->dispose (object);
}
static void
server_server_constructed (GObject *object)
{
@ -174,6 +194,18 @@ server_server_class_init (ServerServerClass *klass)
gobject_class->constructed = server_server_constructed;
gobject_class->set_property = server_server_set_property;
gobject_class->dispose = server_server_dispose;
gobject_class->finalize = server_server_finalize;
signals[DESTROYED] =
g_signal_new (I_("destroyed"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
pspec = g_param_spec_string ("object-path",
"Object-path",
@ -248,16 +280,21 @@ server_name_vanished_callback (GDBusConnection *connection,
g_hash_table_iter_remove (&iter);
}
for (head = server->context_stack; head; head = server->context_stack) {
for (head = server->context_stack; head; ) {
const gchar *client_connection =
server_context_get_client_connection (head->data);
GSList *next = g_slist_next (head);
if (g_strcmp0 (client_connection, name) == 0) {
server->context_stack = g_slist_remove_link (server->context_stack,
head);
g_object_unref (head->data);
g_slist_free1 (head);
}
head = next;
}
if (server->context_stack)
server_context_set_enabled (server->context_stack->data, TRUE);
}
@ -284,9 +321,12 @@ handle_method_call (GDBusConnection *connection,
object_path = g_strdup_printf (SERVER_CONTEXT_PATH, context_id++);
context = server_context_new (object_path, server->connection);
server_context_set_client_connection (context, sender);
server_context_set_client_name (context, client_name);
g_hash_table_insert (server->context_hash,
object_path,
context);
/* the vanished callback is called when clients are disconnected */
g_bus_watch_name_on_connection (server->connection,
sender,
G_BUS_NAME_WATCHER_FLAGS_NONE,
@ -328,6 +368,17 @@ handle_method_call (GDBusConnection *connection,
if (server->context_stack) {
ServerContext *context = server->context_stack->data;
if (g_strcmp0 (server_context_get_client_connection (context),
sender) != 0) {
g_dbus_method_invocation_return_error
(invocation,
G_IO_ERROR,
G_IO_ERROR_FAILED_HANDLED,
"the current context not owned by %s",
sender);
return;
}
server_context_set_enabled (context, FALSE);
server->context_stack = g_slist_next (server->context_stack);
g_object_unref (context);
@ -358,6 +409,12 @@ handle_method_call (GDBusConnection *connection,
return;
}
if (g_strcmp0 (method_name, "Destroy") == 0) {
g_signal_emit_by_name (server, "destroyed", NULL);
g_dbus_method_invocation_return_value (invocation, NULL);
return;
}
g_return_if_reached ();
}

View File

@ -28,7 +28,13 @@
#include "eek/eek-xml.h"
#include "eek/eek-xkl.h"
#if HAVE_CLUTTER_GTK
#include <clutter-gtk/clutter-gtk.h>
#include "eek/eek-clutter.h"
#else /* HAVE_CLUTTER_GTK */
#include "eek/eek-gtk.h"
#endif /* !HAVE_CLUTTER_GTK */
#include "xklutil.h"
@ -41,6 +47,7 @@ static gchar *opt_layouts = NULL;
static gchar *opt_options = NULL;
static gchar *opt_list = NULL;
static guint opt_group = 0;
static gchar *opt_theme = NULL;
static const GOptionEntry options[] = {
{"load", 'l', 0, G_OPTION_ARG_STRING, &opt_load,
@ -57,9 +64,25 @@ static const GOptionEntry options[] = {
N_("Specify options")},
{"group", 'g', 0, G_OPTION_ARG_INT, &opt_group,
N_("Specify group")},
{"theme", 't', 0, G_OPTION_ARG_STRING, &opt_theme,
N_("Specify theme")},
{NULL}
};
#if HAVE_CLUTTER_GTK
static void
on_allocation_changed (ClutterActor *stage,
ClutterActorBox *box,
ClutterAllocationFlags flags,
gpointer user_data)
{
ClutterActor *actor = user_data;
clutter_actor_set_size (actor,
box->x2 - box->x1,
box->y2 - box->y1);
}
#endif
static void
on_destroy (gpointer user_data)
{
@ -80,10 +103,19 @@ main (int argc, char **argv)
{
GOptionContext *context;
#if HAVE_CLUTTER_GTK
if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
g_printerr ("Can't init GTK with Clutter\n");
exit (1);
}
#else
if (!gtk_init_check (&argc, &argv)) {
g_printerr ("Can't init GTK\n");
exit (1);
}
#endif
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
context = g_option_context_new ("eek-example-xml");
g_option_context_add_main_entries (context, options, NULL);
@ -98,6 +130,10 @@ main (int argc, char **argv)
EekBounds bounds;
GtkWidget *widget, *window;
GError *error;
#if HAVE_CLUTTER_GTK
ClutterActor *stage, *actor;
ClutterColor stage_color = { 0xff, 0xff, 0xff, 0xff };
#endif
file = g_file_new_for_path (opt_load);
@ -114,11 +150,40 @@ main (int argc, char **argv)
g_object_unref (layout);
eek_element_set_group (EEK_ELEMENT(keyboard), opt_group);
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
#if HAVE_CLUTTER_GTK
widget = gtk_clutter_embed_new ();
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(widget));
actor = eek_clutter_keyboard_new (keyboard);
if (opt_theme) {
EekTheme *theme = eek_theme_new (opt_theme, NULL, NULL);
eek_clutter_keyboard_set_theme (EEK_CLUTTER_KEYBOARD(actor), theme);
g_object_unref (theme);
}
clutter_container_add_actor (CLUTTER_CONTAINER(stage), actor);
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), TRUE);
clutter_stage_set_minimum_size (CLUTTER_STAGE(stage),
bounds.width / 3,
bounds.height / 3);
g_signal_connect (stage,
"allocation-changed",
G_CALLBACK(on_allocation_changed),
actor);
#else
widget = eek_gtk_keyboard_new (keyboard);
if (opt_theme) {
EekTheme *theme = eek_theme_new (opt_theme, NULL, NULL);
eek_gtk_keyboard_set_theme (EEK_GTK_KEYBOARD(widget), theme);
g_object_unref (theme);
}
#endif
g_object_unref (keyboard);
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
gtk_widget_set_size_request (widget, bounds.width, bounds.height);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);