0

I want to access environment variable from a Gnome-Shell extension.

Some context: I want to create an extension adding "Xorg" or "Wayland" to the panel, based upon the environment variable $XDG_SESSION_TYPE. I have to do this because I frequently switch (Wine has issues with Wayland), and I don't always remember which type of session is running.

cronvel
  • 4,045
  • 2
  • 14
  • 19

2 Answers2

1

I was able to find how to get environment variables in the source code of the Argos extension:

const GLib = imports.gi.GLib ;
const rawEnv = GLib.get_environ() ;

Also the environment variable are stored as an array of strings and should be parsed, i.e.: split on the first '=' occurrence to separate the key and the value.

EDIT: GLib.getenv('ENV_VAR_NAME') is more convenient because it avoids parsing the environment variable (thanks to @andyholmes).

cronvel
  • 4,045
  • 2
  • 14
  • 19
0

Another way to detect Wayland is to ask the window manager:

Meta.is_wayland_compositor()

Tested in GS 3.36, 3.38 and 40.

https://gjs-docs.gnome.org/meta3~3.30.2/meta.is_wayland_compositor

Edit: From extension only, not available from prefs.

GdH
  • 26
  • 2