From f1ed9770ed836048fe7ea61d339ab000773d456b Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 26 Sep 2024 11:11:31 -0400 Subject: [PATCH] feat(nvim): make jsx and tsx respect js indentation --- common/home/neovim/langs/web.nix | 2 +- nixosModules/ags/v2/lib.ts | 39 +++++++++++++++ .../ags/v2/widgets/bar/fullscreen.tsx | 50 +++++++++++++++++++ nixosModules/ags/v2/widgets/bar/main.tsx | 5 ++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 nixosModules/ags/v2/lib.ts create mode 100644 nixosModules/ags/v2/widgets/bar/fullscreen.tsx diff --git a/common/home/neovim/langs/web.nix b/common/home/neovim/langs/web.nix index ed5bde66..29bae264 100644 --- a/common/home/neovim/langs/web.nix +++ b/common/home/neovim/langs/web.nix @@ -34,7 +34,7 @@ in # lua '' vim.api.nvim_create_autocmd('FileType', { - pattern = { 'javascript', 'typescript', 'css', 'scss' }, + pattern = { 'javascript', 'javascriptreact', 'javascript.jsx', 'typescript', 'typescriptreact', 'typescript.tsx', 'css', 'scss' }, command = 'setlocal ts=4 sw=4 sts=0 expandtab', }); diff --git a/nixosModules/ags/v2/lib.ts b/nixosModules/ags/v2/lib.ts new file mode 100644 index 00000000..3ddc175f --- /dev/null +++ b/nixosModules/ags/v2/lib.ts @@ -0,0 +1,39 @@ +import { Gdk } from 'astal'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; + +const Hyprland = AstalHyprland.get_default(); + + +export const get_hyprland_monitor = (monitor: Gdk.Monitor): AstalHyprland.Monitor | undefined => { + const manufacturer = monitor.manufacturer?.replace(',', ''); + const model = monitor.model?.replace(',', ''); + const start = `${manufacturer} ${model}`; + + return Hyprland.monitors.find((m) => m.description?.startsWith(start)); +}; + +export const get_hyprland_monitor_desc = (monitor: Gdk.Monitor): string => { + const manufacturer = monitor.manufacturer?.replace(',', ''); + const model = monitor.model?.replace(',', ''); + const start = `${manufacturer} ${model}`; + + return `desc:${Hyprland.monitors.find((m) => m.description?.startsWith(start))?.description}`; +}; + +export const get_gdkmonitor_from_desc = (desc: string): Gdk.Monitor => { + const display = Gdk.Display.get_default(); + + for (let m = 0; m < (display?.get_n_monitors() ?? 0); m++) { + const monitor = display?.get_monitor(m); + + if (monitor && desc === get_hyprland_monitor_desc(monitor)) { + return monitor; + } + } + + throw Error(`Monitor ${desc} not found`); +}; + +export const get_monitor_desc = (mon: AstalHyprland.Monitor): string => { + return `desc:${mon.description}`; +}; diff --git a/nixosModules/ags/v2/widgets/bar/fullscreen.tsx b/nixosModules/ags/v2/widgets/bar/fullscreen.tsx new file mode 100644 index 00000000..753124f0 --- /dev/null +++ b/nixosModules/ags/v2/widgets/bar/fullscreen.tsx @@ -0,0 +1,50 @@ +import { Variable } from 'astal'; +import AstalHyprland from 'gi://AstalHyprland?version=0.1'; + +const Hyprland = AstalHyprland.get_default(); + +import { get_monitor_desc } from '../../lib'; + + +const FullscreenState = Variable({ + monitors: [] as string[], + clientAddrs: new Map() as Map, +}); + +Hyprland.connect('event', () => { + const arrayEquals = (a1: unknown[], a2: unknown[]) => + a1.sort().toString() === a2.sort().toString(); + + const mapEquals = (m1: Map, m2: Map) => + m1.size === m2.size && + Array.from(m1.keys()).every((key) => m1.get(key) === m2.get(key)); + + const fs = FullscreenState.get(); + const fsClients = Hyprland.get_clients().filter((c) => { + const mon = c.get_monitor(); + + return c.fullscreen && + c.workspace.id === mon?.activeWorkspace.id; + }); + + const monitors = fsClients.map((c) => + get_monitor_desc(c.monitor)); + + const clientAddrs = new Map(fsClients.map((c) => [ + get_monitor_desc(c.monitor), + c.address ?? '', + ])); + + const hasChanged = + !arrayEquals(monitors, fs.monitors) || + !mapEquals(clientAddrs, fs.clientAddrs); + + if (hasChanged) { + FullscreenState.set({ + monitors, + clientAddrs, + }); + } +}); + +export default FullscreenState; diff --git a/nixosModules/ags/v2/widgets/bar/main.tsx b/nixosModules/ags/v2/widgets/bar/main.tsx index 0a950c6d..e0198130 100644 --- a/nixosModules/ags/v2/widgets/bar/main.tsx +++ b/nixosModules/ags/v2/widgets/bar/main.tsx @@ -1,6 +1,11 @@ import { App, Astal, Gtk, idle, Variable } from 'astal'; +import FullscreenState from './fullscreen'; + +FullscreenState.subscribe((v) => { + console.log(v); +}); const isVisible = Variable(false); export default () => {