Determine if the cursor is over Tools shelf, Properties shelf or 3D content I am developping a modal operator. How can I determine if the cursor is over the Tools shelf or Properties shelf or pure 3D content (don't know how to call the last one correctly)?

My idea is to block an event in modal(self, context, event) from passing it back to Blender if the cursor is over pure 3D content. In that case modal(..) returns {'RUNNING_MODAL'}. However if the cursor is over the Tools shelf or Properties shelf the event is passed back to Blender, so the user can change some parameters in GUI panels located in the Tools shelf or Properties shelf. In the latter case modal(..) returns {'PASS_THROUGH'}.
There is a context.region.type variable which can have the following values:


WINDOW - 3D View
UI - Properties Panel
TOOLS -  Tool Panel
values for the other possible regions (see the documentation)


However context.region.type seems to be determined once on operator invokation. So it will always have the same value while a modal operator is running. The only way seems to be to find out manually:

for region in context.area.regions:
    if(region.x &lt;= event.mouse_x &lt; region.x + region.width  and
       region.y &lt;= event.mouse_y &lt; region.y + region.height and
       region.type in ("TOOLS", "UI")):
        #
        return {'PASS_THROUGH'}


Perhaps a more appropriate way would be to check if the cursor is over the  3D View:

for region in context.area.regions:
    if(region.type == "WINDOW" and
       region.x &lt;= event.mouse_x &lt; region.x + region.width and
       region.y &lt;= event.mouse_y &lt; region.y + region.height):
        break
else:
    return {'PASS_THROUGH'}