~ubuntu-branches/ubuntu/lucid/kkbswitch/lucid

« back to all changes in this revision

Viewing changes to kkbswitch/singlewindowwatcher.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lior Kaplan
  • Date: 2005-09-07 02:01:14 UTC
  • Revision ID: james.westby@ubuntu.com-20050907020114-2wyo9eu21uihq86n
Tags: upstream-1.4.3
ImportĀ upstreamĀ versionĀ 1.4.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004 by Leonid Zeitlin                                  *
 
3
 *   lz@europe.com                                                         *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
#include "singlewindowwatcher.h"
 
21
#include "kbconfig.h"
 
22
 
 
23
#include <kwinmodule.h>
 
24
#include <kdebug.h>
 
25
 
 
26
SingleWindowWatcher::SingleWindowWatcher(KBConfig *kbconf, QObject *parent, const char *name)
 
27
 : WindowWatcher(kbconf, parent, name)
 
28
{
 
29
  reset();
 
30
}
 
31
 
 
32
SingleWindowWatcher::~SingleWindowWatcher()
 
33
{
 
34
}
 
35
 
 
36
void SingleWindowWatcher::windowRemoved(WId id)
 
37
{
 
38
  m_window_map.remove(id);
 
39
}
 
40
 
 
41
void SingleWindowWatcher::activeWindowChanged(WId id)
 
42
{
 
43
  if (id == 0) return; // no window is active
 
44
  m_active_window = m_window_map.find(id);
 
45
  if (m_active_window == m_window_map.end())
 
46
    addWindowToMap(id);
 
47
  emit windowChanged(m_active_window.data().groupno, m_active_window.data().next_groupno);
 
48
}
 
49
 
 
50
void SingleWindowWatcher::addWindowToMap(WId window_id)
 
51
{
 
52
  KBWinInfo wininfo = { m_kbconf->default_groupno(),
 
53
    m_kbconf->getNextGroup(m_kbconf->default_groupno()) };
 
54
 
 
55
  m_active_window = m_window_map.insert(window_id, wininfo);
 
56
}
 
57
 
 
58
void SingleWindowWatcher::changeGroup(int groupno, int next_groupno)
 
59
{
 
60
  if (m_active_window != m_window_map.end()) {
 
61
    m_active_window.data().groupno = groupno;
 
62
    m_active_window.data().next_groupno = next_groupno;
 
63
  }  
 
64
}
 
65
 
 
66
void SingleWindowWatcher::reset()
 
67
{
 
68
  m_window_map.clear();
 
69
  WId active_window = m_kwin_module->activeWindow();
 
70
  if (active_window)
 
71
    addWindowToMap(active_window);
 
72
  else m_active_window = m_window_map.end();
 
73
}