feat(theme): add sway bar color integration#2154
Open
him-cyber wants to merge 1 commit intogreshake:masterfrom
Open
feat(theme): add sway bar color integration#2154him-cyber wants to merge 1 commit intogreshake:masterfrom
him-cyber wants to merge 1 commit intogreshake:masterfrom
Conversation
Collaborator
|
Instead of trying to read the config from disk, I'd recommend using Here's a toy program that reads the background and statusline colors: use swayipc_async::Connection;
#[tokio::main]
async fn main() {
let mut connection = Connection::new().await.unwrap();
if let Some(bar_id) = connection.get_bar_ids().await.unwrap().first() {
let bar_config = connection.get_bar_config(bar_id).await.unwrap();
println!(
"Bar config for {}: background {:?} statusline {:?}",
bar_id, bar_config.colors.background, bar_config.colors.statusline
);
}
}Here's another extension of this that finds the bar id for the current i3status-rust that's running: use std::{os::unix::process::parent_id, path::Path};
use swayipc_async::Connection;
use tokio::io::AsyncReadExt as _;
pub async fn read_file(path: impl AsRef<Path>) -> std::io::Result<String> {
let mut file = tokio::fs::File::open(path).await?;
let mut content = String::new();
file.read_to_string(&mut content).await?;
Ok(content.trim_end().to_string())
}
#[tokio::main]
async fn main() {
let mut connection = Connection::new().await.unwrap();
eprintln!("Parent process ID: {}", parent_id());
let ppid_stat = read_file(
Path::new("/proc")
.join(parent_id().to_string())
.join("stat"),
)
.await
.unwrap();
let grandppid = ppid_stat.split(' ').nth(3).unwrap();
eprintln!("Grandparent process ID: {}", grandppid);
let grandppid_cmdline = read_file(Path::new("/proc").join(grandppid).join("cmdline"))
.await
.unwrap();
let grandppid_cmdline_parts: Vec<_> = grandppid_cmdline.split('\0').collect();
if let Some(bar_id) = grandppid_cmdline_parts
.iter()
.position(|&s| s == "-b" || s == "--bar_id")
.and_then(|pos| grandppid_cmdline_parts.get(pos + 1))
{
let bar_config = connection.get_bar_config(&bar_id).await.unwrap();
eprintln!(
"Bar config for {}: background {:?} statusline {:?}",
bar_id, bar_config.colors.background, bar_config.colors.statusline
);
}
println!("{{\"version\": 1, \"click_events\": true}}\n[");
loop {
println!("[],")
}
}This will be able to get the arguments that are used to start bar: (excerpt from | |-swaybar,2147460 -b bar-1
| | |-sh,2147520 -c /tmp/sway_test/target/debug/sway_test 2> /tmp/l
| | | `-sway_test,2147521and the sway config: set $background #ffdddd
bar {
position top
strip_workspace_numbers yes
height $bar_height
status_padding 0
# When the status_command prints a new line to stdout, swaybar updates.
status_command /tmp/sway_test/target/debug/sway_test 2> /tmp/l
colors {
background $background
statusline #222222
separator #666666
# border backgr. text
focused_workspace #0088CC #0088CC #ffffff
active_workspace #333333 #333333 #ffffff
inactive_workspace #333333 #333333 #888888
urgent_workspace #2f343a #900000 #ffffff
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces optional integration with the user's Sway configuration to automatically apply bar colors (background and foreground) from the
~/.config/sway/configfile. Fix for the open issue #2145Motivation
As a Wayland-native window manager, Sway allows defining custom bar colors. This enhancement bridges the theme configuration in i3status-rust with Sway’s color settings, improving visual consistency and user experience for Sway users.
Implementation
sway_integrationsection inconfig.tomlbackground,statusline) from the local Sway configidle_bgandidle_fgfieldsConfig Usage
To enable this, add to your
config.toml: