- name: gnome | keybindings | disable default browser key binding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value }}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/www", value: "@as []" }

- name: gnome | keybindings | disable default file manager binding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value }}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/home", value: "@as []" }

- name: gnome | keybindings | disable default email client binding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value }}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/email", value: "@as []" }

- name: gnome | keybindings | disable default terminal key binding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value }}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/terminal", value: "@as []" }

- name: gnome | keybindings | set custom-keybindings
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings"
    value: "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/']"

- name: gnome | keybindings | set primary browser keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/name", value: "'browser'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/binding", value: "'<Super>b'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/command", value: "'{{ web_browser }}'" }
  when: web_browser is defined

- name: gnome | keybindings | set primary browser keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/name", value: "'browser'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/binding", value: "'<Super>b'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/command", value: "'firefox'" }
  when: web_browser is not defined

- name: gnome | keybindings | set browser (alternate) keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/name", value: "'browser-alt'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/binding", value: "'<Shift><Super>b'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/command", value: "'/usr/bin/google-chrome'" }

- name: gnome | keybindings | set file manager keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/name", value: "'file manager'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/binding", value: "'<Super>f'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/command", value: "'nautilus -w /home/super_user'" }
- name: gnome | keybindings | set bpytop keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/name", value: "'bpytop'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/binding", value: "'<Super>r'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/command", value: "'{{ terminal_emulator }} -e bpytop'" }
  when: terminal_emulator is defined

- name: gnome | keybindings | set bpytop keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/name", value: "'bpytop'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/binding", value: "'<Super>r'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/command", value: "'gnome-terminal -e bpytop'" }
  when: terminal_emulator is not defined

- name: gnome | keybindings | set terminal keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/name", value: "'terminal'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/binding", value: "'<Super>t'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/command", value: "'{{ terminal_emulator }}'" }
  when: terminal_emulator is defined

- name: gnome | keybindings | set terminal keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/name", value: "'terminal'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/binding", value: "'<Super>t'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/command", value: "'gnome-terminal'" }
  when: terminal_emulator is not defined

- name: gnome | keybindings | set text editor keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/name", value: "'text editor'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/binding", value: "'<Super>e'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/command", value: "'{{ gui_editor }}'" }
  when: gui_editor is defined

- name: gnome | keybindings | set text editor keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/name", value: "'text editor'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/binding", value: "'<Super>e'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/command", value: "'gedit'" }
  when: gui_editor is not defined

- name: gnome | keybindings | set tmux keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/name", value: "'tmux'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/binding", value: "'<Shift><Super>t'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/command", value: "'{{ terminal_emulator }} -e tmux'" }
  when: terminal_emulator is defined

- name: gnome | keybindings | set tmux keybinding
  tags: gnome,keybindings
  become_user: super_user
  dconf:
    key: "{{ item.key }}"
    value: "{{ item.value}}"
  with_items:
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/name", value: "'tmux'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/binding", value: "'<Shift><Super>t'" }
    - { key: "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/command", value: "'gnome-terminal -e tmux'" }
  when: terminal_emulator is not defined

# Uncommenting the below plays will restore the default GNOME shortcuts for these actions:
#- name: gnome | keybindings | set keybindings for switching between workspaces
#  become_user: super_user
#  dconf:
#    key: "{{ item.key }}"
#    value: "{{ item.value}}"
#  with_items:
#      - { key: "/org/gnome/desktop/wm/keybindings/switch-to-workspace-down", value: "['<Super>Page_Down']" }
#      - { key: "/org/gnome/desktop/wm/keybindings/switch-to-workspace-up", value: "['<Super>Page_Up']" }
#- name: gnome | keybindings | set key binding for moving windows to other workspaces
#  become_user: super_user
#  dconf:
#    key: "{{ item.key }}"
#    value: "{{ item.value}}"
#  with_items:
#      - { key: "/org/gnome/desktop/wm/keybindings/move-to-workspace-down", value: "['<Shift><Super>Page_Down']" }
#      - { key: "/org/gnome/desktop/wm/keybindings/move-to-workspace-up", value: "['<Shift><Super>Page_Up']" }
#- name: gnome | keybindings | set maximize/minimize key bindings
#  become_user: super_user
#  dconf:
#    key: "/org/gnome/desktop/wm/keybindings/{{ item.key }}"
#    value: "{{ item.value}}"
#  with_items:
#      - { key: maximize, value: "'<Super>Up'" }
#      - { key: unmaximize, value: "'<Super>Down'" }
