v0.8.0-alpha.2 bcc8fd4

main_windows.go RawHistoryFolder

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2024 The Ebitengine Authors
3
4package main
5
6import (
7	"runtime"
8	"unsafe"
9
10	"golang.org/x/sys/windows"
11
12	"github.com/ebitengine/purego"
13)
14
15const (
16	WS_OVERLAPPEDWINDOW = 0x00000000 | 0x00C00000 | 0x00080000 | 0x00040000 | 0x00020000 | 0x00010000
17	CW_USEDEFAULT       = ^0x7fffffff
18	SW_SHOW             = 5
19	WM_DESTROY          = 2
20)
21
22type (
23	ATOM      uint16
24	HANDLE    uintptr
25	HINSTANCE HANDLE
26	HICON     HANDLE
27	HCURSOR   HANDLE
28	HBRUSH    HANDLE
29	HWND      HANDLE
30	HMENU     HANDLE
31)
32
33type WNDCLASSEX struct {
34	Size       uint32
35	Style      uint32
36	WndProc    uintptr
37	ClsExtra   int32
38	WndExtra   int32
39	Instance   HINSTANCE
40	Icon       HICON
41	Cursor     HCURSOR
42	Background HBRUSH
43	MenuName   *uint16
44	ClassName  *uint16
45	IconSm     HICON
46}
47
48type RECT struct {
49	Left, Top, Right, Bottom int32
50}
51
52type POINT struct {
53	X, Y int32
54}
55
56type MSG struct {
57	Hwnd    HWND
58	Message uint32
59	WParam  uintptr
60	LParam  uintptr
61	Time    uint32
62	Pt      POINT
63}
64
65var (
66	GetModuleHandle func(modulename *uint16) HINSTANCE
67	RegisterClassEx func(w *WNDCLASSEX) ATOM
68	CreateWindowEx  func(exStyle uint, className, windowName *uint16,
69		style uint, x, y, width, height int, parent HWND, menu HMENU,
70		instance HINSTANCE, param unsafe.Pointer) HWND
71	AdjustWindowRect func(rect *RECT, style uint, menu bool) bool
72	ShowWindow       func(hwnd HWND, cmdshow int) bool
73	GetMessage       func(msg *MSG, hwnd HWND, msgFilterMin, msgFilterMax uint32) int
74	TranslateMessage func(msg *MSG) bool
75	DispatchMessage  func(msg *MSG) uintptr
76	DefWindowProc    func(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr
77	PostQuitMessage  func(exitCode int)
78)
79
80func init() {
81	kernel32 := windows.NewLazySystemDLL("kernel32.dll").Handle()
82	purego.RegisterLibFunc(&GetModuleHandle, kernel32, "GetModuleHandleW")
83
84	user32 := windows.NewLazySystemDLL("user32.dll").Handle()
85	purego.RegisterLibFunc(&RegisterClassEx, user32, "RegisterClassExW")
86	purego.RegisterLibFunc(&CreateWindowEx, user32, "CreateWindowExW")
87	purego.RegisterLibFunc(&AdjustWindowRect, user32, "AdjustWindowRect")
88	purego.RegisterLibFunc(&ShowWindow, user32, "ShowWindow")
89	purego.RegisterLibFunc(&GetMessage, user32, "GetMessageW")
90	purego.RegisterLibFunc(&TranslateMessage, user32, "TranslateMessage")
91	purego.RegisterLibFunc(&DispatchMessage, user32, "DispatchMessageW")
92	purego.RegisterLibFunc(&DefWindowProc, user32, "DefWindowProcW")
93	purego.RegisterLibFunc(&PostQuitMessage, user32, "PostQuitMessage")
94
95	runtime.LockOSThread()
96}
97
98func main() {
99	className := windows.StringToUTF16Ptr("Sample Window Class")
100	inst := GetModuleHandle(className)
101
102	wc := WNDCLASSEX{
103		Size:      uint32(unsafe.Sizeof(WNDCLASSEX{})),
104		WndProc:   windows.NewCallback(wndProc),
105		Instance:  inst,
106		ClassName: className,
107	}
108
109	RegisterClassEx(&wc)
110
111	wr := RECT{
112		Left:   0,
113		Top:    0,
114		Right:  320,
115		Bottom: 240,
116	}
117	AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, false)
118	hwnd := CreateWindowEx(
119		0, className,
120		windows.StringToUTF16Ptr("My Title"),
121		WS_OVERLAPPEDWINDOW,
122		CW_USEDEFAULT, CW_USEDEFAULT, int(wr.Right-wr.Left), int(wr.Bottom-wr.Top),
123		0, 0, inst, nil,
124	)
125	if hwnd == 0 {
126		panic(windows.GetLastError())
127	}
128
129	ShowWindow(hwnd, SW_SHOW)
130
131	var msg MSG
132	for GetMessage(&msg, 0, 0, 0) != 0 {
133		TranslateMessage(&msg)
134		DispatchMessage(&msg)
135	}
136}
137
138func wndProc(hwnd HWND, msg uint32, wparam, lparam uintptr) uintptr {
139	switch msg {
140	case WM_DESTROY:
141		PostQuitMessage(0)
142	}
143	return DefWindowProc(hwnd, msg, wparam, lparam)
144}

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 1

Tags 102

↑↓ moveenter openesc close