Crates.io | ksway |
lib.rs | ksway |
version | 0.1.0 |
source | src |
created_at | 2019-07-18 00:54:54.84744 |
updated_at | 2019-07-28 02:22:53.50136 |
description | Crate for interfacing with sway/i3 ipc |
homepage | https://github.com/norcalli/ksway/ |
repository | https://github.com/norcalli/ksway/ |
max_upload_size | |
id | 149781 |
size | 44,240 |
ksway
This library provides a convenient interface for quickly making scripts for
i3
and sway
(since they share an IPC
interface API). It will mainly be focused on sway
if that compatibility
changes.
It will also be a container for the many scripts I use on a daily basis which
live under examples/
.
Those examples are the best resource for learning how to use this for complex situations, but here are some small examples:
let mut client = Client::connect()?;
let mut client = Client::connect_to_path("/run/user/1000/sway-ipc.1000.1.sock")?;
The criteria
implementation is complete and up to date as of 2019-07-27.
use ksway::{ipc_command, command};
// These are equivalent
client.ipc(ipc_command::run("exec st"))?;
client.ipc(ipc_command::run(command::raw("exec st"))?;
client.ipc(ipc_command::run(command::exec("st"))?;
client.run(command::exec("st"))?;
// The benefit of using command is the additional methods such as .with_criteria
use ksway::criteria::*;
let cmd = command::raw("focus").with_criteria(vec![floating(), title("mpv")]);
client.run(cmd)?;
// criteria examples
let cmd = command::raw("focus").with_criteria(vec![workspace(focused())]);
let cmd = command::raw("focus").with_criteria(vec![con_id(123)])
let cmd = command::raw("focus").with_criteria(vec![con_id(focused())])
get_*
use ksway::ipc_command;
client.ipc(ipc_command::get_tree())?;
let tree_data = json::parse(str::from_utf8(&client.ipc(ipc_command::get_tree())?)?)?;
client.ipc(ipc_command::get_workspaces())?;
client.ipc(ipc_command::get_version())?;
use ksway::IpcEvent;
let rx = client.subscribe(vec![IpcEvent::Window, IpcEvent::Tick])?;
loop {
while let Ok((payload_type, payload)) = rx.try_recv() {
match payload_type {
IpcEvent::Window => {},
_ => {},
}
}
client.poll()?;
}
examples/sway-focused-window $PATH
: Outputs the json for the currently focused window with no arguments, but you can additionally specify a path to extract, e.g.
sway-focused-window
-> full jsonsway-focused-window window_rect width
sway-focused-window window_properties title
sway-focused-window id
examples/sway-focus-next $INCREMENT $EXPRESSIONS
: Focus the next window which matches the criteria matched by $EXPRESSIONS
. By next, I mean, it will try to find the next window after the currently focused one (if the focused one is included in the set of windows specified by $EXPRESSIONS, otherwise it will choose the first window).
sway-focus-next 1 visible==true
sway-focus-next 1 type==floating
sway-focus-next 1 visible==true type==$(sway-focused-window type)
sway-focus-next -1 visible==true type==$(sway-focused-window type)
examples/watch-sway-windows
: Run rules based on the current windows. This is highly personal and customized for my needs and not very well documented.
serde
typed interface under a feature gate. I plan to generate this with json_typegen
.ksway::command::*
, such as resize
and whatnot.ipc_json
method for deserializing to json
or serde_json
?