aboutsummaryrefslogtreecommitdiff
path: root/src/FluxboxHandler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FluxboxHandler.cc')
-rw-r--r--src/FluxboxHandler.cc200
1 files changed, 0 insertions, 200 deletions
diff --git a/src/FluxboxHandler.cc b/src/FluxboxHandler.cc
deleted file mode 100644
index 23fa1c6..0000000
--- a/src/FluxboxHandler.cc
+++ /dev/null
@@ -1,200 +0,0 @@
1// FluxboxHandler.cc for FbPager
2// Copyright (c) 2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
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#include "FluxboxHandler.hh"
23
24#include "Pager.hh"
25#include "WindowHint.hh"
26#include "FbRootWindow.hh"
27#include "ClientWindow.hh"
28
29#include "FbTk/App.hh"
30
31#include <X11/Xutil.h>
32
33#include <iostream>
34using namespace std;
35
36namespace {
37
38void sendClientMessage(FbTk::FbWindow &src,
39 FbTk::FbWindow &dest,
40 Atom the_atom,
41 unsigned long data1, unsigned long data2 = 0,
42 unsigned long data3 = 0, unsigned long data4 = 0) {
43 // fill in client structure
44 XEvent clientevent;
45 clientevent.xclient.display = FbTk::App::instance()->display();
46 clientevent.xclient.type = ClientMessage;
47 clientevent.xclient.window = dest.window();
48 clientevent.xclient.message_type = the_atom;
49 clientevent.xclient.format = 32;
50 clientevent.xclient.data.l[0] = data1;
51 clientevent.xclient.data.l[1] = data2;
52 clientevent.xclient.data.l[2] = data3;
53 clientevent.xclient.data.l[3] = data4;
54 // send event to root window
55 src.sendEvent(false, SubstructureRedirectMask, clientevent);
56}
57
58} // end anonymous namespace
59
60struct FluxboxHints {
61 unsigned long flags, attrib, workspace, stack, decoration;
62 enum Attrib {
63 ATTRIB_SHADED = 0x01,
64 ATTRIB_STICK = 0x08,
65 ATTRIB_WORKSPACE = 0x10,
66 ATTRIB_DECOR = 0x40
67 };
68 enum Decor { NO_DECOR = 0 };
69};
70
71namespace FbPager {
72
73FluxboxHandler *FluxboxHandler::s_handler = 0;
74
75FluxboxHandler::FluxboxHandler():
76 m_fbatoms(FbTk::App::instance()->display()) {
77 s_handler = this;
78}
79
80void FluxboxHandler::setFocus(FbTk::FbWindow &client) {
81 FbRootWindow root(client.screenNumber());
82 sendClientMessage(root, client,
83 m_fbatoms.getFluxboxChangeWindowFocusAtom(), 0);
84}
85
86void FluxboxHandler::sendToWorkspace(FbTk::FbWindow &client, int workspace) {
87 FbRootWindow root(client.screenNumber());
88 sendClientMessage(root, client,
89 m_fbatoms.getFluxboxChangeAttributesAtom(),
90 FluxboxHints::ATTRIB_WORKSPACE,
91 0,
92 workspace);
93}
94
95bool FluxboxHandler::clientMessage(Pager &pager, XClientMessageEvent &event) {
96 const FbAtoms &fbatoms = *FbAtoms::instance();
97 if (event.data.l[0] == fbatoms.getFluxboxNotifyWorkspaceCountAtom()) {
98 pager.updateWorkspaceCount(event.data.l[1]);
99 return true;
100 } else if (event.data.l[0] == fbatoms.getFluxboxNotifyCurrentWorkspaceAtom()) {
101 pager.setCurrentWorkspace(event.data.l[1]);
102 return true;
103 } else if (event.data.l[0] == fbatoms.getFluxboxNotifyWindowAddAtom()) {
104 pager.addWindow(event.data.l[1], event.data.l[2]);
105 return true;
106 } else if (event.data.l[0] == fbatoms.getFluxboxNotifyWindowDelAtom()) {
107 pager.removeWindow(event.data.l[1]);
108 return true;
109 } else if (event.data.l[0] == fbatoms.getFluxboxNotifyWindowRaiseAtom()) {
110 pager.raiseWindow(event.data.l[1]);
111 return true;
112 } else if (event.data.l[0] == fbatoms.getFluxboxNotifyWindowLowerAtom()) {
113 pager.lowerWindow(event.data.l[1]);
114 return true;
115 } else if (event.data.l[0] == fbatoms.getFluxboxNotifyWindowFocusAtom()) {
116 pager.setFocusedWindow(event.data.l[1]);
117 return true;
118 }
119
120 return false;
121}
122
123void FluxboxHandler::changeWorkspace(int screen_num, int workspace) {
124 FbRootWindow root(screen_num);
125 sendClientMessage(root, root, FbAtoms::instance()->getFluxboxChangeWorkspaceAtom(), workspace);
126}
127
128void FluxboxHandler::setHints(FbTk::FbWindow &win, WindowHint &hints) {
129 FluxboxHints net_hints;
130 net_hints.decoration = (hints.flags() & WindowHint::WHINT_NO_DECOR) ? FluxboxHints::NO_DECOR : 1;
131 net_hints.attrib = (hints.flags() & WindowHint::WHINT_STICKY) ? FluxboxHints::ATTRIB_STICK : 0;
132 // use Decoration and sticky flag
133 net_hints.flags = FluxboxHints::ATTRIB_DECOR | FluxboxHints::ATTRIB_STICK;
134 Atom hint_atom = m_fbatoms.getFluxboxHintsAtom();
135 win.changeProperty(hint_atom, hint_atom,
136 32, PropModeReplace,
137 (unsigned char *)(&net_hints),
138 5); // number of fluxbox hints in the structure
139}
140
141void FluxboxHandler::getHints(const FbTk::FbWindow &win, WindowHint &hint) const {
142 Atom real_type;
143 int format;
144 unsigned long num_elements, not_used;
145 FluxboxHints *win_hints;
146
147 if (!win.property(m_fbatoms.getFluxboxAttributesAtom(), 0L,
148 5, // five elements in our structure
149 false,
150 m_fbatoms.getFluxboxAttributesAtom(),
151 &real_type, &format, &num_elements, &not_used,
152 (unsigned char**)&win_hints) ||
153 num_elements != 5) // must have five elements
154 return; // failure
155
156 hint.setWorkspace(win_hints->workspace);
157
158 // get shaded state
159 bool shaded = false;
160 if (win_hints->flags & FluxboxHints::ATTRIB_SHADED)
161 hint.add(WindowHint::WHINT_SHADED);
162
163 // get sticky state
164 bool sticky = false;
165 if (win_hints->flags & FluxboxHints::ATTRIB_STICK)
166 hint.add(WindowHint::WHINT_STICKY);
167
168 // get icon state
169 long *state;
170 bool iconified = false;
171 if (!win.property(m_fbatoms.getWMStateAtom(), 0, 1,
172 False, m_fbatoms.getWMStateAtom(),
173 &real_type, &format, &num_elements, &not_used,
174 (unsigned char**)&state) || state == 0)
175 cerr<<"Warning: Couldn't get WM_STATE property"<<endl;
176 else if (state[0] == IconicState)
177 hint.add(WindowHint::WHINT_ICONIC);
178
179 return;
180}
181
182int FluxboxHandler::numberOfWorkspaces(int screen_num) const {
183 Atom real_type;
184 int format;
185 unsigned long num_elements, not_used;
186 unsigned char *data = 0;
187 Display *disp = FbTk::App::instance()->display();
188 if (XGetWindowProperty(disp, RootWindow(disp, screen_num),
189 m_fbatoms.getFluxboxNotifyWorkspaceCountAtom(), 0, 1,
190 False, 0,
191 &real_type, &format, &num_elements, &not_used,
192 (unsigned char**)&data) == Success) {
193 if (data != 0)
194 return static_cast<int>(*data);
195 }
196
197 return 0;
198}
199
200} // end namespace FbPager