from libqtile.config import Key, KeyChord
from libqtile.lazy import lazy

import os

mod = "mod4"
control = "control"
shift = "shift"
alt = "mod1"
terminal = "alacritty"
home = os.path.expanduser('~')


keys = [
    # A list of available commands that can be bound to keys can be found
    # at https://docs.qtile.org/en/latest/manual/config/lazy.html
    # Switch between windows
    Key([mod], "h", lazy.layout.left(), desc="Move focus to left"),
    Key([mod], "l", lazy.layout.right(), desc="Move focus to right"),
    Key([mod], "j", lazy.layout.down(), desc="Move focus down"),
    Key([mod], "k", lazy.layout.up(), desc="Move focus up"),
    Key([mod], "space", lazy.layout.next(), desc="Move window focus to other window"),
    # Move windows between left/right columns or move up/down in current stack.
    # Moving out of range in Columns layout will create new column.
    Key([mod, "shift"], "h", lazy.layout.shuffle_left(), desc="Move window to the left"),
    Key([mod, "shift"], "l", lazy.layout.shuffle_right(), desc="Move window to the right"),
    Key([mod, "shift"], "j", lazy.layout.shuffle_down(), desc="Move window down"),
    Key([mod, "shift"], "k", lazy.layout.shuffle_up(), desc="Move window up"),
    # Grow windows. If current window is on the edge of screen and direction
    # will be to screen edge - window would shrink.
    Key([mod, "control"], "h", lazy.layout.grow_left(), desc="Grow window to the left"),
    Key([mod, "control"], "l", lazy.layout.grow_right(), desc="Grow window to the right"),
    Key([mod, "control"], "j", lazy.layout.grow_down(), desc="Grow window down"),
    Key([mod, "control"], "k", lazy.layout.grow_up(), desc="Grow window up"),
    Key([mod], "n", lazy.layout.normalize(), desc="Reset all window sizes"),
    # Toggle between split and unsplit sides of stack.
    # Split = all windows displayed
    # Unsplit = 1 window displayed, like Max layout, but still with
    # multiple stack panes
    Key(
        [mod, "shift"],
        "Return",
        lazy.layout.toggle_split(),
        desc="Toggle between split and unsplit sides of stack",
    ),
    Key([mod], "Return", lazy.spawn('alacritty'), desc="Launch terminal"),
    Key([mod], "w", lazy.spawn("firefox"), desc="Launch firefox"),
    Key([mod], "b", lazy.spawn("betterbird"), desc="Launch betterbird"),
    Key([mod], "d", lazy.spawn("vesktop"), desc="Launch discord"),
    Key([mod], "k", lazy.spawn("keepassxc"), desc="Launch KeePassXC"),

    Key([mod], "s", lazy.spawn('rofi -show ssh'), desc="Spawn rofi SSH"),
    Key([mod], "r", lazy.spawn("rofi -show drun -show-icons"), desc="Spawn rofi drun"),

    Key([mod, "control"], "Down", lazy.spawn("wlr-randr --output VGA-1 --transform normal"), desc="sets second monitor to normal rotation"),
    Key([mod, "control"], "Right", lazy.spawn("wlr-randr --output VGA-1 --transform 90"), desc="sets second monitor to 90 rotation"),
    Key([mod, "control"], "Up", lazy.spawn("wlr-randr --output VGA-1 --transform 180"), desc="sets second monitor to 180 rotation"),
    Key([mod, "control"], "Left", lazy.spawn("wlr-randr --output VGA-1 --transform 270"), desc="sets second monitor to 270 rotation"),

    # Change keyboard leyout
    Key([mod], "z", lazy.widget["keyboardlayout"].next_keyboard(), desc="Next keyboard layout"),

    # Toggle between different layouts as defined below
    Key([mod], "space", lazy.spawn("swaylock -C /home/godot/.config/swaylock/swaylock.conf"), desc="Launch firefox"),
    Key([mod], "Tab", lazy.next_layout(), desc="Toggle between layouts"),
    Key([mod], "q", lazy.window.kill(), desc="Kill focused window"),
    Key([mod, "control"], "r", lazy.reload_config(), desc="Reload the config"),
    Key([mod, "control"], "q", lazy.shutdown(), desc="Shutdown Qtile"),
]
