summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/abaddon.cpp40
-rw-r--r--src/components/channeltabswitcherhandy.cpp16
-rw-r--r--src/components/channeltabswitcherhandy.hpp2
-rw-r--r--src/components/chatwindow.cpp8
-rw-r--r--src/components/chatwindow.hpp2
-rw-r--r--src/windows/mainwindow.cpp8
-rw-r--r--src/windows/mainwindow.hpp2
7 files changed, 73 insertions, 5 deletions
diff --git a/src/abaddon.cpp b/src/abaddon.cpp
index a8e8332..0e674fe 100644
--- a/src/abaddon.cpp
+++ b/src/abaddon.cpp
@@ -76,13 +76,13 @@ constexpr static guint BUTTON_BACK = 8;
constexpr static guint BUTTON_FORWARD = 9;
#endif
-static void HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
- if (event->type != GDK_BUTTON_PRESS) return;
+static bool HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
+ if (event->type != GDK_BUTTON_PRESS) return false;
auto *widget = gtk_get_event_widget(event);
- if (widget == nullptr) return;
+ if (widget == nullptr) return false;
auto *window = gtk_widget_get_toplevel(widget);
- if (static_cast<void *>(window) != static_cast<void *>(main_window->gobj())) return; // is this the right way???
+ if (static_cast<void *>(window) != static_cast<void *>(main_window->gobj())) return false; // is this the right way???
switch (event->button.button) {
case BUTTON_BACK:
@@ -92,10 +92,40 @@ static void HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
main_window->GoForward();
break;
}
+
+ return false;
+}
+
+static bool HandleKeyEvents(GdkEvent *event, MainWindow *main_window) {
+ if (event->type != GDK_KEY_PRESS) return false;
+
+ auto *widget = gtk_get_event_widget(event);
+ if (widget == nullptr) return false;
+ auto *window = gtk_widget_get_toplevel(widget);
+ if (static_cast<void *>(window) != static_cast<void *>(main_window->gobj())) return false;
+
+ const bool ctrl = (event->key.state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
+ const bool shft = (event->key.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
+
+ if (ctrl) {
+ switch (event->key.keyval) {
+ case GDK_KEY_Tab:
+ case GDK_KEY_KP_Tab:
+ case GDK_KEY_ISO_Left_Tab:
+ if (shft)
+ main_window->GoToPreviousTab();
+ else
+ main_window->GoToNextTab();
+ return true;
+ }
+ }
+
+ return false;
}
static void MainEventHandler(GdkEvent *event, void *main_window) {
- HandleButtonEvents(event, static_cast<MainWindow *>(main_window));
+ if (HandleButtonEvents(event, static_cast<MainWindow *>(main_window))) return;
+ if (HandleKeyEvents(event, static_cast<MainWindow *>(main_window))) return;
gtk_main_do_event(event);
}
#endif
diff --git a/src/components/channeltabswitcherhandy.cpp b/src/components/channeltabswitcherhandy.cpp
index 67dbff0..2faa2e2 100644
--- a/src/components/channeltabswitcherhandy.cpp
+++ b/src/components/channeltabswitcherhandy.cpp
@@ -115,6 +115,22 @@ void ChannelTabSwitcherHandy::GoForwardOnCurrent() {
AdvanceOnCurrent(1);
}
+void ChannelTabSwitcherHandy::GoToPreviousTab() {
+ if (!hdy_tab_view_select_previous_page(m_tab_view)) {
+ if (const auto num_pages = hdy_tab_view_get_n_pages(m_tab_view); num_pages > 1) {
+ hdy_tab_view_set_selected_page(m_tab_view, hdy_tab_view_get_nth_page(m_tab_view, num_pages - 1));
+ }
+ }
+}
+
+void ChannelTabSwitcherHandy::GoToNextTab() {
+ if (!hdy_tab_view_select_next_page(m_tab_view)) {
+ if (hdy_tab_view_get_n_pages(m_tab_view) > 1) {
+ hdy_tab_view_set_selected_page(m_tab_view, hdy_tab_view_get_nth_page(m_tab_view, 0));
+ }
+ }
+}
+
int ChannelTabSwitcherHandy::GetNumberOfTabs() const {
return hdy_tab_view_get_n_pages(m_tab_view);
}
diff --git a/src/components/channeltabswitcherhandy.hpp b/src/components/channeltabswitcherhandy.hpp
index 6da9b17..a0149be 100644
--- a/src/components/channeltabswitcherhandy.hpp
+++ b/src/components/channeltabswitcherhandy.hpp
@@ -24,6 +24,8 @@ public:
void GoBackOnCurrent();
void GoForwardOnCurrent();
+ void GoToPreviousTab();
+ void GoToNextTab();
[[nodiscard]] int GetNumberOfTabs() const;
diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp
index 8667488..3cfde1b 100644
--- a/src/components/chatwindow.cpp
+++ b/src/components/chatwindow.cpp
@@ -192,6 +192,14 @@ void ChatWindow::GoBack() {
void ChatWindow::GoForward() {
m_tab_switcher->GoForwardOnCurrent();
}
+
+void ChatWindow::GoToPreviousTab() {
+ m_tab_switcher->GoToPreviousTab();
+}
+
+void ChatWindow::GoToNextTab() {
+ m_tab_switcher->GoToNextTab();
+}
#endif
Snowflake ChatWindow::GetActiveChannel() const {
diff --git a/src/components/chatwindow.hpp b/src/components/chatwindow.hpp
index 1c0b7cc..36bce6a 100644
--- a/src/components/chatwindow.hpp
+++ b/src/components/chatwindow.hpp
@@ -41,6 +41,8 @@ public:
void UseTabsState(const TabsState &state);
void GoBack();
void GoForward();
+ void GoToPreviousTab();
+ void GoToNextTab();
#endif
protected:
diff --git a/src/windows/mainwindow.cpp b/src/windows/mainwindow.cpp
index b77981c..a6da507 100644
--- a/src/windows/mainwindow.cpp
+++ b/src/windows/mainwindow.cpp
@@ -165,6 +165,14 @@ void MainWindow::GoBack() {
void MainWindow::GoForward() {
m_chat.GoForward();
}
+
+void MainWindow::GoToPreviousTab() {
+ m_chat.GoToPreviousTab();
+}
+
+void MainWindow::GoToNextTab() {
+ m_chat.GoToNextTab();
+}
#endif
void MainWindow::OnDiscordSubmenuPopup() {
diff --git a/src/windows/mainwindow.hpp b/src/windows/mainwindow.hpp
index ce3a576..4f6469e 100644
--- a/src/windows/mainwindow.hpp
+++ b/src/windows/mainwindow.hpp
@@ -28,6 +28,8 @@ public:
#ifdef WITH_LIBHANDY
void GoBack();
void GoForward();
+ void GoToPreviousTab();
+ void GoToNextTab();
#endif
ChannelList *GetChannelList();