2016-11-02 15:22:45 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <X11/Xft/Xft.h>
|
|
|
|
#include <xcb/xcbext.h>
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "x11/color.hpp"
|
|
|
|
#include "x11/types.hpp"
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
// fwd
|
|
|
|
class connection;
|
2016-12-09 03:02:47 -05:00
|
|
|
class logger;
|
2016-11-20 17:04:31 -05:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
struct fonttype {
|
2016-12-13 23:13:59 -05:00
|
|
|
explicit fonttype() = default;
|
|
|
|
XftFont* xft{nullptr};
|
|
|
|
xcb_font_t ptr{XCB_NONE};
|
|
|
|
int offset_y{0};
|
|
|
|
int ascent{0};
|
|
|
|
int descent{0};
|
|
|
|
int height{0};
|
|
|
|
int width{0};
|
|
|
|
uint16_t char_max{0};
|
|
|
|
uint16_t char_min{0};
|
|
|
|
vector<xcb_charinfo_t> width_lut{};
|
2016-11-02 15:22:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fonttype_deleter {
|
2016-11-20 17:04:31 -05:00
|
|
|
void operator()(fonttype* f);
|
2016-11-02 15:22:45 -04:00
|
|
|
};
|
|
|
|
|
2016-12-13 23:13:59 -05:00
|
|
|
using fonttype_pointer = unique_ptr<fonttype, fonttype_deleter>;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
class font_manager {
|
2016-11-02 15:22:45 -04:00
|
|
|
public:
|
2016-12-09 03:40:46 -05:00
|
|
|
using make_type = unique_ptr<font_manager>;
|
|
|
|
static make_type make();
|
2016-12-09 03:02:47 -05:00
|
|
|
|
2016-11-20 17:04:31 -05:00
|
|
|
explicit font_manager(connection& conn, const logger& logger);
|
|
|
|
~font_manager();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-25 07:55:15 -05:00
|
|
|
bool load(const string& name, int8_t fontindex = DEFAULT_FONT_INDEX, int8_t offset_y = 0);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-21 09:07:00 -05:00
|
|
|
void set_preferred_font(int8_t index);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-13 23:13:59 -05:00
|
|
|
fonttype_pointer& match_char(uint16_t chr);
|
|
|
|
uint8_t char_width(fonttype_pointer& font, uint16_t chr);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-13 23:13:59 -05:00
|
|
|
XftColor* xftcolor();
|
2016-11-21 09:07:00 -05:00
|
|
|
XftDraw* xftdraw();
|
2016-12-13 23:13:59 -05:00
|
|
|
|
|
|
|
void create_xftdraw(xcb_pixmap_t pm);
|
2016-11-21 09:07:00 -05:00
|
|
|
void destroy_xftdraw();
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-13 23:13:59 -05:00
|
|
|
void allocate_color(uint32_t color);
|
|
|
|
void allocate_color(XRenderColor color);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-21 09:07:00 -05:00
|
|
|
void set_gcontext_font(xcb_gcontext_t gc, xcb_font_t font);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
protected:
|
2016-12-13 23:13:59 -05:00
|
|
|
bool open_xcb_font(fonttype_pointer& fontptr, string fontname);
|
|
|
|
bool has_glyph(fonttype_pointer& font, uint16_t chr);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
connection& m_connection;
|
|
|
|
const logger& m_logger;
|
|
|
|
|
2016-11-21 09:07:00 -05:00
|
|
|
Display* m_display{nullptr};
|
|
|
|
Visual* m_visual{nullptr};
|
|
|
|
Colormap m_colormap{};
|
|
|
|
|
2016-12-13 23:13:59 -05:00
|
|
|
std::map<uint8_t, fonttype_pointer> m_fonts;
|
2016-11-24 13:24:47 -05:00
|
|
|
int8_t m_fontindex{DEFAULT_FONT_INDEX};
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-13 23:13:59 -05:00
|
|
|
XftColor* m_xftcolor{nullptr};
|
2016-11-21 09:07:00 -05:00
|
|
|
XftDraw* m_xftdraw{nullptr};
|
2016-11-02 15:22:45 -04:00
|
|
|
};
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|