Skip to content

Commit 76c74e0

Browse files
committed
Add window control buttons visibility API
Introduces SetWindowControlButtonsVisible and IsWindowControlButtonsVisible methods to the Window class. Implements actual visibility toggling for macOS, stubs for Android, iOS, and OpenHarmony (not applicable), and placeholders for Windows and Linux (not yet implemented). Updates documentation in window.h to reflect platform support.
1 parent 3be4d55 commit 76c74e0

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

src/platform/android/window_android.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ bool Window::IsClosable() const {
262262
return true;
263263
}
264264

265+
void Window::SetWindowControlButtonsVisible(bool is_visible) {
266+
// Not applicable to Android - mobile apps don't have window control buttons
267+
}
268+
269+
bool Window::IsWindowControlButtonsVisible() const {
270+
// Not applicable to Android - mobile apps don't have window control buttons
271+
return false;
272+
}
273+
265274
void Window::SetAlwaysOnTop(bool is_always_on_top) {
266275
ALOGW("SetAlwaysOnTop not fully supported on Android");
267276
}

src/platform/ios/window_ios.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@
262262
return true;
263263
}
264264

265+
void Window::SetWindowControlButtonsVisible(bool is_visible) {
266+
// Not applicable to iOS - mobile apps don't have window control buttons
267+
}
268+
269+
bool Window::IsWindowControlButtonsVisible() const {
270+
// Not applicable to iOS - mobile apps don't have window control buttons
271+
return false;
272+
}
273+
265274
void Window::SetAlwaysOnTop(bool is_always_on_top) {
266275
// Not applicable to iOS (no multi-window in traditional sense)
267276
}

src/platform/linux/window_linux.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ bool Window::IsClosable() const {
384384
return true; // Default assumption
385385
}
386386

387+
void Window::SetWindowControlButtonsVisible(bool is_visible) {
388+
// TODO: Implement for Linux
389+
// This would involve manipulating GTK window decorations
390+
}
391+
392+
bool Window::IsWindowControlButtonsVisible() const {
393+
// TODO: Implement for Linux
394+
return true; // Default to visible
395+
}
396+
387397
void Window::SetAlwaysOnTop(bool is_always_on_top) {
388398
if (pimpl_->gdk_window_) {
389399
gdk_window_set_keep_above(pimpl_->gdk_window_, is_always_on_top);

src/platform/macos/window_macos.mm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,30 @@
299299
return [pimpl_->ns_window_ styleMask] & NSWindowStyleMaskClosable;
300300
}
301301

302+
void Window::SetWindowControlButtonsVisible(bool is_visible) {
303+
NSButton* closeButton = [pimpl_->ns_window_ standardWindowButton:NSWindowCloseButton];
304+
NSButton* miniaturizeButton = [pimpl_->ns_window_ standardWindowButton:NSWindowMiniaturizeButton];
305+
NSButton* zoomButton = [pimpl_->ns_window_ standardWindowButton:NSWindowZoomButton];
306+
307+
if (closeButton) {
308+
[closeButton setHidden:!is_visible];
309+
}
310+
if (miniaturizeButton) {
311+
[miniaturizeButton setHidden:!is_visible];
312+
}
313+
if (zoomButton) {
314+
[zoomButton setHidden:!is_visible];
315+
}
316+
}
317+
318+
bool Window::IsWindowControlButtonsVisible() const {
319+
NSButton* closeButton = [pimpl_->ns_window_ standardWindowButton:NSWindowCloseButton];
320+
if (closeButton) {
321+
return ![closeButton isHidden];
322+
}
323+
return true; // Default to visible if button not found
324+
}
325+
302326
void Window::SetAlwaysOnTop(bool is_always_on_top) {
303327
[pimpl_->ns_window_ setLevel:is_always_on_top ? NSFloatingWindowLevel : NSNormalWindowLevel];
304328
}

src/platform/ohos/window_ohos.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ bool Window::IsClosable() const {
244244
return true;
245245
}
246246

247+
void Window::SetWindowControlButtonsVisible(bool is_visible) {
248+
// Not applicable to OpenHarmony - mobile apps don't have window control buttons
249+
}
250+
251+
bool Window::IsWindowControlButtonsVisible() const {
252+
// Not applicable to OpenHarmony - mobile apps don't have window control buttons
253+
return false;
254+
}
255+
247256
void Window::SetAlwaysOnTop(bool is_always_on_top) {
248257
// SetAlwaysOnTop not fully supported on OpenHarmony
249258
}

src/platform/windows/window_windows.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,16 @@ bool Window::IsClosable() const {
573573
return (style & WS_SYSMENU) != 0;
574574
}
575575

576+
void Window::SetWindowControlButtonsVisible(bool is_visible) {
577+
// TODO: Implement for Windows
578+
// This would involve custom window chrome or DWM frame manipulation
579+
}
580+
581+
bool Window::IsWindowControlButtonsVisible() const {
582+
// TODO: Implement for Windows
583+
return true; // Default to visible
584+
}
585+
576586
void Window::SetAlwaysOnTop(bool is_always_on_top) {
577587
if (pimpl_->hwnd_) {
578588
SetWindowPos(pimpl_->hwnd_, is_always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0,

src/window.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,40 @@ class Window : public NativeObjectProvider, public std::enable_shared_from_this<
429429
*/
430430
bool IsClosable() const;
431431

432+
/**
433+
* @brief Sets the visibility of window control buttons.
434+
*
435+
* @param is_visible true to show window control buttons, false to hide them
436+
*
437+
* Controls the visibility of window control buttons (minimize, maximize, close)
438+
* in the title bar. When hidden, the buttons are not visible but the window
439+
* can still be controlled programmatically.
440+
*
441+
* @note Platform availability:
442+
* - macOS: ✅ Fully supported - Hides/shows the traffic light buttons (red, yellow, green)
443+
* - Windows: ❌ Not implemented - Returns default value (visible)
444+
* - Linux: ❌ Not implemented - Returns default value (visible)
445+
* - Android: ❌ Not applicable - Mobile apps don't have window control buttons
446+
* - iOS: ❌ Not applicable - Mobile apps don't have window control buttons
447+
* - OpenHarmony: ❌ Not applicable - Mobile apps don't have window control buttons
448+
*/
449+
void SetWindowControlButtonsVisible(bool is_visible);
450+
451+
/**
452+
* @brief Checks if the window control buttons are visible.
453+
*
454+
* @return true if window control buttons are visible, false if hidden
455+
*
456+
* @note Platform availability:
457+
* - macOS: ✅ Fully supported - Returns actual visibility state
458+
* - Windows: ❌ Not implemented - Always returns true
459+
* - Linux: ❌ Not implemented - Always returns true
460+
* - Android: ❌ Not applicable - Always returns false
461+
* - iOS: ❌ Not applicable - Always returns false
462+
* - OpenHarmony: ❌ Not applicable - Always returns false
463+
*/
464+
bool IsWindowControlButtonsVisible() const;
465+
432466
/**
433467
* @brief Sets whether the window stays on top of other windows.
434468
*

0 commit comments

Comments
 (0)