// File: /workspace/github_c_makefile_star2_O3/kaugm[P]mmwm/mmwm.c
// Function: update_current
void update_current(client *newfocus)   // newfocus may be NULL
{
    if(!M_HEAD) {                // empty desktop. no clients
        nada();
        return;
    }

    if(!newfocus) {
        if(M_PREVFOCUS)
            M_CURRENT = M_PREVFOCUS;
        else
            M_CURRENT = M_HEAD;
        M_PREVFOCUS = M_GETPREV(M_CURRENT);             // get previous client in list, may be NULL
    }
    else {
        if(newfocus == M_PREVFOCUS) {
            M_CURRENT = M_PREVFOCUS;
            M_PREVFOCUS = M_GETPREV(M_CURRENT);         // get previous client in list, may be NULL
        }
        else {
            M_PREVFOCUS = M_CURRENT;
            M_CURRENT = newfocus;
        }
    }

    if(!M_CURRENT) {  // there is really really really nothing to focus.
        nada();
        return;
    }

	/* Setting window borders: xcb_border_width -----> client_borders(c) */
    for (client *c = M_HEAD; c; c = M_GETNEXT(c)) {
        if (!c->isfullscreen) {
            xcb_change_window_attributes(dis, c->win, XCB_CW_BORDER_PIXEL,
                                    (c == M_CURRENT ? &win_focus : &win_unfocus));
            xcb_border_width(dis, c->win, client_borders(c));
        }
    }

    tile();

    for (client *c = M_HEAD; c; c = M_GETNEXT(c)) {
        if (c->isfullscreen) {
//            xcb_border_width(dis, c->win, 0);
            xcb_lower_window(dis, c->win);
//            xcb_move_resize(dis, c->win, 0, 0,
//                            screen->width_in_pixels, screen->height_in_pixels, &c->position_info);
            break;
        }
    }

    client *rl = NULL;
    for (client *c = M_HEAD; c; c = M_GETNEXT(c)) {
        if (c->ismaximized || c->isfloating || c->istransient || c->type != ewmh->_NET_WM_WINDOW_TYPE_NORMAL) {
            if (c == M_CURRENT) {
                rl = c;
                continue;
            }
        }
        xcb_raise_window(dis, c->win);
    }
    if(rl)
        xcb_raise_window(dis, rl->win);

    if (check_head(&aliens)) {
        alien *a;
        for (a=(alien *)get_head(&aliens); a; a=(alien *)get_next(&a->link)) {
            if (M_CURRENT->isfullscreen
             && a->type != ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION)
                continue;
            xcb_raise_window(dis, a->win);
        }
    }

    if (M_CURRENT) {
        if (M_CURRENT->setfocus) {
            xcb_change_property(dis, XCB_PROP_MODE_REPLACE, screen->root,
                                ewmh->_NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1,
                                &M_CURRENT->win);
            xcb_set_input_focus(dis, XCB_INPUT_FOCUS_POINTER_ROOT, M_CURRENT->win,
                                XCB_CURRENT_TIME);
            DEBUG("xcb_set_input_focus();");
        }
        else {
            sendevent(M_CURRENT->win, wmatoms[WM_TAKE_FOCUS]);
            DEBUG("send WM_TAKE_FOCUS");
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq 0x69b0(%rip), %rax      # 0xa780
movq 0x18(%rax), %rbx
testq %rbx, %rbx
je 0x3df5
movq 0x38(%rax), %rcx
testq %rdi, %rdi
je 0x3e43
cmpq %rdi, %rcx
je 0x3e4a
movq 0x30(%rax), %rcx
movq %rcx, 0x38(%rax)
movq %rdi, 0x30(%rax)
jmp 0x3e55
movq 0x6954(%rip), %rdi      # 0xa750
movq 0x696d(%rip), %rax      # 0xa770
movl (%rax), %esi
movq 0x695c(%rip), %rax      # 0xa768
movl 0x40(%rax), %edx
callq 0x3670
movq 0x6935(%rip), %rdi      # 0xa750
movq 0x694e(%rip), %rax      # 0xa770
movl (%rax), %edx
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x3590
movq 0x6949(%rip), %rax      # 0xa780
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
jmp 0x408a
testq %rcx, %rcx
cmoveq %rbx, %rcx
movq %rcx, 0x30(%rax)
movq (%rcx), %rcx
movq %rcx, 0x38(%rax)
cmpb $0x0, 0x1b(%rbx)
jne 0x3eb1
movq 0x68ee(%rip), %rdi      # 0xa750
movl 0x20(%rbx), %esi
movq 0x6914(%rip), %rax      # 0xa780
cmpq 0x30(%rax), %rbx
leaq 0x6959(%rip), %rax      # 0xa7d0
leaq 0x6956(%rip), %rcx      # 0xa7d4
cmoveq %rax, %rcx
movl $0x8, %edx
callq 0x30f0
movq 0x68bd(%rip), %rdi      # 0xa750
movl 0x20(%rbx), %esi
movl 0x40(%rbx), %eax
xorl %edx, %edx
testl %eax, %eax
cmovgl %eax, %edx
leaq 0xc(%rsp), %rcx
movl %edx, (%rcx)
movl $0x10, %edx
callq 0x32c0
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
jne 0x3e55
callq 0x4f30
movq 0x68ba(%rip), %rax      # 0xa780
movq 0x18(%rax), %r14
testq %r14, %r14
je 0x3fad
movq %r14, %rax
cmpb $0x1, 0x1b(%rax)
je 0x3ee7
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x3ed6
jmp 0x3f11
movq 0x6862(%rip), %rdi      # 0xa750
movl 0x20(%rax), %esi
leaq 0xc(%rsp), %rcx
movl $0x1, (%rcx)
movl $0x40, %edx
callq 0x32c0
movq 0x6873(%rip), %rax      # 0xa780
movq 0x18(%rax), %r14
testq %r14, %r14
je 0x3fad
xorl %r15d, %r15d
leaq 0xc(%rsp), %rbx
cmpb $0x0, 0x1c(%r14)
jne 0x3f4a
cmpb $0x0, 0x1a(%r14)
jne 0x3f4a
cmpb $0x0, 0x19(%r14)
jne 0x3f4a
movl 0x24(%r14), %eax
movq 0x6826(%rip), %rcx      # 0xa768
cmpl 0x104(%rcx), %eax
je 0x3f5a
movq 0x682f(%rip), %rcx      # 0xa780
movq %r14, %rax
cmpq 0x30(%rcx), %r14
je 0x3f7d
movq 0x67ef(%rip), %rdi      # 0xa750
movl 0x20(%r14), %esi
movl $0x0, 0xc(%rsp)
movl $0x40, %edx
movq %rbx, %rcx
callq 0x32c0
movq %r15, %rax
movq 0x8(%r14), %r14
movq %rax, %r15
testq %r14, %r14
jne 0x3f22
testq %rax, %rax
je 0x3fad
movq 0x67bb(%rip), %rdi      # 0xa750
movl 0x20(%rax), %esi
leaq 0xc(%rsp), %rcx
movl $0x0, (%rcx)
movl $0x40, %edx
callq 0x32c0
movq 0x67dc(%rip), %r14      # 0xa790
movq 0x67c5(%rip), %rax      # 0xa780
testq %r14, %r14
je 0x4012
leaq 0xc(%rsp), %rbx
movq 0x30(%rax), %rcx
cmpb $0x1, 0x1b(%rcx)
jne 0x3fe2
movl 0x1c(%r14), %ecx
movq 0x678e(%rip), %rdx      # 0xa768
cmpl 0xf8(%rdx), %ecx
jne 0x4009
movq 0x6767(%rip), %rdi      # 0xa750
movl 0x18(%r14), %esi
movl $0x0, 0xc(%rsp)
movl $0x40, %edx
movq %rbx, %rcx
callq 0x32c0
movq 0x6777(%rip), %rax      # 0xa780
movq 0x8(%r14), %r14
testq %r14, %r14
jne 0x3fc5
movq 0x30(%rax), %rax
testq %rax, %rax
je 0x408a
cmpb $0x1, 0x44(%rax)
jne 0x407c
movq 0x6728(%rip), %rdi      # 0xa750
movq 0x6741(%rip), %rcx      # 0xa770
movl (%rcx), %edx
movq 0x6730(%rip), %rcx      # 0xa768
movl 0x40(%rcx), %ecx
addq $0x20, %rax
xorl %esi, %esi
movl $0x21, %r8d
movl $0x20, %r9d
pushq %rax
pushq $0x1
callq 0x35d0
addq $0x10, %rsp
movq 0x66f0(%rip), %rdi      # 0xa750
movq 0x6719(%rip), %rax      # 0xa780
movq 0x30(%rax), %rax
movl 0x20(%rax), %edx
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x3590
jmp 0x408a
movl 0x20(%rax), %edi
movl 0x6767(%rip), %esi      # 0xa7ec
callq 0x4f58
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq