diff options
author | fluxgen <fluxgen> | 2006-02-18 20:19:22 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2006-02-18 20:19:22 (GMT) |
commit | 5ceacc65925f597180c918fcaa2a8171c42cbcdd (patch) | |
tree | 1cee0d151c5368ee69bf4e0e432d0f7f6af37b38 /src/FocusControl.cc | |
parent | f53c93e5e0add69771204056550d07b4fee4efef (diff) | |
download | fluxbox_pavel-5ceacc65925f597180c918fcaa2a8171c42cbcdd.zip fluxbox_pavel-5ceacc65925f597180c918fcaa2a8171c42cbcdd.tar.bz2 |
moved all focus handling to FocusControl
Diffstat (limited to 'src/FocusControl.cc')
-rw-r--r-- | src/FocusControl.cc | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/src/FocusControl.cc b/src/FocusControl.cc index d18af44..6e98fc4 100644 --- a/src/FocusControl.cc +++ b/src/FocusControl.cc | |||
@@ -142,7 +142,7 @@ void FocusControl::prevFocus(int opts) { | |||
142 | FluxboxWindow *focused_group = 0; | 142 | FluxboxWindow *focused_group = 0; |
143 | // start from the focused window | 143 | // start from the focused window |
144 | bool have_focused = false; | 144 | bool have_focused = false; |
145 | WinClient *focused = Fluxbox::instance()->getFocusedWindow(); | 145 | WinClient *focused = focusedWindow(); |
146 | if (focused != 0) { | 146 | if (focused != 0) { |
147 | if (focused->screen().screenNumber() == m_screen.screenNumber()) { | 147 | if (focused->screen().screenNumber() == m_screen.screenNumber()) { |
148 | have_focused = true; | 148 | have_focused = true; |
@@ -197,7 +197,7 @@ void FocusControl::stopCyclingFocus() { | |||
197 | m_focused_list.push_front(client); | 197 | m_focused_list.push_front(client); |
198 | client->fbwindow()->raise(); | 198 | client->fbwindow()->raise(); |
199 | } else { | 199 | } else { |
200 | Fluxbox::instance()->revertFocus(m_screen); | 200 | revertFocus(m_screen); |
201 | } | 201 | } |
202 | 202 | ||
203 | } | 203 | } |
@@ -307,7 +307,7 @@ void FocusControl::nextFocus(int opts) { | |||
307 | FluxboxWindow *focused_group = 0; | 307 | FluxboxWindow *focused_group = 0; |
308 | // start from the focused window | 308 | // start from the focused window |
309 | bool have_focused = false; | 309 | bool have_focused = false; |
310 | WinClient *focused = Fluxbox::instance()->getFocusedWindow(); | 310 | WinClient *focused = focusedWindow(); |
311 | if (focused != 0) { | 311 | if (focused != 0) { |
312 | if (focused->screen().screenNumber() == m_screen.screenNumber()) { | 312 | if (focused->screen().screenNumber() == m_screen.screenNumber()) { |
313 | have_focused = true; | 313 | have_focused = true; |
@@ -340,11 +340,11 @@ void FocusControl::nextFocus(int opts) { | |||
340 | 340 | ||
341 | void FocusControl::raiseFocus() { | 341 | void FocusControl::raiseFocus() { |
342 | bool have_focused = false; | 342 | bool have_focused = false; |
343 | Fluxbox &fb = *Fluxbox::instance(); | 343 | |
344 | // set have_focused if the currently focused window | 344 | // set have_focused if the currently focused window |
345 | // is on this screen | 345 | // is on this screen |
346 | if (fb.getFocusedWindow()) { | 346 | if (focusedWindow()) { |
347 | if (fb.getFocusedWindow()->screen().screenNumber() == m_screen.screenNumber()) { | 347 | if (focusedWindow()->screen().screenNumber() == m_screen.screenNumber()) { |
348 | have_focused = true; | 348 | have_focused = true; |
349 | } | 349 | } |
350 | } | 350 | } |
@@ -352,7 +352,7 @@ void FocusControl::raiseFocus() { | |||
352 | // if we have a focused window on this screen and | 352 | // if we have a focused window on this screen and |
353 | // number of windows is greater than one raise the focused window | 353 | // number of windows is greater than one raise the focused window |
354 | if (m_screen.currentWorkspace()->numberOfWindows() > 1 && have_focused) | 354 | if (m_screen.currentWorkspace()->numberOfWindows() > 1 && have_focused) |
355 | fb.getFocusedWindow()->raise(); | 355 | focusedWindow()->raise(); |
356 | 356 | ||
357 | } | 357 | } |
358 | 358 | ||
@@ -402,9 +402,12 @@ void FocusControl::dirFocus(FluxboxWindow &win, FocusDir dir) { | |||
402 | int edge=0, upper=0, lower=0, oedge=0, oupper=0, olower=0; | 402 | int edge=0, upper=0, lower=0, oedge=0, oupper=0, olower=0; |
403 | 403 | ||
404 | int otop = (*it)->y(), | 404 | int otop = (*it)->y(), |
405 | // 2 * border = border on each side | ||
405 | obottom = (*it)->y() + (*it)->height() + 2*borderW, | 406 | obottom = (*it)->y() + (*it)->height() + 2*borderW, |
406 | oleft = (*it)->x(), | 407 | oleft = (*it)->x(), |
408 | // 2 * border = border on each side | ||
407 | oright = (*it)->x() + (*it)->width() + 2*borderW; | 409 | oright = (*it)->x() + (*it)->width() + 2*borderW; |
410 | |||
408 | // check if they intersect | 411 | // check if they intersect |
409 | switch (dir) { | 412 | switch (dir) { |
410 | case FOCUSUP: | 413 | case FOCUSUP: |
@@ -441,7 +444,9 @@ void FocusControl::dirFocus(FluxboxWindow &win, FocusDir dir) { | |||
441 | break; | 444 | break; |
442 | } | 445 | } |
443 | 446 | ||
444 | if (oedge < edge) continue; // not in the right direction | 447 | if (oedge < edge) |
448 | continue; // not in the right direction | ||
449 | |||
445 | if (olower <= upper || oupper >= lower) { | 450 | if (olower <= upper || oupper >= lower) { |
446 | // outside our horz bounds, get a heavy weight penalty | 451 | // outside our horz bounds, get a heavy weight penalty |
447 | int myweight = 100000 + oedge - edge + abs(upper-oupper)+abs(lower-olower); | 452 | int myweight = 100000 + oedge - edge + abs(upper-oupper)+abs(lower-olower); |
@@ -475,6 +480,7 @@ void FocusControl::removeClient(WinClient &client) { | |||
475 | cyc = *m_cycling_window; | 480 | cyc = *m_cycling_window; |
476 | 481 | ||
477 | m_focused_list.remove(&client); | 482 | m_focused_list.remove(&client); |
483 | |||
478 | if (cyc == &client) { | 484 | if (cyc == &client) { |
479 | m_cycling_window = m_focused_list.end(); | 485 | m_cycling_window = m_focused_list.end(); |
480 | } | 486 | } |
@@ -548,9 +554,8 @@ void FocusControl::unfocusWindow(WinClient &client, | |||
548 | if (trans_parent->fbwindow() && // can't focus if no fbwin | 554 | if (trans_parent->fbwindow() && // can't focus if no fbwin |
549 | (!unfocus_frame || trans_parent->fbwindow() != fbwin) && // can't be this window | 555 | (!unfocus_frame || trans_parent->fbwindow() != fbwin) && // can't be this window |
550 | trans_parent->fbwindow()->isVisible() && | 556 | trans_parent->fbwindow()->isVisible() && |
551 | trans_parent->fbwindow()-> | 557 | trans_parent->fbwindow()->setCurrentClient(*trans_parent, |
552 | setCurrentClient(*trans_parent, | 558 | s_focused_window == &client)) { |
553 | Fluxbox::instance()->getFocusedWindow() == &client)) { | ||
554 | return; | 559 | return; |
555 | } | 560 | } |
556 | trans_parent = trans_parent->transientFor(); | 561 | trans_parent = trans_parent->transientFor(); |
@@ -565,19 +570,23 @@ void FocusControl::unfocusWindow(WinClient &client, | |||
565 | WinClient *last_focus = screen.focusControl().lastFocusedWindow(*fbwin, &client); | 570 | WinClient *last_focus = screen.focusControl().lastFocusedWindow(*fbwin, &client); |
566 | if (last_focus != 0 && | 571 | if (last_focus != 0 && |
567 | fbwin->setCurrentClient(*last_focus, | 572 | fbwin->setCurrentClient(*last_focus, |
568 | Fluxbox::instance()->getFocusedWindow() == &client)) { | 573 | s_focused_window == &client)) { |
569 | return; | 574 | return; |
570 | } | 575 | } |
571 | } | 576 | } |
572 | 577 | ||
573 | if (full_revert && Fluxbox::instance()->getFocusedWindow() == &client) | 578 | if (full_revert && s_focused_window == &client) |
574 | revertFocus(screen); | 579 | revertFocus(screen); |
575 | 580 | ||
576 | } | 581 | } |
577 | 582 | ||
578 | 583 | ||
579 | void FocusControl::setFocusedWindow(WinClient *client) { | 584 | void FocusControl::setFocusedWindow(WinClient *client) { |
580 | assert(false); | 585 | BScreen *screen = client ? &client->screen() : 0; |
586 | BScreen *old_screen = | ||
587 | FocusControl::focusedWindow() ? | ||
588 | &FocusControl::focusedWindow()->screen() : 0; | ||
589 | |||
581 | #ifdef DEBUG | 590 | #ifdef DEBUG |
582 | cerr<<__FILE__<<endl; | 591 | cerr<<__FILE__<<endl; |
583 | cerr<<"------------------"<<endl; | 592 | cerr<<"------------------"<<endl; |
@@ -587,38 +596,40 @@ void FocusControl::setFocusedWindow(WinClient *client) { | |||
587 | cerr<<"Current Focused window = "<<s_focused_window<<endl; | 596 | cerr<<"Current Focused window = "<<s_focused_window<<endl; |
588 | cerr<<"------------------"<<endl; | 597 | cerr<<"------------------"<<endl; |
589 | #endif // DEBUG | 598 | #endif // DEBUG |
590 | /* | 599 | |
591 | WinClient *old_client = 0; | 600 | WinClient *old_client = 0; |
592 | 601 | ||
593 | // Update the old focused client to non focus | 602 | // Update the old focused client to non focus |
594 | if (s_focused_window != 0) { | 603 | // check if s_focused_window is valid |
595 | // check if s_focused_window is valid | 604 | if (s_focused_window != 0 && |
596 | 605 | Fluxbox::instance()->validateClient(s_focused_window)) { | |
597 | if (Fluxbox::instance()->searchWindow(s_focused_window) != 0) { | ||
598 | s_focused_window = 0; | ||
599 | } else { | ||
600 | old_client = s_focused_window; | ||
601 | if (old_client->fbwindow()) { | ||
602 | FluxboxWindow *old_win = old_client->fbwindow(); | ||
603 | 606 | ||
604 | if (!client || client->fbwindow() != old_win) | 607 | old_client = s_focused_window; |
605 | old_win->setFocusFlag(false); | 608 | if (old_client->fbwindow()) { |
606 | } | 609 | FluxboxWindow *old_win = old_client->fbwindow(); |
610 | |||
611 | if (!client || client->fbwindow() != old_win) | ||
612 | old_win->setFocusFlag(false); | ||
607 | } | 613 | } |
614 | |||
615 | } else { | ||
616 | s_focused_window = 0; | ||
608 | } | 617 | } |
609 | 618 | ||
619 | |||
610 | if (client && client->fbwindow() && !client->fbwindow()->isIconic()) { | 620 | if (client && client->fbwindow() && !client->fbwindow()->isIconic()) { |
611 | // screen should be ok | 621 | // screen should be ok |
612 | FluxboxWindow *win = client->fbwindow(); | 622 | FluxboxWindow *win = client->fbwindow(); |
613 | s_focused_window = client; // update focused window | 623 | s_focused_window = client; // update focused window |
614 | win->setCurrentClient(*client, false); // don't setinputfocus | 624 | win->setCurrentClient(*client, |
625 | false); // don't set inputfocus | ||
615 | win->setFocusFlag(true); // set focus flag | 626 | win->setFocusFlag(true); // set focus flag |
616 | 627 | ||
617 | } else | 628 | } else |
618 | s_focused_window = 0; | 629 | s_focused_window = 0; |
619 | 630 | ||
620 | Fluxbox::instance()->updateFocusedWindow(s_focused_window, old_client); | 631 | // update AtomHandlers and/or other stuff... |
621 | */ | 632 | Fluxbox::instance()->updateFocusedWindow(screen, old_screen); |
622 | } | 633 | } |
623 | 634 | ||
624 | ////////////////////// FocusControl RESOURCES | 635 | ////////////////////// FocusControl RESOURCES |