Posting to clipboard now works.
This commit is contained in:
parent
7d2a91805b
commit
f7b0b05426
|
@ -193,6 +193,9 @@ struct Mac_Vars {
|
||||||
u32 clipboard_change_count;
|
u32 clipboard_change_count;
|
||||||
b32 next_clipboard_is_self;
|
b32 next_clipboard_is_self;
|
||||||
|
|
||||||
|
Arena clip_post_arena;
|
||||||
|
String_Const_u8 clip_post;
|
||||||
|
|
||||||
NSWindow *window;
|
NSWindow *window;
|
||||||
FCoder_View *view;
|
FCoder_View *view;
|
||||||
f32 screen_scale_factor;
|
f32 screen_scale_factor;
|
||||||
|
@ -480,8 +483,8 @@ mac_read_clipboard_contents(Arena *scratch){
|
||||||
{
|
{
|
||||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||||
NSString *utf8_type = @"public.utf8-plain-text";
|
NSString *utf8_type = @"public.utf8-plain-text";
|
||||||
NSArray *array = [NSArray arrayWithObjects:utf8_type, nil];
|
NSArray *types_array = [NSArray arrayWithObjects:utf8_type, nil];
|
||||||
NSString *has_string = [board availableTypeFromArray:array];
|
NSString *has_string = [board availableTypeFromArray:types_array];
|
||||||
if (has_string != nil){
|
if (has_string != nil){
|
||||||
NSData *data = [board dataForType:utf8_type];
|
NSData *data = [board dataForType:utf8_type];
|
||||||
if (data != nil){
|
if (data != nil){
|
||||||
|
@ -504,6 +507,25 @@ mac_read_clipboard_contents(Arena *scratch){
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function void
|
||||||
|
mac_post_clipboard(Arena *scratch, char *text, i32 len){
|
||||||
|
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||||
|
|
||||||
|
NSString *utf8_type = @"public.utf8-plain-text";
|
||||||
|
NSArray<NSString*> *types_array = [NSArray arrayWithObjects:utf8_type, nil];
|
||||||
|
[board declareTypes:types_array
|
||||||
|
owner:nil];
|
||||||
|
|
||||||
|
NSString *paste_string = [[NSString alloc] initWithBytes:text
|
||||||
|
length:len
|
||||||
|
encoding:NSUTF8StringEncoding];
|
||||||
|
[board setString:paste_string
|
||||||
|
forType:utf8_type];
|
||||||
|
[paste_string release];
|
||||||
|
|
||||||
|
mac_vars.next_clipboard_is_self = true;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(FRED_INTERNAL)
|
#if defined(FRED_INTERNAL)
|
||||||
function inline void
|
function inline void
|
||||||
mac_profile(char *name, u64 begin, u64 end){
|
mac_profile(char *name, u64 begin, u64 end){
|
||||||
|
@ -659,6 +681,8 @@ i = 1, mac_profile(name, begin, system_now_time()))
|
||||||
input.clipboard = mac_vars.clipboard_contents;
|
input.clipboard = mac_vars.clipboard_contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mac_vars.clip_post.size = 0;
|
||||||
|
|
||||||
Application_Step_Result result = {};
|
Application_Step_Result result = {};
|
||||||
MacProfileScope("Step"){
|
MacProfileScope("Step"){
|
||||||
// NOTE(yuval): Application Core Update
|
// NOTE(yuval): Application Core Update
|
||||||
|
@ -675,6 +699,14 @@ i = 1, mac_profile(name, begin, system_now_time()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE(yuval): Post new clipboard content
|
||||||
|
MacProfileScope("Post Clipboard"){
|
||||||
|
if (mac_vars.clip_post.size > 0){
|
||||||
|
Scratch_Block scratch(mac_vars.tctx, Scratch_Share);
|
||||||
|
mac_post_clipboard(scratch, (char*)mac_vars.clip_post.str, (i32)mac_vars.clip_post.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MacProfileScope("Render"){
|
MacProfileScope("Render"){
|
||||||
// NOTE(yuval): Render
|
// NOTE(yuval): Render
|
||||||
renderer->render(renderer, &target);
|
renderer->render(renderer, &target);
|
||||||
|
|
|
@ -431,7 +431,21 @@ system_sleep_sig(){
|
||||||
|
|
||||||
function
|
function
|
||||||
system_post_clipboard_sig(){
|
system_post_clipboard_sig(){
|
||||||
NotImplemented;
|
Arena *arena = &mac_vars.clip_post_arena;
|
||||||
|
if (arena->base_allocator == 0){
|
||||||
|
*arena = make_arena_system();
|
||||||
|
} else{
|
||||||
|
linalloc_clear(arena);
|
||||||
|
}
|
||||||
|
|
||||||
|
mac_vars.clip_post.str = push_array(arena, u8, str.size + 1);
|
||||||
|
if (mac_vars.clip_post.str != 0){
|
||||||
|
block_copy(mac_vars.clip_post.str, str.str, str.size);
|
||||||
|
mac_vars.clip_post.str[str.size] = 0;
|
||||||
|
mac_vars.clip_post.size = str.size;
|
||||||
|
} else{
|
||||||
|
// NOTE(yuval): Failed to allocate buffer for clipboard post
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue