summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2022-10-23 02:56:07 +0000
committerGitHub <noreply@github.com>2022-10-23 02:56:07 +0000
commit772598996c24d570cb74686c4d888d6f1aa070ad (patch)
treeea24449b77bc69f9186b1d125acd190bbe27abcc /src
parentccb82c1676326107133e63b7822dfd0b87afd0f2 (diff)
downloadabaddon-portaudio-772598996c24d570cb74686c4d888d6f1aa070ad.tar.gz
abaddon-portaudio-772598996c24d570cb74686c4d888d6f1aa070ad.zip
Add option to hide the menu bar behind alt key (#115)
Diffstat (limited to 'src')
-rw-r--r--src/abaddon.cpp20
-rw-r--r--src/settings.cpp2
-rw-r--r--src/settings.hpp2
-rw-r--r--src/windows/mainwindow.cpp24
-rw-r--r--src/windows/mainwindow.hpp1
5 files changed, 42 insertions, 7 deletions
diff --git a/src/abaddon.cpp b/src/abaddon.cpp
index ec567e7..630e584 100644
--- a/src/abaddon.cpp
+++ b/src/abaddon.cpp
@@ -68,14 +68,13 @@ Abaddon &Abaddon::Get() {
return instance;
}
-#ifdef WITH_LIBHANDY
- #ifdef _WIN32
+#ifdef _WIN32
constexpr static guint BUTTON_BACK = 4;
constexpr static guint BUTTON_FORWARD = 5;
- #else
+#else
constexpr static guint BUTTON_BACK = 8;
constexpr static guint BUTTON_FORWARD = 9;
- #endif
+#endif
static bool HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
if (event->type != GDK_BUTTON_PRESS) return false;
@@ -85,6 +84,7 @@ static bool HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
auto *window = gtk_widget_get_toplevel(widget);
if (static_cast<void *>(window) != static_cast<void *>(main_window->gobj())) return false; // is this the right way???
+#ifdef WITH_LIBHANDY
switch (event->button.button) {
case BUTTON_BACK:
main_window->GoBack();
@@ -93,6 +93,7 @@ static bool HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
main_window->GoForward();
break;
}
+#endif
return false;
}
@@ -108,6 +109,15 @@ static bool HandleKeyEvents(GdkEvent *event, MainWindow *main_window) {
const bool ctrl = (event->key.state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
const bool shft = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
+ constexpr static guint EXCLUDE_STATES = GDK_CONTROL_MASK | GDK_SHIFT_MASK;
+
+ if (!(event->key.state & EXCLUDE_STATES) && event->key.keyval == GDK_KEY_Alt_L) {
+ if (Abaddon::Get().GetSettings().AltMenu) {
+ main_window->ToggleMenuVisibility();
+ }
+ }
+
+#ifdef WITH_LIBHANDY
if (ctrl) {
switch (event->key.keyval) {
case GDK_KEY_Tab:
@@ -134,6 +144,7 @@ static bool HandleKeyEvents(GdkEvent *event, MainWindow *main_window) {
return true;
}
}
+#endif
return false;
}
@@ -143,7 +154,6 @@ static void MainEventHandler(GdkEvent *event, void *main_window) {
if (HandleKeyEvents(event, static_cast<MainWindow *>(main_window))) return;
gtk_main_do_event(event);
}
-#endif
int Abaddon::StartGTK() {
m_gtk_app = Gtk::Application::create("com.github.uowuo.abaddon");
diff --git a/src/settings.cpp b/src/settings.cpp
index dd1fe83..34b3dc0 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -48,6 +48,7 @@ void SettingsManager::ReadSettings() {
SMBOOL("gui", "save_state", SaveState);
SMBOOL("gui", "stock_emojis", ShowStockEmojis);
SMBOOL("gui", "unreads", Unreads);
+ SMBOOL("gui", "alt_menu", AltMenu);
SMBOOL("gui", "hide_to_tray", HideToTray);
SMINT("http", "concurrent", CacheHTTPConcurrency);
SMSTR("http", "user_agent", UserAgent);
@@ -102,6 +103,7 @@ void SettingsManager::Close() {
SMBOOL("gui", "save_state", SaveState);
SMBOOL("gui", "stock_emojis", ShowStockEmojis);
SMBOOL("gui", "unreads", Unreads);
+ SMBOOL("gui", "alt_menu", AltMenu);
SMBOOL("gui", "hide_to_tray", HideToTray);
SMINT("http", "concurrent", CacheHTTPConcurrency);
SMSTR("http", "user_agent", UserAgent);
diff --git a/src/settings.hpp b/src/settings.hpp
index 7f5e015..4ab512e 100644
--- a/src/settings.hpp
+++ b/src/settings.hpp
@@ -27,7 +27,7 @@ public:
bool ShowStockEmojis { true };
#endif
bool Unreads { true };
-
+ bool AltMenu { false };
bool HideToTray { false };
// [http]
diff --git a/src/windows/mainwindow.cpp b/src/windows/mainwindow.cpp
index 07a7f17..20da46b 100644
--- a/src/windows/mainwindow.cpp
+++ b/src/windows/mainwindow.cpp
@@ -158,6 +158,10 @@ void MainWindow::UpdateMenus() {
OnViewSubmenuPopup();
}
+void MainWindow::ToggleMenuVisibility() {
+ m_menu_bar.set_visible(!m_menu_bar.get_visible());
+}
+
#ifdef WITH_LIBHANDY
void MainWindow::GoBack() {
m_chat.GoBack();
@@ -279,7 +283,25 @@ void MainWindow::SetupMenu() {
m_menu_bar.append(m_menu_file);
m_menu_bar.append(m_menu_discord);
m_menu_bar.append(m_menu_view);
- m_menu_bar.show_all();
+
+ if (Abaddon::Get().GetSettings().AltMenu) {
+ auto set_hide_cb = [this](Gtk::Menu &menu) {
+ for (auto *child : menu.get_children()) {
+ auto *item = dynamic_cast<Gtk::MenuItem *>(child);
+ if (item != nullptr) {
+ item->signal_activate().connect([this]() {
+ m_menu_bar.hide();
+ });
+ }
+ }
+ };
+ set_hide_cb(m_menu_discord_sub);
+ set_hide_cb(m_menu_file_sub);
+ set_hide_cb(m_menu_view_sub);
+ m_menu_bar.show_all_children();
+ } else {
+ m_menu_bar.show_all();
+ }
m_menu_discord_connect.signal_activate().connect([this] {
m_signal_action_connect.emit();
diff --git a/src/windows/mainwindow.hpp b/src/windows/mainwindow.hpp
index b013e32..6e95b72 100644
--- a/src/windows/mainwindow.hpp
+++ b/src/windows/mainwindow.hpp
@@ -24,6 +24,7 @@ public:
void UpdateChatReactionAdd(Snowflake id, const Glib::ustring &param);
void UpdateChatReactionRemove(Snowflake id, const Glib::ustring &param);
void UpdateMenus();
+ void ToggleMenuVisibility();
#ifdef WITH_LIBHANDY
void GoBack();