feat: add keyboard layout support
This commit is contained in:
1 parent
86e3ebfe33
commit
821543238d
36 files changed
+1132
-125
No files matched your search
@@ -108,8 +108,34 @@ void gui::desktop_draw_panel(DesktopState* ds) {
|
||||
int date_x = clock_x - date_w - 10;
|
||||
draw_text(fb, date_x, clock_y, date_str, colors::PANEL_TEXT);
|
||||
|
||||
// Volume icon (to the left of the date)
|
||||
int vol_icon_x = date_x - 16 - 12;
|
||||
// Only render switcher if more than one keyboard layout is installed
|
||||
int enabled_layouts = 0;
|
||||
for (int i = 0; i < ds->keyboard.registry.count; i++)
|
||||
if (ds->keyboard.enabled[i]) enabled_layouts++;
|
||||
|
||||
// Whatever text ends up leftmost is what the volume icon spaces off.
|
||||
int vol_anchor_x = date_x;
|
||||
|
||||
if (enabled_layouts > 1) {
|
||||
const char* layout_short = "en";
|
||||
if (ds->keyboard.active >= 0
|
||||
&& ds->keyboard.active < ds->keyboard.registry.count) {
|
||||
layout_short =
|
||||
ds->keyboard.registry.items[ds->keyboard.active].short_name;
|
||||
}
|
||||
int layout_tw = text_width(layout_short);
|
||||
int layout_x = date_x - layout_tw - 10;
|
||||
// Padded evenly past the glyphs so the click target is comfortable.
|
||||
ds->keyboard_layout_rect = {layout_x - 5, 4, layout_tw + 10, 24};
|
||||
draw_text(fb, layout_x, clock_y, layout_short, colors::PANEL_TEXT);
|
||||
vol_anchor_x = layout_x;
|
||||
} else {
|
||||
ds->keyboard_layout_rect = {0, 0, 0, 0};
|
||||
}
|
||||
|
||||
// Volume icon keeps its 12px icon-to-text gap whether it sits next to the
|
||||
// layout tag or, with one layout, the date.
|
||||
int vol_icon_x = vol_anchor_x - 12 - 16;
|
||||
int vol_icon_y = (PANEL_HEIGHT - 16) / 2;
|
||||
ds->vol_icon_rect = {vol_icon_x, vol_icon_y, 16, 16};
|
||||
|
||||
|
||||
Reference in new issue
Block a user