// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/gui/window/backends/xlib/windowxlib.cpp
// Function: smooth::GUI::WindowXLib::Open(smooth::String const&, smooth::GUI::Point const&, smooth::GUI::Size const&, int)
S::Int S::GUI::WindowXLib::Open(const String &title, const Point &pos, const Size &size, Int iFlags)
{
	static Atom	 wmDeleteWindowAtom    = XInternAtom(display, "WM_DELETE_WINDOW", False);

	static Atom	 wmPingAtom	       = XInternAtom(display, "_NET_WM_PING", False);
	static Atom	 wmIconAtom	       = XInternAtom(display, "_NET_WM_ICON", False);

	static Atom	 windowStateAtom       = XInternAtom(display, "_NET_WM_STATE", False);
	static Atom	 windowStateAboveAtom  = XInternAtom(display, "_NET_WM_STATE_ABOVE", False);
	static Atom	 windowStateModalAtom  = XInternAtom(display, "_NET_WM_STATE_MODAL", False);

	static Atom	 windowTypeAtom	       = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
	static Atom	 windowTypeNormalAtom  = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
	static Atom	 windowTypeDialogAtom  = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
	static Atom	 windowTypeUtilityAtom = XInternAtom(display, "_NET_WM_WINDOW_TYPE_UTILITY", False);

	flags	     = iFlags;
	restoredRect = Rect(pos, size);

	XSetWindowAttributes	 attributes;

	attributes.background_pixel  = Setup::BackgroundColor;
	attributes.bit_gravity	     = NorthWestGravity;
	attributes.save_under	     = False;
	attributes.override_redirect = False;

	if (flags & WF_NOTITLE	   ) attributes.override_redirect = True;
	if (flags & WF_TOPMOST	    &&
	    flags & WF_NOTASKBUTTON &&
	    flags & WF_THINBORDER  ) attributes.save_under = True;

	wnd = XCreateWindow(display, RootWindow(display, 0), pos.x, pos.y, Math::Round(size.cx * fontSize) + sizeModifier.cx, Math::Round(size.cy * fontSize) + sizeModifier.cy, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWBitGravity | CWSaveUnder | CWOverrideRedirect, &attributes);

	if (wnd != None)
	{
		/* Create input window.
		 */
		if (im != NIL)
		{
			XLockDisplay(display);

			iwnd = XCreateWindow(display, wnd, 0, 0, 1, 1, 0, CopyFromParent, InputOnly, CopyFromParent, 0, NIL);

			XMapWindow(display, iwnd);

			XUnlockDisplay(display);
		}

		/* Select event types we want to receive.
		 */
		XSelectInput(display, wnd, ExposureMask | FocusChangeMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask);

		/* Opt in to the WM_DELETE_WINDOW and _NET_WM_PING protocols.
		 */
		Atom	 protocols[2] = { wmDeleteWindowAtom, wmPingAtom };

		XSetWMProtocols(display, wnd, protocols, 2);

		/* Process the CreateNotify event again, as GetWindowBackend
		 * cannot find the correct backend until wnd is set.
		 */
		XEvent	 e;

		e.type = CreateNotify;

		ProcessSystemMessages(&e);

		/* Create drawing surface.
		 */
		if ((flags & WF_THINBORDER) || (flags & WF_NORESIZE)) drawSurface = new Surface((Void *) wnd, size * fontSize + sizeModifier);
		else						      drawSurface = new Surface((Void *) wnd);

		drawSurface->SetSize(size * fontSize + sizeModifier);

		/* Set application name.
		 */
		for (Int i = 0; i < Object::GetNOfObjects(); i++)
		{
			if (Object::GetNthObject(i)->GetObjectType() != Application::classID) continue;

			Application	*application = (Application *) Object::GetNthObject(i);
			XClassHint	*classHint   = XAllocClassHint();

			classHint->res_name  = application->GetText();
			classHint->res_class = application->GetText();

			XSetClassHint(display, wnd, classHint);
			XFree(classHint);

			break;
		}

		/* Set window title.
		 */
		SetTitle(title);

		/* Set icon.
		 */
		if (sysIcon != NIL)
		{
			XChangeProperty(display, wnd, wmIconAtom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) sysIcon, sysIconSize);
		}

		/* Set minimum and maximum size.
		 */
		if (flags & WF_NORESIZE)
		{
			minSize = size;
			maxSize = size;
		}

		UpdateWMNormalHints();

		/* Configure window type.
		 */
		if ((flags & WF_TOPMOST) && (flags & WF_NOTASKBUTTON) && (flags & WF_THINBORDER))
		{
			XChangeProperty(display, wnd, windowTypeAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *) &windowTypeUtilityAtom, 1);
		}
		else if (flags & WF_TOPMOST)
		{
			XChangeProperty(display, wnd, windowTypeAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *) &windowTypeDialogAtom, 1);
			XChangeProperty(display, wnd, windowStateAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *) &windowStateAboveAtom, 1);
		}
		else if (flags & WF_MODAL)
		{
			XChangeProperty(display, wnd, windowTypeAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *) &windowTypeDialogAtom, 1);
			XChangeProperty(display, wnd, windowStateAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *) &windowStateModalAtom, 1);
		}
		else
		{
			XChangeProperty(display, wnd, windowTypeAtom, XA_ATOM, 32, PropModeReplace, (unsigned char *) &windowTypeNormalAtom, 1);
		}

		/* Set transient hint.
		 */
		Widget	*container = Window::GetWindow((Void *) wnd)->GetContainer();

		if (container != NIL)
		{
			Window		*parent = container->GetContainerWindow();
			WindowXLib	*leader = FindLeaderWindow();

			if	(parent != NIL) XSetTransientForHint(display, wnd, (X11::Window) parent->GetSystemWindow());
			else if (leader != NIL) XSetTransientForHint(display, wnd, leader->wnd);
		}

		/* Enable dropping files if requested.
		 */
		if (enableDropFiles) EnableDropFiles(True);

		return Success();
	}

	return Error();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movb 0xb2940(%rip), %al      # 0x16cf78
testb %al, %al
je 0xbac02
movb 0xb2942(%rip), %al      # 0x16cf88
testb %al, %al
je 0xbac43
movb 0xb2944(%rip), %al      # 0x16cf98
testb %al, %al
je 0xbac84
movb 0xb2946(%rip), %al      # 0x16cfa8
testb %al, %al
je 0xbacc5
movb 0xb2948(%rip), %al      # 0x16cfb8
testb %al, %al
je 0xbad06
movb 0xb294a(%rip), %al      # 0x16cfc8
testb %al, %al
je 0xbad47
movb 0xb294c(%rip), %al      # 0x16cfd8
testb %al, %al
je 0xbad88
movb 0xb294e(%rip), %al      # 0x16cfe8
testb %al, %al
je 0xbadc9
movb 0xb2950(%rip), %al      # 0x16cff8
testb %al, %al
je 0xbae0a
movb 0xb2952(%rip), %al      # 0x16d008
testb %al, %al
je 0xbae4b
movl %ebp, 0x1b4(%rbx)
movq (%r12), %xmm0
movq (%r14), %xmm1
paddd %xmm0, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqu %xmm0, 0x1a4(%rbx)
movq 0xa6dea(%rip), %rax     # 0x1614d0
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movl $0x1, 0x48(%rsp)
andl $0x0, 0x68(%rsp)
movl %ebp, %eax
shrl $0xe, %eax
andl $0x1, %eax
movl %eax, 0x80(%rsp)
notl %ebp
testb $0x1a, %bpl
jne 0xba71b
movl $0x1, 0x68(%rsp)
movq 0x120(%rbx), %rdi
cvtdq2pd (%r14), %xmm1
movq 0xe8(%rdi), %rcx
movupd 0x178(%rbx), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm1, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm2
cmpltpd %xmm1, %xmm2
movmskpd %xmm2, %eax
movsd 0x28c21(%rip), %xmm1    # 0xe3378
movsd 0x28c21(%rip), %xmm2    # 0xe3380
movapd %xmm1, %xmm3
testb $0x1, %al
jne 0xba76b
movapd %xmm2, %xmm3
movq 0x10(%rcx), %rsi
movl (%r12), %edx
addsd %xmm0, %xmm3
cvttsd2si %xmm3, %r8
movl 0x4(%r12), %ecx
addl 0x18(%rbx), %r8d
testb $0x2, %al
jne 0xba78d
movapd %xmm2, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r9
addl 0x1c(%rbx), %r9d
leaq 0x28(%rsp), %rax
pushq %rax
pushq $0x612                  # imm = 0x612
pushq $0x0
pushq $0x1
pushq $0x0
pushq $0x0
callq 0x568a0
addq $0x30, %rsp
movq %rax, 0x138(%rbx)
testq %rax, %rax
je 0xba904
cmpq $0x0, 0x128(%rbx)
je 0xba850
movq 0x120(%rbx), %rdi
callq 0x5a230
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
subq $0x30, %rsp
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%rsp)
andq $0x0, 0x28(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movl $0x2, 0x10(%rsp)
pushq $0x1
popq %r8
xorl %edx, %edx
xorl %ecx, %ecx
movl %r8d, %r9d
callq 0x568a0
addq $0x30, %rsp
movq %rax, 0x150(%rbx)
movq 0x120(%rbx), %rdi
movq %rax, %rsi
callq 0x58760
movq 0x120(%rbx), %rdi
callq 0x578a0
movq 0x138(%rbx), %rax
movq 0x120(%rbx), %rdi
movl $0x62807f, %edx         # imm = 0x62807F
movq %rax, %rsi
callq 0x598f0
movq 0xb2705(%rip), %rax     # 0x16cf70
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
movq 0xb2706(%rip), %rax     # 0x16cf80
movq %rax, 0x8(%rdx)
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
pushq $0x2
popq %rcx
callq 0x597d0
leaq 0x98(%rsp), %rsi
movl $0x10, (%rsi)
movq %rbx, %rdi
callq 0xb8e6e
movb 0x1b4(%rbx), %bpl
pushq $0x8
popq %rdi
callq 0x56700
movq %rax, %r12
movq 0x138(%rbx), %r13
testb $0x14, %bpl
je 0xba90c
movsd 0x178(%rbx), %xmm0
movq %r14, %rdi
callq 0x57480
movq %rax, %rcx
shrq $0x20, %rcx
movl 0x18(%rbx), %esi
addl %eax, %esi
addl 0x1c(%rbx), %ecx
shlq $0x20, %rcx
orq %rcx, %rsi
leaq 0x8(%rsp), %rdx
movq %rsi, (%rdx)
movq %r12, %rdi
movq %r13, %rsi
callq 0x58340
jmp 0xba920
pushq $-0x1
popq %rax
jmp 0xbabf0
leaq 0x8(%rsp), %rdx
andq $0x0, (%rdx)
movq %r12, %rdi
movq %r13, %rsi
callq 0x58340
movq %r12, 0x10(%rbx)
pushq $0x1
popq %r13
movsd 0x178(%rbx), %xmm0
movq %r14, %rdi
callq 0x57480
movl 0x18(%rbx), %ecx
addl %eax, %ecx
shrq $0x20, %rax
addl 0x1c(%rbx), %eax
shlq $0x20, %rax
orq %rax, %rcx
leaq 0x8(%rsp), %rsi
movq %rcx, (%rsi)
movq %r12, %rdi
callq 0x57100
movq 0xa742e(%rip), %rax     # 0x161d90
xorl %ebp, %ebp
movswl (%rax), %r12d
callq 0x587f0
cmpl %eax, %ebp
jge 0xba9f9
movl %ebp, %edi
callq 0x59b10
leaq 0x20(%rax), %rdi
movl %r12d, %esi
callq 0x5a150
testb %al, %al
je 0xba990
incl %ebp
jmp 0xba968
movl %ebp, %edi
callq 0x59b10
movq %r13, %rbp
movq %rax, %r13
callq 0x59710
movq %rax, %r12
movq (%r13), %rax
movq %r13, %rdi
callq *0xa8(%rax)
movq %rax, %rdi
callq 0x598d0
movq %rax, (%r12)
movq (%r13), %rax
movq %r13, %rdi
movq %rbp, %r13
callq *0xa8(%rax)
movq %rax, %rdi
callq 0x598d0
movq %rax, 0x8(%r12)
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq %r12, %rdx
callq 0x57ad0
movq %r12, %rdi
callq 0x59110
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x38(%rax)
movq 0x158(%rbx), %rax
testq %rax, %rax
je 0xbaa41
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq 0xb256a(%rip), %rdx     # 0x16cf90
movl 0x160(%rbx), %r10d
pushq $0x6
popq %rcx
pushq $0x20
popq %r8
xorl %r9d, %r9d
pushq %r10
pushq %rax
callq 0x58960
popq %rcx
popq %rdx
testb $0x4, 0x1b4(%rbx)
je 0xbaa5e
movq (%r14), %rax
movq %rax, 0x190(%rbx)
movq (%r14), %rax
movq %rax, 0x198(%rbx)
movq %rbx, %rdi
callq 0xb8ae4
movl 0x1b4(%rbx), %eax
movl %eax, %ecx
notl %ecx
testb $0x1a, %cl
jne 0xbaaa2
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq 0xb2546(%rip), %rdx     # 0x16cfd0
leaq 0xb256f(%rip), %rax     # 0x16d000
pushq $0x4
popq %rcx
pushq $0x20
popq %r8
xorl %r9d, %r9d
pushq $0x1
jmp 0xbab64
testb $0x2, %al
jne 0xbaac8
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq 0xb2515(%rip), %rdx     # 0x16cfd0
testb $0x1, %al
jne 0xbab1c
leaq 0xb251a(%rip), %rax     # 0x16cfe0
jmp 0xbaa91
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq 0xb24f3(%rip), %rdx     # 0x16cfd0
leaq 0xb250c(%rip), %rax     # 0x16cff0
pushq $0x4
popq %r14
pushq $0x20
popq %rbp
movq %r14, %rcx
movl %ebp, %r8d
xorl %r9d, %r9d
pushq %r13
pushq %rax
callq 0x58960
popq %rcx
popq %rdx
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq 0xb248d(%rip), %rdx     # 0x16cfa0
leaq 0xb2496(%rip), %rax     # 0x16cfb0
jmp 0xbab59
leaq 0xb24cd(%rip), %rax     # 0x16cff0
pushq $0x4
popq %r14
pushq $0x20
popq %rbp
movq %r14, %rcx
movl %ebp, %r8d
xorl %r9d, %r9d
pushq %r13
pushq %rax
callq 0x58960
popq %rcx
popq %rdx
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq 0xb244e(%rip), %rdx     # 0x16cfa0
leaq 0xb2467(%rip), %rax     # 0x16cfc0
movq %r14, %rcx
movl %ebp, %r8d
xorl %r9d, %r9d
pushq %r13
pushq %rax
callq 0x58960
popq %rcx
popq %rdx
movq 0x138(%rbx), %rdi
callq 0x57e20
movq 0x190(%rax), %rdi
testq %rdi, %rdi
je 0xbabd9
callq 0x56a50
movq %rax, %r14
movq %rbx, %rdi
callq 0xbaf22
testq %r14, %r14
je 0xbabba
movq 0x120(%rbx), %r15
movq 0x138(%rbx), %r12
movq %r14, %rdi
callq 0x562a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
jmp 0xbabd4
testq %rax, %rax
je 0xbabd9
movq 0x120(%rbx), %rdi
movq 0x138(%rbx), %rsi
movq 0x138(%rax), %rdx
callq 0x57340
cmpb $0x1, 0x171(%rbx)
jne 0xbabee
movq (%rbx), %rax
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq *0x58(%rax)
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb236f(%rip), %rdi     # 0x16cf78
callq 0x57210
testl %eax, %eax
je 0xba640
movq 0x120(%rbx), %rdi
leaq 0x48537(%rip), %rsi     # 0x10315b
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb233e(%rip)     # 0x16cf70
leaq 0xb233f(%rip), %rdi     # 0x16cf78
callq 0x57cf0
jmp 0xba640
leaq 0xb233e(%rip), %rdi     # 0x16cf88
callq 0x57210
testl %eax, %eax
je 0xba64e
movq 0x120(%rbx), %rdi
leaq 0x48507(%rip), %rsi     # 0x10316c
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb230d(%rip)     # 0x16cf80
leaq 0xb230e(%rip), %rdi     # 0x16cf88
callq 0x57cf0
jmp 0xba64e
leaq 0xb230d(%rip), %rdi     # 0x16cf98
callq 0x57210
testl %eax, %eax
je 0xba65c
movq 0x120(%rbx), %rdi
leaq 0x48581(%rip), %rsi     # 0x103227
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb22dc(%rip)     # 0x16cf90
leaq 0xb22dd(%rip), %rdi     # 0x16cf98
callq 0x57cf0
jmp 0xba65c
leaq 0xb22dc(%rip), %rdi     # 0x16cfa8
callq 0x57210
testl %eax, %eax
je 0xba66a
movq 0x120(%rbx), %rdi
leaq 0x48492(%rip), %rsi     # 0x103179
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb22ab(%rip)     # 0x16cfa0
leaq 0xb22ac(%rip), %rdi     # 0x16cfa8
callq 0x57cf0
jmp 0xba66a
leaq 0xb22ab(%rip), %rdi     # 0x16cfb8
callq 0x57210
testl %eax, %eax
je 0xba678
movq 0x120(%rbx), %rdi
leaq 0x4850c(%rip), %rsi     # 0x103234
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb227a(%rip)     # 0x16cfb0
leaq 0xb227b(%rip), %rdi     # 0x16cfb8
callq 0x57cf0
jmp 0xba678
leaq 0xb227a(%rip), %rdi     # 0x16cfc8
callq 0x57210
testl %eax, %eax
je 0xba686
movq 0x120(%rbx), %rdi
leaq 0x484df(%rip), %rsi     # 0x103248
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb2249(%rip)     # 0x16cfc0
leaq 0xb224a(%rip), %rdi     # 0x16cfc8
callq 0x57cf0
jmp 0xba686
leaq 0xb2249(%rip), %rdi     # 0x16cfd8
callq 0x57210
testl %eax, %eax
je 0xba694
movq 0x120(%rbx), %rdi
leaq 0x484b2(%rip), %rsi     # 0x10325c
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb2218(%rip)     # 0x16cfd0
leaq 0xb2219(%rip), %rdi     # 0x16cfd8
callq 0x57cf0
jmp 0xba694
leaq 0xb2218(%rip), %rdi     # 0x16cfe8
callq 0x57210
testl %eax, %eax
je 0xba6a2
movq 0x120(%rbx), %rdi
leaq 0x48485(%rip), %rsi     # 0x103270
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb21e7(%rip)     # 0x16cfe0
leaq 0xb21e8(%rip), %rdi     # 0x16cfe8
callq 0x57cf0
jmp 0xba6a2
leaq 0xb21e7(%rip), %rdi     # 0x16cff8
callq 0x57210
testl %eax, %eax
je 0xba6b0
movq 0x120(%rbx), %rdi
leaq 0x4845f(%rip), %rsi     # 0x10328b
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb21b6(%rip)     # 0x16cff0
leaq 0xb21b7(%rip), %rdi     # 0x16cff8
callq 0x57cf0
jmp 0xba6b0
leaq 0xb21b6(%rip), %rdi     # 0x16d008
callq 0x57210
testl %eax, %eax
je 0xba6be
movq 0x120(%rbx), %rdi
leaq 0x48439(%rip), %rsi     # 0x1032a6
xorl %edx, %edx
callq 0x59130
movq %rax, 0xb2185(%rip)     # 0x16d000
leaq 0xb2186(%rip), %rdi     # 0x16d008
callq 0x57cf0
jmp 0xba6be
movq %rax, %rbx
leaq 0xb2172(%rip), %rdi     # 0x16d008
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb2156(%rip), %rdi     # 0x16cff8
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb213a(%rip), %rdi     # 0x16cfe8
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb211e(%rip), %rdi     # 0x16cfd8
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb2102(%rip), %rdi     # 0x16cfc8
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb20e6(%rip), %rdi     # 0x16cfb8
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb20ca(%rip), %rdi     # 0x16cfa8
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb20ae(%rip), %rdi     # 0x16cf98
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb2092(%rip), %rdi     # 0x16cf88
jmp 0xbaf02
movq %rax, %rbx
leaq 0xb2076(%rip), %rdi     # 0x16cf78
callq 0x57520
jmp 0xbaf19
jmp 0xbaf0b
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r12, %rdi
callq 0x564c0
movq %rbx, %rdi
callq 0x58260
nop