fixed focus last crash bug, a dangling m_focused_window pointer
fluxgen fluxgen
1 files changed,
27 insertions(+),
34 deletions(-)
jump to
M
src/fluxbox.cc
→
src/fluxbox.cc
@@ -22,7 +22,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: fluxbox.cc,v 1.135 2003/05/11 13:36:12 fluxgen Exp $ +// $Id: fluxbox.cc,v 1.136 2003/05/11 15:24:09 fluxgen Exp $ #include "fluxbox.hh"@@ -357,11 +357,13 @@
static int handleXErrors(Display *d, XErrorEvent *e) { #ifdef DEBUG + char errtxt[128]; - + XGetErrorText(d, e->error_code, errtxt, 128); - cerr<<"Fluxbox: X Error: "<<errtxt<<"("<<e->error_code<<") opcodes "<< - e->request_code<<"/"<<e->minor_code<<" resource 0x"<<hex<<e->resourceid<<dec<<endl; + cerr<<"Fluxbox: X Error: "<<errtxt<<"("<<(int)e->error_code<<") opcodes "<< + (int)e->request_code<<"/"<<(int)e->minor_code<<" resource 0x"<<hex<<(int)e->resourceid<<dec<<endl; + #endif // !DEBUG if (e->error_code == BadWindow)@@ -748,6 +750,7 @@ if (scr != 0)
win = scr->createWindow(e->xmaprequest.window); else cerr<<"Fluxbox Warning! Could not find screen to map window on!"<<endl; + } // we don't handle MapRequest in FluxboxWindow::handleEvent if (win)@@ -964,11 +967,10 @@ win->unmapNotifyEvent(ue);
client = 0; // it's invalid now when win destroyed the client if (win == m_focused_window) - revertFocus(&win->screen()); + revertFocus(win->screen()); // finaly destroy window if empty if (win->numClients() == 0) { - delete win; win = 0; }@@ -1557,7 +1559,7 @@ // make sure each workspace get this
BScreen &scr = win.screen(); scr.removeWindow(&win); if (m_focused_window == &win) - revertFocus(&scr); + revertFocus(scr); } else if ((&(win.workspaceSig())) == changedsub) { // workspace signal for (size_t i=0; i<m_atomhandler.size(); ++i) {@@ -2292,7 +2294,18 @@
// set focused window void Fluxbox::setFocusedWindow(FluxboxWindow *win) { // already focused - if (m_focused_window == win) return; + if (m_focused_window == win) { +#ifdef DEBUG + cerr<<"Focused window already win"<<endl; +#endif // DEBUG + return; + } +#ifdef DEBUG + cerr<<"-----------------"<<endl; + cerr<<"Setting Focused window = "<<win<<endl; + cerr<<"Current Focused window = "<<m_focused_window<<endl; + cerr<<"------------------"<<endl; +#endif // DEBUG BScreen *old_screen = 0, *screen = 0; FluxboxWindow *old_win = 0; Toolbar *old_tbar = 0, *tbar = 0;@@ -2364,37 +2377,17 @@ * last_focused is set to something if we want to make use of the
* previously focused window (it must NOT be set focused now, it * is probably dying). */ -void Fluxbox::revertFocus(BScreen *screen) { +void Fluxbox::revertFocus(BScreen &screen) { // Relevant resources: // resource.focus_last = whether we focus last focused when changing workspace // Fluxbox::FocusModel = sloppy, click, whatever - - // if no given screen, get it from the mouse - if (screen == 0) { - Window root = 0, ignorew; - int ignored; - BScreen *tempscr = m_screen_list.front(); - XQueryPointer(FbTk::App::instance()->display(), - tempscr->rootWindow().window(), &root, &ignorew, &ignored, - &ignored, &ignored, &ignored, (unsigned int *)&ignored); - screen = searchScreen(root); - if (screen == 0) { -#ifdef DEBUG - cerr<<"No screen to base focus revert on!"<<endl; -#endif // DEBUG - // flounder - XSetInputFocus(FbTk::App::instance()->display(), - PointerRoot, None, CurrentTime); - return; - } - } - - WinClient *next_focus = screen->getLastFocusedWindow(screen->getCurrentWorkspaceID()); + WinClient *next_focus = screen.getLastFocusedWindow(screen.getCurrentWorkspaceID()); if (next_focus && next_focus->fbwindow()) { - next_focus->fbwindow()->setInputFocus(); + setFocusedWindow(next_focus->fbwindow()); } else { - switch (screen->getFocusModel()) { + setFocusedWindow(0); // so we don't get dangling m_focused_window pointer + switch (screen.getFocusModel()) { case SLOPPYFOCUS: case SEMISLOPPYFOCUS: XSetInputFocus(FbTk::App::instance()->display(),@@ -2402,7 +2395,7 @@ PointerRoot, None, CurrentTime);
break; case CLICKTOFOCUS: XSetInputFocus(FbTk::App::instance()->display(), - screen->rootWindow().window(), + screen.rootWindow().window(), RevertToPointerRoot, CurrentTime); break; }