mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-08 19:05:58 +01:00
d5bf15387a
* notifications: free cairo images on destruction asan reports a leak on exit if we dont free the image we created in the draw function. add a destructor and free images on exit. * compositor: destroy wlroots types on exit there are a few types not being destroyed on exit and causing a leak on exit in wlroots reported by asan, add those. * cursormgr: ensure we destroy cursor mgr on exit add a destructor and call wlr_xcursor_manager_destroy on the manager on destruction, leak reported by asan. * keybindmgr: free state and keymap add missing keymap_unref on creation, and add a destructor and free the state on exit. leak reported by asan. * skeyboard: add destructor and free state free the state on destruction of keyboard, reported as leak by asan
67 lines
2.8 KiB
C++
67 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "../defines.hpp"
|
|
#include "../helpers/Timer.hpp"
|
|
#include "../helpers/Monitor.hpp"
|
|
#include "../render/Texture.hpp"
|
|
#include "../SharedDefs.hpp"
|
|
|
|
#include <deque>
|
|
|
|
#include <cairo/cairo.h>
|
|
|
|
enum eIconBackend {
|
|
ICONS_BACKEND_NONE = 0,
|
|
ICONS_BACKEND_NF,
|
|
ICONS_BACKEND_FA
|
|
};
|
|
|
|
static const std::array<std::array<std::string, ICON_NONE + 1>, 3 /* backends */> ICONS_ARRAY = {
|
|
std::array<std::string, ICON_NONE + 1>{"[!]", "[i]", "[Hint]", "[Err]", "[?]", "[ok]", ""},
|
|
std::array<std::string, ICON_NONE + 1>{"", "", "", "", "", "", ""}, std::array<std::string, ICON_NONE + 1>{"", "", "", "", "", ""}};
|
|
static const std::array<CColor, ICON_NONE + 1> ICONS_COLORS = {CColor{255.0 / 255.0, 204 / 255.0, 102 / 255.0, 1.0},
|
|
CColor{128 / 255.0, 255 / 255.0, 255 / 255.0, 1.0},
|
|
CColor{179 / 255.0, 255 / 255.0, 204 / 255.0, 1.0},
|
|
CColor{255 / 255.0, 77 / 255.0, 77 / 255.0, 1.0},
|
|
CColor{255 / 255.0, 204 / 255.0, 153 / 255.0, 1.0},
|
|
CColor{128 / 255.0, 255 / 255.0, 128 / 255.0, 1.0},
|
|
CColor{0, 0, 0, 1.0}};
|
|
|
|
struct SNotification {
|
|
std::string text = "";
|
|
CColor color;
|
|
CTimer started;
|
|
float timeMs = 0;
|
|
eIcons icon = ICON_NONE;
|
|
float fontSize = 13.f;
|
|
};
|
|
|
|
class CHyprNotificationOverlay {
|
|
public:
|
|
CHyprNotificationOverlay();
|
|
~CHyprNotificationOverlay();
|
|
|
|
void draw(CMonitor* pMonitor);
|
|
void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE, const float fontSize = 13.f);
|
|
void dismissNotifications(const int amount);
|
|
bool hasAny();
|
|
|
|
private:
|
|
CBox drawNotifications(CMonitor* pMonitor);
|
|
CBox m_bLastDamage;
|
|
|
|
std::deque<std::unique_ptr<SNotification>> m_dNotifications;
|
|
|
|
cairo_surface_t* m_pCairoSurface = nullptr;
|
|
cairo_t* m_pCairo = nullptr;
|
|
|
|
CMonitor* m_pLastMonitor = nullptr;
|
|
Vector2D m_vecLastSize = Vector2D(-1, -1);
|
|
|
|
CTexture m_tTexture;
|
|
|
|
eIconBackend m_eIconBackend = ICONS_BACKEND_NONE;
|
|
std::string m_szIconFontName = "Sans";
|
|
};
|
|
|
|
inline std::unique_ptr<CHyprNotificationOverlay> g_pHyprNotificationOverlay;
|