Cleanup previous PR

This commit is contained in:
Kovid Goyal 2026-02-22 06:31:13 +05:30
parent 15644d1eed
commit 60ee969028
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 25 additions and 19 deletions

View file

@ -1818,7 +1818,7 @@ def start_drag_with_data(
operations: int = GLFW_DRAG_OPERATION_MOVE
) -> None: ...
def draw_drag_icon_title(os_window_id: int, text: str, fg: int, bg: int, width: int) -> bytes: ...
def draw_single_line_of_text(os_window_id: int, text: str, fg: int, bg: int, width: int, padding_y: int = 2) -> bytes: ...
def set_tab_being_dragged(tab_id: int = 0, drag_started: bool = False, x: float = 0, y: float = 0) -> None: ...
def get_tab_being_dragged() -> tuple[int, bool, float, float]: ...
def request_callback_with_thumbnail(

View file

@ -2760,25 +2760,27 @@ grab_keyboard(PyObject *self UNUSED, PyObject *action) {
}
static PyObject*
draw_drag_icon_title(PyObject *self UNUSED, PyObject *args) {
draw_single_line_of_text(PyObject *self UNUSED, PyObject *args) {
unsigned long long os_window_id;
const char *text;
unsigned int fg, bg;
int width;
if (!PyArg_ParseTuple(args, "KsIIi", &os_window_id, &text, &fg, &bg, &width)) return NULL;
int width, padding_y = 2;
if (!PyArg_ParseTuple(args, "KsIIi|i", &os_window_id, &text, &fg, &bg, &width, &padding_y)) return NULL;
OSWindow *w = os_window_for_id(os_window_id);
if (!w || !w->fonts_data) { PyErr_SetString(PyExc_KeyError, "OS Window with specified id does not exist or has no fonts data"); return NULL; }
double font_sz_pts = w->fonts_data->font_sz_in_pts;
double ydpi = w->fonts_data->logical_dpi_y;
size_t height = (size_t)w->fonts_data->fcm.cell_height + 2; // extra 2px for visual padding
size_t buf_sz = (size_t)width * height * 4;
RAII_ALLOC(uint8_t, buf, calloc(buf_sz, 1));
if (!buf) return PyErr_NoMemory();
if (!draw_window_title(font_sz_pts, ydpi, text, fg, bg, buf, width, height)) {
if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError, "Failed to render drag icon title");
if (!w || !w->fonts_data) {
PyErr_SetString(PyExc_KeyError, "OS Window with specified id does not exist or has no fonts data");
return NULL;
}
return PyBytes_FromStringAndSize((char*)buf, buf_sz);
double font_sz_pts = w->fonts_data->font_sz_in_pts;
double ydpi = w->fonts_data->logical_dpi_y;
size_t height = (size_t)w->fonts_data->fcm.cell_height + padding_y;
size_t buf_sz = (size_t)width * height * 4;
RAII_PyObject(ans, PyBytes_FromStringAndSize(NULL, buf_sz)); if (!ans) return NULL;
if (!draw_window_title(font_sz_pts, ydpi, text, fg, bg, (uint8_t*)PyBytes_AS_STRING(ans), width, height)) {
if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError, "Failed to render text");
return NULL;
}
return Py_NewRef(ans);
}
static PyObject*
@ -2825,7 +2827,7 @@ static PyMethodDef module_methods[] = {
METHODB(pointer_name_to_css_name, METH_O),
{"create_os_window", (PyCFunction)(void (*) (void))(create_os_window), METH_VARARGS | METH_KEYWORDS, NULL},
{"start_drag_with_data", (PyCFunction)(void (*) (void))(start_drag_with_data), METH_VARARGS | METH_KEYWORDS, NULL},
METHODB(draw_drag_icon_title, METH_VARARGS),
METHODB(draw_single_line_of_text, METH_VARARGS),
METHODB(set_default_window_icon, METH_VARARGS),
METHODB(set_os_window_icon, METH_VARARGS),
METHODB(set_clipboard_data_types, METH_VARARGS),

View file

@ -28,7 +28,7 @@
buffer_keys_in_window,
current_focused_os_window_id,
detach_window,
draw_drag_icon_title,
draw_single_line_of_text,
get_boss,
get_click_interval,
get_options,
@ -1642,9 +1642,13 @@ def start_tab_drag(self, pixels: bytes, width: int, height: int) -> None:
title = replace_c0_codes_except_nl_space_tab(title.encode()).decode()
title = re.sub(r'\n', ' ', title)
opts = get_options()
fg = 0xff000000 | color_as_int(opts.active_tab_foreground)
bg = 0xff000000 | color_as_int(opts.active_tab_background)
title_pixels = draw_drag_icon_title(self.os_window_id, title, fg, bg, width)
if td.is_active:
fg = color_as_int(opts.active_tab_foreground)
bg = color_as_int(opts.active_tab_background)
else:
fg = color_as_int(opts.inactive_tab_foreground)
bg = color_as_int(opts.inactive_tab_background)
title_pixels = draw_single_line_of_text(self.os_window_id, title, 0xff000000 | fg, 0xff000000 | bg, width)
title_height = len(title_pixels) // (width * 4)
drag_data = {
f'application/net.kovidgoyal.kitty-tab-{os.getpid()}': str(tab.id).encode(),