Advertisement
Guest User

ltsp

a guest
Oct 30th, 2009
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.91 KB | None | 0 0
  1. #!/bin/sh
  2. # Compiz Manager wrapper script
  3. #
  4. # Copyright (c) 2007 Kristian Lyngst�l <kristian@bohemians.org>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. #
  21. #
  22. # Contributions by: Trevi�o (3v1n0) <trevi55@gmail.com>, Ubuntu Packages
  23. #
  24. # Much of this code is based on Beryl code, also licensed under the GPL.
  25. # This script will detect what options we need to pass to compiz to get it
  26. # started, and start a default plugin and possibly window decorator.
  27. #
  28.  
  29.  
  30. COMPIZ_BIN_PATH="/usr/local/bin/" # For window decorators and compiz
  31. PLUGIN_PATH="/usr/local/lib/compiz/"
  32. GLXINFO="/usr/bin/glxinfo"
  33. KWIN="/usr/bin/kwin"
  34. METACITY="/usr/bin/metacity"
  35. COMPIZ_NAME="compiz" # Final name for compiz (compiz.real)
  36.  
  37. # For Xgl LD_PRELOAD
  38. LIBGL_NVIDIA="/usr/lib/nvidia/libGL.so.1.2.xlibmesa"
  39. LIBGL_FGLRX="/usr/lib/fglrx/libGL.so.1.2.xlibmesa"
  40.  
  41. # Minimum amount of memory (in kilo bytes) that nVidia cards need
  42. # to be allowed to start
  43. # Set to 262144 to require 256MB
  44. NVIDIA_MEMORY="65536" # 64MB
  45. NVIDIA_SETTINGS="nvidia-settings" # Assume it's in the path by default
  46.  
  47. # For detecting what driver is in use, the + is for one or more /'s
  48. XORG_DRIVER_PATH="/usr/lib/xorg/modules/drivers/+"
  49.  
  50. if [ -x $METACITY ]; then
  51. FALLBACKWM="${METACITY}"
  52. elif [ -x $KWIN ]; then
  53. FALLBACKWM="${KWIN}"
  54. else
  55. FALLBACKWM=true
  56. fi
  57. FALLBACKWM_OPTIONS="--replace $@"
  58.  
  59. # Driver whitelist
  60. WHITELIST="nvidia intel ati radeon i810 fglrx"
  61.  
  62. # blacklist based on the pci ids
  63. # See http://wiki.compiz-fusion.org/Hardware/Blacklist for details
  64. #T=" 1002:5954 1002:5854 1002:5955" # ati rs480
  65. #T="$T 1002:4153" # ATI Rv350
  66. #T="$T 1002:3152 1002:3150 1002:5462 1002:5653 " # ati X300 X600,X600 X700
  67. T="8086:1132" # intel i815 (LP: #221920)
  68. T="$T 8086:2e02 " # Intel Eaglelake
  69. T="$T 8086:3577 8086:2562" # Intel 830MG, 845G (LP: #259385)
  70. BLACKLIST_PCIIDS="$T"
  71. unset T
  72.  
  73. COMPIZ_OPTIONS="--ignore-desktop-hints --replace"
  74. COMPIZ_PLUGINS="core"
  75. ENV=""
  76.  
  77. # Use emerald by default if it exist
  78. USE_EMERALD="yes"
  79.  
  80. # No indirect by default
  81. INDIRECT="no"
  82.  
  83. # Default X.org log if xset q doesn't reveal it
  84. XORG_DEFAULT_LOG="/var/log/Xorg.0.log"
  85.  
  86. # Set to yes to enable verbose
  87. VERBOSE="yes"
  88.  
  89. # Echos the arguments if verbose
  90. verbose()
  91. {
  92. if [ "x$VERBOSE" = "xyes" ]; then
  93. printf "$*"
  94. fi
  95. }
  96.  
  97. # abort script and run fallback windowmanager
  98. abort_with_fallback_wm()
  99. {
  100. if [ "x$SKIP_CHECKS" = "xyes" ]; then
  101. verbose "SKIP_CHECKS is yes, so continuing despite problems.\n"
  102. return 0;
  103. fi
  104.  
  105. if [ "x$CM_DRY" = "xyes" ]; then
  106. verbose "Dry run failed: Problems detected with 3D support.'n"
  107. exit 1;
  108. fi
  109.  
  110. verbose "aborting and using fallback: $FALLBACKWM \n"
  111.  
  112. if [ -x $FALLBACKWM ]; then
  113. exec $FALLBACKWM $FALLBACKWM_OPTIONS
  114. else
  115. printf "no $FALLBACKWM found, exiting\n"
  116. exit 1
  117. fi
  118. }
  119.  
  120. # Check if we run with the Software Rasterizer, this happens e.g.
  121. # when a second screen session is opened via f-u-a on intel
  122. check_software_rasterizer()
  123. {
  124. verbose "Checking for Software Rasterizer: "
  125. if glxinfo 2> /dev/null | egrep -q '^OpenGL renderer string: Software Rasterizer' ; then
  126. verbose "present. \n";
  127. return 0;
  128. else
  129. verbose "Not present. \n"
  130. return 1;
  131. fi
  132.  
  133. }
  134.  
  135. # Check for non power of two texture support
  136. check_npot_texture()
  137. {
  138. verbose "Checking for non power of two support: "
  139. if glxinfo 2> /dev/null | egrep -q '(GL_ARB_texture_non_power_of_two|GL_NV_texture_rectangle|GL_EXT_texture_rectangle|GL_ARB_texture_rectangle)' ; then
  140. verbose "present. \n";
  141. return 0;
  142. else
  143. verbose "Not present. \n"
  144. return 1;
  145. fi
  146.  
  147. }
  148.  
  149. # Check for presence of FBConfig
  150. check_fbconfig()
  151. {
  152. verbose "Checking for FBConfig: "
  153. if [ "$INDIRECT" = "yes" ]; then
  154. $GLXINFO -i | grep -q GLX.*fbconfig
  155. FB=$?
  156. else
  157. $GLXINFO | grep -q GLX.*fbconfig
  158. FB=$?
  159. fi
  160.  
  161. if [ $FB = "0" ]; then
  162. unset FB
  163. verbose "present. \n"
  164. return 0;
  165. else
  166. unset FB
  167. verbose "not present. \n"
  168. return 1;
  169. fi
  170. }
  171.  
  172.  
  173. # Check for TFP
  174. check_tfp()
  175. {
  176. verbose "Checking for texture_from_pixmap: "
  177. if [ $($GLXINFO 2>/dev/null | grep GLX_EXT_texture_from_pixmap -c) -gt 2 ] ; then
  178. verbose "present. \n"
  179. return 0;
  180. else
  181. verbose "not present. \n"
  182. if [ "$INDIRECT" = "yes" ]; then
  183. unset LIBGL_ALWAYS_INDIRECT
  184. INDIRECT="no"
  185. return 1;
  186. else
  187. verbose "Trying again with indirect rendering:\n";
  188. INDIRECT="yes"
  189. export LIBGL_ALWAYS_INDIRECT=1
  190. check_tfp;
  191. return $?
  192. fi
  193. fi
  194. }
  195.  
  196. # Check wether the composite extension is present
  197. check_composite()
  198. {
  199. verbose "Checking for Composite extension: "
  200. if xdpyinfo -queryExtensions | grep -q Composite ; then
  201. verbose "present. \n";
  202. return 0;
  203. else
  204. verbose "not present. \n";
  205. return 1;
  206. fi
  207. }
  208.  
  209. # Detects if Xgl is running
  210. check_xgl()
  211. {
  212. verbose "Checking for Xgl: "
  213. if xvinfo | grep -q Xgl ; then
  214. verbose "present. \n"
  215. return 0;
  216. else
  217. verbose "not present. \n"
  218. return 1;
  219. fi
  220. }
  221.  
  222. # Check if the nVidia card has enough video ram to make sense
  223. check_nvidia_memory()
  224. {
  225. if [ ! -x "$NVIDIA_SETTINGS" ]; then
  226. return 0
  227. fi
  228.  
  229. MEM=$(${NVIDIA_SETTINGS} -q VideoRam | egrep Attribute\ \'VideoRam\'\ .*: | cut -d: -f3 | sed 's/[^0-9]//g')
  230. if [ $MEM -lt $NVIDIA_MEMORY ]; then
  231. verbose "Less than ${NVIDIA_MEMORY}kb of memory and nVidia";
  232. return 1;
  233. fi
  234. return 0;
  235. }
  236.  
  237. # Check for existence if NV-GLX
  238. check_nvidia()
  239. {
  240. if [ ! -z $NVIDIA_INTERNAL_TEST ]; then
  241. return $NVIDIA_INTERNAL_TEST;
  242. fi
  243. verbose "Checking for nVidia: "
  244. if xdpyinfo | grep -q NV-GLX ; then
  245. verbose "present. \n"
  246. NVIDIA_INTERNAL_TEST=0
  247. return 0;
  248. else
  249. verbose "not present. \n"
  250. NVIDIA_INTERNAL_TEST=1
  251. return 1;
  252. fi
  253. }
  254.  
  255. # Check if the max texture size is large enough compared to the resolution
  256. check_texture_size()
  257. {
  258. TEXTURE_LIMIT=$(glxinfo -l | grep GL_MAX_TEXTURE_SIZE | sed 's/.*=[^0-9]//g')
  259. RESOLUTION=$(xdpyinfo | grep -i dimensions: | sed 's/[^0-9]*pixels.*(.*).*//' | sed 's/[^0-9x]*//')
  260. VRES=$(echo $RESOLUTION | sed 's/.*x//')
  261. HRES=$(echo $RESOLUTION | sed 's/x.*//')
  262. verbose "Comparing resolution ($RESOLUTION) to maximum 3D texture size ($TEXTURE_LIMIT): ";
  263. if [ $VRES -gt $TEXTURE_LIMIT ] || [ $HRES -gt $TEXTURE_LIMIT ]; then
  264. verbose "Failed.\n"
  265. return 1;
  266. fi
  267. verbose "Passed.\n"
  268. return 0
  269. }
  270.  
  271. # check driver whitelist
  272. running_under_whitelisted_driver()
  273. {
  274. DISPLAY_SOURCE=$(echo $DISPLAY|cut -d: -f1)
  275. if [ "${DISPLAY_SOURCE}" = "" ]; then
  276. LOG=$(xset q|grep "Log file"|awk '{print $3}')
  277. if [ "$LOG" = "" ]; then
  278. verbose "xset q doesn't reveal the location of the log file. Using fallback $XORG_DEFAULT_LOG \n"
  279. LOG=$XORG_DEFAULT_LOG;
  280. fi
  281. else
  282. verbose "Remote display detected. Force fallback wm. \n"
  283. return 1
  284. fi
  285. if [ -z "$LOG" ];then
  286. verbose "AIEEEEH, no Log file found \n"
  287. verbose "$(xset q) \n"
  288. return 0
  289. fi
  290. for DRV in ${WHITELIST}; do
  291. if egrep -q "Loading ${XORG_DRIVER_PATH}${DRV}_drv\.so" $LOG &&
  292. ! egrep -q "Unloading ${XORG_DRIVER_PATH}${DRV}_drv\.so" $LOG;
  293. then
  294. return 0
  295. fi
  296. done
  297. verbose "No whitelisted driver found\n"
  298. return 1
  299. }
  300.  
  301. # check pciid blacklist
  302. have_blacklisted_pciid()
  303. {
  304. OUTPUT=$(lspci -n)
  305. for ID in ${BLACKLIST_PCIIDS}; do
  306. if echo "$OUTPUT" | egrep -q "$ID"; then
  307. verbose "Blacklisted PCIID '$ID' found \n"
  308. return 0
  309. fi
  310. done
  311. OUTPUT=$(lspci -vn | grep -i VGA)
  312. verbose "Detected PCI ID for VGA: $OUTPUT\n"
  313. return 1
  314. }
  315.  
  316. build_env()
  317. {
  318. if check_nvidia; then
  319. ENV="__GL_YIELD=NOTHING "
  320. fi
  321. if [ "$INDIRECT" = "yes" ]; then
  322. ENV="$ENV LIBGL_ALWAYS_INDIRECT=1 "
  323. fi
  324. if check_xgl; then
  325. if [ -f ${LIBGL_NVIDIA} ]; then
  326. ENV="$ENV LD_PRELOAD=${LIBGL_NVIDIA}"
  327. verbose "Enabling Xgl with nVidia drivers...\n"
  328. fi
  329. if [ -f ${LIBGL_FGLRX} ]; then
  330. ENV="$ENV LD_PRELOAD=${LIBGL_FGLRX}"
  331. verbose "Enabling Xgl with fglrx ATi drivers...\n"
  332. fi
  333. fi
  334.  
  335. ENV="$ENV FROM_WRAPPER=yes"
  336.  
  337. if [ -n "$ENV" ]; then
  338. export $ENV
  339. fi
  340. }
  341.  
  342. build_args()
  343. {
  344. if [ "x$INDIRECT" = "xyes" ]; then
  345. COMPIZ_OPTIONS="$COMPIZ_OPTIONS --indirect-rendering "
  346. fi
  347. if check_nvidia; then
  348. if [ "x$INDIRECT" != "xyes" ]; then
  349. COMPIZ_OPTIONS="$COMPIZ_OPTIONS --loose-binding"
  350. fi
  351. fi
  352. }
  353.  
  354. ####################
  355. # Execution begins here.
  356.  
  357. # Read configuration from XDG paths
  358. if [ -z "$XDG_CONFIG_DIRS" ]; then
  359. test -f /etc/xdg/compiz/compiz-manager && . /etc/xdg/compiz/compiz-manager
  360. else
  361. OLD_IFS=$IFS
  362. IFS=:
  363. for CONFIG_DIR in $XDG_CONFIG_DIRS
  364. do
  365. test -f $CONFIG_DIR/compiz/compiz-manager && . $CONFIG_DIR/compiz/compiz-manager
  366. done
  367. IFS=$OLD_IFS
  368. unset OLD_IFS
  369. fi
  370.  
  371. if [ -z "$XDG_CONFIG_HOME" ]; then
  372. test -f $HOME/.config/compiz/compiz-manager && . $HOME/.config/compiz/compiz-manager
  373. else
  374. test -f $XDG_CONFIG_HOME/compiz/compiz-manager && . $XDG_CONFIG_HOME/compiz/compiz-manager
  375. fi
  376.  
  377. # Don't use compiz when running the failsafe session
  378. if [ "x$GNOME_DESKTOP_SESSION_ID" = "xFailsafe" ]; then
  379. abort_with_fallback_wm
  380. fi
  381.  
  382. if [ "x$LIBGL_ALWAYS_INDIRECT" = "x1" ]; then
  383. INDIRECT="yes";
  384. fi
  385.  
  386. # if we run under Xgl, we can skip some tests here
  387. if ! check_xgl; then
  388. # if vesa or vga are in use, do not even try glxinfo (LP#119341)
  389. if ! running_under_whitelisted_driver || have_blacklisted_pciid; then
  390. abort_with_fallback_wm
  391. fi
  392. # check if we have the required bits to run compiz and if not,
  393. # fallback
  394. if ! check_tfp || ! check_npot_texture || ! check_composite || ! check_texture_size; then
  395. abort_with_fallback_wm
  396. fi
  397.  
  398. # check if we run with software rasterizer and if so, bail out
  399. if check_software_rasterizer; then
  400. verbose "Software rasterizer detected, aborting"
  401. abort_with_fallback_wm
  402. fi
  403.  
  404. if check_nvidia && ! check_nvidia_memory; then
  405. abort_with_fallback_wm
  406. fi
  407.  
  408. if ! check_fbconfig; then
  409. abort_with_fallback_wm
  410. fi
  411. fi
  412.  
  413. # load the ccp plugin if present and fallback to plain gconf if not
  414. if [ -f ${PLUGIN_PATH}libccp.so ]; then
  415. COMPIZ_PLUGINS="$COMPIZ_PLUGINS ccp"
  416. elif [ -f ${PLUGIN_PATH}libgconf.so ]; then
  417. COMPIZ_PLUGINS="$COMPIZ_PLUGINS glib gconf"
  418. fi
  419.  
  420. # get environment
  421. build_env
  422. build_args
  423.  
  424. if [ "x$CM_DRY" = "xyes" ]; then
  425. verbose "Dry run finished: everything should work with regards to Compiz and 3D.\n"
  426. exit 0;
  427. fi
  428.  
  429. ${COMPIZ_BIN_PATH}${COMPIZ_NAME} $COMPIZ_OPTIONS "$@" $COMPIZ_PLUGINS || exec $FALLBACKWM $FALLBACKWM_OPTIONS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement