From fa773ca8cf90b1d0835ee774a7f3f9a515c0a0ec Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Thu, 25 Aug 2022 14:49:31 +0200 Subject: [PATCH] =?UTF-8?q?sway:=20Add=20hack=20for=20mayushii=E2=80=99s?= =?UTF-8?q?=20external=20monitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/simon/modules/sway/default.nix | 32 ++++++++++++++++++++++++++-- users/simon/modules/sway/kanshi.nix | 24 +++------------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/users/simon/modules/sway/default.nix b/users/simon/modules/sway/default.nix index 4c732c5..0d9f966 100644 --- a/users/simon/modules/sway/default.nix +++ b/users/simon/modules/sway/default.nix @@ -26,6 +26,15 @@ let wallpaper = if nixosConfig.sbruder.unfree.allowAssets then wallpaperUnfree else wallpaperFree; cfg = config.wayland.windowManager.sway.config; + + # Due to various issues in sway and drm, + # https://github.com/swaywm/sway/issues/5759 and + # https://gitlab.freedesktop.org/drm/amd/-/issues/1376, + # my external monitor often does not turn on after it has been turned off (DPMS). + # This hack fixes this, by not using kanshi for mayushi + # and instead disabling the internal display based on the lid switch state. + # Taken from https://github.com/swaywm/sway/wiki#clamshell-mode + clamshellHack = nixosConfig.networking.hostName == "mayushii"; in { imports = lib.optionals nixosConfig.sbruder.gui.enable [ @@ -47,7 +56,15 @@ in menu = "${pkgs.dmenu-wayland}/bin/dmenu-wl_path | ${pkgs.dmenu-wayland}/bin/dmenu-wl -nb '#002b36' -nf '#839496' -sb '#859900' -sf '#073642' | ${pkgs.findutils}/bin/xargs swaymsg exec --"; - output."*".bg = "${wallpaper} fill"; + output = { + "*".bg = "${wallpaper} fill"; + } // (lib.optionalAttrs clamshellHack { + "Acer Technologies Acer B277K 0x0000F36C" = { + position = "1920,0"; + scale = "2"; + mode = "3840x2160"; + }; + }); input = { "type:keyboard" = { @@ -246,7 +263,18 @@ in dbus-update-activation-environment --systemd ${environmentVariables} && \ systemctl --user start sway-session.target '' - ); + ) + (lib.optionalString clamshellHack '' + bindswitch --reload --locked lid:on output eDP-1 disable + bindswitch --reload --locked lid:off output eDP-1 enable + + exec_always ${pkgs.writeShellScript "sway-lid-switch-toggle-output" /* bash */ '' + if grep -q open /proc/acpi/button/lid/LID/state; then + swaymsg output eDP-1 enable + else + swaymsg output eDP-1 disable + fi + ''} + ''); }; systemd.user.targets.sway-session = { diff --git a/users/simon/modules/sway/kanshi.nix b/users/simon/modules/sway/kanshi.nix index 12f0c47..78696bd 100644 --- a/users/simon/modules/sway/kanshi.nix +++ b/users/simon/modules/sway/kanshi.nix @@ -6,27 +6,9 @@ let else { }; machineConfigs = { - mayushii = { - standalone.outputs = lib.singleton { - criteria = "eDP-1"; - mode = "1920x1080"; - position = "0,0"; - status = "enable"; - }; - home.outputs = [ - { - criteria = "eDP-1"; - position = "1920,0"; - status = "disable"; - } - { - criteria = "Acer Technologies Acer B277K 0x0000F36C"; - mode = "3840x2160"; - position = "0,0"; - scale = 2.0; - } - ]; - }; + # mayushii is handled separately in sway’s main configuration. + # See it for more details. + # mayushii = { }; sayuri = { home.outputs = lib.singleton { criteria = "Acer Technologies Acer B277K 0x0000F36C";