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

Fix legacy color picker crash. #101513

Merged
merged 1 commit into from
Jan 14, 2025
Merged

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Jan 13, 2025

@bruvzg bruvzg added this to the 4.4 milestone Jan 13, 2025
@bruvzg bruvzg requested a review from a team as a code owner January 13, 2025 22:16
@WhalesState

This comment was marked as resolved.

@akien-mga
Copy link
Member

I confirm this fixes the issue for me with X11/XWayland, multi-window on Fedora 41 KDE Wayland.

image

There's still room for improvement possibly (weird resizing of the window with black bars on top and bottom, and the preview is either a black or white square with just a tiny preview of the actual color), but these predate #101266. It looks the same in 4.4.dev7.

For comparison, here's how it looks like in 4.3.stable:

image

@bruvzg
Copy link
Member Author

bruvzg commented Jan 13, 2025

Reverting the changes I have made to fix another bug is not a good fix.

What bug? Legacy picker is a working by picking pixels from pre-rendered texture, so there's no need to hide zoom preview, it can't obstruct anything. The #101266 only relevant for picking pixels from screen, which is never happening when this branch is used.

@WhalesState

This comment was marked as resolved.

@bruvzg
Copy link
Member Author

bruvzg commented Jan 13, 2025

I see a revert of #101266

It's not reverting it, only a tiny part that was wrong (legacy picker). Fix for real X11 is still there.

@WhalesState
Copy link
Contributor

I see a revert of #101266

It's not reverting it, only a tiny part that was wrong (legacy picker). Fix for real X11 is still there.

Sorry, I was confused, forgot that i have added it in two places :')

@akien-mga
Copy link
Member

akien-mga commented Jan 13, 2025

There seems to be an effect to the code being removed on my config (XWayland multi window, which is likely the most common configuration nowadays as most distros now default to Wayland and we default to X11 multi window).

If I just do what @WhalesState suggests, I get:

image

Which seems to be marginally better than what I have with this PR.

diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index f5be4c59a9..affbd7270a 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -1982,9 +1982,11 @@ void ColorPicker::_picker_texture_input(const Ref<InputEvent> &p_event) {
 			picker_preview_style_box_color->set_bg_color(picker_color);
 			picker_preview_style_box->set_bg_color(picker_color.get_luminance() < 0.5 ? Color(1.0f, 1.0f, 1.0f) : Color(0.0f, 0.0f, 0.0f));
 
-			Ref<AtlasTexture> atlas = picker_texture_zoom->get_texture();
-			if (atlas.is_valid()) {
-				atlas->set_region(Rect2i(ofs.x - 8, ofs.y - 8, 17, 17));
+			if (picker_texture_zoom) {
+				Ref<AtlasTexture> atlas = picker_texture_zoom->get_texture();
+				if (atlas.is_valid()) {
+					atlas->set_region(Rect2i(ofs.x - 8, ofs.y - 8, 17, 17));
+				}
 			}
 		}
 	}

It's still imperfect, as the preview square is weirdly offset to the bottom right of the pointer, but it's better.

I think we're starting to get confused by the terminology of legacy, single/multi window, embedded, and FEATURE_SCREEN_EXCLUDE_FROM_CAPTURE. The resulting code is quite a spaghetti mess we'll need to clean up one day...

@bruvzg bruvzg force-pushed the legacy_picker_fix branch from 93c8fc4 to 886d519 Compare January 13, 2025 22:40
@bruvzg
Copy link
Member Author

bruvzg commented Jan 13, 2025

Added missing part for XWayland (different texture setup branch from embedded legacy picker).

@akien-mga
Copy link
Member

That works great on XWayland multi-window:

image

My last nitpick is that there's still an unexpected shrinking of the window with a black bar at the bottom (the window was full screen before). The top black bar is understandable, that's where the window decorations would be, to compare with:

image

In 4.3 as shown above, I'm not getting this shrinking.

But that's outside the scope of this PR.

I'll test XWayland single-window, Wayland single-window, and real X11 multi/single-window.

@bruvzg
Copy link
Member Author

bruvzg commented Jan 13, 2025

I think we're starting to get confused by the terminology of legacy, single/multi window, embedded, and FEATURE_SCREEN_EXCLUDE_FROM_CAPTURE. The resulting code is quite a spaghetti mess we'll need to clean up one day...

For reference there are the following cases:

  • Embedded windows (on any platform) and Wayland (since it's currently singe window), use legacy picker with zoom preview.
  • FEATURE_SCREEN_EXCLUDE_FROM_CAPTURE and FEATURE_SCREEN_CAPTURE available (Windows and macOS) - native window picker with zoom preview.
  • Only FEATURE_SCREEN_CAPTURE available (native X11) - native window picker without zoom preview.
  • Neither is available (XWayland) - legacy picker with zoom preview (but instead of using window texture, it's using a separate window with texture composed of all app windows, that's what causing resizing of the window with black bars).

@akien-mga
Copy link
Member

  • XWayland single-window: It seems to work fine for the most part:

image

There's one minor issue though, when clicking the picker button, a full size copy of the editor window is instantiated as a new window. When moving the cursor, it then disappears and is replaced by the proper preview picker with zoom. Here's an example of what it looks like:

image

Maybe we should send a small mouse event to update the window contents?

  • Wayland single-window: Same behavior as XWayland single-window, including the full window copy.

image

Switching to X11 to test the other cases.

@WhalesState
Copy link
Contributor

Before doing a cleanup, I have those two PRs that fixes other Picker issues

@bruvzg bruvzg force-pushed the legacy_picker_fix branch from 886d519 to 34ebefd Compare January 13, 2025 23:07
@bruvzg
Copy link
Member Author

bruvzg commented Jan 13, 2025

There's one minor issue though, when clicking the picker button, a full size copy of the editor window is instantiated as a new window. When moving the cursor, it then disappears and is replaced by the proper preview picker with zoom. Here's an example of what it looks like:

I can't reproduce it, but I see what can cause it. Added set_region to force preview window size.

@akien-mga
Copy link
Member

akien-mga commented Jan 13, 2025

Switching to X11 to test the other cases.

Tested the last two commits (886d519 and 34ebefd).

  • Native X11 single-window:
    • 886d519: Same behavior as XWayland or Wayland single-window, including window copy.
    • 34ebefd: I confirm this fixes the full sized preview window duplicating the editor window. The only remaining annoyance I see is that the preview window is not instantiated where the picker button was clicked, but at its last known position (top-left corner initially, then wherever it was last clicked/canceled). When the mouse cursor is then moved, it warps to where the cursor is.

image

  • Native X11 multi-window: Same behavior in both commits. This has a preview flickering bug, with different offsets based on the mouse cursor. It's hard to capture in a screenshot, so I made a screen recording:
simplescreenrecorder-2025-01-14_00.15.17.mp4

That last bug also seems to exist in 4.4.dev7, albeit in a worst form where the full size preview with zoom flickers black and white rapidly (epilepsy warning if you test). Edit: That seems to be #100797.

@bruvzg
Copy link
Member Author

bruvzg commented Jan 13, 2025

X11 flicker bug is what #101485 should fix.

@akien-mga
Copy link
Member

akien-mga commented Jan 13, 2025

X11 flicker bug is what #101485 should fix.

Indeed, removing this line solves #100797 on native X11 multi-window:

image

I'd suggest adding it in this PR so it can fix #101412, #100797 and #101328 altogether. It's going to conflict with #101485 anyway so we may as well keep that PR only for code style improvements and fix the known bugs here.

diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 6024ea7b96..d1cff07a40 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -159,7 +159,6 @@ void ColorPicker::_notification(int p_what) {
                        }
                        DisplayServer *ds = DisplayServer::get_singleton();
                        Vector2 ofs = ds->mouse_get_position();
-                       picker_window->set_position(ofs - Vector2(28, 28));
 
                        Color c = DisplayServer::get_singleton()->screen_get_pixel(ofs);

With this change, the only remaining issues I've seen, for future issues/PRs:

  • Single-window (native X11): The preview window is not instantiated where the picker button was clicked, but at its last known position (top-left corner initially, then wherever it was last clicked/canceled). When the mouse cursor is then moved, it warps to where the cursor is.

  • Multi-window (native X11): Even with the flickering fixed, the way the cursor changes offset based on where it is in the window (seemingly based on the quadrant?) seems quite distracting to me. It would probably be better if it stayed always at the bottom right of the cursor, and only flipped to the left and/or top when nearing one of the 3 window corners where it would make sense.

@bruvzg bruvzg force-pushed the legacy_picker_fix branch from 34ebefd to 730495c Compare January 14, 2025 06:25
@bruvzg
Copy link
Member Author

bruvzg commented Jan 14, 2025

I'd suggest adding it in this PR

Done.

Also added initial position to the picker for single-window and changed native X11 preview to always have same offset from cursor except for the bottom and right border of the screen.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Tested successfully on Linux with all combinations (on Fedora 41 KDE):

  • Native X11 single-window
  • Native X11 multi-window
  • XWayland single-window
  • XWayland multi-window
  • Wayland single-window

@akien-mga akien-mga merged commit 3aa5b00 into godotengine:master Jan 14, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@bruvzg
Copy link
Member Author

bruvzg commented Jan 14, 2025

is that there's still an unexpected shrinking of the window with a black bar at the bottom (the window was full screen before). The top black bar is understandable, that's where the window decorations would be, to compare with:

For the reference, native portal picker (#101546) should work much better on XWayland and Wayland (also probably the only way to make screen wide color selection on Wayland).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants