// File: /workspace/github_c_makefile_star2_O3/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
movl $0x0, (%rbx)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x1095f
movl (%rbx), %edi
leaq 0x28(%rsp), %rsi
callq 0x1ae3e
testb %al, %al
je 0xf2ed
movq 0x38(%rsp), %rdx
cmpl $0x1, %r14d
jne 0xf343
leaq 0x1a440(%rip), %rax     # 0x29710
movq (%rax), %rax
movq 0x58(%rax), %rax
cmpq 0x38(%rax), %rdx
je 0xf3ae
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
jmp 0xf337
cmpl $0x1, %r14d
jne 0xf3cc
movl 0x20(%rsp), %edi
callq 0x7446
xorl %ebx, %ebx
testq %rax, %rax
je 0xf3ce
leaq 0x1a3fe(%rip), %rcx     # 0x29710
cmpq (%rcx), %rax
je 0xf3ce
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
je 0xf32c
cmpl 0x28(%rax), %ecx
jne 0xf3cc
movq 0x58(%rax), %rsi
movq 0x38(%rsi), %rdx
movq %rax, %rdi
callq 0xa308
movb $0x1, %bl
jmp 0xf3ce
movq 0x48(%rdx), %rax
movb $0x1, %bl
cmpl $0x3, 0x308(%rax)
je 0xf3ce
leaq 0x1a36f(%rip), %rax     # 0x296c8
movq (%rax), %r15
leaq 0x1a415(%rip), %rax     # 0x29778
movl (%rax), %edx
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x8(%rsp)
movl %eax, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movl $0x2008, %ecx           # imm = 0x2008
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x4250
movq %r15, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x45f0
testq %rax, %rax
je 0xf3a4
cmpb $0x0, 0x1(%rax)
je 0xf3da
movq %rax, %rdi
callq 0x4460
jmp 0xf3ce
leaq 0x1aa45(%rip), %rax     # 0x29dfa
cmpb $0x1, (%rax)
jne 0xf3cc
movq 0x30(%rsp), %rdi
movq %rdx, %rsi
movl $0x1, %edx
callq 0xd303
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 0xf41f
movl %eax, %eax
leaq 0x1066c(%rip), %rcx     # 0x1fa60
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 0x1e6b8
movl 0x20(%rsp), %esi
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x28(%rsp), %xmm0
movups %xmm0, (%rsp)
movl %r14d, %edi
callq 0xf440
jmp 0xf3ce