aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2007-05-20 12:39:11 (GMT)
committerfluxgen <fluxgen>2007-05-20 12:39:11 (GMT)
commitdf022d0fae9b882e8421daa4123f42cb727bd800 (patch)
tree9b33e20e75d4b400c0ca746464aa742af3f3a0eb
parentb4d15cf569ae2ab5cadcbfab7c919c40c756bb71 (diff)
downloadfluxbox_pavel-df022d0fae9b882e8421daa4123f42cb727bd800.zip
fluxbox_pavel-df022d0fae9b882e8421daa4123f42cb727bd800.tar.bz2
added fullscreen test
-rw-r--r--src/tests/Makefile3
-rw-r--r--src/tests/fullscreentest.cc170
2 files changed, 173 insertions, 0 deletions
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 74fd97b..8d1c482 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -51,6 +51,9 @@ testTexture: texturetest.cc
51testDemandAttention: testDemandAttention.cc 51testDemandAttention: testDemandAttention.cc
52 ${COMPILE} testDemandAttention.cc ../FbTk/libFbTk.a -lXpm -o testDemandAttention 52 ${COMPILE} testDemandAttention.cc ../FbTk/libFbTk.a -lXpm -o testDemandAttention
53 53
54testFullscreen: fullscreentest.cc
55 ${COMPILE} fullscreentest.cc ../FbTk/libFbTk.a -o testFullscreen
56
54Parser.o: ../Parser.hh ../Parser.cc 57Parser.o: ../Parser.hh ../Parser.cc
55 ${COMPILE} ${CXXFLAGS} -c ../Parser.cc 58 ${COMPILE} ${CXXFLAGS} -c ../Parser.cc
56 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}