Welcome!
Important information
-- Spectre and Meltdown vulnerabilities
-- Change in MX sources

News
-- MX Linux on social media: here
-- Mepis support still here

Current releases
-- MX-17.1 Final release info here
-- antiX-17 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

Fun with xfwm

Here you can exchange scripts that you created or have permission to share with other users.
Post Reply
Message
Author
User avatar
rich
Forum Regular
Forum Regular
Posts: 283
Joined: Sat Mar 31, 2018 6:39 pm

Fun with xfwm

#1 Post by rich » Wed May 09, 2018 7:14 pm

Updated, see post 2
Does not work (yet?) with xfwm 4.13

Here's a little script to extend some functions in xfwm, mimicking behavior in other popular window managers. This allows for:
  • Regular Window + (Super+Up) = Maximize
    Max Window + (Super+Up) = No action
    Max Window + (Super+Down) = Restore
    Regular Window + (Super+Down) = Minimize
    Tiled Window + (Super+Up) = Maximize
    Tiled Window + (Super+Down) = Restore
Image

Note - This doesn't treat quarter tiled windows in any special way. They'll behave as regular windows.

These are just the keybindings I've grown used to over the years, implemented using a script calling wmctrl, xdotool, and xprop. The keybindings can be assigned where ever, I happen to like using the super key.

Protip - If you've got your whisker menu tied to Super_L and want to use Super_L for other bindings as well, have no fear! xcape can help you with that! apt install xcape and run it in your Session and Startup>Application Autostart. My command is

Code: Select all

xcape -e 'Super_L=Super_L|space'
and my whiskermenu popup is set to Super+Space in Keyboard>Application Shortcuts. This allows menu launch with Super key while allowing Super + whateverkey shortcuts elsewhere.

Note - I have left and right tile set to Super+Left and Super+Right in Window Manager>Keyboard.

extrawm.sh:

Code: Select all

#!/bin/bash

#Check if window is maximized or tiled
windowstate=$(xprop -id $(xdotool getwindowfocus) _NET_WM_STATE | cut -d' '  -f3,4,5)

function maximize()
{
	if [ "$windowstate" != "_NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_FOCUSED" ] # if window's not maximized,...
		then 
		wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz # restore to allow maximzation from tiled/vert maximized state (a little hacky...)
		wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz # and, maximize!
	fi
}

function restoreorminimize()
{
	if [ "$windowstate" == "_NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_FOCUSED" ] # if window is maximized,...
		then 
		wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz # restore 
	elif [ "$windowstate" == "_NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_FOCUSED" ] # if window is tiled...
		then 
		wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz # restore 
	else # if it's not maxmized or tiled...
		xdotool windowminimize $(xdotool getactivewindow) #minimize
	fi
}

if [ "$1" = "up" ]; then
    $(maximize)
elif [ "$1" = "down" ]; then
	$(restoreorminimize)
fi
So, it can be called using $PATHTOSCRIPT(wherever you've placed the script)/$FILENAME(I called it extrawm.sh) up|down. For example,

Code: Select all

/home/rich/bin/extrawm.sh up|down
It can be keybound under Keyboard>Application Shortcuts. Don't forget to chmod +x!

Thanks for reading, any feedback welcome.
MX 17.1 Dell Inspiron N5110

User avatar
rich
Forum Regular
Forum Regular
Posts: 283
Joined: Sat Mar 31, 2018 6:39 pm

Re: Fun with xfwm

#2 Post by rich » Wed May 23, 2018 6:15 pm

Updated, cleaned up, now checks if windows are supposed to be minimized or maximized (some windows like xpad or xfce settings manager aren't supposed to be going anywhere...)

Code: Select all

#!/bin/bash

windowstate=$(xprop -id $(xdotool getwindowfocus) _NET_WM_STATE)
windowperm=$(xprop -id $(xdotool getwindowfocus) _NET_WM_ALLOWED_ACTIONS)

function maximize()
{
	if ! echo $windowstate | grep -qE "_NET_WM_STATE_MAXIMIZED_VERT\
					|_NET_WM_STATE_MAXIMIZED_HORZ"
		then
		echo $windowperm | grep -q 'MAXIMIZE' &&\		
		wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
		wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz		
	fi
}

function restoreorminimize()
{
	if echo $windowstate | grep -q -e 'MAXIMIZED' -e 'FULLSCREEN'
	then 
		wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	else
		echo $windowperm | grep -q 'MINIMIZE' &&\
		xdotool windowminimize $(xdotool getactivewindow)
		
	fi		
}

if [ "$1" = "up" ]; then
	$(maximize)
elif [ "$1" = "down" ]; then
	$(restoreorminimize)
fi
MX 17.1 Dell Inspiron N5110

Post Reply

Return to “Scripts”