I used to sleep with a gun under my pillow, but have since stopped. Iv actually been thinking about this a lot lately.
My head board has two small cubby holes directly behind where you would place a pillow. i switched to keeping my gun in there. This way It can't get worked down, and i cant bump it in my sleep. As a bonus, the pillow covers the mouth of the lower cubby hole, so that you can't see anything inside unless you move the pillow.
As to what you keep, you need something idiot proof. I would suggest a DAO pistol or a DA revolver. pointing the gun will be hard enough when your groggy. Messing with safety's or chambering a round will likely not go as planned.
On the other hand, Iv been questioning the point lately. Several times now I've had family members come into my bedroom, wake me up unexpectedly, and I never even think about the gun. If someone were to break in during the night, I'm seriously questioning if I would even know what was going on, or realize that I needed to get the gun. I would probably just assume it was the dog or cat knocking something over, IF i woke up at all. Just something i need to work out.