Exemple #1
0
void
print_selection(int wn, xcb_window_t *windows, int wsel)
{
    char *wname, *wclass, *winstance = 0;
    int wdesktop, i = 0;
    
    for (i = 0; i < wn; i++) {
	if (wsel == i) {
	    printf(">");
	}
	
	wname     = get_prop_string(XCB_ATOM_WM_NAME, windows[i]);
	wclass    = get_prop_string(XCB_ATOM_WM_CLASS, windows[i]);
	winstance = &wclass[strlen(wclass)+1];
	wdesktop  = desktop_of_window(windows[i])+1;

	printf(" %d: [%s] %s\n", wdesktop, winstance, wname);
    }
}
Exemple #2
0
static void
device_added(LibHalContext *hal_ctx, const char *udi)
{
    char *path = NULL, *driver = NULL, *name = NULL, *config_info = NULL;
    InputOption *options = NULL, *tmpo = NULL;
    DeviceIntPtr dev = NULL;
    DBusError error;
    struct xkb_options xkb_opts = {0};
    int rc;

    LibHalPropertySet *set = NULL;
	LibHalPropertySetIterator set_iter;
    char *psi_key = NULL, *tmp_val;


    dbus_error_init(&error);

    driver = get_prop_string(hal_ctx, udi, "input.x11_driver");
    if (!driver){
        /* verbose, don't tell the user unless they _want_ to see it */
        LogMessageVerb(X_INFO,7,"config/hal: no driver specified for device %s\n", udi);
        goto unwind;
    }

    path = get_prop_string(hal_ctx, udi, "input.device");
    if (!path) {
        LogMessage(X_WARNING,"config/hal: no driver or path specified for %s\n", udi);
        goto unwind;
    }

    name = get_prop_string(hal_ctx, udi, "info.product");
    if (!name)
        name = xstrdup("(unnamed)");

    options = xcalloc(sizeof(*options), 1);
    if (!options){
        LogMessage(X_ERROR, "config/hal: couldn't allocate space for input options!\n");
        goto unwind;
    }

    options->key = xstrdup("_source");
    options->value = xstrdup("server/hal");
    if (!options->key || !options->value) {
        LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n");
        goto unwind;
    }

    /* most drivers use device.. not path. evdev uses both however, but the
     * path version isn't documented apparently. support both for now. */
    add_option(&options, "path", path);
    add_option(&options, "device", path);

    add_option(&options, "driver", driver);
    add_option(&options, "name", name);

    config_info = xalloc(strlen(udi) + 5); /* "hal:" and NULL */
    if (!config_info) {
        LogMessage(X_ERROR, "config/hal: couldn't allocate name\n");
        goto unwind;
    }
    sprintf(config_info, "hal:%s", udi);

    /* Check for duplicate devices */
    if (device_is_duplicate(config_info))
    {
        LogMessage(X_WARNING, "config/hal: device %s already added. Ignoring.\n", name);
        goto unwind;
    }

    /* ok, grab options from hal.. iterate through all properties
    * and lets see if any of them are options that we can add */
    set = libhal_device_get_all_properties(hal_ctx, udi, &error);

    if (!set) {
        LogMessage(X_ERROR, "config/hal: couldn't get property list for %s: %s (%s)\n",
               udi, error.name, error.message);
        goto unwind;
    }

    libhal_psi_init(&set_iter,set);
    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);

        if (psi_key){

            /* normal options first (input.x11_options.<propname>) */
            if (!strncasecmp(psi_key, LIBHAL_PROP_KEY, sizeof(LIBHAL_PROP_KEY)-1)){
                char* tmp;

                /* only support strings for all values */
                tmp_val = get_prop_string(hal_ctx, udi, psi_key);

                if (tmp_val){

                    /* 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.
                     */
                    if ((tmp = strcasestr(psi_key, "xkb")) && strlen(tmp) >= 4)
                    {
                        if (!strcasecmp(&tmp[3], "layout"))
                        {
                            if (xkb_opts.layout)
                                xfree(xkb_opts.layout);
                            xkb_opts.layout = strdup(tmp_val);
                        } else if (!strcasecmp(&tmp[3], "model"))
                        {
                            if (xkb_opts.model)
                                xfree(xkb_opts.model);
                            xkb_opts.model = strdup(tmp_val);
                        } else if (!strcasecmp(&tmp[3], "rules"))
                        {
                            if (xkb_opts.rules)
                                xfree(xkb_opts.rules);
                            xkb_opts.rules = strdup(tmp_val);
                        } else if (!strcasecmp(&tmp[3], "variant"))
                        {
                            if (xkb_opts.variant)
                                xfree(xkb_opts.variant);
                            xkb_opts.variant = strdup(tmp_val);
                        } else if (!strcasecmp(&tmp[3], "options"))
                        {
                            if (xkb_opts.options)
                                xfree(xkb_opts.options);
                            xkb_opts.options = strdup(tmp_val);
                        }
                    } else
                    {
                        /* all others */
                        add_option(&options, psi_key + sizeof(LIBHAL_PROP_KEY)-1, tmp_val);
                        xfree(tmp_val);
                    }
                } else
                {
                    /* server 1.4 had xkb_options as strlist. */
                    if ((tmp = strcasestr(psi_key, "xkb")) &&
                        (strlen(tmp) >= 4) &&
                        (!strcasecmp(&tmp[3], "options")) &&
                        (tmp_val = get_prop_string_array(hal_ctx, udi, psi_key)))
                    {
                        if (xkb_opts.options)
                            xfree(xkb_opts.options);
                        xkb_opts.options = strdup(tmp_val);
                    }
                }
            } else if (!strncasecmp(psi_key, LIBHAL_XKB_PROP_KEY, sizeof(LIBHAL_XKB_PROP_KEY)-1)){
                char* tmp;

                /* 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];

                    if (!strcasecmp(tmp, "layout"))
                    {
                        if (!xkb_opts.layout)
                            xkb_opts.layout = strdup(tmp_val);
                    } else if (!strcasecmp(tmp, "rules"))
                    {
                        if (!xkb_opts.rules)
                            xkb_opts.rules = strdup(tmp_val);
                    } else if (!strcasecmp(tmp, "variant"))
                    {
                        if (!xkb_opts.variant)
                            xkb_opts.variant = strdup(tmp_val);
                    } else if (!strcasecmp(tmp, "model"))
                    {
                        if (!xkb_opts.model)
                            xkb_opts.model = strdup(tmp_val);
                    } else if (!strcasecmp(tmp, "options"))
                    {
                        if (!xkb_opts.options)
                            xkb_opts.options = strdup(tmp_val);
                    }
                    xfree(tmp_val);
                } else
                {
                    /* server 1.4 had xkb options as strlist */
                    tmp_val = get_prop_string_array(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];
                        if (!strcasecmp(tmp, ".options") && (!xkb_opts.options))
                            xkb_opts.options = strdup(tmp_val);
                    }
                }
            }
        }

        /* psi_key doesn't need to be freed */
        libhal_psi_next(&set_iter);
    }


    /* Now add xkb options */
    if (xkb_opts.layout)
        add_option(&options, "xkb_layout", xkb_opts.layout);
    if (xkb_opts.rules)
        add_option(&options, "xkb_rules", xkb_opts.rules);
    if (xkb_opts.variant)
        add_option(&options, "xkb_variant", xkb_opts.variant);
    if (xkb_opts.model)
        add_option(&options, "xkb_model", xkb_opts.model);
    if (xkb_opts.options)
        add_option(&options, "xkb_options", xkb_opts.options);

    /* 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);
    if ((rc = NewInputDeviceRequest(options, &dev)) != Success) {
        LogMessage(X_ERROR, "config/hal: NewInputDeviceRequest failed (%d)\n", rc);
        dev = NULL;
        goto unwind;
    }

    for (; dev; dev = dev->next){
        if (dev->config_info)
            xfree(dev->config_info);
        dev->config_info = xstrdup(config_info);
    }

unwind:
    if (set)
        libhal_free_property_set(set);
    if (path)
        xfree(path);
    if (driver)
        xfree(driver);
    if (name)
        xfree(name);
    if (config_info)
        xfree(config_info);
    while (!dev && (tmpo = options)) {
        options = tmpo->next;
        xfree(tmpo->key);
        xfree(tmpo->value);
        xfree(tmpo);
    }

    if (xkb_opts.layout)
        xfree(xkb_opts.layout);
    if (xkb_opts.rules)
        xfree(xkb_opts.rules);
    if (xkb_opts.model)
        xfree(xkb_opts.model);
    if (xkb_opts.variant)
        xfree(xkb_opts.variant);
    if (xkb_opts.options)
        xfree(xkb_opts.options);

    dbus_error_free(&error);

    return;
}
Exemple #3
0
static void
device_added(LibHalContext *hal_ctx, const char *udi)
{
    char **props;
    /* Cleverly, these are currently all leaked. */
    char *path = NULL, *driver = NULL, *name = NULL, *xkb_rules = NULL;
    char *xkb_model = NULL, *xkb_layout = NULL, *xkb_variant = NULL;
    char **xkb_options = NULL;
    DBusError error;
    struct xserver_option *options = NULL;
    int type = TYPE_NONE;
    int i;
    DeviceIntPtr dev = NULL;

    dbus_error_init(&error);

    props = libhal_device_get_property_strlist(hal_ctx, udi,
                                               "info.capabilities", &error);
    if (!props) {
        DebugF("[config/hal] couldn't get capabilities for %s: %s (%s)\n",
               udi, error.name, error.message);
        goto out_error;
    }
    for (i = 0; props[i]; i++) {
        /* input.keys is the new, of which input.keyboard is a subset, but
         * input.keyboard is the old 'we have keys', so we have to keep it
         * around. */
        if (strcmp(props[i], "input.keys") == 0 ||
            strcmp(props[i], "input.keyboard") == 0)
            type |= TYPE_KEYS;
        if (strcmp(props[i], "input.mouse") == 0)
            type |= TYPE_POINTER;
    }
    libhal_free_string_array(props);

    if (!type)
        goto out_error;

    driver = get_prop_string(hal_ctx, udi, "input.x11_driver");
    path = get_prop_string(hal_ctx, udi, "input.device");
    if (!driver || !path) {
        DebugF("[config/hal] no driver or path specified for %s\n", udi);
        goto unwind;
    }
    name = get_prop_string(hal_ctx, udi, "info.product");
    if (!name)
        name = xstrdup("(unnamed)");

    if (type & TYPE_KEYS) {
        xkb_rules = get_prop_string(hal_ctx, udi, "input.xkb.rules");
        xkb_model = get_prop_string(hal_ctx, udi, "input.xkb.model");
        xkb_layout = get_prop_string(hal_ctx, udi, "input.xkb.layout");
        xkb_variant = get_prop_string(hal_ctx, udi, "input.xkb.variant");
        xkb_options = get_prop_string_array(hal_ctx, udi, "input.xkb.options");
    }

    options = xcalloc(sizeof(*options), 1);
    options->key = xstrdup("_source");
    options->value = xstrdup("server/hal");
    if (!options->key || !options->value) {
        ErrorF("[config] couldn't allocate first key/value pair\n");
        goto unwind;
    }

    add_option(&options, "path", path);
    add_option(&options, "driver", driver);
    add_option(&options, "name", name);
    add_option(&options, "hal_udi", udi);

    if (xkb_model)
        add_option(&options, "xkb_model", xkb_model);
    if (xkb_layout)
        add_option(&options, "xkb_layout", xkb_layout);
    if (xkb_variant)
        add_option(&options, "xkb_variant", xkb_variant);
#if 0
    if (xkb_options)
        add_option(&options, "xkb_options", xkb_options);
#endif

    /* Maemo-specific hack.  Ugh. */
    if (type & TYPE_KEYS)
        add_option(&options, "type", "keyboard");
    else
        add_option(&options, "type", "pointer");

    if (NewInputDeviceRequest(options, &dev) != Success) {
        DebugF("[config/hal] NewInputDeviceRequest failed\n");
        goto unwind;
    }

    dbus_error_free(&error);

    return;

unwind:
    if (path)
        xfree(path);
    if (driver)
        xfree(driver);
    if (name)
        xfree(name);
    if (xkb_rules)
        xfree(xkb_rules);
    if (xkb_model)
        xfree(xkb_model);
    if (xkb_layout)
        xfree(xkb_layout);
    if (xkb_options) {
        for (i = 0; xkb_options[i]; i++)
            xfree(xkb_options[i]);
        xfree(xkb_options);
    }

out_error:
    dbus_error_free(&error);

    return;
}