fall back to system layout more aggressively
This commit is contained in:
@@ -6,23 +6,23 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
KEYMAP_CHANGE,
|
||||||
backend::input::{HoverResult, PointerHit},
|
backend::input::{HoverResult, PointerHit},
|
||||||
gui::panel::GuiPanel,
|
gui::panel::GuiPanel,
|
||||||
overlays::keyboard::{builder::create_keyboard_panel, layout::AltModifier},
|
overlays::keyboard::{builder::create_keyboard_panel, layout::AltModifier},
|
||||||
state::AppState,
|
state::AppState,
|
||||||
subsystem::hid::{
|
subsystem::hid::{
|
||||||
get_keymap_wl, get_keymap_x11, KeyModifier, VirtualKey, WheelDelta, XkbKeymap, ALT, CTRL,
|
ALT, CTRL, KeyModifier, META, SHIFT, SUPER, VirtualKey, WheelDelta, XkbKeymap,
|
||||||
META, SHIFT, SUPER,
|
get_keymap_wl, get_keymap_x11,
|
||||||
},
|
},
|
||||||
windowing::{
|
windowing::{
|
||||||
backend::{FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender},
|
backend::{FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender},
|
||||||
window::OverlayWindowConfig,
|
window::OverlayWindowConfig,
|
||||||
},
|
},
|
||||||
KEYMAP_CHANGE,
|
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use glam::{vec3, Affine3A, Quat, Vec3};
|
use glam::{Affine3A, Quat, Vec3, vec3};
|
||||||
use slotmap::{new_key_type, SlotMap};
|
use slotmap::{SlotMap, new_key_type};
|
||||||
use wgui::{
|
use wgui::{
|
||||||
drawing,
|
drawing,
|
||||||
event::{InternalStateChangeEvent, MouseButton, MouseButtonIndex},
|
event::{InternalStateChangeEvent, MouseButton, MouseButtonIndex},
|
||||||
@@ -180,16 +180,21 @@ impl KeyboardBackend {
|
|||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn switch_to_fcitx_keymap(&mut self, app: &mut AppState) -> anyhow::Result<bool> {
|
fn auto_switch_keymap(&mut self, app: &mut AppState) -> anyhow::Result<bool> {
|
||||||
let fcitx_layout = app
|
let Ok(fcitx_layout) = app
|
||||||
.dbus
|
.dbus
|
||||||
.fcitx_keymap()
|
.fcitx_keymap()
|
||||||
.context("Could not fetch Fcitx5 keymap")
|
.context("Could not keymap via fcitx5, falling back to wayland")
|
||||||
.inspect_err(|e| log::warn!("{e:?}"))?;
|
.inspect_err(|e| log::warn!("{e:?}"))
|
||||||
|
else {
|
||||||
|
let keymap = self.get_system_keymap()?;
|
||||||
|
app.hid_provider.keymap_changed(&keymap);
|
||||||
|
return self.switch_keymap(&keymap, app);
|
||||||
|
};
|
||||||
|
|
||||||
if fcitx_layout.starts_with("keyboard-") {
|
if fcitx_layout.starts_with("keyboard-") {
|
||||||
let keymap = XkbKeymap::from_layout_str(&fcitx_layout[9..])
|
let keymap = XkbKeymap::from_layout_str(&fcitx_layout[9..])
|
||||||
.context("Could not load Fcitx5 keymap")
|
.context("layout is invalid")
|
||||||
.inspect_err(|e| log::warn!("fcitx layout {fcitx_layout}: {e:?}"))?;
|
.inspect_err(|e| log::warn!("fcitx layout {fcitx_layout}: {e:?}"))?;
|
||||||
app.hid_provider.keymap_changed(&keymap);
|
app.hid_provider.keymap_changed(&keymap);
|
||||||
self.switch_keymap(&keymap, app)
|
self.switch_keymap(&keymap, app)
|
||||||
@@ -199,7 +204,10 @@ impl KeyboardBackend {
|
|||||||
app.hid_provider.keymap_changed(&keymap);
|
app.hid_provider.keymap_changed(&keymap);
|
||||||
self.switch_keymap(&keymap, app)
|
self.switch_keymap(&keymap, app)
|
||||||
} else {
|
} else {
|
||||||
anyhow::bail!("Unknown layout or IME: {fcitx_layout}");
|
log::warn!("Unknown layout or IME '{fcitx_layout}', using system layout");
|
||||||
|
let keymap = self.get_system_keymap()?;
|
||||||
|
app.hid_provider.keymap_changed(&keymap);
|
||||||
|
return self.switch_keymap(&keymap, app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +223,7 @@ impl OverlayBackend for KeyboardBackend {
|
|||||||
fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> {
|
fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> {
|
||||||
while KEYMAP_CHANGE.swap(false, Ordering::Relaxed) {
|
while KEYMAP_CHANGE.swap(false, Ordering::Relaxed) {
|
||||||
if self
|
if self
|
||||||
.switch_to_fcitx_keymap(app)
|
.auto_switch_keymap(app)
|
||||||
.inspect_err(|e| log::warn!("{e:?}"))
|
.inspect_err(|e| log::warn!("{e:?}"))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{f32::consts::PI, sync::Arc};
|
use std::{f32::consts::PI, sync::Arc};
|
||||||
|
|
||||||
use glam::{vec3, Affine3A, Quat, Vec3};
|
use glam::{Affine3A, Quat, Vec3, vec3};
|
||||||
use wlx_capture::frame::Transform;
|
use wlx_capture::frame::Transform;
|
||||||
use wlx_common::windowing::{OverlayWindowState, Positioning};
|
use wlx_common::windowing::{OverlayWindowState, Positioning};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use idmap::{idmap, IdMap};
|
use idmap::{IdMap, idmap};
|
||||||
use idmap_derive::IntegerId;
|
use idmap_derive::IntegerId;
|
||||||
use input_linux::{
|
use input_linux::{
|
||||||
AbsoluteAxis, AbsoluteInfo, AbsoluteInfoSetup, EventKind, InputId, Key, RelativeAxis,
|
AbsoluteAxis, AbsoluteInfo, AbsoluteInfoSetup, EventKind, InputId, Key, RelativeAxis,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use wlx_common::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
FRAME_COUNTER,
|
||||||
backend::task::OverlayTask,
|
backend::task::OverlayTask,
|
||||||
overlays::{
|
overlays::{
|
||||||
anchor::create_anchor, edit::EditWrapperManager, keyboard::create_keyboard,
|
anchor::create_anchor, edit::EditWrapperManager, keyboard::create_keyboard,
|
||||||
@@ -19,13 +20,12 @@ use crate::{
|
|||||||
},
|
},
|
||||||
state::AppState,
|
state::AppState,
|
||||||
windowing::{
|
windowing::{
|
||||||
|
OverlayID, OverlaySelector,
|
||||||
backend::{OverlayEventData, OverlayMeta},
|
backend::{OverlayEventData, OverlayMeta},
|
||||||
set::OverlayWindowSet,
|
set::OverlayWindowSet,
|
||||||
snap_upright,
|
snap_upright,
|
||||||
window::{OverlayCategory, OverlayWindowData},
|
window::{OverlayCategory, OverlayWindowData},
|
||||||
OverlayID, OverlaySelector,
|
|
||||||
},
|
},
|
||||||
FRAME_COUNTER,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const MAX_OVERLAY_SETS: usize = 7;
|
pub const MAX_OVERLAY_SETS: usize = 7;
|
||||||
|
|||||||
Reference in New Issue
Block a user