New input binding system up and running.

This commit is contained in:
Allen Webster 2019-10-10 18:40:10 -07:00
parent 0e51ffa80d
commit dbaab9d945
20 changed files with 506 additions and 484 deletions

237
4ed.cpp
View File

@ -111,229 +111,6 @@ DELTA_RULE_SIG(fallback_scroll_rule){
return(pending_delta); return(pending_delta);
} }
#if 0
#define DEFAULT_MAP_SIZE 10
#define DEFAULT_UI_MAP_SIZE 32
// TODO(allen): REWRITE REWRITE REWRITE!
internal b32
interpret_binding_buffer(Models *models, void *buffer, i32 size){
b32 result = true;
Heap *gen = &models->heap;
Scratch_Block scratch(models->tctx, Scratch_Share);
Mapping new_mapping = {};
mapping_init(models->tctx, &new_mapping);
models->scroll_rule = fallback_scroll_rule;
models->hook_open_file = 0;
models->hook_new_file = 0;
models->hook_save_file = 0;
models->hook_end_file = 0;
models->hook_file_edit_range = 0;
models->command_caller = 0;
models->render_caller = 0;
models->input_filter = 0;
b32 did_top = false;
b32 did_file = false;
Command_Map *map_ptr = 0;
Binding_Unit *unit = (Binding_Unit*)buffer;
if (unit->type == unit_header && unit->header.error == 0){
Binding_Unit *end = unit + unit->header.total_size;
mapping_get_or_make_map(&new_mapping, mapid_global);
mapping_get_or_make_map(&new_mapping, mapid_file);
// Find the Size of Each Map
for (++unit; unit < end; ++unit){
switch (unit->type){
case unit_map_begin:
{
i32 mapid = unit->map_begin.mapid;
if (mapid == mapid_nomap){
break;
}
Command_Map *map = mapping_get_or_make_map(&new_mapping, mapid);
map_set_parent(&new_mapping, map, mapid_global);
if (unit->map_begin.replace){
map->real_beginning = unit;
}
else{
if (map->real_beginning == 0){
map->real_beginning = unit;
}
}
}break;
}
}
// Fill in Command Maps
unit = (Binding_Unit*)buffer;
for (++unit; unit < end; ++unit){
switch (unit->type){
case unit_map_begin:
{
i32 mapid = unit->map_begin.mapid;
if (mapid == mapid_nomap){
map_ptr = 0;
}
else{
Command_Map *map = mapping_get_or_make_map(&new_mapping, mapid);
if (unit >= map->real_beginning){
if (mapid == mapid_file || mapid <= mapid_global){
map_ptr = map;
}
else{
map_ptr = 0;
}
}
}
}break;
case unit_inherit:
{
if (map_ptr != 0){
if (unit->map_inherit.mapid == mapid_nomap){
map_null_parent(map_ptr);
}
else{
map_set_parent(&new_mapping, map_ptr, unit->map_inherit.mapid);
}
}
}break;
case unit_callback:
{
if (map_ptr != 0){
Custom_Command_Function *custom = unit->callback.func;
if (unit->callback.code == 0){
map_set_binding_text_input(map_ptr, custom);
}
else{
Key_Modifiers modifiers = {};
modifiers.modifiers[MDFR_SHIFT_INDEX] =
HasFlag(unit->callback.modifiers, MDFR_SHIFT);
modifiers.modifiers[MDFR_CONTROL_INDEX] =
HasFlag(unit->callback.modifiers, MDFR_CTRL);
modifiers.modifiers[MDFR_ALT_INDEX] =
HasFlag(unit->callback.modifiers, MDFR_ALT);
modifiers.modifiers[MDFR_COMMAND_INDEX] =
HasFlag(unit->callback.modifiers, MDFR_CMND);
map_set_binding_key(&new_mapping, map_ptr, custom,
unit->callback.code, &modifiers);
}
}
}break;
case unit_hook:
{
i32 hook_id = unit->hook.hook_id;
if (hook_id >= 0){
if (hook_id < hook_type_count){
models->hooks[hook_id] = (Hook_Function*)unit->hook.func;
}
else{
switch (hook_id){
case special_hook_open_file:
{
models->hook_open_file = (Buffer_Hook_Function*)unit->hook.func;
}break;
case special_hook_new_file:
{
models->hook_new_file = (Buffer_Hook_Function*)unit->hook.func;
}break;
case special_hook_save_file:
{
models->hook_save_file = (Buffer_Hook_Function*)unit->hook.func;
}break;
case special_hook_end_file:
{
models->hook_end_file = (Buffer_Hook_Function*)unit->hook.func;
}break;
case special_hook_file_edit_range:
{
models->hook_file_edit_range = (File_Edit_Range_Function*)unit->hook.func;
}break;
case special_hook_file_externally_modified:
{
models->hook_file_externally_modified = (File_Externally_Modified_Function*)unit->hook.func;
}break;
case special_hook_command_caller:
{
models->command_caller = (Command_Caller_Hook_Function*)unit->hook.func;
}break;
case special_hook_render_caller:
{
models->render_caller = (Render_Caller_Function*)unit->hook.func;
}break;
case special_hook_scroll_rule:
{
models->scroll_rule = (Delta_Rule_Function*)unit->hook.func;
}break;
case special_hook_buffer_name_resolver:
{
models->buffer_name_resolver = (Buffer_Name_Resolver_Function*)unit->hook.func;
}break;
case special_hook_modify_color_table:
{
models->modify_color_table = (Modify_Color_Table_Function*)unit->hook.func;
}break;
case special_hook_clipboard_change:
{
models->clipboard_change = (Clipboard_Change_Hook_Function*)unit->hook.func;
}break;
case special_hook_get_view_buffer_region:
{
models->get_view_buffer_region = (Get_View_Buffer_Region_Function*)unit->hook.func;
}break;
case special_hook_input_filter:
{
models->input_filter = (Input_Filter_Function*)unit->hook.func;
}break;
case special_hook_start:
{
models->hook_start = (Start_Hook_Function*)unit->hook.func;
}break;
}
}
}
}break;
}
}
}
else{
// TODO(allen): do(Error report: bad binding units map.)
// TODO(allen): do(no bindings set recovery plan.)
InvalidPath;
}
mapping_release(models->tctx, &models->mapping);
models->mapping = new_mapping;
return(result);
}
#endif
#include "4ed_api_implementation.cpp" #include "4ed_api_implementation.cpp"
internal void internal void
@ -886,20 +663,21 @@ App_Step_Sig(app_step){
} }
Input_List input_list = input->events; Input_List input_list = input->events;
Key_Modifiers modifiers = system_get_keyboard_modifiers(); Input_Modifier_Set modifiers = system_get_keyboard_modifiers(scratch);
if (input->mouse.press_l){ if (input->mouse.press_l){
Input_Event event = {}; Input_Event event = {};
event.kind = InputEventKind_MouseButton; event.kind = InputEventKind_MouseButton;
event.mouse.code = MouseCode_Left; event.mouse.code = MouseCode_Left;
event.mouse.p = input->mouse.p; event.mouse.p = input->mouse.p;
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
push_input_event(scratch, &input_list, &event); push_input_event(scratch, &input_list, &event);
} }
else if (input->mouse.release_l){ else if (input->mouse.release_l){
Input_Event event = {}; Input_Event event = {};
event.kind = InputEventKind_MouseButton; event.kind = InputEventKind_MouseButtonRelease;
event.mouse.code = MouseCode_Left; event.mouse.code = MouseCode_Left;
event.mouse.p = input->mouse.p; event.mouse.p = input->mouse.p;
event.mouse.release = true; event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
push_input_event(scratch, &input_list, &event); push_input_event(scratch, &input_list, &event);
} }
if (input->mouse.press_r){ if (input->mouse.press_r){
@ -907,14 +685,15 @@ App_Step_Sig(app_step){
event.kind = InputEventKind_MouseButton; event.kind = InputEventKind_MouseButton;
event.mouse.code = MouseCode_Right; event.mouse.code = MouseCode_Right;
event.mouse.p = input->mouse.p; event.mouse.p = input->mouse.p;
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
push_input_event(scratch, &input_list, &event); push_input_event(scratch, &input_list, &event);
} }
else if (input->mouse.release_r){ else if (input->mouse.release_r){
Input_Event event = {}; Input_Event event = {};
event.kind = InputEventKind_MouseButton; event.kind = InputEventKind_MouseButtonRelease;
event.mouse.code = MouseCode_Right; event.mouse.code = MouseCode_Right;
event.mouse.p = input->mouse.p; event.mouse.p = input->mouse.p;
event.mouse.release = true; event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
push_input_event(scratch, &input_list, &event); push_input_event(scratch, &input_list, &event);
} }
if (input->mouse.wheel != 0){ if (input->mouse.wheel != 0){
@ -922,6 +701,7 @@ App_Step_Sig(app_step){
event.kind = InputEventKind_MouseWheel; event.kind = InputEventKind_MouseWheel;
event.mouse_wheel.value = (f32)(input->mouse.wheel); event.mouse_wheel.value = (f32)(input->mouse.wheel);
event.mouse_wheel.p = input->mouse.p; event.mouse_wheel.p = input->mouse.p;
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
push_input_event(scratch, &input_list, &event); push_input_event(scratch, &input_list, &event);
} }
if (input->mouse.p != models->prev_p){ if (input->mouse.p != models->prev_p){
@ -931,6 +711,7 @@ App_Step_Sig(app_step){
Input_Event event = {}; Input_Event event = {};
event.kind = InputEventKind_MouseMove; event.kind = InputEventKind_MouseMove;
event.mouse_move.p = input->mouse.p; event.mouse_move.p = input->mouse.p;
event.mouse.modifiers = copy_modifier_set(scratch, &modifiers);
push_input_event(scratch, &input_list, &event); push_input_event(scratch, &input_list, &event);
} }
} }

View File

@ -74,8 +74,16 @@ global_get_screen_rectangle(Application_Links *app){
api(custom) function Thread_Context* api(custom) function Thread_Context*
get_thread_context(Application_Links *app){ get_thread_context(Application_Links *app){
Models *models = (Models*)app->cmd_context; Thread_Context *tctx = 0;
return(models->tctx); if (app->current_coroutine == 0){
Models *models = (Models*)app->cmd_context;
tctx = models->tctx;
}
else{
Coroutine *coroutine = (Coroutine*)app->current_coroutine;
tctx = coroutine->tctx;
}
return(tctx);
} }
api(custom) function b32 api(custom) function b32

View File

@ -30,6 +30,10 @@ internal void
coroutine_main(void *ptr){ coroutine_main(void *ptr){
Coroutine *me = (Coroutine*)ptr; Coroutine *me = (Coroutine*)ptr;
Thread_Context tctx_ = {};
thread_ctx_init(&tctx_, get_base_allocator_system());
me->tctx = &tctx_;
// NOTE(allen): Init handshake // NOTE(allen): Init handshake
Assert(me->state == CoroutineState_Dead); Assert(me->state == CoroutineState_Dead);
system_mutex_acquire(me->sys->lock); system_mutex_acquire(me->sys->lock);

View File

@ -31,6 +31,7 @@ enum{
struct Coroutine{ struct Coroutine{
Coroutine *next; Coroutine *next;
Thread_Context *tctx;
void *in; void *in;
void *out; void *out;
System_Thread thread; System_Thread thread;

View File

@ -250,7 +250,8 @@ define_api(Arena *arena){
} }
{ {
API_Call *call = api_call(arena, api, "get_keyboard_modifiers", "Key_Modifiers"); API_Call *call = api_call(arena, api, "get_keyboard_modifiers", "Input_Modifier_Set");
api_param(arena, call, "Arena*", "arena");
} }
return(api); return(api);

View File

@ -854,8 +854,8 @@ isearch(Application_Links *app, Scan_Direction start_scan, String_Const_u8 query
b32 string_change = false; b32 string_change = false;
if (match_key_code(&in, KeyCode_Return) || if (match_key_code(&in, KeyCode_Return) ||
match_key_code(&in, KeyCode_Tab)){ match_key_code(&in, KeyCode_Tab)){
Key_Modifiers *mods = &in.event.key.modifiers; Input_Modifier_Set *mods = &in.event.key.modifiers;
if (mods->modifiers[MDFR_CONTROL_INDEX]){ if (has_modifier(mods, KeyCode_Control)){
bar.string.size = cstring_length(previous_isearch_query); bar.string.size = cstring_length(previous_isearch_query);
block_copy(bar.string.str, previous_isearch_query, bar.string.size); block_copy(bar.string.str, previous_isearch_query, bar.string.size);
} }
@ -879,7 +879,7 @@ isearch(Application_Links *app, Scan_Direction start_scan, String_Const_u8 query
bar.string = backspace_utf8(bar.string); bar.string = backspace_utf8(bar.string);
string_change = (bar.string.size < old_bar_string_size); string_change = (bar.string.size < old_bar_string_size);
} }
else if (in.event.key.modifiers.modifiers[MDFR_CONTROL_INDEX]){ else if (has_modifier(&in.event.key.modifiers, KeyCode_Control)){
if (bar.string.size > 0){ if (bar.string.size > 0){
string_change = true; string_change = true;
bar.string.size = 0; bar.string.size = 0;

View File

@ -2753,6 +2753,17 @@ thread_ctx_init(Thread_Context *tctx, Base_Allocator *allocator){
tctx->node_arena = make_arena(allocator, KB(4), 8); tctx->node_arena = make_arena(allocator, KB(4), 8);
} }
internal void
thread_ctx_release(Thread_Context *tctx){
for (Arena_Node *node = tctx->free_arenas;
node != 0;
node = node->next){
linalloc_clear(&node->arena);
}
linalloc_clear(&tctx->node_arena);
block_zero_struct(tctx);
}
internal Arena* internal Arena*
reserve_arena(Thread_Context *tctx, umem chunk_size, umem align){ reserve_arena(Thread_Context *tctx, umem chunk_size, umem align){
Arena_Node *node = tctx->free_arenas; Arena_Node *node = tctx->free_arenas;

View File

@ -9,6 +9,11 @@
// TOP // TOP
internal u64
mapping__key(Input_Event_Kind kind, u32 sub_code){
return((((u64)kind) << 32) | sub_code);
}
internal Command_Map* internal Command_Map*
mapping__alloc_map(Mapping *mapping){ mapping__alloc_map(Mapping *mapping){
Command_Map *result = mapping->free_maps; Command_Map *result = mapping->free_maps;
@ -61,25 +66,25 @@ mapping__free_binding_list(Mapping *mapping, Command_Binding_List *binding_list)
} }
internal Command_Binding_List* internal Command_Binding_List*
map__get_list(Command_Map *map, Key_Code code){ map__get_list(Command_Map *map, u64 key){
Command_Binding_List *result = 0; Command_Binding_List *result = 0;
Table_Lookup lookup = table_lookup(&map->key_code_to_binding_list, code); Table_Lookup lookup = table_lookup(&map->event_code_to_binding_list, key);
if (lookup.found_match){ if (lookup.found_match){
u64 val = 0; u64 val = 0;
table_read(&map->key_code_to_binding_list, lookup, &val); table_read(&map->event_code_to_binding_list, lookup, &val);
result = (Command_Binding_List*)IntAsPtr(val); result = (Command_Binding_List*)IntAsPtr(val);
} }
return(result); return(result);
} }
internal Command_Binding_List* internal Command_Binding_List*
map__get_or_make_list(Mapping *mapping, Command_Map *map, Key_Code code){ map__get_or_make_list(Mapping *mapping, Command_Map *map, u64 key){
Command_Binding_List *result = map__get_list(map, code); Command_Binding_List *result = map__get_list(map, key);
if (result == 0){ if (result == 0){
result = mapping__alloc_binding_list(mapping); result = mapping__alloc_binding_list(mapping);
block_zero_struct(result); block_zero_struct(result);
sll_queue_push(map->list_first, map->list_last, result); sll_queue_push(map->list_first, map->list_last, result);
table_insert(&map->key_code_to_binding_list, code, (u64)PtrAsInt(result)); table_insert(&map->event_code_to_binding_list, key, (u64)PtrAsInt(result));
} }
return(result); return(result);
} }
@ -92,7 +97,7 @@ mapping_init(Thread_Context *tctx, Mapping *mapping){
mapping->node_arena = reserve_arena(tctx); mapping->node_arena = reserve_arena(tctx);
heap_init(&mapping->heap, mapping->node_arena); heap_init(&mapping->heap, mapping->node_arena);
mapping->heap_wrapper = base_allocator_on_heap(&mapping->heap); mapping->heap_wrapper = base_allocator_on_heap(&mapping->heap);
mapping->id_to_map = make_table_u64_u64(tctx->allocator, 100); mapping->id_to_map = make_table_u64_u64(tctx->allocator, 10);
mapping->id_counter = 1; mapping->id_counter = 1;
} }
@ -104,13 +109,19 @@ mapping_release(Thread_Context *tctx, Mapping *mapping){
} }
} }
internal void
map__init(Mapping *mapping, Command_Map *map, Command_Map_ID id){
block_zero_struct(map);
map->id = id;
map->node_arena = make_arena(&mapping->heap_wrapper, KB(2));
map->event_code_to_binding_list = make_table_u64_u64(&mapping->heap_wrapper, 100);
}
internal Command_Map* internal Command_Map*
mapping_begin_new_map(Mapping *mapping){ mapping_begin_new_map(Mapping *mapping){
Command_Map *map = mapping__alloc_map(mapping); Command_Map *map = mapping__alloc_map(mapping);
block_zero_struct(map); map__init(mapping, map, mapping->id_counter);
map->id = mapping->id_counter;
mapping->id_counter += 1; mapping->id_counter += 1;
map->key_code_to_binding_list = make_table_u64_u64(&mapping->heap_wrapper, 8);
table_insert(&mapping->id_to_map, map->id, (u64)PtrAsInt(map)); table_insert(&mapping->id_to_map, map->id, (u64)PtrAsInt(map));
return(map); return(map);
} }
@ -141,9 +152,7 @@ mapping_get_or_make_map(Mapping *mapping, Command_Map_ID id){
Command_Map *result = mapping_get_map(mapping, id); Command_Map *result = mapping_get_map(mapping, id);
if (result == 0){ if (result == 0){
result = mapping__alloc_map(mapping); result = mapping__alloc_map(mapping);
block_zero_struct(result); map__init(mapping, result, id);
result->id = id;
result->key_code_to_binding_list = make_table_u64_u64(&mapping->heap_wrapper, 8);
table_insert(&mapping->id_to_map, result->id, (u64)PtrAsInt(result)); table_insert(&mapping->id_to_map, result->id, (u64)PtrAsInt(result));
} }
return(result); return(result);
@ -160,7 +169,8 @@ mapping_release_map(Mapping *mapping, Command_Map *map){
map->list_last->next = mapping->free_lists; map->list_last->next = mapping->free_lists;
mapping->free_lists = map->list_first; mapping->free_lists = map->list_first;
} }
table_free(&map->key_code_to_binding_list); table_free(&map->event_code_to_binding_list);
linalloc_clear(&map->node_arena);
} }
internal Command_Binding internal Command_Binding
@ -168,6 +178,10 @@ map_get_binding_non_recursive(Command_Map *map, Input_Event *event){
Command_Binding result = {}; Command_Binding result = {};
if (map != 0){ if (map != 0){
b32 do_table_lookup = false;
Input_Modifier_Set *mods = 0;
u64 key = 0;
switch (event->kind){ switch (event->kind){
case InputEventKind_TextInsert: case InputEventKind_TextInsert:
{ {
@ -176,21 +190,56 @@ map_get_binding_non_recursive(Command_Map *map, Input_Event *event){
case InputEventKind_KeyStroke: case InputEventKind_KeyStroke:
{ {
Table_Lookup lookup = table_lookup(&map->key_code_to_binding_list, event->key.code); key = mapping__key(InputEventKind_KeyStroke, event->key.code);
if (lookup.found_match){ do_table_lookup = true;
u64 val = 0; mods = &event->key.modifiers;
table_read(&map->key_code_to_binding_list, lookup, &val); }break;
Command_Binding_List *list = (Command_Binding_List*)IntAsPtr(val);
Key_Modifiers *event_mods = &event->key.modifiers; case InputEventKind_MouseButton:
{
key = mapping__key(InputEventKind_MouseButton, event->mouse.code);
do_table_lookup = true;
mods = &event->mouse.modifiers;
}break;
case InputEventKind_MouseWheel:
{
key = mapping__key(InputEventKind_MouseWheel, 0);
do_table_lookup = true;
mods = &event->mouse_wheel.modifiers;
}break;
case InputEventKind_MouseMove:
{
key = mapping__key(InputEventKind_MouseMove, 0);
do_table_lookup = true;
mods = &event->mouse_move.modifiers;
}break;
case InputEventKind_Core:
{
key = mapping__key(InputEventKind_Core, event->core.code);
do_table_lookup = true;
}break;
}
if (do_table_lookup){
Table_Lookup lookup = table_lookup(&map->event_code_to_binding_list, key);
if (lookup.found_match){
u64 val = 0;
table_read(&map->event_code_to_binding_list, lookup, &val);
Command_Binding_List *list = (Command_Binding_List*)IntAsPtr(val);
if (mods != 0){
for (SNode *node = list->first; for (SNode *node = list->first;
node != 0; node != 0;
node = node->next){ node = node->next){
Command_Modified_Binding *mod_binding = CastFromMember(Command_Modified_Binding, order_node, node); Command_Modified_Binding *mod_binding = CastFromMember(Command_Modified_Binding, order_node, node);
Key_Modifiers *binding_mods = &mod_binding->modifiers; Input_Modifier_Set *binding_modifiers = &mod_binding->modifiers;
b32 is_a_match = true; b32 is_a_match = true;
for (i32 i = 0; i < ArrayCount(binding_mods->modifiers); i += 1){ i32 binding_mod_count = binding_modifiers->count;
if (binding_mods->modifiers[i] && Key_Code *binding_mods = binding_modifiers->mods;
!event_mods->modifiers[i]){ for (i32 i = 0; i < binding_mod_count; i += 1){
if (!has_modifier(mods, binding_mods[i])){
is_a_match = false; is_a_match = false;
break; break;
} }
@ -200,9 +249,12 @@ map_get_binding_non_recursive(Command_Map *map, Input_Event *event){
break; break;
} }
} }
} }
}break; else{
Command_Modified_Binding *mod_binding = CastFromMember(Command_Modified_Binding, order_node, list->first);
result = mod_binding->binding;
}
}
} }
} }
@ -237,17 +289,11 @@ map_null_parent(Command_Map *map){
} }
internal void internal void
map_set_binding_text_input(Command_Map *map, Custom_Command_Function *custom){ map_set_binding(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom,
u32 code1, u32 code2, Input_Modifier_Set *modifiers){
if (map != 0){ if (map != 0){
map->text_input_command.custom = custom; u64 key = mapping__key(code1, code2);
} Command_Binding_List *list = map__get_or_make_list(mapping, map, key);
}
internal void
map_set_binding_key(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom,
Key_Code code, Key_Modifiers *modifiers){
if (map != 0){
Command_Binding_List *list = map__get_or_make_list(mapping, map, code);
Command_Modified_Binding *mod_binding = mapping__alloc_modified_binding(mapping); Command_Modified_Binding *mod_binding = mapping__alloc_modified_binding(mapping);
sll_stack_push(map->binding_first, mod_binding); sll_stack_push(map->binding_first, mod_binding);
if (map->binding_last == 0){ if (map->binding_last == 0){
@ -258,16 +304,62 @@ map_set_binding_key(Mapping *mapping, Command_Map *map, Custom_Command_Function
list->last= list->first; list->last= list->first;
} }
list->count += 1; list->count += 1;
block_copy_struct(&mod_binding->modifiers, modifiers); mod_binding->modifiers = copy_modifier_set(&map->node_arena, modifiers);
mod_binding->binding.custom = custom; mod_binding->binding.custom = custom;
} }
} }
internal void
map_set_binding_key(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom,
Key_Code code, Input_Modifier_Set *modifiers){
map_set_binding(mapping, map, custom, InputEventKind_KeyStroke, code, modifiers);
}
internal void
map_set_binding_mouse(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom,
Mouse_Code code, Input_Modifier_Set *modifiers){
map_set_binding(mapping, map, custom, InputEventKind_MouseButton, code, modifiers);
}
internal void
map_set_binding_core(Mapping *mapping, Command_Map *map, Custom_Command_Function *custom,
Core_Code code, Input_Modifier_Set *modifiers){
map_set_binding(mapping, map, custom, InputEventKind_Core, code, modifiers);
}
internal void
map_set_binding_text_input(Command_Map *map, Custom_Command_Function *custom){
if (map != 0){
map->text_input_command.custom = custom;
}
}
internal Command_Binding_List* internal Command_Binding_List*
map_get_binding_list_on_key(Command_Map *map, Key_Code code){ map_get_binding_list_on_key(Command_Map *map, Key_Code code){
Command_Binding_List *result = 0; Command_Binding_List *result = 0;
if (map != 0){ if (map != 0){
result = map__get_list(map, code); u64 key = mapping__key(InputEventKind_KeyStroke, code);
result = map__get_list(map, key);
}
return(result);
}
internal Command_Binding_List*
map_get_binding_list_on_mouse_button(Command_Map *map, Mouse_Code code){
Command_Binding_List *result = 0;
if (map != 0){
u64 key = mapping__key(InputEventKind_MouseButton, code);
result = map__get_list(map, key);
}
return(result);
}
internal Command_Binding_List*
map_get_binding_list_on_core(Command_Map *map, Core_Code code){
Command_Binding_List *result = 0;
if (map != 0){
u64 key = mapping__key(InputEventKind_Core, code);
result = map__get_list(map, key);
} }
return(result); return(result);
} }
@ -294,18 +386,39 @@ map_null_parent(Mapping *mapping, Command_Map_ID map_id){
} }
internal void internal void
map_set_binding_text_input(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom){ map_set_binding(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom,
u32 code1, u32 code2, Input_Modifier_Set *modifiers){
Command_Map *map = mapping_get_map(mapping, map_id); Command_Map *map = mapping_get_map(mapping, map_id);
map_set_binding_text_input(map, custom); map_set_binding(mapping, map, custom, code1, code2, modifiers);
} }
internal void internal void
map_set_binding_key(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom, map_set_binding_key(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom,
Key_Code code, Key_Modifiers *modifiers){ Key_Code code, Input_Modifier_Set *modifiers){
Command_Map *map = mapping_get_map(mapping, map_id); Command_Map *map = mapping_get_map(mapping, map_id);
map_set_binding_key(mapping, map, custom, code, modifiers); map_set_binding_key(mapping, map, custom, code, modifiers);
} }
internal void
map_set_binding_mouse(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom,
Mouse_Code code, Input_Modifier_Set *modifiers){
Command_Map *map = mapping_get_map(mapping, map_id);
map_set_binding_mouse(mapping, map, custom, code, modifiers);
}
internal void
map_set_binding_core(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom,
Core_Code code, Input_Modifier_Set *modifiers){
Command_Map *map = mapping_get_map(mapping, map_id);
map_set_binding_core(mapping, map, custom, code, modifiers);
}
internal void
map_set_binding_text_input(Mapping *mapping, Command_Map_ID map_id, Custom_Command_Function *custom){
Command_Map *map = mapping_get_map(mapping, map_id);
map_set_binding_text_input(map, custom);
}
internal Command_Binding_List* internal Command_Binding_List*
map_get_binding_list_on_key(Mapping *mapping, Command_Map_ID map_id, Key_Code code){ map_get_binding_list_on_key(Mapping *mapping, Command_Map_ID map_id, Key_Code code){
Command_Map *map = mapping_get_map(mapping, map_id); Command_Map *map = mapping_get_map(mapping, map_id);
@ -327,29 +440,27 @@ map_get_binding_recursive(Mapping *mapping, Command_Map_ID map_id, Input_Event *
//////////////////////////////// ////////////////////////////////
internal void internal void
map_set_binding_key__wrapperv(Mapping *mapping, Command_Map *map, map_set_binding_lv(Mapping *mapping, Command_Map *map,
Custom_Command_Function *custom, Key_Code code, va_list args){ Custom_Command_Function *custom, u32 code1, u32 code2, va_list args){
u32 flags = 0; Input_Modifier_Set mods = {};
for (;;){ Key_Code mods_array[Input_MaxModifierCount];
mods.mods = mods_array;
for (;mods.count < ArrayCount(mods_array);){
i32 v = va_arg(args, i32); i32 v = va_arg(args, i32);
if (v <= 0){ if (v <= 0){
break; break;
} }
flags |= v; mods.mods[mods.count] = v;
mods.count += 1;
} }
Key_Modifiers mod = {}; return(map_set_binding(mapping, map, custom, code1, code2, &mods));
mod.modifiers[MDFR_SHIFT_INDEX] = HasFlag(flags, MDFR_SHIFT);
mod.modifiers[MDFR_CONTROL_INDEX] = HasFlag(flags, MDFR_CTRL);
mod.modifiers[MDFR_ALT_INDEX] = HasFlag(flags, MDFR_ALT);
mod.modifiers[MDFR_COMMAND_INDEX] = HasFlag(flags, MDFR_CMND);
return(map_set_binding_key(mapping, map, custom, code, &mod));
} }
internal void internal void
map_set_binding_key__wrapper(Mapping *mapping, Command_Map *map, map_set_binding_l(Mapping *mapping, Command_Map *map,
Custom_Command_Function *custom, Key_Code code, ...){ Custom_Command_Function *custom, u32 code1, u32 code2, ...){
va_list args; va_list args;
va_start(args, code); va_start(args, code2);
map_set_binding_key__wrapperv(mapping, map, custom, code, args); map_set_binding_lv(mapping, map, custom, code1, code2, args);
va_end(args); va_end(args);
} }
@ -359,7 +470,20 @@ map_set_binding_key__wrapper(Mapping *mapping, Command_Map *map,
#define ParentMap(ID) map_set_parent(m, map, (ID)) #define ParentMap(ID) map_set_parent(m, map, (ID))
#define BindTextInput(F) map_set_binding_text_input(map, (F)) #define BindTextInput(F) map_set_binding_text_input(map, (F))
// TODO(allen): detect compiler and apply va args extensions correctly // TODO(allen): detect compiler and apply va args extensions correctly
#define Bind(F, K, ...) map_set_binding_key__wrapper(m, map, (F), (K), __VA_ARGS__, 0) #define Bind(F, K, ...) \
map_set_binding_l(m, map, (F), InputEventKind_KeyStroke, (K), __VA_ARGS__, 0)
#define BindRelease(F, K, ...) \
map_set_binding_l(m, map, (F), InputEventKind_KeyRelease, (K), __VA_ARGS__, 0)
#define BindMouse(F, K, ...) \
map_set_binding_l(m, map, (F), InputEventKind_MouseButton, (K), __VA_ARGS__, 0)
#define BindMouseRelease(F, K, ...) \
map_set_binding_l(m, map, (F), InputEventKind_MouseButtonRelease, (K), __VA_ARGS__, 0)
#define BindMouseWheel(F, ...) \
map_set_binding_l(m, map, (F), InputEventKind_MouseWheel, 0, __VA_ARGS__, 0)
#define BindMouseMove(F, ...) \
map_set_binding_l(m, map, (F), InputEventKind_MouseMove, 0, __VA_ARGS__, 0)
#define BindCore(F, K, ...) \
map_set_binding_l(m, map, (F), InputEventKind_Core, (K), __VA_ARGS__, 0)
// BOTTOM // BOTTOM

View File

@ -19,7 +19,7 @@ struct Command_Binding{
struct Command_Modified_Binding{ struct Command_Modified_Binding{
Command_Modified_Binding *next; Command_Modified_Binding *next;
SNode order_node; SNode order_node;
Key_Modifiers modifiers; Input_Modifier_Set modifiers;
Command_Binding binding; Command_Binding binding;
}; };
@ -35,7 +35,8 @@ struct Command_Map{
Command_Map_ID id; Command_Map_ID id;
Command_Map_ID parent; Command_Map_ID parent;
Command_Binding text_input_command; Command_Binding text_input_command;
Table_u64_u64 key_code_to_binding_list; Arena node_arena;
Table_u64_u64 event_code_to_binding_list;
Command_Modified_Binding *binding_first; Command_Modified_Binding *binding_first;
Command_Modified_Binding *binding_last; Command_Modified_Binding *binding_last;
Command_Binding_List *list_first; Command_Binding_List *list_first;

View File

@ -4,40 +4,126 @@
// TOP // TOP
internal b32 function b32
has_modifier(Key_Code *mods, i32 count, Key_Code modifier){
b32 result = false;
for (i32 i = 0; i < count; i += 1){
if (mods[i] == modifier){
result = true;
break;
}
}
return(result);
}
function b32
has_modifier(Input_Modifier_Set_Fixed *set, Key_Code modifier){
return(has_modifier(set->mods, set->count, modifier));
}
function b32
has_modifier(Input_Modifier_Set *set, Key_Code modifier){
return(has_modifier(set->mods, set->count, modifier));
}
function Input_Modifier_Set
copy_modifier_set(Arena *arena, Input_Modifier_Set_Fixed *set){
Input_Modifier_Set result = {};
result.count = set->count;
if (result.count > 0){
result.mods = push_array_write(arena, Key_Code, result.count, set->mods);
}
return(result);
}
function void
add_modifier(Input_Modifier_Set_Fixed *set, Key_Code mod){
if (!has_modifier(set, mod)){
if (set->count < ArrayCount(set->mods)){
set->mods[set->count] = mod;
set->count += 1;
}
}
}
function void
remove_modifier(Input_Modifier_Set_Fixed *set, Key_Code mod){
i32 count = set->count;
Key_Code *mods = set->mods;
for (i32 i = 0; i < count; i += 1){
if (mods[i] == mod){
i32 new_count = count - 1;
mods[i] = mods[new_count];
set->count = new_count;
break;
}
}
}
function void
set_modifier(Input_Modifier_Set_Fixed *set, Key_Code mod, b32 val){
if (val){
add_modifier(set, mod);
}
else{
remove_modifier(set, mod);
}
}
function Input_Modifier_Set
copy_modifier_set(Arena *arena, Input_Modifier_Set *set){
Input_Modifier_Set result = {};
result.count = set->count;
if (result.count > 0){
result.mods = push_array_write(arena, Key_Code, result.count, set->mods);
}
return(result);
}
function b32
is_unmodified_key(Input_Event *event){ is_unmodified_key(Input_Event *event){
b32 result = false; b32 result = false;
if (event->kind == InputEventKind_KeyStroke){ if (event->kind == InputEventKind_KeyStroke){
b8 *mods = event->key.modifiers.modifiers; result = (event->key.modifiers.count == 0);
result = (!mods[MDFR_CONTROL_INDEX] && !mods[MDFR_ALT_INDEX]);
} }
return(result); return(result);
} }
internal b32 function Input_Modifier_Set*
is_modified(Input_Event *event){ get_modifiers(Input_Event *event){
b8 *mods = 0; Input_Modifier_Set *result = 0;
switch (event->kind){ switch (event->kind){
case InputEventKind_KeyStroke: case InputEventKind_KeyStroke:
{ {
mods = event->key.modifiers.modifiers; result = &event->key.modifiers;
}break; }break;
case InputEventKind_MouseButton: case InputEventKind_MouseButton:
{ {
mods = event->mouse.modifiers.modifiers; result = &event->mouse.modifiers;
}break;
case InputEventKind_MouseWheel:
{
result = &event->mouse_wheel.modifiers;
}break;
case InputEventKind_MouseMove:
{
result = &event->mouse_move.modifiers;
}break; }break;
}
b32 result = false;
if (mods != 0){
result = (mods[MDFR_CONTROL_INDEX] ||
mods[MDFR_ALT_INDEX] ||
mods[MDFR_SHIFT_INDEX] ||
mods[MDFR_COMMAND_INDEX]);
} }
return(result); return(result);
} }
internal String_Const_u8 function b32
is_modified(Input_Event *event){
Input_Modifier_Set *mods = get_modifiers(event);
b32 result = false;
if (mods != 0){
result = (mods->count > 0);
}
return(result);
}
function String_Const_u8
to_writable(Input_Event *event){ to_writable(Input_Event *event){
String_Const_u8 result = {}; String_Const_u8 result = {};
if (event->kind == InputEventKind_TextInsert){ if (event->kind == InputEventKind_TextInsert){
@ -46,29 +132,27 @@ to_writable(Input_Event *event){
return(result); return(result);
} }
internal b32 function b32
match_key_code(Input_Event *event, Key_Code code){ match_key_code(Input_Event *event, Key_Code code){
return(event->kind == InputEventKind_KeyStroke && event->key.code == code); return(event->kind == InputEventKind_KeyStroke && event->key.code == code);
} }
internal b32 function b32
match_mouse_code(Input_Event *event, Mouse_Code code){ match_mouse_code(Input_Event *event, Mouse_Code code){
return(event->kind == InputEventKind_MouseButton && return(event->kind == InputEventKind_MouseButton && event->mouse.code == code);
event->mouse.code == code && !event->mouse.release);
} }
internal b32 function b32
match_mouse_code_release(Input_Event *event, Mouse_Code code){ match_mouse_code_release(Input_Event *event, Mouse_Code code){
return(event->kind == InputEventKind_MouseButton && return(event->kind == InputEventKind_MouseButtonRelease && event->mouse.code == code);
event->mouse.code == code && event->mouse.release);
} }
internal b32 function b32
match_core_code(Input_Event *event, Core_Code code){ match_core_code(Input_Event *event, Core_Code code){
return(event->kind == InputEventKind_Core && event->core.code == code); return(event->kind == InputEventKind_Core && event->core.code == code);
} }
internal Event_Property function Event_Property
get_event_properties(Input_Event *event){ get_event_properties(Input_Event *event){
Event_Property flags = 0; Event_Property flags = 0;
@ -136,7 +220,7 @@ get_event_properties(Input_Event *event){
return(flags); return(flags);
} }
internal Input_Event* function Input_Event*
push_input_event(Arena *arena, Input_List *list){ push_input_event(Arena *arena, Input_List *list){
Input_Event_Node *node = push_array_zero(arena, Input_Event_Node, 1); Input_Event_Node *node = push_array_zero(arena, Input_Event_Node, 1);
sll_queue_push(list->first, list->last, node); sll_queue_push(list->first, list->last, node);
@ -144,7 +228,7 @@ push_input_event(Arena *arena, Input_List *list){
return(&node->event); return(&node->event);
} }
internal Input_Event* function Input_Event*
push_input_event(Arena *arena, Input_List *list, Input_Event *event){ push_input_event(Arena *arena, Input_List *list, Input_Event *event){
Input_Event_Node *node = push_array(arena, Input_Event_Node, 1); Input_Event_Node *node = push_array(arena, Input_Event_Node, 1);
block_copy_struct(&node->event, event); block_copy_struct(&node->event, event);

View File

@ -12,33 +12,28 @@ typedef u32 Mouse_Code;
typedef u32 Core_Code; typedef u32 Core_Code;
#include "generated/4coder_event_codes.h" #include "generated/4coder_event_codes.h"
typedef i32 Input_Event_Kind; typedef u32 Input_Event_Kind;
enum{ enum{
InputEventKind_TextInsert, InputEventKind_TextInsert,
InputEventKind_KeyStroke, InputEventKind_KeyStroke,
InputEventKind_KeyRelease,
InputEventKind_MouseButton, InputEventKind_MouseButton,
InputEventKind_MouseButtonRelease,
InputEventKind_MouseWheel, InputEventKind_MouseWheel,
InputEventKind_MouseMove, InputEventKind_MouseMove,
InputEventKind_Core, InputEventKind_Core,
}; };
typedef i32 Key_Modifier_Index; global_const i32 Input_MaxModifierCount = 8;
enum{
MDFR_SHIFT_INDEX,
MDFR_CONTROL_INDEX,
MDFR_ALT_INDEX,
MDFR_COMMAND_INDEX,
MDFR_INDEX_BINDABLE_COUNT, struct Input_Modifier_Set{
Key_Code *mods;
MDFR_CAPS_INDEX = MDFR_INDEX_BINDABLE_COUNT, i32 count;
MDFR_HOLD_INDEX,
MDFR_INDEX_COUNT,
}; };
struct Key_Modifiers{ struct Input_Modifier_Set_Fixed{
b8 modifiers[MDFR_INDEX_COUNT]; Key_Code mods[Input_MaxModifierCount];
i32 count;
}; };
struct Input_Event{ struct Input_Event{
@ -53,23 +48,24 @@ struct Input_Event{
} text; } text;
struct{ struct{
Key_Code code; Key_Code code;
Key_Modifiers modifiers; Input_Modifier_Set modifiers;
// used internally // used internally
Input_Event *first_dependent_text; Input_Event *first_dependent_text;
} key; } key;
struct{ struct{
Mouse_Code code; Mouse_Code code;
Key_Modifiers modifiers;
Vec2_i32 p; Vec2_i32 p;
b32 release; Input_Modifier_Set modifiers;
} mouse; } mouse;
struct{ struct{
f32 value; f32 value;
Vec2_i32 p; Vec2_i32 p;
Input_Modifier_Set modifiers;
} mouse_wheel; } mouse_wheel;
struct{ struct{
Vec2_i32 p; Vec2_i32 p;
Input_Modifier_Set modifiers;
} mouse_move; } mouse_move;
struct{ struct{
Core_Code code; Core_Code code;

View File

@ -1889,8 +1889,9 @@ no_mark_snap_to_cursor(Application_Links *app, View_ID view_id){
internal void internal void
no_mark_snap_to_cursor_if_shift(Application_Links *app, View_ID view_id){ no_mark_snap_to_cursor_if_shift(Application_Links *app, View_ID view_id){
Key_Modifiers mods = system_get_keyboard_modifiers(); Scratch_Block scratch(app);
if (mods.modifiers[MDFR_SHIFT_INDEX]){ Input_Modifier_Set mods = system_get_keyboard_modifiers(scratch);
if (has_modifier(&mods, KeyCode_Shift)){
no_mark_snap_to_cursor(app, view_id); no_mark_snap_to_cursor(app, view_id);
} }
} }

View File

@ -1026,9 +1026,9 @@ fill_log_graph_command_map(Mapping *mapping){
SelectMapping(mapping); SelectMapping(mapping);
SelectMap(default_log_graph_map); SelectMap(default_log_graph_map);
Bind(log_graph__escape, KeyCode_Escape); Bind(log_graph__escape, KeyCode_Escape);
//Bind(KeyCodeExt_MouseWheel, MDFR_NONE, log_graph__scroll_wheel); BindMouseWheel(log_graph__scroll_wheel);
//Bind(KeyCodeExt_MouseLeft, MDFR_NONE, log_graph__click_jump_to_event_source); BindMouse(log_graph__click_jump_to_event_source, MouseCode_Left);
//Bind(KeyCodeExt_MouseRight, MDFR_NONE, log_graph__click_select_event); BindMouse(log_graph__click_select_event, MouseCode_Right);
Bind(log_graph__page_up, KeyCode_PageUp); Bind(log_graph__page_up, KeyCode_PageUp);
Bind(log_graph__page_down, KeyCode_PageDown); Bind(log_graph__page_down, KeyCode_PageDown);
} }

View File

@ -65,14 +65,6 @@ ENUM(u32, Child_Process_Set_Target_Flags){
ChildProcessSet_CursorAtEnd = 4, ChildProcessSet_CursorAtEnd = 4,
}; };
ENUM(u32, Key_Modifier_Flag){
MDFR_NONE = 0x0,
MDFR_CTRL = 0x1,
MDFR_ALT = 0x2,
MDFR_CMND = 0x4,
MDFR_SHIFT = 0x8,
};
ENUM(u32, Memory_Protect_Flags){ ENUM(u32, Memory_Protect_Flags){
MemProtect_Read = 0x1, MemProtect_Read = 0x1,
MemProtect_Write = 0x2, MemProtect_Write = 0x2,

View File

@ -89,7 +89,8 @@ enum{
KeyCode_COUNT = 88, KeyCode_COUNT = 88,
}; };
global char* key_code_name[KeyCode_COUNT] = { global char* key_code_name[KeyCode_COUNT] = {
"None""A", "None",
"A",
"B", "B",
"C", "C",
"D", "D",
@ -181,9 +182,23 @@ enum{
MouseCode_Left = 1, MouseCode_Left = 1,
MouseCode_Middle = 2, MouseCode_Middle = 2,
MouseCode_Right = 3, MouseCode_Right = 3,
MouseCode_COUNT = 4,
};
global char* mouse_code_name[MouseCode_COUNT] = {
"None",
"Left",
"Middle",
"Right",
}; };
enum{ enum{
CoreCode_Animate = 1, CoreCode_Animate = 1,
CoreCode_ClickActivateView = 2, CoreCode_ClickActivateView = 2,
CoreCode_ClickDeactivateView = 3, CoreCode_ClickDeactivateView = 3,
CoreCode_COUNT = 4,
};
global char* core_code_name[CoreCode_COUNT] = {
"None",
"Animate",
"ClickActivateView",
"ClickDeactivateView",
}; };

View File

@ -246,12 +246,12 @@ i32 line_number;
}; };
static Command_Metadata fcoder_metacmd_table[224] = { static Command_Metadata fcoder_metacmd_table[224] = {
{ PROC_LINKS(miblo_decrement_time_stamp_minute, 0), "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 249 }, { PROC_LINKS(miblo_decrement_time_stamp_minute, 0), "miblo_decrement_time_stamp_minute", 33, "Decrement a time stamp under the cursor by one minute. (format [m]m:ss or h:mm:ss", 81, "w:\\4ed\\code\\custom\\4coder_miblo_numbers.cpp", 43, 249 },
{ PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1956 }, { PROC_LINKS(seek_beginning_of_textual_line, 0), "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1957 },
{ PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1962 }, { PROC_LINKS(seek_end_of_textual_line, 0), "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1963 },
{ PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1968 }, { PROC_LINKS(seek_beginning_of_line, 0), "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1969 },
{ PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1974 }, { PROC_LINKS(seek_end_of_line, 0), "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1975 },
{ PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1980 }, { PROC_LINKS(goto_beginning_of_file, 0), "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1981 },
{ PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1988 }, { PROC_LINKS(goto_end_of_file, 0), "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "w:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 1989 },
{ PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 196 }, { PROC_LINKS(change_active_panel, 0), "change_active_panel", 19, "Change the currently active panel, moving to the panel with the next highest view_id.", 85, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 196 },
{ PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 206 }, { PROC_LINKS(change_active_panel_backwards, 0), "change_active_panel_backwards", 29, "Change the currently active panel, moving to the panel with the next lowest view_id.", 84, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 206 },
{ PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 216 }, { PROC_LINKS(open_panel_vsplit, 0), "open_panel_vsplit", 17, "Create a new panel by vertically splitting the active panel.", 60, "w:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 216 },

View File

@ -10,27 +10,27 @@ setup_default_mapping(Mapping *mapping){
SelectMapping(mapping); SelectMapping(mapping);
SelectMap(mapid_global); SelectMap(mapid_global);
Bind(change_active_panel, KeyCode_Comma, MDFR_CTRL); Bind(change_active_panel, KeyCode_Comma, KeyCode_Control);
Bind(change_active_panel_backwards, KeyCode_Comma, MDFR_CTRL, MDFR_SHIFT); Bind(change_active_panel_backwards, KeyCode_Comma, KeyCode_Control, KeyCode_Shift);
Bind(interactive_new, KeyCode_N, MDFR_CTRL); Bind(interactive_new, KeyCode_N, KeyCode_Control);
Bind(interactive_open_or_new, KeyCode_O, MDFR_CTRL); Bind(interactive_open_or_new, KeyCode_O, KeyCode_Control);
Bind(open_in_other, KeyCode_O, MDFR_ALT); Bind(open_in_other, KeyCode_O, KeyCode_Alt);
Bind(interactive_kill_buffer, KeyCode_K, MDFR_CTRL); Bind(interactive_kill_buffer, KeyCode_K, KeyCode_Control);
Bind(interactive_switch_buffer, KeyCode_I, MDFR_CTRL); Bind(interactive_switch_buffer, KeyCode_I, KeyCode_Control);
Bind(project_go_to_root_directory, KeyCode_H, MDFR_CTRL); Bind(project_go_to_root_directory, KeyCode_H, KeyCode_Control);
Bind(save_all_dirty_buffers, KeyCode_S, MDFR_CTRL, MDFR_SHIFT); Bind(save_all_dirty_buffers, KeyCode_S, KeyCode_Control, KeyCode_Shift);
Bind(change_to_build_panel, KeyCode_Period, MDFR_ALT); Bind(change_to_build_panel, KeyCode_Period, KeyCode_Alt);
Bind(close_build_panel, KeyCode_Comma, MDFR_ALT); Bind(close_build_panel, KeyCode_Comma, KeyCode_Alt);
Bind(goto_next_jump, KeyCode_N, MDFR_ALT); Bind(goto_next_jump, KeyCode_N, KeyCode_Alt);
Bind(goto_prev_jump, KeyCode_N, MDFR_ALT, MDFR_SHIFT); Bind(goto_prev_jump, KeyCode_N, KeyCode_Alt, KeyCode_Shift);
Bind(goto_first_jump, KeyCode_M, MDFR_ALT, MDFR_SHIFT); Bind(goto_first_jump, KeyCode_M, KeyCode_Alt, KeyCode_Shift);
Bind(build_in_build_panel, KeyCode_M, MDFR_ALT); Bind(build_in_build_panel, KeyCode_M, KeyCode_Alt);
Bind(toggle_filebar, KeyCode_B, MDFR_ALT); Bind(toggle_filebar, KeyCode_B, KeyCode_Alt);
Bind(execute_any_cli, KeyCode_Z, MDFR_ALT); Bind(execute_any_cli, KeyCode_Z, KeyCode_Alt);
Bind(execute_previous_cli, KeyCode_Z, MDFR_ALT, MDFR_SHIFT); Bind(execute_previous_cli, KeyCode_Z, KeyCode_Alt, KeyCode_Shift);
Bind(command_lister, KeyCode_X, MDFR_ALT); Bind(command_lister, KeyCode_X, KeyCode_Alt);
Bind(project_command_lister, KeyCode_X, MDFR_ALT, MDFR_SHIFT); Bind(project_command_lister, KeyCode_X, KeyCode_Alt, KeyCode_Shift);
Bind(list_all_functions_all_buffers_lister, KeyCode_I, MDFR_CTRL, MDFR_SHIFT); Bind(list_all_functions_all_buffers_lister, KeyCode_I, KeyCode_Control, KeyCode_Shift);
Bind(project_fkey_command, KeyCode_F1); Bind(project_fkey_command, KeyCode_F1);
Bind(project_fkey_command, KeyCode_F2); Bind(project_fkey_command, KeyCode_F2);
Bind(project_fkey_command, KeyCode_F3); Bind(project_fkey_command, KeyCode_F3);
@ -47,17 +47,17 @@ setup_default_mapping(Mapping *mapping){
Bind(project_fkey_command, KeyCode_F14); Bind(project_fkey_command, KeyCode_F14);
Bind(project_fkey_command, KeyCode_F15); Bind(project_fkey_command, KeyCode_F15);
Bind(project_fkey_command, KeyCode_F16); Bind(project_fkey_command, KeyCode_F16);
Bind(exit_4coder, KeyCode_F4, MDFR_ALT); Bind(exit_4coder, KeyCode_F4, KeyCode_Alt);
//Bind(KeyCodeExt_MouseWheel, mouse_wheel_scroll); BindMouseWheel(mouse_wheel_scroll);
//Bind(KeyCodeExt_MouseWheel, MDFR_CTRL, mouse_wheel_change_face_size); BindMouseWheel(mouse_wheel_change_face_size, KeyCode_Control);
SelectMap(mapid_file); SelectMap(mapid_file);
ParentMap(mapid_global); ParentMap(mapid_global);
BindTextInput(write_text_input); BindTextInput(write_text_input);
//Bind(KeyCodeExt_MouseLeft, click_set_cursor_and_mark); BindMouse(click_set_cursor_and_mark, MouseCode_Left);
//Bind(KeyCodeExt_ClickActivateView, click_set_cursor_and_mark); BindMouseRelease(click_set_cursor, MouseCode_Left);
//Bind(KeyCodeExt_MouseLeftRelease, click_set_cursor); BindCore(click_set_cursor_and_mark, CoreCode_ClickActivateView);
//Bind(KeyCodeExt_MouseMove, click_set_cursor_if_lbutton); BindMouseMove(click_set_cursor_if_lbutton);
Bind(delete_char, KeyCode_Delete); Bind(delete_char, KeyCode_Delete);
Bind(backspace_char, KeyCode_Backspace); Bind(backspace_char, KeyCode_Backspace);
Bind(move_up, KeyCode_Up); Bind(move_up, KeyCode_Up);
@ -68,82 +68,82 @@ setup_default_mapping(Mapping *mapping){
Bind(seek_beginning_of_line, KeyCode_Home); Bind(seek_beginning_of_line, KeyCode_Home);
Bind(page_up, KeyCode_PageUp); Bind(page_up, KeyCode_PageUp);
Bind(page_down, KeyCode_PageDown); Bind(page_down, KeyCode_PageDown);
Bind(goto_beginning_of_file, KeyCode_PageUp, MDFR_CTRL); Bind(goto_beginning_of_file, KeyCode_PageUp, KeyCode_Control);
Bind(goto_end_of_file, KeyCode_PageDown, MDFR_CTRL); Bind(goto_end_of_file, KeyCode_PageDown, KeyCode_Control);
Bind(move_up_to_blank_line_skip_whitespace, KeyCode_Up, MDFR_CTRL); Bind(move_up_to_blank_line_skip_whitespace, KeyCode_Up, KeyCode_Control);
Bind(move_down_to_blank_line_end, KeyCode_Down, MDFR_CTRL); Bind(move_down_to_blank_line_end, KeyCode_Down, KeyCode_Control);
Bind(move_left_whitespace_boundary, KeyCode_Left, MDFR_CTRL); Bind(move_left_whitespace_boundary, KeyCode_Left, KeyCode_Control);
Bind(move_right_whitespace_boundary, KeyCode_Right, MDFR_CTRL); Bind(move_right_whitespace_boundary, KeyCode_Right, KeyCode_Control);
Bind(move_line_up, KeyCode_Up, MDFR_ALT); Bind(move_line_up, KeyCode_Up, KeyCode_Alt);
Bind(move_line_down, KeyCode_Down, MDFR_ALT); Bind(move_line_down, KeyCode_Down, KeyCode_Alt);
Bind(backspace_alpha_numeric_boundary, KeyCode_Backspace, MDFR_CTRL); Bind(backspace_alpha_numeric_boundary, KeyCode_Backspace, KeyCode_Control);
Bind(delete_alpha_numeric_boundary, KeyCode_Delete, MDFR_CTRL); Bind(delete_alpha_numeric_boundary, KeyCode_Delete, KeyCode_Control);
Bind(snipe_backward_whitespace_or_token_boundary, KeyCode_Backspace, MDFR_ALT); Bind(snipe_backward_whitespace_or_token_boundary, KeyCode_Backspace, KeyCode_Alt);
Bind(snipe_forward_whitespace_or_token_boundary, KeyCode_Delete, MDFR_ALT); Bind(snipe_forward_whitespace_or_token_boundary, KeyCode_Delete, KeyCode_Alt);
Bind(set_mark, KeyCode_Space, MDFR_CTRL); Bind(set_mark, KeyCode_Space, KeyCode_Control);
Bind(replace_in_range, KeyCode_A, MDFR_CTRL); Bind(replace_in_range, KeyCode_A, KeyCode_Control);
Bind(copy, KeyCode_C, MDFR_CTRL); Bind(copy, KeyCode_C, KeyCode_Control);
Bind(delete_range, KeyCode_D, MDFR_CTRL); Bind(delete_range, KeyCode_D, KeyCode_Control);
Bind(delete_line, KeyCode_D, MDFR_CTRL, MDFR_SHIFT); Bind(delete_line, KeyCode_D, KeyCode_Control, KeyCode_Shift);
Bind(center_view, KeyCode_E, MDFR_CTRL); Bind(center_view, KeyCode_E, KeyCode_Control);
Bind(left_adjust_view, KeyCode_E, MDFR_CTRL, MDFR_SHIFT); Bind(left_adjust_view, KeyCode_E, KeyCode_Control, KeyCode_Shift);
Bind(search, KeyCode_F, MDFR_CTRL); Bind(search, KeyCode_F, KeyCode_Control);
Bind(list_all_locations, KeyCode_F, MDFR_CTRL, MDFR_SHIFT); Bind(list_all_locations, KeyCode_F, KeyCode_Control, KeyCode_Shift);
Bind(list_all_substring_locations_case_insensitive, KeyCode_F, MDFR_ALT); Bind(list_all_substring_locations_case_insensitive, KeyCode_F, KeyCode_Alt);
Bind(goto_line, KeyCode_G, MDFR_CTRL); Bind(goto_line, KeyCode_G, KeyCode_Control);
Bind(list_all_locations_of_selection, KeyCode_G, MDFR_CTRL, MDFR_SHIFT); Bind(list_all_locations_of_selection, KeyCode_G, KeyCode_Control, KeyCode_Shift);
Bind(snippet_lister, KeyCode_J, MDFR_CTRL); Bind(snippet_lister, KeyCode_J, KeyCode_Control);
Bind(kill_buffer, KeyCode_K, MDFR_CTRL, MDFR_SHIFT); Bind(kill_buffer, KeyCode_K, KeyCode_Control, KeyCode_Shift);
Bind(duplicate_line, KeyCode_L, MDFR_CTRL); Bind(duplicate_line, KeyCode_L, KeyCode_Control);
Bind(cursor_mark_swap, KeyCode_M, MDFR_CTRL); Bind(cursor_mark_swap, KeyCode_M, KeyCode_Control);
Bind(reopen, KeyCode_O, MDFR_CTRL, MDFR_SHIFT); Bind(reopen, KeyCode_O, KeyCode_Control, KeyCode_Shift);
Bind(query_replace, KeyCode_Q, MDFR_CTRL); Bind(query_replace, KeyCode_Q, KeyCode_Control);
Bind(query_replace_identifier, KeyCode_Q, MDFR_CTRL, MDFR_SHIFT); Bind(query_replace_identifier, KeyCode_Q, KeyCode_Control, KeyCode_Shift);
Bind(query_replace_selection, KeyCode_Q, MDFR_ALT); Bind(query_replace_selection, KeyCode_Q, KeyCode_Alt);
Bind(reverse_search, KeyCode_R, MDFR_CTRL); Bind(reverse_search, KeyCode_R, KeyCode_Control);
Bind(save, KeyCode_S, MDFR_CTRL); Bind(save, KeyCode_S, KeyCode_Control);
Bind(search_identifier, KeyCode_T, MDFR_CTRL); Bind(search_identifier, KeyCode_T, KeyCode_Control);
Bind(list_all_locations_of_identifier, KeyCode_T, MDFR_CTRL, MDFR_SHIFT); Bind(list_all_locations_of_identifier, KeyCode_T, KeyCode_Control, KeyCode_Shift);
Bind(paste_and_indent, KeyCode_V, MDFR_CTRL); Bind(paste_and_indent, KeyCode_V, KeyCode_Control);
Bind(paste_next_and_indent, KeyCode_V, MDFR_CTRL, MDFR_SHIFT); Bind(paste_next_and_indent, KeyCode_V, KeyCode_Control, KeyCode_Shift);
Bind(cut, KeyCode_X, MDFR_CTRL); Bind(cut, KeyCode_X, KeyCode_Control);
Bind(redo, KeyCode_Y, MDFR_CTRL); Bind(redo, KeyCode_Y, KeyCode_Control);
Bind(undo, KeyCode_Z, MDFR_CTRL); Bind(undo, KeyCode_Z, KeyCode_Control);
Bind(view_buffer_other_panel, KeyCode_1, MDFR_CTRL); Bind(view_buffer_other_panel, KeyCode_1, KeyCode_Control);
Bind(swap_buffers_between_panels, KeyCode_2, MDFR_CTRL); Bind(swap_buffers_between_panels, KeyCode_2, KeyCode_Control);
Bind(if_read_only_goto_position, KeyCode_Return); Bind(if_read_only_goto_position, KeyCode_Return);
Bind(if_read_only_goto_position_same_panel, KeyCode_Return, MDFR_SHIFT); Bind(if_read_only_goto_position_same_panel, KeyCode_Return, KeyCode_Shift);
Bind(view_jump_list_with_lister, KeyCode_Period, MDFR_CTRL, MDFR_SHIFT); Bind(view_jump_list_with_lister, KeyCode_Period, KeyCode_Control, KeyCode_Shift);
SelectMap(default_code_map); SelectMap(default_code_map);
ParentMap(mapid_file); ParentMap(mapid_file);
BindTextInput(write_text_and_auto_indent); BindTextInput(write_text_and_auto_indent);
Bind(move_left_alpha_numeric_boundary, KeyCode_Left, MDFR_CTRL); Bind(move_left_alpha_numeric_boundary, KeyCode_Left, KeyCode_Control);
Bind(move_right_alpha_numeric_boundary, KeyCode_Right, MDFR_CTRL); Bind(move_right_alpha_numeric_boundary, KeyCode_Right, KeyCode_Control);
Bind(move_left_alpha_numeric_or_camel_boundary, KeyCode_Left, MDFR_ALT); Bind(move_left_alpha_numeric_or_camel_boundary, KeyCode_Left, KeyCode_Alt);
Bind(move_right_alpha_numeric_or_camel_boundary, KeyCode_Right, MDFR_ALT); Bind(move_right_alpha_numeric_or_camel_boundary, KeyCode_Right, KeyCode_Alt);
Bind(comment_line_toggle, KeyCode_Semicolon, MDFR_CTRL); Bind(comment_line_toggle, KeyCode_Semicolon, KeyCode_Control);
Bind(word_complete, KeyCode_Tab); Bind(word_complete, KeyCode_Tab);
Bind(auto_indent_range, KeyCode_Tab, MDFR_CTRL); Bind(auto_indent_range, KeyCode_Tab, KeyCode_Control);
Bind(auto_indent_line_at_cursor, KeyCode_Tab, MDFR_SHIFT); Bind(auto_indent_line_at_cursor, KeyCode_Tab, KeyCode_Shift);
Bind(write_block, KeyCode_R, MDFR_ALT); Bind(write_block, KeyCode_R, KeyCode_Alt);
Bind(write_todo, KeyCode_T, MDFR_ALT); Bind(write_todo, KeyCode_T, KeyCode_Alt);
Bind(write_note, KeyCode_Y, MDFR_ALT); Bind(write_note, KeyCode_Y, KeyCode_Alt);
Bind(list_all_locations_of_type_definition, KeyCode_D, MDFR_ALT); Bind(list_all_locations_of_type_definition, KeyCode_D, KeyCode_Alt);
Bind(list_all_locations_of_type_definition_of_identifier, KeyCode_T, MDFR_ALT); Bind(list_all_locations_of_type_definition_of_identifier, KeyCode_T, KeyCode_Alt);
Bind(open_long_braces, KeyCode_LeftBracket, MDFR_CTRL); Bind(open_long_braces, KeyCode_LeftBracket, KeyCode_Control);
Bind(open_long_braces_semicolon, KeyCode_LeftBracket, MDFR_CTRL, MDFR_SHIFT); Bind(open_long_braces_semicolon, KeyCode_LeftBracket, KeyCode_Control, KeyCode_Shift);
Bind(open_long_braces_break, KeyCode_RightBracket, MDFR_CTRL, MDFR_SHIFT); Bind(open_long_braces_break, KeyCode_RightBracket, KeyCode_Control, KeyCode_Shift);
Bind(select_surrounding_scope, KeyCode_LeftBracket, MDFR_ALT); Bind(select_surrounding_scope, KeyCode_LeftBracket, KeyCode_Alt);
Bind(select_prev_scope_absolute, KeyCode_RightBracket, MDFR_ALT); Bind(select_prev_scope_absolute, KeyCode_RightBracket, KeyCode_Alt);
Bind(select_next_scope_absolute, KeyCode_Quote, MDFR_ALT); Bind(select_next_scope_absolute, KeyCode_Quote, KeyCode_Alt);
Bind(select_next_scope_after_current, KeyCode_Quote, MDFR_ALT, MDFR_SHIFT); Bind(select_next_scope_after_current, KeyCode_Quote, KeyCode_Alt, KeyCode_Shift);
Bind(place_in_scope, KeyCode_ForwardSlash, MDFR_ALT); Bind(place_in_scope, KeyCode_ForwardSlash, KeyCode_Alt);
Bind(delete_current_scope, KeyCode_Minus, MDFR_ALT); Bind(delete_current_scope, KeyCode_Minus, KeyCode_Alt);
Bind(if0_off, KeyCode_I, MDFR_ALT); Bind(if0_off, KeyCode_I, KeyCode_Alt);
Bind(open_file_in_quotes, KeyCode_1, MDFR_ALT); Bind(open_file_in_quotes, KeyCode_1, KeyCode_Alt);
Bind(open_matching_file_cpp, KeyCode_2, MDFR_ALT); Bind(open_matching_file_cpp, KeyCode_2, KeyCode_Alt);
Bind(write_zero_struct, KeyCode_0, MDFR_CTRL); Bind(write_zero_struct, KeyCode_0, KeyCode_Control);
SelectMap(default_lister_ui_map); SelectMap(default_lister_ui_map);
ParentMap(mapid_global); ParentMap(mapid_global);
@ -154,11 +154,11 @@ setup_default_mapping(Mapping *mapping){
Bind(lister__backspace_text_field, KeyCode_Backspace); Bind(lister__backspace_text_field, KeyCode_Backspace);
Bind(lister__move_up, KeyCode_Up); Bind(lister__move_up, KeyCode_Up);
Bind(lister__move_down, KeyCode_Down); Bind(lister__move_down, KeyCode_Down);
//Bind(KeyCodeExt_MouseWheel, MDFR_NONE, lister__wheel_scroll); BindMouseWheel(lister__wheel_scroll);
//Bind(KeyCodeExt_MouseLeft, MDFR_NONE, lister__mouse_press); BindMouse(lister__mouse_press, MouseCode_Left);
//Bind(KeyCodeExt_MouseLeftRelease, MDFR_NONE, lister__mouse_release); BindMouseRelease(lister__mouse_release, MouseCode_Left);
//Bind(KeyCodeExt_MouseMove, MDFR_NONE, lister__repaint); BindMouseMove(lister__repaint);
//Bind(KeyCodeExt_Animate, MDFR_NONE, lister__repaint); BindCore(lister__repaint, CoreCode_Animate);
} }
#endif #endif

View File

@ -41,7 +41,7 @@
#define system_show_mouse_cursor_sig() void system_show_mouse_cursor(i32 show) #define system_show_mouse_cursor_sig() void system_show_mouse_cursor(i32 show)
#define system_set_fullscreen_sig() b32 system_set_fullscreen(b32 full_screen) #define system_set_fullscreen_sig() b32 system_set_fullscreen(b32 full_screen)
#define system_is_fullscreen_sig() b32 system_is_fullscreen(void) #define system_is_fullscreen_sig() b32 system_is_fullscreen(void)
#define system_get_keyboard_modifiers_sig() Key_Modifiers system_get_keyboard_modifiers(void) #define system_get_keyboard_modifiers_sig() Input_Modifier_Set system_get_keyboard_modifiers(Arena* arena)
typedef String_Const_u8 system_get_path_type(Arena* arena, System_Path_Code path_code); typedef String_Const_u8 system_get_path_type(Arena* arena, System_Path_Code path_code);
typedef String_Const_u8 system_get_canonical_type(Arena* arena, String_Const_u8 name); typedef String_Const_u8 system_get_canonical_type(Arena* arena, String_Const_u8 name);
typedef File_List system_get_file_list_type(Arena* arena, String_Const_u8 directory); typedef File_List system_get_file_list_type(Arena* arena, String_Const_u8 directory);
@ -85,7 +85,7 @@ typedef void system_memory_free_type(void* ptr, umem size);
typedef void system_show_mouse_cursor_type(i32 show); typedef void system_show_mouse_cursor_type(i32 show);
typedef b32 system_set_fullscreen_type(b32 full_screen); typedef b32 system_set_fullscreen_type(b32 full_screen);
typedef b32 system_is_fullscreen_type(void); typedef b32 system_is_fullscreen_type(void);
typedef Key_Modifiers system_get_keyboard_modifiers_type(void); typedef Input_Modifier_Set system_get_keyboard_modifiers_type(Arena* arena);
struct API_VTable_system{ struct API_VTable_system{
system_get_path_type *get_path; system_get_path_type *get_path;
system_get_canonical_type *get_canonical; system_get_canonical_type *get_canonical;
@ -176,7 +176,7 @@ internal void system_memory_free(void* ptr, umem size);
internal void system_show_mouse_cursor(i32 show); internal void system_show_mouse_cursor(i32 show);
internal b32 system_set_fullscreen(b32 full_screen); internal b32 system_set_fullscreen(b32 full_screen);
internal b32 system_is_fullscreen(void); internal b32 system_is_fullscreen(void);
internal Key_Modifiers system_get_keyboard_modifiers(void); internal Input_Modifier_Set system_get_keyboard_modifiers(Arena* arena);
#undef STATIC_LINK_API #undef STATIC_LINK_API
#elif defined(DYNAMIC_LINK_API) #elif defined(DYNAMIC_LINK_API)
global system_get_path_type *system_get_path = 0; global system_get_path_type *system_get_path = 0;

View File

@ -41,4 +41,4 @@ api(system) function void memory_free(void* ptr, umem size);
api(system) function void show_mouse_cursor(i32 show); api(system) function void show_mouse_cursor(i32 show);
api(system) function b32 set_fullscreen(b32 full_screen); api(system) function b32 set_fullscreen(b32 full_screen);
api(system) function b32 is_fullscreen(void); api(system) function b32 is_fullscreen(void);
api(system) function Key_Modifiers get_keyboard_modifiers(void); api(system) function Input_Modifier_Set get_keyboard_modifiers(Arena* arena);

View File

@ -92,9 +92,9 @@ struct Win32_Input_Chunk_Transient{
struct Win32_Input_Chunk_Persistent{ struct Win32_Input_Chunk_Persistent{
Vec2_i32 mouse; Vec2_i32 mouse;
Control_Keys controls; Control_Keys controls;
Input_Modifier_Set_Fixed modifiers;
b8 mouse_l; b8 mouse_l;
b8 mouse_r; b8 mouse_r;
b8 control_keys[MDFR_INDEX_COUNT];
}; };
struct Win32_Input_Chunk{ struct Win32_Input_Chunk{
@ -343,9 +343,7 @@ system_is_fullscreen_sig(){
internal internal
system_get_keyboard_modifiers_sig(){ system_get_keyboard_modifiers_sig(){
Key_Modifiers result = {}; return(copy_modifier_set(arena, &win32vars.input_chunk.pers.modifiers));
block_copy_array(result.modifiers, win32vars.input_chunk.pers.control_keys);
return(result);
} }
// //
@ -951,19 +949,19 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
b8 down = !release; b8 down = !release;
b8 is_right = HasFlag(lParam, bit_25); b8 is_right = HasFlag(lParam, bit_25);
Input_Modifier_Set_Fixed *mods = &win32vars.input_chunk.pers.modifiers;
switch (wParam){ switch (wParam){
case VK_CONTROL:case VK_LCONTROL:case VK_RCONTROL: case VK_CONTROL:case VK_LCONTROL:case VK_RCONTROL:
case VK_MENU:case VK_LMENU:case VK_RMENU: case VK_MENU:case VK_LMENU:case VK_RMENU:
case VK_SHIFT:case VK_LSHIFT:case VK_RSHIFT: case VK_SHIFT:case VK_LSHIFT:case VK_RSHIFT:
{ {
Control_Keys *controls = &win32vars.input_chunk.pers.controls; Control_Keys *controls = &win32vars.input_chunk.pers.controls;
b8 *control_keys = win32vars.input_chunk.pers.control_keys;
if (wParam != 255){ if (wParam != 255){
switch (wParam){ switch (wParam){
case VK_SHIFT: case VK_SHIFT:
{ {
control_keys[MDFR_SHIFT_INDEX] = down; set_modifier(mods, KeyCode_Shift, down);
}break; }break;
case VK_CONTROL: case VK_CONTROL:
{ {
@ -991,20 +989,21 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
ctrl = false; ctrl = false;
alt = false; alt = false;
} }
control_keys[MDFR_CONTROL_INDEX] = ctrl; set_modifier(mods, KeyCode_Control, ctrl);
control_keys[MDFR_ALT_INDEX] = alt; set_modifier(mods, KeyCode_Alt, alt);
} }
}break; }break;
} }
Key_Code key = keycode_lookup_table[(u8)wParam];
if (down){ if (down){
Key_Code key = keycode_lookup_table[(u8)wParam];
if (key != 0){ if (key != 0){
Key_Modifiers modifiers = system_get_keyboard_modifiers(); add_modifier(mods, key);
Input_Event *event = push_input_event(win32vars.frame_arena, &win32vars.input_chunk.trans.event_list); Input_Event *event = push_input_event(win32vars.frame_arena, &win32vars.input_chunk.trans.event_list);
event->kind = InputEventKind_KeyStroke; event->kind = InputEventKind_KeyStroke;
event->key.code = key; event->key.code = key;
block_copy_struct(&event->key.modifiers, &modifiers); event->key.modifiers = copy_modifier_set(win32vars.frame_arena, mods);
win32vars.active_key_stroke = event; win32vars.active_key_stroke = event;
win32vars.got_useful_event = true; win32vars.got_useful_event = true;
@ -1013,8 +1012,16 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
else{ else{
win32vars.active_key_stroke = 0; win32vars.active_key_stroke = 0;
win32vars.active_text_input = 0; win32vars.active_text_input = 0;
win32vars.got_useful_event = true; win32vars.got_useful_event = true;
if (key != 0){
Input_Event *event = push_input_event(win32vars.frame_arena, &win32vars.input_chunk.trans.event_list);
event->kind = InputEventKind_KeyRelease;
event->key.code = key;
event->key.modifiers = copy_modifier_set(win32vars.frame_arena, mods);
remove_modifier(mods, key);
}
} }
}break; }break;
@ -1121,10 +1128,8 @@ win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
win32vars.got_useful_event = true; win32vars.got_useful_event = true;
win32vars.input_chunk.pers.mouse_l = false; win32vars.input_chunk.pers.mouse_l = false;
win32vars.input_chunk.pers.mouse_r = false; win32vars.input_chunk.pers.mouse_r = false;
for (i32 i = 0; i < MDFR_INDEX_COUNT; ++i){
win32vars.input_chunk.pers.control_keys[i] = false;
}
block_zero_struct(&win32vars.input_chunk.pers.controls); block_zero_struct(&win32vars.input_chunk.pers.controls);
block_zero_struct(&win32vars.input_chunk.pers.modifiers);
win32vars.active_key_stroke = 0; win32vars.active_key_stroke = 0;
win32vars.active_text_input = 0; win32vars.active_text_input = 0;
}break; }break;
@ -1791,8 +1796,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// TODO(allen): CROSS REFERENCE WITH LINUX SPECIAL CODE "TIC898989" // TODO(allen): CROSS REFERENCE WITH LINUX SPECIAL CODE "TIC898989"
Win32_Input_Chunk input_chunk = win32vars.input_chunk; Win32_Input_Chunk input_chunk = win32vars.input_chunk;
input_chunk.pers.control_keys[MDFR_CAPS_INDEX] = GetKeyState(VK_CAPITAL) & 0x1;
Application_Step_Input input = {}; Application_Step_Input input = {};
input.first_step = win32vars.first; input.first_step = win32vars.first;