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

Built-in background opacity control #73

Open
Josef-Thorne-A opened this issue Oct 30, 2018 · 7 comments
Open

Built-in background opacity control #73

Josef-Thorne-A opened this issue Oct 30, 2018 · 7 comments
Labels
beginner-friendly Good for newcomers enhancement New feature or request help wanted Extra attention is needed

Comments

@Josef-Thorne-A
Copy link
Contributor

Roxterm allows the user to set custom opacity for the terminal background. It would be nice to have this feature in Termonad. This can be done with functions in the VTE library I believe.

@cdepillabout cdepillabout added enhancement New feature or request beginner-friendly Good for newcomers labels Oct 31, 2018
@cdepillabout
Copy link
Owner

@Grendel-Grendel-Grendel thanks for posting about this as well.

Let me give short explanation of what would be needed to implement this.

  1. Figure out how to make the terminal transparent. It doesn't look like there are any transparency/opacity related options in GI.Vte.Objects.Terminal. (However, the terminalSetColorBackground takes an RGBA, and I imagine the A lets you set the opacity of the color. This might need to be changed???)

    There is a widgetSetOpacity function. You might need to call this on the terminal and the ScrollWin when they are created. I guess it is also possible that you need to call this function on the entire ApplicationWindow, but hopefully not? To be honest I'm not sure how transparency works in the GTK world.

    Also, keep in mind that widgetSetOpacity looks like it has some limitations.

  2. Add an option to the ConfigOptions that allows the user to set the opacity.

I'm setting this issue as beginner-friendly, since it should be relatively easy to look into. The only hard part will be actually figuring out how to make the terminal transparent.

@Josef-Thorne-A
Copy link
Contributor Author

Playing around with set opacity on scrollWin and vteTerm just ends up making them fade into a dark background. It seems like whatever is behind these two things also needs to be made transparent, either that or something needs to be changed with colors. I have a compositing window manager so I know the problem isn't there

deepinscreenshot_termonad_20181102213213

@cdepillabout
Copy link
Owner

@Grendel-Grendel-Grendel Thanks for taking a look at this.

As far as the GTK layout goes, the GTK Notebook should be "setting behind" the ScrollWin and Terminal. I think the only thing behind the Notebook is the actual ApplicationWindow itself. I'm not sure if you need to change the opacity of either the Notebook or ApplicationWindow.

Also, maybe you do actually have to mess with the A alpha channel in the RGBA colors of the terminal.

I can think of three other possible ways of trying to figure this out:

  • Google about how to make GTK windows transparent. I'm sure other people have wanted to do this, so there is probably a StackOverflow answer about how to do this. If not, then you could always ask one!
  • Look at the roxterm source code to figure out how roxterm is doing it. Termonad could probably do something similar.
  • Make an issue on the VTE issue tracker. I'm not sure how receptive they are to issues like this, but it might be worth a try.

@cdepillabout
Copy link
Owner

There's been a small update about this.

@dakotaclemenceplaza figured out that there was a bug in Termonad where the background colors of the terminal weren't getting their alpha set correctly. That could have been what was causing this to not work. This was fixed in #111 and #110.

Someone needs to take another look at this, now that #111 has been merged in. It might work better this time.

@n4074
Copy link

n4074 commented Oct 13, 2019

I've been looking into this and found that the background colour opacity is now properly applied. However, the ApplicationWindow is set behind the notebook and is opaque. Calling widgetSetOpacity on the ApplicationWindow also changes the opacity of the window title bar, which is unlikely to be what people want. The background of the window pane alone can be set to be fully transparent in CSS:

window {
    background-color: transparent;
}

Then the terminal opacity will correspond to the opacity of the background set in the colorscheme. Unfortunately the menubar seems to not have a background of its own, and so the menubar background will also become fully transparent. We can just set the menubar background color in the CSS as well:

menubar {
    background-color: #aaaaaa;
}

Would this suffice, or would it be better to inherit this colour from the GTK theme? I'm not sure yet how to do the latter, but will continue investigating.

@cdepillabout
Copy link
Owner

@n4074 Thanks for looking into this.

To be honest, I don't use opacity, so I'm happy to go with whatever solution you think is best :-)

@ElderEphemera
Copy link

I've managed to get this somewhat working by adapting this stack overflow answer. It works beautifully with picom, but is a mess with KWin. KWin appears to include the window itself when rendering what is behind the window, creating a feedback loop. I have no idea why this happens or how to fix it.

Here is a minimal working config:

import Control.Concurrent.MVar (readMVar)
import Control.Monad (join)

import Data.Foldable (traverse_)

import GI.Gdk.Objects.Screen (screenGetDefault, screenGetRgbaVisual)
import GI.Gtk.Objects.Widget (widgetSetVisual)

import Termonad
  ( ConfigHooks(ConfigHooks), defaultMain, defaultTMConfig, hooks, Option(Set)
  )
import Termonad.Config.Colour
  ( addColourExtension, backgroundColour, createColourExtension
  , defaultColourConfig, sRGB32
  )
import Termonad.Types (TMState, tmStateAppWin)

main :: IO ()
main = do
  colExt <- createColourExtension $ defaultColourConfig
    { backgroundColour = Set $ sRGB32 0 0 0 128 -- Opacity: 128
    }
  defaultMain $ defaultTMConfig
    { hooks = ConfigHooks $ transparencyHook
    } `addColourExtension` colExt

transparencyHook :: TMState -> terminal -> IO ()
transparencyHook tmState _terminal = do
  appWin <- tmStateAppWin <$> readMVar tmState
  maybeScreen <- screenGetDefault
  maybeVisual <- join <$> traverse (screenGetRgbaVisual) maybeScreen
  traverse_ (widgetSetVisual appWin . Just) maybeVisual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner-friendly Good for newcomers enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants