// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movq %r8, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x10(%rsp), %rax
movq %r8, (%rax)
movq %r9, 0x8(%rax)
leaq 0x37eec(%rip), %rax     # 0x406e0
movq %rax, (%rdi)
movq %rsi, 0x10(%rdi)
movw $0x1, 0x18(%rdi)
andq $0x0, 0x50(%rdi)
leaq 0x40d(%rip), %rax       # 0x8c1a
movq %rax, 0x58(%rdi)
leaq 0x6e6(%rip), %rax       # 0x8efe
movq %rax, 0x68(%rdi)
movq %rdi, 0x60(%rdi)
andq $0x0, 0x70(%rdi)
movl %ecx, %ebp
leaq 0x6d6(%rip), %rax       # 0x8f04
movq %rax, 0x2a0(%rdi)
movq %rax, 0x298(%rdi)
andq $0x0, 0x2a8(%rdi)
movl %edx, %r13d
leaq 0x50(%rdi), %rax
movq %rax, (%rsp)
leaq 0x6b0(%rip), %rax       # 0x8f06
movq %rax, 0x2b8(%rdi)
movq %rax, 0x2b0(%rdi)
andq $0x0, 0x2c0(%rdi)
pushq $0xd
popq %rdi
pushq $0x1
popq %rsi
callq 0x3420
movq %rbx, 0x38ada(%rip)     # 0x41358
movq 0x38ac3(%rip), %rdi     # 0x41348
movq %rdi, 0x8(%rbx)
movl $0x20806f, %edx         # imm = 0x20806F
movq %r14, %rsi
callq 0x31d0
leaq 0x48(%rsp), %rdx
movq $0x38, (%rdx)
movl %r13d, 0x20(%rdx)
movl %r13d, 0x18(%rdx)
movl %r13d, 0x10(%rdx)
movl %ebp, 0x24(%rdx)
movl %ebp, 0x1c(%rdx)
movl %ebp, 0x14(%rdx)
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x3130
movq 0x8(%rbx), %rdi
leaq 0x20(%rbx), %r8
leaq 0x37e5e(%rip), %rsi     # 0x40730
pushq $0x6
popq %rdx
xorl %ecx, %ecx
callq 0x34f0
movups 0x28(%rbx), %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
movq 0x8(%rbx), %rdi
pushq $0x2
popq %rcx
movq %r14, %rsi
callq 0x3190
callq 0x3510
cltq
leaq 0x8(%rsp), %r10
movq %rax, (%r10)
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rdx
pushq $0x6
popq %rcx
pushq $0x20
popq %r8
movq %r14, %rsi
xorl %r9d, %r9d
pushq $0x1
pushq %r10
callq 0x32b0
popq %rcx
popq %rdx
movq 0x8(%rbx), %rdi
movq 0x40(%rbx), %rdx
movq 0x48(%rbx), %rcx
movq %r12, %rax
shrq $0x38, %rax
xorl $0xf, %eax
testq %r12, %r12
leaq 0x10(%rsp), %rsi
cmovnsq %rsi, %r15
cmovnsl %eax, %r12d
pushq $0x8
popq %r8
movq %r14, %rsi
xorl %r9d, %r9d
pushq %r12
pushq %r15
callq 0x32b0
popq %rcx
popq %rdx
movq 0x389e0(%rip), %rdi     # 0x41348
movq %r14, %rsi
callq 0x33c0
movq %rbx, %rdi
callq 0x89d0
movq 0x389c9(%rip), %rax     # 0x41348
movl 0x10(%rax), %esi
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x8aac
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x8abc
movq %rbx, %rdi
callq 0x8b1a
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop