Skip to content
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
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ use tokio::time::sleep;

pub const DEFAULT_CONFIG_FILE_PATH: &str = "~/.config/ashell/config.toml";

#[derive(Deserialize, Copy, Clone, Debug, Default, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum RendererBackend {
#[default]
Auto,
Vulkan,
OpenGL,
}

#[derive(Deserialize, Clone, Debug)]
#[serde(default)]
pub struct Config {
pub log_level: String,
pub position: Position,
pub layer: Layer,
pub renderer_backend: RendererBackend,
pub outputs: Outputs,
pub modules: Modules,
#[serde(rename = "CustomModule")]
Expand All @@ -47,6 +57,7 @@ impl Default for Config {
log_level: "warn".to_owned(),
position: Position::default(),
layer: Layer::default(),
renderer_backend: RendererBackend::default(),
outputs: Outputs::default(),
modules: Modules::default(),
updates: None,
Expand Down
26 changes: 26 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ async fn main() -> iced::Result {

logger.set_new_spec(get_log_spec(&config.log_level));

// Set renderer backend BEFORE any wgpu/iced initialization
// Safe: we are single-threaded at this point, no other threads exist yet
if std::env::var("WGPU_BACKEND").is_err() {
match config.renderer_backend {
crate::config::RendererBackend::Vulkan => unsafe {
std::env::set_var("WGPU_BACKEND", "vulkan");
},
crate::config::RendererBackend::OpenGL => unsafe {
std::env::set_var("WGPU_BACKEND", "gl");
},
crate::config::RendererBackend::Auto => {
// Auto-detect: default proprietary NVIDIA driver to OpenGL for better stability
if std::env::var("__NV_PRIME_RENDER_OFFLOAD").is_ok()
|| std::env::var("__GLX_VENDOR_LIBRARY_NAME")
.map(|v| v.contains("nvidia"))
.unwrap_or(false)
{
// Proprietary nvidia driver is loaded
unsafe {
std::env::set_var("WGPU_BACKEND", "gl");
}
}
}
}
}

let font = if let Some(font_name) = &config.appearance.font_name {
Font::with_name(Box::leak(font_name.clone().into_boxed_str()))
} else {
Expand Down
38 changes: 38 additions & 0 deletions website/docs/configuration/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,41 @@ This is useful for keybind-based toggling or scripting.
# Toggle ashell visibility
kill -SIGUSR1 $(pidof ashell)
```

## Renderer Backend

Selects the graphics rendering backend to use.

:::warning
This configuration **requires** restarting Ashell to take effect.
:::

### Valid Options

| Value | Description |
|---|---|
| `"auto"` | **(Default)** Automatically selects the best backend. Automatically uses OpenGL for proprietary NVIDIA driver users, Vulkan for all other hardware (AMD/Intel/nouveau). |
| `"vulkan"` | Force use Vulkan renderer. |
| `"opengl"` | Force use OpenGL renderer. |

:::note Environment Variable Precedence
If the `WGPU_BACKEND` environment variable is already set when starting ashell, this configuration option will be ignored entirely and the environment variable value will be used instead.
:::

### Examples

```toml
renderer_backend = "auto"
```

```toml
renderer_backend = "vulkan"
```

```toml
renderer_backend = "opengl"
```

:::tip NVIDIA Users
Automatic mode will default to OpenGL for systems running the proprietary NVIDIA driver for best stability and performance. You can still explicitly select Vulkan if you prefer.
:::
8 changes: 7 additions & 1 deletion website/docs/configuration/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ Common issues and quick fixes for ashell.

**Cause:** The default Vulkan backend may have compatibility issues with NVIDIA drivers.

**Solution:** Force the use of OpenGL by setting the `WGPU_BACKEND` environment variable:
**Solution 1 (Permanent):** Set renderer backend in your config.toml:

```toml
renderer_backend = "opengl"
```

**Solution 2 (Temporary):** Force the use of OpenGL by setting the `WGPU_BACKEND` environment variable:

```bash
WGPU_BACKEND=gl ashell
Expand Down
Loading