Skip to content

Commit

Permalink
Add Windows implementation of setTitlebarVisible
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Quezion committed Jan 19, 2024
1 parent a04867c commit 1158559
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ Run examples without building (use version from the table above):
./script/run.py --jwm-version <version>
```

### Debugging

Set `JWM_VERBOSE` in process env to see extra log output when running locally.

``` bash
# Mac / Linux
export JWM_VERBOSE=true

# Windows
set JWM_VERBOSE=true
```

# Contributing

PRs & issue reports are welcome!
Expand Down
10 changes: 10 additions & 0 deletions examples/dashboard/java/PanelScreens.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public PanelScreens(Window window) {
titleStyles = new Options("Default", "Hidden", "Transparent", "Unified", "Unified Compact", "Unified Transparent", "Unified Compact Transparent");
} else if (Platform.X11 == Platform.CURRENT) {
titleStyles = new Options("Default", "Hidden");
} else if (Platform.WINDOWS == Platform.CURRENT) {
titleStyles = new Options("Default", "Hidden");
}
}

Expand Down Expand Up @@ -66,6 +68,14 @@ public void setTitleStyle(String style) {
case "Hidden" ->
w.setTitlebarVisible(false);
}
} else if (Platform.WINDOWS == Platform.CURRENT) {
WindowWin32 w = (WindowWin32) window;
switch (style) {
case "Default" ->
w.setTitlebarVisible(true);
case "Hidden" ->
w.setTitlebarVisible(false);
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions windows/cc/WindowWin32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ void jwm::WindowWin32::setTitle(const std::wstring& title) {
SetWindowTextW(_hWnd, title.c_str());
}

void jwm::WindowWin32::setTitlebarVisible(bool isVisible) {
JWM_VERBOSE("Set titlebar visible=" << isVisible << " for window 0x" << this);
if (isVisible == true) {
LONG_PTR lStyle = GetWindowLongPtr(_hWnd, GWL_STYLE);
lStyle |= (WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
SetWindowLongPtr(_hWnd, GWL_STYLE, lStyle);
} else {
LONG_PTR lStyle = GetWindowLongPtr(_hWnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
SetWindowLongPtr(_hWnd, GWL_STYLE, lStyle);
}
}

void jwm::WindowWin32::setIcon(const std::wstring& iconPath) {
JWM_VERBOSE("Set window icon '" << iconPath << "'");
// width / height of 0 along with LR_DEFAULTSIZE tells windows to load the default icon size.
Expand Down Expand Up @@ -656,6 +669,15 @@ LRESULT jwm::WindowWin32::processEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
dispatch(classes::EventWindowFocusOut::kInstance);
break;

case WM_STYLECHANGED: {
IRect rect = getWindowRect();
int windowWidth = rect.getWidth();
int windowHeight = rect.getHeight();
JWM_VERBOSE("StyleChanged event"
<< "window w=" << windowWidth << " h=" << windowHeight);
setContentSize(windowWidth, windowHeight);
return 0;
}

case WM_CLOSE:
JWM_VERBOSE("Event close");
Expand Down Expand Up @@ -1013,6 +1035,12 @@ extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSet
env->ReleaseStringChars(title, titleStr);
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSetTitlebarVisible
(JNIEnv* env, jobject obj, jboolean isVisible) {
jwm::WindowWin32* instance = reinterpret_cast<jwm::WindowWin32*>(jwm::classes::Native::fromJava(env, obj));
instance->setTitlebarVisible(isVisible);
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_WindowWin32__1nSetIcon
(JNIEnv* env, jobject obj, jstring iconPath) {
jwm::WindowWin32* instance = reinterpret_cast<jwm::WindowWin32*>(jwm::classes::Native::fromJava(env, obj));
Expand Down
1 change: 1 addition & 0 deletions windows/cc/WindowWin32.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace jwm {
void unmarkText();
void setImeEnabled(bool enabled);
void setTitle(const std::wstring& title);
void setTitlebarVisible(bool isVisible);
void setIcon(const std::wstring& iconPath);
void setOpacity(float opacity);
float getOpacity();
Expand Down
6 changes: 4 additions & 2 deletions windows/java/WindowWin32.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public Window setTitle(String title) {
return this;
}


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

@Override
public Window setTitlebarVisible(boolean value) {
throw new UnsupportedOperationException("impl me!");
assert _onUIThread();
_nSetTitlebarVisible(value);
return this;
}

@Override
Expand Down Expand Up @@ -225,6 +226,7 @@ public Window winSetParent(long hwnd) {
@ApiStatus.Internal public native void _nSetWindowSize(int width, int height);
@ApiStatus.Internal public native void _nSetContentSize(int width, int height);
@ApiStatus.Internal public native void _nSetTitle(String title);
@ApiStatus.Internal public native void _nSetTitlebarVisible(boolean isVisible);
@ApiStatus.Internal public native void _nSetIcon(String iconPath);
@ApiStatus.Internal public native void _nSetVisible(boolean isVisible);
@ApiStatus.Internal public native void _nSetOpacity(float opacity);
Expand Down

0 comments on commit 1158559

Please sign in to comment.