From 5f04be365f8c12a44af73e5bce237290f9634c32 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 7 Dec 2016 08:44:57 +0530 Subject: [PATCH] Make the tab bar colors configurable --- kitty/char_grid.py | 26 +++++++++++++------------- kitty/config.py | 3 +++ kitty/kitty.conf | 7 +++++++ kitty/tabs.py | 22 +++++++--------------- kitty/utils.py | 4 ++++ 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/kitty/char_grid.py b/kitty/char_grid.py index 31f7581dc..6f50c89bf 100644 --- a/kitty/char_grid.py +++ b/kitty/char_grid.py @@ -9,7 +9,7 @@ from threading import Lock from .config import build_ansi_color_table from .constants import get_boss, viewport_size, cell_size, ScreenGeometry, GLuint -from .utils import get_logical_dpi, to_color, set_primary_selection, open_url +from .utils import get_logical_dpi, to_color, set_primary_selection, open_url, color_as_int from .fast_data_types import ( glUniform2ui, glUniform4f, glUniform1i, glUniform2f, glDrawArraysInstanced, GL_TRIANGLE_FAN, glEnable, glDisable, GL_BLEND, glDrawArrays, ColorProfile, @@ -22,10 +22,6 @@ if DATA_CELL_SIZE % 3: raise ValueError('Incorrect data cell size, must be a multiple of 3') -def color_as_int(val): - return val[0] << 16 | val[1] << 8 | val[2] - - # cell shader {{{ cell_shader = ( @@ -216,6 +212,17 @@ def calculate_gl_geometry(window_geometry): return ScreenGeometry(xstart, ystart, window_geometry.xnum, window_geometry.ynum, dx, dy) +def render_cells(buffer_id, sg, cell_program, sprites): + sprites.bind_sprite_map(buffer_id) + ul = cell_program.uniform_location + glUniform2ui(ul('dimensions'), sg.xnum, sg.ynum) + glUniform4f(ul('steps'), sg.xstart, sg.ystart, sg.dx, sg.dy) + glUniform1i(ul('sprites'), sprites.sampler_num) + glUniform1i(ul('sprite_map'), sprites.buffer_sampler_num) + glUniform2f(ul('sprite_layout'), *(sprites.layout)) + glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, sg.xnum * sg.ynum) + + class CharGrid: url_pat = re.compile('(?:http|https|file|ftp)://\S+', re.IGNORECASE) @@ -430,14 +437,7 @@ class CharGrid: return sg def render_cells(self, sg, cell_program, sprites): - sprites.bind_sprite_map(self.buffer_id) - ul = cell_program.uniform_location - glUniform2ui(ul('dimensions'), sg.xnum, sg.ynum) - glUniform4f(ul('steps'), sg.xstart, sg.ystart, sg.dx, sg.dy) - glUniform1i(ul('sprites'), sprites.sampler_num) - glUniform1i(ul('sprite_map'), sprites.buffer_sampler_num) - glUniform2f(ul('sprite_layout'), *(sprites.layout)) - glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, sg.xnum * sg.ynum) + render_cells(self.buffer_id, sg, cell_program, sprites) def render_cursor(self, sg, cursor_program): cursor = self.current_cursor diff --git a/kitty/config.py b/kitty/config.py index c977b67d4..25f443fee 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -109,6 +109,9 @@ for name in 'foreground background cursor active_border_color inactive_border_co type_map[name] = lambda x: to_color(x, validate=True) for i in range(16): type_map['color%d' % i] = lambda x: to_color(x, validate=True) +for a in ('active', 'inactive'): + for b in ('foreground', 'background'): + type_map['%s_tab_%s' % (a, b)] = lambda x: to_color(x, validate=True) def parse_config(lines): diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 5542657dc..44eab444d 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -77,6 +77,13 @@ active_border_color #00ff00 # The color for the border of inactive windows inactive_border_color #cccccc +# Tab-bar colors +active_tab_foreground #000 +active_tab_background #eee +inactive_tab_foreground #000 +inactive_tab_background #aaa + + # The 16 terminal colors. There are 8 basic colors, each color has a dull and # bright version. diff --git a/kitty/tabs.py b/kitty/tabs.py index d34e67cb5..8526e5faf 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -9,13 +9,10 @@ from ctypes import addressof from .child import Child from .config import build_ansi_color_table from .constants import get_boss, appname, shell_path, cell_size, queue_action, viewport_size, WindowGeometry, GLuint -from .fast_data_types import ( - glfw_post_empty_event, Screen, DECAWM, DATA_CELL_SIZE, - ColorProfile, glUniform2ui, glUniform4f, glUniform1i, glUniform2f, - glDrawArraysInstanced, GL_TRIANGLE_FAN -) -from .char_grid import calculate_gl_geometry +from .fast_data_types import glfw_post_empty_event, Screen, DECAWM, DATA_CELL_SIZE, ColorProfile +from .char_grid import calculate_gl_geometry, render_cells from .layout import all_layouts +from .utils import color_as_int from .borders import Borders from .window import Window @@ -154,12 +151,15 @@ class TabManager: def __init__(self, opts, args, startup_session): self.opts, self.args = opts, args + self.buffer_id = None self.tabs = [Tab(opts, args, self.title_changed, t) for t in startup_session.tabs] self.active_tab_idx = startup_session.active_tab_idx self.tabbar_lock = Lock() self.tabbar_dirty = True self.color_profile = ColorProfile() self.color_profile.update_ansi_color_table(build_ansi_color_table(opts)) + self.default_fg = color_as_int(opts.inactive_tab_foreground) + self.default_bg = color_as_int(opts.inactive_tab_background) def resize(self): for tab in self.tabs: @@ -225,12 +225,4 @@ class TabManager: with self.tabbar_lock: if self.tabbar_dirty: self.update_tab_bar_data(sprites) - sprites.bind_sprite_map(self.buffer_id) - ul, sg = cell_program.uniform_location, self.screen_geometry - ul = cell_program.uniform_location - glUniform2ui(ul('dimensions'), sg.xnum, sg.ynum) - glUniform4f(ul('steps'), sg.xstart, sg.ystart, sg.dx, sg.dy) - glUniform1i(ul('sprites'), sprites.sampler_num) - glUniform1i(ul('sprite_map'), sprites.buffer_sampler_num) - glUniform2f(ul('sprite_layout'), *(sprites.layout)) - glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, sg.xnum * sg.ynum) + render_cells(self.buffer_id, self.screen_geometry, cell_program, sprites) diff --git a/kitty/utils.py b/kitty/utils.py index 1347d6bcb..7da8337f1 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -237,6 +237,10 @@ def to_color(raw, validate=False): return Color(int(val[:2], 16), int(val[2:4], 16), int(val[4:], 16)) +def color_as_int(val): + return val[0] << 16 | val[1] << 8 | val[2] + + def parse_color_set(raw): parts = raw.split(';') for c, spec in [parts[i:i + 2] for i in range(0, len(parts), 2)]: