Skip to content

Commit

Permalink
Merge pull request #15 from tam1m/main
Browse files Browse the repository at this point in the history
adds the possibility to allow or deny certain windows from being affected by the positioning scripts [closes #14]
  • Loading branch information
nclarius authored May 1, 2022
2 parents 17d8387 + a3aa8fd commit ed93b0a
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 21 deletions.
27 changes: 20 additions & 7 deletions always-open-on-active-screen/contents/code/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ GNU General Public License v3.0
*/

// initialization
const debugMode = readConfig("debugMode", true);
function debug(...args) {if (debugMode)
console.debug("alwaysopenonactivescreen:", ...args);}
debug("initializing");
const config = {
classlist: readConfig("classlist", "")
.toLowerCase()
.split("\n")
.map((s) => s.trim()),
allowmode: readConfig("allowmode", false),
denymode: readConfig("denymode", true),
debugmode: readConfig("debugMode", false),
};

function debug(...args) {
if (config.debugmode) console.debug("alwaysopenonactivescreen:", ...args);
}
debug("initializing");

// when a client is added
workspace.clientAdded.connect(client => {
Expand All @@ -19,9 +29,12 @@ workspace.clientAdded.connect(client => {

// abort if client is null, not regeometrizable, or already on right screen
if (!client
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
|| client.screen == activeScreen)
return;
|| (config.denymode && config.classlist.includes(String(client.resourceClass))) // using denymode and window class is in list
|| (config.allowmode && !config.classlist.includes(String(client.resourceClass))) // using allowmode and window class is not in list
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
|| client.screen == activeScreen)
return;

// move client to active screen
debug("sending client", client.caption, "to active screen", activeScreen);
Expand Down
23 changes: 23 additions & 0 deletions always-open-on-active-screen/contents/config/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<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
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="">
<entry name="classlist" type="String">
<label>Effected window class names</label>
<default></default>
</entry>
<entry name="allowmode" type="Bool">
<default>false</default>
</entry>
<entry name="denymode" type="Bool">
<default>true</default>
</entry>
<entry name="debugMode" type="Bool">
<label>Whether to log debug information</label>
<default>false</default>
</entry>
</group>
</kcfg>
73 changes: 73 additions & 0 deletions always-open-on-active-screen/contents/ui/config.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlwaysOpenOnActiveScreenConfigForm</class>
<widget class="QWidget" name="AlwaysOpenOnActiveScreenConfigForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>451</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="whatsThis">
<string notr="true">Effected window class names. One per line</string>
</property>
<property name="text">
<string notr="true">Effected window class names. One per line</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="kcfg_classlist"/>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QRadioButton" name="kcfg_allowmode">
<property name="text">
<string notr="true">Allow matching windows</string>
</property>
<attribute name="buttonGroup">
<string notr="true">matchTypeGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="kcfg_denymode">
<property name="text">
<string notr="true">Deny matching windows</string>
</property>
<attribute name="buttonGroup">
<string notr="true">matchTypeGroup</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_debugMode">
<property name="text">
<string notr="true">DebugMode</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="matchTypeGroup"/>
</buttongroups>
</ui>
1 change: 1 addition & 0 deletions always-open-on-active-screen/metadata.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Type=Service
X-Plasma-API=javascript
X-Plasma-MainScript=code/main.js
X-KDE-ServiceTypes=KWin/Script,KCModule
X-KDE-ConfigModule=kwin/effects/configs/kcm_kwin4_genericscripted
X-KDE-PluginKeyword=alwaysopenonactivescreen
X-KDE-ParentComponents=alwaysopenonactivescreen
X-KDE-PluginInfo-EnabledByDefault=true
26 changes: 19 additions & 7 deletions always-open-on-focused-screen/contents/code/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ GNU General Public License v3.0
*/

// initialization
const debugMode = readConfig("debugMode", true);
function debug(...args) {if (debugMode)
console.debug("alwaysopenonfocusedscreen:", ...args);}
debug("initializing");
const config = {
classlist: readConfig("classlist", "")
.toLowerCase()
.split("\n")
.map((s) => s.trim()),
allowmode: readConfig("allowmode", false),
denymode: readConfig("denymode", true),
debugmode: readConfig("debugMode", false),
};

function debug(...args) {
if (config.debugmode) console.debug("alwaysopenonfocusedscreen:", ...args);
}
debug("initializing");

// when a client is activated, update focused screen to screen client is on
focusedScreen = workspace.activeScreen;
Expand All @@ -24,9 +34,11 @@ workspace.clientAdded.connect(client => {

// abort if client is null, not regeometrizable, or already on right screen
if (!client
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
|| client.screen == focusedScreen)
return;
|| (config.denymode && config.classlist.includes(String(client.resourceClass))) // using denymode and window class is in list
|| (config.allowmode && !config.classlist.includes(String(client.resourceClass))) // using allowmode and window class is not in list
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
|| client.screen == focusedScreen)
return;

// move client to focused screen
debug("sending client", client.caption, "to focused screen", focusedScreen);
Expand Down
23 changes: 23 additions & 0 deletions always-open-on-focused-screen/contents/config/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<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
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="">
<entry name="classlist" type="String">
<label>Effected window class names</label>
<default></default>
</entry>
<entry name="allowmode" type="Bool">
<default>false</default>
</entry>
<entry name="denymode" type="Bool">
<default>true</default>
</entry>
<entry name="debugMode" type="Bool">
<label>Whether to log debug information</label>
<default>false</default>
</entry>
</group>
</kcfg>
73 changes: 73 additions & 0 deletions always-open-on-focused-screen/contents/ui/config.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlwaysOpenOnFocusedScreenConfigForm</class>
<widget class="QWidget" name="AlwaysOpenOnFocusedScreenConfigForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>451</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="whatsThis">
<string notr="true">Effected window class names. One per line</string>
</property>
<property name="text">
<string notr="true">Effected window class names. One per line</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="kcfg_classlist"/>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QRadioButton" name="kcfg_allowmode">
<property name="text">
<string notr="true">Allow matching windows</string>
</property>
<attribute name="buttonGroup">
<string notr="true">matchTypeGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="kcfg_denymode">
<property name="text">
<string notr="true">Deny matching windows</string>
</property>
<attribute name="buttonGroup">
<string notr="true">matchTypeGroup</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_debugMode">
<property name="text">
<string notr="true">DebugMode</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="matchTypeGroup"/>
</buttongroups>
</ui>
1 change: 1 addition & 0 deletions always-open-on-focused-screen/metadata.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Type=Service
X-Plasma-API=javascript
X-Plasma-MainScript=code/main.js
X-KDE-ServiceTypes=KWin/Script,KCModule
X-KDE-ConfigModule=kwin/effects/configs/kcm_kwin4_genericscripted
X-KDE-PluginKeyword=alwaysopenonfocusedscreen
X-KDE-ParentComponents=alwaysopenonfocusedscreen
X-KDE-PluginInfo-EnabledByDefault=true
26 changes: 19 additions & 7 deletions always-open-on-primary-screen/contents/code/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ GNU General Public License v3.0
*/

// initialization
const debugMode = readConfig("debugMode", true);
function debug(...args) {if (debugMode)
console.debug("alwaysopenonprimaryscreen:", ...args);}
debug("initializing");
const config = {
classlist: readConfig("classlist", "")
.toLowerCase()
.split("\n")
.map((s) => s.trim()),
allowmode: readConfig("allowmode", false),
denymode: readConfig("denymode", true),
debugmode: readConfig("debugMode", false),
};

function debug(...args) {
if (config.debugmode) console.debug("alwaysopenonprimaryscreen:", ...args);
}
debug("initializing");

// primary screen is 0'th
primaryScreen = 0;
Expand All @@ -19,9 +29,11 @@ workspace.clientAdded.connect(client => {

// abort if client is null, not regeometrizable, or already on right screen
if (!client
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
|| client.screen == primaryScreen)
return;
|| (config.denymode && config.classlist.includes(String(client.resourceClass))) // using denymode and window class is in list
|| (config.allowmode && !config.classlist.includes(String(client.resourceClass))) // using allowmode and window class is not in list
|| !(client.resizeable && client.moveable && client.moveableAcrossScreens)
|| client.screen == primaryScreen)
return;

// move client to primary screen
debug("sending client", client.caption, "to primary screen", primaryScreen);
Expand Down
23 changes: 23 additions & 0 deletions always-open-on-primary-screen/contents/config/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<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
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="">
<entry name="classlist" type="String">
<label>Effected window class names</label>
<default></default>
</entry>
<entry name="allowmode" type="Bool">
<default>false</default>
</entry>
<entry name="denymode" type="Bool">
<default>true</default>
</entry>
<entry name="debugMode" type="Bool">
<label>Whether to log debug information</label>
<default>false</default>
</entry>
</group>
</kcfg>
Loading

0 comments on commit ed93b0a

Please sign in to comment.