Wayland. Панель Waybar

2024-11-21 · 8 мин. для прочтения

Wayland. Панель Waybar

Содержание

1 Общая информация

2 Конфигурация

2.1 Общая информация

  • Wiki: https://github.com/Alexays/Waybar/wiki/Configuration
  • Конфигурация использует формат файла JSONC и называется config или config.jsonc.
  • Каталоги для этого файла:
    • $XDG_CONFIG_HOME/waybar/
    • ~/.config/waybar/
    • ~/waybar/
    • /etc/xdg/waybar/
    • SYSCONFDIR/xdg/waybar (если SYSCONFDIR установленный во время сборки, отличается от /etc, например /usr/local/etc в системах BSD).

2.2 Файл конфигурации

2.2.1 Начало

// vim:ft=json -*- mode: js-json -*-
{
Распечатка 1: config

2.2.2 Общие настройки

// General
"layer": "top",
// Waybar position (top|bottom|left|right)
"position": "top",
// Waybar height (to be removed for auto height)
"height": 30,
// Gaps between modules (4px)
"spacing": 4,
Распечатка 2: config

2.2.3 Расположение модулей

// Modules
"modules-left": [
    "sway/workspaces",
    "custom/scratchpad",
    "sway/mode",
],
"modules-center": [
    "custom/pomm",
    "custom/weather",
    "custom/clipboard",
    "idle_inhibitor",
],
"modules-right": [
    "memory",
    "cpu",
    "temperature",
    "battery",
    "battery#bat1",
    "network",
    "backlight",
    "wireplumber",
    "clock",
    "sway/language",
    "keyboard-state",
    "tray",
    "custom/power",
],
Распечатка 3: config

2.2.4 Конфигурация модулей

  1. Информационные модули

    1. Память

      // Memory
      "memory": {
          "interval": 30,
          "format": " {used:0.1f}G/{total:0.1f}G",
          "tooltip": true,
          "tooltip-format": "Free {avail:0.1f}G\nUsed: {percentage}%\nSwap: {swapPercentage}%",
      },
      
      Распечатка 4: config
    1. Процессор

      // Cpu
      "cpu": {
          "interval": 10,
          "format": " {usage}% {icon}",
          "max-length": 10,
          "format-icons": ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"],
      },
      
      Распечатка 5: config
    1. Батарея

      // Battery
      "battery": {
          "bat": "BAT0",
          "states": {
            "full": 100,
            "good": 95,
            "warning": 30,
            "critical": 15
          },
          "format": "{icon}  {capacity}% ({time})",
          "format-charging": " {icon}  {capacity}% ({time})",
          "format-full": " {icon}  Full",
          "format-time": "{H}h{M}m",
          "interval": 30,
          "on-click": "gnome-power-statistics",
          "format-icons": [
            " ",
            " ",
            " ",
            " ",
            " "
          ]
      },
      
      Распечатка 6: config
    1. Температура подсистем

      • Задаётся для температурных зон /sys/class/thermal/ или для показаний сенсоров /sys/class/hwmon/hwmon*/temp*_input.
      • Просмотреть все типы температурных зон:
        for i in /sys/class/thermal/thermal_zone*; do echo "$i: $(<$i/type)"; done
        
      • Если нет тепловой зоны, можно использовать сенсоры (sensors), чтобы найти предпочтительный источник температуры:
        for i in /sys/class/hwmon/hwmon*/temp*_input; do echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)"; done
        
      • Сама конфигурация выглядит следующим образом:
      // Themperature
      "temperature": {
          "critical-threshold": 80,
          "interval": 5,
          "thermal-zone": 1,
          "format": "{icon} {temperatureC}°C",
          "format-icons": [
              "", // Icon: temperature-empty
              "", // Icon: temperature-quarter
              "", // Icon: temperature-half
              "", // Icon: temperature-three-quarters
              ""  // Icon: temperature-full
          ],
          "tooltip": true
      },
      
      Распечатка 7: config
    1. Отображение времени

      // Clock
      "clock": {
          "format": " {:%H:%M  %F, %a} ",
          "format-alt": " {:%A, %B %d, %Y (%R)}",
          "tooltip-format": "<tt><small>{calendar}</small></tt>",
          "calendar": {
              "mode"          : "year",
              "mode-mon-col"  : 3,
              "weeks-pos"     : "right",
              "on-scroll"     : 1,
              "format": {
                  "months":     "<span color='#ffead3'><b>{}</b></span>",
                  "days":       "<span color='#ecc6d9'><b>{}</b></span>",
                  "weeks":      "<span color='#99ffdd'><b>W{}</b></span>",
                  "weekdays":   "<span color='#ffcc66'><b>{}</b></span>",
                  "today":      "<span color='#ff6699'><b><u>{}</u></b></span>"
              }
          },
          "actions":  {
              "on-click-right": "mode",
              "on-scroll-up": "tz_up",
              "on-scroll-down": "tz_down",
              "on-scroll-up": "shift_up",
              "on-scroll-down": "shift_down"
          }
      },
      
      Распечатка 8: config
    1. Состояние клавиатуры

      // Keyboard
      "keyboard-state": {
          "numlock": true,
          "capslock": true,
          "format": " {name} {icon}",
          "format-icons": {
              "locked": " ",
              "unlocked": " "
          }
      },
      
      Распечатка 9: config
    1. Сеть

      // Network
      "network": {
          "format": "{ifname}",
          "format-wifi": " {essid}",
          "format-ethernet": " {ifname}",
          "format-disconnected": "", //An empty format will hide the module.
          "tooltip-format": "{ipaddr}/{cidr} via {gwaddr}",
          "tooltip-format-wifi": " {essid} ({signalStrength}%)",
          "tooltip-format-ethernet": "󰩠 {ipaddr}/{cidr} via {gwaddr}",
          "tooltip-format-disconnected": "󰲛 Disconnected",
          "max-length": 50,
          "on-click": "nm-connection-editor"
      },
      
      Распечатка 10: config
  1. Управляемые модули

    1. Звук

      1. Pulseaudio

        // Sound (pulseaudio)
        "pulseaudio": {
            "format": "{icon} {volume}% {format_source}",
            "format-bluetooth": "{icon}  {volume}% {format_source}",
            "format-bluetooth-muted": "󰝟  {format_source}",
            "format-muted": "󰝟 {format_source}",
            "format-source": " {volume}%",
            "format-source-muted": " ",
            "format-icons": {
              "headphone": " ",
              "hands-free": " ",
              "headset": "󰋎 ",
              "phone": " ",
              "portable": " ",
              "car": " ",
              "default": [
                    "",
                    " ",
                    " "
              ]
            },
            "scroll-step": 5,
            "on-click": "pavucontrol",
            "on-click-right": "blueman-manager"
        },
        
        Распечатка 11: config
      1. Pipewire

        // Sound (pipewire)
        "wireplumber": {
            "format": "{icon}{volume}%",
            "format-muted": " ",
            // "on-click": "helvum",
            "on-click": "pavucontrol",
            "on-click-middle": "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle",
            "format-icons": ["", " ", " "],
            "max-volume": 200,
            // "scroll-step": 0.2,
        },
        
        Распечатка 12: config
    1. Трей

      // Tray
      "tray": {
          "icon-size": 20,
          "spacing": 10
      },
      
      Распечатка 13: config
    1. Отключение засыпания экрана

      // Idle inhibitor
      "idle_inhibitor": {
          "format": "{icon}",
          "format-icons": {
            "activated": "  ",
            "deactivated": "  "
          }
      },
      
      Распечатка 14: config
    1. Подсветка экрана

      "backlight": {
          "device": "intel_backlight",
          "format": "{icon} {percent}% ",
          "format-icons": [" ", " "],
      },
      
      Распечатка 15: config
  1. Модули Sway

    1. Окна Sway

      "sway/window": {
          "format": "{}",
          "max-length": 40
      },
      
      Распечатка 16: config
    1. Режим Sway

      "sway/mode": {
          "format": "  {}",
          "max-length": 50
      },
      
      Распечатка 17: config
    1. Рабочие столы Sway

      "sway/workspaces": {
          "disable-scroll": false,
          "disable-scroll-wraparound": true,
          "all-outputs": true,
          "format": "{index}:{name}",
      },
      
      Распечатка 18: config
    1. Переключатель языка Sway

      "sway/language": {
          "format": " {short} ",
          "on-click": "swaymsg input type:keyboard xkb_switch_layout next",
      },
      
      Распечатка 19: config
  1. Самописные модули

    1. Погода

      // Weather
      "custom/weather": {
          "format": "{icon} {text}",
          "tooltip": true,
          "interval": 3600,
          // accepts -c/--city <city> -t/--temperature <C/F> -d/--distance <km/miles>
          "exec": "~/.config/sway/scripts/weather.py",
          "return-type": "json",
          "format-icons": {
              "Unknown": "",
              "Cloudy": "󰖐",
              "Fog": "",
              "HeavyRain": "",
              "HeavyShowers": "",
              "HeavySnow": "",
              "HeavySnowShowers": "󰜗",
              "LightRain": "",
              "LightShowers": "",
              "LightSleet": "",
              "LightSleetShowers": "",
              "LightSnow": "",
              "LightSnowShowers": "󰙿",
              "PartlyCloudy": "",
              "Sunny": "",
              "ThunderyHeavyRain": "󰙾",
              "ThunderyShowers": "",
              "ThunderySnowShowers": "",
              "VeryCloudy": ""
          }
      },
      
      Распечатка 20: config
    1. Скратчпад

      // Scratchpad
      "custom/scratchpad": {
          "interval": "once",
          "escape": true,
          "return-type": "json",
          "format": "{icon}",
          "format-icons": {
              "one": "󰖯 ",
              "many": "󰖲 "
          },
          "exec": "/bin/sh ~/.config/sway/scripts/scratchpad.sh",
          "on-click": "swaymsg 'scratchpad show'",
          "signal": 7
      },
      
      Распечатка 21: config
    1. Отключение машины

      "custom/power": {
          "format" : "⏻ ",
          "tooltip": false,
          "menu": "on-click",
          "menu-file": "$HOME/.config/waybar/power_menu.xml", // Menu file in resources folder
          "menu-actions": {
            "shutdown": "shutdown",
            "reboot": "reboot",
            "suspend": "systemctl suspend",
            "hibernate": "systemctl hibernate"
          }
      },
      
      Распечатка 22: config
    1. Буфер обмена

      // Clipboard
      "custom/clipboard": {
          "format": " ",
          "interval": "once",
          "return-type": "json",
          "on-click": "swaymsg -q exec '$clipboard'; pkill -RTMIN+9 waybar",
          "on-click-right": "swaymsg -q exec '$clipboard-del'; pkill -RTMIN+9 waybar",
          "on-click-middle": "swaymsg -q exec '$clipboard-del-all'",
          "exec": "printf '{\"tooltip\":\"%s\"}' $(cliphist list | wc -l)",
          "exec-if": "[ -x \"$(command -v cliphist)\" ] && [ $(cliphist list | wc -l) -gt 0 ]",
          "signal": 9
      },
      
      Распечатка 23: config
    1. Мониторинг pomm

      • Emacs. Пакет pomm
        // pomm pomodoro timer
        "custom/pomm": {
            "interval": 1,
            "format": " {text}",
            "exec": "/bin/sh ~/.config/waybar/script/pomm.sh"
        },
        
        Распечатка 24: config

2.2.5 Конец

}
Распечатка 25: config

3 Стили

3.1 Общая информация

3.2 Стилевой файл

/* Waybar configuration */

/* Keyframes */

@keyframes blink-warning {
    70% {
      color: white;
    }

    to {
      color: white;
      background-color: orange;
    }
}

@keyframes blink-critical {
    70% {
      color: white;
    }

    to {
      color: white;
      background-color: red;
    }
}

/* Base styles */

/* Reset all styles */
* {
    border: none;
    border-radius: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    font-family: "Iosevka Nerd Font Propo", "Font Awesome 6 Free", "Font Awesome 6 Brands", sans-serif;
    font-size: 14px;
}

/* The whole bar */
window#waybar {
    /* background: @theme_fg_color; */
    background: @theme_base_color;
    /* background: #323232; */
    border-bottom: 1px solid @unfocused_borders;
    color: @theme_text_color;
    /* color: black; */
    /* color: white; */
}

/* Each module */
#battery,
#clock,
#cpu,
#custom-keyboard-layout,
#memory,
#mode,
#network,
#pulseaudio,
#temperature,
#tray {
    padding-left: 4px;
    padding-right: 4px;
}

/* -----------------------------------------------------------------------------
 * Module styles
 * -------------------------------------------------------------------------- */

#battery {
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-direction: alternate;
}

#battery.warning {
    color: orange;
}

#battery.critical {
    color: red;
}

#battery.warning.discharging {
    animation-name: blink-warning;
    animation-duration: 3s;
}

#battery.critical.discharging {
    animation-name: blink-critical;
    animation-duration: 2s;
}

#clock {
    font-weight: bold;
}

#cpu {
  /* No styles */
}

#cpu.warning {
    color: orange;
}

#cpu.critical {
    color: red;
}

#memory {
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-direction: alternate;
}

#memory.warning {
    color: orange;
}

#memory.critical {
    color: red;
    animation-name: blink-critical;
    animation-duration: 2s;
}

#mode {
    background: #64727D;
    border-top: 2px solid white;
    /* To compensate for the top border and still have vertical centering */
    padding-bottom: 2px;
}

#network {
    /* No styles */
}

#network.disconnected {
    color: orange;
}

#pulseaudio {
    /* No styles */
}

#pulseaudio.muted {
    /* No styles */
}

#custom-spotify {
    color: rgb(102, 220, 105);
}

#temperature {
    /* No styles */
}

#temperature.critical {
    color: red;
}

#tray {
    /* No styles */
}

#window {
    font-weight: bold;
}

#workspaces button {
    border-top: 2px solid transparent;
    /* To compensate for the top border and still have vertical centering */
    padding-bottom: 2px;
    padding-left: 10px;
    padding-right: 10px;
    color: #888888;
}

#workspaces button.focused {
    border-color: #4c7899;
    color: white;
    background-color: #285577;
}

#workspaces button.urgent {
    border-color: #c9545d;
    color: #c9545d;
}
Распечатка 26: style.css

4 Вспомогательные файлы

4.1 Перезапуск Waybar

  • Для перезапуска можно использовать скрипт:
    ## Restart waybar
    
    run_waybar() {
        waybar
    }
    
    restart_waybar() {
        pid=$(pgrep waybar)
        [[ ! -z $pid ]] && kill $pid
        run_waybar
    }
    
    restart_waybar
    
    Распечатка 27: waybar.sh

4.2 Меню выключения компьютера

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkMenu" id="menu">
    <child>
      <object class="GtkMenuItem" id="suspend">
      <property name="label">Suspend</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="hibernate">
      <property name="label">Hibernate</property>
      </object>
    </child>
    <child>
      <object class="GtkMenuItem" id="shutdown">
      <property name="label">Shutdown</property>
      </object>
    </child>
    <child>
      <object class="GtkSeparatorMenuItem" id="delimiter1"/>
    </child>
    <child>
      <object class="GtkMenuItem" id="reboot">
      <property name="label">Reboot</property>
      </object>
    </child>
  </object>
</interface>
Распечатка 28: power_menu.xml

4.3 Мониторинг pomm

  • Emacs. Пакет pomm
  • Для мониторинга pomm можно использовать скрипт:
    ## Interface to pomm.el
    
    if ps -e | grep emacs >> /dev/null
    then
        emacsclient --eval "(if (boundp 'pomm-current-mode-line-string) pomm-current-mode-line-string \"\") " | xargs echo -e
    fi
    
    Распечатка 29: pomm.sh

5 Ресурсы

Дмитрий Сергеевич Кулябов
Authors
Профессор кафедры теории вероятностей и кибербезопасности
Мои научные интересы включают физику, администрирование Unix и сетей.