// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movl %edi, %ebp
leaq 0x24(%rsp), %rbx
movl $0x0, (%rbx)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x10928
movl (%rbx), %edi
leaq 0x28(%rsp), %rsi
callq 0x1b0a3
testb %al, %al
je 0xf27a
movq 0x38(%rsp), %rdx
cmpl $0x1, %ebp
jne 0xf2cf
leaq 0x1a4b3(%rip), %rax     # 0x29710
movq (%rax), %rax
movq 0x58(%rax), %rax
cmpq 0x38(%rax), %rdx
je 0xf33a
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
jmp 0xf2c3
cmpl $0x1, %ebp
jne 0xf358
movl 0x20(%rsp), %edi
callq 0x752f
xorl %ebx, %ebx
testq %rax, %rax
je 0xf35a
leaq 0x1a472(%rip), %rcx     # 0x29710
cmpq (%rcx), %rax
je 0xf35a
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
je 0xf2b8
cmpl 0x28(%rax), %ecx
jne 0xf358
movq 0x58(%rax), %rsi
movq 0x38(%rsi), %rdx
movq %rax, %rdi
callq 0xa2cd
movb $0x1, %bl
jmp 0xf35a
movq 0x48(%rdx), %rax
movb $0x1, %bl
cmpl $0x3, 0x308(%rax)
je 0xf35a
leaq 0x1a3e3(%rip), %rax     # 0x296c8
movq (%rax), %r14
leaq 0x1a489(%rip), %rax     # 0x29778
movl (%rax), %edx
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x8(%rsp)
movl %eax, (%rsp)
movq %r14, %rdi
xorl %esi, %esi
movl $0x2008, %ecx           # imm = 0x2008
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x4250
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x45f0
testq %rax, %rax
je 0xf330
cmpb $0x0, 0x1(%rax)
je 0xf365
movq %rax, %rdi
callq 0x4460
jmp 0xf35a
leaq 0x1aab9(%rip), %rax     # 0x29dfa
cmpb $0x1, (%rax)
jne 0xf358
movq 0x30(%rsp), %rdi
movq %rdx, %rsi
movl $0x1, %edx
callq 0xd20e
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rdi
callq 0x4460
cmpl $0x2, %ebp
je 0xf38e
cmpl $0x3, %ebp
je 0xf385
cmpl $0x4, %ebp
jne 0xf3b9
leaq 0x1071d(%rip), %rsi     # 0x1faa0
jmp 0xf395
leaq 0x1074d(%rip), %rsi     # 0x1fad9
jmp 0xf395
leaq 0x106db(%rip), %rsi     # 0x1fa70
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 0x1eb0b
movl 0x20(%rsp), %esi
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x28(%rsp), %xmm0
movups %xmm0, (%rsp)
movl %ebp, %edi
callq 0xf3d9
jmp 0xf35a