Click here to Skip to main content
15,881,413 members
Articles / Desktop Programming / X11
Tip/Trick

Configuring Ubuntu 21.04 for Wayland and Flutter Desktop

Rate me:
Please Sign up or sign in to vote.
4.11/5 (2 votes)
6 Oct 2021CPOL3 min read 13.4K   2  
Moving from X11 with NVIDIA drivers to Wayland may require more configuration
Wayland will be disabled if NVIDIA graphics drivers are detected.

Ubuntu 21.04 Touts Flutter and Wayland

On April 22nd, Ubuntu 21.04 was announced with some hype around delivering "Wayland and Flutter for smoother graphics and clean, beautiful, design-led cross-platform development." As I use Flutter 2.0 regularly, including Flutter on the desktop, I decided to upgrade my Ubuntu 20.04 workstation to 21.04 with do_release_upgrade -d. Most people shouldn't have to add the -d for the development release. Please try it first without the -d. Although I did the upgrade on April 25, after 21.04 was publicly available, I needed to add the -d on my system.

I first upgraded to 20.10, then upgraded to 21.04. Although it took a while to upgrade all the different components, the upgrade went fine.

Problems Switching to Wayland

Although I could log into gdm3, it looked like I was using x11 and not Wayland.

$ echo $XDG_SESSION_TYPE

would return x11, not the expected wayland.

Additionally, I would not get the gear icon on the login screen to choose between the Ubuntu Wayland and X.org. On 21.04, it seems like Wayland is default and just called ubuntu on the gear of the login screen. After my upgrade, the gear did not even appear.

Fixing the Problem

gdm3 custom.conf

Initially, I thought I could fix the problem by modifying /etc/gdm3/custom.conf.

There is a nice comment that sources like commenting out WaylandEnable=false will cause Wayland to be enabled.

# GDM configuration storage
#
# See /usr/share/gdm/gdm.schemas for a list of available options.

[daemon]
# Uncomment the line below to force the login screen to use Xorg
# WaylandEnable=false

# Enabling automatic login
#  AutomaticLoginEnable = true
#  AutomaticLogin = user1

After commenting out WaylandEnable=false, I rebooted my computer, but I still did not get Wayland to work.

gdm udev Rules

Even after I purged all my nvidia driver files, I was still not able to enable Wayland. I then edited /usr/lib/udev/rules.d/61-gdm.rules and commented out the check for DRIVER=="nvidia".

cd /usr/lib/udev/rules.d/

$ sudo vi 61-gdm.rules

# disable Wayland on Hi1710 chipsets
ATTR{vendor}=="0x19e5", ATTR{device}=="0x1711", RUN+="/usr/libexec/gdm-disable-wayland"

# disable Wayland when using the proprietary nvidia driver
# DRIVER=="nvidia", RUN+="/usr/libexec/gdm-disable-wayland"

# disable Wayland if modesetting is disabled
IMPORT{cmdline}="nomodeset", RUN+="/usr/libexec/gdm-disable-wayland"

After rebooting the system, I was able to change into Wayland.

Now, checking on the XDG_SESSION_TYPE shows wayland as expected.

Testing Flutter Desktop

My whole goal of enabling Wayland was to test Flutter desktop as touted by Canonical CEO Mark Shuttleworth in the Ubuntu 21.04 announcement.

I created a sample project called desk. I used the automated dart migrate command to start using Dart 2.12.0 with sound null safety for Flutter 2.0.

$ flutter create --platforms=linux desk
cd desk
dart migrate --apply-changes 
flutter run

The default desktop app runs great on Linux.

I next tested a more complex app for the RICOH THETA 360 camera that I had originally built on Windows.

The app uses 23MP 360 degree images that are around 8MB in size. The app runs and the 360 image can be navigated. However, the graphics performance feels marginally smoother on Windows 10.

I'm running an NVIDIA GTX 950Ti with X.org driver and an Intel i7-6800K CPU.

The NVIDIA 470 Linux driver is supposed to have more Wayland support. However, it's not available right now. I did not test the 465.31 version released on May 18, 2021.

OBS Screen Sharing

OBS 27 released in early June 2021 adds support for Wayland screen capture. The test below was done with OBS 27.0.1, released June 11, 2021. 

obs screenshot

The screen capture should use PipeWire.

Image 2

Summary

Building Flutter Linux desktop apps works with Wayland. However, I can't see any performance or graphic gains initially. I intend to keep using Wayland with Flutter and plan to keep an eye on the status of the NVIDIA drivers for future hardware acceleration improvements.

Updating to 21.10 Impish Indri

in /usr/lib/dev/rules/d/61-gdm.rules

# disable wayland if nvidia-drm modeset is not enabled
ATTR{parameters/modeset}!="Y", GOTO="gdm_disable_wayland"
# disable wayland for nvidia drivers versions lower than 470
ATTR{version}=="4[0-6][0-9].*|[0-3][0-9][0-9].*|[0-9][0-9].*|[0-9].*", 
                              GOTO="gdm_disable_wayland"
GOTO="gdm_prefer_xorg"
LABEL="gdm_nvidia_drm_end"

GOTO="gdm_end"

Image 3

Wayland Did Not Appear at First Boot on 21.10

Explicitly specify nvidia-drm.modeset

Edit /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nvidia-drm.modeset=1"

Run sudo update-grub

Reboot computer.

Wayland Now Works with NVIDIA Driver

$ echo $XDG_SESSION_TYPE
wayland
nvidia-smi
Wed Oct  6 17:46:37 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.63.01    Driver Version: 470.63.01    CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+

Testing Flutter desktop with 4K video at 30fps.

$ flutter run -d linux
Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           
Syncing files to device Linux...     

Flutter desktop app working great!

Running Flutter 2.5.2 with Dart 2.14.3.

Experience is great so far.  :-)

History

  • 27th April, 2021: Initial version
  • 14th June, 2021: Added information on OBS 27
  • 6th October, 2021: Upgraded to Ubuntu 21.10 Impish Indri with NVIDIA driver 470

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --