From 7aa46e8c48fda646705a4f5cb762f1d1e4f4987d Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 7 Nov 2017 23:41:45 -0500 Subject: [PATCH] Mac: more key codes, cursor hiding/setting, fullscreen toggling --- 4coder_default_hooks.cpp | 10 ++- 4ed.h | 11 +--- 4ed_cursor_codes.h | 28 ++++++++ platform_mac/mac_4ed.cpp | 58 +++++++++++----- platform_mac/mac_4ed.m | 73 ++++++++++++++++----- platform_mac/osx_objective_c_to_cpp_links.h | 9 +++ 6 files changed, 145 insertions(+), 44 deletions(-) create mode 100644 4ed_cursor_codes.h diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index 0f186f6c..dd4702c6 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -120,7 +120,15 @@ OPEN_FILE_HOOK_SIG(default_file_settings){ parse_context_id = parse_context_language_rust; } - if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc") || match(ext, "glsl") || match(ext, "m")){ + if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc")){ + if (parse_context_language_cpp == 0){ + init_language_cpp(app); + } + parse_context_id = parse_context_language_cpp; + } + + // TODO(NAME): Real GLSL highlighting + if (match(ext, "glsl")){ if (parse_context_language_cpp == 0){ init_language_cpp(app); } diff --git a/4ed.h b/4ed.h index f1841801..952ce91f 100644 --- a/4ed.h +++ b/4ed.h @@ -86,16 +86,7 @@ void name(System_Functions *system, Render_Target *target, Application_Memory *m typedef App_Init_Sig(App_Init); - -enum Application_Mouse_Cursor{ - APP_MOUSE_CURSOR_DEFAULT, - APP_MOUSE_CURSOR_ARROW, - APP_MOUSE_CURSOR_IBEAM, - APP_MOUSE_CURSOR_LEFTRIGHT, - APP_MOUSE_CURSOR_UPDOWN, - // never below this - APP_MOUSE_CURSOR_COUNT -}; +#include "4ed_cursor_codes.h" struct Application_Step_Result{ Application_Mouse_Cursor mouse_cursor_type; diff --git a/4ed_cursor_codes.h b/4ed_cursor_codes.h new file mode 100644 index 00000000..7f9f2024 --- /dev/null +++ b/4ed_cursor_codes.h @@ -0,0 +1,28 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 07.11.2017 + * + * Application Cursor Codes + * + */ + +// TOP + +#if !defined(FRED_CURSOR_CODES_H) +#define FRED_CURSOR_CODES_H + +typedef enum Application_Mouse_Cursor{ + APP_MOUSE_CURSOR_DEFAULT, + APP_MOUSE_CURSOR_ARROW, + APP_MOUSE_CURSOR_IBEAM, + APP_MOUSE_CURSOR_LEFTRIGHT, + APP_MOUSE_CURSOR_UPDOWN, + // never below this + APP_MOUSE_CURSOR_COUNT +} Application_Mouse_Cursor; + +#endif + +// BOTTOM + diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index 9aa11869..6986ed9c 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -144,7 +144,17 @@ system_schedule_step(void){ internal Sys_Show_Mouse_Cursor_Sig(system_show_mouse_cursor){ - // TODO(allen) + switch (show){ + case MouseCursorShow_Never: + { + osx_show_cursor(-1, 0); + }break; + + case MouseCursorShow_Always: + { + osx_show_cursor(1, 0); + }break; + } } internal @@ -290,9 +300,6 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){ cli->exit = WEXITSTATUS(status); - //struct epoll_event e = {}; - //epoll_ctl(linuxvars.epoll, EPOLL_CTL_DEL, *(int*)&cli->out_read, &e); - close(*(int*)&cli->out_read); close(*(int*)&cli->out_write); @@ -368,6 +375,11 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){ case 0xF701: c = key_down; break; case 0xF702: c = key_left; break; case 0xF703: c = key_right; break; + case 0xF728: c = key_del; break; + case 0xF729: c = key_home; break; + case 0xF72B: c = key_end; break; + case 0xF72C: c = key_page_up; break; + case 0xF72D: c = key_page_down; break; case 0x001B: c = key_esc; break; case 0xF704: c = key_f1; break; @@ -403,20 +415,25 @@ osx_character_input(u32 code, OSX_Keyboard_Modifiers modifier_flags){ osx_push_key(c, 0, 0, mods); } else if (code != 0){ - if (code == '\r'){ - code = '\n'; - } - Key_Code chr = code; - Key_Code nocaps = code; - if (modifier_flags.caps){ - if ('a' <= chr && chr <= 'z'){ - chr += 'A' - 'a'; + if (code < 0xE000 || code > 0xF8FF){ + if (code == '\r'){ + code = '\n'; } - else if ('A' <= chr && chr <= 'Z'){ - chr += 'a' - 'A'; + Key_Code chr = code; + Key_Code nocaps = code; + if (modifier_flags.caps){ + if ('a' <= chr && chr <= 'z'){ + chr += 'A' - 'a'; + } + else if ('A' <= chr && chr <= 'Z'){ + chr += 'a' - 'A'; + } } + osx_push_key(code, chr, nocaps, mods); + } + else{ + fprintf(stdout, "unhandled private code %x\n", code); } - osx_push_key(code, chr, nocaps, mods); } else{ osx_push_key(0, 0, 0, mods); @@ -429,7 +446,7 @@ external void osx_mouse(i32 mx, i32 my, u32 type){ i32 new_x = mx; i32 new_y = osx_objc.height - my; - if (new_x != osxvars.input.mouse.x && new_y != osxvars.input.mouse.y){ + if (new_x != osxvars.input.mouse.x || new_y != osxvars.input.mouse.y){ osxvars.input.mouse.x = new_x; osxvars.input.mouse.y = new_y; osx_schedule_step(); @@ -501,6 +518,9 @@ osx_step(void){ osxvars.input.mouse.release_r = false; osxvars.input.mouse.wheel = 0; + osx_objc.do_toggle = false; + osx_objc.full_screen = osx_is_fullscreen(); + // HACK(allen): THIS SHIT IS FUCKED (happens on linux too) b32 keep_running = osxvars.keep_running; @@ -513,6 +533,12 @@ osx_step(void){ osxvars.keep_running = true; } + if (osx_objc.do_toggle){ + osx_toggle_fullscreen(); + } + + osx_show_cursor(0, result.mouse_cursor_type); + launch_rendering(&sysfunc, &target); if (result.animating || cli_count > 0){ diff --git a/platform_mac/mac_4ed.m b/platform_mac/mac_4ed.m index ce339f43..815747cd 100644 --- a/platform_mac/mac_4ed.m +++ b/platform_mac/mac_4ed.m @@ -15,6 +15,8 @@ #include "4coder_API/version.h" #include "4coder_API/keycodes.h" +#include "4ed_cursor_codes.h" + #define WINDOW_NAME "4coder " VERSION #undef internal @@ -256,27 +258,11 @@ static DISPLINK_SIG(osx_display_link); GLint swapInt = 1; [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; - -#if 0 - CVReturn cvreturn = CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); - cvreturn = CVDisplayLinkSetOutputCallback(displayLink, &osx_display_link, (__bridge void*)(self)); - - CGLContextObj cglContext = [[self openGLContext] CGLContextObj]; - CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj]; - cvreturn = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat); - - CVDisplayLinkStart(displayLink); -#endif } - (void)dealloc { [super dealloc]; - -#if 0 - CVDisplayLinkStop(displayLink); - CVDisplayLinkRelease(displayLink); -#endif } - (BOOL)acceptsFirstResponder @@ -605,7 +591,49 @@ osx_get_file_change_event(char *buffer, i32 max, i32 *size){ return(result); } +void +osx_show_cursor(i32 show, i32 cursor_type){ + local_persist b32 cursor_is_shown = 1; + if (show == 1){ + if (!cursor_is_shown){ + [NSCursor unhide]; + cursor_is_shown = true; + } + } + else if (show == -1){ + if (cursor_is_shown){ + [NSCursor hide]; + cursor_is_shown = false; + } + } + + if (cursor_type > 0){ + switch (cursor_type){ + case APP_MOUSE_CURSOR_ARROW: + { + [[NSCursor arrowCursor] set]; + }break; + + case APP_MOUSE_CURSOR_IBEAM: + { + [[NSCursor IBeamCursor] set]; + }break; + + case APP_MOUSE_CURSOR_LEFTRIGHT: + { + [[NSCursor resizeLeftRightCursor] set]; + }break; + + case APP_MOUSE_CURSOR_UPDOWN: + { + [[NSCursor resizeUpDownCursor] set]; + }break; + } + } +} + My4coderView* view = 0; +NSWindow* window = 0; void osx_schedule_step(void){ @@ -620,6 +648,17 @@ osx_schedule_step(void){ #endif } +void +osx_toggle_fullscreen(void){ + [window toggleFullScreen:nil]; +} + +b32 +osx_is_fullscreen(void){ + b32 result = (([window styleMask] & NSFullScreenWindowMask) != 0); + return(result); +} + void osx_close_app(void){ [NSApp terminate: nil]; @@ -648,7 +687,7 @@ main(int argc, char **argv){ NSRect frame = NSMakeRect((screenRect.size.width - w) * 0.5, (screenRect.size.height - h) * 0.5, w, h); u32 flags = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; - NSWindow* window = [[NSWindow alloc] initWithContentRect:frame styleMask:flags backing:NSBackingStoreBuffered defer:NO]; + window = [[NSWindow alloc] initWithContentRect:frame styleMask:flags backing:NSBackingStoreBuffered defer:NO]; [window setAcceptsMouseMovedEvents:YES]; diff --git a/platform_mac/osx_objective_c_to_cpp_links.h b/platform_mac/osx_objective_c_to_cpp_links.h index e8ad9461..3c5c1274 100644 --- a/platform_mac/osx_objective_c_to_cpp_links.h +++ b/platform_mac/osx_objective_c_to_cpp_links.h @@ -102,9 +102,18 @@ osx_remove_file_listener(char *file_name); external i32 osx_get_file_change_event(char *buffer, i32 max, i32 *size); +external void +osx_show_cursor(i32 show_inc, i32 cursor_type); + external void osx_schedule_step(void); +external void +osx_toggle_fullscreen(void); + +external b32 +osx_is_fullscreen(void); + external void osx_close_app(void);