From 4269a995989aba561a9c79479b680c6490b27b7f Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Tue, 29 Sep 2015 02:24:36 +0200 Subject: [PATCH] Reimplement visual flash that got removed from libvte, reusing the DnD overlay to flash the terminal (gtk2->gtk3) --- terminatorlib/config.py | 1 + terminatorlib/preferences.glade | 21 ++++++++++++++++++-- terminatorlib/prefseditor.py | 8 ++++++++ terminatorlib/terminal.py | 35 +++++++++++++++++++++++++++++++-- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index bd215c21..d69d2e63 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -198,6 +198,7 @@ DEFAULTS = { 'default': { 'allow_bold' : True, 'audible_bell' : False, + 'visible_bell' : False, 'urgent_bell' : False, 'icon_bell' : True, 'background_color' : '#000000', diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index a3015476..bfe32de3 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -1806,6 +1806,23 @@ 0 + + + Visual flash + True + True + False + False + True + True + + + + False + False + 1 + + Audible beep @@ -1820,7 +1837,7 @@ False False - 1 + 2 @@ -1837,7 +1854,7 @@ False False - 2 + 3 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index f691244f..cabe27e4 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -406,6 +406,9 @@ class PrefsEditor: # Icon terminal bell widget = guiget('icon_bell_checkbutton') widget.set_active(self.config['icon_bell']) + # Visual terminal bell + widget = guiget('visual_bell_checkbutton') + widget.set_active(self.config['visible_bell']) # Audible terminal bell widget = guiget('audible_bell_checkbutton') widget.set_active(self.config['audible_bell']) @@ -703,6 +706,11 @@ class PrefsEditor: self.config['icon_bell'] = widget.get_active() self.config.save() + def on_visual_bell_checkbutton_toggled(self, widget): + """Visual bell setting changed""" + self.config['visible_bell'] = widget.get_active() + self.config.save() + def on_audible_bell_checkbutton_toggled(self, widget): """Audible bell setting changed""" self.config['audible_bell'] = widget.get_active() diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 1cafb639..e6092710 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -744,7 +744,8 @@ class Terminal(Gtk.VBox): self.vte.set_audible_bell(self.config['audible_bell']) self.cnxids.remove_signal(self.vte, 'bell') if self.config['urgent_bell'] == True or \ - self.config['icon_bell'] == True: + self.config['icon_bell'] == True or \ + self.config['visible_bell'] == True: try: self.cnxids.new(self.vte, 'bell', self.on_bell) except TypeError: @@ -1515,13 +1516,43 @@ class Terminal(Gtk.VBox): return((self.vte.get_column_count(), self.vte.get_row_count())) def on_bell(self, widget): - """Set the urgency hint for our window""" + """Set the urgency hint/icon/flash for our window""" if self.config['urgent_bell'] == True: window = self.get_toplevel() if window.is_toplevel(): window.set_urgency_hint(True) if self.config['icon_bell'] == True: self.titlebar.icon_bell() + if self.config['visible_bell'] == True: + # Repurposed the code used for drag and drop overlay to provide a visual terminal flash + alloc = widget.get_allocation() + + if self.config['use_theme_colors']: + color = self.vte.get_style_context().get_color(Gtk.StateType.NORMAL) # VERIFY FOR GTK3 as above + else: + color = Gdk.RGBA() + color.parse(self.config['foreground_color']) # VERIFY FOR GTK3 + + coord = ( (0, 0), (alloc.width, 0), (alloc.width, alloc.height), (0, alloc.height)) + + #here, we define some widget internal values + widget._draw_data = { 'color': color, 'coord' : coord } + #redraw by forcing an event + connec = widget.connect_after('draw', self.on_draw) + widget.queue_draw_area(0, 0, alloc.width, alloc.height) + widget.get_window().process_updates(True) + #finaly reset the values + widget.disconnect(connec) + widget._draw_data = None + + # Add timeout to clean up display + GObject.timeout_add(100, self.on_bell_cleanup, widget, alloc) + + def on_bell_cleanup(self, widget, alloc): + '''Queue a redraw to clear the visual flash overlay''' + widget.queue_draw_area(0, 0, alloc.width, alloc.height) + widget.get_window().process_updates(True) + return False def describe_layout(self, count, parent, global_layout, child_order): """Describe our layout"""