Merge pull request #286 from mattrose/dim-on-focus-out-sq
fix issue #74
This commit is contained in:
commit
ebc266e554
|
@ -6,6 +6,7 @@
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import gi
|
import gi
|
||||||
|
import cairo
|
||||||
from gi.repository import GLib, GObject, Pango, Gtk, Gdk, GdkPixbuf
|
from gi.repository import GLib, GObject, Pango, Gtk, Gdk, GdkPixbuf
|
||||||
gi.require_version('Vte', '2.91') # vte-0.38 (gnome-3.14)
|
gi.require_version('Vte', '2.91') # vte-0.38 (gnome-3.14)
|
||||||
from gi.repository import Vte
|
from gi.repository import Vte
|
||||||
|
@ -31,6 +32,25 @@ from . import plugin
|
||||||
from terminatorlib.layoutlauncher import LayoutLauncher
|
from terminatorlib.layoutlauncher import LayoutLauncher
|
||||||
from . import regex
|
from . import regex
|
||||||
|
|
||||||
|
class Overpaint(Vte.Terminal):
|
||||||
|
def __init__(self):
|
||||||
|
Vte.Terminal.__init__(self)
|
||||||
|
self.config = Config()
|
||||||
|
self.dim_p = float(self.config['inactive_color_offset'])
|
||||||
|
self.dim_l = round(1.0 - self.dim_p,3)
|
||||||
|
def dim(self,b):
|
||||||
|
self.overpaint = b
|
||||||
|
|
||||||
|
def do_draw(self,cr):
|
||||||
|
bgc = Vte.Terminal.get_color_background_for_draw(self)
|
||||||
|
Vte.Terminal.do_draw(self,cr)
|
||||||
|
if self.overpaint:
|
||||||
|
bgc.alpha = self.dim_l
|
||||||
|
cr.set_operator(cairo.Operator.OVER)
|
||||||
|
Gdk.cairo_set_source_rgba(cr,bgc)
|
||||||
|
cr.rectangle(0.0,0.0,self.get_allocated_width(),self.get_allocated_height())
|
||||||
|
cr.paint()
|
||||||
|
|
||||||
# pylint: disable-msg=R0904
|
# pylint: disable-msg=R0904
|
||||||
class Terminal(Gtk.VBox):
|
class Terminal(Gtk.VBox):
|
||||||
"""Class implementing the VTE widget and its wrappings"""
|
"""Class implementing the VTE widget and its wrappings"""
|
||||||
|
@ -102,10 +122,8 @@ class Terminal(Gtk.VBox):
|
||||||
directory = None
|
directory = None
|
||||||
|
|
||||||
fgcolor_active = None
|
fgcolor_active = None
|
||||||
fgcolor_inactive = None
|
|
||||||
bgcolor = None
|
bgcolor = None
|
||||||
palette_active = None
|
palette_active = None
|
||||||
palette_inactive = None
|
|
||||||
|
|
||||||
composite_support = None
|
composite_support = None
|
||||||
|
|
||||||
|
@ -135,7 +153,9 @@ class Terminal(Gtk.VBox):
|
||||||
|
|
||||||
self.pending_on_vte_size_allocate = False
|
self.pending_on_vte_size_allocate = False
|
||||||
|
|
||||||
self.vte = Vte.Terminal()
|
self.vte = Overpaint()
|
||||||
|
self.vte.dim(False)
|
||||||
|
self.queue_draw()
|
||||||
self.background_image = None
|
self.background_image = None
|
||||||
if self.config['background_image'] != '':
|
if self.config['background_image'] != '':
|
||||||
self.vte.set_clear_background(False)
|
self.vte.set_clear_background(False)
|
||||||
|
@ -731,58 +751,23 @@ class Terminal(Gtk.VBox):
|
||||||
else:
|
else:
|
||||||
self.bgcolor.alpha = 1
|
self.bgcolor.alpha = 1
|
||||||
|
|
||||||
factor = self.config['inactive_color_offset']
|
|
||||||
if factor > 1.0:
|
|
||||||
factor = 1.0
|
|
||||||
self.fgcolor_inactive = self.fgcolor_active.copy()
|
|
||||||
dbg(("fgcolor_inactive set to: RGB(%s,%s,%s)", getattr(self.fgcolor_inactive, "red"),
|
|
||||||
getattr(self.fgcolor_inactive, "green"),
|
|
||||||
getattr(self.fgcolor_inactive, "blue")))
|
|
||||||
|
|
||||||
for bit in ['red', 'green', 'blue']:
|
|
||||||
setattr(self.fgcolor_inactive, bit,
|
|
||||||
getattr(self.fgcolor_inactive, bit) * factor)
|
|
||||||
|
|
||||||
dbg(("fgcolor_inactive set to: RGB(%s,%s,%s)", getattr(self.fgcolor_inactive, "red"),
|
|
||||||
getattr(self.fgcolor_inactive, "green"),
|
|
||||||
getattr(self.fgcolor_inactive, "blue")))
|
|
||||||
colors = self.config['palette'].split(':')
|
colors = self.config['palette'].split(':')
|
||||||
self.palette_active = []
|
self.palette_active = []
|
||||||
|
|
||||||
for color in colors:
|
for color in colors:
|
||||||
if color:
|
if color:
|
||||||
newcolor = Gdk.RGBA()
|
newcolor = Gdk.RGBA()
|
||||||
newcolor.parse(color)
|
newcolor.parse(color)
|
||||||
self.palette_active.append(newcolor)
|
self.palette_active.append(newcolor)
|
||||||
if len(colors) == 16:
|
self.vte.set_colors(self.fgcolor_active, self.bgcolor,
|
||||||
# RGB values for indices 16..255 copied from vte source in order to dim them
|
|
||||||
shades = [0, 95, 135, 175, 215, 255]
|
|
||||||
for r in range(0, 6):
|
|
||||||
for g in range(0, 6):
|
|
||||||
for b in range(0, 6):
|
|
||||||
newcolor = Gdk.RGBA()
|
|
||||||
setattr(newcolor, "red", shades[r] / 255.0)
|
|
||||||
setattr(newcolor, "green", shades[g] / 255.0)
|
|
||||||
setattr(newcolor, "blue", shades[b] / 255.0)
|
|
||||||
self.palette_active.append(newcolor)
|
|
||||||
for y in range(8, 248, 10):
|
|
||||||
newcolor = Gdk.RGBA()
|
|
||||||
setattr(newcolor, "red", y / 255.0)
|
|
||||||
setattr(newcolor, "green", y / 255.0)
|
|
||||||
setattr(newcolor, "blue", y / 255.0)
|
|
||||||
self.palette_active.append(newcolor)
|
|
||||||
self.palette_inactive = []
|
|
||||||
for color in self.palette_active:
|
|
||||||
newcolor = Gdk.RGBA()
|
|
||||||
for bit in ['red', 'green', 'blue']:
|
|
||||||
setattr(newcolor, bit,
|
|
||||||
getattr(color, bit) * factor)
|
|
||||||
self.palette_inactive.append(newcolor)
|
|
||||||
if self.terminator.last_focused_term == self:
|
|
||||||
self.vte.set_colors(self.fgcolor_active, self.bgcolor,
|
|
||||||
self.palette_active)
|
self.palette_active)
|
||||||
|
|
||||||
|
if self.terminator.last_focused_term == self:
|
||||||
|
self.vte.dim(False)
|
||||||
|
self.queue_draw()
|
||||||
else:
|
else:
|
||||||
self.vte.set_colors(self.fgcolor_inactive, self.bgcolor,
|
self.vte.dim(True)
|
||||||
self.palette_inactive)
|
self.queue_draw()
|
||||||
profiles = self.config.base.profiles
|
profiles = self.config.base.profiles
|
||||||
terminal_box_style_context = self.terminalbox.get_style_context()
|
terminal_box_style_context = self.terminalbox.get_style_context()
|
||||||
for profile in list(profiles.keys()):
|
for profile in list(profiles.keys()):
|
||||||
|
@ -1293,9 +1278,8 @@ class Terminal(Gtk.VBox):
|
||||||
|
|
||||||
def on_vte_focus_in(self, _widget, _event):
|
def on_vte_focus_in(self, _widget, _event):
|
||||||
"""Inform other parts of the application when focus is received"""
|
"""Inform other parts of the application when focus is received"""
|
||||||
self.vte.set_colors(self.fgcolor_active, self.bgcolor,
|
self.vte.dim(False)
|
||||||
self.palette_active)
|
self.queue_draw()
|
||||||
self.set_cursor_color()
|
|
||||||
if not self.terminator.doing_layout:
|
if not self.terminator.doing_layout:
|
||||||
self.terminator.last_focused_term = self
|
self.terminator.last_focused_term = self
|
||||||
if self.get_toplevel().is_child_notebook():
|
if self.get_toplevel().is_child_notebook():
|
||||||
|
@ -1309,9 +1293,8 @@ class Terminal(Gtk.VBox):
|
||||||
|
|
||||||
def on_vte_focus_out(self, _widget, _event):
|
def on_vte_focus_out(self, _widget, _event):
|
||||||
"""Inform other parts of the application when focus is lost"""
|
"""Inform other parts of the application when focus is lost"""
|
||||||
self.vte.set_colors(self.fgcolor_inactive, self.bgcolor,
|
self.vte.dim(True)
|
||||||
self.palette_inactive)
|
self.queue_draw()
|
||||||
self.set_cursor_color()
|
|
||||||
self.emit('focus-out')
|
self.emit('focus-out')
|
||||||
|
|
||||||
def on_window_focus_out(self):
|
def on_window_focus_out(self):
|
||||||
|
|
Loading…
Reference in New Issue