Skip to content

Commit

Permalink
systray: add :hover attribute to tray items (#1091)
Browse files Browse the repository at this point in the history
* systray: add `:hover` attribute to tray items

* doc: add entry to changelog
  • Loading branch information
zeapoz authored May 5, 2024
1 parent 2c88115 commit a4da192
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to eww will be listed here, starting at changes since versio

### Features
- Add `:truncate` property to labels, disabled by default (except in cases where truncation would be enabled in version `0.5.0` and before) (By: Rayzeq).
- Add support for `:hover` css selectors for tray items (By: zeapoz)

## [0.6.0] (21.04.2024)

Expand Down
23 changes: 20 additions & 3 deletions crates/eww/src/widgets/systray.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::widgets::window::Window;
use futures::StreamExt;
use gdk::NotifyType;
use gtk::{cairo::Surface, gdk::ffi::gdk_cairo_surface_create_from_pixbuf, prelude::*};
use notifier_host;
use std::{cell::RefCell, future::Future, rc::Rc};
Expand Down Expand Up @@ -130,11 +131,27 @@ impl Drop for Item {

impl Item {
fn new(id: String, item: notifier_host::Item, icon_size: tokio::sync::watch::Receiver<i32>) -> Self {
let widget = gtk::EventBox::new();
let out_widget = widget.clone(); // copy so we can return it
let gtk_widget = gtk::EventBox::new();

// Support :hover selector
gtk_widget.connect_enter_notify_event(|gtk_widget, evt| {
if evt.detail() != NotifyType::Inferior {
gtk_widget.clone().set_state_flags(gtk::StateFlags::PRELIGHT, false);
}
gtk::Inhibit(false)
});

gtk_widget.connect_leave_notify_event(|gtk_widget, evt| {
if evt.detail() != NotifyType::Inferior {
gtk_widget.clone().unset_state_flags(gtk::StateFlags::PRELIGHT);
}
gtk::Inhibit(false)
});

let out_widget = gtk_widget.clone(); // copy so we can return it

let task = glib::MainContext::default().spawn_local(async move {
if let Err(e) = Item::maintain(widget.clone(), item, icon_size).await {
if let Err(e) = Item::maintain(gtk_widget.clone(), item, icon_size).await {
log::error!("error for systray item {}: {}", id, e);
}
});
Expand Down

0 comments on commit a4da192

Please sign in to comment.