Skip to content

Commit de0ec3c

Browse files
committed
Release version 0.2.0
1 parent 8c12e24 commit de0ec3c

13 files changed

+638
-156
lines changed

ChangeLog

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
Tue Mar 7 02:32:15 EET 2006 - Theodoros V. Kalamatianos <[email protected]>
2+
* Release 0.2.0
3+
* Added the `grab'/`ungrab' attributes that allow keyboard grabbbing
4+
* Added the `grabbed'/`ungrabbed' attributes to fine tune the key
5+
shortcut configuration
6+
* Added the `exec'/`noexec' attributes to control the execution of
7+
external commands
8+
* Added the `ignrel'/`rcvrel'/`allrel' attributes to allow for key
9+
combinations where the keys are pressed sequentially rather than
10+
simultaneously.
11+
* Fixed the -v/--verbose help message line
12+
* Updated documentation
13+
* Some minor Makefile fixes
14+
* Minor fixes and clean-ups here and there
15+
116
Tue Nov 22 23:53:12 EEST 2005 - Theodoros V. Kalamatianos <[email protected]>
217
* Release 0.1.2
318
* Improve automatic keyboard detection

FAQ

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ KeyBoard Daemon. Or...
4545

4646
* Does it work ?
4747

48-
I have performed some minimal testing and it seems to work fine. I will have to
49-
receive quite a lot of feedback before I mark it as stable, though.
48+
It is now launched at boot time on my system and it seems to work without any
49+
problems. I will still have to receive quite a bit of feedback before I mark it
50+
as stable, though.
5051

5152

5253
* How does it work ?

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ actkbd: actkbd.o mask.o config.o linux.o
2424
actkbd.o : actkbd.h
2525
mask.o : actkbd.h
2626

27-
config.o : actkbd.h
27+
config.o : actkbd.h config.c
2828
$(CC) $(CFLAGS) -c -o config.o config.c -DCONFIG=\"$(sysconfdir)/actkbd.conf\"
2929

3030
linux.o : actkbd.h

NEWS

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
0.1.2:
2-
* Improve automatic keyboard detection
1+
0.2.0:
2+
* Added the `grab'/`ungrab' attributes that allow keyboard grabbbing
3+
* Added the `grabbed'/`ungrabbed' attributes to fine tune the key
4+
shortcut configuration
5+
* Added the `exec'/`noexec' attributes to control the execution of
6+
external commands
7+
* Added the `ignrel'/`rcvrel'/`allrel' attributes to allow for key
8+
combinations where the keys are pressed sequentially rather than
9+
simultaneously.
10+
* Fixed the -v/--verbose help message line
11+
* Updated documentation
12+
* Some minor Makefile fixes
13+
* Minor fixes and clean-ups here and there

README

+76-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Contents:
1111
3.1. Compilation
1212
3.2. Installation
1313
3.3. Configuration
14+
3.3.1. Supported command attributes
1415
3.4. Running
1516
4. Internals
1617
5. License
@@ -26,10 +27,10 @@ well-contained, so that support for additional platforms can be added with no or
2627
minimal changes to the rest of the code.
2728

2829
It uses a plain-text configuration file which contains all the bindings. Its
29-
file format has some prediction for command modules, which would allow the user
30-
to perform some common actions (e.g. eject the CD-ROM or change the volume)
31-
without having to call external commands. Currently, though, actkbd can only
32-
execute external commands.
30+
file format has some prediction for command attributes, which allow the user to
31+
perform some common actions (e.g. eject the CD-ROM or change the volume) without
32+
having to call external commands. Currently, though, actkbd can only execute
33+
external commands, as the supported attributes only serve configuration purposes.
3334

3435

3536

@@ -93,7 +94,7 @@ The default configuration file resides in $(sysconfdir)/actkbd.conf. It is a
9394
plain-text file with each line being an entry. A proper entry has the following
9495
format:
9596

96-
<keys>:<event type>:<command module>:<command>
97+
<keys>:<event type>:<attributes>:<command>
9798

9899
The <keys> field is a series of numeric keycodes, separated by the `+'
99100
character. `actkbd -n -s' can be used to find out any keycodes you need, as it
@@ -102,18 +103,86 @@ will report all key presses without executing any commands.
102103
The <event type> string field is one of `key' (key press event), `rep' (key
103104
repeat event) or `rel' (key release event). If empty, it defaults to `key'.
104105

105-
The <command module> field is currently ignored.
106+
The <attributes> field contains a comma separated list of attributes. The listed
107+
attributes can modify the execution of the supplied command or change the state
108+
of actkbd in order to perform complex actions. The attribute actions are executed
109+
in the listed order.
106110

107-
The <command> field is the executed command that will be passed to system().
111+
The <command> field is the executed command that will be passed to system().
108112
Note that in order to have non-blocking behaviour, you have to append the `&'
109113
character to the command, so that /bin/sh will execute it in the background.
114+
Also keep in mind that the listed command attributes can affect the way the
115+
command is executed, if at all. Currently system() is the only interpretter
116+
for commands, but in the future there may be command attributes that use the
117+
contents of this field differently, e.g. to set a sound mixer.
110118

111119
Lines starting with '#' are considered comments. Invalid lines are silently
112120
ignored, unless a high enough verbosity level has been specified.
113121

114122
A sample actkbd.conf is included in the actkbd distribution.
115123

116124

125+
3.3.1. Supported command attributes
126+
127+
The supported attributes are:
128+
129+
* `grab': This grabs the keyboard device to block other applications from
130+
receiving the subsequent events. This allows the user to bind commands
131+
to keys that are not normally usable because they produce symbols that
132+
mess with regular keyboard operation (letters, numbers e.t.c.).
133+
134+
* `ungrab': This releases a grabbed device, so that other programs may get the
135+
key events. Please note that at least some versions of the X keyboard
136+
driver (and possibly other programs) will interpret a key release event
137+
as a full key press/release sequence even if the press event was never
138+
received (why?). Therefore you may prefer to use the `ungrab' attribute
139+
in release event bindings, rather than keypress ones, to ensure correct
140+
operation.
141+
142+
WARNING: Using the `grab' attribute without a well thought way to invoke the
143+
`ungrab' command can easily leave your keyboard unusable for all other
144+
applications with no way out. You may want to invoke something like the
145+
following:
146+
147+
# sleep 120; killall -9 actkbd
148+
149+
in a different console, while testing you configuration, to be able to
150+
reclaim your keyboard even if the configuration file is not correct.
151+
152+
* `grabbed': This instructs actkbd to execute the specified command only if the
153+
keyboard has been grabbed. This can be used to allow a key to act as an
154+
extra Function key that adds extra functionality to the other keys.
155+
156+
* `ungrabbed': This instructs actkbd to execute the specified command only if
157+
the keyboard has not been grabbed.
158+
159+
NOTE: If none of the `grabbed'/`ungrabbed' attributes has been used, the command
160+
is always executed if the key mask matches. If both are specified then
161+
the command is never executed - obviously the keyboard cannot be grabbed
162+
and ungrabbed at the same time.
163+
164+
* `noexec': Do not call system() to run an external command. Useful for entries
165+
that only serve configuration purposes.
166+
167+
* `exec': Use system() to run an external command here and now. Allows specific
168+
ordering of the attribute actions with regard to the system() call.
169+
170+
NOTE: If none of the `noexec'/`exec' attributes has been specified, or if the
171+
attribute list is empty, an `exec' call is implied at the end of the
172+
list. Always use `noexec' for entries with empty/invalid commands.
173+
174+
* `ignrel': Ignore release events for the keys that are currently pressed. This
175+
allows complex key combinations where the keys are pressed sequentially,
176+
rather than simultaneously. When the key combination is completed, the
177+
`allrel' and `rcvrel' attributes should be used to clear the key mask
178+
and to resume the proper reception of release events.
179+
180+
* `allrel': Clear the pressed key mask. It is the equivalent of releasing all
181+
pressed keys, but is not affected by the `ignrel' attribute.
182+
183+
* `rcvrel': Restore proper reception of key release events.
184+
185+
117186
3.4. Running
118187

119188
Run `actkbd --help' to see the various command line options. actkbd is normally

TODO

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
* Implement the module subsystem. Modules to control sound mixers e.t.c. could
1212
be built.
13+
UPDATE: The attribute infrastructure introduced in actkbd-0.2.0 is the core
14+
of the module subsystem. Now we are just missing the modules...
1315

1416
* Use select() to handle multiple keyboards, instead of just the first one,
1517
and get a USB keyboard to test it.
@@ -34,3 +36,5 @@
3436
huge fixed keymaps ?
3537

3638
* Create manual pages: actkbd.1, actkbd.conf.5
39+
40+
* Autotools ?

actkbd.c

+81-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ int uselog = 0;
2626
/* Maximum number of keys */
2727
int maxkey = 0;
2828

29+
/* Device grab state */
30+
int grabbed = 0;
31+
32+
/* Ignore release events */
33+
int ignrel = 0;
34+
2935
/* Keyboard device name */
3036
char *device = NULL;
3137

@@ -48,7 +54,8 @@ static int usage() {
4854
" -n, --noexec Do not execute any commands\n"
4955
" -p, --pidfile <file> Use a file to store the PID\n"
5056
" -q, --quiet Suppress all console messages\n"
51-
" -v, --verbose [level] Specify the verbosity level (0-9)\n"
57+
" -v[level]\n"
58+
" --verbose=[level] Specify the verbosity level (0-9)\n"
5259
" -V, --version Show version information\n"
5360
" -x, --showexec Report executed commands\n"
5461
" -s, --showkey Report key presses\n"
@@ -70,7 +77,8 @@ void on_hup(int signum) {
7077
lprintf("Discarding old configuration\n");
7178

7279
close_config();
73-
clear_key_mask();
80+
free_key_mask();
81+
free_ign_mask();
7482

7583
if (verbose > 1)
7684
lprintf("Reading new configuration\n");
@@ -79,6 +87,8 @@ void on_hup(int signum) {
7987
exit(ret);
8088
if ((ret = init_key_mask()) != OK)
8189
exit(ret);
90+
if ((ret = init_ign_mask()) != OK)
91+
exit(ret);
8292

8393
if (verbose > 1)
8494
lprintf("Reconfiguration complete\n");
@@ -91,7 +101,8 @@ void on_hup(int signum) {
91101
void on_term(int signum) {
92102
close_config();
93103
close_dev();
94-
clear_key_mask();
104+
free_key_mask();
105+
free_ign_mask();
95106

96107
if (detach)
97108
lprintf("actkbd %s terminating for %s\n", VERSION, device);
@@ -128,9 +139,20 @@ static int write_pid() {
128139
}
129140

130141

142+
/* External command execution */
143+
static int ext_exec(char *cmd, int noexec, int showexec) {
144+
if ((verbose > 0) || showexec)
145+
lprintf("Executing: %s\n", cmd);
146+
if (!noexec)
147+
return system(cmd);
148+
149+
return 0;
150+
}
151+
152+
131153
int main(int argc, char **argv) {
132154
int ret, key, type;
133-
char *command;
155+
key_cmd *cmd;
134156

135157
/* Options */
136158
int help = 0, noexec = 0, version = 0, showexec = 0, showkey = 0;
@@ -253,6 +275,9 @@ int main(int argc, char **argv) {
253275
if ((ret = init_key_mask()) != OK)
254276
return ret;
255277

278+
if ((ret = init_ign_mask()) != OK)
279+
return ret;
280+
256281
if ((ret = open_dev()) != OK)
257282
return ret;
258283

@@ -281,6 +306,8 @@ int main(int argc, char **argv) {
281306
signal(SIGTERM, on_term);
282307

283308
while (get_key(&key, &type) == OK) {
309+
int exec_ok = 0;
310+
284311
if ((type == KEY) || (type == REP))
285312
set_key_bit(key, 1);
286313

@@ -295,15 +322,59 @@ int main(int argc, char **argv) {
295322
lprintf("\n");
296323
}
297324

298-
ret = get_command(get_key_mask(), type, &command);
325+
ret = match_key(type, &cmd);
299326
if (ret == OK) {
300-
if ((verbose > 0) || showexec)
301-
lprintf("Executing: %s\n", command);
302-
if (!noexec)
303-
system(command);
327+
attr_t *attr;
328+
329+
/* Attribute implementation */
330+
attr = cmd->attrs;
331+
while (attr != NULL) {
332+
char *str, *opt = "";
333+
switch (attr->type) {
334+
case ATTR_EXEC:
335+
str = "exec";
336+
ext_exec(cmd->command, noexec, showexec);
337+
exec_ok = 1;
338+
break;
339+
case ATTR_GRAB:
340+
str = "grab";
341+
grab_dev();
342+
break;
343+
case ATTR_UNGRAB:
344+
str = "ungrab";
345+
ungrab_dev();
346+
break;
347+
case ATTR_IGNREL:
348+
str = "ignrel";
349+
copy_key_to_ign_mask();
350+
ignrel = 1;
351+
break;
352+
case ATTR_RCVREL:
353+
str = "rcvrel";
354+
ignrel = 0;
355+
break;
356+
case ATTR_ALLREL:
357+
str = "allrel";
358+
clear_key_mask();
359+
break;
360+
default:
361+
str = "unknown";
362+
break;
363+
}
364+
if ((verbose > 0) || showexec)
365+
lprintf("Attribute: %s(%s)\n", str, opt);
366+
367+
attr = attr->next;
368+
}
369+
370+
/* Fall back on command execution */
371+
if ((!exec_ok) && ((cmd->attr_bits & BIT_ATTR_NOEXEC) == 0)) {
372+
ext_exec(cmd->command, noexec, showexec);
373+
exec_ok = 1;
374+
}
304375
}
305376

306-
if (type == REL)
377+
if ((type == REL) && ((!ignrel) || (get_ign_bit(key) == 0)))
307378
set_key_bit(key, 0);
308379
}
309380

actkbd.conf

+33-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,45 @@
1010
# Mute = 113
1111
# Volume Down = 114
1212
# Volume Up = 115
13+
# Eject = 161
1314

14-
113:key::echo mute
1515

16-
56+113:::echo left.alt+mute
1716

17+
# Some simple examples
1818
114:::echo volume down
1919
114:rep::echo volume down rep
20+
56+114:::echo left.alt+volume.down
2021

2122
115:::echo volume up
2223
115:rep::echo volume up rep
2324
115:rel::echo volume up rel
25+
26+
27+
28+
# Use the mute key as a "Function" key.
29+
113:key:ungrabbed,grab:echo Grab!
30+
113:rel:grabbed,ungrab:echo Ungrab!
31+
32+
# This allows the a key to be binded to a command
33+
# To use: press mute, press a, release in any order
34+
113+30::grabbed:echo Alpha!
35+
36+
# Same thing with the b key
37+
113+48::grabbed:echo Beta!
38+
39+
40+
41+
# When the Eject key is pressed, wait for one of the e/m/u keys
42+
161::grab,noexec,ignrel:
43+
44+
# Oh! the `e' key
45+
161+18::grabbed:echo eject
46+
161+18:rel:grabbed,noexec,ungrab,rcvrel,allrel:
47+
48+
# Oh! the `m' key
49+
161+50::grabbed:echo mount
50+
161+50:rel:grabbed,noexec,ungrab,rcvrel,allrel:
51+
52+
# Oh! the `u' key
53+
161+22::grabbed:echo umount
54+
161+22:rel:grabbed,noexec,ungrab,rcvrel,allrel:

0 commit comments

Comments
 (0)