compositor: use XDG_CONFIG_HOME as initial lookup path for xkb
Using XDG_CONFIG_HOME allows users to place their keyboard configuration into their home directory and have them loaded automatically. libxkbcommon now defaults to XDG_CONFIG_HOME/xkb/ first, see https://github.com/xkbcommon/libxkbcommon/pull/117 However - libxkbcommon uses secure_getenv() to obtain XDG_CONFIG_HOME and thus fails to load this for the mutter context which has cap_sys_nice. We need to manually add that search path as lookup path. As we can only append paths to libxkbcommon's context, we need to start with an empty search path set, add our custom path, then append the default search paths. The net effect is nil where a user doesn't have XDG_CONFIG_HOME/xkb/. https://gitlab.gnome.org/GNOME/mutter/merge_requests/936
This commit is contained in:
parent
1eaf9e5f63
commit
f712387325
56
src/backends/meta-keymap-utils.c
Normal file
56
src/backends/meta-keymap-utils.c
Normal file
@ -0,0 +1,56 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* Utilities for use with libxkbcommon
|
||||
*
|
||||
* Copyright 2019 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "backends/meta-keymap-utils.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <limits.h>
|
||||
|
||||
struct xkb_context *
|
||||
meta_create_xkb_context (void)
|
||||
{
|
||||
struct xkb_context *ctx;
|
||||
char xdg[PATH_MAX] = {0};
|
||||
const char *env;
|
||||
|
||||
/*
|
||||
* We can only append search paths in libxkbcommon, so we start with an
|
||||
* emtpy set, then add the XDG dir, then add the default search paths.
|
||||
*/
|
||||
ctx = xkb_context_new (XKB_CONTEXT_NO_DEFAULT_INCLUDES);
|
||||
|
||||
env = g_getenv ("XDG_CONFIG_HOME");
|
||||
if (env)
|
||||
{
|
||||
g_snprintf (xdg, sizeof xdg, "%s/xkb", env);
|
||||
}
|
||||
else if ((env = g_getenv ("HOME")))
|
||||
{
|
||||
g_snprintf (xdg, sizeof xdg, "%s/.config/xkb", env);
|
||||
}
|
||||
|
||||
if (env)
|
||||
xkb_context_include_path_append (ctx, xdg);
|
||||
xkb_context_include_path_append_default (ctx);
|
||||
|
||||
return ctx;
|
||||
}
|
28
src/backends/meta-keymap-utils.h
Normal file
28
src/backends/meta-keymap-utils.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* Utilities for use with libxkbcommon
|
||||
*
|
||||
* Copyright 2020 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef META_KEYMAP_UTILS_H
|
||||
#define META_KEYMAP_UTILS_H
|
||||
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
struct xkb_context * meta_create_xkb_context (void);
|
||||
|
||||
#endif /* META_KEYMAP_UTILS_H */
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "backends/meta-cursor-tracker-private.h"
|
||||
#include "backends/meta-idle-monitor-private.h"
|
||||
#include "backends/meta-keymap-utils.h"
|
||||
#include "backends/meta-logical-monitor.h"
|
||||
#include "backends/meta-monitor-manager-private.h"
|
||||
#include "backends/meta-pointer-constraint.h"
|
||||
@ -437,7 +438,7 @@ meta_backend_native_set_keymap (MetaBackend *backend,
|
||||
names.variant = variants;
|
||||
names.options = options;
|
||||
|
||||
context = xkb_context_new (XKB_CONTEXT_NO_FLAGS);
|
||||
context = meta_create_xkb_context ();
|
||||
keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
xkb_context_unref (context);
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "backends/meta-keymap-utils.h"
|
||||
#include "backends/native/meta-keymap-native.h"
|
||||
#include "backends/native/meta-seat-native.h"
|
||||
|
||||
@ -111,7 +112,7 @@ meta_keymap_native_init (MetaKeymapNative *keymap)
|
||||
names.variant = option_xkb_variant;
|
||||
names.options = option_xkb_options;
|
||||
|
||||
ctx = xkb_context_new (XKB_CONTEXT_NO_FLAGS);
|
||||
ctx = meta_create_xkb_context ();
|
||||
g_assert (ctx);
|
||||
keymap->keymap = xkb_keymap_new_from_names (ctx, &names, 0);
|
||||
xkb_context_unref (ctx);
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <xkbcommon/xkbcommon-x11.h>
|
||||
|
||||
#include "backends/meta-idle-monitor-private.h"
|
||||
#include "backends/meta-keymap-utils.h"
|
||||
#include "backends/meta-stage-private.h"
|
||||
#include "backends/x11/meta-clutter-backend-x11.h"
|
||||
#include "backends/x11/meta-event-x11.h"
|
||||
@ -704,7 +705,7 @@ meta_backend_x11_get_keymap (MetaBackend *backend)
|
||||
|
||||
if (priv->keymap == NULL)
|
||||
{
|
||||
struct xkb_context *context = xkb_context_new (XKB_CONTEXT_NO_FLAGS);
|
||||
struct xkb_context *context = meta_create_xkb_context ();
|
||||
priv->keymap = xkb_x11_keymap_new_from_device (context,
|
||||
priv->xcb,
|
||||
xkb_x11_get_core_keyboard_device_id (priv->xcb),
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "backends/meta-backend-private.h"
|
||||
#include "backends/meta-keymap-utils.h"
|
||||
#include "backends/meta-logical-monitor.h"
|
||||
#include "backends/meta-monitor-manager-private.h"
|
||||
#include "backends/x11/meta-backend-x11.h"
|
||||
@ -741,7 +742,7 @@ create_us_layout (void)
|
||||
names.variant = "";
|
||||
names.options = "";
|
||||
|
||||
context = xkb_context_new (XKB_CONTEXT_NO_FLAGS);
|
||||
context = meta_create_xkb_context ();
|
||||
keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
xkb_context_unref (context);
|
||||
|
||||
|
@ -195,6 +195,8 @@ mutter_sources = [
|
||||
'backends/meta-input-mapper-private.h',
|
||||
'backends/meta-input-settings.c',
|
||||
'backends/meta-input-settings-private.h',
|
||||
'backends/meta-keymap-utils.c',
|
||||
'backends/meta-keymap-utils.h',
|
||||
'backends/meta-logical-monitor.c',
|
||||
'backends/meta-logical-monitor.h',
|
||||
'backends/meta-monitor.c',
|
||||
|
Loading…
Reference in New Issue
Block a user