polybar/src/components/renderer.cpp

663 lines
19 KiB
C++
Raw Normal View History

2016-11-21 14:07:00 +00:00
#include "components/renderer.hpp"
#include "components/logger.hpp"
2016-11-25 12:55:15 +00:00
#include "errors.hpp"
2016-11-21 14:07:00 +00:00
#include "x11/connection.hpp"
#include "x11/draw.hpp"
#include "x11/fonts.hpp"
2016-11-25 03:10:26 +00:00
#include "x11/winspec.hpp"
#include "x11/xlib.hpp"
#include "x11/xutils.hpp"
2016-11-21 14:07:00 +00:00
POLYBAR_NS
/**
* Configure injection module
*/
di::injector<unique_ptr<renderer>> configure_renderer(const bar_settings& bar, const vector<string>& fonts) {
// clang-format off
return di::make_injector(
di::bind<>().to(bar),
di::bind<>().to(fonts),
configure_connection(),
configure_logger(),
configure_font_manager());
// clang-format on
}
/**
* Construct renderer instance
*/
2016-11-21 14:07:00 +00:00
renderer::renderer(connection& conn, const logger& logger, unique_ptr<font_manager> font_manager,
const bar_settings& bar, const vector<string>& fonts)
2016-11-25 03:10:26 +00:00
: m_connection(conn)
, m_log(logger)
, m_fontmanager(forward<decltype(font_manager)>(font_manager))
, m_bar(bar)
, m_rect(bar.inner_area()) {
m_log.trace("renderer: Get TrueColor visual");
m_visual = m_connection.visual_type(m_connection.screen(), 32).get();
m_log.trace("renderer: Allocate colormap");
2016-11-21 14:07:00 +00:00
m_colormap = m_connection.generate_id();
2016-11-25 03:10:26 +00:00
m_connection.create_colormap(XCB_COLORMAP_ALLOC_NONE, m_colormap, m_connection.screen()->root, m_visual->visual_id);
2016-11-21 14:07:00 +00:00
2016-11-25 03:10:26 +00:00
m_log.trace("renderer: Allocate output window");
2016-11-21 14:07:00 +00:00
{
2016-11-25 03:10:26 +00:00
// clang-format off
m_window = winspec(m_connection)
<< cw_size(m_bar.size)
<< cw_pos(m_bar.pos)
<< cw_depth(32)
<< cw_visual(m_visual->visual_id)
<< cw_class(XCB_WINDOW_CLASS_INPUT_OUTPUT)
<< cw_params_back_pixel(0)
<< cw_params_border_pixel(0)
<< cw_params_backing_store(XCB_BACKING_STORE_WHEN_MAPPED)
<< cw_params_colormap(m_colormap)
<< cw_params_event_mask(XCB_EVENT_MASK_PROPERTY_CHANGE
|XCB_EVENT_MASK_EXPOSURE
|XCB_EVENT_MASK_BUTTON_PRESS)
<< cw_params_override_redirect(m_bar.override_redirect)
2016-11-25 03:10:26 +00:00
<< cw_flush(true);
// clang-format on
2016-11-21 14:07:00 +00:00
}
2016-11-25 03:10:26 +00:00
m_log.trace("renderer: Allocate window pixmap");
2016-11-21 14:07:00 +00:00
m_pixmap = m_connection.generate_id();
2016-11-25 03:10:26 +00:00
m_connection.create_pixmap(32, m_pixmap, m_window, m_rect.width, m_rect.height);
2016-11-21 14:07:00 +00:00
2016-11-25 03:10:26 +00:00
m_log.trace("renderer: Allocate graphic contexts");
2016-11-21 14:07:00 +00:00
{
// clang-format off
vector<uint32_t> colors {
m_bar.background,
m_bar.foreground,
m_bar.overline.color,
m_bar.underline.color,
2016-11-21 14:07:00 +00:00
m_bar.borders.at(edge::TOP).color,
m_bar.borders.at(edge::BOTTOM).color,
m_bar.borders.at(edge::LEFT).color,
m_bar.borders.at(edge::RIGHT).color,
};
// clang-format on
for (int i = 0; i < 8; i++) {
2016-11-21 14:07:00 +00:00
uint32_t mask{0};
uint32_t value_list[32]{0};
2016-11-25 03:10:26 +00:00
xcb_params_gc_t params;
XCB_AUX_ADD_PARAM(&mask, &params, foreground, colors[i]);
2016-11-21 14:07:00 +00:00
XCB_AUX_ADD_PARAM(&mask, &params, graphics_exposures, 0);
xutils::pack_values(mask, &params, value_list);
2016-11-25 03:10:26 +00:00
m_colors.emplace(gc(i), colors[i]);
2016-11-25 03:10:26 +00:00
m_gcontexts.emplace(gc(i), m_connection.generate_id());
2016-11-21 14:07:00 +00:00
m_connection.create_gc(m_gcontexts.at(gc(i)), m_pixmap, mask, value_list);
}
}
2016-11-22 00:22:47 +00:00
m_log.trace("renderer: Load fonts");
2016-11-21 14:07:00 +00:00
{
auto fonts_loaded = false;
auto fontindex = 0;
2016-11-25 12:55:15 +00:00
if (fonts.empty()) {
2016-11-21 14:07:00 +00:00
m_log.warn("No fonts specified, using fallback font \"fixed\"");
2016-11-25 12:55:15 +00:00
}
2016-11-21 14:07:00 +00:00
2016-11-25 12:55:15 +00:00
for (const auto& f : fonts) {
2016-11-21 14:07:00 +00:00
fontindex++;
vector<string> fd{string_util::split(f, ';')};
2016-11-21 14:07:00 +00:00
string pattern{fd[0]};
int offset{0};
2016-11-25 12:55:15 +00:00
if (fd.size() > 1) {
offset = std::stoi(fd[1], nullptr, 10);
}
2016-11-21 14:07:00 +00:00
2016-11-25 12:55:15 +00:00
if (m_fontmanager->load(pattern, fontindex, offset)) {
2016-11-21 14:07:00 +00:00
fonts_loaded = true;
2016-11-25 12:55:15 +00:00
} else {
2016-11-21 14:07:00 +00:00
m_log.warn("Unable to load font '%s'", fd[0]);
2016-11-25 12:55:15 +00:00
}
2016-11-21 14:07:00 +00:00
}
2016-11-25 12:55:15 +00:00
if (!fonts_loaded && !fonts.empty()) {
2016-11-21 14:07:00 +00:00
m_log.warn("Unable to load fonts, using fallback font \"fixed\"");
2016-11-25 12:55:15 +00:00
}
2016-11-21 14:07:00 +00:00
2016-11-25 12:55:15 +00:00
if (!fonts_loaded && !m_fontmanager->load("fixed")) {
2016-11-21 14:07:00 +00:00
throw application_error("Unable to load fonts");
2016-11-25 12:55:15 +00:00
}
2016-11-21 14:07:00 +00:00
m_fontmanager->allocate_color(m_bar.foreground, true);
}
}
/**
* Deconstruct instance
*/
renderer::~renderer() {
if (m_window != XCB_NONE) {
m_connection.destroy_window(m_window);
}
}
/**
* Get output window
*/
2016-11-21 14:07:00 +00:00
xcb_window_t renderer::window() const {
return m_window;
}
/**
* Begin render routine
*/
2016-11-21 14:07:00 +00:00
void renderer::begin() {
m_log.trace_x("renderer: begin");
2016-11-25 03:10:26 +00:00
m_rect = m_bar.inner_area();
m_alignment = alignment::NONE;
m_currentx = 0;
2016-11-21 14:07:00 +00:00
m_attributes = 0;
m_actions.clear();
m_fontmanager->create_xftdraw(m_pixmap, m_colormap);
}
/**
* End render routine
*/
2016-11-21 14:07:00 +00:00
void renderer::end() {
m_log.trace_x("renderer: end");
2016-11-22 00:22:47 +00:00
m_fontmanager->destroy_xftdraw();
2016-11-25 03:10:26 +00:00
#ifdef DEBUG_HINTS
debug_hints();
2016-11-22 00:22:47 +00:00
#endif
2016-11-25 03:10:26 +00:00
flush(false);
2016-11-22 00:22:47 +00:00
}
/**
* Redraw window contents
*/
2016-11-25 03:10:26 +00:00
void renderer::flush(bool clear) {
const xcb_rectangle_t& r = m_rect;
xcb_rectangle_t top{0, 0, 0U, 0U};
top.x += m_bar.borders.at(edge::LEFT).size;
top.width += m_bar.size.w - m_bar.borders.at(edge::LEFT).size - m_bar.borders.at(edge::RIGHT).size;
top.height += m_bar.borders.at(edge::TOP).size;
xcb_rectangle_t bottom{0, 0, 0U, 0U};
bottom.x += m_bar.borders.at(edge::LEFT).size;
bottom.y += m_bar.size.h - m_bar.borders.at(edge::BOTTOM).size;
bottom.width += m_bar.size.w - m_bar.borders.at(edge::LEFT).size - m_bar.borders.at(edge::RIGHT).size;
bottom.height += m_bar.borders.at(edge::BOTTOM).size;
2016-11-22 00:22:47 +00:00
2016-11-25 03:10:26 +00:00
xcb_rectangle_t left{0, 0, 0U, 0U};
left.width += m_bar.borders.at(edge::LEFT).size;
left.height += m_bar.size.h;
2016-11-21 14:07:00 +00:00
2016-11-25 03:10:26 +00:00
xcb_rectangle_t right{0, 0, 0U, 0U};
right.x += m_bar.size.w - m_bar.borders.at(edge::RIGHT).size;
right.width += m_bar.borders.at(edge::RIGHT).size;
right.height += m_bar.size.h;
m_log.trace("renderer: copy pixmap (clear=%i)", clear);
m_connection.copy_area(m_pixmap, m_window, m_gcontexts.at(gc::FG), 0, 0, r.x, r.y, r.width, r.height);
m_log.trace_x("renderer: draw top border (%lupx, %08x)", top.height, m_bar.borders.at(edge::TOP).color);
draw_util::fill(m_connection, m_window, m_gcontexts.at(gc::BT), top);
m_log.trace_x("renderer: draw bottom border (%lupx, %08x)", bottom.height, m_bar.borders.at(edge::BOTTOM).color);
draw_util::fill(m_connection, m_window, m_gcontexts.at(gc::BB), bottom);
m_log.trace_x("renderer: draw left border (%lupx, %08x)", left.width, m_bar.borders.at(edge::LEFT).color);
draw_util::fill(m_connection, m_window, m_gcontexts.at(gc::BL), left);
m_log.trace_x("renderer: draw right border (%lupx, %08x)", right.width, m_bar.borders.at(edge::RIGHT).color);
draw_util::fill(m_connection, m_window, m_gcontexts.at(gc::BR), right);
if (clear) {
m_connection.clear_area(false, m_pixmap, 0, 0, r.width, r.height);
2016-11-21 14:07:00 +00:00
}
2016-11-25 03:10:26 +00:00
m_connection.flush();
2016-11-21 14:07:00 +00:00
}
/**
* Reserve space at given edge
*/
2016-11-21 14:07:00 +00:00
void renderer::reserve_space(edge side, uint16_t w) {
m_log.trace_x("renderer: reserve_space(%i, %i)", static_cast<uint8_t>(side), w);
2016-11-25 03:10:26 +00:00
switch (side) {
case edge::NONE:
break;
case edge::TOP:
m_rect.y += w;
m_rect.height -= w;
break;
case edge::BOTTOM:
m_rect.height -= w;
break;
case edge::LEFT:
m_rect.x += w;
m_rect.width -= w;
break;
case edge::RIGHT:
m_rect.width -= w;
break;
case edge::ALL:
m_rect.x += w;
m_rect.y += w;
m_rect.width -= w * 2;
m_rect.height -= w * 2;
break;
}
2016-11-21 14:07:00 +00:00
}
/**
* Change value of background gc
*/
2016-11-22 22:18:47 +00:00
void renderer::set_background(const uint32_t color) {
if (m_colors[gc::BG] == color) {
return m_log.trace_x("renderer: ignoring unchanged background color(#%08x)", color);
}
2016-11-22 22:18:47 +00:00
m_log.trace_x("renderer: set_background(#%08x)", color);
m_connection.change_gc(m_gcontexts.at(gc::BG), XCB_GC_FOREGROUND, &color);
m_colors[gc::BG] = color;
2016-11-22 22:18:47 +00:00
shift_content(0);
2016-11-21 14:07:00 +00:00
}
/**
* Change value of foreground gc
*/
2016-11-22 22:18:47 +00:00
void renderer::set_foreground(const uint32_t color) {
if (m_colors[gc::FG] == color) {
return m_log.trace_x("renderer: ignoring unchanged foreground color(#%08x)", color);
}
2016-11-22 22:18:47 +00:00
m_log.trace_x("renderer: set_foreground(#%08x)", color);
m_connection.change_gc(m_gcontexts.at(gc::FG), XCB_GC_FOREGROUND, &color);
m_fontmanager->allocate_color(color);
m_colors[gc::FG] = color;
2016-11-22 22:18:47 +00:00
}
/**
* Change value of underline gc
*/
2016-11-22 22:18:47 +00:00
void renderer::set_underline(const uint32_t color) {
if (m_colors[gc::UL] == color) {
return m_log.trace_x("renderer: ignoring unchanged underline color(#%08x)", color);
}
2016-11-22 22:18:47 +00:00
m_log.trace_x("renderer: set_underline(#%08x)", color);
m_connection.change_gc(m_gcontexts.at(gc::UL), XCB_GC_FOREGROUND, &color);
m_colors[gc::UL] = color;
2016-11-22 22:18:47 +00:00
}
/**
* Change value of overline gc
*/
2016-11-22 22:18:47 +00:00
void renderer::set_overline(const uint32_t color) {
if (m_colors[gc::OL] == color) {
return m_log.trace_x("renderer: ignoring unchanged overline color(#%08x)", color);
}
2016-11-22 22:18:47 +00:00
m_log.trace_x("renderer: set_overline(#%08x)", color);
m_connection.change_gc(m_gcontexts.at(gc::OL), XCB_GC_FOREGROUND, &color);
m_colors[gc::OL] = color;
2016-11-21 14:07:00 +00:00
}
/**
* Change preferred font index used when matching glyphs
*/
void renderer::set_fontindex(const int8_t font) {
if (m_fontindex == font) {
return m_log.trace_x("renderer: ignoring unchanged font index(%i)", static_cast<int8_t>(font));
}
m_log.trace_x("renderer: set_fontindex(%i)", static_cast<int8_t>(font));
2016-11-21 14:07:00 +00:00
m_fontmanager->set_preferred_font(font);
m_fontindex = font;
2016-11-21 14:07:00 +00:00
}
/**
* Change current alignment
*/
2016-11-21 14:07:00 +00:00
void renderer::set_alignment(const alignment align) {
if (align == m_alignment) {
return m_log.trace_x("renderer: ignoring unchanged alignment(%i)", static_cast<uint8_t>(align));
}
2016-11-21 14:07:00 +00:00
m_log.trace_x("renderer: set_alignment(%i)", static_cast<uint8_t>(align));
m_alignment = align;
2016-11-25 03:10:26 +00:00
m_currentx = 0;
2016-11-21 14:07:00 +00:00
}
/**
* Enable/remove attribute
*/
2016-11-21 14:07:00 +00:00
void renderer::set_attribute(const attribute attr, bool state) {
m_log.trace_x("renderer: set_attribute(%i, %i)", static_cast<uint8_t>(attr), state);
if (state) {
m_attributes |= 1U << static_cast<uint8_t>(attr);
2016-11-21 14:07:00 +00:00
} else {
m_attributes &= ~(1U << static_cast<uint8_t>(attr));
2016-11-21 14:07:00 +00:00
}
}
/**
* Toggle attribute
*/
void renderer::toggle_attribute(const attribute attr) {
m_log.trace_x("renderer: toggle_attribute(%i)", static_cast<uint8_t>(attr));
m_attributes ^= 1U << static_cast<uint8_t>(attr);
}
/**
* Check if the given attribute is set
*/
bool renderer::check_attribute(const attribute attr) {
return (m_attributes >> static_cast<uint8_t>(attr)) & 1U;
}
/**
* Fill background area
*/
2016-11-21 14:07:00 +00:00
void renderer::fill_background() {
m_log.trace_x("renderer: fill_background");
2016-11-25 03:10:26 +00:00
draw_util::fill(m_connection, m_pixmap, m_gcontexts.at(gc::BG), 0, 0, m_rect.width, m_rect.height);
2016-11-21 14:07:00 +00:00
}
/**
* Fill overline area
*/
2016-11-21 14:07:00 +00:00
void renderer::fill_overline(int16_t x, uint16_t w) {
if (!check_attribute(attribute::OVERLINE)) {
return m_log.trace_x("renderer: not filling overline (flag unset)");
} else if (!m_bar.overline.size) {
return m_log.trace_x("renderer: not filling overline (size=0)");
}
m_log.trace_x("renderer: fill_overline(%i, #%08x)", m_bar.overline.size, m_colors[gc::OL]);
2016-11-25 03:10:26 +00:00
draw_util::fill(m_connection, m_pixmap, m_gcontexts.at(gc::OL), x, 0, w, m_bar.overline.size);
2016-11-21 14:07:00 +00:00
}
/**
* Fill underline area
*/
2016-11-21 14:07:00 +00:00
void renderer::fill_underline(int16_t x, uint16_t w) {
if (!check_attribute(attribute::UNDERLINE)) {
return m_log.trace_x("renderer: not filling underline (flag unset)");
} else if (!m_bar.underline.size) {
return m_log.trace_x("renderer: not filling underline (size=0)");
}
m_log.trace_x("renderer: fill_underline(%i, #%08x)", m_bar.underline.size, m_colors[gc::UL]);
2016-11-25 03:10:26 +00:00
int16_t y{static_cast<int16_t>(m_rect.height - m_bar.underline.size)};
draw_util::fill(m_connection, m_pixmap, m_gcontexts.at(gc::UL), x, y, w, m_bar.underline.size);
2016-11-21 14:07:00 +00:00
}
/**
* Shift filled area by given pixels
*/
void renderer::fill_shift(const int16_t px) {
shift_content(px);
}
/**
* Draw character glyph
*/
2016-11-21 14:07:00 +00:00
void renderer::draw_character(uint16_t character) {
2016-11-25 03:10:26 +00:00
m_log.trace_x("renderer: draw_character");
2016-11-21 14:07:00 +00:00
auto& font = m_fontmanager->match_char(character);
if (!font) {
return m_log.warn("No suitable font found (character=%i)", character);
2016-11-21 14:07:00 +00:00
}
if (font->ptr && font->ptr != m_gcfont) {
m_gcfont = font->ptr;
m_fontmanager->set_gcontext_font(m_gcontexts.at(gc::FG), m_gcfont);
}
auto width = m_fontmanager->char_width(font, character);
auto x = shift_content(width);
2016-11-25 03:10:26 +00:00
auto y = m_rect.height / 2 + font->height / 2 - font->descent + font->offset_y;
2016-11-21 14:07:00 +00:00
if (font->xft != nullptr) {
auto color = m_fontmanager->xftcolor();
XftDrawString16(m_fontmanager->xftdraw(), &color, font->xft, x, y, &character, 1);
} else {
uint16_t ucs = ((character >> 8) | (character << 8));
draw_util::xcb_poly_text_16_patched(m_connection, m_pixmap, m_gcontexts.at(gc::FG), x, y, 1, &ucs);
}
fill_underline(x, width);
fill_overline(x, width);
2016-11-21 14:07:00 +00:00
}
/**
* Draw character glyphs
*/
2016-11-21 14:07:00 +00:00
void renderer::draw_textstring(const char* text, size_t len) {
m_log.trace_x("renderer: draw_textstring(\"%s\")", text);
2016-11-21 14:07:00 +00:00
for (size_t n = 0; n < len; n++) {
vector<uint16_t> chars;
chars.emplace_back(text[n]);
auto& font = m_fontmanager->match_char(chars[0]);
if (!font) {
return m_log.warn("No suitable font found (character=%i)", chars[0]);
2016-11-21 14:07:00 +00:00
}
if (font->ptr && font->ptr != m_gcfont) {
m_gcfont = font->ptr;
m_fontmanager->set_gcontext_font(m_gcontexts.at(gc::FG), m_gcfont);
}
while (n + 1 < len && text[n + 1] == chars[0]) {
chars.emplace_back(text[++n]);
}
// TODO: cache
auto width = m_fontmanager->char_width(font, chars[0]) * chars.size();
auto x = shift_content(width);
2016-11-25 03:10:26 +00:00
auto y = m_rect.height / 2 + font->height / 2 - font->descent + font->offset_y;
2016-11-21 14:07:00 +00:00
if (font->xft != nullptr) {
auto color = m_fontmanager->xftcolor();
const FcChar16* drawchars = static_cast<const FcChar16*>(chars.data());
XftDrawString16(m_fontmanager->xftdraw(), &color, font->xft, x, y, drawchars, chars.size());
} else {
2016-11-25 12:55:15 +00:00
for (unsigned short& i : chars) {
i = ((i >> 8) | (i << 8));
2016-11-21 14:07:00 +00:00
}
draw_util::xcb_poly_text_16_patched(
m_connection, m_pixmap, m_gcontexts.at(gc::FG), x, y, chars.size(), chars.data());
}
fill_underline(x, width);
fill_overline(x, width);
2016-11-21 14:07:00 +00:00
}
}
/**
* Create new action block at the current position
*/
2016-11-25 12:55:15 +00:00
void renderer::begin_action(const mousebtn btn, const string& cmd) {
2016-11-21 14:07:00 +00:00
action_block action{};
action.button = btn;
action.align = m_alignment;
action.start_x = m_currentx;
action.command = string_util::replace_all(cmd, ":", "\\:");
action.active = true;
2016-11-25 12:55:15 +00:00
if (action.button == mousebtn::NONE) {
2016-11-21 14:07:00 +00:00
action.button = mousebtn::LEFT;
2016-11-25 12:55:15 +00:00
}
2016-11-21 14:07:00 +00:00
m_log.trace_x("renderer: begin_action(%i, %s)", static_cast<uint8_t>(action.button), cmd.c_str());
m_actions.emplace_back(action);
}
/**
* End action block at the current position
*/
2016-11-21 14:07:00 +00:00
void renderer::end_action(const mousebtn btn) {
2016-11-25 03:10:26 +00:00
int16_t clickable_width{0};
2016-11-21 14:07:00 +00:00
for (auto action = m_actions.rbegin(); action != m_actions.rend(); action++) {
2016-11-25 12:55:15 +00:00
if (!action->active || action->align != m_alignment || action->button != btn) {
2016-11-21 14:07:00 +00:00
continue;
2016-11-25 12:55:15 +00:00
}
2016-11-21 14:07:00 +00:00
action->active = false;
2016-11-25 03:10:26 +00:00
switch (action->align) {
case alignment::NONE:
break;
case alignment::LEFT:
action->end_x = m_currentx;
break;
case alignment::CENTER:
clickable_width = m_currentx - action->start_x;
action->start_x = m_rect.width / 2 - clickable_width / 2 + action->start_x / 2;
action->end_x = action->start_x + clickable_width;
break;
case alignment::RIGHT:
action->start_x = m_rect.width - m_currentx + action->start_x;
action->end_x = m_rect.width;
break;
2016-11-21 14:07:00 +00:00
}
2016-11-25 03:10:26 +00:00
m_log.trace_x("renderer: end_action(%i, %s, %i)", static_cast<uint8_t>(btn), action->command, action->width());
2016-11-21 14:07:00 +00:00
return;
}
}
/**
* Get all action blocks
*/
2016-11-21 14:07:00 +00:00
const vector<action_block> renderer::get_actions() {
return m_actions;
}
/**
* Shift contents by given pixel value
*/
2016-11-25 03:10:26 +00:00
int16_t renderer::shift_content(int16_t x, const int16_t shift_x) {
m_log.trace_x("renderer: shift_content(%i)", shift_x);
2016-11-25 03:10:26 +00:00
int16_t base_x{0};
double delta{static_cast<double>(shift_x)};
2016-11-25 03:10:26 +00:00
switch (m_alignment) {
case alignment::NONE:
break;
case alignment::LEFT:
break;
case alignment::CENTER:
base_x = static_cast<int16_t>(m_rect.width / 2);
m_connection.copy_area(m_pixmap, m_pixmap, m_gcontexts.at(gc::FG), base_x - x / 2, 0, base_x - (x + shift_x) / 2,
0, x, m_rect.height);
x = base_x - (x + shift_x) / 2 + x;
delta /= 2;
break;
case alignment::RIGHT:
base_x = static_cast<int16_t>(m_rect.width - x);
m_connection.copy_area(
m_pixmap, m_pixmap, m_gcontexts.at(gc::FG), base_x, 0, base_x - shift_x, 0, x, m_rect.height);
x = m_rect.width - shift_x;
break;
}
2016-11-25 03:10:26 +00:00
draw_util::fill(m_connection, m_pixmap, m_gcontexts.at(gc::BG), x, 0, m_rect.width - x, m_rect.height);
// Translate pos of clickable areas
if (m_alignment != alignment::LEFT) {
for (auto&& action : m_actions) {
2016-11-25 12:55:15 +00:00
if (action.active || action.align != m_alignment) {
continue;
2016-11-25 12:55:15 +00:00
}
action.start_x -= delta;
action.end_x -= delta;
}
}
m_currentx += shift_x;
2016-11-25 03:10:26 +00:00
return x;
}
/**
* Shift contents by given pixel value
*/
int16_t renderer::shift_content(const int16_t shift_x) {
return shift_content(m_currentx, shift_x);
}
2016-11-25 03:10:26 +00:00
#ifdef DEBUG_HINTS
/**
* Draw debugging hints onto the output window
*/
2016-11-25 03:10:26 +00:00
void renderer::debug_hints() {
uint16_t border_width{1};
2016-11-21 14:07:00 +00:00
map<alignment, int> hint_num{{
2016-11-25 03:10:26 +00:00
// clang-format off
{alignment::LEFT, 0},
{alignment::CENTER, 0},
{alignment::RIGHT, 0},
// clang-format on
2016-11-21 14:07:00 +00:00
}};
2016-11-25 03:10:26 +00:00
for (auto&& hintwin : m_debughints) {
m_connection.destroy_window(hintwin);
}
m_debughints.clear();
2016-11-21 14:07:00 +00:00
for (auto&& action : m_actions) {
if (action.active) {
continue;
}
2016-11-25 03:10:26 +00:00
uint8_t num{static_cast<uint8_t>(hint_num.find(action.align)->second++)};
int16_t x{static_cast<int16_t>(m_bar.pos.x + m_rect.x + action.start_x)};
int16_t y{static_cast<int16_t>(m_bar.pos.y + m_rect.y)};
uint16_t w{static_cast<uint16_t>(action.width() - border_width * 2)};
uint16_t h{static_cast<uint16_t>(m_rect.height - border_width * 2)};
x += num * DEBUG_HINTS_OFFSET_X;
y += num * DEBUG_HINTS_OFFSET_Y;
2016-11-21 14:07:00 +00:00
2016-11-25 03:10:26 +00:00
xcb_window_t hintwin{m_connection.generate_id()};
m_debughints.emplace_back(hintwin);
2016-11-21 14:07:00 +00:00
2016-11-25 03:10:26 +00:00
// clang-format off
winspec(m_connection, hintwin)
<< cw_size(w, h)
<< cw_pos(x, y)
<< cw_border(border_width)
<< cw_depth(32)
<< cw_visual(m_visual->visual_id)
<< cw_params_colormap(m_colormap)
<< cw_params_back_pixel(0)
2016-11-25 03:10:26 +00:00
<< cw_params_border_pixel(num % 2 ? 0xFFFF0000 : 0xFF00FF00)
<< cw_params_override_redirect(true)
<< cw_flush()
;
// clang-format on
2016-11-21 14:07:00 +00:00
2016-11-25 03:10:26 +00:00
xutils::compton_shadow_exclude(m_connection, hintwin);
m_connection.map_window(hintwin);
m_log.info("Debug hint created (x=%lu width=%lu)", x, w);
2016-11-21 14:07:00 +00:00
}
}
2016-11-25 03:10:26 +00:00
#endif
2016-11-21 14:07:00 +00:00
POLYBAR_NS_END