Menu windows actually work properly now

This commit is contained in:
Sasha Koshka 2023-04-10 18:07:49 -04:00
parent 2987331a31
commit d67aac3d4f
3 changed files with 30 additions and 3 deletions

View File

@ -198,11 +198,13 @@ func (window *window) handleButtonPress (
insideWindow := image.Pt ( insideWindow := image.Pt (
int(buttonEvent.EventX), int(buttonEvent.EventX),
int(buttonEvent.EventY)).In(window.metrics.bounds) int(buttonEvent.EventY)).In(window.canvas.Bounds())
scrolling := buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7
if !insideWindow && window.shy { if !insideWindow && window.shy && !scrolling {
window.Close() window.Close()
} else if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { } else if scrolling {
if child, ok := window.child.(tomo.ScrollTarget); ok { if child, ok := window.child.(tomo.ScrollTarget); ok {
sum := scrollSum { } sum := scrollSum { }
sum.add(buttonEvent.Detail, window, buttonEvent.State) sum.add(buttonEvent.Detail, window, buttonEvent.State)

View File

@ -8,6 +8,8 @@ import "github.com/jezek/xgbutil/icccm"
import "github.com/jezek/xgbutil/xprop" import "github.com/jezek/xgbutil/xprop"
import "github.com/jezek/xgbutil/xevent" import "github.com/jezek/xgbutil/xevent"
import "github.com/jezek/xgbutil/xwindow" import "github.com/jezek/xgbutil/xwindow"
import "github.com/jezek/xgbutil/keybind"
import "github.com/jezek/xgbutil/mousebind"
import "github.com/jezek/xgbutil/xgraphics" import "github.com/jezek/xgbutil/xgraphics"
import "git.tebibyte.media/sashakoshka/tomo" import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/data" import "git.tebibyte.media/sashakoshka/tomo/data"
@ -283,6 +285,7 @@ func (window *window) NewModal (bounds image.Rectangle) (tomo.Window, error) {
func (window *window) NewMenu (bounds image.Rectangle) (tomo.MenuWindow, error) { func (window *window) NewMenu (bounds image.Rectangle) (tomo.MenuWindow, error) {
menu, err := window.backend.newWindow ( menu, err := window.backend.newWindow (
bounds.Add(window.metrics.bounds.Min), true) bounds.Add(window.metrics.bounds.Min), true)
menu.shy = true
icccm.WmTransientForSet ( icccm.WmTransientForSet (
window.backend.connection, window.backend.connection,
menu.xWindow.Id, menu.xWindow.Id,
@ -311,6 +314,21 @@ func (window menuWindow) Pin () {
// TODO take off override redirect // TODO take off override redirect
// TODO turn off shy // TODO turn off shy
// TODO set window type to MENU // TODO set window type to MENU
// TODO iungrab keyboard and mouse
}
func (window *window) grabInput () {
keybind.GrabKeyboard(window.backend.connection, window.xWindow.Id)
mousebind.GrabPointer (
window.backend.connection,
window.xWindow.Id,
window.backend.connection.RootWin(), 0)
window.xWindow.Focus()
}
func (window *window) ungrabInput () {
keybind.UngrabKeyboard(window.backend.connection)
mousebind.UngrabPointer(window.backend.connection)
} }
func (window *window) inheritProperties (parent *window) { func (window *window) inheritProperties (parent *window) {
@ -347,10 +365,12 @@ func (window *window) Show () {
} }
window.xWindow.Map() window.xWindow.Map()
if window.shy { window.grabInput() }
} }
func (window *window) Hide () { func (window *window) Hide () {
window.xWindow.Unmap() window.xWindow.Unmap()
if window.shy { window.ungrabInput() }
} }
func (window *window) Copy (data data.Data) { func (window *window) Copy (data data.Data) {

View File

@ -5,6 +5,8 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "github.com/jezek/xgbutil" import "github.com/jezek/xgbutil"
import "github.com/jezek/xgb/xproto" import "github.com/jezek/xgb/xproto"
import "github.com/jezek/xgbutil/xevent" import "github.com/jezek/xgbutil/xevent"
import "github.com/jezek/xgbutil/keybind"
import "github.com/jezek/xgbutil/mousebind"
// Backend is an instance of an X backend. // Backend is an instance of an X backend.
type Backend struct { type Backend struct {
@ -45,6 +47,9 @@ func NewBackend () (output tomo.Backend, err error) {
if err != nil { return } if err != nil { return }
backend.initializeKeymapInformation() backend.initializeKeymapInformation()
keybind.Initialize(backend.connection)
mousebind.Initialize(backend.connection)
output = backend output = backend
return return
} }