// File: /workspace/github_cpp_makefile_star2_O3/Alcaro[P]bridges/arlib/game-x11.cpp
// Function: gameview_x11::gameview_x11(unsigned long, unsigned int, unsigned int, cstring)
gameview_x11(Window window, uint32_t width, uint32_t height, cstring title) : window(window)
{
	signal(SIGPIPE, SIG_IGN);
	
	g_gameview = this;
	display = window_x11.display;
	
	XSelectInput(display, window, ExposureMask|FocusChangeMask|KeyPressMask|KeyReleaseMask|
	                              PointerMotionMask|ButtonPressMask|ButtonReleaseMask|LeaveWindowMask);
	
	XSizeHints hints;
	hints.flags = PSize|PMinSize|PMaxSize;
	hints.width = hints.min_width = hints.max_width = width;
	hints.height = hints.min_height = hints.max_height = height;
	XSetWMNormalHints(display, window, &hints);
	
	static const char * const atom_names[] = {
#define ATOM(name) #name,
		X11_ATOMS
#undef ATOM
	};
	XInternAtoms(display, (char**)atom_names, ARRAY_SIZE(atom_names), false, (Atom*)&atoms);
	
	Atom protocols[2] = { atoms.WM_DELETE_WINDOW, atoms._NET_WM_PING, };
	XSetWMProtocols(display, window, protocols, ARRAY_SIZE(protocols));
	
	long pid = getpid(); // gotta love how X11 insists that long is 32 bits. the C builtin types are ridiculous
	XChangeProperty(display, window, atoms._NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, (uint8_t*)&pid, 1);
	
	XChangeProperty(display, window, atoms._NET_WM_NAME, atoms.UTF8_STRING, 8, PropModeReplace, title.bytes().ptr(), title.length());
	
	XMapWindow(window_x11.display, window);
	
	calc_keyboard_map();
	
	runloop2::await_read(ConnectionNumber(window_x11.display)).then(&wait);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %r13
movq %r8, %r12
movl %ecx, %ebp
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x20(%rsp), %rax
movq %r8, (%rax)
movq %r9, 0x8(%rax)
leaq 0x3b248(%rip), %rax     # 0x45710
movq %rax, (%rdi)
movq %rsi, 0x10(%rdi)
movw $0x1, 0x18(%rdi)
leaq 0x50(%rdi), %rax
movq %rax, (%rsp)
xorl %ecx, %ecx
movq %rcx, 0x50(%rdi)
leaq 0x3e2(%rip), %rax       # 0xa8cc
movq %rax, 0x58(%rdi)
leaq 0x705(%rip), %rax       # 0xabfa
movq %rax, 0x68(%rdi)
movq %rdi, 0x60(%rdi)
movq %rcx, 0x70(%rdi)
leaq 0x6f8(%rip), %rax       # 0xac00
movq %rax, 0x2a0(%rdi)
movq %rax, 0x298(%rdi)
movq %rcx, 0x2a8(%rdi)
leaq 0x6de(%rip), %rax       # 0xac02
movq %rax, 0x2b8(%rdi)
movq %rax, 0x2b0(%rdi)
movq %rcx, 0x2c0(%rdi)
movl $0x1, %esi
movl $0xd, %edi
callq 0x3420
movq %r14, 0x3be09(%rip)     # 0x46358
movq 0x3bdf2(%rip), %rdi     # 0x46348
movq %rdi, 0x8(%r14)
movl $0x20806f, %edx         # imm = 0x20806F
movq %r15, %rsi
callq 0x31d0
leaq 0x48(%rsp), %rdx
movq $0x38, (%rdx)
movl %ebx, 0x20(%rdx)
movl %ebx, 0x18(%rdx)
movl %ebx, 0x10(%rdx)
movl %ebp, 0x24(%rdx)
movl %ebp, 0x1c(%rdx)
movl %ebp, 0x14(%rdx)
movq 0x8(%r14), %rdi
movq %r15, %rsi
callq 0x3130
movq 0x8(%r14), %rdi
leaq 0x20(%r14), %r8
leaq 0x3b1c0(%rip), %rsi     # 0x45760
movl $0x6, %edx
xorl %ecx, %ecx
callq 0x34f0
movups 0x28(%r14), %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
movq 0x8(%r14), %rdi
movq %r15, %rsi
movl $0x2, %ecx
callq 0x3190
callq 0x3510
cltq
leaq 0x18(%rsp), %r10
movq %rax, (%r10)
movq 0x8(%r14), %rdi
movq 0x38(%r14), %rdx
movl $0x6, %ecx
movq %r15, %rsi
movl $0x20, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq %r10
callq 0x32b0
addq $0x10, %rsp
movq 0x8(%r14), %rdi
movq 0x40(%r14), %rdx
movq 0x48(%r14), %rcx
movq %r13, %rax
shrq $0x38, %rax
xorl $0xf, %eax
testq %r13, %r13
leaq 0x20(%rsp), %rsi
cmovnsq %rsi, %r12
cmovnsl %eax, %r13d
movq %r15, %rsi
movl $0x8, %r8d
xorl %r9d, %r9d
pushq %r13
pushq %r12
callq 0x32b0
addq $0x10, %rsp
movq 0x3bd03(%rip), %rdi     # 0x46348
movq %r15, %rsi
callq 0x33c0
movq %r14, %rdi
callq 0xa6a8
movq 0x3bcec(%rip), %rax     # 0x46348
movl 0x10(%rax), %esi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1709a
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0xa78a
xorl %eax, %eax
cmpq %rax, 0x8(%rbx)
je 0xa68a
cmpq $0x0, 0x8(%rsp)
je 0xa696
leaq 0x24faa(%rip), %rdi     # 0x2f63b
callq 0x8683
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq