Skip to content

Commit 1158559

Browse files
committed
Add Windows implementation of setTitlebarVisible
JWM demo works with Ctrl+T "Toggle Resize" Known side-effect/bug of increasing window size on repeated toggles Update README.md with JWM_DEBUG env instructions
1 parent a04867c commit 1158559

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ Run examples without building (use version from the table above):
226226
./script/run.py --jwm-version <version>
227227
```
228228

229+
### Debugging
230+
231+
Set `JWM_VERBOSE` in process env to see extra log output when running locally.
232+
233+
``` bash
234+
# Mac / Linux
235+
export JWM_VERBOSE=true
236+
237+
# Windows
238+
set JWM_VERBOSE=true
239+
```
240+
229241
# Contributing
230242

231243
PRs & issue reports are welcome!

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ 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+
} else {
80+
LONG_PTR lStyle = GetWindowLongPtr(_hWnd, GWL_STYLE);
81+
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
82+
SetWindowLongPtr(_hWnd, GWL_STYLE, lStyle);
83+
}
84+
}
85+
7386
void jwm::WindowWin32::setIcon(const std::wstring& iconPath) {
7487
JWM_VERBOSE("Set window icon '" << iconPath << "'");
7588
// width / height of 0 along with LR_DEFAULTSIZE tells windows to load the default icon size.
@@ -656,6 +669,15 @@ LRESULT jwm::WindowWin32::processEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
656669
dispatch(classes::EventWindowFocusOut::kInstance);
657670
break;
658671

672+
case WM_STYLECHANGED: {
673+
IRect rect = getWindowRect();
674+
int windowWidth = rect.getWidth();
675+
int windowHeight = rect.getHeight();
676+
JWM_VERBOSE("StyleChanged event"
677+
<< "window w=" << windowWidth << " h=" << windowHeight);
678+
setContentSize(windowWidth, windowHeight);
679+
return 0;
680+
}
659681

660682
case WM_CLOSE:
661683
JWM_VERBOSE("Event close");
@@ -1013,6 +1035,12 @@ extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSet
10131035
env->ReleaseStringChars(title, titleStr);
10141036
}
10151037

1038+
extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSetTitlebarVisible
1039+
(JNIEnv* env, jobject obj, jboolean isVisible) {
1040+
jwm::WindowWin32* instance = reinterpret_cast<jwm::WindowWin32*>(jwm::classes::Native::fromJava(env, obj));
1041+
instance->setTitlebarVisible(isVisible);
1042+
}
1043+
10161044
extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSetIcon
10171045
(JNIEnv* env, jobject obj, jstring iconPath) {
10181046
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)