Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt hooks keep making prompt stopped #3896

Open
ilhamfu opened this issue Feb 12, 2024 · 1 comment
Open

prompt hooks keep making prompt stopped #3896

ilhamfu opened this issue Feb 12, 2024 · 1 comment

Comments

@ilhamfu
Copy link

ilhamfu commented Feb 12, 2024

Output of awesome --version:

awesome v4.3-1647-ge6f5c7980-dirty (Too long)
• Compiled against Lua 5.4.6 (running with 0.9.2)
• API level: 4
• D-Bus support: yes
• xcb-errors support: no
• execinfo support: yes
• xcb-randr version: 1.6
• LGI version: /usr/share/lua/5.4/lgi/version.lua
• Transparency enabled: yes
• Custom search paths: no

How to reproduce the issue:
I want to make custom prompt widget. i try to make it to have multiple mode and can be switched when type certain prefixes like :b to search in browser for example, so i decided to use hooks, so whenever the user type space, it will check if the command start with :<prefix> it will change into selected mode. In doc, it says

An optional second return value controls if the prompt should exit or simply update the command (from the first return value) and keep going. The default is to execute the exe_callback and done_callback before exiting.

so i try below code, but for some reason every time i press space inside my prompt, the prompt immediately run the command instead of just replacing the command

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

local popup_instance = nil

local PROMPT_ICON = {
	RUNNER = "",
	BROWSER = "",
}

local function static_icon(theme)
	return wibox.widget({
		widget = wibox.container.background,

		shape = theme.default_shape,
		border_color = theme.primary_color,
		border_width = 2,
		{
			widget = wibox.container.background,
			bg = theme.primary_color,
			fg = theme.accent_color,

			{
				widget = wibox.container.margin,
				left = 8,
				right = 8,
				{ widget = wibox.widget.textbox, text = "", font = "bold 16 " },
			},
		},
	})
end

local function init_popup(theme)
	local prompt = wibox.widget({
		widget = wibox.widget.textbox,
	})

	local icon_widget = wibox.widget({ widget = wibox.widget.textbox, text = "", font = "bold 16 " })

	local widget = awful.popup({
		ontop = true,
		fg = "#ffffff",
		bg = "#00000000",
		placement = function(w)
			awful.placement.top_left(w, { offset = { x = 8, y = 8 } })
		end,
		shape = theme.default_shape,
		widget = {
			widget = wibox.widget.background,
			border_color = theme.primary_color,
			bg = theme.secondary_color,
			border_width = 2,
			forced_height = 24,
			{
				layout = wibox.layout.fixed.horizontal,
				{
					widget = wibox.container.background,
					bg = theme.primary_color,
					fg = theme.accent_color,

					{
						widget = wibox.container.margin,
						left = 8,
						right = 8,
						icon_widget,
					},
				},
				{ widget = wibox.container.margin, left = 4, right = 4, prompt },
			},
		},
	})

	function widget:run(scr)
		awful.prompt.run({
			prompt = "",
			textbox = prompt,
			font = "bold 10",
			exe_callback = function(cmd)
				require("naughty").notify({ text = cmd })
				return awful.spawn(cmd)
			end,
			completion_callback = function(...)
				return awful.completion.shell(...)
			end,
			hooks = {
				{
					{},
					" ",
					function(cmd)
						require("naughty").notify({ text = "hello world" })
						return cmd .. "foo", false
					end,
				},
			},

			done_callback = function()
				self.visible = false
			end,
		})
		icon_widget.text = PROMPT_ICON.RUNNER
		self.screen = scr
		self.visible = true
	end

	return widget
end

return function()
	local theme = beautiful.get()

	local widget = static_icon(theme)

	function widget:run()
		if not popup_instance then
			popup_instance = init_popup(theme)
		end

		popup_instance:run(awful.screen.focused())
	end

	return widget
end

Actual result:

When pressing space, the command get updated but the prompt immediately exit

Expected result:

When pressing space, the command should be updated and prompt kept running

@ilhamfu
Copy link
Author

ilhamfu commented Feb 19, 2024

i think i found the source of my problem

update()

i believed there is supposed to be a return statement after this line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant