Skip to content

Commit 0f2cf6d

Browse files
fireclawthefoxrdb
andcommitted
Add maximized property to WindowProperties, plus implementation (panda3d#809)
Closes panda3d#809 Co-authored-by: rdb <git@rdb.name>
1 parent 4a21329 commit 0f2cf6d

File tree

13 files changed

+276
-17
lines changed

13 files changed

+276
-17
lines changed

panda/src/cocoadisplay/cocoaGraphicsWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class EXPCL_PANDA_COCOADISPLAY CocoaGraphicsWindow : public GraphicsWindow {
5151
void handle_move_event();
5252
void handle_resize_event();
5353
void handle_minimize_event(bool minimized);
54+
void handle_maximize_event(bool maximized);
5455
void handle_foreground_event(bool foreground);
5556
bool handle_close_request();
5657
void handle_close_event();

panda/src/cocoadisplay/cocoaGraphicsWindow.mm

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@
405405
if (!_properties.has_minimized()) {
406406
_properties.set_minimized(false);
407407
}
408+
if (!_properties.has_maximized()) {
409+
_properties.set_maximized(false);
410+
}
408411
if (!_properties.has_z_order()) {
409412
_properties.set_z_order(WindowProperties::Z_normal);
410413
}
@@ -713,7 +716,7 @@
713716

714717
if (_window != nil) {
715718
[_window close];
716-
719+
717720
// Process events once more so any pending NSEvents are cleared. Not doing
718721
// this causes the window to stick around after calling [_window close].
719722
process_events();
@@ -925,6 +928,14 @@
925928
properties.clear_origin();
926929
}
927930

931+
if (properties.has_maximized() && _window != nil) {
932+
_properties.set_maximized(properties.get_maximized());
933+
if (properties.get_maximized() != !![_window isZoomed]) {
934+
[_window zoom:nil];
935+
}
936+
properties.clear_maximized();
937+
}
938+
928939
if (properties.has_title() && _window != nil) {
929940
_properties.set_title(properties.get_title());
930941
[_window setTitle:[NSString stringWithUTF8String:properties.get_title().c_str()]];
@@ -1404,17 +1415,31 @@
14041415

14051416
NSRect frame = [_view convertRect:[_view bounds] toView:nil];
14061417

1418+
WindowProperties properties;
1419+
bool changed = false;
1420+
14071421
if (frame.size.width != _properties.get_x_size() ||
14081422
frame.size.height != _properties.get_y_size()) {
14091423

1410-
WindowProperties properties;
14111424
properties.set_size(frame.size.width, frame.size.height);
14121425

14131426
if (cocoadisplay_cat.is_spam()) {
14141427
cocoadisplay_cat.spam()
14151428
<< "Window changed size to (" << frame.size.width
14161429
<< ", " << frame.size.height << ")\n";
14171430
}
1431+
changed = true;
1432+
}
1433+
1434+
if (_window != nil) {
1435+
bool is_maximized = [_window isZoomed];
1436+
if (is_maximized != _properties.get_maximized()) {
1437+
properties.set_maximized(is_maximized);
1438+
changed = true;
1439+
}
1440+
}
1441+
1442+
if (changed) {
14181443
system_changed_properties(properties);
14191444
}
14201445

@@ -1444,6 +1469,31 @@
14441469
system_changed_properties(properties);
14451470
}
14461471

1472+
/**
1473+
* Called by the window delegate when the window is maximized or
1474+
* demaximized.
1475+
*/
1476+
void CocoaGraphicsWindow::
1477+
handle_maximize_event(bool maximized) {
1478+
if (maximized == _properties.get_maximized()) {
1479+
return;
1480+
}
1481+
1482+
if (cocoadisplay_cat.is_debug()) {
1483+
if (maximized) {
1484+
cocoadisplay_cat.debug() << "Window was maximized\n";
1485+
} else {
1486+
cocoadisplay_cat.debug() << "Window was demaximized\n";
1487+
}
1488+
}
1489+
1490+
WindowProperties properties;
1491+
properties.set_maximized(maximized);
1492+
system_changed_properties(properties);
1493+
}
1494+
1495+
1496+
14471497
/**
14481498
* Called by the window delegate when the window has become the key window or
14491499
* resigned that status.

panda/src/display/config_display.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ ConfigVariableInt win_origin
328328
ConfigVariableBool fullscreen
329329
("fullscreen", false);
330330

331+
ConfigVariableBool maximized
332+
("maximized", false,
333+
PRC_DESC("Start the window in a maximized state as handled by the window"
334+
"manager. In comparison to the fullscreen setting, this will"
335+
"usually not remove the window decoration and not occupy the"
336+
"whole screen space."));
337+
331338
ConfigVariableBool undecorated
332339
("undecorated", false,
333340
PRC_DESC("This specifies the default value of the 'undecorated' window "

panda/src/display/config_display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ extern EXPCL_PANDA_DISPLAY ConfigVariableBool old_alpha_blend;
7373
extern EXPCL_PANDA_DISPLAY ConfigVariableInt win_size;
7474
extern EXPCL_PANDA_DISPLAY ConfigVariableInt win_origin;
7575
extern EXPCL_PANDA_DISPLAY ConfigVariableBool fullscreen;
76+
extern EXPCL_PANDA_DISPLAY ConfigVariableBool maximized;
7677
extern EXPCL_PANDA_DISPLAY ConfigVariableBool undecorated;
7778
extern EXPCL_PANDA_DISPLAY ConfigVariableBool win_fixed_size;
7879
extern EXPCL_PANDA_DISPLAY ConfigVariableBool cursor_hidden;

panda/src/display/graphicsWindow.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
5454
_properties.set_undecorated(false);
5555
_properties.set_fullscreen(false);
5656
_properties.set_minimized(false);
57+
_properties.set_maximized(false);
5758
_properties.set_cursor_hidden(false);
5859

5960
request_properties(WindowProperties::get_default());

panda/src/display/windowProperties.I

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,45 @@ clear_minimized() {
407407
_flags &= ~F_minimized;
408408
}
409409

410+
/**
411+
* Specifies whether the window should be created maximized (true), or normal
412+
* (false).
413+
*/
414+
INLINE void WindowProperties::
415+
set_maximized(bool maximized) {
416+
if (maximized) {
417+
_flags |= F_maximized;
418+
} else {
419+
_flags &= ~F_maximized;
420+
}
421+
_specified |= S_maximized;
422+
}
423+
424+
/**
425+
* Returns true if the window is maximized.
426+
*/
427+
INLINE bool WindowProperties::
428+
get_maximized() const {
429+
return (_flags & F_maximized) != 0;
430+
}
431+
432+
/**
433+
* Returns true if set_maximized() has been specified.
434+
*/
435+
INLINE bool WindowProperties::
436+
has_maximized() const {
437+
return ((_specified & S_maximized) != 0);
438+
}
439+
440+
/**
441+
* Removes the maximized specification from the properties.
442+
*/
443+
INLINE void WindowProperties::
444+
clear_maximized() {
445+
_specified &= ~S_maximized;
446+
_flags &= ~F_maximized;
447+
}
448+
410449
/**
411450
* Specifies whether the window should read the raw mouse devices.
412451
*/

panda/src/display/windowProperties.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ get_config_properties() {
6969
props.set_fullscreen(fullscreen);
7070
props.set_undecorated(undecorated);
7171
props.set_fixed_size(win_fixed_size);
72+
props.set_maximized(maximized);
7273
props.set_cursor_hidden(cursor_hidden);
7374
if (!icon_filename.empty()) {
7475
props.set_icon_filename(icon_filename);
@@ -240,6 +241,9 @@ add_properties(const WindowProperties &other) {
240241
if (other.has_minimized()) {
241242
set_minimized(other.get_minimized());
242243
}
244+
if (other.has_maximized()) {
245+
set_maximized(other.get_maximized());
246+
}
243247
if (other.has_raw_mice()) {
244248
set_raw_mice(other.get_raw_mice());
245249
}
@@ -296,6 +300,9 @@ output(ostream &out) const {
296300
if (has_minimized()) {
297301
out << (get_minimized() ? "minimized " : "!minimized ");
298302
}
303+
if (has_maximized()) {
304+
out << (get_maximized() ? "maximized " : "!maximized ");
305+
}
299306
if (has_raw_mice()) {
300307
out << (get_raw_mice() ? "raw_mice " : "!raw_mice ");
301308
}

panda/src/display/windowProperties.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ class EXPCL_PANDA_DISPLAY WindowProperties {
132132
MAKE_PROPERTY2(minimized, has_minimized, get_minimized,
133133
set_minimized, clear_minimized);
134134

135+
INLINE void set_maximized(bool maximized);
136+
INLINE bool get_maximized() const;
137+
INLINE bool has_maximized() const;
138+
INLINE void clear_maximized();
139+
MAKE_PROPERTY2(maximized, has_maximized, get_maximized,
140+
set_maximized, clear_maximized);
141+
135142
INLINE void set_raw_mice(bool raw_mice);
136143
INLINE bool get_raw_mice() const;
137144
INLINE bool has_raw_mice() const;
@@ -202,6 +209,7 @@ class EXPCL_PANDA_DISPLAY WindowProperties {
202209
S_mouse_mode = 0x02000,
203210
S_parent_window = 0x04000,
204211
S_raw_mice = 0x08000,
212+
S_maximized = 0x10000,
205213
};
206214

207215
// This bitmask represents the truefalse settings for various boolean flags
@@ -211,6 +219,7 @@ class EXPCL_PANDA_DISPLAY WindowProperties {
211219
F_fullscreen = S_fullscreen,
212220
F_foreground = S_foreground,
213221
F_minimized = S_minimized,
222+
F_maximized = S_maximized,
214223
F_open = S_open,
215224
F_cursor_hidden = S_cursor_hidden,
216225
F_fixed_size = S_fixed_size,

panda/src/windisplay/winGraphicsWindow.cxx

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,29 @@ set_properties_now(WindowProperties &properties) {
306306
LPoint2i bottom_right = top_left + _properties.get_size();
307307

308308
DWORD window_style = make_style(_properties);
309+
DWORD current_style = GetWindowLong(_hWnd, GWL_STYLE);
309310
SetWindowLong(_hWnd, GWL_STYLE, window_style);
310311

311-
// Now calculate the proper size and origin with the new window style.
312-
RECT view_rect;
313-
SetRect(&view_rect, top_left[0], top_left[1],
314-
bottom_right[0], bottom_right[1]);
315-
WINDOWINFO wi;
316-
GetWindowInfo(_hWnd, &wi);
317-
AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle);
318-
319-
// We need to call this to ensure that the style change takes effect.
320-
SetWindowPos(_hWnd, HWND_NOTOPMOST, view_rect.left, view_rect.top,
321-
view_rect.right - view_rect.left,
322-
view_rect.bottom - view_rect.top,
323-
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED |
324-
SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
312+
// If we switched to/from undecorated, calculate the new size.
313+
if (((window_style ^ current_style) & WS_CAPTION) != 0) {
314+
RECT view_rect;
315+
SetRect(&view_rect, top_left[0], top_left[1],
316+
bottom_right[0], bottom_right[1]);
317+
WINDOWINFO wi;
318+
GetWindowInfo(_hWnd, &wi);
319+
AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle);
320+
321+
SetWindowPos(_hWnd, HWND_NOTOPMOST, view_rect.left, view_rect.top,
322+
view_rect.right - view_rect.left,
323+
view_rect.bottom - view_rect.top,
324+
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED |
325+
SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
326+
} else {
327+
// We need to call this to ensure that the style change takes effect.
328+
SetWindowPos(_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
329+
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE |
330+
SWP_FRAMECHANGED | SWP_NOSENDCHANGING | SWP_SHOWWINDOW);
331+
}
325332
}
326333

327334
if (properties.has_title()) {
@@ -402,6 +409,23 @@ set_properties_now(WindowProperties &properties) {
402409
properties.clear_minimized();
403410
}
404411

412+
if (properties.has_maximized()) {
413+
if (_properties.get_maximized() != properties.get_maximized()) {
414+
if (properties.get_maximized()) {
415+
ShowWindow(_hWnd, SW_MAXIMIZE);
416+
} else {
417+
ShowWindow(_hWnd, SW_RESTORE);
418+
}
419+
_properties.set_maximized(properties.get_maximized());
420+
421+
if (_properties.get_minimized()) {
422+
// Immediately minimize it again
423+
ShowWindow(_hWnd, SW_MINIMIZE);
424+
}
425+
}
426+
properties.clear_maximized();
427+
}
428+
405429
if (properties.has_fullscreen()) {
406430
if (properties.get_fullscreen() && !is_fullscreen()) {
407431
if (do_fullscreen_switch()){
@@ -507,6 +531,7 @@ open_window() {
507531
}
508532
bool want_foreground = (!_properties.has_foreground() || _properties.get_foreground());
509533
bool want_minimized = (_properties.has_minimized() && _properties.get_minimized()) && !want_foreground;
534+
bool want_maximized = (_properties.has_maximized() && _properties.get_maximized()) && want_foreground;
510535

511536
HWND old_foreground_window = GetForegroundWindow();
512537

@@ -533,6 +558,9 @@ open_window() {
533558
if (want_minimized) {
534559
ShowWindow(_hWnd, SW_MINIMIZE);
535560
ShowWindow(_hWnd, SW_MINIMIZE);
561+
} else if (want_maximized) {
562+
ShowWindow(_hWnd, SW_MAXIMIZE);
563+
ShowWindow(_hWnd, SW_MAXIMIZE);
536564
} else {
537565
ShowWindow(_hWnd, SW_SHOWNORMAL);
538566
ShowWindow(_hWnd, SW_SHOWNORMAL);
@@ -854,6 +882,21 @@ handle_reshape() {
854882
<< "," << properties.get_y_size() << ")\n";
855883
}
856884

885+
// Check whether the window has been maximized or unmaximized.
886+
WINDOWPLACEMENT pl;
887+
pl.length = sizeof(WINDOWPLACEMENT);
888+
if (GetWindowPlacement(_hWnd, &pl)) {
889+
if (pl.showCmd == SW_SHOWMAXIMIZED || (pl.flags & WPF_RESTORETOMAXIMIZED) != 0) {
890+
properties.set_maximized(true);
891+
} else {
892+
properties.set_maximized(false);
893+
}
894+
}
895+
else if (windisplay_cat.is_debug()) {
896+
windisplay_cat.debug()
897+
<< "GetWindowPlacement() failed in handle_reshape. Ignoring.\n";
898+
}
899+
857900
adjust_z_order();
858901
system_changed_properties(properties);
859902
}
@@ -1083,6 +1126,9 @@ calculate_metrics(bool fullscreen, DWORD window_style, WINDOW_METRICS &metrics,
10831126
bool WinGraphicsWindow::
10841127
open_graphic_window() {
10851128
DWORD window_style = make_style(_properties);
1129+
if (_properties.get_maximized()) {
1130+
window_style |= WS_MAXIMIZE;
1131+
}
10861132

10871133
wstring title;
10881134
if (_properties.has_title()) {

panda/src/x11display/x11GraphicsPipe.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ x11GraphicsPipe(const std::string &display) :
363363
_net_wm_state_add = XInternAtom(_display, "_NET_WM_STATE_ADD", false);
364364
_net_wm_state_remove = XInternAtom(_display, "_NET_WM_STATE_REMOVE", false);
365365
_net_wm_bypass_compositor = XInternAtom(_display, "_NET_WM_BYPASS_COMPOSITOR", false);
366+
_net_wm_state_maximized_vert = XInternAtom(_display, "_NET_WM_STATE_MAXIMIZED_VERT", false);
367+
_net_wm_state_maximized_horz = XInternAtom(_display, "_NET_WM_STATE_MAXIMIZED_HORZ", false);
366368
}
367369

368370
/**

0 commit comments

Comments
 (0)