From 29644717234a3c60b8aeb94e6f7643b9770f4f56 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Thu, 23 Mar 2023 10:59:44 +0100 Subject: [PATCH] Move from dunst to swaync and some overall changes for sway --- common.nix | 9 + flake.nix | 1 + home/kagami-pc-home.nix | 5 +- home/modules/linux/graphical/swaync.css | 323 ++++++++++++++++++++++ home/modules/linux/graphical/wayland.nix | 88 +++++- home/modules/programs/my-sway/default.nix | 79 +++--- 6 files changed, 454 insertions(+), 51 deletions(-) create mode 100644 common.nix create mode 100644 home/modules/linux/graphical/swaync.css diff --git a/common.nix b/common.nix new file mode 100644 index 0000000..6d5b4ed --- /dev/null +++ b/common.nix @@ -0,0 +1,9 @@ +# Common stuff +{ lib, pkgs, config, ... }: +with lib; { + # swaync disable notifications on screencast + xdg.portal.wlr.settings.screencast = { + exec_before = ''which swaync-client && swaync-client --inhibitor-add "xdg-desktop-portal-wlr" || true''; + exec_after = ''which swaync-client && swaync-client --inhibitor-remove "xdg-desktop-portal-wlr" || true''; + }; +} diff --git a/flake.nix b/flake.nix index f502e6e..195d11f 100644 --- a/flake.nix +++ b/flake.nix @@ -110,6 +110,7 @@ system = "x86_64-linux"; pkgs = pkgs' system; modules = [ + ./common.nix ./modules/my-tinc sops-nix.nixosModules.sops ./nki-home/configuration.nix diff --git a/home/kagami-pc-home.nix b/home/kagami-pc-home.nix index 3f0ca1f..b8c3652 100644 --- a/home/kagami-pc-home.nix +++ b/home/kagami-pc-home.nix @@ -42,14 +42,14 @@ top_y = builtins.ceil (((2160 / scale) - 1080) / 2); in { - "Unknown U28G2G6B PPYM9JA001554" = { + "AOC U28G2G6B PPYM9JA001554" = { mode = "3840x2160@60Hz"; scale = toString scale; adaptive_sync = "on"; # render_bit_depth = "10"; position = "0 0"; }; - "Unknown 24G2W1G4 ATNN21A005410" = { + "AOC 24G2W1G4 ATNN21A005410" = { mode = "1920x1080@144Hz"; adaptive_sync = "on"; position = "${toString top_x} ${toString top_y}"; @@ -61,6 +61,7 @@ }; }; nki.programs.kitty.enable = true; + nki.programs.kitty.package = pkgs.unstable.kitty; # 0.27 fixes crash on sway 1.8 nki.programs.kitty.fontSize = 14; # Yellow light! diff --git a/home/modules/linux/graphical/swaync.css b/home/modules/linux/graphical/swaync.css new file mode 100644 index 0000000..5b7d28c --- /dev/null +++ b/home/modules/linux/graphical/swaync.css @@ -0,0 +1,323 @@ +/* + * vim: ft=less + */ + +@define-color cc-bg rgba(0, 0, 0, 0.7); + +@define-color noti-border-color rgba(255, 255, 255, 0.15); +@define-color noti-bg rgb(48, 48, 48); +@define-color noti-bg-hover rgb(56, 56, 56); +@define-color noti-bg-focus rgba(68, 68, 68, 0.6); +@define-color noti-close-bg rgba(255, 255, 255, 0.1); +@define-color noti-close-bg-hover rgba(255, 255, 255, 0.15); + +@define-color bg-selected rgb(0, 128, 255); + +.notification-row { + outline: none; +} + +.notification-row:focus, +.notification-row:hover { + background: @noti-bg-focus; +} + +.notification { + border-radius: 12px; + margin: 6px 12px; + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.7), + 0 2px 6px 2px rgba(0, 0, 0, 0.3); + padding: 0; +} + +/* Uncomment to enable specific urgency colors +.low { + background: yellow; + padding: 6px; + border-radius: 12px; +} + +.normal { + background: green; + padding: 6px; + border-radius: 12px; +} + +.critical { + background: red; + padding: 6px; + border-radius: 12px; +} +*/ + +.notification-content { + background: transparent; + padding: 6px; + border-radius: 12px; +} + +.close-button { + background: @noti-close-bg; + color: white; + text-shadow: none; + padding: 0; + border-radius: 100%; + margin-top: 10px; + margin-right: 16px; + box-shadow: none; + border: none; + min-width: 24px; + min-height: 24px; +} + +.close-button:hover { + box-shadow: none; + background: @noti-close-bg-hover; + transition: all 0.15s ease-in-out; + border: none; +} + +.notification-default-action, +.notification-action { + padding: 4px; + margin: 0; + box-shadow: none; + background: @noti-bg; + border: 1px solid @noti-border-color; + color: white; +} + +.notification-default-action:hover, +.notification-action:hover { + -gtk-icon-effect: none; + background: @noti-bg-hover; +} + +.notification-default-action { + border-radius: 12px; +} + +/* When alternative actions are visible */ +.notification-default-action:not(:only-child) { + border-bottom-left-radius: 0px; + border-bottom-right-radius: 0px; +} + +.notification-action { + border-radius: 0px; + border-top: none; + border-right: none; +} + +/* add bottom border radius to eliminate clipping */ +.notification-action:first-child { + border-bottom-left-radius: 10px; +} + +.notification-action:last-child { + border-bottom-right-radius: 10px; + border-right: 1px solid @noti-border-color; +} + +.image { +} + +.body-image { + margin-top: 6px; + background-color: white; + border-radius: 12px; +} + +.summary { + font-size: 16px; + font-weight: bold; + background: transparent; + color: white; + text-shadow: none; +} + +.time { + font-size: 16px; + font-weight: bold; + background: transparent; + color: white; + text-shadow: none; + margin-right: 18px; +} + +.body { + font-size: 15px; + font-weight: normal; + background: transparent; + color: white; + text-shadow: none; +} + +.control-center { + background: @cc-bg; +} + +.control-center-list { + background: transparent; +} + +.control-center-list-placeholder { + opacity: 0.5; +} + +.floating-notifications { + background: transparent; +} + +/* Window behind control center and on all other monitors */ +.blank-window { + background: alpha(black, 0.25); +} + +/*** Widgets ***/ + +/* Title widget */ +.widget-title { + margin: 8px; + font-size: 1.5rem; + color: white; +} +.widget-title > button { + font-size: initial; + color: white; + text-shadow: none; + background: @noti-bg; + border: 1px solid @noti-border-color; + box-shadow: none; + border-radius: 12px; +} +.widget-title > button:hover { + background: @noti-bg-hover; +} + +/* DND widget */ +.widget-dnd { + margin: 8px; + font-size: 1.1rem; + color: white; +} +.widget-dnd > switch { + font-size: initial; + border-radius: 12px; + background: @noti-bg; + border: 1px solid @noti-border-color; + box-shadow: none; +} +.widget-dnd > switch:checked { + background: @bg-selected; +} +.widget-dnd > switch slider { + background: @noti-bg-hover; + border-radius: 12px; +} + +/* Label widget */ +.widget-label { + margin: 8px; +} +.widget-label > label { + font-size: 1.1rem; +} + +/* Mpris widget */ +.widget-mpris { + /* The parent to all players */ + color: white; +} +.widget-mpris-player { + padding: 8px; + margin: 8px; +} +.widget-mpris-title { + font-weight: bold; + font-size: 1.25rem; +} +.widget-mpris-subtitle { + font-size: 1.1rem; +} + +/* Buttons widget */ +.widget-buttons-grid { + padding: 8px; + margin: 8px; + border-radius: 12px; + background-color: @noti-bg; +} + +.widget-buttons-grid>flowbox>flowboxchild>button{ + background: @noti-bg; + border-radius: 12px; +} + +.widget-buttons-grid>flowbox>flowboxchild>button:hover { + background: @noti-bg-hover; +} + +/* Menubar widget */ +.widget-menubar>box>.menu-button-bar>button { + border: none; + background: transparent; +} + +/* .AnyName { Name defined in config after # + background-color: @noti-bg; + padding: 8px; + margin: 8px; + border-radius: 12px; +} + +.AnyName>button { + background: transparent; + border: none; +} + +.AnyName>button:hover { + background-color: @noti-bg-hover; +} */ + +.topbar-buttons>button { /* Name defined in config after # */ + border: none; + background: transparent; +} + +/* Volume widget */ + +.widget-volume { + background-color: @noti-bg; + padding: 8px; + margin: 8px; + border-radius: 12px; + color: white; +} + +/* Backlight widget */ +.widget-backlight { + background-color: @noti-bg; + padding: 8px; + margin: 8px; + border-radius: 12px; + color: white; +} + +/* Title widget */ +.widget-inhibitors { + margin: 8px; + font-size: 1.5rem; +} +.widget-inhibitors > button { + font-size: initial; + color: white; + text-shadow: none; + background: @noti-bg; + border: 1px solid @noti-border-color; + box-shadow: none; + border-radius: 12px; +} +.widget-inhibitors > button:hover { + background: @noti-bg-hover; +} diff --git a/home/modules/linux/graphical/wayland.nix b/home/modules/linux/graphical/wayland.nix index c6cf95b..1219691 100644 --- a/home/modules/linux/graphical/wayland.nix +++ b/home/modules/linux/graphical/wayland.nix @@ -1,6 +1,68 @@ { pkgs, config, lib, ... }: +let + notificationModule = { config, pkgs, lib, ... }: + let + swaync = pkgs.unstable.swaynotificationcenter; + in + with lib; mkIf (config.linux.graphical.type == "wayland") { + home.packages = [ swaync ]; + wayland.windowManager.sway.config = { + startup = [ + { command = "swaync"; } + ]; + }; + xdg.configFile = { + "swaync/config.json" = { + text = builtins.toJSON { + widgets = [ "inhibitors" "title" "dnd" "mpris" "notifications" ]; + scripts = { }; + }; + onChange = "swaync-client -R"; + }; + "swaync/style.css" = { + source = ./swaync.css; + onChange = "swaync-client -rs"; + }; + }; + + programs.my-sway.waybar = { + extraSettings = { + modules-right = mkAfter [ "custom/swaync" ]; + modules."custom/swaync" = { + tooltip = false; + format = "{icon} {}"; + format-icons = { + notification = ""; + none = ""; + dnd-notification = ""; + dnd-none = ""; + inhibited-notification = ""; + inhibited-none = ""; + dnd-inhibited-notification = ""; + dnd-inhibited-none = ""; + }; + return-type = "json"; + # exec-if = "which swaync-client"; + exec = "${swaync}/bin/swaync-client -swb"; + on-click = "${swaync}/bin/swaync-client -t -sw"; + on-click-right = "${swaync}/bin/swaync-client -d -sw"; + escape = true; + }; + }; + extraStyle = mkAfter '' + #custom-swaync { + padding: 0 10px; + margin: 0 5px; + background: #F0FFFF; + color: #000000; + } + ''; + }; + }; +in with lib; { + imports = [ notificationModule ]; config = mkIf (config.linux.graphical.type == "wayland") { # Additional packages home.packages = with pkgs; [ @@ -16,24 +78,24 @@ with lib; ]; # Notification system - services.dunst = { - enable = true; - settings.global.follow = "keyboard"; + # services.dunst = { + # enable = true; + # settings.global.follow = "keyboard"; - settings.global.width = "(400, 800)"; - settings.global.notification_limit = 5; + # settings.global.width = "(400, 800)"; + # settings.global.notification_limit = 5; - settings.global.font = "Monospace 12"; + # settings.global.font = "Monospace 12"; - settings.global.dmenu = "${pkgs.bemenu}/bin/bemenu"; - settings.global.browser = "${pkgs.firefox-wayland}/bin/firefox"; + # settings.global.dmenu = "${pkgs.bemenu}/bin/bemenu"; + # settings.global.browser = "${pkgs.firefox-wayland}/bin/firefox"; - settings.global.mouse_left_click = "do_action, close_current"; - settings.global.mouse_right_click = "close_current"; - settings.global.mouse_middle_click = "close_all"; + # settings.global.mouse_left_click = "do_action, close_current"; + # settings.global.mouse_right_click = "close_current"; + # settings.global.mouse_middle_click = "close_all"; - settings.experimental.per_monitor_dpi = "true"; - }; + # settings.experimental.per_monitor_dpi = "true"; + # }; # Forward wallpaper settings to sway programs.my-sway.wallpaper = config.linux.graphical.wallpaper; diff --git a/home/modules/programs/my-sway/default.nix b/home/modules/programs/my-sway/default.nix index 1b0ad0a..3edcb1a 100644 --- a/home/modules/programs/my-sway/default.nix +++ b/home/modules/programs/my-sway/default.nix @@ -7,16 +7,16 @@ let mod = "Mod4"; # List of workspaces workspaces = [ - "1: web" - "2: chat" - "3: code" - "4: music" - "5: extra" - "6: 6" - "7: 7" - "8: 8" - "9: 9" - "10: 10" + "1:🌏 web" + "2:💬 chat" + "3:⚙️ code" + "4:🎶 music" + "5:🔧 extra" + "6:🧰 6" + "7:🔩 7" + "8:🛠️ 8" + "9:🔨 9" + "10:🎲 misc" ]; wsAttrs = builtins.listToAttrs ( map @@ -92,10 +92,25 @@ in description = "Whether to enable mpd on waybar"; default = false; }; + + waybar = { + extraSettings = mkOption { + type = types.attrs; + description = "Additional settings for the default waybar"; + default = { }; + }; + extraStyle = mkOption { + type = types.str; + description = "Additional style for the default waybar"; + default = ""; + }; + }; }; config.wayland.windowManager.sway = mkIf cfg.enable { enable = true; + package = pkgs.unstable.sway; + systemdIntegration = true; config = { ### Inputs @@ -261,6 +276,11 @@ in { class = "^(d|D)iscord$"; } ]; }; + # Commands + window.commands = [ + { criteria = { title = ".*"; }; command = "inhibit_idle fullscreen"; } + ]; + # Focus focus.followMouse = true; focus.mouseWarping = true; focus.newWindow = "urgent"; @@ -271,12 +291,8 @@ in gaps.smartGaps = true; ### Bars - # - # Enable top bar, as waybar - bars = [{ - command = config.programs.waybar.package + "/bin/waybar"; - position = "top"; - }]; + # Let systemd manage it + bars = [ ]; }; ### Misc # @@ -303,24 +319,7 @@ in (if cfg.enableLaptopBars then '' # Lock screen on lid close bindswitch lid:off exec ${cfg.lockCmd} - '' else "") + - '' - # Fix D-Bus starting up - exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK && \ - hash dbus-update-activation-environment 2>/dev/null && \ - dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK && \ - systemctl --user start sway-session.target - ''; - }; - - config.systemd.user.targets.sway-session = mkIf cfg.enable { - Unit = { - Description = "sway compositor session"; - Documentation = [ "man:systemd.special(7)" ]; - BindsTo = [ "graphical-session.target" ]; - Wants = [ "graphical-session-pre.target" ]; - After = [ "graphical-session-pre.target" ]; - }; + '' else ""); }; config.services.swayidle = mkIf cfg.enable { @@ -333,9 +332,10 @@ in config.programs.waybar = mkIf cfg.enable { enable = true; + systemd.enable = true; settings = [ # Top bar - { + (mkMerge [{ position = "top"; modules-left = [ "sway/workspaces" @@ -363,6 +363,9 @@ in ]; modules = { + "sway/workspaces" = { + format = "{name}"; + }; "sway/mode" = { format = "{}"; }; @@ -436,6 +439,7 @@ in tooltip-format-connected = "{controller_alias}\t{controller_address}\n\n{num_connections} connected\n\n{device_enumerate}"; tooltip-format-enumerate-connected = "{device_alias}\t{device_address}"; tooltip-format-enumerate-connected-battery = "{device_alias}\t{device_address}\t{device_battery_percentage}%"; + on-click = "${pkgs.blueman}/bin/blueman-manager"; }; "pulseaudio" = { # scroll-step = 1; @@ -477,6 +481,8 @@ in }; "tooltip-format" = "MPD (connected)"; "tooltip-format-disconnected" = "MPD (disconnected)"; + "on-click" = "${pkgs.mpc_cli}/bin/mpc toggle"; + "on-click-right" = "${pkgs.mpc_cli}/bin/mpc stop"; }; "custom/media" = { "format" = "{icon}{}"; @@ -491,6 +497,7 @@ in }; }; } + cfg.waybar.extraSettings]) ]; style = '' * { @@ -645,7 +652,7 @@ in background-color: teal; color: white; } - ''; + '' + cfg.waybar.extraStyle; }; config.home.packages = mkIf cfg.enable (with pkgs; [ # Needed for QT_QPA_PLATFORM