Workaround for xremap crate v0.1.0

I noticed git-based dependencies cannot be published to crates.io.
So I removed the sway feature from crates.io temporarily to finish the
namespace reservation.

I'll make it right in the upcoming release of xremap.
This commit is contained in:
Takashi Kokubun 2021-12-22 20:13:51 -08:00
parent d8b9c0b3e9
commit 26c8c8429f
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD
4 changed files with 4 additions and 96 deletions

21
Cargo.lock generated
View File

@ -597,26 +597,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "swayipc"
version = "3.0.0-alpha.3"
source = "git+https://github.com/k0kubun/swayipc-rs#580b5b6e02b911547c4741bfe240ea8d81d1147c"
dependencies = [
"serde",
"serde_json",
"swayipc-types",
]
[[package]]
name = "swayipc-types"
version = "1.0.0-alpha.3"
source = "git+https://github.com/k0kubun/swayipc-rs#580b5b6e02b911547c4741bfe240ea8d81d1147c"
dependencies = [
"serde",
"serde_json",
"thiserror",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.82" version = "1.0.82"
@ -762,7 +742,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",
"swayipc",
"x11", "x11",
"zbus", "zbus",
] ]

View File

@ -2,6 +2,8 @@
name = "xremap" name = "xremap"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
description = "Dynamic key remapp for X and Wayland"
license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -21,5 +23,4 @@ zbus = "1.9.2"
[features] [features]
gnome = [] gnome = []
sway = []
x11 = [] x11 = []

View File

@ -48,13 +48,6 @@ pub fn build_client() -> WMClient {
WMClient::new("GNOME", Box::new(gnome_client::GnomeClient::new())) WMClient::new("GNOME", Box::new(gnome_client::GnomeClient::new()))
} }
#[cfg(feature = "sway")]
mod sway_client;
#[cfg(feature = "sway")]
pub fn build_client() -> WMClient {
WMClient::new("Sway", Box::new(sway_client::SwayClient::new()))
}
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
mod x11_client; mod x11_client;
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
@ -62,9 +55,9 @@ pub fn build_client() -> WMClient {
WMClient::new("X11", Box::new(x11_client::X11Client::new())) WMClient::new("X11", Box::new(x11_client::X11Client::new()))
} }
#[cfg(not(any(feature = "gnome", feature = "sway", feature = "x11")))] #[cfg(not(any(feature = "gnome", feature = "x11")))]
mod null_client; mod null_client;
#[cfg(not(any(feature = "gnome", feature = "sway", feature = "x11")))] #[cfg(not(any(feature = "gnome", feature = "x11")))]
pub fn build_client() -> WMClient { pub fn build_client() -> WMClient {
WMClient::new("none", Box::new(null_client::NullClient)) WMClient::new("none", Box::new(null_client::NullClient))
} }

View File

@ -1,65 +0,0 @@
use crate::client::Client;
use std::fs::read_dir;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::net::UnixStream;
use swayipc::Connection;
pub struct SwayClient {
connection: Option<Connection>,
}
impl SwayClient {
pub fn new() -> SwayClient {
SwayClient { connection: None }
}
fn connect(&mut self) {
if let None = self.connection {
if let Some(socket) = find_socket() {
if let Ok(unix_stream) = UnixStream::connect(socket) {
self.connection = Some(Connection(unix_stream));
}
}
}
}
}
impl Client for SwayClient {
fn supported(&mut self) -> bool {
self.connect();
self.connection.is_some()
}
fn current_application(&mut self) -> Option<String> {
self.connect();
let connection = match &mut self.connection {
Some(connection) => connection,
None => return None,
};
if let Ok(node) = connection.get_tree() {
if let Some(node) = node.find_focused(|n| n.focused) {
return node.app_id;
}
}
None
}
}
// e.g. "/run/user/1000/sway-ipc.1000.2575.sock"
fn find_socket() -> Option<String> {
let uid = 1000; // Assume a first nornal Linux user. TODO: Make it configurable
if let Some(run_user) = read_dir(format!("/run/user/{}", uid)).as_mut().ok() {
while let Some(entry) = run_user.next() {
let path = entry.ok()?.path();
if let Some(fname) = path.file_name() {
if fname.as_bytes().starts_with(b"sway-ipc.") {
if let Ok(path) = path.into_os_string().into_string() {
return Some(path);
}
}
}
}
}
None
}