Skip to content

Fix empty layout display for custom XKB layouts in sway/language module#5151

Closed
nick133 wants to merge 1 commit into
Alexays:masterfrom
nick133:fix-xkb-layout-fallback
Closed

Fix empty layout display for custom XKB layouts in sway/language module#5151
nick133 wants to merge 1 commit into
Alexays:masterfrom
nick133:fix-xkb-layout-fallback

Conversation

@nick133

@nick133 nick133 commented Jun 29, 2026

Copy link
Copy Markdown

Problem

Custom XKB layouts (e.g. defined in ~/.config/xkb/symbols/) are not present in libxkbregistry.
When such a layout is active, sway/language module fails to resolve it in layouts_map_, resulting in empty output for all layout placeholders ({short}, {long}, {shortDescription}).

Cause

The code previously used layouts_map_[current_layout], which assumes every active layout exists in layouts_map_:

layout_ = layouts_map_[current_layout];

For unknown layouts, this produces a default Layout with empty fields.

Fix

Add a fallback for unknown layouts instead of relying on map::operator[].

static std::string fallback_layout_short_name(std::string_view full_name) {
  const size_t n = std::min<size_t>(2, full_name.size());
  return std::string(full_name.substr(0, n));
}

auto Language::set_current_layout(const std::string& current_layout) -> void {
  label_.get_style_context()->remove_class(layout_.short_name);

  auto it = layouts_map_.find(current_layout);

  if (it != layouts_map_.end()) {
    layout_ = it->second;
  } else {
    spdlog::debug("Language: using fallback for unknown layout '{}'", current_layout);

    auto short_name = fallback_layout_short_name(current_layout);

    layout_ = Layout{
      current_layout,
      short_name,
      "",
      short_name
    };
  }

  label_.get_style_context()->add_class(layout_.short_name);
}

Notes

  • No change for layouts found in libxkbregistry
  • Fixes empty output for all layout format fields
  • Improves handling of custom XKB configurations

@Alexays

Alexays commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Closing in favor of #5039, which fixes the same set_current_layout empty-layout issue more completely (it also handles keyboard hot-plug and rebuilds the layouts map across devices). Thanks for spotting the bug and contributing a fix! 🙏

@Alexays Alexays closed this Jul 3, 2026
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.

2 participants