2
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
3
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
9
This library 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 GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "triggers/triggers.h"
21
#include "action_data/action_data.h"
22
#include "windows_handler.h"
23
#include "windows_helper/window_selection_list.h"
25
#include <KDE/KConfigGroup>
33
WindowTriggerVisitor::~WindowTriggerVisitor()
37
WindowTrigger::WindowTrigger(
39
Windowdef_list* windows_P,
40
WindowEvents window_actions_P)
42
_windows( windows_P ),
43
window_actions( window_actions_P ),
45
last_active_window( None ),
50
_windows = new Windowdef_list( "Windowdef_list comment");
53
Q_ASSERT(_windows->isEmpty());
58
WindowTrigger::~WindowTrigger()
60
// kDebug() << "~WindowTrigger :" << this;
61
disconnect( windows_handler, NULL, this, NULL );
66
void WindowTrigger::accept(TriggerVisitor& visitor)
68
if (WindowTriggerVisitor *v = dynamic_cast<WindowTriggerVisitor*>(&visitor))
74
kDebug() << "Visitor error";
79
void WindowTrigger::init()
81
kDebug() << "WindowTrigger::init()";
82
connect( windows_handler, SIGNAL( window_added( WId )), this, SLOT( window_added( WId )));
83
connect( windows_handler, SIGNAL( window_removed( WId )), this, SLOT( window_removed( WId )));
84
if( window_actions & ( WINDOW_ACTIVATES | WINDOW_DEACTIVATES /*| WINDOW_DISAPPEARS*/ ))
85
connect( windows_handler, SIGNAL( active_window_changed( WId )),
86
this, SLOT( active_window_changed( WId )));
87
connect( windows_handler, SIGNAL( window_changed( WId, unsigned int )),
88
this, SLOT( window_changed( WId, unsigned int )));
92
void WindowTrigger::activate( bool activate_P )
98
void WindowTrigger::active_window_changed( WId window_P )
100
if (!existing_windows.contains(window_P))
102
existing_windows[window_P] = windows()->match( Window_data( window_P ));
105
if (!active || !khotkeys_active())
107
// We still keep track of the last active window so we have valid data
108
// if khotkeys is switched on again.
109
last_active_window = window_P;
113
// Check if the last active window was a match for us
114
bool was_match = existing_windows.contains(last_active_window)
115
? existing_windows[last_active_window]
118
if (was_match && (window_actions & WINDOW_DEACTIVATES))
120
windows_handler->set_action_window( window_P );
124
if (existing_windows[window_P] && ( window_actions & WINDOW_ACTIVATES))
126
kDebug() << "Executing data";
127
windows_handler->set_action_window( window_P );
131
last_active_window = window_P;
135
void WindowTrigger::cfg_write( KConfigGroup& cfg_P ) const
137
base::cfg_write( cfg_P );
138
KConfigGroup windowsConfig( cfg_P.config(), cfg_P.name() + "Windows" );
141
windows()->cfg_write( windowsConfig );
143
cfg_P.writeEntry( "WindowActions", static_cast<int>(window_actions));
144
cfg_P.writeEntry( "Type", "WINDOW" ); // overwrites value set in base::cfg_write()
148
const QString WindowTrigger::description() const
150
return i18n( "Window trigger: " ) + windows()->comment();
154
void WindowTrigger::setOnWindowEvents(WindowEvents events)
156
window_actions = events;
160
void WindowTrigger::set_window_rules(Windowdef_list *list)
167
bool WindowTrigger::triggers_on( window_action_t w_action_P ) const
169
return window_actions & w_action_P;
173
void WindowTrigger::window_added( WId window_P )
175
// Always keep track of windows,
176
existing_windows[window_P] = windows()->match( Window_data( window_P ));
178
if (!active || !khotkeys_active())
183
if (existing_windows[window_P] && (window_actions & WINDOW_APPEARS))
185
windows_handler->set_action_window(window_P);
191
void WindowTrigger::window_removed( WId window_P )
193
// Always keep track of windows,
194
bool matches = false;
195
if (existing_windows.contains(window_P))
197
matches = existing_windows[window_P];
198
existing_windows.remove( window_P );
201
if (!active || !khotkeys_active())
206
if (matches && (window_actions & WINDOW_DISAPPEARS))
208
windows_handler->set_action_window( window_P );
214
void WindowTrigger::window_changed( WId window_P, unsigned int dirty_P )
216
if (! (dirty_P & (NET::WMName | NET::WMWindowType)))
219
// Check if the old state was a match
220
bool was_match = false;
221
if (existing_windows.contains(window_P))
222
was_match = existing_windows[window_P];
224
// Check if the new state is a match
225
bool matches = windows()->match( Window_data( window_P ));
226
existing_windows[window_P] = matches;
228
if (!active || !khotkeys_active())
233
if (matches && !was_match)
235
if (window_actions & WINDOW_APPEARS)
237
windows_handler->set_action_window( window_P );
240
else if (window_actions & WINDOW_ACTIVATES && window_P == windows_handler->active_window())
242
windows_handler->set_action_window( window_P );
249
const Windowdef_list* WindowTrigger::windows() const
255
Windowdef_list* WindowTrigger::windows()
261
WindowTrigger* WindowTrigger::copy( ActionData* data_P ) const
263
WindowTrigger* ret = new WindowTrigger( data_P ? data_P : data, windows()->copy(),
265
ret->existing_windows = existing_windows; // CHECKME je tohle vazne treba ?
269
} // namespace KHotKeys