Skip to content

Issue #246: Selection Tool Operation Setting Error

Closes: #246

Reproducing the problem:

Select the Rectangle Select tool (although any select tool shows the problem) with nothing selected.

Set the operation mode to replace (CHANNEL_OP_REPLACE)

Drag the mouse to create a rectangular selection, then release the left mouse button (LMB)

Hold Shift and Alt then use the mouse to move the selection - a floating layer should be created

Whilst still holding LMB release the Shift and Alt keys

Press and hold the Ctrl key

Release the LMB - the operation mode changes to subtract (CHANNEL_OP_MODE_SUBTRACT) as expected since the Ctrl key is being pressed.

Release the Ctrl key - the operation mode should revert to replace but it is latched at subtract

The reason the problem occurs:

Whilst the LMB is held no modifier key events are passed to function gimpselectiontool.c/gimp_selection_tool_modifier_key

When the LMB is released this function receives three modifier key events with the following arguments

key = 1 state = 4 press = 0 key = 4 state = 4 press = 1 key = 8 state = 4 press = 0

The first event is the release of the Shift key but because the Ctrl key is being held state = 4

When servicing this first event the function calls gimp_modifiers_to_channel_op() to set the operation based on the pressed modifier keys (as defined by state) - this has the effect of changing the mode to subtract.

When the second event is processed because key = state the function sets selection_tool->saved_operation to subtract mode thereby latching what should have been a temporary override.

(The third event is the release of the Alt key - no idea why this is not in chronological order - but it would make no difference to the problem if it was)

The fix:

The code that calls gimp_modifiers_to_channel_op() when processing a release event excludes modifier key presses for which the function has yet to receive press events. The change is therefore to keep a record of which modifier keys the function has had press events and use this record to mask the state setting passed to gimp_modifiers_to_channel_op().

This means that when the second event above is processed the operation changes to subtract but reverts to replace mode (as expected) when the Ctrl key is released.

It also checks for the situation in which the record of pressed keys is 0 and restores the operation mode to the contents of selection_tool->saved_operation

Edited by Bruno

Merge request reports