Opacified / Translucent / Transparent Windows in Cinnamon.

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Opacified / Translucent / Transparent Windows in Cinnamon.

Post by smurphos »

So a few days ago a user asked me whether it was possible to extend the feature of the Cinnamox themes to amend theme transparency on the fly to include application windows. As it stands the feature in Cinnamox can only amend transparency for the panel / menu etc. The user shared some attractive screenshots from KDE desktops with translucent windows.

So my answer was no and unlike KDE/KWin (or Mate with Compiz) Cinnamon/Muffin doesn't expose any user facing settings to force the Window manager to automatically set a specific opacity for certain types of window, albeit you can set it to adjust opacity by mouse-scrolling over the titlebar. But I thought it must be possible to do this with a bit of bash scripting...and it is...

Image

So the script below can be saved into ~/bin/ or ~/.local/bin, made executable and then added as a start-up application via the startup applications GUI. As written focused-maximised or fullscreen windows are always fully opaque, focused windowed apps are 95% opaque and non focused apps are 70% opaque. You can amend this to suit your preferences.

It also excludes a few types of application window (specifically Docks) and includes a short list of excluded applications which are always fully opaque - you can edit these exclude lists to suit your needs.

The script requires xdotool and wmctrl to be available - apt install xdotool wmctrl

I'm not the most elegant scripter so any suggestions for improvement are welcome.

Changelog -

15/3/19 - V0.2 - Windows that share a process ID with the focused window are grouped and can have an opacity set separately to other unfocused windows.
20/3/19 - V0.3 - Send any errors thrown by xdotool & xprop to /dev/null if there isn't an focused window & when the window type errors xprop (some splash banners) to elimate .xsession-errors spam.
20/4/19 - V0.4 - Fix method of detecting existing instance of running script

Updated Install Instructions - The script is now hosted on Github at https://github.com/smurphos/nemo_action ... on_scripts

Clone the repo

Code: Select all

git clone https://github.com/smurphos/nemo_actions_and_cinnamon_script
Make ~/.local/bin directory

Code: Select all

mkdir ~/.local/bin
Copy the script to ~/.local/bin

Code: Select all

cp -r ./nemo_actions_and_cinnamon_scripts/.local/bin/opacify_windows.sh ~/.local/bin
Copy the autostart entry to ~/.config/autostart

Code: Select all

cp -r ./nemo_actions_and_cinnamon_scripts/.config/autostart/opacify_windows.desktop ~/.config/autostart
Install dependencies

Code: Select all

apt install xdotool wmctrl
Optionally review the script to amend end user editable variables to suit your preferences.

Code: Select all

xdg-open ~/.local/bin/opacify_windows.sh
Log off and log back in.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 7 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Mintymandy34

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by Mintymandy34 »

smurphos wrote: Wed Mar 13, 2019 2:50 am So a few days ago a user asked me whether it was possible to extend the feature of the Cinnamox themes to amend theme transparency on the fly to include application windows. As it stands the feature in Cinnamox can only amend transparency for the panel / menu etc. The user shared some attractive screenshots from KDE desktops with translucent windows.

So my answer was no and unlike KDE/KWin (or Mate with Compiz) Cinnamon/Muffin doesn't expose any user facing settings to force the Window manager to automatically set a specific opacity for certain types of window, albeit you can set it to adjust opacity by mouse-scrolling over the titlebar. But I thought it must be possible to do this with a bit of bash scripting...and it is...

Image

So the script below can be saved into ~/bin/ or ~/.local/bin, made executable and then added as a start-up application via the startup applications GUI. As written focused-maximised or fullscreen windows are always fully opaque, focused windowed apps are 95% opaque and non focused apps are 70% opaque. You can amend this to suit your preferences.

It also excludes a few types of application window (specifically Docks) and includes a short list of excluded applications which are always fully opaque - you can edit these exclude lists to suit your needs.

The script requires xdotool and wmctrl to be available - apt install xdotool wmctrl

I'm not the most elegant scripter so any suggestions for improvement are welcome.

Code: Select all

#!/bin/bash

# A bash script to set window opacity depending on window status & type.
# Save as ~/bin/opacify_windows.sh or ~./local/bin/opacify_windows.sh and make executable
# Add a startup item to run opacify_windows.sh when you log-in.

# Requires xdotool and wmctrl - apt install xdotool wmctrl

# These variables define the opacity of various window types - value 1 to 100
EXCLUDE_OPACITY=100           # Excluded windows
FULLSCREEN_OPACITY=100        # Full screen windows
TILED_OPACITY=95              # Tiled focused windows
MAXIMISED_OPACITY=100         # Maximised focused windows
DEMANDS_ATTENTION_OPACITY=100 # Any window demanding attention
FOCUS_OPACITY=95              # Focused non-maximised application
DEFAULT_OPACITY=70            # Any others - e.g unfocused applications.

# Any window types to exclude. See https://standards.freedesktop.org/wm-spec/latest/ar01s05.html
EXCLUDE_TYPE='DESKTOP|DOCK'

# Any Window classes to exclude. This is a way of excluding specific applications from the opacify function.
# You can determine window classes for currently open applications using wmctrl -lx
EXCLUDE_CLASS='Firefox|Google-chrome|Xplayer|vlc'

# This function is called on a change of Window state and updates the opacity of all windows on the current workspace.
function opacify_windows {
  # get current workspace with xdotool
  WORKSPACE=$(xdotool get_desktop)
  # set focused window opacity
if xprop -id $1 _NET_WM_WINDOW_TYPE | egrep -q $EXCLUDE_TYPE || xprop -id $1 WM_CLASS | egrep -q $EXCLUDE_CLASS; then
  xprop -id $1 -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $EXCLUDE_OPACITY / 100)))
elif xprop -id $1 _NET_WM_STATE | grep -q FULLSCREEN; then
  xprop -id $1 -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $FULLSCREEN_OPACITY / 100)))
elif xprop -id $1 _NET_WM_STATE | grep -q TILE; then
  xprop -id $1 -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $TILED_OPACITY / 100)))
elif xprop -id $1 _NET_WM_STATE | grep -q MAXIMIZED; then
  xprop -id $1 -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $MAXIMISED_OPACITY / 100)))
elif xprop -id $1 _NET_WM_STATE | grep -q DEMANDS; then
  xprop -id $1 -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $DEMANDS_ATTENTION_OPACITY / 100)))
else
  xprop -id $1 -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $FOCUS_OPACITY / 100)))
fi
# get list of all window IDs in workspace
  WIDS=$(wmctrl -l | awk "/ $WORKSPACE /" | awk '{print$1}')
# run through list and apply default opacity excluding currently focused and excluded windows.
for w in $WIDS; do
  if xprop -id $w _NET_WM_WINDOW_TYPE | egrep -q $EXCLUDE_TYPE || xprop -id $w WM_CLASS | egrep -q $EXCLUDE_CLASS; then
    xprop -id $w -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $EXCLUDE_OPACITY / 100)))
  elif [ $w != $1 ]; then
    xprop -id $w -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * $DEFAULT_OPACITY / 100)))
  fi
done }

# Check for existing instance and exit if already running
for PID in $(pgrep -f "${0##*/}"); do
    if [ "$PID" != $$ ]; then
        exit 1
    fi  
done
# main loop
while :
do
  # get current focused window
  INITID=$(printf 0x0%x $(xdotool getactivewindow))
  # wait for any change in state in the originally focused window
  xprop -notype -id $INITID -spy _NET_WM_STATE | while read -r;
  do
    sleep 0.1;
    # update the currently focused window in case the change was a change in focus
    FOCUSID=$(printf 0x0%x $(xdotool getactivewindow))
    # call opacify function
    opacify_windows $FOCUSID
    # if change was a change in focus kill the xprop -spy process and restart loop
    if [ $INITID != $FOCUSID ]; then
     pkill -P $$ xprop
     break
    fi
  done
done
This looks incredible. :D
I'm going to test this now and will share my findings. :)
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by smurphos »

Cool - please let me know if it causes any issues. It's worked OK in testing my end so far, but I've only been testing for a few hours.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Mintymandy34

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by Mintymandy34 »

smurphos wrote: Wed Mar 13, 2019 3:20 am Cool - please let me know if it causes any issues. It's worked OK in testing my end so far, but I've only been testing for a few hours.
I'm not much of scripting person, I could only help with the visuals. :(
I read the script and you've documented it quite nicely, but some variables, commands are out of my league. :lol:

Can I suggest some modifications? In terms of visual enhancements, maybe?
I don't know if they're possible but if they could be then it would be great. :D
PM or here?

And about issues, I've not yet seen any issues, I'm testing with different apps and I've a lot of them, so I can let you know if they've any issues. :)
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by smurphos »

Post suggestions here.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Mintymandy34

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by Mintymandy34 »

smurphos wrote: Wed Mar 13, 2019 3:55 am Post suggestions here.
While testing with gedit, I found out, that even if the main application is maximised when you go to its Preferences and Preferences open up the main application falls back to 70% opacity.
This might become an issue when an user is enabling some settings and can't properly see the settings being put into effect as the main application window falls back to 70% opacity.
Maybe increasing that opacity value can help, but that would be a problem in for the other general cases. :)

Have you applied any blur effect?
If this could be applied, a little contrast can be brought back to the windows even with 70% opacity. :D
I'm not sure if it could be implemented though, what do you think?

Some applications like LibreOffice have a loading screen that start at least opacity and can't be properly seen.
It's not a problem for LibreOffice, but if some application uses such type of screens as a loading screen with tips and tricks about that software, the user might miss them.
Can those opacity value be time controlled?
I'm not sure if the time-controls will solve this, but I'm thinking how can the window manager know when an application really starts.
If time-controlled values are a reality, I think adding a delay and maybe a transition to the values for an initial time period would be good.

Tell me what you think about all these.
And it's okay if these are too far-fetched, we can implement anything that's achievable and maybe skip the far-fetched ones. :D
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by smurphos »

Thanks for the feedback...it's all good.

I'll need to do a bit of research to see if it can easily link up focused child type windows to their parent and treat the unfocused parent as as special case. I was thinking about this and GIMP actually with it's separated windows,

I don't see that issue with the LibreOffice Splash screen, but can easily exclude Splash screens so they are always full opacity.

EXCLUDE_TYPE='DESKTOP|DOCK|SPLASH'

3) I don't think a blur effect is possible via bash scripting, but will investigate.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Mintymandy34

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by Mintymandy34 »

smurphos wrote: Wed Mar 13, 2019 3:37 pm Thanks for the feedback...it's all good.
My pleasure. :)
smurphos wrote: Wed Mar 13, 2019 3:37 pm I'll need to do a bit of research to see if it can easily link up focused child type windows to their parent and treat the unfocused parent as as special case. I was thinking about this and GIMP actually with it's separated windows,
Hmm, linking child windows, you're onto something special here.
smurphos wrote: Wed Mar 13, 2019 3:37 pm I don't see that issue with the LibreOffice Splash screen, but can easily exclude Splash screens so they are always full opacity.

EXCLUDE_TYPE='DESKTOP|DOCK|SPLASH'
I checked for that in several other apps, they didn't have that issue.
It might be related to only LibreOffice AppImage.
I'll test few more, if that's the only exception, I think it can be happily ignored. :D
smurphos wrote: Wed Mar 13, 2019 3:37 pm 3) I don't think a blur effect is possible via bash scripting, but will investigate.
I think so too.
It really looks hard to implement.

I tested that opacify script with around 50 apps, I didn't notice lags or any visual issues.
It's already great, I'm using it all the time and am not letting it go. :D
Thanks for this. :)

One more thing, is there any plans to add this in your themes, in future?
I think, since it's dependent on xdotool and wmctrl, you could add a small helper script like you did in your cinnamox themes.
Helper script to tell user that it's dependent on those tools and get user permissions and maybe, maybe, give users some control over the opacity values in the terminal itself.
I think, editing scripts and changing values is cool with me, some users might find that helper script handy. :)
I think, you've already planned something similar.

And thanks for this script, it's awesome. :D
gm10

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by gm10 »

smurphos wrote: Wed Mar 13, 2019 2:50 am unlike KDE/KWin (or Mate with Compiz) Cinnamon/Muffin doesn't expose any user facing settings to force the Window manager to automatically set a specific opacity for certain types of window,
But the theme engine supports transparency, you could just modify the theme on the fly I guess. Just another reason why we need a built-in theme editor for things like colours, fonts and, sure, opacity.
scoson
Level 2
Level 2
Posts: 62
Joined: Sun Aug 26, 2018 4:07 pm

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by scoson »

I'm very interested in where this goes! I can't contribute anything, but good goin' you guys :)
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by smurphos »

gm10 wrote: Wed Mar 13, 2019 6:38 pm But the theme engine supports transparency, you could just modify the theme on the fly I guess. Just another reason why we need a built-in theme editor for things like colours, fonts and, sure, opacity.
I'm not sure if you are suggesting modifying the GTK2/GTK3 themes on the fly and reloading, or just having a fully transparent version of the stock GTK themes available to users or a theme editor that supports building one? The former I don't think would go well in practise. I think you remember I briefly experimented with your help at switching GTK theme with workspace a while back and it made for horrible lag.

Having fully transparent versions of GTK themes as alternatives would be good and probably doable. I'm not actually aware of any existing fully transparent GTK theme though and wonder if their is a reason for that? There are some with partial transparency...

Fully support a theme editing GUI, but it would be nice if Cinnamon/Muffin exposed a little more of the Window Manager internals to the end user. KDE/KWins 'Windows Rules' GUI is great in this regard as it allows rules to be set based on WM_STATUS and WM_CLASS which inspired me to try that approach in the script. Not sure if it's very newbie friendly though. Asking the window manager to set window opacity is theme agnostic as-well which I think is a bonus.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
gm10

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by gm10 »

I actually meant the first one, just like I always have (I'm sure I had suggested this to you before). I don't think the lag would matter much, it's not like you'd want to change your theme constantly, but it would save you from having to distribute separate colour variants of themes and icon sets. And these endless discussions about users not liking certain font and/or colour choices would end because they could just adjust whatever they don't like.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by catweazel »

gm10 wrote: Thu Mar 14, 2019 4:48 am I actually meant the first one, just like I always have (I'm sure I had suggested this to you before). I don't think the lag would matter much, it's not like you'd want to change your theme constantly, but it would save you from having to distribute separate colour variants of themes and icon sets. And these endless discussions about users not liking certain font and/or colour choices would end because they could just adjust whatever they don't like.
I recently thought about writing such a thing but it would be in C++ and require Qt libraries. I'm far from keen on piephon.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
gm10

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by gm10 »

catweazel wrote: Thu Mar 14, 2019 4:57 am I recently thought about writing such a thing but it would be in C++ and require Qt libraries. I'm far from keen on piephon.
Gtk theme editor written in Qt? Fight the system! :mrgreen:

Go for it, in whatever language and framework you like, whatever works. I had only taught myself Python for the Mint stuff, it's still not my fav but I've gotten used to it.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by catweazel »

gm10 wrote: Thu Mar 14, 2019 5:07 am
catweazel wrote: Thu Mar 14, 2019 4:57 am I recently thought about writing such a thing but it would be in C++ and require Qt libraries. I'm far from keen on piephon.
Gtk theme editor written in Qt? Fight the system! :mrgreen:
lol
Go for it, in whatever language and framework you like, whatever works. I had only taught myself Python for the Mint stuff, it's still not my fav but I've gotten used to it.
Well, all I really need to get started is some recommendations on the best configuration for developing GUI applications.

Hint! Hint! Nudge! Nudge! Wink! Wink!
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
gm10

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by gm10 »

catweazel wrote: Thu Mar 14, 2019 5:10 am Well, all I really need to get started is some recommendations on the best configuration for developing GUI applications.

Hint! Hint! Nudge! Nudge! Wink! Wink!
Not sure I understand, for I know you can do GUI. You mean for Python/Gtk now?
Mintymandy34

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by Mintymandy34 »

gm10 wrote: Wed Mar 13, 2019 6:38 pm But the theme engine supports transparency, you could just modify the theme on the fly I guess. Just another reason why we need a built-in theme editor for things like colours, fonts and, sure, opacity.
I'm 100% for a built-in theme editor, I think that it would be marvellous.
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by smurphos »

I've just edited the first post with version 0.2 of the script. After experimenting with a few ways to match up related windows (dialogs to parents etc) I settled on a fairly simple but I think quite pleasing method of grouping windows by PID (Process ID's) so they can have a different opacity from unrelated unfocused windows.

As provided the focused window will be 95% opaque, other windows in it's group 90% and other unfocused windows 70%.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Mintymandy34

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by Mintymandy34 »

smurphos wrote: Fri Mar 15, 2019 3:34 pm I've just edited the first post with version 0.2 of the script. After experimenting with a few ways to match up related windows (dialogs to parents etc) I settled on a fairly simple but I think quite pleasing method of grouping windows by PID (Process ID's) so they can have a different opacity from unrelated unfocused windows.

As provided the focused window will be 95% opaque, other windows in it's group 90% and other unfocused windows 70%.
Thanks I'm trying it right now. :D
User avatar
Gruppo Sportivo
Level 4
Level 4
Posts: 276
Joined: Sun May 28, 2017 4:14 am
Location: 🇳🇱

Re: Opacified / Translucent / Transparent Windows in Cinnamon.

Post by Gruppo Sportivo »

smurphos wrote: Fri Mar 15, 2019 3:34 pm I've just edited the first post with version 0.2 of the script. After experimenting with a few ways to match up related windows (dialogs to parents etc) I settled on a fairly simple but I think quite pleasing method of grouping windows by PID (Process ID's) so they can have a different opacity from unrelated unfocused windows.

As provided the focused window will be 95% opaque, other windows in it's group 90% and other unfocused windows 70%.
Script works great and is an extra addition to the themes,well done nice innovation
Locked

Return to “Cinnamon”