There is a phenomenon called terminal agitation, which may occur when a person is near the end of life.
It may look like this: picking in the air, taking off one's clothes no matter who is around, trying to get out of bed regardless of safety issues, wanting out of bed and then wanting to go back to bed within 5 minutes, among many other "fidgety" and "restless" behaviors. There may be yelling, moaning, crying, and hallucinations. The person is not satisfied regardless of the family's attempt at soothing or providing what is requested.
This is agonizing for the family and this behavior has many possible causes that may take a long time to remedy. It can make otherwise reasonable family members become angry and distraught. Know that if the person could change this, they would. Nobody who is aware of themselves and could do something about it would continue it.
With very difficult cases, strong medication is needed and families sometimes have much trouble with knowing their loved one will be sedated. Sedation vs. agitation: think about what you would want.