diff --git a/doc/config.cmake b/doc/config.cmake index b5aaa9b5..37930853 100644 --- a/doc/config.cmake +++ b/doc/config.cmake @@ -331,6 +331,8 @@ ramp-foreground = ${colors.foreground-alt} [module/powermenu] type = custom/menu +expand-right = true + format-spacing = 1 label-open =  diff --git a/include/modules/menu.hpp b/include/modules/menu.hpp index 7f62a3a6..a0e1fa3d 100644 --- a/include/modules/menu.hpp +++ b/include/modules/menu.hpp @@ -33,6 +33,8 @@ namespace modules { static constexpr auto EVENT_MENU_OPEN = "menu-open-"; static constexpr auto EVENT_MENU_CLOSE = "menu-close"; + bool m_expand_right{true}; + label_t m_labelopen; label_t m_labelclose; label_t m_labelseparator; diff --git a/src/modules/menu.cpp b/src/modules/menu.cpp index 5935ae5c..f43f4d8e 100644 --- a/src/modules/menu.cpp +++ b/src/modules/menu.cpp @@ -12,9 +12,17 @@ namespace modules { template class module; menu_module::menu_module(const bar_settings& bar, string name_) : static_module(bar, move(name_)) { + m_expand_right = m_conf.get(name(), "expand-right", m_expand_right); + string default_format; - default_format += TAG_LABEL_TOGGLE; - default_format += TAG_MENU; + if(m_expand_right) { + default_format += TAG_LABEL_TOGGLE; + default_format += TAG_MENU; + } else { + default_format += TAG_MENU; + default_format += TAG_LABEL_TOGGLE; + } + m_formatter->add(DEFAULT_FORMAT, default_format, {TAG_LABEL_TOGGLE, TAG_MENU}); @@ -67,6 +75,20 @@ namespace modules { } else if (tag == TAG_MENU && m_level > -1) { auto spacing = m_formatter->get(get_format())->spacing; for (auto&& item : m_levels[m_level]->items) { + /* + * Depending on whether the menu items are to the left or right of the toggle label, the items need to be + * drawn before or after the spacings and the separator + * + * If the menu expands to the left, the separator should be drawn on the right side because otherwise the menu + * would look like this: + * | x | y + */ + if(!m_expand_right) { + builder->cmd(mousebtn::LEFT, item->exec); + builder->node(item->label); + builder->cmd_close(); + } + if (*m_labelseparator) { if (item != m_levels[m_level]->items[0]) { builder->space(spacing); @@ -74,9 +96,17 @@ namespace modules { builder->node(m_labelseparator); builder->space(spacing); } - builder->cmd(mousebtn::LEFT, item->exec); - builder->node(item->label); - builder->cmd_close(); + + /* + * If the menu expands to the right, the separator should be drawn on the left side because otherwise the menu + * would look like this: + * x | y | + */ + if(m_expand_right) { + builder->cmd(mousebtn::LEFT, item->exec); + builder->node(item->label); + builder->cmd_close(); + } } } else { return false;