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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ All notable changes to eww will be listed here, starting at changes since versio
- Add `value-pos` to scale widget (By: ipsvn)
- Add `floor` and `ceil` function calls to simplexpr (By: wsbankenstein)

### Notable fixes and other changes
- Window will no longer be closed if `eww open` was called on an already opened window
and timer set by the `--duration` option will be updated or removed (By: Elvyria)

## [0.6.0] (21.04.2024)

### Fixes
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ strsim = "0.11"
strum = { version = "0.26", features = ["derive"] }
sysinfo = "0.31.2"
thiserror = "1.0"
tokio-util = "0.7.11"
tokio-util = "0.7.15"
tokio = { version = "1.39.2", features = ["full"] }
unescape = "0.1"
wait-timeout = "0.2"
Expand Down
76 changes: 41 additions & 35 deletions crates/eww/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{
rc::Rc,
};
use tokio::sync::mpsc::UnboundedSender;
use tokio_util::sync::CancellationToken;
use yuck::{
config::{
monitor::MonitorIdentifier,
Expand Down Expand Up @@ -128,7 +129,7 @@ pub struct App<B: DisplayBackend> {
pub script_var_handler: ScriptVarHandlerHandle,

/// Senders that will cancel a windows auto-close timer when started with --duration.
pub window_close_timer_abort_senders: HashMap<String, futures::channel::oneshot::Sender<()>>,
pub window_close_timer_abort_tokens: HashMap<String, CancellationToken>,

pub paths: EwwPaths,
pub phantom: PhantomData<B>,
Expand Down Expand Up @@ -361,9 +362,7 @@ impl<B: DisplayBackend> App<B> {

/// Close a window and do all the required cleanups in the scope_graph and script_var_handler
fn close_window(&mut self, instance_id: &str) -> Result<()> {
if let Some(old_abort_send) = self.window_close_timer_abort_senders.remove(instance_id) {
_ = old_abort_send.send(());
}
self.remove_close_timer(instance_id);
let eww_window = self
.open_windows
.remove(instance_id)
Expand All @@ -390,9 +389,11 @@ impl<B: DisplayBackend> App<B> {
self.failed_windows.remove(instance_id);
log::info!("Opening window {} as '{}'", window_args.window_name, instance_id);

// if an instance of this is already running, close it
// if an instance of this is already running, set a new timer that will close the window
// or remove an existing one if duration wasn't provided
if self.open_windows.contains_key(instance_id) {
self.close_window(instance_id)?;
self.set_close_timer(instance_id, window_args.duration);
return Ok(());
}

self.instance_id_to_args.insert(instance_id.to_string(), window_args.clone());
Expand Down Expand Up @@ -454,33 +455,7 @@ impl<B: DisplayBackend> App<B> {
}
}));

let duration = window_args.duration;
if let Some(duration) = duration {
let app_evt_sender = self.app_evt_send.clone();

let (abort_send, abort_recv) = futures::channel::oneshot::channel();

glib::MainContext::default().spawn_local({
let instance_id = instance_id.to_string();
async move {
tokio::select! {
_ = glib::timeout_future(duration) => {
let (response_sender, mut response_recv) = daemon_response::create_pair();
let command = DaemonCommand::CloseWindows { windows: vec![instance_id.clone()], sender: response_sender };
if let Err(err) = app_evt_sender.send(command) {
log::error!("Error sending close window command to daemon after gtk window destroy event: {}", err);
}
_ = response_recv.recv().await;
}
_ = abort_recv => {}
}
}
});

if let Some(old_abort_send) = self.window_close_timer_abort_senders.insert(instance_id.to_string(), abort_send) {
_ = old_abort_send.send(());
}
}
self.set_close_timer(instance_id, window_args.duration);

self.open_windows.insert(instance_id.to_string(), eww_window);
Ok(())
Expand Down Expand Up @@ -510,10 +485,11 @@ impl<B: DisplayBackend> App<B> {
let open_window_ids: Vec<String> =
self.open_windows.keys().cloned().chain(self.failed_windows.iter().cloned()).dedup().collect();
for instance_id in &open_window_ids {
let window_arguments = self.instance_id_to_args.get(instance_id).with_context(|| {
let window_arguments = self.instance_id_to_args.remove(instance_id).with_context(|| {
format!("Cannot reopen window, initial parameters were not saved correctly for {instance_id}")
})?;
self.open_window(&window_arguments.clone())?;
let _ = self.close_window(instance_id);
self.open_window(&window_arguments)?;
}
Ok(())
}
Expand All @@ -539,6 +515,36 @@ impl<B: DisplayBackend> App<B> {
Ok(())
}
}

fn remove_close_timer(&mut self, instance_id: &str) {
if let Some(token) = self.window_close_timer_abort_tokens.remove(instance_id) {
token.cancel();
}
}

fn set_close_timer(&mut self, instance_id: &str, duration: Option<Duration>) {
self.remove_close_timer(instance_id);

if let Some(duration) = duration {
let token = CancellationToken::new();
self.window_close_timer_abort_tokens.insert(instance_id.to_string(), token.clone());

glib::MainContext::default().spawn_local({
let app_evt_sender = self.app_evt_send.clone();
let instance_id = instance_id.to_string();

token.run_until_cancelled_owned(async move {
glib::timeout_future(duration).await;
let (response_sender, mut response_recv) = daemon_response::create_pair();
let command = DaemonCommand::CloseWindows { windows: vec![instance_id], sender: response_sender };
if let Err(err) = app_evt_sender.send(command) {
log::error!("Error sending close window command to daemon after gtk window destroy event: {}", err);
}
_ = response_recv.recv().await;
})
});
}
}
}

fn initialize_window<B: DisplayBackend>(
Expand Down
2 changes: 1 addition & 1 deletion crates/eww/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn initialize_server<B: DisplayBackend>(
css_provider: gtk::CssProvider::new(),
script_var_handler,
app_evt_send: ui_send.clone(),
window_close_timer_abort_senders: HashMap::new(),
window_close_timer_abort_tokens: HashMap::new(),
paths,
phantom: PhantomData,
};
Expand Down