Settings > Apps: choose the default browser, email, files, terminal, editor, viewers and players
CI / test (push) Failing after 45s
CI / test (push) Failing after 45s
- A sixth Settings tab, Apps (key 6, SettingsTab::Apps; the popup is 390 px wide for it): Web
browser, Email, File manager, Terminal, Text editor, Image viewer, Video player, Music player,
PDF and documents, Archive manager. Each row shows the current default with its real icon (the
icon-theme lookup the task manager uses; a letter tile when there is none). Click a row to list
the installed apps that can take it, click one to make it the default. A chosen app that has
been uninstalled since is named in red under its row ("gthumb is not installed any more").
- Installed apps come from the .desktop files in the XDG data dirs (and flatpak's exports), with
MimeType= and Categories= (desktop_entry_keys, now shared with the launcher's parse_desktop).
A kind lists the shown apps that handle one of its MIME types; the terminal lists
TerminalEmulator apps; browsers are only offered as browsers.
- Reading follows the mimeapps.list spec: $XDG_CONFIG_HOME/[chandra-]mimeapps.list, then
$XDG_CONFIG_DIRS (/etc/xdg), then $XDG_DATA_HOME and $XDG_DATA_DIRS applications/; the first
installed [Default Applications] entry wins, else [Added Associations], else mimeinfo.cache
(minus [Removed Associations]), else the first installed app that handles the type. A hidden
(NoDisplay) default still counts and its name is shown.
- Setting writes [Default Applications] in ~/.config/mimeapps.list for each of the kind's MIME
types the app handles (always the main one: http/https/text/html for browsers, mailto,
inode/directory, text/plain, image/png..., video/mp4..., audio/mpeg..., application/pdf...,
application/zip...), as xdg-mime default / xdg-settings do, without running them. Every other
section, entry, comment and blank line is kept; the app leaves those types' [Removed
Associations]; a chandra-mimeapps.list that already names one of those types is updated too.
- The terminal has no MIME type: state.edn :terminal "kitty" (desktop id), also written first in
~/.config/xdg-terminals.list (xdg-terminal-exec). Terminal=true apps from the launcher (and
session restore) now start in it (foot -e, kgx/gnome-terminal/ptyxis --, kitty <cmd>, wezterm
start --) instead of always foot; with no choice: xdg-terminals.list, then foot, then any
installed terminal. Terminal apps are listed when any terminal emulator is installed, not only
foot.
- New `default-apps` capability (categories, apps, set-default, refresh): host tables 11 (sss:
name current missing) and 12 (issii: category id name icon current), request 19 (category *
1000 + app, -1 rescans) in the wasmer/wasmtime stub, host-wasm and the MoonBit wasmhost
(chandra:host/plasmoids default-app(s32)). Nothing is scanned until the tab opens (refresh).
- Tests with a temporary XDG tree: categories and current defaults (user file, system file,
Added Associations, mimeinfo.cache, missing apps, hidden defaults), writing that keeps other
entries, desktop-specific files, the terminal list and commands, the Apps tab end to end, and
the :terminal round trip through state.edn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgywj7RPmFdFhpzGZj
This commit is contained in:
26 files changed
+1605
-73
No files matched your search
@@ -7,6 +7,7 @@ import {
|
||||
"chandra/desktop/interface/chandra/desktop/power" @power,
|
||||
"chandra/desktop/interface/chandra/desktop/system" @system,
|
||||
"chandra/desktop/interface/chandra/desktop/shortcuts" @shortcuts,
|
||||
"chandra/desktop/interface/chandra/desktop/default-apps" @default_apps,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
|
||||
|
||||
@@ -18,17 +18,22 @@
|
||||
/// Enter) and press the new keys: the compositor takes that combo for it (Escape cancels,
|
||||
/// Backspace unbinds; clicking the row again also cancels). "Reset" at the end of a changed
|
||||
/// row, or Backspace on the highlighted row, puts it back; "Reset all to defaults" does every
|
||||
/// one. Combos two shortcuts share are shown in red and listed under the shortcuts.
|
||||
/// one. Combos two shortcuts share are shown in red and listed under the shortcuts;
|
||||
/// - Apps: the default app for each kind of thing (`default-apps`): web browser, email, file
|
||||
/// manager, terminal, text editor, image viewer, video and music player, PDF and documents,
|
||||
/// archives. Each row shows the current one with its icon; click it to list the installed apps
|
||||
/// that can take its place, click one of those to make it the default (the list folds up
|
||||
/// again). A chosen app that has since been uninstalled is named in red under its row.
|
||||
///
|
||||
/// Clicking a row acts at once and the popup stays open; a row in the panel list only acts through
|
||||
/// its buttons, so a stray click doesn't remove anything. Up/Down move the highlight, Left/Right
|
||||
/// (or 1-5) switch tabs, Enter or Space acts on the highlighted row, Backspace or Delete removes
|
||||
/// (or 1-6) switch tabs, Enter or Space acts on the highlighted row, Backspace or Delete removes
|
||||
/// the highlighted panel module (or resets the highlighted shortcut) and PageUp/PageDown move it,
|
||||
/// Escape or a click elsewhere closes. The shell remembers settings, wallpaper and shortcuts in
|
||||
/// state.edn, the panel in panel.edn.
|
||||
|
||||
///| Popup geometry: the tab bar, then a column of rows, with a margin around them.
|
||||
let popup_w : Int = 360
|
||||
let popup_w : Int = 390
|
||||
|
||||
///|
|
||||
let margin : Int = 6
|
||||
@@ -50,7 +55,13 @@ let switch_w : Int = 34
|
||||
let switch_h : Int = 18
|
||||
|
||||
///|
|
||||
let tab_names : Array[String] = ["Session", "Desktop", "Panel", "Power", "Shortcuts"]
|
||||
let tab_names : Array[String] = ["Session", "Desktop", "Panel", "Power", "Shortcuts", "Apps"]
|
||||
|
||||
///| The Apps tab's category whose choices are listed (-1: none).
|
||||
let expanded : Ref[Int] = { val: -1 }
|
||||
|
||||
///| Size of the app icons on the Apps tab.
|
||||
let icon_size : Int = 18
|
||||
|
||||
///| A popup row.
|
||||
enum Row {
|
||||
@@ -76,6 +87,11 @@ enum Row {
|
||||
Shortcut(Int, @shortcuts.Shortcut)
|
||||
/// "Reset all to defaults" (the shortcuts).
|
||||
ResetShortcuts
|
||||
/// A kind of default app: its index, name, the current default among its choices (None: not
|
||||
/// one of them), the current default's name ("" for none) and how many apps can take it.
|
||||
AppKind(Int, String, @default_apps.AppChoice?, String, Int)
|
||||
/// One of a kind's apps, listed under it while it is expanded: the kind, its index there, the app.
|
||||
AppOption(Int, Int, @default_apps.AppChoice)
|
||||
}
|
||||
|
||||
///| Width of the "Reset" button at the end of a changed shortcut's row.
|
||||
@@ -196,6 +212,23 @@ fn rows() -> Array[Row] {
|
||||
rs.push(PowerNow(2, "Restart"))
|
||||
rs.push(PowerNow(1, "Power off"))
|
||||
}
|
||||
5 => {
|
||||
let cats = @default_apps.categories()
|
||||
let apps = @default_apps.apps()
|
||||
for c = 0; c < cats.length(); c = c + 1 {
|
||||
let mine = apps.filter(a => a.category.reinterpret_as_int() == c)
|
||||
let cur = mine.iter().find_first(a => a.current)
|
||||
rs.push(AppKind(c, cats[c].name, cur, cats[c].current, mine.length()))
|
||||
if cats[c].missing != "" {
|
||||
rs.push(Info("! " + cats[c].missing + " is not installed any more"))
|
||||
}
|
||||
if expanded.val == c {
|
||||
for k, a in mine {
|
||||
rs.push(AppOption(c, k, a))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
4 => {
|
||||
rs.push(Heading("Click one, then press its new keys"))
|
||||
let list = @shortcuts.shortcuts()
|
||||
@@ -363,6 +396,11 @@ let hover_btn : Ref[Int] = { val: -1 }
|
||||
///|
|
||||
fn set_tab(i : Int) -> Unit {
|
||||
cancel_capture()
|
||||
expanded.val = -1
|
||||
if i == 5 && tab.val != 5 {
|
||||
// Another program may have changed a default since the tab was last open.
|
||||
@default_apps.refresh()
|
||||
}
|
||||
tab.val = i
|
||||
armed.val = -1
|
||||
hover.val = first_active(rows())
|
||||
@@ -422,6 +460,11 @@ fn act(rs : Array[Row], i : Int, btn~ : Int = -1, x~ : Int = 0) -> Unit {
|
||||
@shortcuts.capture(k.reinterpret_as_uint())
|
||||
}
|
||||
ResetShortcuts => @shortcuts.reset_all()
|
||||
AppKind(c, _, _, _, n) => expanded.val = if expanded.val == c || n == 0 { -1 } else { c }
|
||||
AppOption(c, k, _) => {
|
||||
@default_apps.set_default(c.reinterpret_as_uint(), k.reinterpret_as_uint())
|
||||
expanded.val = -1
|
||||
}
|
||||
Setting(k, _) => {
|
||||
let idx = k.reinterpret_as_uint()
|
||||
@settings.set_setting(idx, !@settings.is_on(idx))
|
||||
@@ -440,6 +483,28 @@ fn act(rs : Array[Row], i : Int, btn~ : Int = -1, x~ : Int = 0) -> Unit {
|
||||
}
|
||||
}
|
||||
|
||||
///| An app's icon with its left edge at `x`, centred on `mid`: the host's image, or a rounded
|
||||
/// square with the name's first letter.
|
||||
fn app_icon_ops(
|
||||
x : Int,
|
||||
mid : Int,
|
||||
a : @default_apps.AppChoice,
|
||||
fg : @types.Color,
|
||||
) -> Array[@types.DrawOp] {
|
||||
let r = @ui.rect(x, mid - icon_size / 2, icon_size, icon_size)
|
||||
if a.icon != 0U {
|
||||
return [Image({ rect: r, image: a.icon })]
|
||||
}
|
||||
let glyph = match a.name.to_array().get(0) {
|
||||
Some(ch) => ch.to_string().to_upper()
|
||||
None => "?"
|
||||
}
|
||||
[
|
||||
@ui.stroke_rect(r, @ui.with_alpha(fg, 120), width=1, radius=4),
|
||||
@ui.text(x + icon_size / 2, mid, glyph, 10, fg, align=CENTER, bold=true),
|
||||
]
|
||||
}
|
||||
|
||||
///| Move the highlight by `step` rows, skipping headings; stays put at either end.
|
||||
fn move_hover(step : Int) -> Unit {
|
||||
let rs = rows()
|
||||
@@ -678,6 +743,50 @@ pub fn popup() -> PopupSurface? {
|
||||
}
|
||||
}
|
||||
ResetShortcuts => ops.push(@ui.text(margin + 10, mid, "Reset all to defaults", fs - 1, list_fg, bold=true))
|
||||
AppKind(c, name, cur, cur_name, n) => {
|
||||
let open = expanded.val == c
|
||||
ops.push(@ui.text(margin + 10, mid, name, fs - 1, list_fg, bold=open))
|
||||
// The current app at the right, then a chevron (down while its list is open).
|
||||
let cx = w - margin - 14
|
||||
let cfg = if hot { list_fg } else { p.foreground_muted }
|
||||
if n > 0 {
|
||||
if open {
|
||||
ops.push(@ui.line(cx - 4, mid - 2, cx, mid + 2, cfg, width=2))
|
||||
ops.push(@ui.line(cx, mid + 2, cx + 4, mid - 2, cfg, width=2))
|
||||
} else {
|
||||
ops.push(@ui.line(cx - 2, mid - 4, cx + 2, mid, cfg, width=2))
|
||||
ops.push(@ui.line(cx + 2, mid, cx - 2, mid + 4, cfg, width=2))
|
||||
}
|
||||
}
|
||||
let right = cx - 12
|
||||
match cur {
|
||||
Some(a) => {
|
||||
let label = a.name
|
||||
ops.push(@ui.text(right, mid, label, fs - 2, list_fg, align=RIGHT))
|
||||
let tw = @ui.text_width(label, fs - 2)
|
||||
ops.append(app_icon_ops(right - tw - 6 - icon_size, mid, a, list_fg))
|
||||
}
|
||||
None => {
|
||||
let label = if cur_name != "" {
|
||||
cur_name
|
||||
} else if n == 0 {
|
||||
"None installed"
|
||||
} else {
|
||||
"Not set"
|
||||
}
|
||||
ops.push(@ui.text(right, mid, label, fs - 2, if hot { list_fg } else { p.foreground_muted }, align=RIGHT))
|
||||
}
|
||||
}
|
||||
}
|
||||
AppOption(_, _, a) => {
|
||||
let x = margin + 26
|
||||
if a.current {
|
||||
ops.push(@ui.line(margin + 10, mid, margin + 13, mid + 4, list_fg, width=2))
|
||||
ops.push(@ui.line(margin + 13, mid + 4, margin + 20, mid - 4, list_fg, width=2))
|
||||
}
|
||||
ops.append(app_icon_ops(x, mid, a, list_fg))
|
||||
ops.push(@ui.text(x + icon_size + 8, mid, a.name, fs - 1, list_fg, bold=a.current))
|
||||
}
|
||||
}
|
||||
}
|
||||
Some({ size: { w: w.reinterpret_as_uint(), h: h.reinterpret_as_uint() }, ops })
|
||||
@@ -802,7 +911,7 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
|
||||
} else if k == "ArrowLeft" || k == "Left" {
|
||||
set_tab((tab.val + tab_names.length() - 1) % tab_names.length())
|
||||
true
|
||||
} else if k == "1" || k == "2" || k == "3" || k == "4" || k == "5" {
|
||||
} else if k == "1" || k == "2" || k == "3" || k == "4" || k == "5" || k == "6" {
|
||||
set_tab(k[0].to_int() - '1'.to_int())
|
||||
true
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user