menu stuff (fix #4)

This commit is contained in:
ouwou
2020-12-12 21:57:39 -05:00
parent 4b3a086881
commit 93c67bc868
3 changed files with 129 additions and 82 deletions

View File

@@ -13,6 +13,7 @@
#include <condition_variable>
#include <optional>
#include <type_traits>
#include <gtkmm.h>
namespace util {
template<typename T>
@@ -20,7 +21,7 @@ struct is_optional : ::std::false_type {};
template<typename T>
struct is_optional<::std::optional<T>> : ::std::true_type {};
}
} // namespace util
class Semaphore {
public:
@@ -232,3 +233,15 @@ std::string RegexReplaceMany(std::string str, std::string regexstr, F func) {
return str;
}
inline void AddWidgetMenuHandler(Gtk::Widget *widget, Gtk::Menu &menu) {
widget->signal_button_press_event().connect([&menu](GdkEventButton *ev) -> bool {
if (ev->type == GDK_BUTTON_PRESS && ev->button == GDK_BUTTON_SECONDARY) {
menu.popup_at_pointer(reinterpret_cast<const GdkEvent *>(ev));
return true;
}
return false;
// clang-format off
}, false);
// clang-format on
}