add ctrl(+shift)+tab keybinds
This commit is contained in:
@@ -76,13 +76,13 @@ constexpr static guint BUTTON_BACK = 8;
|
|||||||
constexpr static guint BUTTON_FORWARD = 9;
|
constexpr static guint BUTTON_FORWARD = 9;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
|
static bool HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
|
||||||
if (event->type != GDK_BUTTON_PRESS) return;
|
if (event->type != GDK_BUTTON_PRESS) return false;
|
||||||
|
|
||||||
auto *widget = gtk_get_event_widget(event);
|
auto *widget = gtk_get_event_widget(event);
|
||||||
if (widget == nullptr) return;
|
if (widget == nullptr) return false;
|
||||||
auto *window = gtk_widget_get_toplevel(widget);
|
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) {
|
switch (event->button.button) {
|
||||||
case BUTTON_BACK:
|
case BUTTON_BACK:
|
||||||
@@ -92,10 +92,40 @@ static void HandleButtonEvents(GdkEvent *event, MainWindow *main_window) {
|
|||||||
main_window->GoForward();
|
main_window->GoForward();
|
||||||
break;
|
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) {
|
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);
|
gtk_main_do_event(event);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -115,6 +115,22 @@ void ChannelTabSwitcherHandy::GoForwardOnCurrent() {
|
|||||||
AdvanceOnCurrent(1);
|
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 {
|
int ChannelTabSwitcherHandy::GetNumberOfTabs() const {
|
||||||
return hdy_tab_view_get_n_pages(m_tab_view);
|
return hdy_tab_view_get_n_pages(m_tab_view);
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,8 @@ public:
|
|||||||
|
|
||||||
void GoBackOnCurrent();
|
void GoBackOnCurrent();
|
||||||
void GoForwardOnCurrent();
|
void GoForwardOnCurrent();
|
||||||
|
void GoToPreviousTab();
|
||||||
|
void GoToNextTab();
|
||||||
|
|
||||||
[[nodiscard]] int GetNumberOfTabs() const;
|
[[nodiscard]] int GetNumberOfTabs() const;
|
||||||
|
|
||||||
|
@@ -192,6 +192,14 @@ void ChatWindow::GoBack() {
|
|||||||
void ChatWindow::GoForward() {
|
void ChatWindow::GoForward() {
|
||||||
m_tab_switcher->GoForwardOnCurrent();
|
m_tab_switcher->GoForwardOnCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatWindow::GoToPreviousTab() {
|
||||||
|
m_tab_switcher->GoToPreviousTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatWindow::GoToNextTab() {
|
||||||
|
m_tab_switcher->GoToNextTab();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Snowflake ChatWindow::GetActiveChannel() const {
|
Snowflake ChatWindow::GetActiveChannel() const {
|
||||||
|
@@ -41,6 +41,8 @@ public:
|
|||||||
void UseTabsState(const TabsState &state);
|
void UseTabsState(const TabsState &state);
|
||||||
void GoBack();
|
void GoBack();
|
||||||
void GoForward();
|
void GoForward();
|
||||||
|
void GoToPreviousTab();
|
||||||
|
void GoToNextTab();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -165,6 +165,14 @@ void MainWindow::GoBack() {
|
|||||||
void MainWindow::GoForward() {
|
void MainWindow::GoForward() {
|
||||||
m_chat.GoForward();
|
m_chat.GoForward();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::GoToPreviousTab() {
|
||||||
|
m_chat.GoToPreviousTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::GoToNextTab() {
|
||||||
|
m_chat.GoToNextTab();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void MainWindow::OnDiscordSubmenuPopup() {
|
void MainWindow::OnDiscordSubmenuPopup() {
|
||||||
|
@@ -28,6 +28,8 @@ public:
|
|||||||
#ifdef WITH_LIBHANDY
|
#ifdef WITH_LIBHANDY
|
||||||
void GoBack();
|
void GoBack();
|
||||||
void GoForward();
|
void GoForward();
|
||||||
|
void GoToPreviousTab();
|
||||||
|
void GoToNextTab();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ChannelList *GetChannelList();
|
ChannelList *GetChannelList();
|
||||||
|
Reference in New Issue
Block a user