Add debugging and hash the X11 display (suggestion from Andrea)
This commit is contained in:
parent
9044ffabb0
commit
93104c42a2
|
@ -60,9 +60,11 @@ if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
ipc.DBusService()
|
ipc.DBusService()
|
||||||
except ipc.DBusException:
|
except ipc.DBusException:
|
||||||
|
dbg('Unable to become master process, requesting a new window')
|
||||||
ipc.new_window()
|
ipc.new_window()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
dbg('dbus not imported')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
MAKER = Factory()
|
MAKER = Factory()
|
||||||
|
|
|
@ -10,17 +10,19 @@ import dbus.glib
|
||||||
from borg import Borg
|
from borg import Borg
|
||||||
from terminator import Terminator
|
from terminator import Terminator
|
||||||
from config import Config
|
from config import Config
|
||||||
|
from util import dbg
|
||||||
|
|
||||||
CONFIG = Config()
|
CONFIG = Config()
|
||||||
if not CONFIG['dbus']:
|
if not CONFIG['dbus']:
|
||||||
# The config says we are not to load dbus, so pretend like we can't
|
# The config says we are not to load dbus, so pretend like we can't
|
||||||
|
dbg('dbus disabled')
|
||||||
raise ImportError
|
raise ImportError
|
||||||
|
|
||||||
BUS_BASE = 'net.tenshu.Terminator'
|
BUS_BASE = 'net.tenshu.Terminator'
|
||||||
BUS_PATH = '/net/tenshu/Terminator'
|
BUS_PATH = '/net/tenshu/Terminator'
|
||||||
try:
|
try:
|
||||||
# Try and include the X11 display name in the dbus bus name
|
# Try and include the X11 display name in the dbus bus name
|
||||||
DISPLAY = gtk.gdk.get_display().replace(':', '').replace('.', '')
|
DISPLAY = hex(hash(gtk.gdk.get_display())).replace('-', '_')
|
||||||
BUS_NAME = '%s%s' % (BUS_BASE, DISPLAY)
|
BUS_NAME = '%s%s' % (BUS_BASE, DISPLAY)
|
||||||
except:
|
except:
|
||||||
BUS_NAME = BUS_BASE
|
BUS_NAME = BUS_BASE
|
||||||
|
@ -32,17 +34,20 @@ class DBusService(Borg, dbus.service.Object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Class initialiser"""
|
"""Class initialiser"""
|
||||||
|
Borg.__init__(self, self.__class__.__name__)
|
||||||
self.prepare_attributes()
|
self.prepare_attributes()
|
||||||
dbus.service.Object.__init__(self, self.bus_name, BUS_PATH)
|
dbus.service.Object.__init__(self, self.bus_name, BUS_PATH)
|
||||||
|
|
||||||
def prepare_attributes(self):
|
def prepare_attributes(self):
|
||||||
"""Ensure we are populated"""
|
"""Ensure we are populated"""
|
||||||
if not self.bus_name:
|
if not self.bus_name:
|
||||||
|
dbg('Checking for bus name availability: %s' % BUS_NAME)
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
proxy = bus.get_object('org.freedesktop.DBus',
|
proxy = bus.get_object('org.freedesktop.DBus',
|
||||||
'/org/freedesktop/DBus')
|
'/org/freedesktop/DBus')
|
||||||
flags = 1 | 4 # allow replacement | do not queue
|
flags = 1 | 4 # allow replacement | do not queue
|
||||||
if not proxy.RequestName(BUS_NAME, dbus.UInt32(flags)) in (1, 4):
|
if not proxy.RequestName(BUS_NAME, dbus.UInt32(flags)) in (1, 4):
|
||||||
|
dbg('bus name unavailable: %s' % BUS_NAME)
|
||||||
raise dbus.exceptions.DBusException(
|
raise dbus.exceptions.DBusException(
|
||||||
"Couldn't get DBus name %s: Name exists" % BUS_NAME)
|
"Couldn't get DBus name %s: Name exists" % BUS_NAME)
|
||||||
self.bus_name = dbus.service.BusName(BUS_NAME,
|
self.bus_name = dbus.service.BusName(BUS_NAME,
|
||||||
|
@ -53,11 +58,13 @@ class DBusService(Borg, dbus.service.Object):
|
||||||
@dbus.service.method(BUS_NAME)
|
@dbus.service.method(BUS_NAME)
|
||||||
def new_window(self):
|
def new_window(self):
|
||||||
"""Create a new Window"""
|
"""Create a new Window"""
|
||||||
|
dbg('dbus method called')
|
||||||
self.terminator.create_layout('default')
|
self.terminator.create_layout('default')
|
||||||
self.terminator.layout_done()
|
self.terminator.layout_done()
|
||||||
|
|
||||||
def with_proxy(func):
|
def with_proxy(func):
|
||||||
"""Decorator function to connect to the session dbus bus"""
|
"""Decorator function to connect to the session dbus bus"""
|
||||||
|
dbg('dbus client call: %s' % func.func_name)
|
||||||
def _exec(*args, **argd):
|
def _exec(*args, **argd):
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
proxy = bus.get_object(BUS_NAME, BUS_PATH)
|
proxy = bus.get_object(BUS_NAME, BUS_PATH)
|
||||||
|
|
Loading…
Reference in New Issue