简体   繁体   English

在awesome-wm中自动生成小部件

[英]Auto-generating widgets in awesome-wm

So what I currently want to do is pretty much implement rofi in awesome. 所以我现在想要做的就是在很棒的情况下实现rofi。

The reason I want to do this and I don't just use rofi is because I want to learn how to 'auto-generate' widgets in awesome. 我想这样做的原因并不仅仅是使用rofi是因为我想学习如何“自动生成”小部件。 This will come in handy later when I'll implement things like network widgets that when clicked, shows you a panel, shows you the wifi hotspots available as rows, etc etc. So it's just for me to learn how awesome works better. 这将在以后我将实现像网络小部件这样的东西,当点击,向您显示一个面板,向您显示可用作行等的wifi热点等等时,这将会派上用场。所以这对我来说只是让我学会了如何更好地工作。 But also, I want a program launcher. 但是,我想要一个程序启动器。

And also, before someone suggests it, I already know that there's a built-in launcher in awesome, and I also know that there's this . 而且,在有人建议它之前,我已经知道有一个很棒的内置发射器,我也知道有这个 This is not what I'm looking for. 这不是我想要的。 I want to have the same thing thing rofi and dmenu have: I want to have suggestions pop up when you press keys. 我希望rofi和dmenu有同样的事情:我想按键时弹出建议。 and I want to be able to click on the suggestions, etc. What I want is something like this: uhhhh 我希望能够点击建议等。我想要的是这样的: 呃嗯

So what I'm having problems is this: how do I auto-generate the rows? 所以我遇到的问题是:如何自动生成行? I want to be able to specify in only one place how many rows I want, and have awesome do the rest. 我希望能够只在一个地方指定我想要多少行,并且还有其他功能。

I've looked through Elv's github and I found radical and even though what he made is a menu system, I thought that I could use some of his code to do what I want. 我查看了Elv的github并发现了radical ,即使他所做的是一个菜单系统,我认为我可以使用他的一些代码来做我想要的。 But I can't for the love of god figure out how it works. 但我不能因为上帝的爱而弄清楚它是如何运作的。 No offense to him, but it's not all too well docummented, even for users, and for actually explaining how the code works there's no docummentation. 对他来说没有任何冒犯,但即使对于用户来说,它也没有太好的文档,并且实际解释代码是如何工作的,没有任何文档。

So My question is: How can I make this work? 所以我的问题是:我怎样才能做到这一点? How would I go about making the widgets that act as the rows automatically? 我如何自动制作充当行的小部件?

TL;DR: TL; DR:

  • i want to write a program launcher like rofi in awesome 我想写一个像rofi这样的程序启动器
  • i want to be able to specify only in one place the number of rows 我希望能够在一个地方只指定行数
  • therefore, (((I think))) I need to automatically generate widgets as rows somehow, how can I do it? 因此,(((我认为)))我需要以某种方式自动生成小部件作为行,我该怎么办呢?

EDIT: 编辑:

What I want is to be able to create the rows of my launcher automatically. 我想要的是能够自动创建我的启动器的行。 I know I can hardcode the rows myself, have each row have a different id and then I can write a function that on each keypress, will update each widget with the most relevant matches. 我知道我可以自己对行进行硬编码,每行都有不同的ID然后我可以编写一个函数,在每个按键上,将使用最相关的匹配更新每个小部件。 So it would be something like (not tested at all): 所以它会像(根本没有测试过):


local wibox = require("wibox")
local awful = require("awful")

local num_rows = 10
local row_height = 40

-- set the height of the background in accordance to how many rows there are,
-- and how high each row should be
local prompt_height = row_height * num_rows
local prompt_width = 300

-- make a widget in the middle of the screen
local background = wibox({
    x = awful.screen.focused().geometry.width / 2 - prompt_width / 2,
    y = awful.screen.focused().geometry.height / 2 - prompt_height / 2,
    width = prompt_width,
    height = prompt_height,
    bg = "#111111",
    visible = false,
    ontop = false
})
local rofi_launcher = wibox.widget({
    widget = background,
    {
        -- get a flexible layout so the searchbox and the suggestion boxes get 
        -- scaled to take up all the space of the background
        layout = wibox.layout.flex.vertical,
        { -- the prompt you actually type in
            -- set id here so we can adjust its ratio later, so the magnifying
            -- glass will end up on the right, and the texbox will take up the left side
            id = "searchbox_and_mangifying_glass",
            layout = wibox.layout.ratio.horizontal,
            {
                -- set id so we can use it as a prompt later
                id = "searchbox",
                widget = wibox.widget.textbox,
            },
            {
                widget = wibox.widget.imagebox,
                icon = '~/path/to/magnifying_glass_icon.svg',

            },
        },
        { -- this is where I actually create the rows that will display suggestions
            { -- row number 1
                -- make a background for the textbox to sit in, so you can change 
                -- background color later for the selected widget, etc etc. 
                widget = wibox.widget.background,
                    {
                        -- give it an id so we can change what's displayed in the
                        -- textbox when we press keys in the prompt
                        id = "suggestion_1",
                        widget = wibox.widget.textbox,
                    },
            },
            { -- row number 2
                -- background, again
                widget = wibox.widget.background,
                    {
                        -- id and textbox again
                        id = "suggestion_2",
                        widget = wibox.widget.textbox,
                    },
            },
            -- and another 8 (according to the `num_rows` variable) of the same two 
            -- textboxes above. This is exactly my problem. How can I make these 
            -- textboxes automatically and still be able to interact with them to 
            -- display suggestions on the fly, as the user types keys into the prompt?

        },

    },
})

If this is not clear enough please do let me know what you don't understand and I will update my question. 如果这还不够清楚,请告诉我你不理解的内容,我会更新我的问题。

Equally untested as your code, but this creates a tables of textboxes instead of using the declarative layout to create all these textboxes: 同样未经测试的代码,但这会创建一个文本框表,而不是使用声明性布局来创建所有这些文本框:

[SNIP; For shorter code I removed some stuff at the beginning]

local textboxes = {}
local widgets = {}

for i = 1, num_rows do
    local tb = wibox.widget.textbox()
    local bg = wibox.widget.background(tb)
    bg:set_bg("#ff0000") -- The original code did not set a bg color, but that would make the bg widget useless...?

    tb.id = "suggestion_" .. tostring(i) -- This is likely unnecessary, but the original code set these IDs, too

    table.insert(textboxes, tb)
    table.insert(widgets, bg)
end

local rofi_launcher = wibox.widget({
    widget = background,
    {
        -- get a flexible layout so the searchbox and the suggestion boxes get 
        -- scaled to take up all the space of the background
        layout = wibox.layout.flex.vertical,
        { -- the prompt you actually type in
        [SNIP - I did not change anything here; I only removed this part to make the code shorter]
        },
        widgets
    },
})

-- Now make the textboxes display something
textboxes[3].text = "I am the third row"
textboxes[5].text = "I am not"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM