One of the goals of Sapphire is to be as customizable as possible. Similar to awesome and dwm, Sapphire allows you to customize the behavior of the window manager by modifying the source code.
You can use the Keyboard
struct to control keyboard events; a useful instance resides under your WindowManager
instance.
To add a simple keybinding event, you can do:
wm.keyboard.append_keybindings(&[
Keybinding::new()
.on(&[modkey], "1")
.group("Tag")
.description("View tag[1].")
.execute(Box::new(|ctx: EventContext| {
let mut screen = ctx.screen.lock().unwrap();
screen.view_tag(id)
})),
]);
The Mouse
struct allows you to control globally events triggered by the mouse, such as clicks and entering on clients.
To enable the focus on click feature you can do something like:
wm.mouse.on(MouseEvent::Click, Box::new(|ctx: EventContext, info: MouseInfo| {
let mut screen = ctx.screen.lock().unwrap();
let tag = screen.get_focused_tag_mut()?;
let focus_id = tag.get_focused_client().map_or(0, |c| c.id);
if focus_id != info.c_id {
tag.set_focused_client_if(info.c_id, |c| c.is_controlled());
}
Ok(())
}));