diff options
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index 0a63a941..8ebb67a8 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -91,10 +91,13 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { | |||
91 | #endif | 91 | #endif |
92 | 92 | ||
93 | #if !defined (iHaveNativeMenus) | 93 | #if !defined (iHaveNativeMenus) |
94 | /* TODO: Submenus wouldn't hurt here. */ | ||
94 | static const iMenuItem navMenuItems[] = { | 95 | static const iMenuItem navMenuItems[] = { |
95 | { "New Tab", 't', KMOD_PRIMARY, "tabs.new" }, | 96 | { "New Tab", 't', KMOD_PRIMARY, "tabs.new" }, |
96 | { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, | 97 | { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, |
97 | { "---", 0, 0, NULL }, | 98 | { "---", 0, 0, NULL }, |
99 | { "Save to Downloads", SDLK_s, KMOD_PRIMARY, "document.save" }, | ||
100 | { "---", 0, 0, NULL }, | ||
98 | { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, | 101 | { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, |
99 | { "Bookmark This Page", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, | 102 | { "Bookmark This Page", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, |
100 | { "---", 0, 0, NULL }, | 103 | { "---", 0, 0, NULL }, |
@@ -104,7 +107,7 @@ static const iMenuItem navMenuItems[] = { | |||
104 | { "Reset Zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, | 107 | { "Reset Zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, |
105 | { "---", 0, 0, NULL }, | 108 | { "---", 0, 0, NULL }, |
106 | { "Preferences...", SDLK_COMMA, KMOD_PRIMARY, "preferences" }, | 109 | { "Preferences...", SDLK_COMMA, KMOD_PRIMARY, "preferences" }, |
107 | { "Help", 0, 0, "!open url:about:help" }, | 110 | { "Help", SDLK_F1, 0, "!open url:about:help" }, |
108 | { "Release Notes", 0, 0, "!open url:about:version" }, | 111 | { "Release Notes", 0, 0, "!open url:about:version" }, |
109 | { "---", 0, 0, NULL }, | 112 | { "---", 0, 0, NULL }, |
110 | { "Quit Lagrange", 'q', KMOD_PRIMARY, "quit" } | 113 | { "Quit Lagrange", 'q', KMOD_PRIMARY, "quit" } |
@@ -116,6 +119,8 @@ static const iMenuItem navMenuItems[] = { | |||
116 | static const iMenuItem fileMenuItems[] = { | 119 | static const iMenuItem fileMenuItems[] = { |
117 | { "New Tab", SDLK_t, KMOD_PRIMARY, "tabs.new" }, | 120 | { "New Tab", SDLK_t, KMOD_PRIMARY, "tabs.new" }, |
118 | { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, | 121 | { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, |
122 | { "---", 0, 0, NULL }, | ||
123 | { "Save to Downloads", SDLK_s, KMOD_PRIMARY, "document.save" }, | ||
119 | }; | 124 | }; |
120 | 125 | ||
121 | static const iMenuItem editMenuItems[] = { | 126 | static const iMenuItem editMenuItems[] = { |
@@ -362,12 +367,24 @@ static void setupUserInterface_Window(iWindow *d) { | |||
362 | setId_Widget(as_Widget(lock), "navbar.lock"); | 367 | setId_Widget(as_Widget(lock), "navbar.lock"); |
363 | setFont_LabelWidget(lock, defaultSymbols_FontId); | 368 | setFont_LabelWidget(lock, defaultSymbols_FontId); |
364 | updateTextCStr_LabelWidget(lock, "\U0001f512"); | 369 | updateTextCStr_LabelWidget(lock, "\U0001f512"); |
365 | iInputWidget *url = new_InputWidget(0); | 370 | /* URL input field. */ { |
366 | setSelectAllOnFocus_InputWidget(url, iTrue); | 371 | iInputWidget *url = new_InputWidget(0); |
367 | setId_Widget(as_Widget(url), "url"); | 372 | setSelectAllOnFocus_InputWidget(url, iTrue); |
368 | setNotifyEdits_InputWidget(url, iTrue); | 373 | setId_Widget(as_Widget(url), "url"); |
369 | setTextCStr_InputWidget(url, "gemini://"); | 374 | setNotifyEdits_InputWidget(url, iTrue); |
370 | addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); | 375 | setTextCStr_InputWidget(url, "gemini://"); |
376 | addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); | ||
377 | /* Download progress indicator is inside the input field, but hidden normally. */ | ||
378 | setPadding_Widget(as_Widget(url),0, 0, gap_UI * 1, 0); | ||
379 | iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 MB", 0, 0, NULL); | ||
380 | setId_Widget(as_Widget(progress), "document.progress"); | ||
381 | setAlignVisually_LabelWidget(progress, iTrue); | ||
382 | shrink_Rect(&as_Widget(progress)->rect, init_I2(0, gap_UI)); | ||
383 | addChildFlags_Widget(as_Widget(url), | ||
384 | iClob(progress), | ||
385 | moveToParentRightEdge_WidgetFlag); | ||
386 | setBackgroundColor_Widget(as_Widget(progress), uiBackground_ColorId); | ||
387 | } | ||
371 | setId_Widget(addChild_Widget( | 388 | setId_Widget(addChild_Widget( |
372 | navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), | 389 | navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), |
373 | "reload"); | 390 | "reload"); |
@@ -477,26 +494,36 @@ static void drawBlank_Window_(iWindow *d) { | |||
477 | SDL_RenderPresent(d->render); | 494 | SDL_RenderPresent(d->render); |
478 | } | 495 | } |
479 | 496 | ||
480 | // #define ENABLE_SWRENDER | 497 | iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) { |
498 | flags |= SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; | ||
499 | if (SDL_CreateWindowAndRenderer( | ||
500 | width_Rect(rect), height_Rect(rect), flags, &d->win, &d->render)) { | ||
501 | return iFalse; | ||
502 | } | ||
503 | return iTrue; | ||
504 | } | ||
481 | 505 | ||
482 | void init_Window(iWindow *d, iRect rect) { | 506 | void init_Window(iWindow *d, iRect rect) { |
483 | theWindow_ = d; | 507 | theWindow_ = d; |
484 | iZap(d->cursors); | 508 | iZap(d->cursors); |
509 | d->initialPos = rect.pos; | ||
485 | d->pendingCursor = NULL; | 510 | d->pendingCursor = NULL; |
486 | d->isDrawFrozen = iTrue; | 511 | d->isDrawFrozen = iTrue; |
487 | uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; | 512 | uint32_t flags = 0; |
488 | #if defined (ENABLE_SWRENDER) | 513 | #if defined (iPlatformApple) |
489 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); | ||
490 | #elif defined (iPlatformApple) | ||
491 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); | 514 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); |
492 | #else | 515 | #else |
493 | flags |= SDL_WINDOW_OPENGL; | 516 | flags |= SDL_WINDOW_OPENGL; |
494 | #endif | 517 | #endif |
495 | SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); | 518 | SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); |
496 | if (SDL_CreateWindowAndRenderer( | 519 | /* First try SDL's default renderer that should be the best option. */ |
497 | width_Rect(rect), height_Rect(rect), flags, &d->win, &d->render)) { | 520 | if (forceSoftwareRender_App() || !create_Window_(d, rect, flags)) { |
498 | fprintf(stderr, "Error when creating window: %s\n", SDL_GetError()); | 521 | /* No luck, maybe software only? This should always work as long as there is a display. */ |
499 | exit(-2); | 522 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); |
523 | if (!create_Window_(d, rect, 0)) { | ||
524 | fprintf(stderr, "Error when creating window: %s\n", SDL_GetError()); | ||
525 | exit(-2); | ||
526 | } | ||
500 | } | 527 | } |
501 | if (left_Rect(rect) >= 0) { | 528 | if (left_Rect(rect) >= 0) { |
502 | SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); | 529 | SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); |
@@ -571,6 +598,16 @@ SDL_Renderer *renderer_Window(const iWindow *d) { | |||
571 | 598 | ||
572 | static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | 599 | static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { |
573 | switch (ev->event) { | 600 | switch (ev->event) { |
601 | #if defined (LAGRANGE_ENABLE_WINDOWPOS_FIX) | ||
602 | case SDL_WINDOWEVENT_EXPOSED: | ||
603 | if (d->initialPos.x >= 0) { | ||
604 | int bx, by; | ||
605 | SDL_GetWindowBordersSize(d->win, &by, &bx, NULL, NULL); | ||
606 | SDL_SetWindowPosition(d->win, d->initialPos.x + bx, d->initialPos.y + by); | ||
607 | d->initialPos = init1_I2(-1); | ||
608 | } | ||
609 | return iFalse; | ||
610 | #endif | ||
574 | case SDL_WINDOWEVENT_MOVED: | 611 | case SDL_WINDOWEVENT_MOVED: |
575 | /* No need to do anything. */ | 612 | /* No need to do anything. */ |
576 | return iTrue; | 613 | return iTrue; |