mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-27 19:58:08 +01:00
Get example config mostly working
This commit is contained in:
parent
fc7132c0e4
commit
f5b626e14d
10 changed files with 178 additions and 24 deletions
|
@ -1,22 +1,122 @@
|
||||||
use pinnacle_api::{Modifier, MouseButton, MouseEdge};
|
use pinnacle_api::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
pinnacle_api::setup(|pinnacle| {
|
pinnacle_api::setup(|pinnacle| {
|
||||||
pinnacle.output.connect_for_all(move |output| {
|
let input = pinnacle.input;
|
||||||
pinnacle.tag.add(&output, &["1", "2", "3", "4", "5"]);
|
let window = pinnacle.window;
|
||||||
pinnacle.tag.get("1", Some(&output)).unwrap().toggle();
|
let process = pinnacle.process;
|
||||||
|
let tag = pinnacle.tag;
|
||||||
|
let output = pinnacle.output;
|
||||||
|
|
||||||
|
let mod_key = Modifier::Ctrl;
|
||||||
|
|
||||||
|
let terminal = "alacritty";
|
||||||
|
|
||||||
|
// TODO: set env
|
||||||
|
|
||||||
|
input.mousebind(&[mod_key], MouseButton::Left, MouseEdge::Press, move || {
|
||||||
|
window.begin_move(MouseButton::Left);
|
||||||
});
|
});
|
||||||
|
|
||||||
pinnacle.input.keybind(&[Modifier::Ctrl], 'a', move || {
|
input.mousebind(
|
||||||
pinnacle.process.spawn(vec!["alacritty"]).unwrap();
|
&[mod_key],
|
||||||
});
|
MouseButton::Right,
|
||||||
|
|
||||||
pinnacle.input.mousebind(
|
|
||||||
&[Modifier::Ctrl],
|
|
||||||
MouseButton::Left,
|
|
||||||
MouseEdge::Press,
|
MouseEdge::Press,
|
||||||
|| {},
|
move || {
|
||||||
|
window.begin_resize(MouseButton::Right);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
input.keybind(&[mod_key, Modifier::Alt], 'q', move || pinnacle.quit());
|
||||||
|
|
||||||
|
input.keybind(&[mod_key, Modifier::Alt], 'c', move || {
|
||||||
|
if let Some(window) = window.get_focused() {
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
input.keybind(&[mod_key], xkbcommon::xkb::keysyms::KEY_Return, move || {
|
||||||
|
process.spawn(vec![terminal]).unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
|
input.keybind(
|
||||||
|
&[mod_key, Modifier::Alt],
|
||||||
|
xkbcommon::xkb::keysyms::KEY_space,
|
||||||
|
move || {
|
||||||
|
if let Some(window) = window.get_focused() {
|
||||||
|
window.toggle_floating();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
input.keybind(&[mod_key], 'f', move || {
|
||||||
|
if let Some(window) = window.get_focused() {
|
||||||
|
window.toggle_fullscreen();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
input.keybind(&[mod_key], 'm', move || {
|
||||||
|
if let Some(window) = window.get_focused() {
|
||||||
|
window.toggle_maximized();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let tags = ["1", "2", "3", "4", "5"];
|
||||||
|
|
||||||
|
output.connect_for_all(move |output| {
|
||||||
|
tag.add(&output, tags.as_slice());
|
||||||
|
tag.get("1", Some(&output)).unwrap().toggle();
|
||||||
|
});
|
||||||
|
|
||||||
|
// let layout_cycler = tag.layout_cycler(&[
|
||||||
|
// Layout::MasterStack,
|
||||||
|
// Layout::Dwindle,
|
||||||
|
// Layout::Spiral,
|
||||||
|
// Layout::CornerTopLeft,
|
||||||
|
// Layout::CornerTopRight,
|
||||||
|
// Layout::CornerBottomLeft,
|
||||||
|
// Layout::CornerBottomRight,
|
||||||
|
// ]);
|
||||||
|
//
|
||||||
|
// input.keybind(&[mod_key], xkbcommon::xkb::keysyms::KEY_space, move || {
|
||||||
|
// layout_cycler.next(None);
|
||||||
|
// });
|
||||||
|
|
||||||
|
for tag_name in tags.iter().map(|t| t.to_string()) {
|
||||||
|
let t = tag_name.clone();
|
||||||
|
input.keybind(&[mod_key], tag_name.chars().next().unwrap(), move || {
|
||||||
|
println!("tag name is {t}");
|
||||||
|
tag.get(&t, None).unwrap().switch_to();
|
||||||
|
});
|
||||||
|
let t = tag_name.clone();
|
||||||
|
input.keybind(
|
||||||
|
&[mod_key, Modifier::Shift],
|
||||||
|
tag_name.chars().next().unwrap(),
|
||||||
|
move || {
|
||||||
|
tag.get(&t, None).unwrap().toggle();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let t = tag_name.clone();
|
||||||
|
input.keybind(
|
||||||
|
&[mod_key, Modifier::Alt],
|
||||||
|
tag_name.chars().next().unwrap(),
|
||||||
|
move || {
|
||||||
|
if let Some(window) = window.get_focused() {
|
||||||
|
window.move_to_tag(&tag.get(&t, None).unwrap());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let t = tag_name.clone();
|
||||||
|
input.keybind(
|
||||||
|
&[mod_key, Modifier::Shift, Modifier::Alt],
|
||||||
|
tag_name.chars().next().unwrap(),
|
||||||
|
move || {
|
||||||
|
if let Some(window) = window.get_focused() {
|
||||||
|
window.toggle_tag(&tag.get(&t, None).unwrap());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,12 @@ use crate::{
|
||||||
|
|
||||||
use self::libinput::Libinput;
|
use self::libinput::Libinput;
|
||||||
|
|
||||||
|
/// Input management.
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
|
/// Libinput settings.
|
||||||
|
///
|
||||||
|
/// Here you can set stuff like pointer acceleration.
|
||||||
pub libinput: Libinput,
|
pub libinput: Libinput,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{msg::Msg, send_msg};
|
use crate::{msg::Msg, send_msg};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Libinput;
|
pub struct Libinput;
|
||||||
|
|
||||||
impl Libinput {
|
impl Libinput {
|
||||||
|
|
|
@ -11,15 +11,45 @@ mod window;
|
||||||
|
|
||||||
use input::libinput::Libinput;
|
use input::libinput::Libinput;
|
||||||
use input::Input;
|
use input::Input;
|
||||||
pub use input::Modifier;
|
|
||||||
pub use input::MouseButton;
|
|
||||||
pub use input::MouseEdge;
|
|
||||||
use output::Output;
|
use output::Output;
|
||||||
use tag::Tag;
|
use tag::Tag;
|
||||||
use window::rules::WindowRules;
|
use window::rules::WindowRules;
|
||||||
use window::Window;
|
use window::Window;
|
||||||
pub use xkbcommon::xkb::keysyms;
|
|
||||||
pub use xkbcommon::xkb::Keysym;
|
/// The xkbcommon crate, re-exported for your convenience.
|
||||||
|
pub use xkbcommon;
|
||||||
|
|
||||||
|
/// The prelude for the Pinnacle API.
|
||||||
|
///
|
||||||
|
/// This contains useful imports that you will likely need.
|
||||||
|
/// To that end, you can do `use pinnacle_api::prelude::*` to
|
||||||
|
/// prevent your config file from being cluttered with imports.
|
||||||
|
pub mod prelude {
|
||||||
|
pub use crate::input::Modifier;
|
||||||
|
pub use crate::input::MouseButton;
|
||||||
|
pub use crate::input::MouseEdge;
|
||||||
|
pub use crate::output::AlignmentHorizontal;
|
||||||
|
pub use crate::output::AlignmentVertical;
|
||||||
|
pub use crate::tag::Layout;
|
||||||
|
pub use crate::window::rules::WindowRule;
|
||||||
|
pub use crate::window::rules::WindowRuleCondition;
|
||||||
|
pub use crate::window::FloatingOrTiled;
|
||||||
|
pub use crate::window::FullscreenOrMaximized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Re-exports of every config struct.
|
||||||
|
///
|
||||||
|
/// Usually you can just use the [`Pinnacle`][crate::Pinnacle] struct passed into
|
||||||
|
/// the `setup` function, but if you need access to these elsewhere, here they are.
|
||||||
|
pub mod modules {
|
||||||
|
pub use crate::input::libinput::Libinput;
|
||||||
|
pub use crate::input::Input;
|
||||||
|
pub use crate::output::Output;
|
||||||
|
pub use crate::process::Process;
|
||||||
|
pub use crate::tag::Tag;
|
||||||
|
pub use crate::window::rules::WindowRules;
|
||||||
|
pub use crate::window::Window;
|
||||||
|
}
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
@ -181,6 +211,7 @@ fn request(request: Request) -> RequestResponse {
|
||||||
/// The entry to configuration.
|
/// The entry to configuration.
|
||||||
///
|
///
|
||||||
/// This struct houses every submodule you'll need to configure Pinnacle.
|
/// This struct houses every submodule you'll need to configure Pinnacle.
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Pinnacle {
|
pub struct Pinnacle {
|
||||||
/// Process management.
|
/// Process management.
|
||||||
pub process: Process,
|
pub process: Process,
|
||||||
|
@ -193,3 +224,9 @@ pub struct Pinnacle {
|
||||||
/// Tag management.
|
/// Tag management.
|
||||||
pub tag: Tag,
|
pub tag: Tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Pinnacle {
|
||||||
|
pub fn quit(&self) {
|
||||||
|
send_msg(Msg::Quit).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
input::libinput::LibinputSetting,
|
input::{libinput::LibinputSetting, Modifier, MouseEdge},
|
||||||
output::OutputName,
|
output::OutputName,
|
||||||
tag::{Layout, TagId},
|
tag::{Layout, TagId},
|
||||||
window::{FloatingOrTiled, FullscreenOrMaximized, WindowId},
|
window::{FloatingOrTiled, FullscreenOrMaximized, WindowId},
|
||||||
Modifier, MouseEdge,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Hash, PartialEq, Eq, serde::Serialize, serde::Deserialize, Clone, Copy)]
|
#[derive(Debug, Hash, PartialEq, Eq, serde::Serialize, serde::Deserialize, Clone, Copy)]
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
||||||
pub struct OutputName(pub String);
|
pub struct OutputName(pub String);
|
||||||
|
|
||||||
/// Output management.
|
/// Output management.
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Output;
|
pub struct Output;
|
||||||
|
|
||||||
impl Output {
|
impl Output {
|
||||||
|
@ -246,12 +247,14 @@ enum LeftOrRight {
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum AlignmentHorizontal {
|
pub enum AlignmentHorizontal {
|
||||||
Left,
|
Left,
|
||||||
Center,
|
Center,
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum AlignmentVertical {
|
pub enum AlignmentVertical {
|
||||||
Top,
|
Top,
|
||||||
Center,
|
Center,
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
send_msg, CALLBACK_VEC,
|
send_msg, CALLBACK_VEC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Process;
|
pub struct Process;
|
||||||
|
|
||||||
impl Process {
|
impl Process {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::{
|
||||||
request, send_msg,
|
request, send_msg,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Tag;
|
pub struct Tag;
|
||||||
|
|
||||||
impl Tag {
|
impl Tag {
|
||||||
|
@ -16,9 +17,10 @@ impl Tag {
|
||||||
pub fn get(&self, name: &str, output: Option<&OutputHandle>) -> Option<TagHandle> {
|
pub fn get(&self, name: &str, output: Option<&OutputHandle>) -> Option<TagHandle> {
|
||||||
self.get_all()
|
self.get_all()
|
||||||
.filter(|tag| {
|
.filter(|tag| {
|
||||||
tag.properties()
|
tag.properties().output.is_some_and(|op| match output {
|
||||||
.output
|
Some(output) => &op == output,
|
||||||
.is_some_and(|op| Some(&op) == output)
|
None => Some(op) == Output.get_focused(),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.find(|tag| tag.properties().name.is_some_and(|s| s == name))
|
.find(|tag| tag.properties().name.is_some_and(|s| s == name))
|
||||||
}
|
}
|
||||||
|
@ -29,7 +31,10 @@ impl Tag {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
tag_ids.into_iter().map(TagHandle)
|
tag_ids.into_iter().map(|t| {
|
||||||
|
println!("got tag id {t:?}");
|
||||||
|
TagHandle(t)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return taghandles here
|
// TODO: return taghandles here
|
||||||
|
@ -124,6 +129,7 @@ pub enum TagId {
|
||||||
|
|
||||||
pub struct TagHandle(pub TagId);
|
pub struct TagHandle(pub TagId);
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct TagProperties {
|
pub struct TagProperties {
|
||||||
active: Option<bool>,
|
active: Option<bool>,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
pub mod rules;
|
pub mod rules;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
input::MouseButton,
|
||||||
msg::{Msg, Request, RequestResponse},
|
msg::{Msg, Request, RequestResponse},
|
||||||
request, send_msg,
|
request, send_msg,
|
||||||
tag::TagHandle,
|
tag::TagHandle,
|
||||||
MouseButton,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::rules::WindowRules;
|
use self::rules::WindowRules;
|
||||||
|
@ -19,6 +19,7 @@ pub enum WindowId {
|
||||||
Some(u32),
|
Some(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
pub rules: WindowRules,
|
pub rules: WindowRules,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{msg::Msg, output::OutputHandle, send_msg, tag::TagHandle};
|
||||||
|
|
||||||
use super::{FloatingOrTiled, FullscreenOrMaximized};
|
use super::{FloatingOrTiled, FullscreenOrMaximized};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct WindowRules;
|
pub struct WindowRules;
|
||||||
|
|
||||||
impl WindowRules {
|
impl WindowRules {
|
||||||
|
|
Loading…
Add table
Reference in a new issue