Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crop] Add disable_window_dragging option, enable by default #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions scripts/crop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local opts = {
draw_crosshair = true,
draw_text = true,
mouse_support = true,
disable_window_dragging = true,
coarse_movement = 30,
left_coarse = "LEFT",
right_coarse = "RIGHT",
Expand Down Expand Up @@ -315,7 +316,7 @@ function update_crop_zone_state()
corner = clamp_point({ x = dim.ml, y = dim.mt }, crop_cursor, { x = dim.w - dim.mr, y = dim.h - dim.mb })
end
local corner_video = screen_to_video_norm(corner, dim)
if crop_first_corner == nil then
if crop_first_corner == nil or (crop_first_corner.x == corner_video.x and crop_first_corner.y == corner_video.y) then
crop_first_corner = corner_video
redraw()
else
Expand All @@ -326,13 +327,17 @@ function update_crop_zone_state()
end

local bindings = {}
local bindings_complex = {}
local bindings_repeat = {}

function cancel_crop()
crop_first_corner = nil
for key, _ in pairs(bindings) do
mp.remove_key_binding("crop-"..key)
end
for key, _ in pairs(bindings_complex) do
mp.remove_key_binding("crop-"..key)
end
for key, _ in pairs(bindings_repeat) do
mp.remove_key_binding("crop-"..key)
end
Expand Down Expand Up @@ -360,13 +365,20 @@ function start_crop(mode)
active = true
active_mode = mode_maybe

if opts.disable_window_dragging then
mp.set_property_bool("window-dragging", false)
end

if opts.mouse_support then
crop_cursor.x, crop_cursor.y = mp.get_mouse_pos()
end
redraw()
for key, func in pairs(bindings) do
mp.add_forced_key_binding(key, "crop-"..key, func)
end
for key, func in pairs(bindings_complex) do
mp.add_forced_key_binding(key, "crop-"..key, func, { complex = true })
end
for key, func in pairs(bindings_repeat) do
mp.add_forced_key_binding(key, "crop-"..key, func, { repeatable = true })
end
Expand Down Expand Up @@ -408,7 +420,14 @@ if opts.mouse_support then
bindings["MOUSE_MOVE"] = function() crop_cursor.x, crop_cursor.y = mp.get_mouse_pos(); redraw() end
end
for _, key in ipairs(opts.accept) do
bindings[key] = update_crop_zone_state
if string.find(key:lower(), "btn") then
bindings_complex[key] = function(mouse)
if opts.disable_window_dragging then mp.set_property_bool("window-dragging", mouse["event"] ~= "down") end
if crop_first_corner == nil or mouse["event"] ~= "down" then update_crop_zone_state() end
end
else
bindings[key] = update_crop_zone_state
end
end
for _, key in ipairs(opts.cancel) do
bindings[key] = cancel_crop
Expand Down