示例#1
0
bool
OSXKeyState::getGroups(GroupList& groups) const
{
	CFIndex n;
	bool gotLayouts = false;

#if defined(MAC_OS_X_VERSION_10_5)
	// get number of layouts
	CFStringRef keys[] = { kTISPropertyInputSourceCategory };
	CFStringRef values[] = { kTISCategoryKeyboardInputSource };
	CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
	CFArrayRef kbds = TISCreateInputSourceList(dict, false);
	n = CFArrayGetCount(kbds);
	gotLayouts = (n != 0);
#else
	OSStatus status = KLGetKeyboardLayoutCount(&n);
	gotLayouts = (status == noErr);
#endif

	if (!gotLayouts) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}

	// get each layout
	groups.clear();
	for (CFIndex i = 0; i < n; ++i) {
		bool addToGroups = true;
#if defined(MAC_OS_X_VERSION_10_5)
		TISInputSourceRef keyboardLayout = 
			(TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);
#else
		KeyboardLayoutRef keyboardLayout;
		status = KLGetKeyboardLayoutAtIndex(i, &keyboardLayout);
		addToGroups == (status == noErr);
#endif
		if (addToGroups)
    		groups.push_back(keyboardLayout);
	}
	return true;
}
示例#2
0
void keyboard_layout_menu(t_keyboard_layout *x) {
    //OSStatus err;
    KeyboardLayoutRef currentLayoutRef;
    const void *keyboardName;
    char cKeyboardName[100];
    CFIndex countOfLayouts;
    CFIndex i;
    t_atom name;

// TODO this should probably output [menu clear( so other messages work too
    outlet_anything(x->x_status_outlet, gensym("clear"), 0, NULL);

    KLGetKeyboardLayoutCount(&countOfLayouts);
    for(i= 0; i<countOfLayouts; i++) {
        KLGetKeyboardLayoutAtIndex(i, &currentLayoutRef);
        KLGetKeyboardLayoutProperty(currentLayoutRef, kKLName, (const void **)&keyboardName);
        CFStringGetCString((CFStringRef)keyboardName, cKeyboardName, 100, kCFStringEncodingASCII);

        SETSYMBOL(&name, gensym(cKeyboardName));
// TODO this should probably output [menu append( so other messages work too
        outlet_anything(x->x_status_outlet, gensym("append"), 1, &name);
    }
}