From 4c2d71016958e9069bdf5a6dcfc7bb621521ad85 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 14 Dec 2016 10:09:39 +0100 Subject: [PATCH] fix(tray): Adjust action coords Ref #241 --- src/components/bar.cpp | 14 +++++--------- src/components/renderer.cpp | 30 +++++++++++++----------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/components/bar.cpp b/src/components/bar.cpp index 2b6462d5..70883382 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -642,28 +642,24 @@ void bar::handle(const evt::button_press& evt) { 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(evt->detail)}; - const int16_t event_x{static_cast(evt->event_x - m_opts.inner_area().x)}; for (auto&& action : m_renderer->get_actions()) { if (action.active) { - m_log.trace_x("bar: Ignoring action: unclosed)"); continue; } else if (action.button != button) { - m_log.trace_x("bar: Ignoring action: button mismatch"); continue; - } else if (action.start_x >= event_x) { - m_log.trace_x("bar: Ignoring action: start_x(%i) > event_x(%i)", action.start_x, event_x); + } else if (action.start_x >= evt->event_x) { continue; - } else if (action.end_x <= event_x) { - m_log.trace_x("bar: Ignoring action: end_x(%i) < event_x(%i)", action.end_x, event_x); + } else if (action.end_x < evt->event_x) { continue; } + m_log.trace("Found matching input area"); m_log.trace_x("action.command = %s", action.command); - m_log.trace_x("action.button = %i", static_cast(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.end_x = %i", action.end_x); diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index 0c46eb6e..e88a5149 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -213,13 +213,13 @@ void renderer::flush(bool clear) { xcb_rectangle_t clear_area{0, 0, 0U, 0U}; 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.width = m_cleararea.size; clear_area.height = m_bar.size.h; } else if (m_cleararea.size && m_cleararea.side == edge::LEFT) { - clear_area.x = m_rect.x; - clear_area.y = m_rect.y; + clear_area.x = left.width; + clear_area.y = top.height; clear_area.width = m_cleararea.size; clear_area.height = m_rect.height; } else if (m_cleararea.size && m_cleararea.side == edge::TOP) { @@ -570,6 +570,9 @@ void renderer::end_action(const mousebtn btn) { 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(btn), action->command, action->width()); 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); int16_t base_x{0}; - double delta{static_cast(shift_x)}; + double delta{0.0}; switch (m_alignment) { 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, 0, x, m_rect.height); x = base_x - (x + shift_x) / 2 + x; - delta /= 2; + delta = static_cast(shift_x) / 2; break; case alignment::RIGHT: base_x = static_cast(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; + delta = static_cast(shift_x); break; } @@ -662,22 +666,15 @@ void renderer::debug_hints() { continue; } - uint8_t num{static_cast(hint_num.find(action.align)->second++)}; - int16_t x{static_cast(m_bar.pos.x + m_rect.x + action.start_x)}; - int16_t y{static_cast(m_bar.pos.y + m_rect.y)}; - uint16_t w{static_cast(action.width() - border_width * 2)}; - uint16_t h{static_cast(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()}; m_debughints.emplace_back(hintwin); + uint8_t num{static_cast(hint_num.find(action.align)->second++)}; + // clang-format off winspec(m_connection, hintwin) - << cw_size(w, h) - << cw_pos(x, y) + << cw_size(action.width() - border_width * 2, m_rect.height - border_width * 2) + << 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_depth(32) << cw_visual(m_visual->visual_id) @@ -691,7 +688,6 @@ void renderer::debug_hints() { xutils::compton_shadow_exclude(m_connection, hintwin); m_connection.map_window(hintwin); - m_log.info("Debug hint created (x=%lu width=%lu)", x, w); } } #endif