I created a popup menu through API, and I want it to act a certain way when it's near the edge of the screen. Usually, when you have a popup menu appear near the edge of the screen, if the menu is wider than the distance it popped from the edge, the menu will pop out from the opposite side (instead of popping to the lower-right, it will pop out to the lower-left).

I want my menu, instead of opening to the other side, to hug the edge of the screen (where the mouse pointer will be somewhere between the left and right-most part of the menu).

Any ideas on this?