summaryrefslogtreecommitdiff
path: root/data/mate-wm
blob: 0c90b76c77a939f5b9e9224b81c6aaac83d4f48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh

# The user can specify his prefered WM by setting the WINDOW_MANAGER
# environment variable.
#
# If this is not set, we search a list of known windowmanagers and use
# the first one that is found in the users's PATH
#
# NOTE: DON'T USE THIS.  Please have your window manager install
# a desktop file and change the mateconf key
# /desktop/mate/session/required_components/windowmanager

# sm-client-id value
SMID=
# default-wm value
DEFWM=

#read in the arguments
GET=
for n in "$@" ; do
  case "$GET" in
    smid)
      SMID=$n
      GET=
      ;;
    defwm)
      DEFWM=$n
      GET=
      ;;
    *)
      case "$n" in
        --sm-client-id)
          GET=smid
          ;;
        --default-wm)
          GET=defwm
          ;;
      esac
      ;;
  esac
done

# WINDOW_MANAGER overrides all
if [ -z "$WINDOW_MANAGER" ] ; then
    WINDOW_MANAGER=`gsettings get org.mate.session.required-components windowmanager 2> /dev/null | sed -r -e "s/^'([^']*)'$/\\1/"`
fi

# Migrate compiz to compiz-manager if possible and needed
if [ "x$WINDOW_MANAGER" = "xcompiz" -o "x$DEFWM" = "xcompiz" ]; then
  which compiz-manager > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    if [ "x$WINDOW_MANAGER" = "xcompiz" ]; then
      WINDOW_MANAGER="compiz-manager"
    fi
    if [ "x$DEFWM" = "xcompiz" ]; then
      DEFWM="compiz-manager"
    fi
  fi
fi

# Avoid looping if the session configuration tells us to use mate-wm or if
# the user forces mate-wm via WINDOW_MANAGER
if [ "x$WINDOW_MANAGER" = "xmate-wm" ]; then
  WINDOW_MANAGER=""
fi

if [ -z "$WINDOW_MANAGER" ] ; then
  # Create a list of window manager we can handle, trying to only use the
  # compositing ones when it makes sense

  xdpyinfo 2> /dev/null | grep -q "^ *Composite$" 2> /dev/null
  IS_X_COMPOSITED=$?

  KNOWN_WM="sawfish sawmill enlightenment icewm wmaker fvwm2 qvwm fvwm twm kwm"
  if [ $IS_X_COMPOSITED -eq 0 ] ; then
    KNOWN_WM="mutter compiz-manager compiz beryl $KNOWN_WM"
  fi
  # marco is still the default wm in MATE
  KNOWN_WM="marco $KNOWN_WM"

  OLDIFS=$IFS
  if [ -z "$DEFWM" -o "x$DEFWM" = "xmate-wm" ]; then

    for wm in $KNOWN_WM ; do
      IFS=":"
      for dir in $PATH ; do
        if [ -x "$dir/$wm" ] ; then
          WINDOW_MANAGER="$dir/$wm"
          break 2
        fi
      done
      IFS=$OLDIFS
    done

  else
    WINDOW_MANAGER=$DEFWM
  fi
  IFS=$OLDIFS
fi

# If no window manager can be found, we default to xterm

if [ -z "$WINDOW_MANAGER" ] ; then
  echo "WARNING: No window manager can be found."
  WINDOW_MANAGER=xterm
fi

# Now create options OPT1, OPT2 and OPT3 based on the windowmanager used
OPT1=
OPT2=
OPT3=
OPT4=
if [ ! -z "$SMID" ] ; then
  case `basename $WINDOW_MANAGER` in
    sawfish|sawmill|marco|mutter)
      OPT1=--sm-client-id=$SMID
      ;;
    openbox|enlightenment|e16)
      OPT1=--sm-client-id
      OPT2=$SMID
      ;;
    twm)
      OPT1=-clientId
      OPT2=$SMID
      ;;
    lwm)
      OPT1=-s
      OPT2=$SMID
      ;;
    fvwm)
      OPT1=-i
      OPT2=$SMID
      ;;
    compiz|compiz-manager)
      OPT1=--sm-client-id
      OPT2=$SMID
      ;;
    beryl)
      OPT1=--sm-client-id
      OPT2=$SMID
      ;;
    #FIXME: add all other windowmanagers here with their proper options
  esac
fi

case `basename $WINDOW_MANAGER` in
  compiz)
    #commented lines cause high cpu usage
    #export LIBGL_ALWAYS_INDIRECT=1
    gtk-window-decorator &
    #OPT3=glib
    #OPT4=mateconf
    ;;
  beryl)
    emerald &
    ;;
esac

exec $WINDOW_MANAGER $OPT1 $OPT2 $OPT3 $OPT4

echo "ERROR: No window manager could run!"