Skip to content

Commit

Permalink
[Windows] add is highcontrast (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
i10416 authored Oct 4, 2021
1 parent 91d298c commit c2557ee
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 7 deletions.
2 changes: 1 addition & 1 deletion linux/java/WindowX11.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ public Window restore() {
@ApiStatus.Internal public native void _nMinimize();
@ApiStatus.Internal public native void _nRestore();
@ApiStatus.Internal public native Screen _nSetTitle(byte[] title);
}
}
2 changes: 1 addition & 1 deletion macos/java/WindowMac.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ public void close() {
@ApiStatus.Internal public native void _nMaximize();
@ApiStatus.Internal public native void _nRestore();
@ApiStatus.Internal public native void _nClose();
}
}
8 changes: 8 additions & 0 deletions shared/cc/Theme.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace jwm {
class Theme {
public:
bool isHighContrast();
};
} // namespace jwm
24 changes: 24 additions & 0 deletions shared/java/Theme.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.humbleui.jwm;

import org.jetbrains.annotations.*;
import io.github.humbleui.jwm.impl.*;

public class Theme {

/**
* <p>>Check whether OS currently uses high contrast mode.</p>
*
* @return bool;
*/
public static boolean isHighContrast() {
assert _onUIThread();
return _nIsHighContrast();
}


@ApiStatus.Internal public static boolean _onUIThread() {
return App._onUIThread();
}

@ApiStatus.Internal public static native boolean _nIsHighContrast();
}
2 changes: 1 addition & 1 deletion shared/java/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,4 @@ public void close() {
@ApiStatus.Internal public native void _nSetEventListener(Consumer<Event> eventListener);
@ApiStatus.Internal public native void _nSetTextInputClient(TextInputClient client);
@ApiStatus.Internal public abstract void _nSetMouseCursor(int cursorIdx);
}
}
2 changes: 2 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ set(JWM_WINDOWS_SOURCES_CXX
cc/LayerRaster.hh
cc/LayerWGL.cc
cc/LayerWGL.hh
cc/ThemeWin32.cc
cc/ThemeWin32.hh
cc/PlatformWin32.hh
cc/ScreenWin32.cc
cc/ScreenWin32.hh
Expand Down
5 changes: 4 additions & 1 deletion windows/cc/AppWin32.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <D3D12/DX12Common.hh>
#include <ContextWGL.hh>
#include <ScreenWin32.hh>
#include <ThemeWin32.hh>
#include <jni.h>

namespace jwm {
Expand All @@ -25,11 +26,13 @@ namespace jwm {
ContextWGL& getContextWGL() { return _wglContext; }
DX12Common& getDx12Common() { return _dx12common; }
JNIEnv* getJniEnv() const { return _jniEnv; }
ThemeWin32& getTheme() { return _theme; }

private:
std::vector<ScreenWin32> _screens;
WindowManagerWin32 _windowManager;
ClipboardWin32 _clipboard;
ThemeWin32 _theme;
ContextWGL _wglContext;
DX12Common _dx12common;
JNIEnv* _jniEnv;
Expand All @@ -40,4 +43,4 @@ namespace jwm {
static AppWin32& getInstance() { return gInstance; }
static AppWin32 gInstance;
};
}
}
36 changes: 36 additions & 0 deletions windows/cc/ThemeWin32.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "ThemeWin32.hh"

#include <Uxtheme.h>
#include <impl/Library.hh>
#include <AppWin32.hh>
#include <VersionHelpers.h>
#include <WinUser.h>
#include <stdio.h>
#include <Log.hh>
#include <PlatformWin32.hh>
#include "Theme.hh"


bool jwm::ThemeWin32::isHighContrast() {
HIGHCONTRASTA highContrast;
highContrast.cbSize = sizeof(HIGHCONTRASTA);
highContrast.dwFlags = 0;
highContrast.lpszDefaultScheme = nullptr;
bool isOk = SystemParametersInfoA(SPI_GETHIGHCONTRAST, 0, &highContrast, 0);
if (!isOk) {
JWM_VERBOSE("Failed to get SystemParametersInfoA for high contrast");
return false;
}
JWM_VERBOSE("is HighContrast? '"
<< ((HCF_HIGHCONTRASTON & highContrast.dwFlags) == 1) << "'");
return (HCF_HIGHCONTRASTON & highContrast.dwFlags) == 1;
}

// JNI

extern "C" JNIEXPORT bool JNICALL Java_io_github_humbleui_jwm_Theme__1nIsHighContrast
(JNIEnv* env, jclass jclass) {
jwm::AppWin32& app = jwm::AppWin32::getInstance();
jwm::ThemeWin32& theme = app.getTheme();
return theme.isHighContrast();
}
17 changes: 17 additions & 0 deletions windows/cc/ThemeWin32.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <PlatformWin32.hh>

#include "Theme.hh"
#include "ThemeWin32.hh"

namespace jwm {

class ThemeWin32 final : public Theme {
public:
ThemeWin32() = default;
~ThemeWin32() = default;

bool isHighContrast();

};
} // namespace jwm
3 changes: 2 additions & 1 deletion windows/cc/WindowWin32.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace jwm {
void setIcon(const std::wstring& iconPath);
void setOpacity(float opacity);
float getOpacity();
bool isHighContrast();
void setMouseCursor(MouseCursor cursor);
void setVisible(bool value);
void maximize();
Expand Down Expand Up @@ -116,4 +117,4 @@ namespace jwm {
int _nextCallbackID = 0;
wchar_t _highSurrogate = 0;
};
}
}
5 changes: 3 additions & 2 deletions windows/java/WindowWin32.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ public Window setOpacity(float opacity) {
_nSetOpacity(opacity);
return this;
}

@Override
public float getOpacity() {
assert _onUIThread();
return _nGetOpacity();
}


@Override
public Screen getScreen() {
assert _onUIThread();
Expand Down Expand Up @@ -159,4 +160,4 @@ public Window winSetParent(long hwnd) {
@ApiStatus.Internal public native void _nRestore();
@ApiStatus.Internal public native void _nClose();
@ApiStatus.Internal public native void _nWinSetParent(long hwnd);
}
}

0 comments on commit c2557ee

Please sign in to comment.