// File: /workspace/github_c_makefile_star2_O3/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 0xf1b5
movl %eax, 0x8(%rsp)
movb $0x1, 0x1a9ad(%rip)     # 0x29e26
movq %r14, 0x10(%rsp)
movq %r14, 0x1a9a3(%rip)     # 0x29e28
xorl %r12d, %r12d
leaq 0x1a239(%rip), %r15     # 0x296c8
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x4460
movq (%r15), %rdi
callq 0x4610
testq %rax, %rax
jne 0xf4b0
movq (%r15), %rdi
callq 0x4660
jmp 0xf499
movq %rax, %r12
movzbl (%rax), %eax
andl $0x7f, %eax
cmpl $0x5, %eax
je 0xf509
cmpl $0x6, %eax
jne 0xf512
movl 0x4(%r12), %r14d
movl %r14d, %eax
subl %ebp, %eax
leaq 0x1a910(%rip), %rcx     # 0x29de4
cmpl (%rcx), %eax
jb 0xf51a
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 0xf540
movswl %ax, %esi
movswl %di, %edx
leaq 0x50(%rsp), %rdi
callq 0x10783
jmp 0xf5b5
movb $0x0, 0x1a916(%rip)     # 0x29e26
jmp 0xf51a
movq %r12, %rdi
callq 0xdc7c
movl %ebp, %r14d
cmpb $0x1, 0x1a902(%rip)     # 0x29e26
jne 0xf5ce
cmpq $0x0, 0x1a8f6(%rip)     # 0x29e28
movl %r14d, %ebp
jne 0xf491
jmp 0xf5ce
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0xf5b5
movq 0x48(%rsi), %rsi
testq %rsi, %rsi
je 0xf59b
movl 0x328(%rsi), %r8d
cmpl $0x3, %r8d
je 0xf592
cmpl $0x2, %r8d
je 0xf577
cmpl $0x1, %r8d
jne 0xf59b
cmpl $0x3, 0x308(%rsi)
jne 0xf584
jmp 0xf59b
movl 0x308(%rsi), %esi
decl %esi
cmpl $0x1, %esi
ja 0xf59b
leaq 0x50(%rsp), %rdi
movl 0x8(%rsp), %esi
xorl %r8d, %r8d
jmp 0xf5b0
cmpl $0x0, 0x308(%rsi)
je 0xf584
movswl %ax, %edx
movswl %di, %ecx
leaq 0x50(%rsp), %rdi
movl 0x8(%rsp), %esi
movl $0x1, %r8d
callq 0x10b1d
movzwl 0x14(%r12), %ebx
movzwl 0x16(%r12), %r13d
movq (%r15), %rdi
callq 0x4660
jmp 0xf51d
movq %r12, %rdi
callq 0x4460
movq (%r15), %rdi
xorl %esi, %esi
callq 0x4050
cmpq $0x0, 0x1a840(%rip)     # 0x29e28
je 0xf606
movl 0xc(%rsp), %ebp
cmpl $0x2, %ebp
jne 0xf612
leaq 0x10512(%rip), %rsi     # 0x1fb0c
leaq 0x50(%rsp), %r14
movq 0x10(%rsp), %r13
jmp 0xf636
movb $0x0, 0x1a819(%rip)     # 0x29e26
jmp 0xf77b
cmpl $0x4, %ebp
leaq 0x50(%rsp), %r14
movq 0x10(%rsp), %r13
je 0xf62f
cmpl $0x3, %ebp
jne 0xf653
leaq 0x10544(%rip), %rsi     # 0x1fb71
jmp 0xf636
leaq 0x10504(%rip), %rsi     # 0x1fb3a
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 0x1e6b8
xorl %edi, %edi
xorl %esi, %esi
movq %r13, %rdx
callq 0x970b
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 0xff78(%rip), %rsi      # 0x1f610
movl $0x800000, %edi         # imm = 0x800000
xorl %eax, %eax
pushq %r10
pushq %rbx
pushq %r11
callq 0x1e6b8
addq $0x20, %rsp
cmpl $0x2, %ebp
jne 0xf6c4
movq 0x48(%r13), %rax
cmpl $0x2, 0x308(%rax)
jb 0xf6e1
jmp 0xf77b
addl $-0x3, %ebp
cmpl $0x1, %ebp
ja 0xf77b
movq 0x48(%r13), %rax
cmpl $0x0, 0x308(%rax)
jne 0xf77b
movq 0x8(%r14), %rax
movq 0x30(%rax), %rdi
callq 0x920c
testq %rax, %rax
je 0xf77b
movq %rax, %r15
leaq 0xff0f(%rip), %r12      # 0x1f610
cmpq %r13, %r15
je 0xf763
movq 0x48(%r15), %rax
testq %rax, %rax
je 0xf763
cmpl $0x1, 0x308(%rax)
ja 0xf763
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 0x1e6b8
addq $0x20, %rsp
movq 0x8(%r14), %rax
movq 0x30(%rax), %rsi
movq %r15, %rdi
callq 0x926e
movq %rax, %r15
testq %rax, %rax
jne 0xf701
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop