2015-11-16 16:15:45 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 14.11.2015
|
|
|
|
*
|
|
|
|
* Linux layer for project codename "4ed"
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
#include "4ed_config.h"
|
2015-11-16 16:15:45 +00:00
|
|
|
|
|
|
|
#include "4ed_meta.h"
|
|
|
|
|
|
|
|
#define FCPP_FORBID_MALLOC
|
|
|
|
|
|
|
|
#include "4cpp_types.h"
|
|
|
|
#define FCPP_STRING_IMPLEMENTATION
|
2016-02-01 05:03:42 +00:00
|
|
|
#include "4coder_string.h"
|
2015-11-16 16:15:45 +00:00
|
|
|
|
|
|
|
#include "4ed_mem.cpp"
|
|
|
|
#include "4ed_math.cpp"
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2015-11-16 16:15:45 +00:00
|
|
|
#include "4coder_custom.h"
|
|
|
|
#include "4ed_system.h"
|
|
|
|
#include "4ed_rendering.h"
|
2016-02-01 05:03:42 +00:00
|
|
|
#include "4ed.h"
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2015-12-01 02:51:53 +00:00
|
|
|
#include <stdio.h>
|
2016-02-01 05:03:42 +00:00
|
|
|
#include <memory.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/time.h>
|
2016-02-07 15:19:18 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
2016-02-01 05:03:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <GL/glx.h>
|
2016-02-23 03:14:23 +00:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glext.h>
|
2016-02-01 05:03:42 +00:00
|
|
|
#include <xmmintrin.h>
|
|
|
|
#include <linux/fs.h>
|
2016-02-20 18:23:46 +00:00
|
|
|
//#include <X11/extensions/XInput2.h>
|
2016-02-01 05:03:42 +00:00
|
|
|
#include <linux/input.h>
|
2016-02-07 15:19:18 +00:00
|
|
|
#include <time.h>
|
2016-02-11 17:17:52 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <unistd.h>
|
2015-12-01 02:51:53 +00:00
|
|
|
|
2015-11-16 16:15:45 +00:00
|
|
|
#include "4ed_internal.h"
|
|
|
|
#include "4ed_linux_keyboard.cpp"
|
2016-02-11 17:17:52 +00:00
|
|
|
#include "system_shared.h"
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-07 15:19:18 +00:00
|
|
|
#include <stdlib.h>
|
2016-02-21 17:59:47 +00:00
|
|
|
#include <locale.h>
|
2016-02-23 03:14:23 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
struct Linux_Vars{
|
2016-02-20 18:23:46 +00:00
|
|
|
Display *XDisplay;
|
|
|
|
Window XWindow;
|
|
|
|
Render_Target target;
|
|
|
|
|
|
|
|
XIM input_method;
|
|
|
|
XIMStyle input_style;
|
2016-02-21 17:59:47 +00:00
|
|
|
XIC input_context;
|
2016-02-20 18:23:46 +00:00
|
|
|
Key_Codes key_codes;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
Key_Input_Data key_data;
|
|
|
|
Mouse_State mouse_data;
|
|
|
|
|
|
|
|
String clipboard_contents;
|
2016-02-20 18:23:46 +00:00
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
void *app_code;
|
|
|
|
void *custom;
|
|
|
|
|
|
|
|
Plat_Settings settings;
|
|
|
|
System_Functions *system;
|
|
|
|
App_Functions app;
|
|
|
|
Custom_API custom_api;
|
|
|
|
b32 first;
|
|
|
|
|
|
|
|
#if FRED_INTERNAL
|
|
|
|
Sys_Bubble internal_bubble;
|
|
|
|
#endif
|
2016-02-20 18:23:46 +00:00
|
|
|
|
|
|
|
Font_Load_System fnt;
|
2016-02-11 17:17:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
globalvar Linux_Vars linuxvars;
|
|
|
|
globalvar Application_Memory memory_vars;
|
|
|
|
globalvar Exchange exchange_vars;
|
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
#define LinuxGetMemory(size) LinuxGetMemory_(size, __LINE__, __FILE__)
|
|
|
|
|
|
|
|
internal void*
|
|
|
|
LinuxGetMemory_(i32 size, i32 line_number, char *file_name){
|
2016-02-07 15:19:18 +00:00
|
|
|
// TODO(allen): Implement without stdlib.h
|
2016-02-11 17:17:52 +00:00
|
|
|
void *result = 0;
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
Assert(size != 0);
|
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
#if FRED_INTERNAL
|
2016-02-20 18:23:46 +00:00
|
|
|
Sys_Bubble *bubble;
|
2016-02-11 17:17:52 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
result = malloc(size + sizeof(Sys_Bubble));
|
|
|
|
bubble = (Sys_Bubble*)result;
|
|
|
|
bubble->flags = MEM_BUBBLE_SYS_DEBUG;
|
|
|
|
bubble->line_number = line_number;
|
|
|
|
bubble->file_name = file_name;
|
|
|
|
bubble->size = size;
|
2016-02-11 17:17:52 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
// TODO(allen): make Sys_Bubble list thread safe
|
|
|
|
insert_bubble(&linuxvars.internal_bubble, bubble);
|
|
|
|
result = bubble + 1;
|
2016-02-11 17:17:52 +00:00
|
|
|
|
|
|
|
#else
|
2016-02-20 18:23:46 +00:00
|
|
|
result = malloc(size);
|
2016-02-11 17:17:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return(result);
|
2016-02-07 15:19:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
internal void
|
|
|
|
LinuxFreeMemory(void *block){
|
2016-02-07 15:19:18 +00:00
|
|
|
// TODO(allen): Implement without stdlib.h
|
2016-02-11 17:17:52 +00:00
|
|
|
|
|
|
|
if (block){
|
|
|
|
#if FRED_INTERNAL
|
|
|
|
Sys_Bubble *bubble;
|
|
|
|
|
|
|
|
bubble = (Sys_Bubble*)block;
|
|
|
|
--bubble;
|
|
|
|
Assert((bubble->flags & MEM_BUBBLE_DEBUG_MASK) == MEM_BUBBLE_SYS_DEBUG);
|
|
|
|
|
|
|
|
// TODO(allen): make Sys_Bubble list thread safe
|
|
|
|
remove_bubble(bubble);
|
|
|
|
|
|
|
|
free(bubble);
|
|
|
|
#else
|
|
|
|
free(block);
|
|
|
|
#endif
|
|
|
|
}
|
2016-02-07 15:19:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
internal Partition
|
|
|
|
LinuxScratchPartition(i32 size){
|
|
|
|
Partition part;
|
|
|
|
void *data;
|
|
|
|
data = LinuxGetMemory(size);
|
|
|
|
part = partition_open(data, size);
|
|
|
|
return(part);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
LinuxScratchPartitionGrow(Partition *part, i32 new_size){
|
|
|
|
void *data;
|
|
|
|
if (new_size > part->max){
|
|
|
|
data = LinuxGetMemory(new_size);
|
|
|
|
memcpy(data, part->base, part->pos);
|
|
|
|
LinuxFreeMemory(part->base);
|
|
|
|
part->base = (u8*)data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
LinuxScratchPartitionDouble(Partition *part){
|
|
|
|
LinuxScratchPartitionGrow(part, part->max*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Get_Memory_Sig(system_get_memory_){
|
|
|
|
return(LinuxGetMemory_(size, line_number, file_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Free_Memory_Sig(system_free_memory){
|
|
|
|
LinuxFreeMemory(block);
|
|
|
|
}
|
|
|
|
|
2016-02-07 15:19:18 +00:00
|
|
|
#if (defined(_BSD_SOURCE) || defined(_SVID_SOURCE))
|
|
|
|
#define TimeBySt
|
|
|
|
#endif
|
|
|
|
#if (_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
|
|
|
|
#define TimeBySt
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TimeBySt
|
|
|
|
#define nano_mtime_field st_mtim.tv_nsec
|
|
|
|
#undef TimeBySt
|
|
|
|
#else
|
|
|
|
#define nano_mtime_field st_mtimensec
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Sys_File_Time_Stamp_Sig(system_file_time_stamp){
|
|
|
|
struct stat info;
|
|
|
|
i64 nanosecond_timestamp;
|
|
|
|
u64 result;
|
|
|
|
|
|
|
|
stat(filename, &info);
|
|
|
|
nanosecond_timestamp = info.nano_mtime_field;
|
|
|
|
if (nanosecond_timestamp != 0){
|
|
|
|
result = (u64)(nanosecond_timestamp / 1000);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
result = (u64)(info.st_mtime * 1000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
// TODO(allen): DOES THIS AGREE WITH THE FILESTAMP TIMES?
|
2016-02-23 03:14:23 +00:00
|
|
|
// NOTE(inso): I don't think so, CLOCK_MONOTONIC is an arbitrary number
|
2016-02-07 15:19:18 +00:00
|
|
|
Sys_Time_Sig(system_time){
|
|
|
|
struct timespec spec;
|
|
|
|
u64 result;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &spec);
|
|
|
|
result = (spec.tv_sec * 1000000) + (spec.tv_nsec / 1000);
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Set_File_List_Sig(system_set_file_list){
|
|
|
|
DIR *d;
|
|
|
|
struct dirent *entry;
|
|
|
|
char *fname, *cursor, *cursor_start;
|
|
|
|
File_Info *info_ptr;
|
|
|
|
i32 count, file_count, size, required_size;
|
|
|
|
|
|
|
|
terminate_with_null(&directory);
|
|
|
|
d = opendir(directory.str);
|
|
|
|
if (d){
|
|
|
|
count = 0;
|
|
|
|
for (entry = readdir(d);
|
|
|
|
entry != 0;
|
|
|
|
entry = readdir(d)){
|
|
|
|
fname = entry->d_name;
|
|
|
|
++file_count;
|
|
|
|
for (size = 0; fname[size]; ++size);
|
|
|
|
count += size + 1;
|
|
|
|
}
|
|
|
|
closedir(d);
|
|
|
|
|
|
|
|
required_size = count + file_count * sizeof(File_Info);
|
|
|
|
if (file_list->block_size < required_size){
|
2016-02-11 17:17:52 +00:00
|
|
|
system_free_memory(file_list->block);
|
|
|
|
file_list->block = system_get_memory(required_size);
|
2016-02-07 15:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
file_list->infos = (File_Info*)file_list->block;
|
|
|
|
cursor = (char*)(file_list->infos + file_count);
|
|
|
|
|
|
|
|
d = opendir(directory.str);
|
|
|
|
if (d){
|
|
|
|
info_ptr = file_list->infos;
|
|
|
|
for (entry = readdir(d);
|
|
|
|
entry != 0;
|
|
|
|
entry = readdir(d), ++info_ptr){
|
|
|
|
fname = entry->d_name;
|
|
|
|
cursor_start = cursor;
|
|
|
|
for (; *fname; ) *cursor++ = *fname++;
|
2016-02-11 17:17:52 +00:00
|
|
|
|
|
|
|
// TODO(allen): detect file/folder status
|
|
|
|
// (also make sure this even GETS folders!!!)
|
2016-02-07 15:19:18 +00:00
|
|
|
info_ptr->folder = 0;
|
|
|
|
info_ptr->filename.str = cursor_start;
|
|
|
|
info_ptr->filename.size = (i32)(cursor - cursor_start);
|
2016-02-11 17:17:52 +00:00
|
|
|
*cursor++ = 0;
|
2016-02-07 15:19:18 +00:00
|
|
|
info_ptr->filename.memory_size = info_ptr->filename.size + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Post_Clipboard_Sig(system_post_clipboard){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(str);
|
|
|
|
}
|
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
Sys_CLI_Call_Sig(system_cli_call){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(path);
|
|
|
|
AllowLocal(script_name);
|
|
|
|
AllowLocal(cli_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_CLI_Begin_Update_Sig(system_cli_begin_update){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(cli);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_CLI_Update_Step_Sig(system_cli_update_step){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(cli);
|
|
|
|
AllowLocal(dest);
|
|
|
|
AllowLocal(max);
|
|
|
|
AllowLocal(amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_CLI_End_Update_Sig(system_cli_end_update){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(cli);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Post_Job_Sig(system_post_job){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(group_id);
|
|
|
|
AllowLocal(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Cancel_Job_Sig(system_cancel_job){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(group_id);
|
|
|
|
AllowLocal(job_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Acquire_Lock_Sig(system_acquire_lock){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Release_Lock_Sig(system_release_lock){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Grow_Thread_Memory_Sig(system_grow_thread_memory){
|
|
|
|
void *old_data;
|
|
|
|
i32 old_size, new_size;
|
|
|
|
|
|
|
|
system_acquire_lock(CANCEL_LOCK0 + memory->id - 1);
|
|
|
|
old_data = memory->data;
|
|
|
|
old_size = memory->size;
|
|
|
|
new_size = LargeRoundUp(memory->size*2, Kbytes(4));
|
|
|
|
memory->data = system_get_memory(new_size);
|
|
|
|
memory->size = new_size;
|
|
|
|
if (old_data){
|
|
|
|
memcpy(memory->data, old_data, old_size);
|
|
|
|
system_free_memory(old_data);
|
|
|
|
}
|
|
|
|
system_release_lock(CANCEL_LOCK0 + memory->id - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERNAL_Sys_Sentinel_Sig(internal_sentinel){
|
|
|
|
Bubble *result;
|
|
|
|
#if FRED_INTERNAL
|
|
|
|
result = &linuxvars.internal_bubble;
|
|
|
|
#else
|
|
|
|
result = 0;
|
|
|
|
#endif
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERNAL_Sys_Get_Thread_States_Sig(internal_get_thread_states){
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(id);
|
|
|
|
AllowLocal(running);
|
|
|
|
AllowLocal(pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERNAL_Sys_Debug_Message_Sig(internal_debug_message){
|
|
|
|
printf("%s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIRECTORY_HAS_FILE_SIG(system_directory_has_file){
|
|
|
|
int result = 0;
|
2016-02-23 03:14:23 +00:00
|
|
|
|
|
|
|
//TODO(inso): implement
|
|
|
|
char buff[PATH_MAX] = {};
|
|
|
|
memcpy(buff, dir.str, dir.size);
|
|
|
|
printf("Has file %s\n", buff);
|
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
DIRECTORY_CD_SIG(system_directory_cd){
|
|
|
|
int result = 0;
|
|
|
|
// TODO(allen): Implement
|
2016-02-23 03:14:23 +00:00
|
|
|
|
|
|
|
printf("Dir CD: %.*s\n", dir->size, dir->str);
|
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
AllowLocal(dir);
|
|
|
|
AllowLocal(rel_path);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_File_Can_Be_Made(system_file_can_be_made){
|
|
|
|
// TODO(allen): Implement
|
2016-02-23 03:14:23 +00:00
|
|
|
|
|
|
|
printf("File can be made: %s\n", filename);
|
2016-02-11 17:17:52 +00:00
|
|
|
AllowLocal(filename);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Load_File_Sig(system_load_file){
|
|
|
|
Data result = {};
|
2016-02-23 03:14:23 +00:00
|
|
|
struct stat info = {};
|
|
|
|
int fd;
|
|
|
|
u8 *ptr, *read_ptr;
|
|
|
|
size_t bytes_to_read;
|
|
|
|
ssize_t num;
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if(fd < 0){
|
|
|
|
perror("sys_open_file: open");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if(fstat(fd, &info) < 0){
|
|
|
|
perror("sys_open_file: stat");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if(info.st_size <= 0){
|
|
|
|
printf("st_size < 0: %ld\n", info.st_size);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (u8*)LinuxGetMemory(info.st_size);
|
|
|
|
if(!ptr){
|
|
|
|
puts("null pointer from LGM");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
read_ptr = ptr;
|
|
|
|
bytes_to_read = info.st_size;
|
|
|
|
|
|
|
|
do {
|
|
|
|
num = read(fd, read_ptr, bytes_to_read);
|
|
|
|
if(num < 0){
|
|
|
|
if(errno == EINTR){
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
//TODO(inso): error handling
|
|
|
|
perror("sys_load_file: read");
|
|
|
|
LinuxFreeMemory(ptr);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bytes_to_read -= num;
|
|
|
|
read_ptr += num;
|
|
|
|
}
|
|
|
|
} while(bytes_to_read);
|
|
|
|
|
|
|
|
result.size = info.st_size;
|
|
|
|
result.data = ptr;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if(fd >= 0) close(fd);
|
2016-02-11 17:17:52 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Save_File_Sig(system_save_file){
|
|
|
|
b32 result = 0;
|
|
|
|
// TODO(allen): Implement
|
|
|
|
AllowLocal(filename);
|
|
|
|
AllowLocal(data);
|
|
|
|
AllowLocal(size);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
// TODO(allen): Implement this. Also where is this
|
|
|
|
// macro define? Let's try to organize these functions
|
|
|
|
// a little better now that they're starting to settle
|
|
|
|
// into their places.
|
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
#include "system_shared.cpp"
|
|
|
|
#include "4ed_rendering.cpp"
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
internal
|
|
|
|
Font_Load_Sig(system_draw_font_load){
|
2016-02-23 03:14:23 +00:00
|
|
|
Font_Load_Parameters *params;
|
|
|
|
|
|
|
|
system_acquire_lock(FONT_LOCK);
|
|
|
|
params = linuxvars.fnt.free_param.next;
|
|
|
|
fnt__remove(params);
|
|
|
|
fnt__insert(&linuxvars.fnt.used_param, params);
|
|
|
|
system_release_lock(FONT_LOCK);
|
|
|
|
|
|
|
|
if (linuxvars.fnt.part.base == 0){
|
|
|
|
linuxvars.fnt.part = LinuxScratchPartition(Mbytes(8));
|
|
|
|
}
|
|
|
|
|
|
|
|
b32 done = 0;
|
|
|
|
while(!(done =
|
|
|
|
draw_font_load(
|
|
|
|
linuxvars.fnt.part.base,
|
|
|
|
linuxvars.fnt.part.max,
|
|
|
|
font_out,
|
|
|
|
filename,
|
|
|
|
pt_size,
|
|
|
|
tab_width
|
|
|
|
)
|
|
|
|
)){
|
|
|
|
//FIXME(inso): This is an infinite loop if the fonts aren't found!
|
|
|
|
// Figure out how draw_font_load can fail
|
|
|
|
|
|
|
|
printf("draw_font_load failed, %d\n", linuxvars.fnt.part.max);
|
|
|
|
LinuxScratchPartitionDouble(&linuxvars.fnt.part);
|
|
|
|
}
|
|
|
|
|
|
|
|
system_acquire_lock(FONT_LOCK);
|
|
|
|
fnt__remove(params);
|
|
|
|
fnt__insert(&linuxvars.fnt.free_param, params);
|
|
|
|
system_release_lock(FONT_LOCK);
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2016-02-21 17:59:47 +00:00
|
|
|
internal
|
|
|
|
Sys_To_Binary_Path(system_to_binary_path){
|
|
|
|
b32 translate_success = 0;
|
|
|
|
i32 max = out_filename->memory_size;
|
|
|
|
i32 size = readlink("/proc/self/exe", out_filename->str, max);
|
|
|
|
if (size > 0 && size < max-1){
|
|
|
|
out_filename->str[size] = '\0';
|
|
|
|
out_filename->size = size + 1;
|
|
|
|
truncate_to_path_of_directory(out_filename);
|
|
|
|
if (append(out_filename, filename) && terminate_with_null(out_filename)){
|
|
|
|
translate_success = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (translate_success);
|
|
|
|
}
|
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
internal b32
|
|
|
|
LinuxLoadAppCode(){
|
|
|
|
b32 result = 0;
|
|
|
|
App_Get_Functions *get_funcs = 0;
|
|
|
|
|
|
|
|
linuxvars.app_code = dlopen("./4ed_app.so", RTLD_LAZY);
|
|
|
|
if (linuxvars.app_code){
|
|
|
|
get_funcs = (App_Get_Functions*)
|
|
|
|
dlsym(linuxvars.app_code, "app_get_functions");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_funcs){
|
|
|
|
result = 1;
|
|
|
|
linuxvars.app = get_funcs();
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
LinuxLoadSystemCode(){
|
|
|
|
linuxvars.system->file_time_stamp = system_file_time_stamp;
|
|
|
|
linuxvars.system->set_file_list = system_set_file_list;
|
|
|
|
|
|
|
|
linuxvars.system->directory_has_file = system_directory_has_file;
|
|
|
|
linuxvars.system->directory_cd = system_directory_cd;
|
|
|
|
|
|
|
|
linuxvars.system->post_clipboard = system_post_clipboard;
|
|
|
|
linuxvars.system->time = system_time;
|
|
|
|
|
|
|
|
linuxvars.system->cli_call = system_cli_call;
|
|
|
|
linuxvars.system->cli_begin_update = system_cli_begin_update;
|
|
|
|
linuxvars.system->cli_update_step = system_cli_update_step;
|
|
|
|
linuxvars.system->cli_end_update = system_cli_end_update;
|
|
|
|
|
|
|
|
linuxvars.system->post_job = system_post_job;
|
|
|
|
linuxvars.system->cancel_job = system_cancel_job;
|
|
|
|
linuxvars.system->grow_thread_memory = system_grow_thread_memory;
|
|
|
|
linuxvars.system->acquire_lock = system_acquire_lock;
|
|
|
|
linuxvars.system->release_lock = system_release_lock;
|
|
|
|
|
|
|
|
linuxvars.system->internal_sentinel = internal_sentinel;
|
|
|
|
linuxvars.system->internal_get_thread_states = internal_get_thread_states;
|
|
|
|
linuxvars.system->internal_debug_message = internal_debug_message;
|
|
|
|
}
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
internal void
|
|
|
|
LinuxLoadRenderCode(){
|
|
|
|
linuxvars.target.push_clip = draw_push_clip;
|
|
|
|
linuxvars.target.pop_clip = draw_pop_clip;
|
|
|
|
linuxvars.target.push_piece = draw_push_piece;
|
|
|
|
|
|
|
|
linuxvars.target.font_set.font_info_load = draw_font_info_load;
|
|
|
|
linuxvars.target.font_set.font_load = system_draw_font_load;
|
|
|
|
linuxvars.target.font_set.release_font = draw_release_font;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
LinuxRedrawTarget(){
|
|
|
|
system_acquire_lock(RENDER_LOCK);
|
|
|
|
launch_rendering(&linuxvars.target);
|
|
|
|
system_release_lock(RENDER_LOCK);
|
|
|
|
glFlush();
|
|
|
|
glXSwapBuffers(linuxvars.XDisplay, linuxvars.XWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
LinuxResizeTarget(i32 width, i32 height){
|
|
|
|
if (width > 0 && height > 0){
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(0, width, height, 0, -1, 1);
|
|
|
|
glScissor(0, 0, width, height);
|
|
|
|
|
|
|
|
linuxvars.target.width = width;
|
|
|
|
linuxvars.target.height = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-07 15:19:18 +00:00
|
|
|
// NOTE(allen): Thanks to Casey for providing the linux OpenGL launcher.
|
2016-02-01 05:03:42 +00:00
|
|
|
static bool ctxErrorOccurred = false;
|
|
|
|
static int XInput2OpCode = 0;
|
|
|
|
internal int
|
|
|
|
ctxErrorHandler( Display *dpy, XErrorEvent *ev )
|
|
|
|
{
|
|
|
|
ctxErrorOccurred = true;
|
|
|
|
return 0;
|
2015-11-16 16:15:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
#if FRED_INTERNAL
|
|
|
|
static void gl_log(
|
|
|
|
GLenum source,
|
|
|
|
GLenum type,
|
|
|
|
GLuint id,
|
|
|
|
GLenum severity,
|
|
|
|
GLsizei length,
|
|
|
|
const GLchar* message,
|
|
|
|
const void* userParam
|
|
|
|
){
|
|
|
|
printf("GL DEBUG: %s\n", message);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
internal GLXContext
|
|
|
|
InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig &bestFbc, b32 &IsLegacy)
|
|
|
|
{
|
|
|
|
IsLegacy = false;
|
|
|
|
|
|
|
|
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
|
|
|
const char *glxExts = glXQueryExtensionsString(XDisplay, DefaultScreen(XDisplay));
|
|
|
|
|
|
|
|
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
|
|
|
|
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
|
|
|
|
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
|
|
|
|
|
|
|
|
GLXContext ctx = 0;
|
|
|
|
ctxErrorOccurred = false;
|
|
|
|
int (*oldHandler)(Display*, XErrorEvent*) =
|
|
|
|
XSetErrorHandler(&ctxErrorHandler);
|
|
|
|
if (!glXCreateContextAttribsARB)
|
|
|
|
{
|
|
|
|
printf( "glXCreateContextAttribsARB() not found"
|
|
|
|
" ... using old-style GLX context\n" );
|
|
|
|
ctx = glXCreateNewContext( XDisplay, bestFbc, GLX_RGBA_TYPE, 0, True );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int context_attribs[] =
|
|
|
|
{
|
2016-02-23 03:14:23 +00:00
|
|
|
GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
|
|
|
|
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
|
|
|
|
GLX_CONTEXT_PROFILE_MASK_ARB , GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
|
|
|
|
#if FRED_INTERNAL
|
|
|
|
GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_DEBUG_BIT_ARB,
|
|
|
|
#endif
|
2016-02-01 05:03:42 +00:00
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
printf("Attribs: %d %d %d %d %d\n",
|
2016-02-01 05:03:42 +00:00
|
|
|
context_attribs[0],
|
|
|
|
context_attribs[1],
|
|
|
|
context_attribs[2],
|
|
|
|
context_attribs[3],
|
|
|
|
context_attribs[4]);
|
|
|
|
|
|
|
|
printf( "Creating context\n" );
|
|
|
|
ctx = glXCreateContextAttribsARB( XDisplay, bestFbc, 0,
|
|
|
|
True, context_attribs );
|
|
|
|
|
|
|
|
XSync( XDisplay, False );
|
|
|
|
if ( !ctxErrorOccurred && ctx )
|
|
|
|
{
|
|
|
|
printf( "Created GL 4.3 context\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ctxErrorOccurred = false;
|
|
|
|
|
|
|
|
context_attribs[1] = 4;
|
|
|
|
context_attribs[3] = 0;
|
|
|
|
|
|
|
|
printf( "Creating context\n" );
|
|
|
|
ctx = glXCreateContextAttribsARB( XDisplay, bestFbc, 0,
|
|
|
|
True, context_attribs );
|
|
|
|
|
|
|
|
XSync( XDisplay, False );
|
|
|
|
|
|
|
|
if ( !ctxErrorOccurred && ctx )
|
|
|
|
{
|
|
|
|
printf( "Created GL 4.0 context\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context_attribs[1] = 1;
|
|
|
|
context_attribs[3] = 0;
|
|
|
|
|
|
|
|
ctxErrorOccurred = false;
|
|
|
|
|
|
|
|
printf( "Failed to create GL 4.0 context"
|
|
|
|
" ... using old-style GLX context\n" );
|
|
|
|
ctx = glXCreateContextAttribsARB( XDisplay, bestFbc, 0,
|
|
|
|
True, context_attribs );
|
|
|
|
|
|
|
|
IsLegacy = true;
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 16:15:45 +00:00
|
|
|
}
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
XSync( XDisplay, False );
|
|
|
|
XSetErrorHandler( oldHandler );
|
|
|
|
|
|
|
|
if ( ctxErrorOccurred || !ctx )
|
|
|
|
{
|
|
|
|
printf( "Failed to create an OpenGL context\n" );
|
|
|
|
exit(1);
|
2015-11-16 16:15:45 +00:00
|
|
|
}
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
if ( ! glXIsDirect ( XDisplay, ctx ) )
|
|
|
|
{
|
|
|
|
printf( "Indirect GLX rendering context obtained\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf( "Direct GLX rendering context obtained\n" );
|
|
|
|
}
|
2016-02-20 18:23:46 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
printf( "Making context current\n" );
|
|
|
|
glXMakeCurrent( XDisplay, XWindow, ctx );
|
2016-02-20 18:23:46 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
GLint n;
|
|
|
|
char *Vendor = (char *)glGetString(GL_VENDOR);
|
|
|
|
char *Renderer = (char *)glGetString(GL_RENDERER);
|
|
|
|
char *Version = (char *)glGetString(GL_VERSION);
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
//TODO(inso): glGetStringi is required if the GL version is >= 3.0
|
2016-02-01 05:03:42 +00:00
|
|
|
char *Extensions = (char *)glGetString(GL_EXTENSIONS);
|
2016-02-20 18:23:46 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
printf("GL_VENDOR: %s\n", Vendor);
|
|
|
|
printf("GL_RENDERER: %s\n", Renderer);
|
|
|
|
printf("GL_VERSION: %s\n", Version);
|
|
|
|
printf("GL_EXTENSIONS: %s\n", Extensions);
|
2016-02-23 03:14:23 +00:00
|
|
|
|
|
|
|
#if FRED_INTERNAL
|
|
|
|
PFNGLDEBUGMESSAGECALLBACKARBPROC gl_dbg_callback = (PFNGLDEBUGMESSAGECALLBACKARBPROC)glXGetProcAddress((const GLubyte*)"glDebugMessageCallback");
|
|
|
|
if(gl_dbg_callback){
|
|
|
|
puts("enabling gl debug");
|
|
|
|
gl_dbg_callback(&gl_log, 0);
|
|
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
return(ctx);
|
2015-11-16 16:15:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
internal b32
|
|
|
|
GLXSupportsModernContexts(Display *XDisplay)
|
|
|
|
{
|
|
|
|
b32 Result = false;
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
int GLXMajor, GLXMinor;
|
|
|
|
|
|
|
|
char *XVendor = ServerVendor(XDisplay);
|
|
|
|
printf("XWindows vendor: %s\n", XVendor);
|
|
|
|
if(glXQueryVersion(XDisplay, &GLXMajor, &GLXMinor))
|
|
|
|
{
|
|
|
|
printf("GLX version %d.%d\n", GLXMajor, GLXMinor);
|
|
|
|
if(((GLXMajor == 1 ) && (GLXMinor >= 3)) ||
|
|
|
|
(GLXMajor > 1))
|
|
|
|
{
|
|
|
|
Result = true;
|
2015-11-16 16:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
return(Result);
|
2015-11-16 16:15:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
typedef struct glx_config_result{
|
|
|
|
b32 Found;
|
|
|
|
GLXFBConfig BestConfig;
|
|
|
|
XVisualInfo BestInfo;
|
|
|
|
} glx_config_result;
|
|
|
|
|
|
|
|
internal glx_config_result
|
|
|
|
ChooseGLXConfig(Display *XDisplay, int XScreenIndex)
|
|
|
|
{
|
|
|
|
glx_config_result Result = {0};
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
int DesiredAttributes[] =
|
|
|
|
{
|
|
|
|
GLX_X_RENDERABLE , True,
|
|
|
|
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
|
|
|
|
GLX_RENDER_TYPE , GLX_RGBA_BIT,
|
|
|
|
GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
|
|
|
|
GLX_RED_SIZE , 8,
|
|
|
|
GLX_GREEN_SIZE , 8,
|
|
|
|
GLX_BLUE_SIZE , 8,
|
|
|
|
GLX_ALPHA_SIZE , 8,
|
|
|
|
GLX_DEPTH_SIZE , 24,
|
|
|
|
GLX_STENCIL_SIZE , 8,
|
|
|
|
GLX_DOUBLEBUFFER , True,
|
|
|
|
//GLX_SAMPLE_BUFFERS , 1,
|
|
|
|
//GLX_SAMPLES , 4,
|
|
|
|
None
|
|
|
|
};
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
{
|
|
|
|
int ConfigCount;
|
|
|
|
GLXFBConfig *Configs = glXChooseFBConfig(XDisplay,
|
|
|
|
XScreenIndex,
|
|
|
|
DesiredAttributes,
|
|
|
|
&ConfigCount);
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
#if 0
|
|
|
|
int DiffValues[GLXValueCount];
|
|
|
|
#endif
|
|
|
|
{for(int ConfigIndex = 0;
|
|
|
|
ConfigIndex < ConfigCount;
|
|
|
|
++ConfigIndex)
|
|
|
|
{
|
|
|
|
GLXFBConfig &Config = Configs[ConfigIndex];
|
|
|
|
XVisualInfo *VisualInfo = glXGetVisualFromFBConfig(XDisplay, Config);
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
#if 0
|
|
|
|
printf(" Option %d:\n", ConfigIndex);
|
|
|
|
printf(" Depth: %d\n", VisualInfo->depth);
|
|
|
|
printf(" Bits per channel: %d\n", VisualInfo->bits_per_rgb);
|
|
|
|
printf(" Mask: R%06x G%06x B%06x\n",
|
|
|
|
(uint32)VisualInfo->red_mask,
|
|
|
|
(uint32)VisualInfo->green_mask,
|
|
|
|
(uint32)VisualInfo->blue_mask);
|
|
|
|
printf(" Class: %d\n", VisualInfo->c_class);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
{for(int ValueIndex = 0;
|
|
|
|
ValueIndex < GLXValueCount;
|
|
|
|
++ValueIndex)
|
|
|
|
{
|
|
|
|
glx_value_info &ValueInfo = GLXValues[ValueIndex];
|
|
|
|
int Value;
|
|
|
|
glXGetFBConfigAttrib(XDisplay, Config, ValueInfo.ID, &Value);
|
|
|
|
if(DiffValues[ValueIndex] != Value)
|
|
|
|
{
|
|
|
|
printf(" %s: %d\n", ValueInfo.Name, Value);
|
|
|
|
DiffValues[ValueIndex] = Value;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO(casey): How the hell are you supposed to pick a config here??
|
|
|
|
if(ConfigIndex == 0)
|
|
|
|
{
|
|
|
|
Result.Found = true;
|
|
|
|
Result.BestConfig = Config;
|
|
|
|
Result.BestInfo = *VisualInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(VisualInfo);
|
|
|
|
}}
|
|
|
|
|
|
|
|
XFree(Configs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(Result);
|
2015-12-01 02:51:53 +00:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
struct Init_Input_Result{
|
|
|
|
XIM input_method;
|
|
|
|
XIMStyle best_style;
|
|
|
|
XIC xic;
|
|
|
|
};
|
|
|
|
|
|
|
|
internal Init_Input_Result
|
2016-02-01 05:03:42 +00:00
|
|
|
InitializeXInput(Display *dpy, Window XWindow)
|
|
|
|
{
|
2016-02-20 18:23:46 +00:00
|
|
|
#if 0
|
2016-02-01 05:03:42 +00:00
|
|
|
int event, error;
|
|
|
|
if(XQueryExtension(dpy, "XInputExtension", &XInput2OpCode, &event, &error))
|
|
|
|
{
|
|
|
|
int major = 2, minor = 0;
|
|
|
|
if(XIQueryVersion(dpy, &major, &minor) != BadRequest)
|
|
|
|
{
|
2016-02-20 18:23:46 +00:00
|
|
|
printf("XInput initialized version %d.%d\n", major, minor);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("XI2 not available. Server supports %d.%d\n", major, minor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("X Input extension not available.\n");
|
|
|
|
}
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
/*
|
|
|
|
TODO(casey): So, this is all one big clusterfuck I guess.
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
The problem here is that you want to be able to get input
|
|
|
|
from all possible devices that could be a mouse or keyboard
|
|
|
|
(or gamepad, or whatever). So you'd like to be able to
|
|
|
|
register events for XIAllDevices, so that when a new
|
|
|
|
input device is connected, you will start receiving
|
|
|
|
input from it automatically, without having to periodically
|
|
|
|
poll XIQueryDevice to see if a new device has appeared.
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
UNFORTUNATELY, this is not actually possible in Linux because
|
|
|
|
there was a bug in Xorg (as of early 2013, it is still not
|
|
|
|
fixed in most distributions people are using, AFAICT) which
|
|
|
|
makes the XServer return an error if you actually try to
|
|
|
|
do this :(
|
2015-11-16 16:15:45 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
But EVENTUALLY, if that shit gets fixed, then that is
|
|
|
|
the way this should work.
|
|
|
|
*/
|
2015-12-01 02:51:53 +00:00
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
#if 0
|
|
|
|
int DeviceCount;
|
|
|
|
XIDeviceInfo *DeviceInfo = XIQueryDevice(dpy, XIAllDevices, &DeviceCount);
|
|
|
|
{for(int32x DeviceIndex = 0;
|
|
|
|
DeviceIndex < DeviceCount;
|
|
|
|
++DeviceIndex)
|
2015-11-16 16:15:45 +00:00
|
|
|
{
|
2016-02-01 05:03:42 +00:00
|
|
|
XIDeviceInfo *Device = DeviceInfo + DeviceIndex;
|
|
|
|
printf("Device %d: %s\n", Device->deviceid, Device->name);
|
|
|
|
}}
|
|
|
|
XIFreeDeviceInfo(DeviceInfo);
|
2015-11-16 16:15:45 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
XIEventMask Mask = {0};
|
|
|
|
Mask.deviceid = XIAllDevices;
|
|
|
|
Mask.mask_len = XIMaskLen(XI_RawMotion);
|
|
|
|
size_t MaskSize = Mask.mask_len * sizeof(char unsigned);
|
|
|
|
Mask.mask = (char unsigned *)alloca(MaskSize);
|
|
|
|
memset(Mask.mask, 0, MaskSize);
|
|
|
|
if(Mask.mask)
|
|
|
|
{
|
|
|
|
XISetMask(Mask.mask, XI_ButtonPress);
|
|
|
|
XISetMask(Mask.mask, XI_ButtonRelease);
|
|
|
|
XISetMask(Mask.mask, XI_KeyPress);
|
|
|
|
XISetMask(Mask.mask, XI_KeyRelease);
|
|
|
|
XISetMask(Mask.mask, XI_Motion);
|
|
|
|
XISetMask(Mask.mask, XI_DeviceChanged);
|
|
|
|
XISetMask(Mask.mask, XI_Enter);
|
|
|
|
XISetMask(Mask.mask, XI_Leave);
|
|
|
|
XISetMask(Mask.mask, XI_FocusIn);
|
|
|
|
XISetMask(Mask.mask, XI_FocusOut);
|
|
|
|
XISetMask(Mask.mask, XI_HierarchyChanged);
|
|
|
|
XISetMask(Mask.mask, XI_PropertyEvent);
|
|
|
|
XISelectEvents(dpy, XWindow, &Mask, 1);
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
|
|
|
Mask.deviceid = XIAllMasterDevices;
|
|
|
|
memset(Mask.mask, 0, MaskSize);
|
|
|
|
XISetMask(Mask.mask, XI_RawKeyPress);
|
|
|
|
XISetMask(Mask.mask, XI_RawKeyRelease);
|
|
|
|
XISetMask(Mask.mask, XI_RawButtonPress);
|
|
|
|
XISetMask(Mask.mask, XI_RawButtonRelease);
|
|
|
|
XISetMask(Mask.mask, XI_RawMotion);
|
|
|
|
XISelectEvents(dpy, DefaultRootWindow(dpy), &Mask, 1);
|
|
|
|
}
|
2016-02-20 18:23:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// NOTE(allen): Annnndddd... here goes some guess work of my own.
|
|
|
|
Init_Input_Result result = {};
|
|
|
|
XIMStyle style;
|
|
|
|
XIMStyles *styles = 0;
|
|
|
|
i32 i, count;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
2016-02-20 18:23:46 +00:00
|
|
|
XSetLocaleModifiers("");
|
2016-02-21 17:59:47 +00:00
|
|
|
printf("is current locale supported?: %d\n", XSupportsLocale());
|
|
|
|
// TODO(inso): handle the case where it isn't supported somehow?
|
|
|
|
|
|
|
|
XSelectInput(
|
|
|
|
linuxvars.XDisplay,
|
|
|
|
linuxvars.XWindow,
|
|
|
|
ExposureMask |
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
PointerMotionMask |
|
|
|
|
FocusChangeMask |
|
2016-02-23 03:14:23 +00:00
|
|
|
StructureNotifyMask |
|
|
|
|
MappingNotify
|
2016-02-21 17:59:47 +00:00
|
|
|
);
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
result.input_method = XOpenIM(dpy, 0, 0, 0);
|
2016-02-21 17:59:47 +00:00
|
|
|
if (!result.input_method){
|
|
|
|
// NOTE(inso): Try falling back to the internal XIM implementation that
|
|
|
|
// should in theory always exist.
|
|
|
|
|
|
|
|
XSetLocaleModifiers("@im=none");
|
|
|
|
result.input_method = XOpenIM(dpy, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
if (result.input_method){
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
if (!XGetIMValues(result.input_method, XNQueryInputStyle, &styles, NULL) &&
|
|
|
|
styles){
|
|
|
|
result.best_style = 0;
|
|
|
|
count = styles->count_styles;
|
|
|
|
for (i = 0; i < count; ++i){
|
|
|
|
style = styles->supported_styles[i];
|
|
|
|
if (style == (XIMPreeditNothing | XIMStatusNothing)){
|
|
|
|
result.best_style = style;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.best_style){
|
|
|
|
XFree(styles);
|
|
|
|
|
|
|
|
result.xic =
|
|
|
|
XCreateIC(result.input_method, XNInputStyle, result.best_style,
|
|
|
|
XNClientWindow, XWindow,
|
|
|
|
XNFocusWindow, XWindow,
|
|
|
|
0, 0,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
result = {};
|
2016-02-21 17:59:47 +00:00
|
|
|
puts("Could not get minimum required input style");
|
2016-02-20 18:23:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
result = {};
|
2016-02-21 17:59:47 +00:00
|
|
|
puts("Could not open X Input Method");
|
2016-02-20 18:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
2016-02-01 05:03:42 +00:00
|
|
|
}
|
|
|
|
|
2016-02-21 17:59:47 +00:00
|
|
|
static void push_key(u8 code, u8 chr, u8 chr_nocaps, b8 (*mods)[CONTROL_KEY_COUNT], b32 is_hold){
|
|
|
|
i32 *count;
|
|
|
|
Key_Event_Data *data;
|
|
|
|
|
|
|
|
if(is_hold){
|
|
|
|
count = &linuxvars.key_data.hold_count;
|
|
|
|
data = linuxvars.key_data.hold;
|
|
|
|
} else {
|
|
|
|
count = &linuxvars.key_data.press_count;
|
|
|
|
data = linuxvars.key_data.press;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*count < KEY_INPUT_BUFFER_SIZE){
|
2016-02-23 03:14:23 +00:00
|
|
|
data[*count].keycode = code;
|
|
|
|
data[*count].character = chr;
|
|
|
|
data[*count].character_no_caps_lock = chr_nocaps;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
memcpy(data[*count].modifiers, *mods, sizeof(*mods));
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
++(*count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 05:03:42 +00:00
|
|
|
int
|
2016-02-11 17:17:52 +00:00
|
|
|
main(int argc, char **argv)
|
2016-02-01 05:03:42 +00:00
|
|
|
{
|
2016-02-20 18:23:46 +00:00
|
|
|
i32 COUNTER = 0;
|
2016-02-11 17:17:52 +00:00
|
|
|
linuxvars = {};
|
|
|
|
exchange_vars = {};
|
|
|
|
|
|
|
|
#if FRED_INTERNAL
|
|
|
|
linuxvars.internal_bubble.next = &linuxvars.internal_bubble;
|
|
|
|
linuxvars.internal_bubble.prev = &linuxvars.internal_bubble;
|
|
|
|
linuxvars.internal_bubble.flags = MEM_BUBBLE_SYS_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!LinuxLoadAppCode()){
|
|
|
|
// TODO(allen): Failed to load app code, serious problem.
|
|
|
|
return 99;
|
|
|
|
}
|
|
|
|
|
|
|
|
System_Functions system_;
|
|
|
|
System_Functions *system = &system_;
|
|
|
|
linuxvars.system = system;
|
|
|
|
LinuxLoadSystemCode();
|
|
|
|
|
|
|
|
memory_vars.vars_memory_size = Mbytes(2);
|
|
|
|
memory_vars.vars_memory = system_get_memory(memory_vars.vars_memory_size);
|
|
|
|
memory_vars.target_memory_size = Mbytes(512);
|
|
|
|
memory_vars.target_memory = system_get_memory(memory_vars.target_memory_size);
|
|
|
|
|
|
|
|
String current_directory;
|
|
|
|
i32 curdir_req, curdir_size;
|
|
|
|
char *curdir_mem;
|
|
|
|
|
|
|
|
curdir_req = (1 << 9);
|
|
|
|
curdir_mem = (char*)system_get_memory(curdir_req);
|
|
|
|
for (; getcwd(curdir_mem, curdir_req) == 0 && curdir_req < (1 << 13);){
|
|
|
|
system_free_memory(curdir_mem);
|
|
|
|
curdir_req *= 4;
|
|
|
|
curdir_mem = (char*)system_get_memory(curdir_req);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curdir_req >= (1 << 13)){
|
2016-02-20 18:23:46 +00:00
|
|
|
// TODO(allen): bullshit string APIs makin' me pissed
|
2016-02-11 17:17:52 +00:00
|
|
|
return 57;
|
|
|
|
}
|
2016-02-20 18:23:46 +00:00
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
for (curdir_size = 0; curdir_mem[curdir_size]; ++curdir_size);
|
|
|
|
|
|
|
|
current_directory = make_string(curdir_mem, curdir_size, curdir_req);
|
|
|
|
|
|
|
|
Command_Line_Parameters clparams;
|
|
|
|
clparams.argv = argv;
|
|
|
|
clparams.argc = argc;
|
|
|
|
|
|
|
|
char **files;
|
|
|
|
i32 *file_count;
|
|
|
|
i32 output_size;
|
|
|
|
|
|
|
|
output_size =
|
|
|
|
linuxvars.app.read_command_line(system,
|
|
|
|
&memory_vars,
|
|
|
|
current_directory,
|
|
|
|
&linuxvars.settings,
|
|
|
|
&files, &file_count,
|
|
|
|
clparams);
|
2016-02-20 18:23:46 +00:00
|
|
|
|
2016-02-11 17:17:52 +00:00
|
|
|
if (output_size > 0){
|
|
|
|
// TODO(allen): crt free version
|
|
|
|
printf("%.*s", output_size, (char*)memory_vars.target_memory);
|
|
|
|
}
|
|
|
|
if (output_size != 0) return 0;
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
sysshared_filter_real_files(files, file_count);
|
|
|
|
|
2016-02-21 17:59:47 +00:00
|
|
|
linuxvars.XDisplay = XOpenDisplay(0);
|
|
|
|
|
|
|
|
keycode_init(linuxvars.XDisplay, &linuxvars.key_codes);
|
2016-02-20 18:23:46 +00:00
|
|
|
|
|
|
|
#ifdef FRED_SUPER
|
|
|
|
char *custom_file_default = "4coder_custom.so";
|
|
|
|
char *custom_file;
|
|
|
|
if (linuxvars.settings.custom_dll) custom_file = linuxvars.settings.custom_dll;
|
|
|
|
else custom_file = custom_file_default;
|
|
|
|
|
|
|
|
linuxvars.custom = dlopen(custom_file, RTLD_LAZY);
|
|
|
|
if (!linuxvars.custom && custom_file != custom_file_default){
|
|
|
|
if (!linuxvars.settings.custom_dll_is_strict){
|
|
|
|
linuxvars.custom = dlopen(custom_file_default, RTLD_LAZY);
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 17:17:52 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
if (linuxvars.custom){
|
|
|
|
linuxvars.custom_api.get_bindings = (Get_Binding_Data_Function*)
|
|
|
|
dlsym(linuxvars.custom, "get_bindings");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO(allen): Setup background threads and locks
|
|
|
|
|
|
|
|
LinuxLoadRenderCode();
|
|
|
|
linuxvars.target.max = Mbytes(1);
|
|
|
|
linuxvars.target.push_buffer = (byte*)system_get_memory(linuxvars.target.max);
|
|
|
|
|
|
|
|
File_Slot file_slots[32];
|
|
|
|
sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0);
|
|
|
|
|
|
|
|
Font_Load_Parameters params[8];
|
|
|
|
sysshared_init_font_params(&linuxvars.fnt, params, ArrayCount(params));
|
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
|
|
|
|
// NOTE(allen): Here begins the linux screen setup stuff.
|
|
|
|
// Behold the true nature of this wonderful OS:
|
|
|
|
// (thanks again to Casey for providing this stuff)
|
|
|
|
Colormap cmap;
|
|
|
|
XSetWindowAttributes swa;
|
|
|
|
int WinWidth, WinHeight;
|
|
|
|
b32 window_setup_success = 0;
|
|
|
|
|
|
|
|
WinWidth = 800;
|
|
|
|
WinHeight = 600;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
if(linuxvars.XDisplay && GLXSupportsModernContexts(linuxvars.XDisplay))
|
2016-02-01 05:03:42 +00:00
|
|
|
{
|
2016-02-20 18:23:46 +00:00
|
|
|
int XScreenCount = ScreenCount(linuxvars.XDisplay);
|
2016-02-01 05:03:42 +00:00
|
|
|
for(int XScreenIndex = 0;
|
|
|
|
XScreenIndex < XScreenCount;
|
|
|
|
++XScreenIndex)
|
2016-02-20 18:23:46 +00:00
|
|
|
{
|
|
|
|
Screen *XScreen = ScreenOfDisplay(linuxvars.XDisplay, XScreenIndex);
|
|
|
|
|
|
|
|
i32 ScrnWidth, ScrnHeight;
|
|
|
|
ScrnWidth = WidthOfScreen(XScreen);
|
|
|
|
ScrnHeight = HeightOfScreen(XScreen);
|
|
|
|
|
|
|
|
if (ScrnWidth + 50 < WinWidth) WinWidth = ScrnWidth + 50;
|
|
|
|
if (ScrnHeight + 50 < WinHeight) WinHeight = ScrnHeight + 50;
|
|
|
|
|
|
|
|
glx_config_result Config = ChooseGLXConfig(linuxvars.XDisplay, XScreenIndex);
|
2016-02-01 05:03:42 +00:00
|
|
|
if(Config.Found)
|
|
|
|
{
|
2016-02-20 18:23:46 +00:00
|
|
|
swa.colormap = cmap = XCreateColormap(linuxvars.XDisplay,
|
|
|
|
RootWindow(linuxvars.XDisplay, Config.BestInfo.screen ),
|
2016-02-01 05:03:42 +00:00
|
|
|
Config.BestInfo.visual, AllocNone);
|
|
|
|
swa.background_pixmap = None;
|
|
|
|
swa.border_pixel = 0;
|
|
|
|
swa.event_mask = StructureNotifyMask;
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
linuxvars.XWindow =
|
|
|
|
XCreateWindow(linuxvars.XDisplay,
|
|
|
|
RootWindow(linuxvars.XDisplay, Config.BestInfo.screen),
|
|
|
|
0, 0, WinWidth, WinHeight,
|
|
|
|
0, Config.BestInfo.depth, InputOutput,
|
|
|
|
Config.BestInfo.visual,
|
|
|
|
CWBorderPixel|CWColormap|CWEventMask, &swa );
|
|
|
|
|
|
|
|
if(linuxvars.XWindow)
|
2016-02-01 05:03:42 +00:00
|
|
|
{
|
2016-02-20 18:23:46 +00:00
|
|
|
XStoreName(linuxvars.XDisplay, linuxvars.XWindow, "4coder-window");
|
|
|
|
XMapWindow(linuxvars.XDisplay, linuxvars.XWindow);
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
Init_Input_Result input_result =
|
|
|
|
InitializeXInput(linuxvars.XDisplay, linuxvars.XWindow);
|
|
|
|
|
|
|
|
linuxvars.input_method = input_result.input_method;
|
|
|
|
linuxvars.input_style = input_result.best_style;
|
2016-02-21 17:59:47 +00:00
|
|
|
linuxvars.input_context = input_result.xic;
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
b32 IsLegacy = false;
|
|
|
|
GLXContext GLContext =
|
2016-02-20 18:23:46 +00:00
|
|
|
InitializeOpenGLContext(linuxvars.XDisplay, linuxvars.XWindow, Config.BestConfig, IsLegacy);
|
2016-02-01 05:03:42 +00:00
|
|
|
|
|
|
|
XWindowAttributes WinAttribs;
|
2016-02-20 18:23:46 +00:00
|
|
|
if(XGetWindowAttributes(linuxvars.XDisplay, linuxvars.XWindow, &WinAttribs))
|
2016-02-01 05:03:42 +00:00
|
|
|
{
|
|
|
|
WinWidth = WinAttribs.width;
|
|
|
|
WinHeight = WinAttribs.height;
|
|
|
|
}
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
XRaiseWindow(linuxvars.XDisplay, linuxvars.XWindow);
|
|
|
|
XSync(linuxvars.XDisplay, False);
|
2016-02-01 05:03:42 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
window_setup_success = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 17:59:47 +00:00
|
|
|
XSetICFocus(linuxvars.input_context);
|
2016-02-20 18:23:46 +00:00
|
|
|
|
|
|
|
if (window_setup_success){
|
2016-02-23 03:14:23 +00:00
|
|
|
linuxvars.app.init(linuxvars.system, &linuxvars.target,
|
|
|
|
&memory_vars, &exchange_vars, &linuxvars.key_codes,
|
|
|
|
linuxvars.clipboard_contents, current_directory,
|
|
|
|
linuxvars.custom_api);
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
LinuxResizeTarget(WinWidth, WinHeight);
|
2016-02-23 03:14:23 +00:00
|
|
|
|
|
|
|
Atom WM_DELETE_WINDOW = XInternAtom(linuxvars.XDisplay, "WM_DELETE_WINDOW", False);
|
|
|
|
if(WM_DELETE_WINDOW != None){
|
|
|
|
XSetWMProtocols(linuxvars.XDisplay, linuxvars.XWindow, &WM_DELETE_WINDOW, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
b32 keep_running = 1;
|
|
|
|
|
|
|
|
while(keep_running)
|
2016-02-20 18:23:46 +00:00
|
|
|
{
|
2016-02-21 17:59:47 +00:00
|
|
|
XEvent PrevEvent = {};
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
while(XPending(linuxvars.XDisplay))
|
|
|
|
{
|
2016-02-21 17:59:47 +00:00
|
|
|
XEvent Event;
|
2016-02-20 18:23:46 +00:00
|
|
|
XNextEvent(linuxvars.XDisplay, &Event);
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
if (XFilterEvent(&Event, None) == True){
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
switch (Event.type){
|
2016-02-21 17:59:47 +00:00
|
|
|
case KeyPress: {
|
|
|
|
b32 is_hold =
|
|
|
|
PrevEvent.type == KeyRelease &&
|
|
|
|
PrevEvent.xkey.time == Event.xkey.time &&
|
|
|
|
PrevEvent.xkey.keycode == Event.xkey.keycode;
|
|
|
|
|
|
|
|
b8 mods[CONTROL_KEY_COUNT] = {};
|
|
|
|
if(Event.xkey.state & ShiftMask) mods[CONTROL_KEY_SHIFT] = 1;
|
|
|
|
if(Event.xkey.state & ControlMask) mods[CONTROL_KEY_CONTROL] = 1;
|
|
|
|
if(Event.xkey.state & LockMask) mods[CONTROL_KEY_CAPS] = 1;
|
|
|
|
if(Event.xkey.state & Mod1Mask) mods[CONTROL_KEY_ALT] = 1;
|
|
|
|
// NOTE(inso): mod5 == AltGr
|
2016-02-23 03:14:23 +00:00
|
|
|
// if(Event.xkey.state & Mod5Mask) mods[CONTROL_KEY_ALT] = 1;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
KeySym keysym = NoSymbol;
|
2016-02-23 03:14:23 +00:00
|
|
|
char buff[32], no_caps_buff[32];
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
// NOTE(inso): Turn ControlMask off like the win32 code does.
|
|
|
|
if(mods[CONTROL_KEY_CONTROL] && !mods[CONTROL_KEY_ALT]){
|
|
|
|
Event.xkey.state &= ~(ControlMask);
|
|
|
|
}
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
// TODO(inso): Use one of the Xutf8LookupString funcs to allow for non-ascii chars
|
|
|
|
XLookupString(&Event.xkey, buff, sizeof(buff), &keysym, NULL);
|
|
|
|
|
2016-02-23 03:14:23 +00:00
|
|
|
Event.xkey.state &= ~LockMask;
|
|
|
|
XLookupString(&Event.xkey, no_caps_buff, sizeof(no_caps_buff), NULL, NULL);
|
|
|
|
|
2016-02-21 17:59:47 +00:00
|
|
|
u8 key = keycode_lookup(Event.xkey.keycode);
|
|
|
|
|
|
|
|
if(key){
|
2016-02-23 03:14:23 +00:00
|
|
|
push_key(key, 0, 0, &mods, is_hold);
|
2016-02-21 17:59:47 +00:00
|
|
|
} else {
|
|
|
|
key = buff[0] & 0xFF;
|
|
|
|
if(key < 128){
|
2016-02-23 03:14:23 +00:00
|
|
|
u8 no_caps_key = no_caps_buff[0] & 0xFF;
|
|
|
|
if(key == '\r') key = '\n';
|
|
|
|
if(no_caps_key == '\r') no_caps_key = '\n';
|
|
|
|
push_key(key, key, no_caps_key, &mods, is_hold);
|
|
|
|
} else {
|
|
|
|
push_key(0, 0, 0, &mods, is_hold);
|
2016-02-21 17:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case MotionNotify: {
|
|
|
|
linuxvars.mouse_data.x = Event.xmotion.x;
|
|
|
|
linuxvars.mouse_data.y = Event.xmotion.y;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case ButtonPress: {
|
|
|
|
switch(Event.xbutton.button){
|
|
|
|
case Button1: {
|
|
|
|
linuxvars.mouse_data.left_button_pressed = 1;
|
|
|
|
linuxvars.mouse_data.left_button = 1;
|
|
|
|
} break;
|
|
|
|
case Button3: {
|
|
|
|
linuxvars.mouse_data.right_button_pressed = 1;
|
|
|
|
linuxvars.mouse_data.right_button = 1;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case ButtonRelease: {
|
|
|
|
switch(Event.xbutton.button){
|
|
|
|
case Button1: {
|
|
|
|
linuxvars.mouse_data.left_button_released = 1;
|
|
|
|
linuxvars.mouse_data.left_button = 0;
|
|
|
|
} break;
|
|
|
|
case Button3: {
|
|
|
|
linuxvars.mouse_data.right_button_released = 1;
|
|
|
|
linuxvars.mouse_data.right_button = 0;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case EnterNotify: {
|
|
|
|
linuxvars.mouse_data.out_of_window = 0;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case LeaveNotify: {
|
|
|
|
linuxvars.mouse_data.out_of_window = 1;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case FocusIn:
|
|
|
|
case FocusOut: {
|
|
|
|
linuxvars.mouse_data.left_button = 0;
|
|
|
|
linuxvars.mouse_data.right_button = 0;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case ConfigureNotify: {
|
|
|
|
i32 w = Event.xconfigure.width, h = Event.xconfigure.height;
|
|
|
|
|
|
|
|
if(w != linuxvars.target.width || h != linuxvars.target.height){
|
|
|
|
LinuxResizeTarget(Event.xconfigure.width, Event.xconfigure.height);
|
|
|
|
}
|
|
|
|
}break;
|
2016-02-23 03:14:23 +00:00
|
|
|
|
|
|
|
case MappingNotify: {
|
|
|
|
if(Event.xmapping.request == MappingModifier || Event.xmapping.request == MappingKeyboard){
|
|
|
|
XRefreshKeyboardMapping(&Event.xmapping);
|
|
|
|
keycode_init(linuxvars.XDisplay, &linuxvars.key_codes);
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case ClientMessage: {
|
|
|
|
if ((Atom)Event.xclient.data.l[0] == WM_DELETE_WINDOW) {
|
|
|
|
keep_running = false;
|
|
|
|
}
|
|
|
|
}break;
|
2016-02-20 18:23:46 +00:00
|
|
|
}
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
PrevEvent = Event;
|
2016-02-20 18:23:46 +00:00
|
|
|
}
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
b32 redraw = 1;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
Key_Input_Data input_data;
|
|
|
|
Mouse_State mouse;
|
|
|
|
Application_Step_Result result;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
input_data = linuxvars.key_data;
|
|
|
|
mouse = linuxvars.mouse_data;
|
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
|
|
|
|
result.redraw = redraw;
|
|
|
|
result.lctrl_lalt_is_altgr = 0;
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
linuxvars.app.step(linuxvars.system,
|
|
|
|
&linuxvars.key_codes,
|
|
|
|
&input_data,
|
|
|
|
&mouse,
|
|
|
|
&linuxvars.target,
|
|
|
|
&memory_vars,
|
|
|
|
&exchange_vars,
|
|
|
|
linuxvars.clipboard_contents,
|
|
|
|
1, linuxvars.first, redraw,
|
|
|
|
&result);
|
2016-02-21 17:59:47 +00:00
|
|
|
|
2016-02-20 18:23:46 +00:00
|
|
|
if (result.redraw){
|
|
|
|
LinuxRedrawTarget();
|
|
|
|
}
|
2016-02-21 17:59:47 +00:00
|
|
|
|
|
|
|
linuxvars.key_data = {};
|
|
|
|
linuxvars.mouse_data.left_button_pressed = 0;
|
|
|
|
linuxvars.mouse_data.left_button_released = 0;
|
|
|
|
linuxvars.mouse_data.right_button_pressed = 0;
|
|
|
|
linuxvars.mouse_data.right_button_released = 0;
|
2015-11-16 16:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|