2 Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
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 <config-X11.h>
23 #include "shortcuts_handler.h"
24 #include "khotkeysglobal.h"
27 // #include <X11/Xutil.h>
31 #include <KDE/KAction>
37 ShortcutsHandler::ShortcutsHandler( HandlerType type
, QObject
*parent
)
40 ,_actions(new KActionCollection(this))
42 _actions
->setComponentData(KComponentData("khotkeys"));
45 ShortcutsHandler::~ShortcutsHandler()
52 KAction
*ShortcutsHandler::addAction(
55 const KShortcut
&shortcut
)
58 KAction
*newAction
= _actions
->addAction(id
);
63 // If our HandlerType is configuration we have to tell kdedglobalaccel
64 // that this action is only for configuration purposes.
65 // see KAction::~KAction
66 if (_type
==Configuration
)
68 newAction
->setProperty("isConfigurationAction", QVariant(true));
70 newAction
->setText(text
);
71 newAction
->setGlobalShortcut( shortcut
, KAction::ActiveShortcut
);
72 // Enable global shortcut. If that fails there is no sense in proceeding
73 if (!newAction
->isGlobalShortcutEnabled())
75 kWarning() << "Failed to enable global shortcut for '"
76 << text
<< "' " << id
;
77 _actions
->removeAction(newAction
);
80 Q_ASSERT(newAction
->isEnabled());
85 QAction
*ShortcutsHandler::getAction( const QString
&id
)
87 return _actions
->action(id
);
91 bool ShortcutsHandler::removeAction( const QString
&id
)
93 QAction
*action
= getAction( id
);
100 _actions
->removeAction(action
);
108 } // namespace KHotKeys
109 #include <X11/extensions/XTest.h>
113 static bool xtest_available
= false;
114 static bool xtest_inited
= false;
118 return xtest_available
;
120 int dummy1
, dummy2
, dummy3
, dummy4
;
122 ( XTestQueryExtension( QX11Info::display(), &dummy1
, &dummy2
, &dummy3
, &dummy4
) == True
);
123 return xtest_available
;
127 bool ShortcutsHandler::send_macro_key( const QString
& key
, Window window_P
)
129 kError() << "ShortcutsHandler::send_macro_key not implemented!!!";
131 Q_UNUSED( window_P
);
138 // TODO fix this, make sure it works even with stuff like "dead_acute"
139 QKeySequence
ks( key
);
140 if( key
== "Enter" && ks
.isEmpty() )
141 key
= "Return"; // CHECKE hack
142 keyboard_handler
->send_macro_key( ks
.isEmpty() ? 0 : ks
[0], w
);
144 bool ok
= KKeyServer::keyQtToSymX(keycode
, keysym
) && KKeyServer::keyQtToModX(keycode
, x_mod
);
146 KeyCode x_keycode
= XKeysymToKeycode( QX11Info::display(), keysym
);
147 if( x_keycode
== NoSymbol
)
150 if( xtest() && window_P
== None
)
152 // CHECKME tohle jeste potrebuje modifikatory
153 bool ret
= XTestFakeKeyEvent( QX11Info::display(), x_keycode
, True
, CurrentTime
);
154 ret
= ret
&& XTestFakeKeyEvent( QX11Info::display(), x_keycode
, False
, CurrentTime
);
158 if( window_P
== None
|| window_P
== InputFocus
)
159 window_P
= windows_handler
->active_window();
160 if( window_P
== None
) // CHECKME tohle cele je ponekud ...
161 window_P
= InputFocus
;
164 ev
.display
= QX11Info::display();
165 ev
.window
= window_P
;
166 ev
.root
= QX11Info::appRootWindow(); // I don't know whether these have to be set
167 ev
.subwindow
= None
; // to these values, but it seems to work, hmm
168 ev
.time
= CurrentTime
;
173 ev
.keycode
= x_keycode
;
175 ev
.same_screen
= True
;
176 bool ret
= XSendEvent( QX11Info::display(), window_P
, True
, KeyPressMask
, ( XEvent
* )&ev
);
178 ev
.type
= KeyRelease
; // is this actually really needed ??
179 ev
.display
= QX11Info::display();
180 ev
.window
= window_P
;
181 ev
.root
= QX11Info::appRootWindow();
183 ev
.time
= CurrentTime
;
189 ev
.keycode
= x_keycode
;
190 ev
.same_screen
= True
;
191 ret
= ret
&& XSendEvent( QX11Info::display(), window_P
, True
, KeyReleaseMask
, ( XEvent
* )&ev
);
193 // Qt's autorepeat compression is broken and can create "aab" from "aba"
194 // XSync() should create delay longer than Qt's max autorepeat interval
195 XSync( QX11Info::display(), False
);
200 bool Mouse::send_mouse_button( int button_P
, bool release_P
)
205 // CHECKME tohle jeste potrebuje modifikatory
206 // a asi i spravnou timestamp misto CurrentTime
207 bool ret
= XTestFakeButtonEvent( QX11Info::display(), button_P
, True
, CurrentTime
);
209 ret
= ret
&& XTestFakeButtonEvent( QX11Info::display(), button_P
, False
, CurrentTime
);
216 } // namespace KHotKeys
218 #include "moc_shortcuts_handler.cpp"