v0.13.0 976176a

webview_related.go RawHistoryFolder

1package webkit
2
3/*
4#cgo pkg-config: webkitgtk-6.0 gtk4
5#include <webkit/webkit.h>
6#include <gtk/gtk.h>
7#include <stdlib.h>
8
9// create_related_web_view creates a WebView with the related-view property set
10// This is the WebKitGTK 6.0 way to share session/cookies between views (for popups)
11// The related-view property is construct-only, so it must be set during g_object_new
12static inline WebKitWebView* create_related_web_view(WebKitWebView* parent) {
13	return WEBKIT_WEB_VIEW(g_object_new(
14		WEBKIT_TYPE_WEB_VIEW,
15		"related-view", parent,
16		NULL
17	));
18}
19*/
20import "C"
21import (
22	"log"
23	"runtime"
24	"unsafe"
25
26	webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6"
27	coreglib "github.com/diamondburned/gotk4/pkg/core/glib"
28	"github.com/diamondburned/gotk4/pkg/glib/v2"
29	"github.com/diamondburned/gotk4/pkg/gtk/v4"
30)
31
32// NewBareRelatedWebView creates a bare gotk4 WebView with the related-view property set
33// This ensures the popup shares the same session/process context as the parent
34// The returned WebView is bare (no wrapper, no initialization) and must be initialized later
35//
36// Since gotk4-webkitgtk's wrapWebView() is internal and cannot be accessed,
37// we manually construct the WebView struct hierarchy using CGO.
38func NewBareRelatedWebView(parentView *webkit.WebView) *webkit.WebView {
39	if parentView == nil {
40		log.Printf("[webkit] NewBareRelatedWebView: parent is nil, creating unrelated WebView")
41		return webkit.NewWebView()
42	}
43
44	// Get the native C pointer from the gotk4 WebView
45	parentObj := glib.BaseObject(parentView)
46	if parentObj == nil {
47		log.Printf("[webkit] NewBareRelatedWebView: failed to get parent object, creating unrelated WebView")
48		return webkit.NewWebView()
49	}
50	parentNative := (*C.WebKitWebView)(unsafe.Pointer(parentObj.Native()))
51	if parentNative == nil {
52		log.Printf("[webkit] NewBareRelatedWebView: parent native pointer is nil, creating unrelated WebView")
53		return webkit.NewWebView()
54	}
55
56	log.Printf("[webkit] Creating bare WebView with related-view property (parent=%p)", parentNative)
57
58	// Create related WebView using CGO helper with g_object_new
59	log.Printf("[webkit] Step 3: About to call C.create_related_web_view")
60	webViewNative := C.create_related_web_view(parentNative)
61	log.Printf("[webkit] Step 4: C.create_related_web_view returned: %p", webViewNative)
62
63	if webViewNative == nil {
64		log.Printf("[webkit] NewBareRelatedWebView: C.create_related_web_view returned nil")
65		return nil
66	}
67
68	// Wrap the C object in a coreglib.Object
69	// This takes ownership of the floating reference
70	log.Printf("[webkit] Step 5: About to call coreglib.Take")
71	obj := coreglib.Take(unsafe.Pointer(webViewNative))
72	log.Printf("[webkit] Step 6: coreglib.Take succeeded, obj=%p", obj)
73
74	// Manually construct the WebView struct hierarchy
75	// WebView -> WebViewBase -> gtk.Widget -> coreglib.InitiallyUnowned -> coreglib.Object
76	//
77	// Since we cannot call the internal wrapWebView() function, we must
78	// manually construct the full struct hierarchy using the same pattern
79	// that gotk4 uses internally.
80
81	log.Printf("[webkit] Step 7: About to create gtk.Widget base")
82	// Create the gtk.Widget base
83	widget := gtk.Widget{
84		InitiallyUnowned: coreglib.InitiallyUnowned{
85			Object: obj,
86		},
87		Object: obj,
88		Accessible: gtk.Accessible{
89			Object: obj,
90		},
91		Buildable: gtk.Buildable{
92			Object: obj,
93		},
94		ConstraintTarget: gtk.ConstraintTarget{
95			Object: obj,
96		},
97	}
98	log.Printf("[webkit] Step 8: Created gtk.Widget base")
99
100	// Create the WebViewBase
101	log.Printf("[webkit] Step 9: About to create WebViewBase")
102	webViewBase := webkit.WebViewBase{
103		Widget: widget,
104	}
105	log.Printf("[webkit] Step 10: Created WebViewBase")
106
107	// Create the final WebView
108	log.Printf("[webkit] Step 11: About to create final WebView")
109	relatedView := &webkit.WebView{
110		WebViewBase: webViewBase,
111	}
112	log.Printf("[webkit] Step 12: Created final WebView: %p", relatedView)
113
114	// Ensure parentView is kept alive until after the CGO call completes
115	runtime.KeepAlive(parentView)
116
117	log.Printf("[webkit] Created bare related WebView (parent=%p)", parentNative)
118	return relatedView
119}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close