Skip to content

scopes: updates to be GTK4 ready#20465

Merged
TurboGit merged 5 commits intodarktable-org:masterfrom
dtorop:scopes-gtk4-ready
Mar 11, 2026
Merged

scopes: updates to be GTK4 ready#20465
TurboGit merged 5 commits intodarktable-org:masterfrom
dtorop:scopes-gtk4-ready

Conversation

@dtorop
Copy link
Contributor

@dtorop dtorop commented Mar 8, 2026

  • Use dt_gui_{h,v}box() and dt_gui_box_add() for box init/packing
  • Use event controllers and gestures. In case of toggle buttons, capture clicked event (which exists in GTK 4) rather than button-press-event.
  • Update bauhaus scrolling to use event controller (previously it used a GDK event, presumably because scopes sent this via exposure)
  • Be consistent in calls to dt_dev_exposure_handle_event() and always pass an event controller. Previously, in the case of scrolling, it would receive a GDK event.
  • Add new helper function dt_gui_connect_scroll()
  • Simplify the math when handling scroll events which adjust the color harmony guides.
  • Fix two memory leaks: GdkEvent retrieved by gtk_get_current_event() without corresponding call to gdk_event_free().

This PR should produce no user-visible changes, but will allow for more maintainable and forward-compatible code.

There's a lot of finicky bits in bauhaus, particular about mapping events to actions. I tested everything I could find about this, but the biggest risk of this PR would be causing regressions there.

dtorop added 4 commits March 7, 2026 23:30
- Use dt_gui_{h,v}box() instead of gtk_box_new()
- Use dt_gui_box_add() instead of gtk_box_pack_{start,end}()
To make GTK 4 ready.

Be a bit hacky and reset the propagation phase as
the default phase in dt_gui_connect_motion() doesn't. Pull the
GdkEvent by hand to fix edge case of when user clicks between buttons
and a spurious leave event occurs.

Also clean up math in color harmony scroll behaviors -- replace
if/else with one-liner modulos.

Also reorder the _drawable_button_{press,release} functions to align
with order in which they are called.
Convert bauhaus _widget_scroll() to use GtkEventControllerScroll
instead of GdkEventScroll.

- If ignoring scroll, pass it on to the scrolled window.
- Use delta from event controller, not from raw event
- In scopes use discrete scroll events from controller, which aligns
  with how bauhaus does things and gives fine results

Pass a GtkEventController to handle_event aka
dt_dev_exposure_handle_event().

Also: Fix bauhaus memory leak by freeing events returned by
gtk_get_current_event(). See:
https://docs.gtk.org/gtk3/func.get_current_event.html, "The caller of
the function takes ownership of the data, and is responsible for
freeing it."

Also: new dt_gui_connect_scroll() helper function.
- Use GtkGesture to handle clicking of mode buttons.

- Use click event for color harmony buttons, Instead of
  button-press-event.

- Use event controller for enter/leave color harmony buttons
Copy link
Member

@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

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

Different issues with this PR:

  • the currently selected harmony icon is not light-up.
  • sometime the selected harmony icon is not light-up.
  • sometime the selected harmony is not displayed.
  • sometime I have two harmony icons displayed.
  • changing the vectorscope side crashed dt.

To reproduce: click on icons on the histogram display

@dtorop
Copy link
Contributor Author

dtorop commented Mar 9, 2026

Different issues with this PR:

Drat! I'm not seeing this here. Is this occurring on the split ("waveform/vectorscope") mode or in the vectorscope-only mode? I'm trying to think out what other differences I could have in my setup which isn't allowing me to see this...

changing the vectorscope side crashed dt

Is there a helpful backtrace, maybe that could be a clue?

@TurboGit
Copy link
Member

TurboGit commented Mar 9, 2026

I'm not seeing this here. Is this occurring on the split ("waveform/vectorscope") mode or in the vectorscope-only mode?

It was on all modes I think for the vectorscope issue.

I just tried again and it is a bit better, now I have the selected the harmony icon but still not the current histogram mode icon. And switching the vectorscope mode I had a freeze (5s) when clicking on the Luv icon... but I was not able to reproduce starting Darktable a second time to do a video.

So something fishy to me, possible some memory corruption.

Is there a helpful backtrace, maybe that could be a clue?

No, probably a loop somewhere as I had to hard kill Darktable process.

@dtorop
Copy link
Contributor Author

dtorop commented Mar 9, 2026

So something fishy to me, possible some memory corruption.

Quite possible. I'll look at things more carefully.

Do you recall how far you were able to get before failure? E.g. any of:

  1. Switching scope modes
  2. Switching vectorscope mode to get to RYB
  3. Switching color harmony overlays within RYB
  4. Scrolling in histogram or waveform to change exposure
  5. Clicking/dragging in histogram or waveform to change exposure

Not to ask you to bisect, but I believe that the first commit, d0992aa, should be utterly harmless. I'm assuming one of the later commits is the problem.

I don't think the current implementation of the color harmony buttons is ideal (I'd rather see it a combobox than a homegrown radiobutton/scrolling hybrid), but I'd still rather have it not crash!

@TurboGit
Copy link
Member

TurboGit commented Mar 9, 2026

Do you recall how far you were able to get before failure?

Maybe 10 clicks, and probably doing at least once the 5 points above.

Are you at least able to reproduce the current histogram selected icon no being highlighted? This is 100% reproducible on my side. The first fly over shows it selected but as soon as I select another histogram the status is lost.

@dtorop
Copy link
Contributor Author

dtorop commented Mar 9, 2026

Are you at least able to reproduce the current histogram selected icon no being highlighted? This is 100% reproducible on my side. The first fly over shows it selected but as soon as I select another histogram the status is lost.

You're right, I can reproduce this! So far as I can see, 215911f is OK, but the final commit, 01e7145 broke this when I switched from using "button-press-event" to "clicked" event. I think there's also something wrong in that commit about handling of color harmony buttons. More in a bit...

(I still can't reproduce crash/loop or problems with color harmony buttons.)

- Handle mode and color harmony buttons via toggled handler. This is
  simpler than using gestures, and actually works.

- Use signal blocking to group mode toggle buttons: Create a
  radio-button-like behavior of the GtkDarktableToggleButton group which
  allows for choosing scope modes. Whenever a user clicks on a mode/harmony
  toggle button, set the prior mode toggle button to inactive. When a
  user clicks on the currently selected mode toggle button, keep it
  active. When user clicks on the currently selected harmony button,
  turn off the harmony overlays for now. Use signal blocking to avoid
  toggle-handler re-entering.

- Move mode activate button widgets out of own array and into
  dt_scopes_mode_t.

- Rename "waveform/vectorscope" mode to "split". It is less verbose,
  and more accurate to the intent of split mode (which can be generic
  for multiple modes).

- Eliminate crash at startup when showing vectorscope or split.  At
  startup there is no current image, so don't store the color harmony
  guide state to NULL memory.

- Don't use offset indexes into color_harmony_button array, just
  keep first element unused.

- Don't use color_harmony_old and motion events for mouseover preview
  of color harmonies, instead take advantage of widget prelight
  behavior.

- Now that scope scroll events are discrete, simplify the scrolling
  code.

- Eliminate _color_harmony_button_on() helper. It is a relic of the
  prior signal architecture. We know what button we're turning off/on so
  don't have to loop through all buttons.

- Use gtk_toggle_button_set_active() when harmony overlay (in
  scrolling or cycling or when loading new image settings). This will
  automatically turn off prior harmony. Need a bit of a special case to
  go to no harmony, in which case toggle off prior harmony.

- Merge _update_color_harmony_gui() into _vec_signal_image_changed()
  and don't call it from _vec_mode_enter() as it isn't needed there.

- In gui_init(), don't set the active mode until we have initialized
  more of the mode. Otherwise GTK will reference not-yet-extant widgets.

- Don't bother to set initial harmony button setting as it will always
  change when load image.

This should be fairly GTK4 ready, while using modern GTK3. For GTK4,
gtk_toggle_button_set_group() will allow for getting rid of the
signal blocking code.
@dtorop dtorop requested a review from TurboGit March 11, 2026 01:56
@dtorop
Copy link
Contributor Author

dtorop commented Mar 11, 2026

Many fixes in the most recent commit. I can't guarantee that there might be other subtle errors, but this should be an improvement.

Copy link
Member

@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

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

Thanks, looking good and I have not been able to crash it!

@TurboGit TurboGit merged commit b3317ff into darktable-org:master Mar 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants