From 1296aa108b6fccce45655c78fccdc10f102d33fc Mon Sep 17 00:00:00 2001 From: Federico Guerinoni Date: Sun, 5 Feb 2023 03:26:20 +0100 Subject: Ladybird: Close tab clicking wheel of the mouse --- Ladybird/BrowserWindow.cpp | 18 ++++++++++++++++++ Ladybird/BrowserWindow.h | 3 +++ 2 files changed, 21 insertions(+) (limited to 'Ladybird') diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index faccfc978a..14cc23dfe7 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -22,6 +22,7 @@ #include #include #include +#include extern DeprecatedString s_serenity_resource_root; extern Browser::Settings* s_settings; @@ -31,6 +32,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive , m_webdriver_content_ipc_path(webdriver_content_ipc_path) { m_tabs_container = new QTabWidget(this); + m_tabs_container->installEventFilter(this); m_tabs_container->setElideMode(Qt::TextElideMode::ElideRight); m_tabs_container->setMovable(true); m_tabs_container->setTabsClosable(true); @@ -504,3 +506,19 @@ void BrowserWindow::copy_selected_text() clipboard->setText(qstring_from_ak_deprecated_string(text)); } } + +bool BrowserWindow::eventFilter(QObject* obj, QEvent* event) +{ + if (event->type() == QEvent::MouseButtonRelease) { + auto const* const mouse_event = static_cast(event); + if (mouse_event->button() == Qt::MouseButton::MiddleButton) { + if (obj == m_tabs_container) { + auto const tab_index = m_tabs_container->tabBar()->tabAt(mouse_event->pos()); + close_tab(tab_index); + return true; + } + } + } + + return QMainWindow::eventFilter(obj, event); +} diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index 790421d868..5a5438dc94 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -54,6 +54,9 @@ public slots: void select_all(); void copy_selected_text(); +protected: + bool eventFilter(QObject* obj, QEvent* event); + private: void debug_request(DeprecatedString const& request, DeprecatedString const& argument = ""); -- cgit v1.2.3