1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

fix: Update font visual if depth changes

This commit is contained in:
Michael Carlberg 2016-12-15 18:22:04 +01:00
parent b2e8428550
commit b90856157b
5 changed files with 12 additions and 3 deletions

View file

@ -55,6 +55,8 @@ class font_manager {
font_manager(const font_manager& o) = delete; font_manager(const font_manager& o) = delete;
font_manager& operator=(const font_manager& o) = delete; font_manager& operator=(const font_manager& o) = delete;
void set_visual(shared_ptr<Visual>&& v);
void cleanup(); void cleanup();
bool load(const string& name, int8_t fontindex = DEFAULT_FONT_INDEX, int8_t offset_y = 0); bool load(const string& name, int8_t fontindex = DEFAULT_FONT_INDEX, int8_t offset_y = 0);
void set_preferred_font(int8_t index); void set_preferred_font(int8_t index);

View file

@ -8,7 +8,7 @@ POLYBAR_NS
namespace xlib { namespace xlib {
shared_ptr<Display> get_display(); shared_ptr<Display> get_display();
shared_ptr<Visual> get_visual(int screen = 0); shared_ptr<Visual> get_visual(int screen = 0, uint8_t depth = 32);
Colormap create_colormap(int screen = 0); Colormap create_colormap(int screen = 0);

View file

@ -50,6 +50,7 @@ renderer::renderer(connection& conn, signal_emitter& emitter, const logger& logg
if ((m_visual = m_connection.visual_type(m_connection.screen(), 24)) == nullptr) { if ((m_visual = m_connection.visual_type(m_connection.screen(), 24)) == nullptr) {
m_log.err("No 24-bit TrueColor visual found, aborting..."); m_log.err("No 24-bit TrueColor visual found, aborting...");
throw application_error("No matching TrueColor visual found...");
} }
if (m_visual == nullptr) { if (m_visual == nullptr) {
@ -57,6 +58,8 @@ renderer::renderer(connection& conn, signal_emitter& emitter, const logger& logg
} }
m_depth = 24; m_depth = 24;
m_fontmanager->set_visual(xlib::get_visual(m_connection.default_screen(), m_depth));
} }
m_log.trace("renderer: Allocate colormap"); m_log.trace("renderer: Allocate colormap");

View file

@ -56,6 +56,10 @@ font_manager::~font_manager() {
} }
} }
void font_manager::set_visual(shared_ptr<Visual>&& v) {
m_visual = forward<decltype(v)>(v);
}
void font_manager::cleanup() { void font_manager::cleanup() {
if (m_xftdraw != nullptr) { if (m_xftdraw != nullptr) {
XftDrawDestroy(m_xftdraw); XftDrawDestroy(m_xftdraw);

View file

@ -15,10 +15,10 @@ namespace xlib {
return g_display_ptr; return g_display_ptr;
} }
shared_ptr<Visual> get_visual(int screen) { shared_ptr<Visual> get_visual(int screen, uint8_t depth) {
if (!g_visual_ptr) { if (!g_visual_ptr) {
XVisualInfo info{}; XVisualInfo info{};
if (XMatchVisualInfo(get_display().get(), screen, 32, TrueColor, &info)) { if (XMatchVisualInfo(get_display().get(), screen, depth, TrueColor, &info)) {
g_visual_ptr = shared_ptr<Visual>(info.visual, [=](Visual* v) { XFree(v); }); g_visual_ptr = shared_ptr<Visual>(info.visual, [=](Visual* v) { XFree(v); });
} }
} }