Skip to content

Commit

Permalink
Small bug fixes for Plan 9
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
driusan committed Feb 19, 2017
1 parent b79b95e commit 3058d04
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 5 deletions.
1 change: 1 addition & 0 deletions actions/shellcmd.go
@@ -1,4 +1,5 @@
// +build !windows
// +build !plan9

package actions

Expand Down
5 changes: 5 additions & 0 deletions actions/shellcmd_plan9.go
@@ -0,0 +1,5 @@
package actions

func getShellCmd() (cmd, args string) {
return "rc", "-c"
}

This file was deleted.

5 changes: 5 additions & 0 deletions renderer/recalculatefont.go
Expand Up @@ -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)
Expand Down
99 changes: 99 additions & 0 deletions 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

}

0 comments on commit 3058d04

Please sign in to comment.