From 89d656e1cb1ce4b4df7658ee53a46932ef018d15 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 11 Jan 2012 09:51:40 +0100 Subject: [PATCH 2/2] Make xkl_engine_get_current_state() introspectable Define boxed type for XklState and fix the return type transfer annotation. Also add a small test to test_gi.py. --- libxklavier/xkl_engine.h | 6 +++++- libxklavier/xklavier_util.c | 14 ++++++++++++++ tests/test_gi.py | 2 ++ 3 files changed, 21 insertions(+), 1 deletions(-) diff --git a/libxklavier/xkl_engine.h b/libxklavier/xkl_engine.h index 101350c..1421373 100644 --- a/libxklavier/xkl_engine.h +++ b/libxklavier/xkl_engine.h @@ -82,6 +82,10 @@ extern "C" { guint32 indicators; } XklState; +#define XKL_TYPE_STATE (xkl_state_get_type()) + + GType xkl_state_get_type (void) G_GNUC_CONST; + /** * The main Xklavier engine class */ @@ -326,7 +330,7 @@ extern "C" { * xkl_engine_get_current_state: * @engine: the engine * - * Returns: current state of the keyboard. + * Returns: (transfer none): current state of the keyboard. * Returned value is a statically allocated buffer, should not be freed. */ extern XklState *xkl_engine_get_current_state(XklEngine * engine); diff --git a/libxklavier/xklavier_util.c b/libxklavier/xklavier_util.c index 578f408..0891726 100644 --- a/libxklavier/xklavier_util.c +++ b/libxklavier/xklavier_util.c @@ -27,6 +27,20 @@ #include "xklavier_private.h" XklState * +_xkl_state_copy(XklState * state) +{ + XklState * copy; + + copy = g_new(XklState, 1); + copy->group = state->group; + copy->indicators = state->indicators; + + return copy; +} + +G_DEFINE_BOXED_TYPE (XklState, xkl_state, _xkl_state_copy, g_free); + +XklState * xkl_engine_get_current_state(XklEngine * engine) { return &xkl_engine_priv(engine, curr_state); diff --git a/tests/test_gi.py b/tests/test_gi.py index 0602fbd..25867f5 100755 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -36,6 +36,8 @@ print('indicator names:', engine.get_indicators_names()) print('group names:', engine.get_groups_names()) print('default layout:', engine.get_groups_names()[engine.get_default_group()]) print('features: %X' % engine.get_features()) +st = engine.get_current_state() +print('current state: group: %i, indicators: %u' % (st.group, st.indicators)) # check ConfigItem ctor with data i = Xkl.ConfigItem() -- 1.7.7.3