Bug 446381

Summary: Temporary rules are not deleted from the config file
Product: [Plasma] kwin Reporter: r1ntse.a
Component: rulesAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: isma.af, ivnitsky.a
Priority: NOR    
Version First Reported In: 5.23.3   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 6.1
Sentry Crash Report:

Description r1ntse.a 2021-12-02 16:41:58 UTC
SUMMARY
kwin rules not saved upon reboot.

STEPS TO REPRODUCE
1. Start with empty rules section in settings. (also .config/kwinrulesrc is empty)
2. Import the following rule:
``` 
[Disable composoting for slippi]
Description=Disable composoting for slippi
blockcompositing=true
blockcompositingrule=6
title=Dolphin
titlematch=1
wmclass=apprun
wmclassmatch=1
```
3. Hit apply.
4. Reboot.

OBSERVED RESULT
The rule gone in the settings app (but present in .config/kwinrulesrc). 
The rule does not trigger.

EXPECTED RESULT
The rule triggers and shows up in the settings app.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 5.23
KDE Plasma Version: 5.23.3
KDE Frameworks Version: 5.88.0
Qt Version: 5.15.3

ADDITIONAL INFORMATION
The rule is active and is listed as expected before reboot.
kwinrulesrc at that points contains the rule as well as:
```[General]
rules=3e2338cb-3ebc-47eb-8e6e-6fdcef00f79f```
Comment 1 Ismael Asensio 2021-12-02 19:34:33 UTC
It seems you set the rule to "Force temporarily" (blockcompositingrule=6)

By design this setting forces the rule while the window is active and then deletes it, since it's a temporary setting
If you'd like to have it permanently please set it to "Force" instead.

There's a bug though, and it's that it keeps it on the kwinrulesrc file.
Comment 2 r1ntse.a 2021-12-02 22:39:10 UTC
(In reply to Ismael Asensio from comment #1)
> It seems you set the rule to "Force temporarily" (blockcompositingrule=6)
> 
> By design this setting forces the rule while the window is active and then
> deletes it, since it's a temporary setting
> If you'd like to have it permanently please set it to "Force" instead.
> 
> There's a bug though, and it's that it keeps it on the kwinrulesrc file.

I completely misunderstood what "temporarily" indicates in that case. Sorry for the report.
Comment 3 Ismael Asensio 2021-12-02 22:46:12 UTC
(In reply to r1ntse.a from comment #2)
> (In reply to Ismael Asensio from comment #1)
> > It seems you set the rule to "Force temporarily" (blockcompositingrule=6)
> > 
> > By design this setting forces the rule while the window is active and then
> > deletes it, since it's a temporary setting
> > If you'd like to have it permanently please set it to "Force" instead.
> > 
> > There's a bug though, and it's that it keeps it on the kwinrulesrc file.
> 
> I completely misunderstood what "temporarily" indicates in that case. Sorry
> for the report.

Don't be. It was a very good and thorough report, with all the information required to figure it out.

And it exposed something that it isn't working right, so thanks a lot for your time on it!

If you don't mind, I'll change the title of the bug to track that temporary rules are not deleted from the config file.
Comment 4 Andrei Ivnitskii 2022-06-24 07:16:56 UTC
Can  confirm this in Plasma 5.24. Rules with "apply now" are not deleted from config file and not displayed in "Windows rules"
Comment 6 Ismael Asensio 2024-05-13 18:25:49 UTC
Git commit d2d92cdfd2c1869942cf119b2b8f680750fa7e96 by Ismael Asensio.
Committed on 13/05/2024 at 18:18.
Pushed by iasensio into branch 'master'.

rules/RuleBook: Optimize saving discarded rules to config

After porting to KConfigXT settings some time ago, there was still an
inefficient and error-prone codepath between the `RuleBook` (which keeps
the runtime list of `Rules`) and the `RuleBookSettings` (responsible for
config reads and saves), in the form of the `setRules()` method.

We can eliminate the `setRules()` codepath, reducing unnecessary
runtime process and file access operations, and instead:
- Keep track of the config `id` in the `Rules` objects
- Keep a single `RuleBookSettings` object as a member
- Modify or delete the discarded rules settings directly
- Save when necessary

This also fixes two bugs/pitfalls of the previous solution:
- the config group id for each rule is now preserved instead of creating
  new ones
- no leftovers on the config file for the discarded groups and entries

Setting custom configs for the integration tests still works unchanged.
FIXED-IN: 6.1

M  +12   -44   src/rulebooksettings.cpp
M  +2    -4    src/rulebooksettings.h
M  +29   -13   src/rules.cpp
M  +6    -6    src/rules.h

https://invent.kde.org/plasma/kwin/-/commit/d2d92cdfd2c1869942cf119b2b8f680750fa7e96