reddit / emacs

New Emacs frame parameter for transparency

FluentFelicity · 2022-06-07 17:53
Hi all. Just wanted to let everyone know that in January of this year Emacs introduced a new frame parameter: `alpha-background`. I wrote a little about it here: [True Emacs Transparency](https://kristofferbalintona.me/posts/202206071000/). To my knowledge, this originated from [a patch by Håkon Flatval](https://github.com/TheVaffel/emacs) in November of last year. The old `alpha` frame parameter, which many of you are aware of, sets the transparency of both the text and background (i.e. the entire frame). This new frame parameter makes *just the background* of the frame transparent. I haven't seen anything on this subreddit about it, so I thought I'd make a post. Cheers!
MitchellMarquez42 · 2022-06-07 18:07
Been looking for this. Thanks.
NoisyFrequency · 2022-06-07 18:13
Cool! I'm glad there are more options but I don't get it at all, I find transparent backgrounds super distracting, can someone explain to me their use case? Edit: thanks for the answer everyone!
FluentFelicity · 2022-06-07 18:17
I'm not sure what others use it for, but I work on a 14 inch laptop so I don't have much screen space. I use Emacs transparency to have the window under Emacs be visible, which is useful if I want to multitask, say, watching a video and writing/coding in Emacs. I also know that some users love "ricing" Emacs/Linux (i.e. making it look visually pleasing), and transparency is a big element to that, at least for the tiling window manager type of ricing.
AblatedSprocket · 2022-06-07 18:42
Is there a way to apply transparency to internal borders?
michaelhoffman · 2022-06-07 18:44
I use the old `alpha` all the time to take notes while watching a presentation over Zoom, and can't wait until the Emacs I use has `alpha-background`.
nullmove · 2022-06-07 18:49
I am on pure X11 (athena) build and it doesn't work there. Seems like original author didn't make it generic before losing interest. Anyway, I have never seen much of a point in switching to GTK since athena works just fine. Are there any other compelling advantage to switch to GTK build? (outside of nicer menu/scroll bar, wayland support; I don't need these) Edit: actually, `--with-x-toolkit=no` works as well.
elimik31 · 2022-06-07 19:42
I didn't know the word *ricing*, but this is 100% what I use the alpha-background for. I use sway as a tiling window manager on wayland and since I don't have floating windows, there's never any other window behind emacs, so the only thing I see through the transparency is a dimmed version of my screen background, which looks nice. I'm sure there are other ways to have a frame background image in emacs, but this was easiest for me. I use an alpha-background value of 0.9, which is very subtle, and have a function for toggling the transparency, which I mostly use for screenshots, in order to not mess with compression.
arthurno1 · 2022-06-07 19:50
> I haven't seen anything on this subreddit about it, so I thought I'd make a post. https://www.reddit.com/r/emacs/comments/qm3tsv/i_implemented_partial_support_for_background/ https://www.reddit.com/r/emacs/comments/qwlsbu/emacs_is_new_conky/ https://www.reddit.com/r/emacs/comments/qxf192/two_desktop_clocks_a_l%C3%A1_conky_with_emacs/
FluentFelicity · 2022-06-07 19:53
That first one is the one I reference in my post I linked. The other ones I didn't know about since Conky isn't a topic of interest to me. Thanks for linking them nonetheless.
arthurno1 · 2022-06-07 20:11
> I find transparent backgrounds super distracting, can someone explain to me their use case? It is not like you would write your normal text in a completely background window, that would be near to impossible, but there are some special use cases. Think for example [Conky](https://github.com/brndnmtthws/conky), if you are familiar with gnu/Linux and X11. You can display some information in a transparent window that appears on your desktop. Unfortunately the patch does not work for image backgrounds, so we can't display for example transparent SVG images in Emacs frame, otherwise we could do SVG animations on top of desktop, so it is not as flexible as Conky, but it can still be usable. [Someone asked for some sort of graph drawing in Emacs recently](https://www.reddit.com/r/emacs/comments/uwlx1l/is_there_an_excel_mode_that_can_connect_cells/). One could maybe simulate drawing by rendering an SVG image, still or animated, to a child window and rendering a transparent main window on top of it. I am not sure how easy/difficult would it be to implement it, but I think it is possible. Think or Photoshop/Gimp layers. Even without drawing, you could still open a child frame over an ordinary Emacs frame and do some interesting stuff on top of your ordinary text. One could display an invisible frame on top of an ordinary frame and catch user input to transform it in some way or do something etc, before sending to a buffer. I don't know, just thinking loud :-).
arthurno1 · 2022-06-07 20:12
You can have build without Gtk, but you need Cairo for this, I think.
nullmove · 2022-06-07 20:33
Nope, I have Cairo as well.
namoran · 2022-06-07 21:31
What does this do to compression?
by_wicker · 2022-06-07 21:57
I agree that it's generally distracting, though a very slight transparency can be subjectively pleasant *and* non-disruptive. But one use case I can think of is EXWM / Emacs as window manager. Even better if it could be per-window, and then you could have a nice looking status bar, or see the desktop background through unused windows, but you could achieve that with separate positioned frames. One of the things I didn't like about EXWM was how relentlessly bland my environment was. I didn't expect to care, but I do.
NoisyFrequency · 2022-06-07 22:38
That's a very different use-case from everyone else, pretty interesting that'd be like "layers" in the image manipulation software sense, I didn't consider this at first but that's pretty interesting. A cool application imo would be quiz like apps where answers are hidden and maybe narrowing management?
arthurno1 · 2022-06-07 23:21
> A cool application imo would be quiz like apps where answers are hidden and maybe narrowing management? Could be, I am not sure how do you mean, but imagination is the only limit :) By the way, just as info, if you would like to hide/unhide stuff when something happen, you can use text properties (hidden text) or overlays. That is what outline/org use when outlines are collapsed/expanded, for example.
NoisyFrequency · 2022-06-07 23:25
I meant using the drawing capabilities for narrowing, I'm not actually sure how `C-x n n` works under the hood.
arthurno1 · 2022-06-08 00:54
> I meant using the drawing capabilities for narrowing Sure, I think it could be done. You mean using region like sort of stencil buffer? But I think it would be an expensive and complicated way of doing it. > I'm not actually sure how C-x n n works under the hood. I am not sure either, but looking at narrow-to-region as implemented in editfns.c, it seems to just set "buffer bounds" to region. I guess the rendering algorithm uses those bounds to draw the visible text on the screen. With other words, it is pretty cheap, compared to creating child frames to simulate the same effect.
[deleted] · 2022-06-08 02:37
[deleted]
arthurno1 · 2022-06-08 02:49
I have just rebuild without gtk and witch cairo, it works here. Here you have my configuration: $ ./config.status --config --with-native-compilation --with-x --with-x-toolkit=no --without-gconf --without-gsettings --with-cairo --without-toolkit-scroll-bars --with-xinput2 --without-included-regex --without-compress-install 'CFLAGS= -O2 -march=native' ~/repos/emsrc/no-gtk-with-cairo-220608-041017 no-gtk-with-cairo-220608-041017 *17 And copy from 'about screen' (C-h C-a): This is GNU Emacs, a text editor and more. It's a component of the GNU/Linux operating system. GNU Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu, cairo version 1.17.6) of 2022-06-08 Copyright (C) 2022 Free Software Foundation, Inc. I can post screenshot with transparency if you want. Are you sure you have configured your Emacs with Cairo?
Wade-Mealing · 2022-06-08 03:14
repeated data in an image compresses better.
funk443 · 2022-06-08 03:26
What's the difference between using this and using picom to get transparency?
FluentFelicity · 2022-06-08 03:32
Well Picom is a compositor, which means it just provides the capacity for applications to have transparency. Picom alone doesnt give Emacs transparency; this (and the alpha parameter) does
funk443 · 2022-06-08 03:33
Thanks!
nullmove · 2022-06-08 04:20
Yeah I think so. Value of my `system-configuration-features` looks like: system-configuration-features is a variable defined in ‘C source code’. Its value is "ACL CAIRO FREETYPE GIF GLIB GMP GNUTLS HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBOTF LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF WEBP X11 XDBE XIM XINPUT2 XPM LUCID ZLIB" String listing some of the main features this Emacs was compiled with. An element of the form "FOO" generally means that HAVE_FOO was defined during the build. As far as I can tell, my configuration differs from yours only in x-toolkit, as I said I am using `--with-x-toolkit=athena`. But anyway, thanks for checking. I will build with `no` later to see if it's a problem in my cairo.
arthurno1 · 2022-06-08 04:39
Just to be sure, you are on current master, and you set the right value: (set-frame-parameter nil 'alpha-background 0.5) ? I guess you do, but just in case :).
nullmove · 2022-06-08 05:04
Yeah, `emacs-version` shows: GNU Emacs 29.0.50 (build 1, x86_64-unknown-linux-gnu, X toolkit, cairo version 1.16.0) of 2022-05-31 About a week old now, which shouldn't matter if patch was merged in January (unless there was a regression which just got fixed). I also have picom, and old `'alpha` parameter works fine for me.
nullmove · 2022-06-08 05:18
Update: built git HEAD with `--with-x-toolkit=no` like you, and now `'alpha-background` works :/ So either by some twist of luck I was on a buggy commit before, or more likely is that `--with-x-toolkit=athena` isn't supported.
arthurno1 · 2022-06-08 10:36
> more likely is that --with-x-toolkit=athena isn't supported Sounds like most plausible indeed. Evem though luck twist and right constellation between Earth, Saturn and few unknown stars might have played a role too ;-) Good you got it to work.
Drakonluke · 2022-06-08 16:11
I should make a meme about getting old while waiting for an emacs update on linux Mint.
Michaelmrose · 2022-06-15 01:01
It's pretty easy to build from source. Then you get to control the options and the update timeframe.