Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
Sway
https://github.com/swaywm/sway
Admin
Sway is an i3-compatible Wayland compositor for desktop environments.
Tokens:
28,184
Snippets:
398
Trust Score:
7.8
License:
MIT
Update:
2 months ago
Context
Chat
Benchmark
66.94
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Install Sway Dependencies and Build Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Installs necessary development libraries and then builds and installs Sway version 1.4 using Meson and Ninja. ```bash sudo apt install libpcre3-dev libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev xwayland cd ~/sway-src git clone https://github.com/swaywm/sway.git cd sway git checkout 1.4 meson build sudo ninja -C build install ``` -------------------------------- ### Autocreate Backend Example Source: https://github.com/swaywm/sway/blob/master/CONTRIBUTING.md Example function demonstrating how to autocreate a backend, attempting Wayland, X11, and then DRM+libinput. ```c struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { struct wlr_backend *backend; if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) { backend = attempt_wl_backend(display); if (backend) { return backend; } } const char *x11_display = getenv("DISPLAY"); if (x11_display) { return wlr_x11_backend_create(display, x11_display); } // Attempt DRM+libinput struct wlr_session *session = wlr_session_create(display); if (!session) { wlr_log(WLR_ERROR, "Failed to start a DRM session"); return NULL; } int gpu = wlr_session_find_gpu(session); if (gpu == -1) { wlr_log(WLR_ERROR, "Failed to open DRM device"); goto error_session; } backend = wlr_multi_backend_create(session); if (!backend) { goto error_gpu; } struct wlr_backend *libinput = wlr_libinput_backend_create(display, session); if (!libinput) { goto error_multi; } struct wlr_backend *drm = wlr_drm_backend_create(display, session, gpu); if (!drm) { goto error_libinput; } wlr_multi_backend_add(backend, libinput); wlr_multi_backend_add(backend, drm); return backend; error_libinput: wlr_backend_destroy(libinput); error_multi: wlr_backend_destroy(backend); error_gpu: wlr_session_close_file(session, gpu); error_session: wlr_session_destroy(session); return NULL; } ``` -------------------------------- ### Configure HiDPI Scaling Source: https://github.com/swaywm/sway/wiki/Home Example configuration for scaling displays and calculating relative positions for mixed-DPI setups. ```text output HDMI1 scale 2 output HDMI1 pos 0 0 res 3200x1800 output eDP1 pos 1600 0 res 1920x1080 ``` -------------------------------- ### Install Sway from Fedora Official Repository Source: https://github.com/swaywm/sway/wiki/Unsupported-packages Installs Sway from the official Fedora repositories. ```bash sudo dnf install sway ``` -------------------------------- ### Build and Install wlroots from Source Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Clone the wlroots repository, checkout a specific version, configure the build with meson, and install it. ```bash cd ~/sway-src git clone https://github.com/swaywm/wlroots.git cd wlroots git checkout 0.10.0 meson build sudo ninja -C build install ``` -------------------------------- ### Start udevmon Service Source: https://github.com/swaywm/sway/wiki/Tricks Starts the udevmon systemd service immediately. ```bash sudo systemctl start udevmon ``` -------------------------------- ### Build and Install scdoc Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Installs scdoc from source, which is recommended for generating manual pages. Ensure you are in the sway-src directory before cloning. ```bash cd ~/sway-src git clone https://git.sr.ht/~sircmpwn/scdoc cd scdoc git checkout 1.10.1 make PREFIX=/usr/local -j$CPUCOUNT sudo make PREFIX=/usr/local install ``` -------------------------------- ### Install swaybg Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Builds and installs swaybg from source, which is required for the default configuration to function correctly. Ensure you are in the sway-src directory. ```bash cd ~/sway-src git clone https://github.com/swaywm/swaybg.git cd swaybg git checkout 1.0 meson build sudo ninja -C build install ``` -------------------------------- ### Build and Install json-c from Source Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Clone the json-c repository, checkout a specific version, configure the build, compile, and install it to /usr/local. ```bash cd ~/sway-src git clone https://github.com/json-c/json-c.git cd json-c git checkout json-c-0.13.1-20180305 sh autogen.sh ./configure --enable-threading --prefix=/usr/local CPUCOUNT=$(nproc) make -j$CPUCOUNT sudo make install sudo ldconfig ``` -------------------------------- ### Install Sway from Arch Linux Official Repository Source: https://github.com/swaywm/sway/wiki/Unsupported-packages Installs Sway from the official Arch Linux repositories using pacman. ```bash sudo pacman -S sway ``` -------------------------------- ### Install json-c Build Dependencies Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Install autoconf and libtool, which are necessary for building json-c from source. ```bash sudo apt install autoconf libtool ``` -------------------------------- ### Compile and Install wlroots Source: https://github.com/swaywm/sway/wiki/Development-Setup Builds and installs the wlroots Wayland compositor library using Meson and Ninja. This is a prerequisite for compiling Sway. ```sh meson setup build ninja -C build sudo ninja -C build install ``` -------------------------------- ### Bind brightness keys Source: https://github.com/swaywm/sway/wiki/Home Example configuration for brightness control using brightnessctl. ```text bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%- bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+ ``` -------------------------------- ### Install Sway from Nightly Builds Repository Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Add the Sway nightly builds repository and install the sway package. This method provides the latest development version of Sway. ```bash curl -L https://quantum2.xyz/apt.key | sudo apt-key add - echo 'deb [arch=amd64] https://apt.quantum2.xyz/sway-utils/ buster main' | sudo tee /etc/apt/sources.list.d/sway-utils.list sudo apt update sudo apt install sway ``` -------------------------------- ### Install dual-function-keys Plugin (Arch Linux AUR) Source: https://github.com/swaywm/sway/wiki/Tricks Installs the dual-function-keys plugin from the Arch User Repository (AUR) using yay. ```bash yay -S interception-dual-function-keys ``` -------------------------------- ### Install wlroots Dependencies Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Install essential build tools and development libraries required for compiling wlroots. ```bash sudo apt install build-essential cmake libwayland-dev wayland-protocols \ libegl1-mesa-dev libgles2-mesa-dev libdrm-dev libgbm-dev libinput-dev \ libxkbcommon-dev libudev-dev libpixman-1-dev libsystemd-dev libcap-dev \ libxcb1-dev libxcb-composite0-dev libxcb-xfixes0-dev libxcb-xinput-dev \ libxcb-image0-dev libxcb-render-util0-dev libx11-xcb-dev libxcb-icccm4-dev \ freerdp2-dev libwinpr2-dev libpng-dev libavutil-dev libavcodec-dev \ libavformat-dev universal-ctags sudo apt install libelogind-dev libxcb-util0-dev ``` -------------------------------- ### Start Sway with Multiple X11 Outputs Source: https://github.com/swaywm/sway/wiki/Multihead-setup-with-X11-backend Launch Sway with the `WLR_X11_OUTPUTS` environment variable set to the number of monitors you intend to use. ```bash WLR_X11_OUTPUTS=2 sway ``` -------------------------------- ### Install Sway from Debian Official Repository Source: https://github.com/swaywm/sway/wiki/Unsupported-packages Installs the version of Sway available in the official Debian 11 (bullseye) repositories. ```bash sudo apt install sway ``` -------------------------------- ### Install Sway Dependencies on Fedora Source: https://github.com/swaywm/sway/wiki/Development-Setup Installs required development packages for Sway on Fedora using dnf. ```bash dnf install -y git gcc meson ninja-build wayland-devel mesa-libEGL-devel mesa-libGLES-devel mesa-dri-drivers xorg-x11-server-Xwayland libdrm-devel libgbm-devel libxkbcommon-devel libudev-devel pixman-devel libinput-devel libevdev-devel systemd-devel cairo-devel libpcap-devel json-c-devel pam-devel pango-devel pcre-devel gdk-pixbuf2-devel hwdata-devel ``` -------------------------------- ### Install Sway Dependencies on Debian Source: https://github.com/swaywm/sway/wiki/Development-Setup Installs necessary development packages for Sway on Debian-based systems using apt. ```bash apt build-dep sway ``` ```bash apt install glslang-tools libcairo2-dev libcap-dev libdbus-1-dev libdisplay-info-dev libevdev-dev libgdk-pixbuf2.0-dev libinput-dev libjson-c-dev libliftoff-dev libpam0g-dev libpango1.0-dev libpcre2-dev libpixman-1-dev libseat-dev libsystemd-dev libvulkan-dev libwayland-dev libwayland-egl1 libwlroots-dev libxcb-ewmh-dev libxkbcommon-dev meson pkgconf scdoc tree wayland-protocols ``` -------------------------------- ### Configure window borders Source: https://github.com/swaywm/sway/wiki/Home Example configuration rule to remove borders for a specific application. ```sway for_window [app_id="nautilus"] border none ``` -------------------------------- ### Install space2meta Plugin (Arch Linux AUR) Source: https://github.com/swaywm/sway/wiki/Tricks Installs the space2meta plugin from the Arch User Repository (AUR) using yay. ```bash yay -S interception-space2meta ``` -------------------------------- ### Custom XKB Keymap Override Source: https://github.com/swaywm/sway/wiki/Home Example of overriding keymappings for a keyboard and the corresponding XKB symbols file content. ```sway input type:keyboard { # Modified programmer Dvorak. File at ~/.xkb/symbols/dvp_alt_gr_remapped_to_super xkb_layout "dvp_alt_gr_remapped_to_super" # Capslock key should work as escape key # See /usr/share/X11/xkb/rules/xorg.lst for options xkb_options caps:escape repeat_delay 250 repeat_rate 45 } ``` ```xkb default partial alphanumeric_keys xkb_symbols "basic" { include "us(dvp)" name[Group1] = "Modified programmer Dvorak"; key <RALT> { [ Super_L, Super_R ] }; }; ``` -------------------------------- ### Enable udevmon Service Source: https://github.com/swaywm/sway/wiki/Tricks Enables the udevmon systemd service to start automatically on boot. ```bash sudo systemctl enable udevmon.service ``` -------------------------------- ### Install Interception Tools (Arch Linux) Source: https://github.com/swaywm/sway/wiki/Tricks Installs the necessary interception tools package on Arch Linux using pacman. ```bash pacman -S interception-tools ``` -------------------------------- ### HTML Color Picker for Sway (Desktop Entry) Source: https://github.com/swaywm/sway/wiki/Tricks A .desktop file example for launching the HTML color picker script. This allows the color picker to be launched via a desktop file launcher like Rofi. ```desktop [Desktop Entry] Name=HTML Color Picker for Sway Comment=Copies HTML color code to clipboard Encoding=UTF-8 Version=1.0 Keywords= Icon= Exec=$HOME/.local/bin/html-color-picker-for-sway Terminal=false Type=Application StartupNotify=true ``` -------------------------------- ### Compile Sway from Source Source: https://github.com/swaywm/sway/blob/master/README.md Commands to compile Sway from source using Meson and Ninja build systems. Ensure all dependencies are installed before running. ```bash meson setup build/ ninja -C build/ sudo ninja -C build/ install ``` -------------------------------- ### Device-Specific Keyboard Layouts Source: https://github.com/swaywm/sway/wiki/Home Example of applying different keyboard layouts to specific hardware devices. ```sway # default layout input "1:1:AT_Translated_Set_2_keyboard" { xkb_layout us } # custom layout for an external keyboard input "1452:591:Custom_Keyboard" { xkb_layout YourCustomLayout } ``` -------------------------------- ### startup Job Configuration for Sway Source: https://github.com/swaywm/sway/wiki/Startup-(process-manager)-Integration This startup job configuration manages the Sway process, ensuring it starts, stops, and respawns as needed. ```bash # ~/.config/startup/sway.conf start on startup stop on session-end respawn normal exit 0 exec env -u UPSTART_JOB sway ``` -------------------------------- ### Configure Sway to start systemd session Source: https://github.com/swaywm/sway/wiki/systemd-integration Add these commands to your Sway configuration to import environment variables and manage the session target lifecycle. ```bash exec "systemctl --user import-environment {,WAYLAND_}DISPLAY SWAYSOCK; systemctl --user start sway-session.target" exec swaymsg -t subscribe '["shutdown"]' && systemctl --user stop sway-session.target ``` -------------------------------- ### Bemenu Color Scheme Example Source: https://github.com/swaywm/sway/wiki/i3-Migration-Guide Demonstrates how to use bemenu to replicate the color scheme of dmenu. This command sets the prompt, highlighted, and normal text colors. ```bash bemenu-run -p "" --tb "#285577" --hb "#285577" --tf "#eeeeee" --hf "#eeeeee" --nf "#bbbbbb" ``` -------------------------------- ### Disable Display Manager Service Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Disables the graphical display manager (e.g., gdm3) using systemctl to prevent it from starting on boot. This is useful if another desktop environment is installed. ```bash sudo systemctl disable gdm3.service ``` -------------------------------- ### Sway service wrapper script Source: https://github.com/swaywm/sway/wiki/systemd-integration A shell script to import environment variables and start the Sway systemd service. ```sh #! /bin/sh # first import environment variables from the login manager systemctl --user import-environment # then start the service exec systemctl --wait --user start sway.service ``` -------------------------------- ### startup Job Configuration for mako Source: https://github.com/swaywm/sway/wiki/Startup-(process-manager)-Integration This startup job configuration manages the mako notification daemon, ensuring it starts with the Sway session and respawns. ```bash # ~/.config/startup/mako.conf start on sway-session stop on stopping sway respawn reload signal 0 exec mako ``` -------------------------------- ### Start Program on Specific Workspace Source: https://github.com/swaywm/sway/wiki/Tricks Launches a program on a specified workspace and then returns to the previous workspace. This relies on sway correctly matching the PID of the new window to the executed command. ```bash swaymsg 'workspace test; exec gnome-calculator; workspace back_and_forth' ``` -------------------------------- ### Obtain Sway version Source: https://github.com/swaywm/sway/wiki/Home Use these commands to identify the installed version of Sway for bug reports. ```shell swaymsg -t get_version ``` ```shell sway -v ``` -------------------------------- ### Set environment variable in /etc/environment Source: https://github.com/swaywm/sway/wiki/Setting-Environmental-Variables This example sets the QT_QPA_PLATFORMTHEME environment variable to 'qt5ct' system-wide by editing the /etc/environment file. This method affects all users and sessions. ```bash QT_QPA_PLATFORMTHEME=qt5ct ``` -------------------------------- ### Workaround for NVIDIA hybrid setup freezes Source: https://github.com/swaywm/sway/wiki/Home Avoid powering off NVIDIA-attached outputs to prevent deadlocks in the compositor. ```sh timeout 600 'swaymsg "output eDP-1 power off"' resume 'swaymsg "output eDP-1 power on"' ``` -------------------------------- ### Set environment variable in /etc/security/pam_env.conf Source: https://github.com/swaywm/sway/wiki/Setting-Environmental-Variables This example shows how to set the QT_QPA_PLATFORMTHEME environment variable to 'qt5ct' system-wide using the pam_env.conf file. This method affects all users and sessions. ```bash QT_QPA_PLATFORMTHEME DEFAULT=qt5ct ``` -------------------------------- ### Wayland session desktop entry Source: https://github.com/swaywm/sway/wiki/systemd-integration A desktop entry file to allow login managers to start the Sway systemd service. ```ini [Desktop Entry] Name=Sway Service Comment=SirCmpwn's Wayland window manager as a systemd service Exec=sway-service.sh Type=Application ``` -------------------------------- ### Enable Sway Rolling Module on Fedora Source: https://github.com/swaywm/sway/wiki/Unsupported-packages Enables the rolling release module for Sway on Fedora to install a newer version. ```bash sudo dnf module enable sway:rolling sudo dnf install sway ``` -------------------------------- ### Get Specific X11 Window Name Source: https://github.com/swaywm/sway/wiki/Multihead-setup-with-X11-backend Retrieve the name of an X11 window using its ID. ```bash DISPLAY=:0 xdotool getwindowname <window-id> ``` -------------------------------- ### Move Sway X11 Outputs Source: https://github.com/swaywm/sway/wiki/Multihead-setup-with-X11-backend Position Sway's X11 outputs on the unified X11 screen using `xdotool` windowmove. This example assumes two monitors, each 1920 pixels wide. ```bash DISPLAY=:0 xdotool windowmove <window-id-1> 0 0; DISPLAY=:0 xdotool windowmove <window-id-2> 1920 0 ``` -------------------------------- ### Get All X11 Window IDs Source: https://github.com/swaywm/sway/wiki/Multihead-setup-with-X11-backend Use `xdotool` to search for and retrieve the IDs of all windows currently running on the X11 display. ```bash DISPLAY=:0 xdotool search --name '' ``` -------------------------------- ### Get Current Workspace Dimensions Source: https://github.com/swaywm/sway/wiki/Tricks Retrieves the current width and height of the focused workspace using swaymsg and jq. ```bash swaymsg -t get_outputs | jq -r '.. | select(.focused?) | .current_mode | "\(.width)x\(.height)"' ``` -------------------------------- ### Keyboard Repeat Delay and Rate Source: https://github.com/swaywm/sway/wiki/Home Setting the delay before repeat starts and the rate of key repetition. ```sway # or input <identifier> input "type:keyboard" { repeat_delay 500 repeat_rate 5 } ``` -------------------------------- ### Change Default Systemd Target to Multi-User Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Changes the default systemd target from graphical.target to multi-user.target. This will prompt for login at a tty instead of starting a graphical session. ```bash systemctl set-default multi-user.target ``` -------------------------------- ### Initialize Sway Configuration Source: https://github.com/swaywm/sway/wiki/Home Commands to create the configuration directory and copy the default Sway configuration file. ```sh mkdir -p ~/.config/sway cp /etc/sway/config ~/.config/sway/ $EDITOR ~/.config/sway/config ``` -------------------------------- ### Increase Scroll Speed for Specific Apps Source: https://github.com/swaywm/sway/wiki/Tricks This Python script uses i3ipc-python to dynamically increase the scroll speed when applications like Discord or Kitty are focused. It requires the i3ipc-python library to be installed. ```python #!/usr/bin/env python import i3ipc scroll_apps = ['discord', 'kitty'] default_speed = 1 # Reading current value would be nice increased_speed = 6 def on_window_focus(i3, e): v = default_speed window_class = getattr(e.container, 'window_class', None) app_id = getattr(e.container, 'app_id', None) if window_class: c = window_class elif app_id: c = app_id else: return if c in scroll_apps: v = increased_speed i3.command(f'input type:pointer scroll_factor {v}') i3 = i3ipc.Connection() i3.on('window::focus', on_window_focus) i3.main() ``` -------------------------------- ### Compile Sway and wlroots as Subprojects Source: https://github.com/swaywm/sway/wiki/Development-Setup Clones Sway and wlroots repositories, sets up the build environment with Meson, and compiles both projects. ```bash # Clone repositories git clone https://github.com/swaywm/sway.git cd sway git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots # Build sway and wlroots meson setup build/ ninja -C build/ # Start sway build/sway/sway ``` -------------------------------- ### SwayWM Config: Caps Lock as $mod Source: https://github.com/swaywm/sway/wiki/i3-Migration-Guide Configure SwayWM to use Caps Lock as the primary modifier key ($mod) and map it to Escape. This setup allows for one-handed desktop switching and Vim's Normal mode access. ```ini set $mod Escape # main modifier variable used in bindsym commands floating_modifier Mod4 # to avoid config parse error … input "type:keyboard" { … xkb_options caps:escape,… ``` -------------------------------- ### Load Custom XKB Keymap File Source: https://github.com/swaywm/sway/wiki/Home Loading a custom XKB keymap file from a specific path. ```sway # or input <identifier> input "type:keyboard" { xkb_file ~/.config/xkb/custom } ``` -------------------------------- ### Create Sway Source Directory Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Create a dedicated directory to organize the source code for building Sway and its dependencies. ```bash mkdir ~/sway-src ``` -------------------------------- ### Inject Sway Session Information into startup Source: https://github.com/swaywm/sway/wiki/Startup-(process-manager)-Integration Add these commands to your Sway configuration to inject necessary session information into startup, allowing other startup jobs to connect to Sway. ```bash exec initctl set-env --global SWAYSOCK="$SWAYSOCK" exec initctl set-env --global I3SOCK="$I3SOCK" exec initctl set-env --global WAYLAND_DISPLAY="$WAYLAND_DISPLAY" # include only if xwayland is enabled and startup jobs need to access X exec initctl set-env --global DISPLAY="$DISPLAY" exec initctl emit sway-session ``` -------------------------------- ### Configure Preferred XDG Desktop Portals Source: https://github.com/swaywm/sway/wiki/XDG-Desktop-Portal-configuration Create or modify `~/.config/xdg-desktop-portal/sway-portals.conf` to specify preferred portal backends for default actions, screenshots, and screen casting. ```ini [preferred] default=gtk org.freedesktop.impl.portal.Screenshot=wlr org.freedesktop.impl.portal.ScreenCast=wlr ``` -------------------------------- ### startup Job Configuration for swaybg Source: https://github.com/swaywm/sway/wiki/Startup-(process-manager)-Integration This startup job configuration manages the swaybg process for setting the background, ensuring it respawns. ```bash # ~/.config/startup/swaybg.conf start on swaybg stop on stopping sway respawn exec swaybg -o '*' -i /usr/share/backgrounds/default -m fill ``` -------------------------------- ### Define sway-session.target unit file Source: https://github.com/swaywm/sway/wiki/systemd-integration Create this unit file at ~/.config/systemd/user/sway-session.target or /etc/systemd/user/sway-session.target to define the sway session target. ```ini [Unit] Description=sway compositor session Documentation=man:systemd.special(7) BindsTo=graphical-session.target Wants=graphical-session-pre.target After=graphical-session-pre.target ``` -------------------------------- ### Run Sway with seatd-launch Source: https://github.com/swaywm/sway/wiki/Running-Sway-with-seatd,-elogind-or-systemd‐logind Use seatd-launch to run Sway with a dedicated seatd instance. This instance will stop when Sway exits. ```shell seatd-launch -- sway ``` -------------------------------- ### Take Screenshot and Open in Annotation Tool (Desktop Entry) Source: https://github.com/swaywm/sway/wiki/Tricks Provides actions to take screenshots of the current window, output, a selected window, or a selected area, and then opens them in the Swappy annotation tool. This configuration is intended for a .desktop file. ```desktop [Desktop Entry] Name=Swappy GenericName=Annotation Tool GenericName[de]=Anmerkungswerkzeug GenericName[fr]="Outil d'annotat" GenericName[pt_BR]=Ferramenta de Anotação Comment=A Wayland native snapshot editing tool Comment[de]=Ein natives Wayland Bildschirmfoto-Bearbeitungswerkzeug Comment[fr]="Un outil d'édition de capture d'écran avec support natif pour Wayland" Comment[pt_BR]=Uma ferramenta de edição de snapshot nativa do Wayland TryExec=swappy Exec=swappy -f %F Terminal=false Type=Application Keywords=wayland;snapshot;annotation;editing; Icon=swappy Categories=Utility;Graphics;Annotation; StartupNotify=true MimeType=image/png;image/jpeg; Actions=current-window;current-output;select-window;select-area; [Desktop Action current-window] Name=Current Window Exec=sh -c 'grimshot save active - | swappy -f -' [Desktop Action current-output] Name=Current Output Exec=sh -c 'grimshot save output - | swappy -f -' [Desktop Action select-window] Name=Select Window Exec=sh -c 'grimshot save window - | swappy -f -' [Desktop Action select-area] Name=Select Area Exec=sh -c 'grimshot save area - | swappy -f -' ``` -------------------------------- ### startup Job Configuration for swayidle Source: https://github.com/swaywm/sway/wiki/Startup-(process-manager)-Integration This configuration manages swayidle, emitting events for idle and active states, and respawning the process. ```bash # ~/.config/startup/swayidle.conf start on sway-session stop on stopping sway emits swayidle emits swayactive env TIME=60 respawn exec swayidle timeout "$TIME" 'initctl emit -n swayidle' \ resume 'initctl emit -n swayactive' ``` -------------------------------- ### Set Qt5 Wayland Platform Source: https://github.com/swaywm/sway/wiki/Running-programs-natively-under-Wayland Manually set the Qt5 platform to use Wayland if `XDG_SESSION_TYPE=wayland` is not automatically detected. ```shell QT_QPA_PLATFORM=wayland-egl ``` -------------------------------- ### Configure Sway wallpaper Source: https://github.com/swaywm/sway/wiki/Home Use the output command with the bg option to set a wallpaper on a specific display. ```text output HDMI-A-1 bg ~/wallpaper.png stretch ``` -------------------------------- ### Configure urxvt transparency Source: https://github.com/swaywm/sway/wiki/Home Settings for .Xresources to enable real transparency in urxvt. ```text URxvt*depth: 32 URxvt*background: rgba:0000/0000/0200/c800 ``` -------------------------------- ### Implement window marking and switching modes Source: https://github.com/swaywm/sway/wiki/Home Defines modes for marking windows and switching focus to them using numeric keys. ```sway # window switch setting set $mode_set_switch_window "set_switch_window: [0]-[9]" mode $mode_set_switch_window { bindsym 1 mark 1; mode "default" bindsym 2 mark 2; mode "default" bindsym 3 mark 3; mode "default" bindsym 4 mark 4; mode "default" bindsym 5 mark 5; mode "default" bindsym 6 mark 6; mode "default" bindsym 7 mark 7; mode "default" bindsym 8 mark 8; mode "default" bindsym 9 mark 9; mode "default" bindsym 0 mark 0; mode "default" bindsym Return mode "default" bindsym Escape mode "default" } bindsym $mod+ctrl+t mode $mode_set_switch_window set $mode_switch_window "switch_window: [0]-[9]" mode $mode_switch_window { bindsym 1 [con_mark="1"] focus; mode "default" bindsym 2 [con_mark="2"] focus; mode "default" bindsym 3 [con_mark="3"] focus; mode "default" bindsym 4 [con_mark="4"] focus; mode "default" bindsym 5 [con_mark="5"] focus; mode "default" bindsym 6 [con_mark="6"] focus; mode "default" bindsym 7 [con_mark="7"] focus; mode "default" bindsym 8 [con_mark="8"] focus; mode "default" bindsym 9 [con_mark="9"] focus; mode "default" bindsym 0 [con_mark="0"] focus; mode "default" bindsym t mode $mode_set_switch_window bindsym Return mode "default" bindsym Escape mode "default" } bindsym $mod+t mode $mode_switch_window ``` -------------------------------- ### Enable Wayland for LibreOffice Source: https://github.com/swaywm/sway/wiki/Running-programs-natively-under-Wayland If LibreOffice does not default to Wayland, try setting this environment variable to use the GTK3 VCL plugin. ```shell SAL_USE_VCLPLUGIN=gtk3 ``` -------------------------------- ### Configure Clamshell Mode Source: https://github.com/swaywm/sway/wiki/Home Configuration for handling laptop lid events and a script to manage display states on reload. ```text set $laptop <laptop_output_identifier> bindswitch --reload --locked lid:on output $laptop disable bindswitch --reload --locked lid:off output $laptop enable ``` ```sh #!/bin/sh LAPTOP_OUTPUT="<LAPTOP>" LID_STATE_FILE="/proc/acpi/button/lid/LID0/state" read -r LS < "$LID_STATE_FILE" case "$LS" in *open) swaymsg output "$LAPTOP_OUTPUT" enable ;; *closed) swaymsg output "$LAPTOP_OUTPUT" disable ;; *) echo "Could not get lid state" >&2 ; exit 1 ;; esac ``` ```text exec_always /path/to/script.sh ``` -------------------------------- ### Add Unofficial Sway Nightly Repository for Debian 10 (Buster) Source: https://github.com/swaywm/sway/wiki/Unsupported-packages Adds a nightly build repository for Sway compatible with Debian 10 (buster). Requires curl and apt-key. ```bash curl https://quantum2.xyz/apt.key | sudo apt-key add - echo 'deb [arch=amd64] https://apt.quantum2.xyz/sway-utils/ buster main' | sudo tee /etc/apt/sources.list.d/sway-utils.list sudo apt update sudo apt install sway ``` -------------------------------- ### Execute GTK Settings Import in Sway Config Source: https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland This line in your sway configuration executes the `import-gsettings` script, applying the theme, icon, and cursor settings defined in your settings.ini file. Ensure the script is saved and executable before adding this line. ```bash exec_always import-gsettings ``` -------------------------------- ### Libinput Configuration Options Source: https://github.com/swaywm/sway/wiki/Home Common libinput settings for pointer devices, including acceleration and tap-to-click. ```sway input <device name> { left_handed enabled tap enabled natural_scroll disabled dwt enabled accel_profile "flat" # disable mouse acceleration (enabled by default; to set it manually, use "adaptive" instead of "flat") pointer_accel 0.5 # set mouse sensitivity (between -1 and 1) } ``` -------------------------------- ### Execute Polkit Authentication Agent Source: https://github.com/swaywm/sway/wiki/Home Add this command to your Sway configuration to enable Polkit authentication for administrative tasks. ```bash exec "/usr/libexec/polkit-gnome-authentication-agent-1" ``` -------------------------------- ### Configure Multihead Displays Source: https://github.com/swaywm/sway/wiki/Home Commands to set resolution and position for multiple monitors, along with setting the initial focus. ```text output HDMI1 resolution 1920x1080 position 0 0 output eDP1 resolution 1600x900 position 1920 0 ``` ```text focus output <name-or-identifier> ``` ```text exec swaymsg focus output <name-or-identifier> ``` -------------------------------- ### Configure Xwayland DPI settings Source: https://github.com/swaywm/sway/wiki/Home Set a fixed DPI for Xwayland applications to resolve scaling issues on HiDPI screens. ```text Xft.dpi: 96 ``` ```sh exec xrdb -load ~/.Xresources ``` -------------------------------- ### Enable Contrib and Non-Free Repositories Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Modify the apt sources list to include the 'contrib' and 'non-free' components, which may be required for certain dependencies. ```bash sudo sed -i -e 's/main$/main contrib non-free/g' /etc/apt/sources.list ``` -------------------------------- ### Build Sway Dependencies as Subprojects Source: https://github.com/swaywm/sway/wiki/Development-Setup Clones common Sway dependencies as subprojects to build them alongside Sway when system versions are outdated. ```bash git clone https://gitlab.freedesktop.org/wayland/wayland.git subprojects/wayland git clone https://gitlab.freedesktop.org/wayland/wayland-protocols.git subprojects/wayland-protocols git clone https://gitlab.freedesktop.org/emersion/libdisplay-info.git subprojects/libdisplay-info git clone https://gitlab.freedesktop.org/emersion/libliftoff.git subprojects/libliftoff git clone https://gitlab.freedesktop.org/mesa/drm.git subprojects/libdrm git clone https://git.sr.ht/~kennylevinsen/seatd subprojects/seatd ``` -------------------------------- ### Configure udev rules for persistent GPU paths Source: https://github.com/swaywm/sway/wiki/Home Create symlinks for graphics cards to ensure consistent paths when using eGPUs or variable hardware configurations. ```udev KERNEL=="card*", SUBSYSTEM=="drm", ATTRS{vendor}=="0x1002", ATTRS{device}=="0x747e", SYMLINK+="dri/by-name/egpu" KERNEL=="card*", SUBSYSTEM=="drm", ATTRS{vendor}=="0x1002", ATTRS{device}=="0x1681", SYMLINK+="dri/by-name/igpu" ``` ```sh WLR_DRM_DEVICES=/dev/dri/by-name/egpu:/dev/dri/by-name/igpu ``` -------------------------------- ### Launch sway with ConsoleKit2 Source: https://github.com/swaywm/sway/wiki/Home Command to launch sway when not using logind. ```sh exec ck-launch-session dbus-launch --sh-syntax --exit-with-session sway ``` -------------------------------- ### Configure spacetomod4.yaml for Dual-Function Keys Source: https://github.com/swaywm/sway/wiki/Tricks Configuration file for the dual-function-keys plugin, defining tap and hold behavior for the space key. ```yaml TIMING: TAP_MILLISEC: 200 DOUBLE_TAP_MILLISEC: 0 MAPPINGS: - KEY: KEY_SPACE TAP: KEY_SPACE HOLD: KEY_LEFTMETA ``` -------------------------------- ### Upload Screenshot and Copy URL Source: https://github.com/swaywm/sway/wiki/Tricks Takes a screenshot of a selected area, uploads it to 0x0.st, copies the resulting URL to the clipboard, and displays a notification. ```bash bindsym $mod+Shift+Print exec slurp | grim -g - - | curl --form 'file=@-' http://0x0.st | wl-copy && swaynag -m "screenshot uploaded & url copied to clipboard" ``` -------------------------------- ### Load environment variables from environment.d Source: https://github.com/swaywm/sway/wiki/systemd-integration Use this snippet in a Sway startup wrapper script to parse and export environment variables generated by systemd's environment-d-generator. ```sh #!/bin/bash ... # Environment while read -r l; do eval export $l done < <(/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator) ... ``` -------------------------------- ### Enable Wayland for SDL2 Source: https://github.com/swaywm/sway/wiki/Running-programs-natively-under-Wayland Set this environment variable to force SDL2 to use the Wayland video driver instead of Xwayland. ```shell SDL_VIDEODRIVER=wayland ``` -------------------------------- ### startup Job Configuration for Swaylock Source: https://github.com/swaywm/sway/wiki/Startup-(process-manager)-Integration This startup job configuration launches swaylock when a sleep event is emitted, ensuring the screen is locked during sleep. ```bash # ~/.config/startup/swaylock.conf start on sleep stop on stopping sway respawn normal exit 0 exec swaylock ``` -------------------------------- ### Launch JetBrains IDE with custom JRE Source: https://github.com/swaywm/sway/wiki/Home Instructs a JetBrains IDE to use a specific Java Runtime Environment version. ```shell STUDIO_JDK=/usr/lib/jvm/java-11-openjdk-amd64/ /opt/android-studio/bin/studio.sh ``` -------------------------------- ### Configure Display Output Source: https://github.com/swaywm/sway/wiki/Home Basic syntax for defining output modes within the Sway configuration file. ```text output <identifier> { # ...config options... mode 3840x1600@143.998Hz } ``` -------------------------------- ### Configure Keyboard Options in SwayWM Source: https://github.com/swaywm/sway/wiki/i3-Migration-Guide Replaces the X11 'setxkbmap' command with SwayWM's input configuration for keyboard options. This allows setting options like 'terminate:ctrl_alt_bksp', 'caps:super', and 'altwin:menu_win'. ```ini input "type:keyboard" { xkb_options terminate:ctrl_alt_bksp,caps:super,altwin:menu_win } ``` -------------------------------- ### Add Unofficial Sway Nightly Repository for Debian 11 (Bullseye) Source: https://github.com/swaywm/sway/wiki/Unsupported-packages Adds a nightly build repository for Sway compatible with Debian 11 (bullseye). Requires curl and apt-key. ```bash curl https://quantum2.xyz/apt.key | sudo apt-key add - echo 'deb [arch=amd64] https://apt.quantum2.xyz/sway-utils/ bullseye main' | sudo tee /etc/apt/sources.list.d/sway-utils.list sudo apt update sudo apt install sway ``` -------------------------------- ### Create Systemd Service for udevmon Source: https://github.com/swaywm/sway/wiki/Tricks Systemd service file content to manage the udevmon process for input device monitoring. ```ini [Unit] Description=Monitor input devices for launching tasks Wants=systemd-udev-settle.service After=systemd-udev-settle.service Documentation=man:udev(7) [Service] ExecStart=/usr/bin/udevmon -c /etc/interception/udevmon.yaml Nice=-20 Restart=on-failure OOMScoreAdjust=-1000 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Keyboard Layout and Variant Configuration Source: https://github.com/swaywm/sway/wiki/Home Configuring multiple layouts and variants for keyboards, with options to toggle between them. ```sway # or input <identifier> input "type:keyboard" { xkb_layout us,de xkb_variant ,nodeadkeys xkb_options grp:alt_shift_toggle } ``` -------------------------------- ### Configure Android Studio and Gradle Environment Variables Source: https://github.com/swaywm/sway/wiki/Home Set these environment variables to resolve menu placement issues in Android Studio and ensure correct Java versions for Gradle. ```sh # For Android Studio export _JAVA_AWT_WM_NONREPARENTING=1 export STUDIO_JDK=/usr/lib/jvm/java-14-openjdk # For Gradle export JAVA_HOME=/usr/lib/jvm/java-8-openjdk ``` -------------------------------- ### Run Flatpak Applications with Wayland Socket Source: https://github.com/swaywm/sway/wiki/Running-programs-natively-under-Wayland Use this command to run a Flatpak application with Wayland support enabled via a socket. The `--user` flag can be used for user-specific overrides. ```shell flatpak [--user] run --socket=wayland your-app ``` -------------------------------- ### Move all workspace windows configuration Source: https://github.com/swaywm/sway/wiki/Home Defines a mode to move all windows from the current workspace to a target workspace number. Triggered via a keybinding to enter the mode. ```sway set $mode_move_all_workspace_windows "Move all workspace windows to [0-9]?" mode $mode_move_all_workspace_windows { bindsym 1 [workspace=".*"] move to workspace 1; workspace number 1, mode "default" bindsym 2 [workspace=".*"] move to workspace 2; workspace number 2, mode "default" bindsym 3 [workspace=".*"] move to workspace 3; workspace number 3, mode "default" bindsym 4 [workspace=".*"] move to workspace 4; workspace number 4, mode "default" bindsym 5 [workspace=".*"] move to workspace 5; workspace number 5, mode "default" bindsym 6 [workspace=".*"] move to workspace 6; workspace number 6, mode "default" bindsym 7 [workspace=".*"] move to workspace 7; workspace number 7, mode "default" bindsym 8 [workspace=".*"] move to workspace 8; workspace number 8, mode "default" bindsym 9 [workspace=".*"] move to workspace 9; workspace number 9, mode "default" bindsym 0 [workspace=".*"] move to workspace 10; workspace number 10, mode "default" # back to normal: Enter or Escape bindsym Return mode "default" bindsym Escape mode "default" } bindsym $mod+shift+ctrl+m mode $mode_move_all_workspace_windows ``` -------------------------------- ### Redirect Sway output to journald Source: https://github.com/swaywm/sway/wiki/systemd-integration Use systemd-cat to pipe Sway's output into the systemd journal. ```bash exec systemd-cat --identifier=sway sway ``` -------------------------------- ### Configure wl-clipboard and clipman for Clipboard Management Source: https://github.com/swaywm/sway/wiki/Tricks Sets up automatic storage of clipboard content using wl-paste and clipman, and defines keybinds for picking, clearing, and managing clippings. ```ini exec wl-paste -t text --watch clipman store exec wl-paste -p -t text --watch clipman store bindsym $mod+y exec clipman --primary pick --tool rofi bindsym $mod+Shift+y exec clipman clear -a bindsym $mod+Mod1+y exec clipman clear --tool rofi bindsym $mod+Ctrl+y exec : | wl-copy -p ``` -------------------------------- ### Nix Shell for Sway Dependencies Source: https://github.com/swaywm/sway/wiki/Development-Setup Uses nix-shell to acquire all necessary packages for Sway development from nixpkgs-unstable, disabling default hardening. ```bash nix-shell -p cairo cmake gdk-pixbuf glslang hwdata json_c lcms libGL libcap libdisplay-info libdrm libevdev libgbm libinput libliftoff libxkbcommon mesa meson ninja pango pcre2 pixman pkg-config scdoc seatd tree vulkan-loader wayland wayland-protocols wayland-scanner xorg.xcbutilerrors xorg.xcbutilrenderutil xorg.xcbutilwm xwayland -I nixpkgs=http://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz --command "export NIX_HARDENING_ENABLE=; return" ``` -------------------------------- ### Set Environment for dbus-broker Source: https://github.com/swaywm/sway/wiki/XDG-Desktop-Portal-configuration Use this command when `dbus-broker` is the active dbus implementation to set necessary environment variables for Wayland display and desktop environment. ```sh exec systemctl --user set-environment "WAYLAND_DISPLAY=${WAYLAND_DISPLAY}" "XDG_CURRENT_DESKTOP=${XDG_CURRENT_DESKTOP:-sway:wlroots}" ``` -------------------------------- ### List Systemd Target Dependencies Source: https://github.com/swaywm/sway/wiki/Debian-10-(Buster)-Installation Lists all services that are dependencies of the graphical.target. This is useful for identifying critical services before changing the default target to multi-user.target. ```bash $ systemctl list-dependencies graphical.target ``` -------------------------------- ### Generic Input Configuration Block Source: https://github.com/swaywm/sway/wiki/Home Template for defining configuration options for a specific input device identifier. ```sway input <identifier> { # ...config options... } ``` -------------------------------- ### Configure Sway as a systemd user service Source: https://github.com/swaywm/sway/wiki/systemd-integration Defines a systemd service to launch Sway, intended for environments without a display manager. ```ini [Unit] Description=sway - SirCmpwn's Wayland window manager Documentation=man:sway(5) BindsTo=default.target Wants=default.target After=default.target [Install] WantedBy=default.target [Service] Type=simple EnvironmentFile=-%h/.config/sway/env ExecStart=/usr/bin/sway Restart=on-failure RestartSec=1 TimeoutStopSec=10 ``` -------------------------------- ### Configure Sway Bar for Overlay Mode and Transparency Source: https://github.com/swaywm/sway/wiki/Tricks Sway bar configuration to use overlay mode, hide workspace buttons, and set a transparent background for a minimalist look. ```ini bar { position top mode overlay status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done workspace_buttons no colors { statusline #ffffff background #ffffff10 inactive_workspace #32323200 #32323200 #5c5c5c } } ``` -------------------------------- ### Configure launcher shortcut Source: https://github.com/swaywm/sway/wiki/Home Toggles an application launcher on a single keypress, excluding cases where the key is part of another binding. ```sway bindsym --no-repeat --release Super_L exec pkill $launcher || $launcher ``` -------------------------------- ### elogind-inhibit Configuration for Sleep Detection Source: https://github.com/swaywm/sway/wiki/Startup-(process-manager)-Integration This startup job configuration uses elogind inhibitors to detect and manage sleep events, pausing the session when sleep is imminent. ```bash # ~/.config/startup/elogind-inhibit.conf start on startup or dbus SIGNAL='PrepareForSleep' ARG0='FALSE' BUS='system' INTERFACE='org.freedesktop.login1.Manager' stop on session-end or dbus SIGNAL='PrepareForSleep' ARG0='TRUE' BUS='system' INTERFACE='org.freedesktop.login1.Manager' respawn exec elogind-inhibit --what=sleep --who=startup --mode=delay --why="Session Sleep Hook" -- pause pre-stop exec initctl emit sleep ``` -------------------------------- ### Add /usr/local/bin to PATH Source: https://github.com/swaywm/sway/wiki/Development-Setup Ensures the /usr/local/bin directory is included in your system's PATH environment variable. Add this to your ~/.profile if it's not already present. ```sh export PATH=/usr/local/bin:$PATH ``` -------------------------------- ### Sway systemd user service unit file Source: https://github.com/swaywm/sway/wiki/systemd-integration A systemd unit file configuration for running Sway. Place this in ~/.config/systemd/user/sway.service or /etc/systemd/user/sway.service. ```ini [Unit] Description=sway - SirCmpwn's Wayland window manager Documentation=man:sway(5) BindsTo=graphical-session.target Wants=graphical-session-pre.target After=graphical-session-pre.target [Service] Type=simple EnvironmentFile=-%h/.config/sway/env ExecStartPre=systemctl --user unset-environment WAYLAND_DISPLAY DISPLAY # This line make you able to logout to dm and login into sway again ExecStart=/usr/bin/sway Restart=on-failure RestartSec=1 TimeoutStopSec=10 ``` -------------------------------- ### Enable Sanitizers for Sway Build Source: https://github.com/swaywm/sway/wiki/Development-Setup Adds AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan) to the Meson build configuration. ```bash meson setup build/ -Db_sanitize=address,undefined ``` -------------------------------- ### Basic Key Binding with Keysyms Source: https://github.com/swaywm/sway/wiki/Shortcut-handling Binds a key combination to execute a command. The keysyms are case-insensitive. ```shell bindsym Ctrl+Shift+1 kill ``` ```shell bindsym Ctrl+exclam kill ``` ```shell bindsym Ctrl+q+p exit ``` ```shell bindsym Ctrl+p+q exit ``` ```shell bindsym Mod5+R reload ``` ```shell bindsym Mod5+r reload ``` ```shell bindsym Mod5+Shift+R reload ``` -------------------------------- ### Automate Sway X11 Output Positioning Source: https://github.com/swaywm/sway/wiki/Multihead-setup-with-X11-backend A bash script to automate the process of finding and positioning two Sway X11 outputs based on their names. It assumes a 1920-pixel width for each monitor. ```bash #!/bin/bash windows=$(DISPLAY=:0 xdotool search --name '') win1='' win2='' for win in $windows do name=$(DISPLAY=:0 xdotool getwindowname $win) if [[ $name == "wlroots - X11-1" ]] then win1=$win elif [[ $name == "wlroots - X11-2" ]] then win2=$win fi done DISPLAY=:0 xdotool windowmove $win1 1920 0 DISPLAY=:0 xdotool windowmove $win2 0 0 ``` -------------------------------- ### Configure Waybar as a systemd user service Source: https://github.com/swaywm/sway/wiki/systemd-integration Manages the Waybar status bar lifecycle by binding it to the graphical session target. ```ini # ~/.config/systemd/user/waybar.service or /etc/systemd/user/waybar.service [Unit] Description=Highly customizable Wayland bar for Sway and Wlroots based compositors. Documentation=https://github.com/Alexays/Waybar/wiki/ PartOf=graphical-session.target [Service] Type=simple ExecStart=/usr/bin/waybar [Install] WantedBy=sway-session.target ``` -------------------------------- ### Import GTK Settings from settings.ini Source: https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland This script imports GTK theme, icon theme, cursor theme, and font name settings from your GTK 3 settings.ini file into gsettings. It's useful if you prefer managing these settings in a single file. Ensure the script is executable and placed in a location accessible by your system. ```bash #!/bin/sh # usage: import-gsettings config="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-3.0/settings.ini" if [ ! -f "$config" ]; then exit 1; fi gnome_schema="org.gnome.desktop.interface" gtk_theme="$(grep 'gtk-theme-name' "$config" | sed 's/.*\s*=\s*//')" icon_theme="$(grep 'gtk-icon-theme-name' "$config" | sed 's/.*\s*=\s*//')" cursor_theme="$(grep 'gtk-cursor-theme-name' "$config" | sed 's/.*\s*=\s*//')" font_name="$(grep 'gtk-font-name' "$config" | sed 's/.*\s*=\s*//')" gsettings set "$gnome_schema" gtk-theme "$gtk_theme" gsettings set "$gnome_schema" icon-theme "$icon_theme" gsettings set "$gnome_schema" cursor-theme "$cursor_theme" gsettings set "$gnome_schema" font-name "$font_name" ```