2007-11-24 10:55:21 -07:00
|
|
|
/*
|
|
|
|
* Copyright © 2007 Daniel Stone
|
2008-11-02 08:26:08 -07:00
|
|
|
* Copyright © 2007 Red Hat, Inc.
|
2007-11-24 10:55:21 -07:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author: Daniel Stone <daniel@fooishbar.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
#include <hal/libhal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
#include "dbus-core.h"
|
2007-11-24 10:55:21 -07:00
|
|
|
#include "input.h"
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "hotplug.h"
|
|
|
|
#include "config-backends.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
#define LIBHAL_PROP_KEY "input.x11_options."
|
|
|
|
#define LIBHAL_XKB_PROP_KEY "input.xkb."
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
struct config_hal_info {
|
|
|
|
DBusConnection *system_bus;
|
|
|
|
LibHalContext *hal_ctx;
|
|
|
|
};
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* Used for special handling of xkb options. */
|
|
|
|
struct xkb_options {
|
2012-06-10 07:21:05 -06:00
|
|
|
char *layout;
|
|
|
|
char *model;
|
|
|
|
char *rules;
|
|
|
|
char *variant;
|
|
|
|
char *options;
|
2008-11-02 08:26:08 -07:00
|
|
|
};
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
device_removed(LibHalContext * ctx, const char *udi)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
|
|
|
char *value;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (asprintf(&value, "hal:%s", udi) == -1)
|
2007-11-24 10:55:21 -07:00
|
|
|
return;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
remove_devices("hal", value);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(value);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2012-06-10 07:21:05 -06:00
|
|
|
get_prop_string(LibHalContext * hal_ctx, const char *udi, const char *name)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
|
|
|
char *prop, *ret;
|
|
|
|
|
|
|
|
prop = libhal_device_get_property_string(hal_ctx, udi, name, NULL);
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessageVerb(X_INFO, 10, "config/hal: getting %s on %s returned %s\n",
|
|
|
|
name, udi, prop ? prop : "(null)");
|
2007-11-24 10:55:21 -07:00
|
|
|
if (prop) {
|
2010-12-05 08:36:02 -07:00
|
|
|
ret = strdup(prop);
|
2007-11-24 10:55:21 -07:00
|
|
|
libhal_free_string(prop);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2012-06-10 07:21:05 -06:00
|
|
|
get_prop_string_array(LibHalContext * hal_ctx, const char *udi,
|
|
|
|
const char *prop)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
|
|
|
char **props, *ret, *str;
|
|
|
|
int i, len = 0;
|
|
|
|
|
|
|
|
props = libhal_device_get_property_strlist(hal_ctx, udi, prop, NULL);
|
|
|
|
if (props) {
|
|
|
|
for (i = 0; props[i]; i++)
|
|
|
|
len += strlen(props[i]);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
ret = calloc(sizeof(char), len + i); /* i - 1 commas, 1 NULL */
|
2007-11-24 10:55:21 -07:00
|
|
|
if (!ret) {
|
|
|
|
libhal_free_string_array(props);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = ret;
|
|
|
|
for (i = 0; props[i]; i++) {
|
2007-12-13 14:06:02 -07:00
|
|
|
strcpy(str, props[i]);
|
|
|
|
str += strlen(props[i]);
|
2007-11-24 10:55:21 -07:00
|
|
|
*str++ = ',';
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
*(str - 1) = '\0';
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
libhal_free_string_array(props);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
device_added(LibHalContext * hal_ctx, const char *udi)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
char *path = NULL, *driver = NULL, *name = NULL, *config_info = NULL;
|
2010-12-05 08:36:02 -07:00
|
|
|
char *hal_tags, *parent;
|
2012-06-10 07:21:05 -06:00
|
|
|
InputOption *input_options = NULL;
|
|
|
|
InputAttributes attrs = { 0 };
|
2009-09-06 13:44:18 -06:00
|
|
|
DeviceIntPtr dev = NULL;
|
2007-11-24 10:55:21 -07:00
|
|
|
DBusError error;
|
2012-06-10 07:21:05 -06:00
|
|
|
struct xkb_options xkb_opts = { 0 };
|
2009-09-06 13:44:18 -06:00
|
|
|
int rc;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
LibHalPropertySet *set = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
LibHalPropertySetIterator set_iter;
|
2008-11-02 08:26:08 -07:00
|
|
|
char *psi_key = NULL, *tmp_val;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
dbus_error_init(&error);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
driver = get_prop_string(hal_ctx, udi, "input.x11_driver");
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!driver) {
|
2008-11-02 08:26:08 -07:00
|
|
|
/* verbose, don't tell the user unless they _want_ to see it */
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessageVerb(X_INFO, 7,
|
|
|
|
"config/hal: no driver specified for device %s\n", udi);
|
2008-11-02 08:26:08 -07:00
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
path = get_prop_string(hal_ctx, udi, "input.device");
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!path) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"config/hal: no driver or path specified for %s\n", udi);
|
2007-11-24 10:55:21 -07:00
|
|
|
goto unwind;
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
attrs.device = strdup(path);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
name = get_prop_string(hal_ctx, udi, "info.product");
|
|
|
|
if (!name)
|
2010-12-05 08:36:02 -07:00
|
|
|
name = strdup("(unnamed)");
|
2010-07-27 13:02:24 -06:00
|
|
|
else
|
2010-12-05 08:36:02 -07:00
|
|
|
attrs.product = strdup(name);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
attrs.vendor = get_prop_string(hal_ctx, udi, "info.vendor");
|
2010-12-05 08:36:02 -07:00
|
|
|
hal_tags = get_prop_string(hal_ctx, udi, "input.tags");
|
|
|
|
attrs.tags = xstrtokenize(hal_tags, ",");
|
|
|
|
free(hal_tags);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (libhal_device_query_capability(hal_ctx, udi, "input.keys", NULL))
|
2017-12-08 08:01:59 -07:00
|
|
|
attrs.flags |= ATTR_KEY | ATTR_KEYBOARD;
|
2010-07-27 13:02:24 -06:00
|
|
|
if (libhal_device_query_capability(hal_ctx, udi, "input.mouse", NULL))
|
|
|
|
attrs.flags |= ATTR_POINTER;
|
|
|
|
if (libhal_device_query_capability(hal_ctx, udi, "input.joystick", NULL))
|
|
|
|
attrs.flags |= ATTR_JOYSTICK;
|
|
|
|
if (libhal_device_query_capability(hal_ctx, udi, "input.tablet", NULL))
|
|
|
|
attrs.flags |= ATTR_TABLET;
|
2017-12-08 08:01:59 -07:00
|
|
|
if (libhal_device_query_capability(hal_ctx, udi, "input.tablet_pad", NULL))
|
|
|
|
attrs.flags |= ATTR_TABLET_PAD;
|
2010-07-27 13:02:24 -06:00
|
|
|
if (libhal_device_query_capability(hal_ctx, udi, "input.touchpad", NULL))
|
|
|
|
attrs.flags |= ATTR_TOUCHPAD;
|
|
|
|
if (libhal_device_query_capability(hal_ctx, udi, "input.touchscreen", NULL))
|
|
|
|
attrs.flags |= ATTR_TOUCHSCREEN;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
parent = get_prop_string(hal_ctx, udi, "info.parent");
|
|
|
|
if (parent) {
|
|
|
|
int usb_vendor, usb_product;
|
2014-05-02 13:27:46 -06:00
|
|
|
char *old_parent;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
|
|
|
/* construct USB ID in lowercase - "0000:ffff" */
|
|
|
|
usb_vendor = libhal_device_get_property_int(hal_ctx, parent,
|
|
|
|
"usb.vendor_id", NULL);
|
|
|
|
LogMessageVerb(X_INFO, 10,
|
|
|
|
"config/hal: getting usb.vendor_id on %s "
|
|
|
|
"returned %04x\n", parent, usb_vendor);
|
|
|
|
usb_product = libhal_device_get_property_int(hal_ctx, parent,
|
|
|
|
"usb.product_id", NULL);
|
|
|
|
LogMessageVerb(X_INFO, 10,
|
|
|
|
"config/hal: getting usb.product_id on %s "
|
|
|
|
"returned %04x\n", parent, usb_product);
|
|
|
|
if (usb_vendor && usb_product)
|
2011-11-05 07:32:40 -06:00
|
|
|
if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_product)
|
2012-06-10 07:21:05 -06:00
|
|
|
== -1)
|
|
|
|
attrs.usb_id = NULL;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
attrs.pnp_id = get_prop_string(hal_ctx, parent, "pnp.id");
|
|
|
|
old_parent = parent;
|
|
|
|
|
|
|
|
while (!attrs.pnp_id &&
|
|
|
|
(parent = get_prop_string(hal_ctx, parent, "info.parent"))) {
|
|
|
|
attrs.pnp_id = get_prop_string(hal_ctx, parent, "pnp.id");
|
|
|
|
|
|
|
|
free(old_parent);
|
|
|
|
old_parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(old_parent);
|
2010-12-05 08:36:02 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options = input_option_new(NULL, "_source", "server/hal");
|
|
|
|
if (!input_options) {
|
|
|
|
LogMessage(X_ERROR,
|
|
|
|
"config/hal: couldn't allocate first key/value pair\n");
|
2007-11-24 10:55:21 -07:00
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* most drivers use device.. not path. evdev uses both however, but the
|
|
|
|
* path version isn't documented apparently. support both for now. */
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options = input_option_new(input_options, "path", path);
|
|
|
|
input_options = input_option_new(input_options, "device", path);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options = input_option_new(input_options, "driver", driver);
|
|
|
|
input_options = input_option_new(input_options, "name", name);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (asprintf(&config_info, "hal:%s", udi) == -1) {
|
2011-11-05 07:32:40 -06:00
|
|
|
config_info = NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
LogMessage(X_ERROR, "config/hal: couldn't allocate name\n");
|
2007-11-24 10:55:21 -07:00
|
|
|
goto unwind;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-01-12 13:17:47 -07:00
|
|
|
/* Check for duplicate devices */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (device_is_duplicate(config_info)) {
|
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"config/hal: device %s already added. Ignoring.\n", name);
|
2009-01-12 13:17:47 -07:00
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* ok, grab options from hal.. iterate through all properties
|
2012-06-10 07:21:05 -06:00
|
|
|
* and lets see if any of them are options that we can add */
|
2008-11-02 08:26:08 -07:00
|
|
|
set = libhal_device_get_all_properties(hal_ctx, udi, &error);
|
|
|
|
|
|
|
|
if (!set) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_ERROR,
|
|
|
|
"config/hal: couldn't get property list for %s: %s (%s)\n",
|
|
|
|
udi, error.name, error.message);
|
2008-11-02 08:26:08 -07:00
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
libhal_psi_init(&set_iter, set);
|
2008-11-02 08:26:08 -07:00
|
|
|
while (libhal_psi_has_more(&set_iter)) {
|
|
|
|
/* we are looking for supported keys.. extract and add to options */
|
|
|
|
psi_key = libhal_psi_get_key(&set_iter);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (psi_key) {
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* normal options first (input.x11_options.<propname>) */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!strncasecmp
|
|
|
|
(psi_key, LIBHAL_PROP_KEY, sizeof(LIBHAL_PROP_KEY) - 1)) {
|
|
|
|
char *tmp;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* only support strings for all values */
|
|
|
|
tmp_val = get_prop_string(hal_ctx, udi, psi_key);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (tmp_val) {
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* xkb needs special handling. HAL specs include
|
|
|
|
* input.xkb.xyz options, but the x11-input.fdi specifies
|
|
|
|
* input.x11_options.Xkbxyz options. By default, we use
|
|
|
|
* the former, unless the specific X11 ones are specified.
|
|
|
|
* Since we can't predict the order in which the keys
|
|
|
|
* arrive, we need to store them.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((tmp = strcasestr(psi_key, "xkb")) && strlen(tmp) >= 4) {
|
|
|
|
if (!strcasecmp(&tmp[3], "layout")) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb_opts.layout);
|
2008-11-02 08:26:08 -07:00
|
|
|
xkb_opts.layout = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(&tmp[3], "model")) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb_opts.model);
|
2008-11-02 08:26:08 -07:00
|
|
|
xkb_opts.model = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(&tmp[3], "rules")) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb_opts.rules);
|
2008-11-02 08:26:08 -07:00
|
|
|
xkb_opts.rules = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(&tmp[3], "variant")) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb_opts.variant);
|
2008-11-02 08:26:08 -07:00
|
|
|
xkb_opts.variant = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(&tmp[3], "options")) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb_opts.options);
|
2008-11-02 08:26:08 -07:00
|
|
|
xkb_opts.options = strdup(tmp_val);
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2008-11-02 08:26:08 -07:00
|
|
|
/* all others */
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options,
|
|
|
|
psi_key + sizeof(LIBHAL_PROP_KEY) -
|
|
|
|
1, tmp_val);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(tmp_val);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2008-11-02 08:26:08 -07:00
|
|
|
/* server 1.4 had xkb_options as strlist. */
|
|
|
|
if ((tmp = strcasestr(psi_key, "xkb")) &&
|
|
|
|
(strlen(tmp) >= 4) &&
|
|
|
|
(!strcasecmp(&tmp[3], "options")) &&
|
2012-06-10 07:21:05 -06:00
|
|
|
(tmp_val =
|
|
|
|
get_prop_string_array(hal_ctx, udi, psi_key))) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb_opts.options);
|
2008-11-02 08:26:08 -07:00
|
|
|
xkb_opts.options = strdup(tmp_val);
|
|
|
|
}
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strncasecmp
|
|
|
|
(psi_key, LIBHAL_XKB_PROP_KEY,
|
|
|
|
sizeof(LIBHAL_XKB_PROP_KEY) - 1)) {
|
|
|
|
char *tmp;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* only support strings for all values */
|
|
|
|
tmp_val = get_prop_string(hal_ctx, udi, psi_key);
|
|
|
|
|
|
|
|
if (tmp_val && strlen(psi_key) >= sizeof(LIBHAL_XKB_PROP_KEY)) {
|
|
|
|
|
|
|
|
tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1];
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!strcasecmp(tmp, "layout")) {
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!xkb_opts.layout)
|
|
|
|
xkb_opts.layout = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(tmp, "rules")) {
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!xkb_opts.rules)
|
|
|
|
xkb_opts.rules = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(tmp, "variant")) {
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!xkb_opts.variant)
|
|
|
|
xkb_opts.variant = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(tmp, "model")) {
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!xkb_opts.model)
|
|
|
|
xkb_opts.model = strdup(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (!strcasecmp(tmp, "options")) {
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!xkb_opts.options)
|
|
|
|
xkb_opts.options = strdup(tmp_val);
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(tmp_val);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2008-11-02 08:26:08 -07:00
|
|
|
/* server 1.4 had xkb options as strlist */
|
|
|
|
tmp_val = get_prop_string_array(hal_ctx, udi, psi_key);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (tmp_val &&
|
|
|
|
strlen(psi_key) >= sizeof(LIBHAL_XKB_PROP_KEY)) {
|
2008-11-02 08:26:08 -07:00
|
|
|
tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1];
|
|
|
|
if (!strcasecmp(tmp, ".options") && (!xkb_opts.options))
|
|
|
|
xkb_opts.options = strdup(tmp_val);
|
|
|
|
}
|
2011-12-18 09:08:59 -07:00
|
|
|
free(tmp_val);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* psi_key doesn't need to be freed */
|
|
|
|
libhal_psi_next(&set_iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now add xkb options */
|
|
|
|
if (xkb_opts.layout)
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_layout", xkb_opts.layout);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (xkb_opts.rules)
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_rules", xkb_opts.rules);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (xkb_opts.variant)
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_variant", xkb_opts.variant);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (xkb_opts.model)
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_model", xkb_opts.model);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (xkb_opts.options)
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_options", xkb_opts.options);
|
|
|
|
input_options = input_option_new(input_options, "config_info", config_info);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* this isn't an error, but how else do you output something that the user can see? */
|
|
|
|
LogMessage(X_INFO, "config/hal: Adding input device %s\n", name);
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((rc = NewInputDeviceRequest(input_options, &attrs, &dev)) != Success) {
|
|
|
|
LogMessage(X_ERROR, "config/hal: NewInputDeviceRequest failed (%d)\n",
|
|
|
|
rc);
|
2008-06-14 18:17:32 -06:00
|
|
|
dev = NULL;
|
2007-11-24 10:55:21 -07:00
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
unwind:
|
2008-11-02 08:26:08 -07:00
|
|
|
if (set)
|
|
|
|
libhal_free_property_set(set);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(path);
|
|
|
|
free(driver);
|
|
|
|
free(name);
|
|
|
|
free(config_info);
|
2012-06-10 07:21:05 -06:00
|
|
|
input_option_free_list(&input_options);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(attrs.product);
|
|
|
|
free(attrs.vendor);
|
|
|
|
free(attrs.device);
|
|
|
|
free(attrs.pnp_id);
|
|
|
|
free(attrs.usb_id);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (attrs.tags) {
|
|
|
|
char **tag = attrs.tags;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
while (*tag) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(*tag);
|
2010-07-27 13:02:24 -06:00
|
|
|
tag++;
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(attrs.tags);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(xkb_opts.layout);
|
|
|
|
free(xkb_opts.rules);
|
|
|
|
free(xkb_opts.model);
|
|
|
|
free(xkb_opts.variant);
|
|
|
|
free(xkb_opts.options);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
dbus_error_free(&error);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
disconnect_hook(void *data)
|
|
|
|
{
|
|
|
|
DBusError error;
|
|
|
|
struct config_hal_info *info = data;
|
|
|
|
|
|
|
|
if (info->hal_ctx) {
|
2008-11-02 08:26:08 -07:00
|
|
|
if (dbus_connection_get_is_connected(info->system_bus)) {
|
|
|
|
dbus_error_init(&error);
|
|
|
|
if (!libhal_ctx_shutdown(info->hal_ctx, &error))
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"config/hal: disconnect_hook couldn't shut down context: %s (%s)\n",
|
|
|
|
error.name, error.message);
|
2008-11-02 08:26:08 -07:00
|
|
|
dbus_error_free(&error);
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
libhal_ctx_free(info->hal_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
info->hal_ctx = NULL;
|
|
|
|
info->system_bus = NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static BOOL
|
2012-06-10 07:21:05 -06:00
|
|
|
connect_and_register(DBusConnection * connection, struct config_hal_info *info)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
|
|
|
DBusError error;
|
|
|
|
char **devices;
|
|
|
|
int num_devices, i;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (info->hal_ctx)
|
2012-06-10 07:21:05 -06:00
|
|
|
return TRUE; /* already registered, pretend we did something */
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
info->system_bus = connection;
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
info->hal_ctx = libhal_ctx_new();
|
2007-11-24 10:55:21 -07:00
|
|
|
if (!info->hal_ctx) {
|
2008-11-02 08:26:08 -07:00
|
|
|
LogMessage(X_ERROR, "config/hal: couldn't create HAL context\n");
|
2007-11-24 10:55:21 -07:00
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!libhal_ctx_set_dbus_connection(info->hal_ctx, info->system_bus)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_ERROR,
|
|
|
|
"config/hal: couldn't associate HAL context with bus\n");
|
2009-09-06 13:44:18 -06:00
|
|
|
goto out_err;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
if (!libhal_ctx_init(info->hal_ctx, &error)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_ERROR,
|
|
|
|
"config/hal: couldn't initialise context: %s (%s)\n",
|
|
|
|
error.name ? error.name : "unknown error",
|
|
|
|
error.message ? error.message : "null");
|
2009-09-06 13:44:18 -06:00
|
|
|
goto out_err;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
if (!libhal_device_property_watch_all(info->hal_ctx, &error)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_ERROR,
|
|
|
|
"config/hal: couldn't watch all properties: %s (%s)\n",
|
|
|
|
error.name ? error.name : "unknown error",
|
|
|
|
error.message ? error.message : "null");
|
2009-09-06 13:44:18 -06:00
|
|
|
goto out_ctx;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
libhal_ctx_set_device_added(info->hal_ctx, device_added);
|
|
|
|
libhal_ctx_set_device_removed(info->hal_ctx, device_removed);
|
|
|
|
|
|
|
|
devices = libhal_find_device_by_capability(info->hal_ctx, "input",
|
|
|
|
&num_devices, &error);
|
|
|
|
/* FIXME: Get default devices if error is set. */
|
2009-09-06 13:44:18 -06:00
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
LogMessage(X_ERROR, "config/hal: couldn't find input device: %s (%s)\n",
|
2012-06-10 07:21:05 -06:00
|
|
|
error.name ? error.name : "unknown error",
|
|
|
|
error.message ? error.message : "null");
|
2009-09-06 13:44:18 -06:00
|
|
|
goto out_ctx;
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
for (i = 0; i < num_devices; i++)
|
|
|
|
device_added(info->hal_ctx, devices[i]);
|
|
|
|
libhal_free_string_array(devices);
|
|
|
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return TRUE;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
out_ctx:
|
2009-09-06 13:44:18 -06:00
|
|
|
dbus_error_free(&error);
|
|
|
|
|
|
|
|
if (!libhal_ctx_shutdown(info->hal_ctx, &error)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_WARNING,
|
|
|
|
"config/hal: couldn't shut down context: %s (%s)\n",
|
|
|
|
error.name ? error.name : "unknown error",
|
|
|
|
error.message ? error.message : "null");
|
2009-09-06 13:44:18 -06:00
|
|
|
dbus_error_free(&error);
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
out_err:
|
2007-11-24 10:55:21 -07:00
|
|
|
dbus_error_free(&error);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (info->hal_ctx) {
|
|
|
|
libhal_ctx_free(info->hal_ctx);
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
info->hal_ctx = NULL;
|
|
|
|
info->system_bus = NULL;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle NewOwnerChanged signals to deal with HAL startup at X server runtime.
|
|
|
|
*
|
|
|
|
* NewOwnerChanged is send once when HAL shuts down, and once again when it
|
|
|
|
* comes back up. Message has three arguments, first is the name
|
|
|
|
* (org.freedesktop.Hal), the second one is the old owner, third one is new
|
|
|
|
* owner.
|
|
|
|
*/
|
|
|
|
static DBusHandlerResult
|
2012-06-10 07:21:05 -06:00
|
|
|
ownerchanged_handler(DBusConnection * connection, DBusMessage * message,
|
|
|
|
void *data)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
int ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
|
|
|
|
if (dbus_message_is_signal(message,
|
2012-06-10 07:21:05 -06:00
|
|
|
"org.freedesktop.DBus", "NameOwnerChanged")) {
|
2009-09-06 13:44:18 -06:00
|
|
|
DBusError error;
|
|
|
|
char *name, *old_owner, *new_owner;
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
dbus_message_get_args(message, &error,
|
|
|
|
DBUS_TYPE_STRING, &name,
|
|
|
|
DBUS_TYPE_STRING, &old_owner,
|
2012-06-10 07:21:05 -06:00
|
|
|
DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF
|
|
|
|
("[config/hal] failed to get NameOwnerChanged args: %s (%s)\n",
|
|
|
|
error.name, error.message);
|
|
|
|
}
|
|
|
|
else if (name && strcmp(name, "org.freedesktop.Hal") == 0) {
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
if (!old_owner || !strlen(old_owner)) {
|
|
|
|
DebugF("[config/hal] HAL startup detected.\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
if (connect_and_register
|
|
|
|
(connection, (struct config_hal_info *) data))
|
2009-09-06 13:44:18 -06:00
|
|
|
dbus_connection_unregister_object_path(connection,
|
2012-06-10 07:21:05 -06:00
|
|
|
"/org/freedesktop/DBus");
|
2009-09-06 13:44:18 -06:00
|
|
|
else
|
|
|
|
ErrorF("[config/hal] Failed to connect to HAL bus.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
}
|
|
|
|
dbus_error_free(&error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a handler for the NameOwnerChanged signal.
|
|
|
|
*/
|
|
|
|
static BOOL
|
2012-06-10 07:21:05 -06:00
|
|
|
listen_for_startup(DBusConnection * connection, void *data)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DBusObjectPathVTable vtable = {.message_function = ownerchanged_handler, };
|
2009-09-06 13:44:18 -06:00
|
|
|
DBusError error;
|
|
|
|
const char MATCH_RULE[] = "sender='org.freedesktop.DBus',"
|
2012-06-10 07:21:05 -06:00
|
|
|
"interface='org.freedesktop.DBus',"
|
|
|
|
"type='signal',"
|
|
|
|
"path='/org/freedesktop/DBus'," "member='NameOwnerChanged'";
|
2009-09-06 13:44:18 -06:00
|
|
|
int rc = FALSE;
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
dbus_bus_add_match(connection, MATCH_RULE, &error);
|
|
|
|
if (!dbus_error_is_set(&error)) {
|
|
|
|
if (dbus_connection_register_object_path(connection,
|
2012-06-10 07:21:05 -06:00
|
|
|
"/org/freedesktop/DBus",
|
|
|
|
&vtable, data))
|
2009-09-06 13:44:18 -06:00
|
|
|
rc = TRUE;
|
|
|
|
else
|
|
|
|
ErrorF("[config/hal] cannot register object path.\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2009-09-06 13:44:18 -06:00
|
|
|
ErrorF("[config/hal] couldn't add match rule: %s (%s)\n", error.name,
|
2012-06-10 07:21:05 -06:00
|
|
|
error.message);
|
2009-09-06 13:44:18 -06:00
|
|
|
ErrorF("[config/hal] cannot detect a HAL startup.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
connect_hook(DBusConnection * connection, void *data)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
struct config_hal_info *info = data;
|
|
|
|
|
|
|
|
if (listen_for_startup(connection, data) &&
|
|
|
|
connect_and_register(connection, info))
|
|
|
|
dbus_connection_unregister_object_path(connection,
|
|
|
|
"/org/freedesktop/DBus");
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct config_hal_info hal_info;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
static struct dbus_core_hook hook = {
|
2007-11-24 10:55:21 -07:00
|
|
|
.connect = connect_hook,
|
|
|
|
.disconnect = disconnect_hook,
|
|
|
|
.data = &hal_info,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
config_hal_init(void)
|
|
|
|
{
|
|
|
|
memset(&hal_info, 0, sizeof(hal_info));
|
|
|
|
hal_info.system_bus = NULL;
|
|
|
|
hal_info.hal_ctx = NULL;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
if (!dbus_core_add_hook(&hook)) {
|
2008-11-02 08:26:08 -07:00
|
|
|
LogMessage(X_ERROR, "config/hal: failed to add D-Bus hook\n");
|
2007-11-24 10:55:21 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* verbose message */
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessageVerb(X_INFO, 7, "config/hal: initialized\n");
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
config_hal_fini(void)
|
|
|
|
{
|
2014-09-27 11:52:59 -06:00
|
|
|
dbus_core_remove_hook(&hook);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|