Opacity slider in window menu

About programming and getting involved with Linux Mint development
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
NeatNit
Level 1
Level 1
Posts: 3
Joined: Thu Jan 26, 2023 8:21 am

Opacity slider in window menu

Post by NeatNit »

I want to add an opacity slider, like this mock-up:

Image

Context:
Today, if you go to System Settings -> Windows, and change "Action on title bar with mouse scroll" to "Adjust opacity", you can make any window partially transparent! I want to add a more convenient way to access this feature. More importantly, the scroll action doesn't work on all windows - an easy example is the Calculator app that comes installed by default (GNOME Calculator).

While I think this could be a good pull request, I decided to try and implement it in an Extension first. I started looking into how to do it but reached a dead end. I never worked with Cinnamon before so I might be missing something. Here's what I have so far:

1. This is the code that handles the mouse scroll action. It sets window->opacity and then calls meta_compositor_window_opacity_changed, which in turn calls meta_window_actor_update_opacity.
2. The window menu (which appears when you right-click a window's title bar) is implemented in JavaScript here. Specifically, when the user right-clicks, this line creates a new WindowMenu object, and generating the actual menu items happens in _buildMenu. Here's my first problem: I don't see any clean way to add my own extra items to the menu through an extension.
3. Assuming there was a way (e.g. hijacking the _buildMenu function), adding the slider itself should be easy - WindowMenu extends PopupMenu which has an implementation of a Slider menu item - although I haven't tested it, and I don't know if it's used anywhere.
4. Now comes the actual dead end... Setting window->opacity is easy (probably), but how do I call meta_window_actor_update_opacity? I've been trawling the linuxmint repositories for hours. I don't really understand how the JS <-> C glue works. Is there just no way?

An extension called Opacify uses a tweener to change the window's opacity value but doesn't call meta_window_actor_update_opacity. Probably as a result, it has a long-standing rendering bug.


I hope that wasn't too much :) but to sum up:

How does the JS <-> C binding happen?

How can I call that specific C function from a JavaScript extension?

How can I - or can I - add a menu entry to WindowMenu? (Note, this will not be necessary for a pull request - only for an extension)
Last edited by LockBot on Tue Aug 08, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
NeatNit
Level 1
Level 1
Posts: 3
Joined: Thu Jan 26, 2023 8:21 am

Re: Opacity slider in window menu

Post by NeatNit »

Well. I just found that window.set_opacity([0-255]) exists and works. That's surprising - I'm not sure why I didn't find it before.

Now I just have to figure out how to add a menu entry.
NeatNit
Level 1
Level 1
Posts: 3
Joined: Thu Jan 26, 2023 8:21 am

Re: Opacity slider in window menu

Post by NeatNit »

It works! https://github.com/NeatNit/cinnamon-opa ... eatnit.net

Image

I still need to figure out why adding the slider causes the whole menu to get wider.
Locked

Return to “Programming & Development”