v0.12.0 d035193

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

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