Skip to content

Commit

Permalink
Fixed github #3: Use System Fonts?
Browse files Browse the repository at this point in the history
The desktop setting key 'monospace-font-name' of the
'org.gnome.desktop.interface' schema is listened to set the terminal
font.
  • Loading branch information
zzrough committed Oct 15, 2012
1 parent f5223ac commit ee7eb81
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ v3 (2012-10-06)
this simplifies shell restart survival a lot

v4 (????-??-??)
- feature: always open on the primary monitor on multihead (this is where the panelBox is)
- feature: always open on the primary monitor on multihead (this is where the panelBox is) (github #1)
- bugfix: use the system monospace font (github #3)
2 changes: 1 addition & 1 deletion ROADMAP
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ v4
- feature: copy/paste via popupmenu + shortcuts (ctrl-shift'ed) + dnd
- feature: multi tabs
- feature: open prefs on first start
- feature: use the system monospace font
- feature: check for dependencies at startup (asked by l300lvl -- Debian distributes gir files in their own packages)
- feature: detect active pid and ask before exiting the shell? (or detach it?)
- bugfix: ZSH (github #2)

- code: switch to window-manager for window handling?
- code: investigate if the inner-border can be retrieved
Expand Down
33 changes: 28 additions & 5 deletions drop-down-terminal@gs-extensions.zzrough.org/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ANIMATION_TIME_IN_MS = 0.25;
const ENABLE_ANIMATION_SETTING_KEY = "enable-animation";
const WINDOW_HEIGHT_SETTING_KEY = "window-height";
const REAL_SHORTCUT_SETTING_KEY = "real-shortcut";
const FONT_NAME_SETTING_KEY = "monospace-font-name";
const DEBUG = false;


Expand All @@ -60,6 +61,7 @@ const DropDownTerminalIface =
<arg name="width" type="i" direction="in"/>
<arg name="height" type="i" direction="in"/>
</method>
<method name="SetFont"><arg type="s" direction="in"/></method>
<method name="IsOpened"><arg type="b" direction="out"/></method>
<method name="Toggle"/>
<method name="Focus"/>
Expand Down Expand Up @@ -101,6 +103,9 @@ const DropDownTerminalExtension = new Lang.Class({
_init: function() {
// retrieves the settings
this._settings = Convenience.getSettings(Me.path, Me.metadata.id);
this._interfaceSettings = new Gio.Settings({
settings_schema: Gio.SettingsSchemaSource.get_default().lookup("org.gnome.desktop.interface", false)
});

// initializes the child pid and bus proxy members early as it used to know if it has been spawn already
this._childPid = null;
Expand All @@ -112,9 +117,6 @@ const DropDownTerminalExtension = new Lang.Class({

// initializes if we should toggle on bus name appearance
this._toggleOnBusNameAppearance = false;

// id of the timeout used to delay the window height setting application
this._windowHeightDelayTimeoutId = null;
},

enable: function() {
Expand All @@ -126,19 +128,24 @@ const DropDownTerminalExtension = new Lang.Class({
// applies the settings initially
this._animationEnabledSettingChanged();
this._updateWindowSize();
this._updateFont();
this._bindShortcut();

// honours setting changes
this._settingChangedHandlerIds = [
this._settings.connect("changed::" + ENABLE_ANIMATION_SETTING_KEY, Lang.bind(this, this._animationEnabledSettingChanged)),

this._settings.connect("changed::" + WINDOW_HEIGHT_SETTING_KEY, Lang.bind(this, function() {
Convenience.throttle(250, this._updateWindowSize, this); // throttles 1s (it's an "heavy weight" setting)
Convenience.throttle(200, this._updateWindowSize, this); // throttles 200ms (it's an "heavy weight" setting)
})),

this._settings.connect("changed::" + REAL_SHORTCUT_SETTING_KEY, Lang.bind(this, function() {
this._unbindShortcut();
this._bindShortcut();
})),

this._interfaceSettings.connect("changed::" + FONT_NAME_SETTING_KEY, Lang.bind(this, function() {
Convenience.throttle(200, this._updateFont, this); // throttles 200ms (it's an "heavy weight" setting)
}))
];

Expand Down Expand Up @@ -248,6 +255,17 @@ const DropDownTerminalExtension = new Lang.Class({
return false;
},

_updateFont: function() {
this._fontName = this._interfaceSettings.get_string(FONT_NAME_SETTING_KEY);

// applies the change dynamically if the terminal is already spawn
if (this._busProxy !== null && this._fontName !== null) {
this._busProxy.SetFontRemote(this._fontName);
}

return false;
},

_bindShortcut: function() {
global.display.add_keybinding(REAL_SHORTCUT_SETTING_KEY, this._settings, Meta.KeyBindingFlags.NONE,
Lang.bind(this, this._toggle));
Expand Down Expand Up @@ -390,11 +408,16 @@ const DropDownTerminalExtension = new Lang.Class({
}
}));

// applies the eventual window height change
// applies the possible window height change
if (this._windowHeight !== null) {
this._busProxy.SetSizeSync(Main.layoutManager.primaryMonitor.width, this._windowHeight);
}

// applies the possible font name
if (this._fontName !== null) {
this._busProxy.SetFontSync(this._fontName);
}

// initial toggling if explicitely asked to, since we we can also be called on a shell restart
// (the shell reexec itself thus not letting the extensions a chance to properly shut down)
if (this._toggleOnBusNameAppearance) {
Expand Down
26 changes: 19 additions & 7 deletions drop-down-terminal@gs-extensions.zzrough.org/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const DropDownTerminalIface =
<interface name="org.zzrough.GsExtensions.DropDownTerminal">
<property name="Pid" type="i" access="read"/>
<method name="SetSize">
<arg name="width" type="i" direction="in"/>
<arg name="height" type="i" direction="in"/>
</method>
<arg name="width" type="i" direction="in"/>
<arg name="height" type="i" direction="in"/>
</method>
<method name="SetFont"><arg type="s" direction="in"/></method>
<method name="IsOpened"><arg type="b" direction="out"/></method>
<method name="Toggle"/>
<method name="Focus"/>
Expand Down Expand Up @@ -148,10 +149,21 @@ const DropDownTerminal = new Lang.Class({
},

SetSize: function(width, height) {
// update the window height in the UI thread since this callback happens in the gdbus thread
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, Lang.bind(this, function() {
this._window.resize(width, height);
}));
let [currentWidth, currentHeight] = this._window.get_size();

if (width != currentWidth || height != currentHeight) {
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, Lang.bind(this, function() {
this._window.resize(width, height);
}));
}
},

SetFont: function(font) {
if (font != this._terminal.get_font().to_string()) {
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, Lang.bind(this, function() {
this._terminal.set_font_from_string(font);
}));
}
},

IsOpened: function() {
Expand Down

0 comments on commit ee7eb81

Please sign in to comment.