diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-10-26 20:08:01 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-10-26 20:08:04 +0200 |
commit | 009d2f850e8fdd27d961423892920e0b6817c031 (patch) | |
tree | 4bac2fc384cf23c8a6c27610f588968228f9e997 /src/WindowNotification.cpp | |
parent | 000295e724345aed5c3bcf08edaf76069a9e2cfb (diff) |
Add window notification
Diffstat (limited to 'src/WindowNotification.cpp')
-rw-r--r-- | src/WindowNotification.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/WindowNotification.cpp b/src/WindowNotification.cpp new file mode 100644 index 0000000..acb47da --- /dev/null +++ b/src/WindowNotification.cpp @@ -0,0 +1,34 @@ +#include "../include/WindowNotification.hpp" +#include <gtkmm.h> + +static Gtk::Overlay *overlay = nullptr; +static Gtk::Label *label = nullptr; + +namespace dchat +{ + WindowNotification::WindowNotification() + { + label.set_line_wrap(true); + label.set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + label.set_halign(Gtk::ALIGN_START); + revealer.add(label); + add(revealer); + set_valign(Gtk::ALIGN_START); + set_halign(Gtk::ALIGN_CENTER); + revealer.get_style_context()->add_class("window-notification"); + show_all(); + } + + void WindowNotification::show(const Glib::ustring &text) + { + hideTimer.disconnect(); + label.set_text(text); + revealer.set_reveal_child(true); + int showTime = (int)std::max(1.0, (double)text.size() * 0.1); + hideTimer = Glib::signal_timeout().connect_seconds([this] + { + revealer.set_reveal_child(false); + return false; + }, showTime); + } +}
\ No newline at end of file |