Setting "GTK Legacy theme" in Snap application


I’ve been trying to look around a bit into our Snap build of Graphs. One issue is that Ubuntu forces the Yaru theme over the application by default cough, which makes our carefully crafted default theme stick out like a sore thumb.

Partly the icons take the Yaru theme ones instead of the default GNOME icons. Which I personally find pretty annoying, it can be an accessibility issue if the metaphors change, but personally I really don’t like them either. But I can live with that, especially as it’s at least consistent with the rest of the icons in Ubuntu.

But a bigger issue is that the colours are off. Which becomes apparant in dark mode. If you look at the graph canvas itself, you can see that there’s a clear black border around the canvas:

For reference, this is how it should look like:

I noticed however, that setting “Adwaita” as legacy GTK theme in GNOME Tweaks actually solves this issue, and then indeed the correct style sheets are taken (even though it’s libadwaita and GTK4, so I’m not 100% sure why it’s affected by the legacy style which should theme GTK3 afaik). So I was wondering if it’s possible to set this legacy GTK theme in the snapcraft.yaml so the Snapcraft build can be consistent with how it is designed to look?

Note that just setting GTK_THEME=Adwaita-dark doesn’t help, that just tries to force the old GTK3 style over Libadwaita, making it look terrible. That’s explicitly not what I want. What I want is to set the general GTK theme in the application to follow the same stylesheet as stock GNOME (so it should look like the middle screenshot). See the result of setting the GTK_THEME from the CLI:

I’ve been looking a bit more, and based on this, would it make sense to bundle the Adwaita themes as slots like this?

    interface: content
    content: desktop-theme
      - /usr/share/themes/Adwaita
    interface: content
    content: desktop-theme-icon
      - /usr/share/icons/Adwaita
    interface: dbus
    bus: session
    name: se.sjoerd.Graphs

Would more changes be necessary? For example should the theme also be included in the parts? Or somehow in the part of the main application to tell it to actually use it? If so, how would I go around doing that as I cannot really find any references for this.

I’m running Fedora Silverblue myself, which doesn’t work nicely with Snap, so I am running Ubuntu from a VM. For some reason, it doesn’t properly build the snapcraft.yml file (it misses the cairo modules for some reason), while it works perfectly fine in the Snapcraft store and in our Github actions. Since libadwaita 1.4 is still not released in the Sdk, I cannot test it in the edge channel of the Snap package either. So I can’t really test if the above code is working at this very moment, hence my question if this would be the right way to go.

For reference, here’s what the entire snapcraft.yaml manifest looks like currently (without any theme overrides):

name: graphs # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
adopt-info: graphs
grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots
compression: lzo
license: GPL-3.0
  - build-on: amd64
  - build-on: arm64

    interface: dbus
    bus: session
    name: se.sjoerd.Graphs

    source-tag: 'v0.10.0'
    plugin: meson
      - --prefix=/usr
    override-prime: |
      echo 'Skip'
    after: [ blueprint-compiler ]
    # See 'snapcraft plugins'
    plugin: meson
    #source-tag: 'v1.5.2'
      - --prefix=/snap/graphs/current/usr
      - --buildtype=release
      - PYTHONPATH: $CRAFT_STAGE/usr/lib/python3/dist-packages:$PYTHONPATH
      - GI_TYPELIB_PATH: /snap/gnome-42-2204-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET/girepository-1.0:/snap/gnome-42-2204-sdk/current/usr/lib/girepository-1.0
    override-pull: |
      craftctl default
      patch -p1 < $CRAFT_PROJECT_DIR/snap/graphs.patch
    override-build: |
      craftctl default
      pip install --prefix=$CRAFT_PART_INSTALL/usr matplotlib==3.8.0
      pip install --prefix=$CRAFT_PART_INSTALL/usr scipy==1.11.2
      sed -e '1c#!/usr/bin/env python3' -i ${CRAFT_PART_INSTALL}/snap/graphs/current/usr/bin/graphs
      sed -e '1c#!/usr/bin/python3' -i $CRAFT_PART_INSTALL/usr/local/bin/*
      mkdir -p $CRAFT_PART_INSTALL/meta/gui
      cp -r $CRAFT_PART_INSTALL/snap/graphs/current/usr/share/icons $CRAFT_PART_INSTALL/meta/gui/
      for i in `find $CRAFT_PART_INSTALL/meta/gui/icons -name "*.svg" -o -name "*.png"`; do
        mv $i "`dirname $i`/snap.$CRAFT_PROJECT_NAME.`basename $i`"
      snap/graphs/current/usr: usr
      usr/local: usr
      usr/lib/python3: usr/lib/python3.10
    parse-info: [usr/share/appdata/se.sjoerd.Graphs.appdata.xml]
      - meta/*
      - usr/bin/graphs
      - usr/lib/python3.10/
      - usr/share/app*
      - usr/share/i*
      - usr/share/l*
      - usr/share/g*
    command: usr/bin/graphs
    desktop: usr/share/applications/se.sjoerd.Graphs.desktop
    common-id: se.sjoerd.Graphs
      PYTHONPATH: $SNAP/usr/lib/python3.10/dist-packages:$PYTHONPATH
    extensions: [gnome]