Magellan Linux

Annotation of /mcore-src/trunk/mcore-tools/src/modules/basic-video/graphic.client.class.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2813 - (hide annotations) (download)
Fri Apr 7 08:00:51 2017 UTC (7 years, 1 month ago) by niro
File size: 5514 byte(s)
-support graphic resolution and color depths auto detection at runtime
1 niro 1248 # $Id$
2    
3 niro 1258 provide basic-video
4 niro 1248
5 niro 1258 # todo monitor gfxcard
6     helper_graphic_add_configs()
7     {
8     local path="$1"
9     local conf
10    
11     # exit ERR if path does not exist
12     [[ ! -d ${path} ]] && return 1
13    
14     for conf in $(find "${path}" -mindepth 1 -maxdepth 1 -type f -name \*.conf | sort)
15     do
16     cat "${conf}" >> "${CONFIG}"
17     done
18     }
19    
20     # everything from xorg conf but inputdevices. they are handled properly trough udev!
21     helper_graphic_rebuild_xorg_conf_d()
22     {
23     local CONFIG
24     local conf
25    
26     # rebuild 25-gfxcard.conf
27     # always clear the config
28 niro 2194 CONFIG="${MROOT}@@SYSCONFDIR@@/X11/xorg.conf.d/25-device.conf"
29 niro 1258 clearconfig
30 niro 2019 addconfig "# Autogenerated by mcored"
31 niro 1258 # but only add lines if some values are found in config.d dir
32 niro 2018 if path_not_empty ${MROOT}/${MCORE_CONFIG_PATH}/xorg/device
33 niro 1258 then
34     addconfig 'Section "Device"'
35 niro 2018 helper_graphic_add_configs ${MROOT}/${MCORE_CONFIG_PATH}/xorg/device
36 niro 1258 addconfig 'EndSection'
37     fi
38    
39     # rebuild 25-module.conf
40     # always clear the config
41 niro 2194 CONFIG="${MROOT}@@SYSCONFDIR@@/X11/xorg.conf.d/25-module.conf"
42 niro 1258 clearconfig
43 niro 2019 addconfig "# Autogenerated by mcored"
44 niro 1258 # but only add lines if some values are found in config.d dir
45 niro 2018 if path_not_empty ${MROOT}/${MCORE_CONFIG_PATH}/xorg/module
46 niro 1258 then
47     addconfig 'Section "Module"'
48 niro 2018 helper_graphic_add_configs ${MROOT}/${MCORE_CONFIG_PATH}/xorg/module
49 niro 1258 addconfig 'EndSection'
50     fi
51    
52     # rebuild 25-screen.conf
53     # always clear the config
54 niro 2194 CONFIG="${MROOT}@@SYSCONFDIR@@/X11/xorg.conf.d/25-screen.conf"
55 niro 1258 clearconfig
56 niro 2019 addconfig "# Autogenerated by mcored"
57 niro 1258 # but only add lines if some values are found in config.d dir
58 niro 2018 if path_not_empty ${MROOT}/${MCORE_CONFIG_PATH}/xorg/screen
59 niro 1258 then
60     addconfig 'Section "Screen"'
61     addconfig ' Identifier "Screen0"'
62     addconfig ' Monitor "Monitor0"'
63 niro 2018 helper_graphic_add_configs ${MROOT}/${MCORE_CONFIG_PATH}/xorg/screen
64 niro 1258 addconfig 'EndSection'
65     fi
66     }
67    
68 niro 1248 help_graphic_resolution()
69     {
70     mecho "set graphic.resolution [resolution]"
71 niro 2813 mecho " auto, 800x600, 1024x768, 1280x1024 etc"
72 niro 1248 }
73    
74     help_graphic_refresh()
75     {
76     mecho "set graphic.refresh [refresh rate]"
77 niro 2813 mecho " auto, 60, 100 - all values are Hz"
78 niro 1248 }
79    
80 niro 1258 help_graphic_depth()
81     {
82     mecho "set graphic.depth [color-depth]"
83 niro 2813 mecho " auto, 1, 4, 8, 15, 16, 24 - all values are bits"
84 niro 1258 }
85    
86     help_graphic_driver()
87     {
88     mecho "get graphic.driver [action]"
89     mecho " Shows current selected or system available graphic drivers."
90     mecho " Available actions:"
91     mecho " system - show available drivers on the system"
92     mecho " current - shows the current selected driver used by Xorg"
93     mecho
94     mecho "set graphic.driver [driver]"
95     mecho " Selects the graphic card driver used by Xorg."
96     }
97    
98 niro 1248 # set_graphic_resolution ${value}
99     set_graphic_resolution()
100     {
101 niro 2269 local resolution="${CLASS_ARGV[0]}"
102 niro 1258 local CONFIG
103     local depth
104     [[ -z ${resolution} ]] && help_graphic_resolution && return 1
105 niro 1248
106 niro 2018 CONFIG="${MROOT}/${MCORE_CONFIG_PATH}/xorg/screen/20-resolution.conf"
107 niro 1248
108 niro 2813 case ${depth} in
109     *x*)
110     clearconfig
111     # do it for all supported color depth
112     for depth in 1 4 8 15 16 24
113     do
114     addconfig ' SubSection "Display"'
115     addconfig " Depth ${depth}"
116     addconfig " Modes \"${resolution}\""
117     addconfig ' ViewPort 0 0'
118     addconfig ' EndSubSection'
119     done
120 niro 1258
121 niro 2813 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
122     then
123     x11runas "xrandr --size ${resolution}"
124     fi
125     ;;
126     auto) clearconfig ;;
127     esac
128    
129 niro 1258 helper_graphic_rebuild_xorg_conf_d
130 niro 1248 }
131    
132 niro 1258 # set_graphic_depth ${value}
133     set_graphic_depth()
134     {
135 niro 2269 local depth="${CLASS_ARGV[0]}"
136 niro 1258 local CONFIG
137     [[ -z ${depth} ]] && help_graphic_depth && return 1
138    
139 niro 2813 CONFIG="${MROOT}/${MCORE_CONFIG_PATH}/xorg/screen/10-depth.conf"
140    
141 niro 1258 # do it only for supported color depths
142     case "${depth}" in
143     1|4|8|15|16|24)
144     clearconfig
145     addconfig " DefaultDepth ${depth}"
146     ;;
147 niro 2813 auto) clearconfig ;;
148 niro 1258 *) help_graphic_depth && return 1 ;;
149     esac
150    
151     helper_graphic_rebuild_xorg_conf_d
152 niro 2018 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
153     then
154     mecho "X11 restart required!"
155     fi
156 niro 1258 }
157    
158 niro 1248 # set_graphic_refresh ${value}
159     set_graphic_refresh()
160     {
161 niro 2269 local value="${CLASS_ARGV[0]}"
162 niro 1258 [[ -z ${value} ]] && help_graphic_refresh && return 1
163 niro 1248
164 niro 2018 #echo "${value}" > ${MROOT}/${MCORE_CONFIG_PATH}/xorg/refresh
165 niro 1248
166 niro 2018 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
167     then
168     x11runas "xrandr --refresh ${value}"
169     fi
170 niro 1248
171 niro 1258 helper_graphic_rebuild_xorg_conf_d
172 niro 1248 }
173    
174 niro 1258 set_graphic_driver()
175 niro 1248 {
176 niro 2269 local driver="${CLASS_ARGV[0]}"
177 niro 2194 local driverdir="@@LIBDIR@@/xorg/modules/drivers"
178 niro 1258 local CONFIG
179     [[ -z ${driver} ]] && help_graphic_driver && return 1
180 niro 1248
181 niro 2665 if [[ ${driver} = auto ]]
182 niro 1258 then
183 niro 2665 decho "Using driver autodetection, doing nothing"
184     elif [[ -f ${MROOT}/${driverdir}/${driver}_drv.so ]]
185     then
186 niro 2018 CONFIG="${MROOT}/${MCORE_CONFIG_PATH}/xorg/device/25-device.conf"
187 niro 1258 clearconfig
188     addconfig " Identifier \"Card0\""
189     addconfig " Driver \"${driver}\""
190 niro 1248
191 niro 1258 helper_graphic_rebuild_xorg_conf_d
192 niro 2018 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
193     then
194     mecho "X11 restart required!"
195     fi
196 niro 1258 else
197     eecho "Driver '${driver}' does not exist on this system. Aborted!"
198 niro 1248 fi
199     }
200    
201 niro 1258 get_graphic_driver()
202 niro 1248 {
203 niro 2269 local action="${CLASS_ARGV[0]}"
204 niro 2194 local driverdir="@@LIBDIR@@/xorg/modules/drivers"
205 niro 1258 local driver
206     local config="${MCORE_CONFIG_PATH}/xorg/device/25-device.conf"
207     local i
208 niro 1248
209 niro 1258 case "${action}" in
210     current)
211 niro 2018 if [[ -f ${MROOT}/${config} ]]
212 niro 1258 then
213 niro 2018 driver=$(grep Driver "${MROOT}/${config}" | sed 's:.*Driver.*\"\(.*\)\":\1:')
214 niro 1643 rvecho "${driver}"
215 niro 1258 else
216 niro 1643 rvecho "none"
217 niro 1258 fi
218     ;;
219     system)
220 niro 2039 driver=$(list_files_in_directory ${MROOT}/${driverdir} -mindepth 1 -maxdepth 1 | sed s':_drv.so::g')
221 niro 1643 rvecho "${driver}"
222 niro 1258 ;;
223     *)
224     help_graphic_driver
225     return 1
226     ;;
227     esac
228 niro 1248 }