%
% anyremote configuration file for mpv management. (Server-mode)
% 

% STATUS stable
% XTEST yes
% ENV no
% SOUND mixer
% FBROWSER v.4i
% DEF_VIDEO_PLAYER   
% ALL_IN_ONE 
% MEDIACENTER video

GuiAppName=MPV
GuiAppBinary=mpv
GuiAppRun=A=`ps -ef|grep mpv|grep -v grep|grep -v edit|grep -v anyremote`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=mpv.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=A free, open source, and cross-platform media player (https://mpv.io/)

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Include($(CfgDir)/Utils/aliases-server-fbrowser-v4i.cfg);\
	Macro(FBROWSER_IC_INIT);\
	Include($(CfgDir)/Utils/aliases-server-video-player.cfg);\
	Make(var,app_name,by_value,MPV);\
	Make(var,open_file,by_value,);\
	Make(var,do_app_init,by_value,1);\
	Make(var,mpv_pure_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get mpv_pure_layout`;\
	     if [ "x$V" = "x" ]; then echo "3x4"; else echo $V; fi);\
	Make(var,app_manage_mode,by_value,mpv_$(mpv_pure_layout));

(Exit)=\
	Macro(FBROWSER_IC_EXIT);\
	Exec($(CfgDir)/Utils/registry.sh $(TmpDir) set mpv_pure_layout $(mpv_pure_layout));

(Connect)=\
	Make(mode,mpv_init);

[Mode]=mpv_init : default_video_player_init

APP_IS_RUN=\
	Make(var,app_run,\
		ID=`id -u`;A=`ps -fu $ID|grep mpv|grep -v grep|grep -v edit|grep -v anyremote`; \
		if [ "x$A" = "x" ]; then echo 0; else echo 1; fi);

[ModeEnd]

[Mode]=mpv_general


APP_START_IF=\
	Set(title,$(open_file));\
	Make(var,app_run,\
		ID=`id -u`;A=`ps -fu $ID|grep mpv|grep -v grep|grep -v edit|grep -v anyremote`; \
		if [ "x$A" = "x" ]; then echo 0; else echo 1; fi);\
 	Exec(if [ "x$(app_run)" = "x0" ]; then cd "$(fbrowser_dir)";mpv $(open_file) > /dev/null & fi);

% Application window should be present in output of "wmctrl -l"
APP_RAISE=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh -switch mpv);

APP_QUIT=\
	Exec(pkill -u `id -u` mpv);

APP_FULLSCREEN=\
	Emulate(key,f)

PLAY=\
	Emulate(key,space)
	
RWD=\
	Emulate(key,Left);
FF=\
	Emulate(key,Right);
STOP=\
	Emulate(key,space);
PAUSE=\
	Emulate(key,space);

Layout 3x4=\
	Make(mode,mpv_3x4);

Layout 5x1=\
	Make(mode,mpv_5x1);

[ModeEnd]

[Mode]=mpv_3x4 : mpv_general,default_video_player

% (EnterMode) by Utils/aliases-server-video-player.cfg

APP_POST_SETUP=\
	Make(var,mpv_pure_layout,by_value,3x4);\
	Make(var,app_manage_mode,by_value,mpv_$(mpv_pure_layout));


APP_MENU=\
	Set(menu,replace,Layout 5x1,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

[ModeEnd]

[Mode]=mpv_5x1 : mpv_general,default_video_player_5x1 

APP_POST_SETUP=\
	Make(var,mpv_pure_layout,by_value,5x1);\
	Make(var,app_manage_mode,by_value,mpv_$(mpv_pure_layout));

APP_MENU=\
	Set(menu,replace,Help,Mute,Quit,Fullscreen,Files,Layout 3x4,IMDB,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

Fullscreen=\
	Macro(APP_FULLSCREEN);

[ModeEnd]

[End]
