Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions guake/data/org.guake.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
<summary>Hide tab bar if there is only one tab</summary>
<description>When true, the tab bar will hide when there is only one tab</description>
</key>
<key name="per-terminal-zoom" type="b">
<default>false</default>
<summary>Zoom only the focused terminal</summary>
<description>When true, the zoom in/out shortcuts change the font size of the focused terminal only, and each terminal keeps its own zoom level. When false, they change the configured font size, zooming every terminal at once.</description>
</key>
<key name="quick-open-enable" type="b">
<default>false</default>
<summary>Enable Quick Open feature.</summary>
Expand Down
17 changes: 17 additions & 0 deletions guake/data/prefs.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,23 @@
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="per_terminal_zoom">
<property name="label" translatable="yes">Zoom in/out affects only the focused terminal</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="tooltip-text" translatable="yes">Each terminal keeps its own zoom level. When disabled, zooming changes the configured font size and every terminal at once.</property>
<property name="halign">start</property>
<property name="use-underline">True</property>
<property name="draw-indicator">True</property>
<signal name="toggled" handler="on_per_terminal_zoom_toggled" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
Expand Down
45 changes: 35 additions & 10 deletions guake/guake_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,22 +950,47 @@ def accel_reset_terminal(self, *args):
HidePrevention(self.window).allow()
return True

def zoom(self, step):
"""Zoom in or out by one step.

A zoom level is a scale a terminal applies on top of the configured font size.
With per-terminal zoom, only the focused terminal is zoomed and each terminal
keeps its own level. Otherwise every terminal ends up the same size as the
focused one: their individual levels are dropped, and the configured font size
is changed instead, so the zoom is remembered across restarts.
"""
notebook = self.get_notebook()
terminal = notebook.get_current_terminal()

if self.settings.general.get_boolean("per-terminal-zoom"):
if terminal:
terminal.font_scale += step
return

if self.settings.general.get_boolean("use-default-font"):
# The font size follows the desktop setting, so there is no configured size
# to change here: zoom every terminal to the same level instead.
scale = (terminal.font_scale if terminal else 0) + step
for term in notebook.iter_terminals():
term.font_scale = scale
return

font, _, size = self.settings.styleFont.get_string("style").rpartition(" ")
# Start from the size the focused terminal shows, so a terminal zoomed on its
# own is the one the others snap to.
size = round(int(size) * terminal.font_scale_factor) if terminal else int(size)
self.settings.styleFont.set_string("style", f"{font} {max(1, size + step)}")
for term in notebook.iter_terminals():
term.font_scale = 0

def accel_zoom_in(self, *args):
"""Callback to zoom in."""
font = " ".join(self.settings.styleFont.get_string("style").split(" ")[:-1])
new_size = int(self.settings.styleFont.get_string("style").split(" ")[-1]) + 1
self.settings.styleFont.set_string("style", f"{font} {new_size}")
for term in self.get_notebook().iter_terminals():
term.set_font_scale(new_size / (new_size - 1))
self.zoom(1)
return True

def accel_zoom_out(self, *args):
"""Callback to zoom out."""
font = " ".join(self.settings.styleFont.get_string("style").split(" ")[:-1])
new_size = int(self.settings.styleFont.get_string("style").split(" ")[-1]) - 1
self.settings.styleFont.set_string("style", f"{font} {new_size}")
for term in self.get_notebook().iter_terminals():
term.set_font_scale((new_size - 1) / new_size)
self.zoom(-1)
return True

def accel_increase_height(self, *args):
Expand Down
8 changes: 8 additions & 0 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ def on_bold_is_bright_toggled(self, chk):
"""Changes the value of bold_is_bright in dconf"""
self.settings.styleFont.set_boolean("bold-is-bright", chk.get_active())

def on_per_terminal_zoom_toggled(self, chk):
"""Changes the activity of per_terminal_zoom in dconf"""
self.settings.general.set_boolean("per-terminal-zoom", chk.get_active())

def on_cell_height_scale_value_changed(self, scale):
value = scale.get_value()
self.settings.styleFont.set_double("cell-height-scale", value)
Expand Down Expand Up @@ -1290,6 +1294,10 @@ def load_configs(self):
value = self.settings.styleFont.get_boolean("bold-is-bright")
self.get_widget("bold_is_bright").set_active(value)

# zoom only the focused terminal
value = self.settings.general.get_boolean("per-terminal-zoom")
self.get_widget("per_terminal_zoom").set_active(value)

# cell height scale
value = self.settings.styleFont.get_double("cell-height-scale")
self.get_widget("cell_height_scale_adjustment").set_value(value)
Expand Down
8 changes: 6 additions & 2 deletions guake/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ def set_font_scale_index(self, scale_index):
self.font_scale_index = clamp(scale_index, -6, 12)

font = Pango.FontDescription(self.font.to_string())
scale_factor = 2 ** (self.font_scale_index / 6)
new_size = int(scale_factor * font.get_size())
new_size = int(self.font_scale_factor * font.get_size())

if font.get_size_is_absolute():
font.set_absolute_size(new_size)
Expand All @@ -525,6 +524,11 @@ def set_font_scale_index(self, scale_index):

font_scale = property(fset=set_font_scale_index, fget=lambda self: self.font_scale_index)

@property
def font_scale_factor(self):
"""Factor the zoom level applies to the configured font size."""
return 2 ** (self.font_scale_index / 6)

def increase_font_size(self):
self.font_scale += 1

Expand Down
17 changes: 17 additions & 0 deletions releasenotes/notes/per_terminal_zoom-102c01144c94d613.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
release_summary: >
Zoom in and out can now apply to the focused terminal only, letting each terminal
keep its own zoom level.

features:
- |
- New "Zoom in/out affects only the focused terminal" preference, in Appearance.
When enabled, each terminal keeps its own zoom level, applied on top of the
configured font size. When disabled (the default, as before), zooming changes
the configured font size and every terminal with it.

fixes:
- |
- Zooming every terminal no longer applies the new font size twice, once as a
font size and once as a terminal font scale, which made a zoom step larger
than intended and zoom out a different size than zoom in.
- Zooming out repeatedly no longer reaches a font size of zero.