aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tests/Makefile6
-rw-r--r--src/tests/fullscreentest.cc170
-rw-r--r--src/tests/titletest.cc120
3 files changed, 296 insertions, 0 deletions
diff --git a/src/tests/Makefile b/src/tests/Makefile
index e39ab0b..8d1c482 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -24,6 +24,9 @@ testKeys: testKeys.o
24testResource: Resourcetest.o Resource.o 24testResource: Resourcetest.o Resource.o
25 ${CXX} ${LIBS} ${XLIBS} Resourcetest.o Resource.o -o testResource 25 ${CXX} ${LIBS} ${XLIBS} Resourcetest.o Resource.o -o testResource
26 26
27testTitle: titletest.cc
28 ${CXX} ${CXXFLAGS} ${LIBS} ${XLIBS} titletest.cc ../FbTk/libFbTk.a -o testTitle
29
27signaltest: 30signaltest:
28 ${COMPILE} ../FbTk/SignalHandler.o signaltest.cc -o signaltest 31 ${COMPILE} ../FbTk/SignalHandler.o signaltest.cc -o signaltest
29 32
@@ -48,6 +51,9 @@ testTexture: texturetest.cc
48testDemandAttention: testDemandAttention.cc 51testDemandAttention: testDemandAttention.cc
49 ${COMPILE} testDemandAttention.cc ../FbTk/libFbTk.a -lXpm -o testDemandAttention 52 ${COMPILE} testDemandAttention.cc ../FbTk/libFbTk.a -lXpm -o testDemandAttention
50 53
54testFullscreen: fullscreentest.cc
55 ${COMPILE} fullscreentest.cc ../FbTk/libFbTk.a -o testFullscreen
56
51Parser.o: ../Parser.hh ../Parser.cc 57Parser.o: ../Parser.hh ../Parser.cc
52 ${COMPILE} ${CXXFLAGS} -c ../Parser.cc 58 ${COMPILE} ${CXXFLAGS} -c ../Parser.cc
53 59
diff --git a/src/tests/fullscreentest.cc b/src/tests/fullscreentest.cc
new file mode 100644
index 0000000..13d7325
--- /dev/null
+++ b/src/tests/fullscreentest.cc
@@ -0,0 +1,170 @@
1// fullscreentest.cc for EWMH test suite
2// Copyright (c) 2007 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
32#include <X11/Xutil.h>
33#include <X11/keysym.h>
34#include <X11/Xatom.h>
35
36#include <string>
37#include <iostream>
38using namespace std;
39/// Motif wm Hints
40enum {
41 MwmHintsFunctions = (1l << 0), ///< use motif wm functions
42 MwmHintsDecorations = (1l << 1) ///< use motif wm decorations
43};
44/// Motif wm functions
45enum MwmFunc{
46 MwmFuncAll = (1l << 0), ///< all motif wm functions
47 MwmFuncResize = (1l << 1), ///< resize
48 MwmFuncMove = (1l << 2), ///< move
49 MwmFuncIconify = (1l << 3), ///< iconify
50 MwmFuncMaximize = (1l << 4), ///< maximize
51 MwmFuncClose = (1l << 5) ///< close
52};
53
54typedef struct MwmHints {
55 unsigned long flags; // Motif wm flags
56 unsigned long functions; // Motif wm functions
57 unsigned long decorations; // Motif wm decorations
58} MwmHints;
59
60class App:public FbTk::App, public FbTk::EventHandler {
61public:
62 App(const char *displayname, bool fullscreen):
63 FbTk::App(displayname),
64 m_win(DefaultScreen(display()),
65 0, 0, 100, 100, KeyPressMask | ExposureMask ),
66 m_fullscreen(fullscreen) {
67
68 if (fullscreen) {
69
70 // setup fullscreen as initial state
71 Atom net_wm_state = XInternAtom(display(), "_NET_WM_STATE", False);
72 Atom state_fullscreen = XInternAtom(display(), "_NET_WM_STATE_FULLSCREEN", False);
73 m_win.changeProperty(net_wm_state, XA_ATOM, 32, PropModeReplace,
74 reinterpret_cast<unsigned char*>(&state_fullscreen),
75 1 );
76 MwmHints hints;
77 hints.flags = MwmHintsFunctions;
78 hints.functions = MwmFuncIconify | MwmFuncClose;
79
80 // disable resize
81 Atom mwm_hints = XInternAtom(display(), "_MOTIF_WM_HINTS", False);
82
83 m_win.changeProperty(mwm_hints, mwm_hints, 32, PropModeReplace,
84 reinterpret_cast<unsigned char*>(&hints), 3);
85
86 }
87
88 m_win.show();
89
90 m_win.setBackgroundColor(FbTk::Color("white", m_win.screenNumber()));
91 FbTk::EventManager::instance()->add(*this, m_win);
92 m_win.setName("Fullscreen test.");
93 }
94
95 ~App() {
96 }
97
98 void keyPressEvent(XKeyEvent &ke) {
99 KeySym ks;
100 char keychar[1];
101 XLookupString(&ke, keychar, 1, &ks, 0);
102 if (ks == XK_Escape)
103 end();
104 else
105 toggleFullscreen();
106 }
107 void exposeEvent(XExposeEvent &event) {
108 redraw();
109 }
110
111 void redraw() {
112 m_win.clear();
113 }
114
115 void toggleFullscreen() {
116 setFullscreen(!m_fullscreen);
117 }
118 void setFullscreen( bool state ) {
119 m_fullscreen = state;
120 Atom net_wm_state = XInternAtom(display(), "_NET_WM_STATE", False);
121 Atom net_wm_state_fullscreen = XInternAtom(display(), "_NET_WM_STATE_FULLSCREEN", False);
122 XEvent event;
123 event.type = ClientMessage;
124 event.xclient.message_type = net_wm_state;
125 event.xclient.display = m_win.display();
126 event.xclient.format = 32;
127 event.xclient.window = m_win.window();
128 event.xclient.data.l[0] = state;
129 event.xclient.data.l[1] = net_wm_state_fullscreen;
130 event.xclient.data.l[2] = 0;
131 event.xclient.data.l[3] = 0;
132 event.xclient.data.l[4] = 0;
133 XSendEvent(display(), DefaultRootWindow(display()), False,
134 SubstructureRedirectMask | SubstructureNotifyMask,
135 &event);
136 if ( ! state ) {
137 // if no fullscreen then
138 // enable all functions
139 MwmHints hints;
140 hints.flags = MwmHintsFunctions;
141 hints.functions = MwmFuncAll;
142
143 // disable resize
144 Atom mwm_hints = XInternAtom(display(), "_MOTIF_WM_HINTS", False);
145
146 m_win.changeProperty(mwm_hints, mwm_hints, 32, PropModeReplace,
147 reinterpret_cast<unsigned char*>(&hints), 3);
148 }
149 }
150private:
151 FbTk::FbWindow m_win;
152 bool m_fullscreen;
153};
154
155int main(int argc, char **argv) {
156 string displayname("");
157 bool fullscreen = false;
158 for (int a=1; a<argc; ++a) {
159 if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) {
160 displayname = argv[++a];
161 } else if (strcmp("-f", argv[a]) == 0) {
162 fullscreen = true;
163 }
164 }
165
166 App app(displayname.c_str(), fullscreen);
167
168 app.eventLoop();
169
170}
diff --git a/src/tests/titletest.cc b/src/tests/titletest.cc
new file mode 100644
index 0000000..fadcc9b
--- /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 = 15000;
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}