fix(tray): Adjust action coords

Ref #241
This commit is contained in:
Michael Carlberg 2016-12-14 10:09:39 +01:00
parent 3a6ca90fcb
commit 4c2d710169
2 changed files with 18 additions and 26 deletions

View File

@ -642,28 +642,24 @@ void bar::handle(const evt::button_press& evt) {
return m_log.trace_x("bar: Ignoring button press (throttled)..."); return m_log.trace_x("bar: Ignoring button press (throttled)...");
} }
m_log.trace_x("bar: Received button press: %i at pos(%i, %i)", evt->detail, evt->event_x, evt->event_y); m_log.trace("bar: Received button press: %i at pos(%i, %i)", evt->detail, evt->event_x, evt->event_y);
const mousebtn button{static_cast<mousebtn>(evt->detail)}; const mousebtn button{static_cast<mousebtn>(evt->detail)};
const int16_t event_x{static_cast<int16_t>(evt->event_x - m_opts.inner_area().x)};
for (auto&& action : m_renderer->get_actions()) { for (auto&& action : m_renderer->get_actions()) {
if (action.active) { if (action.active) {
m_log.trace_x("bar: Ignoring action: unclosed)");
continue; continue;
} else if (action.button != button) { } else if (action.button != button) {
m_log.trace_x("bar: Ignoring action: button mismatch");
continue; continue;
} else if (action.start_x >= event_x) { } else if (action.start_x >= evt->event_x) {
m_log.trace_x("bar: Ignoring action: start_x(%i) > event_x(%i)", action.start_x, event_x);
continue; continue;
} else if (action.end_x <= event_x) { } else if (action.end_x < evt->event_x) {
m_log.trace_x("bar: Ignoring action: end_x(%i) < event_x(%i)", action.end_x, event_x);
continue; continue;
} }
m_log.trace("Found matching input area"); m_log.trace("Found matching input area");
m_log.trace_x("action.command = %s", action.command); m_log.trace_x("action.command = %s", action.command);
m_log.trace_x("action.button = %i", static_cast<int>(action.button)); m_log.trace_x("action.button = %i", evt->detail);
m_log.trace_x("action.start_x = %i", action.start_x); m_log.trace_x("action.start_x = %i", action.start_x);
m_log.trace_x("action.end_x = %i", action.end_x); m_log.trace_x("action.end_x = %i", action.end_x);

View File

@ -213,13 +213,13 @@ void renderer::flush(bool clear) {
xcb_rectangle_t clear_area{0, 0, 0U, 0U}; xcb_rectangle_t clear_area{0, 0, 0U, 0U};
if (m_cleararea.size && m_cleararea.side == edge::RIGHT) { if (m_cleararea.size && m_cleararea.side == edge::RIGHT) {
clear_area.x = m_bar.size.w - m_cleararea.size; clear_area.x = m_bar.size.w - m_cleararea.size - right.width;
clear_area.y = 0; clear_area.y = 0;
clear_area.width = m_cleararea.size; clear_area.width = m_cleararea.size;
clear_area.height = m_bar.size.h; clear_area.height = m_bar.size.h;
} else if (m_cleararea.size && m_cleararea.side == edge::LEFT) { } else if (m_cleararea.size && m_cleararea.side == edge::LEFT) {
clear_area.x = m_rect.x; clear_area.x = left.width;
clear_area.y = m_rect.y; clear_area.y = top.height;
clear_area.width = m_cleararea.size; clear_area.width = m_cleararea.size;
clear_area.height = m_rect.height; clear_area.height = m_rect.height;
} else if (m_cleararea.size && m_cleararea.side == edge::TOP) { } else if (m_cleararea.size && m_cleararea.side == edge::TOP) {
@ -570,6 +570,9 @@ void renderer::end_action(const mousebtn btn) {
break; break;
} }
action->start_x += m_bar.pos.x + m_rect.x;
action->end_x += m_bar.pos.x + m_rect.x;
m_log.trace_x("renderer: end_action(%i, %s, %i)", static_cast<uint8_t>(btn), action->command, action->width()); m_log.trace_x("renderer: end_action(%i, %s, %i)", static_cast<uint8_t>(btn), action->command, action->width());
return; return;
@ -590,7 +593,7 @@ int16_t renderer::shift_content(int16_t x, const int16_t shift_x) {
m_log.trace_x("renderer: shift_content(%i)", shift_x); m_log.trace_x("renderer: shift_content(%i)", shift_x);
int16_t base_x{0}; int16_t base_x{0};
double delta{static_cast<double>(shift_x)}; double delta{0.0};
switch (m_alignment) { switch (m_alignment) {
case alignment::NONE: case alignment::NONE:
@ -602,13 +605,14 @@ int16_t renderer::shift_content(int16_t x, const int16_t shift_x) {
m_connection.copy_area(m_pixmap, m_pixmap, m_gcontexts.at(gc::FG), base_x - x / 2, 0, base_x - (x + shift_x) / 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); 0, x, m_rect.height);
x = base_x - (x + shift_x) / 2 + x; x = base_x - (x + shift_x) / 2 + x;
delta /= 2; delta = static_cast<double>(shift_x) / 2;
break; break;
case alignment::RIGHT: case alignment::RIGHT:
base_x = static_cast<int16_t>(m_rect.width - x); base_x = static_cast<int16_t>(m_rect.width - x);
m_connection.copy_area( 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); 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; x = m_rect.width - shift_x;
delta = static_cast<double>(shift_x);
break; break;
} }
@ -662,22 +666,15 @@ void renderer::debug_hints() {
continue; continue;
} }
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;
xcb_window_t hintwin{m_connection.generate_id()}; xcb_window_t hintwin{m_connection.generate_id()};
m_debughints.emplace_back(hintwin); m_debughints.emplace_back(hintwin);
uint8_t num{static_cast<uint8_t>(hint_num.find(action.align)->second++)};
// clang-format off // clang-format off
winspec(m_connection, hintwin) winspec(m_connection, hintwin)
<< cw_size(w, h) << cw_size(action.width() - border_width * 2, m_rect.height - border_width * 2)
<< cw_pos(x, y) << cw_pos(action.start_x + num * DEBUG_HINTS_OFFSET_X, m_bar.pos.y + m_rect.y + num * DEBUG_HINTS_OFFSET_Y)
<< cw_border(border_width) << cw_border(border_width)
<< cw_depth(32) << cw_depth(32)
<< cw_visual(m_visual->visual_id) << cw_visual(m_visual->visual_id)
@ -691,7 +688,6 @@ void renderer::debug_hints() {
xutils::compton_shadow_exclude(m_connection, hintwin); xutils::compton_shadow_exclude(m_connection, hintwin);
m_connection.map_window(hintwin); m_connection.map_window(hintwin);
m_log.info("Debug hint created (x=%lu width=%lu)", x, w);
} }
} }
#endif #endif