A minimum width of 1600 px was left in from a debugging session in which the headless X server seemed to ignore the requested window size; it made the window unusable on smaller screens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
260 lines
11 KiB
Plaintext
260 lines
11 KiB
Plaintext
// The main window: picks the desktop or the mobile shell and puts the
|
|
// current page's screens into it. See docs/ui.md for the structure and how
|
|
// to add a screen.
|
|
|
|
import "assets/fonts/Inter-Regular.ttf";
|
|
import "assets/fonts/Inter-Medium.ttf";
|
|
import "assets/fonts/Inter-SemiBold.ttf";
|
|
import "assets/fonts/Inter-Bold.ttf";
|
|
import "assets/fonts/Inter-Italic.ttf";
|
|
|
|
import { Palette } from "std-widgets.slint";
|
|
import { Theme } from "theme.slint";
|
|
import { Icons } from "icons.slint";
|
|
import { Bridge } from "bridge.slint";
|
|
import { Nav, Page, MobileTab, SettingsSection } from "nav.slint";
|
|
import { EmojiPicker, Toast, ResizeHandle } from "components/index.slint";
|
|
import { DesktopShell, Sidebar } from "shells/desktop.slint";
|
|
import { MobileShell } from "shells/mobile.slint";
|
|
import { Panel } from "shells/common.slint";
|
|
import { ServerHeader, ConnectActions, ChannelTree } from "screens/channels.slint";
|
|
import { ChatView } from "screens/chat.slint";
|
|
import { PinsDrawer, TopicsDrawer, TopicDialog } from "screens/drawers.slint";
|
|
import { MemberCardPopup, VoiceGrid } from "screens/members.slint";
|
|
import { StreamsPanel, StreamViewer } from "screens/streams.slint";
|
|
import { SettingsNav, SettingsPage } from "screens/settings.slint";
|
|
import { HomeNav, HomePage } from "screens/home.slint";
|
|
import { MobileServers, ActivityPage, YouPage } from "screens/mobile.slint";
|
|
import { BookmarkDialog, ShareDialog, ClientAudioDialog, AboutDialog } from "screens/dialogs.slint";
|
|
|
|
// Rust reaches the globals and structs through this file.
|
|
export * from "bridge.slint";
|
|
export { Theme } from "theme.slint";
|
|
export { Nav, Page, MobileTab, SettingsSection } from "nav.slint";
|
|
|
|
export component MainWindow inherits Window {
|
|
title: Bridge.app-name;
|
|
preferred-width: 1280px;
|
|
preferred-height: 820px;
|
|
min-width: 360px;
|
|
min-height: 480px;
|
|
background: Theme.bg-app;
|
|
default-font-family: "Inter";
|
|
default-font-size: Theme.font-body;
|
|
|
|
// Set from change handlers: a binding on `width` would loop through the
|
|
// layout.
|
|
property <length> breakpoint: Nav.narrow-breakpoint;
|
|
changed width => { Nav.narrow = self.width < Nav.narrow-breakpoint; }
|
|
changed breakpoint => { Nav.narrow = self.width < Nav.narrow-breakpoint; }
|
|
init => {
|
|
Nav.narrow = self.width < Nav.narrow-breakpoint;
|
|
Theme.system-dark = Palette.color-scheme != ColorScheme.light;
|
|
}
|
|
// Android: the space under the on-screen keyboard (the window is not
|
|
// resized for it). Zero on desktop.
|
|
property <length> keyboard-inset: 0;
|
|
changed virtual-keyboard-size => {
|
|
keyboard-inset = self.virtual-keyboard-size.height > 0 ? self.height - self.virtual-keyboard-position.y : 0;
|
|
}
|
|
|
|
// The viewer takes the whole window in full screen and when popped out.
|
|
property <bool> chrome: !(Bridge.viewer-open && (Bridge.viewer-fullscreen || Bridge.viewer-popped));
|
|
|
|
// The standard widgets follow the theme. In "system" mode the palette
|
|
// is left alone (it tracks the system) unless an explicit mode was
|
|
// set before; then the scheme seen at start is used.
|
|
property <string> theme-mode: Theme.mode;
|
|
property <bool> scheme-set;
|
|
changed theme-mode => { apply-color-scheme(); }
|
|
function apply-color-scheme() {
|
|
if Theme.mode == "dark" {
|
|
Palette.color-scheme = ColorScheme.dark;
|
|
} else if Theme.mode == "light" {
|
|
Palette.color-scheme = ColorScheme.light;
|
|
} else if Theme.mode == "system" && scheme-set {
|
|
Palette.color-scheme = Theme.system-dark ? ColorScheme.dark : ColorScheme.light;
|
|
}
|
|
scheme-set = scheme-set || Theme.mode == "dark" || Theme.mode == "light";
|
|
}
|
|
|
|
// Status messages show as a toast.
|
|
property <string> status: Bridge.status-text;
|
|
changed status => { toast.shown = status != ""; }
|
|
|
|
// Dragging the members panel stores its width (`ui.members_width`).
|
|
property <length> panel-width: Nav.right-panel-width;
|
|
changed panel-width => { Bridge.panel-resized(panel-width / 1px); }
|
|
|
|
// Compatibility with callers from before the navigation global.
|
|
public function open-share-dialog() {
|
|
Nav.open-share();
|
|
}
|
|
|
|
keys := FocusScope {
|
|
// Ctrl+K: search.
|
|
capture-key-pressed(event) => {
|
|
if event.modifiers.control && (event.text == "k" || event.text == "K") && !Nav.narrow && root.chrome {
|
|
Nav.search-requests += 1;
|
|
return accept;
|
|
}
|
|
reject
|
|
}
|
|
VerticalLayout {
|
|
// Android draws the window under the status and navigation bars.
|
|
padding-top: root.safe-area-insets.top;
|
|
padding-left: root.safe-area-insets.left;
|
|
padding-right: root.safe-area-insets.right;
|
|
padding-bottom: max(root.safe-area-insets.bottom, root.keyboard-inset);
|
|
|
|
if !root.chrome: StreamViewer { }
|
|
|
|
if !Nav.narrow && root.chrome: DesktopShell {
|
|
context: Nav.page == Page.settings ? @tr("Settings") : "";
|
|
if Nav.page == Page.home: Sidebar {
|
|
HomeNav { }
|
|
Rectangle { vertical-stretch: 1; }
|
|
}
|
|
if Nav.page == Page.home: Panel {
|
|
horizontal-stretch: 1;
|
|
HomePage { }
|
|
}
|
|
if Nav.page == Page.server: Sidebar {
|
|
ServerHeader { }
|
|
if !Bridge.voice-connected && !Bridge.voice-connecting: ConnectActions { }
|
|
ChannelTree {
|
|
vertical-stretch: 1;
|
|
}
|
|
}
|
|
if Nav.page == Page.server: Panel {
|
|
horizontal-stretch: 1;
|
|
if Bridge.viewer-open: StreamViewer { }
|
|
if !Bridge.viewer-open && Nav.voice-grid && Bridge.voice-connected: VoiceGrid { }
|
|
if !Bridge.viewer-open && !(Nav.voice-grid && Bridge.voice-connected): ChatView { }
|
|
// The pins and the topics slide in over the chat.
|
|
if !Bridge.viewer-open && (Nav.pins-open || Nav.topics-open): Rectangle {
|
|
x: parent.width - self.width - 12px;
|
|
y: 12px;
|
|
width: min(parent.width - 24px, 400px);
|
|
height: parent.height - 24px;
|
|
if Nav.pins-open: PinsDrawer {
|
|
width: parent.width;
|
|
height: parent.height;
|
|
}
|
|
if Nav.topics-open: TopicsDrawer {
|
|
width: parent.width;
|
|
height: parent.height;
|
|
}
|
|
}
|
|
}
|
|
if Nav.page == Page.server && Nav.right-panel-open: ResizeHandle {
|
|
size <=> Nav.right-panel-width;
|
|
minimum: Theme.right-panel-min;
|
|
maximum: Theme.right-panel-max;
|
|
left: false;
|
|
}
|
|
if Nav.page == Page.server && Nav.right-panel-open: Panel {
|
|
width: Nav.right-panel-width;
|
|
horizontal-stretch: 0;
|
|
StreamsPanel { }
|
|
}
|
|
if Nav.page == Page.settings: Sidebar {
|
|
SettingsNav { }
|
|
Rectangle { vertical-stretch: 1; }
|
|
}
|
|
if Nav.page == Page.settings: Panel {
|
|
horizontal-stretch: 1;
|
|
SettingsPage { }
|
|
}
|
|
}
|
|
|
|
if Nav.narrow && root.chrome: MobileShell {
|
|
title: Nav.page == Page.settings ? @tr("Settings")
|
|
: Nav.mobile-tab == MobileTab.home ? Bridge.app-name
|
|
: Nav.mobile-tab == MobileTab.you ? @tr("You")
|
|
: Nav.mobile-tab == MobileTab.activity ? @tr("Activity")
|
|
: Bridge.server-title;
|
|
subtitle: Nav.page == Page.settings ? "" : Nav.mobile-tab == MobileTab.chat && Bridge.current-tab >= 0 && Bridge.current-tab < Bridge.tabs.length ? Bridge.tabs[Bridge.current-tab].title : Nav.mobile-tab == MobileTab.servers ? Bridge.server-stats : "";
|
|
back: Nav.page == Page.settings;
|
|
unread: Bridge.unread-total;
|
|
go-back => { Nav.show(Page.server); }
|
|
if Nav.page == Page.settings: SettingsPage {
|
|
compact: true;
|
|
}
|
|
if Nav.page != Page.settings && (Nav.page == Page.home || Nav.mobile-tab == MobileTab.home): HomePage { }
|
|
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.servers: MobileServers { }
|
|
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.chat && Bridge.viewer-open: StreamViewer { }
|
|
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.chat && !Bridge.viewer-open: ChatView {
|
|
header: false;
|
|
}
|
|
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.activity: ActivityPage { }
|
|
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.you: YouPage { }
|
|
}
|
|
}
|
|
}
|
|
|
|
toast := Toast {
|
|
x: (parent.width - self.width) / 2;
|
|
y: parent.height - self.height - (Nav.narrow ? 140px : 96px);
|
|
text: Bridge.status-text;
|
|
}
|
|
|
|
// The member card of the members panel, over everything.
|
|
if Bridge.member-card.open: Rectangle {
|
|
TouchArea {
|
|
clicked => { Bridge.open-member(-1); }
|
|
}
|
|
MemberCardPopup {
|
|
x: max(8px, parent.width - self.width - (Nav.narrow ? 8px : Nav.right-panel-open && Nav.page == Page.server ? Nav.right-panel-width + 24px : 32px));
|
|
y: max(8px, min(parent.height - self.height - 8px, 120px));
|
|
}
|
|
}
|
|
|
|
if Nav.emoji-open: Rectangle {
|
|
// Clicks outside the picker close it.
|
|
TouchArea {
|
|
clicked => { Nav.emoji-open = false; }
|
|
}
|
|
EmojiPicker {
|
|
x: max(8px, parent.width - self.width - (Nav.narrow ? 8px : Nav.right-panel-open && Nav.page == Page.server ? Nav.right-panel-width + 40px : 32px));
|
|
y: max(8px, parent.height - self.height - (Nav.narrow ? 150px : 90px));
|
|
// Picked for a message: a reaction; otherwise the composer.
|
|
picked(cell) => {
|
|
if Nav.react-key != 0 {
|
|
Bridge.react(Nav.react-key, cell.text);
|
|
Nav.react-key = 0;
|
|
Nav.emoji-open = false;
|
|
} else {
|
|
Nav.draft = Nav.draft + cell.text;
|
|
}
|
|
}
|
|
close => {
|
|
Nav.react-key = 0;
|
|
Nav.emoji-open = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if Nav.topic-form-open: TopicDialog {
|
|
done => { Nav.topic-form-open = false; }
|
|
}
|
|
|
|
if Nav.bookmark-open: BookmarkDialog {
|
|
form <=> Nav.bookmark-form;
|
|
done => { Nav.bookmark-open = false; }
|
|
}
|
|
|
|
if Nav.share-open: ShareDialog {
|
|
form <=> Nav.share-form;
|
|
done => { Nav.share-open = false; }
|
|
}
|
|
|
|
if Nav.client-open: ClientAudioDialog {
|
|
done => { Nav.client-open = false; }
|
|
}
|
|
|
|
if Nav.about-open: AboutDialog {
|
|
done => { Nav.about-open = false; }
|
|
}
|
|
}
|