// File: /workspace/github_c_makefile_star2_O2/comfies[P]custard/src/ipc/ipc.c
// Function: ipc_command_window
void ipc_command_window(vector_t *input, unsigned short *screen_update) {
    // Missing input
    if (input->size < 2) return;
    char *variable = vector_iterator(input);

    /*
     * Usage:
     * custard - window close
     *  custard - window geometry [label]
     */

    window_t *window = NULL;
    if (focused_window == XCB_WINDOW_NONE)
        return;
    if (window_is_managed(focused_window))
        window = get_window_by_id(focused_window);

    if (!strcmp(variable, "close")) {
        close_window(focused_window);
    } else if (!strcmp(variable, "raise")) {

        if (window)
            raise_window(window->parent);
        else
            raise_window(focused_window);

    } else if (!strcmp(variable, "expand")) {

        if (!window || window->floating)
            return;

        char *cardinal = vector_iterator(input);
        grid_geometry_t *geometry = (grid_geometry_t*)window->geometry;

        if (!strcmp(cardinal, "north")) {
            if (geometry->y == 0)
                return;
            geometry->y--;
            geometry->height++;
        } else if (!strcmp(cardinal, "south"))
            geometry->height++;
        else if (!strcmp(cardinal, "east"))
            geometry->width++;
        else if (!strcmp(cardinal, "west")) {
            if (geometry->x == 0)
                return;
            geometry->x--;
            geometry->width++;
        } else return;

        set_window_geometry(window, geometry);
        decorate(window);

    } else if (!strcmp(variable, "contract")) {

        if (!window || window->floating)
            return;

        char *cardinal = vector_iterator(input);
        grid_geometry_t *geometry = (grid_geometry_t*)window->geometry;

        if (!strcmp(cardinal, "north")) {
            if (geometry->height == 1)
                return;
            geometry->y++;
            geometry->height--;
        } else if (!strcmp(cardinal, "south")) {
            if (geometry->height == 1)
                return;
            geometry->height--;
        } else if (!strcmp(cardinal, "east")) {
            if (geometry->width == 1)
                return;
            geometry->width--;
        } else if (!strcmp(cardinal, "west")) {
            if (geometry->width == 1)
                return;
            geometry->x++;
            geometry->width--;
        } else return;

        set_window_geometry(window, geometry);
        decorate(window);

    } else if (!strcmp(variable, "move")) {

        if (!window || window->floating)
            return;

        char *cardinal = vector_iterator(input);
        grid_geometry_t *geometry = (grid_geometry_t*)window->geometry;

        if (!strcmp(cardinal, "north")) {
            if (geometry->y == 0)
                return;
            geometry->y--;
        } else if (!strcmp(cardinal, "south"))
            geometry->y++;
        else if (!strcmp(cardinal, "east"))
            geometry->x++;
        else if (!strcmp(cardinal, "west")) {
            if (geometry->x == 0)
                return;
            geometry->x--;
        } else return;

        set_window_geometry(window, geometry);
        decorate(window);


    } else if (!strcmp(variable, "lower")) {

        if (window)
            lower_window(window->parent);
        else
            lower_window(focused_window);

    } else if (!strcmp(variable, "workspace")) {

        unsigned int workspace = string_to_integer(vector_iterator(input));

        if (window) {
            if (window->workspace == workspace)
                return;

            window->workspace = workspace;

            monitor_t *monitor = monitor_with_cursor_residence();
            if (monitor->workspace != window->workspace)
                unmap_window(window->parent);
        }

    } else if (!strcmp(variable, "geometry")) {
        char *label = vector_iterator(input);

        grid_geometry_t *geometry = (grid_geometry_t *)calloc(1,
            sizeof(grid_geometry_t));
        monitor_t *monitor = monitor_with_cursor_residence();

        log_debug("Looking for geometry(%s) in monitor(%s)",
            label, monitor->name);

        memcpy(geometry,
            get_geometry_from_monitor(monitor, label),
            sizeof(grid_geometry_t));

        if (!geometry)
            return;

        window_t *window = get_window_by_id(focused_window);
        if (window) {
            window->floating = 0;

            free(window->geometry);
            set_window_geometry(window, geometry);
            decorate(window);
        }

    } else if (!strcmp(variable, "float")) {
        char *token;
        char *size;
        char *position;
        unsigned int height;
        unsigned int width;
        unsigned int x;
        unsigned int y;

        size = vector_iterator(input);
        position = vector_iterator(input);

        token = strsep(&size, "x");

        width = string_to_integer(token);
        height = string_to_integer(size);

        token = strsep(&position, ",");

        x = string_to_integer(token);
        y = string_to_integer(position);

        window_t *window = get_window_by_id(focused_window);
        if (window) {
            window->floating = 1;
            screen_geometry_t *geometry = create_screen_geometry(x, y, height,
                width);

            free(window->geometry);
            set_window_geometry(window, geometry);
            decorate(window);
        }
    }

    *screen_update = 1;
}

// Assembly:
cmpl $0x2, 0xc(%rdi)
jb 0x40a2
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r15
callq 0x383d
leaq 0x8b35(%rip), %rbp      # 0xc8e0
movl (%rbp), %edi
testl %edi, %edi
je 0x4094
movq %rax, %r12
callq 0x6904
testw %ax, %ax
je 0x3dd0
movl (%rbp), %edi
callq 0x6916
movq %rax, %r14
jmp 0x3dd3
xorl %r14d, %r14d
leaq 0x42df(%rip), %rsi      # 0x80b9
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3f41
leaq 0x42ce(%rip), %rsi      # 0x80bf
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3f4e
leaq 0x42bd(%rip), %rsi      # 0x80c5
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3f60
leaq 0x42c3(%rip), %rsi      # 0x80e2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3ff6
leaq 0x42b5(%rip), %rsi      # 0x80eb
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x40a3
leaq 0x42a3(%rip), %rsi      # 0x80f0
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4130
leaq 0x41e7(%rip), %rsi      # 0x804b
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4142
leaq 0x4b7e(%rip), %rsi      # 0x89f9
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4189
leaq 0x42ad(%rip), %rsi      # 0x813f
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x408f
movq %r15, %rdi
callq 0x383d
leaq 0x20(%rsp), %r14
movq %rax, (%r14)
movq %r15, %rdi
callq 0x383d
leaq 0x18(%rsp), %r15
movq %rax, (%r15)
leaq 0x41ec(%rip), %rsi      # 0x80b5
movq %r14, %rdi
callq 0x3430
movq %rax, %rdi
callq 0x46ec
movl %eax, 0x14(%rsp)
movq (%r14), %rdi
callq 0x46ec
movl %eax, %r14d
leaq 0x41c8(%rip), %rsi      # 0x80b7
movq %r15, %rdi
callq 0x3430
movq %rax, %rdi
callq 0x46ec
movl %eax, %r12d
movq (%r15), %rdi
callq 0x46ec
movl %eax, %r13d
movl (%rbp), %edi
callq 0x6916
testq %rax, %rax
je 0x408f
movq %rax, %r15
movw $0x1, 0x22(%rax)
movl %r12d, %edi
movl %r13d, %esi
movl %r14d, %edx
movl 0x14(%rsp), %ecx
callq 0x5cc3
movq %rax, %r14
jmp 0x4203
movl (%rbp), %edi
callq 0x73cf
jmp 0x408f
testq %r14, %r14
je 0x4087
movl 0x4(%r14), %edi
jmp 0x408a
testq %r14, %r14
je 0x4094
cmpw $0x0, 0x22(%r14)
jne 0x4094
movq %r15, %rdi
callq 0x383d
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x4141(%rip), %rsi      # 0x80cc
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x422c
leaq 0x4130(%rip), %rsi      # 0x80d2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4245
leaq 0x411f(%rip), %rsi      # 0x80d8
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4262
leaq 0x410d(%rip), %rsi      # 0x80dd
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x4094
movl (%r15), %ecx
testl %ecx, %ecx
je 0x4094
pushq $0xc
popq %rax
movq %r15, %rdx
jmp 0x423f
testq %r14, %r14
je 0x4094
cmpw $0x0, 0x22(%r14)
jne 0x4094
movq %r15, %rdi
callq 0x383d
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x40ab(%rip), %rsi      # 0x80cc
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x4249
leaq 0x409a(%rip), %rsi      # 0x80d2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x426b
leaq 0x4089(%rip), %rsi      # 0x80d8
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4292
leaq 0x4077(%rip), %rsi      # 0x80dd
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x4094
movl 0xc(%r15), %eax
cmpl $0x1, %eax
je 0x4094
leaq 0xc(%r15), %rcx
movq %r15, %rdx
jmp 0x425e
movl (%rbp), %edi
callq 0x7348
movw $0x1, (%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x4094
cmpw $0x0, 0x22(%r14)
jne 0x4094
movq %r15, %rdi
callq 0x383d
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x4006(%rip), %rsi      # 0x80cc
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x427e
leaq 0x3ff5(%rip), %rsi      # 0x80d2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x42a9
leaq 0x3fe4(%rip), %rsi      # 0x80d8
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x42af
leaq 0x3fd2(%rip), %rsi      # 0x80dd
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x4094
movl (%r15), %eax
testl %eax, %eax
je 0x4094
decl %eax
movl %eax, (%r15)
jmp 0x42b2
testq %r14, %r14
je 0x421f
movl 0x4(%r14), %edi
jmp 0x4222
movq %r15, %rdi
callq 0x383d
movq %rax, %rdi
callq 0x46ec
testq %r14, %r14
je 0x408f
cmpl %eax, 0x24(%r14)
je 0x4094
movl %eax, 0x24(%r14)
callq 0x65f0
movl 0x20(%rax), %eax
cmpl 0x24(%r14), %eax
je 0x408f
movl 0x4(%r14), %edi
callq 0x727e
jmp 0x408f
movq %r15, %rdi
callq 0x383d
movq %rax, %r15
pushq $0x1
popq %rdi
pushq $0x10
popq %rsi
callq 0x3340
movq %rax, %r14
callq 0x65f0
movq %rax, %r12
movq (%rax), %rax
movq %rax, (%rsp)
leaq 0x3f3e(%rip), %rsi      # 0x80f6
leaq 0x3f45(%rip), %rdx      # 0x8104
leaq 0x3f51(%rip), %r8       # 0x8117
pushq $0x3
popq %rdi
movl $0x156, %ecx            # imm = 0x156
movq %r15, %r9
xorl %eax, %eax
callq 0x50dd
movq %r12, %rdi
movq %r15, %rsi
callq 0x5d9b
movups (%rax), %xmm0
movups %xmm0, (%r14)
movl (%rbp), %edi
callq 0x6916
testq %rax, %rax
je 0x408f
movq %rax, %r15
andw $0x0, 0x22(%rax)
movq 0x8(%r15), %rdi
callq 0x3060
movq %r15, %rdi
movq %r14, %rsi
callq 0x6c26
movq %r15, %rdi
jmp 0x42c0
movl (%rbp), %edi
callq 0x738a
jmp 0x408f
movl 0x4(%r15), %ecx
testl %ecx, %ecx
je 0x4094
leaq 0x4(%r15), %rdx
pushq $0x8
popq %rax
decl %ecx
movl %ecx, (%rdx)
jmp 0x4265
pushq $0x8
jmp 0x4264
movl 0x8(%r15), %eax
cmpl $0x1, %eax
je 0x4094
leaq 0x8(%r15), %rcx
leaq 0x4(%r15), %rdx
incl (%rdx)
jmp 0x42a3
pushq $0xc
popq %rax
incl (%r15,%rax)
jmp 0x42b2
movl 0x8(%r15), %eax
cmpl $0x1, %eax
je 0x4094
leaq 0x8(%r15), %rcx
jmp 0x42a3
movl 0x4(%r15), %eax
testl %eax, %eax
je 0x4094
decl %eax
movl %eax, 0x4(%r15)
jmp 0x42b2
movl 0xc(%r15), %eax
cmpl $0x1, %eax
je 0x4094
leaq 0xc(%r15), %rcx
decl %eax
movl %eax, (%rcx)
jmp 0x42b2
incl 0x4(%r15)
jmp 0x42b2
incl (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x6c26
movq %r14, %rdi
callq 0x5726
jmp 0x408f