22
22
#include "cursorwidget.h"
23
#include "mousebutton.h"
24
#include "keymon/device.h"
25
#include "keymon/manager.h"
23
#include "config/mousebutton.h"
24
#include "keymonmanager.h"
28
#include <kdeversion.h>
29
#if KDE_IS_VERSION(4,3,80)
32
27
#include <kdebug.h>
33
28
#include <kapplication.h>
34
29
#include <kwindowsystem.h>
61
57
// _UGLY_ HACK: Prevents KWin to draw a shadow
62
58
setAttribute(Qt::WA_X11NetWmWindowTypeDock);
70
65
m_timer = new QTimer(this);
71
66
connect(m_timer, SIGNAL(timeout()), this, SLOT(updatePos()));
81
76
m_normalColor = Qt::black;
82
77
m_currentColor = m_normalColor;
79
connect(KeyMonManager::self(), SIGNAL(keyEvent(KeyMon::Event)), this,
80
SLOT(buttonPressed(KeyMon::Event)));
87
85
CursorWidget::~CursorWidget()
93
89
delete m_resetTimer;
209
void CursorWidget::click(const int &button)
212
if (m_resetTimer->isActive()) {
213
m_resetTimer->stop();
216
m_currentColor = m_buttons[button];
217
XAllowEvents(x11Info().display(), ReplayPointer, CurrentTime);
220
m_resetTimer->start(350);
226
WId CursorWidget::getWindow() const
229
return static_cast<QWidget*>(parent())->winId();
234
201
void CursorWidget::updatePos()
271
238
m_currentColor = m_normalColor;
277
void CursorWidget::updateGrab(const bool &grab)
280
QHashIterator<int, QColor> it(m_buttons);
281
const int screen = x11Info().appScreen();
284
while (it.hasNext()) {
286
KXErrorHandler handler;
287
XGrabButton(x11Info().display(),
290
x11Info().appRootWindow(screen),
295
x11Info().appRootWindow(screen),
297
if (handler.error(true)) {
298
XErrorEvent event = handler.errorEvent();
299
if (event.error_code == 10) { // BadAccess
300
MouseButton::Button button = MouseButton::getButtonFromXButton(it.key());
301
const QString buttonName = MouseButton::getName(button);
302
emit error(i18n("Grab failed!\n"
303
"Perhaps the button \"%1\" is already grabbed by another"
304
" application.", buttonName));
309
#if KDE_IS_VERSION(4,3,80)
311
KAuth::Action action("org.kde.recorditnow.helper.watch");
312
action.setHelperID("org.kde.recorditnow.helper");
313
connect(action.watcher(), SIGNAL(progressStep(QVariantMap)), this,
314
SLOT(progressStep(QVariantMap)));
317
args["Device"] = m_deviceName;
318
action.setArguments(args);
319
action.setExecutesAsync(true);
321
KAuth::ActionReply reply = action.execute("org.kde.recorditnow.helper");
322
if (reply.type() != 2) {
324
emit error(i18n("Grab failed!"));
327
m_device = KeyMon::Manager::watch(m_deviceName, this);
329
connect(m_device, SIGNAL(buttonPressed(KeyMon::Event)), this,
330
SLOT(buttonPressed(KeyMon::Event)));
332
emit error(i18n("Grab failed!"));
337
while (it.hasNext()) {
339
XUngrabButton(x11Info().display(),
342
x11Info().appRootWindow(screen));
344
#if KDE_IS_VERSION(4,3,80)
346
KAuth::Action action;
347
action.setName("watch");
348
action.setHelperID("org.kde.recorditnow.helper");
354
m_device->disconnect(this);
355
m_device->deleteLater();
364
249
void CursorWidget::buttonPressed(const KeyMon::Event &event)
252
if (!event.mouseEvent) {
367
256
if (m_resetTimer->isActive()) {
368
257
m_resetTimer->stop();
371
264
switch (event.key) {
372
265
case KeyMon::Event::WheelUp:
373
266
case KeyMon::Event::WheelDown: {
374
267
m_currentColor = m_buttons[event.keyToXButton(event.key)];
375
m_resetTimer->start(350);
268
m_resetTimer->start(RESET_TIME);
379
272
if (event.pressed) {
380
273
m_currentColor = m_buttons[event.keyToXButton(event.key)];
382
m_currentColor = m_normalColor;
275
m_resetTimer->start(RESET_TIME);
392
void CursorWidget::progressStep(const QVariantMap &data)
395
#if KDE_IS_VERSION(4,3,80)
397
event.key = static_cast<KeyMon::Event::Key>(data["Key"].toInt());
398
event.pressed = data["Pressed"].toBool();
399
buttonPressed(event);
407
286
void CursorWidget::previewColors()