more typing work

This commit is contained in:
Kovid Goyal
2020-03-13 16:13:26 +05:30
parent 9f2fb76309
commit 917559f883
14 changed files with 693 additions and 488 deletions

View File

@@ -3,11 +3,14 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from itertools import chain
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from .constants import WindowGeometry
from .fast_data_types import (
BORDERS_PROGRAM, add_borders_rect, compile_program, init_borders_program,
os_window_has_background_image
)
from .options_stub import Options
from .utils import load_shaders
try:
@@ -16,20 +19,26 @@ except ImportError:
from enum import IntEnum as IntFlag # type: ignore
if TYPE_CHECKING:
from .window import Window
from .layout import Layout
Window, Layout
class BorderColor(IntFlag):
# See the border vertex shader for how these flags become actual colors
default_bg, active, inactive, window_bg, bell = ((1 << i) for i in range(5))
def vertical_edge(os_window_id, tab_id, color, width, top, bottom, left):
def vertical_edge(os_window_id: int, tab_id: int, color: int, width: int, top: int, bottom: int, left: int) -> None:
add_borders_rect(os_window_id, tab_id, left, top, left + width, bottom, color)
def horizontal_edge(os_window_id, tab_id, color, height, left, right, top):
def horizontal_edge(os_window_id: int, tab_id: int, color: int, height: int, left: int, right: int, top: int) -> None:
add_borders_rect(os_window_id, tab_id, left, top, right, top + height, color)
def draw_edges(os_window_id, tab_id, colors, width, geometry, base_width=0):
def draw_edges(os_window_id: int, tab_id: int, colors: Sequence[int], width: int, geometry: 'WindowGeometry', base_width: int = 0) -> None:
left = geometry.left - (width + base_width)
top = geometry.top - (width + base_width)
right = geometry.right + (width + base_width)
@@ -40,28 +49,28 @@ def draw_edges(os_window_id, tab_id, colors, width, geometry, base_width=0):
vertical_edge(os_window_id, tab_id, colors[2], width, top, bottom, geometry.right + base_width)
def load_borders_program():
def load_borders_program() -> None:
compile_program(BORDERS_PROGRAM, *load_shaders('border'))
init_borders_program()
class Borders:
def __init__(self, os_window_id, tab_id, opts):
def __init__(self, os_window_id: int, tab_id: int, opts: Options):
self.os_window_id = os_window_id
self.tab_id = tab_id
self.draw_active_borders = opts.active_border_color is not None
def __call__(
self,
windows,
active_window,
current_layout,
extra_blank_rects,
padding_width,
border_width,
draw_window_borders=True,
):
windows: Sequence['Window'],
active_window: Optional['Window'],
current_layout: 'Layout',
extra_blank_rects: Sequence[Tuple[int, int, int, int]],
padding_width: int,
border_width: int,
draw_window_borders: bool = True,
) -> None:
add_borders_rect(self.os_window_id, self.tab_id, 0, 0, 0, 0, BorderColor.default_bg)
has_background_image = os_window_has_background_image(self.os_window_id)
if not has_background_image: