// File: /workspace/github_c_makefile_star2_O0/mcaimi[P]st/x.c
// Function: go_fullscreen
void
go_fullscreen(const Arg *arg)
{
  int error;
  unsigned int has_fullscreen_set = 0;
  Atom actual_type_return, req_property_type = XInternAtom(xw.dpy, "ATOM", False);
  int actual_format_return;
  unsigned long nitems_return, bytes_after_return;
  long long_offset, long_length;
  unsigned char *data = NULL;

  // query Xlib for current window properties. we need to determine whether the _NET_WM_STATE_FULLSCREEN
  // atom is already set.
  // https://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html
  long_offset = 0; // retrieve from the beginning of property list
  long_length = GET_WINDOW_PROPERTY_SIZE;
  error = XGetWindowProperty(xw.dpy, xw.win,
                               xw.window_state,
                               long_offset,
                               long_length,
                               FALSE,
                               req_property_type,
                               &actual_type_return,
                               &actual_format_return,
                               &nitems_return,
                               &bytes_after_return,
                               &data);

  if (error != Success) {
    fprintf(stderr, "%s - %s [%d]\n", "Xst ERROR", "go_fullscreen(): XGetWindowProperty() failed.", error );
    return;
  }

  // check if the _NET_WM_STATE_FULLSCREEN property is set:
  if (data) {
    for (int i=0; i<nitems_return; i++) {
      has_fullscreen_set = (xw.window_fullscreen == ((unsigned long*)data)[i]) ? 1 : 0; // property is 32bit cast to unsigned long
      if (has_fullscreen_set) {
        break;
      }
    }
    XFree(data);
  }

  // see https://specifications.freedesktop.org/wm-spec/1.3/ar01s05.html, _NET_WM_STATE paragraph
  /*
    window  = the respective client window
    message_type = _NET_WM_STATE
    format = 32
    data.l[0] = the action, as listed below
    data.l[1] = first property to alter
    data.l[2] = second property to alter
    data.l[3] = source indication
    other data.l[] elements = 0

    _NET_WM_STATE_REMOVE 0
    _NET_WM_STATE_ADD 1
    _NET_WM_STATE_TOGGLE 2
  */

  // See Xlib.h, line 36
  XEvent xevent;
  bzero(&xevent, sizeof(xevent));
  // prepare client message
  // we are interested in the 'xclient' field of the Xevent union
  xevent.type = ClientMessage;
  xevent.xclient.window = xw.win;
  xevent.xclient.message_type = xw.window_state;
  xevent.xclient.format = 32;
  xevent.xclient.data.l[0] = (! has_fullscreen_set) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
  xevent.xclient.data.l[1] = xw.window_fullscreen;
  xevent.xclient.data.l[2] = 0;
  xevent.xclient.data.l[3] = 0;
  xevent.xclient.data.l[4] = 0;
  // Message must be sent to root win, see https://specifications.freedesktop.org/wm-spec/wm-spec-1.3.html#idm140130317705584
  // for specific parameters (for XCB). For Xlib, as used in this program, the equivalent Root window flags are named:
  // X.h:#define SubstructureNotifyMask              (1L<<19)
  // X.h:#define SubstructureRedirectMask    (1L<<20)
  // as found by grepping through Xorg's header files
  XSendEvent(xw.dpy, DefaultRootWindow(xw.dpy), FALSE, SubstructureNotifyMask|SubstructureRedirectMask, &xevent);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movq 0x14316(%rip), %rdi     # 0x24988
leaq 0xab42(%rip), %rsi      # 0x1b1bb
xorl %edx, %edx
callq 0x6810
movq %rax, -0x38(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x58(%rbp)
movq $0xffff, -0x60(%rbp)    # imm = 0xFFFF
movq 0x142e5(%rip), %rdi     # 0x24988
movq 0x142ee(%rip), %rsi     # 0x24998
movq 0x1432f(%rip), %rdx     # 0x249e0
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x38(%rbp), %r15
xorl %r9d, %r9d
leaq -0x30(%rbp), %r14
leaq -0x3c(%rbp), %rbx
leaq -0x48(%rbp), %r11
leaq -0x50(%rbp), %r10
leaq -0x68(%rbp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x61f0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1072e
movq 0xe8ea(%rip), %rax      # 0x1eff0
movq (%rax), %rdi
movl -0x24(%rbp), %r8d
leaq 0xaaac(%rip), %rsi      # 0x1b1c0
leaq 0xaab3(%rip), %rdx      # 0x1b1ce
leaq 0xaab6(%rip), %rcx      # 0x1b1d8
movb $0x0, %al
callq 0x6970
jmp 0x1085a
cmpq $0x0, -0x68(%rbp)
je 0x10787
movl $0x0, -0x6c(%rbp)
movslq -0x6c(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x1077e
movq 0x1428b(%rip), %rdx     # 0x249d8
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovel %ecx, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x10771
jmp 0x1077e
jmp 0x10773
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1073c
movq -0x68(%rbp), %rdi
callq 0x60a0
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0xc0, %edx
callq 0x60c0
movl $0x21, -0x130(%rbp)
movq 0x141ed(%rip), %rax     # 0x24998
movq %rax, -0x110(%rbp)
movq 0x14227(%rip), %rax     # 0x249e0
movq %rax, -0x108(%rbp)
movl $0x20, -0x100(%rbp)
cmpl $0x0, -0x28(%rbp)
setne %dl
xorb $-0x1, %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
cltq
movq %rax, -0xf8(%rbp)
movq 0x141e7(%rip), %rax     # 0x249d8
movq %rax, -0xf0(%rbp)
movq $0x0, -0xe8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
movq 0x14168(%rip), %rdi     # 0x24988
movq 0x14161(%rip), %rax     # 0x24988
movq 0xe8(%rax), %rax
movq 0x14153(%rip), %rcx     # 0x24988
movslq 0xe0(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
xorl %edx, %edx
movl $0x180000, %ecx         # imm = 0x180000
leaq -0x130(%rbp), %r8
callq 0x66d0
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)