diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/listwidget.c | 7 | ||||
-rw-r--r-- | src/ui/util.c | 3 | ||||
-rw-r--r-- | src/ui/window.c | 51 |
3 files changed, 36 insertions, 25 deletions
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c index 68ebc377..199121e4 100644 --- a/src/ui/listwidget.c +++ b/src/ui/listwidget.c | |||
@@ -563,11 +563,12 @@ static void draw_ListWidget_(const iListWidget *d) { | |||
563 | } | 563 | } |
564 | setClip_Paint(&p, bounds_Widget(w)); | 564 | setClip_Paint(&p, bounds_Widget(w)); |
565 | draw_VisBuf(d->visBuf, addY_I2(topLeft_Rect(bounds), -scrollY), ySpan_Rect(bounds)); | 565 | draw_VisBuf(d->visBuf, addY_I2(topLeft_Rect(bounds), -scrollY), ySpan_Rect(bounds)); |
566 | if (d->dragItem != iInvalidPos) { | 566 | const iInt2 mousePos = mouseCoord_Window(get_Window(), 0); |
567 | const iInt2 mousePos = mouseCoord_Window(get_Window(), 0); | 567 | if (d->dragItem != iInvalidPos && contains_Rect(bounds, mousePos)) { |
568 | iInt2 pos = add_I2(mousePos, d->dragOrigin); | 568 | iInt2 pos = add_I2(mousePos, d->dragOrigin); |
569 | const iListItem *item = constAt_PtrArray(&d->items, d->dragItem); | 569 | const iListItem *item = constAt_PtrArray(&d->items, d->dragItem); |
570 | const iRect itemRect = { init_I2(left_Rect(bounds), pos.y), init_I2(d->visBuf->texSize.x, d->itemHeight) }; | 570 | const iRect itemRect = { init_I2(left_Rect(bounds), pos.y), |
571 | init_I2(d->visBuf->texSize.x, d->itemHeight) }; | ||
571 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); | 572 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); |
572 | iBool dstOnto; | 573 | iBool dstOnto; |
573 | const size_t dstIndex = resolveDragDestination_ListWidget_(d, mousePos, &dstOnto); | 574 | const size_t dstIndex = resolveDragDestination_ListWidget_(d, mousePos, &dstOnto); |
diff --git a/src/ui/util.c b/src/ui/util.c index a8d9b04e..4ab086fe 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -1022,7 +1022,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1022 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); | 1022 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); |
1023 | setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); | 1023 | setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); |
1024 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); | 1024 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); |
1025 | arrange_Widget(d); | 1025 | arrange_Widget(d); /* need to know the height */ |
1026 | #if defined (LAGRANGE_ENABLE_POPUP_MENUS) | 1026 | #if defined (LAGRANGE_ENABLE_POPUP_MENUS) |
1027 | /* Determine total display bounds where the popup may appear. */ | 1027 | /* Determine total display bounds where the popup may appear. */ |
1028 | iRect displayRect = zero_Rect(); | 1028 | iRect displayRect = zero_Rect(); |
@@ -1065,6 +1065,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1065 | } | 1065 | } |
1066 | iWindow *win = newPopup_Window(menuPos, d); /* window takes the widget */ | 1066 | iWindow *win = newPopup_Window(menuPos, d); /* window takes the widget */ |
1067 | SDL_SetWindowTitle(win->win, "Menu"); | 1067 | SDL_SetWindowTitle(win->win, "Menu"); |
1068 | arrange_Widget(d); | ||
1068 | addPopup_App(win); | 1069 | addPopup_App(win); |
1069 | SDL_ShowWindow(win->win); | 1070 | SDL_ShowWindow(win->win); |
1070 | draw_Window(win); | 1071 | draw_Window(win); |
diff --git a/src/ui/window.c b/src/ui/window.c index 543a0b88..bdac441a 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -123,6 +123,7 @@ static iMenuItem bookmarksMenuItems_[] = { | |||
123 | { "${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" }, | 123 | { "${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" }, |
124 | { "${menu.newfolder}", 0, 0, "bookmarks.addfolder" }, | 124 | { "${menu.newfolder}", 0, 0, "bookmarks.addfolder" }, |
125 | { "---", 0, 0, NULL }, | 125 | { "---", 0, 0, NULL }, |
126 | { "${menu.sort.alpha}", 0, 0, "bookmarks.sort" }, | ||
126 | { "${menu.import.links}", 0, 0, "bookmark.links confirm:1" }, | 127 | { "${menu.import.links}", 0, 0, "bookmark.links confirm:1" }, |
127 | { "---", 0, 0, NULL }, | 128 | { "---", 0, 0, NULL }, |
128 | { "${macos.menu.bookmarks.list}", 0, 0, "open url:about:bookmarks" }, | 129 | { "${macos.menu.bookmarks.list}", 0, 0, "open url:about:bookmarks" }, |
@@ -130,7 +131,6 @@ static iMenuItem bookmarksMenuItems_[] = { | |||
130 | { "${macos.menu.bookmarks.bytime}", 0, 0, "open url:about:bookmarks?created" }, | 131 | { "${macos.menu.bookmarks.bytime}", 0, 0, "open url:about:bookmarks?created" }, |
131 | { "${menu.feeds.entrylist}", 0, 0, "open url:about:feeds" }, | 132 | { "${menu.feeds.entrylist}", 0, 0, "open url:about:feeds" }, |
132 | { "---", 0, 0, NULL }, | 133 | { "---", 0, 0, NULL }, |
133 | { "${menu.sort.alpha}", 0, 0, "bookmarks.sort" }, | ||
134 | { "---", 0, 0, NULL }, | 134 | { "---", 0, 0, NULL }, |
135 | { "${menu.bookmarks.refresh}", 0, 0, "bookmarks.reload.remote" }, | 135 | { "${menu.bookmarks.refresh}", 0, 0, "bookmarks.reload.remote" }, |
136 | { "${menu.feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" }, | 136 | { "${menu.feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" }, |
@@ -369,7 +369,7 @@ SDL_HitTestResult hitTest_MainWindow(const iMainWindow *d, iInt2 pos) { | |||
369 | } | 369 | } |
370 | #endif | 370 | #endif |
371 | 371 | ||
372 | iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) { | 372 | void create_Window_(iWindow *d, iRect rect, uint32_t flags) { |
373 | flags |= SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN; | 373 | flags |= SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN; |
374 | if (d->type == main_WindowType) { | 374 | if (d->type == main_WindowType) { |
375 | flags |= SDL_WINDOW_RESIZABLE; | 375 | flags |= SDL_WINDOW_RESIZABLE; |
@@ -397,14 +397,23 @@ iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) { | |||
397 | fprintf(stderr, "[window] failed to create window: %s\n", SDL_GetError()); | 397 | fprintf(stderr, "[window] failed to create window: %s\n", SDL_GetError()); |
398 | exit(-3); | 398 | exit(-3); |
399 | } | 399 | } |
400 | if (forceSoftwareRender_App()) { | ||
401 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); | ||
402 | } | ||
400 | d->render = SDL_CreateRenderer( | 403 | d->render = SDL_CreateRenderer( |
401 | d->win, | 404 | d->win, |
402 | -1, | 405 | -1, |
403 | (forceSoftwareRender_App() ? SDL_RENDERER_SOFTWARE : SDL_RENDERER_ACCELERATED) | | 406 | (forceSoftwareRender_App() ? SDL_RENDERER_SOFTWARE : SDL_RENDERER_ACCELERATED) | |
404 | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE); | 407 | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE); |
405 | if (!d->render) { | 408 | if (!d->render) { |
406 | fprintf(stderr, "[window] failed to create renderer: %s\n", SDL_GetError()); | 409 | /* Try a basic software rendering instead. */ |
407 | exit(-4); | 410 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); |
411 | d->render = SDL_CreateRenderer(d->win, -1, SDL_RENDERER_SOFTWARE); | ||
412 | if (!d->render) { | ||
413 | /* This shouldn't fail.-..? */ | ||
414 | fprintf(stderr, "[window] failed to create renderer: %s\n", SDL_GetError()); | ||
415 | exit(-4); | ||
416 | } | ||
408 | } | 417 | } |
409 | #if defined(LAGRANGE_ENABLE_CUSTOM_FRAME) | 418 | #if defined(LAGRANGE_ENABLE_CUSTOM_FRAME) |
410 | if (type_Window(d) == main_WindowType && prefs_App()->customFrame) { | 419 | if (type_Window(d) == main_WindowType && prefs_App()->customFrame) { |
@@ -413,7 +422,6 @@ iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) { | |||
413 | SDL_SetWindowResizable(d->win, SDL_TRUE); | 422 | SDL_SetWindowResizable(d->win, SDL_TRUE); |
414 | } | 423 | } |
415 | #endif | 424 | #endif |
416 | return iTrue; | ||
417 | } | 425 | } |
418 | 426 | ||
419 | static SDL_Surface *loadImage_(const iBlock *data, int resized) { | 427 | static SDL_Surface *loadImage_(const iBlock *data, int resized) { |
@@ -445,25 +453,23 @@ void init_Window(iWindow *d, enum iWindowType type, iRect rect, uint32_t flags) | |||
445 | d->isInvalidated = iFalse; /* set when posting event, to avoid repeated events */ | 453 | d->isInvalidated = iFalse; /* set when posting event, to avoid repeated events */ |
446 | d->isMouseInside = iTrue; | 454 | d->isMouseInside = iTrue; |
447 | d->ignoreClick = iFalse; | 455 | d->ignoreClick = iFalse; |
448 | d->focusGainedAt = 0; | 456 | d->focusGainedAt = SDL_GetTicks(); |
449 | d->presentTime = 0.0; | 457 | d->presentTime = 0.0; |
450 | d->frameTime = SDL_GetTicks(); | 458 | d->frameTime = SDL_GetTicks(); |
451 | d->keyRoot = NULL; | 459 | d->keyRoot = NULL; |
452 | d->borderShadow = NULL; | 460 | d->borderShadow = NULL; |
453 | iZap(d->roots); | 461 | iZap(d->roots); |
454 | iZap(d->cursors); | 462 | iZap(d->cursors); |
455 | /* First try SDL's default renderer that should be the best option. */ | 463 | create_Window_(d, rect, flags); |
456 | if (forceSoftwareRender_App() || !create_Window_(d, rect, flags)) { | ||
457 | /* No luck, maybe software only? This should always work as long as there is a display. */ | 464 | /* No luck, maybe software only? This should always work as long as there is a display. */ |
458 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); | 465 | // SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); |
459 | flags &= ~SDL_WINDOW_OPENGL; | 466 | // flags &= ~SDL_WINDOW_OPENGL; |
460 | start_PerfTimer(create_Window_); | 467 | // start_PerfTimer(create_Window_); |
461 | if (!create_Window_(d, rect, flags)) { | 468 | // if (!create_Window_(d, rect, flags)) { |
462 | fprintf(stderr, "Error when creating window: %s\n", SDL_GetError()); | 469 | // exit(-2); |
463 | exit(-2); | 470 | // } |
464 | } | 471 | // stop_PerfTimer(create_Window_); |
465 | stop_PerfTimer(create_Window_); | 472 | // } |
466 | } | ||
467 | // start_PerfTimer(setPos); | 473 | // start_PerfTimer(setPos); |
468 | // if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) { | 474 | // if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) { |
469 | // SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); | 475 | // SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); |
@@ -482,7 +488,9 @@ void init_Window(iWindow *d, enum iWindowType type, iRect rect, uint32_t flags) | |||
482 | d->displayScale = displayScale_Window_(d); | 488 | d->displayScale = displayScale_Window_(d); |
483 | d->uiScale = initialUiScale_; | 489 | d->uiScale = initialUiScale_; |
484 | /* TODO: Ratios, scales, and metrics must be window-specific, not global. */ | 490 | /* TODO: Ratios, scales, and metrics must be window-specific, not global. */ |
485 | setScale_Metrics(d->pixelRatio * d->displayScale * d->uiScale); | 491 | if (d->type == main_WindowType) { |
492 | setScale_Metrics(d->pixelRatio * d->displayScale * d->uiScale); | ||
493 | } | ||
486 | d->text = new_Text(d->render); | 494 | d->text = new_Text(d->render); |
487 | } | 495 | } |
488 | 496 | ||
@@ -519,9 +527,7 @@ void init_MainWindow(iMainWindow *d, iRect rect) { | |||
519 | uint32_t flags = 0; | 527 | uint32_t flags = 0; |
520 | #if defined (iPlatformAppleDesktop) | 528 | #if defined (iPlatformAppleDesktop) |
521 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl"); | 529 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl"); |
522 | if (shouldDefaultToMetalRenderer_MacOS()) { | 530 | flags |= shouldDefaultToMetalRenderer_MacOS() ? SDL_WINDOW_METAL : SDL_WINDOW_OPENGL; |
523 | flags |= SDL_WINDOW_METAL; | ||
524 | } | ||
525 | #elif defined (iPlatformAppleMobile) | 531 | #elif defined (iPlatformAppleMobile) |
526 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); | 532 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); |
527 | flags |= SDL_WINDOW_METAL; | 533 | flags |= SDL_WINDOW_METAL; |
@@ -1632,7 +1638,10 @@ iWindow *newPopup_Window(iInt2 screenPos, iWidget *rootWidget) { | |||
1632 | start_PerfTimer(newPopup_Window); | 1638 | start_PerfTimer(newPopup_Window); |
1633 | iPerfTimer pt; init_PerfTimer(&pt); | 1639 | iPerfTimer pt; init_PerfTimer(&pt); |
1634 | const iBool oldSw = forceSoftwareRender_App(); | 1640 | const iBool oldSw = forceSoftwareRender_App(); |
1641 | /* On macOS, SDL seems to want to not use HiDPI with software rendering. */ | ||
1642 | #if !defined (iPlatformApple) | ||
1635 | setForceSoftwareRender_App(iTrue); | 1643 | setForceSoftwareRender_App(iTrue); |
1644 | #endif | ||
1636 | iWindow *win = | 1645 | iWindow *win = |
1637 | new_Window(popup_WindowType, | 1646 | new_Window(popup_WindowType, |
1638 | (iRect){ screenPos, divf_I2(rootWidget->rect.size, get_Window()->pixelRatio) }, | 1647 | (iRect){ screenPos, divf_I2(rootWidget->rect.size, get_Window()->pixelRatio) }, |