OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Virtual Me2Me implementation. This script runs and manages the processes | 6 # Virtual Me2Me implementation. This script runs and manages the processes |
7 # required for a Virtual Me2Me desktop, which are: X server, X desktop | 7 # required for a Virtual Me2Me desktop, which are: X server, X desktop |
8 # session, and Host process. | 8 # session, and Host process. |
9 # This script is intended to run continuously as a background daemon | 9 # This script is intended to run continuously as a background daemon |
10 # process, running under an ordinary (non-root) user account. | 10 # process, running under an ordinary (non-root) user account. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 if retcode != 0: | 322 if retcode != 0: |
323 logging.error("Failed to set XKB to 'evdev'") | 323 logging.error("Failed to set XKB to 'evdev'") |
324 | 324 |
325 # Register the screen sizes if the X server's RANDR extension supports it. | 325 # Register the screen sizes if the X server's RANDR extension supports it. |
326 # Errors here are non-fatal; the X server will continue to run with the | 326 # Errors here are non-fatal; the X server will continue to run with the |
327 # dimensions from the "-screen" option. | 327 # dimensions from the "-screen" option. |
328 for width, height in self.sizes: | 328 for width, height in self.sizes: |
329 label = "%dx%d" % (width, height) | 329 label = "%dx%d" % (width, height) |
330 args = ["xrandr", "--newmode", label, "0", str(width), "0", "0", "0", | 330 args = ["xrandr", "--newmode", label, "0", str(width), "0", "0", "0", |
331 str(height), "0", "0", "0"] | 331 str(height), "0", "0", "0"] |
332 proc = subprocess.Popen(args, env=self.child_env, stdout=devnull, | 332 subprocess.call(args, env=self.child_env, stdout=devnull, stderr=devnull) |
Lambros
2013/01/04 22:21:37
call() takes same args as Popen() so I decided to
| |
333 stderr=devnull) | |
334 proc.wait() | |
335 args = ["xrandr", "--addmode", "screen", label] | 333 args = ["xrandr", "--addmode", "screen", label] |
336 proc = subprocess.Popen(args, env=self.child_env, stdout=devnull, | 334 subprocess.call(args, env=self.child_env, stdout=devnull, stderr=devnull) |
337 stderr=devnull) | |
338 proc.wait() | |
339 | 335 |
340 # Set the initial mode to the first size specified, otherwise the X server | 336 # Set the initial mode to the first size specified, otherwise the X server |
341 # would default to (max_width, max_height), which might not even be in the | 337 # would default to (max_width, max_height), which might not even be in the |
342 # list. | 338 # list. |
343 label = "%dx%d" % self.sizes[0] | 339 (width, height) = self.sizes[0] |
340 label = "%dx%d" % (width, height) | |
344 args = ["xrandr", "-s", label] | 341 args = ["xrandr", "-s", label] |
345 proc = subprocess.Popen(args, env=self.child_env, stdout=devnull, | 342 subprocess.call(args, env=self.child_env, stdout=devnull, stderr=devnull) |
346 stderr=devnull) | 343 |
347 proc.wait() | 344 # Set the physical size of the display so that the initial mode is running |
345 # at approximately 96 DPI, since some desktops require the DPI to be set to | |
346 # something realistic. | |
347 DPI = 96.0 | |
348 MM_PER_INCH = 25.4 | |
349 # width / DPI is width in inches. Multiplying by MM_PER_INCH converts to mm. | |
350 width_mm = int(width / DPI * MM_PER_INCH) | |
Wez
2013/01/04 22:32:57
nit: Bracket width / DPI for readability.
| |
351 height_mm = int(height / DPI * MM_PER_INCH) | |
352 args = ["xrandr", "--fbmm", "%dx%d" % (width_mm, height_mm)] | |
Sergey Ulanov
2013/01/04 22:28:33
why not use --dpi here?
Wez
2013/01/04 23:36:02
Good point; xrandr --dpi 96/screen should work.
| |
353 subprocess.call(args, env=self.child_env, stdout=devnull, stderr=devnull) | |
348 | 354 |
349 devnull.close() | 355 devnull.close() |
350 | 356 |
351 def _launch_x_session(self): | 357 def _launch_x_session(self): |
352 # Start desktop session | 358 # Start desktop session |
353 # The /dev/null input redirection is necessary to prevent the X session | 359 # The /dev/null input redirection is necessary to prevent the X session |
354 # reading from stdin. If this code runs as a shell background job in a | 360 # reading from stdin. If this code runs as a shell background job in a |
355 # terminal, any reading from stdin causes the job to be suspended. | 361 # terminal, any reading from stdin causes the job to be suspended. |
356 # Daemonization would solve this problem by separating the process from the | 362 # Daemonization would solve this problem by separating the process from the |
357 # controlling terminal. | 363 # controlling terminal. |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 host_config.clear_auth() | 1056 host_config.clear_auth() |
1051 host_config.clear_host_info() | 1057 host_config.clear_host_info() |
1052 host_config.save() | 1058 host_config.save() |
1053 return 0 | 1059 return 0 |
1054 | 1060 |
1055 | 1061 |
1056 if __name__ == "__main__": | 1062 if __name__ == "__main__": |
1057 logging.basicConfig(level=logging.DEBUG, | 1063 logging.basicConfig(level=logging.DEBUG, |
1058 format="%(asctime)s:%(levelname)s:%(message)s") | 1064 format="%(asctime)s:%(levelname)s:%(message)s") |
1059 sys.exit(main()) | 1065 sys.exit(main()) |
OLD | NEW |