diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-01-26 17:02:05 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-01-26 17:02:05 -0500 |
commit | d78fde45d49e298016e87fcec203a9877348428b (patch) | |
tree | 35ec7bc00573d5231a8702cb988d1fcc62982680 /components | |
parent | 7334a4db72e148c825df70b4f385aad0a2abeefe (diff) | |
download | abaddon-portaudio-d78fde45d49e298016e87fcec203a9877348428b.tar.gz abaddon-portaudio-d78fde45d49e298016e87fcec203a9877348428b.zip |
make status indicator colors customizable
Diffstat (limited to 'components')
-rw-r--r-- | components/statusindicator.cpp | 35 | ||||
-rw-r--r-- | components/statusindicator.hpp | 4 |
2 files changed, 19 insertions, 20 deletions
diff --git a/components/statusindicator.cpp b/components/statusindicator.cpp index abf389c..f10d1ef 100644 --- a/components/statusindicator.cpp +++ b/components/statusindicator.cpp @@ -11,10 +11,12 @@ StatusIndicator::StatusIndicator(Snowflake user_id) : Glib::ObjectBase("statusindicator") , Gtk::Widget() , m_id(user_id) - , m_color(OfflineColor) { + , m_status(static_cast<PresenceStatus>(-1)) { set_has_window(true); set_name("status-indicator"); + get_style_context()->add_class("status-indicator"); + Abaddon::Get().GetDiscordClient().signal_guild_member_list_update().connect(sigc::hide(sigc::mem_fun(*this, &StatusIndicator::CheckStatus))); auto cb = [this](Snowflake id, PresenceStatus status) { if (id == m_id) CheckStatus(); @@ -29,26 +31,21 @@ StatusIndicator::~StatusIndicator() { void StatusIndicator::CheckStatus() { const auto status = Abaddon::Get().GetDiscordClient().GetUserStatus(m_id); + const auto last_status = m_status; + get_style_context()->remove_class("online"); + get_style_context()->remove_class("dnd"); + get_style_context()->remove_class("idle"); + get_style_context()->remove_class("offline"); if (status.has_value()) { - switch (*status) { - case PresenceStatus::Online: - m_color = OnlineColor; - break; - case PresenceStatus::Offline: - m_color = OfflineColor; - break; - case PresenceStatus::DND: - m_color = DNDColor; - break; - case PresenceStatus::Idle: - m_color = IdleColor; - break; - } + get_style_context()->add_class(GetPresenceString(*status)); + m_status = *status; } else { - m_color = OfflineColor; + m_status = PresenceStatus::Offline; + get_style_context()->add_class("offline"); } - queue_draw(); + if (last_status != m_status) + queue_draw(); } Gtk::SizeRequestMode StatusIndicator::get_request_mode_vfunc() const { @@ -126,7 +123,9 @@ bool StatusIndicator::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) { const auto width = allocation.get_width(); const auto height = allocation.get_height(); - cr->set_source_rgb(m_color.get_red(), m_color.get_green(), m_color.get_blue()); + const auto color = get_style_context()->get_color(Gtk::STATE_FLAG_NORMAL); + + cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue()); cr->arc(width / 2, height / 2, width / 3, 0.0, 2 * (4 * std::atan(1))); cr->close_path(); cr->fill_preserve(); diff --git a/components/statusindicator.hpp b/components/statusindicator.hpp index 9c7382e..9949b0d 100644 --- a/components/statusindicator.hpp +++ b/components/statusindicator.hpp @@ -1,6 +1,7 @@ #pragma once #include <gtkmm.h> #include "../discord/snowflake.hpp" +#include "../discord/activity.hpp" class StatusIndicator : public Gtk::Widget { public: @@ -22,9 +23,8 @@ protected: Glib::RefPtr<Gdk::Window> m_window; -private: void CheckStatus(); Snowflake m_id; - Gdk::RGBA m_color; + PresenceStatus m_status; }; |