<commit_before>/*
 *  HotKey.c
 *  GrowlTunes
 *
 *  Created by rudy on 12/20/05.
 *  Copyright 2005-2007, The Growl Project. All rights reserved.
 *
 */

#include "HotKey.h"

static void _updateModifiersString(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	static long modToChar[4][2] =
	{
		{ cmdKey, 		0x2318 },
		{ optionKey,	0x2325 },
		{ controlKey,	0x005E },
		{ shiftKey,		0x21e7 }
	};

	if (hotkey->mModifierString)
		CFRelease(hotkey->mModifierString);
	hotkey->mModifierString = CFStringCreateMutable(kCFAllocatorDefault, 0);
	
	
	for (int i=0; i < 4; ++i)
		if (hotkey->mModifierCode & modToChar[i][0])
			CFStringAppendCharacters(hotkey->mModifierString, ((const UniChar *)(&(modToChar[i][1]))), 1);

	GrowlLog("%s exited", __FUNCTION__);
}

void hotkey_unregisterHotKeyAndHandler(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	if (hotkey->mHotKeyEventHandler) 
	{
		RemoveEventHandler(hotkey->mHotKeyEventHandler);
		//printf("%p ", hotkey->mHotKeyEventHandler);
	}
	if (hotkey->mHotKeyEventReference) 
	{
		UnregisterEventHotKey(hotkey->mHotKeyEventReference);
		//printf("%p\n", hotkey->mHotKeyEventReference);
	}
	GrowlLog("%s exited", __FUNCTION__);
}

static void _registerHotKeyAndHandler(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	//GrowlLog(1, CFSTR("a %p %p\n"), hotkey->mHotKeyEventHandler, hotkey->mHotKeyEventReference);
	hotkey_unregisterHotKeyAndHandler(hotkey);
	if ((!hotkey->mHotKeyEventHandler) && (!hotkey->mHotKeyEventReference)) 
	{
		RegisterEventHotKey(hotkey->mKeyCode, hotkey->mModifierCode, hotkey->mHotKeyID, GetEventDispatcherTarget(), 0, &hotkey->mHotKeyEventReference);
		InstallEventHandler(GetEventDispatcherTarget(), hotkey->mHotKeyEventHandlerProcPtr, 2, hotkey->mEventSpec, hotkey->mData, &hotkey->mHotKeyEventHandler);
	}
	GrowlLog("%s exited", __FUNCTION__);
}

static void _updateKeyCodeString(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	UCKeyboardLayout  *uchrData;
	void              *KCHRData;
	SInt32            keyLayoutKind;
	KeyboardLayoutRef currentLayout;
	UInt32            keyTranslateState;
	UInt32            deadKeyState;
	OSStatus          err = noErr;
	CFLocaleRef       locale = CFLocaleCopyCurrent();

	err = KLGetCurrentKeyboardLayout(&currentLayout);
	if (err != noErr)
	{
		GrowlLog("%s exited", __FUNCTION__);
		return;<commit_msg>Initialize keyTranslateState to 0, so as not to crash iTunes on launch.<commit_after>/*
 *  HotKey.c
 *  GrowlTunes
 *
 *  Created by rudy on 12/20/05.
 *  Copyright 2005-2007, The Growl Project. All rights reserved.
 *
 */

#include "HotKey.h"

static void _updateModifiersString(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	static long modToChar[4][2] =
	{
		{ cmdKey, 		0x2318 },
		{ optionKey,	0x2325 },
		{ controlKey,	0x005E },
		{ shiftKey,		0x21e7 }
	};

	if (hotkey->mModifierString)
		CFRelease(hotkey->mModifierString);
	hotkey->mModifierString = CFStringCreateMutable(kCFAllocatorDefault, 0);
	
	
	for (int i=0; i < 4; ++i)
		if (hotkey->mModifierCode & modToChar[i][0])
			CFStringAppendCharacters(hotkey->mModifierString, ((const UniChar *)(&(modToChar[i][1]))), 1);

	GrowlLog("%s exited", __FUNCTION__);
}

void hotkey_unregisterHotKeyAndHandler(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	if (hotkey->mHotKeyEventHandler) 
	{
		RemoveEventHandler(hotkey->mHotKeyEventHandler);
		//printf("%p ", hotkey->mHotKeyEventHandler);
	}
	if (hotkey->mHotKeyEventReference) 
	{
		UnregisterEventHotKey(hotkey->mHotKeyEventReference);
		//printf("%p\n", hotkey->mHotKeyEventReference);
	}
	GrowlLog("%s exited", __FUNCTION__);
}

static void _registerHotKeyAndHandler(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	//GrowlLog(1, CFSTR("a %p %p\n"), hotkey->mHotKeyEventHandler, hotkey->mHotKeyEventReference);
	hotkey_unregisterHotKeyAndHandler(hotkey);
	if ((!hotkey->mHotKeyEventHandler) && (!hotkey->mHotKeyEventReference)) 
	{
		RegisterEventHotKey(hotkey->mKeyCode, hotkey->mModifierCode, hotkey->mHotKeyID, GetEventDispatcherTarget(), 0, &hotkey->mHotKeyEventReference);
		InstallEventHandler(GetEventDispatcherTarget(), hotkey->mHotKeyEventHandlerProcPtr, 2, hotkey->mEventSpec, hotkey->mData, &hotkey->mHotKeyEventHandler);
	}
	GrowlLog("%s exited", __FUNCTION__);
}

static void _updateKeyCodeString(hotkey_t *hotkey) 
{
	GrowlLog("%s entered", __FUNCTION__);
	UCKeyboardLayout  *uchrData;
	void              *KCHRData;
	SInt32            keyLayoutKind;
	KeyboardLayoutRef currentLayout;
	UInt32            keyTranslateState = 0U;
	UInt32            deadKeyState;
	OSStatus          err = noErr;
	CFLocaleRef       locale = CFLocaleCopyCurrent();

	err = KLGetCurrentKeyboardLayout(&currentLayout);
	if (err != noErr)
	{
		GrowlLog("%s exited", __FUNCTION__);
		return;
{'fraction_non_alphanumeric': 0.1352365076057512, 'fraction_numerical': 0.02083767451552407, 'mean_word_length': 5.099110546378653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2953336', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1752, 'n_words': 299}