Skip to content

feat(widgets): add base64 property to image widget.#1434

Open
OddSuvius wants to merge 1 commit into
elkowar:masterfrom
OddSuvius:feat-image-base64
Open

feat(widgets): add base64 property to image widget.#1434
OddSuvius wants to merge 1 commit into
elkowar:masterfrom
OddSuvius:feat-image-base64

Conversation

@OddSuvius

Copy link
Copy Markdown

Description

Added a new :base64 property to the (image) widget. This allows users to pass Base64-encoded image data directly to Eww, completely bypassing the need to write and read temporary image files to/from disk.

Under the hood, it decodes the string natively using glib::base64_decode and pipes the raw bytes into a GTK MemoryInputStream to be consumed efficiently by gdk_pixbuf::Pixbuf::from_stream_at_scale. It also includes graceful error handling if an invalid string is passed.

Usage

You can pass a Base64-encoded image string directly into the image widget.

;; Example of a dynamically updated base64 image
(defwidget workspace_icon [icon_data]
  (image :base64 icon_data 
         :image-width 24 
         :image-height 24 
         :preserve-aspect-ratio true))

Additional Notes

My use case:
I was building a fast DWM ipc integration and needed a better way to handle app icons. Instead of the usual annoying route of doing slow .desktop file lookups or writing temporary images to the hard drive from memory I just pass the raw _NET_WM_ICON ARGB pixel data from the X11 server encoded to Base64 straight into Eww. This skips disk I/O.

Other Potential Use Cases:

  • Media Players: Scripts that fetch album art directly from APIs and can push the Base64 data directly to Eww without needing to manage a /tmp/current_album.png file.
  • Notification Daemons: Passing inline notification icons directly through IPC without saving them to disk first.
    etc...

Checklist

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

Allows users to bypass disk I/O by passing Base64 encoded image strings directly to the image widget via a new `:base64` property. Decodes natively using GLib and loads into a GTK MemoryInputStream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant