Skip to content

Commit 6b583ae

Browse files
committed
Add Windows implementation of setTitlebarVisible
JWM demo works with Ctrl+T "Toggle Resize" Update README.md with JWM_DEBUG env instructions & $JAVA_HOME/bin
1 parent a04867c commit 6b583ae

File tree

6 files changed

+80
-3
lines changed

6 files changed

+80
-3
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ Alpha. Expect API breakages.
133133
| setMinimumSize ||||
134134
| setMaximumSize ||||
135135
| setResizable ||||
136+
| bringToFront ||||
137+
| isFront ||||
136138

137139
### Events
138140

@@ -226,6 +228,35 @@ Run examples without building (use version from the table above):
226228
./script/run.py --jwm-version <version>
227229
```
228230

231+
### Local JAR
232+
233+
Generate & install a local .jar file:
234+
235+
```
236+
./script/install.py
237+
```
238+
239+
This outputs `target/jwm-0.0.0-SNAPSHOT.jar` for use in testing (e.g. `io.github.humbleui/jwm {:local/root "..."}` if using deps.edn)
240+
241+
### MacOS
242+
243+
Before running the build, ensure you've installed:
244+
* XCode Developer Tools (`xcode-select --install`)
245+
* Ninja (`brew install ninja`)
246+
* Python 3 (`brew install python`)
247+
248+
### Debugging
249+
250+
Set `JWM_VERBOSE` in process env to see extra log output when running locally.
251+
252+
``` bash
253+
# Mac / Linux
254+
export JWM_VERBOSE=true
255+
256+
# Windows
257+
set JWM_VERBOSE=true
258+
```
259+
229260
# Contributing
230261

231262
PRs & issue reports are welcome!

docs/windows/build.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ or from chocolatey
2525
```sh
2626
choco install -y python
2727
```
28+
29+
You'll need to ensure your Java installation's `$JAVA_HOME/bin` is on your system PATH. This exposes necessary interop codefiles like `jni.h` to the compiler. Your JAVA bin path will look similar to "`C:\Program Files\Java\jdk-17.0.2\bin`"
30+
2831
## Install Ninja
2932

3033
Download executable from https://github.com/ninja-build/ninja/releases and export path.

examples/dashboard/java/PanelScreens.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public PanelScreens(Window window) {
2020
titleStyles = new Options("Default", "Hidden", "Transparent", "Unified", "Unified Compact", "Unified Transparent", "Unified Compact Transparent");
2121
} else if (Platform.X11 == Platform.CURRENT) {
2222
titleStyles = new Options("Default", "Hidden");
23+
} else if (Platform.WINDOWS == Platform.CURRENT) {
24+
titleStyles = new Options("Default", "Hidden");
2325
}
2426
}
2527

@@ -66,6 +68,14 @@ public void setTitleStyle(String style) {
6668
case "Hidden" ->
6769
w.setTitlebarVisible(false);
6870
}
71+
} else if (Platform.WINDOWS == Platform.CURRENT) {
72+
WindowWin32 w = (WindowWin32) window;
73+
switch (style) {
74+
case "Default" ->
75+
w.setTitlebarVisible(true);
76+
case "Hidden" ->
77+
w.setTitlebarVisible(false);
78+
}
6979
}
7080
}
7181

windows/cc/WindowWin32.cc

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,31 @@ void jwm::WindowWin32::setTitle(const std::wstring& title) {
7070
SetWindowTextW(_hWnd, title.c_str());
7171
}
7272

73+
void jwm::WindowWin32::setTitlebarVisible(bool isVisible) {
74+
JWM_VERBOSE("Set titlebar visible=" << isVisible << " for window 0x" << this);
75+
if (isVisible == true) {
76+
LONG_PTR lStyle = GetWindowLongPtr(_hWnd, GWL_STYLE);
77+
lStyle |= (WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
78+
SetWindowLongPtr(_hWnd, GWL_STYLE, lStyle);
79+
80+
IRect rect = getWindowRect();
81+
int windowWidth = rect.getWidth();
82+
int windowHeight = rect.getHeight();
83+
84+
setContentSize(windowWidth, windowHeight);
85+
} else {
86+
IRect rect = getContentRect();
87+
int contentWidth = rect.getWidth();
88+
int contentHeight = rect.getHeight();
89+
90+
LONG_PTR lStyle = GetWindowLongPtr(_hWnd, GWL_STYLE);
91+
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
92+
SetWindowLongPtr(_hWnd, GWL_STYLE, lStyle);
93+
94+
setWindowSize(contentWidth, contentHeight);
95+
}
96+
}
97+
7398
void jwm::WindowWin32::setIcon(const std::wstring& iconPath) {
7499
JWM_VERBOSE("Set window icon '" << iconPath << "'");
75100
// width / height of 0 along with LR_DEFAULTSIZE tells windows to load the default icon size.
@@ -656,7 +681,6 @@ LRESULT jwm::WindowWin32::processEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
656681
dispatch(classes::EventWindowFocusOut::kInstance);
657682
break;
658683

659-
660684
case WM_CLOSE:
661685
JWM_VERBOSE("Event close");
662686
dispatch(classes::EventWindowCloseRequest::kInstance);
@@ -1013,6 +1037,12 @@ extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSet
10131037
env->ReleaseStringChars(title, titleStr);
10141038
}
10151039

1040+
extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSetTitlebarVisible
1041+
(JNIEnv* env, jobject obj, jboolean isVisible) {
1042+
jwm::WindowWin32* instance = reinterpret_cast<jwm::WindowWin32*>(jwm::classes::Native::fromJava(env, obj));
1043+
instance->setTitlebarVisible(isVisible);
1044+
}
1045+
10161046
extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSetIcon
10171047
(JNIEnv* env, jobject obj, jstring iconPath) {
10181048
jwm::WindowWin32* instance = reinterpret_cast<jwm::WindowWin32*>(jwm::classes::Native::fromJava(env, obj));

windows/cc/WindowWin32.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace jwm {
5151
void unmarkText();
5252
void setImeEnabled(bool enabled);
5353
void setTitle(const std::wstring& title);
54+
void setTitlebarVisible(bool isVisible);
5455
void setIcon(const std::wstring& iconPath);
5556
void setOpacity(float opacity);
5657
float getOpacity();

windows/java/WindowWin32.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public Window setTitle(String title) {
6868
return this;
6969
}
7070

71-
7271
@Override
7372
public Window setIcon(File icon){
7473
assert _onUIThread() : "Should be run on UI thread";
@@ -78,7 +77,9 @@ public Window setIcon(File icon){
7877

7978
@Override
8079
public Window setTitlebarVisible(boolean value) {
81-
throw new UnsupportedOperationException("impl me!");
80+
assert _onUIThread();
81+
_nSetTitlebarVisible(value);
82+
return this;
8283
}
8384

8485
@Override
@@ -225,6 +226,7 @@ public Window winSetParent(long hwnd) {
225226
@ApiStatus.Internal public native void _nSetWindowSize(int width, int height);
226227
@ApiStatus.Internal public native void _nSetContentSize(int width, int height);
227228
@ApiStatus.Internal public native void _nSetTitle(String title);
229+
@ApiStatus.Internal public native void _nSetTitlebarVisible(boolean isVisible);
228230
@ApiStatus.Internal public native void _nSetIcon(String iconPath);
229231
@ApiStatus.Internal public native void _nSetVisible(boolean isVisible);
230232
@ApiStatus.Internal public native void _nSetOpacity(float opacity);

0 commit comments

Comments
 (0)