In the 18th and early 19th centuries, one of the most popular men's hat styles featured a dome over the head itself, with a wide brim around it. . The brim was pinned up to the dome over the head, rather than remaining flat. In the 1700's, the brim was pinned up in three places, giving the hat a triangular shape. This was called a "three-cornered hat". The Americans in our Revolutionary War are oftenb pictured wearing three-cornered hats. I think Smetana did a classical music piece called "The Three-Cornered Hat.
Sometime around the start of the 1800s, the style changed to a hat pinned up on either side, a two-cornered hat, often called a bicorne ("two-horned")hat. At first this was worn with the corners to either side, like your ears. Later the fashionbecame to wear it with one pointing forward and the other pointing back. Napoleon in particular liked bicornes. This was also known as a "cocked hat", with each of the flaps pinned up being a cock. So the guy in the quote is so sloppy one of his cocks comes undone and he just lets it flap.
Later in the first half of the 20th century, when almost all American men wore hats, my dad told me that it wasw only the stuffiest, most staid and conventional men who wore their hats sitting straight on top of their heads with the brim level and the peak pointing forward. Younger and more macho types always wore their hats with a tilt to one side, sometimes a little bit sometimes a lot. You coild also wear it with the brim tilted down in front, or pointing up with the hat more toward the back of your hat. This was called "cocking the hat", but it probably didn't have anything to do with the cocks of the 19th century hat.
How you cocked your hat in the 20-th century said something about your self-image, but I was too young to get the code for that that my dad knew. Look at pictures of soldiers in WWII in group pictures or when not on parade, and you can see some of the various cocks.
Picture of bicorne, the orgiinal "cocked hat"