From 4a467faff08e1fa63188ee51342b89fa5f40ff89 Mon Sep 17 00:00:00 2001 From: Etoh Date: Thu, 28 Dec 2017 15:31:20 +0000 Subject: [PATCH] Disable OSC visibility when input box is active (if supported) --- resources/syncplayintf.lua | 16 +++++++++++++++- syncplay/constants.py | 1 + syncplay/players/mpv.py | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/resources/syncplayintf.lua b/resources/syncplayintf.lua index f5ad996..0b33d2a 100644 --- a/resources/syncplayintf.lua +++ b/resources/syncplayintf.lua @@ -18,6 +18,7 @@ local MOOD_NEUTRAL = 0 local MOOD_BAD = 1 local MOOD_GOOD = 2 local WORDWRAPIFY_MAGICWORD = "{\\\\fscx0} {\\\\fscx100}" +local default_oscvisibility_state = "never" local ALPHA_WARNING_TEXT_COLOUR = "FF00FF" -- RBG local HINT_TEXT_COLOUR = "00FFFF" -- RBG @@ -30,6 +31,8 @@ local chat_log = {} local assdraw = require "mp.assdraw" +local opt = require 'mp.options' + function format_scrolling(xpos, ypos, text) local chat_message = chat_format .. "{\\pos("..xpos..","..ypos..")}"..text.."\n" return string.format(chat_message) @@ -306,6 +309,7 @@ opts = { -- Enable/Disable ['chatInputEnabled'] = true, ['chatOutputEnabled'] = true, + ['OscVisibilityChangeCompatible'] = false, -- Set the font size used for the REPL and the console. This will be -- multiplied by "scale." ['chatInputFontSize'] = 20, @@ -481,6 +485,13 @@ function set_active(active) repl_active = false mp.disable_key_bindings('repl-input') end + if default_oscvisibility_state ~= "never" and opts['OscVisibilityChangeCompatible'] == true then + if active then + mp.commandv("script-message", "osc-visibility","never", "no-osd") + else + mp.commandv("script-message", "osc-visibility",default_oscvisibility_state, "no-osd") + end + end end -- Show the repl if hidden and replace its contents with 'text' @@ -877,7 +888,7 @@ end) mp.command('print-text ""') function set_syncplayintf_options(input) - ---mp.command('print-text "...'..input..'"') + --mp.command('print-text "...'..input..'"') for option, value in string.gmatch(input, "([^ ,=]+)=([^,]+)") do local valueType = type(opts[option]) if valueType == "number" then @@ -895,6 +906,9 @@ function set_syncplayintf_options(input) chat_format = get_output_style() local vertical_output_area = CANVAS_HEIGHT-(opts['chatTopMargin']+opts['chatBottomMargin']+(opts['chatOutputFontSize']+opts['scrollingFirstRowOffset'])) max_scrolling_rows = math.floor(vertical_output_area/opts['chatOutputFontSize']) + local user_opts = { visibility = "auto", } + opt.read_options(user_opts, "osc") + default_oscvisibility_state = user_opts.visibility if opts['chatInputEnabled'] == true then mp.add_forced_key_binding('enter', handle_enter) mp.add_forced_key_binding('kp_enter', handle_enter) diff --git a/syncplay/constants.py b/syncplay/constants.py index b492cf8..9feb4c6 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -185,6 +185,7 @@ MPV_ARGS = ['--force-window', '--idle', '--hr-seek=always', '--keep-open'] MPV_SLAVE_ARGS = ['--msg-level=all=error,cplayer=info,term-msg=info', '--input-terminal=no', '--input-file=/dev/stdin'] MPV_SLAVE_ARGS_NEW = ['--term-playing-msg=\nANS_filename=${filename}\nANS_length=${=length:${=duration:0}}\nANS_path=${path}\n', '--terminal=yes'] MPV_NEW_VERSION = False +MPV_OSC_VISIBILITY_CHANGE_VERSION = False MPV_SYNCPLAYINTF_OPTIONS_TO_SEND = ["chatInputEnabled","chatInputFontFamily", "chatInputFontSize", "chatInputFontWeight","chatInputFontUnderline", "chatInputFontColor", "chatInputPosition","chatOutputFontFamily","chatOutputFontSize", "chatOutputFontWeight","chatOutputFontUnderline","chatOutputMode","chatMaxLines", diff --git a/syncplay/players/mpv.py b/syncplay/players/mpv.py index e7c0851..4d89a53 100644 --- a/syncplay/players/mpv.py +++ b/syncplay/players/mpv.py @@ -18,6 +18,9 @@ class MpvPlayer(MplayerPlayer): except: ver = None constants.MPV_NEW_VERSION = ver is None or int(ver.group(1)) > 0 or int(ver.group(2)) >= 6 + constants.MPV_OSC_VISIBILITY_CHANGE_VERSION = False if ver is None else int(ver.group(1)) > 0 or int(ver.group(2)) >= 28 + if not constants.MPV_OSC_VISIBILITY_CHANGE_VERSION: + client.ui.showDebugMessage(u"This version of mpv is not known to be compatible with changing the OSC visibility. Please use mpv >=0.28.0.") if constants.MPV_NEW_VERSION: return NewMpvPlayer(client, MpvPlayer.getExpandedPath(playerPath), filePath, args) else: @@ -257,6 +260,7 @@ class NewMpvPlayer(OldMpvPlayer): options.append(option) for option in constants.MPV_SYNCPLAYINTF_LANGUAGE_TO_SEND: options.append(u"{}={}".format(option,getMessage(option))) + options.append(u"OscVisibilityChangeCompatible={}".format(constants.MPV_OSC_VISIBILITY_CHANGE_VERSION)) options_string = ", ".join(options) self._listener.sendLine(u'script-message-to syncplayintf set_syncplayintf_options "{}"'.format(options_string)) self._setOSDPosition()