// File: /workspace/github_c_makefile_star2_O3/mati75[P]evilwm/screen.c
// Function: screen_init
void screen_init(struct screen *s) {
	int i = s->screen;

	// Used to set the DISPLAY environment variable to something like
	// ":0.x" depending on which screen a terminal is launched from.
	s->display = screen_to_display_str(i);

	s->root = RootWindow(display.dpy, i);
#ifdef RANDR
	s->nmonitors = 0;
	s->monitors = NULL;
        if (display.have_randr) {
		XRRSelectInput(display.dpy, s->root, RRScreenChangeNotifyMask);
	}
#endif
	screen_probe_monitors(s);

	// Default to first virtual desktop.  TODO: consider checking the
	// _NET_WM_DESKTOP property of the window with focus when we start to
	// change this default?
	s->vdesk = 0;

	// In case the visual for this screen uses a colourmap, ensure our
	// border colours are in it.
	XColor dummy;
	XAllocNamedColor(display.dpy, DefaultColormap(display.dpy, i), option.fg, &s->fg, &dummy);
	XAllocNamedColor(display.dpy, DefaultColormap(display.dpy, i), option.bg, &s->bg, &dummy);
	XAllocNamedColor(display.dpy, DefaultColormap(display.dpy, i), option.fc, &s->fc, &dummy);

	// When dragging an outline, we use an inverting graphics context
	// (GCFunction + GXinvert) so that simply drawing it again will erase
	// it from the screen.

	XGCValues gv;
	gv.function = GXinvert;
	gv.subwindow_mode = IncludeInferiors;
	gv.line_width = 1;  // option.bw
	gv.font = display.font->fid;
	s->invert_gc = XCreateGC(display.dpy, s->root,
				 GCFunction | GCSubwindowMode | GCLineWidth | GCFont, &gv);

	// We handle events to the root window:
	// SubstructureRedirectMask - create, destroy, configure window notifications
	// SubstructureNotifyMask - configure window requests
	// EnterWindowMask - enter events
	// ColormapChangeMask - when a new colourmap is needed

	XSetWindowAttributes attr;
	attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
	                  | EnterWindowMask | ColormapChangeMask;
	XChangeWindowAttributes(display.dpy, s->root, CWEventMask, &attr);

	// Grab the various keyboard shortcuts
	bind_grab_for_screen(s);

	s->active = None;
	s->docks_visible = 1;

	Atom supported[] = {
		X_ATOM(_NET_CLIENT_LIST),
		X_ATOM(_NET_CLIENT_LIST_STACKING),
		X_ATOM(_NET_NUMBER_OF_DESKTOPS),
		X_ATOM(_NET_DESKTOP_GEOMETRY),
		X_ATOM(_NET_DESKTOP_VIEWPORT),
		X_ATOM(_NET_CURRENT_DESKTOP),
		X_ATOM(_NET_ACTIVE_WINDOW),
		X_ATOM(_NET_WORKAREA),
		X_ATOM(_NET_SUPPORTING_WM_CHECK),

		X_ATOM(_NET_CLOSE_WINDOW),
		X_ATOM(_NET_MOVERESIZE_WINDOW),
		X_ATOM(_NET_RESTACK_WINDOW),
		X_ATOM(_NET_REQUEST_FRAME_EXTENTS),

		X_ATOM(_NET_WM_DESKTOP),
		X_ATOM(_NET_WM_WINDOW_TYPE),
		X_ATOM(_NET_WM_WINDOW_TYPE_DESKTOP),
		X_ATOM(_NET_WM_WINDOW_TYPE_DOCK),
		X_ATOM(_NET_WM_STATE),
		X_ATOM(_NET_WM_STATE_MAXIMIZED_VERT),
		X_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ),
		X_ATOM(_NET_WM_STATE_HIDDEN),
		X_ATOM(_NET_WM_STATE_FULLSCREEN),
		X_ATOM(_NET_WM_STATE_FOCUSED),
		X_ATOM(_NET_WM_ALLOWED_ACTIONS),

		// Not sure if it makes any sense including every action here
		// as they'll already be listed per-client in the
		// _NET_WM_ALLOWED_ACTIONS property, but EWMH spec is unclear.
		X_ATOM(_NET_WM_ACTION_MOVE),
		X_ATOM(_NET_WM_ACTION_RESIZE),
		X_ATOM(_NET_WM_ACTION_MAXIMIZE_HORZ),
		X_ATOM(_NET_WM_ACTION_MAXIMIZE_VERT),
		X_ATOM(_NET_WM_ACTION_FULLSCREEN),
		X_ATOM(_NET_WM_ACTION_CHANGE_DESKTOP),
		X_ATOM(_NET_WM_ACTION_CLOSE),
		X_ATOM(_NET_FRAME_EXTENTS),
	};

	unsigned long num_desktops = option.vdesks;
	unsigned long vdesk = s->vdesk;
	unsigned long pid = getpid();

	s->supporting = XCreateSimpleWindow(display.dpy, s->root, 0, 0, 1, 1, 0, 0, 0);
	XChangeProperty(display.dpy, s->root, X_ATOM(_NET_SUPPORTED),
			XA_ATOM, 32, PropModeReplace,
			(unsigned char *)&supported,
			sizeof(supported) / sizeof(Atom));
	XChangeProperty(display.dpy, s->root, X_ATOM(_NET_NUMBER_OF_DESKTOPS),
			XA_CARDINAL, 32, PropModeReplace,
			(unsigned char *)&num_desktops, 1);
	XChangeProperty(display.dpy, s->root, X_ATOM(_NET_CURRENT_DESKTOP),
			XA_CARDINAL, 32, PropModeReplace,
			(unsigned char *)&vdesk, 1);
	XChangeProperty(display.dpy, s->root, X_ATOM(_NET_ACTIVE_WINDOW),
	                XA_WINDOW, 32, PropModeReplace,
	                (unsigned char *)&s->active, 1);
	XChangeProperty(display.dpy, s->root, X_ATOM(_NET_SUPPORTING_WM_CHECK),
			XA_WINDOW, 32, PropModeReplace,
			(unsigned char *)&s->supporting, 1);
	XChangeProperty(display.dpy, s->supporting, X_ATOM(_NET_SUPPORTING_WM_CHECK),
			XA_WINDOW, 32, PropModeReplace,
			(unsigned char *)&s->supporting, 1);
	XChangeProperty(display.dpy, s->supporting, X_ATOM(_NET_WM_NAME),
			XA_STRING, 8, PropModeReplace,
			(const unsigned char *)"evilwm", 6);
	XChangeProperty(display.dpy, s->supporting, X_ATOM(_NET_WM_PID),
			XA_CARDINAL, 32, PropModeReplace,
			(unsigned char *)&pid, 1);

	ewmh_set_screen_workarea(s);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %rbx
movslq (%rdi), %r14
leaq 0x6aca(%rip), %r13      # 0xf728
movq (%r13), %rax
movq 0xd8(%rax), %r12
movq %r12, %rdi
callq 0x42f0
leaq 0x14(%rax), %rdi
callq 0x9eb8
movq %rax, %r15
movabsq $0x3d59414c50534944, %rax # imm = 0x3D59414C50534944
movq %rax, (%r15)
movb $0x0, 0x8(%r15)
movq %r15, %rdi
movq %r12, %rsi
callq 0x4410
movq %r15, %rdi
movl $0x3a, %esi
callq 0x4380
testq %rax, %rax
je 0x8cf2
cmpl $0x2, 0x188(%r13)
jl 0x8cf2
movq %rax, %r12
movq %rax, %rdi
movl $0x2e, %esi
callq 0x4480
testq %rax, %rax
jne 0x8cd9
movq %r12, %rdi
callq 0x42f0
addq %rax, %r12
movq %r12, %rax
leaq 0x262d(%rip), %rdx      # 0xb30d
movl $0xc, %esi
movq %rax, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x40a0
movq %r15, 0x8(%rbx)
movq (%r13), %rdi
movq 0xe8(%rdi), %rax
shlq $0x7, %r14
movq 0x10(%rax,%r14), %rsi
movq %rsi, 0x10(%rbx)
movl $0x0, 0x6c(%rbx)
movq $0x0, 0x70(%rbx)
cmpl $0x0, 0x180(%r13)
je 0x8d31
movl $0x1, %edx
callq 0x42c0
movq %rbx, %rdi
callq 0x90ee
xorl %eax, %eax
movl %eax, 0x60(%rbx)
movq (%r13), %rdi
movq 0xe8(%rdi), %rax
movq 0x50(%rax,%r14), %rsi
leaq 0x6b9b(%rip), %rbp      # 0xf8f0
movq 0x10(%rbp), %rdx
leaq 0x30(%rbx), %rcx
leaq 0x20(%rsp), %r15
movq %r15, %r8
callq 0x4200
movq (%r13), %rdi
movq 0xe8(%rdi), %rax
movq 0x50(%rax,%r14), %rsi
movq 0x18(%rbp), %rdx
leaq 0x40(%rbx), %rcx
movq %r15, %r8
callq 0x4200
movq (%r13), %rdi
movq 0xe8(%rdi), %rax
movq 0x50(%rax,%r14), %rsi
movq 0x20(%rbp), %rdx
leaq 0x50(%rbx), %rcx
movq %r15, %r8
callq 0x4200
leaq 0xa0(%rsp), %rcx
movl $0xa, (%rcx)
movl $0x1, %r14d
movl %r14d, 0x60(%rcx)
movl %r14d, 0x20(%rcx)
movq (%r13), %rdi
movq 0x160(%r13), %rax
movq 0x8(%rax), %rax
movq %rax, 0x58(%rcx)
movq 0x10(%rbx), %rsi
movl $0xc011, %edx           # imm = 0xC011
callq 0x4490
movq %rax, 0x28(%rbx)
leaq 0x30(%rsp), %rcx
movq $0x980010, 0x48(%rcx)   # imm = 0x980010
movq (%r13), %rdi
movq 0x10(%rbx), %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x4780
movq %rbx, %rdi
callq 0x4e74
leaq 0x20(%rbx), %rax
movq %rax, (%rsp)
movq $0x0, 0x20(%rbx)
movl %r14d, 0x68(%rbx)
movups 0x48(%r13), %xmm0
movups 0x58(%r13), %xmm1
movups 0x68(%r13), %xmm2
movups 0x78(%r13), %xmm3
leaq 0x120(%rsp), %r12
movaps %xmm0, (%r12)
movaps %xmm1, 0x10(%r12)
movaps %xmm2, 0x20(%r12)
movaps %xmm3, 0x30(%r12)
movups 0x88(%r13), %xmm0
movaps %xmm0, 0x40(%r12)
movups 0x98(%r13), %xmm0
movaps %xmm0, 0x50(%r12)
movq 0xa8(%r13), %rax
movq %rax, 0x60(%r12)
movups 0xb8(%r13), %xmm0
movups %xmm0, 0x68(%r12)
movups 0xc8(%r13), %xmm0
movups %xmm0, 0x78(%r12)
movups 0xe0(%r13), %xmm0
movups %xmm0, 0x88(%r12)
movups 0xf0(%r13), %xmm0
movups %xmm0, 0x98(%r12)
movups 0x100(%r13), %xmm0
movups %xmm0, 0xa8(%r12)
movups 0x110(%r13), %xmm0
movups %xmm0, 0xb8(%r12)
movups 0x120(%r13), %xmm0
movups %xmm0, 0xc8(%r12)
movups 0x130(%r13), %xmm0
movups %xmm0, 0xd8(%r12)
movups 0x140(%r13), %xmm0
movups %xmm0, 0xe8(%r12)
movq 0x158(%r13), %rax
movq %rax, 0xf8(%r12)
movl 0x2c(%rbp), %eax
leaq 0x18(%rsp), %r15
movq %rax, (%r15)
movl 0x60(%rbx), %eax
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
callq 0x4280
cltq
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq (%r13), %rdi
movq 0x10(%rbx), %rsi
subq $0x20, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
xorl %eax, %eax
movl %eax, (%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x4270
addq $0x20, %rsp
leaq 0x18(%rbx), %rbp
movq %rax, 0x18(%rbx)
movq 0x10(%rbx), %rsi
movq (%r13), %rdi
movq 0x40(%r13), %rdx
movl $0x4, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq $0x20
pushq %r12
callq 0x4640
addq $0x10, %rsp
movq 0x10(%rbx), %rsi
movq (%r13), %rdi
movq 0x58(%r13), %rdx
movl $0x6, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %r15
callq 0x4640
addq $0x10, %rsp
movq 0x10(%rbx), %rsi
movq (%r13), %rdi
movq 0x70(%r13), %rdx
movl $0x6, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r14
leaq 0x18(%rsp), %rax
pushq %rax
callq 0x4640
addq $0x10, %rsp
movq 0x10(%rbx), %rsi
movq (%r13), %rdi
movq 0x78(%r13), %rdx
movl $0x21, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r14
pushq 0x8(%rsp)
callq 0x4640
addq $0x10, %rsp
movq 0x10(%rbx), %rsi
movq (%r13), %rdi
movq 0x88(%r13), %rdx
movl $0x21, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %rbp
callq 0x4640
addq $0x10, %rsp
movq 0x18(%rbx), %rsi
movq (%r13), %rdi
movq 0x88(%r13), %rdx
movl $0x21, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %rbp
callq 0x4640
addq $0x10, %rsp
movq 0x18(%rbx), %rsi
movq (%r13), %rdi
movq 0xb0(%r13), %rdx
leaq 0x2271(%rip), %rax      # 0xb2fd
movl $0x1f, %ecx
movl $0x8, %r8d
xorl %r9d, %r9d
pushq $0x6
pushq %rax
callq 0x4640
addq $0x10, %rsp
movq 0x18(%rbx), %rsi
movq (%r13), %rdi
movq 0x150(%r13), %rdx
movl $0x6, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r14
leaq 0x10(%rsp), %rax
pushq %rax
callq 0x4640
addq $0x10, %rsp
movq %rbx, %rdi
callq 0x7c5c
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq