简体   繁体   English

在X.org中切换kb布局时会触发哪个事件

[英]Which event is fired when switching kb layout in X.org

I'm new to the X.org programming. 我是X.org编程的新手。 I want to build up a small application which reacts on the X keyboard layout switch. 我想建立一个小应用程序,它对X键盘布局开关作出反应。 I've searched, but didn't find which event is fired when the kb layout is switched. 我已经搜索过,但是在切换kb布局时没有找到触发的事件。 Please, point me to the correct event. 请指出正确的事件。 Thanks 谢谢

There's the XkbStateNotify event type, which is part of the X Keyboard Extension . XkbStateNotify事件类型,它是X键盘扩展的一部分 You can grab layout language from it like this: 您可以从中获取布局语言,如下所示:

void x11Events(XEvent* evt)
{
    if(evt->type == xkbEventType) {
        XkbEvent* xkbevt = (XkbEvent*)evt;
        if (xkbevt->any.xkb_type == XkbStateNotify) {
            int lang = xkbevt->state.group;
            // Some code using lang here.
        }
    }
}

To get xkbEventType , call the XkbQueryExtension() function (declared in XKBlib.h ). 要获取xkbEventType ,请调用XkbQueryExtension()函数(在XKBlib.h声明)。

However, XkbStateNotify is fired not only on layout change. 但是, XkbStateNotify不仅会在布局更改时触发。 This is from specification referenced above: 这来自上面引用的规范:

The changes reported include changes to any aspect of the keyboard state: when a modifier is set or unset, when the current group changes, or when a pointer button is pressed or released. 报告的更改包括对键盘状态的任何方面的更改:设置或取消设置修改器时,当前组更改时,或按下或释放指针按钮时。

Because of this, you'll have to save the value of lang somewhere, and then, when new event arrives, compare new value of lang to the one previously saved. 因此,您必须在某处保存lang的值,然后,当新事件到达时,将lang新值与先前保存的值进行比较。

NB. NB。 There's also the XkbMapNotifyEvent event, which notifies not about switching layout per se, but about changing keyboard mapping. 还有XkbMapNotifyEvent事件,它不会通知切换布局本身,而是关于更改键盘映射。 You might want to look into that one, too. 你可能也想研究那个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM