add mention overlay to folders in classic

This commit is contained in:
ouwou 2024-05-25 00:09:08 -04:00
parent bf29c44d9f
commit 96687f019e
3 changed files with 42 additions and 10 deletions

View File

@ -103,7 +103,22 @@ static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, Snowflake guild_id) {
mention_overlay->signal_realize().connect([mention_overlay]() {
mention_overlay->get_window()->set_pass_through(true);
});
overlay->show_all();
mention_overlay->show();
overlay->show();
return overlay;
}
static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, const UserSettingsGuildFoldersEntry &folder) {
auto *overlay = Gtk::make_managed<Gtk::Overlay>();
overlay->add(*widget);
auto *mention_overlay = Gtk::make_managed<MentionOverlay>(folder);
overlay->add_overlay(*mention_overlay);
overlay->set_overlay_pass_through(*mention_overlay, true);
mention_overlay->signal_realize().connect([mention_overlay]() {
mention_overlay->get_window()->set_pass_through(true);
});
mention_overlay->show();
overlay->show();
return overlay;
}
@ -151,7 +166,7 @@ void GuildList::AddFolder(const UserSettingsGuildFoldersEntry &folder) {
}
folder_widget->show();
add(*folder_widget);
add(*AddMentionOverlay(folder_widget, folder));
}
void GuildList::Clear() {

View File

@ -5,7 +5,16 @@
#include "abaddon.hpp"
MentionOverlay::MentionOverlay(Snowflake guild_id)
: m_guild_id(guild_id) {
: m_guild_ids({ guild_id }) {
Init();
}
MentionOverlay::MentionOverlay(const UserSettingsGuildFoldersEntry &folder)
: m_guild_ids({ folder.GuildIDs.begin(), folder.GuildIDs.end() }) {
Init();
}
void MentionOverlay::Init() {
m_font.set_family("sans 14");
m_layout = create_pango_layout("12");
m_layout->set_font_description(m_font);
@ -24,20 +33,24 @@ MentionOverlay::MentionOverlay(Snowflake guild_id)
});
Abaddon::Get().GetDiscordClient().signal_message_create().connect([this](const Message &msg) {
if (msg.GuildID.has_value() && *msg.GuildID != m_guild_id) return;
if (msg.GuildID.has_value() && m_guild_ids.find(*msg.GuildID) == m_guild_ids.end()) return;
if (!msg.DoesMentionEveryone && msg.Mentions.empty() && msg.MentionRoles.empty()) return;
queue_draw();
});
}
bool MentionOverlay::OnDraw(const Cairo::RefPtr<Cairo::Context> &cr) {
int total_mentions = 0;
for (auto guild_id : m_guild_ids) {
int mentions;
Abaddon::Get().GetDiscordClient().GetUnreadStateForGuild(m_guild_id, mentions);
if (mentions == 0) return true;
m_layout->set_text(std::to_string(mentions));
Abaddon::Get().GetDiscordClient().GetUnreadStateForGuild(guild_id, mentions);
total_mentions += mentions;
}
if (total_mentions == 0) return true;
m_layout->set_text(std::to_string(total_mentions));
const int width = get_allocated_width();
const int height = get_allocated_height();
const int height = std::min(get_allocated_height(), 48); // cope
int lw, lh;
m_layout->get_pixel_size(lw, lh);

View File

@ -4,15 +4,19 @@
#include <pangomm/fontdescription.h>
#include "discord/snowflake.hpp"
#include "discord/usersettings.hpp"
class MentionOverlay : public Gtk::DrawingArea {
public:
MentionOverlay(Snowflake guild_id);
MentionOverlay(const UserSettingsGuildFoldersEntry &folder);
private:
void Init();
bool OnDraw(const Cairo::RefPtr<Cairo::Context> &cr);
Snowflake m_guild_id;
std::set<Snowflake> m_guild_ids;
Pango::FontDescription m_font;
Glib::RefPtr<Pango::Layout> m_layout;