mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-19 10:26:36 +01:00
Add convenience methods
This commit is contained in:
parent
5b9450fa8d
commit
e08c653ab4
3 changed files with 163 additions and 4 deletions
|
@ -16,8 +16,6 @@ use crate::tag::TagHandle;
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Output {
|
||||
// client: OutputServiceClient<Channel>,
|
||||
// tag_client: TagServiceClient<Channel>,
|
||||
channel: Channel,
|
||||
fut_sender: UnboundedSender<BoxFuture<'static, ()>>,
|
||||
}
|
||||
|
@ -102,6 +100,22 @@ pub struct OutputHandle {
|
|||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Alignment {
|
||||
TopAlignLeft,
|
||||
TopAlignCenter,
|
||||
TopAlignRight,
|
||||
BottomAlignLeft,
|
||||
BottomAlignCenter,
|
||||
BottomAlignRight,
|
||||
LeftAlignTop,
|
||||
LeftAlignCenter,
|
||||
LeftAlignBottom,
|
||||
RightAlignTop,
|
||||
RightAlignCenter,
|
||||
RightAlignBottom,
|
||||
}
|
||||
|
||||
impl OutputHandle {
|
||||
pub fn set_location(&self, x: Option<i32>, y: Option<i32>) {
|
||||
let mut client = self.client.clone();
|
||||
|
@ -113,8 +127,67 @@ impl OutputHandle {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn set_loc_adj_to(&self, other: &OutputHandle) {
|
||||
todo!()
|
||||
pub fn set_loc_adj_to(&self, other: &OutputHandle, alignment: Alignment) {
|
||||
let self_props = self.props();
|
||||
let other_props = other.props();
|
||||
|
||||
let attempt_set_loc = || -> Option<()> {
|
||||
let other_x = other_props.x?;
|
||||
let other_y = other_props.y?;
|
||||
let other_width = other_props.pixel_width? as i32;
|
||||
let other_height = other_props.pixel_height? as i32;
|
||||
|
||||
let self_width = self_props.pixel_width? as i32;
|
||||
let self_height = self_props.pixel_height? as i32;
|
||||
|
||||
use Alignment::*;
|
||||
|
||||
let x: i32;
|
||||
let y: i32;
|
||||
|
||||
if let TopAlignLeft | TopAlignCenter | TopAlignRight | BottomAlignLeft
|
||||
| BottomAlignCenter | BottomAlignRight = alignment
|
||||
{
|
||||
if let TopAlignLeft | TopAlignCenter | TopAlignRight = alignment {
|
||||
y = other_y - self_height;
|
||||
} else {
|
||||
// bottom
|
||||
y = other_y + other_height;
|
||||
}
|
||||
|
||||
match alignment {
|
||||
TopAlignLeft | BottomAlignLeft => x = other_x,
|
||||
TopAlignCenter | BottomAlignCenter => {
|
||||
x = other_x + (other_width - self_width) / 2;
|
||||
}
|
||||
TopAlignRight | BottomAlignRight => x = other_x + (other_width - self_width),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else {
|
||||
if let LeftAlignTop | LeftAlignCenter | LeftAlignBottom = alignment {
|
||||
x = other_x - self_width;
|
||||
} else {
|
||||
x = other_x + other_width;
|
||||
}
|
||||
|
||||
match alignment {
|
||||
LeftAlignTop | RightAlignTop => y = other_y,
|
||||
LeftAlignCenter | RightAlignCenter => {
|
||||
y = other_y + (other_height - self_height) / 2;
|
||||
}
|
||||
LeftAlignBottom | RightAlignBottom => {
|
||||
y = other_y + (other_height - self_height);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
self.set_location(Some(x), Some(y));
|
||||
|
||||
Some(())
|
||||
};
|
||||
|
||||
attempt_set_loc();
|
||||
}
|
||||
|
||||
pub fn props(&self) -> OutputProperties {
|
||||
|
@ -149,6 +222,52 @@ impl OutputHandle {
|
|||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make a macro for the following or something
|
||||
|
||||
pub fn make(&self) -> Option<String> {
|
||||
self.props().make
|
||||
}
|
||||
|
||||
pub fn model(&self) -> Option<String> {
|
||||
self.props().model
|
||||
}
|
||||
|
||||
pub fn x(&self) -> Option<i32> {
|
||||
self.props().x
|
||||
}
|
||||
|
||||
pub fn y(&self) -> Option<i32> {
|
||||
self.props().y
|
||||
}
|
||||
|
||||
pub fn pixel_width(&self) -> Option<u32> {
|
||||
self.props().pixel_width
|
||||
}
|
||||
|
||||
pub fn pixel_height(&self) -> Option<u32> {
|
||||
self.props().pixel_height
|
||||
}
|
||||
|
||||
pub fn refresh_rate(&self) -> Option<u32> {
|
||||
self.props().refresh_rate
|
||||
}
|
||||
|
||||
pub fn physical_width(&self) -> Option<u32> {
|
||||
self.props().physical_width
|
||||
}
|
||||
|
||||
pub fn physical_height(&self) -> Option<u32> {
|
||||
self.props().physical_height
|
||||
}
|
||||
|
||||
pub fn focused(&self) -> Option<bool> {
|
||||
self.props().focused
|
||||
}
|
||||
|
||||
pub fn tags(&self) -> Vec<TagHandle> {
|
||||
self.props().tags
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -177,6 +177,18 @@ impl TagHandle {
|
|||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn active(&self) -> Option<bool> {
|
||||
self.props().active
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Option<String> {
|
||||
self.props().name
|
||||
}
|
||||
|
||||
pub fn output(&self) -> Option<OutputHandle> {
|
||||
self.props().output
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TagProperties {
|
||||
|
|
|
@ -252,4 +252,32 @@ impl WindowHandle {
|
|||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geometry(&self) -> Option<Geometry> {
|
||||
self.props().geometry
|
||||
}
|
||||
|
||||
pub fn class(&self) -> Option<String> {
|
||||
self.props().class
|
||||
}
|
||||
|
||||
pub fn title(&self) -> Option<String> {
|
||||
self.props().title
|
||||
}
|
||||
|
||||
pub fn focused(&self) -> Option<bool> {
|
||||
self.props().focused
|
||||
}
|
||||
|
||||
pub fn floating(&self) -> Option<bool> {
|
||||
self.props().floating
|
||||
}
|
||||
|
||||
pub fn fullscreen_or_maximized(&self) -> Option<FullscreenOrMaximized> {
|
||||
self.props().fullscreen_or_maximized
|
||||
}
|
||||
|
||||
pub fn tags(&self) -> Vec<TagHandle> {
|
||||
self.props().tags
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue