summaryrefslogtreecommitdiff
path: root/src/tests/titletest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/titletest.cc')
-rw-r--r--src/tests/titletest.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/tests/titletest.cc b/src/tests/titletest.cc
new file mode 100644
index 0000000..a473d06
--- /dev/null
+++ b/src/tests/titletest.cc
@@ -0,0 +1,120 @@
1// titletest.cc for fbtk test suite
2// Copyright (c) 2007 Henrik Kinnunen (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 "Timer.hh"
30#include "SimpleCommand.hh"
31#include "stringstream.hh"
32#include "GContext.hh"
33#include "Color.hh"
34
35#include <X11/Xutil.h>
36#include <X11/keysym.h>
37
38#include <string>
39#include <iostream>
40using namespace std;
41
42class App:public FbTk::App, public FbTk::EventHandler {
43public:
44 App(const char *displayname):
45 FbTk::App(displayname),
46 m_win(DefaultScreen(display()),
47 0, 0, 640, 100, KeyPressMask | ExposureMask |
48 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),
49 m_tick( 0 ) {
50
51 m_win.show();
52 m_win.setBackgroundColor(FbTk::Color("white", m_win.screenNumber()));
53 FbTk::EventManager::instance()->add(*this, m_win);
54 FbTk::RefCount<FbTk::Command> cmd(new FbTk::SimpleCommand<App>
55 (*this,
56 &App::updateTitle));
57 timeval t;
58 t.tv_sec = 0;
59 t.tv_usec = 150000;
60 m_timer.setTimeout(t);
61 m_timer.setCommand(cmd);
62 m_timer.fireOnce(false);
63 m_timer.start();
64
65 updateTitle();
66 m_win.clear();
67 srand( time( 0 ) );
68 }
69
70 ~App() {
71 }
72 void eventLoop() {
73 XEvent ev;
74 while (!done()) {
75 if (XPending(display())) {
76 XNextEvent(display(), &ev);
77 FbTk::EventManager::instance()->handleEvent(ev);
78 } else {
79 FbTk::Timer::updateTimers(ConnectionNumber(display()));
80 }
81 }
82 }
83
84 void updateTitle() {
85 FbTk_ostringstream str;
86 ++m_tick;
87 for (int i = 0, n = rand( ) % 10; i < max( 1, n ); ++i) {
88 str << " Tick #" << m_tick;
89 }
90
91 m_win.setName( str.str().c_str() );
92 // set _NET_WM_NAME
93 Atom net_wm_name = XInternAtom(display(), "_NET_WM_NAME", False);
94 Atom utf8_string = XInternAtom(display(), "UTF8_STRING", False);
95 XChangeProperty(display(), m_win.window(),
96 net_wm_name, utf8_string, 8,
97 PropModeReplace,
98 (unsigned char*)str.str().c_str(), str.str().size() );
99 }
100
101
102private:
103 FbTk::FbWindow m_win;
104 FbTk::Timer m_timer;
105 unsigned int m_tick;
106};
107
108int main(int argc, char **argv) {
109 string displayname("");
110 for (int a=1; a<argc; ++a) {
111 if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) {
112 displayname = argv[++a];
113 }
114 }
115
116 App app(displayname.c_str());
117
118 app.eventLoop();
119
120}