Skip to content

Commit

Permalink
feat: wip transforming komorebi response
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Feb 27, 2024
1 parent 097ac71 commit 1a7b845
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
30 changes: 29 additions & 1 deletion packages/desktop/src/providers/komorebi/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
};

use async_trait::async_trait;
use komorebi_client::Monitor;
use tokio::{
sync::mpsc::Sender,
task::{self, AbortHandle},
Expand All @@ -17,7 +18,7 @@ use crate::providers::{
variables::ProviderVariables,
};

use super::KomorebiProviderConfig;
use super::{KomorebiMonitor, KomorebiProviderConfig};

const SOCKET_NAME: &str = "zebar.sock";

Expand All @@ -33,6 +34,33 @@ impl KomorebiProvider {
abort_handle: None,
}
}

fn transform_response(
state: komorebi_client::State,
) -> KomorebiVariables {
let monitors = state
.monitors
.elements()
.into_iter()
.map(|&monitor| KomorebiMonitor {
id: monitor.id(),
name: monitor.name().to_string(),
device_id: monitor.device_id().clone(),
size: monitor.size(),
work_area_size: KomorebiRect {
left: size.left,
top: size.top,
right: size.right,
bottom: size.bottom,
},
work_area_offset: monitor.work_area_offset(),
work_area_size: monitor.work_area_size(),
workspaces: monitor.workspaces(),
})
.collect();

KomorebiVariables { monitors }
}
}

#[async_trait]
Expand Down
76 changes: 74 additions & 2 deletions packages/desktop/src/providers/komorebi/variables.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,80 @@
use komorebi_client::{Monitor, Ring};
use serde::Serialize;

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KomorebiVariables {
pub monitors: Ring<Monitor>,
pub monitors: Vec<KomorebiMonitor>,
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KomorebiMonitor {
pub id: isize,
pub name: String,
pub device_id: Option<String>,
pub size: KomorebiRect,
pub work_area_offset: Option<KomorebiRect>,
pub work_area_size: KomorebiRect,
pub workspaces: Vec<KomorebiWorkspace>,
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KomorebiWorkspace {
pub container_padding: u64,
pub floating_windows: Vec<KomorebiWindow>,
pub latest_layout: Vec<KomorebiRect>,
pub layout: KomorebiLayout,
pub layout_flip: Option<KomorebiLayoutFlip>,
pub name: String,
pub maximized_window: Option<KomorebiWindow>,
pub monocle_container: Option<KomorebiWindow>,
pub tiling_containers: Vec<KomorebiWindow>,
pub workspace_padding: u64,
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KomorebiContainer {
pub class: String,
pub exe: String,
pub hwnd: u64,
pub size: KomorebiRect,
pub title: String,
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KomorebiWindow {
pub class: String,
pub exe: String,
pub hwnd: u64,
pub size: KomorebiRect,
pub title: String,
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KomorebiRect {
pub left: u64,
pub top: u64,
pub right: u64,
pub bottom: u64,
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum KomorebiLayout {
Bsp,
VerticalStack,
HorizontalStack,
UltrawideVerticalStack,
Rows,
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum KomorebiLayoutFlip {
Horizontal,
Vertical,
}

0 comments on commit 1a7b845

Please sign in to comment.