summaryrefslogtreecommitdiffstats
path: root/kxkb/layoutmap.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kxkb/layoutmap.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kxkb/layoutmap.cpp')
-rw-r--r--kxkb/layoutmap.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/kxkb/layoutmap.cpp b/kxkb/layoutmap.cpp
new file mode 100644
index 000000000..f6273c967
--- /dev/null
+++ b/kxkb/layoutmap.cpp
@@ -0,0 +1,132 @@
+//
+// C++ Implementation: layoutmap
+//
+// Description:
+//
+//
+// Author: Andriy Rysin <rysin@kde.org>, (C) 2006
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "layoutmap.h"
+
+#include "x11helper.h"
+
+
+LayoutMap::LayoutMap(const KxkbConfig& kxkbConfig_):
+ m_kxkbConfig(kxkbConfig_),
+ m_currentWinId( X11Helper::UNKNOWN_WINDOW_ID )
+{
+}
+
+// private
+void LayoutMap::clearMaps()
+{
+ m_appLayouts.clear();
+ m_winLayouts.clear();
+ m_globalLayouts.clear();
+ //setCurrentWindow( -1 );
+}
+
+void LayoutMap::reset()
+{
+ clearMaps();
+ setCurrentWindow( X11Helper::UNKNOWN_WINDOW_ID );
+}
+
+
+
+void LayoutMap::setCurrentWindow(WId winId)
+{
+ m_currentWinId = winId;
+ if( m_kxkbConfig.m_switchingPolicy == SWITCH_POLICY_WIN_CLASS )
+ m_currentWinClass = X11Helper::getWindowClass(winId, qt_xdisplay());
+}
+
+// private
+//LayoutQueue&
+QPtrQueue<LayoutState>& LayoutMap::getCurrentLayoutQueueInternal(WId winId)
+{
+ if( winId == X11Helper::UNKNOWN_WINDOW_ID )
+ return m_globalLayouts;
+
+ switch( m_kxkbConfig.m_switchingPolicy ) {
+ case SWITCH_POLICY_WIN_CLASS: {
+// QString winClass = X11Helper::getWindowClass(winId, qt_xdisplay());
+ return m_appLayouts[ m_currentWinClass ];
+ }
+ case SWITCH_POLICY_WINDOW:
+ return m_winLayouts[ winId ];
+
+ default:
+ return m_globalLayouts;
+ }
+}
+
+// private
+//LayoutQueue&
+QPtrQueue<LayoutState>& LayoutMap::getCurrentLayoutQueue(WId winId)
+{
+ QPtrQueue<LayoutState>& layoutQueue = getCurrentLayoutQueueInternal(winId);
+ if( layoutQueue.count() == 0 ) {
+ initLayoutQueue(layoutQueue);
+ kdDebug() << "map: Created queue for " << winId << " size: " << layoutQueue.count() << endl;
+ }
+
+ return layoutQueue;
+}
+
+LayoutState& LayoutMap::getCurrentLayout() {
+ return *getCurrentLayoutQueue(m_currentWinId).head();
+}
+
+LayoutState& LayoutMap::getNextLayout() {
+ LayoutQueue& layoutQueue = getCurrentLayoutQueue(m_currentWinId);
+ LayoutState* layoutState = layoutQueue.dequeue();
+ layoutQueue.enqueue(layoutState);
+
+ kdDebug() << "map: Next layout: " << layoutQueue.head()->layoutUnit.toPair()
+ << " group: " << layoutQueue.head()->layoutUnit.defaultGroup << " for " << m_currentWinId << endl;
+
+ return *layoutQueue.head();
+}
+
+void LayoutMap::setCurrentGroup(int group) {
+ getCurrentLayout().group = group;
+}
+
+void LayoutMap::setCurrentLayout(const LayoutUnit& layoutUnit) {
+ LayoutQueue& layoutQueue = getCurrentLayoutQueue(m_currentWinId);
+ kdDebug() << "map: Storing layout: " << layoutUnit.toPair()
+ << " group: " << layoutUnit.defaultGroup << " for " << m_currentWinId << endl;
+
+ int queueSize = (int)layoutQueue.count();
+ for(int ii=0; ii<queueSize; ii++) {
+ if( layoutQueue.head()->layoutUnit == layoutUnit )
+ return; // if present return when it's in head
+
+ LayoutState* layoutState = layoutQueue.dequeue();
+ if( ii < queueSize - 1 ) {
+ layoutQueue.enqueue(layoutState);
+ }
+ else {
+ delete layoutState;
+ layoutQueue.enqueue(new LayoutState(layoutUnit));
+ }
+ }
+ for(int ii=0; ii<queueSize - 1; ii++) {
+ LayoutState* layoutState = layoutQueue.dequeue();
+ layoutQueue.enqueue(layoutState);
+ }
+}
+
+// private
+void LayoutMap::initLayoutQueue(LayoutQueue& layoutQueue) {
+ int queueSize = ( m_kxkbConfig.m_stickySwitching )
+ ? m_kxkbConfig.m_stickySwitchingDepth : m_kxkbConfig.m_layouts.count();
+ for(int ii=0; ii<queueSize; ii++) {
+ layoutQueue.enqueue( new LayoutState(m_kxkbConfig.m_layouts[ii]) );
+ }
+}