# How to get mouse width/height if bl_options = {'GRAB_CURSOR', 'BLOCKING'}

I'm trying to get visual position of cursor in modal VIEW_3D area if bl_options = {'GRAB_CURSOR', 'BLOCKING'}. Value continue to go further after reaching the area border but cursor appears at the opposite side.

If anyone is wondering how to do it:

for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
area_W = area.width-2 # to compensate gaps on borders
area_H = area.height-28

print("Area  WIDTH/HEIGHT:", area_W, area_H)
print("Curr  WIDTH/HEIGHT:", event.mouse_region_x, event.mouse_region_y)

# calculation (/-divide, or //-divide and round without using int())
crossing_count_W = event.mouse_region_x / area_W
crossing_count_H = event.mouse_region_y / area_H

self.mouse_area_x = event.mouse_region_x - area_W * int(crossing_count_W)
if self.mouse_area_x < 0:
self.mouse_area_x = area_W + self.mouse_area_x

self.mouse_area_y = event.mouse_region_y - area_H * int(crossing_count_H)
if self.mouse_area_y < 0:
self.mouse_area_y = area_H + self.mouse_area_y

print("Mouse WIDTH/HEIGHT:", self.mouse_area_x, self.mouse_area_y)


Maybe someone has a more elegant solution?

I have no idea how to calculate more accurate value for compensation (for area width and height). After 2+ crossing position become more and more inaccurate.