Add support for Xnest

This commit is contained in:
Marco Pesenti Gritti 2006-07-16 14:22:10 +02:00
parent ed303285a8
commit 5ec089b829
2 changed files with 52 additions and 31 deletions

View File

@ -1,47 +1,59 @@
import logging
import os
import socket
import sys
from Process import Process
def get_display_number():
"""Find a free display number trying to connect to 6000+ ports"""
retries = 20
display_number = 1
display_is_free = False
while not display_is_free and retries > 0:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('127.0.0.1', 6000 + display_number))
logging.info('Display %d is already in use. Trying next.' % (display_number))
s.close()
display_number += 1
retries -= 1
except:
display_is_free = True
if display_is_free:
return display_number
else:
logging.error('Cannot find a free display.')
sys.exit(0)
class XephyrProcess(Process):
def __init__(self):
self._display = self.get_display_number()
self._display = get_display_number()
cmd = 'Xephyr :%d -ac -screen 640x480' % (self._display)
Process.__init__(self, cmd)
def get_display_number(self):
"""Find a free display number trying to connect to 6000+ ports"""
retries = 20
display_number = 1
display_is_free = False
while not display_is_free and retries > 0:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('127.0.0.1', 6000 + display_number))
logging.info('Display %d is already in use. Trying next.' % (display_number))
s.close()
display_number += 1
retries -= 1
except:
display_is_free = True
if display_is_free:
return display_number
return -1
def get_name(self):
return 'Xephyr'
def start(self):
if self._display < 0:
logging.error('Cannot find a free display.')
else:
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
class XnestProcess(Process):
def __init__(self):
self._display = get_display_number()
cmd = 'Xnest :%d -geometry 640x480' % (self._display)
Process.__init__(self, cmd)
def get_name(self):
return 'Xnest'
def start(self):
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
class Emulator:
"""The OLPC emulator"""
@ -50,5 +62,13 @@ class Emulator:
pass
def start(self):
process = XephyrProcess()
process.start()
try:
process = XephyrProcess()
process.start()
except:
try:
process = XnestProcess()
process.start()
except:
logging.error('Cannot run the emulator. You need to install Xephyr or Xnest.')
sys.exit(0)

View File

@ -3,6 +3,7 @@ bin_SCRIPTS = sugar sugar-activity
sugardir = $(pkgdatadir)/shell
sugar_PYTHON = \
__init__.py \
ActivitiesModel.py \
ActivityRegistry.py \
ConsoleLogger.py \
Emulator.py \