Skip to content

Commit cb55bde

Browse files
committed
Remove click handling on kitty tab bar
1 parent e55f353 commit cb55bde

File tree

1 file changed

+5
-74
lines changed

1 file changed

+5
-74
lines changed

kitty/tab_bar.py

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,26 @@
22
import math
33
import socket
44
from pathlib import Path
5-
from time import monotonic
65
from typing import Any, Callable, Dict, List, Optional
76

87
from kittens.ssh.utils import get_connection_data
98
from paramiko import SSHConfig
109

1110
from kitty.boss import Boss
1211
from kitty.fast_data_types import (
13-
GLFW_MOUSE_BUTTON_LEFT,
14-
GLFW_MOUSE_BUTTON_MIDDLE,
15-
GLFW_PRESS,
16-
GLFW_RELEASE,
1712
Color,
1813
Screen,
19-
current_focused_os_window_id,
2014
get_boss,
2115
get_options,
22-
get_click_interval,
2316
)
2417
from kitty.tab_bar import (
2518
Dict,
2619
DrawData,
2720
ExtraData,
28-
TabBar,
2921
TabBarData,
3022
as_rgb,
3123
draw_title,
3224
)
33-
from kitty.tabs import TabMouseEvent
3425
from kitty.utils import color_as_int
3526
from kitty.window import Window
3627

@@ -235,64 +226,7 @@ def _get_system_info(active_window: Window) -> Dict[str, Any]:
235226

236227

237228
def _get_git_info() -> Dict[str, Any]:
238-
return {"branch": "main"}
239-
240-
241-
def _register_button(first_cell: int, last_cell: int, action: Callable) -> None:
242-
button = Button(first_cell, last_cell, action)
243-
buttons.append(button)
244-
245-
246-
def _button_at(tab_bar: TabBar, x: int) -> Optional[Button]:
247-
if tab_bar.laid_out_once:
248-
cell = (x - tab_bar.window_geometry.left) // tab_bar.cell_width
249-
for button in buttons:
250-
if button.first_cell <= cell <= button.last_cell:
251-
return button
252-
return None
253-
254-
255-
def _handle_click(self, x: int, button: int, modifiers: int, action: int) -> None:
256-
tab_idx = self.tab_bar.tab_at(x)
257-
now = monotonic()
258-
if tab_idx is None:
259-
if (
260-
button == GLFW_MOUSE_BUTTON_LEFT
261-
and action == GLFW_RELEASE
262-
and len(self.recent_mouse_events) > 2
263-
):
264-
ci = get_click_interval()
265-
prev, prev2 = self.recent_mouse_events[-1], self.recent_mouse_events[-2]
266-
if (
267-
prev.button == button
268-
and prev2.button == button
269-
and prev.action == GLFW_PRESS
270-
and prev2.action == GLFW_RELEASE
271-
and prev.tab_idx is None
272-
and prev2.tab_idx is None
273-
and now - prev.at <= ci
274-
and now - prev2.at <= 2 * ci
275-
): # double click
276-
self.new_tab()
277-
self.recent_mouse_events.clear()
278-
return
279-
else:
280-
if action == GLFW_PRESS and button == GLFW_MOUSE_BUTTON_LEFT:
281-
self.set_active_tab_idx(tab_idx)
282-
elif (
283-
button == GLFW_MOUSE_BUTTON_MIDDLE
284-
and action == GLFW_RELEASE
285-
and self.recent_mouse_events
286-
):
287-
p = self.recent_mouse_events[-1]
288-
if p.button == button and p.action == GLFW_PRESS and p.tab_idx == tab_idx:
289-
tab = self.tabs[tab_idx]
290-
get_boss().close_tab(tab)
291-
self.recent_mouse_events.append(
292-
TabMouseEvent(button, modifiers, action, now, tab_idx)
293-
)
294-
if len(self.recent_mouse_events) > 5:
295-
self.recent_mouse_events.popleft()
229+
return {"is_git_repo": True, "branch": "main"}
296230

297231

298232
def draw_tab(
@@ -368,12 +302,16 @@ def draw_tab(
368302
assert isinstance(active_window, Window)
369303

370304
is_running_pager = _is_running_pager(active_window)
305+
git_info = _get_git_info()
306+
is_git_repo, branch = git_info["is_git_repo"], git_info["branch"]
371307
sys_info = _get_system_info(active_window)
372308
user, host, is_ssh = sys_info["user"], sys_info["host"], sys_info["is_ssh"]
373309

374310
elements = list()
375311
if is_running_pager:
376312
elements.append({"title": "", "icon": PAGER_ICON, "accented": True})
313+
if is_git_repo:
314+
elements.append({"title": branch, "icon": BRANCH_ICON, "accented": False})
377315
elements.append({"title": user, "icon": USER_ICON, "accented": is_ssh})
378316
elements.append({"title": host, "icon": HOST_ICON, "accented": is_ssh})
379317

@@ -400,11 +338,4 @@ def draw_tab(
400338
soft_sep=PADDING if element is not elements[-1] else None,
401339
)
402340

403-
# Patch behavior of mouse click on tab bar
404-
os_window_id = current_focused_os_window_id()
405-
tm = boss.os_window_map.get(os_window_id)
406-
if tm is not None:
407-
tm.handle_click_on_tab = _handle_click.__get__(tm)
408-
tb = tm.tab_bar
409-
410341
return end

0 commit comments

Comments
 (0)