Skip to content

Commit

Permalink
OS X|Fixed: Showing and hiding the mouse cursor
Browse files Browse the repository at this point in the history
On OS X 10.11, the mouse cursor is not fully hidden via the Qt
setCursor methods. Use the native API to control mouse cursor
visibility.
  • Loading branch information
skyjake committed Jun 14, 2015
1 parent d2161a8 commit 0c871f8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
6 changes: 4 additions & 2 deletions doomsday/apps/client/CMakeLists.txt
Expand Up @@ -28,8 +28,10 @@ file (GLOB_RECURSE SOURCES src/*.cpp src/*.c)

if (APPLE)
include_directories (include/macx)
list (APPEND HEADERS include/macx/MusicPlayer.h)
list (APPEND SOURCES src/macx/MusicPlayer.mm)
file (GLOB MACX_HEADERS include/macx/*.h)
file (GLOB MACX_SOURCES src/macx/*.mm)
list (APPEND HEADERS ${MACX_HEADERS})
list (APPEND SOURCES ${MACX_SOURCES})
elseif (WIN32)
include_directories (include/windows)
list (APPEND SOURCES res/windows/doomsday.rc)
Expand Down
30 changes: 30 additions & 0 deletions doomsday/apps/client/include/macx/cursor_macx.h
@@ -0,0 +1,30 @@
/** @file cursor_macx.h Native OS X mouse cursor functions.
* @ingroup ui
*
* @authors Copyright © 2015 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_MACX_CURSOR_H
#define CLIENT_MACX_CURSOR_H

/**
* Show or hide the mouse cursor.
*
* @param show @c true to show, @c false to hide.
*/
void Cursor_Show(bool show);

#endif // CLIENT_MACX_CURSOR_H
32 changes: 32 additions & 0 deletions doomsday/apps/client/src/macx/cursor_macx.mm
@@ -0,0 +1,32 @@
/** @file cursor_macx.mm Native OS X mouse cursor functions.
* @ingroup ui
*
* @authors Copyright © 2015 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include <AppKit/AppKit.h>

void Cursor_Show(bool show)
{
if(show)
{
[NSCursor unhide];
}
else
{
[NSCursor hide];
}
}
14 changes: 14 additions & 0 deletions doomsday/apps/client/src/ui/mouse_qt.cpp
Expand Up @@ -34,6 +34,10 @@
#include <QCursor>
#include <de/Canvas>

#ifdef MACOSX
# include "cursor_macx.h"
#endif

typedef struct clicker_s {
int down; // Count for down events.
int up; // Count for up events.
Expand Down Expand Up @@ -120,22 +124,32 @@ static void Mouse_Qt_GetState(mousestate_t *state)

static void Mouse_Qt_ShowCursor(bool yes)
{
#ifndef MACOSX
de::Canvas &canvas = ClientWindowSystem::main().canvas();
#endif

LOG_INPUT_VERBOSE("%s cursor (presently visible? %b)")
<< (yes? "showing" : "hiding") << !cursorHidden;

if(!yes && !cursorHidden)
{
cursorHidden = true;
#ifdef MACOSX
Cursor_Show(false);
#else
canvas.setCursor(QCursor(Qt::BlankCursor));
qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
#endif
}
else if(yes && cursorHidden)
{
cursorHidden = false;
#ifdef MACOSX
Cursor_Show(true);
#else
qApp->restoreOverrideCursor();
canvas.setCursor(QCursor(Qt::ArrowCursor)); // Default cursor.
#endif
}
}

Expand Down

0 comments on commit 0c871f8

Please sign in to comment.