Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(linux): keep window controls clickable and Jan visible with left button layout

Akarshan Biswas3f9aa4820dc0
diff --git a/web-app/src/components/WindowControls.tsx b/web-app/src/components/WindowControls.tsx
index be3ba03ce..f061cbe96 100644
--- a/web-app/src/components/WindowControls.tsx
+++ b/web-app/src/components/WindowControls.tsx
@@ -1,26 +1,25 @@
-import { useCallback, useEffect, useState } from 'react'
+import { useCallback, useEffect } from 'react'
import { Minus, Square, X } from 'lucide-react'
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
import { invoke } from '@tauri-apps/api/core'
import { Button } from '@/components/ui/button'
-
-type ButtonId = 'minimize' | 'maximize' | 'close'
-type TitlebarLayout = { left: ButtonId[]; right: ButtonId[] }
-
-const DEFAULT_LAYOUT: TitlebarLayout = {
- left: [],
- right: ['minimize', 'maximize', 'close'],
-}
+import {
+ useTitlebarLayout,
+ type ButtonId,
+ type TitlebarLayout,
+ DEFAULT_TITLEBAR_LAYOUT,
+} from '@/stores/titlebar-layout-store'
export const WindowControls = () => {
const appWindow = getCurrentWebviewWindow()
- const [layout, setLayout] = useState<TitlebarLayout>(DEFAULT_LAYOUT)
+ const layout = useTitlebarLayout((s) => s.layout)
+ const setLayout = useTitlebarLayout((s) => s.setLayout)
const refresh = useCallback(() => {
invoke<TitlebarLayout>('get_titlebar_layout')
.then((l) => setLayout(l))
- .catch(() => setLayout(DEFAULT_LAYOUT))
- }, [])
+ .catch(() => setLayout(DEFAULT_TITLEBAR_LAYOUT))
+ }, [setLayout])
// Refetch on focus so changes made in the DE's settings (KDE/GNOME) while Jan
// was unfocused are picked up without a restart.
@@ -67,14 +66,14 @@ export const WindowControls = () => {
return (
<>
{layout.left.length > 0 && (
- <div className="absolute top-0 z-50 left-4 h-15">
+ <div className="absolute top-0 z-[60] left-4 h-15">
<div className="flex items-center h-full">
{renderGroup(layout.left)}
</div>
</div>
)}
{layout.right.length > 0 && (
- <div className="absolute top-0 z-50 right-4 h-15">
+ <div className="absolute top-0 z-[60] right-4 h-15">
<div className="flex items-center h-full">
{renderGroup(layout.right)}
</div>
diff --git a/web-app/src/components/left-sidebar/index.tsx b/web-app/src/components/left-sidebar/index.tsx
index 818a5628b..1a72bd834 100644
--- a/web-app/src/components/left-sidebar/index.tsx
+++ b/web-app/src/components/left-sidebar/index.tsx
@@ -12,16 +12,25 @@ import {
SidebarRail,
} from '@/components/ui/sidebar'
import { cn } from '@/lib/utils'
+import { useTitlebarLayout } from '@/stores/titlebar-layout-store'
export function LeftSidebar() {
const { open: isLeftPanelOpen } = useLeftPanel()
+ // Right-align the header when native controls own the top-left (macOS, or a Linux
+ // DE placing buttons left); "Jan" moves into the right cluster except on macOS.
+ const leftButtons = useTitlebarLayout((s) => s.layout.left.length)
+ const controlsOnLeft = !IS_MACOS && leftButtons > 0
+ const reserveLeft = IS_MACOS || controlsOnLeft
return (
<div className='relative z-50'>
<Sidebar variant="floating" collapsible="offcanvas">
<SidebarHeader className="flex px-1">
- <div className={cn("flex items-center w-full justify-between", IS_MACOS && "justify-end")}>
- {!IS_MACOS && <span className="ml-2 font-medium font-studio">Jan</span>}
- <div>
+ <div className={cn("flex items-center w-full justify-between", reserveLeft && "justify-end")}>
+ {!reserveLeft && <span className="ml-2 font-medium font-studio">Jan</span>}
+ <div className="flex items-center">
+ {controlsOnLeft && (
+ <span className="mr-2 font-medium font-studio">Jan</span>
+ )}
{isLeftPanelOpen && <DownloadManagement />}
<SidebarTrigger className="text-muted-foreground rounded-full hover:bg-sidebar-foreground/8! -mt-0.5 relative z-50 ml-0.5" />
</div>
diff --git a/web-app/src/containers/HeaderPage.tsx b/web-app/src/containers/HeaderPage.tsx
index b87edf744..2c9c54b67 100644
--- a/web-app/src/containers/HeaderPage.tsx
+++ b/web-app/src/containers/HeaderPage.tsx
@@ -6,12 +6,18 @@ import {
import { ReactNode, memo } from 'react'
import { Button } from "@/components/ui/button"
import { DownloadManagement } from '@/containers/DownloadManegement'
+import { useTitlebarLayout } from '@/stores/titlebar-layout-store'
type HeaderPageProps = {
children?: ReactNode
}
const HeaderPage = memo(function HeaderPage({ children }: HeaderPageProps) {
const { open, setLeftPanel } = useLeftPanel()
+ // Collapsed, this header owns the top-left strip — indent past left-anchored Linux
+ // window controls (size-8 each at left-4); macOS uses the pl-24 class below.
+ const leftButtons = useTitlebarLayout((s) => s.layout.left.length)
+ const linuxControlsPad =
+ !IS_MACOS && !open && leftButtons > 0 ? leftButtons * 32 + 24 : undefined
return (
<div
@@ -20,6 +26,7 @@ const HeaderPage = memo(function HeaderPage({ children }: HeaderPageProps) {
(IS_MACOS && !open) ? 'pl-24' : ' pl-4',
children === undefined && 'border-none'
)}
+ style={linuxControlsPad ? { paddingLeft: linuxControlsPad } : undefined}
>
<div
className={cn(
diff --git a/web-app/src/stores/titlebar-layout-store.ts b/web-app/src/stores/titlebar-layout-store.ts
new file mode 100644
index 000000000..5de3f4090
--- /dev/null
+++ b/web-app/src/stores/titlebar-layout-store.ts
@@ -0,0 +1,19 @@
+import { create } from 'zustand'
+
+export type ButtonId = 'minimize' | 'maximize' | 'close'
+export type TitlebarLayout = { left: ButtonId[]; right: ButtonId[] }
+
+export const DEFAULT_TITLEBAR_LAYOUT: TitlebarLayout = {
+ left: [],
+ right: ['minimize', 'maximize', 'close'],
+}
+
+type TitlebarLayoutState = {
+ layout: TitlebarLayout
+ setLayout: (layout: TitlebarLayout) => void
+}
+
+export const useTitlebarLayout = create<TitlebarLayoutState>()((set) => ({
+ layout: DEFAULT_TITLEBAR_LAYOUT,
+ setLayout: (layout) => set({ layout }),
+}))