diff --git a/common/overlays/default.nix b/common/overlays/default.nix index 5ccbd6c..481870f 100644 --- a/common/overlays/default.nix +++ b/common/overlays/default.nix @@ -1,5 +1,10 @@ -{nixpkgs-wayland, ...} @ inputs: [ +{ + grim-hyprland, + nixpkgs-wayland, + ... +} @ inputs: [ (import ./dracula-theme inputs) + grim-hyprland.overlays.default nixpkgs-wayland.overlay ] diff --git a/common/pkgs/rars-flatlaf/default.nix b/common/pkgs/rars-flatlaf/default.nix deleted file mode 100644 index 0a6585a..0000000 --- a/common/pkgs/rars-flatlaf/default.nix +++ /dev/null @@ -1,110 +0,0 @@ -{ - config, - writeShellApplication, - stdenvNoCC, - jre, - fetchFromGitHub, - fetchurl, - makeWrapper, - makeDesktopItem, - rsync, - ... -}: -stdenvNoCC.mkDerivation rec { - name = "rars-flatlaf"; - - src = fetchFromGitHub { - owner = "privat"; - repo = "rars"; - rev = "fd34014efd65b3cb5a52f1729c3b8240cae0c332"; - hash = "sha256-D8X/cr+fnq/OOFYfMG9aPss95J8Z2yiROuF9kmHkK40="; - fetchSubmodules = true; - }; - - desktopItem = let - hyprland = config.home-manager.users.${config.vars.mainUser}.wayland.windowManager.hyprland.finalPackage; - execScript = writeShellApplication { - name = "execScript"; - runtimeInputs = [hyprland]; - text = "(sleep 1; hyprctl dispatch togglefloating) & ${name}"; - }; - in - makeDesktopItem { - name = "RARS"; - desktopName = "RARS"; - exec = "${execScript}/bin/execScript"; - icon = name; - }; - - nativeBuildInputs = [makeWrapper rsync jre]; - - installPhase = let - flatlaf = fetchurl { - url = "https://repo1.maven.org/maven2/com/formdev/flatlaf/3.2/flatlaf-3.2.jar"; - hash = "sha256-HAG+G9undDXWtySokKl7lkIUCFI7lEBduu+UgSVaxAA="; - }; - icon = fetchurl { - url = "https://riscv.or.jp/wp-content/uploads/2019/06/cropped-RISC-V-logo-figonly-mod-2.png"; - hash = "sha256-e1/iVmadVzyO77ikBr1cdXsJdDj8TiXh3Oyjek9GwqM="; - }; - in - /* - bash - */ - '' - # ./build-jar.sh - mkdir -p build - find src -name "*.java" | xargs javac --release 8 -d build - if [[ "$OSTYPE" == "darwin"* ]]; then - find src -type f -not -name "*.java" -exec rsync -R {} build \; - else - find src -type f -not -name "*.java" -exec cp --parents {} build \; - fi - cp -rf build/src/* build - rm -r build/src - cp README.md License.txt build - cd build - jar cfm ../rars.jar ./META-INF/MANIFEST.MF * - chmod +x ../rars.jar - - cd .. - - # ./build-jar-flatlaf.sh - mkdir -p build-flatlaf/ - cd build-flatlaf/ - - cp ${flatlaf} ../flatlaf.jar - - jar x < ../rars.jar - jar x < "../flatlaf.jar" - - cat > META-INF/MANIFEST.MF < ./rars.desktop < { + App.closeWindow('win-screenshot'); + timeout(delay, () => { + execAsync(['bash', '-c', `grim ${selector} - | satty -f -`]) + .catch(console.error); + }); +}; + +export default () => { + const windowList = Box({ + vertical: true, + }); + + const updateWindows = async() => { + if (!App.getWindow('win-screenshot')?.visible) { + return; + } + + windowList.children = (JSON.parse( + await Hyprland.messageAsync('j/clients'), + ) as Client[]) + .filter((client) => client.workspace.id === Hyprland.active.workspace.id) + .map((client) => CursorBox({ + class_name: 'item-btn', + + on_primary_click_release: () => { + takeScreenshot(`-w ${client.address}`); + }, + + child: Box({ + hpack: 'center', + + children: [ + Icon(Applications + .query(client.class)[0]?.app.get_string('Icon') ?? ''), + + Label({ + label: client.title, + truncate: 'end', + max_width_chars: 50, + }), + ], + }), + })); + }; + + + const stack = Stack({ + transition: 'slide_left_right', + + children: { + monitors: Scrollable({ + child: Box({ + vertical: true, + }).hook(Hyprland, (self) => { + self.children = Hyprland.monitors.map((monitor) => CursorBox({ + class_name: 'item-btn', + + on_primary_click_release: () => { + takeScreenshot(`-o ${monitor.name}`); + }, + + child: Label({ + label: `${monitor.name}: ${monitor.description}`, + truncate: 'end', + max_width_chars: 50, + }), + })); + }, 'notify::monitors'), + }), + + windows: Scrollable({ + child: windowList + .hook(Hyprland, updateWindows, 'notify::clients') + .hook(Hyprland.active.workspace, updateWindows), + }), + }, + }); + + const monitorsButton = CursorBox({ + class_name: 'header-btn', + + on_primary_click_release: () => { + stack.shown = 'monitors'; + }, + + child: Box({ + hpack: 'center', + + children: [ + Icon('display-symbolic'), + Label('monitors'), + ], + }), + }); + + const windowsButton = CursorBox({ + class_name: 'header-btn', + + on_primary_click_release: () => { + stack.shown = 'windows'; + }, + + child: Box({ + hpack: 'center', + + children: [ + Icon('window-symbolic'), + Label('windows'), + ], + }), + }); + + const regionButton = CursorBox({ + class_name: 'header-btn', + + on_primary_click_release: () => { + takeScreenshot('-g "$(slurp)"', 0); + }, + + child: Box({ + hpack: 'center', + + children: [ + Icon('tool-pencil-symbolic'), + Label('region'), + ], + }), + }); + + return PopupWindow({ + name: 'screenshot', + on_open: () => { + updateWindows(); + }, + child: Box({ + class_name: 'screenshot', + vertical: true, + + children: [ + Box({ + class_name: 'header', + homogeneous: true, + + children: [ + monitorsButton, + windowsButton, + regionButton, + ], + }).hook(stack, () => { + switch (stack.shown) { + case 'monitors': + monitorsButton.toggleClassName('active', true); + windowsButton.toggleClassName('active', false); + break; + + case 'windows': + monitorsButton.toggleClassName('active', false); + windowsButton.toggleClassName('active', true); + break; + + default: + break; + } + }, 'notify::shown'), + + stack, + ], + }), + }); +}; diff --git a/modules/ags/config/wim.ts b/modules/ags/config/wim.ts index fce2713..a19247d 100644 --- a/modules/ags/config/wim.ts +++ b/modules/ags/config/wim.ts @@ -10,6 +10,7 @@ import OSD from './ts/osd/main.ts'; import OSK from './ts/on-screen-keyboard/main.ts'; import Powermenu from './ts/powermenu.ts'; import QSettings from './ts/quick-settings/main.ts'; +import Screenshot from './ts/screenshot/main.ts'; App.config({ @@ -30,6 +31,7 @@ App.config({ OSK(), Powermenu(), QSettings(), + Screenshot(), Bar(), BgFade(), diff --git a/modules/ags/default.nix b/modules/ags/default.nix index d315a54..29d1daa 100644 --- a/modules/ags/default.nix +++ b/modules/ags/default.nix @@ -146,15 +146,17 @@ in { ]; bind = [ - "$mainMod SHIFT, E, exec, ags -t win-powermenu" - "$mainMod , D, exec, ags -t win-applauncher" + "$mainMod SHIFT, E , exec, ags -t win-powermenu" + "$mainMod , D , exec, ags -t win-applauncher" + "$mainMod , V , exec, ags -t win-clipboard" + " , Print, exec, ags -t win-screenshot" ]; binde = [ ## Brightness control - ", XF86MonBrightnessUp, exec, ags -r 'Brightness.screen += 0.05'" + ", XF86MonBrightnessUp , exec, ags -r 'Brightness.screen += 0.05'" ", XF86MonBrightnessDown, exec, ags -r 'Brightness.screen -= 0.05'" ]; - bindn = [" , Escape, exec, ags -r 'closeAll()'"]; + bindn = [" , Escape , exec, ags -r 'closeAll()'"]; bindr = ["CAPS, Caps_Lock, exec, ags -r 'Brightness.fetchCapsState()'"]; }; }; diff --git a/modules/hyprland/packages.nix b/modules/hyprland/packages.nix index 3d174d2..25f9ef8 100644 --- a/modules/hyprland/packages.nix +++ b/modules/hyprland/packages.nix @@ -6,6 +6,7 @@ }: let inherit (lib) makeLibraryPath optionalString; inherit (pkgs.writers) writeTOML; + inherit (config.vars) mainUser; flakeDir = config.environment.variables.FLAKE; in { @@ -46,71 +47,57 @@ in { }) ]; - home.packages = with pkgs; [ - # School - xournalpp - virt-manager - libreoffice-fresh # TODO: declarative conf? - hunspell - hunspellDicts.en_CA - config.customPkgs.rars-flatlaf + home.packages = + (with pkgs; [ + # School + xournalpp + virt-manager + libreoffice-fresh # TODO: declarative conf? + hunspell + hunspellDicts.en_CA - # Apps - thunderbird # TODO: use programs.thunderbird - protonmail-bridge - spotifywm - photoqt - nextcloud-client - jellyfin-media-player - prismlauncher + # Apps + thunderbird # TODO: use programs.thunderbird + protonmail-bridge + spotifywm + photoqt + nextcloud-client + jellyfin-media-player + prismlauncher - # tools - wl-color-picker - wl-clipboard - cliphist - grim - slurp - satty - - # TODO: make an ags widget to select windows, screens or a selection - (writeShellApplication { - name = "screenshot"; - runtimeInputs = [ - config.programs.hyprland.package - satty - grim - jq - ]; - text = '' - screen=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true).name') - exec grim -o "$screen" - | satty -f - - ''; - }) - - /* - Discord themes for Vencord - https://markchan0225.github.io/RoundedDiscord/RoundedDiscord.theme.css - https://raw.githubusercontent.com/dracula/BetterDiscord/master/Dracula_Official.theme.css - */ - (symlinkJoin { - name = "discord"; - paths = [ - (discord.override { - withOpenASAR = true; - withVencord = true; - }) - ]; - buildInputs = [makeWrapper]; - postBuild = '' - wrapProgram $out/bin/Discord ${optionalString config.nvidia.enable - ''--prefix LD_LIBRARY_PATH : "${makeLibraryPath [ - addOpenGLRunpath.driverLink - libglvnd - ]}"''} \ - --add-flags "--enable-features=UseOzonePlatform,WebRTCPipeWireCapturer --ozone-platform=wayland" - ''; - }) - ]; + # tools + wl-color-picker + wl-clipboard + cliphist + grim-hyprland + slurp + satty + ]) + ++ [ + /* + Discord themes for Vencord + https://markchan0225.github.io/RoundedDiscord/RoundedDiscord.theme.css + https://raw.githubusercontent.com/dracula/BetterDiscord/master/Dracula_Official.theme.css + */ + (pkgs.symlinkJoin { + name = "discord"; + paths = [ + (pkgs.discord.override { + withOpenASAR = true; + withVencord = true; + }) + ]; + buildInputs = [pkgs.makeWrapper]; + postBuild = '' + wrapProgram $out/bin/Discord ${optionalString config.nvidia.enable + ''--prefix LD_LIBRARY_PATH : "${makeLibraryPath [ + pkgs.addOpenGLRunpath.driverLink + pkgs.libglvnd + ]}"''} \ + --add-flags "--enable-features=UseOzonePlatform,WebRTCPipeWireCapturer --ozone-platform=wayland" + ''; + }) + ]; wayland.windowManager.hyprland = { settings = { @@ -144,11 +131,6 @@ in { bind = [ "$mainMod, Q, exec, foot" - # Clipboard History - "$mainMod, V, exec, ags -t win-clipboard" - - " , Print, exec, screenshot" - "$mainMod, Print, exec, grim -g \"$(slurp)\" - | satty -f -" "$mainMod SHIFT, C, exec, wl-color-picker" "$mainMod, T, togglespecialworkspace, thunder"