You are not logged in.

#1 2020-09-22 16:13:17

zu0107
Member
From: South Korea
Registered: 2017-05-02
Posts: 8
Website

[SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

I am currently trying to separate superfluous environment variable exports from my bashrc, as I am trying to share same bashrc for multiple platforms, including Ubuntu and WSL environment.
Since I use uim, I tried following this guide on Japanese ArchWiki and created these two systemd units:

# ~/.config/systemd/user/uim.service
[Unit]
Description=uim daemon
Wants=uim-env.service
After=xorg.target

[Service]
ExecStart=/usr/bin/uim-xim
Restart=on-abort

[Install]
WantedBy=xorg.target
# ~/.config/systemd/user/uim-env.service

[Unit]
Description=uim environment initialization
Before=xorg.target

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl --user set-environment XMODIFIERS='@im=uim'
ExecStart=/usr/bin/systemctl --user set-environment GTK_IM_MODULE='uim'
ExecStart=/usr/bin/systemctl --user set-environment QT_IM_MODULE='uim'

After a reboot, Firefox and other GTK-based programs work just fine, but Qt programs don't seem to recognize the QT_IM_MODULE environment variable there.
I discovered that printenv command's output does not show the variables I declared in the systemd service above.
Manually supplying the QT_IM_MODULE variable works as expected:

env QT_IM_MODULE='uim' kate

Do systemd environment variables exist in different namespace?
Is there a way to "export" these systemd environments, or possibly make Qt programs recognize these systemd environments like GTK applications do?

================

Since LightDM is a process run by system-wide systemd service, creating a user systemd service has no effect on bspwm.
It seems like the only solution is modifying ~/.profile so that login shells import the environment variables.

Last edited by zu0107 (2020-10-07 08:19:51)

Offline

#2 2020-09-22 18:37:58

GaKu999
Member
From: US/Eastern
Registered: 2020-06-21
Posts: 696

Re: [SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

zu0107 wrote:

Do systemd environment variables exist in different namespace?

Yes.

zu0107 wrote:

Is there a way to "export" these systemd environments, or possibly make Qt programs recognize these systemd environments like GTK applications do?

What I usually do in ~/.profile:

export FOO=BAR
systemctl --user import-environment FOO

So they get loaded in the initial login shell, every new subshell and systemd services if needed, otherwise I omit the import to systemd.

Idk about other ways...

Last edited by GaKu999 (2020-09-22 18:40:28)


My reposSome snippets

Heisenberg might have been here.

Offline

#3 2020-09-28 06:19:06

zu0107
Member
From: South Korea
Registered: 2017-05-02
Posts: 8
Website

Re: [SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

Thank you for your reply.

For now I reverted my changes back, so my bashrc has environment variable declarations...

However I still have some questions.
Correct me if I misunderstand something: so systemd will pass those "systemd environments" to programs started by systemd units, but not to the children of those programs?

Offline

#4 2020-10-02 02:51:26

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

zu0107 wrote:

However I still have some questions.
Correct me if I misunderstand something: so systemd will pass those "systemd environments" to programs started by systemd units, but not to the children of those programs?

You misunderstood. systemd will pass those "systemd environments" to programs started by systemd units, that's all. Then due to the way processes work, the children retain the same environments.

The problem is that programs in your graphical desktop environment are not usually children of systemd units... it's possible to run them as children of systemd units but this is not the default.

Usually you will want to add the environment variables to *both* .profile and systemd, so that no matter how the program got started, it sees the environment.

You could use htop to get a better idea of the tree of processes and which ones are children of which other ones.

Last edited by eschwartz (2020-10-02 02:53:09)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2020-10-03 12:45:48

zu0107
Member
From: South Korea
Registered: 2017-05-02
Posts: 8
Website

Re: [SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

eschwarts wrote:

systemd will pass those "systemd environments" to programs started by systemd units, that's all. Then due to the way processes work, the children retain the same environments.

That's odd. Since my Qt applications are started by a keybinding daemon that is started by bspwm, which in turn is started by LightDM systemd unit, I assume the Qt apps should inherit the systemd environment variables...
Does it mean that when I enter my own login session the systemd user units are not being started automatically?

Offline

#6 2020-10-05 04:47:46

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

zu0107 wrote:

That's odd. Since my Qt applications are started by a keybinding daemon that is started by bspwm, which in turn is started by LightDM systemd unit, I assume the Qt apps should inherit the systemd environment variables...

This is a system service, lightdm runs as root and reads and executes your login.

It does not run inside a "systemd --user" session

zu0107 wrote:

Does it mean that when I enter my own login session the systemd user units are not being started automatically?

The systemd user units start just fine... but they are children of lightdm, not the other way around. bspwm is also a child of lightdm.

lightdm
├── bspwm
│   └── keybinding-daemon
│       └── qt-program
└── systemd-user-units
    └── uim

Where in this tree do you start your gtk programs? uim-env.service tells "systemd-user-units" that all future children of "systemd-user-units" should also inherit XMODIFIERS GTK_IM_MODULE QT_IM_MODULE but this does not apply to the bspwm branch.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#7 2020-10-06 16:05:35

zu0107
Member
From: South Korea
Registered: 2017-05-02
Posts: 8
Website

Re: [SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

eschwartz wrote:

The systemd user units start just fine... but they are children of lightdm, not the other way around. bspwm is also a child of lightdm.

Ah, that explains it a lot! So the two services do run in completely different contexts.
I guess my only option is to keep my current option or make uim environment service a system-wide service...
I think I'll stick with the former for now. Thank you!

Offline

#8 2020-10-06 16:10:41

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] Qt programs don't honor QT_IM_MODULE systemd env vars

Great, happy to help. smile

Consider editing the first post and adding the word "[Solved]" to the thread title.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB