From d09162cd81a5d7a06aacc1d54037d56189d8dc24 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Wed, 30 May 2012 15:45:26 -0400 Subject: [PATCH] still broken. ug --- client.go | 44 ++++----- frame.go | 11 ++- frame_abst.go | 3 +- frame_borders_pieces.go | 3 +- frame_full_pieces.go | 5 +- main.go | 10 +- prompt_cycle.go | 7 +- prompt_select.go | 23 ++--- render_text.go | 3 +- state_workspace.go | 3 +- window.go | 205 ---------------------------------------- 11 files changed, 64 insertions(+), 253 deletions(-) delete mode 100644 window.go diff --git a/client.go b/client.go index 392a00d..5683272 100644 --- a/client.go +++ b/client.go @@ -16,7 +16,7 @@ import ( ) type client struct { - window *window + window *xwindow.Window workspace *workspace layer int name, vname, wmname string @@ -40,7 +40,7 @@ type client struct { wmclass *icccm.WmClass stateStore map[string]*clientState - promptStore map[string]*window + promptStore map[string]*xwindow.Window frame Frame frameNada *frameNada @@ -51,7 +51,7 @@ type client struct { func newClient(id xproto.Window) *client { return &client{ - window: newWindow(id), + window: xwindow.New(X, id), workspace: nil, layer: stackDefault, name: "", @@ -73,7 +73,7 @@ func newClient(id xproto.Window) *client { transientFor: 0, wmclass: nil, stateStore: make(map[string]*clientState), - promptStore: make(map[string]*window), + promptStore: make(map[string]*xwindow.Window), frame: nil, frameNada: nil, frameSlim: nil, @@ -90,7 +90,7 @@ func (c *client) unmanage() { c.frame.Destroy() c.setWmState(icccm.StateWithdrawn) - xevent.Detach(X, c.window.id) + xevent.Detach(X, c.window.Id) c.promptRemove() WM.stackRemove(c) WM.clientRemove(c) @@ -116,7 +116,7 @@ func (c *client) Map() { if c.Mapped() { return } - c.window.map_() + c.window.Map() c.frame.Map() c.isMapped = true c.initMap = true @@ -167,7 +167,7 @@ func (c *client) setWmState(state int) { return } - err := icccm.WmStateSet(X, c.window.id, &icccm.WmState{State: state}) + err := icccm.WmStateSet(X, c.Id(), &icccm.WmState{State: state}) if err != nil { var stateStr string switch state { @@ -199,16 +199,16 @@ func (c *client) Close() { return } - cm, err := xevent.NewClientMessage(32, c.window.id, wm_protocols, + cm, err := xevent.NewClientMessage(32, c.Id(), wm_protocols, int(wm_del_win)) if err != nil { logger.Warning.Println(err) return } - xproto.SendEvent(X.Conn(), false, c.window.id, 0, string(cm.Bytes())) + xproto.SendEvent(X.Conn(), false, c.Id(), 0, string(cm.Bytes())) } else { - c.window.kill() + c.window.Kill() } } @@ -229,7 +229,7 @@ func (c *client) Alive() bool { continue } - wid := c.Win().id + wid := c.Id() ev := everr.Event if um, ok := ev.(xproto.UnmapNotifyEvent); ok && um.Window == wid { if ignore <= 0 { @@ -245,7 +245,7 @@ func (c *client) Alive() bool { // Namely, when we know the window has been unmapped but are not sure // if it is still an X resource. func (c *client) TrulyAlive() bool { - _, err := xwindow.RawGeometry(X, xproto.Drawable(c.window.id)) + _, err := xwindow.RawGeometry(X, xproto.Drawable(c.Id())) if err != nil { return false } @@ -262,7 +262,7 @@ func (c *client) ForceWorkspace() { func (c *client) Focus() { if c.hints.Flags&icccm.HintInput > 0 && c.hints.Input == 1 { c.ForceWorkspace() - c.window.focus() + c.window.Focus() c.Focused() } else if strIndex("WM_TAKE_FOCUS", c.protocols) > -1 { c.ForceWorkspace() @@ -279,16 +279,14 @@ func (c *client) Focus() { return } - cm, err := xevent.NewClientMessage(32, c.window.id, - wm_protocols, - int(wm_take_focus), - int(X.TimeGet())) + cm, err := xevent.NewClientMessage(32, c.Id(), + wm_protocols, int(wm_take_focus), int(X.TimeGet())) if err != nil { logger.Warning.Println(err) return } - xproto.SendEvent(X.Conn(), false, c.window.id, 0, string(cm.Bytes())) + xproto.SendEvent(X.Conn(), false, c.Id(), 0, string(cm.Bytes())) c.Focused() } @@ -370,7 +368,7 @@ func (c *client) updateProperty(ev xevent.PropertyNotifyEvent) { c.transientFor = transientFor } case "_NET_WM_USER_TIME": - newTime, err := ewmh.WmUserTimeGet(X, c.window.id) + newTime, err := ewmh.WmUserTimeGet(X, c.Id()) showVals(c.lastTime, newTime) if err == nil { c.lastTime = newTime @@ -447,11 +445,11 @@ func (c *client) FrameFull() { } func (c *client) Geom() xrect.Rect { - return c.window.geom + return c.window.Geom } func (c *client) Id() xproto.Window { - return c.window.id + return c.window.Id } func (c *client) Layer() int { @@ -475,10 +473,10 @@ func (c *client) Name() string { return "N/A" } -func (c *client) Win() *window { +func (c *client) Win() *xwindow.Window { return c.window } func (c *client) String() string { - return fmt.Sprintf("%s (%X)", c.Name(), c.window.id) + return fmt.Sprintf("%s (%X)", c.Name(), c.Id()) } diff --git a/frame.go b/frame.go index 5abdc42..d387337 100644 --- a/frame.go +++ b/frame.go @@ -6,6 +6,7 @@ import ( "github.com/BurntSushi/xgbutil/xevent" "github.com/BurntSushi/xgbutil/xgraphics" "github.com/BurntSushi/xgbutil/xrect" + "github.com/BurntSushi/xgbutil/xwindow" ) const ( @@ -30,7 +31,7 @@ type Frame interface { On() Parent() *frameParent ParentId() xproto.Window - ParentWin() *window + ParentWin() *xwindow.Window State() int Active() Inactive() @@ -52,7 +53,7 @@ type Frame interface { } type frameParent struct { - window *window + window *xwindow.Window client *client } @@ -75,7 +76,7 @@ func newParent(c *client) *frameParent { return p } -func (p *frameParent) Win() *window { +func (p *frameParent) Win() *xwindow.Window { return p.window } @@ -83,12 +84,12 @@ func (p *frameParent) Win() *window { // decorations. Basically, it contains the raw X window and pixmaps for each // of the available states for quick switching. type framePiece struct { - win *window + win *xwindow.Window imgActive xproto.Pixmap imgInactive xproto.Pixmap } -func newFramePiece(win *window, imgA, imgI xproto.Pixmap) framePiece { +func newFramePiece(win *xwindow.Window, imgA, imgI xproto.Pixmap) framePiece { return framePiece{win: win, imgActive: imgA, imgInactive: imgI} } diff --git a/frame_abst.go b/frame_abst.go index 478ef7f..bae78a3 100644 --- a/frame_abst.go +++ b/frame_abst.go @@ -4,6 +4,7 @@ import ( "github.com/BurntSushi/xgb/xproto" "github.com/BurntSushi/xgbutil/xrect" + "github.com/BurntSushi/xgbutil/xwindow" ) type abstFrame struct { @@ -70,7 +71,7 @@ func (f *abstFrame) ParentId() xproto.Window { return f.parent.window.id } -func (f *abstFrame) ParentWin() *window { +func (f *abstFrame) ParentWin() *xwindow.Window { return f.parent.window } diff --git a/frame_borders_pieces.go b/frame_borders_pieces.go index 4e3ca58..f725301 100644 --- a/frame_borders_pieces.go +++ b/frame_borders_pieces.go @@ -4,10 +4,11 @@ import ( "github.com/BurntSushi/xgb/xproto" "github.com/BurntSushi/xgbutil/xgraphics" + "github.com/BurntSushi/xgbutil/xwindow" ) func (f *frameBorders) newPieceWindow(ident string, - cursor xproto.Cursor) *window { + cursor xproto.Cursor) *xwindow.Window { mask := xproto.CwBackPixmap | xproto.CwEventMask | xproto.CwCursor vals := []uint32{xproto.BackPixmapParentRelative, diff --git a/frame_full_pieces.go b/frame_full_pieces.go index 0822e6f..7e27de4 100644 --- a/frame_full_pieces.go +++ b/frame_full_pieces.go @@ -4,9 +4,12 @@ import ( "github.com/BurntSushi/xgb/xproto" "github.com/BurntSushi/xgbutil/xgraphics" + "github.com/BurntSushi/xgbutil/xwindow" ) -func (f *frameFull) newPieceWindow(ident string, cursor xproto.Cursor) *window { +func (f *frameFull) newPieceWindow(ident string, + cursor xproto.Cursor) *xwindow.Window { + mask := xproto.CwBackPixmap | xproto.CwEventMask | xproto.CwCursor vals := []uint32{xproto.BackPixmapParentRelative, xproto.EventMaskButtonPress | xproto.EventMaskButtonRelease | diff --git a/main.go b/main.go index 211d7a8..a29ec83 100644 --- a/main.go +++ b/main.go @@ -106,7 +106,15 @@ func main() { xevent.MapRequestFun(clientMapRequest).Connect(X, ROOT.id) // Oblige configure requests from windows we don't manage. - xevent.ConfigureRequestFun(configureRequest).Connect(X, ROOT.id) + xevent.ConfigureRequestFun( + func(X *xgbutil.XUtil, ev xevent.ConfigureRequestEvent) { + flags := int(ev.ValueMask) & + ^int(xproto.ConfigWindowSibling) & + ^int(xproto.ConfigWindowStack) + xwindow.New(ev.Window).Configure(flags, + int(ev.X), int(ev.Y), int(ev.Width), int(ev.Height), + ev.Sibling, ev.StackMode) + }).Connect(X, ROOT.id) // Listen to Root client message events. // We satisfy EWMH with these AND it also provides a mechanism diff --git a/prompt_cycle.go b/prompt_cycle.go index 45a9b1f..aee46d4 100644 --- a/prompt_cycle.go +++ b/prompt_cycle.go @@ -7,6 +7,7 @@ import ( "github.com/BurntSushi/xgbutil/keybind" "github.com/BurntSushi/xgbutil/xevent" "github.com/BurntSushi/xgbutil/xgraphics" + "github.com/BurntSushi/xgbutil/xwindow" "github.com/BurntSushi/wingo/logger" ) @@ -17,9 +18,9 @@ type promptCycle struct { grabbedMods uint16 clients []*client fontHeight int - top *window - bTop, bBot, bLft, bRht *window - iconBorder *window + top *xwindow.Window + bTop, bBot, bLft, bRht *xwindow.Window + iconBorder *xwindow.Window } func (pc *promptCycle) Id() xproto.Window { diff --git a/prompt_select.go b/prompt_select.go index 83e9f2f..fe6a542 100644 --- a/prompt_select.go +++ b/prompt_select.go @@ -32,6 +32,7 @@ import ( "github.com/BurntSushi/xgbutil/keybind" "github.com/BurntSushi/xgbutil/xevent" "github.com/BurntSushi/xgbutil/xgraphics" + "github.com/BurntSushi/xgbutil/xwindow" "github.com/BurntSushi/wingo/logger" ) @@ -51,7 +52,7 @@ type promptSelectListFun func() []*promptSelectGroup // prompt under a specific heading. type promptSelectGroup struct { label string - win *window + win *xwindow.Window items []*promptSelectItem } @@ -70,10 +71,10 @@ func newPromptSelectGroup(label string, win *window, // promptSelectItem represents a single *selectable* item in a prompt. type promptSelectItem struct { - text string // visually displayed and used for tab completion - action func() // performed when this item is selected - active *window // window w/ image when selected - inactive *window // window w/ image when not selected + text string // visually displayed and used for tab completion + action func() // performed when this item is selected + active *xwindow.Window // window w/ image when selected + inactive *xwindow.Window // window w/ image when not selected } func newPromptSelectItem(text string, action func(), @@ -98,13 +99,13 @@ type promptSelect struct { prefixSearch bool // whether prefix or substring search groups []*promptSelectGroup itemsShowing []*promptSelectItem - top *window + top *xwindow.Window input *textInput - labVisible *window - labHidden *window - bInp *window - bTop, bBot *window - bLft, bRht *window + labVisible *xwindow.Window + labHidden *xwindow.Window + bInp *xwindow.Window + bTop, bBot *xwindow.Window + bLft, bRht *xwindow.Window } // Id returns the parent window of this prompt. diff --git a/render_text.go b/render_text.go index 55e9660..7c25832 100644 --- a/render_text.go +++ b/render_text.go @@ -7,6 +7,7 @@ import ( "code.google.com/p/freetype-go/freetype/truetype" "github.com/BurntSushi/xgbutil/xgraphics" + "github.com/BurntSushi/xgbutil/xwindow" "github.com/BurntSushi/wingo/logger" ) @@ -18,7 +19,7 @@ import ( const renderTextBreathe = 5 type textInput struct { - win *window + win *xwindow.Window img *wImg text []rune bgColor int diff --git a/state_workspace.go b/state_workspace.go index 90129c6..a89d947 100644 --- a/state_workspace.go +++ b/state_workspace.go @@ -6,6 +6,7 @@ import ( "github.com/BurntSushi/xgbutil/ewmh" "github.com/BurntSushi/xgbutil/xrect" + "github.com/BurntSushi/xgbutil/xwindow" "github.com/BurntSushi/wingo/logger" ) @@ -22,7 +23,7 @@ type workspace struct { name string // note that this does not have to be unique head int // the most recent physical head this workspace was on active bool - promptStore map[string]*window + promptStore map[string]*xwindow.Window state int // the default placement policy of this workspace floaters []layout tilers []layout diff --git a/window.go b/window.go deleted file mode 100644 index f5d5f20..0000000 --- a/window.go +++ /dev/null @@ -1,205 +0,0 @@ -package main - -import ( - "image" - - "github.com/BurntSushi/xgb/xproto" - - "github.com/BurntSushi/xgbutil" - "github.com/BurntSushi/xgbutil/xevent" - "github.com/BurntSushi/xgbutil/xgraphics" - "github.com/BurntSushi/xgbutil/xrect" - "github.com/BurntSushi/xgbutil/xwindow" - - "github.com/BurntSushi/wingo/logger" -) - -type window struct { - id xproto.Window - geom xrect.Rect -} - -const ( - DoX = xproto.ConfigWindowX - DoY = xproto.ConfigWindowY - DoW = xproto.ConfigWindowWidth - DoH = xproto.ConfigWindowHeight - DoBorder = xproto.ConfigWindowBorderWidth - DoSibling = xproto.ConfigWindowSibling - DoStack = xproto.ConfigWindowStackMode -) - -func newWindow(id xproto.Window) *window { - return &window{ - id: id, - geom: xrect.New(0, 0, 1, 1), - } -} - -func createWindow(parent xproto.Window, masks int, vals ...uint32) *window { - wid, err := xproto.NewWindowId(X.Conn()) - if err != nil { - logger.Error.Printf("Could not create window: %s", err) - return nil - } - scrn := X.Screen() - - xproto.CreateWindow(X.Conn(), scrn.RootDepth, wid, parent, 0, 0, 1, 1, 0, - xproto.WindowClassInputOutput, scrn.RootVisual, - uint32(masks), vals) - - return newWindow(wid) -} - -func createImageWindow(parent xproto.Window, img image.Image, - masks int, vals ...uint32) *window { - newWin := createWindow(parent, masks, vals...) - - width, height := xgraphics.GetDim(img) - newWin.moveresize(DoW|DoH, 0, 0, width, height) - - xgraphics.PaintImg(X, newWin.id, img) - - return newWin -} - -func (w *window) listen(masks int) { - xproto.ChangeWindowAttributes(X.Conn(), w.id, - xproto.CwEventMask, []uint32{uint32(masks)}) -} - -func (w *window) map_() { - xproto.MapWindow(X.Conn(), w.id) -} - -func (w *window) unmap() { - xproto.UnmapWindow(X.Conn(), w.id) -} - -func (w *window) change(masks int, vals ...uint32) { - xproto.ChangeWindowAttributes(X.Conn(), w.id, uint32(masks), vals) -} - -func (w *window) clear() { - xproto.ClearArea(X.Conn(), false, w.id, 0, 0, 0, 0) -} - -func (w *window) geometry() (xrect.Rect, error) { - var err error - w.geom, err = xwindow.RawGeometry(X, xproto.Drawable(w.id)) - if err != nil { - return nil, err - } - return w.geom, nil -} - -func (w *window) kill() { - xproto.KillClient(X.Conn(), uint32(w.id)) -} - -func (w *window) destroy() { - xproto.DestroyWindow(X.Conn(), w.id) - xevent.Detach(X, w.id) -} - -func (w *window) focus() { - xproto.SetInputFocus(X.Conn(), xproto.InputFocusPointerRoot, w.id, 0) -} - -// moveresize is a wrapper around configure that only accepts parameters -// related to size and position. -func (win *window) moveresize(flags, x, y, w, h int) { - // Kill any hopes of stacking - flags = (flags & ^DoSibling) & ^DoStack - win.configure(flags, x, y, w, h, 0, 0) -} - -// configure is the method version of 'configure'. -// It is duplicated because we need to update our idea of the window's -// geometry. (We don't want another set of 'if' statements because it -// needs to be as efficient as possible.) -func (win *window) configure(flags, x, y, w, h int, - sibling xproto.Window, stackMode byte) { - - vals := []uint32{} - - if DoX&flags > 0 { - vals = append(vals, uint32(x)) - win.geom.XSet(x) - } - if DoY&flags > 0 { - vals = append(vals, uint32(y)) - win.geom.YSet(y) - } - if DoW&flags > 0 { - if int16(w) <= 0 { - w = 1 - } - vals = append(vals, uint32(w)) - win.geom.WidthSet(w) - } - if DoH&flags > 0 { - if int16(h) <= 0 { - h = 1 - } - vals = append(vals, uint32(h)) - win.geom.HeightSet(h) - } - if DoSibling&flags > 0 { - vals = append(vals, uint32(sibling)) - } - if DoStack&flags > 0 { - vals = append(vals, uint32(stackMode)) - } - - // Don't send anything if we have nothing to send - if len(vals) == 0 { - return - } - - xproto.ConfigureWindow(X.Conn(), win.id, uint16(flags), vals) -} - -// configure is a nice wrapper around ConfigureWindow. -// We purposefully omit 'BorderWidth' because I don't think it's ever used -// any more. -func configure(window xproto.Window, flags, x, y, w, h int, - sibling xproto.Window, stackMode byte) { - - vals := []uint32{} - - if DoX&flags > 0 { - vals = append(vals, uint32(x)) - } - if DoY&flags > 0 { - vals = append(vals, uint32(y)) - } - if DoW&flags > 0 { - if int16(w) <= 0 { - w = 1 - } - vals = append(vals, uint32(w)) - } - if DoH&flags > 0 { - if int16(h) <= 0 { - h = 1 - } - vals = append(vals, uint32(h)) - } - if DoSibling&flags > 0 { - vals = append(vals, uint32(sibling)) - } - if DoStack&flags > 0 { - vals = append(vals, uint32(stackMode)) - } - - xproto.ConfigureWindow(X.Conn(), window, uint16(flags), vals) -} - -// configureRequest responds to generic configure requests from windows that -// we don't manage. -func configureRequest(X *xgbutil.XUtil, ev xevent.ConfigureRequestEvent) { - configure(ev.Window, int(ev.ValueMask) & ^int(DoStack) & ^int(DoSibling), - int(ev.X), int(ev.Y), int(ev.Width), int(ev.Height), - ev.Sibling, ev.StackMode) -}