Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ clap = { version = "4.3.0", features = ["derive"] }
crossbeam-utils = "0.8.15"
regex = "1.8"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.143"
smithay-client-toolkit = "0.16.1"
toml = "0.7.4"
tracing = "0.1.37"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ timeout_ms = 250 # default
# (Useful for debugging purposes when setting up several hot corners.)
color = "#FFFF0000" # default

# Whether waycorner should work when fullscreen
disable_when_fullscreen = true # default

# Optional output config to specify what output to use.
[main-monitor.output]
# Regex to match output descriptions on.
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ fn default_command() -> Vec<String> {
Vec::new()
}

fn default_disable_when_fullscreen() -> bool {
true
}

fn from_hex<'de, D>(deserializer: D) -> Result<u32, D::Error>
where
D: Deserializer<'de>,
Expand Down Expand Up @@ -77,6 +81,8 @@ pub struct CornerConfig {
pub timeout_ms: u16,
#[serde(default = "default_color", deserialize_with = "from_hex")]
pub color: u32,
#[serde(default = "default_disable_when_fullscreen")]
pub disable_when_fullscreen: bool,
}

#[derive(Clone, Debug, Deserialize)]
Expand Down
40 changes: 35 additions & 5 deletions src/corner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use std::{
Arc, Mutex,
},
time::{Duration, Instant},
env,
};

use anyhow::Result;
use regex::Regex;
use tracing::{debug, info};
use serde_json::{Value, from_slice};

use crate::config::CornerConfig;

Expand Down Expand Up @@ -66,12 +68,16 @@ impl Corner {
}
Err(_error) => {
if let Some(event) = last_event {
if event == CornerEvent::Enter {
self.execute_command(&self.config.enter_command)?;
} else if event == CornerEvent::Leave {
self.execute_command(&self.config.exit_command)?;
if self.config.disable_when_fullscreen && self.is_fullscreen() {
debug!("In fullscreen mode");
} else {
if event == CornerEvent::Enter {
self.execute_command(&self.config.enter_command)?;
} else if event == CornerEvent::Leave {
self.execute_command(&self.config.exit_command)?;
}
command_done_at = Some(Instant::now());
}
command_done_at = Some(Instant::now());
}
last_event = None;
}
Expand Down Expand Up @@ -108,6 +114,30 @@ impl Corner {
.unwrap_or(true)
}

pub fn is_fullscreen(&self) -> bool {
let desktop = env::var("XDG_CURRENT_DESKTOP")
.ok()
.map(|s| s.to_lowercase());
match desktop.as_deref() {
Some("hyprland") => {
let status = Command::new("hyprctl")
.args(["activewindow", "-j"])
.output()
.ok()
.and_then(|output| from_slice::<Value>(&output.stdout).ok())
.unwrap()
.get("fullscreen")
.and_then(|v| v.as_i64());
return status == Some(2);
},
Some("sway") => {
// TODO: add sway equivalent
return false;
},
_ => false
}
}

fn execute_command(&self, command: &[String]) -> Result<()> {
if let Some(binary) = command.first() {
let args = command
Expand Down