Re: [PATCH]: PrintInfo Bindings
On Sun, Feb 08, 2009 at 02:44:15AM +, Thomas Adam wrote: Hello all, Something I've seen an increase of lately, on the fvwm list and particularly on IRC and the forums, is the question of: What are the default mouse/key bindings of fvwm? To which the answer varies, since invariably the question is: Can I list all my bindings fvwm knows about? Well, with the attached patch, you can. I've added it to PrintInfo, since it really is only useful in certain circumstances. Dominik: I've deliberately not restructured this patch to sit on top of the InitialMapCommand patches -- so if you consider applying this patch along with that one, you might get some conflicts in NEWS, AUTHORS and Changelog. Hopefully shouldn't be a problem though. That's no problem. Comment/suggestions welcome as always. See below. Index: AUTHORS === RCS file: /home/cvs/fvwm/fvwm/AUTHORS,v retrieving revision 1.130 diff -u -r1.130 AUTHORS --- AUTHORS 19 Oct 2008 12:04:12 - 1.130 +++ AUTHORS 8 Feb 2009 02:27:54 - @@ -15,6 +15,7 @@ StartShaded style option. Introduce the command expansion placeholder: $[w.visiblename] Make style matching honour a window's visible name (c.f. $[w.visiblename]) +Added bindings option to PrintInfo command useful for debugging. Serge (gentoosiast) Koksharov: Documentation fixes, bug fixes. Index: ChangeLog === RCS file: /home/cvs/fvwm/fvwm/ChangeLog,v retrieving revision 1.3061 diff -u -r1.3061 ChangeLog --- ChangeLog 30 Dec 2008 13:32:40 - 1.3061 +++ ChangeLog 8 Feb 2009 02:28:04 - @@ -1,3 +1,16 @@ +2009-02-05 Thomas Adam thomas.ada...@gmail.com + * libs/charmap.c (charmap_table_to_string): + * libs/charmap.h: + Introduce charmap_to_string function which is used to build up a + binding string, for use with PrintInfo. + + * fvwm/bindings.c (print_bindings): + Introduce print_bindings to print all bindings known to fvwm. + + * fvwm/builtins.c (CMD_PrintInfo): + * fvwm/builtins.h: + Add support for binding as an option to PrintInfo. + 2008-12-29 Alexandre Julliard julli...@winehq.org * fvwm/ewmh_events.c (ewmh_WMStateMaxHoriz): Index: NEWS === RCS file: /home/cvs/fvwm/fvwm/NEWS,v retrieving revision 1.767 diff -u -r1.767 NEWS --- NEWS 30 Dec 2008 13:32:40 - 1.767 +++ NEWS 8 Feb 2009 02:28:05 - @@ -18,6 +18,9 @@ ... is now honoured. Useful with IndexedWindowName as a style option. + - New option to PrintInfo, bindings which prints out all of the Key, + PointerKey, Mouse and Stroke bindings which fvwm knows about. + * Bug fixes: - Fixed compilation without XRender support. Index: doc/commands/PrintInfo.xml === RCS file: /home/cvs/fvwm/fvwm/doc/commands/PrintInfo.xml,v retrieving revision 1.4 diff -u -r1.4 PrintInfo.xml --- doc/commands/PrintInfo.xml16 Jun 2007 12:38:46 - 1.4 +++ doc/commands/PrintInfo.xml8 Feb 2009 02:28:05 - @@ -57,4 +57,10 @@ replaceableverbose/replaceable can be 1./para +parafvwmopt cms=PrintInfo opt=bindings/ +which prints information on all the bindings fvwm has: key, mouse and +stroke bindings. +replaceableverbose/replaceable +has no effect with this option./para + /section Index: fvwm/bindings.c === RCS file: /home/cvs/fvwm/fvwm/fvwm/bindings.c,v retrieving revision 1.103 diff -u -r1.103 bindings.c --- fvwm/bindings.c 23 Nov 2007 08:49:11 - 1.103 +++ fvwm/bindings.c 8 Feb 2009 02:28:10 - @@ -639,6 +639,60 @@ return; } +void print_bindings(int verbose) If the verbose flag has no effect, why is it an argument to the function? +{ + Binding *b; + + fprintf(stderr, Current list of bindings:\n\n); + + for (b = Scr.AllBindings; b != NULL; b = b-NextBinding) + { + /* Key, PointerKey, Mouse, Stroke. */ + char *binding_type = NULL; + char type[20]; + switch (b-type) + { + case BIND_KEYPRESS: + binding_type = Key; + sprintf(type, %s, b-key_name); + break; + case BIND_PKEYPRESS: + binding_type = PointerKey; + sprintf(type, %s, b-key_name); + break; + case BIND_BUTTONPRESS: + case BIND_BUTTONRELEASE: +binding_type = Mouse; +sprintf(type, %d, b-Button_Key); +
Re: [PATCH]: PrintInfo Bindings
2009/2/8 Dominik Vogt dominik.v...@gmx.de: On Sun, Feb 08, 2009 at 02:44:15AM +, Thomas Adam wrote: Comment/suggestions welcome as always. See below. Thanks. +void print_bindings(int verbose) If the verbose flag has no effect, why is it an argument to the function? I had thought about trying to utilise verbose at one point, but couldn't think of the need. Changed to void instead. + char type[20]; + switch (b-type) + { + case BIND_KEYPRESS: + binding_type = Key; + sprintf(type, %s, b-key_name); + break; + case BIND_PKEYPRESS: + binding_type = PointerKey; + sprintf(type, %s, b-key_name); + break; + case BIND_BUTTONPRESS: + case BIND_BUTTONRELEASE: +binding_type = Mouse; +sprintf(type, %d, b-Button_Key); +break; + case BIND_STROKE: + binding_type = Stroke; + sprintf(type, %s\t%d, (char *)b-Stroke_Seq, + b-Button_Key); I think we shouldn't copy arbitrary strings into a fixed length buffer. I'm sure there are key names that are longer than 19 characters. I checked in bindings.c:ParseBindings() -- key_string is defined as: char key_string[201] = ; I've mimicked this here as well for char[] type. If you think that's still going to cause problems, I will really make it dynamic, although from testing it locally, it's not yet caused any problems, and my Thinkpad does have some nice XF86LongNameKeys defined, for instance. + break; + } + + char *mod_string = charmap_table_to_string( + MaskUsedModifiers(b-Modifier),key_modifiers); + char *context_string = charmap_table_to_string( + b-Context, win_contexts); + char win_name[260] = ; Uh, I know we have hard coded some length limit to the window name, but that's just because there was or is a bug in the X system that caused a crash. OK. Changed to be dynamic, although I will note that again, according to ParseBindings(), the max length of a window name is capped at 79 chars. But I've ignored that again here, and allocated win_name with malloc(). #include config.h #include stdio.h #include ctype.h +#include string.h You can't rely on string.h being present. On some systems, it's callend strings.h. Luckily you don't have to take care of that yourself: config.h already includes the proper file, so you can just delete this line. I'm sure I had problems with that before -- but you're right. Removed without any problems. #include charmap.h +#include safemalloc.h Should be libs/safemalloc.h. Maybe I should remove libs from the include path. Fixed. From doing a quick cursive glance through some of the other header files in libs/, there's a real mixture of some header files being included as libs/foo.h and others just as foo.h. If you don't get around to this some point next week, I will send in a patch to clean this up on your behalf. + +/* Used from PrintInfo Bindings. */ +char *charmap_table_to_string(int mask, charmap_t *table) +{ + char *allmods = safemalloc (sizeof(table)); + memset (allmods, '\0', sizeof(table)); Are you sure you want to reserve sizeof(table) bytes? This would reserve space to store a pointer, not space to store a charmap_t. Oops. I meant: sizeof(*table) here. Feel free to replace it with: sizeof(charmap_t) -- I know some prefer the latter over the former. + + int modmask = mask; Please don't declare variables in the middle of a block. This does not compile with oplder compilers. I didn't quite understand what you meant by this -- the declaration wasn't in a block, it was just after the function had been declared. I've tried to change it, but if it's still wrong, do say and I'll correct it again. Please see print-bindings2.patch attached. Kindly, -- Thomas Adam Index: AUTHORS === RCS file: /home/cvs/fvwm/fvwm/AUTHORS,v retrieving revision 1.130 diff -u -r1.130 AUTHORS --- AUTHORS 19 Oct 2008 12:04:12 - 1.130 +++ AUTHORS 8 Feb 2009 17:35:08 - @@ -15,6 +15,7 @@ StartShaded style option. Introduce the command expansion placeholder: $[w.visiblename] Make style matching honour a window's visible name (c.f. $[w.visiblename]) +Added bindings option to PrintInfo command useful for debugging. Serge (gentoosiast) Koksharov: Documentation fixes, bug fixes. Index: NEWS === RCS file:
Re: [PATCH]: PrintInfo Bindings
On Sun, Feb 08, 2009 at 05:55:51PM +, Thomas Adam wrote: 2009/2/8 Dominik Vogt dominik.v...@gmx.de: [sniiip] + int modmask = mask; Please don't declare variables in the middle of a block. This does not compile with oplder compilers. I didn't quite understand what you meant by this -- the declaration wasn't in a block, All code is in blocks. Don't forget the curly braces that delimit the function body :-) it was just after the function had been declared. I've tried to change it, but if it's still wrong, do say and I'll correct it again. In C89 you can't have { declaration; statement; declaration; } You have to put all the declarations at the beginning of the block, i.e.: Wrong (does not compile): void foo(void) { int x; memset(x, 0, sizeof(x); int y; } Right: void foo(void) { int x; int y; memset(x, 0, sizeof(x); } More comments later when I've got time to look at the new patch. Ciao Dominik ^_^ ^_^ -- Dominik Vogt