Window rule for Firefox no longer sets window size

I have a window rule for Firefox that sets the size and position when I open it.

The position is still working, but the size rule stopped working a few days ago. I see Firefox open to the correct position, and the window looks like it is opening to the desired size very briefly, but then the size shrinks.

I’ve tried Force, and Remember, but no help.

Plasma 6 and Wayland.

You could try re-setting the window class using the detect window property tool to pick the details from your Firefox window, it could be a change within Firefox that has caused it.

I deleted the rule and recreated it, a few times, with Detect Window Properties.

The rule is firing and placing the window where I want it, upper left corner.

I suppose it could be a recent update of Firefox that is overriding the size that kwin applies very briefly.

Are you using the plasma title bar?
I. e. is it ticked, right click next to url bar, Costumize and tick Title Bar on the very bottom left?

Yes, Title Bar is checked.

Are you using Firefox from Flatpak, snap or a local system install?

1 Like

Local install. I download the tarball from Mozilla and unpack it directly.

If you set it to “force” it still opens at the correct size briefly and then resize?

Yes, same behavior with Apply Initially, Force, and Remember.

After I restarted Firefox and the window shrank in size, I opened the window rule, selected Apply Now for Size, and the window expanded to the size I have set in the rule.

I set Size back to Apply Initially, and New Window and New Private Window both open to the desired size.

I opened the debug console and confirmed what I thought, that the window is resizing to the “default” size (the size with no window rule).

Start Firefox with the window rule - it opens, shrinks, and I see:

frameGeometry 0,0 1283x750

Correct position, top left corner, but wrong size.

I delete the window rule and restart Firefox and see:

frameGeometry 382,182 1283x750

A centered window with the “default” 1283x750 size.

The position rule working, but the size rule getting overridden is odd.

1 Like

I have no idea what can be the problem, but perhaps you can workaround by creating a custom kwin script that “waits” a bit before resizing the window. If this may be a solution for you I can guide you through the procedure

PS it just came to my mind an old problem I had with Firefox that I solved by setting an environmental variable to force Wayland instead of x11 as backend. I think this should be the default now, but never say never. Try to look for “Firefox force Wayland” for the procedure

Thanks for the offer on a kwin script, tubbadu. I’m going to just resize after the rare reboot for now.

I do have that env variable set:

$ env | grep MOZ
MOZ_ENABLE_WAYLAND=1

1 Like

Hi tubbadu
I’m interested in the custom kwin script you offered:
“… script that “waits” a bit before resizing the window.”
I restart often and getting tired of resizing the Firefox window after it overrides my kwin rule.

Hi reteip!
I’m currently not at home so I cannot write and test the script right now, I’ll do it as soon as I can.

The idea is to write a custom kwin script (JavaScript) using the API provided by kwin: KWin scripting API | Developer

The script should register a handler for the windowAdded signal: kwin will call the handler function anytime a new window is created. The handler should check if the window is a Firefox window, and if it is it should wait some time (can be achieved with a JavaScript timer or something like that), and then resize the window

If you want to try to write it it’s not that hard, otherwise I’ll write it for you as soon as I can

(Note: the APIs are plasma 6 specific. The plasma 5 APIs are slightly different)

Okay, thank you. Yes, I’m using Plasma 6. I haven’t written a script previously, but will have a look at the link when I have more time on the weekend.
Cheers

Sorry for the very late reply, I completely forgot about it :confused:
here’s an example script to wait for 2 seconds before resizing the firefox window when it is created:

function onWindowAdded(win) {
	if(win.resourceName == "firefox" && win.resourceClass == "firefox"){
		console.log("firefox added!")
		var timer = new QTimer();
		timer.timeout.connect(function() {
			let geom = Object.assign({}, win.frameGeometry);
			geom.height = 900
			geom.width = 900
			geom.x = 100
			geom.y = 100
			win.frameGeometry = geom
		});
		timer.interval = 1000; // milliseconds
		timer.singleShot = true;
		timer.start()
	}
}
workspace.windowAdded.connect(onWindowAdded);

you can adjust position, size and timer interval to fit your use case

you can try to run it using plasma-interactiveconsole, but make sure to log out and log back in everytime you change some values in the script, because otherwise multiple copies of the script will run concurrently, leading to unexpected behavior.
once you’re happy with your script you can install it following this simple guide.

Let me know if it works for you or if you find any problem!

Hey that’s great, thank you :slight_smile:
I looked at the scripting tool, but wasn’t confident. So now I’ll give this a go and let you know.
Cheers

1 Like

Just curiosity. What exactly version of Plasma do you have?
After kinfocenter:
Operating System: Fedora Linux 40
KDE Plasma Version: 6.1.1
KDE Frameworks Version: 6.4.0
Qt Version: 6.7.1
Kernel Version: 6.8.5-301.fc40.x86_64 (64-bit)
Graphics Platform: Wayland

In my system I checked your problem, and Firefox 130.0.1 started at the chosen place and size without any problems.

Radek

PS.: Can you check if you can change theme for borders. I want mark private Firefox mode with diff color on title bar. Thanks.

Hi Radek
I have:
Operating System: openSUSE Tumbleweed 20241005
KDE Plasma Version: 6.1.5
KDE Frameworks Version: 6.6.0
Qt Version: 6.7.3
Kernel Version: 6.11.0-1-default (64-bit)
Graphics Platform: Wayland

4K screen scaled to 150%

Currently running the Flatpak version of Firefox - 131.0

Regarding the theme for boarders, changing the window decorations border option, say to ‘tiny’, has no effect even after logging out & back in. It seems only the theme’s default ‘normal’ boarder option is able to take effect.
I have no option to change just the Firefox title bar.

I’ve started my journey learning about scripting tubbadu, but it’s taking me some time to work out how to do this properly. I’ll hopefully have more time this week to learn more and work on trying this out.