2
// C++ Implementation: layoutmap
7
// Author: Andriy Rysin <rysin@kde.org>, (C) 2006
9
// Copyright: See COPYING file that comes with this distribution
2
* Copyright (C) 2006 Andriy Rysin (rysin@kde.org)
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
13
20
#include <QX11Info>
21
#include <kwindowsystem.h>
15
23
#include "layoutmap.h"
45
53
m_currentWinId = winId;
46
54
if( m_kxkbConfig.m_switchingPolicy == SWITCH_POLICY_WIN_CLASS )
47
55
m_currentWinClass = X11Helper::getWindowClass(winId, QX11Info::display());
57
if( m_kxkbConfig.m_switchingPolicy == SWITCH_POLICY_DESKTOP )
58
m_currentDesktop = KWindowSystem::currentDesktop();
52
QQueue<int>& LayoutMap::getCurrentLayoutQueueInternal(WId winId)
63
QQueue<int>& LayoutMap::getCurrentLayoutQueueInternal()
54
if( winId == X11Helper::UNKNOWN_WINDOW_ID )
65
if( m_currentWinId == X11Helper::UNKNOWN_WINDOW_ID )
55
66
return m_globalLayouts;
57
68
switch( m_kxkbConfig.m_switchingPolicy ) {
60
71
return m_appLayouts[ m_currentWinClass ];
62
73
case SWITCH_POLICY_WINDOW:
63
return m_winLayouts[ winId ];
74
return m_winLayouts[ m_currentWinId ];
75
case SWITCH_POLICY_DESKTOP:
76
return m_winLayouts[ m_currentDesktop ];
66
78
return m_globalLayouts;
83
QString LayoutMap::getOwner()
85
switch( m_kxkbConfig.m_switchingPolicy ) {
86
case SWITCH_POLICY_WIN_CLASS:
87
return QString("winclass: %1").arg(m_currentWinClass);
88
case SWITCH_POLICY_WINDOW:
89
return QString("window: %1").arg(m_currentWinId);
90
case SWITCH_POLICY_DESKTOP:
91
return QString("desktop: %1").arg(m_currentDesktop);
72
QQueue<int>& LayoutMap::getCurrentLayoutQueue(WId winId)
99
QQueue<int>& LayoutMap::getCurrentLayoutQueue()
74
QQueue<int>& layoutQueue = getCurrentLayoutQueueInternal(winId);
101
QQueue<int>& layoutQueue = getCurrentLayoutQueueInternal();
75
102
if( layoutQueue.count() == 0 ) {
76
103
initLayoutQueue(layoutQueue);
77
kDebug() << "map: Created queue for " << winId << " size: " << layoutQueue.count();
104
kDebug() << "Created queue for " << getOwner() << " size: " << layoutQueue.count();
80
107
return layoutQueue;
83
110
int LayoutMap::getCurrentLayout() {
84
return getCurrentLayoutQueue(m_currentWinId).head();
111
return getCurrentLayoutQueue().head();
87
114
int LayoutMap::getNextLayout() {
88
LayoutQueue& layoutQueue = getCurrentLayoutQueue(m_currentWinId);
115
LayoutQueue& layoutQueue = getCurrentLayoutQueue(/*m_currentWinId*/);
89
116
int layoutState = layoutQueue.dequeue();
90
117
layoutQueue.enqueue(layoutState);
92
119
kDebug() << "map: Next layout: " << layoutQueue.head()
93
120
// << " group: " << layoutQueue.head()->layoutUnit.defaultGroup
94
<< " for " << m_currentWinId << endl;
121
<< " for " << getOwner();
96
123
return layoutQueue.head();
99
126
void LayoutMap::setCurrentLayout(int layoutUnit) {
100
LayoutQueue& layoutQueue = getCurrentLayoutQueue(m_currentWinId);
127
LayoutQueue& layoutQueue = getCurrentLayoutQueue(/*m_currentWinId*/);
101
128
kDebug() << "map: Storing layout: " << layoutUnit
102
129
// << " group: " << layoutUnit.defaultGroup
103
<< " for " << m_currentWinId << endl;
130
<< " for " << getOwner();
105
132
int queueSize = (int)layoutQueue.count();
106
133
for(int ii=0; ii<queueSize; ii++) {