Skip to content
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

awful.widget.launcher has weird error when SVG string passed into image #3835

Open
NobbZ opened this issue Aug 9, 2023 · 4 comments
Open

Comments

@NobbZ
Copy link

NobbZ commented Aug 9, 2023

Output of awesome --version:

$ nix run .\#awesome -- --version
warning: Git tree '/home/nmelzer/Projects/nixos-config' is dirty
awesome 4.3 (Too long)
 • Compiled against Lua 5.2.4 (running with Lua 5.2)
 • API level: 4
 • D-Bus support: yes
 • xcb-errors support: no
 • execinfo support: yes
 • xcb-randr version: 1.6
 • LGI version: [string "return require('lgi.version')"]:1: module 'lgi.version' not found:
        no field package.preload['lgi.version']
        no file './share/lua/5.2/lgi/version.lua'
        no file './lgi/version.lua'
        no file './lgi/version/init.lua'
        no file './lib/lua/5.2/lgi/version.so'
        no file './lgi/version.so'
        no file './lib/lua/5.2/loadall.so'
        no file './lib/lua/5.2/lgi.so'
        no file './lgi.so'
        no file './lib/lua/5.2/loadall.so'
 • Transparency enabled: yes
 • Custom search paths: yes

Build from:

awesome: (git repository)
    repository: https://github.com/awesomewm/awesome.git
    branch: master
    revision: 0e5fc4575ab0adbae75908cb49937d9cf63437ec
    url: https://github.com/awesomewm/awesome/archive/0e5fc4575ab0adbae75908cb49937d9cf63437ec.tar.gz
    hash: 0zkqn5ni4iqwfxyilcnp78l0xan7ksvk1q71wqh1i2fh5hmxhn34

How to reproduce the issue:

In the default config, replace the mylauncher definition with the following:

local mylauncher = awful.widget.launcher({
    image =
    [[<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path fill="#7ebae4" fill-rule="evenodd" d="M13 11.115L6.183 23.76L4.59 20.87l1.839-3.387l-3.651-.01L2 16.029l.8-1.477l5.2.018l1.868-3.447Zm.527 10.108h13.64l-1.541 2.922l-3.658-.011l1.817 3.389l-.779 1.449h-1.593l-2.584-4.825l-3.722-.008Zm7.94-5.541l-6.82-12.645l3.134-.032L19.6 6.4l1.834-3.379h1.557l.795 1.479l-2.612 4.807l1.854 3.455Z"/><path fill="#5277c3" fill-rule="evenodd" d="m10.542 16.324l6.821 12.645l-3.134.031l-1.821-3.4l-1.834 3.38H9.016l-.8-1.476l2.615-4.804l-1.855-3.457Zm7.922-5.573H4.823l1.542-2.922l3.658.011l-1.816-3.389L8.986 3h1.592l2.584 4.825l3.722.008ZM19 20.888l6.817-12.644l1.593 2.89l-1.839 3.386l3.651.01l.778 1.449l-.8 1.477l-5.2-.018l-1.868 3.447Z"/></svg>]],
    menu = mymainmenu
})

Actual result:

I got an error like this:

2023-08-09 20:10:06 E: awesome: Failed to load '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path fill="#7ebae4" fill-rule="evenodd" d="M13 11.115L6.183 23.76L4.59 20.87l1.839-3.387l-3.651-.01L2 16.029l.8-1.477l5.2.018l1.868-3.447Zm.527 10.108h13.64l-1.541 2.922l-3.658-.011l1.817 3.389l-.779 1.449h-1.593l-2.584-4.825l-3.722-.008Zm7.94-5.541l-6.82-12.645l3.134-.032L19.6 6.4l1.834-3.379h1.557l.795 1.479l-2.612 4.807l1.854 3.455Z"/><path fill="#5277c3" fill-rule="evenodd" d="m10.542 16.324l6.821 12.645l-3.134.031l-1.821-3.4l-1.834 3.38H9.016l-.8-1.476l2.615-4.804l-1.855-3.457Zm7.922-5.573H4.823l1.542-2.922l3.658.011l-1.816-3.389L8.986 3h1.592l2.584 4.825l3.722.008ZM19 20.888l6.817-12.644l1.593 2.89l-1.839 3.386l3.651.01l.778 1.449l-.8 1.477l-5.2-.018l-1.868 3.447Z"/></svg>': Failed to open file “<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><path fill="#7ebae4" fill-rule="evenodd" d="M13 11.115L6.183 23.76L4.59 20.87l1.839-3.387l-3.651-.01L2 16.029l.8-1.477l5.2.018l1.868-3.447Zm.527 10.108h13.64l-1.541 2.922l-3.658-.011l1.817 3.389l-.779 1.449h-1.593l-2.584-4.825l-3.722-.008Zm7.94-5.541l-6.82-12.645l3.134-.032L19.6 6.4l1.834-3.379h1.557l.795 1.479l-2.612 4.807l1.854 3.455Z"/><path fill="#5277c3" fill-rule="evenodd" d="m10.542 16.324l6.821 12.645l-3.134.031l-1.821-3.4l-1.834 3.38H9.016l-.8-1.476l2.615-4.804l-1.855-3.457Zm7.922-5.573H4.823l1.542-2.922l3.658.011l-1.816-3.389L8.986 3h1.592l2.584 4.825l3.722.008ZM19 20.888l6.817-12.644l1.593 2.89l-1.839 3.386l3.651.01l.778 1.449l-.8 1.477l-5.2-.018l-1.868 3.447Z"/></svg>”: No such file or directory
stack traceback:
        ...08cb49937d9cf63437ec/share/awesome/lib/gears/surface.lua:103: in function <...08cb49937d9cf63437ec/share/awesome/lib/gears/surface.lua:95>
        (...tail calls...)
        ...937d9cf63437ec/share/awesome/lib/awful/widget/button.lua:54: in function 'set_image'
        ...937d9cf63437ec/share/awesome/lib/awful/widget/button.lua:61: in function <...937d9cf63437ec/share/awesome/lib/awful/widget/button.lua:42>
        (...tail calls...)
        ...7d9cf63437ec/share/awesome/lib/awful/widget/launcher.lua:72: in function <...7d9cf63437ec/share/awesome/lib/awful/widget/launcher.lua:70>
        (...tail calls...)
        /nix/store/99i2bz5h83aq29d8k99dkhmpvz22iv2p-awesomerc.lua:70: in main chunk
2023-08-09 20:10:07 W: awesome: a_glib_poll:477: Last main loop iteration took 0.167526 seconds! Increasing limit for this warning to that value.
2023-08-09 20:10:11 E: awesome: a_xcb_io_cb:441: X server connection broke (error 1)

Expected result:

Two variants:

  1. Display the error also as a notification, not in the terminal
  2. No error message displayed and a nice SVG icon is used for the menu widget.

Preferably 2, as that would reflect what is currently documented: https://awesomewm.org/apidoc/widgets/awful.widget.launcher.html#image

image

@actionless
Copy link
Member

actionless commented Aug 9, 2023

it seems to be not updated to suort new rsvg handle, it should be smth like this, but i don't have time to finish it as a comlete and tested patch:

diff --git a/lib/awful/widget/button.lua b/lib/awful/widget/button.lua
index c71dc8831..733885b29 100644
--- a/lib/awful/widget/button.lua
+++ b/lib/awful/widget/button.lua
@@ -39,12 +39,23 @@ function button.new(args)
     local img_press

     function w:set_image(image)
-        img_release = surface.load(image)
-        img_press = img_release:create_similar(cairo.Content.COLOR_ALPHA, img_release.width, img_release.height)
-        local cr = cairo.Context(img_press)
-        cr:set_source_surface(img_release, 2, 2)
-        cr:paint()
-        orig_set_image(self, img_release)
+        orig_set_image(self, image)
+        img_release = w._private.image
+        if not img_release then
+            local handle = w._private.handle
+            if handle then
+                local surf = cairo.ImageSurface(-2, -2, w._private.default.width, w._private.default.height)
+                local cr = cairo.Context(surf)
+                handle:render_cairo(cr)
+                img_release = surf
+            end
+        end
+        if img_release then
+            img_press = img_release:create_similar(cairo.Content.COLOR_ALPHA, img_release.width, img_release.height)
+        end
     end
     w:set_image(args.image)

@actionless actionless added the bug label Aug 9, 2023
@Aire-One
Copy link
Member

Aire-One commented Aug 9, 2023

Hello @NobbZ,

Thank you for the report.

The bug comes from this method override in awful.widget.button. (To be fair, the method override was written long before imagebox supports that much image sources)

function w:set_image(image)
img_release = surface.load(image)
img_press = img_release:create_similar(cairo.Content.COLOR_ALPHA, img_release.width, img_release.height)
local cr = cairo.Context(img_press)
cr:set_source_surface(img_release, 2, 2)
cr:paint()
orig_set_image(self, img_release)
end

The implementation needs to be revisited.

@Aire-One
Copy link
Member

Aire-One commented Aug 9, 2023

Oops! You're too fast @actionless

I'll mark the issue as "Good first issue" so new contributors can pick up your patch and finish the work 😄

@actionless
Copy link
Member

actionless commented Aug 9, 2023

i also was thinking that strategically it might be better to extract logic from imagebox:set_image() somewhere into gears.surface, to not write if handle boilerlate everywhere and have instead an universal function to get a surface from anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants