LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 09-08-2023, 11:59 AM   #1
jr_bob_dobbs
Member
 
Registered: Mar 2009
Distribution: Bedrock, Devuan, Slackware, Linux From Scratch, Void
Posts: 651
Blog Entries: 135

Rep: Reputation: 188Reputation: 188
Question 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. 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.

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

b4_wm_choice()
{
  killall bbkeys > /dev/null 2>&1
  killall bbkeys > /dev/null 2>&1
  killall pnmixer > /dev/null 2>&1
  killall pnmixer > /dev/null 2>&1
  killall autocutsel > /dev/null 2>&1
  killall autocutsel > /dev/null 2>&1
  killall wmacpi > /dev/null 2>&1
  killall wmacpi > /dev/null 2>&1
  killall wmmoonclock > /dev/null 2>&1
  killall wmmoonclock > /dev/null 2>&1
  killall nm-applet > /dev/null 2>&1
  killall nm-applet > /dev/null 2>&1
  killall stalonetray > /dev/null 2>&1
  killall stalonetray > /dev/null 2>&1
  xrdb $HOME/.Xresources
  xmodmap $HOME/.Xmodmap
}

after_all()
{
  killall pulseaudio
  killall gmplayer
  killall gmplayer
  killall worker
}

do_blackbox()
{
  autocutsel 2>/dev/null > /dev/null &
  bbkeys > /dev/null &
  xrdb $HOME/.Xresources
  xmodmap $HOME/.Xmodmap
  (stalonetray --dockapp-mode simple -bg "#7f7f7f" -t false -p true \
    --geometry 2x2 --kludges force_icons_size) &
  ( sleep 1 ; pnmixer ) &
  ( sleep 2 ; wmmoonclock -lat 39.173869 -lon 78.176356 ) &
  ( sleep 3 ; wmacpi -a 5 ) &
  ( sleep 4 ; xsetroot -xcf /usr/share/icons/Adwaita/cursors/left_ptr 36 ) &
  ( sleep 5 ; nm-applet ) &
  blackbox
}

do_dwm()
{
  autocutsel 2>/dev/null > /dev/null &
  xrdb $HOME/.Xresources
  xmodmap $HOME/.Xmodmap
  ( sleep 3 ; pnmixer ) &
  ( sleep 4 ; xsetroot -xcf /usr/share/icons/Adwaita/cursors/left_ptr 36 ) &
  ( sleep 5 ; nm-applet ) &
  while true
  do
    LALDATE=`date +"%l:%M %P"`
    SBTRY=`acpi -b`
    xsetroot -name "[$SBTRY] [$LALDATE]"
    sleep 19
  done &
  dwm
}

do_fvwm()
{
  autocutsel 2>/dev/null > /dev/null &
  xrdb $HOME/.Xresources
  xmodmap $HOME/.Xmodmap
  ( sleep 2 ; pnmixer ) &
  ( sleep 5 ; xsetroot -xcf /usr/share/icons/Adwaita/cursors/left_ptr 36 ) &
  ( sleep 6 ; nm-applet ) &
  fvwm
}

do_treewm()
{
  ~/.fehbg
  xrdb $HOME/.Xresources
  xmodmap $HOME/.Xmodmap
  LANG=C treewm
}

gamma_fix 2>/dev/null > /dev/null
.fehbg
while true
do
  b4_wm_choice
  # pick Exit or a window manager
  BLOORP=`xmessage 'Which Window Manager?' \
    -buttons Blackbox,Dwm,Fvwm,Treewm,Exit -nearmouse -print -timeout 60`
  case "$BLOORP" in
    "Blackbox" )
      do_blackbox
    ;;
    "Dwm" )
      do_dwm
    ;;
    "Fvwm" )
      do_fvwm
    ;;
    "Treewm" )
      do_treewm
    ;;
    * )
      # exit now
      after_all
      exec true
    ;;
  esac
done
# Actual end of this file.
 
Old 09-08-2023, 02:32 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,153

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
u dont need to quit x just to change window manager eg
Code:
killall xfwm4;sleep 2;lfswm2
this would kill the 1st wm and launch the s3cond one,the sleep command may or may not be needed
u could make up a fancy dialog box to select what wm to run

Last edited by Keith Hedger; 09-08-2023 at 02:33 PM.
 
Old 10-13-2023, 05:05 PM   #3
jr_bob_dobbs
Member
 
Registered: Mar 2009
Distribution: Bedrock, Devuan, Slackware, Linux From Scratch, Void
Posts: 651

Original Poster
Blog Entries: 135

Rep: Reputation: 188Reputation: 188
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
do
  b4_wm_choice
  # pick Exit or a window manager
  Xdialog \
    --title " select a window manager or cancel for console" \
    --timeout 60 \
    --ascii-lines \
    --menu "wm" \
    12 50 10 \
    "b" "blackbox" \
    "d" "dwm" \
    "f" "fvwm" \
    "t" "treewm" \
    "e" "exit" \
    2>/tmp/temp_wm_menu_picked
    # The result temp file has no newline on the end.  If the user
    # picked Cancel, the result temp file is zero-length
  BLOORP=`cat /tmp/temp_wm_menu_picked`
  # rm /tmp/temp_wm_menu_picked
  case "$BLOORP" in
    "b" )
      do_blackbox
    ;;
    "d" )
      do_dwm
    ;;
    "f" )
      do_fvwm
    ;;
    "t" )
      do_treewm
    ;;
    * )
      # exit now
      after_all
      exec true
    ;;
  esac
done
I'm going to guess that having a cursor is, for the most part, a feature of window managers and is not often available during the in-between time when one is outside of a window manager with intent to select a window manager.

p.s. And yes, running programs keep running during switches, except for certain dockapp things that my .xinitrc explicitly terminates between window managers.

Last edited by jr_bob_dobbs; 10-13-2023 at 05:07 PM.
 
  


Reply

Tags
xorg programming .xinitrc



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: CrazyFlie 6-DOF Review – Fly away now, fly away LXer Syndicated Linux News 0 04-20-2013 12:12 AM
LXer: Flipping the Linux switch: Desktop environments vs. window managers LXer Syndicated Linux News 0 12-20-2007 09:20 AM
How do I switch Window Managers ru4life Linux - Newbie 1 07-19-2004 09:02 PM
Window Managers vs. Desktop Managers mikeshn Linux - General 4 02-11-2004 11:31 AM
Switch window managers Wynd Linux - General 7 09-11-2003 11:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 06:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration