Compare commits
No commits in common. "b58932f02bcad5979516344de20c1bf4db3b2b10" and "55215dedc267c0c030a055fb5b8e679f4111b8ec" have entirely different histories.
b58932f02b
...
55215dedc2
20
x/event.go
20
x/event.go
@ -7,7 +7,6 @@ import "github.com/jezek/xgb/xproto"
|
||||
import "git.tebibyte.media/tomo/xgbkb"
|
||||
import "github.com/jezek/xgbutil/xevent"
|
||||
import "git.tebibyte.media/tomo/tomo/input"
|
||||
import "git.tebibyte.media/tomo/tomo/config"
|
||||
|
||||
type scrollSum struct {
|
||||
x, y int
|
||||
@ -227,7 +226,7 @@ func (window *window) handleKeyPress (
|
||||
key, numberPad := keycodeToKey(keyEvent.Detail, keyEvent.State)
|
||||
window.updateModifiers(keyEvent.State)
|
||||
|
||||
if config.KeyChordClose.Pressed(key, window.Modifiers()) && window.shy {
|
||||
if key == input.KeyEscape && window.shy {
|
||||
window.Close()
|
||||
} else {
|
||||
window.hierarchy.HandleKeyDown(key, numberPad)
|
||||
@ -434,15 +433,14 @@ func (window *window) compressMotionNotify (
|
||||
|
||||
func (window *window) updateModifiers (state uint16) {
|
||||
xModifiers := xgbkb.StateToModifiers(state)
|
||||
var modifiers input.Modifiers
|
||||
if xModifiers.Shift { modifiers |= input.ModShift }
|
||||
if xModifiers.ShiftLock { modifiers |= input.ModShift }
|
||||
if xModifiers.Control { modifiers |= input.ModControl }
|
||||
if xModifiers.Alt { modifiers |= input.ModAlt }
|
||||
if xModifiers.Meta { modifiers |= input.ModMeta }
|
||||
if xModifiers.Super { modifiers |= input.ModSuper }
|
||||
if xModifiers.Hyper { modifiers |= input.ModHyper }
|
||||
window.hierarchy.HandleModifiers(modifiers)
|
||||
window.hierarchy.HandleModifiers(input.Modifiers {
|
||||
Shift: xModifiers.Shift || xModifiers.ShiftLock,
|
||||
Control: xModifiers.Control,
|
||||
Alt: xModifiers.Alt,
|
||||
Meta: xModifiers.Meta,
|
||||
Super: xModifiers.Super,
|
||||
Hyper: xModifiers.Hyper,
|
||||
})
|
||||
}
|
||||
|
||||
func (window *window) updateMousePosition (x, y int16) {
|
||||
|
121
x/window.go
121
x/window.go
@ -1,7 +1,6 @@
|
||||
package x
|
||||
|
||||
import "image"
|
||||
import "strings"
|
||||
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
@ -42,10 +41,7 @@ type window struct {
|
||||
innerBounds image.Rectangle // bounds of the drawable area
|
||||
}
|
||||
|
||||
on struct {
|
||||
close event.FuncBroadcaster
|
||||
tryClose event.Broadcaster[func () bool]
|
||||
}
|
||||
onClose event.FuncBroadcaster
|
||||
}
|
||||
|
||||
type windowLink struct {
|
||||
@ -68,12 +64,27 @@ func (this *windowLink) NotifyMinimumSizeChange () {
|
||||
this.window.doMinimumSize()
|
||||
}
|
||||
|
||||
func (this *Backend) NewWindow (kind tomo.WindowKind, bounds image.Rectangle) (tomo.Window, error) {
|
||||
func (this *Backend) NewWindow (
|
||||
bounds image.Rectangle,
|
||||
) (
|
||||
output tomo.Window,
|
||||
err error,
|
||||
) {
|
||||
this.assert()
|
||||
return this.newWindow(bounds, false)
|
||||
}
|
||||
|
||||
func (this *Backend) NewPlainWindow (
|
||||
bounds image.Rectangle,
|
||||
) (
|
||||
output tomo.Window,
|
||||
err error,
|
||||
) {
|
||||
this.assert()
|
||||
window, err := this.newWindow(bounds, false)
|
||||
if err != nil { return nil, err }
|
||||
window.setKind(kind)
|
||||
return window, nil
|
||||
window.setType("dock")
|
||||
|
||||
return window, err
|
||||
}
|
||||
|
||||
func (this *Backend) newWindow (
|
||||
@ -120,11 +131,7 @@ func (this *Backend) newWindow (
|
||||
if err != nil { return }
|
||||
|
||||
window.xWindow.WMGracefulClose (func (xWindow *xwindow.Window) {
|
||||
holdOff := false
|
||||
for _, callback := range window.on.tryClose.Listeners() {
|
||||
if !callback() { holdOff = true }
|
||||
}
|
||||
if !holdOff { window.Close() }
|
||||
window.Close()
|
||||
})
|
||||
|
||||
xevent.ExposeFun(window.handleExpose).
|
||||
@ -240,29 +247,56 @@ func (this *window) SetBounds (bounds image.Rectangle) {
|
||||
bounds.Min.Y + bounds.Dy())
|
||||
}
|
||||
|
||||
func (this *window) NewChild (kind tomo.WindowKind, bounds image.Rectangle) (tomo.Window, error) {
|
||||
func (this *window) NewChild (bounds image.Rectangle) (tomo.Window, error) {
|
||||
leader := this.leader
|
||||
|
||||
child, err := this.backend.newWindow (
|
||||
bounds.Add(this.metrics.innerBounds.Min), false)
|
||||
child.leader = leader
|
||||
if err != nil { return nil, err }
|
||||
|
||||
child.leader = leader
|
||||
err = child.setKind(kind)
|
||||
if err != nil { return nil, err }
|
||||
if kind == tomo.WindowKindModal {
|
||||
this.hasModal = true
|
||||
child.modalParent = this
|
||||
}
|
||||
child.setClientLeader(leader)
|
||||
leader.setClientLeader(leader)
|
||||
|
||||
icccm.WmTransientForSet (
|
||||
this.backend.x,
|
||||
child.xWindow.Id,
|
||||
leader.xWindow.Id)
|
||||
child.setType("UTILITY")
|
||||
// child.inheritProperties(leader.window)
|
||||
return child, err
|
||||
}
|
||||
|
||||
func (this *window) NewMenu (bounds image.Rectangle) (tomo.Window, error) {
|
||||
menu, err := this.backend.newWindow (
|
||||
bounds.Add(this.metrics.innerBounds.Min), true)
|
||||
menu.shy = true
|
||||
icccm.WmTransientForSet (
|
||||
this.backend.x,
|
||||
menu.xWindow.Id,
|
||||
this.xWindow.Id)
|
||||
menu.setType("POPUP_MENU")
|
||||
// menu.inheritProperties(this)
|
||||
return menu, err
|
||||
}
|
||||
|
||||
func (this *window) NewModal (bounds image.Rectangle) (tomo.Window, error) {
|
||||
modal, err := this.backend.newWindow (
|
||||
bounds.Add(this.metrics.innerBounds.Min), false)
|
||||
icccm.WmTransientForSet (
|
||||
this.backend.x,
|
||||
modal.xWindow.Id,
|
||||
this.xWindow.Id)
|
||||
ewmh.WmStateSet (
|
||||
this.backend.x,
|
||||
modal.xWindow.Id,
|
||||
[]string { "_NET_WM_STATE_MODAL" })
|
||||
modal.modalParent = this
|
||||
this.hasModal = true
|
||||
// modal.inheritProperties(window)
|
||||
return modal, err
|
||||
}
|
||||
|
||||
func (this *window) Modifiers () input.Modifiers {
|
||||
return this.hierarchy.Modifiers()
|
||||
}
|
||||
@ -296,12 +330,12 @@ func (this *window) Visible () bool {
|
||||
return this.visible
|
||||
}
|
||||
|
||||
func (this *window) Close () error {
|
||||
func (this *window) Close () {
|
||||
xevent .Detach(this.backend.x, this.xWindow.Id)
|
||||
keybind .Detach(this.backend.x, this.xWindow.Id)
|
||||
mousebind.Detach(this.backend.x, this.xWindow.Id)
|
||||
|
||||
this.on.close.Broadcast()
|
||||
this.onClose.Broadcast()
|
||||
if this.modalParent != nil {
|
||||
// we are a modal dialog, so unlock the parent
|
||||
this.modalParent.hasModal = false
|
||||
@ -311,15 +345,10 @@ func (this *window) Close () error {
|
||||
delete(this.backend.windows, this.xWindow.Id)
|
||||
this.xWindow.Destroy()
|
||||
this.hierarchy.Close()
|
||||
return nil // TODO maybe return an error? maybe join them?
|
||||
}
|
||||
|
||||
func (this *window) OnClose (callback func ()) event.Cookie {
|
||||
return this.on.close.Connect(callback)
|
||||
}
|
||||
|
||||
func (this *window) OnTryClose (callback func () bool) event.Cookie {
|
||||
return this.on.tryClose.Connect(callback)
|
||||
return this.onClose.Connect(callback)
|
||||
}
|
||||
|
||||
func (this *window) grabInput () {
|
||||
@ -335,19 +364,6 @@ func (this *window) ungrabInput () {
|
||||
mousebind.UngrabPointer(this.backend.x)
|
||||
}
|
||||
|
||||
func (this *window) setKind (kind tomo.WindowKind) error {
|
||||
err := this.setType(windowKindToType(kind))
|
||||
if err != nil { return err }
|
||||
if kind == tomo.WindowKindModal {
|
||||
err = this.setState("MODAL")
|
||||
if err != nil { return err }
|
||||
}
|
||||
if kind == tomo.WindowKindMenu {
|
||||
this.shy = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *window) setType (ty string) error {
|
||||
return ewmh.WmWindowTypeSet (
|
||||
this.backend.x,
|
||||
@ -355,13 +371,6 @@ func (this *window) setType (ty string) error {
|
||||
[]string { "_NET_WM_WINDOW_TYPE_" + ty })
|
||||
}
|
||||
|
||||
func (this *window) setState (state string) error {
|
||||
return ewmh.WmStateSet (
|
||||
this.backend.x,
|
||||
this.xWindow.Id,
|
||||
[]string { "_NET_WM_STATE_" + state })
|
||||
}
|
||||
|
||||
func (this *window) setClientLeader (leader *window) error {
|
||||
hints, _ := icccm.WmHintsGet(this.backend.x, this.xWindow.Id)
|
||||
if hints == nil {
|
||||
@ -467,15 +476,3 @@ func (this *window) doMinimumSize () {
|
||||
this.xWindow.Resize(newWidth, newHeight)
|
||||
}
|
||||
}
|
||||
|
||||
func windowKindToType (kind tomo.WindowKind) string {
|
||||
switch kind {
|
||||
case tomo.WindowKindNormal: return "NORMAL"
|
||||
case tomo.WindowKindPlain: return "DOCK"
|
||||
case tomo.WindowKindUtility: return "UTILITY"
|
||||
case tomo.WindowKindToolbar: return "TOOLBAR"
|
||||
case tomo.WindowKindMenu: return "POPUP_MENU"
|
||||
case tomo.WindowKindModal: return "NORMAL"
|
||||
default: return strings.ReplaceAll(strings.ToUpper(string(kind)), " ", "_")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user