aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/config.rs6
-rw-r--r--src/main.rs18
2 files changed, 19 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs
index 6181d77..2edb8a5 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -17,6 +17,8 @@ pub struct Config {
pub muted: u32,
pub border: u32,
pub show_status_bar: bool,
+ /// Window background opacity; below 1.0 the desktop shows through, blurred.
+ pub opacity: f32,
pub shortcuts: HashMap<String, String>,
pub width: f32,
pub height: f32,
@@ -213,6 +215,7 @@ impl Config {
.map_err(|e| anyhow::anyhow!(e.to_string()))?,
)?,
show_status_bar: get!("show_status_bar"),
+ opacity: get!("opacity"),
shortcuts: get!("shortcuts"),
width: get!("width"),
height: get!("height"),
@@ -233,11 +236,12 @@ impl Config {
|| !(0.0..=100.0).contains(&c.padding)
|| !(400.0..=4000.0).contains(&c.width)
|| !(300.0..=3000.0).contains(&c.height)
+ || !(0.2..=1.0).contains(&c.opacity)
|| c.palette.len() != 16
|| c.scrollback > 1_000_000
{
bail!(
- "invalid font, spacing, window dimensions, scrollback, or palette (requires 16 colors)"
+ "invalid font, spacing, window dimensions, opacity (0.2-1), scrollback, or palette (requires 16 colors)"
);
}
for (key, action) in &c.shortcuts {
diff --git a/src/main.rs b/src/main.rs
index c5494f4..b7eff36 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,8 +5,9 @@ use gpui::{
App, Application, Bounds, ClipboardItem, Context, ElementInputHandler, EntityInputHandler,
FocusHandle, FontStyle, FontWeight, KeyDownEvent, Keystroke, MouseButton, MouseDownEvent,
MouseMoveEvent, Pixels, Point, ResizeEdge, ScrollWheelEvent, TextRun, TitlebarOptions,
- UTF16Selection, UnderlineStyle, Window, WindowBounds, WindowDecorations, WindowOptions, canvas,
- div, fill, font, point, prelude::*, px, rgb, size,
+ UTF16Selection, UnderlineStyle, Window, WindowBackgroundAppearance, WindowBounds,
+ WindowDecorations, WindowOptions, canvas, div, fill, font, point, prelude::*, px, rgb, rgba,
+ size,
};
use std::{ops::Range, sync::atomic::Ordering, time::Duration};
use terminal::{Terminal, ansi_color};
@@ -445,6 +446,10 @@ fn key_bytes(key: &Keystroke, application: bool) -> Option<Vec<u8>> {
// Printable text is delivered by GPUI's input handler, including IME commits.
None
}
+fn translucent(color: u32, opacity: f32) -> gpui::Rgba {
+ rgba((color << 8) | (opacity.clamp(0., 1.) * 255.).round() as u32)
+}
+
impl Render for Ducky {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let c = self.config.clone();
@@ -470,7 +475,7 @@ impl Render for Ducky {
.items_center()
.gap_3()
.rounded_md()
- .bg(rgb(if active { c.surface } else { c.background }))
+ .when(active, |tab| tab.bg(rgb(c.surface)))
.text_color(rgb(if active { c.foreground } else { c.muted }))
.text_size(px(12.))
.hover(|s| s.bg(rgb(c.surface)))
@@ -550,7 +555,7 @@ impl Render for Ducky {
.overflow_hidden()
.border_1()
.border_color(rgb(c.border))
- .bg(rgb(c.background))
+ .bg(translucent(c.background, c.opacity))
.text_color(rgb(c.foreground))
.font_family(c.font.clone())
.track_focus(&self.focus)
@@ -863,6 +868,11 @@ fn main() -> anyhow::Result<()> {
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
window_decorations: Some(WindowDecorations::Client),
+ window_background: if config.opacity < 1. {
+ WindowBackgroundAppearance::Blurred
+ } else {
+ WindowBackgroundAppearance::Opaque
+ },
titlebar: Some(TitlebarOptions {
title: Some("Ducky Shell".into()),
appears_transparent: true,