mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-10 03:03:41 +02:00
This commit ensures that new features such as stackbar, particularly where the configuration is located in the global state, can be configured via SocketMessages. A few structs had to be moved to komorebi-core to make this possible. I've also cleaned up a bunch of strum snake_case attrs which seemed to be unused. A new GlobalState SocketMessage has been introduced, and going forward we should make sure that this can send all global state to a requester, and move global state out of the State handler, which should only handle window manager state.
66 lines
1.7 KiB
Rust
66 lines
1.7 KiB
Rust
use std::num::NonZeroUsize;
|
|
|
|
use clap::ValueEnum;
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use strum::Display;
|
|
use strum::EnumString;
|
|
|
|
use crate::direction::Direction;
|
|
use crate::Axis;
|
|
|
|
#[derive(
|
|
Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum, JsonSchema,
|
|
)]
|
|
pub enum OperationDirection {
|
|
Left,
|
|
Right,
|
|
Up,
|
|
Down,
|
|
}
|
|
|
|
impl OperationDirection {
|
|
#[must_use]
|
|
pub const fn opposite(self) -> Self {
|
|
match self {
|
|
Self::Left => Self::Right,
|
|
Self::Right => Self::Left,
|
|
Self::Up => Self::Down,
|
|
Self::Down => Self::Up,
|
|
}
|
|
}
|
|
|
|
fn flip(self, layout_flip: Option<Axis>) -> Self {
|
|
layout_flip.map_or(self, |flip| match self {
|
|
Self::Left => match flip {
|
|
Axis::Horizontal | Axis::HorizontalAndVertical => Self::Right,
|
|
Axis::Vertical => self,
|
|
},
|
|
Self::Right => match flip {
|
|
Axis::Horizontal | Axis::HorizontalAndVertical => Self::Left,
|
|
Axis::Vertical => self,
|
|
},
|
|
Self::Up => match flip {
|
|
Axis::Vertical | Axis::HorizontalAndVertical => Self::Down,
|
|
Axis::Horizontal => self,
|
|
},
|
|
Self::Down => match flip {
|
|
Axis::Vertical | Axis::HorizontalAndVertical => Self::Up,
|
|
Axis::Horizontal => self,
|
|
},
|
|
})
|
|
}
|
|
|
|
#[must_use]
|
|
pub fn destination(
|
|
self,
|
|
layout: &dyn Direction,
|
|
layout_flip: Option<Axis>,
|
|
idx: usize,
|
|
len: NonZeroUsize,
|
|
) -> Option<usize> {
|
|
layout.index_in_direction(self.flip(layout_flip), idx, len.get())
|
|
}
|
|
}
|