From a10babeb5d25af31ea4515a2e7fc83229ffa836f Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 20 Jan 2010 23:36:11 +0000 Subject: [PATCH] Port geometry hinting from trunk to epic-refactor. HEY THEO. --- terminatorlib/terminal.py | 11 +++++++++++ terminatorlib/window.py | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index acbb4bcc..a74d560c 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -859,6 +859,9 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) def on_vte_size_allocate(self, widget, allocation): self.titlebar.update_terminal_size(self.vte.get_column_count(), self.vte.get_row_count()) + if self.vte.window and self.config['geometry_hinting']: + window = util.get_top_window(self) + window.set_rough_geometry_hints() def on_vte_notify_enter(self, term, event): """Handle the mouse entering this terminal""" @@ -1084,6 +1087,14 @@ for %s (%s)' % (name, urlplugin.__class__.__name__)) height = self.vte.get_char_height() return((col * width, row * height)) + def get_font_size(self): + """Return the width/height of our font""" + return((self.vte.get_char_width(), self.vte.get_char_height())) + + def get_size(self): + """Return the column/rows of the terminal""" + return((self.vte.get_column_count(), self.vte.get_row_count())) + # There now begins a great list of keyboard event handlers # FIXME: Probably a bunch of these are wrong. TEST! def key_zoom_in(self): diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 72807751..40a76f84 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -333,16 +333,44 @@ class Window(Container, gtk.Window): if maker.isinstance(child, 'Container'): terminals.update(child.get_visible_terminals()) - elif maker.isnstance(child, 'Terminal'): - # This branch is only possible if we started out as a Notebook. We - # wouldn't have been called if there was really only one Terminal - # child. + elif maker.isinstance(child, 'Terminal'): terminals[child] = child.get_allocation() else: err('Unknown child type %s' % type(child)) return(terminals) + def set_rough_geometry_hints(self): + """Walk all the terminals along the top and left edges to fake up how + many columns/rows we sort of have""" + terminals = self.get_visible_terminals() + column_sum = 0 + row_sum = 0 + + for terminal in terminals: + rect = terminal.get_allocation() + if rect.x == 0: + cols, rows = terminal.get_size() + row_sum = row_sum + rows + if rect.y == 0: + cols, rows = terminal.get_size() + column_sum = column_sum + cols + + # FIXME: I don't think we should just use whatever font size info is on + # the last terminal we inspected. Looking up the default profile font + # size and calculating its character sizes would be rather expensive + # though. + font_width, font_height = terminal.get_font_size() + total_font_width = font_width * column_sum + total_font_height = font_height * row_sum + + win_width, win_height = self.get_size() + extra_width = win_width - total_font_width + extra_height = win_height - total_font_height + + self.set_geometry_hints(self, -1, -1, -1, -1, extra_width, + extra_height, font_width, font_height, -1.0, -1.0) + class WindowTitle(object): """Class to handle the setting of the window title"""