close one notification to close all
This commit is contained in:
@@ -1,25 +1,34 @@
|
||||
#include "widgets/notification/notificationWindow.hpp"
|
||||
#include <cstdint>
|
||||
#include <sys/types.h>
|
||||
#include "helpers/string.hpp"
|
||||
|
||||
#include "gtkmm/box.h"
|
||||
#include "gtkmm/button.h"
|
||||
#include "gtkmm/gestureclick.h"
|
||||
#include "gtkmm/image.h"
|
||||
#include "gtkmm/label.h"
|
||||
|
||||
NotificationWindow::NotificationWindow(std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage notify) : BaseNotification(monitor) {
|
||||
NotificationWindow::NotificationWindow(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage notify) : BaseNotification(notificationId, monitor) {
|
||||
set_title(notify.summary);
|
||||
|
||||
if (notify.imageData) {
|
||||
auto img = Gtk::make_managed<Gtk::Image>(*(notify.imageData));
|
||||
img->set_pixel_size(64);
|
||||
img->set_halign(Gtk::Align::CENTER);
|
||||
img->set_valign(Gtk::Align::CENTER);
|
||||
img->add_css_class("notification-image");
|
||||
set_child(*img);
|
||||
}
|
||||
auto window_click = Gtk::GestureClick::create();
|
||||
window_click->set_button(GDK_BUTTON_PRIMARY);
|
||||
window_click->set_exclusive(false);
|
||||
window_click->signal_released().connect([this](int, double x, double y) {
|
||||
Gtk::Widget *picked = this->pick(x, y, Gtk::PickFlags::DEFAULT);
|
||||
for (auto *w = picked; w != nullptr; w = w->get_parent()) {
|
||||
if (dynamic_cast<Gtk::Button *>(w) != nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->signal_close.emit(this->notificationId);
|
||||
});
|
||||
add_controller(window_click);
|
||||
|
||||
// Main vertical box
|
||||
auto vbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 8);
|
||||
vbox->set_halign(Gtk::Align::FILL);
|
||||
|
||||
switch (notify.urgency) {
|
||||
case NotificationUrgency::CRITICAL:
|
||||
@@ -31,10 +40,30 @@ NotificationWindow::NotificationWindow(std::shared_ptr<Gdk::Monitor> monitor, No
|
||||
case NotificationUrgency::LOW:
|
||||
add_css_class("notification-low");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
auto header_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||
header_box->set_halign(Gtk::Align::START);
|
||||
header_box->add_css_class("notification-header");
|
||||
header_box->set_hexpand(true);
|
||||
header_box->set_halign(Gtk::Align::FILL);
|
||||
|
||||
if (notify.imageData) {
|
||||
auto img = Gtk::make_managed<Gtk::Image>(*(notify.imageData));
|
||||
img->set_pixel_size(16);
|
||||
img->set_halign(Gtk::Align::START);
|
||||
img->set_valign(Gtk::Align::CENTER);
|
||||
img->add_css_class("notification-app-icon");
|
||||
header_box->append(*img);
|
||||
}
|
||||
|
||||
auto app_label = Gtk::make_managed<Gtk::Label>(StringHelper::trimToSize(notify.app_name, 24));
|
||||
app_label->set_halign(Gtk::Align::START);
|
||||
app_label->set_wrap(false);
|
||||
app_label->add_css_class("notification-app-name");
|
||||
header_box->append(*app_label);
|
||||
vbox->append(*header_box);
|
||||
|
||||
// Summary label
|
||||
auto summary_label = Gtk::make_managed<Gtk::Label>("<b>" + StringHelper::trimToSize(notify.summary, 20) + "</b>");
|
||||
summary_label->set_use_markup(true);
|
||||
@@ -62,7 +91,7 @@ NotificationWindow::NotificationWindow(std::shared_ptr<Gdk::Monitor> monitor, No
|
||||
btn->signal_clicked().connect([this, action_id, cb = notify.on_action]() {
|
||||
if (cb) {
|
||||
cb(action_id);
|
||||
this->close();
|
||||
this->signal_close.emit(this->notificationId);
|
||||
}
|
||||
});
|
||||
actions_box->append(*btn);
|
||||
|
||||
Reference in New Issue
Block a user