session.go RawHistoryFolder

1package launcher
2
3import (
4	"context"
5	"net"
6	"os/exec"
7	"time"
8
9	"github.com/bnema/zerowrap"
10)
11
12// sessionVars are the displays D-Bus and systemd user services (portals,
13// notification daemons) need to reach the session.
14var sessionVars = []string{"WAYLAND_DISPLAY", "DISPLAY", "XDG_CURRENT_DESKTOP", "XDG_SESSION_TYPE"}
15
16// portalUnits are the desktop portal and its backends. They read the
17// session variables once, at start: a portal started without them (before
18// the export, or after the last session ended) never serves this session.
19// Portals are per user, like the exported variables: another graphical
20// session of the same user running at once is not supported.
21const portalUnits = "xdg-desktop-portal*.service"
22
23// ExportSession shares the session's displays with D-Bus and systemd user
24// services, and waits for it: clients started next may activate them. Portals
25// already running restart to read them; the restart does not block, since a
26// backend may connect to the display before it serves.
27func ExportSession(ctx context.Context, env []string, log zerowrap.Logger) {
28	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
29	defer cancel()
30	if !runSessionCommand(ctx, env, log, append([]string{"--systemd"}, sessionVars...), "session exported") {
31		return
32	}
33	runSystemctl(ctx, env, log, []string{"--no-block", "try-restart", portalUnits}, "portal restart failed")
34}
35
36// UnexportSession withdraws the displays from the systemd user manager on
37// exit, so services started after logout do not reach a dead display, and
38// stops the portals that still hold them.
39func UnexportSession(env []string, log zerowrap.Logger) {
40	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
41	defer cancel()
42	runSystemctl(ctx, env, log, append([]string{"unset-environment"}, sessionVars...), "session unexport failed")
43	runSystemctl(ctx, env, log, []string{"--no-block", "stop", portalUnits}, "portal stop failed")
44}
45
46// runSystemctl runs systemctl --user with args; a missing systemctl is skipped.
47func runSystemctl(ctx context.Context, env []string, log zerowrap.Logger, args []string, failed string) {
48	path, err := childLookPath("systemctl", env)
49	if err != nil {
50		return
51	}
52	cmd := exec.CommandContext(ctx, path, append([]string{"--user"}, args...)...)
53	cmd.Env = env
54	if err := cmd.Run(); err != nil {
55		log.Warn().Err(err).Strs("args", args).Msg(failed)
56	}
57}
58
59// runSessionCommand runs dbus-update-activation-environment and reports
60// whether it succeeded.
61func runSessionCommand(ctx context.Context, env []string, log zerowrap.Logger, args []string, done string) bool {
62	path, err := childLookPath("dbus-update-activation-environment", env)
63	if err != nil {
64		log.Warn().Err(err).Msg("session export skipped: dbus-update-activation-environment not found")
65		return false
66	}
67	cmd := exec.CommandContext(ctx, path, args...)
68	cmd.Env = env
69	if err := cmd.Run(); err != nil {
70		log.Warn().Err(err).Msg("session export failed")
71		return false
72	}
73	log.Info().Strs("vars", sessionVars).Msg(done)
74	return true
75}
76
77// NotifyReady tells the systemd user manager that the compositor is ready.
78func NotifyReady(socket string, log zerowrap.Logger) {
79	if socket == "" {
80		return
81	}
82	conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: socket, Net: "unixgram"})
83	if err != nil {
84		log.Warn().Err(err).Msg("session readiness notification failed")
85		return
86	}
87	defer conn.Close()
88	if _, err := conn.Write([]byte("READY=1")); err != nil {
89		log.Warn().Err(err).Msg("session readiness notification failed")
90		return
91	}
92	log.Info().Msg("session ready")
93}

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 23

Tags 10

↑↓ moveenter openesc close