SetKeyMapDefault() changes "global" keymap?

This forum is for general developer support questions.
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

SetKeyMapDefault() changes "global" keymap?

Post by javierdlr »

Hi, testing keymap.library (SDK) and using ObtainKeyMapInfo() I can get whatever KEYMAP: I want/need, but how does SetKeyMapDefault() work?
Does SetKeyMapDefault() change globally in my system the KEYMAP I want/need?
How? The code example below shows 'KEYMAP:usa_ISO-8859-15' info/data OK, but if I try to change my keymap from e_ISO-8859-15 (defined in input.prefs) to 'usa_ISO-8859-15' with SetKeyMapDefault() seems nothing happens.

Code: Select all

int main(void)
{
 ULONG KM_res;
 APTR KM_handle;
 STRPTR KM_name, KM_localname;
 //struct KeyMap *km = NULL;
 struct KeyMapNode *kmn = NULL;
..
open KeymapBase & IFace
..
 KM_handle = IKeymap->OpenKeyMapHandle("KEYMAP:usa_ISO-8859-15", NULL);

 KM_res = IKeymap->ObtainKeyMapInfo(KM_handle,
                                     KEYMAPINFO_KEYMAPNODE, &kmn,
                                     KEYMAPINFO_INFOTEXT_ENGLISH, &KM_name,
                                     KEYMAPINFO_INFOTEXT_LOCAL, &KM_localname,
                                    TAG_END);

 IDOS->Printf("(0x%08lx) %s | %s\n",kmn->kn_KeyMap,KM_name,KM_localname);

 IKeymap->SetKeyMapDefault(kmn->kn_KeyMap);
..
close KeymapBase & IFace
..
return(0);
}
BTW: how can I retrive my default keymap name and localname?
BTW2: must I ReleaseKeyMapInfo() if I use ObtainKeyMapInfo() in my code?

TIA
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: SetKeyMapDefault() changes "global" keymap?

Post by trixie »

Could it be because SetKeyMapDefault() expects a POINTER to struct KeyMap as parameter, whereas your kmn->kn_KeyMap provides the actual structure (not a pointer to it)? You must pass the address of the kn_KeyMap field, using the & operator.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: SetKeyMapDefault() changes "global" keymap?

Post by salass00 »

To add to what trixie wrote you are not allowed to free the keymap after you have used it with SetKeyMapDefault() (this fact is stated in the autodoc).
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: SetKeyMapDefault() changes "global" keymap?

Post by javierdlr »

trixie wrote:Could it be because SetKeyMapDefault() expects a POINTER to struct KeyMap as parameter, whereas your kmn->kn_KeyMap provides the actual structure (not a pointer to it)? You must pass the address of the kn_KeyMap field, using the & operator.
Ooops, YES thx that solved.

BTW if I use 'keyMap = AskKeyMapDefault()' can then I use (pseudo_code):

Code: Select all

struct KeyMapNode
{
    struct Node   kn_Node;   /* including name of keymap */
    struct KeyMap kn_KeyMap;
} kmn;

 kmn->kn_KeyMap = keyMap;
so I get the 'name of the keymap'?
well just trying it now to see what happens...

THX
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: SetKeyMapDefault() changes "global" keymap?

Post by javierdlr »

salass00 wrote:To add to what trixie wrote you are not allowed to free the keymap after you have used it with SetKeyMapDefault() (this fact is stated in the autodoc).
Yes, you're right, now I see.

And if I use ObtainKeyMapInfo() only to create a list/table, then I must use ReleaseKeyMapInfo() after each ObtainKeyMapInfo() read?
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: SetKeyMapDefault() changes "global" keymap?

Post by trixie »

@javierdl

No, I'm afraid you got it all wrong. Do you use MemGuard when developing? You program must be trashing memory all along the watchtower! :-)
if I use 'keyMap = AskKeyMapDefault()' can then I use (pseudo_code):

Code: Select all

struct KeyMapNode
{
    struct Node   kn_Node;   /* including name of keymap */
    struct KeyMap kn_KeyMap;
} kmn;

 kmn->kn_KeyMap = keyMap; 
First, your kmn is declared as a physical structure KeyMapNode here (not as a pointer to this structure), so you cannot use the -> operator to access its members (fields). Second, the kn_KeyMap field is declared as a physical structure KeyMap, so you cannot initialize it with your result from AskKeyMapDefault() because the result is a pointer.
so I get the 'name of the keymap'?
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.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: SetKeyMapDefault() changes "global" keymap?

Post by javierdlr »

trixie wrote:@javierdl

No, I'm afraid you got it all wrong. Do you use MemGuard when developing? You program must be trashing memory all along the watchtower! :-)
Nop, but the os4 internal MUNGE option.
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.
OK, so now there is no "direct" function/way to get default keyboard name/charset/...
Right now I'm reading 'ENV:input.prefs' and getting the variables/data I need using the example from the wiki http://wiki.amigaos.net/index.php/Prefe ... ences_File

THX for all the help mate
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: SetKeyMapDefault() changes "global" keymap?

Post by trixie »

javierdlr wrote: OK, so now there is no "direct" function/way to get default keyboard name/charset/...
Possibly not. I'm quite surprised that OpenKeyMapHandleA() does not accept a NULL name argument, in which case the function would return handle to the current default keymap. This way you could get your KeyMapNode and, thus, the name of the default keymap as well. Time for an enhancement request perhaps?

As for charset, you can read the system env-var called "Charset" (I think).
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

Re: SetKeyMapDefault() changes "global" keymap?

Post by chris »

trixie wrote:As for charset, you can read the system env-var called "Charset" (I think).
It's better to use GetDiskFontCtrl().
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: SetKeyMapDefault() changes "global" keymap?

Post by trixie »

@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 :-)
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
Post Reply