Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add window states API #2473

Open
wants to merge 283 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 212 commits
Commits
Show all changes
283 commits
Select commit Hold shift + click to select a range
0cf8cf8
Fixed winforms backend and testbed tests
proneon267 Mar 29, 2024
d82c615
Corrected gtk backend and core
proneon267 Mar 30, 2024
96ef3ed
Fixed winforms backend and cocoa
proneon267 Mar 31, 2024
4657567
Fixed core tests
proneon267 Mar 31, 2024
00491c8
Fixed cocoa backend and tests
proneon267 Mar 31, 2024
41c1dd7
Fixed testbed tests
proneon267 Mar 31, 2024
60d5e43
corrected testbed
proneon267 Mar 31, 2024
f497a1d
Added android implementation
proneon267 Apr 1, 2024
d34cb2f
Fixed core
proneon267 Apr 1, 2024
4d790b2
Fixed core
proneon267 Apr 1, 2024
18b0cbc
Added stub implementations for iOS, textual, web
proneon267 Apr 2, 2024
618d647
Merge branch 'beeware:main' into window_states
proneon267 Apr 2, 2024
b7eb117
Added mobile platform tests
proneon267 Apr 2, 2024
cadc4cc
Added changelog
proneon267 Apr 2, 2024
bf3511a
Restart CI
proneon267 Apr 3, 2024
d61a644
Merge remote-tracking branch 'remotes/origin/main' into window_states
proneon267 May 10, 2024
5b58045
Merge branch 'beeware:main' into window_states
proneon267 May 10, 2024
c9a1307
Minor modifications
proneon267 May 22, 2024
ab9b778
Minor modifications
proneon267 May 22, 2024
0a90a12
Minor modifications
proneon267 May 22, 2024
73721b3
Minor modifications
proneon267 May 22, 2024
c809698
Fixed bug on Window.close()
proneon267 May 23, 2024
06b7f2a
Fixed dummy backend
proneon267 May 23, 2024
11fea69
Fixed tests
proneon267 Jun 1, 2024
938504c
Minor cleanup
proneon267 Jun 1, 2024
be87113
Code Cleanup
proneon267 Jun 1, 2024
9aefd30
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Jun 1, 2024
13d2ff3
Merge branch 'beeware:main' into window_states
proneon267 Jun 1, 2024
176e879
Code Cleanup
proneon267 Jun 1, 2024
1ba73b8
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Jun 1, 2024
d4bfdaa
Restart CI for Linux Testbed failure
proneon267 Jun 1, 2024
d993b80
Merge branch 'main' into window_states
proneon267 Jun 12, 2024
38bf5c3
Updated to latest main branch
proneon267 Jun 12, 2024
b710eaf
Parameterized test on core
proneon267 Jun 16, 2024
b461295
Merge branch 'main' into window_states
proneon267 Jun 16, 2024
0c7900b
Updating to latest main branch
proneon267 Jun 16, 2024
97a6c66
Changed attribute to is_presentation_mode
proneon267 Jun 16, 2024
ba28194
Misc cleanup
proneon267 Jun 16, 2024
c7320ce
Name cleanups
proneon267 Jun 16, 2024
aed5251
Modified as per review
proneon267 Jun 17, 2024
a76bf9b
Added _PLATFORM_ALLOWS_CLOSE attribute on required backends
proneon267 Jun 17, 2024
f0d5d80
Handled deprecation warning on testbed tests
proneon267 Jun 17, 2024
e416f20
Removed explicit closing from dummy backend
proneon267 Jun 17, 2024
1fa8cde
100% coverage on core
proneon267 Jun 17, 2024
6350b5f
100% coverage on Android & iOS
proneon267 Jun 17, 2024
d091955
Restart CI for windows failure
proneon267 Jun 17, 2024
5c2a53b
Merge branch 'main' into window_states
proneon267 Jun 23, 2024
564c5ed
Updated to latest `main` branch
proneon267 Jun 23, 2024
e36e596
Delete changes/1857.bugfix.rst
proneon267 Jun 23, 2024
174d66b
Merge branch 'beeware:main' into window_states
proneon267 Jun 26, 2024
17564a8
Fixed testbed failures
proneon267 Jun 26, 2024
51cea93
Restart CI for pre-commit failure
proneon267 Jun 26, 2024
feb78a8
 
proneon267 Jun 26, 2024
4632738
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Jun 26, 2024
8286b86
 
proneon267 Jun 26, 2024
16d5758
Fix testbed for macOS
proneon267 Jun 26, 2024
5b59b14
Wayland test
proneon267 Jun 26, 2024
85dd202
Fix testbed for wayland
proneon267 Jun 26, 2024
552c0fc
Fix testbed for wayland
proneon267 Jun 26, 2024
56edec1
Restart CI for macOS
proneon267 Jun 26, 2024
971b8da
Merge branch 'main' into window_states
proneon267 Jun 27, 2024
934b6b1
Updated to latest main branch
proneon267 Jun 27, 2024
1e6bd76
Merge branch 'main' into window_states
proneon267 Jun 29, 2024
426e8b9
Updated to latest main branch
proneon267 Jun 29, 2024
ccef113
Merge branch 'beeware:main' into window_states
proneon267 Jul 4, 2024
4d83d19
Update changes/1857.removal.rst
proneon267 Jul 4, 2024
067e988
Update core/src/toga/constants/__init__.py
proneon267 Jul 4, 2024
3c84a80
Update core/src/toga/app.py
proneon267 Jul 4, 2024
a276f22
Various changes as per review: 1
proneon267 Jul 4, 2024
78cdd3b
Various changes as per review: 2
proneon267 Jul 4, 2024
b9e87c5
Various changes as per review: 3
proneon267 Jul 4, 2024
06d5a9e
Various changes as per review: 4
proneon267 Jul 4, 2024
b0c37fe
Various changes as per review: 5
proneon267 Jul 4, 2024
09ee428
Various changes as per review: 6
proneon267 Jul 4, 2024
1bd1f39
Various changes as per review: 7
proneon267 Jul 5, 2024
2b6d347
Added new tests as per review: 8
proneon267 Jul 5, 2024
8bba100
Minor change on cocoa
proneon267 Jul 6, 2024
6b3e883
Added tests as per review: 9
proneon267 Jul 6, 2024
74685d1
Restored to app presentation mode test to non-parameterized form to c…
proneon267 Jul 6, 2024
25c420f
Fixed testbed failures
proneon267 Jul 6, 2024
83dcab4
Minor change on testbed
proneon267 Jul 6, 2024
ab0ed45
Fixed cocoa backend and tests
proneon267 Jul 6, 2024
4fa4af6
Fixed dummy backend
proneon267 Jul 6, 2024
71f4314
Fixed gtk test backend
proneon267 Jul 7, 2024
a308ea7
Fixed core and added new test
proneon267 Jul 7, 2024
42642ee
Fixed winforms
proneon267 Jul 7, 2024
6b513c7
Fixed gtk backend
proneon267 Jul 7, 2024
ccc8f11
Fixed Android backend
proneon267 Jul 7, 2024
56f32a7
Test to diagnose wayland failure
proneon267 Jul 7, 2024
5da8231
Removed diagnostic tests
proneon267 Jul 7, 2024
4c6070d
Diagnostic test
proneon267 Jul 9, 2024
cfa255a
Various code cleanups
proneon267 Jul 9, 2024
87383f3
Fixed core
proneon267 Jul 10, 2024
c3f32c7
Minor cleanup
proneon267 Jul 9, 2024
4b2fdbb
Removed diagnostic tests
proneon267 Jul 7, 2024
b592ee2
Added review notes
proneon267 Jul 10, 2024
a5891e8
Fixed testbed tests
proneon267 Jul 10, 2024
e8ad898
100% coverage
proneon267 Jul 10, 2024
8684038
Removed diagnostic code
proneon267 Jul 10, 2024
1b53c16
diagnosing failure
proneon267 Jul 10, 2024
3cebc76
Revert change
proneon267 Jul 10, 2024
d2510e0
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Jul 10, 2024
4485cda
100% coverage
proneon267 Jul 10, 2024
d0dcb35
Merge branch 'beeware:main' into window_states
proneon267 Jul 16, 2024
f429307
Removed overspecified assertions and test
proneon267 Jul 25, 2024
6aedeea
changed is_presentation_mode to in_presentation_mode
proneon267 Jul 25, 2024
d7228ba
skipped some tests on the unimplemented iOS backend
proneon267 Jul 25, 2024
600e4c9
Modified cocoa implementation
proneon267 Jul 29, 2024
3689314
Typo fix on cocoa
proneon267 Jul 29, 2024
1a6b4ad
Merge branch 'beeware:main' into window_states
proneon267 Jul 29, 2024
2885d1c
Typo fix on cocoa
proneon267 Jul 29, 2024
cd9e00b
Typo fix on cocoa
proneon267 Jul 29, 2024
57fd1e3
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Jul 29, 2024
7835fe8
Fix cocoa
proneon267 Jul 29, 2024
1c0a969
Implemented new window states handling on cocoa and gtk
proneon267 Aug 6, 2024
cf23ce9
Fixed cocoa implementation
proneon267 Aug 6, 2024
e6f4dcc
Reimplemented on cocoa backend
proneon267 Aug 10, 2024
30e5968
Reimplemented on winforms
proneon267 Aug 12, 2024
c623254
 
proneon267 Aug 12, 2024
f2bd750
 
proneon267 Aug 12, 2024
11444e3
Reimplemented on gtk
proneon267 Aug 14, 2024
0771349
Update 1857.feature.rst
proneon267 Aug 14, 2024
c9b7b90
Removed unncessary complexity from cocoa implementation
proneon267 Aug 14, 2024
3441cb3
Misc fixes
proneon267 Aug 14, 2024
62dcd7d
Update cocoa/src/toga_cocoa/window.py
proneon267 Aug 15, 2024
4f36f28
proneon267 Aug 15, 2024
ea8058a
Update test_window.py
proneon267 Aug 15, 2024
11c3ec3
Reimplemented on cocoa backend
proneon267 Aug 16, 2024
0bd68c4
Reimplemented on gtk
proneon267 Aug 16, 2024
edef651
Merge branch 'beeware:main' into window_states
proneon267 Aug 16, 2024
3c8b0f1
Correcting test failure on cocoa
proneon267 Aug 17, 2024
e915d72
Correcting test failure on cocoa
proneon267 Aug 17, 2024
fb6e657
Correcting test failure on cocoa
proneon267 Aug 17, 2024
b810d65
Correcting test failure on cocoa
proneon267 Aug 17, 2024
1e59da1
Correcting test failure on cocoa
proneon267 Aug 17, 2024
9dba56b
Fix delegate error on cocoa
proneon267 Aug 17, 2024
56cc124
Fixing delegate error on cocoa
proneon267 Aug 17, 2024
2d29072
Add check guards for invalid impl on cocoa delegate
proneon267 Aug 17, 2024
c2e88e5
Removed unused state flags from gtk
proneon267 Aug 17, 2024
279dfda
Removed unused branch in cocoa implementation
proneon267 Aug 17, 2024
73bf7aa
Added checks for wayland
proneon267 Aug 18, 2024
af6a292
Added checks for wayland
proneon267 Aug 18, 2024
5a0352f
Minor gtk fix
proneon267 Aug 19, 2024
ef68572
Added no cover for wayland
proneon267 Aug 19, 2024
ca48ba2
parameterized tests on core
proneon267 Aug 20, 2024
cd8eba2
Reimplemented on Android
proneon267 Aug 20, 2024
e5eff2b
Merge branch 'main' into window_states
proneon267 Aug 20, 2024
26eb01c
Use the new wayland detection
proneon267 Aug 20, 2024
3a6aaf7
Removed legacy code from window example.
proneon267 Aug 20, 2024
78b5ddf
Added checks for wayland
proneon267 Aug 20, 2024
e0f5bf0
Minor fix on testbed
proneon267 Aug 20, 2024
54cfaab
Restart CI for intermittent failures
proneon267 Aug 20, 2024
8b8685e
Removed unused flags from Android implementation
proneon267 Aug 20, 2024
d599730
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Aug 20, 2024
91b70da
Reorganized test
proneon267 Aug 20, 2024
b38ff03
Merge branch 'beeware:main' into window_states
proneon267 Aug 20, 2024
2cf1839
Merge branch 'main' into window_states
proneon267 Aug 29, 2024
aa120e9
Resolving file conflicts with main branch
proneon267 Aug 29, 2024
3661110
Merge branch 'main' into window_states
proneon267 Sep 3, 2024
c928ac1
Fixed cocoa delegate
proneon267 Sep 3, 2024
f9c18f5
Modified testbed test
proneon267 Sep 9, 2024
ace13ce
Testing native OS delay for each platform
proneon267 Sep 10, 2024
ef7b3dc
Restart CI as previous run dropped by intermittent failure
proneon267 Sep 10, 2024
bc19c7f
Re-running CI to confirm cocoa errors are consistently produced
proneon267 Sep 10, 2024
c2235f7
Testing native OS delay for each platform
proneon267 Sep 10, 2024
b0ead86
Removed unused flag from gtk
proneon267 Sep 10, 2024
7bbf330
Restart CI for intermittent failures
proneon267 Sep 10, 2024
0f7fe4f
Removed unused flag on gtk
proneon267 Sep 10, 2024
7308e11
Enable presentation and fullscreen mode on wayland
proneon267 Sep 11, 2024
8f858be
Enable skipped test on wayland
proneon267 Sep 11, 2024
9f95554
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Sep 11, 2024
295cd59
Fix test timing
proneon267 Sep 11, 2024
5bd410e
Restart CI for intermittent failures
proneon267 Sep 11, 2024
00a742e
Delay tests according to native platforms
proneon267 Sep 11, 2024
4ef9c50
Covered missing coverage
proneon267 Sep 12, 2024
a1613be
Covered missing coverage
proneon267 Sep 12, 2024
138d0e3
Covered missing coverage
proneon267 Sep 13, 2024
450efad
Added XFAIL for iOS
proneon267 Sep 13, 2024
51d3590
Replace use of app_probe.redraw with window_probe.wait_for_window
proneon267 Sep 13, 2024
3de8eef
Moved presentation implementation on cocoa to window from app
proneon267 Sep 16, 2024
77e2b7e
Removed miniaturization delay from cocoa
proneon267 Sep 16, 2024
7db80d2
Removed miniaturization delay from cocoa
proneon267 Sep 16, 2024
aaee1f9
Ensuring coverage on macOS
proneon267 Sep 16, 2024
903860b
Ensuring coverage on macOS
proneon267 Sep 16, 2024
a6df392
Ensuring coverage on macOS
proneon267 Sep 19, 2024
f9f1375
Merge branch 'main' into window_states
proneon267 Sep 19, 2024
ad427ab
Ensuring coverage on macOS
proneon267 Sep 19, 2024
56de33d
Ensuring coverage on macOS
proneon267 Sep 19, 2024
59012cd
Ensuring coverage on macOS
proneon267 Sep 19, 2024
5a66725
Merge branch 'beeware:main' into window_states
proneon267 Sep 25, 2024
bb22a9f
Ensuring coverage on macOS
proneon267 Sep 25, 2024
f6a851d
Modified rapid state switching delay timing
proneon267 Sep 25, 2024
35bbb8e
Resolve error
proneon267 Sep 25, 2024
8bddf0e
Ensuring coverage on macOS
proneon267 Sep 25, 2024
03dd538
Update core/src/toga/window.py
proneon267 Sep 25, 2024
2af1509
Modified to correct expected error in test
proneon267 Sep 25, 2024
8b56d66
Clarified reasoning comment regarding state checks being performed at…
proneon267 Sep 27, 2024
7cd1489
Clarified reasoning comment regarding state checks being performed at…
proneon267 Sep 27, 2024
598021f
Modified testbed tests
proneon267 Sep 27, 2024
596acc4
Removed unused probe method from backends
proneon267 Sep 29, 2024
d3f90ba
Removed repeated tests
proneon267 Sep 29, 2024
945caf5
Removed repeated tests
proneon267 Sep 29, 2024
116eec3
Checking for coverage issues on macOS
proneon267 Sep 29, 2024
71aec38
Added no-cover on cocoa
proneon267 Sep 29, 2024
2559fa0
Improved tests
proneon267 Sep 30, 2024
d822ff0
Added platform notes
proneon267 Oct 2, 2024
14b64b7
Added platform notes
proneon267 Oct 3, 2024
d8c8422
Improved tests on mobile platform
proneon267 Oct 3, 2024
bb513d3
Merge branch 'beeware:main' into window_states
proneon267 Oct 3, 2024
eb2d9a5
Apply suggestions from code review
proneon267 Oct 7, 2024
abfa707
corrected pre-commit issues
proneon267 Oct 7, 2024
8f7c954
Moved implementation of app presentation mode to core from backends
proneon267 Oct 7, 2024
379e002
Removed unused code from dummy backend
proneon267 Oct 7, 2024
e3f31ff
corrected core tests
proneon267 Oct 7, 2024
383e027
Restart CI for intermittent Android failures
proneon267 Oct 7, 2024
c986e3d
Improved tests
proneon267 Oct 8, 2024
5f365c6
Improved tests
proneon267 Oct 8, 2024
2961507
Moved same state transition tests to core
proneon267 Oct 8, 2024
9ca14ed
Improved tests
proneon267 Oct 8, 2024
b6edc2a
Restart CI for Intermittent Android failure
proneon267 Oct 8, 2024
0f74ad9
Merge branch 'beeware:main' into window_states
proneon267 Oct 12, 2024
589e3c7
Restart CI for intermittent Android failures
proneon267 Oct 12, 2024
621c723
Restart CI for intermittent Android failures
proneon267 Oct 12, 2024
655a146
Restart CI for intermittent Android failures
proneon267 Oct 12, 2024
4f2f2a5
Debugging android CI failure
proneon267 Oct 13, 2024
c29ab39
Merge branch 'window_states' of https://github.com/proneon267/toga in…
proneon267 Oct 13, 2024
0d67322
Debugging android CI failure
proneon267 Oct 13, 2024
07e82f9
replaced with
proneon267 Oct 15, 2024
8be4d8d
replaced with
proneon267 Oct 15, 2024
1692a0d
added new method on window probe
proneon267 Oct 15, 2024
f8ee69d
Revert commented code
proneon267 Oct 15, 2024
b82b6d0
Revert
proneon267 Oct 15, 2024
247847e
Corrected probe method on android
proneon267 Oct 15, 2024
1b624ad
Merge branch 'beeware:main' into window_states
proneon267 Oct 16, 2024
5560e3d
Diagnosing macOS-arm64 failures
proneon267 Oct 16, 2024
a8fed19
Merge branch 'beeware:main' into window_states
proneon267 Oct 18, 2024
c44a28b
Testing potential fix
proneon267 Oct 18, 2024
fd59b4e
Testing potential fix
proneon267 Oct 19, 2024
1d45421
Testing potential fix
proneon267 Oct 19, 2024
d31b2d1
Auditing codebase to check for bugs
proneon267 Oct 20, 2024
8611fb9
Auditing codebase to check for bugs
proneon267 Oct 20, 2024
623f7bf
Auditing codebase to check for bugs
proneon267 Oct 20, 2024
172bdf2
Diagnosing cause of failure
proneon267 Oct 20, 2024
e6e7bff
Diagnosing cause of failure
proneon267 Oct 20, 2024
a9a952e
Diagnosing cause of failure
proneon267 Oct 20, 2024
bbb1298
Diagnosing cause of failure
proneon267 Oct 20, 2024
a17f5ae
Diagnosing cause of failure
proneon267 Oct 20, 2024
5776c4e
Diagnosing cause of failure
proneon267 Oct 20, 2024
612f410
Fixed test cleanup
proneon267 Oct 21, 2024
a91a9a3
Removed unused android code
proneon267 Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions android/src/toga_android/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import toga
from toga.command import Group, Separator
from toga.constants import WindowState
from toga.dialogs import InfoDialog

from .libs import events
Expand Down Expand Up @@ -314,14 +315,18 @@ def set_current_window(self, window):
pass

######################################################################
# Full screen control
# Presentation mode controls
######################################################################

def enter_full_screen(self, windows):
pass
def enter_presentation_mode(self, screen_window_dict):
for screen, window in screen_window_dict.items():
window._impl._before_presentation_mode_screen = window.screen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this variable in aid of? It doesn't appear to be used anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed it.

window.screen = screen
window._impl.set_window_state(WindowState.PRESENTATION)

def exit_full_screen(self, windows):
pass
def exit_presentation_mode(self):
# There is only a single window on android.
self.interface.main_window._impl.set_window_state(WindowState.NORMAL)
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved

######################################################################
# Platform-specific APIs
Expand Down
80 changes: 78 additions & 2 deletions android/src/toga_android/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from java import dynamic_proxy
from java.io import ByteArrayOutputStream

from toga.constants import WindowState
from toga.types import Position, Size

from .container import Container
Expand All @@ -36,6 +37,9 @@ def __init__(self, interface, title, position, size):
self.interface = interface
self.interface._impl = self
self._initial_title = title
# Use a shadow variable since the presence of ActionBar is not
# a reliable indicator for confirmation of presentation mode.
self._in_presentation_mode = False

######################################################################
# Window properties
Expand All @@ -47,6 +51,11 @@ def get_title(self):
def set_title(self, title):
self.app.native.setTitle(title)

def show_actionbar(self, show): # pragma: no cover
# The testbed can't create a simple window, so we can't test this.
# ActionBar is always hidden on Window.
pass

######################################################################
# Window lifecycle
######################################################################
Expand Down Expand Up @@ -137,8 +146,68 @@ def get_visible(self):
# Window state
######################################################################

def set_full_screen(self, is_full_screen):
self.interface.factory.not_implemented("Window.set_full_screen()")
def get_window_state(self):
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved
# `window.state` is called in `_close()`, which itself is
# sometimes called during certain stages when the app
# attribute may not exist. In such cases, return NORMAL.
if getattr(self, "app", None) is None:
return WindowState.NORMAL
decor_view = self.app.native.getWindow().getDecorView()
system_ui_flags = decor_view.getSystemUiVisibility()
if system_ui_flags & (
decor_view.SYSTEM_UI_FLAG_FULLSCREEN
| decor_view.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| decor_view.SYSTEM_UI_FLAG_IMMERSIVE
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved
):
if self._in_presentation_mode:
return WindowState.PRESENTATION
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved
else:
return WindowState.FULLSCREEN
return WindowState.NORMAL

def set_window_state(self, state):
current_state = self.get_window_state()
decor_view = self.app.native.getWindow().getDecorView()

if current_state == state:
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this should be an optimisation at the core level - it's something that will be common to every implementation.

Copy link
Contributor Author

@proneon267 proneon267 Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be done at the core level because we can't reliably determine the current state. Backends like Cocoa and GTK use non-blocking state APIs, meaning the state might be in in-between transition when checked. As a result, we could end up comparing against an outdated state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - but that means there are 2 possible interpretations of "window state" - the "current state", and the "state we're transitioning to". On blocking APIs, the two are always the same; on non-blocking, they might be different. This is easy enough to accomodate with a boolean argument to get_window_state() that allows the user to explicitly request "actual" state or "in progress" state.

For the purpose of the public API, I'd argue you always want the "state we're transitioning to" - as that is the answer that will be consistent across platforms, and will ensure that:

window.state = X
assert window.state == X

will always return the expected result. However, it would warrant a note on the state accessor to highlight that the value returned might not reflect the actual state immediately after making a request.

Copy link
Contributor Author

@proneon267 proneon267 Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified get_window_state() and moved same state checking to the core. I have also moved same state transition tests to the core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case - is the check right here still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really, since the Android API is blocking in nature and the internal API set_window_state() is not called internally anywhere on the implementation side.

It is only required on the non-blocking API backends like cocoa, as the internal API _apply_state() is called internally on the implementation side at different places.

So, I have removed it from the Android backend.


elif current_state != WindowState.NORMAL:
if current_state == WindowState.FULLSCREEN:
decor_view.setSystemUiVisibility(0)

else: # current_state == WindowState.PRESENTATION:
decor_view.setSystemUiVisibility(0)
self.show_actionbar(True)
self._in_presentation_mode = False

self.set_window_state(state)

else: # current_state == WindowState.NORMAL:
if state == WindowState.MAXIMIZED:
# no-op on Android.
pass

elif state == WindowState.MINIMIZED:
# no-op on Android.
pass

elif state == WindowState.FULLSCREEN:
decor_view.setSystemUiVisibility(
# These constants are all marked as deprecated as of API 30.
decor_view.SYSTEM_UI_FLAG_FULLSCREEN
| decor_view.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| decor_view.SYSTEM_UI_FLAG_IMMERSIVE
)

else: # state == WindowState.PRESENTATION:
decor_view.setSystemUiVisibility(
decor_view.SYSTEM_UI_FLAG_FULLSCREEN
| decor_view.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| decor_view.SYSTEM_UI_FLAG_IMMERSIVE
)
self.show_actionbar(False)
self._in_presentation_mode = True
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved

######################################################################
# Window capabilities
Expand Down Expand Up @@ -168,3 +237,10 @@ def create_toolbar(self):
# Toolbar items are configured as part of onPrepareOptionsMenu; trigger that
# handler.
self.app.native.invalidateOptionsMenu()

def show_actionbar(self, show):
actionbar = self.app.native.getSupportActionBar()
if show:
actionbar.show()
else:
actionbar.hide()
29 changes: 27 additions & 2 deletions android/tests_backend/window.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from androidx.appcompat import R as appcompat_R

from toga.constants import WindowState

from .dialogs import DialogsMixin
from .probe import BaseProbe


class WindowProbe(BaseProbe, DialogsMixin):
supports_fullscreen = True
supports_presentation = True

def __init__(self, app, window):
super().__init__(app)
self.native = self.app._impl.native
self.window = window

async def wait_for_window(self, message, minimize=False, full_screen=False):
await self.redraw(message)
async def wait_for_window(
self, message, minimize=False, full_screen=False, rapid_state_switching=False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the argument list gets too long, we try to break the arguments into separate lines, rather than the "all on one line indented" format. Black will auto-format this if you add a comma to the end of the argument list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, Thanks.

):
await self.redraw(
message, delay=0.1 if (full_screen or rapid_state_switching) else 0
)

@property
def content_size(self):
Expand All @@ -20,6 +29,22 @@ def content_size(self):
self.root_view.getHeight() / self.scale_factor,
)

def get_window_state(self):
decor_view = self.native.getWindow().getDecorView()
system_ui_flags = decor_view.getSystemUiVisibility()
if system_ui_flags & (
decor_view.SYSTEM_UI_FLAG_FULLSCREEN
| decor_view.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| decor_view.SYSTEM_UI_FLAG_IMMERSIVE
):
if self.window._impl._in_presentation_mode:
current_state = WindowState.PRESENTATION
else:
current_state = WindowState.FULLSCREEN
else:
current_state = WindowState.NORMAL
return current_state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this probe add anything. It's an literal reproduction of parts of the "real" get_window_state() method - what do we gain by the duplication?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is still current.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed it.


def _native_menu(self):
return self.native.findViewById(appcompat_R.id.action_bar).getMenu()

Expand Down
1 change: 1 addition & 0 deletions changes/1857.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Toga apps can now detect and set their window states including maximized, minimized, normal, full screen and presentation states.
1 change: 1 addition & 0 deletions changes/1857.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Full screen mode" on an app has been renamed "Presentation mode" to avoid the ambiguity with "full screen mode" on a window. The ``toga.App.enter_full_screen`` and ``toga.App.exit_full_screen`` APIs have been renamed ``toga.App.enter_presentation_mode`` and ``toga.App.exit_presentation_mode``, respectively. ```
26 changes: 15 additions & 11 deletions cocoa/src/toga_cocoa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import toga
from toga.command import Command, Group, Separator
from toga.constants import WindowState
from toga.handlers import NativeHandler

from .command import Command as CommandImpl, submenu_for_group
Expand Down Expand Up @@ -369,34 +370,37 @@ def set_current_window(self, window):
window._impl.native.makeKeyAndOrderFront(window._impl.native)

######################################################################
# Full screen control
# Presentation mode controls
######################################################################

def enter_full_screen(self, windows):
def enter_presentation_mode(self, screen_window_dict):
opts = NSMutableDictionary.alloc().init()
opts.setObject(
NSNumber.numberWithBool(True), forKey="NSFullScreenModeAllScreens"
)

for window, screen in zip(windows, NSScreen.screens):
for screen, window in screen_window_dict.items():
# The widgets are actually added to window._impl.container.native, instead of
# window.content._impl.native. And window._impl.native.contentView is
# window._impl.container.native. Hence, we need to go fullscreen on
# window._impl.container.native instead.
window._impl.container.native.enterFullScreenMode(screen, withOptions=opts)
# Going full screen causes the window content to be re-homed
# in a NSFullScreenWindow; teach the new parent window
# about its Toga representations.
window._impl.container.native.enterFullScreenMode(
screen._impl.native, withOptions=opts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above - we try not to use the "all on one lines but indented" when there's more than one argument. Add a comma to the end of the argument list and black-format to 1 argument per line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, Thanks.

)
# Going presentation mode causes the window content to be re-homed
# in a NSFullScreenWindow; teach the new parent window about its
# Toga representations.
window._impl.container.native.window._impl = window._impl
window._impl.container.native.window.interface = window
window.content.refresh()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I've asked this before, but this ticket has enough history that it's not easy to find a relevant comment...

Why is this logic in App, and not part of the set_window_state() handling for Window? It's literally per-window logic for performing per-window state changes - I can't see why there's a need to split up the logic, if only because it means there's a gap in Window.set_window_state() that would be picked up by a formal type analysis. If there is a reason, then the reason should be documented in a code comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the design discussion, we had discussed to keep presentation mode on the app in cocoa. But looking at it now, moving the code to window makes more sense. So, I'll move it.


def exit_full_screen(self, windows):
def exit_presentation_mode(self):
opts = NSMutableDictionary.alloc().init()
opts.setObject(
NSNumber.numberWithBool(True), forKey="NSFullScreenModeAllScreens"
)

for window in windows:
window._impl.container.native.exitFullScreenModeWithOptions(opts)
window.content.refresh()
for window in self.interface.windows:
if window.state == WindowState.PRESENTATION:
window._impl.container.native.exitFullScreenModeWithOptions(opts)
window.content.refresh()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how this mechanically exit presentation mode, but I don't see how this causes a change in the value of window.state. The windowDidExitFullScreen: selector will apply the pending state... but how is the pending state set? This either indicates (a) a gap in testing, or (b) the need for a comment explaining the workflow.

Also - as above, it's not clear why this isn't part of the set_window_state() implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved it to set_window_state().

Loading