1
/****************************************************************************
5
Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
7
Distributed under the terms of the GNU General Public License version 2.
9
****************************************************************************/
13
#include "windows_handler.h"
15
#include "windows_helper/window_selection_rules.h"
16
#include "windows_helper/window_selection_list.h"
21
#include <kconfiggroup.h>
23
#include <kwindowsystem.h>
26
#include "khotkeysglobal.h"
29
#include <X11/Xutil.h>
37
WindowsHandler::WindowsHandler( bool enable_signal_P, QObject* parent_P )
38
: QObject( parent_P ), signals_enabled( enable_signal_P ),
43
connect( KWindowSystem::self(), SIGNAL( windowAdded( WId )), SLOT( window_added_slot( WId )));
44
connect( KWindowSystem::self(), SIGNAL( windowRemoved( WId )), SLOT( window_removed_slot( WId )));
45
connect( KWindowSystem::self(), SIGNAL( activeWindowChanged( WId )),
46
SLOT( active_window_changed_slot( WId )));
50
WindowsHandler::~WindowsHandler()
54
void WindowsHandler::window_added_slot( WId window_P )
57
emit window_added( window_P );
58
// CHECKME tyhle i dalsi by asi mely jit nastavit, jestli aktivuji vsechny, nebo jen jeden
59
// pripojeny slot ( stejne jako u Kdb, kde by to take melo jit nastavit )
62
void WindowsHandler::window_removed_slot( WId window_P )
65
emit window_removed( window_P );
66
if( window_P == _action_window )
70
void WindowsHandler::active_window_changed_slot( WId window_P )
73
emit active_window_changed( window_P );
76
void WindowsHandler::window_changed_slot( WId window_P )
79
emit window_changed( window_P );
82
void WindowsHandler::window_changed_slot( WId window_P, unsigned int flags_P )
85
emit window_changed( window_P, flags_P );
88
QString WindowsHandler::get_window_role( WId id_P )
90
// TODO this is probably just a hack
91
return KWindowSystem::windowInfo( id_P, 0, NET::WM2WindowRole ).windowRole();
94
QString WindowsHandler::get_window_class( WId id_P )
97
if( XGetClassHint( QX11Info::display(), id_P, &hints_ret ) == 0 ) // 0 means error
99
QString ret( hints_ret.res_name );
101
ret += hints_ret.res_class;
102
XFree( hints_ret.res_name );
103
XFree( hints_ret.res_class );
107
WId WindowsHandler::active_window()
109
return KWindowSystem::activeWindow();
112
WId WindowsHandler::action_window()
114
return _action_window;
117
void WindowsHandler::set_action_window( WId window_P )
119
_action_window = window_P;
122
WId WindowsHandler::find_window( const Windowdef_list* window_P )
124
for( QList< WId >::const_iterator it = KWindowSystem::windows().begin();
125
it != KWindowSystem::windows().end();
128
Window_data tmp( *it );
129
if( window_P->match( tmp ))
135
WId WindowsHandler::window_at_position( int x, int y )
138
Window parent = QX11Info::appRootWindow();
139
Atom wm_state = XInternAtom( QX11Info::display(), "WM_STATE", False );
145
// find child at that position
146
if( !XTranslateCoordinates( QX11Info::display(), parent, parent, x, y, &destx, &desty, &child )
149
// and now transform coordinates to the child
150
if( !XTranslateCoordinates( QX11Info::display(), parent, child, x, y, &destx, &desty, &dummy ))
156
unsigned long nitems, after;
158
if( XGetWindowProperty( QX11Info::display(), child, wm_state, 0, 0, False, AnyPropertyType,
159
&type, &format, &nitems, &after, &prop ) == Success )
172
void WindowsHandler::activate_window( WId id_P )
174
KWindowSystem::forceActiveWindow( id_P );
179
Window_data::Window_data( WId id_P )
180
: type( NET::Unknown )
182
KWindowInfo kwin_info = KWindowSystem::windowInfo( id_P, NET::WMName | NET::WMWindowType ); // TODO optimize
183
if( kwin_info.valid())
185
title = kwin_info.name();
186
role = windows_handler->get_window_role( id_P );
187
wclass = windows_handler->get_window_class( id_P );
188
type = kwin_info.windowType( SUPPORTED_WINDOW_TYPES_MASK );
189
if( type == NET::Override ) // HACK consider non-NETWM fullscreens to be normal too
191
if( type == NET::Unknown )
196
} // namespace KHotKeys
198
#include "moc_windows_handler.cpp"