summaryrefslogtreecommitdiffstats
path: root/src/core/dynkeymap.c
blob: 2f7c49937c6b5f4aed048026a15ce1e81bb1bfc8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright (C) 2022 Michael Brown <mbrown@fensystems.co.uk>.
 *
 * 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 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * You can also choose to distribute this program under the terms of
 * the Unmodified Binary Distribution Licence (as given in the file
 * COPYING.UBDL), provided that you have satisfied its requirements.
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

/** @file
 *
 * Dynamic keyboard mappings
 *
 */

#include <stdlib.h>
#include <errno.h>
#include <ipxe/settings.h>
#include <ipxe/keymap.h>

/**
 * Require a keyboard map
 *
 * @v name		Keyboard map name
 */
#define REQUIRE_KEYMAP( name ) REQUIRE_OBJECT ( keymap_ ## name )

/** Keyboard map setting */
const struct setting keymap_setting __setting ( SETTING_MISC, keymap ) = {
	.name = "keymap",
	.description = "Keyboard map",
	.type = &setting_type_string,
};

/**
 * Apply keyboard map settings
 *
 * @ret rc		Return status code
 */
static int keymap_apply ( void ) {
	struct keymap *keymap;
	char *name;
	int rc;

	/* Fetch keyboard map name */
	fetch_string_setting_copy ( NULL, &keymap_setting, &name );

	/* Identify keyboard map */
	if ( name ) {
		/* Identify named keyboard map */
		keymap = keymap_find ( name );
		if ( ! keymap ) {
			DBGC ( &keymap_setting, "KEYMAP could not identify "
			       "\"%s\"\n", name );
			rc = -ENOENT;
			goto err_unknown;
		}
	} else {
		/* Use default keyboard map */
		keymap = NULL;
	}

	/* Set keyboard map */
	keymap_set ( keymap );

	/* Success */
	rc = 0;

 err_unknown:
	free ( name );
	return rc;
}

/** Keyboard map setting applicator */
struct settings_applicator keymap_applicator __settings_applicator = {
	.apply = keymap_apply,
};

/* Provide virtual "dynamic" keyboard map for linker */
PROVIDE_SYMBOL ( obj_keymap_dynamic );

/* Drag in keyboard maps via keymap_setting */
REQUIRING_SYMBOL ( keymap_setting );

/* Require all known keyboard maps */
REQUIRE_KEYMAP ( al );
REQUIRE_KEYMAP ( by );
REQUIRE_KEYMAP ( cf );
REQUIRE_KEYMAP ( cz );
REQUIRE_KEYMAP ( de );
REQUIRE_KEYMAP ( dk );
REQUIRE_KEYMAP ( es );
REQUIRE_KEYMAP ( et );
REQUIRE_KEYMAP ( fi );
REQUIRE_KEYMAP ( fr );
REQUIRE_KEYMAP ( gr );
REQUIRE_KEYMAP ( hu );
REQUIRE_KEYMAP ( il );
REQUIRE_KEYMAP ( it );
REQUIRE_KEYMAP ( lt );
REQUIRE_KEYMAP ( mk );
REQUIRE_KEYMAP ( mt );
REQUIRE_KEYMAP ( nl );
REQUIRE_KEYMAP ( no );
REQUIRE_KEYMAP ( no_latin1 );
REQUIRE_KEYMAP ( pl );
REQUIRE_KEYMAP ( pt );
REQUIRE_KEYMAP ( ro );
REQUIRE_KEYMAP ( ru );
REQUIRE_KEYMAP ( se );
REQUIRE_KEYMAP ( sg );
REQUIRE_KEYMAP ( sr_latin );
REQUIRE_KEYMAP ( ua );
REQUIRE_KEYMAP ( uk );
REQUIRE_KEYMAP ( us );