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

New icons seem to have white background #1018

Closed
kidpollo opened this issue Apr 13, 2023 · 41 comments
Closed

New icons seem to have white background #1018

kidpollo opened this issue Apr 13, 2023 · 41 comments
Labels

Comments

@kidpollo
Copy link

Its weird I the repo seems to show images with transparent background but in my editor they don't seem right :(

Using

Treemacs 3.1
Emacs 29.0.60
Spacemacs develop branch

Screenshot 2023-04-13 at 11 46 58 AM

@idanov
Copy link

idanov commented May 16, 2023

I can report the same issue. Here's details for my setup. It seems that it's an issue with all the svg icons.

macOS M1, using emacs-plus.
Spacemacs development branch
GNU Emacs 29.0.90 (build 1, aarch64-apple-darwin22.4.0, NS appkit-2299.50 Version 13.3.1 (Build 22E261)) of 2023-05-02
[Treemacs] v3.1 (installed 2023.05.02) @ Emacs 29.0.90

image

@ashlineldridge
Copy link

Is it possible to disable these fancy directory icons and make all directories display the same "normal" icons?

@ashlineldridge
Copy link

ashlineldridge commented Jun 16, 2023

The recent changes to master seem to have fixed this issue for me 👍🏽

EDIT: I was mistaken

Screenshot 2023-06-17 at 7 14 10 am

@Alexander-Miller Any idea why these white-background png images are being used for special directories? I'm using treemacs-nerd-icons which should have suitable unicode character icons for these file/dir types.

  (use-package treemacs-nerd-icons
    :after (treemacs nerd-icons)
    :functions treemacs-load-theme
    :custom-face
    (treemacs-nerd-icons-root-face ((t (:inherit nerd-icons-green :height 1.3))))
    (treemacs-nerd-icons-file-face ((t (:inherit nerd-icons-dsilver))))
    :config
    (treemacs-load-theme "nerd-icons"))

Really all I'm looking for is a way to go back to the default closed/open directory icon that is being displayed for non-special directories.

@ashlineldridge
Copy link

I figured out what is causing these ugly icons to be shown (at least in my case). These icons are being used when the current theme does not provide an override for them. In my case, treemacs-nerd-icons doesn't provide icons for src-open, src-closed, build-open, build-closed, etc. So the image icons from the "Default" theme get used. It's unfortunate that it works this way, as third-party themes will often be behind the full set of icons that treemacs might wante to display and I can't imagine why a person would ever want these unmatching image icons mixed in with their cohesive theme - much better to just have treemacs default to the standard dir-open and dir-closed.

Anyway my fix was to override the treemacs icon propagation function like so: (defun treemacs--propagate-new-icons (_theme)). My full treemacs config is below for anyone interested.

(use-package treemacs
  :bind
  (:map global-map
        ("M-t" . treemacs)
        ("M-0" . treemacs-select-window))
  (:map treemacs-mode-map
        ;; Otherwise it takes two clicks to open a directory.
        ([mouse-1] . treemacs-single-click-expand-action))

  :hook
  ;; Don't wrap long lines in Treemacs.
  (treemacs-mode . (lambda () (setq-local truncate-lines t)))

  :custom
  (treemacs-follow-mode 1)
  (treemacs-project-follow-mode 1)
  (treemacs-filewatch-mode 1)
  (treemacs-width 40)
  (treemacs-missing-project-action 'remove)
  (treemacs-follow-after-init t)

  :config
  (defun treemacs--propagate-new-icons (_theme))
  (use-package treemacs-nerd-icons
    :functions treemacs-load-theme
    :custom-face
    (treemacs-nerd-icons-root-face ((t (:inherit nerd-icons-green :height 1.3))))
    (treemacs-nerd-icons-file-face ((t (:inherit nerd-icons-dsilver))))
    :config
    (treemacs-load-theme "nerd-icons"))

  ;; By default, treemacs-mode will add itself to `aw-ignored-buffers' which
  ;; prevents jumping to its window using ace-window. Personally, I prefer
  ;; being able to treat it just like any other window.
  (require 'ace-window)
  (setq aw-ignored-buffers (delq 'treemacs-mode aw-ignored-buffers)))

@kidpollo
Copy link
Author

I confirm that latest did NOT fix it for me either

@kidpollo
Copy link
Author

I tried changing to the all-the-icons theme and also get ugly icons. I am using spacemacs.

@ashlineldridge
Copy link

@kidpollo Did you try following my workaround above?

@BlindingDark
Copy link
Contributor

Another way is to convert these svg to png (but still keep the suffix name as svg), you may need to install librsvg first.

#!/bin/bash
## brew install librsvg
TREEMACS_PATH=$(find ~/.emacs.d/elpa -type d -name 'treemacs-[0-9]*' -print)
TREEMACS_ICONS_PATH="$TREEMACS_PATH/icons/default/vsc"

pushd $TREEMACS_ICONS_PATH

for file in *.svg
do
    filename=$(basename $file .svg)
    echo $filename
    rsvg-convert $filename.svg > $filename.svg.png
    mv $filename.svg.png $filename.svg
done

popd

Note that this script replaces the original svg file, so you can only run this script once

@Alexander-Miller
Copy link
Owner

Does your Emacs have a general problem with svgs or is it something that treemacs does? Try downloading this image and then insert it like this: (insert "\n" (propertize " " 'display (create-image "~/Downloads/schedule.svg"))).

Do you also see a white background then?
On my end it looks like this:
p

@BlindingDark
Copy link
Contributor

@Alexander-Miller On my side no white background in this calendar svg.

@Alexander-Miller
Copy link
Owner

Do you see the red background when you do this?

(insert "\n" (propertize " " 'display (create-image "~/Downloads/schedule.svg" 'svg nil :background "#ff0000")))

@BlindingDark
Copy link
Contributor

Yes, I can get a red background.

@Alexander-Miller
Copy link
Owner

All right, that is one theory down the drain. Back to digging.

Make sure treemacs is open, then run this:

(let ((icons (with-current-buffer (treemacs-get-local-buffer) treemacs-icons))
      (eval-expression-print-level 999))
  (insert (ht-get icons "src-closed"))
  (print (ht-get icons "src-closed")))

Does the inserted icon have a white background?
What is printed? It should be something like this:

#(" " 0 1 (display (image :type png :file "/home/am/Documents/git/treemacs/icons/default/git.png" :scale 1 :ascent center :width 22 :height 22 :transform-smoothing t :background "#2d2d31") img-selected (image :type png :file "/home/am/Documents/git/treemacs/icons/default/git.png" :scale 1 :ascent center :width 22 :height 22 :transform-smoothing t :background "#383844") img-unselected (image :type png :file "/home/am/Documents/git/treemacs/icons/default/git.png" :scale 1 :ascent center :width 22 :height 22 :transform-smoothing t :background "#2d2d31")))

Take the :file that's in the output and pass it to the same code as before:

(insert "\n" (propertize " " 'display (create-image "/home/am/Documents/git/treemacs/icons/default/vsc/dir-src-closed.svg" 'svg nil)))

Does this version of the icon have a white background?

@kidpollo
Copy link
Author

kidpollo commented Jul 3, 2023

Hi @Alexander-Miller !

Sorry i've been in holiday. Here is a screenshot of what you have requested so far.

Screenshot 2023-07-03 at 3 03 07 PM

That insert seems to produce an error when I replace with that image path for me I get that invalid image size error. Also note on that let form the icon did show with white background.

(let ((icons (with-current-buffer (treemacs-get-local-buffer) treemacs-icons))
      (eval-expression-print-level 999))
  (insert (ht-get icons "src-closed"))
  (print (ht-get icons "src-closed")))
  

;;  In *Messages* buffer
;;#("  " 0 1 (img-unselected (image :type imagemagick :file "/Users/paks/.emacs.d/elpa/29.0/develop/treemacs-20230615.1714/icons/default/vsc/dir-src-closed.svg" :scale 1 :ascent center :width 22 :height 22 :transform-smoothing t :background "#282c34") img-selected (image :type imagemagick :file "/Users/paks/.emacs.d/elpa/29.0/develop/treemacs-20230615.1714/icons/default/vsc/dir-src-closed.svg" :scale 1 :ascent center :width 22 :height 22 :transform-smoothing t :background "#21242b") display (image :type imagemagick :file "/Users/paks/.emacs.d/elpa/29.0/develop/treemacs-20230615.1714/icons/default/vsc/dir-src-closed.svg" :scale 1 :ascent center :width 22 :height 22 :transform-smoothing t :background "#282c34"))) [2 times]


(insert "\n" (propertize " " 'display (create-image "/Users/paks/.emacs.d/elpa/29.0/develop/treemacs-20230615.1714/icons/default/vsc/dir-src-closed.svg" 'svg nil)))

 
;;  In *Messages* buffer many times
;; Invalid image size (see ‘max-image-size’) [29 times]

@BlindingDark
Copy link
Contributor

Same as @kidpollo here

@Alexander-Miller
Copy link
Owner

That insert seems to produce an error when I replace with that image path for me I get that invalid image size error.

Try it with explicit width and height arguments, like this:

(insert "\n" (propertize " " 'display (create-image "/home/am/Documents/git/treemacs/icons/default/vsc/dir-src-open.svg" 'svg nil :width 33 :height 33)))

Another thing: Is everyone who has this issue on Emacs 29?

@kidpollo
Copy link
Author

kidpollo commented Jul 5, 2023

Yeah Emacs 29 here. I just get a black square

I did use the 'svg nil :width 33 :height 33 options as you suggested

Screenshot 2023-07-05 at 1 35 31 PM

@Alexander-Miller
Copy link
Owner

Let's check whether it's something I did with the icons. Download the original one here, and try inserting that.

Also is svg a member of your image-types variable?

@kidpollo
Copy link
Author

kidpollo commented Jul 5, 2023

Black square again and yes on the SVG in image-types
Screenshot 2023-07-05 at 2 36 56 PM

@ashlineldridge
Copy link

ashlineldridge commented Jul 6, 2023

@Alexander-Miller

Another thing: Is everyone who has this issue on Emacs 29?

Yes to 29 for me too. Thanks for looking into this.

Is my conclusion here correct? I.e. that:

...treemacs-nerd-icons doesn't provide icons for src-open, src-closed, build-open, build-closed, etc. So the image icons from the "Default" theme get used.

Isn't this why the not-so-attractive icons get displayed? Because they're getting pulled from the "Default" theme rather than the treemacs-nerd-icons theme? What is the desired behaviour here? It seems that unless there is a standard set of icon names (i.e. dir-open, dir-closed, src-open, etc) that all themes can agree on, we'll always be susceptible to third-party themes not implementing particular icons and then falling back to a default that doesn't fit in with the theme?

(This is somewhat orthogonal to the white background - I guess I'm coming from the angle of using a third-party theme like treemacs-nerd-icons to avoid the SVGs altogether).

@Alexander-Miller
Copy link
Owner

Isn't this why the not-so-attractive icons get displayed? Because they're getting pulled from the "Default" theme rather than the treemacs-nerd-icons theme? What is the desired behaviour here?

Extending the default theme - or any other theme for that matter - is an opt in feature. You have to explicitly ask for it - see the :extends argument of treemacs-create-theme. If you don't set it the theme you create will contain only the icons you give it, including your fallbacks.

Yes to 29 for me too. Thanks for looking into this.

It's not just Emacs 29. I have compiled my own v29.0.92 now, and svgs still work fine on my end. I am starting to run out of ideas here. The only thing left for me is to see whether other packages are affected too. If they are you should raise the bug with whoever compiled your Emacs.

Another svg-using package is all-the-icon. Clone it, check out the "svg" branch, then run this:

(add-to-list 'load-path  "~/Documents/git/all-the-icons.el")
(require 'all-the-icons)
(insert (all-the-icons-icon-for-file "x.el"))

If all-the-icons' svgs don't work either then I think I am officially not to blame.

@kidpollo
Copy link
Author

Screenshot 2023-07-11 at 4 28 11 PM

All the icons seemed to work for me there

@kidpollo
Copy link
Author

Its just the "special" file or folder icons with the problem but I just realized if I force the all the icons theme I don't see a different icon for the src directory anymore. The problem is I kinda prefer the default theme. Also all the icons theme alignment is kinda weird.

So its this

Screenshot 2023-07-11 at 4 43 29 PM

VS:

Screenshot 2023-07-11 at 4 45 08 PM

@kidpollo
Copy link
Author

I'll keep All the icons theme for now. Its honestly not a bit deal IMO I just wanted to report it because its weird :P

Thanks @Alexander-Miller for looking into this feel free to close.

@kidpollo
Copy link
Author

NVM I dont know what happened but they show again with all the icons . I don't know why suddenly they now show :S
Screenshot 2023-07-11 at 5 02 04 PM

@Alexander-Miller
Copy link
Owner

Good news: I seem to have reproduced the problem, at least I am now seeing black squares instead of svg icons. No idea why now, I don't think I changed anything.

The bad news: the icons are to blame. I took them from this repo, and almost every single icon in there shows as a black square for me now with only a few exceptions. Other icons seem to work. I'll keep looking for a replacement, or maybe a version that does work.

@kidpollo
Copy link
Author

kidpollo commented Jul 24, 2023 via email

@Alexander-Miller
Copy link
Owner

Small test: I have uploaded a new version of one icon. Can you confirm that directories named "docs" or "readme" have the correct icon now? It should look like this
docs

@kidpollo
Copy link
Author

Ugh, I've been trying to check this out for you but I am getting a different error. Where treemacs does not even load the files. I've tried re-installing emacs. Clearing my .emacs, but no dice. I am not sure if it's because of my emacs setup or the latest treemacs-specific issue.

This is what I see in *Messages*

Saving file /Users/paks/.emacs.d/.cache/treemacs-persist...
Wrote /Users/paks/.emacs.d/.cache/undo-tree-history/.!Users!paks!.emacs.d!.cache!treemacs-persist.~undo-tree~
Wrote /Users/paks/.emacs.d/.cache/treemacs-persist
Wrote /Users/paks/.emacs.d/.cache/undo-tree-history/.!Users!paks!.emacs.d!.cache!treemacs-persist.~undo-tree~
Symbol’s value as variable is void: treemacs
Error in post-command-hook (treemacs--post-command): (wrong-type-argument number-or-marker-p nil)
Error during redisplay: (eval (doom-modeline-segment--modals)) signaled (void-function nil) [164 times]
End of buffer
Error during redisplay: (eval (doom-modeline-segment--modals)) signaled (void-function nil) [4 times]
Mark set
Error during redisplay: (eval (doom-modeline-segment--modals)) signaled (void-function nil) [12 times]

Ill keep poking at this. Not sure how package versions work in emacs but it seems I have 20230809.2040. Its installed trough the treemacs layer in spacemacs.

@kidpollo
Copy link
Author

If it helps this is what I see in a Dired buffer

Screenshot 2023-08-09 at 5 59 05 PM

@kidpollo
Copy link
Author

This one shows a docs folder
Screenshot 2023-08-09 at 6 01 12 PM

@kidpollo
Copy link
Author

Ok the issue seems to be related to doom theme, weird I did not have a problem before but here it is. Looks the same as Dired
Screenshot 2023-08-10 at 5 12 47 PM

@Alexander-Miller
Copy link
Owner

Ok the issue seems to be related to doom theme

Yeah, there was a doom modeline related change that borked things for a day or two. That one should be fixed now.

Looks the same as Dired

Does it also look like this is you download the image directly and then create an icon yourself like this (insert "\n" (propertize " " 'display (create-image "~/Downloads/docs-svgrepo-com.svg" 'svg nil :width 22 :height 22)))?

@Alexander-Miller
Copy link
Owner

I've now also replaced the src, test, git & github icons with those from svgrepo.

@kidpollo
Copy link
Author

Hope this screenshot conveys all the answers you currently seek 😛
Screenshot 2023-08-17 at 11 49 59 AM

@Alexander-Miller
Copy link
Owner

What if you take the downloaded icon and feed it to treemacs?

(treemacs-create-icon :file "~/Downloads/docs-svgrepo-com.svg" :extensions ("docs-closed"))

You'll need to hit refresh for the change to apply.

@kidpollo
Copy link
Author

kidpollo commented Aug 24, 2023 via email

@Alexander-Miller
Copy link
Owner

Ok, enough with the svgs. I've converted the docs icon to a png now. If you can confirm that it works for you as well I'll convert the rest as well.

@kidpollo
Copy link
Author

Yay! Docs folder looks good now. The others still don't but that's great! Thaks!
Screenshot 2023-08-30 at 2 12 01 PM

@Alexander-Miller
Copy link
Owner

I've converted all the svg icons back to pngs. Do things look correct on your end now?

@kidpollo
Copy link
Author

Loooks beautiful! Thanks for the hard work and sorry for the late response!

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

No branches or pull requests

5 participants