Refactor: allow event handlers to have a poll function
authorJacques Lucke <mail@jlucke.com>
Wed, 24 Apr 2019 15:34:48 +0000 (17:34 +0200)
committerJacques Lucke <mail@jlucke.com>
Wed, 24 Apr 2019 15:34:48 +0000 (17:34 +0200)
Previously only a fixed bounding box could be used.
This was not flexible enough.
T63193 will benefit from this refactor.

Reviewers: brecht, campbellbarton

16 files changed:
source/blender/editors/screen/area.c
source/blender/editors/space_action/space_action.c
source/blender/editors/space_clip/space_clip.c
source/blender/editors/space_console/space_console.c
source/blender/editors/space_file/space_file.c
source/blender/editors/space_graph/space_graph.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_nla/space_nla.c
source/blender/editors/space_node/space_node.c
source/blender/editors/space_outliner/space_outliner.c
source/blender/editors/space_script/space_script.c
source/blender/editors/space_sequencer/space_sequencer.c
source/blender/editors/space_text/space_text.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/wm_event_system.h

index 5cd5153b060908ceb64995316ec047e00d109081..a06674bd8b815d4f5a4e7149eb1e89a9367d63a1 100644 (file)
@@ -1550,6 +1550,13 @@ static void region_subwindow(ARegion *ar)
   ar->visible = !hidden;
 }
 
+static bool event_in_markers_region(const ARegion *ar, const wmEvent *event)
+{
+  rcti rect = ar->winrct;
+  rect.ymax = rect.ymin + UI_MARKER_MARGIN_Y;
+  return BLI_rcti_isect_pt(&rect, event->x, event->y);
+}
+
 /**
  * \param ar: Region, may be NULL when adding handlers for \a sa.
  */
@@ -1591,13 +1598,7 @@ static void ed_default_handlers(
   if (flag & ED_KEYMAP_MARKERS) {
     /* time-markers */
     wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Markers", 0, 0);
-
-    /* use a boundbox restricted map */
-    /* same local check for all areas */
-    static rcti rect = {0, 10000, 0, -1};
-    rect.ymax = UI_MARKER_MARGIN_Y;
-    BLI_assert(ar->type->regionid == RGN_TYPE_WINDOW);
-    WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
+    WM_event_add_keymap_handler_poll(handlers, keymap, event_in_markers_region);
   }
   if (flag & ED_KEYMAP_ANIMATION) {
     /* frame changing and timeline operators (for time spaces) */
index d6d46904db36fa4e5797904a7231d9308642c645..5a9c3a66f2bea8eded772b546666ffe5ac8ae683 100644 (file)
@@ -166,7 +166,7 @@ static void action_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Dopesheet", SPACE_ACTION, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
   keymap = WM_keymap_ensure(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
 }
@@ -271,7 +271,7 @@ static void action_channel_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Animation Channels", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
index f176763abf5e7b008258395bdaeccc5cafc26016..aa58e4cbe54a871824f3d89fae4184bcc6f8e3d2 100644 (file)
@@ -859,14 +859,14 @@ static void clip_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* mask polls mode */
   keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Clip Editor", SPACE_CLIP, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void clip_main_region_draw(const bContext *C, ARegion *ar)
@@ -1002,13 +1002,13 @@ static void clip_preview_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Clip", SPACE_CLIP, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Clip Graph Editor", SPACE_CLIP, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void graph_region_draw(const bContext *C, ARegion *ar)
@@ -1140,7 +1140,7 @@ static void clip_channels_region_init(wmWindowManager *wm, ARegion *ar)
   UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Clip Dopesheet Editor", SPACE_CLIP, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void clip_channels_region_draw(const bContext *C, ARegion *ar)
index 2cf8f6c46b9edc8495d9ea8304b82715bd6622a6..834ede2a9274b6b8a532bf13cade58457d18740c 100644 (file)
@@ -136,7 +136,7 @@ static void console_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Console", SPACE_CONSOLE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* add drop boxes */
   lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
index e0d370cdde25556c5f6de28719092e63b1d157a0..1216755151ba81b18537edb7b1e7e3f28ca47e4e 100644 (file)
@@ -316,10 +316,10 @@ static void file_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymaps */
   keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "File Browser Main", SPACE_FILE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void file_main_region_listener(wmWindow *UNUSED(win),
@@ -498,7 +498,7 @@ static void file_tools_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymaps */
   keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void file_tools_region_draw(const bContext *C, ARegion *ar)
@@ -528,7 +528,7 @@ static void file_header_region_init(wmWindowManager *wm, ARegion *ar)
   ED_region_header_init(ar);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void file_header_region_draw(const bContext *C, ARegion *ar)
@@ -545,10 +545,10 @@ static void file_ui_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "File Browser Buttons", SPACE_FILE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void file_ui_region_draw(const bContext *C, ARegion *ar)
index e45a27a08fb511b9015cdb140d088b54bbfcd61d..c02021591db4a505be36662cc035ab3836c60cd3 100644 (file)
@@ -186,7 +186,7 @@ static void graph_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor", SPACE_GRAPH, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
   keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor Generic", SPACE_GRAPH, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
 }
@@ -353,7 +353,7 @@ static void graph_channel_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Animation Channels", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
   keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor Generic", SPACE_GRAPH, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
 }
@@ -406,7 +406,7 @@ static void graph_buttons_region_init(wmWindowManager *wm, ARegion *ar)
   ED_region_panels_init(wm, ar);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Graph Editor Generic", SPACE_GRAPH, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void graph_buttons_region_draw(const bContext *C, ARegion *ar)
index 1e1d1e570b3a85c48dcdc372f575a94c1380ab20..ebecd474621b350d2db4b95f9bb6784ef270e956 100644 (file)
@@ -536,17 +536,17 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* mask polls mode */
   keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* image paint polls for mode */
   keymap = WM_keymap_ensure(wm->defaultconf, "Curve", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Paint Curve", 0, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Image Paint", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "UV Editor", 0, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
@@ -558,7 +558,7 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
   keymap = WM_keymap_ensure(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
   keymap = WM_keymap_ensure(wm->defaultconf, "Image", SPACE_IMAGE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void image_main_region_draw(const bContext *C, ARegion *ar)
index 527a4f6e5f6e93808a58cec8c6e8a665e1b9d2b2..69fc97e8ea5391680fc1d3a6ebfb62f5b966464a 100644 (file)
@@ -174,13 +174,13 @@ static void nla_channel_region_init(wmWindowManager *wm, ARegion *ar)
   /* own keymap */
   /* own channels map first to override some channel keymaps */
   keymap = WM_keymap_ensure(wm->defaultconf, "NLA Channels", SPACE_NLA, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
   /* now generic channels map for everything else that can apply */
   keymap = WM_keymap_ensure(wm->defaultconf, "Animation Channels", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "NLA Generic", SPACE_NLA, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 /* draw entirely, view changes should be handled here */
@@ -220,7 +220,7 @@ static void nla_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "NLA Editor", SPACE_NLA, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
   keymap = WM_keymap_ensure(wm->defaultconf, "NLA Generic", SPACE_NLA, 0);
   WM_event_add_keymap_handler(&ar->handlers, keymap);
 }
@@ -328,7 +328,7 @@ static void nla_buttons_region_init(wmWindowManager *wm, ARegion *ar)
   ED_region_panels_init(wm, ar);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "NLA Generic", SPACE_NLA, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void nla_buttons_region_draw(const bContext *C, ARegion *ar)
index 94380814fe84ab2fbfa5364bbf29444e5f25b5e9..2152bb9847ad714b198c0bb0530ea0c125cdffca 100644 (file)
@@ -617,7 +617,7 @@ static void node_main_region_init(wmWindowManager *wm, ARegion *ar)
   WM_event_add_keymap_handler(&ar->handlers, keymap);
 
   keymap = WM_keymap_ensure(wm->defaultconf, "Node Editor", SPACE_NODE, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* add drop boxes */
   lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW);
index 26b97a1cdd9e5a5d9ff21c8131b2ad6d6320b491..8e9cd9743b626483c49d97238c7f12dcb45a0a2f 100644 (file)
@@ -74,8 +74,7 @@ static void outliner_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Outliner", SPACE_OUTLINER, 0);
-  /* don't pass on view2d mask, it's always set with scrollbar space, hide fails */
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, NULL, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* Add dropboxes */
   lb = WM_dropboxmap_find("Outliner", SPACE_OUTLINER, RGN_TYPE_WINDOW);
index 3ffa54727e6c9034cb67456811fae83a36a22424..e1d01847ad78c5942a62c4cb9291549b4630976c 100644 (file)
@@ -116,7 +116,7 @@ static void script_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Script", SPACE_SCRIPT, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void script_main_region_draw(const bContext *C, ARegion *ar)
index 30aca84f4e0d6d93fd45736a2aca0cbc102153af..b2c231d649e5c3917699f151d7a7aa62b7f270a3 100644 (file)
@@ -468,15 +468,15 @@ static void sequencer_main_region_init(wmWindowManager *wm, ARegion *ar)
 
 #if 0
   keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 #endif
 
   keymap = WM_keymap_ensure(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Sequencer", SPACE_SEQ, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* add drop boxes */
   lb = WM_dropboxmap_find("Sequencer", SPACE_SEQ, RGN_TYPE_WINDOW);
@@ -614,15 +614,15 @@ static void sequencer_preview_region_init(wmWindowManager *wm, ARegion *ar)
 
 #if 0
   keymap = WM_keymap_ensure(wm->defaultconf, "Mask Editing", 0, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 #endif
 
   keymap = WM_keymap_ensure(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "SequencerPreview", SPACE_SEQ, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void sequencer_preview_region_draw(const bContext *C, ARegion *ar)
@@ -729,7 +729,7 @@ static void sequencer_buttons_region_init(wmWindowManager *wm, ARegion *ar)
   wmKeyMap *keymap;
 
   keymap = WM_keymap_ensure(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   ED_region_panels_init(wm, ar);
 }
index 49d5ae06413275329e8d71c048a24ae1d0729e7b..899805338d6d036c923d4a93daf71d8e8c71d8f3 100644 (file)
@@ -273,9 +273,9 @@ static void text_main_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymap */
   keymap = WM_keymap_ensure(wm->defaultconf, "Text Generic", SPACE_TEXT, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
   keymap = WM_keymap_ensure(wm->defaultconf, "Text", SPACE_TEXT, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 
   /* add drop boxes */
   lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
@@ -394,7 +394,7 @@ static void text_properties_region_init(wmWindowManager *wm, ARegion *ar)
 
   /* own keymaps */
   keymap = WM_keymap_ensure(wm->defaultconf, "Text Generic", SPACE_TEXT, 0);
-  WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+  WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap);
 }
 
 static void text_properties_region_draw(const bContext *C, ARegion *ar)
index 5cc70aecd8deaf4511db79c59f95f3b8e3c052c1..f1037dadf8592a739b702ccbb8abba8a9650b564 100644 (file)
@@ -208,12 +208,13 @@ int WM_userdef_event_type_from_keymap_type(int kmitype);
 
 /* handlers */
 
+typedef bool (*EventHandlerPoll)(const ARegion *ar, const struct wmEvent *event);
 struct wmEventHandler_Keymap *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
-/* boundbox, optional subwindow boundbox for offset */
-struct wmEventHandler_Keymap *WM_event_add_keymap_handler_bb(ListBase *handlers,
-                                                             wmKeyMap *keymap,
-                                                             const rcti *bb,
-                                                             const rcti *swinbb);
+struct wmEventHandler_Keymap *WM_event_add_keymap_handler_poll(ListBase *handlers,
+                                                               wmKeyMap *keymap,
+                                                               EventHandlerPoll poll);
+struct wmEventHandler_Keymap *WM_event_add_keymap_handler_v2d_mask(ListBase *handlers,
+                                                                   wmKeyMap *keymap);
 /* priority not implemented, it adds in begin */
 struct wmEventHandler_Keymap *WM_event_add_keymap_handler_priority(ListBase *handlers,
                                                                    wmKeyMap *keymap,
index 76a59944832432a43f7330c89837df47278a8c0d..2e94d22bc841143898f8b97b384e7f0dbe32511d 100644 (file)
@@ -2470,38 +2470,6 @@ static int wm_handler_fileselect_call(bContext *C,
   return wm_handler_fileselect_do(C, handlers, handler, event->val);
 }
 
-static bool handler_boundbox_test(wmEventHandler *handler, const wmEvent *event)
-{
-  if (handler->bbwin) {
-    if (handler->bblocal) {
-      rcti rect = *handler->bblocal;
-      BLI_rcti_translate(&rect, handler->bbwin->xmin, handler->bbwin->ymin);
-
-      if (BLI_rcti_isect_pt_v(&rect, &event->x)) {
-        return 1;
-      }
-      else if (event->type == MOUSEMOVE && BLI_rcti_isect_pt_v(&rect, &event->prevx)) {
-        return 1;
-      }
-      else {
-        return 0;
-      }
-    }
-    else {
-      if (BLI_rcti_isect_pt_v(handler->bbwin, &event->x)) {
-        return 1;
-      }
-      else if (event->type == MOUSEMOVE && BLI_rcti_isect_pt_v(handler->bbwin, &event->prevx)) {
-        return 1;
-      }
-      else {
-        return 0;
-      }
-    }
-  }
-  return 1;
-}
-
 static int wm_action_not_handled(int action)
 {
   return action == WM_HANDLER_CONTINUE || action == (WM_HANDLER_BREAK | WM_HANDLER_MODAL);
@@ -2540,7 +2508,7 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
     if (handler_base->flag & WM_HANDLER_DO_FREE) {
       /* pass */
     }
-    else if (handler_boundbox_test(handler_base, event)) { /* optional boundbox */
+    else if (handler_base->poll == NULL || handler_base->poll(CTX_wm_region(C), event)) {
       /* in advance to avoid access to freed event on window close */
       always_pass = wm_event_always_pass(event);
 
@@ -3608,20 +3576,44 @@ wmEventHandler_Keymap *WM_event_add_keymap_handler_priority(ListBase *handlers,
   return handler;
 }
 
-wmEventHandler_Keymap *WM_event_add_keymap_handler_bb(ListBase *handlers,
-                                                      wmKeyMap *keymap,
-                                                      const rcti *bblocal,
-                                                      const rcti *bbwin)
+static bool event_or_prev_in_rect(const wmEvent *event, const rcti *rect)
 {
-  wmEventHandler_Keymap *handler = WM_event_add_keymap_handler(handlers, keymap);
+  if (BLI_rcti_isect_pt(rect, event->x, event->y)) {
+    return true;
+  }
+  else if (event->type == MOUSEMOVE && BLI_rcti_isect_pt(rect, event->prevx, event->prevy)) {
+    return true;
+  }
+  else {
+    return false;
+  }
+}
 
-  if (handler) {
-    handler->head.bblocal = bblocal;
-    handler->head.bbwin = bbwin;
+static bool handler_region_v2d_mask_test(const ARegion *ar, const wmEvent *event)
+{
+  rcti rect = ar->v2d.mask;
+  BLI_rcti_translate(&rect, ar->winrct.xmin, ar->winrct.ymin);
+  return event_or_prev_in_rect(event, &rect);
+}
+
+wmEventHandler_Keymap *WM_event_add_keymap_handler_poll(ListBase *handlers,
+                                                        wmKeyMap *keymap,
+                                                        EventHandlerPoll poll)
+{
+  wmEventHandler_Keymap *handler = WM_event_add_keymap_handler(handlers, keymap);
+  if (handler == NULL) {
+    return NULL;
   }
+
+  handler->head.poll = poll;
   return handler;
 }
 
+wmEventHandler_Keymap *WM_event_add_keymap_handler_v2d_mask(ListBase *handlers, wmKeyMap *keymap)
+{
+  return WM_event_add_keymap_handler_poll(handlers, keymap, handler_region_v2d_mask_test);
+}
+
 void WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
 {
   LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
@@ -4802,7 +4794,7 @@ static wmKeyMapItem *wm_kmi_from_event(bContext *C,
     if (handler_base->flag & WM_HANDLER_DO_FREE) {
       /* pass */
     }
-    else if (handler_boundbox_test(handler_base, event)) { /* optional boundbox */
+    else if (handler_base->poll == NULL || handler_base->poll(CTX_wm_region(C), event)) {
       if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
         wmEventHandler_Keymap *handler = (wmEventHandler_Keymap *)handler_base;
         wmKeyMap *keymap = WM_event_get_keymap_from_handler(wm, handler);
index 9a2f8bda0417d1f4c2d07cc7ddcfc6380450ad2d..049e4d44994bbec63b50587f72c91a8d16554811 100644 (file)
@@ -44,14 +44,15 @@ enum eWM_EventHandlerType {
   WM_HANDLER_TYPE_KEYMAP,
 };
 
+typedef bool (*EventHandlerPoll)(const ARegion *ar, const wmEvent *event);
+
 typedef struct wmEventHandler {
   struct wmEventHandler *next, *prev;
 
   enum eWM_EventHandlerType type;
   char flag; /* WM_HANDLER_BLOCKING, ... */
 
-  /** Optional local and windowspace bb. */
-  const rcti *bblocal, *bbwin;
+  EventHandlerPoll poll;
 } wmEventHandler;
 
 /** Run after the keymap item runs. */