Allow some operators when interface is locked
Now it's possible to mark operator as safe to be used in locked interface mode by adding OPTYPE_ALLOW_LOCKED bit to operator template flags. This bit is completely handled by wm_evem_system, not with operator run routines, so it's still possible to run operators from drivers and handlers. Currently allowed image editor navigation and zooming.
This commit is contained in:
@@ -360,7 +360,7 @@ void IMAGE_OT_view_pan(wmOperatorType *ot)
|
||||
ot->poll = space_image_main_area_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER;
|
||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER | OPTYPE_ALLOW_LOCKED;
|
||||
|
||||
/* properties */
|
||||
RNA_def_float_vector(ot->srna, "offset", 2, NULL, -FLT_MAX, FLT_MAX,
|
||||
@@ -575,7 +575,7 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot)
|
||||
ot->poll = space_image_main_area_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_BLOCKING;
|
||||
ot->flag = OPTYPE_BLOCKING | OPTYPE_ALLOW_LOCKED;
|
||||
|
||||
/* properties */
|
||||
RNA_def_float(ot->srna, "factor", 0.0f, -FLT_MAX, FLT_MAX,
|
||||
@@ -638,6 +638,9 @@ void IMAGE_OT_view_ndof(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->invoke = image_view_ndof_invoke;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_ALLOW_LOCKED;
|
||||
}
|
||||
|
||||
/********************** view all operator *********************/
|
||||
@@ -693,6 +696,9 @@ void IMAGE_OT_view_all(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->exec = image_view_all_exec;
|
||||
ot->poll = space_image_main_area_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_GRAB_POINTER;
|
||||
}
|
||||
|
||||
/********************** view selected operator *********************/
|
||||
@@ -755,6 +761,9 @@ void IMAGE_OT_view_selected(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->exec = image_view_selected_exec;
|
||||
ot->poll = image_view_selected_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_GRAB_POINTER;
|
||||
}
|
||||
|
||||
/********************** view zoom in/out operator *********************/
|
||||
@@ -797,6 +806,9 @@ void IMAGE_OT_view_zoom_in(wmOperatorType *ot)
|
||||
ot->exec = image_view_zoom_in_exec;
|
||||
ot->poll = space_image_main_area_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_ALLOW_LOCKED;
|
||||
|
||||
/* properties */
|
||||
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location", "Cursor location in screen coordinates", -10.0f, 10.0f);
|
||||
}
|
||||
@@ -839,6 +851,9 @@ void IMAGE_OT_view_zoom_out(wmOperatorType *ot)
|
||||
ot->exec = image_view_zoom_out_exec;
|
||||
ot->poll = space_image_main_area_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_ALLOW_LOCKED;
|
||||
|
||||
/* properties */
|
||||
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location", "Cursor location in screen coordinates", -10.0f, 10.0f);
|
||||
}
|
||||
@@ -880,7 +895,10 @@ void IMAGE_OT_view_zoom_ratio(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->exec = image_view_zoom_ratio_exec;
|
||||
ot->poll = space_image_main_area_poll;
|
||||
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_ALLOW_LOCKED;
|
||||
|
||||
/* properties */
|
||||
RNA_def_float(ot->srna, "ratio", 0.0f, -FLT_MAX, FLT_MAX,
|
||||
"Ratio", "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out", -FLT_MAX, FLT_MAX);
|
||||
|
||||
@@ -133,6 +133,7 @@ struct ImBuf;
|
||||
* and don't make sense to be accessed from the
|
||||
* search menu, even if poll() returns TRUE.
|
||||
* currently only used for the search toolbox */
|
||||
#define OPTYPE_ALLOW_LOCKED 128 /* Allow operator to run when interface is locked */
|
||||
|
||||
/* context to call operator in for WM_operator_name_call */
|
||||
/* rna_ui.c contains EnumPropertyItem's of these, keep in sync */
|
||||
|
||||
@@ -1441,6 +1441,22 @@ static void wm_event_modalkeymap(const bContext *C, wmOperator *op, wmEvent *eve
|
||||
}
|
||||
}
|
||||
|
||||
/* Check whether operator is allowed to run in case interface is locked,
|
||||
* If interface is unlocked, will always return truth.
|
||||
*/
|
||||
static bool wm_operator_check_locked_interface(bContext *C, wmOperatorType *ot)
|
||||
{
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
|
||||
if (wm->is_interface_locked) {
|
||||
if ((ot->flag & OPTYPE_ALLOW_LOCKED) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* bad hacking event system... better restore event type for checking of KM_CLICK for example */
|
||||
/* XXX modal maps could use different method (ton) */
|
||||
static void wm_event_modalmap_end(wmEvent *event)
|
||||
@@ -1467,7 +1483,12 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
|
||||
wmOperator *op = handler->op;
|
||||
wmOperatorType *ot = op->type;
|
||||
|
||||
if (ot->modal) {
|
||||
if (!wm_operator_check_locked_interface(C, ot)) {
|
||||
/* Interface is locked and pperator is not allowed to run,
|
||||
* nothing to do in this case.
|
||||
*/
|
||||
}
|
||||
else if (ot->modal) {
|
||||
/* we set context to where modal handler came from */
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
ScrArea *area = CTX_wm_area(C);
|
||||
@@ -1537,7 +1558,9 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
|
||||
wmOperatorType *ot = WM_operatortype_find(event->keymap_idname, 0);
|
||||
|
||||
if (ot) {
|
||||
retval = wm_operator_invoke(C, ot, event, properties, NULL, FALSE);
|
||||
if (wm_operator_check_locked_interface(C, ot)) {
|
||||
retval = wm_operator_invoke(C, ot, event, properties, NULL, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Finished and pass through flag as handled */
|
||||
@@ -1825,14 +1848,18 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
|
||||
}
|
||||
}
|
||||
else if (handler->ui_handle) {
|
||||
action |= wm_handler_ui_call(C, handler, event, always_pass);
|
||||
if (!wm->is_interface_locked) {
|
||||
action |= wm_handler_ui_call(C, handler, event, always_pass);
|
||||
}
|
||||
}
|
||||
else if (handler->type == WM_HANDLER_FILESELECT) {
|
||||
/* screen context changes here */
|
||||
action |= wm_handler_fileselect_call(C, handlers, handler, event);
|
||||
if (!wm->is_interface_locked) {
|
||||
/* screen context changes here */
|
||||
action |= wm_handler_fileselect_call(C, handlers, handler, event);
|
||||
}
|
||||
}
|
||||
else if (handler->dropboxes) {
|
||||
if (event->type == EVT_DROP) {
|
||||
if (!wm->is_interface_locked && event->type == EVT_DROP) {
|
||||
wmDropBox *drop = handler->dropboxes->first;
|
||||
for (; drop; drop = drop->next) {
|
||||
/* other drop custom types allowed */
|
||||
@@ -2083,21 +2110,6 @@ void wm_event_do_handlers(bContext *C)
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
wmWindow *win;
|
||||
|
||||
if (wm->is_interface_locked) {
|
||||
/* If we're in locked interaction mode, skip all the events
|
||||
* from the queue and prevent them from being accumulated.
|
||||
* This is so no events are applied after interface is unlocked.
|
||||
*/
|
||||
for (win = wm->windows.first; win; win = win->next) {
|
||||
wmEvent *event;
|
||||
while ( (event = win->queue.first) ) {
|
||||
BLI_remlink(&win->queue, event);
|
||||
wm_event_free(event);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* update key configuration before handling events */
|
||||
WM_keyconfig_update(wm);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user