Summon the Obsidian window and keep it on top with a single system-wide hotkey — press the same key again to hide it.
Desktop only (Windows / macOS / Linux).
restore()).screen-saver z-order level, which avoids Electron's Windows-only "place the window behind the taskbar" path.manifest.json, main.js, styles.css.<your-vault>/.obsidian/plugins/pin-toggle/.
The folder name must match the id field in manifest.json (pin-toggle).Settings → Community plugins, turn off Restricted mode, then enable Pin Toggle.Hotkeys are bound in Obsidian's own hotkey UI — not inside the plugin settings page.
Settings → Hotkeys.Ctrl+Alt+Space.Ctrl+Alt+Space, so it works out of the box.Note: the bound combination is registered system-wide, so it is captured from every application while the plugin is enabled. Prefer combinations that no other app relies on.
Alt+<letter>is a poor choice on Windows — it also drives menu mnemonics.
| Option | Description | Default |
|---|---|---|
| 置顶 (always on top) | Whether the summoned window really floats above other applications. Turn it off to merely bring it to the front. | On |
| 置顶守护 (topmost keeper) | Keep re-asserting the z-order so the window cannot be pushed behind other windows. Turn it off to save power, at the cost of only pinning at summon time. | On |
| 收起方式 | Collapse behavior: hide the window (no taskbar entry, like Alt+E) or minimize it to the taskbar. |
Hide |
| 内部窗口优先 | Keep Obsidian's own separate windows (Settings, popout notes, dialogs) above the main window; the main window only covers other applications. Turn it off to put the main window back on top. | On |
Press your hotkey in any application: the window is summoned and pinned on top. Press it again to collapse and return to what you were doing. You can also use the 📌 ribbon icon in the left sidebar, or run the command from the command palette.
Two details decide whether "always on top" survives contact with other applications.
1. The z-order level matters on Windows. setAlwaysOnTop(flag) defaults to the floating level. On Windows, Electron does not use the level to pick a z-order band — it uses it to decide whether the window should be placed behind the taskbar (Shell_TrayWnd). The levels floating, torn-off-menu, modal-panel, main-menu and status all trigger that behaviour. Windows documents that repositioning a topmost window after any non-topmost window removes its topmost status, so a window pinned at the default level can silently stop being topmost. This plugin pins at screen-saver, which is not in that set.
2. A single setAlwaysOnTop call is not enough. Fullscreen windows (browser F11, video fullscreen, PDF/PPT presentation) are raised above topmost windows by the OS. The only compensation is to re-assert the z-order periodically, which the keeper does — with moveTop() only, never focus(), so the focus stays wherever the user put it.
3. Re-assertion must be conditional. moveTop() resolves to SetWindowPos(hwnd, HWND_TOP, ...). For a window that is already topmost, that means "move to the very front of the topmost band" — which also puts it in front of the IME candidate window, because that is a topmost popup in the same band. An unconditional timer therefore covers the candidate list roughly every 1.5 s while you type pinyin. The keeper now skips re-assertion in two cases:
isFocused()) — it is already above every non-topmost window, so there is nothing to recover;compositionstart / compositionupdate / compositionend on the document).Only an explicit summon bypasses both checks.
F11, video fullscreen, PDF/PPT presentation) can be covered.focus(). Stealing focus would prevent you from typing into the fullscreen page underneath. It only calls moveTop(), which changes the z-order without changing activation.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }), which has no effect on Windows.If the window still gets covered, run the read-only diagnostic probe while reproducing:
python tools/win-zorder-probe.py # one shot
python tools/win-zorder-probe.py --watch # live, once per second
It prints every top-level window's z-order, WS_EX_TOPMOST flag, fullscreen state and the Obsidian window's position relative to the taskbar, then classifies the failure as A/B/C/D.
[Pin Toggle] 无法获取 Electron 窗口, the Electron remote API is unavailable in your environment; pinning and the global hotkey are disabled.npm install
npm run typecheck # tsc --noEmit
npm run lint # eslint src/ package.json
npm run build # bundles src/main.ts into main.js
npm test # state-machine smoke test against the built main.js
src/main.ts is the source of truth. main.js at the repository root is the esbuild bundle that Obsidian actually loads — do not edit it by hand.
一个极简 Obsidian 桌面插件:一次全局热键把窗口唤出并置顶,再按一次收起。
screen-saver 置顶层级,绕开 Electron 在 Windows 上「把窗口压到任务栏之后」的路径。manifest.json、main.js、styles.css。<你的vault>/.obsidian/plugins/pin-toggle/manifest.json 里的 id(即 pin-toggle)一致。设置 → 社区插件 → 关闭「安全模式」→ 在「已安装插件」列表里启用 Pin Toggle。设置 → 快捷键。Ctrl+Alt+Space)绑定即可。Ctrl+Alt+Space,开箱即用。注意:绑定的组合键会被全局注册,插件启用期间会从所有软件那里截获该按键。请避免使用其他软件依赖的组合键;Windows 上
Alt+字母尤其不合适(会与菜单助记符冲突)。
在任意软件按下你设定的热键 → 窗口立即置顶唤出;用完再按 → 收起,回到原工作。左侧边栏也有一个 📌 图标可点按切换;命令面板里也能搜到该命令手动执行。
两个细节决定「置顶」能不能扛住其他软件。
一、Windows 上置顶层级很关键。 setAlwaysOnTop(flag) 缺省级别是 floating。Electron 在 Windows 上并不用这个级别决定层级高低,而是用它决定窗口要不要被压到任务栏之后——floating、torn-off-menu、modal-panel、main-menu、status 这五个都会触发该行为。而 Windows 官方文档明确:把最顶层窗口重新定位到任何非最顶层窗口之后,它就不再是最顶层窗口。所以按默认级别置顶的窗口可能悄悄失去 topmost。本插件改用 screen-saver,不命中该集合。
二、只调用一次 setAlwaysOnTop 不够。 全屏窗口(浏览器 F11、视频全屏、PDF/PPT 放映)会被操作系统抬到 topmost 窗口之上。唯一的补偿办法是周期性重新断言 z 序——由「置顶守护」完成,且只用 moveTop()、绝不用 focus(),不会打断你的输入。
F11、视频全屏、PDF/PPT 放映)可以覆盖。focus()。否则会抢走焦点,你就无法在全屏页面里打字。只用 moveTop(),只改 z 序、不改激活状态。setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true }),该 API 在 Windows 上无效。若窗口仍被盖住,在复现问题时运行只读诊断探针:
python tools/win-zorder-probe.py # 打印一次
python tools/win-zorder-probe.py --watch # 每秒刷新,边操作边看
它会打印所有顶层窗口的 z 序、WS_EX_TOPMOST 标志、是否全屏、以及 Obsidian 相对任务栏的位置,并给出 A/B/C/D 判定。
[Pin Toggle] 无法获取 Electron 窗口:说明当前环境拿不到 Electron remote,置顶与全局热键会停用。npm install
npm run typecheck
npm run lint
npm run build
npm test
src/main.ts 是源码;根目录的 main.js 是 esbuild 产物,不要手改。