Oh, my heart hurts for you. I've recently been there myself and there's no easy answer. My dog was over 14 years old, had beaten cancer once (it had returned, albeit slow-growing), but still had his good days. He was on fairly strong painkillers for arthritis and one of his back legs was all but useless and dragging behind him. He would sometimes fall and be unable to rise. He had marked dementia, slept around 18-22 hours a day, and when he was awake, would pace around. It was rare for us to see him seem truly joyful. And yet, we still clung to the good moments.
I talked to a lot of friends and family about what to do, but talking it over with his vet was what helped me the most. She listened very sympathetically and then told me, "If you decide you are ready to say goodbye to him, no one here would object to your decision. You're in the best position to judge his quality of life and at this point, that's entirely what you need to consider. He's very old now and will only continue to decline. If you decide the time is now, we're here to support that decision."
I appreciated that she didn't let me off the hook or venture a guess with "If it were my dog..." At that point, I knew what needed to happen and knowing that my vet's office was in my corner made a big difference. I fully recognize you might not get the same solace from talking to your vet, but they are in a really good position to give advice. They've seen this thousands of times and if you're feeling any doubts, they can answer your questions and hopefully give you confidence in your choice, whatever it may be.
The only other advice I would give is, personally, I think if you wait until your dog gives you a sign that makes you 100% certain it's time, you've probably waited too long. I didn't want it to take him breaking a bone in a fall, or being completely unwilling to get up to go potty, or in some similarly terrible condition to make the choice. For me, that was much, much more than I could ask him to endure and would've just broken my heart.
I hope this helpful. You're in a rotten situation, no doubt about it. My deepest sympathies to you.