Skip to content
Merged
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
16 changes: 9 additions & 7 deletions crates/hacknetd/src/backend/hypr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ impl Backend for Hyprland {
.unwrap_or(false),
floating: c.get("floating").and_then(Value::as_bool).unwrap_or(false),
sticky: c.get("pinned").and_then(Value::as_bool).unwrap_or(false),
fullscreen: c
.get("fullscreen")
.and_then(Value::as_i64)
.map(|v| v > 0)
.or_else(|| c.get("fullscreen").and_then(Value::as_bool))
.unwrap_or(false),
rect: Rect::new(xy(at, 0), xy(at, 1), xy(size, 0), xy(size, 1)),
});
}
Expand Down Expand Up @@ -150,13 +156,9 @@ impl Backend for Hyprland {
cmd("hyprctl", &["reload".into()]).map(|_| ())
}

fn native_fullscreen(&self, id: &str, on: bool) -> Result<(), String> {
self.dispatch(&[
"fullscreen",
if on { "1" } else { "0" },
&format!("address:0x{}", id.trim_start_matches("0x")),
])
.map(|_| ())
fn native_fullscreen(&self, id: &str, _on: bool) -> Result<(), String> {
self.dispatch_window("focuswindow", id)?;
self.dispatch(&["fullscreen", "0"]).map(|_| ())
}

fn output_size(&self) -> Option<(i32, i32)> {
Expand Down
1 change: 1 addition & 0 deletions crates/hacknetd/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct RawWindow {
pub active: bool,
pub floating: bool,
pub sticky: bool,
pub fullscreen: bool,
pub rect: Rect,
}

Expand Down
5 changes: 5 additions & 0 deletions crates/hacknetd/src/backend/sway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ fn walk(node: &Value, workspace: i32, floating: bool, out: &mut Vec<RawWindow>)
.unwrap_or(false),
floating,
sticky: node.get("sticky").and_then(Value::as_bool).unwrap_or(false),
fullscreen: node
.get("fullscreen_mode")
.and_then(Value::as_i64)
.unwrap_or(0)
> 0,
rect: Rect::new(g("x"), g("y"), g("width"), g("height")),
});
}
Expand Down
97 changes: 76 additions & 21 deletions crates/hacknetd/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,23 @@ impl Engine {
}
}
Zone::Stage => {
// Place inside the viewport below the caption and window
// title strip, never over the shell chrome.
eff_rect = self.compiled.rects.stage_app;
actions.push(Action::Place {
w: r.clone(),
rect: eff_rect,
sticky: false,
});
if r.fullscreen {
self.fullscreen_window = Some(r.id.clone());
self.placed.remove(&r.id);
} else {
if self.fullscreen_window.as_deref() == Some(&r.id) {
self.fullscreen_window = None;
self.placed.remove(&r.id);
}
// Place inside the viewport below the caption and window
// title strip, never over the shell chrome.
eff_rect = self.compiled.rects.stage_app;
actions.push(Action::Place {
w: r.clone(),
rect: eff_rect,
sticky: false,
});
}
if r.workspace != deck {
actions.push(Action::ToWorkspace {
id: r.id.clone(),
Expand Down Expand Up @@ -934,11 +943,13 @@ impl Engine {
pub fn set_fullscreen(&mut self, id: &str, enable: bool) -> Result<(), String> {
if enable {
self.fullscreen_window = Some(id.to_string());
self.placed.remove(id);
self.backend.set_fullscreen(id, true)?;
} else {
if self.fullscreen_window.as_deref() == Some(id) {
self.fullscreen_window = None;
}
self.placed.remove(id);
self.backend.set_fullscreen(id, false)?;
}
self.revision += 1;
Expand Down Expand Up @@ -1172,43 +1183,87 @@ impl Engine {
pub fn media(&self, action: &str) -> Result<(), String> {
let arg = match action {
"play_pause" | "toggle" => "play-pause",
"play" => "play",
"pause" => "pause",
"next" => "next",
"previous" | "prev" => "previous",
"stop" => "stop",
other => return Err(format!("unknown media action {other}")),
};
std::process::Command::new("playerctl")
.arg(arg)
.output()
.map_err(|e| format!("playerctl: {e}"))?;
let mut cmd = std::process::Command::new("playerctl");
cmd.arg(arg);
if std::env::var_os("DBUS_SESSION_BUS_ADDRESS").is_none() {
if let Some(rt) = std::env::var_os("XDG_RUNTIME_DIR") {
cmd.env(
"DBUS_SESSION_BUS_ADDRESS",
format!("unix:path={}/bus", rt.to_string_lossy()),
);
}
}
let out = cmd.output().map_err(|e| format!("playerctl: {e}"))?;
if !out.status.success() {
let err = String::from_utf8_lossy(&out.stderr).trim().to_string();
if !err.is_empty() {
return Err(format!("playerctl {arg}: {err}"));
}
}
Ok(())
}

pub fn set_volume(&self, value: f64) -> Result<(), String> {
pub fn set_volume(&mut self, value: f64) -> Result<(), String> {
let v = (value.clamp(0.0, 1.5) * 100.0).round() as i64;
let _ = std::process::Command::new("wpctl")
let ok = std::process::Command::new("wpctl")
.args(["set-volume", "@DEFAULT_AUDIO_SINK@", &format!("{v}%")])
.output();
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if !ok {
let _ = std::process::Command::new("pactl")
.args(["set-sink-volume", "@DEFAULT_SINK@", &format!("{v}%")])
.output();
}
self.revision += 1;
Ok(())
}

pub fn adjust_volume(&self, delta: f64) -> Result<(), String> {
pub fn adjust_volume(&mut self, delta: f64) -> Result<(), String> {
let pct = (delta.abs() * 100.0).round() as i64;
let arg = if delta < 0.0 {
format!("{pct}%-")
} else {
format!("{pct}%+")
};
let _ = std::process::Command::new("wpctl")
let ok = std::process::Command::new("wpctl")
.args(["set-volume", "-l", "1.5", "@DEFAULT_AUDIO_SINK@", &arg])
.output();
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if !ok {
let parg = if delta < 0.0 {
format!("-{pct}%")
} else {
format!("+{pct}%")
};
let _ = std::process::Command::new("pactl")
.args(["set-sink-volume", "@DEFAULT_SINK@", &parg])
.output();
}
self.revision += 1;
Ok(())
}

pub fn toggle_mute(&self) -> Result<(), String> {
let _ = std::process::Command::new("wpctl")
pub fn toggle_mute(&mut self) -> Result<(), String> {
let ok = std::process::Command::new("wpctl")
.args(["set-mute", "@DEFAULT_AUDIO_SINK@", "toggle"])
.output();
.output()
.map(|o| o.status.success())
.unwrap_or(false);
if !ok {
let _ = std::process::Command::new("pactl")
.args(["set-sink-mute", "@DEFAULT_SINK@", "toggle"])
.output();
}
self.revision += 1;
Ok(())
}
}
Expand Down
Loading