summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Screen.cc12
-rw-r--r--src/WinClient.cc126
-rw-r--r--src/WinClient.hh21
3 files changed, 123 insertions, 36 deletions
diff --git a/src/Screen.cc b/src/Screen.cc
index 45f9693..73acb3a 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -1177,10 +1177,8 @@ FluxboxWindow *BScreen::createWindow(Window client) {
1177 FbTk::App::instance()->sync(false); 1177 FbTk::App::instance()->sync(false);
1178 1178
1179 1179
1180 if (isKdeDockapp(client)) { 1180 if (isKdeDockapp(client) && addKdeDockapp(client)) {
1181 if (addKdeDockapp(client)) { 1181 return 0; // dont create a FluxboxWindow for this one
1182 return 0; // dont create a FluxboxWindow for this one
1183 }
1184 } 1182 }
1185 1183
1186 WinClient *winclient = new WinClient(client, *this); 1184 WinClient *winclient = new WinClient(client, *this);
@@ -1387,7 +1385,7 @@ void BScreen::nextFocus(int opts) {
1387 break; 1385 break;
1388 } 1386 }
1389 1387
1390 FluxboxWindow *fbwin = (*it)->m_win; 1388 FluxboxWindow *fbwin = (*it)->fbwindow();
1391 if (fbwin && !fbwin->isIconic() && 1389 if (fbwin && !fbwin->isIconic() &&
1392 (fbwin->isStuck() 1390 (fbwin->isStuck()
1393 || fbwin->workspaceNumber() == currentWorkspaceID())) { 1391 || fbwin->workspaceNumber() == currentWorkspaceID())) {
@@ -1482,7 +1480,7 @@ void BScreen::prevFocus(int opts) {
1482 break; 1480 break;
1483 } 1481 }
1484 1482
1485 FluxboxWindow *fbwin = (*it)->m_win; 1483 FluxboxWindow *fbwin = (*it)->fbwindow();
1486 if (fbwin && !fbwin->isIconic() && 1484 if (fbwin && !fbwin->isIconic() &&
1487 (fbwin->isStuck() 1485 (fbwin->isStuck()
1488 || fbwin->workspaceNumber() == currentWorkspaceID())) { 1486 || fbwin->workspaceNumber() == currentWorkspaceID())) {
@@ -2220,7 +2218,7 @@ FluxboxWindow *BScreen::findGroupRight(WinClient &winclient) {
2220 other->getGroupLeftWindow() != None) 2218 other->getGroupLeftWindow() != None)
2221 return 0; 2219 return 0;
2222 2220
2223 return other->m_win; 2221 return other->fbwindow();
2224} 2222}
2225void BScreen::initXinerama() { 2223void BScreen::initXinerama() {
2226#ifdef XINERAMA 2224#ifdef XINERAMA
diff --git a/src/WinClient.cc b/src/WinClient.cc
index 42f8cae..df27621 100644
--- a/src/WinClient.cc
+++ b/src/WinClient.cc
@@ -27,14 +27,18 @@
27#include "fluxbox.hh" 27#include "fluxbox.hh"
28#include "Screen.hh" 28#include "Screen.hh"
29#include "FbAtoms.hh" 29#include "FbAtoms.hh"
30#include "EventManager.hh" 30
31#include "Xutil.hh" 31#include "Xutil.hh"
32 32
33#include "EventManager.hh"
33#include "FbTk/I18n.hh" 34#include "FbTk/I18n.hh"
35#include "FbTk/MultLayers.hh"
34 36
35#include <iostream> 37#include <iostream>
36#include <algorithm> 38#include <algorithm>
37#include <iterator> 39#include <iterator>
40#include <memory>
41
38#ifdef HAVE_CASSERT 42#ifdef HAVE_CASSERT
39 #include <cassert> 43 #include <cassert>
40#else 44#else
@@ -43,6 +47,9 @@
43 47
44using namespace std; 48using namespace std;
45 49
50
51WinClient::TransientWaitMap WinClient::s_transient_wait;
52
46WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin):FbTk::FbWindow(win), 53WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin):FbTk::FbWindow(win),
47 transient_for(0), 54 transient_for(0),
48 window_group(0), 55 window_group(0),
@@ -80,6 +87,16 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin):FbTk::Fb
80 if (window_group != None) 87 if (window_group != None)
81 Fluxbox::instance()->saveGroupSearch(window_group, this); 88 Fluxbox::instance()->saveGroupSearch(window_group, this);
82 89
90 // search for this in transient waiting list
91 if (s_transient_wait.find(win) != s_transient_wait.end()) {
92 // Found transients that are waiting for this.
93 // For each transient that waits call updateTransientInfo
94 for_each(s_transient_wait[win].begin(),
95 s_transient_wait[win].end(),
96 mem_fun(&WinClient::updateTransientInfo));
97 // clear transient waiting list for this window
98 s_transient_wait.erase(win);
99 }
83} 100}
84 101
85WinClient::~WinClient() { 102WinClient::~WinClient() {
@@ -99,16 +116,25 @@ WinClient::~WinClient() {
99 116
100 Fluxbox *fluxbox = Fluxbox::instance(); 117 Fluxbox *fluxbox = Fluxbox::instance();
101 118
119
120 //
121 // clear transients and transient_for
122 //
102 if (transient_for != 0) { 123 if (transient_for != 0) {
103 assert(transient_for != this); 124 assert(transient_for != this);
104 transient_for->transientList().remove(this); 125 transient_for->transientList().remove(this);
105 transient_for = 0; 126 transient_for = 0;
106 } 127 }
107 128
108 while (!transients.empty()) { 129 while (!transients.empty()) {
109 transients.back()->transient_for = 0; 130 transients.back()->transient_for = 0;
110 transients.pop_back(); 131 transients.pop_back();
111 } 132 }
133 // This fixes issue 1 (see WinClient.hh):
134 // If transients die before the transient_for is created
135 removeTransientFromWaitingList();
136 s_transient_wait.erase(window());
137
112 138
113 screen().removeNetizen(window()); 139 screen().removeNetizen(window());
114 140
@@ -142,12 +168,12 @@ bool WinClient::sendFocus() {
142 cerr<<"WinClient::"<<__FUNCTION__<<": this = "<<this<< 168 cerr<<"WinClient::"<<__FUNCTION__<<": this = "<<this<<
143 " window = 0x"<<hex<<window()<<dec<<endl; 169 " window = 0x"<<hex<<window()<<dec<<endl;
144#endif // DEBUG 170#endif // DEBUG
145 Display *disp = FbTk::App::instance()->display(); 171
146 // setup focus msg 172 // setup focus msg
147 XEvent ce; 173 XEvent ce;
148 ce.xclient.type = ClientMessage; 174 ce.xclient.type = ClientMessage;
149 ce.xclient.message_type = FbAtoms::instance()->getWMProtocolsAtom(); 175 ce.xclient.message_type = FbAtoms::instance()->getWMProtocolsAtom();
150 ce.xclient.display = disp; 176 ce.xclient.display = display();
151 ce.xclient.window = window(); 177 ce.xclient.window = window();
152 ce.xclient.format = 32; 178 ce.xclient.format = 32;
153 ce.xclient.data.l[0] = FbAtoms::instance()->getWMTakeFocusAtom(); 179 ce.xclient.data.l[0] = FbAtoms::instance()->getWMTakeFocusAtom();
@@ -156,21 +182,20 @@ bool WinClient::sendFocus() {
156 ce.xclient.data.l[3] = 0l; 182 ce.xclient.data.l[3] = 0l;
157 ce.xclient.data.l[4] = 0l; 183 ce.xclient.data.l[4] = 0l;
158 // send focus msg 184 // send focus msg
159 XSendEvent(disp, window(), false, NoEventMask, &ce); 185 XSendEvent(display(), window(), false, NoEventMask, &ce);
160 return true; 186 return true;
161} 187}
162 188
163void WinClient::sendClose(bool forceful) { 189void WinClient::sendClose(bool forceful) {
164 if (forceful || !send_close_message) 190 if (forceful || !send_close_message)
165 XKillClient(FbTk::App::instance()->display(), window()); 191 XKillClient(display(), window());
166 else { 192 else {
167 // send WM_DELETE message 193 // send WM_DELETE message
168 Display *disp = FbTk::App::instance()->display();
169 // fill in XClientMessage structure for delete message 194 // fill in XClientMessage structure for delete message
170 XEvent ce; 195 XEvent ce;
171 ce.xclient.type = ClientMessage; 196 ce.xclient.type = ClientMessage;
172 ce.xclient.message_type = FbAtoms::instance()->getWMProtocolsAtom(); 197 ce.xclient.message_type = FbAtoms::instance()->getWMProtocolsAtom();
173 ce.xclient.display = disp; 198 ce.xclient.display = display();
174 ce.xclient.window = window(); 199 ce.xclient.window = window();
175 ce.xclient.format = 32; 200 ce.xclient.format = 32;
176 ce.xclient.data.l[0] = FbAtoms::instance()->getWMDeleteAtom(); 201 ce.xclient.data.l[0] = FbAtoms::instance()->getWMDeleteAtom();
@@ -179,20 +204,20 @@ void WinClient::sendClose(bool forceful) {
179 ce.xclient.data.l[3] = 0l; 204 ce.xclient.data.l[3] = 0l;
180 ce.xclient.data.l[4] = 0l; 205 ce.xclient.data.l[4] = 0l;
181 // send event delete message to client window 206 // send event delete message to client window
182 XSendEvent(disp, window(), false, NoEventMask, &ce); 207 XSendEvent(display(), window(), false, NoEventMask, &ce);
183 } 208 }
184} 209}
185 210
186bool WinClient::getAttrib(XWindowAttributes &attr) const { 211bool WinClient::getAttrib(XWindowAttributes &attr) const {
187 return XGetWindowAttributes(FbTk::App::instance()->display(), window(), &attr); 212 return XGetWindowAttributes(display(), window(), &attr);
188} 213}
189 214
190bool WinClient::getWMName(XTextProperty &textprop) const { 215bool WinClient::getWMName(XTextProperty &textprop) const {
191 return XGetWMName(FbTk::App::instance()->display(), window(), &textprop); 216 return XGetWMName(display(), window(), &textprop);
192} 217}
193 218
194bool WinClient::getWMIconName(XTextProperty &textprop) const { 219bool WinClient::getWMIconName(XTextProperty &textprop) const {
195 return XGetWMName(FbTk::App::instance()->display(), window(), &textprop); 220 return XGetWMName(display(), window(), &textprop);
196} 221}
197 222
198const std::string &WinClient::getWMClassName() const { 223const std::string &WinClient::getWMClassName() const {
@@ -205,7 +230,7 @@ const std::string &WinClient::getWMClassClass() const {
205 230
206void WinClient::updateWMClassHint() { 231void WinClient::updateWMClassHint() {
207 XClassHint ch; 232 XClassHint ch;
208 if (XGetClassHint(FbTk::App::instance()->display(), window(), &ch) == 0) { 233 if (XGetClassHint(display(), window(), &ch) == 0) {
209#ifdef DEBUG 234#ifdef DEBUG
210 cerr<<"WinClient: Failed to read class hint!"<<endl; 235 cerr<<"WinClient: Failed to read class hint!"<<endl;
211#endif //DEBUG 236#endif //DEBUG
@@ -234,16 +259,16 @@ void WinClient::updateTransientInfo() {
234 if (m_win == 0) 259 if (m_win == 0)
235 return; 260 return;
236 261
237 // remove us from parent 262
263 // remove this from parent
238 if (transientFor() != 0) { 264 if (transientFor() != 0) {
239 transientFor()->transientList().remove(this); 265 transientFor()->transientList().remove(this);
240 } 266 }
241 267
242 transient_for = 0; 268 transient_for = 0;
243 Display *disp = FbTk::App::instance()->display();
244 // determine if this is a transient window 269 // determine if this is a transient window
245 Window win = 0; 270 Window win = 0;
246 if (!XGetTransientForHint(disp, window(), &win)) { 271 if (!XGetTransientForHint(display(), window(), &win)) {
247#ifdef DEBUG 272#ifdef DEBUG
248 cerr<<__FUNCTION__<<": window() = 0x"<<hex<<window()<<dec<<"Failed to read transient for hint."<<endl; 273 cerr<<__FUNCTION__<<": window() = 0x"<<hex<<window()<<dec<<"Failed to read transient for hint."<<endl;
249#endif // DEBUG 274#endif // DEBUG
@@ -266,6 +291,22 @@ void WinClient::updateTransientInfo() {
266 291
267 292
268 transient_for = Fluxbox::instance()->searchWindow(win); 293 transient_for = Fluxbox::instance()->searchWindow(win);
294 // if we did not find a transient WinClient but still
295 // have a transient X window, then we have to put the
296 // X transient_for window in a waiting list and update this clients transient
297 // list later when the transient_for has a Winclient
298 if (!transient_for) {
299 // We might also already waiting for an old transient_for;
300 //
301 // this call fixes issue 2:
302 // If transients changes to new transient_for before the old transient_for is created.
303 // (see comment in WinClient.hh)
304 //
305 removeTransientFromWaitingList();
306
307 s_transient_wait[win].push_back(this);
308 }
309
269 310
270#ifdef DEBUG 311#ifdef DEBUG
271 cerr<<__FUNCTION__<<": transient_for window = 0x"<<hex<<win<<dec<<endl; 312 cerr<<__FUNCTION__<<": transient_for window = 0x"<<hex<<win<<dec<<endl;
@@ -287,6 +328,7 @@ void WinClient::updateTransientInfo() {
287 if (transientFor()->fbwindow() && transientFor()->fbwindow()->isStuck()) 328 if (transientFor()->fbwindow() && transientFor()->fbwindow()->isStuck())
288 m_win->stick(); 329 m_win->stick();
289 } 330 }
331
290} 332}
291 333
292 334
@@ -301,7 +343,7 @@ void WinClient::updateTitle() {
301 // also influenced 343 // also influenced
302 // 344 //
303 // the limitation to 512 chars only avoids running in that trap 345 // the limitation to 512 chars only avoids running in that trap
304 m_title = string(Xutil::getWMName(window()) ,0 , 512); 346 m_title = string(Xutil::getWMName(window()), 0, 512);
305} 347}
306 348
307void WinClient::updateIconTitle() { 349void WinClient::updateIconTitle() {
@@ -314,7 +356,7 @@ void WinClient::updateIconTitle() {
314 if (text_prop.encoding != XA_STRING) { 356 if (text_prop.encoding != XA_STRING) {
315 text_prop.nitems = strlen((char *) text_prop.value); 357 text_prop.nitems = strlen((char *) text_prop.value);
316 358
317 if (XmbTextPropertyToTextList(FbTk::App::instance()->display(), &text_prop, 359 if (XmbTextPropertyToTextList(display(), &text_prop,
318 &list, &num) == Success && 360 &list, &num) == Success &&
319 num > 0 && *list) { 361 num > 0 && *list) {
320 m_icon_title = (char *)*list; 362 m_icon_title = (char *)*list;
@@ -341,6 +383,10 @@ void WinClient::saveBlackboxAttribs(FluxboxWindow::BlackboxAttributes &blackbox_
341 ); 383 );
342} 384}
343 385
386void WinClient::setFluxboxWindow(FluxboxWindow *win) {
387 m_win = win;
388}
389
344void WinClient::updateBlackboxHints() { 390void WinClient::updateBlackboxHints() {
345 int format; 391 int format;
346 Atom atom_return; 392 Atom atom_return;
@@ -392,7 +438,7 @@ void WinClient::updateMWMHints() {
392} 438}
393 439
394void WinClient::updateWMHints() { 440void WinClient::updateWMHints() {
395 XWMHints *wmhint = XGetWMHints(FbTk::App::instance()->display(), window()); 441 XWMHints *wmhint = XGetWMHints(display(), window());
396 if (! wmhint) { 442 if (! wmhint) {
397 m_focus_mode = F_PASSIVE; 443 m_focus_mode = F_PASSIVE;
398 window_group = None; 444 window_group = None;
@@ -447,7 +493,7 @@ void WinClient::updateWMHints() {
447void WinClient::updateWMNormalHints() { 493void WinClient::updateWMNormalHints() {
448 long icccm_mask; 494 long icccm_mask;
449 XSizeHints sizehint; 495 XSizeHints sizehint;
450 if (! XGetWMNormalHints(FbTk::App::instance()->display(), window(), &sizehint, &icccm_mask)) { 496 if (! XGetWMNormalHints(display(), window(), &sizehint, &icccm_mask)) {
451 min_width = min_height = 497 min_width = min_height =
452 base_width = base_height = 498 base_width = base_height =
453 width_inc = height_inc = 1; 499 width_inc = height_inc = 1;
@@ -515,7 +561,7 @@ Window WinClient::getGroupLeftWindow() const {
515 int format; 561 int format;
516 Atom atom_return; 562 Atom atom_return;
517 unsigned long num = 0, len = 0; 563 unsigned long num = 0, len = 0;
518 Atom group_left_hint = XInternAtom(FbTk::App::instance()->display(), "_FLUXBOX_GROUP_LEFT", False); 564 Atom group_left_hint = XInternAtom(display(), "_FLUXBOX_GROUP_LEFT", False);
519 565
520 Window *data = 0; 566 Window *data = 0;
521 if (property(group_left_hint, 0, 567 if (property(group_left_hint, 0,
@@ -538,7 +584,7 @@ Window WinClient::getGroupLeftWindow() const {
538 584
539 585
540void WinClient::setGroupLeftWindow(Window win) { 586void WinClient::setGroupLeftWindow(Window win) {
541 Atom group_left_hint = XInternAtom(FbTk::App::instance()->display(), "_FLUXBOX_GROUP_LEFT", False); 587 Atom group_left_hint = XInternAtom(display(), "_FLUXBOX_GROUP_LEFT", False);
542 changeProperty(group_left_hint, XA_WINDOW, 32, 588 changeProperty(group_left_hint, XA_WINDOW, 32,
543 PropModeReplace, (unsigned char *) &win, 1); 589 PropModeReplace, (unsigned char *) &win, 1);
544} 590}
@@ -549,7 +595,7 @@ bool WinClient::hasGroupLeftWindow() const {
549 int format; 595 int format;
550 Atom atom_return; 596 Atom atom_return;
551 unsigned long num = 0, len = 0; 597 unsigned long num = 0, len = 0;
552 Atom group_left_hint = XInternAtom(FbTk::App::instance()->display(), "_FLUXBOX_GROUP_LEFT", False); 598 Atom group_left_hint = XInternAtom(display(), "_FLUXBOX_GROUP_LEFT", False);
553 599
554 Window *data = 0; 600 Window *data = 0;
555 if (property(group_left_hint, 0, 601 if (property(group_left_hint, 0,
@@ -581,13 +627,12 @@ void WinClient::removeModal() {
581} 627}
582 628
583bool WinClient::validateClient() const { 629bool WinClient::validateClient() const {
584 Display *display = FbTk::App::instance()->display();
585 FbTk::App::instance()->sync(false); 630 FbTk::App::instance()->sync(false);
586 631
587 XEvent e; 632 XEvent e;
588 if (( XCheckTypedWindowEvent(display, window(), DestroyNotify, &e) || 633 if (( XCheckTypedWindowEvent(display(), window(), DestroyNotify, &e) ||
589 XCheckTypedWindowEvent(display, window(), UnmapNotify, &e)) 634 XCheckTypedWindowEvent(display(), window(), UnmapNotify, &e))
590 && XPutBackEvent(display, &e)) { 635 && XPutBackEvent(display(), &e)) {
591 Fluxbox::instance()->ungrab(); 636 Fluxbox::instance()->ungrab();
592 return false; 637 return false;
593 } 638 }
@@ -620,7 +665,7 @@ void WinClient::updateWMProtocols() {
620 int num_return = 0; 665 int num_return = 0;
621 FbAtoms *fbatoms = FbAtoms::instance(); 666 FbAtoms *fbatoms = FbAtoms::instance();
622 667
623 if (XGetWMProtocols(FbTk::App::instance()->display(), window(), &proto, &num_return)) { 668 if (XGetWMProtocols(display(), window(), &proto, &num_return)) {
624 669
625 // defaults 670 // defaults
626 send_focus_message = false; 671 send_focus_message = false;
@@ -762,3 +807,28 @@ void WinClient::applySizeHints(int &width, int &height,
762 if (display_height) 807 if (display_height)
763 *display_height = j; 808 *display_height = j;
764} 809}
810
811void WinClient::removeTransientFromWaitingList() {
812
813 // holds the windows that dont have empty
814 // transient waiting list
815 std::list<Window> remove_list;
816
817 // The worst case complexity is huge, but since we usually do not (virtualy never)
818 // have a large transient waiting list the time spent here is neglectable
819 TransientWaitMap::iterator t_it = s_transient_wait.begin();
820 TransientWaitMap::iterator t_it_end = s_transient_wait.end();
821 for (; t_it != t_it_end; ++t_it) {
822 (*t_it).second.remove(this);
823 // if the list is empty, add it to remove list
824 // so we can erase it later
825 if ((*t_it).second.empty())
826 remove_list.push_back((*t_it).first);
827 }
828
829 // erase empty waiting lists
830 std::list<Window>::iterator it = remove_list.begin();
831 std::list<Window>::iterator it_end = remove_list.end();
832 for (; it != it_end; ++it)
833 s_transient_wait.erase(*it);
834}
diff --git a/src/WinClient.hh b/src/WinClient.hh
index 49e1931..deeffd5 100644
--- a/src/WinClient.hh
+++ b/src/WinClient.hh
@@ -94,6 +94,7 @@ public:
94 void setGroupLeftWindow(Window win); 94 void setGroupLeftWindow(Window win);
95 95
96 void saveBlackboxAttribs(FluxboxWindow::BlackboxAttributes &blackbox_attribs); 96 void saveBlackboxAttribs(FluxboxWindow::BlackboxAttributes &blackbox_attribs);
97 void setFluxboxWindow(FluxboxWindow *win);
97 98
98 // does this client have a pending unmap or destroy event? 99 // does this client have a pending unmap or destroy event?
99 bool validateClient() const; 100 bool validateClient() const;
@@ -164,7 +165,7 @@ public:
164 unsigned long initial_state, normal_hint_flags, wm_hint_flags; 165 unsigned long initial_state, normal_hint_flags, wm_hint_flags;
165 166
166 167
167 FluxboxWindow *m_win; 168
168 class WinClientSubj: public FbTk::Subject { 169 class WinClientSubj: public FbTk::Subject {
169 public: 170 public:
170 explicit WinClientSubj(WinClient &client):m_winclient(client) { } 171 explicit WinClientSubj(WinClient &client):m_winclient(client) { }
@@ -176,6 +177,11 @@ public:
176 enum FocusMode { F_NOINPUT = 0, F_PASSIVE, F_LOCALLYACTIVE, F_GLOBALLYACTIVE }; 177 enum FocusMode { F_NOINPUT = 0, F_PASSIVE, F_LOCALLYACTIVE, F_GLOBALLYACTIVE };
177 178
178private: 179private:
180 /// removes client from any waiting list and clears empty waiting lists
181 void removeTransientFromWaitingList();
182
183 FluxboxWindow *m_win;
184
179 // number of transients which we are modal for 185 // number of transients which we are modal for
180 // or indicates that we are modal if don't have any transients 186 // or indicates that we are modal if don't have any transients
181 int m_modal; 187 int m_modal;
@@ -195,6 +201,19 @@ private:
195 BScreen &m_screen; 201 BScreen &m_screen;
196 202
197 Strut *m_strut; 203 Strut *m_strut;
204 // map transient_for X window to winclient transient
205 // (used if transient_for FbWindow was created after transient)
206 // Since a lot of transients can be created before transient_for
207 // we need to map transient_for window to a list of transients
208 //
209 // Stuff to worry about:
210 // 1) If transients die before the transient_for is created
211 // 2) If transients changes to a new transient_for before old transient_for is created
212 // ( 3) Transient_for is never created
213 // This is not a big deal since the key value will be cleared
214 // once the list is empty )
215 typedef std::map<Window, TransientList> TransientWaitMap;
216 static TransientWaitMap s_transient_wait;
198 217
199}; 218};
200 219