Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check value correctly with xkb_state_layout_index_is_active() #5925

Merged
merged 1 commit into from
May 7, 2024

Conversation

ikalco
Copy link
Contributor

@ikalco ikalco commented May 7, 2024

Describe your PR, what does it fix/add?

fixes
language onevent with error #5923

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

xkb_state_layout_index_is_active()
Test whether a layout is active in a given keyboard state by index.

Returns
1 if the layout is active, 0 if it is not. If the layout index is not valid in the keymap, returns -1.

in cpp -1 is truthy and Hyprland uses this

std::string IKeyboard::getActiveLayout() {
    const auto WLRKB      = wlr();
    const auto KEYMAP     = WLRKB->keymap;
    const auto STATE      = WLRKB->xkb_state;
    const auto LAYOUTSNUM = xkb_keymap_num_layouts(KEYMAP);

    for (uint32_t i = 0; i < LAYOUTSNUM; ++i) {
        if (xkb_state_layout_index_is_active(STATE, i, XKB_STATE_LAYOUT_EFFECTIVE)) {
            const auto LAYOUTNAME = xkb_keymap_layout_get_name(KEYMAP, i);

            if (LAYOUTNAME)
                return std::string(LAYOUTNAME);
            return "error";
        }
    }

    return "none";
}

Not sure how it would get an invalid index though

Is it ready for merging, or does it need work?

Yes

@vaxerski vaxerski linked an issue May 7, 2024 that may be closed by this pull request
@vaxerski
Copy link
Member

vaxerski commented May 7, 2024

ah yeah I should rtfm indeed

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@vaxerski vaxerski merged commit 6ccc221 into hyprwm:main May 7, 2024
7 of 9 checks passed
@ikalco ikalco deleted the fix_xkb_layout_checking branch May 7, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

language onevent with error
2 participants