12#include "WindowBeingDragged_p.h"
13#include "kddockwidgets/KDDockWidgets.h"
14#include "DragController_p.h"
18#include "core/DockWidget_p.h"
19#include "kddockwidgets/core/TitleBar.h"
20#include "kddockwidgets/core/Stack.h"
21#include "kddockwidgets/core/Group.h"
22#include "kddockwidgets/core/Platform.h"
23#include "kddockwidgets/core/Layout.h"
24#include "kddockwidgets/core/FloatingWindow.h"
28#ifdef KDDW_FRONTEND_QT
44 if (
auto titleBar = draggable->asView()->asTitleBarController()) {
45 if (titleBar->isVisible())
48 auto fw = titleBar->window()->asFloatingWindowController();
52 if (fw->titleBar() == titleBar) {
56 if (KDDockWidgets::usesNativeTitleBar())
58 return fw->titleBar();
65WindowBeingDragged::WindowBeingDragged(
FloatingWindow *fw, Draggable *draggable)
66 : m_floatingWindow(fw)
68 , m_draggableView(m_draggable ? m_draggable->asView() : nullptr)
69 , m_guard(m_draggableView)
72 updateTransparency(
true);
75WindowBeingDragged::WindowBeingDragged(Draggable *draggable)
76 : m_draggable(draggable)
77 , m_draggableView(m_draggable->asView())
78 , m_guard(m_draggableView)
81 KDDW_ERROR(
"Wrong ctor called.");
87#ifdef DOCKS_DEVELOPER_MODE
91 : m_floatingWindow(fw)
92 , m_draggable(nullptr)
99WindowBeingDragged::~WindowBeingDragged()
102 updateTransparency(
false);
105void WindowBeingDragged::init()
107 assert(m_floatingWindow);
109 m_floatingWindow->view()->raise();
112void WindowBeingDragged::updateTransparency(
bool enable)
119 const bool transparencySupported = !std::isnan(opacity) && !
fuzzyCompare(1.0, opacity);
120 if (transparencySupported) {
123 if (
Config::self().transparencyOnlyOverDropIndicator()) {
131 m_floatingWindow->view()->setWindowOpacity(opacity);
135void WindowBeingDragged::grabMouse(
bool grab)
140 KDDW_DEBUG(
"WindowBeingDragged: fw={}, grab={}, draggableView={} ", (
void * )m_floatingWindow, grab, (
void * )m_draggableView);
143 DragController::instance()->grabMouseFor(m_draggableView);
145 DragController::instance()->releaseMouse(m_draggableView);
150 return m_floatingWindow ? m_floatingWindow->affinities() :
Vector<QString>();
153Size WindowBeingDragged::size()
const
155 if (m_floatingWindow)
156 return m_floatingWindow->size();
161Size WindowBeingDragged::minSize()
const
163 if (m_floatingWindow)
164 return m_floatingWindow->layout()->layoutMinimumSize();
169Size WindowBeingDragged::maxSize()
const
171 if (m_floatingWindow)
172 return m_floatingWindow->layout()->layoutMaximumSizeHint();
177bool WindowBeingDragged::contains(
Layout *layout)
const
182 if (m_floatingWindow)
183 return m_floatingWindow->layout() == layout;
185 if (
auto fw = m_draggableView->rootView()->asFloatingWindowController()) {
188 return fw->layout() == layout && fw->hasSingleGroup();
196 if (m_floatingWindow)
197 return m_floatingWindow->dockWidgets();
202Draggable *WindowBeingDragged::draggable()
const
207Pixmap WindowBeingDragged::pixmap()
const
214 return m_floatingWindow;
217Core::View *WindowBeingDragged::floatingWindowView()
const
219 if (m_floatingWindow)
220 return m_floatingWindow->view();
225WindowBeingDraggedWayland::WindowBeingDraggedWayland(Draggable *draggable)
226 : WindowBeingDragged(draggable)
230 KDDW_ERROR(
"This CTOR is only called on Wayland");
235 if (
auto tb = draggable->asView()->asTitleBarController()) {
236 if (
auto fw = tb->floatingWindow()) {
238 m_floatingWindow = fw;
239 }
else if (
Group *group = tb->group()) {
242 KDDW_ERROR(
"Shouldn't happen. TitleBar of what ?");
244 }
else if (
auto fw = draggable->asView()->asFloatingWindowController()) {
247 m_floatingWindow = fw;
248 }
else if (
auto tabBar = draggable->asView()->asTabBarController()) {
250 m_dockWidget = tabBar->currentDockWidget();
251 }
else if (
auto stack = draggable->asView()->asStackController()) {
253 m_group = stack->group();
255 KDDW_ERROR(
"Unknown draggable {} please fix)", (
void * )draggable);
259WindowBeingDraggedWayland::~WindowBeingDraggedWayland()
263Pixmap WindowBeingDraggedWayland::pixmap()
const
265#ifdef KDDW_FRONTEND_QT
271 if (m_floatingWindow) {
272 m_floatingWindow->view()->render(&p);
273 }
else if (m_group) {
274 m_group->view()->render(&p);
275 }
else if (m_dockWidget) {
276 m_dockWidget->view()->render(&p);
288 if (m_floatingWindow)
289 return WindowBeingDragged::affinities();
291 return m_group->affinities();
292 else if (m_dockWidget)
293 return { m_dockWidget->affinities() };
300 if (m_floatingWindow)
301 return WindowBeingDragged::dockWidgets();
303 return m_group->dockWidgets();
304 else if (m_dockWidget)
305 return { m_dockWidget };
310bool WindowBeingDraggedWayland::isInWaylandDrag(
Group *group)
const
315 return (group && m_group == group) || (m_dockWidget && m_dockWidget->dptr()->group() == group);
318Size WindowBeingDraggedWayland::size()
const
320 if (m_floatingWindow)
321 return WindowBeingDragged::size();
323 return m_group->geometry().size();
324 else if (m_dockWidget)
325 return m_dockWidget->size();
327 KDDW_ERROR(
"Unknown size, shouldn't happen");
331Size WindowBeingDraggedWayland::minSize()
const
333 if (m_floatingWindow) {
334 return WindowBeingDragged::minSize();
335 }
else if (m_group) {
336 return m_group->view()->minSize();
337 }
else if (m_dockWidget) {
338 return m_dockWidget->view()->minSize();
341 KDDW_ERROR(
"Unknown minSize, shouldn't happen");
345Size WindowBeingDraggedWayland::maxSize()
const
347 if (m_floatingWindow) {
348 return WindowBeingDragged::maxSize();
349 }
else if (m_group) {
350 return m_group->view()->maxSizeHint();
351 }
else if (m_dockWidget) {
352 return m_dockWidget->view()->maxSizeHint();
355 KDDW_ERROR(
"Unknown maxSize, shouldn't happen");
static Draggable * bestDraggable(Draggable *draggable)