Skip to content

Gtk4 + libadwaita migration - #1137

Open
xiaoqiangwang wants to merge 10 commits into
AravisProject:mainfrom
xiaoqiangwang:gtk4_migration
Open

xiaoqiangwang wants to merge 10 commits into
AravisProject:mainfrom
xiaoqiangwang:gtk4_migration

Conversation

@xiaoqiangwang

Copy link
Copy Markdown
Contributor

Port the viewer to GTK 4 and libadwaita

Build: gtk+-3.0 >= 3.12 becomes gtk4 >= 4.12 and libadwaita-1 >= 1.4, so the viewer now needs Ubuntu 24.04 / Fedora 40 / RHEL 9.4 or later. CI dependency lists and building.md updated to match.

Widgets:

Before After
GtkTreeView + GtkListStore + cell renderers GtkColumnView over a sortable model (arvcameralist.c)
GtkComboBox/GtkComboBoxText GtkDropDown
GtkHScale, GtkToolbar, GtkToolButton GtkScale, GtkBox, GtkButton
GtkApplicationWindow + header bar AdwApplicationWindow + AdwToolbarView + AdwHeaderBar/AdwWindowTitle

Video display: gtksink is a GTK 3 widget and could not be embedded in a GTK 4 window, so the viewer had no working display path. A new sink module (arvvideosink.c) chooses a renderer at runtime: gtk4paintablesink (gst-plugins-rs, GPU) when available, otherwise appsink with a single-frame slot painted from a tick callback. gst-plugins-rs stays optional — nothing is required at build time.

Snapshot saving: gtk_dialog_run() no longer exists, so the save flow is rebuilt on GtkFileDialog's callback API.

Result: the viewer builds with no deprecation warnings.

Behaviour changes

  • YCbCr422_8 and other packed YUV formats now display: the CPU sink states the formats it can draw, so videoconvert converts them instead of passing them through.

Testing

  • All four CI workflows pass (Linux, macOS, MinGW, MSVC/Conan).
  • Verified on Linux, Windows and macOS with the fake cameras: device list, camera selection, window close, snapshot save, CPU sink, and YUV conversion.
  • GPU sink verified on Fedora 45.

Known gaps

  • Multipart component selection is untested — neither fake camera exposes components.

xiaoqiangwang and others added 10 commits November 24, 2026 20:04
Migrate the viewer's build, entry point and UI definition to GTK4 and
libadwaita, targeting RHEL 9 (GTK 4.12, libadwaita 1.4).

Build:
- require libadwaita-1 >= 1.4 and gtk4 >= 4.12 instead of gtk+-3.0.

main.c:
- adw_init() replaces gtk_init(), which no longer takes argc/argv.
- gtk_icon_theme_get_for_display() replaces gtk_icon_theme_get_default().
- drop the gtk_get_option_group() registration; GTK4 has no options to add.
- drop the XInitThreads()/gstgldisplay_x11 block, already compiled out.

arvviewer.c:
- ArvViewer derives from AdwApplication.

arv-viewer.ui:
- <packing> is gone in GTK4. Grid children move to <layout>
  (left-attach/top-attach -> column/row), box children to
  hexpand/vexpand, headerbar children to <child type="end">.
- GtkHScale -> GtkScale + orientation, GtkToolbar -> GtkBox,
  GtkToolButton -> GtkButton.
- remove properties dropped in GTK4: popover::relative-to,
  use-action-appearance, shadow-type, draw-indicator,
  always-show-image, label-yalign, and on spin buttons only,
  invisible-char and the icon-activatable flags (GtkEntry keeps them).
- GtkApplicationWindow + titlebar -> AdwApplicationWindow, which has no
  titlebar slot, so the headerbar becomes AdwToolbarView's top bar and
  the existing overlay becomes its content.
- GtkHeaderBar -> AdwHeaderBar with an AdwWindowTitle, restoring the
  subtitle that GTK4's header bar dropped.

The viewer does not build yet: arvviewer.c still calls removed GTK3 API
(GtkToolButton, gtk_entry_get_text, gtk_dialog_run, gtk_container_*,
gtk_header_bar_set_title, ...). Those are converted next.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Continue the GTK4/libadwaita migration: convert the widget API that no
longer compiles, keeping the GtkTreeView/GtkComboBox stack as-is for now.

Casts and callbacks:
- GtkCheckButton no longer derives from GtkToggleButton, so component_check
  uses gtk_check_button_get/set_active() and its callback takes
  GtkCheckButton. The GtkToggleButton casts were bogus at runtime and
  tripped type assertions as soon as a camera was selected.
- GtkToolButton is gone: the refresh/video/back callbacks take GtkButton.
- arv_viewer_quit_cb returns gboolean for GtkWindow::close-request.

Entry and focus:
- gtk_entry_get/set_text() -> gtk_editable_get/set_text().
- frame rate commits from notify::has-focus rather than the removed
  GdkEventFocus/focus-out-event, folding the activate and focus-out
  handlers into one.

Containers and visibility:
- GtkFrame holds a single child: gtk_frame_set_child()/gtk_frame_get_child()
  replace gtk_container_add()/gtk_container_foreach(), and children are
  removed with gtk_widget_unparent().
- gtk_widget_show_all() is gone; widgets are visible by default and the
  window is presented explicitly. trigger_combobox is hidden with
  set_visible() instead of no-show-all.
- the window is added to the application before being presented. With no
  window owned by the application, GApplication quits immediately.

Titles:
- Header bar title and subtitle go through AdwWindowTitle on the
  window_title widget, restoring the subtitle GTK4's header bar dropped.

snapshot_cb is left as an empty stub pending a rewrite for GtkFileDialog,
which leaves arv_viewer_show_notification() and _save_gst_sample_to_file()
unused until then.

Co-Authored-By: Claude Code <noreply@anthropic.com>
gtksink is a GTK3 widget and cannot be embedded in a GTK4 window, so the
viewer had no working display path. Replace it with a sink module that
picks a renderer at runtime:

- gtk4paintablesink (gst-plugins-rs), when the element is available. The
  sink exposes a GdkPaintable which a GtkPicture renders on the GPU. GTK
  repaints on its frame clock, so when frames arrive faster than the
  display refreshes only the newest one is shown.

- appsink otherwise. The streaming thread copies the newest frame into a
  single slot and a tick callback on the GtkPicture builds a
  GdkMemoryTexture only when the sequence number changed. Decode rate and
  paint rate are decoupled, so a slow UI skips frames instead of queueing
  them.

Both paths present through a GtkPicture and keep sync=FALSE, preserving
the previous gtksink behaviour: the sink never drops for lateness, and
framerate excess is handled upstream by appsrc.

The pixel format is derived from the negotiated caps rather than assumed.
An unmatched format used to fall through to R8G8B8, which made
gdk_memory_texture_new() fail on GRAY8 with a stride mismatch. GRAY8 maps
to GDK_MEMORY_G8 and unknown formats now warn instead of silently
producing a broken texture.

Teardown happens entirely in arv_video_sink_free(), in dependency order:
stop the tick callback, disconnect and release the sink element, then
detach the picture through gtk_frame_set_child(). Three crashes came from
getting this wrong: the picture was freed before its tick callback was
removed, the element dangled because the pipeline was unreffed first, and
GtkFrame kept a cached child pointer after a bare gtk_widget_unparent().
The sink now holds its own reference on the element, and remove_widget()
is gone.

Co-Authored-By: Claude Code <noreply@anthropic.com>
gtk_dialog_run() is gone in GTK4, so the snapshot dialog cannot block and
return a response. Reimplement the save flow around GtkFileDialog, which
reports its result through a callback.

snapshot_cb() keeps everything up to and including launching the dialog:
gathering the sample and buffer, building the default filename, and
assembling the filters. snapshot_save_finish_cb() resolves the chosen
file and then performs the save that used to follow gtk_dialog_run().
The PNG/JPEG/raw dispatch and the failure notification are unchanged.

Dialog API mapping:
- gtk_file_chooser_dialog_new        -> gtk_file_dialog_new
- set_do_overwrite_confirmation      -> dropped, GtkFileDialog always asks
- set_filename + set_current_name    -> set_initial_folder + set_initial_name
- add_filter + set_filter            -> set_filters + set_default_filter
- gtk_dialog_run + get_filename      -> save_finish + g_file_get_path
- gtk_widget_destroy                 -> dialog is unreffed once the pending
                                        operation has taken its own reference

Two behaviours the deprecated API gave for free are now explicit:
cancelling the dialog is filtered out with GTK_DIALOG_ERROR_DISMISSED so
it does not raise a failure notification, and a non-local save location
(g_file_get_path() returning NULL) is reported rather than passed on to
the save helpers.

The sample and buffer are attached to the dialog with
g_object_set_data_full(), which releases them with it, instead of being
held in the viewer.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The viewer now builds against gtk4 >= 4.12 and libadwaita-1 >= 1.4, so the
CI dependency lists and the build instructions no longer match what meson
looks for.

CI:
- linux: libgtk-3-dev -> libgtk-4-dev and libadwaita-1-dev.
- macos: add gtk4 and libadwaita, which were missing entirely; the viewer
  target could not have configured.
- mingw: gtk3 -> gtk4 and libadwaita. Both are built for ucrt64 and
  clang64, which is what the matrix uses.

docs:
- README: the viewer depends on GTK 4 and libadwaita. Note that the GPU
  renderer comes from gst-plugins-rs and is optional at build time, since
  the sink is chosen at runtime.
- building.md: update the dependency commands for Ubuntu, Fedora, macOS
  and crossroad. Raise the Ubuntu and Fedora sections to releases that
  actually ship a new enough GTK 4, and say why.

Co-Authored-By: Claude Code <noreply@anthropic.com>
GtkTreeView, GtkListStore and the cell renderers are deprecated since
GTK 4.10. Replace them with the list widgets, in a module of their own:

  GListStore(ArvCameraItem) -> GtkSortListModel -> GtkSingleSelection
    -> GtkColumnView

The columns are Vendor, Model (protocol icon plus name) and Serial, each
sortable by clicking its header. Sorting needs the column view's own
sorter attached to the sort model, not just a sorter on the column.

The list lives in arvcameralist.{c,h}, which keeps the item type private:
callers populate it by field and read the selection back as a device id.

Two bugs found while porting:

- GtkSingleSelection auto-selects the first row as the list fills, and
  that happens before the notify::selected handler is connected. The
  selection already reads 0 when the user picks that row, so no change is
  emitted and start_camera() never runs: with a single camera nothing
  could be opened. autoselect is now off, so the list starts empty and
  the user's first pick is a change.

- Closing the window segfaulted in finalize(). GtkSingleSelection does
  not take a reference on the model it is given, yet frees it when
  disposed, as the sort model does with the store. Both were therefore
  released twice, the second time through a dangling pointer. The models
  are now owned by the chain above them and only the references taken by
  the viewer are dropped. The factories follow the same rule: the column
  view frees them when it is torn down, so they are never unref'd here.

Co-Authored-By: Claude Code <noreply@anthropic.com>
GtkComboBoxText and the cell renderers are deprecated since GTK 4.10. The
pixel format list becomes a GtkDropDown over a GListStore of
ArvPixelFormatItem, which carries the name and whether GStreamer can
display it.

An entry the viewer cannot show is greyed out and cannot be picked. The
list item's own selectable property does the refusing: GtkDropDown
declines to adopt an unselectable item even when one is pushed through
the selection model, so no selection model subclass is needed.

GtkDropDown takes two factories, and this needs both: the factory draws
the button's label, while the rows inside the popup come from
list-factory. With only the first set the popup rows are drawn by the
default factory and nothing greys.

Packed YUV was reaching the CPU renderer unchanged and coming out
garbled: an appsink caps of ANY gives videoconvert nothing to negotiate
toward, so YCbCr422_8 (YUY2) arrived as-is and had no GdkMemoryFormat
mapping. The sink now states the formats it can draw, and videoconvert
converts the rest first. Measured through the pipeline: YUY2 and UYVY
become RGB, while GRAY8, RGB and BGR pass through untouched.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The last deprecated widget in the viewer. GtkComboBoxText and its cell
renderer give way to a GtkDropDown over a GtkStringList.

Unlike the pixel format list there is no state to carry per entry: every
component a camera offers is selectable, so the model is a list of names
rather than objects, and GtkDropDown supplies its own factory for a
GtkStringList. The three gtk_combo_box_text_get_active_text() call sites
collapse into component_combo_get_active().

This clears the last of the GTK 4.10 deprecations: the viewer now builds
with no deprecation warnings at all.

Co-Authored-By: Claude Code <noreply@anthropic.com>
A GtkComboBox the viewer only ever looked up in order to hide it, a
leftover from when the widget existed to drive triggering. Nothing read
its value or connected to it, and it was the last deprecated widget class
in the .ui file.

Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants