Skip to content

Commit

Permalink
rust-api: Better layout API
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottatop committed Jan 7, 2025
1 parent 787abce commit fa01293
Show file tree
Hide file tree
Showing 15 changed files with 1,372 additions and 800 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ indexmap = { workspace = true }
snowcap = { path = "./snowcap", optional = true }
snowcap-api = { path = "./snowcap/api/rust", optional = true }
assert_matches = "1.5.0"
taffy = "0.7.2"
treediff = "5.0.0"

[build-dependencies]
vergen-gitcl = { version = "1.0.2", features = ["rustc", "cargo", "si"] }
Expand Down
55 changes: 55 additions & 0 deletions api/protobuf/pinnacle/layout/v1/layout.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
syntax = "proto3";

package pinnacle.layout.v1;

message LayoutTree {
uint32 tree_id = 1;
float outer_gaps = 2;
float inner_gaps = 3;
LayoutNode root = 4;
}

message LayoutNode {
uint32 node_id = 1;
NodeStyle style = 2;
repeated LayoutNode children = 3;
}

enum FlexDir {
FLEX_DIR_UNSPECIFIED = 0;
FLEX_DIR_ROW = 1;
FLEX_DIR_COLUMN = 2;
}

message NodeStyle {
FlexDir flex_dir = 1;
float size_proportion = 2;
}

message LayoutRequest {
message TreeResponse {
uint32 request_id = 1;
LayoutTree tree = 2;
string output_name = 3;
}

message ForceLayout {
string output_name = 1;
}

oneof request {
TreeResponse tree_response = 1;
ForceLayout force_layout = 2;
}
}

message LayoutResponse {
uint32 request_id = 1;
string output_name = 2;
uint32 window_count = 3;
repeated uint32 tag_ids = 4;
}

service LayoutService {
rpc Layout(stream LayoutRequest) returns (stream LayoutResponse);
}
24 changes: 12 additions & 12 deletions api/rust/examples/default_config/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ use pinnacle_api::input::libinput::Capability;
use pinnacle_api::input::Bind;
use pinnacle_api::input::BindLayer;
use pinnacle_api::input::Keysym;
use pinnacle_api::layout::{
CornerLayout, CornerLocation, CyclingLayoutManager, DwindleLayout, FairLayout, MasterSide,
MasterStackLayout, SpiralLayout,
};
use pinnacle_api::layout;
use pinnacle_api::layout::CornerLayout;
use pinnacle_api::layout::CornerLocation;
use pinnacle_api::layout::CyclingLayoutManager;
use pinnacle_api::layout::DwindleLayout;
use pinnacle_api::layout::FairLayout;
use pinnacle_api::layout::MasterSide;
use pinnacle_api::layout::MasterStackLayout;
use pinnacle_api::layout::SpiralLayout;
use pinnacle_api::output;
use pinnacle_api::output::OutputSetup;
use pinnacle_api::pinnacle;
Expand All @@ -34,7 +39,6 @@ async fn main() {
// Deconstruct to get all the APIs.
#[allow(unused_variables)]
let ApiModules {
layout,
render,
#[cfg(feature = "snowcap")]
snowcap,
Expand Down Expand Up @@ -230,7 +234,8 @@ async fn main() {
// Create a `CyclingLayoutManager` that can cycle between layouts on different tags.
//
// It takes in some layout generators that need to be boxed and dyn-coerced.
let layout_requester = layout.set_manager(CyclingLayoutManager::new([

let layout_requester = layout::set_manager(CyclingLayoutManager::new([
Box::<MasterStackLayout>::default() as _,
Box::new(MasterStackLayout {
master_side: MasterSide::Right,
Expand Down Expand Up @@ -295,7 +300,7 @@ async fn main() {
};
let Some(first_active_tag) = focused_op
.tags()
.batch_find(|tg| Box::pin(tg.active_async()), |active| *active)
.batch_find(|tag| Box::pin(tag.active_async()), |active| *active)
else {
return;
};
Expand Down Expand Up @@ -362,11 +367,6 @@ async fn main() {
}

input::libinput::for_all_devices(|device| {
// TODO: remove this
if device.capabilities().contains(Capability::POINTER) {
device.set_accel_profile(AccelProfile::Flat);
}

if device.get_type().is_touchpad() {
device.set_natural_scroll(true);
}
Expand Down
7 changes: 7 additions & 0 deletions api/rust/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use pinnacle_api_defs::pinnacle::{
input::v1::input_service_client::InputServiceClient,
layout::v1::layout_service_client::LayoutServiceClient,
output::v1::output_service_client::OutputServiceClient,
process::v1::process_service_client::ProcessServiceClient,
tag::v1::tag_service_client::TagServiceClient,
Expand All @@ -20,6 +21,7 @@ pub struct Client {
output: OutputServiceClient<Channel>,
input: InputServiceClient<Channel>,
process: ProcessServiceClient<Channel>,
layout: LayoutServiceClient<Channel>,
}

impl Client {
Expand Down Expand Up @@ -59,6 +61,10 @@ impl Client {
Self::get().process.clone()
}

pub fn layout() -> LayoutServiceClient<Channel> {
Self::get().layout.clone()
}

fn new(channel: Channel) -> Self {
Self {
pinnacle: PinnacleServiceClient::new(channel.clone()),
Expand All @@ -67,6 +73,7 @@ impl Client {
output: OutputServiceClient::new(channel.clone()),
input: InputServiceClient::new(channel.clone()),
process: ProcessServiceClient::new(channel.clone()),
layout: LayoutServiceClient::new(channel.clone()),
}
}
}
Expand Down
Loading

0 comments on commit fa01293

Please sign in to comment.