// File: /workspace/github_c_makefile_star2_O2/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, %r12d
shrl $0x10, %r12d
movq 0x10(%rax), %r14
movq %r14, %rdi
movl %edx, 0xc(%rsp)
callq 0xe563
movl %eax, 0x8(%rsp)
movb $0x1, 0x1a615(%rip)     # 0x28e26
movq %r14, 0x10(%rsp)
movq %r14, 0x1a60b(%rip)     # 0x28e28
xorl %r13d, %r13d
leaq 0x19ea1(%rip), %r15     # 0x286c8
xorl %ebp, %ebp
movq %r13, %rdi
callq 0x4460
movq (%r15), %rdi
callq 0x4610
testq %rax, %rax
jne 0xe848
movq (%r15), %rdi
callq 0x4660
jmp 0xe831
movq %rax, %r13
movzbl (%rax), %eax
andl $0x7f, %eax
cmpl $0x5, %eax
je 0xe8a4
cmpl $0x6, %eax
jne 0xe8ad
movl 0x4(%r13), %r14d
movl %r14d, %eax
subl %ebp, %eax
leaq 0x1a579(%rip), %rcx     # 0x28de4
cmpl (%rcx), %eax
jb 0xe8b5
movswl 0x14(%r13), %edx
movl %edx, %eax
subl %ebx, %eax
movswl 0x16(%r13), %ecx
movl %ecx, %esi
subl %r12d, %esi
movswl %ax, %r8d
movswl %si, %eax
cmpl $0x2, 0xc(%rsp)
jne 0xe8db
leaq 0x50(%rsp), %rdi
movl %r8d, %esi
movl %eax, %edx
callq 0xf9a8
jmp 0xe94c
movb $0x0, 0x1a57b(%rip)     # 0x28e26
jmp 0xe8b5
movq %r13, %rdi
callq 0xd0d4
movl %ebp, %r14d
cmpb $0x1, 0x1a567(%rip)     # 0x28e26
jne 0xe963
cmpq $0x0, 0x1a55b(%rip)     # 0x28e28
movl %r14d, %ebp
jne 0xe829
jmp 0xe963
cmpq $0x0, 0x10(%rsp)
je 0xe94c
movq 0x10(%rsp), %rsi
movq 0x48(%rsi), %rsi
testq %rsi, %rsi
je 0xe935
movl 0x328(%rsi), %edi
cmpl $0x3, %edi
je 0xe92c
cmpl $0x2, %edi
je 0xe911
cmpl $0x1, %edi
jne 0xe935
cmpl $0x3, 0x308(%rsi)
jne 0xe91e
jmp 0xe935
movl 0x308(%rsi), %esi
decl %esi
cmpl $0x1, %esi
ja 0xe935
leaq 0x50(%rsp), %rdi
movl 0x8(%rsp), %esi
xorl %r8d, %r8d
jmp 0xe947
cmpl $0x0, 0x308(%rsi)
je 0xe91e
leaq 0x50(%rsp), %rdi
movl 0x8(%rsp), %esi
movl %r8d, %edx
movl %eax, %ecx
pushq $0x1
popq %r8
callq 0xfd0b
movzwl 0x14(%r13), %ebx
movzwl 0x16(%r13), %r12d
movq (%r15), %rdi
callq 0x4660
jmp 0xe8b8
movq %r13, %rdi
callq 0x4460
movq (%r15), %rdi
xorl %esi, %esi
callq 0x4050
cmpq $0x0, 0x1a4ab(%rip)     # 0x28e28
je 0xe99b
movl 0xc(%rsp), %ebp
cmpl $0x2, %ebp
jne 0xe9a7
leaq 0x1017d(%rip), %rsi     # 0x1eb0c
leaq 0x50(%rsp), %r14
movq 0x10(%rsp), %r13
jmp 0xe9cb
movb $0x0, 0x1a484(%rip)     # 0x28e26
jmp 0xea6b
cmpl $0x4, %ebp
leaq 0x50(%rsp), %r14
movq 0x10(%rsp), %r13
je 0xe9c4
cmpl $0x3, %ebp
jne 0xe9e8
leaq 0x101af(%rip), %rsi     # 0x1eb71
jmp 0xe9cb
leaq 0x1016f(%rip), %rsi     # 0x1eb3a
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 0x1d07d
xorl %edi, %edi
xorl %esi, %esi
movq %r13, %rdx
callq 0x932e
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 0xfbe3(%rip), %rsi      # 0x1e610
movl $0x800000, %edi         # imm = 0x800000
xorl %eax, %eax
pushq %r10
pushq %rbx
pushq %r11
callq 0x1d07d
addq $0x20, %rsp
cmpl $0x2, %ebp
jne 0xea56
movq 0x48(%r13), %rax
cmpl $0x2, 0x308(%rax)
jae 0xea6b
jmp 0xea7a
addl $-0x3, %ebp
cmpl $0x1, %ebp
ja 0xea6b
movq 0x48(%r13), %rax
cmpl $0x0, 0x308(%rax)
je 0xea7a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rax
movq 0x30(%rax), %rdi
callq 0x8e72
movq %rax, %r12
leaq 0xfb7f(%rip), %r15      # 0x1e610
testq %r12, %r12
je 0xea6b
cmpq %r13, %r12
je 0xeafa
movq 0x48(%r12), %rax
testq %rax, %rax
je 0xeafa
cmpl $0x1, 0x308(%rax)
ja 0xeafa
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 (%r12), %r8d
subq $0x8, %rsp
movl $0x800000, %edi         # imm = 0x800000
movq %r15, %rsi
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
callq 0x1d07d
addq $0x20, %rsp
movq 0x8(%r14), %rax
movq 0x30(%rax), %rsi
movq %r12, %rdi
callq 0x8ed0
movq %rax, %r12
jmp 0xea91
nop