fix mouseover error when only one cursor is defined

If only cursor-click or cursor-scroll is defined, but not the other, the
bar could try to set the cursor to the empty string which resulted in an
error.
This commit is contained in:
patrick96 2022-03-20 19:09:45 +01:00 committed by Patrick Ziegler
parent cea9949be1
commit 3f89d73374
4 changed files with 48 additions and 61 deletions

View File

@ -31,12 +31,7 @@ namespace tags {
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify, evt::enter_notify,
evt::leave_notify, evt::motion_notify, evt::destroy_notify, evt::client_message, evt::configure_notify>,
public signal_receiver<SIGN_PRIORITY_BAR, signals::ui::dim_window
#if WITH_XCURSOR
,
signals::ui::cursor_change
#endif
> {
public signal_receiver<SIGN_PRIORITY_BAR, signals::ui::dim_window> {
public:
using make_type = unique_ptr<bar>;
static make_type make(eventloop::loop&, bool only_initialize_values = false);
@ -80,8 +75,14 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
void handle(const evt::configure_notify& evt) override;
bool on(const signals::ui::dim_window&) override;
#if WITH_XCURSOR
bool on(const signals::ui::cursor_change&) override;
/**
* Change cursor to the given cursor name.
*
* The cursor name must be valid (cursor_util::valid)
*/
void change_cursor(const string& name);
#endif
private:

View File

@ -81,9 +81,6 @@ namespace signals {
struct button_press : public detail::value_signal<button_press, string> {
using base_type::base_type;
};
struct cursor_change : public detail::value_signal<cursor_change, string> {
using base_type::base_type;
};
struct visibility_change : public detail::value_signal<visibility_change, bool> {
using base_type::base_type;
};

View File

@ -28,7 +28,6 @@ namespace signals {
namespace ui {
struct changed;
struct button_press;
struct cursor_change;
struct visibility_change;
struct dim_window;
struct request_snapshot;

View File

@ -747,21 +747,14 @@ void bar::handle(const evt::motion_notify& evt) {
return false;
};
if (has_action({mousebtn::LEFT, mousebtn::MIDDLE, mousebtn::RIGHT, mousebtn::DOUBLE_LEFT, mousebtn::DOUBLE_MIDDLE,
mousebtn::DOUBLE_RIGHT})) {
if (m_opts.cursor != m_opts.cursor_click) {
m_opts.cursor = m_opts.cursor_click;
m_sig.emit(cursor_change{string{m_opts.cursor}});
}
if (!m_opts.cursor_click.empty() && has_action({mousebtn::LEFT, mousebtn::MIDDLE, mousebtn::RIGHT,
mousebtn::DOUBLE_LEFT, mousebtn::DOUBLE_MIDDLE, mousebtn::DOUBLE_RIGHT})) {
change_cursor(m_opts.cursor_click);
return;
}
if (has_action({mousebtn::SCROLL_DOWN, mousebtn::SCROLL_UP})) {
if (m_opts.cursor != m_opts.cursor_scroll) {
m_opts.cursor = m_opts.cursor_scroll;
m_sig.emit(cursor_change{string{m_opts.cursor}});
}
if (!m_opts.cursor_scroll.empty() && has_action({mousebtn::SCROLL_DOWN, mousebtn::SCROLL_UP})) {
change_cursor(m_opts.cursor_scroll);
return;
}
@ -769,10 +762,7 @@ void bar::handle(const evt::motion_notify& evt) {
if (!m_opts.cursor_click.empty() &&
!(action.button == mousebtn::SCROLL_UP || action.button == mousebtn::SCROLL_DOWN ||
action.button == mousebtn::NONE)) {
if (m_opts.cursor != m_opts.cursor_click) {
m_opts.cursor = m_opts.cursor_click;
m_sig.emit(cursor_change{string{m_opts.cursor}});
}
change_cursor(m_opts.cursor_click);
return true;
} else if (!m_opts.cursor_scroll.empty() &&
(action.button == mousebtn::SCROLL_UP || action.button == mousebtn::SCROLL_DOWN)) {
@ -786,25 +776,20 @@ void bar::handle(const evt::motion_notify& evt) {
for (auto&& action : m_opts.actions) {
if (!action.command.empty()) {
m_log.trace("Found matching fallback handler");
if (find_click_area(action))
if (find_click_area(action)) {
return;
}
}
}
if (found_scroll) {
if (m_opts.cursor != m_opts.cursor_scroll) {
m_opts.cursor = m_opts.cursor_scroll;
m_sig.emit(cursor_change{string{m_opts.cursor}});
}
change_cursor(m_opts.cursor_scroll);
return;
}
if (m_opts.cursor != "default") {
m_log.trace("No matching cursor area found");
m_opts.cursor = "default";
m_sig.emit(cursor_change{string{m_opts.cursor}});
change_cursor("default");
return;
}
#endif
}
@ -931,12 +916,17 @@ bool bar::on(const signals::ui::dim_window& sig) {
}
#if WITH_XCURSOR
bool bar::on(const signals::ui::cursor_change& sig) {
if (!cursor_util::set_cursor(m_connection, m_connection.screen(), m_opts.window, sig.cast())) {
void bar::change_cursor(const string& name) {
// This is already the same cursor, no need to update
if (m_opts.cursor == name) {
return;
}
m_opts.cursor = name;
if (!cursor_util::set_cursor(m_connection, m_connection.screen(), m_opts.window, name)) {
m_log.warn("Failed to create cursor context");
}
m_connection.flush();
return false;
}
#endif