a .xinitrc to switch window managers on the fly
First of all, I was just going to post this in the programming section of Linux Questions, since that is the obvious place for it. I'm obviously confused, because there isn't one, or I can't find it today. :p Because it involves running window managers in xorg, I guess this Deskstop section is the correct place? If this is in the wrong place, sorry. :o
Background When I boot up any Linux distro on my computer, I log on in text mode and then, depending on what I am doing, when I am good & ready, I'll type startx to start xorg. If I want to switch to a different window manager, I exit back to the console, copy the corresponding file to be the new .xinitrc and then start the gui again. I've always wanted to switch between window managers in such a way that I don't have to do that copying. Also I'd like for any running GUI programs to still run, interrupted by the switch. Imagine you're in blackbox and you've got gimp, xterm, a file manager and a browser running. You'd select a menu option and ... boink, you're in dwm. All the programs are still there, though their windows have been abruptly resized. You work for a bit, then, you hit some key combination and ... plink plink, you're in windowmaker, and the programs are still running. This must be possible because in some distros I've seen blackbox with menu choices to switch to other window managers. The thing is, things like dock apps and tray things get kind of funny: multiple copies run, or get terminated and not restarted, that sort of thing. It only partially works. The three main things to solve seem to be as follows. One: a way, independent of window manager, to pick and switch to another window manager, while keeping everything running. Two: a way to stop certain programs (dock apps, tool-tray things, etc.) that need to be stopped when exiting a specific window manager. Three: a way to start certain programs whenever starting a specific window manager. I eventually worked out a way to do this, based on an assumption: despite not having a "#!/bin/sh" as the first line, .xinitrc is actually a shell script. Turns out that assumption is correct. Now I can switch managers on the fly, with only having find and resize program windows. Based on looping code from the sample .xinit code included in the treewm (window manager) package, my .xinitrc, when one exits a window manager, brings up a dialog box to select a window manager or to exit out of xorg entirely. There is a subroutine for cleanup (killall on various known tool-tray and dockapp programs) after exiting any window manager, plus an entry subroutine for each window manager. xmessage (It comes with xorg so it seems a reasonably portable choice) is used to bring up the file manager selection menu. I've been using this for several weeks now, on two distros. The Actual Question There is just one strange bug: when one first runs startx, the xmessage dialog appears, but there is no cursor (pointer). After a delay, and some mouse-waving on my part, it appears. I've no idea why. Because of this, I've set a time out of 60 seconds, after which, if no button is pressed, it will exit out of xorg, back to the console. I hoping someone here can figure it out whatever I am overlooking. Thank you. My .xinit follows (note: yes I know I have a lot of per-wm hard-coding): Code:
#!/bin/bash |
u dont need to quit x just to change window manager eg
Code:
killall xfwm4;sleep 2;lfswm2 u could make up a fancy dialog box to select what wm to run |
An update. Using Xdialog instead of xmessage to bring up a menu means that I can use the keyboard to select between window managers, provided that the (still at times invisible) cursor/pointer is over the dialog. It's a small improvement but (a) a nice GTK2 dialog is an esthetic improvement (b) when I first type startx, provided that I don't move the mouse, I can use the keyboard to select a window manager.
The updated section of my .xinitrc Code:
while true p.s. And yes, running programs keep running during switches, except for certain dockapp things that my .xinitrc explicitly terminates between window managers. |
All times are GMT -5. The time now is 03:35 AM. |