Skip to content

Commit 7dbf011

Browse files
committed
Get orientation from RGBA setting
1 parent 2cffdd6 commit 7dbf011

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

kitty/config_data.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ def box_drawing_scale(x):
295295
and very thick lines.
296296
'''))
297297

298+
o('subpixel_rendering', False, long_text=_('''
299+
Use subpixel rendering instead of grayscale in freetype. Impacts performance,
300+
but may look better on low DPI screens. Possible values are :code:`none`,
301+
:code:`lcd`, and :code:`lcd_v`.
302+
'''))
303+
298304
# }}}
299305

300306
g('cursor') # {{{
@@ -940,21 +946,6 @@ def macos_option_as_alt(x):
940946
light and dark backgrounds. WARNING: this might make your mouse cursor
941947
invisible on dual GPU machines.'''))
942948

943-
944-
def to_subpixel_options(x):
945-
x = x.lower()
946-
if x == 'lcd':
947-
return 1
948-
if x == 'lcd_v':
949-
return 2
950-
return 0
951-
952-
953-
o('subpixel_rendering', 'none', option_type=to_subpixel_options, long_text=_('''
954-
Use subpixel rendering instead of grayscale in freetype. Impacts performance,
955-
but may look better on low DPI screens. Possible values are :code:`none`,
956-
:code:`lcd`, and :code:`lcd_v`.
957-
'''))
958949
# }}}
959950

960951
g('shortcuts') # {{{

kitty/freetype.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,17 @@ populate_processed_bitmap(FT_GlyphSlotRec *slot, FT_Bitmap *bitmap, ProcessedBit
388388
static inline bool
389389
render_bitmap(Face *self, int glyph_id, ProcessedBitmap *ans, unsigned int cell_width, unsigned int cell_height, unsigned int num_cells, bool bold, bool italic, bool rescale, FONTS_DATA_HANDLE fg) {
390390
int flags = FT_LOAD_RENDER;
391-
switch (OPT(subpixel_rendering)) {
392-
case SUBPIXEL_LCD:
393-
flags |= FT_LOAD_TARGET_LCD;
394-
break;
395-
case SUBPIXEL_LCD_V:
396-
flags |= FT_LOAD_TARGET_LCD_V;
397-
break;
398-
case SUBPIXEL_NONE:
399-
default:
400-
break;
391+
if (OPT(subpixel_rendering)) {
392+
switch (self->rgba) {
393+
case FC_RGBA_RGB:
394+
case FC_RGBA_BGR:
395+
flags |= FT_LOAD_TARGET_LCD;
396+
break;
397+
case FC_RGBA_VRGB:
398+
case FC_RGBA_VBGR:
399+
flags |= FT_LOAD_TARGET_LCD_V;
400+
break;
401+
}
401402
}
402403
if (!load_glyph(self, glyph_id, flags)) return false;
403404
unsigned int max_width = cell_width * num_cells;
@@ -670,17 +671,21 @@ render_simple_text_impl(PyObject *s, const char *text, unsigned int baseline) {
670671
int error = FT_Load_Glyph(self->face, glyph_index, FT_LOAD_DEFAULT);
671672
if (error) continue;
672673
int flags = 0;
673-
switch (OPT(subpixel_rendering)) {
674-
case SUBPIXEL_LCD:
675-
flags |= FT_RENDER_MODE_LCD;
676-
break;
677-
case SUBPIXEL_LCD_V:
678-
flags |= FT_RENDER_MODE_LCD_V;
679-
break;
680-
case SUBPIXEL_NONE:
681-
default:
674+
if (OPT(subpixel_rendering)) {
675+
switch (self->rgba) {
676+
case FC_RGBA_RGB:
677+
case FC_RGBA_BGR:
678+
flags |= FT_RENDER_MODE_LCD;
679+
break;
680+
case FC_RGBA_VRGB:
681+
case FC_RGBA_VBGR:
682+
flags |= FT_RENDER_MODE_LCD_V;
683+
break;
684+
default:
685+
flags |= FT_RENDER_MODE_LCD;
686+
}
687+
} else {
682688
flags |= FT_RENDER_MODE_NORMAL;
683-
break;
684689
}
685690
error = FT_Render_Glyph(self->face->glyph, flags);
686691
if (error) continue;

kitty/glfw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
567567
// blank the window once so that there is no initial flash of color
568568
// changing, in case the background color is not black
569569
blank_canvas(is_semi_transparent ? OPT(background_opacity) : 1.0f);
570-
bool is_subpixel_enabled = (OPT(subpixel_rendering) == SUBPIXEL_LCD || OPT(subpixel_rendering) == SUBPIXEL_LCD_V);
571570
#ifndef __APPLE__
572571
if (is_first_window) glfwSwapInterval(OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0);
573572
#endif
@@ -580,7 +579,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
580579
glfwShowWindow(glfw_window);
581580
}
582581
if (is_first_window) {
583-
PyObject *ret = PyObject_CallFunction(load_programs, "OO", is_semi_transparent ? Py_True : Py_False, is_subpixel_enabled ? Py_True : Py_False);
582+
PyObject *ret = PyObject_CallFunction(load_programs, "OO", is_semi_transparent ? Py_True : Py_False, OPT(subpixel_rendering) ? Py_True : Py_False);
584583
if (ret == NULL) return NULL;
585584
Py_DECREF(ret);
586585
#ifdef __APPLE__

kitty/state.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ PYWRAP1(set_options) {
408408
S(macos_window_resizable, PyObject_IsTrue);
409409
S(macos_hide_from_tasks, PyObject_IsTrue);
410410
S(macos_thicken_font, PyFloat_AsDouble);
411-
S(subpixel_rendering, PyLong_AsLong);
411+
S(subpixel_rendering, PyObject_IsTrue);
412412
S(tab_bar_min_tabs, PyLong_AsUnsignedLong);
413413
S(disable_ligatures, PyLong_AsLong);
414414

kitty/state.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
typedef enum { LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, BOTTOM_EDGE } Edge;
1414

15-
typedef enum { SUBPIXEL_NONE, SUBPIXEL_LCD, SUBPIXEL_LCD_V } SubpixelRendering;
16-
1715
typedef struct {
1816
double visual_bell_duration, cursor_blink_interval, cursor_stop_blinking_after, mouse_hide_wait, click_interval, wheel_scroll_multiplier, touch_scroll_multiplier;
1917
bool enable_audio_bell;
@@ -27,7 +25,7 @@ typedef struct {
2725
double repaint_delay, input_delay;
2826
bool focus_follows_mouse, hide_window_decorations;
2927
bool macos_hide_from_tasks, macos_quit_when_last_window_closed, macos_window_resizable, macos_traditional_fullscreen, macos_show_window_title_in_menubar;
30-
SubpixelRendering subpixel_rendering;
28+
bool subpixel_rendering;
3129
unsigned int macos_option_as_alt;
3230
float macos_thicken_font;
3331
int adjust_line_height_px, adjust_column_width_px;

0 commit comments

Comments
 (0)