Skip to content

Instantly share code, notes, and snippets.

@tuxor1337
Last active May 19, 2018 21:58
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tuxor1337/74e76d3d153c67593454 to your computer and use it in GitHub Desktop.
Save tuxor1337/74e76d3d153c67593454 to your computer and use it in GitHub Desktop.
Remove titlebar of maximized windows in GNOME3 (One for <=3.14 and one for >=3.16)
#!/usr/bin/bash
#
# This script requires the command `wmctrl`!
#
# Execute this script at GNOME startup as a daemon (e.g. with the & control operator).
#
# It will check in an endless loop that all windows that are currently open have
# the _GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED atom set to true.
#
check_hidden() {
echo $(xprop -id $1 | grep "_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED(CARDINAL) = 1")
}
check_maximized() {
echo $(xprop -id $1 | grep "_NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_VERT")
}
while true; do
known_windows=$(wmctrl -l | awk '{ print $1 }')
for id in ${known_windows}; do
if [ "$(check_hidden $id)" == "" ]; then
xprop -id $id -f _GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED 32c \
-set _GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED 0x1
if [ "$(check_maximized $id)" != "" ]; then
wmctrl -i -r $id -b toggle,maximized_vert,maximized_horz \
&& wmctrl -i -r $id -b toggle,maximized_vert,maximized_horz
fi
fi
done
sleep 0.5
done
#!/usr/bin/bash
#
# This script takes the GNOME window (i.e. metacity) theme $THEME and creates a
# new theme called "$THEME-nomaxtitlebar" in the user's local theme directory.
#
# The new theme will be identical with $THEME apart from the fact that
# maximized windows won't have titlebars.
#
# You can activate the new theme by using gnome-tweak-tool or directly changing
# the dconf value "theme" in "org.gnome.desktop.wm.preferences".
#
# Effectively, you end up with the same result when using the maximus extension:
# https://extensions.gnome.org/extension/354/maximus/
# But it seems to me like changing the window theme is the canonical solution.
#
THEME="Adwaita"
THEME_FILE="/usr/share/themes/$THEME/metacity-1/metacity-theme-3.xml"
OUTPUT_DIR="$HOME/.local/share/themes/$THEME-nomaxtitlebar/metacity-1"
OUTPUT_FILE="$OUTPUT_DIR/metacity-theme-3.xml"
TMP_FILE="$(mktemp)"
mkdir -p "$OUTPUT_DIR"
# At the moment, the XML file provided by GNOME isn't valid XML:
# https://bugzilla.gnome.org/show_bug.cgi?id=740889
# This is my temporary workaround:
sed 's/="\([^"]*\)<\([^"]*\)"/="\1\&lt;\2"/g' "$THEME_FILE" > "$OUTPUT_FILE"
sed 's/="\([^"]*\)>\([^"]*\)"/="\1\&gt;\2"/g' "$OUTPUT_FILE" > "$TMP_FILE"
rm "$OUTPUT_FILE"
xsltproc --nodtdattr -o "$OUTPUT_FILE" - "$TMP_FILE" << EOF
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="frame_geometry[@name='max']">
<xsl:copy>
<xsl:attribute name="has_title">
<xsl:text>false</xsl:text>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@title_scale[parent::frame_geometry[@name='max']]">
</xsl:template>
<xsl:template match="frame_geometry[@name='max']/distance/@value">
<xsl:attribute name="value">
<xsl:text>0</xsl:text>
</xsl:attribute>
</xsl:template>
<xsl:template match="frame_geometry[@name='max']/border">
<xsl:copy>
<xsl:attribute name="left">
<xsl:text>0</xsl:text>
</xsl:attribute>
<xsl:attribute name="right">
<xsl:text>0</xsl:text>
</xsl:attribute>
<xsl:attribute name="top">
<xsl:text>0</xsl:text>
</xsl:attribute>
<xsl:attribute name="bottom">
<xsl:text>0</xsl:text>
</xsl:attribute>
<xsl:apply-templates select="@name"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
EOF
# Unfortunately `xsltproc` replaces hexcode entities
sed 's/Â/\&#194;/g' "$OUTPUT_FILE" > "$TMP_FILE"
cp "$TMP_FILE" "$OUTPUT_FILE"
rm $TMP_FILE
@v6ak
Copy link

v6ak commented May 19, 2018

I have tried to get rid of polling: https://gist.github.com/v6ak/b6e1c18b85ad2dc19c03cac1669b65d0

Maybe my script is too simple in some ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment