// File: /workspace/github_c_makefile_star2_O2/mati75[P]evilwm/display.c
// Function: display_open
void display_open(void) {
	LOG_ENTER("display_open()");

	display.dpy = XOpenDisplay(option.display);
	if (!display.dpy) {
		LOG_ERROR("can't open display %s\n", option.display);
		exit(1);
	}
	display.info_window = None;

	XSetErrorHandler(handle_xerror);

	// While debugging, synchronous behaviour may be desirable:
	//XSynchronize(display.dpy, True);

	// Sanity check that there's a name for each atom in the enum:
	assert(NUM_ATOMS == (sizeof(atom_list)/sizeof(atom_list[0])));

	// Get or create all required atom IDs
	for (int i = 0; i < NUM_ATOMS; i++) {
		display.atom[i] = XInternAtom(display.dpy, atom_list[i], False);
	}

	// Get the font used for window info
	display.font = XLoadQueryFont(display.dpy, option.font);
	if (!display.font) {
		LOG_DEBUG("failed to load specified font, trying default: %s\n", DEF_FONT);
		display.font = XLoadQueryFont(display.dpy, DEF_FONT);
	}
	if (!display.font) {
		LOG_ERROR("couldn't find a font to use: try starting with -fn fontname\n");
		exit(1);
	}

	// Cursors used for different actions
	display.move_curs = XCreateFontCursor(display.dpy, XC_fleur);
	display.resize_curs = XCreateFontCursor(display.dpy, XC_plus);

	// Find out which modifier is NumLock - for every grab, we need to also
	// grab the combination where this is set.
	numlockmask = 0;
	XModifierKeymap *modmap = XGetModifierMapping(display.dpy);
	for (unsigned i = 0; i < 8; i++) {
		for (unsigned j = 0; j < (unsigned)modmap->max_keypermod; j++) {
			if (modmap->modifiermap[i*modmap->max_keypermod+j] == XKeysymToKeycode(display.dpy, XK_Num_Lock)) {
				numlockmask = (1<<i);
				LOG_DEBUG("XK_Num_Lock is (1<<0x%02x)\n", i);
			}
		}
	}
	XFreeModifiermap(modmap);

	// SHAPE extension?
#ifdef SHAPE
	{
		int e_dummy;
		display.have_shape = XShapeQueryExtension(display.dpy, &display.shape_event, &e_dummy);
	}
#endif
	// XRandR extension?
#ifdef RANDR
	{
		int e_dummy;
		display.have_randr = XRRQueryExtension(display.dpy, &display.randr_event_base, &e_dummy);
		if (!display.have_randr) {
			LOG_DEBUG("XRandR is not supported on this display.\n");
		}
	}
#endif

	// Initialise screens
	display.nscreens = ScreenCount(display.dpy);
	if (display.nscreens < 0) {
		LOG_ERROR("Can't count screens\n");
		exit(1);
	}
	display.screens = xmalloc(display.nscreens * sizeof(struct screen));
	for (int i = 0; i < display.nscreens; i++) {
		display.screens[i].screen = i;
		screen_init(&display.screens[i]);
	}

	LOG_LEAVE();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x8b52(%rip), %rbx      # 0xf8f0
movq (%rbx), %rdi
callq 0x42b0
movq %rax, 0x897b(%rip)      # 0xf728
testq %rax, %rax
je 0x6f73
andq $0x0, 0x8b02(%rip)      # 0xf8c0
leaq 0x23f1(%rip), %rdi      # 0x91b6
callq 0x4670
xorl %r14d, %r14d
leaq 0x3a8c(%rip), %r15      # 0xa860
leaq 0x894d(%rip), %r12      # 0xf728
movq 0x8946(%rip), %rdi      # 0xf728
cmpq $0xac, %r14
je 0x6e04
movslq (%r14,%r15), %rsi
addq %r15, %rsi
xorl %edx, %edx
callq 0x45d0
movq %rax, 0x8(%r12,%r14,2)
addq $0x4, %r14
jmp 0x6ddb
movq 0x8(%rbx), %rsi
callq 0x4560
movq %rax, 0x8a74(%rip)      # 0xf888
testq %rax, %rax
jne 0x6e3c
movq 0x8908(%rip), %rdi      # 0xf728
leaq 0x3c51(%rip), %rsi      # 0xaa78
callq 0x4560
movq %rax, 0x8a55(%rip)      # 0xf888
testq %rax, %rax
je 0x6fa5
movq 0x88e5(%rip), %rdi      # 0xf728
pushq $0x34
popq %rsi
callq 0x4040
movq %rax, 0x8a3e(%rip)      # 0xf890
movq 0x88cf(%rip), %rdi      # 0xf728
pushq $0x5a
popq %rsi
callq 0x4040
movq %rax, 0x8a30(%rip)      # 0xf898
leaq 0x8a69(%rip), %r14      # 0xf8d8
andl $0x0, (%r14)
movq 0x88ae(%rip), %rdi      # 0xf728
callq 0x45c0
movq %rax, %rbx
xorl %ebp, %ebp
cmpl $0x8, %ebp
je 0x6ecc
pushq $0x1
popq %r12
movl %ebp, %ecx
shll %cl, %r12d
xorl %r13d, %r13d
movl (%rbx), %eax
cmpl %eax, %r13d
jae 0x6ec8
movq 0x8(%rbx), %rcx
imull %ebp, %eax
addl %r13d, %eax
movb (%rcx,%rax), %r15b
movq 0x8877(%rip), %rdi      # 0xf728
movl $0xff7f, %esi           # imm = 0xFF7F
callq 0x4610
cmpb %al, %r15b
jne 0x6ec3
movl %r12d, (%r14)
incl %r13d
jmp 0x6e95
incl %ebp
jmp 0x6e84
movq %rbx, %rdi
callq 0x41d0
movq 0x884d(%rip), %rdi      # 0xf728
leaq 0x89c2(%rip), %rsi      # 0xf8a4
leaq 0x4(%rsp), %rdx
callq 0x41a0
movl %eax, 0x89ae(%rip)      # 0xf8a0
movq 0x882f(%rip), %rdi      # 0xf728
leaq 0x89ac(%rip), %rsi      # 0xf8ac
movq %rsp, %rdx
callq 0x4210
movl %eax, 0x899a(%rip)      # 0xf8a8
movq 0x8813(%rip), %rax      # 0xf728
movslq 0xe4(%rax), %rax
movl %eax, 0x898e(%rip)      # 0xf8b0
testq %rax, %rax
js 0x6f90
imulq $0x78, %rax, %rdi
callq 0x99bc
movq %rax, 0x8981(%rip)      # 0xf8b8
xorl %ebx, %ebx
xorl %r14d, %r14d
movslq 0x896d(%rip), %rax      # 0xf8b0
cmpq %rax, %r14
jge 0x6f64
movq 0x8969(%rip), %rdi      # 0xf8b8
movl %r14d, (%rdi,%rbx)
addq %rbx, %rdi
callq 0x8800
incq %r14
addq $0x78, %rbx
jmp 0x6f3c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8076(%rip), %rax      # 0xeff0
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x34da(%rip), %rsi      # 0xa461
xorl %eax, %eax
callq 0x4700
jmp 0x6fc1
movq 0x8059(%rip), %rax      # 0xeff0
movq (%rax), %rcx
leaq 0x3514(%rip), %rdi      # 0xa4b5
pushq $0x14
jmp 0x6fb8
movq 0x8044(%rip), %rax      # 0xeff0
movq (%rax), %rcx
leaq 0x34c2(%rip), %rdi      # 0xa478
pushq $0x3c
popq %rsi
pushq $0x1
popq %rdx
callq 0x46b0
pushq $0x1
popq %rdi
callq 0x4160