update to new clipboard stuff, maybe correctly

This commit is contained in:
Alex Baines 2020-02-16 14:50:53 +00:00
parent 8cd068421e
commit a6eaacd057
2 changed files with 52 additions and 21 deletions

View File

@ -174,11 +174,10 @@ struct Linux_Vars {
System_Mutex global_frame_mutex;
Arena* clipboard_out_arena;
Arena* clipboard_arena;
String_Const_u8 clipboard_out_contents;
String_Const_u8 clipboard_contents;
b32 received_new_clipboard;
b32 clipboard_catch_all;
Atom atom_TARGETS;
Atom atom_CLIPBOARD;
@ -1154,7 +1153,7 @@ linux_clipboard_send(XSelectionRequestEvent* req) {
XA_STRING,
};
if(linuxvars.clipboard_out_contents.size == 0) {
if(linuxvars.clipboard_contents.size == 0) {
goto done;
}
@ -1193,8 +1192,8 @@ linux_clipboard_send(XSelectionRequestEvent* req) {
req->target,
8,
PropModeReplace,
linuxvars.clipboard_out_contents.str,
linuxvars.clipboard_out_contents.size
linuxvars.clipboard_contents.str,
linuxvars.clipboard_contents.size
);
rsp.property = req->property;
@ -1464,8 +1463,8 @@ linux_handle_x11_events() {
case SelectionClear: {
if(event.xselectionclear.selection == linuxvars.atom_CLIPBOARD) {
linalloc_clear(linuxvars.clipboard_out_arena);
block_zero_struct(&linuxvars.clipboard_out_contents);
linalloc_clear(linuxvars.clipboard_arena);
block_zero_struct(&linuxvars.clipboard_contents);
}
} break;
@ -1476,7 +1475,7 @@ linux_handle_x11_events() {
default: {
// clipboard update notification - ask for the new content
if (event.type == linuxvars.xfixes_selection_event) {
if (linuxvars.clipboard_catch_all && event.type == linuxvars.xfixes_selection_event) {
XFixesSelectionNotifyEvent* sne = (XFixesSelectionNotifyEvent*)&event;
if (sne->subtype == XFixesSelectionNotify && sne->owner != linuxvars.win){
XConvertSelection(
@ -1571,7 +1570,6 @@ main(int argc, char **argv){
// NOTE(allen): memory
linuxvars.frame_arena = reserve_arena(&linuxvars.tctx);
linuxvars.clipboard_arena = reserve_arena(&linuxvars.tctx);
linuxvars.clipboard_out_arena = reserve_arena(&linuxvars.tctx);
render_target.arena = make_arena_system(KB(256));
linuxvars.fontconfig = FcInitLoadConfigAndFonts();
@ -1585,7 +1583,7 @@ main(int argc, char **argv){
//InitializeCriticalSection(&win32vars.thread_launch_mutex);
//InitializeConditionVariable(&win32vars.thread_launch_cv);
// dpi ?
linuxvars.clipboard_catch_all = true;
// NOTE(allen): load core
System_Library core_library = {};
@ -1703,7 +1701,7 @@ main(int argc, char **argv){
{
Scratch_Block scratch(&linuxvars.tctx, Scratch_Share);
String_Const_u8 curdir = system_get_path(scratch, SystemPath_CurrentDirectory);
app.init(&linuxvars.tctx, &render_target, base_ptr, linuxvars.clipboard_contents, curdir, custom);
app.init(&linuxvars.tctx, &render_target, base_ptr, curdir, custom);
}
linuxvars.global_frame_mutex = system_mutex_make();
@ -1741,7 +1739,7 @@ main(int argc, char **argv){
// NOTE(allen): Frame Clipboard Input
// Request clipboard contents from X11 on first step, or every step if they don't have XFixes notification ability.
if (first_step || !linuxvars.has_xfixes){
if (first_step || (!linuxvars.has_xfixes && linuxvars.clipboard_catch_all)){
XConvertSelection(linuxvars.dpy, linuxvars.atom_CLIPBOARD, linuxvars.atom_UTF8_STRING, linuxvars.atom_CLIPBOARD, linuxvars.win, CurrentTime);
}
@ -1749,7 +1747,6 @@ main(int argc, char **argv){
if (linuxvars.received_new_clipboard){
input.clipboard = linuxvars.clipboard_contents;
input.clipboard_changed = true;
linuxvars.received_new_clipboard = false;
}

View File

@ -92,7 +92,11 @@ system_get_canonical(Arena* arena, String_Const_u8 name){
}
}
LINUX_FN_DEBUG("[%.*s] -> [%.*s]", (int)name.size, name.str, (int)(q - output), output);
#ifdef INSO_DEBUG
if(name.size != q - output) {
LINUX_FN_DEBUG("[%.*s] -> [%.*s]", (int)name.size, name.str, (int)(q - output), output);
}
#endif
// TODO: use realpath at this point to resolve symlinks?
return SCu8(output, q - output);
@ -205,15 +209,23 @@ internal File_Attributes
system_save_file(Arena* scratch, char* file_name, String_Const_u8 data){
LINUX_FN_DEBUG("%s", file_name);
File_Attributes result = {};
// TODO(inso): should probably put a \n on the end if it's a text file.
int fd = open(file_name, O_WRONLY, O_CREAT);
if (fd != -1) {
int bytes_written = write(fd, data.str, data.size);
if (bytes_written != -1) {
if (bytes_written == -1) {
perror("write");
} else if(bytes_written == data.size) {
struct stat file_stat;
fstat(fd, &file_stat);
return linux_file_attributes_from_struct_stat(&file_stat);
}
} else {
perror("open");
}
return result;
}
@ -273,7 +285,7 @@ system_wake_up_timer_release(Plat_Handle handle){
internal void
system_wake_up_timer_set(Plat_Handle handle, u32 time_milliseconds){
LINUX_FN_DEBUG("%u", time_milliseconds);
//LINUX_FN_DEBUG("%u", time_milliseconds);
Linux_Object* object = handle_to_object(handle);
if (object->kind == LinuxObjectKind_Timer){
@ -311,14 +323,33 @@ system_sleep(u64 microseconds){
nanosleep(&requested, &remaining);
}
internal String_Const_u8
system_get_clipboard(Arena* arena, i32 index){
// TODO(inso): index?
u8* ptr = push_array_write(arena, u8, linuxvars.clipboard_contents.size, linuxvars.clipboard_contents.str);
return SCu8(ptr, linuxvars.clipboard_contents.size);
}
internal void
system_post_clipboard(String_Const_u8 str){
//LINUX_FN_DEBUG("%.*s", (int)str.size, str.str);
linalloc_clear(linuxvars.clipboard_out_arena);
linuxvars.clipboard_out_contents = push_u8_stringf(linuxvars.clipboard_out_arena, "%.*s", str.size, str.str);
system_post_clipboard(String_Const_u8 str, i32 index){
// TODO(inso): index?
//LINUX_FN_DEBUG("%.*s", string_expand(str));
linalloc_clear(linuxvars.clipboard_arena);
linuxvars.clipboard_contents = push_u8_stringf(linuxvars.clipboard_arena, "%.*s", str.size, str.str);
XSetSelectionOwner(linuxvars.dpy, linuxvars.atom_CLIPBOARD, linuxvars.win, CurrentTime);
}
internal void
system_set_clipboard_catch_all(b32 enabled){
LINUX_FN_DEBUG("%d", enabled);
linuxvars.clipboard_catch_all = !!enabled;
}
internal b32
system_get_clipboard_catch_all(void){
return linuxvars.clipboard_catch_all;
}
internal b32
system_cli_call(Arena* scratch, char* path, char* script, CLI_Handles* cli_out){
LINUX_FN_DEBUG("%s / %s", path, script);
@ -595,7 +626,7 @@ system_memory_allocate(u64 size, String_Const_u8 location){
void* result = mmap(
NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
// TODO(andrew): Allocation tracking?
LINUX_FN_DEBUG("%" PRIu64 ", %.*s %p", size, (int)location.size, location.str, result);
//LINUX_FN_DEBUG("%" PRIu64 ", %.*s %p", size, (int)location.size, location.str, result);
return result;
}
@ -671,3 +702,6 @@ system_get_keyboard_modifiers(Arena* arena){
//LINUX_FN_DEBUG();
return(copy_modifier_set(arena, &linuxvars.input.pers.modifiers));
}
// NOTE(inso): to prevent me continuously messing up indentation
// vim: et:ts=4:sts=4:sw=4