Advanced Settings Panel
[pierogi] / pirapplication.cpp
1 #include "pirapplication.h"
2
3 #include <QWidget>
4 #include <X11/Xlib.h>
5 #include <X11/Xatom.h>
6 #include <QX11Info>
7 #include <QTimer>
8
9
10 PIRApplication::PIRApplication(
11   int &argc,
12   char **argv)
13   : QApplication(argc, argv),
14     changingKeyset(false)
15 {
16 }
17
18
19 void PIRApplication::setupRockerSwitch(QWidget *window)
20 {
21   // free the rocker switch from the volume controls:
22   unsigned long val = 1;
23
24   Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", 0);
25
26   XChangeProperty( 
27     QX11Info::display(),
28     window->winId(),
29     atom,
30     XA_INTEGER,
31     32,
32     PropModeReplace,
33     (unsigned char *) &val,
34     1);
35 }
36
37
38 bool PIRApplication::x11EventFilter(
39   XEvent *event)
40 {
41   // Return true means we will consume the event here; return false means
42   // letting the event continue to be passed up the chain.
43
44   if (event->type == KeyPress)
45   {
46     // Function key 7 (keycode 73) or "Zoom Out" button will go up.
47     // Function key 8 (keycode 74) or "Zoom In" button will go down.
48     if (
49       event->xkey.keycode == 73 ||
50       event->xkey.keycode == QKeySequence::ZoomOut)
51     {
52       if (!changingKeyset)
53       {
54         changingKeyset = true;
55         QTimer::singleShot(500, this, SLOT(finishChangingKeyset()));
56         emit decreaseRockerPressed();
57       }
58       return true;
59     }
60     else if (
61       event->xkey.keycode == 74 ||
62       event->xkey.keycode == QKeySequence::ZoomIn)
63     {
64       if (!changingKeyset)
65       {
66         changingKeyset = true;
67         QTimer::singleShot(500, this, SLOT(finishChangingKeyset()));
68         emit increaseRockerPressed();
69       }
70       return true;
71     }
72   }
73
74   return false;
75 }
76
77
78 void PIRApplication::finishChangingKeyset()
79 {
80   changingKeyset = false;
81 }