Posting to clipboard now works.
parent
7d2a91805b
commit
f7b0b05426
|
@ -193,6 +193,9 @@ struct Mac_Vars {
|
|||
u32 clipboard_change_count;
|
||||
b32 next_clipboard_is_self;
|
||||
|
||||
Arena clip_post_arena;
|
||||
String_Const_u8 clip_post;
|
||||
|
||||
NSWindow *window;
|
||||
FCoder_View *view;
|
||||
f32 screen_scale_factor;
|
||||
|
@ -480,8 +483,8 @@ mac_read_clipboard_contents(Arena *scratch){
|
|||
{
|
||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||
NSString *utf8_type = @"public.utf8-plain-text";
|
||||
NSArray *array = [NSArray arrayWithObjects:utf8_type, nil];
|
||||
NSString *has_string = [board availableTypeFromArray:array];
|
||||
NSArray *types_array = [NSArray arrayWithObjects:utf8_type, nil];
|
||||
NSString *has_string = [board availableTypeFromArray:types_array];
|
||||
if (has_string != nil){
|
||||
NSData *data = [board dataForType:utf8_type];
|
||||
if (data != nil){
|
||||
|
@ -504,6 +507,25 @@ mac_read_clipboard_contents(Arena *scratch){
|
|||
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)
|
||||
function inline void
|
||||
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;
|
||||
}
|
||||
|
||||
mac_vars.clip_post.size = 0;
|
||||
|
||||
Application_Step_Result result = {};
|
||||
MacProfileScope("Step"){
|
||||
// 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"){
|
||||
// NOTE(yuval): Render
|
||||
renderer->render(renderer, &target);
|
||||
|
|
|
@ -431,7 +431,21 @@ system_sleep_sig(){
|
|||
|
||||
function
|
||||
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