Skip to content

Commit

Permalink
Utility: Implement hasDarkSystray_private on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Oct 29, 2020
1 parent 07f1e50 commit f8e7669
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/common/utility_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <QLibrary>

#include "common/winrthelper/winrthelper.h"

extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

static const char systemRunPathC[] = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
Expand Down Expand Up @@ -102,7 +104,7 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName,

static inline bool hasDarkSystray_private()
{
return true;
return WinRtHelper::hasDarkSystray();
}

QVariant Utility::registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName)
Expand Down
55 changes: 55 additions & 0 deletions src/common/winrthelper/winrthelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) by Hannah von Reth <hannah.vonreth@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "winrthelper.h"

#include <wrl.h>
#include <Windows.UI.ViewManagement.h>

#include <algorithm>

namespace {

ABI::Windows::UI::Color GetThemeColor(ABI::Windows::UI::ViewManagement::UIColorType type, bool *ok)
{
*ok = false;
ABI::Windows::UI::Color color;
Microsoft::WRL::ComPtr<ABI::Windows::UI::ViewManagement::IUISettings3> settings;
if (SUCCEEDED(Windows::Foundation::ActivateInstance(Microsoft::WRL::Wrappers::HStringReference(
RuntimeClass_Windows_UI_ViewManagement_UISettings).Get(), &settings)) )
{
settings->GetColorValue(type, &color);
*ok = true;
}
return color;
}
}

namespace WinRtHelper {
bool hasDarkSystray()
{
bool ok;
const auto color = GetThemeColor(ABI::Windows::UI::ViewManagement::UIColorType::UIColorType_Background, &ok);
if (ok)
{
const auto lightness = 0.5 * (std::max(color.R, std::max(color.G, color.B)) + std::min(color.R, std::min(color.G, color.B))) / 255.0;
return lightness < 0.5;
}
return true;
}
}
28 changes: 28 additions & 0 deletions src/common/winrthelper/winrthelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) by Hannah von Reth <hannah.vonreth@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef WINRTHELPER_H
#define WINRTHELPER_H


namespace WinRtHelper
{
bool hasDarkSystray();
};

#endif // WINRTHELPER_H
9 changes: 9 additions & 0 deletions src/csync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ configure_file(csync_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/csync_version.h)

add_library("${csync_NAME}" SHARED ${common_SOURCES} ${csync_SRCS})

if (WIN32)
add_library(ocwinrt STATIC ../common/winrthelper/winrthelper.cpp)
set_property(TARGET ocwinrt PROPERTY CXX_STANDARD 17)
target_link_libraries(ocwinrt PUBLIC runtimeobject)

target_link_libraries("${csync_NAME}" ocwinrt)
endif()


target_include_directories(
"${csync_NAME}"
PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/std
Expand Down

0 comments on commit f8e7669

Please sign in to comment.