Skip to content

Commit

Permalink
code for detecting retina displays
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Aug 15, 2012
1 parent 7522574 commit dc87fba
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cpp/desktop/CMakeLists.txt
Expand Up @@ -149,6 +149,12 @@ else()
endif()
endif(WIN32)

if(APPLE)
set(DESKTOP_SOURCE_FILES ${DESKTOP_SOURCE_FILES}
DesktopUtilsMac.mm
)
endif()

# include directories
include_directories(
include
Expand Down Expand Up @@ -210,7 +216,7 @@ if(WIN32)

elseif(APPLE)
find_library(APPLICATION_SERVICES_LIBRARY NAMES ApplicationServices)
set(LINK_FLAGS ${APPLICATION_SERVICES_LIBRARY})
find_library(COCOA_LIBRARY NAMES Cocoa)
endif(WIN32)


Expand Down Expand Up @@ -275,7 +281,8 @@ else()
target_link_libraries(RStudio
${QT_LIBRARIES}
rstudio-core
${LINK_FLAGS})
${APPLICATION_SERVICES_LIBRARY}
${COCOA_LIBRARY})

endif()

Expand Down
5 changes: 5 additions & 0 deletions src/cpp/desktop/DesktopGwtCallback.cpp
Expand Up @@ -377,6 +377,11 @@ bool GwtCallback::canChooseRVersion()
#endif
}

bool GwtCallback::isRetina()
{
return desktop::isRetina(pMainWindow_);
}

void GwtCallback::openMinimalWindow(QString name,
QString url,
int width,
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/desktop/DesktopGwtCallback.hpp
Expand Up @@ -73,6 +73,8 @@ public slots:
QString chooseRVersion();
bool canChooseRVersion();

bool isRetina();

void openMinimalWindow(QString name, QString url, int width, int height);
void activateSatelliteWindow(QString name);
void prepareForSatelliteWindow(QString name, int width, int height);
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/desktop/DesktopUtils.cpp
Expand Up @@ -26,6 +26,13 @@ using namespace core;

namespace desktop {

#ifndef Q_OS_MAC
bool isRetina(QMainWindow* pMainWindow)
{
return false;
}
#endif

void raiseAndActivateWindow(QWidget* pWindow)
{
// WId wid = pWindow->effectiveWinId(); -- gets X11 window id
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/desktop/DesktopUtils.hpp
Expand Up @@ -16,9 +16,12 @@

#include <QUrl>
#include <QMessageBox>
#include <QMainWindow>

namespace desktop {

bool isRetina(QMainWindow* pMainWindow);

void raiseAndActivateWindow(QWidget* pWindow);

QMessageBox::Icon safeMessageBoxIcon(QMessageBox::Icon icon);
Expand Down
36 changes: 36 additions & 0 deletions src/cpp/desktop/DesktopUtilsMac.mm
@@ -0,0 +1,36 @@
/*
* DesktopUtilsMac.mm
*
* Copyright (C) 2009-12 by RStudio, Inc.
*
* This program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/

#include "DesktopUtils.hpp"

#include <QWidget>

namespace desktop {

bool isRetina(QMainWindow* pMainWindow)
{
OSWindowRef macWindow = qt_mac_window_for(pMainWindow);
NSWindow* pWindow = (NSWindow*)macWindow;

if ([pWindow respondsToSelector:@selector(backingScaleFactor)])
{
double scaleFactor = [pWindow backingScaleFactor];
return scaleFactor == 2.0;
}
else
{
return false;
}
}

} // namespace desktop
22 changes: 22 additions & 0 deletions src/gwt/src/org/rstudio/core/client/BrowseCap.java
Expand Up @@ -111,6 +111,28 @@ public static boolean isChromeFrame()
return isUserAgent("chromeframe");
}

public static boolean isRetina()
{
if (Desktop.isDesktop())
return Desktop.getFrame().isRetina();
else
return getIsRetina();
}

private static native final boolean getIsRetina() /*-{
try
{
return ((('devicePixelRatio' in $wnd) &&
($wnd.devicePixelRatio == 2)) ||
(('matchMedia' in $wnd) &&
$wnd.matchMedia("(min-resolution:144dpi)").matches));
}
catch(ex)
{
return false;
}
}-*/;

private static native final boolean isUserAgent(String uaTest) /*-{
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf(uaTest) != -1)
Expand Down
Expand Up @@ -77,6 +77,8 @@ JsObject promptForText(String title,
String chooseRVersion();
boolean canChooseRVersion();

boolean isRetina();

void cleanClipboard();

public static final int PENDING_RESTART_NONE = 0;
Expand Down

0 comments on commit dc87fba

Please sign in to comment.