2016-11-21 14:07:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "components/types.hpp"
|
2016-12-05 19:41:00 +00:00
|
|
|
#include "events/signal_emitter.hpp"
|
|
|
|
#include "events/signal_fwd.hpp"
|
|
|
|
#include "events/signal_receiver.hpp"
|
|
|
|
#include "x11/fonts.hpp"
|
2016-11-21 14:07:00 +00:00
|
|
|
#include "x11/types.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
2016-12-09 08:02:47 +00:00
|
|
|
// fwd
|
2016-11-21 14:07:00 +00:00
|
|
|
class connection;
|
|
|
|
class font_manager;
|
|
|
|
class logger;
|
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
using namespace signals::parser;
|
2016-12-09 08:02:47 +00:00
|
|
|
using std::map;
|
2016-12-05 19:41:00 +00:00
|
|
|
|
|
|
|
class renderer
|
|
|
|
: public signal_receiver<SIGN_PRIORITY_RENDERER, change_background, change_foreground, change_underline,
|
|
|
|
change_overline, change_font, change_alignment, offset_pixel, attribute_set, attribute_unset,
|
|
|
|
attribute_toggle, action_begin, action_end, write_text_ascii, write_text_unicode, write_text_string> {
|
2016-11-21 14:07:00 +00:00
|
|
|
public:
|
2016-11-24 18:24:47 +00:00
|
|
|
enum class gc : uint8_t { BG, FG, OL, UL, BT, BB, BL, BR };
|
|
|
|
|
2016-12-09 08:40:46 +00:00
|
|
|
using make_type = unique_ptr<renderer>;
|
|
|
|
static make_type make(const bar_settings& bar, vector<string>&& fonts);
|
2016-12-09 08:02:47 +00:00
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
explicit renderer(connection& conn, signal_emitter& emitter, const logger& logger,
|
|
|
|
unique_ptr<font_manager> font_manager, const bar_settings& bar, const vector<string>& fonts);
|
2016-11-25 10:41:41 +00:00
|
|
|
~renderer();
|
2016-11-21 14:07:00 +00:00
|
|
|
|
|
|
|
xcb_window_t window() const;
|
|
|
|
|
|
|
|
void begin();
|
|
|
|
void end();
|
2016-11-25 03:10:26 +00:00
|
|
|
void flush(bool clear);
|
2016-11-21 14:07:00 +00:00
|
|
|
|
|
|
|
void reserve_space(edge side, uint16_t w);
|
|
|
|
|
2016-11-22 22:18:47 +00:00
|
|
|
void set_background(const uint32_t color);
|
|
|
|
void set_foreground(const uint32_t color);
|
|
|
|
void set_underline(const uint32_t color);
|
|
|
|
void set_overline(const uint32_t color);
|
2016-11-24 18:24:47 +00:00
|
|
|
void set_fontindex(const int8_t font);
|
2016-11-21 14:07:00 +00:00
|
|
|
void set_alignment(const alignment align);
|
|
|
|
void set_attribute(const attribute attr, const bool state);
|
2016-11-24 18:24:47 +00:00
|
|
|
void toggle_attribute(const attribute attr);
|
|
|
|
bool check_attribute(const attribute attr);
|
2016-11-21 14:07:00 +00:00
|
|
|
|
|
|
|
void fill_background();
|
|
|
|
void fill_overline(int16_t x, uint16_t w);
|
|
|
|
void fill_underline(int16_t x, uint16_t w);
|
2016-11-24 18:24:47 +00:00
|
|
|
void fill_shift(const int16_t px);
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2016-11-24 18:24:47 +00:00
|
|
|
void draw_character(const uint16_t character);
|
|
|
|
void draw_textstring(const char* text, const size_t len);
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
void begin_action(const mousebtn btn, const string& cmd);
|
2016-11-21 14:07:00 +00:00
|
|
|
void end_action(const mousebtn btn);
|
|
|
|
const vector<action_block> get_actions();
|
|
|
|
|
|
|
|
protected:
|
2016-11-25 03:10:26 +00:00
|
|
|
int16_t shift_content(int16_t x, const int16_t shift_x);
|
2016-11-24 18:24:47 +00:00
|
|
|
int16_t shift_content(const int16_t shift_x);
|
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
bool on(const change_background& evt);
|
|
|
|
bool on(const change_foreground& evt);
|
|
|
|
bool on(const change_underline& evt);
|
|
|
|
bool on(const change_overline& evt);
|
|
|
|
bool on(const change_font& evt);
|
|
|
|
bool on(const change_alignment& evt);
|
|
|
|
bool on(const offset_pixel& evt);
|
|
|
|
bool on(const attribute_set& evt);
|
|
|
|
bool on(const attribute_unset& evt);
|
|
|
|
bool on(const attribute_toggle& evt);
|
|
|
|
bool on(const action_begin& evt);
|
|
|
|
bool on(const action_end& evt);
|
|
|
|
bool on(const write_text_ascii& evt);
|
|
|
|
bool on(const write_text_unicode& evt);
|
|
|
|
bool on(const write_text_string& evt);
|
|
|
|
|
2016-11-25 03:10:26 +00:00
|
|
|
#ifdef DEBUG_HINTS
|
|
|
|
vector<xcb_window_t> m_debughints;
|
|
|
|
void debug_hints();
|
|
|
|
#endif
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2016-12-05 02:49:57 +00:00
|
|
|
protected:
|
|
|
|
struct reserve_area {
|
|
|
|
edge side{edge::NONE};
|
|
|
|
uint16_t size{0U};
|
|
|
|
};
|
|
|
|
|
2016-11-21 14:07:00 +00:00
|
|
|
private:
|
|
|
|
connection& m_connection;
|
2016-12-05 19:41:00 +00:00
|
|
|
signal_emitter& m_sig;
|
2016-11-21 14:07:00 +00:00
|
|
|
const logger& m_log;
|
|
|
|
unique_ptr<font_manager> m_fontmanager;
|
|
|
|
|
|
|
|
const bar_settings& m_bar;
|
|
|
|
|
2016-11-25 03:10:26 +00:00
|
|
|
xcb_rectangle_t m_rect{0, 0, 0U, 0U};
|
2016-12-05 02:49:57 +00:00
|
|
|
xcb_rectangle_t m_cleared{0, 0, 0U, 0U};
|
|
|
|
reserve_area m_cleararea{};
|
|
|
|
|
2016-11-21 14:07:00 +00:00
|
|
|
xcb_window_t m_window;
|
|
|
|
xcb_colormap_t m_colormap;
|
|
|
|
xcb_visualtype_t* m_visual;
|
|
|
|
// xcb_gcontext_t m_gcontext;
|
|
|
|
xcb_pixmap_t m_pixmap;
|
|
|
|
|
|
|
|
map<gc, xcb_gcontext_t> m_gcontexts;
|
|
|
|
map<alignment, xcb_pixmap_t> m_pixmaps;
|
|
|
|
vector<action_block> m_actions;
|
|
|
|
|
|
|
|
// bool m_autosize{false};
|
2016-11-24 18:24:47 +00:00
|
|
|
uint16_t m_currentx{0U};
|
2016-11-21 14:07:00 +00:00
|
|
|
alignment m_alignment{alignment::NONE};
|
2016-11-24 18:24:47 +00:00
|
|
|
map<gc, uint32_t> m_colors;
|
|
|
|
uint8_t m_attributes{0U};
|
|
|
|
int8_t m_fontindex{DEFAULT_FONT_INDEX};
|
2016-11-21 14:07:00 +00:00
|
|
|
|
2016-11-24 18:24:47 +00:00
|
|
|
xcb_font_t m_gcfont{XCB_NONE};
|
2016-11-21 14:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|