// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/pointer.c
// Function: track_pointer
void track_pointer(coordinates_t loc, pointer_action_t pac, xcb_point_t pos)
{
	node_t *n = loc.node;
	resize_handle_t rh = get_handle(loc.node, pos, pac);

	uint16_t last_motion_x = pos.x, last_motion_y = pos.y;
	xcb_timestamp_t last_motion_time = 0;

	xcb_generic_event_t *evt = NULL;

	grabbing = true;
	grabbed_node = n;

	do {
		free(evt);
		while ((evt = xcb_wait_for_event(dpy)) == NULL) {
			xcb_flush(dpy);
		}
		uint8_t resp_type = XCB_EVENT_RESPONSE_TYPE(evt);
		if (resp_type == XCB_MOTION_NOTIFY) {
			xcb_motion_notify_event_t *e = (xcb_motion_notify_event_t*) evt;
			uint32_t dtime = e->time - last_motion_time;
			if (dtime < pointer_motion_interval) {
				continue;
			}
			last_motion_time = e->time;
			int16_t dx = e->root_x - last_motion_x;
			int16_t dy = e->root_y - last_motion_y;
			if (pac == ACTION_MOVE) {
				move_client(&loc, dx, dy);
			} else if (n) {
				client_t *c = n->client;
				if (c && SHOULD_HONOR_SIZE_HINTS(c->honor_size_hints, c->state)) {
					resize_client(&loc, rh, e->root_x, e->root_y, false);
				} else {
					resize_client(&loc, rh, dx, dy, true);
				}
			}
			last_motion_x = e->root_x;
			last_motion_y = e->root_y;
			xcb_flush(dpy);
		} else if (resp_type == XCB_BUTTON_RELEASE) {
			grabbing = false;
		} else {
			handle_event(evt);
		}
	} while (grabbing && grabbed_node != NULL);
	free(evt);

	xcb_ungrab_pointer(dpy, XCB_CURRENT_TIME);

	if (grabbed_node == NULL) {
		grabbing = false;
		return;
	}

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

	xcb_rectangle_t r = get_rectangle(NULL, NULL, n);

	put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", loc.monitor->id, loc.desktop->id, loc.node->id, r.width, r.height, r.x, r.y);

	if ((pac == ACTION_MOVE && IS_TILED(n->client)) ||
	    ((pac == ACTION_RESIZE_CORNER || pac == ACTION_RESIZE_SIDE) &&
	     n->client->state == STATE_TILED)) {
		for (node_t *f = first_extrema(loc.desktop->root); f != NULL; f = next_leaf(f, loc.desktop->root)) {
			if (f == n || f->client == NULL || !IS_TILED(f->client)) {
				continue;
			}
			xcb_rectangle_t r = f->client->tiled_rectangle;
			put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", loc.monitor->id, loc.desktop->id, f->id, r.width, r.height, r.x, r.y);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movl %edi, %edx
leaq 0x50(%rsp), %rax
movl %esi, %r13d
shrl $0x10, %r13d
movq 0x10(%rax), %r14
movq %r14, %rdi
movl %edx, 0xc(%rsp)
callq 0xf145
movl %eax, 0x8(%rsp)
movb $0x1, 0x1aa14(%rip)     # 0x29e26
movq %r14, 0x10(%rsp)
movq %r14, 0x1aa0a(%rip)     # 0x29e28
xorl %r12d, %r12d
leaq 0x1a2a0(%rip), %r15     # 0x296c8
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x4460
movq (%r15), %rdi
callq 0x4610
testq %rax, %rax
jne 0xf449
movq (%r15), %rdi
callq 0x4660
jmp 0xf432
movq %rax, %r12
movzbl (%rax), %eax
andl $0x7f, %eax
cmpl $0x5, %eax
je 0xf4a2
cmpl $0x6, %eax
jne 0xf4ab
movl 0x4(%r12), %r14d
movl %r14d, %eax
subl %ebp, %eax
leaq 0x1a977(%rip), %rcx     # 0x29de4
cmpl (%rcx), %eax
jb 0xf4b3
movswl 0x14(%r12), %edx
movl %edx, %eax
subl %ebx, %eax
movswl 0x16(%r12), %ecx
movl %ecx, %edi
subl %r13d, %edi
cmpl $0x2, 0xc(%rsp)
jne 0xf4d9
movswl %ax, %esi
movswl %di, %edx
leaq 0x50(%rsp), %rdi
callq 0x1070c
jmp 0xf55e
movb $0x0, 0x1a97d(%rip)     # 0x29e26
jmp 0xf4b3
movq %r12, %rdi
callq 0xdc1c
movl %ebp, %r14d
cmpb $0x1, 0x1a969(%rip)     # 0x29e26
jne 0xf577
cmpq $0x0, 0x1a95d(%rip)     # 0x29e28
movl %r14d, %ebp
jne 0xf42a
jmp 0xf577
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0xf55e
movq 0x48(%rsi), %rsi
testq %rsi, %rsi
je 0xf544
movl 0x328(%rsi), %r8d
cmpl $0x3, %r8d
je 0xf51a
cmpl $0x2, %r8d
je 0xf529
cmpl $0x1, %r8d
jne 0xf544
cmpl $0x3, 0x308(%rsi)
jne 0xf536
cmpl $0x2, %r8d
je 0xf529
cmpl $0x3, %r8d
jne 0xf544
cmpl $0x0, 0x308(%rsi)
je 0xf536
cmpl $0x2, %r8d
jne 0xf544
movl 0x308(%rsi), %esi
decl %esi
cmpl $0x1, %esi
ja 0xf544
leaq 0x50(%rsp), %rdi
movl 0x8(%rsp), %esi
xorl %r8d, %r8d
jmp 0xf559
movswl %ax, %edx
movswl %di, %ecx
leaq 0x50(%rsp), %rdi
movl 0x8(%rsp), %esi
movl $0x1, %r8d
callq 0x10aeb
movzwl 0x14(%r12), %ebx
movzwl 0x16(%r12), %r13d
movq (%r15), %rdi
callq 0x4660
jmp 0xf4b6
movq %r12, %rdi
callq 0x4460
movq (%r15), %rdi
xorl %esi, %esi
callq 0x4050
cmpq $0x0, 0x1a897(%rip)     # 0x29e28
je 0xf5af
movl 0xc(%rsp), %ebp
cmpl $0x2, %ebp
jne 0xf5bb
leaq 0x1056d(%rip), %rsi     # 0x1fb10
leaq 0x50(%rsp), %r14
movq 0x10(%rsp), %r13
jmp 0xf5df
movb $0x0, 0x1a870(%rip)     # 0x29e26
jmp 0xf71f
cmpl $0x4, %ebp
leaq 0x50(%rsp), %r14
movq 0x10(%rsp), %r13
je 0xf5d8
cmpl $0x3, %ebp
jne 0xf5fc
leaq 0x1059f(%rip), %rsi     # 0x1fb75
jmp 0xf5df
leaq 0x1055f(%rip), %rsi     # 0x1fb3e
movq (%r14), %rax
movq 0x8(%r14), %rcx
movl 0x20(%rax), %edx
movl 0x20(%rcx), %ecx
movl (%r13), %r8d
movl $0x8000000, %edi        # imm = 0x8000000
xorl %eax, %eax
callq 0x1eb0b
xorl %edi, %edi
xorl %esi, %esi
movq %r13, %rdx
callq 0x982d
movq %rax, %r10
shrq $0x20, %rax
movq %r10, %r11
shrq $0x30, %r11
movq (%r14), %rcx
movq 0x8(%r14), %rsi
movl 0x20(%rcx), %edx
movl 0x20(%rsi), %ecx
movq 0x10(%r14), %rsi
movl (%rsi), %r8d
movzwl %ax, %r9d
movswl %r10w, %ebx
sarl $0x10, %r10d
subq $0x8, %rsp
leaq 0xffdf(%rip), %rsi      # 0x1f620
movl $0x800000, %edi         # imm = 0x800000
xorl %eax, %eax
pushq %r10
pushq %rbx
pushq %r11
callq 0x1eb0b
addq $0x20, %rsp
cmpl $0x2, %ebp
jne 0xf668
movq 0x48(%r13), %rax
cmpl $0x2, 0x308(%rax)
jb 0xf685
addl $-0x3, %ebp
cmpl $0x1, %ebp
ja 0xf71f
movq 0x48(%r13), %rax
cmpl $0x0, 0x308(%rax)
jne 0xf71f
movq 0x8(%r14), %rax
movq 0x30(%rax), %rdi
callq 0x92fd
testq %rax, %rax
je 0xf71f
movq %rax, %r15
leaq 0xff7b(%rip), %r12      # 0x1f620
cmpq %r13, %r15
je 0xf707
movq 0x48(%r15), %rax
testq %rax, %rax
je 0xf707
cmpl $0x1, 0x308(%rax)
ja 0xf707
movswl 0x320(%rax), %r10d
movswl 0x322(%rax), %r11d
movzwl 0x324(%rax), %r9d
movzwl 0x326(%rax), %ebx
movq (%r14), %rax
movq 0x8(%r14), %rcx
movl 0x20(%rax), %edx
movl 0x20(%rcx), %ecx
movl (%r15), %r8d
subq $0x8, %rsp
movl $0x800000, %edi         # imm = 0x800000
movq %r12, %rsi
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
callq 0x1eb0b
addq $0x20, %rsp
movq 0x8(%r14), %rax
movq 0x30(%rax), %rsi
movq %r15, %rdi
callq 0x9363
movq %rax, %r15
testq %rax, %rax
jne 0xf6a5
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop