@@ -10,6 +10,7 @@ CwlGestureManager::CwlGestureManager(CwlCompositor *compositor, QObject *parent)
1010 , m_compositor(compositor)
1111{
1212 initializeActions ();
13+ initializeGestureMapping ();
1314}
1415
1516CwlGestureManager::~CwlGestureManager ()
@@ -19,6 +20,12 @@ CwlGestureManager::~CwlGestureManager()
1920 ++it) {
2021 delete it.value ();
2122 }
23+
24+ // Clean up gesture registry actions
25+ for (auto it = m_gestureRegistry.begin (); it != m_gestureRegistry.end ();
26+ ++it) {
27+ delete it.value ();
28+ }
2229}
2330
2431void CwlGestureManager::initializeActions ()
@@ -38,6 +45,13 @@ void CwlGestureManager::initializeActions()
3845
3946bool CwlGestureManager::handleGesture (QPointerEvent *ev, int edge, int corner)
4047{
48+ // Use the new registry-based approach
49+ IGestureAction *action = findActionForGesture (ev, edge, corner);
50+ if (action && action->canExecute (m_compositor)) {
51+ return action->execute (ev, m_compositor);
52+ }
53+
54+ // Fallback to legacy approach for backward compatibility
4155 switch (edge) {
4256 case EDGE_LEFT :
4357 return handleLeftEdgeGesture (ev);
@@ -61,6 +75,16 @@ bool CwlGestureManager::handleGesture(QPointerEvent *ev, int edge, int corner)
6175
6276bool CwlGestureManager::handleLeftEdgeGesture (QPointerEvent *ev)
6377{
78+ // Try registry first, fallback to legacy
79+ IGestureAction *action = getGestureAction (GestureType::LEFT_EDGE );
80+ if (action) {
81+ if (action->canExecute (m_compositor)) {
82+ return action->execute (ev, m_compositor);
83+ }
84+ return false ;
85+ }
86+
87+ // Legacy fallback
6488 if (!m_leftEdgeAction->canExecute (m_compositor)) {
6589 return false ;
6690 }
@@ -69,6 +93,16 @@ bool CwlGestureManager::handleLeftEdgeGesture(QPointerEvent *ev)
6993
7094bool CwlGestureManager::handleRightEdgeGesture (QPointerEvent *ev)
7195{
96+ // Try registry first, fallback to legacy
97+ IGestureAction *action = getGestureAction (GestureType::RIGHT_EDGE );
98+ if (action) {
99+ if (action->canExecute (m_compositor)) {
100+ return action->execute (ev, m_compositor);
101+ }
102+ return false ;
103+ }
104+
105+ // Legacy fallback
72106 if (!m_rightEdgeAction->canExecute (m_compositor)) {
73107 return false ;
74108 }
@@ -77,6 +111,16 @@ bool CwlGestureManager::handleRightEdgeGesture(QPointerEvent *ev)
77111
78112bool CwlGestureManager::handleTopEdgeGesture (QPointerEvent *ev)
79113{
114+ // Try registry first, fallback to legacy
115+ IGestureAction *action = getGestureAction (GestureType::TOP_EDGE );
116+ if (action) {
117+ if (action->canExecute (m_compositor)) {
118+ return action->execute (ev, m_compositor);
119+ }
120+ return false ;
121+ }
122+
123+ // Legacy fallback
80124 if (!m_topEdgeAction->canExecute (m_compositor)) {
81125 return false ;
82126 }
@@ -85,6 +129,16 @@ bool CwlGestureManager::handleTopEdgeGesture(QPointerEvent *ev)
85129
86130bool CwlGestureManager::handleBottomEdgeGesture (QPointerEvent *ev)
87131{
132+ // Try registry first, fallback to legacy
133+ IGestureAction *action = getGestureAction (GestureType::BOTTOM_EDGE );
134+ if (action) {
135+ if (action->canExecute (m_compositor)) {
136+ return action->execute (ev, m_compositor);
137+ }
138+ return false ;
139+ }
140+
141+ // Legacy fallback
88142 if (!m_bottomEdgeAction->canExecute (m_compositor)) {
89143 return false ;
90144 }
@@ -93,15 +147,247 @@ bool CwlGestureManager::handleBottomEdgeGesture(QPointerEvent *ev)
93147
94148bool CwlGestureManager::handleCornerGesture (QPointerEvent *ev, int corner)
95149{
150+ // Try registry first, fallback to legacy
151+ IGestureAction *action = getCornerGestureAction (corner);
152+ if (action) {
153+ if (action->canExecute (m_compositor)) {
154+ return action->execute (ev, m_compositor);
155+ }
156+ return false ;
157+ }
158+
159+ // Legacy fallback
96160 auto it = m_cornerActions.find (corner);
97161 if (it == m_cornerActions.end ()) {
98162 return false ;
99163 }
100164
101- IGestureAction *action = it.value ();
102- if (!action ->canExecute (m_compositor)) {
165+ IGestureAction *legacyAction = it.value ();
166+ if (!legacyAction ->canExecute (m_compositor)) {
103167 return false ;
104168 }
105169
106- return action->execute (ev, m_compositor);
170+ return legacyAction->execute (ev, m_compositor);
171+ }
172+
173+ void CwlGestureManager::initializeGestureMapping ()
174+ {
175+ // Initialize the gesture registry with default mappings
176+ // Edge gesture mappings
177+ m_gestureRegistry[createGestureKey (GestureType::LEFT_EDGE )] =
178+ new LeftEdgeGestureAction (this );
179+ m_gestureRegistry[createGestureKey (GestureType::RIGHT_EDGE )] =
180+ new RightEdgeGestureAction (this );
181+ m_gestureRegistry[createGestureKey (GestureType::TOP_EDGE )] =
182+ new TopEdgeGestureAction (this );
183+ m_gestureRegistry[createGestureKey (GestureType::BOTTOM_EDGE )] =
184+ new BottomEdgeGestureAction (this );
185+
186+ // Corner gesture mappings
187+ m_gestureRegistry[createGestureKey (GestureType::CORNER_BR , CORNER_BR )] =
188+ new BottomCornerGestureAction (CORNER_BR , this );
189+ m_gestureRegistry[createGestureKey (GestureType::CORNER_BL , CORNER_BL )] =
190+ new BottomCornerGestureAction (CORNER_BL , this );
191+ }
192+
193+ GestureType CwlGestureManager::convertEdgeToGestureType (int edge) const
194+ {
195+ switch (edge) {
196+ case EDGE_LEFT :
197+ return GestureType::LEFT_EDGE ;
198+ case EDGE_RIGHT :
199+ return GestureType::RIGHT_EDGE ;
200+ case EDGE_TOP :
201+ return GestureType::TOP_EDGE ;
202+ case EDGE_BOTTOM :
203+ return GestureType::BOTTOM_EDGE ;
204+ default :
205+ return GestureType::UNDEFINED ;
206+ }
207+ }
208+
209+ GestureKey CwlGestureManager::createGestureKey (GestureType type,
210+ int cornerPosition) const
211+ {
212+ GestureKey key;
213+ key.type = type;
214+ key.cornerPosition = cornerPosition;
215+ return key;
216+ }
217+
218+ IGestureAction *CwlGestureManager::findActionForGesture (QPointerEvent *ev,
219+ int edge,
220+ int corner) const
221+ {
222+ // First try to find edge gesture action
223+ if (edge != EDGE_UNDEFINED ) {
224+ GestureType gestureType = convertEdgeToGestureType (edge);
225+ if (gestureType != GestureType::UNDEFINED ) {
226+ GestureKey key = createGestureKey (gestureType);
227+ auto it = m_gestureRegistry.find (key);
228+ if (it != m_gestureRegistry.end ()) {
229+ return it.value ();
230+ }
231+ }
232+ }
233+
234+ // Then try corner gesture action
235+ if (corner == CORNER_BR || corner == CORNER_BL ) {
236+ GestureType cornerType = (corner == CORNER_BR ) ?
237+ GestureType::CORNER_BR :
238+ GestureType::CORNER_BL ;
239+ GestureKey key = createGestureKey (cornerType, corner);
240+ auto it = m_gestureRegistry.find (key);
241+ if (it != m_gestureRegistry.end ()) {
242+ return it.value ();
243+ }
244+ }
245+
246+ return nullptr ;
247+ }
248+
249+ void CwlGestureManager::setGestureAction (GestureType type,
250+ IGestureAction *action)
251+ {
252+ GestureKey key = createGestureKey (type);
253+ // Delete existing action if present
254+ auto it = m_gestureRegistry.find (key);
255+ if (it != m_gestureRegistry.end ()) {
256+ delete it.value ();
257+ }
258+ m_gestureRegistry[key] = action;
259+ }
260+
261+ void CwlGestureManager::setCornerGestureAction (int cornerPosition,
262+ IGestureAction *action)
263+ {
264+ GestureType cornerType;
265+ switch (cornerPosition) {
266+ case CORNER_TL :
267+ cornerType = GestureType::CORNER_TL ;
268+ break ;
269+ case CORNER_TR :
270+ cornerType = GestureType::CORNER_TR ;
271+ break ;
272+ case CORNER_BL :
273+ cornerType = GestureType::CORNER_BL ;
274+ break ;
275+ case CORNER_BR :
276+ cornerType = GestureType::CORNER_BR ;
277+ break ;
278+ default :
279+ return ; // Invalid corner position
280+ }
281+
282+ GestureKey key = createGestureKey (cornerType, cornerPosition);
283+ // Delete existing action if present
284+ auto it = m_gestureRegistry.find (key);
285+ if (it != m_gestureRegistry.end ()) {
286+ delete it.value ();
287+ }
288+ m_gestureRegistry[key] = action;
289+ }
290+
291+ IGestureAction *CwlGestureManager::getGestureAction (GestureType type) const
292+ {
293+ GestureKey key = createGestureKey (type);
294+ auto it = m_gestureRegistry.find (key);
295+ return (it != m_gestureRegistry.end ()) ? it.value () : nullptr ;
296+ }
297+
298+ IGestureAction *
299+ CwlGestureManager::getCornerGestureAction (int cornerPosition) const
300+ {
301+ GestureType cornerType;
302+ switch (cornerPosition) {
303+ case CORNER_TL :
304+ cornerType = GestureType::CORNER_TL ;
305+ break ;
306+ case CORNER_TR :
307+ cornerType = GestureType::CORNER_TR ;
308+ break ;
309+ case CORNER_BL :
310+ cornerType = GestureType::CORNER_BL ;
311+ break ;
312+ case CORNER_BR :
313+ cornerType = GestureType::CORNER_BR ;
314+ break ;
315+ default :
316+ return nullptr ; // Invalid corner position
317+ }
318+
319+ GestureKey key = createGestureKey (cornerType, cornerPosition);
320+ auto it = m_gestureRegistry.find (key);
321+ return (it != m_gestureRegistry.end ()) ? it.value () : nullptr ;
322+ }
323+
324+ void CwlGestureManager::remapGesture (GestureType fromType, GestureType toType)
325+ {
326+ GestureKey fromKey = createGestureKey (fromType);
327+ GestureKey toKey = createGestureKey (toType);
328+
329+ auto fromIt = m_gestureRegistry.find (fromKey);
330+ if (fromIt != m_gestureRegistry.end ()) {
331+ // Move the action from fromType to toType
332+ IGestureAction *action = fromIt.value ();
333+ m_gestureRegistry.remove (fromKey);
334+
335+ // Delete existing action at target if present
336+ auto toIt = m_gestureRegistry.find (toKey);
337+ if (toIt != m_gestureRegistry.end ()) {
338+ delete toIt.value ();
339+ }
340+
341+ m_gestureRegistry[toKey] = action;
342+ }
343+ }
344+
345+ void CwlGestureManager::remapCornerGesture (int fromCorner, int toCorner)
346+ {
347+ IGestureAction *action = getCornerGestureAction (fromCorner);
348+ if (action) {
349+ // Create a new action for the target corner
350+ // Note: This is a simplified approach; in a real implementation,
351+ // you might want to clone the action or implement action copying
352+ clearCornerGestureMapping (fromCorner);
353+ // The actual remapping would need action cloning capability
354+ }
355+ }
356+
357+ void CwlGestureManager::clearGestureMapping (GestureType type)
358+ {
359+ GestureKey key = createGestureKey (type);
360+ auto it = m_gestureRegistry.find (key);
361+ if (it != m_gestureRegistry.end ()) {
362+ delete it.value ();
363+ m_gestureRegistry.remove (key);
364+ }
365+ }
366+
367+ void CwlGestureManager::clearCornerGestureMapping (int cornerPosition)
368+ {
369+ GestureType cornerType;
370+ switch (cornerPosition) {
371+ case CORNER_TL :
372+ cornerType = GestureType::CORNER_TL ;
373+ break ;
374+ case CORNER_TR :
375+ cornerType = GestureType::CORNER_TR ;
376+ break ;
377+ case CORNER_BL :
378+ cornerType = GestureType::CORNER_BL ;
379+ break ;
380+ case CORNER_BR :
381+ cornerType = GestureType::CORNER_BR ;
382+ break ;
383+ default :
384+ return ; // Invalid corner position
385+ }
386+
387+ GestureKey key = createGestureKey (cornerType, cornerPosition);
388+ auto it = m_gestureRegistry.find (key);
389+ if (it != m_gestureRegistry.end ()) {
390+ delete it.value ();
391+ m_gestureRegistry.remove (key);
392+ }
107393}
0 commit comments