Anti-aliasing 在令人敬畏的 window 经理

Anti-aliasing in the awesome window manager

好吧,基本上,我们能以某种方式在很棒的 window 经理中获得 anti-aliasing 吗?

字体看起来很棒,一切都很棒,但如果将 anti-aliasing 应用到常规小部件中,那就太棒了。 Anti-aliased round-cornered 标题栏会很棒。其他形状也应用于 gears.shape.rounded_rectgears.shape.circle 等小部件。或所有其他四舍五入的人。

这可能吗?我搜索了 cairo 和抗锯齿,但我几乎找不到任何东西,甚至有人说在 cairo 中很难或根本不可能获得真正好的抗锯齿。

此外,我查看了 awesome-wm 存储库的旧副本,有时我在 draw.c 文件中找到了这个:

draw_rectangle_gradient(draw_context_t *ctx, area_t geometry, float line_width, bool filled,
                        vector_t gradient_vector, const color_t *pcolor,
                        const color_t *pcolor_center, const color_t *pcolor_end)
{
    cairo_pattern_t *pat;

    cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
    cairo_set_line_width(ctx->cr, line_width);
    cairo_set_miter_limit(ctx->cr, 10.0);
cairo_set_line_join(ctx->cr, CAIRO_LINE_JOIN_MITER);

现在在当前存储库中我找不到这样的东西,所以我的问题是 "can we users do something to make the rounded shapes in awesome be anti-aliased?"

编辑:如果没有简单的方法,您能否指导我进行哪些更改才能使这项工作正常进行?

Anti-aliased round-cornered titlebars would be amazing

Non-rectangular windows 在 X11 中使用 SHAPE 扩展完成。此扩展仅允许 "this pixel is in the window" 或 "this pixel is outside of the window"。因此,这里不可能有 anti-aliasing。 https://www.x.org/releases/X11R7.7/doc/xextproto/shape.html

但是,当您有合成管理器 运行 时,可以向 window 添加 alpha 通道。这允许事情成为例如50% 半透明。因此,有了这个,alpha 通道是可能的。

因此,在 AwesomeWM 中,您可以通过将边框宽度设置为零并在客户端的每一侧添加一个包含一些 "real transparency" 的标题栏来围绕客户端设置 outside-rounded 边框。 =20=]

一个廉价的例子,实际上没有做圆角,但显示透明度:

local my_widget = wibox.widget.base.make_widget()
local cairo = require("lgi").cairo
function my_widget:draw(_, cr, width, height)
    cr:set_operator(cairo.Operator.SOURCE)
    cr:set_source(gears.color.create_linear_pattern{
        from = { 0, 0 },
        to = { width, 0 },
        stops = {
            { 0, "#f000" },
            { 1, "#0f0f" },
        },
    })
    cr:paint()
end
awful.titlebar(c, { position = "bottom" }):set_widget(my_widget)

这样,就可以用 anti-aliased 的方式制作一个画圆角的标题栏。但是,这需要分多块做,因为我们需要分别创建每个标题栏。

另外,这个只能在外面做一个圆角。在内部(即针对实际客户端内容),AwesomeWM 仅提供对形状扩展的访问。但是,我们必须在实际客户端 window 上绘制一些东西才能有一个抗锯齿的圆角。这目前是不可能的。

(希望这段能看懂,总觉得有点难describe/understand。)

Also the other shapes applied to widgets like gears.shape.rounded_rect or gears.shape.circle.

嗯......我不确定你为什么认为这里没有抗锯齿。

local w = wibox{ x = 10, y = 10, height = 300, width = 300 }
w:setup {
    widget = wibox.container.background,
    bg = '#f00',
    {
        widget = wibox.container.background,
        shape = gears.shape.circle,
        bg = '#0f0',
    }
}
w.visible = true

放大生成的图像清楚地显示抗锯齿:

Or all of the others that have rounded anything.

这实际上不是特定于形状,而是特定于应用形状的东西。例如 wibox.container.background("draws directly",因此可以抗锯齿)与 awful.client.shape(使用 X11 形状扩展,因此不能抗锯齿)。