// File: /workspace/github_c_makefile_star2_O2/baskerville[P]bspwm/src/pointer.c
// Function: grab_pointer
bool grab_pointer(pointer_action_t pac)
{
	xcb_window_t win = XCB_NONE;
	xcb_point_t pos;

	query_pointer(&win, &pos);

	coordinates_t loc;

	if (!locate_window(win, &loc)) {
		if (pac == ACTION_FOCUS) {
			monitor_t *m = monitor_from_point(pos);
			if (m != NULL && m != mon && (win == XCB_NONE || win == m->root)) {
				focus_node(m, m->desk, m->desk->focus);
				return true;
			}
		}
		return false;
	}

	if (pac == ACTION_FOCUS) {
		if (loc.node != mon->desk->focus) {
			focus_node(loc.monitor, loc.desktop, loc.node);
			return true;
		} else if (focus_follows_pointer) {
			stack(loc.desktop, loc.node, true);
		}
		return false;
	}

	if (loc.node->client->state == STATE_FULLSCREEN) {
		return true;
	}

	xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(dpy, xcb_grab_pointer(dpy, 0, root, XCB_EVENT_MASK_BUTTON_RELEASE|XCB_EVENT_MASK_BUTTON_MOTION, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_CURRENT_TIME), NULL);

	if (reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) {
		free(reply);
		return true;
	}
	free(reply);

	if (pac == ACTION_MOVE) {
		put_status(SBSC_MASK_POINTER_ACTION, "pointer_action 0x%08X 0x%08X 0x%08X move begin\n", loc.monitor->id, loc.desktop->id, loc.node->id);
	} else if (pac == ACTION_RESIZE_CORNER) {
		put_status(SBSC_MASK_POINTER_ACTION, "pointer_action 0x%08X 0x%08X 0x%08X resize_corner begin\n", loc.monitor->id, loc.desktop->id, loc.node->id);
	} else if (pac == ACTION_RESIZE_SIDE) {
		put_status(SBSC_MASK_POINTER_ACTION, "pointer_action 0x%08X 0x%08X 0x%08X resize_side begin\n", loc.monitor->id, loc.desktop->id, loc.node->id);
	}

	track_pointer(loc, pac, pos);

	return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movl %edi, %r14d
leaq 0x24(%rsp), %rbx
andl $0x0, (%rbx)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xfb66
movl (%rbx), %edi
leaq 0x28(%rsp), %rsi
callq 0x199cc
testb %al, %al
je 0xe689
movq 0x38(%rsp), %rdx
cmpl $0x1, %r14d
jne 0xe6df
leaq 0x1a0a4(%rip), %rax     # 0x28710
movq (%rax), %rax
movq 0x58(%rax), %rax
cmpq 0x38(%rax), %rdx
je 0xe746
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
jmp 0xe6d3
cmpl $0x1, %r14d
jne 0xe764
movl 0x20(%rsp), %edi
callq 0x72fe
xorl %ebx, %ebx
testq %rax, %rax
je 0xe766
leaq 0x1a062(%rip), %rcx     # 0x28710
cmpq (%rcx), %rax
je 0xe766
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
je 0xe6c8
cmpl 0x28(%rax), %ecx
jne 0xe764
movq 0x58(%rax), %rsi
movq 0x38(%rsi), %rdx
movq %rax, %rdi
callq 0x9cf6
movb $0x1, %bl
jmp 0xe766
movq 0x48(%rdx), %rax
movb $0x1, %bl
cmpl $0x3, 0x308(%rax)
je 0xe766
leaq 0x19fd3(%rip), %rax     # 0x286c8
movq (%rax), %r15
leaq 0x1a079(%rip), %rax     # 0x28778
movl (%rax), %edx
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x1
popq %r8
movq %r15, %rdi
xorl %esi, %esi
movl $0x2008, %ecx           # imm = 0x2008
movl %r8d, %r9d
callq 0x4250
movq %r15, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x45f0
testq %rax, %rax
je 0xe73c
cmpb $0x0, 0x1(%rax)
je 0xe772
movq %rax, %rdi
callq 0x4460
jmp 0xe766
leaq 0x1a6ad(%rip), %rax     # 0x28dfa
cmpb $0x1, (%rax)
jne 0xe764
movq 0x30(%rsp), %rdi
pushq $0x1
popq %rax
movq %rdx, %rsi
movl %eax, %edx
callq 0xc7ea
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rdi
callq 0x4460
leal -0x2(%r14), %eax
cmpl $0x2, %eax
ja 0xe7b7
movl %eax, %eax
leaq 0x102d4(%rip), %rcx     # 0x1ea60
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movl 0x20(%rax), %edx
movl 0x20(%rcx), %ecx
movq 0x38(%rsp), %rax
movl (%rax), %r8d
movl $0x8000000, %edi        # imm = 0x8000000
xorl %eax, %eax
callq 0x1d07d
movl 0x20(%rsp), %esi
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x28(%rsp), %xmm0
movups %xmm0, (%rsp)
movl %r14d, %edi
callq 0xe7d8
jmp 0xe766