wm-swap

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

wm-swap

Unread post by elixir » Sat Mar 05, 2016 1:11 am

Just a little tool I wrote to easily change your .xinitrc config so X will jump into a new window manager when restarted. Thought it would be useful to some.

Usage:

Code: Select all

wm-swap [window manager]
Code:

Code: Select all

#/bin/bash
#
# This is a tool that will edit you .xinitrc file to comment
# your current wm, and uncomment your desired wm.
#

if [ -z $1 ]; then
	echo "Usage: wm-swap [window manager]"
	exit 1
else 
	WM="$1"
fi

xinit="/home/$USER/.xinitrc"

if [ -f /home/$USER/$xinit.temp ]; then
	rm $xinit.temp
fi

found=0

while read line; do
	if [[ $line =~ ^exec ]]; then
		echo $line | sed 's/^/#/' >> $xinit.temp
	elif [[ $line =~ $WM ]]; then
		echo $line | sed 's/#//' >> $xinit.temp
		found=1
	else
		echo $line >> $xinit.temp
	fi
done < $xinit

if [ $found == 0 ]; then
	echo "exec $WM" >> $xinit.temp
fi

cp $xinit.temp $xinit
rm $xinit.temp

## optional
# pkill x

exit 0
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: wm-swap

Unread post by dkeg » Sat Mar 05, 2016 2:43 am

kudos on the idea. I had something, idea wise for swapping current wall. Anyway, this is what I do.

Here's my .xinitrc

Work hard; Complain less

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: wm-swap

Unread post by elixir » Sat Mar 05, 2016 2:48 am

^ Wow, that is a genius idea. Thank you for sharing.

I was hoping to implement something that could actually reload the X server for you, but I could not find a good way to do it. Since most users would run this in a virtual terminal, it would get as far as killing the X server which would then kill the script itself.
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: wm-swap

Unread post by machinebacon » Sat Mar 05, 2016 4:40 am

I think the optional line should be:

Code: Select all

pkill -9 X
To reload the Xserver, the only method I can think of is automatically starting it via ~/.bash_profile (or ~/.profile) on a selected TTY.

There is another way of doing what your script can do, but it is extremely Debian-ish:

- keep "exec x-window-manager" as magic line in ~/.xinitrc
- on Debian systems, use the interactive mode of 'update-alternatives' to select the window manager
- on non-Debian systems, link /usr/bin/x-window-manager to the window manager of choice

This would not tinker with ~/.xinitrc, and not create temp files.
..gnutella..

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: wm-swap

Unread post by Snap » Sat Mar 05, 2016 8:35 am

Plenty of smart ideas here. Great job, folks. Thanks for sharing.

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: wm-swap

Unread post by Snap » Sat Mar 05, 2016 4:46 pm

@ dkeg:

What's wew in your .xinitrc? And xwait? Is it a script? I don't see it described in the xinit or startx man pages. Does it belong to any other xserver bit? Never heard of those two before.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: wm-swap

Unread post by machinebacon » Sat Mar 05, 2016 4:55 pm

..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: wm-swap

Unread post by rhowaldt » Sun Mar 06, 2016 5:24 am

^ what!? google??? that is a revolutionary approach! ;)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: wm-swap

Unread post by pidsley » Sun Mar 06, 2016 4:15 pm

If you don't need conditionals, you can just use this last line in .xinitrc:

Code: Select all

exec $1
Then call xinit with the name of the wm you want to start.

If you want to use a fancy dialog to pick the wm, try the pick-wm script from cream (this requires the "exec $1" mod to .xinitrc):
https://github.com/linuxbbq/toolbox/blob/master/pick-wm

If I wanted to switch window managers from inside X, I'd probably write the name of the new window manager to a temp file, pkill X, and then "xinit $(<tmpfile)".

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: wm-swap

Unread post by machinebacon » Sun Mar 06, 2016 4:55 pm

addendum to the last idea of pidsley:

if the magic process is not a window manager, but something else (a fake process like a loop), the WM could even by switched on the fly - I think - using a pick-wm script that does not "exec <wm>" but simply starts "<wm> &". Though I am not sure how often people switch their WMs a day.
..gnutella..

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: wm-swap

Unread post by pidsley » Sun Mar 06, 2016 5:11 pm

machinebacon wrote:Though I am not sure how often people switch their WMs a day.
Exactly. I just have a list of commented "exec" lines and an alias that opens my .xinitrc file. If I want to change wms I edit the file, change the comments, and restart X. I only do this when I need to test something in another wm, so a script seems like overkill. But that's just my opinion, worth exactly what you paid for it.

User avatar
Snap
Sperminator
Posts: 189
Joined: Sun Oct 05, 2014 8:11 pm

Re: wm-swap

Unread post by Snap » Mon Mar 07, 2016 11:01 am

^ That's how my .xinitrc looks like too. Anyway these WM switching methods are useful and good to know when tweaking a new WM. Switching back and forth to check changes and differences.

Thanks for all the info, guys.

Post Reply