From b90856157bda6ad7613ee538b305ab06be2cbecb Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Thu, 15 Dec 2016 18:22:04 +0100 Subject: [PATCH] fix: Update font visual if depth changes --- include/x11/fonts.hpp | 2 ++ include/x11/xlib.hpp | 2 +- src/components/renderer.cpp | 3 +++ src/x11/fonts.cpp | 4 ++++ src/x11/xlib.cpp | 4 ++-- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/x11/fonts.hpp b/include/x11/fonts.hpp index 5361ef3a..37c782c4 100644 --- a/include/x11/fonts.hpp +++ b/include/x11/fonts.hpp @@ -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&& 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); diff --git a/include/x11/xlib.hpp b/include/x11/xlib.hpp index ae4f3d4f..6a44cf77 100644 --- a/include/x11/xlib.hpp +++ b/include/x11/xlib.hpp @@ -8,7 +8,7 @@ POLYBAR_NS namespace xlib { shared_ptr get_display(); - shared_ptr get_visual(int screen = 0); + shared_ptr get_visual(int screen = 0, uint8_t depth = 32); Colormap create_colormap(int screen = 0); diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index 2bdaaeec..0020d821 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -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"); diff --git a/src/x11/fonts.cpp b/src/x11/fonts.cpp index 4f492159..3ba187a6 100644 --- a/src/x11/fonts.cpp +++ b/src/x11/fonts.cpp @@ -56,6 +56,10 @@ font_manager::~font_manager() { } } +void font_manager::set_visual(shared_ptr&& v) { + m_visual = forward(v); +} + void font_manager::cleanup() { if (m_xftdraw != nullptr) { XftDrawDestroy(m_xftdraw); diff --git a/src/x11/xlib.cpp b/src/x11/xlib.cpp index 046d40cc..844fa703 100644 --- a/src/x11/xlib.cpp +++ b/src/x11/xlib.cpp @@ -15,10 +15,10 @@ namespace xlib { return g_display_ptr; } - shared_ptr get_visual(int screen) { + shared_ptr 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(info.visual, [=](Visual* v) { XFree(v); }); } }