Page 2 of 2

Re: SetKeyMapDefault() changes "global" keymap?

Posted: Mon Oct 21, 2013 6:53 pm
by chris
trixie wrote:@chris
This function should never be called by the average user. Its sole purpose is to provide the font preferences editor with data about the current diskfont settings. It should not be called for other purposes.
The GetDiskFontCtrl() autodoc doesn't sound very encouraging, though :-)
For that specific function, it is fine and safe to use. I've been using it for ages :-)

If it's only for Font Prefs and serves no other purpose then it should be a private function. It isn't, and I see no reason why querying these parameters is a bad thing to do. SetDiskFontCtrl(), yeah, avoid, but GetDiskFontCtrl() is useful for getting the local charset, and translating to/from UTF-8.

The DPI stuff doesn't seem to be used by diskfont. That would be useful too if the user could set it.

Re: SetKeyMapDefault() changes "global" keymap?

Posted: Fri Feb 21, 2014 7:05 pm
by salass00
trixie wrote: Still, even if you fix the problems above, this approach will get you nowhere. The name of the keymap is stored in the ln_Name field of the Node structure that is embedded in struct KeyMapNode. But function AskKeyMapDefault() has no knowledge of struct KeyMapNode so it cannot possibly supply the name of the default keymap in the ln_Name field.
Assuming that the default keymap is always set to point to the kn_KeyMap portion of a KeyMapNode struct as per recommendation in keymap.library autodoc (see SetKeyMapDefault function) then it is a simple matter to get the KeyMapNode from the KeyMap pointer.

Using explicit casting and pointer math:

Code: Select all

struct KeyMapNode *default_keymap;
default_keymap = (struct KeyMapNode *)((struct Node *)IKeyMap->AskKeyMapDefault() - 1);
Using a useful container_of() macro:

Code: Select all

#ifdef __GNUC__
#define container_of(ptr, type, member) ({ \
	const typeof( ((type *)0)->member ) *__mptr = (ptr); \
	(type *)( (char *)__mptr - offsetof(type, member) );})
#else
#define container_of(ptr, type, member) ( (type *)( (char *)(ptr) - offsetof(type, member) ) )
#endif

struct KeyMapNode *default_keymap;
default_keymap = container_of(IKeyMap->AskKeyMapDefault(), struct KeyMapNode, kn_KeyMap);