mirror of
https://github.com/house-of-vanity/swkb.git
synced 2025-07-07 19:24:07 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
ab127dc580 | |||
ebd4e8fd31 | |||
2ac4101019 | |||
3e2cea8dc0 |
2
.github/workflows/PKGBUILD
vendored
2
.github/workflows/PKGBUILD
vendored
@ -1,7 +1,7 @@
|
||||
# Maintainer: Alexandr Bogomyakov (ultradesu) <ab@hexor.ru>
|
||||
|
||||
pkgname=swkb
|
||||
pkgver=0.2.1
|
||||
pkgver=0.2.4
|
||||
pkgrel=1
|
||||
pkgdesc="swkb"
|
||||
url="https://github.com/house-of-vanity/swkb.git"
|
||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -536,7 +536,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swkb"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"failure",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "swkb"
|
||||
version = "0.2.1"
|
||||
version = "0.2.4"
|
||||
authors = ["Alexandr Bogomyakov <abogomyakov@iponweb.net>"]
|
||||
edition = "2018"
|
||||
|
||||
@ -21,3 +21,7 @@ unstable = []
|
||||
|
||||
#[dependencies.swayipc]
|
||||
#features = ["async", "event_stream"]
|
||||
|
||||
[packaging]
|
||||
depends = ["sway"]
|
||||
makedepends = ["cargo", "git"]
|
||||
|
33
PKGBUILD
Normal file
33
PKGBUILD
Normal file
@ -0,0 +1,33 @@
|
||||
# Maintainer:
|
||||
|
||||
pkgname=
|
||||
pkgver=
|
||||
pkgrel=1
|
||||
pkgdesc=
|
||||
url=
|
||||
arch=($CARCH)
|
||||
license=
|
||||
depends=()
|
||||
makedepends=()
|
||||
source=("git+https://github.com/house-of-vanity/$pkgname")
|
||||
sha512sums=('SKIP')
|
||||
|
||||
pkgver() {
|
||||
cd "$srcdir/$pkgname"
|
||||
git describe --long --tags | awk -F '-' '{print $1}'| sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
|
||||
}
|
||||
|
||||
prepare() {
|
||||
cd "$srcdir/$pkgname"
|
||||
cargo fetch --target $CARCH-unknown-linux-gnu
|
||||
}
|
||||
|
||||
build() {
|
||||
cd "$srcdir/$pkgname"
|
||||
cargo build --release --frozen --all-targets --all-features
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$srcdir/$pkgname"
|
||||
install -Dt "$pkgdir/usr/bin" target/release/$pkgname
|
||||
}
|
33
assets/PKGBUILD.jinja
Normal file
33
assets/PKGBUILD.jinja
Normal file
@ -0,0 +1,33 @@
|
||||
# Maintainer: {{ config.authors }}
|
||||
|
||||
pkgname={{ config.name }}
|
||||
pkgver={{ config.version }}
|
||||
pkgrel=1
|
||||
pkgdesc={{ config.desc }}
|
||||
url={{ config.url }}
|
||||
arch=($CARCH)
|
||||
license={{ config.licence }}
|
||||
depends=({{ config.depends }})
|
||||
makedepends=({{ config.makedepends }})
|
||||
source=("git+https://github.com/house-of-vanity/$pkgname")
|
||||
sha512sums=('SKIP')
|
||||
|
||||
pkgver() {
|
||||
cd "$srcdir/$pkgname"
|
||||
git describe --long --tags | awk -F '-' '{print $1}'| sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
|
||||
}
|
||||
|
||||
prepare() {
|
||||
cd "$srcdir/$pkgname"
|
||||
cargo fetch --target $CARCH-unknown-linux-gnu
|
||||
}
|
||||
|
||||
build() {
|
||||
cd "$srcdir/$pkgname"
|
||||
cargo build --release --frozen --all-targets --all-features
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$srcdir/$pkgname"
|
||||
install -Dt "$pkgdir/usr/bin" target/release/$pkgname
|
||||
}
|
26
src/main.rs
26
src/main.rs
@ -7,17 +7,26 @@ use swayipc::{Connection, EventType, Fallible};
|
||||
|
||||
async fn get_input_id() -> Vec<String> {
|
||||
let mut connection = Connection::new().await.unwrap();
|
||||
let inputs = connection.get_inputs().await.unwrap();
|
||||
let mut ids: Vec<String> = Vec::new();
|
||||
match connection.get_inputs().await {
|
||||
Ok(inputs) => {
|
||||
for i in inputs {
|
||||
ids.push(i.identifier);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
ids
|
||||
}
|
||||
|
||||
async fn get_focus_id() -> i64 {
|
||||
let mut connection = Connection::new().await.unwrap();
|
||||
let tree = connection.get_tree().await.unwrap();
|
||||
let tree = match connection.get_tree().await {
|
||||
Ok(tree) => tree,
|
||||
Err(_) => {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
let mut focused: i64 = 0;
|
||||
for i in tree.nodes {
|
||||
for z in i.nodes {
|
||||
@ -48,15 +57,21 @@ async fn main() -> Fallible<()> {
|
||||
while let Some(event) = events.next().await {
|
||||
match event {
|
||||
Ok(Event::Input(event)) => {
|
||||
//println!("Input: {:?}", event);
|
||||
let layouts_list = event.input.xkb_layout_names;
|
||||
let layout_name = event.input.xkb_active_layout_name.unwrap();
|
||||
let index = layouts_list.iter().position(|r| *r == layout_name).unwrap() as i64;
|
||||
let layout_name = event.input.xkb_active_layout_name.unwrap_or("none".to_string());
|
||||
if layout_name == "none" {
|
||||
continue
|
||||
}
|
||||
let index = layouts_list.iter().position(|r| *r == layout_name).unwrap_or(0) as i64;
|
||||
let mut layouts = layouts.lock().unwrap();
|
||||
let current_window = get_focus_id().await;
|
||||
//println!("Layout saved [{:?}] for {:?}", layout_name, current_window);
|
||||
layouts.insert(current_window, index);
|
||||
}
|
||||
Ok(Event::Window(event)) => match event.change {
|
||||
Ok(Event::Window(event)) => {
|
||||
//println!("Window: {:?}", event);
|
||||
match event.change {
|
||||
swayipc::reply::WindowChange::Focus => {
|
||||
let layouts = layouts.lock().unwrap();
|
||||
let mut connection = Connection::new().await?;
|
||||
@ -84,6 +99,7 @@ async fn main() -> Fallible<()> {
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
44
tmp_builder.py
Normal file
44
tmp_builder.py
Normal file
@ -0,0 +1,44 @@
|
||||
from jinja2 import Environment, PackageLoader, FileSystemLoader
|
||||
|
||||
cargo = dict()
|
||||
|
||||
|
||||
# async-std = { version = "1.6", features = ["attributes", "unstable"], optional = true }
|
||||
|
||||
|
||||
|
||||
def parse_line(val):
|
||||
result = dict()
|
||||
attr, value = line.split("=", maxsplit=1)
|
||||
result[value] = dict()
|
||||
|
||||
return result
|
||||
|
||||
def parse(filename='Cargo.toml'):
|
||||
with open(filename) as cargo_file:
|
||||
level = ''
|
||||
for line in cargo_file.readlines():
|
||||
if line[0] == '#' or line[0] == '\n':
|
||||
continue
|
||||
|
||||
print("line is ", (line, len(line)))
|
||||
|
||||
if line[0] == '[':
|
||||
attr = line.replace('[', '').replace(']', '').strip()
|
||||
cargo[attr] = dict()
|
||||
level = attr
|
||||
continue
|
||||
|
||||
value = parse_line(line)
|
||||
print(value)
|
||||
cargo[level] += value
|
||||
|
||||
print(cargo)
|
||||
|
||||
config = {}
|
||||
|
||||
with open("PKGBUILD", "w") as rcfile_obj:
|
||||
file_loader = Environment(loader=FileSystemLoader('assets'))
|
||||
template = file_loader.get_template('PKGBUILD.jinja')
|
||||
output = template.render(config=config)
|
||||
rcfile_obj.write(output+ "\n")
|
Reference in New Issue
Block a user