Skip to content

Commit

Permalink
WIP track list of keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Nov 16, 2024
1 parent daacf0f commit 4ad0bce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub struct Common {
pub viewporter_state: ViewporterState,
pub kde_decoration_state: KdeDecorationState,
pub xdg_decoration_state: XdgDecorationState,
pub keymap_state: KeymapState,

// shell-related wayland state
pub xdg_shell_state: XdgShellState,
Expand Down Expand Up @@ -523,7 +524,7 @@ impl State {
VirtualKeyboardManagerState::new::<State, _>(&dh, client_is_privileged);
AlphaModifierState::new::<Self>(&dh);
SinglePixelBufferState::new::<Self>(&dh);
KeymapState::new::<State, _>(&dh, client_is_privileged);
let keymap_state = KeymapState::new::<State, _>(&dh, client_is_privileged);

let idle_notifier_state = IdleNotifierState::<Self>::new(&dh, handle.clone());
let idle_inhibit_manager_state = IdleInhibitManagerState::new::<State>(&dh);
Expand Down Expand Up @@ -627,6 +628,7 @@ impl State {
xwayland_state: None,
xwayland_shell_state,
pointer_focus_state: None,
keymap_state,

atspi_state,
atspi_ei: Default::default(),
Expand Down
9 changes: 8 additions & 1 deletion src/wayland/handlers/keymap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-only
//

use crate::{state::State, wayland::protocols::keymap::delegate_keymap};
use crate::wayland::protocols::keymap::{KeymapHandler, KeymapState};

impl KeymapHandler for State {
fn keymap_state(&mut self) -> &mut KeymapState {
&mut self.common.keymap_state
}
}

delegate_keymap!(State);
30 changes: 25 additions & 5 deletions src/wayland/protocols/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ use smithay::{
keyboard::{KeyboardHandle, Layout},
SeatHandler,
},
reexports::wayland_server::{Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New},
reexports::{
wayland_server::{Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New},
}
};
use wayland_backend::server::GlobalId;
use wayland_backend::server::{ClientId, GlobalId};

pub trait KeymapHandler {
fn keymap_state(&mut self) -> &mut KeymapState;
}

// TODO: add a refrensh function that sends `group`
// track list of keymaps per keyboard
#[derive(Debug)]
pub struct KeymapState {
pub global: GlobalId,
keymaps: Vec<ZcosmicKeymapV1>,
}

impl KeymapState {
Expand All @@ -28,7 +38,7 @@ impl KeymapState {
filter: Box::new(client_filter),
},
);
KeymapState { global }
KeymapState { global, keymaps: Vec::new() }
}
}

Expand Down Expand Up @@ -64,9 +74,10 @@ where
D: Dispatch<ZcosmicKeymapV1, KeymapUserData<D>>,
D: 'static,
D: SeatHandler,
D: KeymapHandler,
{
fn request(
_state: &mut D,
state: &mut D,
_client: &Client,
_resource: &ZcosmicKeymapManagerV1,
request: zcosmic_keymap_manager_v1::Request,
Expand All @@ -77,9 +88,10 @@ where
match request {
zcosmic_keymap_manager_v1::Request::GetKeymap { keymap, keyboard } => {
let handle = KeyboardHandle::<D>::from_resource(&keyboard);
data_init.init(keymap, KeymapUserData {
let keymap = data_init.init(keymap, KeymapUserData {
handle
});
state.keymap_state().keymaps.push(keymap);
}
zcosmic_keymap_manager_v1::Request::Destroy => {}
_ => unreachable!(),
Expand All @@ -97,6 +109,7 @@ where
D: Dispatch<ZcosmicKeymapV1, KeymapUserData<D>>,
D: 'static,
D: SeatHandler,
D: KeymapHandler,
{
fn request(
state: &mut D,
Expand All @@ -119,6 +132,13 @@ where
_ => unreachable!(),
}
}

fn destroyed(state: &mut D, _client: ClientId, keymap: &ZcosmicKeymapV1, _data: &KeymapUserData<D>) {
let keymaps = &mut state.keymap_state().keymaps;
if let Some(idx) = keymaps.iter().position(|x| x == keymap) {
keymaps.remove(idx);
}
}
}

macro_rules! delegate_keymap {
Expand Down

0 comments on commit 4ad0bce

Please sign in to comment.