Skip to content

Commit 3b8c18d

Browse files
committed
Improved obs startup. Bugfix
1 parent 7c4f16a commit 3b8c18d

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

obs-zoom-to-mouse.lua

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ local use_auto_follow_mouse = true
5252
local use_follow_outside_bounds = false
5353
local is_following_mouse = false
5454
local force_16_9 = true
55-
local auto_start = false
55+
local lock_in = false
5656
local follow_speed = 0.1
5757
local follow_border = 0
5858
local follow_safezone_sensitivity = 10
@@ -621,7 +621,7 @@ function refresh_sceneitem(find_newest)
621621
source_height = monitor_info.height
622622
else
623623
log("ERROR: Something went wrong determining source size.\n" ..
624-
" Try using the 'Set manual source position' option and adding override values")
624+
" Try using the 'Set manual source position' option and adding override values")
625625
end
626626
else
627627
log("Using source size: " .. source_width .. ", " .. source_height)
@@ -1148,10 +1148,8 @@ function on_settings_modified(props, prop, settings)
11481148
end
11491149
end
11501150

1151-
if auto_start then
1152-
on_toggle_zoom(true, true)
1153-
else
1154-
on_toggle_zoom(true, false)
1151+
if lock_in ~= nil then
1152+
on_toggle_zoom(true, lock_in)
11551153
end
11561154
return false
11571155
end
@@ -1182,7 +1180,7 @@ function log_current_settings()
11821180
socket_poll = socket_poll,
11831181
debug_logs = debug_logs,
11841182
force_16_9 = force_16_9,
1185-
auto_start = auto_start,
1183+
lock_in = lock_in,
11861184
version = VERSION
11871185
}
11881186

@@ -1258,7 +1256,9 @@ function script_properties()
12581256
-- Add the rest of the settings UI
12591257
local zoom = obs.obs_properties_add_float(props, "zoom_value", "Zoom Factor", 1, 5, 0.5)
12601258
local zoom_speed = obs.obs_properties_add_float_slider(props, "zoom_speed", "Zoom Speed", 0.01, 1, 0.01)
1261-
local auto_start = obs.obs_properties_add_bool(props, "auto_start", "Auto start ")
1259+
local lock_in = obs.obs_properties_add_bool(props, "lock_in", "Lock-In ")
1260+
obs.obs_property_set_long_description(lock_in,
1261+
"When enabled, auto zoom feature cannot be disabled manually, and auto zoom restarts with OBS too")
12621262
local force_16_9 = obs.obs_properties_add_bool(props, "force_16_9", "Force 16:9 aspect ratio ")
12631263
local follow = obs.obs_properties_add_bool(props, "follow", "Auto follow mouse ")
12641264
obs.obs_property_set_long_description(follow,
@@ -1395,7 +1395,7 @@ function script_load(settings)
13951395
socket_port = obs.obs_data_get_int(settings, "socket_port")
13961396
socket_poll = obs.obs_data_get_int(settings, "socket_poll")
13971397
debug_logs = obs.obs_data_get_bool(settings, "debug_logs")
1398-
auto_start = obs.obs_data_get_bool(settings, "auto_start")
1398+
lock_in = obs.obs_data_get_bool(settings, "lock_in")
13991399
force_16_9 = obs.obs_data_get_bool(settings, "force_16_9")
14001400

14011401
obs.obs_frontend_add_event_callback(on_frontend_event)
@@ -1456,7 +1456,7 @@ function script_unload()
14561456
stop_server()
14571457
end
14581458

1459-
if auto_start then
1459+
if lock_in then
14601460
on_toggle_zoom(true, false)
14611461
end
14621462
end
@@ -1486,7 +1486,7 @@ function script_defaults(settings)
14861486
obs.obs_data_set_default_int(settings, "socket_poll", 10)
14871487
obs.obs_data_set_default_bool(settings, "debug_logs", false)
14881488
obs.obs_data_set_default_bool(settings, "force_16_9", true)
1489-
obs.obs_data_set_default_bool(settings, "auto_start", false)
1489+
obs.obs_data_set_default_bool(settings, "lock_in", false)
14901490
end
14911491

14921492
function script_save(settings)
@@ -1544,7 +1544,7 @@ function script_update(settings)
15441544
socket_poll = obs.obs_data_get_int(settings, "socket_poll")
15451545
debug_logs = obs.obs_data_get_bool(settings, "debug_logs")
15461546
force_16_9 = obs.obs_data_get_bool(settings, "force_16_9")
1547-
auto_start = obs.obs_data_get_bool(settings, "auto_start")
1547+
lock_in = obs.obs_data_get_bool(settings, "lock_in")
15481548

15491549
-- Only do the expensive refresh if the user selected a new source
15501550
if source_name ~= old_source_name and is_obs_loaded then
@@ -1578,10 +1578,20 @@ function script_update(settings)
15781578
start_server()
15791579
end
15801580

1581-
if auto_start then
1582-
on_toggle_zoom(true, true)
1583-
else
1584-
on_toggle_zoom(true, false)
1581+
if lock_in ~= nil and source == nil then
1582+
local timer_interval = math.floor(obs.obs_get_frame_interval_ns() / 100000)
1583+
obs.timer_add(wait_for_auto_start, timer_interval)
1584+
elseif lock_in ~= nil and source ~= nil then
1585+
on_toggle_zoom(true, lock_in)
1586+
end
1587+
end
1588+
1589+
function wait_for_auto_start()
1590+
local found_source = obs.obs_get_source_by_name(source_name)
1591+
if found_source ~= nil then
1592+
source = found_source
1593+
on_toggle_zoom(true, lock_in)
1594+
obs.remove_current_callback()
15851595
end
15861596
end
15871597

0 commit comments

Comments
 (0)