UI/Qt: Detach dragged tabs dropped outside any tab bar to a new window

Previously, a tab would only detach into a new window when dropped
outside the source window entirely. Dropping a tab onto the content
area of any browser window would instead silently move it to the end of
that window's tab bar.

TabWidget now rejects tab drag events outside its tab bar row, and the
detach condition checks the tab bar row bounds rather than the full
window geometry. This means dropping a tab anywhere that is not a tab
bar row opens a new window at the cursor position.
This commit is contained in:
Tim Ledbetter 2026-05-26 01:12:55 +01:00 committed by Andreas Kling
parent 6a2c9dae06
commit ee3960e425
2 changed files with 13 additions and 2 deletions

View file

@ -452,8 +452,12 @@ void TabBar::start_tab_drag(int index)
if (action == Qt::MoveAction && s_pending_tab_drop_target) {
if (auto* target_window = qobject_cast<BrowserWindow*>(s_pending_tab_drop_target->window()))
source_window->move_tab_to_window(current_index, *target_window, s_pending_tab_drop_index);
} else if (action == Qt::IgnoreAction && !source_window->geometry().contains(QCursor::pos())) {
source_window->detach_tab_to_new_window(current_index, QCursor::pos());
} else if (action == Qt::IgnoreAction) {
auto tab_bar_row_global = QRect(
m_tab_widget->tab_bar_row()->mapToGlobal(QPoint(0, 0)),
m_tab_widget->tab_bar_row()->size());
if (!tab_bar_row_global.contains(QCursor::pos()) && m_tab_widget->count() > 1)
source_window->detach_tab_to_new_window(current_index, QCursor::pos());
}
}
}
@ -716,6 +720,12 @@ void TabWidget::accept_tab_drag(QDragMoveEvent* event)
return;
}
auto position_in_tab_bar_row = m_tab_bar_row->mapFrom(this, event->position().toPoint());
if (!m_tab_bar_row->rect().contains(position_in_tab_bar_row)) {
event->ignore();
return;
}
event->setDropAction(Qt::MoveAction);
event->accept();
}

View file

@ -85,6 +85,7 @@ public:
explicit TabWidget(QWidget* parent = nullptr);
TabBar* tab_bar() const { return m_tab_bar; }
QWidget* tab_bar_row() const { return m_tab_bar_row; }
void add_tab(Tab* widget, QString const& label);
void insert_tab(int index, Tab* widget, QString const& label);