Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a way to dinamically only change GTK CSS configuration. #1291

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to eww will be listed here, starting at changes since versio
- `get_locale` now follows POSIX standard for locale selection (By: mirhahn, w-lfchen)

### Features
- Add `--onlycss` flag to `eww reload` (By: nwnbark)
- Add `eww poll` subcommand to force-poll a variable (By: kiana-S)
- Add OnDemand support for focusable on wayland (By: GallowsDove)
- Add jq `raw-output` support (By: RomanHargrave)
Expand Down
15 changes: 10 additions & 5 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ pub enum DaemonCommand {
NoOp,
UpdateVars(Vec<(VarName, DynVal)>),
PollVars(Vec<VarName>),
ReloadConfigAndCss(DaemonResponseSender),
ReloadConfigAndCss {
onlycss: bool,
sender: DaemonResponseSender,
},
OpenInspector,
OpenMany {
windows: Vec<(String, String)>,
Expand Down Expand Up @@ -173,12 +176,14 @@ impl<B: DisplayBackend> App<B> {
self.force_poll_variable(var_name);
}
}
DaemonCommand::ReloadConfigAndCss(sender) => {
DaemonCommand::ReloadConfigAndCss { onlycss, sender } => {
let mut errors = Vec::new();

let config_result = config::read_from_eww_paths(&self.paths);
if let Err(e) = config_result.and_then(|new_config| self.load_config(new_config)) {
errors.push(e)
if !onlycss {
let config_result = config::read_from_eww_paths(&self.paths);
if let Err(e) = config_result.and_then(|new_config| self.load_config(new_config)) {
errors.push(e)
}
}
match crate::config::scss::parse_scss_from_config(self.paths.get_config_dir()) {
Ok((file_id, css)) => {
Expand Down
10 changes: 8 additions & 2 deletions crates/eww/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ pub enum ActionWithServer {

/// Reload the configuration
#[command(name = "reload", alias = "r")]
Reload,
Reload {
/// Only Reload the eww.(s)css file
#[arg(long = "onlycss")]
onlycss: bool,
},

/// Kill the eww daemon
#[command(name = "kill", alias = "k")]
Expand Down Expand Up @@ -294,7 +298,9 @@ impl ActionWithServer {
ActionWithServer::CloseWindows { windows } => {
return with_response_channel(|sender| app::DaemonCommand::CloseWindows { windows, sender });
}
ActionWithServer::Reload => return with_response_channel(app::DaemonCommand::ReloadConfigAndCss),
ActionWithServer::Reload { onlycss } => {
return with_response_channel(|sender| app::DaemonCommand::ReloadConfigAndCss { onlycss, sender });
}
ActionWithServer::ListWindows => return with_response_channel(app::DaemonCommand::ListWindows),
ActionWithServer::ListActiveWindows => return with_response_channel(app::DaemonCommand::ListActiveWindows),
ActionWithServer::ShowState { all } => {
Expand Down
6 changes: 4 additions & 2 deletions crates/eww/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ async fn run_filewatch<P: AsRef<Path>>(config_dir: P, evt_send: UnboundedSender<
Ok(notify::Event { kind: notify::EventKind::Modify(_), paths, .. }) => {
let relevant_files_changed = paths.iter().any(|path| {
let ext = path.extension().unwrap_or_default();
ext == "yuck" || ext == "scss" || ext == "css"
let skip = path.with_extension("").file_name().unwrap_or_default().to_str().expect("").ends_with("__");

!skip && (ext == "yuck" || ext == "scss" || ext == "css")
});
if relevant_files_changed {
if let Err(err) = tx.send(()) {
Expand Down Expand Up @@ -222,7 +224,7 @@ async fn run_filewatch<P: AsRef<Path>>(config_dir: P, evt_send: UnboundedSender<
// and eww being too fast, thus reading the file while it's empty.
// There should be some cleaner solution for this, but this will do for now.
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
evt_send.send(app::DaemonCommand::ReloadConfigAndCss(daemon_resp_sender))?;
evt_send.send(app::DaemonCommand::ReloadConfigAndCss { onlycss: false, sender: daemon_resp_sender })?;
tokio::spawn(async move {
match daemon_resp_response.recv().await {
Some(daemon_response::DaemonResponse::Success(_)) => log::info!("Reloaded config successfully"),
Expand Down
2 changes: 2 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ as well as most layout-related CSS properties such as flexbox, `float`, absolute
To get started, you'll need to create two files: `eww.yuck` and `eww.scss` (or `eww.css`, if you prefer).
These files must be placed under `$XDG_CONFIG_HOME/eww` (this is most likely `~/.config/eww`).

Keep in mind that all `.yuck`, `.css` and `.scss` files on the config folder are monitored recursively. Any changes to these files will automatically trigger a reload of all the eww configuration, recreating all the windows on the process. If this behaviour is not desired see [Unmonitoring Files and Only Reloading GTK CSS](working_with_gtk.md).

Now that those files are created, you can start writing your first widget!

## Creating your first window
Expand Down
2 changes: 2 additions & 0 deletions docs/src/working_with_gtk.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ If you have **NO** clue about how to do CSS, check out some online guides or tut

SCSS is _very_ close to CSS, so if you know CSS you'll have no problem learning SCSS.

If you need to make specific CSS changes, such as modifying colors or font styles, without recreating all windows, use the `--onlycss` flag when reloading eww. Additionally, to complement this feature, you can append `__` to the filename to exclude it from monitoring like: `colors__.scss`, or simply use symlinks as an alternative.

## GTK-Debugger

The debugger can be used for **a lot** of things, especially if something doesn't work or isn't styled right.
Expand Down