2003-11-14 16:54:54 +01:00
|
|
|
/************************************************************
|
|
|
|
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this
|
|
|
|
software and its documentation for any purpose and without
|
|
|
|
fee is hereby granted, provided that the above copyright
|
|
|
|
notice appear in all copies and that both that copyright
|
|
|
|
notice and this permission notice appear in supporting
|
2014-10-31 00:45:12 +01:00
|
|
|
documentation, and that the name of Silicon Graphics not be
|
|
|
|
used in advertising or publicity pertaining to distribution
|
2003-11-14 16:54:54 +01:00
|
|
|
of the software without specific prior written permission.
|
2014-10-31 00:45:12 +01:00
|
|
|
Silicon Graphics makes no representation about the suitability
|
2003-11-14 16:54:54 +01:00
|
|
|
of this software for any purpose. It is provided "as is"
|
|
|
|
without any express or implied warranty.
|
|
|
|
|
2014-10-31 00:45:12 +01:00
|
|
|
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
2003-11-14 16:54:54 +01:00
|
|
|
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
2014-10-31 00:45:12 +01:00
|
|
|
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
|
|
|
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
2003-11-14 16:54:54 +01:00
|
|
|
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
|
|
|
|
THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
********************************************************/
|
|
|
|
|
2005-07-03 09:02:09 +02:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2005-08-31 16:58:09 +02:00
|
|
|
#include <xkb-config.h>
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xos.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/extensions/XKM.h>
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#define XKBSRV_NEED_FILE_FUNCS
|
2007-03-18 21:31:19 +01:00
|
|
|
#include <xkbsrv.h>
|
2005-04-20 14:25:48 +02:00
|
|
|
#include <X11/extensions/XI.h>
|
2003-11-25 20:29:01 +01:00
|
|
|
#include "xkb.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#define PRE_ERROR_MSG "\"The XKEYBOARD keymap compiler (xkbcomp) reports:\""
|
|
|
|
#define ERROR_PREFIX "\"> \""
|
|
|
|
#define POST_ERROR_MSG1 "\"Errors from xkbcomp are not fatal to the X server\""
|
|
|
|
#define POST_ERROR_MSG2 "\"End of messages from xkbcomp\""
|
|
|
|
|
2007-06-29 00:59:05 +02:00
|
|
|
#if defined(WIN32)
|
2005-01-09 16:29:45 +01:00
|
|
|
#define PATHSEPARATOR "\\"
|
|
|
|
#else
|
|
|
|
#define PATHSEPARATOR "/"
|
|
|
|
#endif
|
|
|
|
|
2014-03-12 07:31:25 +01:00
|
|
|
static unsigned
|
|
|
|
LoadXKM(unsigned want, unsigned need, const char *keymap, XkbDescPtr *xkbRtrn);
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
OutputDirectory(char *outdir, size_t size)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
#ifndef WIN32
|
2009-09-29 19:05:06 +02:00
|
|
|
/* Can we write an xkm and then open it too? */
|
2012-03-21 20:55:09 +01:00
|
|
|
if (access(XKM_OUTPUT_DIR, W_OK | X_OK) == 0 &&
|
|
|
|
(strlen(XKM_OUTPUT_DIR) < size)) {
|
|
|
|
(void) strcpy(outdir, XKM_OUTPUT_DIR);
|
|
|
|
}
|
|
|
|
else
|
2008-02-03 13:30:22 +01:00
|
|
|
#else
|
2012-03-21 20:55:09 +01:00
|
|
|
if (strlen(Win32TempDir()) + 1 < size) {
|
|
|
|
(void) strcpy(outdir, Win32TempDir());
|
|
|
|
(void) strcat(outdir, "\\");
|
|
|
|
}
|
|
|
|
else
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
if (strlen("/tmp/") < size) {
|
|
|
|
(void) strcpy(outdir, "/tmp/");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-12 07:08:15 +01:00
|
|
|
/**
|
|
|
|
* Callback invoked by XkbRunXkbComp. Write to out to talk to xkbcomp.
|
|
|
|
*/
|
|
|
|
typedef void (*xkbcomp_buffer_callback)(FILE *out, void *userdata);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start xkbcomp, let the callback write into xkbcomp's stdin. When done,
|
|
|
|
* return a strdup'd copy of the file name we've written to.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
RunXkbComp(xkbcomp_buffer_callback callback, void *userdata)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
FILE *out;
|
|
|
|
char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX];
|
2008-11-25 23:12:26 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
const char *emptystring = "";
|
2010-05-12 20:54:51 +02:00
|
|
|
char *xkbbasedirflag = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
const char *xkbbindir = emptystring;
|
|
|
|
const char *xkbbindirsep = emptystring;
|
2005-02-01 19:14:01 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifdef WIN32
|
2008-11-25 23:12:26 +01:00
|
|
|
/* WIN32 has no popen. The input must be stored in a file which is
|
|
|
|
used as input for xkbcomp. xkbcomp does not read from stdin. */
|
|
|
|
char tmpname[PATH_MAX];
|
|
|
|
const char *xkmfile = tmpname;
|
|
|
|
#else
|
|
|
|
const char *xkmfile = "-";
|
|
|
|
#endif
|
2008-11-19 22:44:26 +01:00
|
|
|
|
|
|
|
snprintf(keymap, sizeof(keymap), "server-%s", display);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2005-01-09 16:29:45 +01:00
|
|
|
OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
|
2008-11-25 23:12:26 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifdef WIN32
|
2004-11-15 16:06:51 +01:00
|
|
|
strcpy(tmpname, Win32TempDir());
|
|
|
|
strcat(tmpname, "\\xkb_XXXXXX");
|
2003-11-14 16:54:54 +01:00
|
|
|
(void) mktemp(tmpname);
|
|
|
|
#endif
|
2008-11-25 23:12:26 +01:00
|
|
|
|
|
|
|
if (XkbBaseDirectory != NULL) {
|
2012-03-21 20:55:09 +01:00
|
|
|
if (asprintf(&xkbbasedirflag, "\"-R%s\"", XkbBaseDirectory) == -1)
|
|
|
|
xkbbasedirflag = NULL;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2008-11-25 23:12:26 +01:00
|
|
|
|
|
|
|
if (XkbBinDirectory != NULL) {
|
2012-03-21 20:55:09 +01:00
|
|
|
int ld = strlen(XkbBinDirectory);
|
|
|
|
int lps = strlen(PATHSEPARATOR);
|
2008-11-25 23:12:26 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
xkbbindir = XkbBinDirectory;
|
2008-11-25 23:12:26 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if ((ld >= lps) && (strcmp(xkbbindir + ld - lps, PATHSEPARATOR) != 0)) {
|
|
|
|
xkbbindirsep = PATHSEPARATOR;
|
|
|
|
}
|
2008-11-25 23:12:26 +01:00
|
|
|
}
|
|
|
|
|
2010-11-28 05:09:04 +01:00
|
|
|
if (asprintf(&buf,
|
2012-03-21 20:55:09 +01:00
|
|
|
"\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
|
|
|
|
"-em1 %s -emp %s -eml %s \"%s%s.xkm\"",
|
|
|
|
xkbbindir, xkbbindirsep,
|
|
|
|
((xkbDebugFlags < 2) ? 1 :
|
|
|
|
((xkbDebugFlags > 10) ? 10 : (int) xkbDebugFlags)),
|
|
|
|
xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
|
|
|
|
PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
|
|
|
|
xkm_output_dir, keymap) == -1)
|
|
|
|
buf = NULL;
|
2008-11-25 23:12:26 +01:00
|
|
|
|
2010-05-12 20:54:51 +02:00
|
|
|
free(xkbbasedirflag);
|
2010-06-06 22:19:03 +02:00
|
|
|
|
|
|
|
if (!buf) {
|
2012-03-21 20:55:09 +01:00
|
|
|
LogMessage(X_ERROR,
|
|
|
|
"XKB: Could not invoke xkbcomp: not enough memory\n");
|
2014-03-12 07:08:15 +01:00
|
|
|
return NULL;
|
2010-06-06 22:19:03 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifndef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
out = Popen(buf, "w");
|
2003-11-14 16:54:54 +01:00
|
|
|
#else
|
2012-03-21 20:55:09 +01:00
|
|
|
out = fopen(tmpname, "w");
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
if (out != NULL) {
|
2014-03-12 07:08:15 +01:00
|
|
|
/* Now write to xkbcomp */
|
|
|
|
(*callback)(out, userdata);
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifndef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
if (Pclose(out) == 0)
|
2003-11-14 16:54:54 +01:00
|
|
|
#else
|
2012-03-21 20:55:09 +01:00
|
|
|
if (fclose(out) == 0 && System(buf) >= 0)
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
{
|
2008-02-03 13:30:22 +01:00
|
|
|
if (xkbDebugFlags)
|
2012-03-21 20:55:09 +01:00
|
|
|
DebugF("[xkb] xkb executes: %s\n", buf);
|
2010-11-08 23:35:33 +01:00
|
|
|
free(buf);
|
2011-10-08 15:39:07 +02:00
|
|
|
#ifdef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
unlink(tmpname);
|
2011-10-08 15:39:07 +02:00
|
|
|
#endif
|
2014-03-12 07:08:15 +01:00
|
|
|
return xnfstrdup(keymap);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2017-10-31 20:22:31 +01:00
|
|
|
else {
|
|
|
|
LogMessage(X_ERROR, "Error compiling keymap (%s) executing '%s'\n",
|
|
|
|
keymap, buf);
|
|
|
|
}
|
2004-12-24 15:40:28 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
/* remove the temporary file */
|
|
|
|
unlink(tmpname);
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifndef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
LogMessage(X_ERROR, "XKB: Could not invoke xkbcomp\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
#else
|
2012-03-21 20:55:09 +01:00
|
|
|
LogMessage(X_ERROR, "Could not open file %s\n", tmpname);
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
2010-11-08 23:35:33 +01:00
|
|
|
free(buf);
|
2014-03-12 07:08:15 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
XkbDescPtr xkb;
|
|
|
|
XkbComponentNamesPtr names;
|
|
|
|
unsigned int want;
|
|
|
|
unsigned int need;
|
|
|
|
} XkbKeymapNamesCtx;
|
|
|
|
|
|
|
|
static void
|
|
|
|
xkb_write_keymap_for_names_cb(FILE *out, void *userdata)
|
|
|
|
{
|
|
|
|
XkbKeymapNamesCtx *ctx = userdata;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (xkbDebugFlags) {
|
|
|
|
ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
|
|
|
|
XkbWriteXKBKeymapForNames(stderr, ctx->names, ctx->xkb, ctx->want, ctx->need);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
XkbWriteXKBKeymapForNames(out, ctx->names, ctx->xkb, ctx->want, ctx->need);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
|
|
|
|
XkbComponentNamesPtr names,
|
|
|
|
unsigned want,
|
|
|
|
unsigned need, char *nameRtrn, int nameRtrnLen)
|
|
|
|
{
|
|
|
|
char *keymap;
|
|
|
|
Bool rc = FALSE;
|
|
|
|
XkbKeymapNamesCtx ctx = {
|
|
|
|
.xkb = xkb,
|
|
|
|
.names = names,
|
|
|
|
.want = want,
|
|
|
|
.need = need
|
|
|
|
};
|
|
|
|
|
|
|
|
keymap = RunXkbComp(xkb_write_keymap_for_names_cb, &ctx);
|
|
|
|
|
|
|
|
if (keymap) {
|
|
|
|
if(nameRtrn)
|
|
|
|
strlcpy(nameRtrn, keymap, nameRtrnLen);
|
|
|
|
|
|
|
|
free(keymap);
|
|
|
|
rc = TRUE;
|
|
|
|
} else if (nameRtrn)
|
|
|
|
*nameRtrn = '\0';
|
|
|
|
|
|
|
|
return rc;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2014-03-12 07:31:25 +01:00
|
|
|
typedef struct {
|
|
|
|
const char *keymap;
|
|
|
|
size_t len;
|
|
|
|
} XkbKeymapString;
|
|
|
|
|
|
|
|
static void
|
|
|
|
xkb_write_keymap_string_cb(FILE *out, void *userdata)
|
|
|
|
{
|
|
|
|
XkbKeymapString *s = userdata;
|
|
|
|
fwrite(s->keymap, s->len, 1, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
XkbDDXLoadKeymapFromString(DeviceIntPtr keybd,
|
|
|
|
const char *keymap, int keymap_length,
|
|
|
|
unsigned int want,
|
|
|
|
unsigned int need,
|
|
|
|
XkbDescPtr *xkbRtrn)
|
|
|
|
{
|
|
|
|
unsigned int have;
|
|
|
|
char *map_name;
|
|
|
|
XkbKeymapString map = {
|
|
|
|
.keymap = keymap,
|
|
|
|
.len = keymap_length
|
|
|
|
};
|
|
|
|
|
|
|
|
*xkbRtrn = NULL;
|
|
|
|
|
|
|
|
map_name = RunXkbComp(xkb_write_keymap_string_cb, &map);
|
|
|
|
if (!map_name) {
|
|
|
|
LogMessage(X_ERROR, "XKB: Couldn't compile keymap\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
have = LoadXKM(want, need, map_name, xkbRtrn);
|
|
|
|
free(map_name);
|
|
|
|
|
|
|
|
return have;
|
|
|
|
}
|
|
|
|
|
2007-03-18 21:31:19 +01:00
|
|
|
static FILE *
|
2014-03-12 08:17:25 +01:00
|
|
|
XkbDDXOpenConfigFile(const char *mapName, char *fileNameRtrn, int fileNameRtrnLen)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
char buf[PATH_MAX], xkm_output_dir[PATH_MAX];
|
|
|
|
FILE *file;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
buf[0] = '\0';
|
|
|
|
if (mapName != NULL) {
|
|
|
|
OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
|
|
|
|
if ((XkbBaseDirectory != NULL) && (xkm_output_dir[0] != '/')
|
2004-11-15 16:06:51 +01:00
|
|
|
#ifdef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
&& (!isalpha(xkm_output_dir[0]) || xkm_output_dir[1] != ':')
|
2004-11-15 16:06:51 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
) {
|
2011-02-14 06:36:02 +01:00
|
|
|
if (snprintf(buf, PATH_MAX, "%s/%s%s.xkm", XkbBaseDirectory,
|
|
|
|
xkm_output_dir, mapName) >= PATH_MAX)
|
|
|
|
buf[0] = '\0';
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-02-14 06:36:02 +01:00
|
|
|
if (snprintf(buf, PATH_MAX, "%s%s.xkm", xkm_output_dir, mapName)
|
|
|
|
>= PATH_MAX)
|
|
|
|
buf[0] = '\0';
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
if (buf[0] != '\0')
|
|
|
|
file = fopen(buf, "rb");
|
|
|
|
else
|
|
|
|
file = NULL;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else
|
|
|
|
file = NULL;
|
|
|
|
if ((fileNameRtrn != NULL) && (fileNameRtrnLen > 0)) {
|
|
|
|
strlcpy(fileNameRtrn, buf, fileNameRtrnLen);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2014-03-12 08:18:22 +01:00
|
|
|
static unsigned
|
|
|
|
LoadXKM(unsigned want, unsigned need, const char *keymap, XkbDescPtr *xkbRtrn)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
char fileName[PATH_MAX];
|
|
|
|
unsigned missing;
|
|
|
|
|
|
|
|
file = XkbDDXOpenConfigFile(keymap, fileName, PATH_MAX);
|
|
|
|
if (file == NULL) {
|
|
|
|
LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n",
|
|
|
|
fileName);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
missing = XkmReadFile(file, need, want, xkbRtrn);
|
|
|
|
if (*xkbRtrn == NULL) {
|
|
|
|
LogMessage(X_ERROR, "Error loading keymap %s\n", fileName);
|
|
|
|
fclose(file);
|
|
|
|
(void) unlink(fileName);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DebugF("Loaded XKB keymap %s, defined=0x%x\n", fileName,
|
|
|
|
(*xkbRtrn)->defined);
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
(void) unlink(fileName);
|
|
|
|
return (need | want) & (~missing);
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
unsigned
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbDDXLoadKeymapByNames(DeviceIntPtr keybd,
|
|
|
|
XkbComponentNamesPtr names,
|
|
|
|
unsigned want,
|
|
|
|
unsigned need,
|
|
|
|
XkbDescPtr *xkbRtrn, char *nameRtrn, int nameRtrnLen)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbDescPtr xkb;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2008-02-16 19:01:18 +01:00
|
|
|
*xkbRtrn = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
if ((keybd == NULL) || (keybd->key == NULL) ||
|
|
|
|
(keybd->key->xkbInfo == NULL))
|
|
|
|
xkb = NULL;
|
|
|
|
else
|
|
|
|
xkb = keybd->key->xkbInfo->desc;
|
|
|
|
if ((names->keycodes == NULL) && (names->types == NULL) &&
|
|
|
|
(names->compat == NULL) && (names->symbols == NULL) &&
|
|
|
|
(names->geometry == NULL)) {
|
2008-05-07 21:24:19 +02:00
|
|
|
LogMessage(X_ERROR, "XKB: No components provided for device %s\n",
|
2008-06-26 00:06:49 +02:00
|
|
|
keybd->name ? keybd->name : "(unnamed keyboard)");
|
2008-02-03 13:48:57 +01:00
|
|
|
return 0;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else if (!XkbDDXCompileKeymapByNames(xkb, names, want, need,
|
|
|
|
nameRtrn, nameRtrnLen)) {
|
|
|
|
LogMessage(X_ERROR, "XKB: Couldn't compile keymap\n");
|
|
|
|
return 0;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2014-03-12 08:18:22 +01:00
|
|
|
|
|
|
|
return LoadXKM(want, need, nameRtrn, xkbRtrn);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
Bool
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbDDXNamesFromRules(DeviceIntPtr keybd,
|
2013-11-15 14:28:47 +01:00
|
|
|
const char *rules_name,
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbRF_VarDefsPtr defs, XkbComponentNamesPtr names)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
char buf[PATH_MAX];
|
|
|
|
FILE *file;
|
|
|
|
Bool complete;
|
|
|
|
XkbRF_RulesPtr rules;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
if (!rules_name)
|
2012-03-21 20:55:09 +01:00
|
|
|
return FALSE;
|
2008-05-07 21:24:19 +02:00
|
|
|
|
2011-02-14 06:36:02 +01:00
|
|
|
if (snprintf(buf, PATH_MAX, "%s/rules/%s", XkbBaseDirectory, rules_name)
|
|
|
|
>= PATH_MAX) {
|
2008-05-07 21:24:19 +02:00
|
|
|
LogMessage(X_ERROR, "XKB: Rules name is too long\n");
|
2010-01-15 01:07:38 +01:00
|
|
|
return FALSE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2008-05-07 21:24:19 +02:00
|
|
|
|
|
|
|
file = fopen(buf, "r");
|
|
|
|
if (!file) {
|
2008-05-14 01:39:30 +02:00
|
|
|
LogMessage(X_ERROR, "XKB: Couldn't open rules file %s\n", buf);
|
2012-03-21 20:55:09 +01:00
|
|
|
return FALSE;
|
2008-05-07 21:24:19 +02:00
|
|
|
}
|
|
|
|
|
2008-07-18 15:27:57 +02:00
|
|
|
rules = XkbRF_Create();
|
2008-05-07 21:24:19 +02:00
|
|
|
if (!rules) {
|
|
|
|
LogMessage(X_ERROR, "XKB: Couldn't create rules struct\n");
|
2012-03-21 20:55:09 +01:00
|
|
|
fclose(file);
|
|
|
|
return FALSE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2008-05-07 21:24:19 +02:00
|
|
|
|
|
|
|
if (!XkbRF_LoadRules(file, rules)) {
|
|
|
|
LogMessage(X_ERROR, "XKB: Couldn't parse rules file %s\n", rules_name);
|
2012-03-21 20:55:09 +01:00
|
|
|
fclose(file);
|
|
|
|
XkbRF_Free(rules, TRUE);
|
|
|
|
return FALSE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2008-05-07 21:24:19 +02:00
|
|
|
|
|
|
|
memset(names, 0, sizeof(*names));
|
2012-03-21 20:55:09 +01:00
|
|
|
complete = XkbRF_GetComponents(rules, defs, names);
|
2003-11-14 16:54:54 +01:00
|
|
|
fclose(file);
|
2010-01-15 01:07:38 +01:00
|
|
|
XkbRF_Free(rules, TRUE);
|
2003-11-14 17:49:22 +01:00
|
|
|
|
2008-05-07 21:24:19 +02:00
|
|
|
if (!complete)
|
|
|
|
LogMessage(X_ERROR, "XKB: Rules returned no components\n");
|
2003-11-14 17:49:22 +01:00
|
|
|
|
2008-05-07 21:24:19 +02:00
|
|
|
return complete;
|
|
|
|
}
|
2008-12-26 08:38:25 +01:00
|
|
|
|
2011-02-10 06:11:34 +01:00
|
|
|
static Bool
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbRMLVOtoKcCGST(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
|
|
|
|
XkbComponentNamesPtr kccgst)
|
2008-12-26 08:38:25 +01:00
|
|
|
{
|
|
|
|
XkbRF_VarDefsRec mlvo;
|
|
|
|
|
|
|
|
mlvo.model = rmlvo->model;
|
|
|
|
mlvo.layout = rmlvo->layout;
|
|
|
|
mlvo.variant = rmlvo->variant;
|
|
|
|
mlvo.options = rmlvo->options;
|
|
|
|
|
2011-02-10 06:11:34 +01:00
|
|
|
return XkbDDXNamesFromRules(dev, rmlvo->rules, &mlvo, kccgst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compile the given RMLVO keymap and return it. Returns the XkbDescPtr on
|
|
|
|
* success or NULL on failure. If the components compiled are not a superset
|
|
|
|
* or equal to need, the compiliation is treated as failure.
|
|
|
|
*/
|
|
|
|
static XkbDescPtr
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbCompileKeymapForDevice(DeviceIntPtr dev, XkbRMLVOSet * rmlvo, int need)
|
2011-02-10 06:11:34 +01:00
|
|
|
{
|
2011-03-11 13:30:49 +01:00
|
|
|
XkbDescPtr xkb = NULL;
|
2011-02-10 06:11:34 +01:00
|
|
|
unsigned int provided;
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbComponentNamesRec kccgst = { 0 };
|
2011-02-10 06:11:34 +01:00
|
|
|
char name[PATH_MAX];
|
|
|
|
|
2011-03-11 13:30:49 +01:00
|
|
|
if (XkbRMLVOtoKcCGST(dev, rmlvo, &kccgst)) {
|
2012-03-21 20:55:09 +01:00
|
|
|
provided =
|
|
|
|
XkbDDXLoadKeymapByNames(dev, &kccgst, XkmAllIndicesMask, need, &xkb,
|
|
|
|
name, PATH_MAX);
|
2011-03-11 13:30:49 +01:00
|
|
|
if ((need & provided) != need) {
|
|
|
|
if (xkb) {
|
|
|
|
XkbFreeKeyboard(xkb, 0, TRUE);
|
|
|
|
xkb = NULL;
|
|
|
|
}
|
2011-02-10 06:11:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-11 13:30:49 +01:00
|
|
|
XkbFreeComponentNames(&kccgst, FALSE);
|
2011-02-10 06:11:34 +01:00
|
|
|
return xkb;
|
|
|
|
}
|
|
|
|
|
2014-03-12 08:20:17 +01:00
|
|
|
static XkbDescPtr
|
|
|
|
KeymapOrDefaults(DeviceIntPtr dev, XkbDescPtr xkb)
|
|
|
|
{
|
|
|
|
XkbRMLVOSet dflts;
|
|
|
|
|
|
|
|
if (xkb)
|
|
|
|
return xkb;
|
|
|
|
|
|
|
|
/* we didn't get what we really needed. And that will likely leave
|
|
|
|
* us with a keyboard that doesn't work. Use the defaults instead */
|
|
|
|
LogMessage(X_ERROR, "XKB: Failed to load keymap. Loading default "
|
|
|
|
"keymap instead.\n");
|
|
|
|
|
|
|
|
XkbGetRulesDflts(&dflts);
|
|
|
|
|
|
|
|
xkb = XkbCompileKeymapForDevice(dev, &dflts, 0);
|
|
|
|
|
|
|
|
XkbFreeRMLVOSet(&dflts, FALSE);
|
|
|
|
|
|
|
|
return xkb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 06:11:34 +01:00
|
|
|
XkbDescPtr
|
2012-03-21 20:55:09 +01:00
|
|
|
XkbCompileKeymap(DeviceIntPtr dev, XkbRMLVOSet * rmlvo)
|
2011-02-10 06:11:34 +01:00
|
|
|
{
|
|
|
|
XkbDescPtr xkb;
|
xkb: if the keymap failed to compile, load the default keymap instead.
We really need symbols, compat, keynames, vmods and types for a sensible keymap.
Try this in your xorg.conf.d snippets for all keyboards:
Option "XkbLayout" "us"
Option "XkbVariant" "nodeadkeys"
us(nodeadkeys) doesn't exist so xkbcomp provides everything but the symbols
map. We say we want everything but don't _need_ anything, the server happily
gives us a keymap with every key mapped to NoSymbol. This in turn isn't what
we want after all.
So instead, require symbols, compat, keynames, vmods and types from the
keymap and if that fails, load the default keymap instead. If that fails
too, all bets are off.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Dan Nicholson <dbn.lists@gmail.com>
2011-02-10 06:12:14 +01:00
|
|
|
unsigned int need;
|
2011-02-10 06:11:34 +01:00
|
|
|
|
|
|
|
if (!dev || !rmlvo) {
|
|
|
|
LogMessage(X_ERROR, "XKB: No device or RMLVO specified\n");
|
2008-12-26 08:38:25 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
xkb: if the keymap failed to compile, load the default keymap instead.
We really need symbols, compat, keynames, vmods and types for a sensible keymap.
Try this in your xorg.conf.d snippets for all keyboards:
Option "XkbLayout" "us"
Option "XkbVariant" "nodeadkeys"
us(nodeadkeys) doesn't exist so xkbcomp provides everything but the symbols
map. We say we want everything but don't _need_ anything, the server happily
gives us a keymap with every key mapped to NoSymbol. This in turn isn't what
we want after all.
So instead, require symbols, compat, keynames, vmods and types from the
keymap and if that fails, load the default keymap instead. If that fails
too, all bets are off.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Dan Nicholson <dbn.lists@gmail.com>
2011-02-10 06:12:14 +01:00
|
|
|
/* These are the components we really really need */
|
|
|
|
need = XkmSymbolsMask | XkmCompatMapMask | XkmTypesMask |
|
2012-03-21 20:55:09 +01:00
|
|
|
XkmKeyNamesMask | XkmVirtualModsMask;
|
xkb: if the keymap failed to compile, load the default keymap instead.
We really need symbols, compat, keynames, vmods and types for a sensible keymap.
Try this in your xorg.conf.d snippets for all keyboards:
Option "XkbLayout" "us"
Option "XkbVariant" "nodeadkeys"
us(nodeadkeys) doesn't exist so xkbcomp provides everything but the symbols
map. We say we want everything but don't _need_ anything, the server happily
gives us a keymap with every key mapped to NoSymbol. This in turn isn't what
we want after all.
So instead, require symbols, compat, keynames, vmods and types from the
keymap and if that fails, load the default keymap instead. If that fails
too, all bets are off.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Dan Nicholson <dbn.lists@gmail.com>
2011-02-10 06:12:14 +01:00
|
|
|
|
|
|
|
xkb = XkbCompileKeymapForDevice(dev, rmlvo, need);
|
|
|
|
|
2014-03-12 08:20:17 +01:00
|
|
|
return KeymapOrDefaults(dev, xkb);
|
2008-12-26 08:38:25 +01:00
|
|
|
}
|
2014-03-12 07:31:25 +01:00
|
|
|
|
|
|
|
XkbDescPtr
|
|
|
|
XkbCompileKeymapFromString(DeviceIntPtr dev,
|
|
|
|
const char *keymap, int keymap_length)
|
|
|
|
{
|
|
|
|
XkbDescPtr xkb;
|
|
|
|
unsigned int need, provided;
|
|
|
|
|
|
|
|
if (!dev || !keymap) {
|
|
|
|
LogMessage(X_ERROR, "XKB: No device or keymap specified\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These are the components we really really need */
|
|
|
|
need = XkmSymbolsMask | XkmCompatMapMask | XkmTypesMask |
|
|
|
|
XkmKeyNamesMask | XkmVirtualModsMask;
|
|
|
|
|
|
|
|
provided =
|
|
|
|
XkbDDXLoadKeymapFromString(dev, keymap, keymap_length,
|
|
|
|
XkmAllIndicesMask, need, &xkb);
|
|
|
|
if ((need & provided) != need) {
|
|
|
|
if (xkb) {
|
|
|
|
XkbFreeKeyboard(xkb, 0, TRUE);
|
|
|
|
xkb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return KeymapOrDefaults(dev, xkb);
|
|
|
|
}
|