BurntSushi / wingo

A fully-featured window manager written in Go.
Do What The F*ck You Want To Public License
1k stars 90 forks source link

Text in title bars should be centered vertically #48

Closed cshapeshifter closed 11 years ago

cshapeshifter commented 11 years ago

As seen on the screenshots, the window titles are not centered in the title bars, unless the window is not maximized and the font size fits the title bar size perfectly (i.e. font size=14 in this case). In all other cases, the text sits too high. It's also impossible to have the title fit properly for both maximized and regular windows, mostly because in maximized windows, the text really sits on the edge of the title bar.

It would be best if the text would simply be centered vertically no matter what size the text has.

$THIN_COLOR := 0x585a5d
$DARK_BLUE := 0x02608c

[Full]
font := /usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf
font_size := 12
a_font_color := 0xffffff
i_font_color := 0xffffff

title_size := 16
title_top_margin := 2
a_title_color := $DARK_BLUE $DARK_BLUE
i_title_color := $THIN_COLOR $THIN_COLOR

border_size := 2
a_border_color := $DARK_BLUE
i_border_color := $THIN_COLOR

$ACTIVE_BUTTON := 0xffffff
$INACTIVE_BUTTON := 0xffffff

close := ./data/close.png
a_close_color := $ACTIVE_BUTTON
i_close_color := $INACTIVE_BUTTON

maximize := ./data/maximize.png
a_maximize_color := $ACTIVE_BUTTON
i_maximize_color := $INACTIVE_BUTTON

minimize := ./data/minimize.png
a_minimize_color := $ACTIVE_BUTTON
i_minimize_color := $INACTIVE_BUTTON

[Borders]
border_size := 2
a_thin_color := $THIN_COLOR
i_thin_color := $THIN_COLOR
a_border_color := 0xff7f00
i_border_color := 0xdfdcdf

[Slim]
border_size := 1
a_border_color := 0x000000
i_border_color := 0x000000

[Prompt]
bg_color := 0x8e8e8e
border_color := 0x585a5d
border_size := 8
padding := 15
font := /usr/share/fonts/TTF/DejaVuSansMono.ttf
font_size := 17
font_color := 0xffffff
select_active_color := 0x4c4c4c
select_active_bg_color := 0xffffff
select_group_bg_color := 0x8e8e8e
select_group_font := /usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf
select_group_font_size := 25
select_group_font_color := 0xffffff
cycle_icon_size := 128
cycle_icon_border_size := 8

cycle_icon_transparency := 30

[Misc]
default_icon := ./data/wingo.png

2012-12-14-122710_798x337_scrot 2012-12-14-123757_574x209_scrot 2012-12-14-124437_442x182_scrot

BurntSushi commented 11 years ago

The problem here is that the font library I'm using doesn't report the bounding box of text correctly. For instance, using your theme, the title bar size is 16 pixels and the height of the font rendered is also 16 pixels, even though we can clearly see that it is less than that. These extra pixels are a result of a fixed amount of padding added to the text extents to derive the bounding box.

This is a known bug. I think I could patch freetype to report the appropriate info, but I don't have the time at the moment.

Someone else had a similar problem as you, and I added an extra theme option that may or may not help in your case: title_top_margin. Of course, if the alignment looks OK in regular windows but not maximized windows, this option probably won't help since it always applies.

I'll leave this open until freetype-go reports proper font metrics. Updating Wingo to use them will be easy.

BurntSushi commented 11 years ago

I've submitted a patch to freetype-go. I'll give them a little time to see if it's accepted upstream, otherwise I'll fork freetype-go and adapt xgbutil/wingo to use that until functionality is added upstream.

BurntSushi commented 11 years ago

In light of the fix, I've removed the title_top_margin option. A warning will be logged if it is used.

cshapeshifter commented 11 years ago

Thanks, it's looking pretty good. I only notice one very minor problem with the OSD when changing workspaces (I have them numbered 1 to 8): The height of the small box containing the number changes height depending on the number. With 3, 5, 6 and 8 it's 1px taller. I don't think this needs fixing but I guess this is one implication to keep in mind, that the height of the bounding box is not the same for a given font size, but depends on the content of the string, i.e. if the text contains ascending or descending glyphs, it will be larger (e.g. the h vs. the S below). I did some research but I couldn't actually find guidelines on how to center lines of text vertically, i.e. which line to use as a center. Maybe the mean between baseline and median...

Typography_Line_Terms svg

BurntSushi commented 11 years ago

I see. You're probably right that it still isn't quite right. However, I do consider the issue of centering text solved for now.

We may want to revisit font rendering if Wingo gets more sophisticated with text rendering, but I suspect that it won't.