Package: halevt Version: 0.1.3-3 Severity: wishlist Tags: patch Hi,
Attached is a relatively simple patch that adds support for an optional "detail" attribute in Condition rules. I would appreciate it if you would consider adding this patch to the package and/or sending it upstream for inclusion there. As stated, this patch allows for multiple Condition rules on the same event to be differentiated by a "detail" attribute, as repoted by "halevt -i". This is useful, for example, to enable halevt to support event handlers for hotkeys. Hotkeys get processed by HAL via the input layer, either from the keyboard driver (atkbd) or other machine-specific mechanisms (e.g., thinkpad-acpi). Typically, HAL forwards these as keypress events to X11 where they're able to be captured by client programs such as xbindkeys. As far as I know, each hotkey generates a "ButtonPressed" event, which can only be differentiated by the contents of the detail field, which contains the name of the hotkey pressed. Thus, this patch enables halevt to assign event handlers for individual keypresses (as opposed to a single halder for all hotkey events). This patch is useful as there's no general way to capture hotkey events outside X11. The acpid package used to be capable of capturing some hotkeys (those that went through the ACPI layer), but as of kernel 2.6.29 this ability has largely been lost due to the removal of the /proc/acpi/events interface. In contrast, this patch allows for all hotkeys to be captured via halevt as a single general mechanism that works in both the Linux console as well as X11. Such a feature has already been requested by others [1]. The patch includes an update to the example halevt.xml config file that demonstrates how to use the detail attribute to write Condition rules that capture keyboard volume buttons and execute commands that change system volume accordingly. Thanks! [1] http://www.mail-archive.com/ibm-acpi-de...@lists.sourceforge.net/msg01705.html
diff -uNr halevt-0.1.3.orig/halevt.xml halevt-0.1.3/halevt.xml --- halevt-0.1.3.orig/halevt.xml 2008-05-24 09:51:56.000000000 -0400 +++ halevt-0.1.3/halevt.xml 2009-04-15 23:22:13.412236485 -0400 @@ -83,6 +83,18 @@ !--> <!-- +Example of a use of Condition with detail attribute. This condition +differentiates between three different hotkeys for a ButtonPressed event +and performs the appropriate action for each. + +<halevt:Device match="hal.input.originating_device.hal.info.linux.driver = atkbd"> + <halevt:Condition name="ButtonPressed" detail="mute" exec="amixer -q set Master toggle"/> + <halevt:Condition name="ButtonPressed" detail="volume-down" exec="amixer -q set Master 1-"/> + <halevt:Condition name="ButtonPressed" detail="volume-up" exec="amixer -q set Master 1+"/> +</halevt:Device> +!--> + +<!-- Example of a use of OnInit. At startup all the devices are matched and the exec comand is run for those that match. diff -uNr halevt-0.1.3.orig/src/hal_interface.c halevt-0.1.3/src/hal_interface.c --- halevt-0.1.3.orig/src/hal_interface.c 2008-06-05 19:12:00.000000000 -0400 +++ halevt-0.1.3/src/hal_interface.c 2009-04-15 23:22:13.412236485 -0400 @@ -204,6 +204,8 @@ while (current_condition != NULL) { if (!strcmp(current_condition->name, condition_name) + && (current_condition->detail == NULL + || !strcmp(current_condition->detail, condition_detail)) && halevt_true_tree(current_condition->match, udi, NULL)) { halevt_run_command(current_condition->exec, udi, NULL); diff -uNr halevt-0.1.3.orig/src/parse_config.c halevt-0.1.3/src/parse_config.c --- halevt-0.1.3.orig/src/parse_config.c 2007-02-04 21:23:36.000000000 -0500 +++ halevt-0.1.3/src/parse_config.c 2009-04-15 23:22:13.412236485 -0400 @@ -262,7 +262,7 @@ } halevt_condition *halevt_add_condition(const xmlChar *match, - const xmlChar *exec, const xmlChar *name) + const xmlChar *exec, const xmlChar *name, const xmlChar *detail) { halevt_condition *new_condition; new_condition = malloc (sizeof(halevt_condition)); @@ -279,15 +279,24 @@ free(new_condition); return NULL; } + if (detail == NULL) { new_condition->detail = NULL; } + else if ((new_condition->detail = (char *) xmlStrdup(detail)) == NULL) + { + halevt_free_boolean_expression (new_condition->match); + free(new_condition->name); + free(new_condition); + return NULL; + } if ((new_condition->exec = halevt_new_exec(exec)) == NULL) { halevt_free_boolean_expression (new_condition->match); free(new_condition->name); + free(new_condition->detail); free(new_condition); return NULL; } /* - printf ("add_condition %s, %s, %s\n", match, exec, name); + printf ("add_condition %s, %s, %s, %s\n", match, exec, name, detail); */ new_condition->next = halevt_condition_root; halevt_condition_root = new_condition; @@ -453,15 +462,17 @@ { xmlChar *exec = NULL; xmlChar *name = NULL; + xmlChar *detail = NULL; exec = xmlGetProp(cur, (const xmlChar *) "exec"); name = xmlGetProp(cur, (const xmlChar *) "name"); + detail = xmlGetProp(cur, (const xmlChar *) "detail"); if (exec == NULL || name == NULL) { DEBUG(_("Warning: %s XML tag encountered with missing or bad attributes, ignored"), cur->name); } else { - halevt_add_condition(match, exec, name); + halevt_add_condition(match, exec, name, detail); } } else if (! xmlStrcmp(cur->name, (const xmlChar *) "Property")) diff -uNr halevt-0.1.3.orig/src/parse_config.h halevt-0.1.3/src/parse_config.h --- halevt-0.1.3.orig/src/parse_config.h 2007-02-04 19:50:41.000000000 -0500 +++ halevt-0.1.3/src/parse_config.h 2009-04-15 23:22:13.412236485 -0400 @@ -74,6 +74,7 @@ typedef struct halevt_condition { char *name; + char *detail; halevt_exec *exec; halevt_boolean_expression *match; struct halevt_condition* next;