Skip to content

Commit

Permalink
Client|Task Bar: Dismiss when clicking outside the task bar
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 1, 2013
1 parent d46161e commit 8222e4b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
23 changes: 4 additions & 19 deletions doomsday/client/src/ui/widgets/legacywidget.cpp
Expand Up @@ -245,26 +245,11 @@ bool LegacyWidget::handleEvent(Event const &event)
* submit as Latin1.
*/

// Clicking on the game view will trap the mouse automatically.
Canvas &canvas = root().window().canvas();
if(!canvas.isMouseTrapped() && event.type() == Event::MouseButton &&
App_GameLoaded())
if(event.type() == Event::MouseButton && !root().window().canvas().isMouseTrapped())
{
MouseEvent const &mouse = event.as<MouseEvent>();
if(mouse.state() == MouseEvent::Released && hitTest(mouse.pos()))
{
if(root().focus())
{
// First click will remove UI focus, allowing LegacyWidget
// to receive events.
root().setFocus(0);
return true;
}

canvas.trapMouse();
root().window().taskBar().close();
return true;
}
// If the mouse is not trapped, we will just eat button clicks which
// will prevent them from reaching the legacy input system.
return true;
}

if(event.type() == Event::KeyPress ||
Expand Down
27 changes: 27 additions & 0 deletions doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -302,6 +302,33 @@ void TaskBarWidget::drawContent()

bool TaskBarWidget::handleEvent(Event const &event)
{
Canvas &canvas = root().window().canvas();

if(!canvas.isMouseTrapped() && event.type() == Event::MouseButton)
{
// Clicking outside the taskbar will trap the mouse automatically.
MouseEvent const &mouse = event.as<MouseEvent>();
if(mouse.state() == MouseEvent::Released && !hitTest(mouse.pos()))
{
if(root().focus())
{
// First click will remove UI focus, allowing LegacyWidget
// to receive events.
root().setFocus(0);
return true;
}

if(App_GameLoaded())
{
// Allow game to use the mouse.
canvas.trapMouse();
}

root().window().taskBar().close();
return true;
}
}

if(event.type() == Event::KeyPress)
{
KeyEvent const &key = event.as<KeyEvent>();
Expand Down

0 comments on commit 8222e4b

Please sign in to comment.