added compatibility with sway

This commit is contained in:
Jürg Hallenbarter
2026-02-09 11:42:36 +00:00
parent 91b07e4589
commit 1a8b6dc83b
12 changed files with 341 additions and 132 deletions

184
README.md
View File

@@ -1,66 +1,33 @@
# MyI3Repo
# MyI3Config
This repository contains a very minimal and practical **i3 window manager** configuration.
It is designed to stay close to upstream i3 behavior while adding a few convenience features
for daily use.
The goal is:
- Predictable tiling behavior
- Keyboard-driven workflow
- Minimal visual noise
- Easy extensibility via simple shell scripts
No external theming frameworks or heavy abstractions are used.
---
## Concept: Application Settings
All user-configurable applications are defined inside the `settings/` directory.
Each file contains **only the binary name**, for example:
```sh
firefox
```
The i3 config itself handles the `exec` logic and simply reads these files.
This keeps configuration clean and avoids hardcoding application names.
If an application does not exist on the system, the installer will warn the user.
A minimal, practical window manager configuration that supports both **i3 (X11)** and **Sway (Wayland)**. The configuration is designed to stay close to upstream behavior while adding convenience features for daily use.
---
## Features
- i3 (X11) based setup
- Focus follows mouse
- Simple, readable keybindings
- Keyboard layout switching (e.g. `ch_de``us_workman`)
- Keyboard-driven window movement and resizing
- Minimal logout / power overlay
- Multi-monitor friendly (`xrandr`)
- No hidden logic or frameworks
- **Dual compatibility**: Works with both i3 (X11) and Sway (Wayland)
- **Focus follows mouse**: Natural window focus behavior
- **Keyboard-driven workflow**: All common actions accessible via keyboard
- **Minimal visual noise**: No bars, no bloat, just windows
- **Environment-aware scripts**: Auto-detect i3 vs Sway and use appropriate tools
- **Easy extensibility**: Simple shell scripts for customization
- **Unified configuration**: One config file for both window managers
---
## Required Packages (Arch Linux)
## Structure
### Core
- `i3-wm`
- `xorg-server`
- `xorg-xinit`
- `dmenu` or `rofi`
### Utilities
- `xrandr`
- `setxkbmap`
- `picom` (optional)
- `feh` (optional)
- `playerctl` (optional)
- `brightnessctl` (optional)
---
```
MyI3Config/
├── i3/ # i3-specific configuration and scripts
├── scripts/ # Environment-aware scripts (work in both i3/Sway)
├── settings/ # User application preferences
├── install.sh # Smart installer with i3/Sway detection
├── packages-common.txt # Packages shared by both i3 and Sway
├── packages-i3.txt # i3-specific packages (X11)
└── packages-sway.txt # Sway-specific packages (Wayland)
```
## Installation
@@ -71,8 +38,6 @@ git clone https://github.com/JGH0/MyI3Config.git
cd MyI3Config
```
---
### 2. Run the installer
```bash
@@ -81,40 +46,101 @@ cd MyI3Config
The installer will:
- Ask if you want to install the i3 configuration
- Copy the config to `~/.config/i3`
- Ask which terminal, browser, file manager, and calculator you want to use
- Validate that the chosen applications exist
- Write the selected application names into `settings/*.sh`
1. **Detect your environment**: Auto-detects if you're running i3 or Sway (or lets you choose)
2. **Install packages**: Installs only the necessary packages for your chosen window manager
3. **Configure applications**: Lets you choose your preferred terminal, browser, file manager, and calculator
4. **Set up configuration**: Copies files to `~/.config/MyI3Config` and creates appropriate symlinks
If an application is not found, you will be asked again.
## Package Management
---
The repository uses three package lists for clean dependency management:
### 3. Log into i3
- **`packages-common.txt`**: Applications that work on both i3 and Sway
- `rofi`, `brightnessctl`, `playerctl`, etc.
- **`packages-i3.txt`**: i3/X11 specific packages
- `i3-wm`, `xorg-server`, `maim`, `xclip`, `i3lock`, etc.
- **`packages-sway.txt`**: Sway/Wayland specific packages
- `sway`, `grim`, `slurp`, `wl-clipboard`, `swaylock`, etc.
When starting i3 for the first time:
- **Do NOT generate a new config**
- Use the installed configuration
## Environment-Aware Scripts
---
The `scripts/` directory contains smart scripts that detect whether they're running under i3 or Sway and use the appropriate tools:
## packages.txt
- **`screenshot.sh`**: Uses `maim` + `xclip` on i3, `grim` + `wl-copy` on Sway
- **`display-tool.sh`**: Launches `arandr` on i3, `wdisplays` on Sway
- **`lock.sh`**: Uses `i3lock` on i3, `swaylock` on Sway
- **`keyboard-setup.sh`**: Uses `setxkbmap` on i3, `swaymsg input` on Sway
- **`startup.sh`**: Runs appropriate startup commands for each environment
The `packages.txt` file contains a suggested list of packages you may want to install.
It is intentionally not installed automatically to keep full user control.
## Application Settings
Example:
All user-configurable applications are defined in the `settings/` directory. Each file contains only the binary name, for example:
```bash
sudo pacman -S --needed - < packages.txt
```sh
# settings/terminal.sh
kitty
```
The configuration reads these files, keeping your app choices separate from keybindings.
## Switching Between i3 and Sway
If you want to use both window managers:
1. **Run the installer twice**: Once selecting i3, once selecting Sway
2. **Both configs will be installed**: The installer creates symlinks to the same config file
3. **Log out and switch**: Choose your window manager from your display manager
**Note**: The configuration file is written in i3 syntax but uses environment-aware scripts to handle differences between i3 and Sway.
## Keybindings (Common to Both)
| Key Combination | Action |
|----------------|--------|
| `Super + Return` | Terminal |
| `Super + b` | Browser |
| `Super + e` | File manager |
| `Super + Ctrl + c` | Calculator |
| `Super + Ctrl + Return` | Application launcher (rofi) |
| `Super + 1-0` | Switch workspaces |
| `Super + Shift + 1-0` | Move window to workspace |
| `Super + q` | Close window |
| `Super + f` | Toggle fullscreen |
| `Super + Shift + s` | Take screenshot |
| `Super + l` | Lock screen |
| `Super + space` | Toggle keyboard layout |
| `Super + Shift + c` | Reload configuration |
| `Super + Shift + r` | Restart window manager |
## Customization
1. **Application preferences**: Edit files in `~/.config/MyI3Config/settings/`
2. **Keybindings**: Edit `~/.config/MyI3Config/i3/config`
3. **Scripts**: Modify `~/.config/MyI3Config/scripts/` for custom behavior
4. **Package lists**: Update the `packages-*.txt` files to add/remove packages
## Troubleshooting
### i3 Issues
- Ensure X11 packages are installed (`packages-i3.txt`)
- Check that `~/.config/i3/config` is symlinked correctly
- Verify X server is running (`startx` or display manager)
### Sway Issues
- Ensure Wayland packages are installed (`packages-sway.txt`)
- Check that `~/.config/sway/config` is symlinked correctly
- Make sure to select Sway from your display manager
- Some applications may need Wayland flags (e.g., `--enable-features=WaylandWindowDecorations`)
### General Issues
- Run `install.sh` again to reinstall
- Check script permissions: `chmod +x ~/.config/MyI3Config/scripts/*.sh`
- Reload configuration: `Super + Shift + c`
## License
This configuration is licensed under the MIT License. See [LICENSE](LICENSE) for details.
---
## Notes
- This configuration is intentionally minimal
- Everything is plain text and easy to understand
- No magic, no hidden behavior
- You are encouraged to fork and modify this setup to your needs
**Goal**: Predictable tiling behavior with keyboard-driven workflow, minimal visual noise, and easy extensibility via simple shell scripts.

View File

@@ -1,5 +1,5 @@
# ----------------------------------------
# Minimal i3 config (no fluff, no bar)
# Minimal i3/sway config
# ----------------------------------------
set $mod Mod4
@@ -12,29 +12,25 @@ bindsym $mod+Return exec ~/.config/MyI3Config/settings/terminal.sh
bindsym $mod+b exec ~/.config/MyI3Config/settings/browser.sh
bindsym $mod+e exec ~/.config/MyI3Config/settings/filemanager.sh
bindsym $mod+Ctrl+c exec ~/.config/MyI3Config/settings/calculator.sh
bindsym $mod+Ctrl+Return exec --no-startup-id rofi -show drun
# ----------------------------------------
# Window management
# ----------------------------------------
bindsym $mod+q kill
# Kill all windows of same class
bindsym $mod+Shift+q exec --no-startup-id ~/.config/MyI3Config/i3/kill-same-class.sh
bindsym $mod+Shift+q exec --no-startup-id ~/.config/MyI3Config/scripts/kill-same-class.sh
bindsym $mod+f fullscreen toggle
bindsym $mod+t floating toggle
bindsym $mod+j split toggle
bindsym $mod+m fullscreen toggle
# visual monitor arrangement tool
bindsym $mod+p exec arandr
# visual monitor arrangement tool (handled by script)
bindsym $mod+p exec ~/.config/MyI3Config/scripts/display-tool.sh
# ----------------------------------------
# Overlay power menu
# ----------------------------------------
bindsym $mod+Control+q exec --no-startup-id ~/.config/MyI3Config/i3/overlay-menu.sh
bindsym $mod+Control+q exec --no-startup-id ~/.config/MyI3Config/scripts/overlay-menu.sh
# ----------------------------------------
# Focus / move / resize
@@ -86,20 +82,20 @@ bindsym $mod+Shift+c reload
bindsym $mod+Shift+r restart
# ----------------------------------------
# Screenshot
# Screenshot (handled by script)
# ----------------------------------------
bindsym $mod+Shift+s exec maim -s | xclip -selection clipboard -t image/png
bindsym $mod+Shift+s exec ~/.config/MyI3Config/scripts/screenshot.sh
# ----------------------------------------
# Keyboard layout
# Keyboard layout (handled by script)
# ----------------------------------------
exec --no-startup-id setxkbmap -layout ch -variant de
bindsym $mod+space exec --no-startup-id ~/.config/MyI3Config/i3/layout-toggle.sh
exec --no-startup-id ~/.config/MyI3Config/scripts/keyboard-setup.sh
bindsym $mod+space exec --no-startup-id ~/.config/MyI3Config/scripts/layout-toggle.sh
# ----------------------------------------
# Lock
# Lock (handled by script)
# ----------------------------------------
bindsym $mod+l exec i3lock
bindsym $mod+l exec ~/.config/MyI3Config/scripts/lock.sh
# ----------------------------------------
# Visuals
@@ -109,7 +105,21 @@ floating_modifier $mod
focus_follows_mouse yes
# ----------------------------------------
# Startup
# Fn keys (Dual bindings - both syntaxes)
# ----------------------------------------
exec --no-startup-id xsetroot -cursor_name left_ptr
exec --no-startup-id xrandr --output HDMI-1 --auto --left-of DP-2 --output DP-2 --auto
bindsym XF86MonBrightnessUp exec brightnessctl -q s +1%
bindsym XF86MonBrightnessDown exec brightnessctl -q s 1%-
bindsym XF86AudioRaiseVolume exec pactl set-sink-mute @DEFAULT_SINK@ 0 && pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-mute @DEFAULT_SINK@ 0 && pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioPause exec playerctl pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
# ----------------------------------------
# Startup (handled by script)
# ----------------------------------------
exec --no-startup-id ~/.config/MyI3Config/scripts/startup.sh

View File

@@ -8,7 +8,6 @@ set -e
# Detect repository directory dynamically
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CFG_ROOT="$HOME/.config/MyI3Config"
I3_DIR="$HOME/.config/i3"
# ----------------------------
# Functions
@@ -42,6 +41,11 @@ ask_app() {
done
}
# Detect if running in Sway
is_sway() {
[ -n "$SWAYSOCK" ] || pgrep -x sway >/dev/null 2>&1
}
# ----------------------------
# Installer
# ----------------------------
@@ -49,22 +53,88 @@ ask_app() {
echo "=== MyI3Config installer ==="
echo
if ! ask "Install this i3 configuration?"; then
# Ask if installing for i3 or Sway
echo "Select window manager:"
echo "1) i3 (X11)"
echo "2) Sway (Wayland)"
echo "3) Auto-detect"
read -rp "Choice (1/2/3): " wm_choice
case "$wm_choice" in
1) WM="i3" ;;
2) WM="sway" ;;
3)
if is_sway; then
WM="sway"
echo "Auto-detected: Sway"
else
WM="i3"
echo "Auto-detected: i3"
fi
;;
*)
echo "Invalid choice, defaulting to i3"
WM="i3"
;;
esac
echo "Installing for: $WM"
echo
if ! ask "Install this configuration?"; then
echo "Aborted."
exit 0
fi
mkdir -p "$HOME/.config"
mkdir -p "$I3_DIR"
mkdir -p "$CFG_ROOT"
# ----------------------------
# 1/4: Install packages
# ----------------------------
echo
echo "[1/4] Installing packages..."
# Remove any packages that don't exist on Arch
# Initialize package list
PACKAGES=""
# Check for split package files
if [ -f "$REPO_DIR/packages-common.txt" ]; then
# We have split package configuration
echo " Using split package configuration"
# Always install common packages
COMMON_PACKAGES=$(grep -v '^#' "$REPO_DIR/packages-common.txt" | tr '\n' ' ')
PACKAGES="$PACKAGES $COMMON_PACKAGES"
# Install WM-specific packages
if [ "$WM" = "sway" ] && [ -f "$REPO_DIR/packages-sway.txt" ]; then
echo " Installing Sway packages..."
SWAY_PACKAGES=$(grep -v '^#' "$REPO_DIR/packages-sway.txt" | tr '\n' ' ')
PACKAGES="$PACKAGES $SWAY_PACKAGES"
elif [ "$WM" = "i3" ] && [ -f "$REPO_DIR/packages-i3.txt" ]; then
echo " Installing i3 packages..."
I3_PACKAGES=$(grep -v '^#' "$REPO_DIR/packages-i3.txt" | tr '\n' ' ')
PACKAGES="$PACKAGES $I3_PACKAGES"
else
echo " Warning: No $WM-specific package file found"
fi
else
# Fall back to original unified packages.txt
echo " Using unified packages.txt"
PACKAGES=$(grep -v '^#' "$REPO_DIR/packages.txt" | tr '\n' ' ')
sudo pacman -S --needed $PACKAGES || true
fi
# Remove any duplicate packages
if [ -n "$PACKAGES" ]; then
UNIQUE_PACKAGES=$(echo "$PACKAGES" | tr ' ' '\n' | sort -u | tr '\n' ' ')
echo " Installing: $UNIQUE_PACKAGES"
sudo pacman -S --needed $UNIQUE_PACKAGES || {
echo " Some packages might have failed to install. Continuing..."
}
else
echo " No packages to install."
fi
# ----------------------------
# 2/4: Choose applications
@@ -99,18 +169,28 @@ echo "$CALCULATOR" > "$CFG_ROOT/settings/calculator.sh"
find "$CFG_ROOT/settings" -type f -name "*.sh" -exec chmod +x {} \;
# ----------------------------
# Link i3 config to ~/.config/i3/config
# Create symlink for config
# ----------------------------
echo
echo "Linking i3 config → ~/.config/i3/config"
echo "Linking config..."
mkdir -p "$I3_DIR"
if [ -f "$CFG_ROOT/i3/config" ]; then
ln -sf "$CFG_ROOT/i3/config" "$I3_DIR/config"
if [ "$WM" = "sway" ]; then
# Link for Sway
SWAY_DIR="$HOME/.config/sway"
mkdir -p "$SWAY_DIR"
ln -sf "$CFG_ROOT/i3/config" "$SWAY_DIR/config"
echo "Linked: $SWAY_DIR/config → $CFG_ROOT/i3/config"
echo
echo "Note: Your config is written for i3. For Sway, you may need to:"
echo " 1. Replace X11 commands (xrandr, xsetroot, etc.) with Wayland equivalents"
echo " 2. Install Sway-specific tools: grim, slurp, wl-clipboard, etc."
echo " 3. Update screenshot and display scripts in ~/.config/MyI3Config/scripts/"
else
echo "Error: i3 config file not found in $CFG_ROOT/i3/"
exit 1
# Link for i3
I3_DIR="$HOME/.config/i3"
mkdir -p "$I3_DIR"
ln -sf "$CFG_ROOT/i3/config" "$I3_DIR/config"
echo "Linked: $I3_DIR/config → $CFG_ROOT/i3/config"
fi
# ----------------------------
@@ -119,4 +199,10 @@ fi
echo
echo "✓ Done"
echo
echo "Reload i3 with: Super + Shift + C"
if [ "$WM" = "sway" ]; then
echo "For Sway, reload with: Super + Shift + C"
echo "Make sure to log out and select Sway from your display manager"
else
echo "For i3, reload with: Super + Shift + C"
fi

View File

@@ -1,23 +1,9 @@
# Window manager
i3-wm
# Xorg (required for i3)
xorg-server
xorg-xinit
xorg-xrandr
xorg-xsetroot
xorg-xkb-utils
# Application launcher
rofi
# Terminal emulator
kitty
# Clipboard & screenshots
maim
xclip
# Audio (PipeWire stack)
pipewire
pipewire-alsa
@@ -30,10 +16,6 @@ playerctl
# Brightness control
brightnessctl
# Lock screen
i3lock
xss-lock
# Fonts
ttf-dejavu
noto-fonts
@@ -43,4 +25,5 @@ firefox
gnome-calculator
nautilus
# Power menu
wlogout

17
packages-i3.txt Normal file
View File

@@ -0,0 +1,17 @@
# Window manager
i3-wm
# Xorg (required for i3)
xorg-server
xorg-xinit
xorg-xrandr
xorg-xsetroot
xorg-xkb-utils
# Clipboard & screenshots (X11)
maim
xclip
# Lock screen (X11)
i3lock
xss-lock

16
packages-sway.txt Normal file
View File

@@ -0,0 +1,16 @@
# Window manager (Wayland)
sway
# Screenshots (Wayland)
grim
slurp
# Clipboard (Wayland)
wl-clipboard
# Lock screen (Wayland)
swaylock
swayidle
# Display configuration (Wayland)
wdisplays

9
scripts/display-tool.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
if [ -n "$SWAYSOCK" ]; then
# Sway
wdisplays
else
# i3
arandr
fi

10
scripts/keyboard-setup.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
if [ -n "$SWAYSOCK" ]; then
# Sway
swaymsg input "*" xkb_layout "ch"
swaymsg input "*" xkb_variant "de"
else
# i3
setxkbmap -layout ch -variant de
fi

22
scripts/layout-toggle.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# Toggle between CH and US layouts
if [ -n "$SWAYSOCK" ]; then
# Sway: get current layout and toggle
current=$(swaymsg -t get_inputs | jq -r '.[] | select(.type=="keyboard") | .xkb_active_layout_name' | head -1)
if [ "$current" = "Swiss" ] || [ "$current" = "ch" ]; then
swaymsg input "*" xkb_layout "us"
swaymsg input "*" xkb_variant "workman"
else
swaymsg input "*" xkb_layout "ch"
swaymsg input "*" xkb_variant "de"
fi
else
# i3: get current layout and toggle
current=$(setxkbmap -query | grep layout | awk '{print $2}')
if [ "$current" = "ch" ]; then
setxkbmap -layout us -variant workman
else
setxkbmap -layout ch -variant de
fi
fi

9
scripts/lock.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
if [ -n "$SWAYSOCK" ]; then
# Sway
swaylock
else
# i3
i3lock
fi

9
scripts/screenshot.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
if [ -n "$SWAYSOCK" ]; then
# Sway
grim -g "$(slurp)" - | wl-copy
else
# i3
maim -s | xclip -selection clipboard -t image/png
fi

12
scripts/startup.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
if [ -n "$SWAYSOCK" ]; then
# Sway startup commands
# Set cursor (optional, Sway handles this differently)
# For Sway, output configuration should be in the config file, not here
echo "Running Sway startup"
else
# i3 startup commands
xsetroot -cursor_name left_ptr
xrandr --output HDMI-1 --auto --left-of DP-2 --output DP-2 --auto
fi