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& operator=(const font_manager& o) = delete;
void set_visual(shared_ptr<Visual>&& v);
void cleanup();
bool load(const string& name, int8_t fontindex = DEFAULT_FONT_INDEX, int8_t offset_y = 0);
void set_preferred_font(int8_t index);

View File

@ -8,7 +8,7 @@ POLYBAR_NS
namespace xlib {
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);

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) {
m_log.err("No 24-bit TrueColor visual found, aborting...");
throw application_error("No matching TrueColor visual found...");
}
if (m_visual == nullptr) {
@ -57,6 +58,8 @@ renderer::renderer(connection& conn, signal_emitter& emitter, const logger& logg
}
m_depth = 24;
m_fontmanager->set_visual(xlib::get_visual(m_connection.default_screen(), m_depth));
}
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() {
if (m_xftdraw != nullptr) {
XftDrawDestroy(m_xftdraw);

View File

@ -15,10 +15,10 @@ namespace xlib {
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) {
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); });
}
}