Skip to content

Commit

Permalink
Add Optional Feature to Hide Tiled Window Titles (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hou-Rui authored Dec 21, 2024
1 parent 3c12fbe commit c766151
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 69 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Based on (but not forked from) [bahamondev/hide-titles](https://github.com/baham
* Automatically filters out potential breakages (e.g. GTK applications)
* Configurable blacklist
* Optional screen edge listener to toggle it off/on in case you need the title bar for a moment
* Optionally also hide window titles for tiled windows

![usage demonstration](https://images.pling.com/img/00/00/71/36/84/2018573/video.gif)

Expand Down
22 changes: 16 additions & 6 deletions contents/code/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// utils
function isMaximized(window) {
var shouldHideTiled = false;

function shouldHideTitle(window) {
if (shouldHideTiled && window.tile !== null) {
return true;
}
var area = workspace.clientArea(KWin.MaximizeArea, window);
return window.width >= area.width && window.height >= area.height;
}
Expand All @@ -25,12 +30,16 @@ function isManaged(window) {
function windowAdded(window) {
tryManage(window);
if (isManaged(window)) {
if (isMaximized(window)) {
if (shouldHideTitle(window)) {
window.noBorder = true;
}
window.maximizedChanged.connect(() => {
window.noBorder = isMaximized(window);
});
function statusChanged() {
window.noBorder = shouldHideTitle(window);
}
// always connect all signals even if the related option is disabled
// to support config hot reloading if KWin supports that
window.maximizedChanged.connect(statusChanged);
window.tileChanged.connect(statusChanged);
}
}
workspace.windowAdded.connect(windowAdded);
Expand All @@ -44,7 +53,7 @@ workspace.windowRemoved.connect((window) => {
function screenEdgeActivated() {
for (window of workspace.windowList()) {
if (window.active) {
if (isManaged(window) && isMaximized(window)) {
if (isManaged(window) && shouldHideTitle(window)) {
window.noBorder = !window.noBorder;
}
return;
Expand Down Expand Up @@ -73,6 +82,7 @@ function initScreenEdges() {
// init
function init() {
blacklist = readConfig("blacklist", "yakuake").split(",").filter((name) => name.length != 0);
shouldHideTiled = readConfig("shouldHideTiled", false);
initScreenEdges();
}
options.configChanged.connect(init);
Expand Down
3 changes: 3 additions & 0 deletions contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<entry name="blacklist" type="String">
<default>yakuake</default>
</entry>
<entry name="shouldHideTiled" type="Bool">
<default>false</default>
</entry>
</group>
</kcfg>
131 changes: 68 additions & 63 deletions contents/ui/config.ui
Original file line number Diff line number Diff line change
@@ -1,66 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<!-- After creating with Qt Designer, geometry was swapped out for minimumSize -->
<property name="minimumSize">
<size>
<height>142</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label_save_notice">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>541</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Due to a limitation of Kwin, you must disable and re-enable the script
for changes to take effect.</string>
</property>
</widget>
<widget class="QLabel" name="label_blacklist">
<property name="geometry">
<rect>
<x>0</x>
<y>80</y>
<width>301</width>
<height>18</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Window Class Blacklist (comma-separated)</string>
</property>
</widget>
<widget class="QLineEdit" name="kcfg_blacklist">
<property name="geometry">
<rect>
<x>0</x>
<y>100</y>
<width>531</width>
<height>32</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>755</width>
<height>142</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>142</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_save_notice">
<property name="font">
<font>
<pointsize>11</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Due to a limitation of Kwin, you must disable and re-enable the script for changes to take effect.</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_blacklist">
<property name="text">
<string>Window Class Blacklist (comma-separated)</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="kcfg_blacklist"/>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_optional">
<property name="text">
<string>Optional Features:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_shouldHideTiled">
<property name="text">
<string>Also &amp;hide title bar for tiled windows</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit c766151

Please sign in to comment.