Skip to content

Added: new system-gpu-envycontrol script #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions polybar-scripts/system-gpu-envycontrol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Script: system-gpu-envycontrol

A script that shows the current GPU in use, given that the GPUs are managed by [envycontrol](https://github.com/bayasdev/envycontrol).

The script also allows for switching GPU in one click.
Be aware that this will log you out of your session without asking for confirmation.


## Configuration

Set `hybrid_switching` to `1` if the system switches between hybrid and nvidia.
Otherwise the system switches between intel and nvidia.


## Module

```ini
[module/system-gpu-optimus]
type = custom/script
exec = ~/polybar-scripts/system-gpu-optimus.sh
interval = 1200
click-right = ~/polybar-scripts/system-gpu-optimus.sh --switch
```
52 changes: 52 additions & 0 deletions polybar-scripts/system-gpu-envycontrol/system-gpu-envycontrol.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

icon_intel="#1"
icon_nvidia="#2"
icon_hybrid="#3"

hybrid_switching=0

gpu_current() {
mode=$(envycontrol --query)

echo "$mode"
}

gpu_switch() {
mode=$(gpu_current)

if [ "$mode" = "intel" ]; then
next="nvidia"
elif [ "$mode" = "nvidia" ]; then
if [ "$hybrid_switching" = 1 ]; then
next="hybrid"
else
next="intel"
fi
elif [ "$mode" = "hybrid" ]; then
next="nvidia"
fi

envycontrol --switch "$next"
}

gpu_display(){
mode=$(gpu_current)

if [ "$mode" = "intel" ]; then
echo "$icon_intel"
elif [ "$mode" = "nvidia" ]; then
echo "$icon_nvidia"
elif [ "$mode" = "hybrid" ]; then
echo "$icon_hybrid"
fi
}

case "$1" in
--switch)
gpu_switch
;;
*)
gpu_display
;;
esac