-
Notifications
You must be signed in to change notification settings - Fork 0
feat(rs): xcb and wmctl backends #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2b871d7
chore(rs): move client to i3 backend
mibli 0619b6f
refactor(rs): move json logic to backend
mibli 54ab984
chore(rs): create backend traits
mibli 4b2f7e8
feat(rs): encapsulate i3 in a backend
mibli 4c0bdc4
refactor(rs): move cli to its own module
mibli 97d17ba
feat(rs): add wmctl backend
mibli ecc69a7
feat(rs): support backend selection
mibli e3bcc0e
feat(rs): add backend cli option
mibli fd1c113
feat(rs): add xcb backend
mibli 73e5fdd
fix(rs): use normalized positions and withdrawn state
mibli 849acd1
feat(rs): add cli option for xcb
mibli 9b12725
fix(rs): fetch full window info per window
mibli f553fdb
feat(rs): enjoyable cli interface
mibli a9143a2
feat(rs): allow selecting features to compile
mibli 2798f9e
refactor(rs): overhaul logging and drop deps
mibli a2eb874
build(rs): added libxcb dependencies
mibli 420b1ec
refactor(rs): move instead of cloning in as_arrangement
mibli 1a10cc4
refactor(rs): consolidate converters into navigation
mibli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #[cfg(feature = "i3")] | ||
| use crate::backend::i3; | ||
| #[cfg(feature = "wmctl")] | ||
| use crate::backend::wmctl; | ||
| #[cfg(feature = "xcb")] | ||
| use crate::backend::xcb; | ||
|
|
||
| use crate::backend::traits::*; | ||
| use crate::types::Windows; | ||
|
|
||
| pub enum UsedBackend { | ||
| #[cfg(feature = "i3")] | ||
| I3(i3::Backend), | ||
| #[cfg(feature = "wmctl")] | ||
| WmCtl(wmctl::Backend), | ||
| #[cfg(feature = "xcb")] | ||
| Xcb(xcb::Backend), | ||
| } | ||
|
|
||
| pub struct Backend { | ||
| used_backend: UsedBackend, | ||
| } | ||
|
|
||
| impl Backend { | ||
| pub fn new(use_backend: UsedBackend) -> Self { | ||
| Self { | ||
| used_backend: use_backend, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl GetTabs for Backend { | ||
| fn get_tabs(&self) -> Result<Windows, String> { | ||
| match self.used_backend { | ||
| #[cfg(feature = "i3")] | ||
| UsedBackend::I3(ref i3) => i3.get_tabs(), | ||
| #[cfg(feature = "wmctl")] | ||
| UsedBackend::WmCtl(ref wmctl) => wmctl.get_tabs(), | ||
| #[cfg(feature = "xcb")] | ||
| UsedBackend::Xcb(ref xcb) => xcb.get_tabs(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl GetVisible for Backend { | ||
| fn get_visible(&self) -> Result<Windows, String> { | ||
| match self.used_backend { | ||
| #[cfg(feature = "i3")] | ||
| UsedBackend::I3(ref i3) => i3.get_visible(), | ||
| #[cfg(feature = "wmctl")] | ||
| UsedBackend::WmCtl(ref wmctl) => wmctl.get_visible(), | ||
| #[cfg(feature = "xcb")] | ||
| UsedBackend::Xcb(ref xcb) => xcb.get_visible(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl SetFocus for Backend { | ||
| fn set_focus(& mut self, id: &u64) { | ||
| match self.used_backend { | ||
| #[cfg(feature = "i3")] | ||
| UsedBackend::I3(ref mut i3) => i3.set_focus(id), | ||
| #[cfg(feature = "wmctl")] | ||
| UsedBackend::WmCtl(ref mut wmctl) => wmctl.set_focus(id), | ||
| #[cfg(feature = "xcb")] | ||
| UsedBackend::Xcb(ref mut xcb) => xcb.set_focus(id), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| use crate::backend::traits::*; | ||
| use crate::logging::ResultExt; | ||
| use crate::logging; | ||
| use crate::types::Windows; | ||
| use super::client::{Client, Request}; | ||
| use super::compass; | ||
|
|
||
| use serde_json as json; | ||
| use std::process; | ||
|
|
||
| pub struct Backend { | ||
| client: Client, | ||
| root: json::Value, | ||
| } | ||
|
|
||
| impl Backend { | ||
| pub fn new() -> Self { | ||
| // Establish a connection to the i3 IPC server and get the tree structure | ||
| let i3_socket_path_output = process::Command::new("i3").arg("--get-socketpath").output() | ||
| .expect_log("Failed to get i3 socket path"); | ||
| let i3_path = String::from_utf8(i3_socket_path_output.stdout) | ||
| .expect_log("Failed to parse i3 socket path output"); | ||
| let mut client = Client::new(&i3_path.trim()) | ||
| .expect_log("Failed to connect to i3 IPC server"); | ||
| let root_string = client.request(Request::GetTree, "") | ||
| .expect_log("Failed to get i3 tree JSON"); | ||
|
|
||
| // Parse the i3 tree to get the current workspace and window information | ||
| let root = json::from_str::<json::Value>(&root_string) | ||
| .expect_log("Failed to parse i3 tree JSON"); | ||
| Self { | ||
| client, | ||
| root, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl GetTabs for Backend { | ||
| fn get_tabs(&self) -> Result<Windows, String> { | ||
| let nodes = compass::available_tabs(&self.root); | ||
| Ok(compass::to_windows(nodes)) | ||
| } | ||
| } | ||
|
|
||
| impl GetVisible for Backend { | ||
| fn get_visible(&self) -> Result<Windows, String> { | ||
| let nodes = compass::visible_nodes(&self.root); | ||
| Ok(compass::to_windows(nodes)) | ||
| } | ||
| } | ||
|
|
||
| impl SetFocus for Backend { | ||
| fn set_focus(& mut self, window_id: &u64) { | ||
| // Focus the window with the determined ID | ||
| logging::info!("Focusing window with ID: {}", window_id); | ||
| let payload = format!("[con_id={}] focus", window_id); | ||
| self.client.request(Request::Command, &payload) | ||
| .expect_log("Failed to send focus command"); | ||
| } | ||
| } |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.