[Bf-blender-cvs] [09c7c638905] master: UI Code Quality: Use "params" struct for area and region callbacks

Hans Goudey noreply at git.blender.org
Tue Jan 19 00:28:53 CET 2021


Commit: 09c7c638905230a608a9b0204b68c775cf71bf67
Author: Hans Goudey
Date:   Mon Jan 18 17:28:47 2021 -0600
Branches: master
https://developer.blender.org/rB09c7c638905230a608a9b0204b68c775cf71bf67

UI Code Quality: Use "params" struct for area and region callbacks

These functions with many arguments can be unwieldy. Aside from the obvious issues
with rewriting the list of arguments and the opportunities for error and frustration
that presents, the long list of arguments make these systems hard to change. So when
an argument should be added, someone might skip that and add some hack instead.

So, as proposed in T73586#1037210, this patch instead uses a "params" struct for
each of these callbacks.

- Use param argument for `ARegionType.listener`
    - Remove unused window field in region listener
- Use param argument for `SpaceType.listener`
- Use params struct for `ARegionType.message_subscribe`

Differential Revision: https://developer.blender.org/D9750

===================================================================

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/interface/interface_region_popup.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/screen/area_utils.c
M	source/blender/editors/space_action/space_action.c
M	source/blender/editors/space_buttons/space_buttons.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_console/space_console.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/editors/space_graph/space_graph.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/space_info/space_info.c
M	source/blender/editors/space_nla/space_nla.c
M	source/blender/editors/space_node/space_node.c
M	source/blender/editors/space_outliner/space_outliner.c
M	source/blender/editors/space_script/space_script.c
M	source/blender/editors/space_sequencer/space_sequencer.c
M	source/blender/editors/space_statusbar/space_statusbar.c
M	source/blender/editors/space_text/space_text.c
M	source/blender/editors/space_topbar/space_topbar.c
M	source/blender/editors/space_userpref/space_userpref.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/gizmo/WM_gizmo_api.h
M	source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
M	source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 7b5df98d148..4274d59cb9f 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -67,6 +67,13 @@ struct wmWindowManager;
 
 #define BKE_ST_MAXNAME 64
 
+typedef struct wmSpaceTypeListenerParams {
+  struct wmWindow *window;
+  struct ScrArea *area;
+  struct wmNotifier *notifier;
+  const struct Scene *scene;
+} wmSpaceTypeListenerParams;
+
 typedef struct SpaceType {
   struct SpaceType *next, *prev;
 
@@ -85,10 +92,7 @@ typedef struct SpaceType {
   /* exit is called when the area is hidden or removed */
   void (*exit)(struct wmWindowManager *wm, struct ScrArea *area);
   /* Listeners can react to bContext changes */
-  void (*listener)(struct wmWindow *win,
-                   struct ScrArea *area,
-                   struct wmNotifier *wmn,
-                   struct Scene *scene);
+  void (*listener)(wmSpaceTypeListenerParams *params);
 
   /* called when the mouse moves out of the area */
   void (*deactivate)(struct ScrArea *area);
@@ -134,6 +138,23 @@ typedef struct SpaceType {
 
 /* region types are also defined using spacetypes_init, via a callback */
 
+typedef struct wmRegionListenerParams {
+  struct ScrArea *area; /* Can be NULL when the region is not part of an area. */
+  struct ARegion *region;
+  struct wmNotifier *notifier;
+  const struct Scene *scene;
+} wmRegionListenerParams;
+
+typedef struct wmRegionMessageSubscribeParams {
+  const struct bContext *context;
+  struct wmMsgBus *message_bus;
+  struct WorkSpace *workspace;
+  struct Scene *scene;
+  struct bScreen *screen;
+  struct ScrArea *area;
+  struct ARegion *region;
+} wmRegionMessageSubscribeParams;
+
 typedef struct ARegionType {
   struct ARegionType *next, *prev;
 
@@ -158,19 +179,9 @@ typedef struct ARegionType {
   /* snap the size of the region (can be NULL for no snapping). */
   int (*snap_size)(const struct ARegion *region, int size, int axis);
   /* contextual changes should be handled here */
-  void (*listener)(struct wmWindow *win,
-                   struct ScrArea *area,
-                   struct ARegion *region,
-                   struct wmNotifier *wmn,
-                   const struct Scene *scene);
+  void (*listener)(wmRegionListenerParams *params);
   /* Optional callback to generate subscriptions. */
-  void (*message_subscribe)(const struct bContext *C,
-                            struct WorkSpace *workspace,
-                            struct Scene *scene,
-                            struct bScreen *screen,
-                            struct ScrArea *area,
-                            struct ARegion *region,
-                            struct wmMsgBus *mbus);
+  void (*message_subscribe)(wmRegionMessageSubscribeParams *params);
 
   void (*free)(struct ARegion *);
 
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 20417634020..571f4e74c60 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -57,15 +57,14 @@ struct wmMsgSubscribeKey;
 struct wmMsgSubscribeValue;
 struct wmNotifier;
 struct wmOperatorType;
+struct wmRegionListenerParams;
+struct wmRegionMessageSubscribeParams;
+struct wmSpaceTypeListenerParams;
 struct wmWindow;
 struct wmWindowManager;
 
 /* regions */
-void ED_region_do_listen(struct wmWindow *win,
-                         struct ScrArea *area,
-                         struct ARegion *region,
-                         struct wmNotifier *note,
-                         const Scene *scene);
+void ED_region_do_listen(struct wmRegionListenerParams *params);
 void ED_region_do_layout(struct bContext *C, struct ARegion *region);
 void ED_region_do_draw(struct bContext *C, struct ARegion *region);
 void ED_region_exit(struct bContext *C, struct ARegion *region);
@@ -144,29 +143,11 @@ void ED_area_do_msg_notify_tag_refresh(struct bContext *C,
                                        struct wmMsgSubscribeKey *msg_key,
                                        struct wmMsgSubscribeValue *msg_val);
 
-void ED_area_do_mgs_subscribe_for_tool_header(const struct bContext *C,
-                                              struct WorkSpace *workspace,
-                                              struct Scene *scene,
-                                              struct bScreen *screen,
-                                              struct ScrArea *area,
-                                              struct ARegion *region,
-                                              struct wmMsgBus *mbus);
-void ED_area_do_mgs_subscribe_for_tool_ui(const struct bContext *C,
-                                          struct WorkSpace *workspace,
-                                          struct Scene *scene,
-                                          struct bScreen *screen,
-                                          struct ScrArea *area,
-                                          struct ARegion *region,
-                                          struct wmMsgBus *mbus);
+void ED_area_do_mgs_subscribe_for_tool_header(struct wmRegionMessageSubscribeParams *params);
+void ED_area_do_mgs_subscribe_for_tool_ui(struct wmRegionMessageSubscribeParams *params);
 
 /* message bus */
-void ED_region_message_subscribe(struct bContext *C,
-                                 struct WorkSpace *workspace,
-                                 struct Scene *scene,
-                                 struct bScreen *screen,
-                                 struct ScrArea *area,
-                                 struct ARegion *region,
-                                 struct wmMsgBus *mbus);
+void ED_region_message_subscribe(struct wmRegionMessageSubscribeParams *params);
 
 /* spaces */
 void ED_spacetypes_keymap(struct wmKeyConfig *keyconf);
@@ -178,7 +159,7 @@ void ED_area_exit(struct bContext *C, struct ScrArea *area);
 int ED_screen_area_active(const struct bContext *C);
 void ED_screen_global_areas_refresh(struct wmWindow *win);
 void ED_screen_global_areas_sync(struct wmWindow *win);
-void ED_area_do_listen(struct wmWindow *win, ScrArea *area, struct wmNotifier *note, Scene *scene);
+void ED_area_do_listen(struct wmSpaceTypeListenerParams *params);
 void ED_area_tag_redraw(ScrArea *area);
 void ED_area_tag_redraw_no_rebuild(ScrArea *area);
 void ED_area_tag_redraw_regiontype(ScrArea *area, int type);
@@ -427,13 +408,8 @@ void ED_region_cache_draw_cached_segments(struct ARegion *region,
                                           const int efra);
 
 /* area_utils.c */
-void ED_region_generic_tools_region_message_subscribe(const struct bContext *C,
-                                                      struct WorkSpace *workspace,
-                                                      struct Scene *scene,
-                                                      struct bScreen *screen,
-                                                      struct ScrArea *area,
-                                                      struct ARegion *region,
-                                                      struct wmMsgBus *mbus);
+void ED_region_generic_tools_region_message_subscribe(
+    struct wmRegionMessageSubscribeParams *params);
 int ED_region_generic_tools_region_snap_size(const struct ARegion *region, int size, int axis);
 
 /* area_query.c */
diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c
index 93e3dbb2cc8..c6c6cd1eeea 100644
--- a/source/blender/editors/interface/interface_region_popup.c
+++ b/source/blender/editors/interface/interface_region_popup.c
@@ -413,12 +413,11 @@ static void ui_block_region_draw(const bContext *C, ARegion *region)
 /**
  * Use to refresh centered popups on screen resizing (for splash).
  */
-static void ui_block_region_popup_window_listener(wmWindow *UNUSED(win),
-                                                  ScrArea *UNUSED(area),
-                                                  ARegion *region,
-                                                  wmNotifier *wmn,
-                                                  const Scene *UNUSED(scene))
+static void ui_block_region_popup_window_listener(wmRegionListenerParams *params)
 {
+  ARegion *region = params->region;
+  wmNotifier *wmn = params->notifier;
+
   switch (wmn->category) {
     case NC_WINDOW: {
       switch (wmn->action) {
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 581169d823e..24773ccbbee 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -141,13 +141,15 @@ void ED_region_pixelspace(ARegion *region)
 }
 
 /* only exported for WM */
-void ED_region_do_listen(
-    wmWindow *win, ScrArea *area, ARegion *region, wmNotifier *note, const Scene *scene)
+void ED_region_do_listen(wmRegionListenerParams *params)
 {
+  ARegion *region = params->region;
+  wmNotifier *notifier = params->notifier;
+
   /* generic notes first */
-  switch (note->category) {
+  switch (notifier->category) {
     case NC_WM:
-      if (note->data == ND_FILEREAD) {
+      if (notifier->data == ND_FILEREAD) {
         ED_region_tag_redraw(region);
       }
       break;
@@ -157,16 +159,16 @@ void ED_region_do_listen(
   }
 
   if (region->type && region->type->listener) {
-    region->type->listener(win, area, region, note, scene);
+    region->type->listener(params);
   }
 }
 
 /* only exported for WM */
-void ED_area_do_listen(wmWindow *win, ScrArea *area, wmNotifier *note, Scene *scene)
+void ED_area_do_listen(wmSpaceTypeListenerParams *params)
 {
   /* no generic notes? */
-  if (area->type && area->type->listener) {
-    area->type->listener(win, area, note, scene);
+  if (params->area->type && params->area->type->listener) {
+    params->area->type->listener(params);
   }
 }
 
@@ -418,16 +420,13 @@ void ED_area_do_msg_notify_tag_refresh(
   ED_area_tag_refresh(area);
 }
 
-void ED_area_do_mgs_subscribe_for_tool_header(
-    /* Follow ARegionType.message_subscribe */
-    const struct bContext *UNUSED(C),
-    struct WorkSpace *workspace,
-    struct Scene *UNUSED(scene),
-    st

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list