From 3058d04c49f537bc8e64e1c54f02d83fd9d0308c Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Sat, 18 Feb 2017 22:20:02 -0500 Subject: [PATCH] Small bug fixes for Plan 9 Use rc instead of sh for executing commands, and use the default DPI instead of the 0 value, since the driver doesn't send the correct DPI. --- actions/shellcmd.go | 1 + actions/shellcmd_plan9.go | 5 + .../Description | 5 - renderer/recalculatefont.go | 5 + viewer/window.go | 99 +++++++++++++++++++ 5 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 actions/shellcmd_plan9.go delete mode 100644 issues/Keyboard-plumbing-should-include-click-attribute/Description create mode 100644 viewer/window.go diff --git a/actions/shellcmd.go b/actions/shellcmd.go index 6461fda..54c14a9 100644 --- a/actions/shellcmd.go +++ b/actions/shellcmd.go @@ -1,4 +1,5 @@ // +build !windows +// +build !plan9 package actions diff --git a/actions/shellcmd_plan9.go b/actions/shellcmd_plan9.go new file mode 100644 index 0000000..70d2e60 --- /dev/null +++ b/actions/shellcmd_plan9.go @@ -0,0 +1,5 @@ +package actions + +func getShellCmd() (cmd, args string) { + return "rc", "-c" +} diff --git a/issues/Keyboard-plumbing-should-include-click-attribute/Description b/issues/Keyboard-plumbing-should-include-click-attribute/Description deleted file mode 100644 index c3b7b01..0000000 --- a/issues/Keyboard-plumbing-should-include-click-attribute/Description +++ /dev/null @@ -1,5 +0,0 @@ -When a mouse event generates a click, the message plumbed includes a click -attribute in order to make it easier for the plumber to get things right -from context. - -The keyboard should do this too, when "enter" generates a plumbing event. \ No newline at end of file diff --git a/renderer/recalculatefont.go b/renderer/recalculatefont.go index 6168677..60f06d8 100644 --- a/renderer/recalculatefont.go +++ b/renderer/recalculatefont.go @@ -15,6 +15,11 @@ import ( ) func RecalculateFontFace(dpi float64) { + if dpi == 0 { + // If called with the 0 value, continue to use our + // default. + return + } ft, err := truetype.Parse(gomono.TTF) if err != nil { fmt.Fprintf(os.Stderr, "Could not parse font: %s\n", err) diff --git a/viewer/window.go b/viewer/window.go new file mode 100644 index 0000000..2810a1a --- /dev/null +++ b/viewer/window.go @@ -0,0 +1,99 @@ +package main + +import ( + "image" + "image/draw" + "sync" + + "github.com/driusan/de/demodel" + "github.com/driusan/de/kbmap" + "github.com/driusan/de/renderer" + "github.com/driusan/de/viewer" + "golang.org/x/exp/shiny/screen" + "golang.org/x/mobile/event/size" +) + +// dewindow encapsulates the shiny window of de. +type dewindow struct { + sync.Mutex + screen.Window + + painting bool + buffer screen.Buffer + sz size.Event +} + +func (w *dewindow) paint(buf *demodel.CharBuffer, viewport *viewer.Viewport) { + if w.painting { + return + } + w.realpaint(buf, viewport) +} + +// paints buf into the viewport attached to this window +func (w *dewindow) realpaint(buf *demodel.CharBuffer, viewport *viewer.Viewport) { + w.Lock() + defer w.Unlock() + + defer func() { + w.painting = false + }() + w.painting = true + + if w.buffer == nil { + return + } + dst := w.buffer.RGBA() + + // Fill the buffer with the window background colour before + // drawing the web page on top of it. + // This should logically be in the viewport code itself, but importing + // kbmap to switch on the mode sentinals would result in a cyclical + // import. + if viewport.BackgroundMode != viewer.StableBackground { + switch viewport.GetKeyboardMode() { + case kbmap.InsertMode: + draw.Draw(dst, dst.Bounds(), &image.Uniform{renderer.InsertBackground}, image.ZP, draw.Src) + case kbmap.DeleteMode: + draw.Draw(dst, dst.Bounds(), &image.Uniform{renderer.DeleteBackground}, image.ZP, draw.Src) + default: + draw.Draw(dst, dst.Bounds(), &image.Uniform{renderer.NormalBackground}, image.ZP, draw.Src) + } + } else { + draw.Draw(dst, dst.Bounds(), &image.Uniform{renderer.NormalBackground}, image.ZP, draw.Src) + } + + s := w.sz.Size() + + contentBounds := dst.Bounds() + tagBounds := tagSize + // ensure that the tag takes no more than half the window, so that the content doesn't get + // drowned out by commands that output more to stderr than they should. + if wHeight := s.Y; tagBounds.Max.Y > wHeight/2 { + tagBounds.Max.Y = wHeight / 2 + } + contentBounds.Min.Y = tagBounds.Max.Y + + tagline.RenderInto(dst.SubImage(image.Rectangle{image.ZP, image.Point{s.X, tagBounds.Max.Y}}).(*image.RGBA), buf.Tagline, clipRectangle(w.sz, viewport)) + viewport.RenderInto(dst.SubImage(image.Rectangle{image.Point{0, tagBounds.Max.Y}, s}).(*image.RGBA), buf, clipRectangle(w.sz, viewport)) + + w.Upload(image.Point{0, 0}, w.buffer, dst.Bounds()) + w.Publish() + return +} + +func (w *dewindow) setSize(s size.Event, sc screen.Screen) error { + w.Lock() + defer w.Unlock() + + w.sz = s + if w.buffer != nil { + // Release the old buffer. + w.buffer.Release() + } + + sbuffer, err := sc.NewBuffer(s.Size()) + w.buffer = sbuffer + return err + +}