mirror of
https://github.com/swaywm/sway.git
synced 2026-04-26 06:46:26 -04:00
input/keyboard: use $XDG_CONFIG_HOME/xkb as first lookup path for the XKB context
This commit is contained in:
parent
21b77f376d
commit
23892fcc47
5 changed files with 86 additions and 2 deletions
28
include/meta-keymap-utils.h
Normal file
28
include/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 */
|
||||||
|
|
@ -31,13 +31,14 @@
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "meta-keymap-utils.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
struct sway_config *config = NULL;
|
struct sway_config *config = NULL;
|
||||||
|
|
||||||
static struct xkb_state *keysym_translation_state_create(
|
static struct xkb_state *keysym_translation_state_create(
|
||||||
struct xkb_rule_names rules) {
|
struct xkb_rule_names rules) {
|
||||||
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
struct xkb_context *context = meta_create_xkb_context();
|
||||||
struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names(
|
struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names(
|
||||||
context,
|
context,
|
||||||
&rules,
|
&rules,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include "sway/input/seat.h"
|
#include "sway/input/seat.h"
|
||||||
#include "sway/ipc-server.h"
|
#include "sway/ipc-server.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "meta-keymap-utils.h"
|
||||||
|
|
||||||
static struct modifier_key {
|
static struct modifier_key {
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -701,7 +702,7 @@ static void handle_xkb_context_log(struct xkb_context *context,
|
||||||
|
|
||||||
struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic,
|
struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic,
|
||||||
char **error) {
|
char **error) {
|
||||||
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
struct xkb_context *context = meta_create_xkb_context();
|
||||||
if (!sway_assert(context, "cannot create XKB context")) {
|
if (!sway_assert(context, "cannot create XKB context")) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ sway_sources = files(
|
||||||
'ipc-json.c',
|
'ipc-json.c',
|
||||||
'ipc-server.c',
|
'ipc-server.c',
|
||||||
'main.c',
|
'main.c',
|
||||||
|
'meta-keymap-utils.c',
|
||||||
'server.c',
|
'server.c',
|
||||||
'swaynag.c',
|
'swaynag.c',
|
||||||
'xdg_decoration.c',
|
'xdg_decoration.c',
|
||||||
|
|
|
||||||
53
sway/meta-keymap-utils.c
Normal file
53
sway/meta-keymap-utils.c
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* -*- 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 "meta-keymap-utils.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <linux/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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue