Support for grab cursor in macro system (and vice versa).
authorMartin Poirier <theeth@yahoo.com>
Thu, 19 Nov 2009 19:27:10 +0000 (19:27 +0000)
committerMartin Poirier <theeth@yahoo.com>
Thu, 19 Nov 2009 19:27:10 +0000 (19:27 +0000)
This may result in cursor being grabbed twice (though we don't have any macro that can do this at the moment). If this is a problem, a check can be added.

source/blender/editors/mesh/mesh_ops.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c

index 3ce5bbc7e5a58e13807a5a1b007d50777cdc006d..70ab3f06b897cdea51f55d46bca30520e9bcd78b 100644 (file)
@@ -185,7 +185,7 @@ void ED_operatormacros_mesh(void)
        otmacro= WM_operatortype_macro_define(ot, "TFM_OT_translate");
        RNA_enum_set(otmacro->ptr, "proportional", 0);
 
-       ot= WM_operatortype_append_macro("MESH_OT_extrude_move_along_normals", "Extrude Along Normals", OPTYPE_UNDO|OPTYPE_REGISTER|OPTYPE_BLOCKING);
+       ot= WM_operatortype_append_macro("MESH_OT_extrude_move_along_normals", "Extrude Along Normals", OPTYPE_UNDO|OPTYPE_REGISTER);
        ot->poll = ED_operator_editmesh_face_select; /* restrict extrude along normals to face select */
        WM_operatortype_macro_define(ot, "MESH_OT_extrude");
        otmacro= WM_operatortype_macro_define(ot, "TFM_OT_translate");
@@ -193,7 +193,7 @@ void ED_operatormacros_mesh(void)
        RNA_enum_set(otmacro->ptr, "constraint_orientation", V3D_MANIP_NORMAL);
        RNA_boolean_set_array(otmacro->ptr, "constraint_axis", constraint_axis);
 
-       ot= WM_operatortype_append_macro("MESH_OT_extrude_move", "Extrude", OPTYPE_UNDO|OPTYPE_REGISTER|OPTYPE_BLOCKING);
+       ot= WM_operatortype_append_macro("MESH_OT_extrude_move", "Extrude", OPTYPE_UNDO|OPTYPE_REGISTER);
        WM_operatortype_macro_define(ot, "MESH_OT_extrude");
        otmacro= WM_operatortype_macro_define(ot, "TFM_OT_translate");
        RNA_enum_set(otmacro->ptr, "proportional", 0);
index d8c0e9daf46634e72984e86e440b2526911fc970..02fb56f93c8db18d5a9ec339d4facab8d633da64 100644 (file)
@@ -461,10 +461,18 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
                                WM_operator_free(op);
                }
                else if(retval & OPERATOR_RUNNING_MODAL) {
-                       /* grab cursor during blocking modal ops (X11) */
-                       if(ot->flag & OPTYPE_BLOCKING) {
+                       /* grab cursor during blocking modal ops (X11)
+                        * Also check for macro
+                        * */
+                       if(ot->flag & OPTYPE_BLOCKING || (op->opm && op->opm->type->flag & OPTYPE_BLOCKING)) {
                                int bounds[4] = {-1,-1,-1,-1};
-                               int wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) && ((op->flag & OP_GRAB_POINTER) || (ot->flag & OPTYPE_GRAB_POINTER));
+                               int wrap;
+
+                               if (op->opm) {
+                                       wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) && ((op->opm->flag & OP_GRAB_POINTER) || (op->opm->type->flag & OPTYPE_GRAB_POINTER));
+                               } else {
+                                       wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) && ((op->flag & OP_GRAB_POINTER) || (ot->flag & OPTYPE_GRAB_POINTER));
+                               }
 
                                if(wrap) {
                                        ARegion *ar= CTX_wm_region(C);
index 89e0943dcd10cc25cbff9e6b273b293d70c1fcf9..e4906bed8e078cb87aec64e6a75846a12038ca63 100644 (file)
@@ -260,6 +260,26 @@ static int wm_macro_modal(bContext *C, wmOperator *op, wmEvent *event)
                                        BLI_remlink(&win->modalhandlers, handler);
                                        wm_event_free_handler(handler);
                                }
+
+                               /* if operator is blocking, grab cursor
+                                * This may end up grabbing twice, but we don't care.
+                                * */
+                               if(op->opm->type->flag & OPTYPE_BLOCKING) {
+                                       int bounds[4] = {-1,-1,-1,-1};
+                                       int wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) && ((op->opm->flag & OP_GRAB_POINTER) || (op->opm->type->flag & OPTYPE_GRAB_POINTER));
+
+                                       if(wrap) {
+                                               ARegion *ar= CTX_wm_region(C);
+                                               if(ar) {
+                                                       bounds[0]= ar->winrct.xmin;
+                                                       bounds[1]= ar->winrct.ymax;
+                                                       bounds[2]= ar->winrct.xmax;
+                                                       bounds[3]= ar->winrct.ymin;
+                                               }
+                                       }
+
+                                       WM_cursor_grab(CTX_wm_window(C), wrap, FALSE, bounds);
+                               }
                        }
 
                }