Please deduplicate - there are two ways the mouse lock can be active, but you can check both of them in the same if-condition or (if you think it's more readable) draw the calculation of whether to perform the mouse lock or not out of the "if".