Change the naming of directions in option background_image_anchor for consistency

Replaced cardinal directions with "relative" directions.
This commit is contained in:
itepechi 2021-10-27 04:58:08 +09:00
parent 86d7aaa03a
commit 87d79c7415
7 changed files with 27 additions and 34 deletions

View File

@ -65,7 +65,7 @@ typedef enum MouseTrackingProtocols { NORMAL_PROTOCOL, UTF8_PROTOCOL, SGR_PROTOC
typedef enum MouseShapes { BEAM, HAND, ARROW } MouseShape;
typedef enum { NONE, MENUBAR, WINDOW, ALL } WindowTitleIn;
typedef enum { TILING, SCALED, MIRRORED, CLAMPED } BackgroundImageLayout;
typedef enum { NORTHWEST, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, CENTER } BackgroundImageAnchor;
typedef enum { TOP_LEFT, TOP, TOP_RIGHT, LEFT, CENTER, RIGHT, BOTTOM_LEFT, BOTTOM, BOTTOM_RIGHT } BackgroundImageAnchor;
#define MAX_CHILDREN 512
#define BLANK_CHAR 0

View File

@ -1110,8 +1110,8 @@ opt('background_image_layout', 'tiled',
long_text='Whether to tile, scale or clamp the background image.'
)
opt('background_image_anchor', 'northwest',
choices=('northwest', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'center'), ctype='bganchor',
opt('background_image_anchor', 'top-left',
choices=('top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right'), ctype='bganchor',
long_text='Where to position the background image in the window.'
)

View File

@ -63,7 +63,7 @@ class Parser:
raise ValueError(f"The value {val} is not a valid choice for background_image_anchor")
ans["background_image_anchor"] = val
choices_for_background_image_anchor = frozenset(('northwest', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'center'))
choices_for_background_image_anchor = frozenset(('top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right'))
def background_image_layout(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
val = val.lower()

View File

@ -81,31 +81,24 @@ bglayout(PyObject *layout_name) {
static BackgroundImageAnchor
bganchor(PyObject *anchor_name) {
const char *name = PyUnicode_AsUTF8(anchor_name);
if (strcmp(name, "north") == 0) {
return NORTH;
}
else if (strcmp(name, "northeast") == 0) {
return NORTHEAST;
}
else if (strcmp(name, "east") == 0) {
return EAST;
}
else if (strcmp(name, "southeast") == 0) {
return SOUTHEAST;
}
else if (strcmp(name, "south") == 0) {
return SOUTH;
}
else if (strcmp(name, "southwest") == 0) {
return SOUTHWEST;
}
else if (strcmp(name, "west") == 0) {
return WEST;
}
else if (strcmp(name, "center") == 0) {
if (strcmp(name, "top") == 0) {
return TOP;
} else if (strcmp(name, "top-right") == 0) {
return TOP_RIGHT;
} else if (strcmp(name, "left") == 0) {
return LEFT;
} else if (strcmp(name, "center") == 0) {
return CENTER;
} else if (strcmp(name, "right") == 0) {
return RIGHT;
} else if (strcmp(name, "bottom-left") == 0) {
return BOTTOM_LEFT;
} else if (strcmp(name, "bottom") == 0) {
return BOTTOM;
} else if (strcmp(name, "bottom-right") == 0) {
return BOTTOM_RIGHT;
}
return NORTHWEST;
return TOP_LEFT;
}
#define STR_SETTER(name) { \

View File

@ -14,7 +14,7 @@ from kitty.types import FloatEdges, SingleKey
import kitty.types
if typing.TYPE_CHECKING:
choices_for_background_image_anchor = typing.Literal['northwest', 'north', 'northeast', 'east', 'southeast', 'south', 'southwest', 'west', 'center']
choices_for_background_image_anchor = typing.Literal['top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right']
choices_for_background_image_layout = typing.Literal['mirror-tiled', 'scaled', 'tiled', 'clamped']
choices_for_default_pointer_shape = typing.Literal['arrow', 'beam', 'hand']
choices_for_linux_display_server = typing.Literal['auto', 'wayland', 'x11']
@ -456,7 +456,7 @@ class Options:
allow_remote_control: str = 'n'
background: Color = Color(0, 0, 0)
background_image: typing.Optional[str] = None
background_image_anchor: choices_for_background_image_anchor = 'northwest'
background_image_anchor: choices_for_background_image_anchor = 'top-left'
background_image_layout: choices_for_background_image_layout = 'tiled'
background_image_linear: bool = False
background_opacity: float = 1.0

View File

@ -55,7 +55,7 @@ How the image should be displayed. The value of configured will use the configur
--anchor
type=choices
choices=northwest,north,northeast,east,southeast,south,southwest,west,northwest,north,center,configured
choices=top-left,top,top-right,left,center,right,bottom-left,bottom,bottom-right,configured
Where the image should be positioned. The value of configured will use the configured value.

View File

@ -418,14 +418,14 @@ draw_bg(OSWindow *w) {
}
float translate_left = 0.0f, translate_top = 0.0f;
if (unscaled) {
if (OPT(background_image_anchor) == NORTH || OPT(background_image_anchor) == CENTER || OPT(background_image_anchor) == SOUTH) {
if (OPT(background_image_anchor) == TOP || OPT(background_image_anchor) == CENTER || OPT(background_image_anchor) == BOTTOM) {
translate_left = ((float)w->window_width / 2.0f - (float)w->bgimage->width / 2.0f) / (float)w->bgimage->width;
} else if (OPT(background_image_anchor) == NORTHEAST || OPT(background_image_anchor) == EAST || OPT(background_image_anchor) == SOUTHEAST) {
} else if (OPT(background_image_anchor) == TOP_RIGHT || OPT(background_image_anchor) == RIGHT || OPT(background_image_anchor) == BOTTOM_RIGHT) {
translate_left = ((float)w->window_width - (float)w->bgimage->width) / (float)w->bgimage->width;
}
if (OPT(background_image_anchor) == WEST || OPT(background_image_anchor) == CENTER || OPT(background_image_anchor) == EAST) {
if (OPT(background_image_anchor) == LEFT || OPT(background_image_anchor) == CENTER || OPT(background_image_anchor) == RIGHT) {
translate_top = ((float)w->window_height / 2.0f - (float)w->bgimage->height / 2.0f) / (float)w->bgimage->height;
} else if (OPT(background_image_anchor) == SOUTHWEST || OPT(background_image_anchor) == SOUTH || OPT(background_image_anchor) == SOUTHEAST) {
} else if (OPT(background_image_anchor) == BOTTOM_LEFT || OPT(background_image_anchor) == BOTTOM || OPT(background_image_anchor) == BOTTOM_RIGHT) {
translate_top = ((float)w->window_height - (float)w->bgimage->height) / (float)w->bgimage->height;
}
}