Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
- added some comments
- changed behaviour of rofi moving window to new workspace
  • Loading branch information
berezowski committed Oct 30, 2024
1 parent 2c9da6e commit 17e64ce
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 185 deletions.
90 changes: 0 additions & 90 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ version = "0.1.0"
edition = "2021"

[dependencies]
mockall = "0.12.1"
regex = "1.10.4"
swayipc = "3.0.2"
160 changes: 87 additions & 73 deletions src/ipcadapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@ use core::fmt::Debug;
use std::any::Any;
use std::cell::RefCell;
use std::error::Error;
use std::fmt;
use std::rc::Rc;

////////////////////////////////////////////////////////////////////////////////
// INTERFACES
////////////////////////////////////////////////////////////////////////////////

pub type IpcResult = Result<Vec<String>, Box<dyn Error>>;

use std::fmt;

#[derive(Debug)]
pub struct IpcError {
pub command: String,
}

impl Error for IpcError {}
impl fmt::Display for IpcError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Command {} failed", self.command)
}
}

////////////////////////////////////////////////////////////////////////////////
// INTERFACES
////////////////////////////////////////////////////////////////////////////////

pub trait ConnectionProxy {
fn run_command(&mut self, payload: String) -> IpcResult;
fn as_any(&self) -> &dyn Any;
Expand Down Expand Up @@ -70,14 +69,12 @@ impl Debug for dyn OutputProxy {

pub trait IPCAdapter {
///
/// asdfasdfasfdafdsasdf
/// Provides Workspaces, Outputs, as well as a connection from/to sway
///
/// # Examples
///
/// ```
/// # #![allow(unused_mut)]
/// ```
fn new() -> impl IPCAdapter;
///
/// Breaks up ipcAdapter into objects and passing on ownership of those
///
fn explode(
self,
) -> (
Expand All @@ -88,9 +85,21 @@ pub trait IPCAdapter {
}

////////////////////////////////////////////////////////////////////////////////
// TESTING IMPLEMENTATION
// # TESTING IMPLEMENTATION
////////////////////////////////////////////////////////////////////////////////

///
/// Connection implementation for testing
///
/// # Examples
///
/// ```
/// use std::rc::Rc;
/// use swaymsg_workspace::ipcadapter::MockConnection;
///
/// let mockconnection = MockConnection {
/// commandhistory: Rc::new(vec![].into()),
/// };
/// ```
#[derive(Debug)]
pub struct MockConnection {
pub commandhistory: Rc<RefCell<Vec<String>>>,
Expand All @@ -106,6 +115,21 @@ impl ConnectionProxy for MockConnection {
}
}

///
/// Workspace implementation for testing
///
/// # Examples
///
/// ```
/// use swaymsg_workspace::ipcadapter::MockWorkspace;
///
/// let mockworkspace = MockWorkspace {
/// num: Some(1),
/// name: "Foo".to_string(),
/// output: "eDP-1".to_string(),
/// focused: true,
/// };
/// ```
#[derive(Debug)]
pub struct MockWorkspace {
pub num: Option<usize>,
Expand All @@ -129,6 +153,19 @@ impl WorkspaceProxy for MockWorkspace {
}
}

///
/// Output implementation for testing
///
/// # Examples
///
/// ```
/// use swaymsg_workspace::ipcadapter::MockOutput;
///
/// let mockoutput = MockOutput {
/// name: "eDP-1".to_string(),
/// focused: true,
/// };
/// ```
#[derive(Debug)]
pub struct MockOutput {
pub name: String,
Expand All @@ -149,7 +186,23 @@ pub struct MockIPCAdapter {
pub outputs: Vec<Box<dyn OutputProxy>>,
}

///
/// IPCAdapter implementation for testing
///
/// # Examples
///
/// ```
/// use swaymsg_workspace::ipcadapter::MockIPCAdapter;
/// use crate::swaymsg_workspace::ipcadapter::IPCAdapter;
///
/// let mockipcadapter = MockIPCAdapter::new();
/// ```
impl IPCAdapter for MockIPCAdapter {
///
/// ### constructs a basic mocked environment:
/// - 2 Workspaces "Foo" and "Bar"
/// - 1 Output "eDP-1"
///
fn new() -> impl IPCAdapter {
MockIPCAdapter {
connection: RefCell::new(Box::new(MockConnection {
Expand All @@ -160,73 +213,34 @@ impl IPCAdapter for MockIPCAdapter {
num: Some(1),
name: "Foo".to_string(),
output: "eDP-1".to_string(),
focused: false,
focused: true,
}),
Box::new(MockWorkspace {
num: Some(2),
name: "Bar".to_string(),
output: "eDP-1".to_string(),
focused: false,
}),
Box::new(MockWorkspace {
num: Some(3),
name: "Bar".to_string(),
output: "eDP-1".to_string(),
focused: false,
}),
Box::new(MockWorkspace {
num: Some(3),
name: "Bar".to_string(),
output: "HDMI-1".to_string(),
focused: false,
}),
Box::new(MockWorkspace {
num: None,
name: "Span2".to_string(),
output: "eDP-1".to_string(),
focused: false,
}),
Box::new(MockWorkspace {
num: None,
name: "Span2".to_string(),
output: "HDMI-1".to_string(),
focused: false,
}),
Box::new(MockWorkspace {
num: None,
name: "Span3".to_string(),
output: "eDP-1".to_string(),
focused: true,
}),
Box::new(MockWorkspace {
num: None,
name: "Span3".to_string(),
output: "HDMI-1".to_string(),
focused: false,
}),
Box::new(MockWorkspace {
num: None,
name: "Span3".to_string(),
output: "HDMI-2".to_string(),
focused: true,
}),
],
outputs: vec![
Box::new(MockOutput {
focused: false,
name: "eDP-1".to_string(),
}),
Box::new(MockOutput {
focused: true,
name: "HDMI-1".to_string(),
}),
Box::new(MockOutput {
focused: false,
name: "HDMI-2".to_string(),
}),
],
outputs: vec![Box::new(MockOutput {
focused: true,
name: "eDP-1".to_string(),
})],
}
}

///
/// Breaks up ipcAdapter into objects and passing on ownership of those
///
/// # Examples
///
/// ```
/// use swaymsg_workspace::ipcadapter::MockIPCAdapter;
/// use crate::swaymsg_workspace::ipcadapter::IPCAdapter;
///
/// let ipcadapter = MockIPCAdapter::new();
/// let (connection, ipcworkspaces, ipcoutputs) = ipcadapter.explode();
/// ```
fn explode(
self,
) -> (
Expand All @@ -239,7 +253,7 @@ impl IPCAdapter for MockIPCAdapter {
}

////////////////////////////////////////////////////////////////////////////////
// PROD IMPLEMENTATION
// # PROD IMPLEMENTATION
////////////////////////////////////////////////////////////////////////////////

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::panic;
use ipcadapter::IpcResult;
use std::rc::Rc;
use workspaces::extract_starting_number;
use workspaces::find_free_workspace_num;
use workspaces::find_free_adjecent_workspace_num;
use workspaces::Workspace;
use workspaces::Workspaces;
pub mod ipcadapter;
Expand Down Expand Up @@ -166,7 +166,7 @@ pub fn execute_userinput(
Some(_number) => workspaces.move_container_to(&workspacename),
None => workspaces.move_container_to(&format!(
"{} {}",
find_free_workspace_num(&workspaces.on_same_screen()),
find_free_adjecent_workspace_num(&workspaces.on_same_screen()),
&workspacename
)),
},
Expand Down
Loading

0 comments on commit 17e64ce

Please sign in to comment.