diff options
author | fluxgen <fluxgen> | 2006-05-13 15:00:45 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2006-05-13 15:00:45 (GMT) |
commit | d812faffb499286861b04c24c4cd98ad60fb33bd (patch) | |
tree | a5b77845062324d3dd80b54723e0ef88c260da2e /src/tests/testDemandAttention.cc | |
parent | 03ca0654c82de2fb6b04ed33a8f34110d5c9886a (diff) | |
download | fluxbox-d812faffb499286861b04c24c4cd98ad60fb33bd.zip fluxbox-d812faffb499286861b04c24c4cd98ad60fb33bd.tar.bz2 |
test program for _NET_WM_STATE_DEMANDS_ATTENTION
Diffstat (limited to 'src/tests/testDemandAttention.cc')
-rw-r--r-- | src/tests/testDemandAttention.cc | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/tests/testDemandAttention.cc b/src/tests/testDemandAttention.cc new file mode 100644 index 0000000..874d05e --- /dev/null +++ b/src/tests/testDemandAttention.cc | |||
@@ -0,0 +1,131 @@ | |||
1 | // testDemandAttention.cc for fbtk test suite | ||
2 | // Copyright (c) 2006 Fluxbox Team (fluxgen at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id$ | ||
23 | |||
24 | #include "App.hh" | ||
25 | #include "FbWindow.hh" | ||
26 | #include "Font.hh" | ||
27 | #include "EventHandler.hh" | ||
28 | #include "EventManager.hh" | ||
29 | #include "GContext.hh" | ||
30 | #include "Color.hh" | ||
31 | #include "SimpleCommand.hh" | ||
32 | #include "Timer.hh" | ||
33 | |||
34 | #include <X11/Xutil.h> | ||
35 | #include <X11/keysym.h> | ||
36 | |||
37 | #include <string> | ||
38 | #include <iostream> | ||
39 | using namespace std; | ||
40 | |||
41 | class App:public FbTk::App, public FbTk::EventHandler { | ||
42 | public: | ||
43 | App(const char *displayname): | ||
44 | FbTk::App(displayname), | ||
45 | m_win(DefaultScreen(display()), | ||
46 | 0, 0, 640, 480, KeyPressMask | ExposureMask | | ||
47 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask) { | ||
48 | |||
49 | m_win.setName("Demand Attention"); | ||
50 | m_win.show(); | ||
51 | m_win.setBackgroundColor(FbTk::Color("white", m_win.screenNumber())); | ||
52 | FbTk::EventManager::instance()->add(*this, m_win); | ||
53 | |||
54 | m_net_wm_state = XInternAtom(m_win.display(), | ||
55 | "_NET_WM_STATE", | ||
56 | False); | ||
57 | m_net_wm_state_demands_attention = | ||
58 | XInternAtom(m_win.display(), | ||
59 | "_NET_WM_STATE_DEMANDS_ATTENTION", | ||
60 | False); | ||
61 | FbTk::RefCount<FbTk::Command> cmd(new FbTk::SimpleCommand<App> | ||
62 | (*this, | ||
63 | &App::demandAttention)); | ||
64 | timeval t; | ||
65 | t.tv_sec = 5; | ||
66 | t.tv_usec = 0; | ||
67 | m_timer.setTimeout(t); | ||
68 | m_timer.setCommand(cmd); | ||
69 | m_timer.fireOnce(false); | ||
70 | m_timer.start(); | ||
71 | } | ||
72 | |||
73 | ~App() { | ||
74 | } | ||
75 | void eventLoop() { | ||
76 | XEvent ev; | ||
77 | while (!done()) { | ||
78 | if (XPending(display())) { | ||
79 | XNextEvent(display(), &ev); | ||
80 | FbTk::EventManager::instance()->handleEvent(ev); | ||
81 | } else { | ||
82 | FbTk::Timer::updateTimers(ConnectionNumber(display())); | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | void exposeEvent(XExposeEvent &event) { | ||
87 | redraw(); | ||
88 | } | ||
89 | |||
90 | void redraw() { | ||
91 | m_win.clear(); | ||
92 | } | ||
93 | |||
94 | void demandAttention() { | ||
95 | cerr << "Demand attention!" << endl; | ||
96 | XEvent event; | ||
97 | event.type = ClientMessage; | ||
98 | event.xclient.message_type = m_net_wm_state; | ||
99 | event.xclient.display = m_win.display(); | ||
100 | event.xclient.format = 32; | ||
101 | event.xclient.window = m_win.window(); | ||
102 | event.xclient.data.l[0] = 1; // STATE_ADD | ||
103 | event.xclient.data.l[1] = m_net_wm_state_demands_attention; | ||
104 | event.xclient.data.l[2] = 0; | ||
105 | event.xclient.data.l[3] = 0; | ||
106 | event.xclient.data.l[4] = 0; | ||
107 | XSendEvent(display(), DefaultRootWindow(display()), False, | ||
108 | SubstructureRedirectMask | SubstructureNotifyMask, | ||
109 | &event); | ||
110 | } | ||
111 | |||
112 | private: | ||
113 | FbTk::FbWindow m_win; | ||
114 | FbTk::Timer m_timer; | ||
115 | Atom m_net_wm_state; | ||
116 | Atom m_net_wm_state_demands_attention; | ||
117 | }; | ||
118 | |||
119 | int main(int argc, char **argv) { | ||
120 | string displayname(""); | ||
121 | for (int a=1; a<argc; ++a) { | ||
122 | if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) { | ||
123 | displayname = argv[++a]; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | App app(displayname.c_str()); | ||
128 | |||
129 | app.eventLoop(); | ||
130 | |||
131 | } | ||