Bug 388249 - KWin should query org.freedesktop.locale1 for the default keyboard layout
Summary: KWin should query org.freedesktop.locale1 for the default keyboard layout
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: generic-wayland (show other bugs)
Version: master
Platform: Other Linux
: NOR wishlist
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-26 15:30 UTC by Fabian Vogt
Modified: 2018-01-15 07:57 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
mgraesslin: Wayland+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabian Vogt 2017-12-26 15:30:52 UTC
If no keyboard layout is set, kwin currently uses "us" as default instead of the system-wide configuration.
Comment 1 Martin Flöser 2017-12-26 16:17:16 UTC
KWin does not use "us" as default keyboard layout. It uses whatever xkbcommon uses as default layout. I would say changing KWin is the wrong place. This should be handled upstream in xkbcommon. Especially as according to documentation (see https://xkbcommon.org/doc/current/structxkb__rule__names.html ) "the system default is used".
Comment 2 Martin Flöser 2017-12-26 16:19:41 UTC
Setting to WONTFIX as there is no locale1 on my system. I assume that this is a relatively new systemd service and we cannot depend on that yet. We might re-evaluate the situation in about 2 years when the usage tickled through all distros. At the moment that would be too much hassle with conditional code paths dependent on whether it's available or not.

But as said in previous comment: ideally xkbcommon gains support for that which would mean that KWin (and other compositors) don't need to be changed at all.
Comment 3 Fabian Vogt 2017-12-26 16:29:11 UTC
(In reply to Martin Flöser from comment #2)
> Setting to WONTFIX as there is no locale1 on my system. I assume that this
> is a relatively new systemd service and we cannot depend on that yet. We
> might re-evaluate the situation in about 2 years when the usage tickled
> through all distros. At the moment that would be too much hassle with
> conditional code paths dependent on whether it's available or not.

No, localed is really old (2010?).
It's only loaded on demand, you can just query over dbus or use "localectl".

> But as said in previous comment: ideally xkbcommon gains support for that
> which would mean that KWin (and other compositors) don't need to be changed
> at all.

Ok, I'll have a look at that.
Comment 4 Fabian Vogt 2017-12-26 16:50:28 UTC
(In reply to Fabian Vogt from comment #3)
> (In reply to Martin Flöser from comment #2)
> > But as said in previous comment: ideally xkbcommon gains support for that
> > which would mean that KWin (and other compositors) don't need to be changed
> > at all.
> 
> Ok, I'll have a look at that.

I did - it doesn't look good. libxkbcommmon's interpretation of "system default" means: Use the values given during build, hardcoded into libxkbcommon itself.

https://github.com/xkbcommon/libxkbcommon/blob/b82e3b764e60df337ca695e8f8642e7bf42b0cca/meson.build#L65

So either the documentation is really misleading here or the code just doesn't do what the documentation says.
Comment 5 Martin Flöser 2017-12-26 18:40:04 UTC
Doesn't change much. For our usage it would be better if xkbcommon handles it. Or if an external tool takes care of it. There's nothing wrong with startplasmacompositor querying locale1 and setting the XKB_DEFAULT_* env variables accordingly.

From coding side it's for KWin difficult to interact with it as we actually expect the behavior that the XKB_DEFAULT* env variables are honored.

Anyway I think KWin's the wrong place for it. I think having that feature implemented makes a lot of sense, just KWin shouldn't be it. Best would be xkbcommon, second best IMHO a dedicated tool.
Comment 6 Fabian Vogt 2017-12-26 21:14:21 UTC
Patch for startplasmacompositor available at https://phabricator.kde.org/D9512.
Comment 7 Fabian Vogt 2017-12-29 17:47:44 UTC
Git commit 361ee31606fb4d770356e7adde8c45369cca0aab by Fabian Vogt.
Committed on 29/12/2017 at 17:45.
Pushed by fvogt into branch 'master'.

startplasmacompositor: If available, query org.freedesktop.locale1 for XKB defaults

Summary:
kwin_wayland will then use those values to set the default keyboard layout
accordingly.

Test Plan:
Ran startplasmacompositor, keyboard layout now set correctly and env
shows all XKB_DEFAULT_* variables set.

Reviewers: #plasma, graesslin

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9512

M  +23   -0    startkde/startplasmacompositor.cmake

https://commits.kde.org/plasma-workspace/361ee31606fb4d770356e7adde8c45369cca0aab
Comment 8 Fabian Vogt 2018-01-13 16:59:59 UTC
Sadly this doesn't actually work, as I just found out.

xkbcommon uses secure_getenv to read environment variables, which just returns NULL when "the effective capability bit was set on the executable file".

All of my local kwin_wayland builds do not use CAP_SYS_NICE...

How should this be fixed then, move the environment reading into xkb.cpp?
Comment 9 Fabian Vogt 2018-01-15 07:57:03 UTC
Git commit eb69e87288d37fdb13eca32ca807ed8279f912af by Fabian Vogt.
Committed on 15/01/2018 at 07:56.
Pushed by fvogt into branch 'master'.

Manually take XKB_DEFAULT_{RULES,MODEL,LAYOUT,VARIANT,OPTIONS} into account

Summary:
As kwin_wayland can have the CAP_SYS_NICE capability, libxkbcommon does not
read environment variables (see secure_getenv).
So process them here, in the same way xkb_context_sanitize_rule_names would.

Test Plan: kwin_wayland has the capability set, keyboard layout is applied correctly.

Reviewers: #plasma, graesslin

Subscribers: kwin, plasma-devel, #kwin

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9873

M  +34   -1    xkb.cpp

https://commits.kde.org/kwin/eb69e87288d37fdb13eca32ca807ed8279f912af