Fix system fonts under gtk3
This commit is contained in:
parent
45cb6e05c6
commit
2bc19498ea
|
@ -79,12 +79,7 @@ from configobj.validate import Validator
|
||||||
from borg import Borg
|
from borg import Borg
|
||||||
from util import dbg, err, DEBUG, get_config_dir, dict_diff
|
from util import dbg, err, DEBUG, get_config_dir, dict_diff
|
||||||
|
|
||||||
try:
|
from gi.repository import Gio
|
||||||
import gi
|
|
||||||
gi.require_version('GConf','2.0')
|
|
||||||
from gi.repository import GConf
|
|
||||||
except ImportError:
|
|
||||||
dbg('Unable to import gconf, GNOME defaults unavailable')
|
|
||||||
|
|
||||||
DEFAULTS = {
|
DEFAULTS = {
|
||||||
'global_config': {
|
'global_config': {
|
||||||
|
@ -272,7 +267,6 @@ class Config(object):
|
||||||
"""Class to provide a slightly richer config API above ConfigBase"""
|
"""Class to provide a slightly richer config API above ConfigBase"""
|
||||||
base = None
|
base = None
|
||||||
profile = None
|
profile = None
|
||||||
gconf = None
|
|
||||||
system_mono_font = None
|
system_mono_font = None
|
||||||
system_prop_font = None
|
system_prop_font = None
|
||||||
system_focus = None
|
system_focus = None
|
||||||
|
@ -282,6 +276,7 @@ class Config(object):
|
||||||
self.base = ConfigBase()
|
self.base = ConfigBase()
|
||||||
self.set_profile(profile)
|
self.set_profile(profile)
|
||||||
self.inhibited = False
|
self.inhibited = False
|
||||||
|
self.connect_gsetting_callbacks()
|
||||||
|
|
||||||
def __getitem__(self, key, default=None):
|
def __getitem__(self, key, default=None):
|
||||||
"""Look up a configuration item"""
|
"""Look up a configuration item"""
|
||||||
|
@ -360,70 +355,69 @@ class Config(object):
|
||||||
"""List all configured layouts"""
|
"""List all configured layouts"""
|
||||||
return(self.base.layouts.keys())
|
return(self.base.layouts.keys())
|
||||||
|
|
||||||
|
def connect_gsetting_callbacks(self):
|
||||||
|
"""Get system settings and create callbacks for changes"""
|
||||||
|
dbg("GSetting connects for system changes")
|
||||||
|
# Have to preserve these to self, or callbacks don't happen
|
||||||
|
self.gsettings_interface=Gio.Settings.new('org.gnome.desktop.interface')
|
||||||
|
self.gsettings_interface.connect("changed::font-name", self.on_gsettings_change_event)
|
||||||
|
self.gsettings_interface.connect("changed::monospace-font-name", self.on_gsettings_change_event)
|
||||||
|
self.gsettings_wm=Gio.Settings.new('org.gnome.desktop.wm.preferences')
|
||||||
|
self.gsettings_wm.connect("changed::focus-mode", self.on_gsettings_change_event)
|
||||||
|
|
||||||
def get_system_prop_font(self):
|
def get_system_prop_font(self):
|
||||||
"""Look up the system font"""
|
"""Look up the system font"""
|
||||||
if self.system_prop_font is not None:
|
if self.system_prop_font is not None:
|
||||||
return(self.system_prop_font)
|
return(self.system_prop_font)
|
||||||
elif 'GConf' not in globals():
|
elif 'org.gnome.desktop.interface' not in Gio.Settings.list_schemas():
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if self.gconf is None:
|
gsettings=Gio.Settings.new('org.gnome.desktop.interface')
|
||||||
self.gconf = GConf.Client.get_default()
|
value = gsettings.get_value('font-name')
|
||||||
|
|
||||||
value = self.gconf.get(
|
|
||||||
'/desktop/gnome/interface/font_name')
|
|
||||||
if value:
|
if value:
|
||||||
self.system_prop_font = value.get_string()
|
self.system_prop_font = value.get_string()
|
||||||
else:
|
else:
|
||||||
self.system_prop_font = "Sans 10"
|
self.system_prop_font = "Sans 10"
|
||||||
self.gconf.notify_add(
|
|
||||||
'/desktop/gnome/interface/font_name',
|
|
||||||
self.on_gconf_notify)
|
|
||||||
return(self.system_prop_font)
|
return(self.system_prop_font)
|
||||||
|
|
||||||
def get_system_mono_font(self):
|
def get_system_mono_font(self):
|
||||||
"""Look up the system font"""
|
"""Look up the system font"""
|
||||||
if self.system_mono_font is not None:
|
if self.system_mono_font is not None:
|
||||||
return(self.system_mono_font)
|
return(self.system_mono_font)
|
||||||
elif 'GConf' not in globals():
|
elif 'org.gnome.desktop.interface' not in Gio.Settings.list_schemas():
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if self.gconf is None:
|
gsettings=Gio.Settings.new('org.gnome.desktop.interface')
|
||||||
self.gconf = GConf.Client.get_default()
|
value = gsettings.get_value('monospace-font-name')
|
||||||
|
|
||||||
value = self.gconf.get(
|
|
||||||
'/desktop/gnome/interface/monospace_font_name')
|
|
||||||
if value:
|
if value:
|
||||||
self.system_mono_font = value.get_string()
|
self.system_mono_font = value.get_string()
|
||||||
else:
|
else:
|
||||||
self.system_mono_font = "Mono 10"
|
self.system_mono_font = "Mono 10"
|
||||||
self.gconf.notify_add(
|
|
||||||
'/desktop/gnome/interface/monospace_font_name',
|
|
||||||
self.on_gconf_notify)
|
|
||||||
return(self.system_mono_font)
|
return(self.system_mono_font)
|
||||||
|
|
||||||
def get_system_focus(self):
|
def get_system_focus(self):
|
||||||
"""Look up the system focus setting"""
|
"""Look up the system focus setting"""
|
||||||
if self.system_focus is not None:
|
if self.system_focus is not None:
|
||||||
return(self.system_focus)
|
return(self.system_focus)
|
||||||
elif 'GConf' not in globals():
|
elif 'org.gnome.desktop.interface' not in Gio.Settings.list_schemas():
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if self.gconf is None:
|
gsettings=Gio.Settings.new('org.gnome.desktop.wm.preferences')
|
||||||
self.gconf = GConf.Client.get_default()
|
value = gsettings.get_value('focus-mode')
|
||||||
|
|
||||||
value = self.gconf.get('/apps/metacity/general/focus_mode')
|
|
||||||
if value:
|
if value:
|
||||||
self.system_focus = value.get_string()
|
self.system_focus = value.get_string()
|
||||||
self.gconf.notify_add('/apps/metacity/general/focus_mode',
|
|
||||||
self.on_gconf_notify)
|
|
||||||
return(self.system_focus)
|
return(self.system_focus)
|
||||||
|
|
||||||
def on_gconf_notify(self, _client, _cnxn_id, _entry, _what):
|
def on_gsettings_change_event(self, settings, key):
|
||||||
"""Handle a gconf watch changing"""
|
"""Handle a gsetting change event"""
|
||||||
dbg('GConf notification received. Invalidating caches')
|
dbg('GSetting change event received. Invalidating caches')
|
||||||
self.system_focus = None
|
self.system_focus = None
|
||||||
self.system_font = None
|
self.system_font = None
|
||||||
|
self.system_mono_font = None
|
||||||
|
# Need to trigger a reconfigure to change active terminals immediately
|
||||||
|
if "Terminator" not in globals():
|
||||||
|
from terminator import Terminator
|
||||||
|
Terminator().reconfigure()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Cause ConfigBase to save our config to file"""
|
"""Cause ConfigBase to save our config to file"""
|
||||||
|
|
Loading…
Reference in New Issue