Skip to content

Commit

Permalink
UI|Task Bar: Various tweaks to focus/mouse trap behavior
Browse files Browse the repository at this point in the history
When the sidebar is open, the task bar will behave a bit differently.
While the "taskbar" command will still always open the task bar and
set focus to the command line, Shift-Esc will now just open the task
bar, as the assumption is that the user is interested in accessing
the sidebar editor rather than the command line.

Clicking on nothing or a panel background will now clear the input
focus.
  • Loading branch information
skyjake committed Sep 10, 2013
1 parent c9408d5 commit d750839
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 26 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/clientwindow.h
Expand Up @@ -92,6 +92,8 @@ class ClientWindow : public de::PersistentCanvasWindow,

void unsetSidebar(SidebarLocation location) { setSidebar(location, 0); }

bool hasSidebar(SidebarLocation location = RightEdge) const;

/**
* Sets the operating mode of the window. In Busy mode, the normal
* widgets of the window will be replaced with a single BusyWidget.
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/framework/guirootwidget.h
Expand Up @@ -67,6 +67,8 @@ class GuiRootWidget : public de::RootWidget

void routeMouse(de::Widget *routeTo);

bool processEvent(de::Event const &event);

// Events.
void update();
void draw();
Expand Down
6 changes: 1 addition & 5 deletions doomsday/client/src/con_main.cpp
Expand Up @@ -2739,15 +2739,11 @@ D_CMD(TaskBar)
DENG2_UNUSED3(src, argc, argv);

ClientWindow &win = ClientWindow::main();
if(!win.taskBar().isOpen())
if(!win.taskBar().isOpen() || !win.console().commandLine().hasFocus())
{
win.taskBar().open();
win.console().focusOnCommandLine();
}
else if(!win.console().commandLine().hasFocus())
{
win.console().focusOnCommandLine();
}
else
{
win.taskBar().close();
Expand Down
7 changes: 7 additions & 0 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -670,3 +670,10 @@ void ClientWindow::setSidebar(SidebarLocation location, GuiWidget *sidebar)

d->installSidebar(location, sidebar);
}

bool ClientWindow::hasSidebar(SidebarLocation location) const
{
DENG2_ASSERT(location == RightEdge);

return d->sidebar != 0;
}
5 changes: 5 additions & 0 deletions doomsday/client/src/ui/dialogs/renderersettingsdialog.cpp
Expand Up @@ -267,6 +267,11 @@ void RendererSettingsDialog::showAppearanceMenu()
// The last profile cannot be deleted.
org.itemWidget(6)->disable();
}
if(root().window().hasSidebar())
{
// The sidebar is already open, so don't allow editing.
org.itemWidget(0)->disable();
}

popup->setDeleteAfterDismissed(true);
popup->setAnchorAndOpeningDirection(d->appearButton->rule(), ui::Down);
Expand Down
14 changes: 14 additions & 0 deletions doomsday/client/src/ui/framework/guirootwidget.cpp
Expand Up @@ -260,6 +260,20 @@ void GuiRootWidget::routeMouse(Widget *routeTo)
<< Event::MouseWheel, routeTo);
}

bool GuiRootWidget::processEvent(Event const &event)
{
if(!RootWidget::processEvent(event))
{
if(event.type() == Event::MouseButton)
{
// Button events that no one handles will relinquish input focus.
setFocus(0);
}
return false;
}
return true;
}

void GuiRootWidget::update()
{
if(window().canvas().isGLReady())
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -467,7 +467,7 @@ bool DialogWidget::handleEvent(Event const &event)
if(event.isKeyDown() ||
(event.type() == Event::MouseButton &&
event.as<MouseEvent>().state() == MouseEvent::Pressed &&
!hitTest(event.as<MouseEvent>().pos())))
!hitTest(event)))
{
d->startBorderFlash();
}
Expand All @@ -476,7 +476,7 @@ bool DialogWidget::handleEvent(Event const &event)
else
{
if((event.type() == Event::MouseButton || event.type() == Event::MousePosition) &&
hitTest(event.as<MouseEvent>().pos()))
hitTest(event))
{
// Non-modal dialogs eat mouse clicks/position inside the dialog.
return true;
Expand Down
25 changes: 22 additions & 3 deletions doomsday/client/src/ui/widgets/legacywidget.cpp
Expand Up @@ -270,9 +270,28 @@ bool LegacyWidget::handleEvent(Event const &event)

if(event.type() == Event::MouseButton && !root().window().canvas().isMouseTrapped())
{
// 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(!root().window().hasSidebar())
{
// 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 the sidebar is open, we must explicitly click on the LegacyWidget to
// cause input to be trapped.
switch(handleMouseClick(event))
{
case MouseClickFinished:
// Click completed on the widget, trap the mouse.
root().window().canvas().trapMouse();
root().window().taskBar().close();
root().setFocus(0); // Allow input to reach here.
break;

default:
// Just ignore the event.
return true;
}
}

if(event.type() == Event::KeyPress ||
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/ui/widgets/panelwidget.cpp
Expand Up @@ -263,6 +263,7 @@ bool PanelWidget::handleEvent(Event const &event)
// Eat buttons that land on the panel.
if(hitTest(mouse.pos()))
{
root().setFocus(0);
return true;
}
}
Expand Down
45 changes: 29 additions & 16 deletions doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -383,7 +383,8 @@ bool TaskBarWidget::handleEvent(Event const &event)
{
Canvas &canvas = root().window().canvas();

if(!canvas.isMouseTrapped() && event.type() == Event::MouseButton)
if(!canvas.isMouseTrapped() && event.type() == Event::MouseButton &&
!root().window().hasSidebar())
{
// Clicking outside the taskbar will trap the mouse automatically.
MouseEvent const &mouse = event.as<MouseEvent>();
Expand All @@ -408,6 +409,15 @@ bool TaskBarWidget::handleEvent(Event const &event)
}
}

if(event.type() == Event::MouseButton)
{
// Eat all button events occurring inside the task bar area.
if(hitTest(event))
{
return true;
}
}

if(event.type() == Event::KeyPress)
{
KeyEvent const &key = event.as<KeyEvent>();
Expand Down Expand Up @@ -435,8 +445,11 @@ bool TaskBarWidget::handleEvent(Event const &event)
if(key.modifiers().testFlag(KeyEvent::Shift) ||
!App_GameLoaded())
{
// Automatically focus the command line.
root().setFocus(&d->console->commandLine());
if(!root().window().hasSidebar())
{
// Automatically focus the command line, unless an editor is open.
root().setFocus(&d->console->commandLine());
}

open();
return true;
Expand All @@ -462,21 +475,21 @@ void TaskBarWidget::open()
setOpacity(1, OPEN_CLOSE_SPAN);

emit opened();
}

// Untrap the mouse if it is trapped.
if(hasRoot())
// Untrap the mouse if it is trapped.
if(hasRoot())
{
Canvas &canvas = root().window().canvas();
d->mouseWasTrappedWhenOpening = canvas.isMouseTrapped();
if(canvas.isMouseTrapped())
{
Canvas &canvas = root().window().canvas();
d->mouseWasTrappedWhenOpening = canvas.isMouseTrapped();
if(canvas.isMouseTrapped())
{
canvas.trapMouse(false);
}
canvas.trapMouse(false);
}

if(!App_GameLoaded())
{
root().setFocus(&d->console->commandLine());
}
if(!App_GameLoaded())
{
root().setFocus(&d->console->commandLine());
}
}
}
Expand Down Expand Up @@ -515,7 +528,7 @@ void TaskBarWidget::close()
emit closed();

// Retrap the mouse if it was trapped when opening.
if(hasRoot() && App_GameLoaded())
if(hasRoot() && App_GameLoaded() && !root().window().hasSidebar())
{
Canvas &canvas = root().window().canvas();
if(d->mouseWasTrappedWhenOpening)
Expand Down

0 comments on commit d750839

Please sign in to comment.