File indexing completed on 2025-04-20 08:02:36
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include "drag.h" 0012 0013 #include "wayland/datadevicemanager.h" 0014 0015 #include <QList> 0016 #include <QPoint> 0017 #include <QPointer> 0018 0019 namespace KWin 0020 { 0021 class DataDeviceInterface; 0022 class DataSourceInterface; 0023 class SurfaceInterface; 0024 class Window; 0025 class X11Window; 0026 0027 namespace Xwl 0028 { 0029 class X11Source; 0030 enum class DragEventReply; 0031 class Xvisit; 0032 class Dnd; 0033 0034 class WlToXDrag : public Drag 0035 { 0036 Q_OBJECT 0037 using Drag::Drag; 0038 0039 public: 0040 explicit WlToXDrag(Dnd *dnd); 0041 DragEventReply moveFilter(Window *target) override; 0042 bool handleClientMessage(xcb_client_message_event_t *event) override; 0043 0044 private: 0045 Dnd *const m_dnd; 0046 Q_DISABLE_COPY(WlToXDrag) 0047 }; 0048 0049 // visit to an X window 0050 class Xvisit : public QObject 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 // TODO: handle ask action 0056 0057 Xvisit(X11Window *target, AbstractDataSource *dataSource, Dnd *dnd, QObject *parent); 0058 0059 bool handleClientMessage(xcb_client_message_event_t *event); 0060 bool handleStatus(xcb_client_message_event_t *event); 0061 bool handleFinished(xcb_client_message_event_t *event); 0062 0063 void sendPosition(const QPointF &globalPos); 0064 void leave(); 0065 0066 bool finished() const 0067 { 0068 return m_state.finished; 0069 } 0070 X11Window *target() const 0071 { 0072 return m_target; 0073 } 0074 void drop(); 0075 Q_SIGNALS: 0076 void finish(Xvisit *self); 0077 0078 private: 0079 void sendEnter(); 0080 void sendDrop(uint32_t time); 0081 void sendLeave(); 0082 0083 void receiveOffer(); 0084 void enter(); 0085 0086 void retrieveSupportedActions(); 0087 void determineProposedAction(); 0088 void requestDragAndDropAction(); 0089 void setProposedAction(); 0090 0091 void doFinish(); 0092 void stopConnections(); 0093 0094 Dnd *const m_dnd; 0095 X11Window *m_target; 0096 QPointer<AbstractDataSource> m_dataSource; 0097 uint32_t m_version = 0; 0098 0099 QMetaObject::Connection m_motionConnection; 0100 0101 struct 0102 { 0103 bool pending = false; 0104 bool cached = false; 0105 QPoint cache; 0106 } m_pos; 0107 0108 // supported by the Wl source 0109 DataDeviceManagerInterface::DnDActions m_supportedActions = DataDeviceManagerInterface::DnDAction::None; 0110 // preferred by the X client 0111 DataDeviceManagerInterface::DnDAction m_preferredAction = DataDeviceManagerInterface::DnDAction::None; 0112 // decided upon by the compositor 0113 DataDeviceManagerInterface::DnDAction m_proposedAction = DataDeviceManagerInterface::DnDAction::None; 0114 0115 struct 0116 { 0117 bool entered = false; 0118 bool dropped = false; 0119 bool finished = false; 0120 } m_state; 0121 0122 bool m_accepts = false; 0123 0124 Q_DISABLE_COPY(Xvisit) 0125 }; 0126 0127 } // namespace Xwl 0128 } // namespace KWin