[GH-ISSUE #806] keep focus on the modal #589

Open
opened 2026-03-04 01:06:17 +03:00 by kerem · 5 comments
Owner

Originally created by @tcurdt on GitHub (Jan 31, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/806

When I have two pages, one for a modal

	pages := tview.NewPages()
	pages.AddPage("background", background, true, true)
	pages.AddPage("modal", modal(edit, 50, 20), true, true)

I can still switch focus with the mouse and access the controls that are in the background.
Is there an easy way to disable this?

I know I could use HidePage() before I open the modal but I would like to still have the background visible - just not accessible.

Originally created by @tcurdt on GitHub (Jan 31, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/806 When I have two pages, one for a modal ``` pages := tview.NewPages() pages.AddPage("background", background, true, true) pages.AddPage("modal", modal(edit, 50, 20), true, true) ``` I can still switch focus with the mouse and access the controls that are in the background. Is there an easy way to disable this? I know I could use `HidePage()` before I open the modal but I would like to still have the background visible - just not accessible.
Author
Owner

@tcurdt commented on GitHub (Jan 31, 2023):

I just found this dialog implementation that wraps the input/mouse handler. That's the only way I assume?

<!-- gh-comment-id:1409640580 --> @tcurdt commented on GitHub (Jan 31, 2023): I just found [this dialog implementation](https://github.com/navidys/tvxwidgets/blob/main/dialog.go#L153) that wraps the input/mouse handler. That's the only way I assume?
Author
Owner

@tcurdt commented on GitHub (Jan 31, 2023):

@tcurdt Read the document comments for the functions you are using. AddPage is ("name", primitive, resize, FOCUSED).... focus determines if input is received.

It's visible and not focused

https://github.com/rivo/tview/blob/master/pages.go#L64

func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Pages {

...and from the comments it sounds like SetFocus is called from the library. So 🤷‍♂️

<!-- gh-comment-id:1409658766 --> @tcurdt commented on GitHub (Jan 31, 2023): > @tcurdt Read the document comments for the functions you are using. AddPage is ("name", primitive, resize, FOCUSED).... focus determines if input is received. It's `visible` and not `focused` https://github.com/rivo/tview/blob/master/pages.go#L64 ``` func (p *Pages) AddPage(name string, item Primitive, resize, visible bool) *Pages { ``` ...and from the comments it sounds like `SetFocus` is called from the library. So 🤷‍♂️
Author
Owner

@tcurdt commented on GitHub (Feb 1, 2023):

setfocus can be called on the app instance to specify the focus..

But we are on the page level and the focus can also be set by the mouse.
So I don't get how how that is relevant.

I would recommend just browsing the demos and docs for the library as a lot of this stuff is explained. Also many issues already exist that you can search for examples.

Not my first rodeo and I only open issue when I have

  • read the docs
  • looked at the examples
  • searched the issues

If I have missed information I am sorry and would love a link pointing me into the right direction.

Look at the list of applications using tview. See how they are doing things.

Searching 10+ other projects in the hope they have implemented what I am looking for is not a particular great use of our collective time TBH. But I have already linked to an implementation further up and would just like to know if that's the intended way of doing things.

Check out tslocum/cview

I came across it before - not sure how I feel about the whole gitlab/self-hosted/mirrored storry.

tview is a great lib to use and build on. See example below... the base is tview but used creatively with additional primitives/focus/viewstackinig then the original...

Without a link to the code it's a nice encouragement - but otherwise not that helpful ;)
Maybe add that as another demo?

<!-- gh-comment-id:1412007388 --> @tcurdt commented on GitHub (Feb 1, 2023): > setfocus can be called on the app instance to specify the focus.. But we are on the page level and the focus can also be set by the mouse. So I don't get how how that is relevant. > I would recommend just browsing the demos and docs for the library as a lot of this stuff is explained. Also many issues already exist that you can search for examples. Not my first rodeo and I only open issue when I have - read the docs - looked at the examples - searched the issues If I have missed information I am sorry and would love a link pointing me into the right direction. > Look at the list of applications using tview. See how they are doing things. Searching 10+ other projects in the hope they have implemented what I am looking for is not a particular great use of our collective time TBH. But I have already linked to an implementation further up and would just like to know if that's the intended way of doing things. > Check out [tslocum/cview](https://github.com/tslocum/cview) I came across it before - not sure how I feel about the whole gitlab/self-hosted/mirrored storry. > tview is a great lib to use and build on. See example below... the base is tview but used creatively with additional primitives/focus/viewstackinig then the original... Without a link to the code it's a nice encouragement - but otherwise not that helpful ;) Maybe add that as another demo?
Author
Owner

@OsvaldoTCF commented on GitHub (May 9, 2024):

When I have two pages, one for a modal

	pages := tview.NewPages()
	pages.AddPage("background", background, true, true)
	pages.AddPage("modal", modal(edit, 50, 20), true, true)

I can still switch focus with the mouse and access the controls that are in the background. Is there an easy way to disable this?

I know I could use HidePage() before I open the modal but I would like to still have the background visible - just not accessible.

.
image
.

Perhaps the solution is to interfere with the flow of mouse events by accepting only events destined for the current primitive.

<!-- gh-comment-id:2103072748 --> @OsvaldoTCF commented on GitHub (May 9, 2024): > When I have two pages, one for a modal > > ``` > pages := tview.NewPages() > pages.AddPage("background", background, true, true) > pages.AddPage("modal", modal(edit, 50, 20), true, true) > ``` > > I can still switch focus with the mouse and access the controls that are in the background. Is there an easy way to disable this? > > I know I could use `HidePage()` before I open the modal but I would like to still have the background visible - just not accessible. . ![image](https://github.com/rivo/tview/assets/5272869/a1936362-d9be-4568-841a-bec832ec20bd) . Perhaps the solution is to interfere with the flow of mouse events by accepting only events destined for the current primitive.
Author
Owner

@OsvaldoTCF commented on GitHub (May 9, 2024):

This way worked for a small example.
The ideal would be to get the "primitive" on which the "click" is being made.

//
if err := tview.NewApplication().SetRoot(pages, true).
SetMouseCapture(mcap).EnableMouse(true).Run(); err != nil {
panic(err)

func mcap(event *tcell.EventMouse, action tview.MouseAction) (*tcell.EventMouse, tview.MouseAction) {
if action == 0 {
return event, action
}

x, y := event.Position()
if (x > 30 && x < 60) && (y > 10 && y < 20) {
	return event, action

}

return nil, action

}

<!-- gh-comment-id:2103182142 --> @OsvaldoTCF commented on GitHub (May 9, 2024): This way worked for a small example. The ideal would be to get the "primitive" on which the "click" is being made. // if err := tview.NewApplication().SetRoot(pages, true). SetMouseCapture(mcap).EnableMouse(true).Run(); err != nil { panic(err) func mcap(event *tcell.EventMouse, action tview.MouseAction) (*tcell.EventMouse, tview.MouseAction) { if action == 0 { return event, action } x, y := event.Position() if (x > 30 && x < 60) && (y > 10 && y < 20) { return event, action } return nil, action }
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#589
No description provided.