Skip to content

Commit 6f3b432

Browse files
committed
add configuration to include/exclude windows by application
1 parent ed93b0a commit 6f3b432

File tree

11 files changed

+143
-116
lines changed

11 files changed

+143
-116
lines changed
-28.2 KB
Loading

always-open-on-active-screen/CHANGELOG.bbcode

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[h1]v4.0[/h1]
2+
[list]\n[*] add configuration to include/exclude windows by application
3+
[/list]
4+
15
[h1]v3.0[/h1]
26
[list]\n[*] better compatibility with Wayland
37
[/list]

always-open-on-active-screen/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v4.0
2+
- add configuration to include/exclude windows by application
3+
14
# v3.0
25
- better compatibility with Wayland
36

always-open-on-active-screen/README.bbcode

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
Makes new windows always open on the monitor that has the mouse cursor.
22

3+
The windows to be affected can be filtered by application.
4+
35
Alternatives:[list]
46
[*] [url=https://store.kde.org/p/1618008/]Always Open on Focused Screen[/url] (the one that has the focused window)
5-
[*] [url=https://store.kde.org/p/1617641/]Always Open on Primary Screen[/url] (the one set as primary in the display settings)[/list][b]In order for the script to work properly you need to have 'Active screen follows mouse' enabled.[/b] For more information on installation and set-up as well as any requests, please visit [url=https://github.com/nclarius/KWin-window-positioning-scripts/tree/main/always-open-on-active-screen]the GitHub page[/url].
7+
[*] [url=https://store.kde.org/p/1617641/]Always Open on Primary Screen[/url] (the one set as primary in the display settings)[/list][b]In order for the script to work properly you need to have 'Active screen follows mouse' enabled.[/b] For more information on installation, set-up and configuration as well as any requests, please visit [url=https://github.com/nclarius/KWin-window-positioning-scripts/tree/main/always-open-on-active-screen]the GitHub page[/url].
68

7-
© 2021 Natalie Clarius ‹[email protected]
9+
© 2021-2022 Natalie Clarius ‹[email protected]
810

9-
with contributions by [url=https://github.com/joedefen]Joe Defenderfer[/url].
11+
with contributions by [url=https://github.com/joedefen]Joe Defenderfer[/url] and [url=https://github.com/tam1m]Tamim Baschour[/url].
1012

1113
This work is licensed under the GNU General Public License v3.0.
1214
This program comes with absolutely no warranty.

always-open-on-active-screen/README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Extension for KDE’s window manager to make new windows always open on the monitor that has the mouse cursor.
44

5+
The windows to be affected can be filtered by application.
6+
57
![logo](.img/logo_.png)
68

79

@@ -40,20 +42,40 @@ kwriteconfig5 --file kwinrc --group Windows --key ActiveMouseScreen true
4042
qdbus org.kde.KWin /KWin reconfigure
4143
```
4244

45+
## Configuration
46+
47+
*System Settings* > *Window Management* > *KWin Scripts* > configuration button in the *Always Open on Active Screen* entry.
48+
49+
You may need to uncheck the checkbox for the script, apply the settings, recheck, and reapply in order for the changes to take effect.
50+
51+
In Plasma versions < 5.24, a bug in the KWin scripting system [[1]](https://bugs.kde.org/show_bug.cgi?id=411430) [[2]](https://bugs.kde.org/show_bug.cgi?id=444378) may cause the configuration not to be found. To fix this, please execute the following commands in a terminal:
52+
53+
```bash
54+
sed -i 's/ConfigModule/Library/g' ~/.local/share/kwin/scripts/tilegaps/metadata.desktop
55+
mkdir -p ~/.local/share/kservices5/
56+
ln -sf ~/.local/share/kwin/scripts/tilegaps/metadata.desktop ~/.local/share/kservices5/tilegaps.desktop
57+
qdbus org.kde.KWin /KWin reconfigure
58+
```
59+
60+
### Window class
61+
62+
To find the window class name of an application: Right-click on the titlebar of a window of the application > *More Actions* > *Configure Special Application Settings...* > the pre-filled entry in *Window class (application)* (if it consists of two words, only the second part) is the window class to put in the script configuration.
63+
4364

4465
## Troubleshooting and known issues
4566

46-
- If some applications still open on the wrong screen, consider disabling applications requesting their own window geometry (this features only exists on X11): *System Settings* > *Window Management* > *Window Behavior* > *Advanced* > *Window placement* > *Allow apps to remember the positions of their own windows, if they support it*.
47-
- Some XWayland applications may attempt to remember their window position; this can be prevented with a window rule, as suggested [here](https://github.com/nclarius/KWin-window-positioning-scripts/issues/11#issuecomment-1091979196): *System Settings* > *Window Management* > *Window Rules* > *Add New...* > enter the window class of the application and possibly restrict the window type to normal windows > *Add Property..* > *Ignore requested geometry* > *Force*, *Yes* > *Apply*.
48-
- It has been suggested that the script might not work for snap applications; if this appears to be the case for you, consider using native packages instead.
67+
- On X11: If KDE applications open on the wrong screen, consider disabling applications requesting their own window geometry: *System Settings* > *Window Management* > *Window Behavior* > *Advanced* > *Window placement* > *Allow apps to remember the positions of their own windows, if they support it*.
68+
- On Wayland: Some XWayland applications may attempt to remember their window position; this can be prevented with a window rule: *System Settings* > *Window Management* > *Window Rules* > *Add New...* > enter the window class of the application and possibly restrict the window type to normal windows > *Add Property..* > *Ignore requested geometry* > *Force*, *Yes* > *Apply*.
69+
- It has been suggested that the script might not work for snap applications; if this appears to be the case for you, consider using the native packages instead.
4970
- Notifications do not follow the placement request. The only thing that can be done about this at the moment is to leave a vote at the [bug report](https://bugs.kde.org/show_bug.cgi?id=452294) for this to be addressed in core Plasma.
50-
- Some applications (e.g. Spotify) may still open on the wrong screen despite these workarounds. I have not yet figured out how to fix this. If you do, please let me know!
71+
- If some applications still open on the wrong screen despite these workarounds, please report it, even more so if you have an idea what the problem might be or how to fix it.
72+
5173

5274
## Small Print
5375

54-
© 2021 Natalie Clarius \<[email protected]\>
76+
© 2021-2022 Natalie Clarius \<[email protected]\>
5577

56-
with contributions by [Joe Defenderfer](https://github.com/joedefen).
78+
with contributions by [Joe Defenderfer](https://github.com/joedefen) and [Tamim Baschour](https://github.com/tam1m).
5779

5880
This work is licensed under the GNU General Public License v3.0.
5981
This program comes with absolutely no warranty.
Binary file not shown.

always-open-on-active-screen/contents/code/main.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ GNU General Public License v3.0
66

77
// initialization
88
const config = {
9-
classlist: readConfig("classlist", "")
10-
.toLowerCase()
11-
.split("\n")
12-
.map((s) => s.trim()),
13-
allowmode: readConfig("allowmode", false),
14-
denymode: readConfig("denymode", true),
15-
debugmode: readConfig("debugMode", false),
16-
};
9+
classList: readConfig("classList", "")
10+
.toLowerCase()
11+
.split("\n")
12+
.map((s) => s.trim()),
13+
allowMode: readConfig("allowMode", true),
14+
denyMode: readConfig("denyMode", false),
15+
debugMode: readConfig("debugMode", true)
16+
};
1717

1818
function debug(...args) {
19-
if (config.debugmode) console.debug("alwaysopenonactivescreen:", ...args);
19+
if (config.debugMode) console.debug("alwaysopenonactivescreen:", ...args);
2020
}
2121
debug("initializing");
2222

@@ -25,24 +25,22 @@ workspace.clientAdded.connect(client => {
2525
debug("client", JSON.stringify(client, undefined, 2));
2626

2727
// get active screen
28-
activeScreen = workspace.activeScreen;
28+
var activeScreen = workspace.activeScreen;
2929

30-
// abort if client is null, not regeometrizable, or already on right screen
31-
if (!client
32-
|| (config.denymode && config.classlist.includes(String(client.resourceClass))) // using denymode and window class is in list
33-
|| (config.allowmode && !config.classlist.includes(String(client.resourceClass))) // using allowmode and window class is not in list
34-
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
35-
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
36-
|| client.screen == activeScreen)
30+
// abort conditions
31+
if (!client // null
32+
|| (config.allowMode && !config.classList.includes(String(client.resourceClass))) // using allowmode and window class is not in list
33+
|| (config.denyMode && config.classList.includes(String(client.resourceClass))) // using denymode and window class is in list
34+
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens) // not regeomtrizable
35+
|| client.screen == activeScreen) // already on right screen
3736
return;
3837

3938
// move client to active screen
4039
debug("sending client", client.caption, "to active screen", activeScreen);
4140
workspace.sendClientToScreen(client, activeScreen);
4241

4342
// clip and move client into bounds of screen dimensions
44-
if (!(client.moveable && client.resizeable)) return;
45-
area = workspace.clientArea(KWin.MaximizeArea, client);
43+
var area = workspace.clientArea(KWin.MaximizeArea, client);
4644
// window width/height maximally screen width/height
4745
client.geometry.width = Math.min(client.width, area.width);
4846
client.geometry.height = Math.min(client.height, area.height);
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
5-
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
6-
<kcfgfile name=""/>
2+
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
3+
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
4+
<kcfgfile name="" />
75
<group name="">
8-
<entry name="classlist" type="String">
6+
<entry name="classList" type="String">
97
<label>Effected window class names</label>
108
<default></default>
119
</entry>
12-
<entry name="allowmode" type="Bool">
13-
<default>false</default>
14-
</entry>
15-
<entry name="denymode" type="Bool">
10+
<entry name="allowMode" type="Bool">
1611
<default>true</default>
1712
</entry>
13+
<entry name="denyMode" type="Bool">
14+
<default>false</default>
15+
</entry>
1816
<entry name="debugMode" type="Bool">
1917
<label>Whether to log debug information</label>
20-
<default>false</default>
18+
<default>true</default>
2119
</entry>
2220
</group>
2321
</kcfg>
Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ui version="4.0">
3-
<class>AlwaysOpenOnActiveScreenConfigForm</class>
4-
<widget class="QWidget" name="AlwaysOpenOnActiveScreenConfigForm">
5-
<property name="geometry">
6-
<rect>
7-
<x>0</x>
8-
<y>0</y>
9-
<width>400</width>
10-
<height>451</height>
11-
</rect>
12-
</property>
13-
<property name="windowTitle">
14-
<string>Form</string>
15-
</property>
16-
<layout class="QVBoxLayout" name="verticalLayout">
17-
<item>
18-
<widget class="QLabel" name="label">
19-
<property name="whatsThis">
20-
<string notr="true">Effected window class names. One per line</string>
21-
</property>
22-
<property name="text">
23-
<string notr="true">Effected window class names. One per line</string>
24-
</property>
3+
<class>AlwaysOpenOnActiveScreenConfigForm</class>
4+
<widget class="QWidget" name="AlwaysOpenOnActiveScreenConfigForm">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>451</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Always Open on Active Screen</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QLabel" name="label_1">
19+
<property name="text">
20+
<string>Apply to windows belonging to</string>
21+
</property>
22+
</widget>
23+
</item>
24+
<item>
25+
<widget class="QSplitter" name="splitter">
26+
<property name="sizePolicy">
27+
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
28+
<horstretch>0</horstretch>
29+
<verstretch>0</verstretch>
30+
</sizepolicy>
31+
</property>
32+
<property name="orientation">
33+
<enum>Qt::Horizontal</enum>
34+
</property>
35+
<widget class="QRadioButton" name="kcfg_allowMode">
36+
<property name="text">
37+
<string notr="true">all except the follwing</string>
38+
</property>
39+
<attribute name="buttonGroup">
40+
<string notr="true">matchTypeGroup</string>
41+
</attribute>
42+
</widget>
43+
<widget class="QRadioButton" name="kcfg_denyMode">
44+
<property name="text">
45+
<string notr="true">none except the following</string>
46+
</property>
47+
<attribute name="buttonGroup">
48+
<string notr="true">matchTypeGroup</string>
49+
</attribute>
50+
</widget>
51+
</widget>
52+
</item>
53+
<item>
54+
<widget class="QLabel" name="label_2">
55+
<property name="text">
56+
<string>applications:</string>
57+
</property>
58+
</widget>
59+
</item>
60+
<item>
61+
<widget class="QPlainTextEdit" name="kcfg_classList">
62+
<property name="placeholderText">
63+
<string>List of window classes (example: dolphin), one per line</string>
64+
</property>
65+
</widget>
66+
</item>
67+
</layout>
2568
</widget>
26-
</item>
27-
<item>
28-
<widget class="QPlainTextEdit" name="kcfg_classlist"/>
29-
</item>
30-
<item>
31-
<widget class="QSplitter" name="splitter">
32-
<property name="sizePolicy">
33-
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
34-
<horstretch>0</horstretch>
35-
<verstretch>0</verstretch>
36-
</sizepolicy>
37-
</property>
38-
<property name="orientation">
39-
<enum>Qt::Horizontal</enum>
40-
</property>
41-
<widget class="QRadioButton" name="kcfg_allowmode">
42-
<property name="text">
43-
<string notr="true">Allow matching windows</string>
44-
</property>
45-
<attribute name="buttonGroup">
46-
<string notr="true">matchTypeGroup</string>
47-
</attribute>
48-
</widget>
49-
<widget class="QRadioButton" name="kcfg_denymode">
50-
<property name="text">
51-
<string notr="true">Deny matching windows</string>
52-
</property>
53-
<attribute name="buttonGroup">
54-
<string notr="true">matchTypeGroup</string>
55-
</attribute>
56-
</widget>
57-
</widget>
58-
</item>
59-
<item>
60-
<widget class="QCheckBox" name="kcfg_debugMode">
61-
<property name="text">
62-
<string notr="true">DebugMode</string>
63-
</property>
64-
</widget>
65-
</item>
66-
</layout>
67-
</widget>
68-
<resources/>
69-
<connections/>
70-
<buttongroups>
71-
<buttongroup name="matchTypeGroup"/>
72-
</buttongroups>
69+
<resources />
70+
<connections />
71+
<buttongroups>
72+
<buttongroup name="matchTypeGroup" />
73+
</buttongroups>
7374
</ui>

always-open-on-active-screen/metadata.desktop

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Comment[nl]=Opent nieuwe vensters altijd op het scherm met de cursor]
1212
Icon=preferences-system-windows
1313

1414
X-KDE-PluginInfo-Name=alwaysopenonactivescreen
15-
X-KDE-PluginInfo-Version=3.0
15+
X-KDE-PluginInfo-Version=4.0
1616
X-KDE-PluginInfo-Author=Natalie Clarius
1717
X-KDE-PluginInfo-Email[email protected]
1818
X-KDE-PluginInfo-License=GPL v3.0
@@ -25,4 +25,3 @@ X-KDE-ServiceTypes=KWin/Script,KCModule
2525
X-KDE-ConfigModule=kwin/effects/configs/kcm_kwin4_genericscripted
2626
X-KDE-PluginKeyword=alwaysopenonactivescreen
2727
X-KDE-ParentComponents=alwaysopenonactivescreen
28-
X-KDE-PluginInfo-EnabledByDefault=true

0 commit comments

Comments
 (0)