Skip to content

Commit

Permalink
Initial commit 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBackx committed May 24, 2021
0 parents commit 384d178
Show file tree
Hide file tree
Showing 9 changed files with 773 additions and 0 deletions.
98 changes: 98 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

# Created by https://www.toptal.com/developers/gitignore/api/rust,linux,windows,macos,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,linux,windows,macos,visualstudiocode

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Rust ###
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/rust,linux,windows,macos,visualstudiocode

41 changes: 41 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'waycorner'",
"cargo": {
"args": ["build", "--bin=waycorner", "--package=waycorner"],
"filter": {
"name": "waycorner",
"kind": "bin"
}
},
"args": ["--preview"],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'waycorner'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=waycorner",
"--package=waycorner"
],
"filter": {
"name": "waycorner",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
19 changes: 19 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "waycorner"
version = "0.1.0"
authors = ["Andreas Backx"]
edition = "2018"

[dependencies]
anyhow = "1.0"
clap = "3.0.0-beta.2"
crossbeam-utils = "0.8.4"
env_logger = "0.8.3"
log = "0.4.0"
regex = "1.5"
serde = { version = "1.0.125", features = ["derive"] }
smithay-client-toolkit = "0.13.0"
tempfile = "3.2.0"
toml = "0.5.8"
wayland-client = "0.28.5"
wayland-protocols = "0.28.5"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Andreas Backx

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# waycorner

Hot corners for Wayland. Waycorner allows you to create anchors on specified locations of your monitors and execute a command of your choice.

_Note: Currently only tested on swaywm. Though it should work on any Wayland compositor that supports the xdg-output protocol._

## Installation

Currently only available on AUR. Feel free to make an issue if you would like to see it elsewhere and have some time available to help.

### Manually

```zsh
git clone [email protected]:AndreasBackx/waycorner.git
cd waycorner
cargo install --path .
```

## Configuration

Default configuration location is `~/.config/waycorner/config.toml`, this needs to be created manually. You can also specify a different location using `--config`. Preview your configuration with the `--preview` flag.

```toml
[left]
# Shell command to execute when hotcorner is triggered.
command = "lock" # required

# Locations of the hot corners.
# Options: top_left, top_right, bottom_right, and bottom_left.
locations = ["bottom_right", "bottom_left"] # default

# Size of the hot corners in pixels.
size = 10 # default

# Timeout in milliseconds before command is triggered.
timeout_ms = 250 # default

# Optional output config to specify what output to use.
[left.output]
# Regex to match output descriptions on.
# Regex engine is similar to RE2: https://github.com/rust-lang/regex
#
# Use `swaymsg -t get_outputs` to get a list of outputs in the format:
# Output ${NAME} '${DESCRIPTION}'
description = "" # default, empty means all outputs
```

Then add `exec waycorner` to your swaywm config.

## Logging

Pass `RUST_LOG` with either `trace`, `debug`, `info`, `warn`, or `error`. To set the logging level, default is `error`. See [env_logger documentation](https://docs.rs/env_logger/0.8.3/env_logger/).
73 changes: 73 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use std::{collections::HashMap, env, fs::File, io::Read, path::PathBuf};

use anyhow::{Context, Error, Result};
use serde::Deserialize;

fn default_locations() -> Vec<Location> {
vec![Location::BottomRight, Location::BottomLeft]
}

fn default_size() -> u8 {
10
}

fn default_timeout_ms() -> u16 {
250
}

#[derive(Clone, Debug, Deserialize)]
pub struct CornerConfig {
pub output: Option<OutputConfig>,
pub command: Vec<String>,
#[serde(default = "default_locations")]
pub locations: Vec<Location>,
#[serde(default = "default_size")]
pub size: u8,
#[serde(default = "default_timeout_ms")]
pub timeout_ms: u16,
}

#[derive(Clone, Debug, Deserialize)]
pub struct OutputConfig {
pub description: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Location {
TopLeft,
TopRight,
BottomRight,
BottomLeft,
}

type Config = HashMap<String, CornerConfig>;

pub fn get_configs(config_path: PathBuf) -> Result<Vec<CornerConfig>> {
let path = if config_path.starts_with("~/") {
debug!("Replacing ~/ with $HOME/");
let home_path = env::var_os("HOME")
.expect("could not find the $HOME env var to use for the default config path");
let relative_path = config_path
.to_str()
.expect(format!("invalid config path specified: {}", config_path.display()).as_str())
.to_string()
.split_off(2);
PathBuf::from(home_path).join(relative_path)
} else {
config_path
};
info!("Using config: {}", path.display());
let mut config_file = File::open(path.clone())
.with_context(|| format!("could not open the file {}", path.display()))?;
let mut config_content = String::new();
config_file.read_to_string(&mut config_content)?;
toml::from_str::<Config>(config_content.as_str())
.map_err(|error| -> Error { error.into() })
.with_context(|| format!("could not parse {}", path.display()))
.map(|item| {
item.into_iter()
.map(|(_key, value)| value)
.collect::<Vec<_>>()
})
}
Loading

0 comments on commit 384d178

Please sign in to comment.