aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-05-11 15:24:09 (GMT)
committerfluxgen <fluxgen>2003-05-11 15:24:09 (GMT)
commit403a9727ce6071bfc2812c9b2141dc3ef475c007 (patch)
tree73d9146f3ce668fb84cb56b48bb900025a289e40 /src
parentaa72e23c8e1f6decf0bb78f8bd909e3e67b3a9da (diff)
downloadfluxbox_paul-403a9727ce6071bfc2812c9b2141dc3ef475c007.zip
fluxbox_paul-403a9727ce6071bfc2812c9b2141dc3ef475c007.tar.bz2
fixed focus last crash bug, a dangling m_focused_window pointer
Diffstat (limited to 'src')
-rw-r--r--src/fluxbox.cc61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 64be2e8..b7727e8 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: fluxbox.cc,v 1.135 2003/05/11 13:36:12 fluxgen Exp $ 25// $Id: fluxbox.cc,v 1.136 2003/05/11 15:24:09 fluxgen Exp $
26 26
27#include "fluxbox.hh" 27#include "fluxbox.hh"
28 28
@@ -357,11 +357,13 @@ static Window last_bad_window = None;
357 357
358static int handleXErrors(Display *d, XErrorEvent *e) { 358static int handleXErrors(Display *d, XErrorEvent *e) {
359#ifdef DEBUG 359#ifdef DEBUG
360
360 char errtxt[128]; 361 char errtxt[128];
361 362
362 XGetErrorText(d, e->error_code, errtxt, 128); 363 XGetErrorText(d, e->error_code, errtxt, 128);
363 cerr<<"Fluxbox: X Error: "<<errtxt<<"("<<e->error_code<<") opcodes "<< 364 cerr<<"Fluxbox: X Error: "<<errtxt<<"("<<(int)e->error_code<<") opcodes "<<
364 e->request_code<<"/"<<e->minor_code<<" resource 0x"<<hex<<e->resourceid<<dec<<endl; 365 (int)e->request_code<<"/"<<(int)e->minor_code<<" resource 0x"<<hex<<(int)e->resourceid<<dec<<endl;
366
365#endif // !DEBUG 367#endif // !DEBUG
366 368
367 if (e->error_code == BadWindow) 369 if (e->error_code == BadWindow)
@@ -748,6 +750,7 @@ void Fluxbox::handleEvent(XEvent * const e) {
748 win = scr->createWindow(e->xmaprequest.window); 750 win = scr->createWindow(e->xmaprequest.window);
749 else 751 else
750 cerr<<"Fluxbox Warning! Could not find screen to map window on!"<<endl; 752 cerr<<"Fluxbox Warning! Could not find screen to map window on!"<<endl;
753
751 } 754 }
752 // we don't handle MapRequest in FluxboxWindow::handleEvent 755 // we don't handle MapRequest in FluxboxWindow::handleEvent
753 if (win) 756 if (win)
@@ -964,11 +967,10 @@ void Fluxbox::handleUnmapNotify(XUnmapEvent &ue) {
964 client = 0; // it's invalid now when win destroyed the client 967 client = 0; // it's invalid now when win destroyed the client
965 968
966 if (win == m_focused_window) 969 if (win == m_focused_window)
967 revertFocus(&win->screen()); 970 revertFocus(win->screen());
968 971
969 // finaly destroy window if empty 972 // finaly destroy window if empty
970 if (win->numClients() == 0) { 973 if (win->numClients() == 0) {
971
972 delete win; 974 delete win;
973 win = 0; 975 win = 0;
974 } 976 }
@@ -1557,7 +1559,7 @@ void Fluxbox::update(FbTk::Subject *changedsub) {
1557 BScreen &scr = win.screen(); 1559 BScreen &scr = win.screen();
1558 scr.removeWindow(&win); 1560 scr.removeWindow(&win);
1559 if (m_focused_window == &win) 1561 if (m_focused_window == &win)
1560 revertFocus(&scr); 1562 revertFocus(scr);
1561 1563
1562 } else if ((&(win.workspaceSig())) == changedsub) { // workspace signal 1564 } else if ((&(win.workspaceSig())) == changedsub) { // workspace signal
1563 for (size_t i=0; i<m_atomhandler.size(); ++i) { 1565 for (size_t i=0; i<m_atomhandler.size(); ++i) {
@@ -2292,7 +2294,18 @@ void Fluxbox::timeout() {
2292// set focused window 2294// set focused window
2293void Fluxbox::setFocusedWindow(FluxboxWindow *win) { 2295void Fluxbox::setFocusedWindow(FluxboxWindow *win) {
2294 // already focused 2296 // already focused
2295 if (m_focused_window == win) return; 2297 if (m_focused_window == win) {
2298#ifdef DEBUG
2299 cerr<<"Focused window already win"<<endl;
2300#endif // DEBUG
2301 return;
2302 }
2303#ifdef DEBUG
2304 cerr<<"-----------------"<<endl;
2305 cerr<<"Setting Focused window = "<<win<<endl;
2306 cerr<<"Current Focused window = "<<m_focused_window<<endl;
2307 cerr<<"------------------"<<endl;
2308#endif // DEBUG
2296 BScreen *old_screen = 0, *screen = 0; 2309 BScreen *old_screen = 0, *screen = 0;
2297 FluxboxWindow *old_win = 0; 2310 FluxboxWindow *old_win = 0;
2298 Toolbar *old_tbar = 0, *tbar = 0; 2311 Toolbar *old_tbar = 0, *tbar = 0;
@@ -2364,37 +2377,17 @@ void Fluxbox::setFocusedWindow(FluxboxWindow *win) {
2364 * previously focused window (it must NOT be set focused now, it 2377 * previously focused window (it must NOT be set focused now, it
2365 * is probably dying). 2378 * is probably dying).
2366 */ 2379 */
2367void Fluxbox::revertFocus(BScreen *screen) { 2380void Fluxbox::revertFocus(BScreen &screen) {
2368 // Relevant resources: 2381 // Relevant resources:
2369 // resource.focus_last = whether we focus last focused when changing workspace 2382 // resource.focus_last = whether we focus last focused when changing workspace
2370 // Fluxbox::FocusModel = sloppy, click, whatever 2383 // Fluxbox::FocusModel = sloppy, click, whatever
2371 2384 WinClient *next_focus = screen.getLastFocusedWindow(screen.getCurrentWorkspaceID());
2372 // if no given screen, get it from the mouse
2373 if (screen == 0) {
2374 Window root = 0, ignorew;
2375 int ignored;
2376 BScreen *tempscr = m_screen_list.front();
2377 XQueryPointer(FbTk::App::instance()->display(),
2378 tempscr->rootWindow().window(), &root, &ignorew, &ignored,
2379 &ignored, &ignored, &ignored, (unsigned int *)&ignored);
2380 screen = searchScreen(root);
2381 if (screen == 0) {
2382#ifdef DEBUG
2383 cerr<<"No screen to base focus revert on!"<<endl;
2384#endif // DEBUG
2385 // flounder
2386 XSetInputFocus(FbTk::App::instance()->display(),
2387 PointerRoot, None, CurrentTime);
2388 return;
2389 }
2390 }
2391
2392 WinClient *next_focus = screen->getLastFocusedWindow(screen->getCurrentWorkspaceID());
2393 2385
2394 if (next_focus && next_focus->fbwindow()) { 2386 if (next_focus && next_focus->fbwindow()) {
2395 next_focus->fbwindow()->setInputFocus(); 2387 setFocusedWindow(next_focus->fbwindow());
2396 } else { 2388 } else {
2397 switch (screen->getFocusModel()) { 2389 setFocusedWindow(0); // so we don't get dangling m_focused_window pointer
2390 switch (screen.getFocusModel()) {
2398 case SLOPPYFOCUS: 2391 case SLOPPYFOCUS:
2399 case SEMISLOPPYFOCUS: 2392 case SEMISLOPPYFOCUS:
2400 XSetInputFocus(FbTk::App::instance()->display(), 2393 XSetInputFocus(FbTk::App::instance()->display(),
@@ -2402,7 +2395,7 @@ void Fluxbox::revertFocus(BScreen *screen) {
2402 break; 2395 break;
2403 case CLICKTOFOCUS: 2396 case CLICKTOFOCUS:
2404 XSetInputFocus(FbTk::App::instance()->display(), 2397 XSetInputFocus(FbTk::App::instance()->display(),
2405 screen->rootWindow().window(), 2398 screen.rootWindow().window(),
2406 RevertToPointerRoot, CurrentTime); 2399 RevertToPointerRoot, CurrentTime);
2407 break; 2400 break;
2408 } 2401 }