├── .github └── FUNDING.yml ├── .gitignore ├── README.md ├── menu.gif ├── pmenu.gif ├── pmenu2.gif ├── polybar-kdeconnect.sh └── screenshot.png /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ['https://www.buymeacoffee.com/HAliPunjabi'] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/* 2 | !.vscode/settings.json 3 | !.vscode/tasks.json 4 | !.vscode/launch.json 5 | !.vscode/extensions.json 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # polybar-kdeconnect 2 | 3 | [KDEConnect](https://github.com/KDE/kdeconnect-kde) module for [Polybar](https://github.com/jaagr/polybar) 4 | 5 | ![menu](menu.gif) 6 | ![pmenu](pmenu.gif) 7 | ![pmenu2](pmenu2.gif) 8 | ![screenshot](screenshot.png) 9 | Demo with [Material Theme](https://github.com/DaveDavenport/rofi-themes/blob/master/User%20Themes/material.rasi) and [Material Polybar](https://github.com/adi1090x/polybar-themes) 10 | 11 | ## Dependencies 12 | * [rofi](https://github.com/DaveDavenport/rofi) 13 | * [kdeconnect](https://github.com/KDE/kdeconnect-kde) 14 | * Iosevka Nerd Font 15 | * [Zenity](https://github.com/GNOME/zenity) 16 | * qbus-qt5 (or qt5tools on some distros) 17 | 18 | ## Usage 19 | Place the given script in some folder, and use it in your polybar `config` as 20 | ``` 21 | [module/kdeconnect] 22 | type = custom/script 23 | exec = "/path/to/files/polybar-kdeconnect.sh -d" 24 | tail = true 25 | ```` 26 | 27 | ## Customization 28 | You can change the variables in [`polybar-kdeconnect.sh`](polybar-kdeconnect.sh) to customize the [rofi](https://github.com/DaveDavenport/rofi) menu and the icons shown in [polybar](https://github.com/jaagr/polybar) 29 | 30 | ## Default Color Code Legend 31 | Color | Meaning | 32 | ---|---| 33 | ![Disconnected](https://via.placeholder.com/16.png/000000/000000) | Device Disconnected | 34 | ![New Device](https://via.placeholder.com/16.png/FFFF00/FFFF00) | Unpaired Device | 35 | ![Baterry_90](https://via.placeholder.com/16.png/FFFFFF/FFFFFF) | Battery >= 90 | 36 | ![Baterry_80](https://via.placeholder.com/16.png/CCCCCC/CCCCCC) | Battery >= 80 | 37 | ![Baterry_70](https://via.placeholder.com/16.png/AAAAAA/AAAAAA) | Battery >= 70 | 38 | ![Baterry_60](https://via.placeholder.com/16.png/888888/888888) | Battery >= 60 | 39 | ![Baterry_50](https://via.placeholder.com/16.png/666666/666666) | Battery >= 50 | 40 | ![Baterry_LOW](https://via.placeholder.com/16.png/FF0000/FF0000) | Battery < 50 | 41 | 42 | 43 | ## Changelog 44 | ### v2 45 | * Supports Multiple Devices without extra configuration 46 | * Supports pairing/unpairing devices 47 | * Removed `kdeconnect-cli` as dependency 48 | * Combined seperate files into one 49 | * Seperate icons for tablets and smartphone 50 | -------------------------------------------------------------------------------- /menu.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haideralipunjabi/polybar-kdeconnect/21fdc8bcd500a605b861dd4ef40e47d97a7adae9/menu.gif -------------------------------------------------------------------------------- /pmenu.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haideralipunjabi/polybar-kdeconnect/21fdc8bcd500a605b861dd4ef40e47d97a7adae9/pmenu.gif -------------------------------------------------------------------------------- /pmenu2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haideralipunjabi/polybar-kdeconnect/21fdc8bcd500a605b861dd4ef40e47d97a7adae9/pmenu2.gif -------------------------------------------------------------------------------- /polybar-kdeconnect.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # CONFIGURATION 4 | LOCATION=0 5 | YOFFSET=0 6 | XOFFSET=0 7 | WIDTH=12 8 | WIDTH_WIDE=24 9 | THEME=solarized 10 | 11 | # Color Settings of Icon shown in Polybar 12 | COLOR_DISCONNECTED='#000' # Device Disconnected 13 | COLOR_NEWDEVICE='#ff0' # New Device 14 | COLOR_BATTERY_90='#fff' # Battery >= 90 15 | COLOR_BATTERY_80='#ccc' # Battery >= 80 16 | COLOR_BATTERY_70='#aaa' # Battery >= 70 17 | COLOR_BATTERY_60='#888' # Battery >= 60 18 | COLOR_BATTERY_50='#666' # Battery >= 50 19 | COLOR_BATTERY_LOW='#f00' # Battery < 50 20 | 21 | # Icons shown in Polybar 22 | ICON_SMARTPHONE='' 23 | ICON_TABLET='' 24 | SEPERATOR='|' 25 | 26 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 27 | 28 | show_devices (){ 29 | IFS=$',' 30 | devices="" 31 | for device in $(qdbus --literal org.kde.kdeconnect /modules/kdeconnect org.kde.kdeconnect.daemon.devices); do 32 | deviceid=$(echo "$device" | awk -F'["|"]' '{print $2}') 33 | devicename=$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.name) 34 | devicetype=$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.type) 35 | isreach="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isReachable)" 36 | istrust="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isTrusted)" 37 | if [ "$isreach" = "true" ] && [ "$istrust" = "true" ] 38 | then 39 | battery="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid/battery" org.kde.kdeconnect.device.battery.charge)" 40 | icon=$(get_icon "$battery" "$devicetype") 41 | devices+="%{A1:$DIR/polybar-kdeconnect.sh -n '$devicename' -i $deviceid -b $battery -m:}$icon%{A}$SEPERATOR" 42 | elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ] 43 | then 44 | devices+="$(get_icon -1 "$devicetype")$SEPERATOR" 45 | else 46 | haspairing="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.hasPairingRequests)" 47 | if [ "$haspairing" = "true" ] 48 | then 49 | show_pmenu2 "$devicename" "$deviceid" 50 | fi 51 | icon=$(get_icon -2 "$devicetype") 52 | devices+="%{A1:$DIR/polybar-kdeconnect.sh -n $devicename -i $deviceid -p:}$icon%{A}$SEPERATOR" 53 | 54 | fi 55 | done 56 | echo "${devices::-1}" 57 | } 58 | 59 | show_menu () { 60 | menu="$(rofi -sep "|" -dmenu -i -p "$DEV_NAME" -location $LOCATION -yoffset $YOFFSET -xoffset $XOFFSET -theme $THEME -width $WIDTH -hide-scrollbar -line-padding 4 -padding 20 -lines 5 <<< "Battery: $DEV_BATTERY%|Ping|Find Device|Send File|Browse Files|Unpair")" 61 | case "$menu" in 62 | *Ping) qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/ping" org.kde.kdeconnect.device.ping.sendPing ;; 63 | *'Find Device') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/findmyphone" org.kde.kdeconnect.device.findmyphone.ring ;; 64 | *'Send File') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/share" org.kde.kdeconnect.device.share.shareUrl "file://$(zenity --file-selection)" ;; 65 | *'Browse Files') 66 | if "$(qdbus --literal org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/sftp" org.kde.kdeconnect.device.sftp.isMounted)" == "false"; then 67 | qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/sftp" org.kde.kdeconnect.device.sftp.mount 68 | fi 69 | qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/sftp" org.kde.kdeconnect.device.sftp.startBrowsing 70 | ;; 71 | *'Unpair' ) qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID" org.kde.kdeconnect.device.unpair 72 | esac 73 | } 74 | 75 | show_pmenu () { 76 | menu="$(rofi -sep "|" -dmenu -i -p "$DEV_NAME" -location $LOCATION -yoffset $YOFFSET -xoffset $XOFFSET -theme $THEME -width $WIDTH -hide-scrollbar -line-padding 1 -padding 20 -lines 1<<<"Pair Device")" 77 | case "$menu" in 78 | *'Pair Device') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID" org.kde.kdeconnect.device.requestPair 79 | esac 80 | } 81 | 82 | show_pmenu2 () { 83 | menu="$(rofi -sep "|" -dmenu -i -p "$1 has sent a pairing request" -location $LOCATION -yoffset $YOFFSET -xoffset $XOFFSET -theme $THEME -width $WIDTH_WIDE -hide-scrollbar -line-padding 4 -padding 20 -lines 2 <<< "Accept|Reject")" 84 | case "$menu" in 85 | *'Accept') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$2" org.kde.kdeconnect.device.acceptPairing ;; 86 | *) qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$2" org.kde.kdeconnect.device.rejectPairing 87 | esac 88 | 89 | } 90 | get_icon () { 91 | if [ "$2" = "tablet" ] 92 | then 93 | icon=$ICON_TABLET 94 | else 95 | icon=$ICON_SMARTPHONE 96 | fi 97 | case $1 in 98 | "-1") ICON="%{F$COLOR_DISCONNECTED}$icon%{F-}" ;; 99 | "-2") ICON="%{F$COLOR_NEWDEVICE}$icon%{F-}" ;; 100 | 5*) ICON="%{F$COLOR_BATTERY_50}$icon%{F-}" ;; 101 | 6*) ICON="%{F$COLOR_BATTERY_60}$icon%{F-}" ;; 102 | 7*) ICON="%{F$COLOR_BATTERY_70}$icon%{F-}" ;; 103 | 8*) ICON="%{F$COLOR_BATTERY_80}$icon%{F-}" ;; 104 | 9*|100) ICON="%{F$COLOR_BATTERY_90}$icon%{F-}" ;; 105 | *) ICON="%{F$COLOR_BATTERY_LOW}$icon%{F-}" ;; 106 | esac 107 | echo $ICON 108 | } 109 | 110 | unset DEV_ID DEV_NAME DEV_BATTERY 111 | while getopts 'di:n:b:mp' c 112 | do 113 | # shellcheck disable=SC2220 114 | case $c in 115 | d) show_devices ;; 116 | i) DEV_ID=$OPTARG ;; 117 | n) DEV_NAME=$OPTARG ;; 118 | b) DEV_BATTERY=$OPTARG ;; 119 | m) show_menu ;; 120 | p) show_pmenu ;; 121 | esac 122 | done 123 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haideralipunjabi/polybar-kdeconnect/21fdc8bcd500a605b861dd4ef40e47d97a7adae9/screenshot.png --------------------------------------------------------------------------------