pinnacle/api/rust/examples/default_config/main.rs

152 lines
4.2 KiB
Rust
Raw Normal View History

2024-01-22 05:54:32 +01:00
use pinnacle_api::xkbcommon::xkb::Keysym;
2024-01-20 02:37:00 +01:00
use pinnacle_api::{
input::{Mod, MouseButton, MouseEdge},
2024-01-21 04:27:22 +01:00
tag::{Layout, LayoutCycler},
2024-01-20 02:37:00 +01:00
ApiModules,
};
#[pinnacle_api::config(modules)]
async fn main() {
let ApiModules {
pinnacle,
process,
window,
input,
output,
tag,
} = modules;
let mod_key = Mod::Ctrl;
2024-01-23 03:27:22 +01:00
let terminal = "alacritty";
// Mousebinds
// `mod_key + left click` starts moving a window
2024-01-20 02:37:00 +01:00
input.mousebind([mod_key], MouseButton::Left, MouseEdge::Press, || {
window.begin_move(MouseButton::Left);
});
2024-01-23 03:27:22 +01:00
// `mod_key + right click` starts resizing a window
2024-01-20 02:37:00 +01:00
input.mousebind([mod_key], MouseButton::Right, MouseEdge::Press, || {
window.begin_resize(MouseButton::Right);
});
// Keybinds
2024-01-23 03:27:22 +01:00
// `mod_key + alt + q` quits Pinnacle
2024-01-20 02:37:00 +01:00
input.keybind([mod_key, Mod::Alt], 'q', || {
pinnacle.quit();
});
2024-01-23 03:27:22 +01:00
// `mod_key + alt + c` closes the focused window
2024-01-20 02:37:00 +01:00
input.keybind([mod_key, Mod::Alt], 'c', || {
if let Some(window) = window.get_focused() {
window.close();
}
});
2024-01-23 03:27:22 +01:00
// `mod_key + Return` spawns a terminal
input.keybind([mod_key], Keysym::Return, move || {
process.spawn([terminal]);
2024-01-20 02:37:00 +01:00
});
2024-01-23 03:27:22 +01:00
// `mod_key + alt + space` toggles floating
2024-01-21 04:27:22 +01:00
input.keybind([mod_key, Mod::Alt], Keysym::space, || {
2024-01-20 02:37:00 +01:00
if let Some(window) = window.get_focused() {
window.toggle_floating();
}
});
2024-01-23 03:27:22 +01:00
// `mod_key + f` toggles fullscreen
2024-01-20 02:37:00 +01:00
input.keybind([mod_key], 'f', || {
if let Some(window) = window.get_focused() {
window.toggle_fullscreen();
}
});
2024-01-23 03:27:22 +01:00
// `mod_key + m` toggles maximized
2024-01-20 02:37:00 +01:00
input.keybind([mod_key], 'm', || {
if let Some(window) = window.get_focused() {
window.toggle_maximized();
}
});
2024-01-23 03:27:22 +01:00
// Window rules
//
// You can define window rules to get windows to open with desired properties.
// See `pinnacle_api::window::rules` in the docs for more information.
2024-01-20 02:37:00 +01:00
// Tags
let tag_names = ["1", "2", "3", "4", "5"];
2024-01-23 03:27:22 +01:00
// Setup all monitors with tags "1" through "5"
2024-01-20 02:37:00 +01:00
output.connect_for_all(move |op| {
2024-02-23 23:24:43 +01:00
let tags = tag.add(op, tag_names);
2024-01-23 03:27:22 +01:00
// Be sure to set a tag to active or windows won't display
2024-02-23 23:24:43 +01:00
tags.first().unwrap().set_active(true);
2024-01-20 02:37:00 +01:00
});
2024-01-23 03:27:22 +01:00
process.spawn_once([terminal]);
2024-01-20 02:37:00 +01:00
2024-01-23 03:27:22 +01:00
// Create a layout cycler to cycle through the given layouts
2024-01-21 04:27:22 +01:00
let LayoutCycler {
prev: layout_prev,
next: layout_next,
} = tag.new_layout_cycler([
Layout::MasterStack,
Layout::Dwindle,
Layout::Spiral,
Layout::CornerTopLeft,
Layout::CornerTopRight,
Layout::CornerBottomLeft,
Layout::CornerBottomRight,
]);
2024-01-23 03:27:22 +01:00
// `mod_key + space` cycles to the next layout
2024-01-21 04:27:22 +01:00
input.keybind([mod_key], Keysym::space, move || {
layout_next(None);
});
2024-01-23 03:27:22 +01:00
// `mod_key + shift + space` cycles to the previous layout
2024-01-21 04:27:22 +01:00
input.keybind([mod_key, Mod::Shift], Keysym::space, move || {
layout_prev(None);
});
2024-01-20 02:37:00 +01:00
for tag_name in tag_names {
2024-01-23 03:27:22 +01:00
// `mod_key + 1-5` switches to tag "1" to "5"
2024-01-20 02:37:00 +01:00
input.keybind([mod_key], tag_name, move || {
if let Some(tg) = tag.get(tag_name) {
2024-01-20 02:37:00 +01:00
tg.switch_to();
}
});
2024-01-23 03:27:22 +01:00
// `mod_key + shift + 1-5` toggles tag "1" to "5"
2024-01-20 02:37:00 +01:00
input.keybind([mod_key, Mod::Shift], tag_name, move || {
if let Some(tg) = tag.get(tag_name) {
2024-01-20 02:37:00 +01:00
tg.toggle_active();
}
});
2024-01-23 03:27:22 +01:00
// `mod_key + alt + 1-5` moves the focused window to tag "1" to "5"
2024-01-20 02:37:00 +01:00
input.keybind([mod_key, Mod::Alt], tag_name, move || {
if let Some(tg) = tag.get(tag_name) {
2024-01-20 02:37:00 +01:00
if let Some(win) = window.get_focused() {
win.move_to_tag(&tg);
}
}
});
2024-01-23 03:27:22 +01:00
// `mod_key + shift + alt + 1-5` toggles tag "1" to "5" on the focused window
2024-01-20 02:37:00 +01:00
input.keybind([mod_key, Mod::Shift, Mod::Alt], tag_name, move || {
if let Some(tg) = tag.get(tag_name) {
2024-01-20 02:37:00 +01:00
if let Some(win) = window.get_focused() {
win.toggle_tag(&tg);
}
}
});
}
}