Skip to content

Commit

Permalink
Ladybird: Close tab clicking wheel of the mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
guerinoni authored and AtkinsSJ committed Feb 16, 2023
1 parent d5f7771 commit 1296aa1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Ladybird/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QGuiApplication>
#include <QInputDialog>
#include <QPlainTextEdit>
#include <QTabBar>

extern DeprecatedString s_serenity_resource_root;
extern Browser::Settings* s_settings;
Expand All @@ -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);
Expand Down Expand Up @@ -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<QMouseEvent*>(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);
}
3 changes: 3 additions & 0 deletions Ladybird/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "");

Expand Down

0 comments on commit 1296aa1

Please sign in to comment.