// File: /workspace/github_c_makefile_star2_O1/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 0x96c2(%rip), %rbx      # 0x10900
movq (%rbx), %rdi
callq 0x42b0
movq %rax, 0x94eb(%rip)      # 0x10738
testq %rax, %rax
je 0x7432
movq $0x0, 0x966f(%rip) # 0x108d0
leaq 0x25e1(%rip), %rdi      # 0x9849
callq 0x4670
xorl %r14d, %r14d
leaq 0x94c1(%rip), %r15      # 0x10738
leaq 0x45e2(%rip), %r12      # 0xb860
movq 0x94b3(%rip), %rdi      # 0x10738
movslq (%r14,%r12), %rsi
addq %r12, %rsi
xorl %edx, %edx
callq 0x45d0
movq %rax, 0x8(%r15,%r14,2)
addq $0x4, %r14
cmpq $0xac, %r14
jne 0x727e
movq 0x948c(%rip), %rdi      # 0x10738
movq 0x8(%rbx), %rsi
callq 0x4560
movq %rax, 0x95dc(%rip)      # 0x10898
testq %rax, %rax
jne 0x72db
movq 0x9470(%rip), %rdi      # 0x10738
leaq 0x47af(%rip), %rsi      # 0xba7e
callq 0x4560
movq %rax, 0x95bd(%rip)      # 0x10898
cmpq $0x0, 0x95b5(%rip)      # 0x10898
je 0x7437
movq 0x9448(%rip), %rdi      # 0x10738
movl $0x34, %esi
callq 0x4040
movq %rax, 0x959f(%rip)      # 0x108a0
movq 0x9430(%rip), %rdi      # 0x10738
movl $0x5a, %esi
callq 0x4040
movq %rax, 0x958f(%rip)      # 0x108a8
leaq 0x95c8(%rip), %r14      # 0x108e8
movl $0x0, (%r14)
movq 0x940a(%rip), %rdi      # 0x10738
callq 0x45c0
movq %rax, %rbx
xorl %ebp, %ebp
movl (%rbx), %eax
testl %eax, %eax
je 0x737d
movl $0x1, %r15d
movl %ebp, %ecx
shll %cl, %r15d
xorl %r12d, %r12d
movq 0x8(%rbx), %rcx
imull %ebp, %eax
addl %r12d, %eax
movb (%rcx,%rax), %r13b
movq 0x93d7(%rip), %rdi      # 0x10738
movl $0xff7f, %esi           # imm = 0xFF7F
callq 0x4610
cmpb %al, %r13b
jne 0x7373
movl %r15d, (%r14)
incl %r12d
movl (%rbx), %eax
cmpl %eax, %r12d
jb 0x734c
incl %ebp
cmpl $0x8, %ebp
jne 0x7338
movq %rbx, %rdi
callq 0x41d0
movq 0x93a5(%rip), %rdi      # 0x10738
leaq 0x951a(%rip), %rsi      # 0x108b4
leaq 0x4(%rsp), %rdx
callq 0x41a0
movl %eax, 0x9506(%rip)      # 0x108b0
movq 0x9387(%rip), %rdi      # 0x10738
leaq 0x9504(%rip), %rsi      # 0x108bc
movq %rsp, %rdx
callq 0x4210
movl %eax, 0x94f2(%rip)      # 0x108b8
movq 0x936b(%rip), %rax      # 0x10738
movslq 0xe4(%rax), %rax
movl %eax, 0x94e6(%rip)      # 0x108c0
testq %rax, %rax
js 0x743c
imulq $0x78, %rax, %rdi
callq 0xa0b0
movq %rax, 0x94d9(%rip)      # 0x108c8
cmpl $0x0, 0x94ca(%rip)      # 0x108c0
jle 0x7423
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x94c4(%rip), %rdi      # 0x108c8
movl %r14d, (%rdi,%rbx)
addq %rbx, %rdi
callq 0x8d74
incq %r14
movslq 0x94a6(%rip), %rax      # 0x108c0
addq $0x78, %rbx
cmpq %rax, %r14
jl 0x73fd
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x484f
callq 0x482a
callq 0x4805