Skip to content

Commit c2557ee

Browse files
authored
[Windows] add is highcontrast (#153)
1 parent 91d298c commit c2557ee

File tree

11 files changed

+99
-7
lines changed

11 files changed

+99
-7
lines changed

linux/java/WindowX11.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ public Window restore() {
145145
@ApiStatus.Internal public native void _nMinimize();
146146
@ApiStatus.Internal public native void _nRestore();
147147
@ApiStatus.Internal public native Screen _nSetTitle(byte[] title);
148-
}
148+
}

macos/java/WindowMac.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,4 @@ public void close() {
146146
@ApiStatus.Internal public native void _nMaximize();
147147
@ApiStatus.Internal public native void _nRestore();
148148
@ApiStatus.Internal public native void _nClose();
149-
}
149+
}

shared/cc/Theme.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
namespace jwm {
4+
class Theme {
5+
public:
6+
bool isHighContrast();
7+
};
8+
} // namespace jwm

shared/java/Theme.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.humbleui.jwm;
2+
3+
import org.jetbrains.annotations.*;
4+
import io.github.humbleui.jwm.impl.*;
5+
6+
public class Theme {
7+
8+
/**
9+
* <p>>Check whether OS currently uses high contrast mode.</p>
10+
*
11+
* @return bool;
12+
*/
13+
public static boolean isHighContrast() {
14+
assert _onUIThread();
15+
return _nIsHighContrast();
16+
}
17+
18+
19+
@ApiStatus.Internal public static boolean _onUIThread() {
20+
return App._onUIThread();
21+
}
22+
23+
@ApiStatus.Internal public static native boolean _nIsHighContrast();
24+
}

shared/java/Window.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,4 @@ public void close() {
298298
@ApiStatus.Internal public native void _nSetEventListener(Consumer<Event> eventListener);
299299
@ApiStatus.Internal public native void _nSetTextInputClient(TextInputClient client);
300300
@ApiStatus.Internal public abstract void _nSetMouseCursor(int cursorIdx);
301-
}
301+
}

windows/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ set(JWM_WINDOWS_SOURCES_CXX
4545
cc/LayerRaster.hh
4646
cc/LayerWGL.cc
4747
cc/LayerWGL.hh
48+
cc/ThemeWin32.cc
49+
cc/ThemeWin32.hh
4850
cc/PlatformWin32.hh
4951
cc/ScreenWin32.cc
5052
cc/ScreenWin32.hh

windows/cc/AppWin32.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <D3D12/DX12Common.hh>
66
#include <ContextWGL.hh>
77
#include <ScreenWin32.hh>
8+
#include <ThemeWin32.hh>
89
#include <jni.h>
910

1011
namespace jwm {
@@ -25,11 +26,13 @@ namespace jwm {
2526
ContextWGL& getContextWGL() { return _wglContext; }
2627
DX12Common& getDx12Common() { return _dx12common; }
2728
JNIEnv* getJniEnv() const { return _jniEnv; }
29+
ThemeWin32& getTheme() { return _theme; }
2830

2931
private:
3032
std::vector<ScreenWin32> _screens;
3133
WindowManagerWin32 _windowManager;
3234
ClipboardWin32 _clipboard;
35+
ThemeWin32 _theme;
3336
ContextWGL _wglContext;
3437
DX12Common _dx12common;
3538
JNIEnv* _jniEnv;
@@ -40,4 +43,4 @@ namespace jwm {
4043
static AppWin32& getInstance() { return gInstance; }
4144
static AppWin32 gInstance;
4245
};
43-
}
46+
}

windows/cc/ThemeWin32.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "ThemeWin32.hh"
2+
3+
#include <Uxtheme.h>
4+
#include <impl/Library.hh>
5+
#include <AppWin32.hh>
6+
#include <VersionHelpers.h>
7+
#include <WinUser.h>
8+
#include <stdio.h>
9+
#include <Log.hh>
10+
#include <PlatformWin32.hh>
11+
#include "Theme.hh"
12+
13+
14+
bool jwm::ThemeWin32::isHighContrast() {
15+
HIGHCONTRASTA highContrast;
16+
highContrast.cbSize = sizeof(HIGHCONTRASTA);
17+
highContrast.dwFlags = 0;
18+
highContrast.lpszDefaultScheme = nullptr;
19+
bool isOk = SystemParametersInfoA(SPI_GETHIGHCONTRAST, 0, &highContrast, 0);
20+
if (!isOk) {
21+
JWM_VERBOSE("Failed to get SystemParametersInfoA for high contrast");
22+
return false;
23+
}
24+
JWM_VERBOSE("is HighContrast? '"
25+
<< ((HCF_HIGHCONTRASTON & highContrast.dwFlags) == 1) << "'");
26+
return (HCF_HIGHCONTRASTON & highContrast.dwFlags) == 1;
27+
}
28+
29+
// JNI
30+
31+
extern "C" JNIEXPORT bool JNICALL Java_io_github_humbleui_jwm_Theme__1nIsHighContrast
32+
(JNIEnv* env, jclass jclass) {
33+
jwm::AppWin32& app = jwm::AppWin32::getInstance();
34+
jwm::ThemeWin32& theme = app.getTheme();
35+
return theme.isHighContrast();
36+
}

windows/cc/ThemeWin32.hh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include <PlatformWin32.hh>
3+
4+
#include "Theme.hh"
5+
#include "ThemeWin32.hh"
6+
7+
namespace jwm {
8+
9+
class ThemeWin32 final : public Theme {
10+
public:
11+
ThemeWin32() = default;
12+
~ThemeWin32() = default;
13+
14+
bool isHighContrast();
15+
16+
};
17+
} // namespace jwm

windows/cc/WindowWin32.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace jwm {
5454
void setIcon(const std::wstring& iconPath);
5555
void setOpacity(float opacity);
5656
float getOpacity();
57+
bool isHighContrast();
5758
void setMouseCursor(MouseCursor cursor);
5859
void setVisible(bool value);
5960
void maximize();
@@ -116,4 +117,4 @@ namespace jwm {
116117
int _nextCallbackID = 0;
117118
wchar_t _highSurrogate = 0;
118119
};
119-
}
120+
}

0 commit comments

Comments
 (0)