Skip to content

Commit

Permalink
fix: making sure the context menu is always contained in the main
Browse files Browse the repository at this point in the history
window.
  • Loading branch information
s4my committed Oct 31, 2023
1 parent f2d3204 commit 64b9f08
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions luigi2.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ typedef struct UIMenu {
UIElement e;
int pointX, pointY;
UIScrollBar *vScroll;
UIWindow *parentWindow;
} UIMenu;
#endif

Expand Down Expand Up @@ -4332,6 +4333,7 @@ UIMenu *UIMenuCreate(UIElement *parent, uint32_t flags) {
UIWindow *window = UIWindowCreate(parent->window, UI_WINDOW_MENU, 0, 0, 0);
UIMenu *menu = (UIMenu *) UIElementCreate(sizeof(UIMenu), &window->e, flags, _UIMenuMessage, "Menu");
menu->vScroll = UIScrollBarCreate(&menu->e, UI_ELEMENT_NON_CLIENT);
menu->parentWindow = parent->window;

if (parent->parent) {
UIRectangle screenBounds = UIElementScreenBounds(parent);
Expand Down Expand Up @@ -5550,23 +5552,20 @@ void UIMenuShow(UIMenu *menu) {
int width, height;
_UIMenuPrepare(menu, &width, &height);

for (int i = 0; i < ScreenCount(ui.display); i++) {
Screen *screen = ScreenOfDisplay(ui.display, i);

int x, y;
Window child;
XTranslateCoordinates(ui.display, screen->root, DefaultRootWindow(ui.display), 0, 0, &x, &y, &child);

if (menu->pointX >= x && menu->pointX < x + screen->width
&& menu->pointY >= y && menu->pointY < y + screen->height) {
if (menu->pointX + width > x + screen->width) menu->pointX = x + screen->width - width;
if (menu->pointY + height > y + screen->height) menu->pointY = y + screen->height - height;
if (menu->pointX < x) menu->pointX = x;
if (menu->pointY < y) menu->pointY = y;
if (menu->pointX + width > x + screen->width) width = x + screen->width - menu->pointX;
if (menu->pointY + height > y + screen->height) height = y + screen->height - menu->pointY;
break;
}
UIWindow *parentWindow = menu->parentWindow;

int x, y;
Window child;
XTranslateCoordinates(ui.display, parentWindow->window, DefaultRootWindow(ui.display), 0, 0, &x, &y, &child);

if (menu->pointX >= x && menu->pointX < x + parentWindow->width
&& menu->pointY >= y && menu->pointY < y + parentWindow->height) {
if (menu->pointX + width > x + parentWindow->width) menu->pointX = x + parentWindow->width - width;
if (menu->pointY + height > y + parentWindow->height) menu->pointY = y + parentWindow->height - height;
if (menu->pointX < x) menu->pointX = x;
if (menu->pointY < y) menu->pointY = y;
if (menu->pointX + width > x + parentWindow->width) width = x + parentWindow->width - menu->pointX;
if (menu->pointY + height > y + parentWindow->height) height = y + parentWindow->height - menu->pointY;
}

Atom properties[] = {
Expand Down

0 comments on commit 64b9f08

Please sign in to comment.