Implement Caps Lock warning
This commit is contained in:
@@ -31,6 +31,7 @@ class OSUtilsBase : public QObject
|
||||
|
||||
public:
|
||||
virtual bool isDarkMode() = 0;
|
||||
virtual bool isCapslockEnabled() = 0;
|
||||
|
||||
protected:
|
||||
explicit OSUtilsBase(QObject* parent = nullptr);
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
#include "MacUtils.h"
|
||||
#include <QApplication>
|
||||
|
||||
#include <CoreGraphics/CGEventSource.h>
|
||||
|
||||
|
||||
QPointer<MacUtils> MacUtils::m_instance = nullptr;
|
||||
|
||||
MacUtils::MacUtils(QObject* parent)
|
||||
@@ -85,3 +88,8 @@ bool MacUtils::enableScreenRecording()
|
||||
{
|
||||
return m_appkit->enableScreenRecording();
|
||||
}
|
||||
|
||||
bool MacUtils::isCapslockEnabled()
|
||||
{
|
||||
return (CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState) & kCGEventFlagMaskAlphaShift) != 0;
|
||||
}
|
||||
|
||||
@@ -33,13 +33,15 @@ class MacUtils : public OSUtilsBase
|
||||
public:
|
||||
static MacUtils* instance();
|
||||
|
||||
bool isDarkMode() override;
|
||||
bool isCapslockEnabled() override;
|
||||
|
||||
WId activeWindow();
|
||||
bool raiseWindow(WId pid);
|
||||
bool raiseLastActiveWindow();
|
||||
bool raiseOwnWindow();
|
||||
bool hideOwnWindow();
|
||||
bool isHidden();
|
||||
bool isDarkMode() override;
|
||||
bool enableAccessibility();
|
||||
bool enableScreenRecording();
|
||||
|
||||
|
||||
@@ -18,9 +18,17 @@
|
||||
#include "NixUtils.h"
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
#include <QGuiApplication>
|
||||
#include <QPalette>
|
||||
#include <QStyle>
|
||||
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
// namespace required to avoid name clashes with declarations in XKBlib.h
|
||||
namespace X11
|
||||
{
|
||||
#include <X11/XKBlib.h>
|
||||
}
|
||||
|
||||
QPointer<NixUtils> NixUtils::m_instance = nullptr;
|
||||
|
||||
NixUtils* NixUtils::instance()
|
||||
@@ -48,3 +56,24 @@ bool NixUtils::isDarkMode()
|
||||
}
|
||||
return qApp->style()->standardPalette().color(QPalette::Window).toHsl().lightness() < 110;
|
||||
}
|
||||
|
||||
bool NixUtils::isCapslockEnabled()
|
||||
{
|
||||
QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface();
|
||||
auto* display = native->nativeResourceForWindow("display", nullptr);
|
||||
if (!display) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QString platform = QGuiApplication::platformName();
|
||||
if (platform == "xcb") {
|
||||
unsigned state = 0;
|
||||
if (X11::XkbGetIndicatorState(reinterpret_cast<X11::Display*>(display), XkbUseCoreKbd, &state) == Success) {
|
||||
return ((state & 1u) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Wayland
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
static NixUtils* instance();
|
||||
|
||||
bool isDarkMode() override;
|
||||
bool isCapslockEnabled() override;
|
||||
|
||||
private:
|
||||
explicit NixUtils(QObject* parent = nullptr);
|
||||
|
||||
@@ -83,3 +83,8 @@ bool WinUtils::isDarkMode()
|
||||
QSettings::NativeFormat);
|
||||
return settings.value("AppsUseLightTheme", 1).toInt() == 0;
|
||||
}
|
||||
|
||||
bool WinUtils::isCapslockEnabled()
|
||||
{
|
||||
return GetKeyState(VK_CAPITAL) == 1;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
static void registerEventFilters();
|
||||
|
||||
bool isDarkMode() override;
|
||||
bool isCapslockEnabled() override;
|
||||
|
||||
protected:
|
||||
explicit WinUtils(QObject* parent = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user