From e87f8232f3e2b1303fb07581e77324eb54f9ed80 Mon Sep 17 00:00:00 2001 From: Jan Koprowski Date: Sat, 18 Jul 2026 14:18:48 +0000 Subject: [PATCH 1/4] Force Wayland when WSL 2 GUI enabled. --- gtk/src/toga_gtk/libs/gtk.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtk/src/toga_gtk/libs/gtk.py b/gtk/src/toga_gtk/libs/gtk.py index 0880b8d265..976540f7a3 100644 --- a/gtk/src/toga_gtk/libs/gtk.py +++ b/gtk/src/toga_gtk/libs/gtk.py @@ -98,7 +98,10 @@ "environment variable set correctly?" ) -IS_WAYLAND = not isinstance(Gdk.Display.get_default(), GdkX11.X11Display) +IS_WSL2_GUI_ENABLED = os.getenv("WSL2_GUI_APPS_ENABLED", "0") == "1" + +# Force Wayland on WSL2 if the WSL2 GUI apps feature is enabled +IS_WAYLAND = not isinstance(Gdk.Display.get_default(), GdkX11.X11Display) or IS_WSL2_GUI_ENABLED # The following imports will fail if the underlying libraries or their API wrappers # aren't installed; handle failure gracefully (see From 831c7bd92cacfadd5177e2ab87fb1fb0c0054c94 Mon Sep 17 00:00:00 2001 From: Jan Koprowski Date: Sat, 18 Jul 2026 17:45:42 +0000 Subject: [PATCH 2/4] Add change description. --- changes/4572.feature.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/4572.feature.md diff --git a/changes/4572.feature.md b/changes/4572.feature.md new file mode 100644 index 0000000000..97b1406526 --- /dev/null +++ b/changes/4572.feature.md @@ -0,0 +1 @@ +Force Wayland on WSL2 if the WSL2 GUI apps feature is enabled \ No newline at end of file From 0acb8cf19d1d20776dd9181fc205db2c880e4547 Mon Sep 17 00:00:00 2001 From: Jan Koprowski Date: Sat, 18 Jul 2026 18:27:54 +0000 Subject: [PATCH 3/4] Fix the lines. --- changes/4572.feature.md | 2 +- gtk/src/toga_gtk/libs/gtk.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/changes/4572.feature.md b/changes/4572.feature.md index 97b1406526..a800dc88ad 100644 --- a/changes/4572.feature.md +++ b/changes/4572.feature.md @@ -1 +1 @@ -Force Wayland on WSL2 if the WSL2 GUI apps feature is enabled \ No newline at end of file +Force Wayland on WSL2 if the WSL2 GUI apps feature is enabled diff --git a/gtk/src/toga_gtk/libs/gtk.py b/gtk/src/toga_gtk/libs/gtk.py index 976540f7a3..5f260c7633 100644 --- a/gtk/src/toga_gtk/libs/gtk.py +++ b/gtk/src/toga_gtk/libs/gtk.py @@ -101,7 +101,8 @@ IS_WSL2_GUI_ENABLED = os.getenv("WSL2_GUI_APPS_ENABLED", "0") == "1" # Force Wayland on WSL2 if the WSL2 GUI apps feature is enabled -IS_WAYLAND = not isinstance(Gdk.Display.get_default(), GdkX11.X11Display) or IS_WSL2_GUI_ENABLED +IS_WAYLAND = (not isinstance(Gdk.Display.get_default(), GdkX11.X11Display) + or IS_WSL2_GUI_ENABLED) # The following imports will fail if the underlying libraries or their API wrappers # aren't installed; handle failure gracefully (see From ba1832702ab877a59229d35a97e863d6f86203e4 Mon Sep 17 00:00:00 2001 From: Jan Koprowski Date: Sat, 18 Jul 2026 18:34:14 +0000 Subject: [PATCH 4/4] Ruff fixes. --- gtk/src/toga_gtk/libs/gtk.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gtk/src/toga_gtk/libs/gtk.py b/gtk/src/toga_gtk/libs/gtk.py index 5f260c7633..ec89812182 100644 --- a/gtk/src/toga_gtk/libs/gtk.py +++ b/gtk/src/toga_gtk/libs/gtk.py @@ -101,8 +101,9 @@ IS_WSL2_GUI_ENABLED = os.getenv("WSL2_GUI_APPS_ENABLED", "0") == "1" # Force Wayland on WSL2 if the WSL2 GUI apps feature is enabled -IS_WAYLAND = (not isinstance(Gdk.Display.get_default(), GdkX11.X11Display) - or IS_WSL2_GUI_ENABLED) +IS_WAYLAND = ( + not isinstance(Gdk.Display.get_default(), GdkX11.X11Display) or IS_WSL2_GUI_ENABLED +) # The following imports will fail if the underlying libraries or their API wrappers # aren't installed; handle failure gracefully (see