diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-04 22:34:31 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-04 22:34:31 +0300 |
commit | 7a4d9cc39337f93cb3b9e5bca982b04f0a7c7da5 (patch) | |
tree | 1e55a93e0e69b91d4b50c75ce581e03d6b54e229 /src/ui/documentwidget.c | |
parent | d827dab6cdbc376b6d33cbe5924588e92cffcf54 (diff) |
Split view pinning, "linksplit" special tag
A navigation aid: when in split mode, option to keep one of the tabs pinned to the current page so all links open to the side.
Added "linksplit" bookmark tag to activate view splitting when opening a link on the page.
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 6a44fd5f..8d519865 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -221,6 +221,7 @@ enum iDocumentWidgetFlag { | |||
221 | pinchZoom_DocumentWidgetFlag = iBit(9), | 221 | pinchZoom_DocumentWidgetFlag = iBit(9), |
222 | movingSelectMarkStart_DocumentWidgetFlag = iBit(10), | 222 | movingSelectMarkStart_DocumentWidgetFlag = iBit(10), |
223 | movingSelectMarkEnd_DocumentWidgetFlag = iBit(11), | 223 | movingSelectMarkEnd_DocumentWidgetFlag = iBit(11), |
224 | otherRootByDefault_DocumentWidgetFlag = iBit(12), /* links open to other root by default */ | ||
224 | }; | 225 | }; |
225 | 226 | ||
226 | enum iDocumentLinkOrdinalMode { | 227 | enum iDocumentLinkOrdinalMode { |
@@ -956,6 +957,20 @@ static void documentRunsInvalidated_DocumentWidget_(iDocumentWidget *d) { | |||
956 | iZap(d->renderRuns); | 957 | iZap(d->renderRuns); |
957 | } | 958 | } |
958 | 959 | ||
960 | iBool isPinned_DocumentWidget_(const iDocumentWidget *d) { | ||
961 | if (d->flags & otherRootByDefault_DocumentWidgetFlag) { | ||
962 | return iTrue; | ||
963 | } | ||
964 | const iWidget *w = constAs_Widget(d); | ||
965 | const iWindow *win = get_Window(); | ||
966 | if (numRoots_Window(win) == 1) { | ||
967 | return iFalse; | ||
968 | } | ||
969 | const iPrefs *prefs = prefs_App(); | ||
970 | return (prefs->pinSplit == 1 && w->root == win->roots[0]) || | ||
971 | (prefs->pinSplit == 2 && w->root == win->roots[1]); | ||
972 | } | ||
973 | |||
959 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { | 974 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { |
960 | setUrl_GmDocument(d->doc, d->mod.url); | 975 | setUrl_GmDocument(d->doc, d->mod.url); |
961 | setSource_GmDocument(d->doc, source, documentWidth_DocumentWidget_(d)); | 976 | setSource_GmDocument(d->doc, source, documentWidth_DocumentWidget_(d)); |
@@ -965,6 +980,15 @@ void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { | |||
965 | d->drawBufs->flags |= updateSideBuf_DrawBufsFlag; | 980 | d->drawBufs->flags |= updateSideBuf_DrawBufsFlag; |
966 | invalidate_DocumentWidget_(d); | 981 | invalidate_DocumentWidget_(d); |
967 | refresh_Widget(as_Widget(d)); | 982 | refresh_Widget(as_Widget(d)); |
983 | /* Check for special bookmark tags. */ | ||
984 | d->flags &= ~otherRootByDefault_DocumentWidgetFlag; | ||
985 | const uint16_t bmid = findUrl_Bookmarks(bookmarks_App(), d->mod.url); | ||
986 | if (bmid) { | ||
987 | const iBookmark *bm = get_Bookmarks(bookmarks_App(), bmid); | ||
988 | if (hasTag_Bookmark(bm, linkSplit_BookmarkTag)) { | ||
989 | d->flags |= otherRootByDefault_DocumentWidgetFlag; | ||
990 | } | ||
991 | } | ||
968 | } | 992 | } |
969 | 993 | ||
970 | static void updateTheme_DocumentWidget_(iDocumentWidget *d) { | 994 | static void updateTheme_DocumentWidget_(iDocumentWidget *d) { |
@@ -2455,7 +2479,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2455 | linkUrl_GmDocument(d->doc, run->linkId))) != 0) { | 2479 | linkUrl_GmDocument(d->doc, run->linkId))) != 0) { |
2456 | const iBookmark *bm = get_Bookmarks(bookmarks_App(), bmid); | 2480 | const iBookmark *bm = get_Bookmarks(bookmarks_App(), bmid); |
2457 | /* We can import local copies of remote bookmarks. */ | 2481 | /* We can import local copies of remote bookmarks. */ |
2458 | if (!hasTag_Bookmark(bm, "remote")) { | 2482 | if (!hasTag_Bookmark(bm, remote_BookmarkTag)) { |
2459 | remove_PtrArrayIterator(&i); | 2483 | remove_PtrArrayIterator(&i); |
2460 | } | 2484 | } |
2461 | } | 2485 | } |
@@ -2740,11 +2764,12 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2740 | else { | 2764 | else { |
2741 | postCommandf_Root(w->root, | 2765 | postCommandf_Root(w->root, |
2742 | "open newtab:%d url:%s", | 2766 | "open newtab:%d url:%s", |
2743 | d->ordinalMode == | 2767 | (isPinned_DocumentWidget_(d) ? otherRoot_OpenTabFlag : 0) ^ |
2768 | (d->ordinalMode == | ||
2744 | numbersAndAlphabet_DocumentLinkOrdinalMode | 2769 | numbersAndAlphabet_DocumentLinkOrdinalMode |
2745 | ? openTabMode_Sym(modState_Keys()) | 2770 | ? openTabMode_Sym(modState_Keys()) |
2746 | : (d->flags & newTabViaHomeKeys_DocumentWidgetFlag ? 1 : 0), | 2771 | : (d->flags & newTabViaHomeKeys_DocumentWidgetFlag ? 1 : 0)), |
2747 | cstr_String(absoluteUrl_String( | 2772 | cstr_String(absoluteUrl_String( |
2748 | d->mod.url, linkUrl_GmDocument(d->doc, run->linkId)))); | 2773 | d->mod.url, linkUrl_GmDocument(d->doc, run->linkId)))); |
2749 | } | 2774 | } |
2750 | setLinkNumberMode_DocumentWidget_(d, iFalse); | 2775 | setLinkNumberMode_DocumentWidget_(d, iFalse); |
@@ -2862,8 +2887,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2862 | } | 2887 | } |
2863 | if (ev->button.button == SDL_BUTTON_MIDDLE && d->hoverLink) { | 2888 | if (ev->button.button == SDL_BUTTON_MIDDLE && d->hoverLink) { |
2864 | postCommandf_Root(w->root, "open newtab:%d url:%s", | 2889 | postCommandf_Root(w->root, "open newtab:%d url:%s", |
2865 | modState_Keys() & KMOD_SHIFT ? 1 : 2, | 2890 | (isPinned_DocumentWidget_(d) ? otherRoot_OpenTabFlag : 0) | |
2866 | cstr_String(linkUrl_GmDocument(d->doc, d->hoverLink->linkId))); | 2891 | (modState_Keys() & KMOD_SHIFT ? new_OpenTabFlag : newBackground_OpenTabFlag), |
2892 | cstr_String(linkUrl_GmDocument(d->doc, d->hoverLink->linkId))); | ||
2867 | return iTrue; | 2893 | return iTrue; |
2868 | } | 2894 | } |
2869 | if (ev->button.button == SDL_BUTTON_RIGHT && | 2895 | if (ev->button.button == SDL_BUTTON_RIGHT && |
@@ -3237,8 +3263,12 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
3237 | refresh_Widget(w); | 3263 | refresh_Widget(w); |
3238 | } | 3264 | } |
3239 | else if (linkFlags & supportedProtocol_GmLinkFlag) { | 3265 | else if (linkFlags & supportedProtocol_GmLinkFlag) { |
3266 | int tabMode = openTabMode_Sym(modState_Keys()); | ||
3267 | if (isPinned_DocumentWidget_(d)) { | ||
3268 | tabMode ^= otherRoot_OpenTabFlag; | ||
3269 | } | ||
3240 | postCommandf_Root(w->root, "open newtab:%d url:%s", | 3270 | postCommandf_Root(w->root, "open newtab:%d url:%s", |
3241 | openTabMode_Sym(modState_Keys()), | 3271 | tabMode, |
3242 | cstr_String(absoluteUrl_String( | 3272 | cstr_String(absoluteUrl_String( |
3243 | d->mod.url, linkUrl_GmDocument(d->doc, linkId)))); | 3273 | d->mod.url, linkUrl_GmDocument(d->doc, linkId)))); |
3244 | } | 3274 | } |