cleaning up everything in mac input setup

master
Allen Webster 2017-11-08 19:12:14 -05:00
parent bb7a098663
commit 30c16d6752
8 changed files with 666 additions and 638 deletions

View File

@ -691,13 +691,17 @@ static int32_t named_map_count = 0;
static void
change_mapping(Application_Links *app, String mapping){
bool32 did_remap = false;
for (int32_t i = 0; i < named_map_count; ++i){
if (match(mapping, named_maps[i].name)){
did_remap = true;
exec_command(app, named_maps[i].remap_command);
break;
}
}
if (!did_remap){
print_message(app, literal("Leaving bindings unaltered.\n"));
}
}
CUSTOM_COMMAND_SIG(remap_interactive){

View File

@ -14,8 +14,18 @@ TYPE: 'drop-in-command-pack'
// Buffer Filling Helpers
//
enum{
B_None,
B_Major,
B_Minor,
B_Both,
};
void
default_keys(Bind_Helper *context){
bind(Bind_Helper *context,
void
default_keys(Bind_Helper *context){
// NOTE(allen|a4.0.22): GLOBAL
begin_map(context, mapid_global);
@ -189,22 +199,23 @@ default_keys(Bind_Helper *context){
bind(context, 'I', MDFR_CTRL, list_all_functions_current_buffer);
end_map(context);
}
}
void
bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, int32_t command){
void
bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, int32_t command){
bind(context, code, MDFR_CTRL, command);
bind(context, code, MDFR_CMND, command);
}
}
void
bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, Custom_Command_Function *command){
void
bind_ctrl_and_cmnd(Bind_Helper *context, Key_Code code, Custom_Command_Function *command){
bind(context, code, MDFR_CTRL, command);
bind(context, code, MDFR_CMND, command);
}
bind(context, code, MDFR_CTRL|MDFR_CMND, command);
}
void
mac_4coder_like_keys(Bind_Helper *context){
void
mac_4coder_like_keys(Bind_Helper *context){
// NOTE(allen|a4.0.22): GLOBAL
begin_map(context, mapid_global);
@ -378,10 +389,10 @@ mac_4coder_like_keys(Bind_Helper *context){
bind_ctrl_and_cmnd(context, 'I', list_all_functions_current_buffer);
end_map(context);
}
}
void
mac_default_keys(Bind_Helper *context){
void
mac_default_keys(Bind_Helper *context){
// NOTE(allen|a4.0.22): GLOBAL
begin_map(context, mapid_global);
@ -555,15 +566,15 @@ mac_default_keys(Bind_Helper *context){
bind(context, 'I', MDFR_CMND, list_all_functions_current_buffer);
end_map(context);
}
}
//
// Remapping Commands
//
//
// Remapping Commands
//
static Bind_Helper
get_context_on_global_part(void){
static Bind_Helper
get_context_on_global_part(void){
Bind_Helper result = {0};
int32_t size = (1 << 20);
for (;;){
@ -575,21 +586,21 @@ get_context_on_global_part(void){
size = (size >> 1);
}
return(result);
}
}
CUSTOM_COMMAND_SIG(set_bindings_choose){
#if defined(_WIN32) || defined(__linux__)
CUSTOM_COMMAND_SIG(set_bindings_choose){
#if defined(_WIN32) || defined(__linux__)
set_bindings_default(app);
#elif defined(__APPLE__) && defined(__MACH__)
#elif defined(__APPLE__) && defined(__MACH__)
set_bindings_mac_default(app);
#endif
}
#endif
}
CUSTOM_COMMAND_SIG(set_bindings_default){
CUSTOM_COMMAND_SIG(set_bindings_default){
Temp_Memory temp = begin_temp_memory(&global_part);
Bind_Helper context = get_context_on_global_part();
@ -599,9 +610,9 @@ CUSTOM_COMMAND_SIG(set_bindings_default){
global_set_mapping(app, result.data, result.size);
end_temp_memory(temp);
}
}
CUSTOM_COMMAND_SIG(set_bindings_mac_4coder_like){
CUSTOM_COMMAND_SIG(set_bindings_mac_4coder_like){
Temp_Memory temp = begin_temp_memory(&global_part);
Bind_Helper context = get_context_on_global_part();
@ -611,9 +622,9 @@ CUSTOM_COMMAND_SIG(set_bindings_mac_4coder_like){
global_set_mapping(app, result.data, result.size);
end_temp_memory(temp);
}
}
CUSTOM_COMMAND_SIG(set_bindings_mac_default){
CUSTOM_COMMAND_SIG(set_bindings_mac_default){
Temp_Memory temp = begin_temp_memory(&global_part);
Bind_Helper context = get_context_on_global_part();
@ -623,9 +634,10 @@ CUSTOM_COMMAND_SIG(set_bindings_mac_default){
global_set_mapping(app, result.data, result.size);
end_temp_memory(temp);
}
}
#endif
#endif
// BOTTOM
// BOTTOM

View File

@ -687,6 +687,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
memset(new_mapping.map_id_table, -1, user_map_count*sizeof(i32));
new_mapping.user_maps = push_array(part, Command_Map, user_map_count);
memset(new_mapping.user_maps, 0, user_map_count*sizeof(Command_Map));
// Find the Size of Each Map
for (++unit; unit < end; ++unit){
@ -824,9 +825,10 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
{
if (map_ptr != 0){
Command_Function *func = 0;
if (unit->binding.command_id >= 0 && unit->binding.command_id < cmdid_count)
if (unit->binding.command_id >= 0 && unit->binding.command_id < cmdid_count){
func = command_table[unit->binding.command_id];
if (func){
}
if (func != 0){
if (unit->binding.code == 0){
u32 index = 0;
if (map_get_modifiers_hash(unit->binding.modifiers, &index)){
@ -846,7 +848,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
if (map_ptr != 0){
Command_Function *func = command_user_callback;
Custom_Command_Function *custom = unit->callback.func;
if (func){
if (func != 0){
if (unit->callback.code == 0){
u32 index = 0;
if (map_get_modifiers_hash(unit->binding.modifiers, &index)){

View File

@ -2098,7 +2098,7 @@ DOC_SEE(User_Input)
}
API_EXPORT User_Input
Get_Command_Input (Application_Links *app)
Get_Command_Input(Application_Links *app)
/*
DOC_RETURN(This call returns the input that triggered the currently executing command.)
DOC_SEE(User_Input)

View File

@ -138,7 +138,7 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f
u32 max = map->max;
u32 index = hash % max;
Command_Binding entry = map->commands[index];
while (entry.function != 0 && entry.hash != COMMAND_HASH_ERASED){
for (; entry.function != 0 && entry.hash != COMMAND_HASH_ERASED;){
if (entry.hash == hash){
result = true;
break;
@ -148,13 +148,15 @@ map_add(Command_Map *map, Key_Code event_code, u8 modifiers, Command_Function *f
}
if (override_original || !result){
Command_Binding bind;
Command_Binding bind = {0};
bind.function = function;
bind.custom = custom;
bind.hash = hash;
map->commands[index] = bind;
if (!result){
++map->count;
}
}
return(result);
}
@ -171,7 +173,7 @@ map_find_entry(Command_Map *map, Key_Code event_code, u8 modifiers, u32 *index_o
u32 index = hash % max;
b32 result = false;
Command_Binding entry = map->commands[index];
while (entry.function != 0){
for (; entry.function != 0;){
if (entry.hash == hash){
*index_out = index;
result = true;
@ -222,13 +224,16 @@ map_get_modifiers_hash(u8 modifiers, u32 *hash_out){
b32 result = true;
u32 hash = 0;
if (modifiers & MDFR_SHIFT){
hash += 0x1;
hash += MDFR_SHIFT;
}
if (modifiers & MDFR_CTRL){
hash += 0x2;
hash += MDFR_CTRL;
}
if (modifiers & MDFR_CMND){
hash += MDFR_CMND;
}
if (modifiers & MDFR_ALT){
hash += 0x4;
hash += MDFR_ALT;
}
*hash_out = hash;
return(result);
@ -253,8 +258,8 @@ map_extract(Command_Map *map, Key_Event_Data key){
u8 mod_flags = MDFR_NONE;
if (ctrl) mod_flags |= MDFR_CTRL;
if (command) mod_flags |= MDFR_CMND;
if (alt) mod_flags |= MDFR_ALT;
if (command) mod_flags |= MDFR_CMND;
if (shift) mod_flags |= MDFR_SHIFT;
Key_Code code = key.character_no_caps_lock;

View File

@ -4146,10 +4146,14 @@ internal Single_Line_Input_Step
app_single_line_input_core(System_Functions *system, Working_Set *working_set, Key_Event_Data key, Single_Line_Mode mode){
Single_Line_Input_Step result = {0};
b8 ctrl = key.modifiers[MDFR_CONTROL_INDEX];
b8 cmnd = key.modifiers[MDFR_COMMAND_INDEX];
b8 alt = key.modifiers[MDFR_ALT_INDEX];
if (key.keycode == key_back){
result.hit_backspace = 1;
result.hit_backspace = true;
if (mode.string->size > 0){
result.made_a_change = 1;
result.made_a_change = true;
--mode.string->size;
switch (mode.type){
case SINGLE_LINE_STRING:
@ -4159,7 +4163,7 @@ app_single_line_input_core(System_Functions *system, Working_Set *working_set, K
case SINGLE_LINE_FILE:
{
if (!key.modifiers[MDFR_CONTROL_INDEX]){
if (!ctrl && !cmnd && !alt){
char end_character = mode.string->str[mode.string->size];
if (char_is_slash(end_character)){
mode.string->size = reverse_seek_slash(*mode.string) + 1;
@ -4183,14 +4187,14 @@ app_single_line_input_core(System_Functions *system, Working_Set *working_set, K
}
else if (key.keycode == key_esc){
result.hit_esc = 1;
result.made_a_change = 1;
result.hit_esc = true;
result.made_a_change = true;
}
else if (key.character){
result.hit_a_character = 1;
if (!key.modifiers[MDFR_CONTROL_INDEX] && !key.modifiers[MDFR_ALT_INDEX]){
if (mode.string->size+1 < mode.string->memory_size){
result.hit_a_character = true;
if (!ctrl && !cmnd && !alt){
if (mode.string->size + 1 < mode.string->memory_size){
u8 new_character = (u8)key.character;
mode.string->str[mode.string->size] = new_character;
mode.string->size++;
@ -4198,11 +4202,11 @@ app_single_line_input_core(System_Functions *system, Working_Set *working_set, K
if (mode.type == SINGLE_LINE_FILE && char_is_slash(new_character)){
hot_directory_set(system, mode.hot_directory, *mode.string);
}
result.made_a_change = 1;
result.made_a_change = true;
}
}
else{
result.did_command = 1;
result.did_command = true;
}
}

View File

@ -37,7 +37,9 @@ SOURCE=$PHYS_DIR/$TARGET_FILE
FLAGS="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -Wno-writable-strings"
DEBUG=-g
cd "$REAL_PWD"
echo "Building custom_4coders.so from $SOURCE"
g++ -I"$CODE_HOME" $FLAGS -std=gnu++0x "$SOURCE" -shared -o custom_4coder.so -fPIC
g++ -I"$CODE_HOME" $FLAGS $DEBUG -std=gnu++0x "$SOURCE" -shared -o custom_4coder.so -fPIC

View File

@ -1,4 +1,3 @@
/*
* Mr. 4th Dimention - Allen Webster
*